FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/avr.c
Date: 2024-03-28 14:59:00
Exec Total Coverage
Lines: 3 35 8.6%
Functions: 1 2 50.0%
Branches: 1 18 5.6%

Line Branch Exec Source
1 /*
2 * AVR demuxer
3 * Copyright (c) 2012 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/intreadwrite.h"
23 #include "avformat.h"
24 #include "demux.h"
25 #include "internal.h"
26 #include "pcm.h"
27
28 7124 static int avr_probe(const AVProbeData *p)
29 {
30
1/2
✓ Branch 0 taken 7124 times.
✗ Branch 1 not taken.
7124 if (AV_RL32(p->buf) != MKTAG('2', 'B', 'I', 'T'))
31 7124 return 0;
32
33 if (!AV_RB16(p->buf+12) || AV_RB16(p->buf+12) > 256) // channels
34 return AVPROBE_SCORE_EXTENSION/2;
35 if (AV_RB16(p->buf+14) > 256) // bps
36 return AVPROBE_SCORE_EXTENSION/2;
37
38 return AVPROBE_SCORE_EXTENSION;
39 }
40
41 static int avr_read_header(AVFormatContext *s)
42 {
43 uint16_t chan, sign, bps;
44 AVStream *st;
45
46 st = avformat_new_stream(s, NULL);
47 if (!st)
48 return AVERROR(ENOMEM);
49
50 st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
51
52 avio_skip(s->pb, 4 /* magic */ + 8 /* sample_name */);
53
54 chan = avio_rb16(s->pb);
55 if (!chan) {
56 st->codecpar->ch_layout.nb_channels = 1;
57 } else if (chan == 0xFFFFu) {
58 st->codecpar->ch_layout.nb_channels = 2;
59 } else {
60 avpriv_request_sample(s, "chan %d", chan);
61 return AVERROR_PATCHWELCOME;
62 }
63
64 st->codecpar->bits_per_coded_sample = bps = avio_rb16(s->pb);
65
66 sign = avio_rb16(s->pb);
67
68 avio_skip(s->pb, 2 /* loop */ + 2 /* midi */ + 1 /* replay speed */);
69
70 st->codecpar->sample_rate = avio_rb24(s->pb);
71 if (st->codecpar->sample_rate == 0)
72 return AVERROR_INVALIDDATA;
73
74 avio_skip(s->pb, 4 * 3 + 2 * 3 + 20 + 64);
75
76 st->codecpar->codec_id = ff_get_pcm_codec_id(bps, 0, 1, sign);
77 if (st->codecpar->codec_id == AV_CODEC_ID_NONE) {
78 avpriv_request_sample(s, "Bps %d and sign %d", bps, sign);
79 return AVERROR_PATCHWELCOME;
80 }
81
82 st->codecpar->block_align = bps * st->codecpar->ch_layout.nb_channels / 8;
83
84 avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
85 return 0;
86 }
87
88 const FFInputFormat ff_avr_demuxer = {
89 .p.name = "avr",
90 .p.long_name = NULL_IF_CONFIG_SMALL("AVR (Audio Visual Research)"),
91 .p.extensions = "avr",
92 .p.flags = AVFMT_GENERIC_INDEX,
93 .read_probe = avr_probe,
94 .read_header = avr_read_header,
95 .read_packet = ff_pcm_read_packet,
96 .read_seek = ff_pcm_read_seek,
97 };
98