FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/ac4dec.c
Date: 2024-02-16 17:37:06
Exec Total Coverage
Lines: 7 40 17.5%
Functions: 1 3 33.3%
Branches: 2 20 10.0%

Line Branch Exec Source
1 /*
2 * RAW AC-4 demuxer
3 * Copyright (c) 2019 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/crc.h"
24 #include "avformat.h"
25 #include "rawdec.h"
26
27 7023 static int ac4_probe(const AVProbeData *p)
28 {
29 7023 const uint8_t *buf = p->buf;
30 7023 int left = p->buf_size;
31 7023 int max_frames = 0;
32
33
1/2
✓ Branch 0 taken 7023 times.
✗ Branch 1 not taken.
7023 while (left > 7) {
34 int size;
35
36
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7023 times.
7023 if (buf[0] == 0xAC &&
37 (buf[1] == 0x40 ||
38 buf[1] == 0x41)) {
39 size = (buf[2] << 8) | buf[3];
40 if (size == 0xFFFF)
41 size = 3 + ((buf[4] << 16) | (buf[5] << 8) | buf[6]);
42 size += 4;
43 if (buf[1] == 0x41)
44 size += 2;
45 max_frames++;
46 left -= size;
47 buf += size;
48 } else {
49 break;
50 }
51 }
52
53 7023 return FFMIN(AVPROBE_SCORE_MAX, max_frames * 7);
54 }
55
56 static int ac4_read_header(AVFormatContext *s)
57 {
58 AVStream *st;
59
60 st = avformat_new_stream(s, NULL);
61 if (!st)
62 return AVERROR(ENOMEM);
63
64 st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
65 st->codecpar->codec_id = AV_CODEC_ID_AC4;
66
67 return 0;
68 }
69
70 static int ac4_read_packet(AVFormatContext *s, AVPacket *pkt)
71 {
72 AVIOContext *pb = s->pb;
73 int64_t pos;
74 uint16_t sync;
75 int ret, size;
76
77 if (avio_feof(s->pb))
78 return AVERROR_EOF;
79
80 pos = avio_tell(s->pb);
81 sync = avio_rb16(pb);
82 size = avio_rb16(pb);
83 if (size == 0xffff)
84 size = avio_rb24(pb);
85
86 ret = av_get_packet(pb, pkt, size);
87 pkt->pos = pos;
88 pkt->stream_index = 0;
89
90 if (sync == 0xAC41)
91 avio_skip(pb, 2);
92
93 return ret;
94 }
95
96 const AVInputFormat ff_ac4_demuxer = {
97 .name = "ac4",
98 .long_name = NULL_IF_CONFIG_SMALL("raw AC-4"),
99 .read_probe = ac4_probe,
100 .read_header = ac4_read_header,
101 .read_packet = ac4_read_packet,
102 .flags = AVFMT_GENERIC_INDEX,
103 .extensions = "ac4",
104 };
105