FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/mlpdec.c
Date: 2022-11-26 13:19:19
Exec Total Coverage
Lines: 41 42 97.6%
Branches: 18 23 78.3%

Line Branch Exec Source
1 /*
2 * MLP and TrueHD demuxer
3 * Copyright (c) 2001 Fabrice Bellard
4 * Copyright (c) 2005 Alex Beregszaszi
5 * Copyright (c) 2015 Carl Eugen Hoyos
6 *
7 * This file is part of FFmpeg.
8 *
9 * FFmpeg is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * FFmpeg is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with FFmpeg; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24 #include "config_components.h"
25
26 #include "avformat.h"
27 #include "avio_internal.h"
28 #include "internal.h"
29 #include "rawdec.h"
30 #include "libavutil/intreadwrite.h"
31 #include "libavcodec/mlp.h"
32 #include "libavcodec/mlp_parse.h"
33
34 13560 static int av_always_inline mlp_thd_probe(const AVProbeData *p, uint32_t sync)
35 {
36 13560 const uint8_t *buf, *last_buf = p->buf, *end = p->buf + p->buf_size;
37 13560 int valid = 0, size = 0;
38 13560 int nsubframes = 0;
39
40
2/2
✓ Branch 0 taken 278671306 times.
✓ Branch 1 taken 13560 times.
278684866 for (buf = p->buf; buf + 8 <= end; buf++) {
41
2/2
✓ Branch 0 taken 752 times.
✓ Branch 1 taken 278670554 times.
278671306 if (AV_RB32(buf + 4) == sync) {
42
1/2
✓ Branch 0 taken 752 times.
✗ Branch 1 not taken.
752 if (last_buf + size == buf) {
43 752 valid += 1 + nsubframes / 8;
44 }
45 752 nsubframes = 0;
46 752 last_buf = buf;
47 752 size = (AV_RB16(buf) & 0xfff) * 2;
48
2/2
✓ Branch 0 taken 84292 times.
✓ Branch 1 taken 278586262 times.
278670554 } else if (buf - last_buf == size) {
49 84292 nsubframes++;
50 84292 size += (AV_RB16(buf) & 0xfff) * 2;
51 }
52 }
53
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 13558 times.
13560 if (valid >= 100)
54 2 return AVPROBE_SCORE_MAX;
55 13558 return 0;
56 }
57
58 9 static int mlp_read_header(AVFormatContext *s)
59 {
60 9 int ret = ff_raw_audio_read_header(s);
61
62
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (ret < 0)
63 return ret;
64
65 9 ret = ffio_ensure_seekback(s->pb, 10);
66
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (ret == 0) {
67 uint8_t buffer[10];
68 9 int read, sample_rate = 0;
69
70 9 read = avio_read(s->pb, buffer, 10);
71
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (read == 10) {
72
3/3
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 3 times.
9 switch (buffer[7]) {
73 4 case SYNC_TRUEHD:
74 4 sample_rate = mlp_samplerate(buffer[8] >> 4);
75 4 break;
76 2 case SYNC_MLP:
77 2 sample_rate = mlp_samplerate(buffer[9] >> 4);
78 2 break;
79 }
80
81
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
9 if (sample_rate)
82 6 avpriv_set_pts_info(s->streams[0], 64, 1, sample_rate);
83 }
84
85
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (read > 0)
86 9 avio_seek(s->pb, -read, SEEK_CUR);
87 }
88
89 9 return 0;
90 }
91
92 #if CONFIG_MLP_DEMUXER
93 6780 static int mlp_probe(const AVProbeData *p)
94 {
95 6780 return mlp_thd_probe(p, 0xf8726fbb);
96 }
97
98 const AVInputFormat ff_mlp_demuxer = {
99 .name = "mlp",
100 .long_name = NULL_IF_CONFIG_SMALL("raw MLP"),
101 .read_probe = mlp_probe,
102 .read_header = mlp_read_header,
103 .read_packet = ff_raw_read_partial_packet,
104 .flags = AVFMT_GENERIC_INDEX | AVFMT_NOTIMESTAMPS,
105 .extensions = "mlp",
106 .raw_codec_id = AV_CODEC_ID_MLP,
107 .priv_data_size = sizeof(FFRawDemuxerContext),
108 .priv_class = &ff_raw_demuxer_class,
109 };
110 #endif
111
112 #if CONFIG_TRUEHD_DEMUXER
113 6780 static int thd_probe(const AVProbeData *p)
114 {
115 6780 return mlp_thd_probe(p, 0xf8726fba);
116 }
117
118 const AVInputFormat ff_truehd_demuxer = {
119 .name = "truehd",
120 .long_name = NULL_IF_CONFIG_SMALL("raw TrueHD"),
121 .read_probe = thd_probe,
122 .read_header = mlp_read_header,
123 .read_packet = ff_raw_read_partial_packet,
124 .flags = AVFMT_GENERIC_INDEX | AVFMT_NOTIMESTAMPS,
125 .extensions = "thd",
126 .raw_codec_id = AV_CODEC_ID_TRUEHD,
127 .priv_data_size = sizeof(FFRawDemuxerContext),
128 .priv_class = &ff_raw_demuxer_class,
129 };
130 #endif
131