1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-26 09:02:38 +00:00

Fix incorrect channel ordering for lavc audio codecs (specifically ffac3,

ffdca, ffflac, ffaac, fftruehd).  In the process, adds support for 32-bit
samples.



git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@29533 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
tack 2009-08-18 22:24:36 +00:00
parent 3961e12fca
commit f89696a8e2
5 changed files with 30 additions and 41 deletions

View File

@ -212,7 +212,7 @@ static af_data_t* play(struct af_instance_s* af, af_data_t* data)
if (c->nch >= 5) if (c->nch >= 5)
reorder_channel_nch(s->pending_data, reorder_channel_nch(s->pending_data,
AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT, AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT,
AF_CHANNEL_LAYOUT_LAVC_AC3_DEFAULT, AF_CHANNEL_LAYOUT_LAVC_DEFAULT,
c->nch, c->nch,
s->expect_len / 2, 2); s->expect_len / 2, 2);
@ -224,7 +224,7 @@ static af_data_t* play(struct af_instance_s* af, af_data_t* data)
if (c->nch >= 5) if (c->nch >= 5)
reorder_channel_nch(src, reorder_channel_nch(src,
AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT, AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT,
AF_CHANNEL_LAYOUT_LAVC_AC3_DEFAULT, AF_CHANNEL_LAYOUT_LAVC_DEFAULT,
c->nch, c->nch,
s->expect_len / 2, 2); s->expect_len / 2, 2);
len = avcodec_encode_audio(s->lavc_actx,dest,destsize,(void *)src); len = avcodec_encode_audio(s->lavc_actx,dest,destsize,(void *)src);

View File

@ -293,6 +293,9 @@ void reorder_channel_copy(void *src,
case AF_CHANNEL_LAYOUT_5_1_E << 16 | AF_CHANNEL_LAYOUT_5_1_B: case AF_CHANNEL_LAYOUT_5_1_E << 16 | AF_CHANNEL_LAYOUT_5_1_B:
reorder_copy_6ch(dest, src, samples, samplesize, 1, 3, 4, 5, 2, 0); reorder_copy_6ch(dest, src, samples, samplesize, 1, 3, 4, 5, 2, 0);
break; break;
case AF_CHANNEL_LAYOUT_5_1_F << 16 | AF_CHANNEL_LAYOUT_5_1_B:
reorder_copy_6ch(dest, src, samples, samplesize, 1, 2, 4, 5, 0, 3);
break;
default: default:
mp_msg(MSGT_GLOBAL, MSGL_WARN, "[reorder_channel_copy] unsupport " mp_msg(MSGT_GLOBAL, MSGL_WARN, "[reorder_channel_copy] unsupport "
"from %x to %x, %d * %d\n", src_layout, dest_layout, "from %x to %x, %d * %d\n", src_layout, dest_layout,
@ -1099,6 +1102,9 @@ void reorder_channel(void *src,
case AF_CHANNEL_LAYOUT_5_1_E << 16 | AF_CHANNEL_LAYOUT_5_1_B: case AF_CHANNEL_LAYOUT_5_1_E << 16 | AF_CHANNEL_LAYOUT_5_1_B:
reorder_self_2_4(src, samples, samplesize, 2, 4, 0, 1, 3, 5); reorder_self_2_4(src, samples, samplesize, 2, 4, 0, 1, 3, 5);
break; break;
case AF_CHANNEL_LAYOUT_5_1_F << 16 | AF_CHANNEL_LAYOUT_5_1_B:
reorder_self_2_4(src, samples, samplesize, 3, 5, 0, 1, 2, 4);
break;
default: default:
mp_msg(MSGT_GLOBAL, MSGL_WARN, mp_msg(MSGT_GLOBAL, MSGL_WARN,
"[reorder_channel] unsupported from %x to %x, %d * %d\n", "[reorder_channel] unsupported from %x to %x, %d * %d\n",
@ -1111,22 +1117,18 @@ static int channel_layout_mapping_5ch[AF_CHANNEL_LAYOUT_SOURCE_NUM] = {
AF_CHANNEL_LAYOUT_ALSA_5CH_DEFAULT, AF_CHANNEL_LAYOUT_ALSA_5CH_DEFAULT,
AF_CHANNEL_LAYOUT_AAC_5CH_DEFAULT, AF_CHANNEL_LAYOUT_AAC_5CH_DEFAULT,
AF_CHANNEL_LAYOUT_WAVEEX_5CH_DEFAULT, AF_CHANNEL_LAYOUT_WAVEEX_5CH_DEFAULT,
AF_CHANNEL_LAYOUT_LAVC_AC3_5CH_DEFAULT, AF_CHANNEL_LAYOUT_LAVC_5CH_DEFAULT,
AF_CHANNEL_LAYOUT_LAVC_LIBA52_5CH_DEFAULT,
AF_CHANNEL_LAYOUT_LAVC_DCA_5CH_DEFAULT,
AF_CHANNEL_LAYOUT_VORBIS_5CH_DEFAULT, AF_CHANNEL_LAYOUT_VORBIS_5CH_DEFAULT,
AF_CHANNEL_LAYOUT_FLAC_5CH_DEFAULT, AF_CHANNEL_LAYOUT_LAVC_AAC_DEC_5CH_DEFAULT,
}; };
static int channel_layout_mapping_6ch[AF_CHANNEL_LAYOUT_SOURCE_NUM] = { static int channel_layout_mapping_6ch[AF_CHANNEL_LAYOUT_SOURCE_NUM] = {
AF_CHANNEL_LAYOUT_ALSA_6CH_DEFAULT, AF_CHANNEL_LAYOUT_ALSA_6CH_DEFAULT,
AF_CHANNEL_LAYOUT_AAC_6CH_DEFAULT, AF_CHANNEL_LAYOUT_AAC_6CH_DEFAULT,
AF_CHANNEL_LAYOUT_WAVEEX_6CH_DEFAULT, AF_CHANNEL_LAYOUT_WAVEEX_6CH_DEFAULT,
AF_CHANNEL_LAYOUT_LAVC_AC3_6CH_DEFAULT, AF_CHANNEL_LAYOUT_LAVC_6CH_DEFAULT,
AF_CHANNEL_LAYOUT_LAVC_LIBA52_6CH_DEFAULT,
AF_CHANNEL_LAYOUT_LAVC_DCA_6CH_DEFAULT,
AF_CHANNEL_LAYOUT_VORBIS_6CH_DEFAULT, AF_CHANNEL_LAYOUT_VORBIS_6CH_DEFAULT,
AF_CHANNEL_LAYOUT_FLAC_6CH_DEFAULT, AF_CHANNEL_LAYOUT_LAVC_AAC_DEC_6CH_DEFAULT,
}; };
void reorder_channel_copy_nch(void *src, void reorder_channel_copy_nch(void *src,

View File

@ -53,8 +53,9 @@
#define AF_CHANNEL_LAYOUT_5_1_C ((114<<8)|6|AF_LFE) // L C R Ls Rs LFE #define AF_CHANNEL_LAYOUT_5_1_C ((114<<8)|6|AF_LFE) // L C R Ls Rs LFE
#define AF_CHANNEL_LAYOUT_5_1_D ((115<<8)|6|AF_LFE) // C L R Ls Rs LFE #define AF_CHANNEL_LAYOUT_5_1_D ((115<<8)|6|AF_LFE) // C L R Ls Rs LFE
#define AF_CHANNEL_LAYOUT_5_1_E ((116<<8)|6|AF_LFE) // LFE L C R Ls Rs #define AF_CHANNEL_LAYOUT_5_1_E ((116<<8)|6|AF_LFE) // LFE L C R Ls Rs
#define AF_CHANNEL_LAYOUT_6_1_A ((117<<8)|7|AF_LFE) // L R C LFE Ls Rs Cs #define AF_CHANNEL_LAYOUT_5_1_F ((117<<8)|6|AF_LFE) // C L R LFE Ls Rs
#define AF_CHANNEL_LAYOUT_7_1_A ((118<<8)|8|AF_LFE) // L R C LFE Ls Rs Rls Rrs #define AF_CHANNEL_LAYOUT_6_1_A ((118<<8)|7|AF_LFE) // L R C LFE Ls Rs Cs
#define AF_CHANNEL_LAYOUT_7_1_A ((119<<8)|8|AF_LFE) // L R C LFE Ls Rs Rls Rrs
#define AF_CHANNEL_LAYOUT_ALSA_5CH_DEFAULT AF_CHANNEL_LAYOUT_5_0_B #define AF_CHANNEL_LAYOUT_ALSA_5CH_DEFAULT AF_CHANNEL_LAYOUT_5_0_B
@ -65,16 +66,12 @@
#define AF_CHANNEL_LAYOUT_AAC_6CH_DEFAULT AF_CHANNEL_LAYOUT_5_1_D #define AF_CHANNEL_LAYOUT_AAC_6CH_DEFAULT AF_CHANNEL_LAYOUT_5_1_D
#define AF_CHANNEL_LAYOUT_WAVEEX_5CH_DEFAULT AF_CHANNEL_LAYOUT_5_0_A #define AF_CHANNEL_LAYOUT_WAVEEX_5CH_DEFAULT AF_CHANNEL_LAYOUT_5_0_A
#define AF_CHANNEL_LAYOUT_WAVEEX_6CH_DEFAULT AF_CHANNEL_LAYOUT_5_1_A #define AF_CHANNEL_LAYOUT_WAVEEX_6CH_DEFAULT AF_CHANNEL_LAYOUT_5_1_A
#define AF_CHANNEL_LAYOUT_LAVC_AC3_5CH_DEFAULT AF_CHANNEL_LAYOUT_5_0_C #define AF_CHANNEL_LAYOUT_LAVC_5CH_DEFAULT AF_CHANNEL_LAYOUT_5_0_A
#define AF_CHANNEL_LAYOUT_LAVC_AC3_6CH_DEFAULT AF_CHANNEL_LAYOUT_5_1_C #define AF_CHANNEL_LAYOUT_LAVC_6CH_DEFAULT AF_CHANNEL_LAYOUT_5_1_A
#define AF_CHANNEL_LAYOUT_LAVC_LIBA52_5CH_DEFAULT AF_CHANNEL_LAYOUT_5_0_C
#define AF_CHANNEL_LAYOUT_LAVC_LIBA52_6CH_DEFAULT AF_CHANNEL_LAYOUT_5_1_E
#define AF_CHANNEL_LAYOUT_LAVC_DCA_5CH_DEFAULT AF_CHANNEL_LAYOUT_5_0_D
#define AF_CHANNEL_LAYOUT_LAVC_DCA_6CH_DEFAULT AF_CHANNEL_LAYOUT_5_1_D
#define AF_CHANNEL_LAYOUT_VORBIS_5CH_DEFAULT AF_CHANNEL_LAYOUT_5_0_C #define AF_CHANNEL_LAYOUT_VORBIS_5CH_DEFAULT AF_CHANNEL_LAYOUT_5_0_C
#define AF_CHANNEL_LAYOUT_VORBIS_6CH_DEFAULT AF_CHANNEL_LAYOUT_5_1_C #define AF_CHANNEL_LAYOUT_VORBIS_6CH_DEFAULT AF_CHANNEL_LAYOUT_5_1_C
#define AF_CHANNEL_LAYOUT_FLAC_5CH_DEFAULT AF_CHANNEL_LAYOUT_5_0_A #define AF_CHANNEL_LAYOUT_LAVC_AAC_DEC_5CH_DEFAULT AF_CHANNEL_LAYOUT_5_0_D
#define AF_CHANNEL_LAYOUT_FLAC_6CH_DEFAULT AF_CHANNEL_LAYOUT_5_1_A #define AF_CHANNEL_LAYOUT_LAVC_AAC_DEC_6CH_DEFAULT AF_CHANNEL_LAYOUT_5_1_F
#define AF_CHANNEL_MASK 0xFF #define AF_CHANNEL_MASK 0xFF
#define AF_GET_CH_NUM(A) ((A)&0x7F) #define AF_GET_CH_NUM(A) ((A)&0x7F)
@ -103,12 +100,10 @@ void reorder_channel(void *buf,
#define AF_CHANNEL_LAYOUT_ALSA_DEFAULT 0 #define AF_CHANNEL_LAYOUT_ALSA_DEFAULT 0
#define AF_CHANNEL_LAYOUT_AAC_DEFAULT 1 #define AF_CHANNEL_LAYOUT_AAC_DEFAULT 1
#define AF_CHANNEL_LAYOUT_WAVEEX_DEFAULT 2 #define AF_CHANNEL_LAYOUT_WAVEEX_DEFAULT 2
#define AF_CHANNEL_LAYOUT_LAVC_AC3_DEFAULT 3 #define AF_CHANNEL_LAYOUT_LAVC_DEFAULT 3
#define AF_CHANNEL_LAYOUT_LAVC_LIBA52_DEFAULT 4 #define AF_CHANNEL_LAYOUT_VORBIS_DEFAULT 4
#define AF_CHANNEL_LAYOUT_LAVC_DCA_DEFAULT 5 #define AF_CHANNEL_LAYOUT_LAVC_AAC_DEC_DEFAULT 5
#define AF_CHANNEL_LAYOUT_VORBIS_DEFAULT 6 #define AF_CHANNEL_LAYOUT_SOURCE_NUM 6
#define AF_CHANNEL_LAYOUT_FLAC_DEFAULT 7
#define AF_CHANNEL_LAYOUT_SOURCE_NUM 8
#define AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT AF_CHANNEL_LAYOUT_ALSA_DEFAULT #define AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT AF_CHANNEL_LAYOUT_ALSA_DEFAULT
/// Optimized channel reorder between different audio sources and targets. /// Optimized channel reorder between different audio sources and targets.

View File

@ -174,27 +174,19 @@ static int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int m
if(len2>0){ if(len2>0){
if (((AVCodecContext *)sh_audio->context)->channels >= 5) { if (((AVCodecContext *)sh_audio->context)->channels >= 5) {
int src_ch_layout = AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT; int src_ch_layout = AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT;
int samplesize = av_get_bits_per_sample_format(((AVCodecContext *)
sh_audio->context)->sample_fmt) / 8;
const char *codec=((AVCodecContext*)sh_audio->context)->codec->name; const char *codec=((AVCodecContext*)sh_audio->context)->codec->name;
if (!strcasecmp(codec, "ac3") if (!strcasecmp(codec, "aac"))
|| !strcasecmp(codec, "eac3")) src_ch_layout = AF_CHANNEL_LAYOUT_LAVC_AAC_DEC_DEFAULT;
src_ch_layout = AF_CHANNEL_LAYOUT_LAVC_AC3_DEFAULT;
else if (!strcasecmp(codec, "dca"))
src_ch_layout = AF_CHANNEL_LAYOUT_LAVC_DCA_DEFAULT;
else if (!strcasecmp(codec, "libfaad")
|| !strcasecmp(codec, "mpeg4aac"))
src_ch_layout = AF_CHANNEL_LAYOUT_AAC_DEFAULT;
else if (!strcasecmp(codec, "liba52"))
src_ch_layout = AF_CHANNEL_LAYOUT_LAVC_LIBA52_DEFAULT;
else if (!strcasecmp(codec, "vorbis")) else if (!strcasecmp(codec, "vorbis"))
src_ch_layout = AF_CHANNEL_LAYOUT_VORBIS_DEFAULT; src_ch_layout = AF_CHANNEL_LAYOUT_VORBIS_DEFAULT;
else if (!strcasecmp(codec, "flac"))
src_ch_layout = AF_CHANNEL_LAYOUT_FLAC_DEFAULT;
else else
src_ch_layout = AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT; src_ch_layout = AF_CHANNEL_LAYOUT_LAVC_DEFAULT;
reorder_channel_nch(buf, src_ch_layout, reorder_channel_nch(buf, src_ch_layout,
AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT, AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT,
((AVCodecContext *)sh_audio->context)->channels, ((AVCodecContext *)sh_audio->context)->channels,
len2 / 2, 2); len2 / samplesize, samplesize);
} }
//len=len2;break; //len=len2;break;
if(len<0) len=len2; else len+=len2; if(len<0) len=len2; else len+=len2;

View File

@ -109,7 +109,7 @@ static int encode_lavc(audio_encoder_t *encoder, uint8_t *dest, void *src, int s
!strcmp(lavc_acodec->name,"libfaac"))) { !strcmp(lavc_acodec->name,"libfaac"))) {
int isac3 = !strcmp(lavc_acodec->name,"ac3"); int isac3 = !strcmp(lavc_acodec->name,"ac3");
reorder_channel_nch(src, AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT, reorder_channel_nch(src, AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT,
isac3 ? AF_CHANNEL_LAYOUT_LAVC_AC3_DEFAULT isac3 ? AF_CHANNEL_LAYOUT_LAVC_DEFAULT
: AF_CHANNEL_LAYOUT_AAC_DEFAULT, : AF_CHANNEL_LAYOUT_AAC_DEFAULT,
encoder->params.channels, encoder->params.channels,
size / 2, 2); size / 2, 2);