]> git.sesse.net Git - vlc/blobdiff - modules/audio_output/coreaudio.c
* modules/codec/ffmpeg/*: ported the ffmpeg audio and video decoders to the new api.
[vlc] / modules / audio_output / coreaudio.c
index 53c85c152dc418b84d1c0510bfc7496a527991e8..5b5318dedddc3cb338939489d33e70f3d7e99bd2 100644 (file)
@@ -2,7 +2,7 @@
  * coreaudio.c: CoreAudio output plugin
  *****************************************************************************
  * Copyright (C) 2002-2003 VideoLAN
- * $Id: coreaudio.c,v 1.1 2003/03/30 23:35:06 jlj Exp $
+ * $Id: coreaudio.c,v 1.6 2003/06/06 02:23:30 hartman Exp $
  *
  * Authors: Colin Delacroix <colin@zoy.org>
  *          Jon Lech Johansen <jon-vl@nanocrew.net>
@@ -215,14 +215,17 @@ static OSStatus StreamListener   ( AudioStreamID inStream,
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
-#define ADEV_TEXT N_("audio device")
+#define ADEV_TEXT N_("Audio device")
+#define ADEV_LONGTEXT N_("Choose a number corresponding to the number of an " \
+    "audio device, as listed in your 'audio device' menu. This device will " \
+    "then be used by default for audio playback.")
 
 vlc_module_begin();
     set_description( _("CoreAudio output") );
     set_capability( "audio output", 100 );
     set_callbacks( Open, Close );
     add_category_hint( N_("Audio"), NULL, VLC_FALSE );
-    add_integer( "coreaudio-dev", -1, NULL, ADEV_TEXT, ADEV_TEXT, VLC_FALSE ); 
+    add_integer( "coreaudio-dev", -1, NULL, ADEV_TEXT, ADEV_LONGTEXT, VLC_FALSE ); 
 vlc_module_end();
 
 /*****************************************************************************
@@ -337,6 +340,26 @@ static int Open( vlc_object_t * p_this )
 
         msg_Dbg( p_aout, "device buffer size set to: [%ld]", 
                  p_sys->i_buffer_size );
+
+        /* Set buffer frame size */
+        i_param_size = sizeof( p_aout->output.i_nb_samples );
+        err = AudioDeviceSetProperty( p_sys->devid, 0, 0, FALSE,
+                                      kAudioDevicePropertyBufferFrameSize,
+                                      i_param_size,
+                                      &p_aout->output.i_nb_samples );
+        if( err != noErr )
+        {
+            msg_Err( p_aout, "failed to set buffer frame size: [%4.4s]", 
+                     (char *)&err );
+            FreeDevice( p_aout );
+            FreeHardwareInfo( p_aout );
+            vlc_mutex_destroy( &p_sys->lock );
+            free( (void *)p_sys );
+            return( VLC_EGENERIC );
+        }
+
+        msg_Dbg( p_aout, "device buffer frame size set to: [%d]",
+                 p_aout->output.i_nb_samples );
     }
 
     switch( p_sys->stream_format.mFormatID )
@@ -412,26 +435,6 @@ static int Open( vlc_object_t * p_this )
         return( VLC_EGENERIC );
     }
 
-    /* Set buffer frame size */
-    i_param_size = sizeof( p_aout->output.i_nb_samples );
-    err = AudioDeviceSetProperty( p_sys->devid, 0, 0, FALSE,
-                                  kAudioDevicePropertyBufferFrameSize,
-                                  i_param_size,
-                                  &p_aout->output.i_nb_samples );
-    if( err != noErr )
-    {
-        msg_Err( p_aout, "failed to set buffer frame size: [%4.4s]", 
-                 (char *)&err );
-        FreeDevice( p_aout );
-        FreeHardwareInfo( p_aout );
-        vlc_mutex_destroy( &p_sys->lock );
-        free( (void *)p_sys );
-        return( VLC_EGENERIC );
-    }
-
-    msg_Dbg( p_aout, "device buffer frame size set to: [%d]",
-             p_aout->output.i_nb_samples );
-
     /* Add callback */
     err = AudioDeviceAddIOProc( p_sys->devid,
                                 (AudioDeviceIOProc)IOCallback,
@@ -586,6 +589,13 @@ static OSStatus IOCallback( AudioDeviceID inDevice,
 
     host_time.mFlags = kAudioTimeStampHostTimeValid;
     AudioDeviceTranslateTime( inDevice, inOutputTime, &host_time );
+
+#if 1
+    p_sys->clock_diff = - (mtime_t)
+        AudioConvertHostTimeToNanos( AudioGetCurrentHostTime() ) / 1000; 
+    p_sys->clock_diff += mdate();
+#endif
+
     current_date = p_sys->clock_diff +
                    AudioConvertHostTimeToNanos( host_time.mHostTime ) / 1000;
 
@@ -1119,14 +1129,7 @@ static int InitDevice( aout_instance_t * p_aout )
         return( VLC_ENOVAR );
     }
 
-    if( !sscanf( val.psz_string, "%d:", &i_option ) ||
-        p_sys->i_options <= i_option )
-    {
-        i_option = 0;
-    }
-
-    free( (void *)val.psz_string );
-
+    i_option = val.i_int;
     p_option = &p_sys->p_options[i_option];
     p_dev = &p_sys->p_devices[p_option->i_dev];
 
@@ -1450,7 +1453,7 @@ static void InitDeviceVar( aout_instance_t * p_aout, int i_option,
                            vlc_bool_t b_change )
 { 
     UInt32 i;
-    vlc_value_t val;
+    vlc_value_t val, text;
 
     struct aout_sys_t * p_sys = p_aout->output.p_sys;
 
@@ -1466,13 +1469,15 @@ static void InitDeviceVar( aout_instance_t * p_aout, int i_option,
         }
     }
 
-    var_Create( p_aout, "audio-device", VLC_VAR_STRING | 
-                                        VLC_VAR_HASCHOICE );
+    var_Create( p_aout, "audio-device", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
+    text.psz_string = _("Audio device");
+    var_Change( p_aout, "audio-device", VLC_VAR_SETTEXT, &text, NULL );
 
     for( i = 0; i < p_sys->i_options; i++ )
     {
-        val.psz_string = p_sys->p_options[i].sz_option;
-        var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE, &val );
+        text.psz_string = p_sys->p_options[i].sz_option;
+        val.i_int = i;
+        var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE, &val, &text );
 
         if( !b_change && i == (UInt32)i_option )
         {
@@ -1487,7 +1492,7 @@ static void InitDeviceVar( aout_instance_t * p_aout, int i_option,
 
     if( b_change )
     {
-        val.psz_string = p_sys->p_options[i_option].sz_option;
+        val.i_int = i_option;
         var_Set( p_aout, "audio-device", val );
     }