annotate pcm-mpeg.c @ 10278:1a4af35efbda libavcodec

Hardcode AC-3 critical band tables when CONFIG_HARDCODED_TABLES is set.
author jbr
date Sun, 27 Sep 2009 04:07:49 +0000
parents 94cb694c2af7
children 8a4984c5cacc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10099
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
1 /*
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
2 * LPCM codecs for PCM formats found in MPEG streams
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
3 * Copyright (c) 2009 Christian Schmidt
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
4 *
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
5 * This file is part of FFmpeg.
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
6 *
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
11 *
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
15 * Lesser General Public License for more details.
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
16 *
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
20 */
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
21
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
22 /**
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
23 * @file libavcodec/pcm-mpeg.c
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
24 * PCM codecs for encodings found in MPEG streams (DVD/Blu-ray)
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
25 */
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
26
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
27 #include "avcodec.h"
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
28 #include "bytestream.h"
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
29
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
30 /*
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
31 * Channel Mapping according to
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
32 * Blu-ray Disc Read-Only Format Version 1
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
33 * Part 3: Audio Visual Basic Specifications
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
34 * mono M1 X
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
35 * stereo L R
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
36 * 3/0 L R C X
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
37 * 2/1 L R S X
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
38 * 3/1 L R C S
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
39 * 2/2 L R LS RS
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
40 * 3/2 L R C LS RS X
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
41 * 3/2+lfe L R C LS RS lfe
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
42 * 3/4 L R C LS Rls Rrs RS X
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
43 * 3/4+lfe L R C LS Rls Rrs RS lfe
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
44 */
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
45
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
46 /**
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
47 * Parse the header of a LPCM frame read from a MPEG-TS stream
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
48 * @param avctx the codec context
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
49 * @param header pointer to the first four bytes of the data packet
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
50 */
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
51 static int pcm_bluray_parse_header(AVCodecContext *avctx,
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
52 const uint8_t *header)
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
53 {
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
54 static const uint8_t bits_per_samples[4] = { 0, 16, 20, 24 };
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
55 static const uint32_t channel_layouts[16] = {
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
56 0, CH_LAYOUT_MONO, 0, CH_LAYOUT_STEREO, CH_LAYOUT_SURROUND,
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
57 CH_LAYOUT_2_1, CH_LAYOUT_4POINT0, CH_LAYOUT_2_2, CH_LAYOUT_5POINT0,
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
58 CH_LAYOUT_5POINT1, CH_LAYOUT_7POINT0, CH_LAYOUT_7POINT1, 0, 0, 0, 0
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
59 };
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
60 static const uint8_t channels[16] = {
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
61 0, 1, 0, 2, 3, 3, 4, 4, 5, 6, 7, 8, 0, 0, 0, 0
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
62 };
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
63 uint8_t channel_layout = header[2] >> 4;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
64
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
65 if (avctx->debug & FF_DEBUG_PICT_INFO)
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
66 dprintf(avctx, "pcm_bluray_parse_header: header = %02x%02x%02x%02x\n",
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
67 header[0], header[1], header[2], header[3]);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
68
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
69 /* get the sample depth and derive the sample format from it */
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
70 avctx->bits_per_coded_sample = bits_per_samples[header[3] >> 6];
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
71 if (!avctx->bits_per_coded_sample) {
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
72 av_log(avctx, AV_LOG_ERROR, "unsupported sample depth (0)\n");
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
73 return -1;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
74 }
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
75 avctx->sample_fmt = avctx->bits_per_coded_sample == 16 ? SAMPLE_FMT_S16 :
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
76 SAMPLE_FMT_S32;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
77
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
78 /* get the sample rate. Not all values are known or exist. */
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
79 switch (header[2] & 0x0f) {
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
80 case 1:
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
81 avctx->sample_rate = 48000;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
82 break;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
83 case 4:
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
84 avctx->sample_rate = 96000;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
85 break;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
86 case 5:
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
87 avctx->sample_rate = 192000;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
88 break;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
89 default:
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
90 avctx->sample_rate = 0;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
91 av_log(avctx, AV_LOG_ERROR, "unsupported sample rate (%d)\n",
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
92 header[2] & 0x0f);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
93 return -1;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
94 }
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
95
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
96 /*
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
97 * get the channel number (and mapping). Not all values are known or exist.
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
98 * It must be noted that the number of channels in the MPEG stream can
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
99 * differ from the actual meaningful number, e.g. mono audio still has two
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
100 * channels, one being empty.
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
101 */
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
102 avctx->channel_layout = channel_layouts[channel_layout];
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
103 avctx->channels = channels[channel_layout];
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
104 if (!avctx->channels) {
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
105 av_log(avctx, AV_LOG_ERROR, "unsupported channel configuration (%d)\n",
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
106 channel_layout);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
107 return -1;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
108 }
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
109
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
110 avctx->bit_rate = avctx->channels * avctx->sample_rate *
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
111 avctx->bits_per_coded_sample;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
112
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
113 if (avctx->debug & FF_DEBUG_PICT_INFO)
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
114 dprintf(avctx,
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
115 "pcm_bluray_parse_header: %d channels, %d bits per sample, %d kHz, %d kbit\n",
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
116 avctx->channels, avctx->bits_per_coded_sample,
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
117 avctx->sample_rate, avctx->bit_rate);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
118 return 0;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
119 }
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
120
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
121 static int pcm_bluray_decode_frame(AVCodecContext *avctx,
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
122 void *data,
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
123 int *data_size,
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
124 AVPacket *avpkt)
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
125 {
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
126 const uint8_t *src = avpkt->data;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
127 int buf_size = avpkt->size;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
128 int num_source_channels, channel, retval;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
129 int sample_size, samples, output_size;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
130 int16_t *dst16 = data;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
131 int32_t *dst32 = data;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
132
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
133 if (buf_size < 4) {
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
134 av_log(avctx, AV_LOG_ERROR, "PCM packet too small\n");
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
135 return -1;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
136 }
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
137
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
138 if (pcm_bluray_parse_header(avctx, src))
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
139 return -1;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
140 src += 4;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
141 buf_size -= 4;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
142
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
143 /* There's always an even number of channels in the source */
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
144 num_source_channels = FFALIGN(avctx->channels, 2);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
145 sample_size = (num_source_channels * avctx->bits_per_coded_sample) >> 3;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
146 samples = buf_size / sample_size;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
147
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
148 output_size = samples * avctx->channels *
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
149 (avctx->sample_fmt == SAMPLE_FMT_S32 ? 4 : 2);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
150 if (output_size > *data_size) {
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
151 av_log(avctx, AV_LOG_ERROR,
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
152 "Insufficient output buffer space (%d bytes, needed %d bytes)\n",
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
153 *data_size, output_size);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
154 return -1;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
155 }
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
156 *data_size = output_size;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
157
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
158 if (samples) {
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
159 switch (avctx->channel_layout) {
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
160 /* cases with same number of source and coded channels */
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
161 case CH_LAYOUT_STEREO:
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
162 case CH_LAYOUT_4POINT0:
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
163 case CH_LAYOUT_2_2:
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
164 samples *= num_source_channels;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
165 if (SAMPLE_FMT_S16 == avctx->sample_fmt) {
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
166 #if HAVE_BIGENDIAN
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
167 memcpy(dst16, src, output_size);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
168 #else
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
169 do {
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
170 *dst16++ = bytestream_get_be16(&src);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
171 } while (--samples);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
172 #endif
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
173 } else {
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
174 do {
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
175 *dst32++ = bytestream_get_be24(&src) << 8;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
176 } while (--samples);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
177 }
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
178 break;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
179 /* cases where number of source channels = coded channels + 1 */
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
180 case CH_LAYOUT_MONO:
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
181 case CH_LAYOUT_SURROUND:
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
182 case CH_LAYOUT_2_1:
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
183 case CH_LAYOUT_5POINT0:
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
184 if (SAMPLE_FMT_S16 == avctx->sample_fmt) {
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
185 do {
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
186 #if HAVE_BIGENDIAN
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
187 memcpy(dst16, src, avctx->channels * 2);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
188 dst16 += avctx->channels;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
189 src += sample_size;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
190 #else
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
191 channel = avctx->channels;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
192 do {
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
193 *dst16++ = bytestream_get_be16(&src);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
194 } while (--channel);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
195 src += 2;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
196 #endif
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
197 } while (--samples);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
198 } else {
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
199 do {
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
200 channel = avctx->channels;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
201 do {
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
202 *dst32++ = bytestream_get_be24(&src) << 8;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
203 } while (--channel);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
204 src += 3;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
205 } while (--samples);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
206 }
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
207 break;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
208 /* remapping: L, R, C, LBack, RBack, LF */
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
209 case CH_LAYOUT_5POINT1:
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
210 if (SAMPLE_FMT_S16 == avctx->sample_fmt) {
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
211 do {
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
212 dst16[0] = bytestream_get_be16(&src);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
213 dst16[1] = bytestream_get_be16(&src);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
214 dst16[2] = bytestream_get_be16(&src);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
215 dst16[4] = bytestream_get_be16(&src);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
216 dst16[5] = bytestream_get_be16(&src);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
217 dst16[3] = bytestream_get_be16(&src);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
218 dst16 += 6;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
219 } while (--samples);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
220 } else {
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
221 do {
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
222 dst32[0] = bytestream_get_be24(&src) << 8;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
223 dst32[1] = bytestream_get_be24(&src) << 8;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
224 dst32[2] = bytestream_get_be24(&src) << 8;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
225 dst32[4] = bytestream_get_be24(&src) << 8;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
226 dst32[5] = bytestream_get_be24(&src) << 8;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
227 dst32[3] = bytestream_get_be24(&src) << 8;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
228 dst32 += 6;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
229 } while (--samples);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
230 }
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
231 break;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
232 /* remapping: L, R, C, LSide, LBack, RBack, RSide, <unused> */
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
233 case CH_LAYOUT_7POINT0:
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
234 if (SAMPLE_FMT_S16 == avctx->sample_fmt) {
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
235 do {
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
236 dst16[0] = bytestream_get_be16(&src);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
237 dst16[1] = bytestream_get_be16(&src);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
238 dst16[2] = bytestream_get_be16(&src);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
239 dst16[5] = bytestream_get_be16(&src);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
240 dst16[3] = bytestream_get_be16(&src);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
241 dst16[4] = bytestream_get_be16(&src);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
242 dst16[6] = bytestream_get_be16(&src);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
243 dst16 += 7;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
244 src += 2;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
245 } while (--samples);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
246 } else {
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
247 do {
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
248 dst32[0] = bytestream_get_be24(&src) << 8;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
249 dst32[1] = bytestream_get_be24(&src) << 8;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
250 dst32[2] = bytestream_get_be24(&src) << 8;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
251 dst32[5] = bytestream_get_be24(&src) << 8;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
252 dst32[3] = bytestream_get_be24(&src) << 8;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
253 dst32[4] = bytestream_get_be24(&src) << 8;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
254 dst32[6] = bytestream_get_be24(&src) << 8;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
255 dst32 += 7;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
256 src += 3;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
257 } while (--samples);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
258 }
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
259 break;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
260 /* remapping: L, R, C, LSide, LBack, RBack, RSide, LF */
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
261 case CH_LAYOUT_7POINT1:
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
262 if (SAMPLE_FMT_S16 == avctx->sample_fmt) {
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
263 do {
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
264 dst16[0] = bytestream_get_be16(&src);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
265 dst16[1] = bytestream_get_be16(&src);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
266 dst16[2] = bytestream_get_be16(&src);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
267 dst16[6] = bytestream_get_be16(&src);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
268 dst16[4] = bytestream_get_be16(&src);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
269 dst16[5] = bytestream_get_be16(&src);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
270 dst16[7] = bytestream_get_be16(&src);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
271 dst16[3] = bytestream_get_be16(&src);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
272 dst16 += 8;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
273 } while (--samples);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
274 } else {
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
275 do {
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
276 dst32[0] = bytestream_get_be24(&src) << 8;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
277 dst32[1] = bytestream_get_be24(&src) << 8;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
278 dst32[2] = bytestream_get_be24(&src) << 8;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
279 dst32[6] = bytestream_get_be24(&src) << 8;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
280 dst32[4] = bytestream_get_be24(&src) << 8;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
281 dst32[5] = bytestream_get_be24(&src) << 8;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
282 dst32[7] = bytestream_get_be24(&src) << 8;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
283 dst32[3] = bytestream_get_be24(&src) << 8;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
284 dst32 += 8;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
285 } while (--samples);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
286 }
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
287 break;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
288 }
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
289 }
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
290
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
291 retval = src - avpkt->data;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
292 if (avctx->debug & FF_DEBUG_BITSTREAM)
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
293 dprintf(avctx, "pcm_bluray_decode_frame: decoded %d -> %d bytes\n",
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
294 retval, *data_size);
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
295 return retval;
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
296 }
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
297
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
298 AVCodec pcm_bluray_decoder = {
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
299 "pcm_bluray",
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
300 CODEC_TYPE_AUDIO,
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
301 CODEC_ID_PCM_BLURAY,
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
302 0,
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
303 NULL,
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
304 NULL,
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
305 NULL,
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
306 pcm_bluray_decode_frame,
10145
7955db355703 Make sample_fmts and channel_layouts compound literals const to reduce size of
reimar
parents: 10099
diff changeset
307 .sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16, SAMPLE_FMT_S32,
10099
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
308 SAMPLE_FMT_NONE},
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
309 .long_name = NULL_IF_CONFIG_SMALL("PCM signed 16|20|24-bit big-endian for Blu-ray media"),
27eef2ead6ab Decoder for LPCM as used in Bluray discs.
cehoyos
parents:
diff changeset
310 };