]> git.sesse.net Git - vlc/blobdiff - modules/audio_output/auhal.c
For consistency, remove references to vlc from libvlc
[vlc] / modules / audio_output / auhal.c
index 0778ab77c752b151919355438216ea328123aa5c..4e14bde61edf521f2dbce9dc6919119e19900976 100644 (file)
@@ -30,6 +30,7 @@
 
 #include <vlc/vlc.h>
 #include <vlc/aout.h>
+#include <vlc_interaction.h>
 
 #include "aout_internal.h"
 
@@ -184,9 +185,9 @@ static int Open( vlc_object_t * p_this )
     aout_FormatPrint( p_aout, "VLC is looking for:", (audio_sample_format_t *)&p_aout->output.output );
     
     /* Persistent device variable */
-    if( var_Type( p_aout->p_vlc, "macosx-audio-device" ) == 0 )
+    if( var_Type( p_aout->p_libvlc, "macosx-audio-device" ) == 0 )
     {
-        var_Create( p_aout->p_vlc, "macosx-audio-device", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+        var_Create( p_aout->p_libvlc, "macosx-audio-device", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
     }
 
     /* Build a list of devices */
@@ -240,6 +241,9 @@ static int Open( vlc_object_t * p_this )
     if( p_sys->i_hog_pid != -1 && p_sys->i_hog_pid != getpid() )
     {
         msg_Err( p_aout, "Selected audio device is exclusively in use by another program." );
+        intf_UserFatal( p_aout, VLC_FALSE, _("Audio output failed"), 
+                        _("The selected audio output device is exclusively in "
+                          "use by another program.") );
         goto error;
     }
 
@@ -292,130 +296,149 @@ static int OpenAnalog( aout_instance_t *p_aout )
     }
 
     err = OpenAComponent( p_sys->au_component, &p_sys->au_unit );
-    if( err )
+    if( err != noErr )
     {
         msg_Warn( p_aout, "we cannot open our HAL component" );
         return VLC_FALSE;
     }
     
     /* Set the device we will use for this output unit */
-    verify_noerr( AudioUnitSetProperty( p_sys->au_unit,
+    err = AudioUnitSetProperty( p_sys->au_unit,
                          kAudioOutputUnitProperty_CurrentDevice,
                          kAudioUnitScope_Global,
                          0,
                          &p_sys->i_selected_dev,
-                         sizeof( AudioDeviceID )));
+                         sizeof( AudioDeviceID ));
+                         
+    if( err != noErr )
+    {
+        msg_Warn( p_aout, "we cannot select the audio device" );
+        return VLC_FALSE;
+    }
                          
     /* Get the current format */
     i_param_size = sizeof(AudioStreamBasicDescription);
 
-    verify_noerr( AudioUnitGetProperty( p_sys->au_unit,
+    err = AudioUnitGetProperty( p_sys->au_unit,
                                    kAudioUnitProperty_StreamFormat,
                                    kAudioUnitScope_Input,
                                    0,
                                    &DeviceFormat,
-                                   &i_param_size ));
+                                   &i_param_size );
                                    
-    msg_Dbg( p_aout, STREAM_FORMAT_MSG( "current format is: ", DeviceFormat ) );
+    if( err != noErr ) return VLC_FALSE;
+    else msg_Dbg( p_aout, STREAM_FORMAT_MSG( "current format is: ", DeviceFormat ) );
 
     /* Get the channel layout of the device side of the unit (vlc -> unit -> device) */
-    verify_noerr( AudioUnitGetPropertyInfo( p_sys->au_unit,
+    err = AudioUnitGetPropertyInfo( p_sys->au_unit,
                                    kAudioDevicePropertyPreferredChannelLayout,
                                    kAudioUnitScope_Output,
                                    0,
                                    &i_param_size,
-                                   NULL ));
+                                   NULL );
 
-    layout = (AudioChannelLayout *)malloc( i_param_size);
-
-    verify_noerr( AudioUnitGetProperty( p_sys->au_unit,
-                                   kAudioDevicePropertyPreferredChannelLayout,
-                                   kAudioUnitScope_Output,
-                                   0,
-                                   layout,
-                                   &i_param_size ));
-                                   
-    /* We need to "fill out" the ChannelLayout, because there are multiple ways that it can be set */
-    if( layout->mChannelLayoutTag == kAudioChannelLayoutTag_UseChannelBitmap)
-    {
-        /* bitmap defined channellayout */
-        verify_noerr( AudioFormatGetProperty( kAudioFormatProperty_ChannelLayoutForBitmap,
-                                sizeof( UInt32), &layout->mChannelBitmap,
-                                &i_param_size,
-                                layout ));
-    }
-    else if( layout->mChannelLayoutTag != kAudioChannelLayoutTag_UseChannelDescriptions )
-    {
-        /* layouttags defined channellayout */
-        verify_noerr( AudioFormatGetProperty( kAudioFormatProperty_ChannelLayoutForTag,
-                                sizeof( AudioChannelLayoutTag ), &layout->mChannelLayoutTag,
-                                &i_param_size,
-                                layout ));
-    }
-
-    msg_Dbg( p_aout, "layout of AUHAL has %d channels" , (int)layout->mNumberChannelDescriptions );
-    
-    /* Initialize the VLC core channel count */
-    p_aout->output.output.i_physical_channels = 0;
-    i_original = p_aout->output.output.i_original_channels & AOUT_CHAN_PHYSMASK;
-    
-    if( i_original == AOUT_CHAN_CENTER || layout->mNumberChannelDescriptions < 2 )
-    {
-        /* We only need Mono or cannot output more than 1 channel */
-        p_aout->output.output.i_physical_channels = AOUT_CHAN_CENTER;
-    }
-    else if( i_original == (AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT) || layout->mNumberChannelDescriptions < 3 )
-    {
-        /* We only need Stereo or cannot output more than 2 channels */
-        p_aout->output.output.i_physical_channels = AOUT_CHAN_RIGHT | AOUT_CHAN_LEFT;
-    }
-    else
+    if( err == noErr )
     {
-        /* We want more than stereo and we can do that */
-        for( i = 0; i < layout->mNumberChannelDescriptions; i++ )
+        layout = (AudioChannelLayout *)malloc( i_param_size);
+
+        verify_noerr( AudioUnitGetProperty( p_sys->au_unit,
+                                       kAudioDevicePropertyPreferredChannelLayout,
+                                       kAudioUnitScope_Output,
+                                       0,
+                                       layout,
+                                       &i_param_size ));
+                                       
+        /* We need to "fill out" the ChannelLayout, because there are multiple ways that it can be set */
+        if( layout->mChannelLayoutTag == kAudioChannelLayoutTag_UseChannelBitmap)
         {
-            msg_Dbg( p_aout, "this is channel: %d", (int)layout->mChannelDescriptions[i].mChannelLabel );
+            /* bitmap defined channellayout */
+            verify_noerr( AudioFormatGetProperty( kAudioFormatProperty_ChannelLayoutForBitmap,
+                                    sizeof( UInt32), &layout->mChannelBitmap,
+                                    &i_param_size,
+                                    layout ));
+        }
+        else if( layout->mChannelLayoutTag != kAudioChannelLayoutTag_UseChannelDescriptions )
+        {
+            /* layouttags defined channellayout */
+            verify_noerr( AudioFormatGetProperty( kAudioFormatProperty_ChannelLayoutForTag,
+                                    sizeof( AudioChannelLayoutTag ), &layout->mChannelLayoutTag,
+                                    &i_param_size,
+                                    layout ));
+        } 
+
+        msg_Dbg( p_aout, "layout of AUHAL has %d channels" , (int)layout->mNumberChannelDescriptions );
+        
+        /* Initialize the VLC core channel count */
+        p_aout->output.output.i_physical_channels = 0;
+        i_original = p_aout->output.output.i_original_channels & AOUT_CHAN_PHYSMASK;
+        
+        if( i_original == AOUT_CHAN_CENTER || layout->mNumberChannelDescriptions < 2 )
+        {
+            /* We only need Mono or cannot output more than 1 channel */
+            p_aout->output.output.i_physical_channels = AOUT_CHAN_CENTER;
+        }
+        else if( i_original == (AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT) || layout->mNumberChannelDescriptions < 3 )
+        {
+            /* We only need Stereo or cannot output more than 2 channels */
+            p_aout->output.output.i_physical_channels = AOUT_CHAN_RIGHT | AOUT_CHAN_LEFT;
+        }
+        else
+        {
+            /* We want more than stereo and we can do that */
+            for( i = 0; i < layout->mNumberChannelDescriptions; i++ )
+            {
+                msg_Dbg( p_aout, "this is channel: %d", (int)layout->mChannelDescriptions[i].mChannelLabel );
 
-            switch( layout->mChannelDescriptions[i].mChannelLabel )
+                switch( layout->mChannelDescriptions[i].mChannelLabel )
+                {
+                    case kAudioChannelLabel_Left:
+                        p_aout->output.output.i_physical_channels |= AOUT_CHAN_LEFT;
+                        continue;
+                    case kAudioChannelLabel_Right:
+                        p_aout->output.output.i_physical_channels |= AOUT_CHAN_RIGHT;
+                        continue;
+                    case kAudioChannelLabel_Center:
+                        p_aout->output.output.i_physical_channels |= AOUT_CHAN_CENTER;
+                        continue;
+                    case kAudioChannelLabel_LFEScreen:
+                        p_aout->output.output.i_physical_channels |= AOUT_CHAN_LFE;
+                        continue;
+                    case kAudioChannelLabel_LeftSurround:
+                        p_aout->output.output.i_physical_channels |= AOUT_CHAN_REARLEFT;
+                        continue;
+                    case kAudioChannelLabel_RightSurround:
+                        p_aout->output.output.i_physical_channels |= AOUT_CHAN_REARRIGHT;
+                        continue;
+                    case kAudioChannelLabel_RearSurroundLeft:
+                        p_aout->output.output.i_physical_channels |= AOUT_CHAN_MIDDLELEFT;
+                        continue;
+                    case kAudioChannelLabel_RearSurroundRight:
+                        p_aout->output.output.i_physical_channels |= AOUT_CHAN_MIDDLERIGHT;
+                        continue;
+                    case kAudioChannelLabel_CenterSurround:
+                        p_aout->output.output.i_physical_channels |= AOUT_CHAN_REARCENTER;
+                        continue;
+                    default:
+                        msg_Warn( p_aout, "unrecognized channel form provided by driver: %d", (int)layout->mChannelDescriptions[i].mChannelLabel );
+                }
+            }
+            if( p_aout->output.output.i_physical_channels == 0 )
             {
-                case kAudioChannelLabel_Left:
-                    p_aout->output.output.i_physical_channels |= AOUT_CHAN_LEFT;
-                    continue;
-                case kAudioChannelLabel_Right:
-                    p_aout->output.output.i_physical_channels |= AOUT_CHAN_RIGHT;
-                    continue;
-                case kAudioChannelLabel_Center:
-                    p_aout->output.output.i_physical_channels |= AOUT_CHAN_CENTER;
-                    continue;
-                case kAudioChannelLabel_LFEScreen:
-                    p_aout->output.output.i_physical_channels |= AOUT_CHAN_LFE;
-                    continue;
-                case kAudioChannelLabel_LeftSurround:
-                    p_aout->output.output.i_physical_channels |= AOUT_CHAN_REARLEFT;
-                    continue;
-                case kAudioChannelLabel_RightSurround:
-                    p_aout->output.output.i_physical_channels |= AOUT_CHAN_REARRIGHT;
-                    continue;
-                case kAudioChannelLabel_RearSurroundLeft:
-                    p_aout->output.output.i_physical_channels |= AOUT_CHAN_MIDDLELEFT;
-                    continue;
-                case kAudioChannelLabel_RearSurroundRight:
-                    p_aout->output.output.i_physical_channels |= AOUT_CHAN_MIDDLERIGHT;
-                    continue;
-                case kAudioChannelLabel_CenterSurround:
-                    p_aout->output.output.i_physical_channels |= AOUT_CHAN_REARCENTER;
-                    continue;
-                default:
-                    msg_Warn( p_aout, "Unrecognized channel form provided by driver: %d", (int)layout->mChannelDescriptions[i].mChannelLabel );
+                p_aout->output.output.i_physical_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT;
+                msg_Err( p_aout, "You should configure your speaker layout with Audio Midi Setup Utility in /Applications/Utilities. Now using Stereo mode." );
+                intf_UserFatal( p_aout, VLC_FALSE, _("Audio device is not configured"), 
+                                _("You should configure your speaker layout with "
+                                  "the \"Audio Midi Setup Utility\" in /Applications/"
+                                  "Utilities. Stereo mode is being used now.") );
             }
         }
-        if( p_aout->output.output.i_physical_channels == 0 )
-        {
-            p_aout->output.output.i_physical_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT;
-            msg_Err( p_aout, "You should configure your speaker layout with Audio Midi Setup Utility in /Applications/Utilities. Now using Stereo mode." );
-        }
+        if( layout ) free( layout );
+    }
+    else
+    {
+        msg_Warn( p_aout, "this driver does not support kAudioDevicePropertyPreferredChannelLayout. BAD DRIVER AUTHOR !!!" );
+        p_aout->output.output.i_physical_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT;
     }
-    if( layout ) free( layout );
 
     msg_Dbg( p_aout, "selected %d physical channels for device output", aout_FormatNbChannels( &p_aout->output.output ) );
     msg_Dbg( p_aout, "VLC will output: %s", aout_FormatPrintChannels( &p_aout->output.output ));
@@ -622,7 +645,7 @@ static int OpenSPDIF( aout_instance_t * p_aout )
     p_streams = (AudioStreamID *)malloc( i_param_size );
     if( p_streams == NULL )
     {
-        msg_Err( p_aout, "Out of memory" );
+        msg_Err( p_aout, "out of memory" );
         return VLC_FALSE;
     }
     
@@ -997,7 +1020,7 @@ static void Probe( aout_instance_t * p_aout )
             var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE, &val, &text );
             if( p_sys->i_default_dev == p_devices[i] && config_GetInt( p_aout, "spdif" ) )
             {
-                /* I we selected to prefer SPDIF output if available
+                /* We selected to prefer SPDIF output if available
                  * then this "dummy" entry should be selected */
                 var_Change( p_aout, "audio-device", VLC_VAR_SETDEFAULT, &val, NULL );
                 var_Set( p_aout, "audio-device", val );
@@ -1008,7 +1031,7 @@ static void Probe( aout_instance_t * p_aout )
     }
     
     /* If a device is already "preselected", then use this device */
-    var_Get( p_aout->p_vlc, "macosx-audio-device", &val );
+    var_Get( p_aout->p_libvlc, "macosx-audio-device", &val );
     if( val.i_int > 0 )
     {
         var_Change( p_aout, "audio-device", VLC_VAR_SETDEFAULT, &val, NULL );
@@ -1073,7 +1096,7 @@ static int AudioDeviceSupportsDigital( aout_instance_t *p_aout, AudioDeviceID i_
     p_streams = (AudioStreamID *)malloc( i_param_size );
     if( p_streams == NULL )
     {
-        msg_Err( p_aout, "Out of memory" );
+        msg_Err( p_aout, "out of memory" );
         return VLC_ENOMEM;
     }
     
@@ -1289,7 +1312,7 @@ static OSStatus RenderCallbackAnalog( vlc_object_t *_p_aout,
     if( p_sys->i_total_bytes > 0 )
     {
         i_mData_bytes = __MIN( p_sys->i_total_bytes - p_sys->i_read_bytes, ioData->mBuffers[0].mDataByteSize );
-        p_aout->p_vlc->pf_memcpy( ioData->mBuffers[0].mData, &p_sys->p_remainder_buffer[p_sys->i_read_bytes], i_mData_bytes );
+        p_aout->p_libvlc->pf_memcpy( ioData->mBuffers[0].mData, &p_sys->p_remainder_buffer[p_sys->i_read_bytes], i_mData_bytes );
         p_sys->i_read_bytes += i_mData_bytes;
         current_date += (mtime_t) ( (mtime_t) 1000000 / p_aout->output.output.i_rate ) *
                         ( i_mData_bytes / 4 / aout_FormatNbChannels( &p_aout->output.output )  ); // 4 is fl32 specific
@@ -1308,13 +1331,13 @@ static OSStatus RenderCallbackAnalog( vlc_object_t *_p_aout,
         {
             uint32_t i_second_mData_bytes = __MIN( p_buffer->i_nb_bytes, ioData->mBuffers[0].mDataByteSize - i_mData_bytes );
             
-            p_aout->p_vlc->pf_memcpy( (uint8_t *)ioData->mBuffers[0].mData + i_mData_bytes, p_buffer->p_buffer, i_second_mData_bytes );
+            p_aout->p_libvlc->pf_memcpy( (uint8_t *)ioData->mBuffers[0].mData + i_mData_bytes, p_buffer->p_buffer, i_second_mData_bytes );
             i_mData_bytes += i_second_mData_bytes;
 
             if( i_mData_bytes >= ioData->mBuffers[0].mDataByteSize )
             {
                 p_sys->i_total_bytes = p_buffer->i_nb_bytes - i_second_mData_bytes;
-                p_aout->p_vlc->pf_memcpy( p_sys->p_remainder_buffer, &p_buffer->p_buffer[i_second_mData_bytes], p_sys->i_total_bytes );
+                p_aout->p_libvlc->pf_memcpy( p_sys->p_remainder_buffer, &p_buffer->p_buffer[i_second_mData_bytes], p_sys->i_total_bytes );
             }
             else
             {
@@ -1326,7 +1349,7 @@ static OSStatus RenderCallbackAnalog( vlc_object_t *_p_aout,
         }
         else
         {
-             p_aout->p_vlc->pf_memset( (uint8_t *)ioData->mBuffers[0].mData +i_mData_bytes, 0, ioData->mBuffers[0].mDataByteSize - i_mData_bytes );
+             p_aout->p_libvlc->pf_memset( (uint8_t *)ioData->mBuffers[0].mData +i_mData_bytes, 0, ioData->mBuffers[0].mDataByteSize - i_mData_bytes );
              i_mData_bytes += ioData->mBuffers[0].mDataByteSize - i_mData_bytes;
         }
     }
@@ -1368,13 +1391,13 @@ static OSStatus RenderCallbackSPDIF( AudioDeviceID inDevice,
             msg_Warn( p_aout, "bytesize: %d nb_bytes: %d", (int)BUFFER.mDataByteSize, (int)p_buffer->i_nb_bytes );
         
         /* move data into output data buffer */
-        p_aout->p_vlc->pf_memcpy( BUFFER.mData,
+        p_aout->p_libvlc->pf_memcpy( BUFFER.mData,
                                   p_buffer->p_buffer, p_buffer->i_nb_bytes );
         aout_BufferFree( p_buffer );
     }
     else
     {
-        p_aout->p_vlc->pf_memset( BUFFER.mData, 0, BUFFER.mDataByteSize );
+        p_aout->p_libvlc->pf_memset( BUFFER.mData, 0, BUFFER.mDataByteSize );
     }
 #undef BUFFER
 
@@ -1437,7 +1460,7 @@ static int AudioDeviceCallback( vlc_object_t *p_this, const char *psz_variable,
                      vlc_value_t old_val, vlc_value_t new_val, void *param )
 {
     aout_instance_t *p_aout = (aout_instance_t *)p_this;
-    var_Set( p_aout->p_vlc, "macosx-audio-device", new_val );
+    var_Set( p_aout->p_libvlc, "macosx-audio-device", new_val );
     msg_Dbg( p_aout, "Set Device: %#x", new_val.i_int );
     return aout_ChannelsRestart( p_this, psz_variable, old_val, new_val, param );
 }