FFmpeg coverage


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