FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/rsoenc.c
Date: 2022-12-05 20:26:17
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 "rawenc.h"
26 #include "riff.h"
27 #include "rso.h"
28
29 1 static int rso_write_header(AVFormatContext *s)
30 {
31 1 AVIOContext *pb = s->pb;
32 1 AVCodecParameters *par = s->streams[0]->codecpar;
33
34
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!par->codec_tag)
35 return AVERROR_INVALIDDATA;
36
37
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (par->ch_layout.nb_channels != 1) {
38 av_log(s, AV_LOG_ERROR, "RSO only supports mono\n");
39 return AVERROR_INVALIDDATA;
40 }
41
42
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!(s->pb->seekable & AVIO_SEEKABLE_NORMAL)) {
43 av_log(s, AV_LOG_ERROR, "muxer does not support non seekable output\n");
44 return AVERROR_INVALIDDATA;
45 }
46
47 /* XXX: find legal sample rates (if any) */
48
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (par->sample_rate >= 1u<<16) {
49 av_log(s, AV_LOG_ERROR, "Sample rate must be < 65536\n");
50 return AVERROR_INVALIDDATA;
51 }
52
53
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (par->codec_id == AV_CODEC_ID_ADPCM_IMA_WAV) {
54 avpriv_report_missing_feature(s, "ADPCM in RSO");
55 return AVERROR_PATCHWELCOME;
56 }
57
58 /* format header */
59 1 avio_wb16(pb, par->codec_tag); /* codec ID */
60 1 avio_wb16(pb, 0); /* data size, will be written at EOF */
61 1 avio_wb16(pb, par->sample_rate);
62 1 avio_wb16(pb, 0x0000); /* play mode ? (0x0000 = don't loop) */
63
64 1 return 0;
65 }
66
67 1 static int rso_write_trailer(AVFormatContext *s)
68 {
69 1 AVIOContext *pb = s->pb;
70 int64_t file_size;
71 uint16_t coded_file_size;
72
73 1 file_size = avio_tell(pb);
74
75
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (file_size < 0)
76 return file_size;
77
78
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (file_size > 0xffff + RSO_HEADER_SIZE) {
79 av_log(s, AV_LOG_WARNING,
80 "Output file is too big (%"PRId64" bytes >= 64kB)\n", file_size);
81 coded_file_size = 0xffff;
82 } else {
83 1 coded_file_size = file_size - RSO_HEADER_SIZE;
84 }
85
86 /* update file size */
87 1 avio_seek(pb, 2, SEEK_SET);
88 1 avio_wb16(pb, coded_file_size);
89 1 avio_seek(pb, file_size, SEEK_SET);
90
91 1 return 0;
92 }
93
94 const AVOutputFormat ff_rso_muxer = {
95 .name = "rso",
96 .long_name = NULL_IF_CONFIG_SMALL("Lego Mindstorms RSO"),
97 .extensions = "rso",
98 .audio_codec = AV_CODEC_ID_PCM_U8,
99 .video_codec = AV_CODEC_ID_NONE,
100 .write_header = rso_write_header,
101 .write_packet = ff_raw_write_packet,
102 .write_trailer = rso_write_trailer,
103 .codec_tag = ff_rso_codec_tags_list,
104 .flags = AVFMT_NOTIMESTAMPS,
105 };
106