2015-10-03 22:40:27 +02:00
|
|
|
/*
|
|
|
|
* MLP and TrueHD demuxer
|
|
|
|
* Copyright (c) 2001 Fabrice Bellard
|
|
|
|
* Copyright (c) 2005 Alex Beregszaszi
|
|
|
|
* Copyright (c) 2015 Carl Eugen Hoyos
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2022-02-23 14:56:49 +02:00
|
|
|
#include "config_components.h"
|
|
|
|
|
2015-10-03 22:40:27 +02:00
|
|
|
#include "avformat.h"
|
2021-09-05 17:55:19 +02:00
|
|
|
#include "avio_internal.h"
|
2024-02-10 16:50:43 +02:00
|
|
|
#include "demux.h"
|
2021-09-05 17:55:19 +02:00
|
|
|
#include "internal.h"
|
2015-10-03 22:40:27 +02:00
|
|
|
#include "rawdec.h"
|
|
|
|
#include "libavutil/intreadwrite.h"
|
2021-09-05 17:55:19 +02:00
|
|
|
#include "libavcodec/mlp.h"
|
|
|
|
#include "libavcodec/mlp_parse.h"
|
2015-10-03 22:40:27 +02:00
|
|
|
|
2019-03-21 02:18:37 +02:00
|
|
|
static int av_always_inline mlp_thd_probe(const AVProbeData *p, uint32_t sync)
|
2015-10-03 22:40:27 +02:00
|
|
|
{
|
|
|
|
const uint8_t *buf, *last_buf = p->buf, *end = p->buf + p->buf_size;
|
2022-06-28 12:23:31 +02:00
|
|
|
int valid = 0, size = 0;
|
2015-11-17 01:28:58 +02:00
|
|
|
int nsubframes = 0;
|
2015-10-03 22:40:27 +02:00
|
|
|
|
|
|
|
for (buf = p->buf; buf + 8 <= end; buf++) {
|
|
|
|
if (AV_RB32(buf + 4) == sync) {
|
|
|
|
if (last_buf + size == buf) {
|
2015-11-17 01:28:58 +02:00
|
|
|
valid += 1 + nsubframes / 8;
|
2015-10-03 22:40:27 +02:00
|
|
|
}
|
2015-11-17 01:28:58 +02:00
|
|
|
nsubframes = 0;
|
2015-10-03 22:40:27 +02:00
|
|
|
last_buf = buf;
|
|
|
|
size = (AV_RB16(buf) & 0xfff) * 2;
|
|
|
|
} else if (buf - last_buf == size) {
|
2015-11-17 01:28:58 +02:00
|
|
|
nsubframes++;
|
2015-10-03 22:40:27 +02:00
|
|
|
size += (AV_RB16(buf) & 0xfff) * 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (valid >= 100)
|
|
|
|
return AVPROBE_SCORE_MAX;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-09-05 17:55:19 +02:00
|
|
|
static int mlp_read_header(AVFormatContext *s)
|
|
|
|
{
|
|
|
|
int ret = ff_raw_audio_read_header(s);
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = ffio_ensure_seekback(s->pb, 10);
|
|
|
|
if (ret == 0) {
|
|
|
|
uint8_t buffer[10];
|
|
|
|
int read, sample_rate = 0;
|
|
|
|
|
|
|
|
read = avio_read(s->pb, buffer, 10);
|
|
|
|
if (read == 10) {
|
|
|
|
switch (buffer[7]) {
|
|
|
|
case SYNC_TRUEHD:
|
|
|
|
sample_rate = mlp_samplerate(buffer[8] >> 4);
|
|
|
|
break;
|
|
|
|
case SYNC_MLP:
|
|
|
|
sample_rate = mlp_samplerate(buffer[9] >> 4);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sample_rate)
|
|
|
|
avpriv_set_pts_info(s->streams[0], 64, 1, sample_rate);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (read > 0)
|
|
|
|
avio_seek(s->pb, -read, SEEK_CUR);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-10-03 22:40:27 +02:00
|
|
|
#if CONFIG_MLP_DEMUXER
|
2019-03-21 02:18:37 +02:00
|
|
|
static int mlp_probe(const AVProbeData *p)
|
2015-10-03 22:40:27 +02:00
|
|
|
{
|
|
|
|
return mlp_thd_probe(p, 0xf8726fbb);
|
|
|
|
}
|
|
|
|
|
2024-02-10 16:50:43 +02:00
|
|
|
const FFInputFormat ff_mlp_demuxer = {
|
|
|
|
.p.name = "mlp",
|
|
|
|
.p.long_name = NULL_IF_CONFIG_SMALL("raw MLP"),
|
|
|
|
.p.flags = AVFMT_GENERIC_INDEX | AVFMT_NOTIMESTAMPS,
|
|
|
|
.p.extensions = "mlp",
|
|
|
|
.p.priv_class = &ff_raw_demuxer_class,
|
2015-10-03 22:40:27 +02:00
|
|
|
.read_probe = mlp_probe,
|
2021-09-05 17:55:19 +02:00
|
|
|
.read_header = mlp_read_header,
|
2015-10-03 22:40:27 +02:00
|
|
|
.read_packet = ff_raw_read_partial_packet,
|
|
|
|
.raw_codec_id = AV_CODEC_ID_MLP,
|
2019-07-06 11:32:48 +02:00
|
|
|
.priv_data_size = sizeof(FFRawDemuxerContext),
|
2015-10-03 22:40:27 +02:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CONFIG_TRUEHD_DEMUXER
|
2019-03-21 02:18:37 +02:00
|
|
|
static int thd_probe(const AVProbeData *p)
|
2015-10-03 22:40:27 +02:00
|
|
|
{
|
|
|
|
return mlp_thd_probe(p, 0xf8726fba);
|
|
|
|
}
|
|
|
|
|
2024-02-10 16:50:43 +02:00
|
|
|
const FFInputFormat ff_truehd_demuxer = {
|
|
|
|
.p.name = "truehd",
|
|
|
|
.p.long_name = NULL_IF_CONFIG_SMALL("raw TrueHD"),
|
|
|
|
.p.flags = AVFMT_GENERIC_INDEX | AVFMT_NOTIMESTAMPS,
|
|
|
|
.p.extensions = "thd",
|
|
|
|
.p.priv_class = &ff_raw_demuxer_class,
|
2015-10-03 22:40:27 +02:00
|
|
|
.read_probe = thd_probe,
|
2021-09-05 17:55:19 +02:00
|
|
|
.read_header = mlp_read_header,
|
2015-10-03 22:40:27 +02:00
|
|
|
.read_packet = ff_raw_read_partial_packet,
|
|
|
|
.raw_codec_id = AV_CODEC_ID_TRUEHD,
|
2019-07-06 11:32:48 +02:00
|
|
|
.priv_data_size = sizeof(FFRawDemuxerContext),
|
2015-10-03 22:40:27 +02:00
|
|
|
};
|
|
|
|
#endif
|