FFmpeg
Loading...
Searching...
No Matches
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 "config_components.h"
25
26#include "avformat.h"
27#include "avio_internal.h"
28#include "demux.h"
29#include "internal.h"
30#include "rawdec.h"
32#include "libavcodec/mlp.h"
34
35static int av_always_inline mlp_thd_probe(const AVProbeData *p, uint32_t sync)
36{
37 const uint8_t *buf, *last_buf = p->buf, *end = p->buf + p->buf_size;
38 int valid = 0, size = 0;
39 int nsubframes = 0;
40
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;
45 }
46 nsubframes = 0;
47 last_buf = buf;
48 size = (AV_RB16(buf) & 0xfff) * 2;
49 } else if (buf - last_buf == size) {
50 nsubframes++;
51 size += (AV_RB16(buf) & 0xfff) * 2;
52 }
53 }
54 if (valid >= 100)
55 return AVPROBE_SCORE_MAX;
56 return 0;
57}
58
60{
61 int ret = ff_raw_audio_read_header(s);
62
63 if (ret < 0)
64 return ret;
65
66 ret = ffio_ensure_seekback(s->pb, 10);
67 if (ret == 0) {
68 uint8_t buffer[10];
69 int read, sample_rate = 0;
70
71 read = avio_read(s->pb, buffer, 10);
72 if (read == 10) {
73 switch (buffer[7]) {
74 case SYNC_TRUEHD:
75 sample_rate = mlp_samplerate(buffer[8] >> 4);
76 break;
77 case SYNC_MLP:
78 sample_rate = mlp_samplerate(buffer[9] >> 4);
79 break;
80 }
81
82 if (sample_rate)
83 avpriv_set_pts_info(s->streams[0], 64, 1, sample_rate);
84 }
85
86 if (read > 0)
87 avio_seek(s->pb, -read, SEEK_CUR);
88 }
89
90 return 0;
91}
92
93#if CONFIG_MLP_DEMUXER
94static int mlp_probe(const AVProbeData *p)
95{
96 return mlp_thd_probe(p, 0xf8726fbb);
97}
98
100 .p.name = "mlp",
101 .p.long_name = NULL_IF_CONFIG_SMALL("raw MLP"),
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),
110};
111#endif
112
113#if CONFIG_TRUEHD_DEMUXER
114static int thd_probe(const AVProbeData *p)
115{
116 return mlp_thd_probe(p, 0xf8726fba);
117}
118
120 .p.name = "truehd",
121 .p.long_name = NULL_IF_CONFIG_SMALL("raw TrueHD"),
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),
130};
131#endif
const FFInputFormat ff_truehd_demuxer
const FFInputFormat ff_mlp_demuxer
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition avformat.c:834
Main libavformat public API header.
#define AVPROBE_SCORE_MAX
maximum score
Definition avformat.h:483
#define AVFMT_GENERIC_INDEX
Use generic index building code.
Definition avformat.h:499
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition avformat.h:498
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition aviobuf.c:236
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition aviobuf.c:615
int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)
Ensures that the requested seekback buffer size will be available.
Definition aviobuf.c:1026
static uint32_t BS_FUNC read(BSCTX *bc, unsigned int n)
Return n bits from the buffer, n has to be in the 0-32 range.
#define s(width, name)
Definition cbs_vp9.c:198
@ AV_CODEC_ID_TRUEHD
Definition codec_id.h:497
@ AV_CODEC_ID_MLP
Definition codec_id.h:482
#define AV_RB32(p)
#define AV_RB16(p)
static int av_always_inline mlp_thd_probe(const AVProbeData *p, uint32_t sync)
Definition mlpdec.c:35
static int mlp_read_header(AVFormatContext *s)
Definition mlpdec.c:59
const AVClass ff_raw_demuxer_class
Definition rawdec.c:141
int ff_raw_audio_read_header(AVFormatContext *s)
Definition rawdec.c:54
int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
Definition rawdec.c:33
#define av_always_inline
Definition attributes.h:72
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
#define SYNC_TRUEHD
Definition mlp.h:30
#define SYNC_MLP
Definition mlp.h:29
static int mlp_samplerate(int in)
Definition mlp_parse.h:87
Format I/O context.
Definition avformat.h:1333
This structure contains the data a format has to probe a file.
Definition avformat.h:471
static char buffer[20]
Definition seek.c:32
int size