Index: libmpcodecs/ae_faac.c =================================================================== --- libmpcodecs/ae_faac.c (revision 25192) +++ libmpcodecs/ae_faac.c (working copy) @@ -11,6 +11,7 @@ #include "libmpdemux/ms_hdr.h" #include "stream/stream.h" #include "libmpdemux/muxer.h" +#include "reorder_copy.h" #include #include "ae.h" @@ -98,6 +99,15 @@ static int encode_faac(audio_encoder_t *encoder, uint8_t *dest, void *src, int len, int max_size) { + if (encoder->params.channels == 6) + reorder_channel(src, AF_CHANNEL_LAYOUT_MPLAYER_6CH_DEFAULT, + AF_CHANNEL_LAYOUT_AAC_6CH_DEFAULT, + len / divisor, divisor); + else if (encoder->params.channels == 5) + reorder_channel(src, AF_CHANNEL_LAYOUT_MPLAYER_5CH_DEFAULT, + AF_CHANNEL_LAYOUT_AAC_5CH_DEFAULT, + len / divisor, divisor); + // len is divided by the number of bytes per sample enc_frame_size = faacEncEncode(faac, (int32_t*) src, len / divisor, dest, max_size); Index: libmpcodecs/ae_pcm.c =================================================================== --- libmpcodecs/ae_pcm.c (revision 25192) +++ libmpcodecs/ae_pcm.c (working copy) @@ -12,6 +12,7 @@ #include "stream/stream.h" #include "libmpdemux/muxer.h" #include "ae_pcm.h" +#include "reorder_copy.h" static int bind_pcm(audio_encoder_t *encoder, muxer_stream_t *mux_a) @@ -38,6 +39,18 @@ static int encode_pcm(audio_encoder_t *encoder, uint8_t *dest, void *src, int nsamples, int max_size) { max_size = FFMIN(nsamples, max_size); + if (encoder->params.channels == 6 || encoder->params.channels == 5) { + max_size -= max_size % (encoder->params.channels * 2); + if (encoder->params.channels == 6) + reorder_channel_copy(src, AF_CHANNEL_LAYOUT_MPLAYER_6CH_DEFAULT, + dest, AF_CHANNEL_LAYOUT_WAVEEX_6CH_DEFAULT, + max_size / 2, 2); + else + reorder_channel_copy(src, AF_CHANNEL_LAYOUT_MPLAYER_5CH_DEFAULT, + dest, AF_CHANNEL_LAYOUT_WAVEEX_5CH_DEFAULT, + max_size / 2, 2); + } + else memcpy(dest, src, max_size); return max_size; } Index: libmpcodecs/ad_pcm.c =================================================================== --- libmpcodecs/ad_pcm.c (revision 25192) +++ libmpcodecs/ad_pcm.c (working copy) @@ -5,6 +5,7 @@ #include "config.h" #include "ad_internal.h" #include "libaf/af_format.h" +#include "reorder_copy.h" static ad_info_t info = { @@ -126,5 +127,15 @@ // based on channels in preinit() return -1; len=demux_read_data(sh_audio->ds,buf,len); + if (len > 0) { + if (sh_audio->channels == 6) + reorder_channel(buf, AF_CHANNEL_LAYOUT_WAVEEX_6CH_DEFAULT, + AF_CHANNEL_LAYOUT_MPLAYER_6CH_DEFAULT, + len / sh_audio->samplesize, sh_audio->samplesize); + else if (sh_audio->channels == 5) + reorder_channel(buf, AF_CHANNEL_LAYOUT_WAVEEX_5CH_DEFAULT, + AF_CHANNEL_LAYOUT_MPLAYER_5CH_DEFAULT, + len / sh_audio->samplesize, sh_audio->samplesize); + } return len; } Index: libmpcodecs/ad_faad.c =================================================================== --- libmpcodecs/ad_faad.c (revision 25192) +++ libmpcodecs/ad_faad.c (working copy) @@ -10,6 +10,7 @@ #include "config.h" #include "ad_internal.h" +#include "reorder_copy.h" static ad_info_t info = { @@ -277,6 +278,18 @@ /* XXX: samples already multiplied by channels! */ mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"FAAD: Successfully decoded frame (%ld Bytes)!\n", sh->samplesize*faac_finfo.samples); + + if (sh->channels == 6) + reorder_channel_copy(faac_sample_buffer, + AF_CHANNEL_LAYOUT_AAC_6CH_DEFAULT, + buf+len, AF_CHANNEL_LAYOUT_MPLAYER_6CH_DEFAULT, + faac_finfo.samples, sh->samplesize); + else if (sh->channels == 5) + reorder_channel_copy(faac_sample_buffer, + AF_CHANNEL_LAYOUT_AAC_5CH_DEFAULT, + buf+len, AF_CHANNEL_LAYOUT_MPLAYER_5CH_DEFAULT, + faac_finfo.samples, sh->samplesize); + else memcpy(buf+len,faac_sample_buffer, sh->samplesize*faac_finfo.samples); last_dec_len = sh->samplesize*faac_finfo.samples; len += last_dec_len; Index: libmpcodecs/ad_dmo.c =================================================================== --- libmpcodecs/ad_dmo.c (revision 25192) +++ libmpcodecs/ad_dmo.c (working copy) @@ -7,6 +7,7 @@ #include "help_mp.h" #include "ad_internal.h" +#include "reorder_copy.h" static ad_info_t info = { @@ -94,6 +95,18 @@ sh_audio->a_in_buffer_len-=size_in; memmove(sh_audio->a_in_buffer,&sh_audio->a_in_buffer[size_in],sh_audio->a_in_buffer_len); } + if (size_out > 0) { + if (sh_audio->channels == 6) + reorder_channel(buf, AF_CHANNEL_LAYOUT_WAVEEX_6CH_DEFAULT, + AF_CHANNEL_LAYOUT_MPLAYER_6CH_DEFAULT, + size_out / sh_audio->samplesize, + sh_audio->samplesize); + else if (sh_audio->channels == 5) + reorder_channel(buf, AF_CHANNEL_LAYOUT_WAVEEX_5CH_DEFAULT, + AF_CHANNEL_LAYOUT_MPLAYER_5CH_DEFAULT, + size_out / sh_audio->samplesize, + sh_audio->samplesize); + } // len=size_out; return size_out; } Index: libmpcodecs/ae_lavc.c =================================================================== --- libmpcodecs/ae_lavc.c (revision 25192) +++ libmpcodecs/ae_lavc.c (working copy) @@ -14,6 +14,7 @@ #include "help_mp.h" #include "config.h" #include "libaf/af_format.h" +#include "reorder_copy.h" #ifdef USE_LIBAVCODEC_SO #include #else @@ -111,6 +112,21 @@ static int encode_lavc(audio_encoder_t *encoder, uint8_t *dest, void *src, int size, int max_size) { int n; + if ((encoder->params.channels == 6 || encoder->params.channels == 5) && + (!strcmp(lavc_acodec->name,"ac3") || + !strcmp(lavc_acodec->name,"libfaac"))) { + int isac3 = !strcmp(lavc_acodec->name,"ac3"); + if (encoder->params.channels == 6) + reorder_channel(src, AF_CHANNEL_LAYOUT_MPLAYER_6CH_DEFAULT, + isac3 ? AF_CHANNEL_LAYOUT_LAVC_AC3_6CH_DEFAULT + : AF_CHANNEL_LAYOUT_AAC_6CH_DEFAULT, + size / 2, 2); + else if (encoder->params.channels == 5) + reorder_channel(src, AF_CHANNEL_LAYOUT_MPLAYER_5CH_DEFAULT, + isac3 ? AF_CHANNEL_LAYOUT_LAVC_AC3_5CH_DEFAULT + : AF_CHANNEL_LAYOUT_AAC_5CH_DEFAULT, + size / 2, 2); + } n = avcodec_encode_audio(lavc_actx, dest, size, src); compressed_frame_size = n; return n; Index: libao2/ao_pcm.c =================================================================== --- libao2/ao_pcm.c (revision 25192) +++ libao2/ao_pcm.c (working copy) @@ -12,6 +12,7 @@ #include "audio_out_internal.h" #include "mp_msg.h" #include "help_mp.h" +#include "reorder_copy.h" static ao_info_t info = @@ -200,6 +201,19 @@ } #endif + if (ao_data.channels == 6 || ao_data.channels == 5) { + int frame_size = le2me_16(wavhdr.bits) / 8; + len -= len % (frame_size * ao_data.channels); + if (ao_data.channels == 6) + reorder_channel(data, AF_CHANNEL_LAYOUT_MPLAYER_6CH_DEFAULT, + AF_CHANNEL_LAYOUT_WAVEEX_6CH_DEFAULT, + len / frame_size, frame_size); + else + reorder_channel(data, AF_CHANNEL_LAYOUT_MPLAYER_5CH_DEFAULT, + AF_CHANNEL_LAYOUT_WAVEEX_5CH_DEFAULT, + len / frame_size, frame_size); + } + //printf("PCM: Writing chunk!\n"); fwrite(data,len,1,fp); Index: Makefile =================================================================== --- Makefile (revision 25192) +++ Makefile (working copy) @@ -33,6 +33,7 @@ subopt-helper.c \ subreader.c \ vobsub.c \ + reorder_copy.c \ SRCS_COMMON-$(UNRARLIB) += unrarlib.c Index: reorder_copy.c =================================================================== --- reorder_copy.c (revision 0) +++ reorder_copy.c (revision 0) @@ -0,0 +1,898 @@ +#include +#include +#include +#include +#include "libvo/fastmemcpy.h" + +#include "reorder_copy.h" + +#ifdef TEST +#define mp_msg(mod,lev, fmt, args... ) printf( fmt, ## args ) +#else +#include "mp_msg.h" +#endif + +#define REORDER_COPY_5(DEST,SRC,SAMPLES,S0,S1,S2,S3,S4) \ +for (i = 0; i < SAMPLES; i += 5) {\ + DEST[i] = SRC[i+S0];\ + DEST[i+1] = SRC[i+S1];\ + DEST[i+2] = SRC[i+S2];\ + DEST[i+3] = SRC[i+S3];\ + DEST[i+4] = SRC[i+S4];\ +} + +#define REORDER_COPY_6(DEST,SRC,SAMPLES,S0,S1,S2,S3,S4,S5) \ +for (i = 0; i < SAMPLES; i += 6) {\ + DEST[i] = SRC[i+S0];\ + DEST[i+1] = SRC[i+S1];\ + DEST[i+2] = SRC[i+S2];\ + DEST[i+3] = SRC[i+S3];\ + DEST[i+4] = SRC[i+S4];\ + DEST[i+5] = SRC[i+S5];\ +} + +#define REORDER_COPY_5CH(DEST,SRC,SAMPLES,SAMPLESIZE,S0,S1,S2,S3,S4) \ +switch(SAMPLESIZE)\ +{\ + case 1:\ + {\ + int8_t *dest_8 = (int8_t *)(DEST);\ + const int8_t *src_8 = (const int8_t *)(SRC);\ + REORDER_COPY_5(dest_8,src_8,SAMPLES,S0,S1,S2,S3,S4); \ + break;\ + }\ + case 2:\ + {\ + int16_t *dest_16 = (int16_t *)(DEST);\ + const int16_t *src_16 = (const int16_t *)(SRC);\ + REORDER_COPY_5(dest_16,src_16,SAMPLES,S0,S1,S2,S3,S4); \ + break;\ + }\ + case 3:\ + {\ + int8_t *dest_8 = (int8_t *)(DEST);\ + const int8_t *src_8 = (const int8_t *)(SRC);\ + for (i = 0; i < SAMPLES; i += 15) {\ + }\ + dest_8[i] = src_8[i+S0*3];\ + dest_8[i+1] = src_8[i+S0*3+1];\ + dest_8[i+2] = src_8[i+S0*3+2];\ + dest_8[i+3] = src_8[i+S1*3];\ + dest_8[i+4] = src_8[i+S1*3+1];\ + dest_8[i+5] = src_8[i+S1*3+2];\ + dest_8[i+6] = src_8[i+S2*3];\ + dest_8[i+7] = src_8[i+S2*3+1];\ + dest_8[i+8] = src_8[i+S2*3+2];\ + dest_8[i+9] = src_8[i+S3*3];\ + dest_8[i+10] = src_8[i+S3*3+1];\ + dest_8[i+11] = src_8[i+S3*3+2];\ + dest_8[i+12] = src_8[i+S4*3];\ + dest_8[i+13] = src_8[i+S4*3+1];\ + dest_8[i+14] = src_8[i+S4*3+2];\ + }\ + case 4:\ + {\ + int32_t *dest_32 = (int32_t *)(DEST);\ + const int32_t *src_32 = (const int32_t *)(SRC);\ + REORDER_COPY_5(dest_32,src_32,SAMPLES,S0,S1,S2,S3,S4); \ + break;\ + }\ + case 8:\ + {\ + int64_t *dest_64 = (int64_t *)(DEST);\ + const int64_t *src_64 = (const int64_t *)(SRC);\ + REORDER_COPY_5(dest_64,src_64,SAMPLES,S0,S1,S2,S3,S4); \ + break;\ + }\ + default:\ + mp_msg(MSGT_GLOBAL, MSGL_WARN,\ + "[reorder_copy] Unsupported sample size: %d, please "\ + "report this error on the MPlayer mailing list.\n",SAMPLESIZE);\ +} + +#define REORDER_COPY_6CH(DEST,SRC,SAMPLES,SAMPLESIZE,S0,S1,S2,S3,S4,S5) \ +switch(SAMPLESIZE)\ +{\ + case 1:\ + {\ + int8_t *dest_8 = (int8_t *)(DEST);\ + const int8_t *src_8 = (const int8_t *)(SRC);\ + REORDER_COPY_6(dest_8,src_8,SAMPLES,S0,S1,S2,S3,S4,S5); \ + break;\ + }\ + case 2:\ + {\ + int16_t *dest_16 = (int16_t *)(DEST);\ + const int16_t *src_16 = (const int16_t *)(SRC);\ + REORDER_COPY_6(dest_16,src_16,SAMPLES,S0,S1,S2,S3,S4,S5); \ + break;\ + }\ + case 3:\ + {\ + int8_t *dest_8 = (int8_t *)(DEST);\ + const int8_t *src_8 = (const int8_t *)(SRC);\ + for (i = 0; i < SAMPLES; i += 18) {\ + }\ + dest_8[i] = src_8[i+S0*3];\ + dest_8[i+1] = src_8[i+S0*3+1];\ + dest_8[i+2] = src_8[i+S0*3+2];\ + dest_8[i+3] = src_8[i+S1*3];\ + dest_8[i+4] = src_8[i+S1*3+1];\ + dest_8[i+5] = src_8[i+S1*3+2];\ + dest_8[i+6] = src_8[i+S2*3];\ + dest_8[i+7] = src_8[i+S2*3+1];\ + dest_8[i+8] = src_8[i+S2*3+2];\ + dest_8[i+9] = src_8[i+S3*3];\ + dest_8[i+10] = src_8[i+S3*3+1];\ + dest_8[i+11] = src_8[i+S3*3+2];\ + dest_8[i+12] = src_8[i+S4*3];\ + dest_8[i+13] = src_8[i+S4*3+1];\ + dest_8[i+14] = src_8[i+S4*3+2];\ + dest_8[i+15] = src_8[i+S5*3];\ + dest_8[i+16] = src_8[i+S5*3+1];\ + dest_8[i+17] = src_8[i+S5*3+2];\ + }\ + case 4:\ + {\ + int32_t *dest_32 = (int32_t *)(DEST);\ + const int32_t *src_32 = (const int32_t *)(SRC);\ + REORDER_COPY_6(dest_32,src_32,SAMPLES,S0,S1,S2,S3,S4,S5); \ + break;\ + }\ + case 8:\ + {\ + int64_t *dest_64 = (int64_t *)(DEST);\ + const int64_t *src_64 = (const int64_t *)(SRC);\ + REORDER_COPY_6(dest_64,src_64,SAMPLES,S0,S1,S2,S3,S4,S5); \ + break;\ + }\ + default:\ + mp_msg(MSGT_GLOBAL, MSGL_WARN,\ + "[reorder_copy] Unsupported sample size: %d, please "\ + "report this error on the MPlayer mailing list.\n",SAMPLESIZE);\ +} + +void reorder_channel_copy(void *src, + int src_layout, + void *dest, + int dest_layout, + int samples, + int samplesize) +{ + int i; + if (dest_layout==src_layout) { + fast_memcpy(dest, src, samples*samplesize); + return; + } + if (!AF_IS_SAME_CH_NUM(dest_layout,src_layout)) { + mp_msg(MSGT_GLOBAL, MSGL_WARN, "[reorder_copy] different channel count " + "between src and dest: %x, %x\n", + AF_GET_CH_NUM_WITH_LFE(src_layout), + AF_GET_CH_NUM_WITH_LFE(dest_layout)); + return; + } + switch ((src_layout<<16)|dest_layout) { + // AF_CHANNEL_LAYOUT_5_0_A L R C Ls Rs + // AF_CHANNEL_LAYOUT_5_0_B L R Ls Rs C + // AF_CHANNEL_LAYOUT_5_0_C L C R Ls Rs + // AF_CHANNEL_LAYOUT_5_0_D C L R Ls Rs + case AF_CHANNEL_LAYOUT_5_0_A << 16 | AF_CHANNEL_LAYOUT_5_0_B: + REORDER_COPY_5CH(dest, src, samples, samplesize, 0, 1, 3, 4, 2); + break; + case AF_CHANNEL_LAYOUT_5_0_A << 16 | AF_CHANNEL_LAYOUT_5_0_C: + REORDER_COPY_5CH(dest, src, samples, samplesize, 0, 2, 1, 3, 4); + break; + case AF_CHANNEL_LAYOUT_5_0_A << 16 | AF_CHANNEL_LAYOUT_5_0_D: + REORDER_COPY_5CH(dest, src, samples, samplesize, 2, 0, 1, 3, 4); + break; + case AF_CHANNEL_LAYOUT_5_0_B << 16 | AF_CHANNEL_LAYOUT_5_0_A: + REORDER_COPY_5CH(dest, src, samples, samplesize, 0, 1, 4, 2, 3); + break; + case AF_CHANNEL_LAYOUT_5_0_B << 16 | AF_CHANNEL_LAYOUT_5_0_C: + REORDER_COPY_5CH(dest, src, samples, samplesize, 0, 4, 1, 2, 3); + break; + case AF_CHANNEL_LAYOUT_5_0_B << 16 | AF_CHANNEL_LAYOUT_5_0_D: + REORDER_COPY_5CH(dest, src, samples, samplesize, 4, 1, 2, 3, 4); + break; + case AF_CHANNEL_LAYOUT_5_0_C << 16 | AF_CHANNEL_LAYOUT_5_0_A: + REORDER_COPY_5CH(dest, src, samples, samplesize, 0, 2, 1, 3, 4); + break; + case AF_CHANNEL_LAYOUT_5_0_C << 16 | AF_CHANNEL_LAYOUT_5_0_B: + REORDER_COPY_5CH(dest, src, samples, samplesize, 0, 2, 3, 4, 1); + break; + case AF_CHANNEL_LAYOUT_5_0_C << 16 | AF_CHANNEL_LAYOUT_5_0_D: + REORDER_COPY_5CH(dest, src, samples, samplesize, 1, 0, 2, 3, 4); + break; + case AF_CHANNEL_LAYOUT_5_0_D << 16 | AF_CHANNEL_LAYOUT_5_0_A: + REORDER_COPY_5CH(dest, src, samples, samplesize, 1, 2, 0, 3, 4); + break; + case AF_CHANNEL_LAYOUT_5_0_D << 16 | AF_CHANNEL_LAYOUT_5_0_B: + REORDER_COPY_5CH(dest, src, samples, samplesize, 1, 2, 3, 4, 0); + break; + case AF_CHANNEL_LAYOUT_5_0_D << 16 | AF_CHANNEL_LAYOUT_5_0_C: + REORDER_COPY_5CH(dest, src, samples, samplesize, 1, 0, 2, 3, 4); + break; + // AF_CHANNEL_LAYOUT_5_1_A L R C LFE Ls Rs + // AF_CHANNEL_LAYOUT_5_1_B L R Ls Rs C LFE + // AF_CHANNEL_LAYOUT_5_1_C L C R Ls Rs LFE + // AF_CHANNEL_LAYOUT_5_1_D C L R Ls Rs LFE + case AF_CHANNEL_LAYOUT_5_1_A << 16 | AF_CHANNEL_LAYOUT_5_1_B: + REORDER_COPY_6CH(dest, src, samples, samplesize, 0, 1, 4, 5, 2, 3); + break; + case AF_CHANNEL_LAYOUT_5_1_A << 16 | AF_CHANNEL_LAYOUT_5_1_C: + REORDER_COPY_6CH(dest, src, samples, samplesize, 0, 2, 1, 4, 5, 3); + break; + case AF_CHANNEL_LAYOUT_5_1_A << 16 | AF_CHANNEL_LAYOUT_5_1_D: + REORDER_COPY_6CH(dest, src, samples, samplesize, 2, 0, 1, 4, 5, 3); + break; + case AF_CHANNEL_LAYOUT_5_1_B << 16 | AF_CHANNEL_LAYOUT_5_1_A: + REORDER_COPY_6CH(dest, src, samples, samplesize, 0, 1, 4, 5, 2, 3); + break; + case AF_CHANNEL_LAYOUT_5_1_B << 16 | AF_CHANNEL_LAYOUT_5_1_C: + REORDER_COPY_6CH(dest, src, samples, samplesize, 0, 4, 1, 2, 3, 5); + break; + case AF_CHANNEL_LAYOUT_5_1_B << 16 | AF_CHANNEL_LAYOUT_5_1_D: + REORDER_COPY_6CH(dest, src, samples, samplesize, 4, 1, 2, 3, 4, 5); + break; + case AF_CHANNEL_LAYOUT_5_1_C << 16 | AF_CHANNEL_LAYOUT_5_1_A: + REORDER_COPY_6CH(dest, src, samples, samplesize, 0, 2, 1, 5, 3, 4); + break; + case AF_CHANNEL_LAYOUT_5_1_C << 16 | AF_CHANNEL_LAYOUT_5_1_B: + REORDER_COPY_6CH(dest, src, samples, samplesize, 0, 2, 3, 4, 1, 5); + break; + case AF_CHANNEL_LAYOUT_5_1_C << 16 | AF_CHANNEL_LAYOUT_5_1_D: + REORDER_COPY_6CH(dest, src, samples, samplesize, 1, 0, 2, 3, 4, 5); + break; + case AF_CHANNEL_LAYOUT_5_1_D << 16 | AF_CHANNEL_LAYOUT_5_1_A: + REORDER_COPY_6CH(dest, src, samples, samplesize, 1, 2, 0, 5, 3, 4); + break; + case AF_CHANNEL_LAYOUT_5_1_D << 16 | AF_CHANNEL_LAYOUT_5_1_B: + REORDER_COPY_6CH(dest, src, samples, samplesize, 1, 2, 3, 4, 0, 5); + break; + case AF_CHANNEL_LAYOUT_5_1_D << 16 | AF_CHANNEL_LAYOUT_5_1_C: + REORDER_COPY_6CH(dest, src, samples, samplesize, 1, 0, 2, 3, 4, 5); + break; + default: + mp_msg(MSGT_GLOBAL, MSGL_WARN, "[reorder_channel_copy] unsupport " + "from %x to %x, %d * %d\n", src_layout, dest_layout, + samples, samplesize); + fast_memcpy(dest, src, samples*samplesize); + } +} + +#define REORDER_SELF_SWAP_2(SRC,TMP,SAMPLES,CHNUM,S0,S1) \ +for (i = 0; i < SAMPLES; i += CHNUM) {\ + TMP = SRC[i+S0];\ + SRC[i+S0] = SRC[i+S1];\ + SRC[i+S1] = TMP;\ +} + +#define REORDER_SELF_2(SRC,SAMPLES,SAMPLESIZE,CHNUM,S0,S1) \ +switch(SAMPLESIZE)\ +{\ + case 1:\ + {\ + int8_t *src_8 = (int8_t *)(SRC);\ + int8_t tmp;\ + REORDER_SELF_SWAP_2(src_8,tmp,SAMPLES,CHNUM,S0,S1); \ + break;\ + }\ + case 2:\ + {\ + int16_t *src_16 = (int16_t *)(SRC);\ + int16_t tmp;\ + REORDER_SELF_SWAP_2(src_16,tmp,SAMPLES,CHNUM,S0,S1); \ + break;\ + }\ + case 3:\ + {\ + int8_t *src_8 = (int8_t *)(SRC);\ + int8_t tmp0, tmp1, tmp2;\ + for (i = 0; i < SAMPLES; i += CHNUM*3) {\ + tmp0 = src_8[i+S0*3];\ + tmp1 = src_8[i+S0*3+1];\ + tmp2 = src_8[i+S0*3+2];\ + src_8[i+S0*3] = src_8[i+S1*3];\ + src_8[i+S0*3+1] = src_8[i+S1*3+1];\ + src_8[i+S0*3+2] = src_8[i+S1*3+2];\ + src_8[i+S1*3] = tmp0;\ + src_8[i+S1*3+1] = tmp1;\ + src_8[i+S1*3+2] = tmp2;\ + }\ + }\ + case 4:\ + {\ + int32_t *src_32 = (int32_t *)(SRC);\ + int32_t tmp;\ + REORDER_SELF_SWAP_2(src_32,tmp,SAMPLES,CHNUM,S0,S1); \ + break;\ + }\ + case 8:\ + {\ + int64_t *src_64 = (int64_t *)(SRC);\ + int64_t tmp;\ + REORDER_SELF_SWAP_2(src_64,tmp,SAMPLES,CHNUM,S0,S1); \ + break;\ + }\ + default:\ + mp_msg(MSGT_GLOBAL, MSGL_WARN,\ + "[reorder_copy] Unsupported sample size: %d, please "\ + "report this error on the MPlayer mailing list.\n",SAMPLESIZE);\ +} + +#define REORDER_SELF_SWAP_3(SRC,TMP,SAMPLES,CHNUM,S0,S1,S2) \ +for (i = 0; i < SAMPLES; i += CHNUM) {\ + TMP = SRC[i+S0];\ + SRC[i+S0] = SRC[i+S1];\ + SRC[i+S1] = SRC[i+S2];\ + SRC[i+S2] = TMP;\ +} + +#define REORDER_SELF_3(SRC,SAMPLES,SAMPLESIZE,CHNUM,S0,S1,S2) \ +switch(SAMPLESIZE)\ +{\ + case 1:\ + {\ + int8_t *src_8 = (int8_t *)(SRC);\ + int8_t tmp;\ + REORDER_SELF_SWAP_3(src_8,tmp,SAMPLES,CHNUM,S0,S1,S2); \ + break;\ + }\ + case 2:\ + {\ + int16_t *src_16 = (int16_t *)(SRC);\ + int16_t tmp;\ + REORDER_SELF_SWAP_3(src_16,tmp,SAMPLES,CHNUM,S0,S1,S2); \ + break;\ + }\ + case 3:\ + {\ + int8_t *src_8 = (int8_t *)(SRC);\ + int8_t tmp0, tmp1, tmp2;\ + for (i = 0; i < SAMPLES; i += CHNUM*3) {\ + tmp0 = src_8[i+S0*3];\ + tmp1 = src_8[i+S0*3+1];\ + tmp2 = src_8[i+S0*3+2];\ + src_8[i+S0*3] = src_8[i+S1*3];\ + src_8[i+S0*3+1] = src_8[i+S1*3+1];\ + src_8[i+S0*3+2] = src_8[i+S1*3+2];\ + src_8[i+S1*3] = src_8[i+S2*3];\ + src_8[i+S1*3+1] = src_8[i+S2*3+1];\ + src_8[i+S1*3+2] = src_8[i+S2*3+2];\ + src_8[i+S2*3] = tmp0;\ + src_8[i+S2*3+1] = tmp1;\ + src_8[i+S2*3+2] = tmp2;\ + }\ + }\ + case 4:\ + {\ + int32_t *src_32 = (int32_t *)(SRC);\ + int32_t tmp;\ + REORDER_SELF_SWAP_3(src_32,tmp,SAMPLES,CHNUM,S0,S1,S2); \ + break;\ + }\ + case 8:\ + {\ + int64_t *src_64 = (int64_t *)(SRC);\ + int64_t tmp;\ + REORDER_SELF_SWAP_3(src_64,tmp,SAMPLES,CHNUM,S0,S1,S2); \ + break;\ + }\ + default:\ + mp_msg(MSGT_GLOBAL, MSGL_WARN,\ + "[reorder_copy] Unsupported sample size: %d, please "\ + "report this error on the MPlayer mailing list.\n",SAMPLESIZE);\ +} + +#define REORDER_SELF_SWAP_4_STEP_1(SRC,TMP,SAMPLES,CHNUM,S0,S1,S2,S3) \ +for (i = 0; i < SAMPLES; i += CHNUM) {\ + TMP = SRC[i+S0];\ + SRC[i+S0] = SRC[i+S1];\ + SRC[i+S1] = SRC[i+S2];\ + SRC[i+S2] = SRC[i+S3];\ + SRC[i+S3] = TMP;\ +} + +#define REORDER_SELF_4_STEP_1(SRC,SAMPLES,SAMPLESIZE,CHNUM,S0,S1,S2,S3) \ +switch(SAMPLESIZE)\ +{\ + case 1:\ + {\ + int8_t *src_8 = (int8_t *)(SRC);\ + int8_t tmp;\ + REORDER_SELF_SWAP_4_STEP_1(src_8,tmp,SAMPLES,CHNUM,S0,S1,S2,S3); \ + break;\ + }\ + case 2:\ + {\ + int16_t *src_16 = (int16_t *)(SRC);\ + int16_t tmp;\ + REORDER_SELF_SWAP_4_STEP_1(src_16,tmp,SAMPLES,CHNUM,S0,S1,S2,S3); \ + break;\ + }\ + case 3:\ + {\ + int8_t *src_8 = (int8_t *)(SRC);\ + int8_t tmp0, tmp1, tmp2;\ + for (i = 0; i < SAMPLES; i += CHNUM*3) {\ + tmp0 = src_8[i+S0*3];\ + tmp1 = src_8[i+S0*3+1];\ + tmp2 = src_8[i+S0*3+2];\ + src_8[i+S0*3] = src_8[i+S1*3];\ + src_8[i+S0*3+1] = src_8[i+S1*3+1];\ + src_8[i+S0*3+2] = src_8[i+S1*3+2];\ + src_8[i+S1*3] = src_8[i+S2*3];\ + src_8[i+S1*3+1] = src_8[i+S2*3+1];\ + src_8[i+S1*3+2] = src_8[i+S2*3+2];\ + src_8[i+S2*3] = src_8[i+S3*3];\ + src_8[i+S2*3+1] = src_8[i+S3*3+1];\ + src_8[i+S2*3+2] = src_8[i+S3*3+2];\ + src_8[i+S3*3] = tmp0;\ + src_8[i+S3*3+1] = tmp1;\ + src_8[i+S3*3+2] = tmp2;\ + }\ + }\ + case 4:\ + {\ + int32_t *src_32 = (int32_t *)(SRC);\ + int32_t tmp;\ + REORDER_SELF_SWAP_4_STEP_1(src_32,tmp,SAMPLES,CHNUM,S0,S1,S2,S3); \ + break;\ + }\ + case 8:\ + {\ + int64_t *src_64 = (int64_t *)(SRC);\ + int64_t tmp;\ + REORDER_SELF_SWAP_4_STEP_1(src_64,tmp,SAMPLES,CHNUM,S0,S1,S2,S3); \ + break;\ + }\ + default:\ + mp_msg(MSGT_GLOBAL, MSGL_WARN,\ + "[reorder_copy] Unsupported sample size: %d, please "\ + "report this error on the MPlayer mailing list.\n",SAMPLESIZE);\ +} + +#define REORDER_SELF_SWAP_4_STEP_2(SRC,TMP,SAMPLES,CHNUM,S0,S1,S2,S3) \ +for (i = 0; i < SAMPLES; i += CHNUM) {\ + TMP = SRC[i+S0];\ + SRC[i+S0] = SRC[i+S2];\ + SRC[i+S2] = TMP;\ + TMP = SRC[i+S1];\ + SRC[i+S1] = SRC[i+S3];\ + SRC[i+S3] = TMP;\ +} + +#define REORDER_SELF_4_STEP_2(SRC,SAMPLES,SAMPLESIZE,CHNUM,S0,S1,S2,S3) \ +switch(SAMPLESIZE)\ +{\ + case 1:\ + {\ + int8_t *src_8 = (int8_t *)(SRC);\ + int8_t tmp;\ + REORDER_SELF_SWAP_4_STEP_2(src_8,tmp,SAMPLES,CHNUM,S0,S1,S2,S3); \ + break;\ + }\ + case 2:\ + {\ + int16_t *src_16 = (int16_t *)(SRC);\ + int16_t tmp;\ + REORDER_SELF_SWAP_4_STEP_2(src_16,tmp,SAMPLES,CHNUM,S0,S1,S2,S3); \ + break;\ + }\ + case 3:\ + {\ + int8_t *src_8 = (int8_t *)(SRC);\ + int8_t tmp0, tmp1, tmp2;\ + for (i = 0; i < SAMPLES; i += CHNUM*3) {\ + tmp0 = src_8[i+S0*3];\ + tmp1 = src_8[i+S0*3+1];\ + tmp2 = src_8[i+S0*3+2];\ + src_8[i+S0*3] = src_8[i+S2*3];\ + src_8[i+S0*3+1] = src_8[i+S2*3+1];\ + src_8[i+S0*3+2] = src_8[i+S2*3+2];\ + src_8[i+S2*3] = tmp0;\ + src_8[i+S2*3+1] = tmp1;\ + src_8[i+S2*3+2] = tmp2;\ + tmp0 = src_8[i+S1*3];\ + tmp1 = src_8[i+S1*3+1];\ + tmp2 = src_8[i+S1*3+2];\ + src_8[i+S1*3] = src_8[i+S3*3];\ + src_8[i+S1*3+1] = src_8[i+S3*3+1];\ + src_8[i+S1*3+2] = src_8[i+S3*3+2];\ + src_8[i+S3*3] = tmp0;\ + src_8[i+S3*3+1] = tmp1;\ + src_8[i+S3*3+2] = tmp2;\ + }\ + }\ + case 4:\ + {\ + int32_t *src_32 = (int32_t *)(SRC);\ + int32_t tmp;\ + REORDER_SELF_SWAP_4_STEP_2(src_32,tmp,SAMPLES,CHNUM,S0,S1,S2,S3); \ + break;\ + }\ + case 8:\ + {\ + int64_t *src_64 = (int64_t *)(SRC);\ + int64_t tmp;\ + REORDER_SELF_SWAP_4_STEP_2(src_64,tmp,SAMPLES,CHNUM,S0,S1,S2,S3); \ + break;\ + }\ + default:\ + mp_msg(MSGT_GLOBAL, MSGL_WARN,\ + "[reorder_copy] Unsupported sample size: %d, please "\ + "report this error on the MPlayer mailing list.\n",SAMPLESIZE);\ +} + +#define REORDER_SELF_SWAP_5_STEP_1(SRC,TMP,SAMPLES,CHNUM,S0,S1,S2,S3,S4) \ +for (i = 0; i < SAMPLES; i += CHNUM) {\ + TMP = SRC[i+S0];\ + SRC[i+S0] = SRC[i+S1];\ + SRC[i+S1] = SRC[i+S2];\ + SRC[i+S2] = SRC[i+S3];\ + SRC[i+S3] = SRC[i+S4];\ + SRC[i+S4] = TMP;\ +} + +#define REORDER_SELF_5_STEP_1(SRC,SAMPLES,SAMPLESIZE,CHNUM,S0,S1,S2,S3,S4) \ +switch(SAMPLESIZE)\ +{\ + case 1:\ + {\ + int8_t *src_8 = (int8_t *)(SRC);\ + int8_t tmp;\ + REORDER_SELF_SWAP_5_STEP_1(src_8,tmp,SAMPLES,CHNUM,S0,S1,S2,S3,S4); \ + break;\ + }\ + case 2:\ + {\ + int16_t *src_16 = (int16_t *)(SRC);\ + int16_t tmp;\ + REORDER_SELF_SWAP_5_STEP_1(src_16,tmp,SAMPLES,CHNUM,S0,S1,S2,S3,S4); \ + break;\ + }\ + case 3:\ + {\ + int8_t *src_8 = (int8_t *)(SRC);\ + int8_t tmp0, tmp1, tmp2;\ + for (i = 0; i < SAMPLES; i += CHNUM*3) {\ + tmp0 = src_8[i+S0*3];\ + tmp1 = src_8[i+S0*3+1];\ + tmp2 = src_8[i+S0*3+2];\ + src_8[i+S0*3] = src_8[i+S1*3];\ + src_8[i+S0*3+1] = src_8[i+S1*3+1];\ + src_8[i+S0*3+2] = src_8[i+S1*3+2];\ + src_8[i+S1*3] = src_8[i+S2*3];\ + src_8[i+S1*3+1] = src_8[i+S2*3+1];\ + src_8[i+S1*3+2] = src_8[i+S2*3+2];\ + src_8[i+S2*3] = src_8[i+S3*3];\ + src_8[i+S2*3+1] = src_8[i+S3*3+1];\ + src_8[i+S2*3+2] = src_8[i+S3*3+2];\ + src_8[i+S3*3] = src_8[i+S4*3];\ + src_8[i+S3*3+1] = src_8[i+S4*3+1];\ + src_8[i+S3*3+2] = src_8[i+S4*3+2];\ + src_8[i+S4*3] = tmp0;\ + src_8[i+S4*3+1] = tmp1;\ + src_8[i+S4*3+2] = tmp2;\ + }\ + }\ + case 4:\ + {\ + int32_t *src_32 = (int32_t *)(SRC);\ + int32_t tmp;\ + REORDER_SELF_SWAP_5_STEP_1(src_32,tmp,SAMPLES,CHNUM,S0,S1,S2,S3,S4); \ + break;\ + }\ + case 8:\ + {\ + int64_t *src_64 = (int64_t *)(SRC);\ + int64_t tmp;\ + REORDER_SELF_SWAP_5_STEP_1(src_64,tmp,SAMPLES,CHNUM,S0,S1,S2,S3,S4); \ + break;\ + }\ + default:\ + mp_msg(MSGT_GLOBAL, MSGL_WARN,\ + "[reorder_copy] Unsupported sample size: %d, please "\ + "report this error on the MPlayer mailing list.\n",SAMPLESIZE);\ +} + +#define REORDER_SELF_SWAP_2_3(SRC,TMP,SAMPLES,CHNUM,S0,S1,S2,S3,S4) \ +for (i = 0; i < SAMPLES; i += CHNUM) {\ + TMP = SRC[i+S0];\ + SRC[i+S0] = SRC[i+S1];\ + SRC[i+S1] = TMP;\ + TMP = SRC[i+S2];\ + SRC[i+S2] = SRC[i+S3];\ + SRC[i+S3] = SRC[i+S4];\ + SRC[i+S4] = TMP;\ +} + +#define REORDER_SELF_2_3(SRC,SAMPLES,SAMPLESIZE,CHNUM,S0,S1,S2,S3,S4) \ +switch(SAMPLESIZE)\ +{\ + case 1:\ + {\ + int8_t *src_8 = (int8_t *)(SRC);\ + int8_t tmp;\ + REORDER_SELF_SWAP_2_3(src_8,tmp,SAMPLES,CHNUM,S0,S1,S2,S3,S4); \ + break;\ + }\ + case 2:\ + {\ + int16_t *src_16 = (int16_t *)(SRC);\ + int16_t tmp;\ + REORDER_SELF_SWAP_2_3(src_16,tmp,SAMPLES,CHNUM,S0,S1,S2,S3,S4); \ + break;\ + }\ + case 3:\ + {\ + int8_t *src_8 = (int8_t *)(SRC);\ + int8_t tmp0, tmp1, tmp2;\ + for (i = 0; i < SAMPLES; i += CHNUM*3) {\ + tmp0 = src_8[i+S0*3];\ + tmp1 = src_8[i+S0*3+1];\ + tmp2 = src_8[i+S0*3+2];\ + src_8[i+S0*3] = src_8[i+S1*3];\ + src_8[i+S0*3+1] = src_8[i+S1*3+1];\ + src_8[i+S0*3+2] = src_8[i+S1*3+2];\ + src_8[i+S1*3] = tmp0;\ + src_8[i+S1*3+1] = tmp1;\ + src_8[i+S1*3+2] = tmp2;\ + tmp0 = src_8[i+S2*3];\ + tmp1 = src_8[i+S2*3+1];\ + tmp2 = src_8[i+S2*3+2];\ + src_8[i+S2*3] = src_8[i+S3*3];\ + src_8[i+S2*3+1] = src_8[i+S3*3+1];\ + src_8[i+S2*3+2] = src_8[i+S3*3+2];\ + src_8[i+S3*3] = src_8[i+S4*3];\ + src_8[i+S3*3+1] = src_8[i+S4*3+1];\ + src_8[i+S3*3+2] = src_8[i+S4*3+2];\ + src_8[i+S4*3] = tmp0;\ + src_8[i+S4*3+1] = tmp1;\ + src_8[i+S4*3+2] = tmp2;\ + }\ + }\ + case 4:\ + {\ + int32_t *src_32 = (int32_t *)(SRC);\ + int32_t tmp;\ + REORDER_SELF_SWAP_2_3(src_32,tmp,SAMPLES,CHNUM,S0,S1,S2,S3,S4); \ + break;\ + }\ + case 8:\ + {\ + int64_t *src_64 = (int64_t *)(SRC);\ + int64_t tmp;\ + REORDER_SELF_SWAP_2_3(src_64,tmp,SAMPLES,CHNUM,S0,S1,S2,S3,S4); \ + break;\ + }\ + default:\ + mp_msg(MSGT_GLOBAL, MSGL_WARN,\ + "[reorder_copy] Unsupported sample size: %d, please "\ + "report this error on the MPlayer mailing list.\n",SAMPLESIZE);\ +} + +#define REORDER_SELF_SWAP_3_3(SRC,TMP,SAMPLES,CHNUM,S0,S1,S2,S3,S4,S5) \ +for (i = 0; i < SAMPLES; i += CHNUM) {\ + TMP = SRC[i+S0];\ + SRC[i+S0] = SRC[i+S1];\ + SRC[i+S1] = SRC[i+S2];\ + SRC[i+S2] = TMP;\ + TMP = SRC[i+S3];\ + SRC[i+S3] = SRC[i+S4];\ + SRC[i+S4] = SRC[i+S5];\ + SRC[i+S5] = TMP;\ +} + +#define REORDER_SELF_3_3(SRC,SAMPLES,SAMPLESIZE,CHNUM,S0,S1,S2,S3,S4,S5) \ +switch(SAMPLESIZE)\ +{\ + case 1:\ + {\ + int8_t *src_8 = (int8_t *)(SRC);\ + int8_t tmp;\ + REORDER_SELF_SWAP_3_3(src_8,tmp,SAMPLES,CHNUM,S0,S1,S2,S3,S4,S5); \ + break;\ + }\ + case 2:\ + {\ + int16_t *src_16 = (int16_t *)(SRC);\ + int16_t tmp;\ + REORDER_SELF_SWAP_3_3(src_16,tmp,SAMPLES,CHNUM,S0,S1,S2,S3,S4,S5); \ + break;\ + }\ + case 3:\ + {\ + int8_t *src_8 = (int8_t *)(SRC);\ + int8_t tmp0, tmp1, tmp2;\ + for (i = 0; i < SAMPLES; i += CHNUM*3) {\ + tmp0 = src_8[i+S0*3];\ + tmp1 = src_8[i+S0*3+1];\ + tmp2 = src_8[i+S0*3+2];\ + src_8[i+S0*3] = src_8[i+S1*3];\ + src_8[i+S0*3+1] = src_8[i+S1*3+1];\ + src_8[i+S0*3+2] = src_8[i+S1*3+2];\ + src_8[i+S1*3] = src_8[i+S2*3];\ + src_8[i+S1*3+1] = src_8[i+S2*3+1];\ + src_8[i+S1*3+2] = src_8[i+S2*3+2];\ + src_8[i+S2*3] = tmp0;\ + src_8[i+S2*3+1] = tmp1;\ + src_8[i+S2*3+2] = tmp2;\ + tmp0 = src_8[i+S3*3];\ + tmp1 = src_8[i+S3*3+1];\ + tmp2 = src_8[i+S3*3+2];\ + src_8[i+S3*3] = src_8[i+S4*3];\ + src_8[i+S3*3+1] = src_8[i+S4*3+1];\ + src_8[i+S3*3+2] = src_8[i+S4*3+2];\ + src_8[i+S4*3] = src_8[i+S5*3];\ + src_8[i+S4*3+1] = src_8[i+S5*3+1];\ + src_8[i+S4*3+2] = src_8[i+S5*3+2];\ + src_8[i+S5*3] = tmp0;\ + src_8[i+S5*3+1] = tmp1;\ + src_8[i+S5*3+2] = tmp2;\ + }\ + }\ + case 4:\ + {\ + int32_t *src_32 = (int32_t *)(SRC);\ + int32_t tmp;\ + REORDER_SELF_SWAP_3_3(src_32,tmp,SAMPLES,CHNUM,S0,S1,S2,S3,S4,S5); \ + break;\ + }\ + case 8:\ + {\ + int64_t *src_64 = (int64_t *)(SRC);\ + int64_t tmp;\ + REORDER_SELF_SWAP_3_3(src_64,tmp,SAMPLES,CHNUM,S0,S1,S2,S3,S4,S5); \ + break;\ + }\ + default:\ + mp_msg(MSGT_GLOBAL, MSGL_WARN,\ + "[reorder_copy] Unsupported sample size: %d, please "\ + "report this error on the MPlayer mailing list.\n",SAMPLESIZE);\ +} + + +void reorder_channel(void *src, + int src_layout, + int dest_layout, + int samples, + int samplesize) +{ + int i; + if (dest_layout==src_layout) + return; + if (!AF_IS_SAME_CH_NUM(dest_layout,src_layout)) { + mp_msg(MSGT_GLOBAL, MSGL_WARN, + "[reorder_channel] different channel count " + "between current and target: %x, %x\n", + AF_GET_CH_NUM_WITH_LFE(src_layout), + AF_GET_CH_NUM_WITH_LFE(dest_layout)); + return; + } + switch ((src_layout<<16)|dest_layout) { + // AF_CHANNEL_LAYOUT_5_0_A L R C Ls Rs + // AF_CHANNEL_LAYOUT_5_0_B L R Ls Rs C + // AF_CHANNEL_LAYOUT_5_0_C L C R Ls Rs + // AF_CHANNEL_LAYOUT_5_0_D C L R Ls Rs + case AF_CHANNEL_LAYOUT_5_0_A << 16 | AF_CHANNEL_LAYOUT_5_0_B: + REORDER_SELF_3(src, samples, samplesize, 5, 2, 3, 4); + break; + case AF_CHANNEL_LAYOUT_5_0_A << 16 | AF_CHANNEL_LAYOUT_5_0_C: + REORDER_SELF_2(src, samples, samplesize, 5, 1, 2); + break; + case AF_CHANNEL_LAYOUT_5_0_A << 16 | AF_CHANNEL_LAYOUT_5_0_D: + REORDER_SELF_3(src, samples, samplesize, 5, 2, 1, 0); + break; + case AF_CHANNEL_LAYOUT_5_0_B << 16 | AF_CHANNEL_LAYOUT_5_0_A: + REORDER_SELF_3(src, samples, samplesize, 5, 4, 3, 2); + break; + case AF_CHANNEL_LAYOUT_5_0_B << 16 | AF_CHANNEL_LAYOUT_5_0_C: + REORDER_SELF_4_STEP_1(src, samples, samplesize, 5, 4, 3, 2, 1); + break; + case AF_CHANNEL_LAYOUT_5_0_B << 16 | AF_CHANNEL_LAYOUT_5_0_D: + REORDER_SELF_5_STEP_1(src, samples, samplesize, 5, 4, 3, 2, 1, 0); + break; + case AF_CHANNEL_LAYOUT_5_0_C << 16 | AF_CHANNEL_LAYOUT_5_0_A: + REORDER_SELF_2(src, samples, samplesize, 5, 1, 2); + break; + case AF_CHANNEL_LAYOUT_5_0_C << 16 | AF_CHANNEL_LAYOUT_5_0_B: + REORDER_SELF_4_STEP_1(src, samples, samplesize, 5, 1, 2, 3, 4); + break; + case AF_CHANNEL_LAYOUT_5_0_C << 16 | AF_CHANNEL_LAYOUT_5_0_D: + REORDER_SELF_2(src, samples, samplesize, 5, 0, 1); + break; + case AF_CHANNEL_LAYOUT_5_0_D << 16 | AF_CHANNEL_LAYOUT_5_0_A: + REORDER_SELF_3(src, samples, samplesize, 5, 0, 1, 2); + break; + case AF_CHANNEL_LAYOUT_5_0_D << 16 | AF_CHANNEL_LAYOUT_5_0_B: + REORDER_SELF_5_STEP_1(src, samples, samplesize, 5, 0, 1, 2, 3, 4); + break; + case AF_CHANNEL_LAYOUT_5_0_D << 16 | AF_CHANNEL_LAYOUT_5_0_C: + REORDER_SELF_2(src, samples, samplesize, 5, 0, 1); + break; + // AF_CHANNEL_LAYOUT_5_1_A L R C LFE Ls Rs + // AF_CHANNEL_LAYOUT_5_1_B L R Ls Rs C LFE + // AF_CHANNEL_LAYOUT_5_1_C L C R Ls Rs LFE + // AF_CHANNEL_LAYOUT_5_1_D C L R Ls Rs LFE + case AF_CHANNEL_LAYOUT_5_1_A << 16 | AF_CHANNEL_LAYOUT_5_1_B: + if (samplesize == 2 || samplesize == 4) { + REORDER_SELF_2(src, samples/2, samplesize*2, 3, 1, 2); + } + else { + REORDER_SELF_4_STEP_2(src, samples, samplesize, 6, 2, 3, 4, 5); + } + break; + case AF_CHANNEL_LAYOUT_5_1_A << 16 | AF_CHANNEL_LAYOUT_5_1_C: + REORDER_SELF_2_3(src, samples, samplesize, 6, 1, 2, 3, 4, 5); + break; + case AF_CHANNEL_LAYOUT_5_1_A << 16 | AF_CHANNEL_LAYOUT_5_1_D: + REORDER_SELF_3_3(src, samples, samplesize, 6, 2, 1, 0, 3, 4, 5); + break; + case AF_CHANNEL_LAYOUT_5_1_B << 16 | AF_CHANNEL_LAYOUT_5_1_A: + if (samplesize == 2 || samplesize == 4) { + REORDER_SELF_2(src, samples/2, samplesize*2, 3, 1, 2); + } + else { + REORDER_SELF_4_STEP_2(src, samples, samplesize, 6, 2, 3, 4, 5); + } + break; + case AF_CHANNEL_LAYOUT_5_1_B << 16 | AF_CHANNEL_LAYOUT_5_1_C: + REORDER_SELF_4_STEP_1(src, samples, samplesize, 6, 4, 3, 2, 1); + break; + case AF_CHANNEL_LAYOUT_5_1_B << 16 | AF_CHANNEL_LAYOUT_5_1_D: + REORDER_SELF_5_STEP_1(src, samples, samplesize, 6, 4, 3, 2, 1, 0); + break; + case AF_CHANNEL_LAYOUT_5_1_C << 16 | AF_CHANNEL_LAYOUT_5_1_A: + REORDER_SELF_2_3(src, samples, samplesize, 6, 1, 2, 5, 4, 3); + break; + case AF_CHANNEL_LAYOUT_5_1_C << 16 | AF_CHANNEL_LAYOUT_5_1_B: + REORDER_SELF_4_STEP_1(src, samples, samplesize, 6, 1, 2, 3, 4); + break; + case AF_CHANNEL_LAYOUT_5_1_C << 16 | AF_CHANNEL_LAYOUT_5_1_D: + REORDER_SELF_2(src, samples, samplesize, 6, 0, 1); + break; + case AF_CHANNEL_LAYOUT_5_1_D << 16 | AF_CHANNEL_LAYOUT_5_1_A: + REORDER_SELF_3_3(src, samples, samplesize, 6, 0, 1, 2, 5, 4, 3); + break; + case AF_CHANNEL_LAYOUT_5_1_D << 16 | AF_CHANNEL_LAYOUT_5_1_B: + REORDER_SELF_5_STEP_1(src, samples, samplesize, 6, 0, 1, 2, 3, 4); + break; + case AF_CHANNEL_LAYOUT_5_1_D << 16 | AF_CHANNEL_LAYOUT_5_1_C: + REORDER_SELF_2(src, samples, samplesize, 6, 0, 1); + break; + default: + mp_msg(MSGT_GLOBAL, MSGL_WARN, + "[reorder_channel] unsupported from %x to %x, %d * %d\n", + src_layout, dest_layout, samples, samplesize); + } +} + + +#ifdef TEST + +static void test_copy(int channels) { + int samples = 12*1024*1024; + int samplesize = 2; + int i; + unsigned char *bufin = malloc((samples+100)*samplesize); + unsigned char *bufout = malloc((samples+100)*samplesize); + memset(bufin, 0xFF, samples*samplesize); + for (i = 0;i < 100; ++i) + reorder_channel_copy(bufin, AF_CHANNEL_LAYOUT_AAC_6CH_DEFAULT, + bufout, AF_CHANNEL_LAYOUT_MPLAYER_6CH_DEFAULT, + samples, samplesize); + free(bufin); + free(bufout); +} + +int main(int argc, char *argv[]) { + int channels = 6; + if (argc > 1) + channels = atoi(argv[1]); + test_copy(channels); + return 0; +} + +#endif + Index: reorder_copy.h =================================================================== --- reorder_copy.h (revision 0) +++ reorder_copy.h (revision 0) @@ -0,0 +1,82 @@ +#ifndef REORDER_COPY_H +#define REORDER_COPY_H + +// L - left +// R - right +// C - center +// Ls - left surround +// Rs - right surround +// Cs - center surround +// Rls - rear left surround +// Rrs - rear right surround + +#define AF_LFE (1<<7) + +#define AF_CHANNEL_LAYOUT_MONO ((100<<8)|1) +#define AF_CHANNEL_LAYOUT_STEREO ((101<<8)|2) + +// MPEG defined layouts +#define AF_CHANNEL_LAYOUT_1_0 AF_CHANNEL_LAYOUT_MONO // C +#define AF_CHANNEL_LAYOUT_2_0 AF_CHANNEL_LAYOUT_STEREO // L R +#define AF_CHANNEL_LAYOUT_2_1 ((102<<8)|3) // L R LFE +#define AF_CHANNEL_LAYOUT_3_0_A ((103<<8)|3) // L R C +#define AF_CHANNEL_LAYOUT_3_0_B ((104<<8)|3) // C L R +#define AF_CHANNEL_LAYOUT_4_0_A ((105<<8)|4) // L R C Cs +#define AF_CHANNEL_LAYOUT_4_0_B ((106<<8)|4) // C L R Cs +#define AF_CHANNEL_LAYOUT_4_0_C ((107<<8)|4) // L R Ls Rs +#define AF_CHANNEL_LAYOUT_5_0_A ((108<<8)|5) // L R C Ls Rs +#define AF_CHANNEL_LAYOUT_5_0_B ((109<<8)|5) // L R Ls Rs C +#define AF_CHANNEL_LAYOUT_5_0_C ((110<<8)|5) // L C R Ls Rs +#define AF_CHANNEL_LAYOUT_5_0_D ((111<<8)|5) // C L R Ls Rs +#define AF_CHANNEL_LAYOUT_5_1_A ((112<<8)|6|AF_LFE) // L R C LFE Ls Rs +#define AF_CHANNEL_LAYOUT_5_1_B ((113<<8)|6|AF_LFE) // L R Ls Rs C 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_6_1_A ((116<<8)|7|AF_LFE) // L R C LFE Ls Rs Cs +#define AF_CHANNEL_LAYOUT_7_1_A ((117<<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_6CH_DEFAULT AF_CHANNEL_LAYOUT_5_1_B +#define AF_CHANNEL_LAYOUT_MPLAYER_5CH_DEFAULT AF_CHANNEL_LAYOUT_ALSA_5CH_DEFAULT +#define AF_CHANNEL_LAYOUT_MPLAYER_6CH_DEFAULT AF_CHANNEL_LAYOUT_ALSA_6CH_DEFAULT +#define AF_CHANNEL_LAYOUT_AAC_5CH_DEFAULT AF_CHANNEL_LAYOUT_5_0_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_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_AC3_6CH_DEFAULT AF_CHANNEL_LAYOUT_5_1_C + +#define AF_CHANNEL_MASK 0xFF +#define AF_GET_CH_NUM(A) ((A)&0x7F) +#define AF_GET_CH_NUM_WITH_LFE(A) ((A)&0xFF) +#define AF_IS_SAME_CH_NUM(A,B) (((A)&0xFF)==((B)&0xFF)) +#define AF_IS_LAYOUT_SPECIFIED(A) ((A)&0xFFFFF800) +#define AF_IS_LAYOUT_UNSPECIFIED(A) (!AF_IS_LAYOUT_SPECIFIED(A)) + +// For all channel numbers, maybe use to simple caller code in the future. +/* +#define AF_CHANNEL_LAYOUT_ALSA_DEFAULT 0 +#define AF_CHANNEL_LAYOUT_AAC_DEFAULT 1 +#define AF_CHANNEL_LAYOUT_WAVEEX_DEFAULT 2 +#define AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT AF_CHANNEL_LAYOUT_ALSA_DEFAULT +*/ + +/// Optimized channel reorder between channel layouts with same channel number. +void reorder_channel_copy(void *src, + int src_layout, + void *dest, + int dest_layout, + int samples, + int samplesize); + +/// Same with reorder_channel_copy, but work on single buffer. + +void reorder_channel(void *buf, + int src_layout, + int dest_layout, + int samples, + int samplesize); + + +#endif // REORDER_COPY_H