Originally committed as revision 18542 to svn://svn.ffmpeg.org/ffmpeg/trunk
| ... | ... |
@@ -1233,6 +1233,7 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size, |
| 1233 | 1233 |
AC3DecodeContext *s = avctx->priv_data; |
| 1234 | 1234 |
int16_t *out_samples = (int16_t *)data; |
| 1235 | 1235 |
int blk, ch, err; |
| 1236 |
+ const uint8_t *channel_map; |
|
| 1236 | 1237 |
|
| 1237 | 1238 |
/* initialize the GetBitContext with the start of valid AC-3 Frame */ |
| 1238 | 1239 |
if (s->input_buffer) {
|
| ... | ... |
@@ -1321,6 +1322,7 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size, |
| 1321 | 1321 |
} |
| 1322 | 1322 |
|
| 1323 | 1323 |
/* decode the audio blocks */ |
| 1324 |
+ channel_map = ff_ac3_dec_channel_map[s->output_mode & ~AC3_OUTPUT_LFEON][s->lfe_on]; |
|
| 1324 | 1325 |
for (blk = 0; blk < s->num_blocks; blk++) {
|
| 1325 | 1326 |
const float *output[s->out_channels]; |
| 1326 | 1327 |
if (!err && decode_audio_block(s, blk)) {
|
| ... | ... |
@@ -1328,7 +1330,7 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size, |
| 1328 | 1328 |
err = 1; |
| 1329 | 1329 |
} |
| 1330 | 1330 |
for (ch = 0; ch < s->out_channels; ch++) |
| 1331 |
- output[ch] = s->output[ch]; |
|
| 1331 |
+ output[ch] = s->output[channel_map[ch]]; |
|
| 1332 | 1332 |
s->dsp.float_to_int16_interleave(out_samples, output, 256, s->out_channels); |
| 1333 | 1333 |
out_samples += 256 * s->out_channels; |
| 1334 | 1334 |
} |
| ... | ... |
@@ -79,21 +79,34 @@ const uint8_t ff_ac3_channels_tab[8] = {
|
| 79 | 79 |
2, 1, 2, 3, 3, 4, 4, 5 |
| 80 | 80 |
}; |
| 81 | 81 |
|
| 82 |
+#define COMMON_CHANNEL_MAP \ |
|
| 83 |
+ { { 0, 1, }, { 0, 1, 2, } },\
|
|
| 84 |
+ { { 0, }, { 0, 1, } },\
|
|
| 85 |
+ { { 0, 1, }, { 0, 1, 2, } },\
|
|
| 86 |
+ { { 0, 2, 1, }, { 0, 2, 1, 3, } },\
|
|
| 87 |
+ { { 0, 1, 2, }, { 0, 1, 3, 2, } },\
|
|
| 88 |
+ { { 0, 2, 1, 3, }, { 0, 2, 1, 4, 3, } },
|
|
| 89 |
+ |
|
| 82 | 90 |
/** |
| 83 | 91 |
* Table to remap channels from SMPTE order to AC-3 order. |
| 84 | 92 |
* [channel_mode][lfe][ch] |
| 85 | 93 |
*/ |
| 86 | 94 |
const uint8_t ff_ac3_enc_channel_map[8][2][6] = {
|
| 87 |
- { { 0, 1, }, { 0, 1, 2, } },
|
|
| 88 |
- { { 0, }, { 0, 1, } },
|
|
| 89 |
- { { 0, 1, }, { 0, 1, 2, } },
|
|
| 90 |
- { { 0, 2, 1, }, { 0, 2, 1, 3, } },
|
|
| 91 |
- { { 0, 1, 2, }, { 0, 1, 3, 2, } },
|
|
| 92 |
- { { 0, 2, 1, 3, }, { 0, 2, 1, 4, 3, } },
|
|
| 95 |
+ COMMON_CHANNEL_MAP |
|
| 93 | 96 |
{ { 0, 1, 2, 3, 4, }, { 0, 1, 3, 4, 2, } },
|
| 94 | 97 |
{ { 0, 2, 1, 3, 4, }, { 0, 2, 1, 4, 5, 3 } },
|
| 95 | 98 |
}; |
| 96 | 99 |
|
| 100 |
+/** |
|
| 101 |
+ * Table to remap channels from from AC-3 order to SMPTE order. |
|
| 102 |
+ * [channel_mode][lfe][ch] |
|
| 103 |
+ */ |
|
| 104 |
+const uint8_t ff_ac3_dec_channel_map[8][2][6] = {
|
|
| 105 |
+ COMMON_CHANNEL_MAP |
|
| 106 |
+ { { 0, 1, 2, 3, 4, }, { 0, 1, 4, 2, 3, } },
|
|
| 107 |
+ { { 0, 2, 1, 3, 4, }, { 0, 2, 1, 5, 3, 4 } },
|
|
| 108 |
+}; |
|
| 109 |
+ |
|
| 97 | 110 |
/* possible frequencies */ |
| 98 | 111 |
const uint16_t ff_ac3_sample_rate_tab[3] = { 48000, 44100, 32000 };
|
| 99 | 112 |
|
| ... | ... |
@@ -27,6 +27,7 @@ |
| 27 | 27 |
extern const uint16_t ff_ac3_frame_size_tab[38][3]; |
| 28 | 28 |
extern const uint8_t ff_ac3_channels_tab[8]; |
| 29 | 29 |
extern const uint8_t ff_ac3_enc_channel_map[8][2][6]; |
| 30 |
+extern const uint8_t ff_ac3_dec_channel_map[8][2][6]; |
|
| 30 | 31 |
extern const uint16_t ff_ac3_sample_rate_tab[3]; |
| 31 | 32 |
extern const uint16_t ff_ac3_bitrate_tab[19]; |
| 32 | 33 |
extern const int16_t ff_ac3_window[256]; |