FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/rsoenc.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 23 35 65.7%
Functions: 2 2 100.0%
Branches: 7 14 50.0%

Line Branch Exec Source
1 /*
2 * RSO muxer
3 * Copyright (c) 2001 Fabrice Bellard (original AU code)
4 * Copyright (c) 2010 Rafael Carre
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include "avformat.h"
24 #include "internal.h"
25 #include "mux.h"
26 #include "rawenc.h"
27 #include "riff.h"
28 #include "rso.h"
29
30 1 static int rso_write_header(AVFormatContext *s)
31 {
32 1 AVIOContext *pb = s->pb;
33 1 AVCodecParameters *par = s->streams[0]->codecpar;
34
35
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!par->codec_tag)
36 return AVERROR_INVALIDDATA;
37
38
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (par->ch_layout.nb_channels != 1) {
39 av_log(s, AV_LOG_ERROR, "RSO only supports mono\n");
40 return AVERROR_INVALIDDATA;
41 }
42
43
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!(s->pb->seekable & AVIO_SEEKABLE_NORMAL)) {
44 av_log(s, AV_LOG_ERROR, "muxer does not support non seekable output\n");
45 return AVERROR_INVALIDDATA;
46 }
47
48 /* XXX: find legal sample rates (if any) */
49
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (par->sample_rate >= 1u<<16) {
50 av_log(s, AV_LOG_ERROR, "Sample rate must be < 65536\n");
51 return AVERROR_INVALIDDATA;
52 }
53
54
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (par->codec_id == AV_CODEC_ID_ADPCM_IMA_WAV) {
55 avpriv_report_missing_feature(s, "ADPCM in RSO");
56 return AVERROR_PATCHWELCOME;
57 }
58
59 /* format header */
60 1 avio_wb16(pb, par->codec_tag); /* codec ID */
61 1 avio_wb16(pb, 0); /* data size, will be written at EOF */
62 1 avio_wb16(pb, par->sample_rate);
63 1 avio_wb16(pb, 0x0000); /* play mode ? (0x0000 = don't loop) */
64
65 1 return 0;
66 }
67
68 1 static int rso_write_trailer(AVFormatContext *s)
69 {
70 1 AVIOContext *pb = s->pb;
71 int64_t file_size;
72 uint16_t coded_file_size;
73
74 1 file_size = avio_tell(pb);
75
76
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (file_size < 0)
77 return file_size;
78
79
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (file_size > 0xffff + RSO_HEADER_SIZE) {
80 av_log(s, AV_LOG_WARNING,
81 "Output file is too big (%"PRId64" bytes >= 64kB)\n", file_size);
82 coded_file_size = 0xffff;
83 } else {
84 1 coded_file_size = file_size - RSO_HEADER_SIZE;
85 }
86
87 /* update file size */
88 1 avio_seek(pb, 2, SEEK_SET);
89 1 avio_wb16(pb, coded_file_size);
90 1 avio_seek(pb, file_size, SEEK_SET);
91
92 1 return 0;
93 }
94
95 const FFOutputFormat ff_rso_muxer = {
96 .p.name = "rso",
97 .p.long_name = NULL_IF_CONFIG_SMALL("Lego Mindstorms RSO"),
98 .p.extensions = "rso",
99 .p.audio_codec = AV_CODEC_ID_PCM_U8,
100 .p.video_codec = AV_CODEC_ID_NONE,
101 .p.subtitle_codec = AV_CODEC_ID_NONE,
102 .flags_internal = FF_OFMT_FLAG_MAX_ONE_OF_EACH,
103 .write_header = rso_write_header,
104 .write_packet = ff_raw_write_packet,
105 .write_trailer = rso_write_trailer,
106 .p.codec_tag = ff_rso_codec_tags_list,
107 .p.flags = AVFMT_NOTIMESTAMPS,
108 };
109