[vlc-commits] auhal: implement channel re-ordering for 6.1 and 7.1 setups (close #7783)

Felix Paul Kühne git at videolan.org
Fri Jan 25 13:24:16 CET 2013


vlc/vlc-2.0 | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Sat Dec 15 16:46:19 2012 +0100| [c8afad0f2771969ba1678d2818a92d67a40ac859] | committer: Felix Paul Kühne

auhal: implement channel re-ordering for 6.1 and 7.1 setups (close #7783)
(cherry picked from commit 5a946038b1775bcb884dc728663b4e54aa9b08dd)

Conflicts:
	modules/audio_output/auhal.c

> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.0.git/?a=commit;h=c8afad0f2771969ba1678d2818a92d67a40ac859
---

 NEWS                         |    1 +
 modules/audio_output/auhal.c |   58 +++++++++++++++++++++++++++++++++++-------
 2 files changed, 50 insertions(+), 9 deletions(-)

diff --git a/NEWS b/NEWS
index e7bf1f5..74f8c80 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,7 @@ Decoders:
  * Fix GPU decoding on Intel HD 2000/3000 cards on Windows
 
 Mac OS X:
+ * Fix speaker layout for 6.1 and 7.1 audio playback
  * Fix subtitle rendering resolution when using OS X's native fullscreen mode
  * Improve fullscreen controller time slider with larger click target
  * Fix listing of the lua interfaces (web, telnet and console)
diff --git a/modules/audio_output/auhal.c b/modules/audio_output/auhal.c
index 2a73ebf..f2a2390 100644
--- a/modules/audio_output/auhal.c
+++ b/modules/audio_output/auhal.c
@@ -79,6 +79,9 @@ struct aout_sys_t
     bool                        b_digital;           /* Are we running in digital mode? */
     mtime_t                     clock_diff;          /* Difference between VLC clock and Device clock */
 
+    uint8_t chans_to_reorder;                        /* do we need channel reordering */
+    uint8_t chan_table[AOUT_CHAN_MAX];
+
     /* AUHAL specific */
     Component                   au_component;        /* The Audiocomponent we use */
     AudioUnit                   au_unit;             /* The AudioUnit we use */
@@ -467,8 +470,10 @@ static int OpenAnalog( audio_output_t *p_aout )
     msg_Dbg( p_aout, "VLC will output: %s", aout_FormatPrintChannels( &p_aout->format ));
 
     memset (&new_layout, 0, sizeof(new_layout));
-    switch( aout_FormatNbChannels( &p_aout->format ) )
-    {
+
+    uint32_t chans_out[AOUT_CHAN_MAX];
+
+    switch(aout_FormatNbChannels(fmt)) {
         case 1:
             new_layout.mChannelLayoutTag = kAudioChannelLayoutTag_Mono;
             break;
@@ -520,12 +525,37 @@ static int OpenAnalog( audio_output_t *p_aout )
             }
             break;
         case 7:
-            /* FIXME: This is incorrect. VLC uses the internal ordering: L R Lm Rm Lr Rr C LFE but this is wrong */
-            new_layout.mChannelLayoutTag = kAudioChannelLayoutTag_MPEG_6_1_A; // L R C LFE Ls Rs Cs
+            new_layout.mChannelLayoutTag = kAudioChannelLayoutTag_MPEG_6_1_A;
+
+            chans_out[0] = AOUT_CHAN_LEFT;
+            chans_out[1] = AOUT_CHAN_RIGHT;
+            chans_out[2] = AOUT_CHAN_CENTER;
+            chans_out[3] = AOUT_CHAN_LFE;
+            chans_out[4] = AOUT_CHAN_REARLEFT;
+            chans_out[5] = AOUT_CHAN_REARRIGHT;
+            chans_out[6] = AOUT_CHAN_REARCENTER;
+
+            p_aout->sys->chans_to_reorder = aout_CheckChannelReorder( NULL, chans_out, fmt->i_physical_channels, p_aout->sys->chan_table );
+            if (p_aout->sys->chans_to_reorder)
+                msg_Dbg( p_aout, "channel reordering needed" );
+
             break;
         case 8:
-            /* FIXME: This is incorrect. VLC uses the internal ordering: L R Lm Rm Lr Rr C LFE but this is wrong */
-            new_layout.mChannelLayoutTag = kAudioChannelLayoutTag_MPEG_7_1_A; // L R C LFE Ls Rs Lc Rc
+            new_layout.mChannelLayoutTag = kAudioChannelLayoutTag_MPEG_7_1_A;
+
+            chans_out[0] = AOUT_CHAN_LEFT;
+            chans_out[1] = AOUT_CHAN_RIGHT;
+            chans_out[2] = AOUT_CHAN_CENTER;
+            chans_out[3] = AOUT_CHAN_LFE;
+            chans_out[4] = AOUT_CHAN_MIDDLELEFT;
+            chans_out[5] = AOUT_CHAN_MIDDLERIGHT;
+            chans_out[6] = AOUT_CHAN_REARLEFT;
+            chans_out[7] = AOUT_CHAN_REARRIGHT;
+
+            p_aout->sys->chans_to_reorder = aout_CheckChannelReorder( NULL, chans_out, fmt->i_physical_channels, p_aout->sys->chan_table );
+            if (p_aout->sys->chans_to_reorder)
+                msg_Dbg( p_aout, "channel reordering needed" );
+
             break;
     }
 
@@ -590,8 +620,8 @@ static int OpenAnalog( audio_output_t *p_aout )
     /* Set the new_layout as the layout VLC will use to feed the AU unit */
     verify_noerr( AudioUnitSetProperty( p_sys->au_unit,
                             kAudioUnitProperty_AudioChannelLayout,
-                            kAudioUnitScope_Input,
-                            0, &new_layout, sizeof(new_layout) ) );
+                            kAudioUnitScope_Output,
+                            0, &new_layout, sizeof(new_layout)));
 
     if( new_layout.mNumberChannelDescriptions > 0 )
         free( new_layout.mChannelDescriptions );
@@ -1344,7 +1374,17 @@ static OSStatus RenderCallbackAnalog( vlc_object_t *_p_aout,
 
         if( p_buffer != NULL )
         {
-            uint32_t i_second_mData_bytes = __MIN( p_buffer->i_buffer, ioData->mBuffers[0].mDataByteSize - i_mData_bytes );
+            /* Do the channel reordering */
+            if (p_buffer && p_sys->chans_to_reorder)
+            {
+                aout_ChannelReorder(p_buffer->p_buffer,
+                                    p_buffer->i_buffer,
+                                    p_sys->chans_to_reorder,
+                                    p_sys->chan_table,
+                                    32);
+            }
+
+            uint32_t i_second_mData_bytes = __MIN(p_buffer->i_buffer, ioData->mBuffers[0].mDataByteSize - i_mData_bytes);
 
             vlc_memcpy( (uint8_t *)ioData->mBuffers[0].mData + i_mData_bytes,
                         p_buffer->p_buffer, i_second_mData_bytes );



More information about the vlc-commits mailing list