Commit a42e3a67 authored by Christian Schmidt's avatar Christian Schmidt Committed by Luca Barbato

pcm_dvd: consolidate pieces from pcm.c and mpeg.c

Remove the header decoding for PCM audio from mpeg.c and the
20/24bit parts from pcm.c and merge them into a new decoder in
pcm-dvd.c.

The decoder has added support for samples that span multiple
packets and modified 20/24bit group decoding. Both is needed to
decode samples that have been generated with DVD-Lab Pro 2. The
decoding of 16bit PCM and two channel 24bit is identical to
before. No other samples are known to verify the correctness of
the encoding this software does.
The complete list of tested formats is
48kHz/16bit/2-8 channels
48kHz/24bit/2-5 channels
96kHz/16bit/2-4 channels
96kHz/24bit/2 channels
Signed-off-by: 's avatarLuca Barbato <lu_zero@gentoo.org>
parent 21fd2f84
......@@ -427,7 +427,7 @@ OBJS-$(CONFIG_ZMBV_ENCODER) += zmbvenc.o
OBJS-$(CONFIG_PCM_ALAW_DECODER) += pcm.o
OBJS-$(CONFIG_PCM_ALAW_ENCODER) += pcm.o
OBJS-$(CONFIG_PCM_BLURAY_DECODER) += pcm-bluray.o
OBJS-$(CONFIG_PCM_DVD_DECODER) += pcm.o
OBJS-$(CONFIG_PCM_DVD_DECODER) += pcm-dvd.o
OBJS-$(CONFIG_PCM_F32BE_DECODER) += pcm.o
OBJS-$(CONFIG_PCM_F32BE_ENCODER) += pcm.o
OBJS-$(CONFIG_PCM_F32LE_DECODER) += pcm.o
......
This diff is collapsed.
......@@ -265,16 +265,7 @@ static int pcm_decode_frame(AVCodecContext *avctx, void *data,
/* av_get_bits_per_sample returns 0 for AV_CODEC_ID_PCM_DVD */
samples_per_block = 1;
if (avctx->codec->id == AV_CODEC_ID_PCM_DVD) {
if (avctx->bits_per_coded_sample != 20 &&
avctx->bits_per_coded_sample != 24) {
av_log(avctx, AV_LOG_ERROR, "PCM DVD unsupported sample depth\n");
return AVERROR(EINVAL);
}
/* 2 samples are interleaved per block in PCM_DVD */
samples_per_block = 2;
sample_size = avctx->bits_per_coded_sample * 2 / 8;
} else if (avctx->codec_id == AV_CODEC_ID_PCM_LXF) {
if (avctx->codec_id == AV_CODEC_ID_PCM_LXF) {
/* we process 40-bit blocks per channel for LXF */
samples_per_block = 2;
sample_size = 5;
......@@ -408,37 +399,6 @@ static int pcm_decode_frame(AVCodecContext *avctx, void *data,
samples += 2;
}
break;
case AV_CODEC_ID_PCM_DVD:
{
const uint8_t *src8;
dst_int32_t = (int32_t *)frame->data[0];
n /= avctx->channels;
switch (avctx->bits_per_coded_sample) {
case 20:
while (n--) {
c = avctx->channels;
src8 = src + 4 * c;
while (c--) {
*dst_int32_t++ = (bytestream_get_be16(&src) << 16) + ((*src8 & 0xf0) << 8);
*dst_int32_t++ = (bytestream_get_be16(&src) << 16) + ((*src8++ & 0x0f) << 12);
}
src = src8;
}
break;
case 24:
while (n--) {
c = avctx->channels;
src8 = src + 4 * c;
while (c--) {
*dst_int32_t++ = (bytestream_get_be16(&src) << 16) + ((*src8++) << 8);
*dst_int32_t++ = (bytestream_get_be16(&src) << 16) + ((*src8++) << 8);
}
src = src8;
}
break;
}
break;
}
case AV_CODEC_ID_PCM_LXF:
{
int i;
......@@ -522,7 +482,6 @@ AVCodec ff_ ## name_ ## _decoder = { \
/* Note: Do not forget to add new entries to the Makefile as well. */
PCM_CODEC (PCM_ALAW, AV_SAMPLE_FMT_S16, pcm_alaw, "PCM A-law");
PCM_DECODER(PCM_DVD, AV_SAMPLE_FMT_S32, pcm_dvd, "PCM signed 20|24-bit big-endian");
PCM_CODEC (PCM_F32BE, AV_SAMPLE_FMT_FLT, pcm_f32be, "PCM 32-bit floating point big-endian");
PCM_CODEC (PCM_F32LE, AV_SAMPLE_FMT_FLT, pcm_f32le, "PCM 32-bit floating point little-endian");
PCM_CODEC (PCM_F64BE, AV_SAMPLE_FMT_DBL, pcm_f64be, "PCM 64-bit floating point big-endian");
......
......@@ -27,7 +27,7 @@
*/
#define LIBAVCODEC_VERSION_MAJOR 55
#define LIBAVCODEC_VERSION_MINOR 17
#define LIBAVCODEC_VERSION_MINOR 18
#define LIBAVCODEC_VERSION_MICRO 0
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
......
......@@ -453,7 +453,6 @@ static int mpegps_read_packet(AVFormatContext *s,
codec_id = AV_CODEC_ID_DTS;
} else if (startcode >= 0xa0 && startcode <= 0xaf) {
type = AVMEDIA_TYPE_AUDIO;
/* 16 bit form will be handled as AV_CODEC_ID_PCM_S16BE */
codec_id = AV_CODEC_ID_PCM_DVD;
} else if (startcode >= 0xb0 && startcode <= 0xbf) {
type = AVMEDIA_TYPE_AUDIO;
......@@ -494,35 +493,10 @@ static int mpegps_read_packet(AVFormatContext *s,
st->id = startcode;
st->codec->codec_type = type;
st->codec->codec_id = codec_id;
if (codec_id != AV_CODEC_ID_PCM_S16BE)
st->need_parsing = AVSTREAM_PARSE_FULL;
st->need_parsing = AVSTREAM_PARSE_FULL;
found:
if(st->discard >= AVDISCARD_ALL)
goto skip;
if ((startcode >= 0xa0 && startcode <= 0xaf) ||
(startcode == 0x1bd && ((dvdaudio_substream_type & 0xe0) == 0xa0))) {
int b1, freq;
/* for LPCM, we just skip the header and consider it is raw
audio data */
if (len <= 3)
goto skip;
avio_r8(s->pb); /* emphasis (1), muse(1), reserved(1), frame number(5) */
b1 = avio_r8(s->pb); /* quant (2), freq(2), reserved(1), channels(3) */
avio_r8(s->pb); /* dynamic range control (0x80 = off) */
len -= 3;
freq = (b1 >> 4) & 3;
st->codec->sample_rate = lpcm_freq_tab[freq];
st->codec->channels = 1 + (b1 & 7);
st->codec->bits_per_coded_sample = 16 + ((b1 >> 6) & 3) * 4;
st->codec->bit_rate = st->codec->channels *
st->codec->sample_rate *
st->codec->bits_per_coded_sample;
if (st->codec->bits_per_coded_sample == 16)
st->codec->codec_id = AV_CODEC_ID_PCM_S16BE;
else if (st->codec->bits_per_coded_sample == 28)
return AVERROR(EINVAL);
}
ret = av_get_packet(s->pb, pkt, len);
pkt->pts = pts;
pkt->dts = dts;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment