Permalink
Browse files

Add patch to set the used channel layout in MPlayer. Fixes wrong mult…

…ichannel layout with OS X's default ordering.
  • Loading branch information...
1 parent bac3ee4 commit aac9031bd3840f487d1a7e3d14e38ca90621ceca @sttz committed Oct 21, 2013
Showing with 95 additions and 0 deletions.
  1. +95 −0 patches/ao_coreaudio_set_channel_layout.patch
@@ -0,0 +1,95 @@
+Index: libao2/ao_coreaudio.c
+===================================================================
+--- libao2/ao_coreaudio.c (revision 36463)
++++ libao2/ao_coreaudio.c (working copy)
+@@ -412,14 +412,15 @@
+ static int init(int rate,int channels,int format,int flags)
+ {
+ AudioStreamBasicDescription inDesc;
+-ComponentDescription desc;
+-Component comp;
++AudioComponentDescription desc;
++AudioComponent comp;
+ AURenderCallbackStruct renderCallback;
+ OSStatus err;
+ UInt32 size, maxFrames, b_alive;
+ char *psz_name;
+ AudioDeviceID devid_def = 0;
+ int device_id, display_help = 0;
++AudioChannelLayout channelLayout;
+
+ const opt_t subopts[] = {
+ {"device_id", OPT_ARG_INT, &device_id, NULL},
+@@ -557,25 +558,22 @@
+ desc.componentFlags = 0;
+ desc.componentFlagsMask = 0;
+
+- comp = FindNextComponent(NULL, &desc); //Finds an component that meets the desc spec's
++ comp = AudioComponentFindNext(NULL, &desc); //Finds an component that meets the desc spec's
+ if (comp == NULL) {
+ ao_msg(MSGT_AO, MSGL_WARN, "Unable to find Output Unit component\n");
+ goto err_out;
+ }
+
+- err = OpenAComponent(comp, &(ao->theOutputUnit)); //gains access to the services provided by the component
++ err = AudioComponentInstanceNew(comp, &(ao->theOutputUnit));
+ if (err) {
+ ao_msg(MSGT_AO, MSGL_WARN, "Unable to open Output Unit component: [%4.4s]\n", (char *)&err);
+ goto err_out;
+ }
+
+- // Initialize AudioUnit
+- err = AudioUnitInitialize(ao->theOutputUnit);
+- if (err) {
+- ao_msg(MSGT_AO, MSGL_WARN, "Unable to initialize Output Unit component: [%4.4s]\n", (char *)&err);
+- goto err_out1;
+- }
++ //Set the Current Device to the Default Output Unit.
++ err = AudioUnitSetProperty(ao->theOutputUnit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &ao->i_selected_dev, sizeof(ao->i_selected_dev));
+
++ // Set input format
+ size = sizeof(AudioStreamBasicDescription);
+ err = AudioUnitSetProperty(ao->theOutputUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &inDesc, size);
+
+@@ -584,6 +582,31 @@
+ goto err_out2;
+ }
+
++ // Initialize AudioUnit
++ err = AudioUnitInitialize(ao->theOutputUnit);
++ if (err) {
++ ao_msg(MSGT_AO, MSGL_WARN, "Unable to initialize Output Unit component: [%4.4s]\n", (char *)&err);
++ goto err_out1;
++ }
++
++ // Set channel layout
++ if (channels == 5 || channels == 6 || channels == 8) {
++ memset(&channelLayout, 0, sizeof(channelLayout));
++ if (channels == 5) {
++ channelLayout.mChannelLayoutTag = kAudioChannelLayoutTag_MPEG_5_1_B;
++ } else if (channels == 6) {
++ channelLayout.mChannelLayoutTag = kAudioChannelLayoutTag_MPEG_5_0_B;
++ } else {
++ channelLayout.mChannelLayoutTag = kAudioChannelLayoutTag_Emagic_Default_7_1;
++ }
++ err = AudioUnitSetProperty(ao->theOutputUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Input, 0, &channelLayout, sizeof(channelLayout));
++
++ if (err) {
++ ao_msg(MSGT_AO, MSGL_WARN, "Unable to set channel layout: [%d]\n", err);
++ goto err_out1;
++ }
++ }
++
+ size = sizeof(UInt32);
+ err = AudioUnitGetProperty(ao->theOutputUnit, kAudioDevicePropertyBufferSize, kAudioUnitScope_Input, 0, &maxFrames, &size);
+
+@@ -593,9 +616,6 @@
+ goto err_out2;
+ }
+
+- //Set the Current Device to the Default Output Unit.
+- err = AudioUnitSetProperty(ao->theOutputUnit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &ao->i_selected_dev, sizeof(ao->i_selected_dev));
+-
+ ao->chunk_size = maxFrames;//*inDesc.mBytesPerFrame;
+
+ ao_data.samplerate = inDesc.mSampleRate;

0 comments on commit aac9031

Please sign in to comment.