FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/sdxdec.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 3 39 7.7%
Functions: 1 2 50.0%
Branches: 1 15 6.7%

Line Branch Exec Source
1 /*
2 * SDX demuxer
3 * Copyright (c) 2017 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/avstring.h"
23 #include "libavutil/intreadwrite.h"
24 #include "avformat.h"
25 #include "demux.h"
26 #include "internal.h"
27 #include "pcm.h"
28
29 7186 static int sdx_probe(const AVProbeData *p)
30 {
31
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7186 times.
7186 if (AV_RB32(p->buf) == AV_RB32("SDX:"))
32 return AVPROBE_SCORE_EXTENSION;
33 7186 return 0;
34 }
35
36 static int sdx_read_header(AVFormatContext *s)
37 {
38 AVStream *st;
39 int depth, length;
40
41 avio_skip(s->pb, 4);
42 while (!avio_feof(s->pb)) {
43 if (avio_r8(s->pb) == 0x1a)
44 break;
45 }
46 if (avio_r8(s->pb) != 1)
47 return AVERROR_INVALIDDATA;
48 length = avio_r8(s->pb);
49 avio_skip(s->pb, length);
50 avio_skip(s->pb, 4);
51 depth = avio_r8(s->pb);
52
53 st = avformat_new_stream(s, NULL);
54 if (!st)
55 return AVERROR(ENOMEM);
56
57 st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
58 st->codecpar->ch_layout.nb_channels = 1;
59 st->codecpar->sample_rate = avio_rl32(s->pb);
60 switch (depth) {
61 case 8:
62 st->codecpar->codec_id = AV_CODEC_ID_PCM_U8;
63 break;
64 case 16:
65 st->codecpar->codec_id = AV_CODEC_ID_PCM_U16LE;
66 break;
67 case 24:
68 st->codecpar->codec_id = AV_CODEC_ID_PCM_U24LE;
69 break;
70 case 32:
71 st->codecpar->codec_id = AV_CODEC_ID_PCM_U32LE;
72 break;
73 default:
74 return AVERROR_INVALIDDATA;
75 }
76 avio_skip(s->pb, 16);
77 st->codecpar->block_align = depth / 8;
78
79 return 0;
80 }
81
82 const FFInputFormat ff_sdx_demuxer = {
83 .p.name = "sdx",
84 .p.long_name = NULL_IF_CONFIG_SMALL("Sample Dump eXchange"),
85 .p.extensions = "sdx",
86 .p.flags = AVFMT_GENERIC_INDEX,
87 .read_probe = sdx_probe,
88 .read_header = sdx_read_header,
89 .read_packet = ff_pcm_read_packet,
90 .read_seek = ff_pcm_read_seek,
91 };
92