FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/musx.c
Date: 2026-09-26 05:01:43
Exec Total Coverage
Lines: 3 121 2.5%
Functions: 1 3 33.3%
Branches: 1 60 1.7%

Line Branch Exec Source
1 /*
2 * MUSX demuxer
3 * Copyright (c) 2016 Paul B Mahol
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include "libavutil/avassert.h"
23 #include "libavutil/intreadwrite.h"
24 #include "avformat.h"
25 #include "demux.h"
26 #include "internal.h"
27
28 8066 static int musx_probe(const AVProbeData *p)
29 {
30 unsigned version;
31
32
1/2
✓ Branch 0 taken 8066 times.
✗ Branch 1 not taken.
8066 if (AV_RB32(p->buf) != MKBETAG('M','U','S','X'))
33 8066 return 0;
34
35 ✗ version = AV_RL32(p->buf + 8);
36 ✗ if (version != 10 &&
37 ✗ version != 6 &&
38 ✗ version != 5 &&
39 ✗ version != 4 &&
40 version != 201)
41 ✗ return 0;
42
43 ✗ return AVPROBE_SCORE_MAX / 5 * 2;
44 }
45
46 ✗ static int musx_read_header(AVFormatContext *s)
47 {
48 unsigned type, version, coding, offset;
49 AVStream *st;
50
51 ✗ avio_skip(s->pb, 8);
52 ✗ version = avio_rl32(s->pb);
53 ✗ if (version != 10 &&
54 ✗ version != 6 &&
55 ✗ version != 5 &&
56 ✗ version != 4 &&
57 version != 201) {
58 ✗ avpriv_request_sample(s, "Unsupported version: %d", version);
59 ✗ return AVERROR_PATCHWELCOME;
60 }
61 ✗ avio_skip(s->pb, 4);
62
63 ✗ st = avformat_new_stream(s, NULL);
64 ✗ if (!st)
65 ✗ return AVERROR(ENOMEM);
66
67 ✗ if (version == 201) {
68 ✗ avio_skip(s->pb, 8);
69 ✗ offset = avio_rl32(s->pb);
70 ✗ st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
71 ✗ st->codecpar->codec_id = AV_CODEC_ID_ADPCM_PSX;
72 ✗ st->codecpar->ch_layout.nb_channels = 2;
73 ✗ st->codecpar->sample_rate = 32000;
74 ✗ st->codecpar->block_align = 0x80 * st->codecpar->ch_layout.nb_channels;
75 ✗ } else if (version == 10) {
76 ✗ type = avio_rl32(s->pb);
77 ✗ st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
78 ✗ offset = 0x800;
79 ✗ switch (type) {
80 ✗ case MKTAG('P', 'S', '3', '_'):
81 ✗ st->codecpar->ch_layout.nb_channels = 2;
82 ✗ st->codecpar->sample_rate = 44100;
83 ✗ avio_skip(s->pb, 44);
84 ✗ coding = avio_rl32(s->pb);
85 ✗ if (coding == MKTAG('D', 'A', 'T', '4') ||
86 coding == MKTAG('D', 'A', 'T', '8')) {
87 ✗ avio_skip(s->pb, 4);
88 ✗ st->codecpar->ch_layout.nb_channels = avio_rl32(s->pb);
89 ✗ if (st->codecpar->ch_layout.nb_channels <= 0 ||
90 ✗ st->codecpar->ch_layout.nb_channels > INT_MAX / 0x20)
91 ✗ return AVERROR_INVALIDDATA;
92 ✗ st->codecpar->sample_rate = avio_rl32(s->pb);
93 }
94 ✗ st->codecpar->codec_id = AV_CODEC_ID_ADPCM_IMA_DAT4;
95 ✗ st->codecpar->block_align = 0x20 * st->codecpar->ch_layout.nb_channels;
96 ✗ break;
97 ✗ case MKTAG('W', 'I', 'I', '_'):
98 ✗ avio_skip(s->pb, 44);
99 ✗ coding = avio_rl32(s->pb);
100 ✗ if (coding != MKTAG('D', 'A', 'T', '4') &&
101 coding != MKTAG('D', 'A', 'T', '8')) {
102 ✗ avpriv_request_sample(s, "Unsupported coding: %X", coding);
103 ✗ return AVERROR_PATCHWELCOME;
104 }
105 ✗ avio_skip(s->pb, 4);
106 ✗ st->codecpar->codec_id = AV_CODEC_ID_ADPCM_IMA_DAT4;
107 ✗ st->codecpar->ch_layout.nb_channels = avio_rl32(s->pb);
108 ✗ if (st->codecpar->ch_layout.nb_channels <= 0 ||
109 ✗ st->codecpar->ch_layout.nb_channels > INT_MAX / 0x20)
110 ✗ return AVERROR_INVALIDDATA;
111 ✗ st->codecpar->sample_rate = avio_rl32(s->pb);
112 ✗ st->codecpar->block_align = 0x20 * st->codecpar->ch_layout.nb_channels;
113 ✗ break;
114 ✗ case MKTAG('X', 'E', '_', '_'):
115 ✗ st->codecpar->codec_id = AV_CODEC_ID_ADPCM_IMA_DAT4;
116 ✗ st->codecpar->ch_layout.nb_channels = 2;
117 ✗ st->codecpar->sample_rate = 32000;
118 ✗ st->codecpar->block_align = 0x20 * st->codecpar->ch_layout.nb_channels;
119 ✗ break;
120 ✗ case MKTAG('P', 'S', 'P', '_'):
121 ✗ st->codecpar->codec_id = AV_CODEC_ID_ADPCM_PSX;
122 ✗ st->codecpar->ch_layout.nb_channels = 2;
123 ✗ st->codecpar->sample_rate = 32768;
124 ✗ st->codecpar->block_align = 0x80 * st->codecpar->ch_layout.nb_channels;
125 ✗ break;
126 ✗ case MKTAG('P', 'S', '2', '_'):
127 ✗ st->codecpar->codec_id = AV_CODEC_ID_ADPCM_PSX;
128 ✗ st->codecpar->ch_layout.nb_channels = 2;
129 ✗ st->codecpar->sample_rate = 32000;
130 ✗ st->codecpar->block_align = 0x80 * st->codecpar->ch_layout.nb_channels;
131 ✗ break;
132 ✗ default:
133 ✗ avpriv_request_sample(s, "Unsupported type: %X", type);
134 ✗ return AVERROR_PATCHWELCOME;
135 }
136 ✗ } else if (version == 6 || version == 5 || version == 4) {
137 ✗ type = avio_rl32(s->pb);
138 ✗ avio_skip(s->pb, 20);
139 ✗ st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
140 ✗ st->codecpar->ch_layout.nb_channels = 2;
141 ✗ switch (type) {
142 ✗ case MKTAG('G', 'C', '_', '_'):
143 ✗ st->codecpar->codec_id = AV_CODEC_ID_ADPCM_IMA_DAT4;
144 ✗ st->codecpar->block_align = 0x20 * st->codecpar->ch_layout.nb_channels;
145 ✗ st->codecpar->sample_rate = 32000;
146 ✗ offset = avio_rb32(s->pb);
147 ✗ break;
148 ✗ case MKTAG('P', 'S', '2', '_'):
149 ✗ st->codecpar->codec_id = AV_CODEC_ID_ADPCM_PSX;
150 ✗ st->codecpar->block_align = 0x80 * st->codecpar->ch_layout.nb_channels;
151 ✗ st->codecpar->sample_rate = 32000;
152 ✗ offset = avio_rl32(s->pb);
153 ✗ break;
154 ✗ case MKTAG('X', 'B', '_', '_'):
155 ✗ st->codecpar->codec_id = AV_CODEC_ID_ADPCM_IMA_DAT4;
156 ✗ st->codecpar->block_align = 0x20 * st->codecpar->ch_layout.nb_channels;
157 ✗ st->codecpar->sample_rate = 44100;
158 ✗ offset = avio_rl32(s->pb);
159 ✗ break;
160 ✗ default:
161 ✗ avpriv_request_sample(s, "Unsupported type: %X", type);
162 ✗ return AVERROR_PATCHWELCOME;
163 }
164 } else {
165 ✗ av_assert0(0);
166 }
167
168 ✗ avio_seek(s->pb, offset, SEEK_SET);
169
170 ✗ avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
171
172 ✗ return 0;
173 }
174
175 ✗ static int musx_read_packet(AVFormatContext *s, AVPacket *pkt)
176 {
177 ✗ AVCodecParameters *par = s->streams[0]->codecpar;
178
179 ✗ return av_get_packet(s->pb, pkt, par->block_align);
180 }
181
182 const FFInputFormat ff_musx_demuxer = {
183 .p.name = "musx",
184 .p.long_name = NULL_IF_CONFIG_SMALL("Eurocom MUSX"),
185 .p.extensions = "musx",
186 .read_probe = musx_probe,
187 .read_header = musx_read_header,
188 .read_packet = musx_read_packet,
189 };
190