FFmpeg
mlpdec.c
Go to the documentation of this file.
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 "avformat.h"
25 #include "rawdec.h"
26 #include "libavutil/intreadwrite.h"
27 
28 static int av_always_inline mlp_thd_probe(const AVProbeData *p, uint32_t sync)
29 {
30  const uint8_t *buf, *last_buf = p->buf, *end = p->buf + p->buf_size;
31  int frames = 0, valid = 0, size = 0;
32  int nsubframes = 0;
33 
34  for (buf = p->buf; buf + 8 <= end; buf++) {
35  if (AV_RB32(buf + 4) == sync) {
36  frames++;
37  if (last_buf + size == buf) {
38  valid += 1 + nsubframes / 8;
39  }
40  nsubframes = 0;
41  last_buf = buf;
42  size = (AV_RB16(buf) & 0xfff) * 2;
43  } else if (buf - last_buf == size) {
44  nsubframes++;
45  size += (AV_RB16(buf) & 0xfff) * 2;
46  }
47  }
48  if (valid >= 100)
49  return AVPROBE_SCORE_MAX;
50  return 0;
51 }
52 
53 #if CONFIG_MLP_DEMUXER
54 static int mlp_probe(const AVProbeData *p)
55 {
56  return mlp_thd_probe(p, 0xf8726fbb);
57 }
58 
61  .name = "mlp",
62  .long_name = NULL_IF_CONFIG_SMALL("raw MLP"),
63  .read_probe = mlp_probe,
64  .read_header = ff_raw_audio_read_header,
65  .read_packet = ff_raw_read_partial_packet,
67  .extensions = "mlp",
68  .raw_codec_id = AV_CODEC_ID_MLP,
69  .priv_data_size = sizeof(FFRawDemuxerContext),
70  .priv_class = &mlp_demuxer_class,
71 };
72 #endif
73 
74 #if CONFIG_TRUEHD_DEMUXER
75 static int thd_probe(const AVProbeData *p)
76 {
77  return mlp_thd_probe(p, 0xf8726fba);
78 }
79 
82  .name = "truehd",
83  .long_name = NULL_IF_CONFIG_SMALL("raw TrueHD"),
84  .read_probe = thd_probe,
85  .read_header = ff_raw_audio_read_header,
86  .read_packet = ff_raw_read_partial_packet,
88  .extensions = "thd",
89  .raw_codec_id = AV_CODEC_ID_TRUEHD,
90  .priv_data_size = sizeof(FFRawDemuxerContext),
91  .priv_class = &truehd_demuxer_class,
92 };
93 #endif
94 
AVFMT_NOTIMESTAMPS
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition: avformat.h:462
mlp_thd_probe
static int av_always_inline mlp_thd_probe(const AVProbeData *p, uint32_t sync)
Definition: mlpdec.c:28
AVProbeData::buf_size
int buf_size
Size of buf except extra allocated bytes.
Definition: avformat.h:444
AV_CODEC_ID_TRUEHD
@ AV_CODEC_ID_TRUEHD
Definition: codec_id.h:468
AVPROBE_SCORE_MAX
#define AVPROBE_SCORE_MAX
maximum score
Definition: avformat.h:453
frames
if it could not because there are no more frames
Definition: filter_design.txt:266
FFRawDemuxerContext
Definition: rawdec.h:37
AVFMT_GENERIC_INDEX
#define AVFMT_GENERIC_INDEX
Use generic index building code.
Definition: avformat.h:463
AVInputFormat
Definition: avformat.h:640
ff_raw_read_partial_packet
int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
Definition: rawdec.c:35
intreadwrite.h
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:645
AVProbeData::buf
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:443
ff_mlp_demuxer
AVInputFormat ff_mlp_demuxer
rawdec.h
ff_raw_audio_read_header
int ff_raw_audio_read_header(AVFormatContext *s)
Definition: rawdec.c:56
AVProbeData
This structure contains the data a format has to probe a file.
Definition: avformat.h:441
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
size
int size
Definition: twinvq_data.h:10344
AV_RB32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
Definition: bytestream.h:96
ff_truehd_demuxer
AVInputFormat ff_truehd_demuxer
av_always_inline
#define av_always_inline
Definition: attributes.h:49
uint8_t
uint8_t
Definition: audio_convert.c:194
avformat.h
AV_CODEC_ID_MLP
@ AV_CODEC_ID_MLP
Definition: codec_id.h:453
AV_RB16
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16
Definition: bytestream.h:98
FF_RAW_DEMUXER_CLASS
#define FF_RAW_DEMUXER_CLASS(name)
Definition: rawdec.h:55