2 * MLP and TrueHD demuxer
3 * Copyright (c) 2001 Fabrice Bellard
4 * Copyright (c) 2005 Alex Beregszaszi
5 * Copyright (c) 2015 Carl Eugen Hoyos
7 * This file is part of FFmpeg.
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.
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.
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
24 #include "config_components.h"
27 #include "avio_internal.h"
31 #include "libavutil/intreadwrite.h"
32 #include "libavcodec/mlp.h"
33 #include "libavcodec/mlp_parse.h"
35 static int av_always_inline
mlp_thd_probe(const AVProbeData
*p
, uint32_t sync
)
37 const uint8_t *buf
, *last_buf
= p
->buf
, *end
= p
->buf
+ p
->buf_size
;
38 int valid
= 0, size
= 0;
41 for (buf
= p
->buf
; buf
+ 8 <= end
; buf
++) {
42 if (AV_RB32(buf
+ 4) == sync
) {
43 if (last_buf
+ size
== buf
) {
44 valid
+= 1 + nsubframes
/ 8;
48 size
= (AV_RB16(buf
) & 0xfff) * 2;
49 } else if (buf
- last_buf
== size
) {
51 size
+= (AV_RB16(buf
) & 0xfff) * 2;
55 return AVPROBE_SCORE_MAX
;
59 static int mlp_read_header(AVFormatContext
*s
)
61 int ret
= ff_raw_audio_read_header(s
);
66 ret
= ffio_ensure_seekback(s
->pb
, 10);
69 int read
, sample_rate
= 0;
71 read
= avio_read(s
->pb
, buffer
, 10);
75 sample_rate
= mlp_samplerate(buffer
[8] >> 4);
78 sample_rate
= mlp_samplerate(buffer
[9] >> 4);
83 avpriv_set_pts_info(s
->streams
[0], 64, 1, sample_rate
);
87 avio_seek(s
->pb
, -read
, SEEK_CUR
);
93 #if CONFIG_MLP_DEMUXER
94 static int mlp_probe(const AVProbeData
*p
)
96 return mlp_thd_probe(p
, 0xf8726fbb);
99 const FFInputFormat ff_mlp_demuxer
= {
101 .p
.long_name
= NULL_IF_CONFIG_SMALL("raw MLP"),
102 .p
.flags
= AVFMT_GENERIC_INDEX
| AVFMT_NOTIMESTAMPS
,
103 .p
.extensions
= "mlp",
104 .p
.priv_class
= &ff_raw_demuxer_class
,
105 .read_probe
= mlp_probe
,
106 .read_header
= mlp_read_header
,
107 .read_packet
= ff_raw_read_partial_packet
,
108 .raw_codec_id
= AV_CODEC_ID_MLP
,
109 .priv_data_size
= sizeof(FFRawDemuxerContext
),
113 #if CONFIG_TRUEHD_DEMUXER
114 static int thd_probe(const AVProbeData
*p
)
116 return mlp_thd_probe(p
, 0xf8726fba);
119 const FFInputFormat ff_truehd_demuxer
= {
121 .p
.long_name
= NULL_IF_CONFIG_SMALL("raw TrueHD"),
122 .p
.flags
= AVFMT_GENERIC_INDEX
| AVFMT_NOTIMESTAMPS
,
123 .p
.extensions
= "thd",
124 .p
.priv_class
= &ff_raw_demuxer_class
,
125 .read_probe
= thd_probe
,
126 .read_header
= mlp_read_header
,
127 .read_packet
= ff_raw_read_partial_packet
,
128 .raw_codec_id
= AV_CODEC_ID_TRUEHD
,
129 .priv_data_size
= sizeof(FFRawDemuxerContext
),