FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/ac3dec.c
Date: 2022-12-05 20:26:17
Exec Total Coverage
Lines: 49 51 96.1%
Functions: 3 3 100.0%
Branches: 49 54 90.7%

Line Branch Exec Source
1 /*
2 * RAW AC-3 and E-AC-3 demuxer
3 * Copyright (c) 2007 Justin Ruggles <justin.ruggles@gmail.com>
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 "config_components.h"
23
24 #include "libavutil/avassert.h"
25 #include "libavutil/crc.h"
26 #include "libavcodec/ac3_parser.h"
27 #include "avformat.h"
28 #include "rawdec.h"
29
30 13564 static int ac3_eac3_probe(const AVProbeData *p, enum AVCodecID expected_codec_id)
31 {
32 13564 int max_frames, first_frames = 0, frames;
33 const uint8_t *buf, *buf2, *end;
34 13564 enum AVCodecID codec_id = AV_CODEC_ID_AC3;
35
36 13564 max_frames = 0;
37 13564 buf = p->buf;
38 13564 end = buf + p->buf_size;
39
40
2/2
✓ Branch 0 taken 278778568 times.
✓ Branch 1 taken 13564 times.
278792132 for(; buf < end; buf++) {
41
6/6
✓ Branch 0 taken 278765004 times.
✓ Branch 1 taken 13564 times.
✓ Branch 2 taken 1684166 times.
✓ Branch 3 taken 277080838 times.
✓ Branch 4 taken 1680250 times.
✓ Branch 5 taken 3916 times.
278778568 if(buf > p->buf && !(buf[0] == 0x0B && buf[1] == 0x77)
42
4/4
✓ Branch 0 taken 506090 times.
✓ Branch 1 taken 278254998 times.
✓ Branch 2 taken 500206 times.
✓ Branch 3 taken 5884 times.
278761088 && !(buf[0] == 0x77 && buf[1] == 0x0B) )
43 278755204 continue;
44 23364 buf2 = buf;
45
46
2/2
✓ Branch 0 taken 112536 times.
✓ Branch 1 taken 104 times.
112640 for(frames = 0; buf2 < end; frames++) {
47 uint8_t buf3[4096];
48 uint8_t bitstream_id;
49 uint16_t frame_size;
50 int i, ret;
51
52
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 112536 times.
112536 if(!memcmp(buf2, "\x1\x10", 2)) {
53 if (buf2 + 16 > end)
54 23260 break;
55 buf2+=16;
56 }
57
4/4
✓ Branch 0 taken 5968 times.
✓ Branch 1 taken 106568 times.
✓ Branch 2 taken 5900 times.
✓ Branch 3 taken 68 times.
112536 if (buf[0] == 0x77 && buf[1] == 0x0B) {
58
2/2
✓ Branch 0 taken 23600 times.
✓ Branch 1 taken 5900 times.
29500 for(i=0; i<8; i+=2) {
59 23600 buf3[i ] = buf2[i+1];
60 23600 buf3[i+1] = buf2[i ];
61 }
62 5900 ret = av_ac3_parse_header(buf3, 8, &bitstream_id,
63 &frame_size);
64 }else
65 106636 ret = av_ac3_parse_header(buf2, end - buf2, &bitstream_id,
66 &frame_size);
67
2/2
✓ Branch 0 taken 16834 times.
✓ Branch 1 taken 95702 times.
112536 if (ret < 0)
68 16834 break;
69
2/2
✓ Branch 0 taken 1724 times.
✓ Branch 1 taken 93978 times.
95702 if(buf2 + frame_size > end)
70 1724 break;
71
3/4
✓ Branch 0 taken 3694 times.
✓ Branch 1 taken 90284 times.
✓ Branch 2 taken 3694 times.
✗ Branch 3 not taken.
93978 if (buf[0] == 0x77 && buf[1] == 0x0B) {
72
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3694 times.
3694 av_assert0(frame_size <= sizeof(buf3));
73
2/2
✓ Branch 0 taken 2083800 times.
✓ Branch 1 taken 3694 times.
2087494 for(i = 8; i < frame_size; i += 2) {
74 2083800 buf3[i ] = buf2[i+1];
75 2083800 buf3[i+1] = buf2[i ];
76 }
77
2/2
✓ Branch 1 taken 3678 times.
✓ Branch 2 taken 16 times.
3694 if (av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, buf3 + 2, frame_size - 2))
78 3678 break;
79 } else {
80
2/2
✓ Branch 1 taken 1024 times.
✓ Branch 2 taken 89260 times.
90284 if (av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, buf2 + 2, frame_size - 2))
81 1024 break;
82 }
83
2/2
✓ Branch 0 taken 87438 times.
✓ Branch 1 taken 1838 times.
89276 if (bitstream_id > 10)
84 87438 codec_id = AV_CODEC_ID_EAC3;
85 89276 buf2 += frame_size;
86 }
87 23364 max_frames = FFMAX(max_frames, frames);
88
2/2
✓ Branch 0 taken 13564 times.
✓ Branch 1 taken 9800 times.
23364 if(buf == p->buf)
89 13564 first_frames = frames;
90 }
91
2/2
✓ Branch 0 taken 6782 times.
✓ Branch 1 taken 6782 times.
13564 if(codec_id != expected_codec_id) return 0;
92 // keep this in sync with mp3 probe, both need to avoid
93 // issues with MPEG-files!
94
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 6762 times.
6782 if (first_frames>=7) return AVPROBE_SCORE_EXTENSION + 1;
95
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6761 times.
6762 else if(max_frames>200)return AVPROBE_SCORE_EXTENSION;
96
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 6739 times.
6761 else if(max_frames>=4) return AVPROBE_SCORE_EXTENSION/2;
97
2/2
✓ Branch 0 taken 45 times.
✓ Branch 1 taken 6694 times.
6739 else if(max_frames>=1) return 1;
98 6694 else return 0;
99 }
100
101 #if CONFIG_AC3_DEMUXER
102 6782 static int ac3_probe(const AVProbeData *p)
103 {
104 6782 return ac3_eac3_probe(p, AV_CODEC_ID_AC3);
105 }
106
107 const AVInputFormat ff_ac3_demuxer = {
108 .name = "ac3",
109 .long_name = NULL_IF_CONFIG_SMALL("raw AC-3"),
110 .read_probe = ac3_probe,
111 .read_header = ff_raw_audio_read_header,
112 .read_packet = ff_raw_read_partial_packet,
113 .flags= AVFMT_GENERIC_INDEX,
114 .extensions = "ac3",
115 .raw_codec_id = AV_CODEC_ID_AC3,
116 .priv_data_size = sizeof(FFRawDemuxerContext),
117 .priv_class = &ff_raw_demuxer_class,
118 };
119 #endif
120
121 #if CONFIG_EAC3_DEMUXER
122 6782 static int eac3_probe(const AVProbeData *p)
123 {
124 6782 return ac3_eac3_probe(p, AV_CODEC_ID_EAC3);
125 }
126
127 const AVInputFormat ff_eac3_demuxer = {
128 .name = "eac3",
129 .long_name = NULL_IF_CONFIG_SMALL("raw E-AC-3"),
130 .read_probe = eac3_probe,
131 .read_header = ff_raw_audio_read_header,
132 .read_packet = ff_raw_read_partial_packet,
133 .flags = AVFMT_GENERIC_INDEX,
134 .extensions = "eac3,ec3",
135 .raw_codec_id = AV_CODEC_ID_EAC3,
136 .priv_data_size = sizeof(FFRawDemuxerContext),
137 .priv_class = &ff_raw_demuxer_class,
138 };
139 #endif
140