FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/sdns.c
Date: 2024-05-04 02:01:39
Exec Total Coverage
Lines: 3 41 7.3%
Functions: 1 3 33.3%
Branches: 1 22 4.5%

Line Branch Exec Source
1 /*
2 * SDNS demuxer
3 * Copyright (c) 2023 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/channel_layout.h"
23 #include "libavutil/intreadwrite.h"
24 #include "avformat.h"
25 #include "demux.h"
26 #include "internal.h"
27
28 7128 static int sdns_probe(const AVProbeData *p)
29 {
30
1/2
✓ Branch 0 taken 7128 times.
✗ Branch 1 not taken.
7128 if (AV_RL32(p->buf) != MKTAG('S','D','N','S'))
31 7128 return 0;
32 if (AV_RB32(p->buf + 8) <= 0)
33 return 0;
34 if (AV_RB32(p->buf + 12) <= 0 ||
35 AV_RB32(p->buf + 12) > 128)
36 return 0;
37 return AVPROBE_SCORE_MAX / 3;
38 }
39
40 static int sdns_read_header(AVFormatContext *s)
41 {
42 AVIOContext *pb = s->pb;
43 AVCodecParameters *par;
44 int channels, ret;
45 AVStream *st;
46
47 avio_skip(pb, 8);
48
49 st = avformat_new_stream(s, NULL);
50 if (!st)
51 return AVERROR(ENOMEM);
52
53 par = st->codecpar;
54 par->codec_type = AVMEDIA_TYPE_AUDIO;
55 par->codec_id = AV_CODEC_ID_XMA1;
56 par->sample_rate = avio_rb32(pb);
57 channels = avio_rb32(pb);
58 if (channels <= 0 || channels > 128)
59 return AVERROR_INVALIDDATA;
60 av_channel_layout_default(&par->ch_layout, channels);
61 if (par->sample_rate <= 0)
62 return AVERROR_INVALIDDATA;
63 par->block_align = 2048;
64 if ((ret = ff_alloc_extradata(par, 8 + 20 * ((channels + 1) / 2))) < 0)
65 return ret;
66 memset(par->extradata, 0, 28);
67 par->extradata[4] = (channels + 1) / 2;
68 for (int i = 0; i < par->extradata[4]; i++)
69 par->extradata[8 + 20 * i + 17] = FFMIN(2, channels - i * 2);
70 avpriv_set_pts_info(st, 64, 1, par->sample_rate);
71 avio_seek(pb, 0x1000, SEEK_SET);
72
73 return 0;
74 }
75
76 static int sdns_read_packet(AVFormatContext *s, AVPacket *pkt)
77 {
78 int ret;
79
80 if (avio_feof(s->pb))
81 return AVERROR_EOF;
82 ret = av_get_packet(s->pb, pkt, 2048);
83 pkt->stream_index = 0;
84
85 return ret;
86 }
87
88 const FFInputFormat ff_sdns_demuxer = {
89 .p.name = "sdns",
90 .p.long_name = NULL_IF_CONFIG_SMALL("Xbox SDNS"),
91 .p.flags = AVFMT_GENERIC_INDEX,
92 .p.extensions = "sdns",
93 .read_probe = sdns_probe,
94 .read_header = sdns_read_header,
95 .read_packet = sdns_read_packet,
96 };
97