]> git.sesse.net Git - vlc/blobdiff - modules/audio_output/alsa.c
Do not try to access other's filters
[vlc] / modules / audio_output / alsa.c
index 5042a0e8081f261581a1cb7b880bba378ea86ebb..35df6846ce3384b991fece91f4e4d7e73fe38825 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
+#include <vlc/vlc.h>
+
+#include <stdio.h>
 #include <errno.h>                                                 /* ENOMEM */
 #include <string.h>                                            /* strerror() */
 #include <stdlib.h>                            /* calloc(), malloc(), free() */
+#include <vlc_interface.h>
 
-#include <vlc/vlc.h>
-
-#include <vlc/aout.h>
-
-#include "aout_internal.h"
+#include <vlc_aout.h>
 
 /* ALSA part
    Note: we use the new API which is available since 0.9.0beta10a. */
@@ -201,7 +201,7 @@ static void Probe( aout_instance_t * p_aout,
                     break;
                 case 6:
                     val.i_int = AOUT_VAR_5_1;
-                    text.psz_string = N_("5.1");
+                    text.psz_string = "5.1";
                     var_Change( p_aout, "audio-device",
                                 VLC_VAR_ADDCHOICE, &val, &text );
                     break;
@@ -225,7 +225,7 @@ static void Probe( aout_instance_t * p_aout,
                 var_Set( p_aout, "audio-device", val );
             }
         }
-        
+
         /* Close the previously opened device */
         snd_pcm_close( p_sys->p_snd_pcm );
     }
@@ -322,6 +322,9 @@ static int Open( vlc_object_t *p_this )
     if( (psz_device = config_GetPsz( p_aout, "alsadev" )) == NULL )
     {
         msg_Err( p_aout, "no audio device given (maybe \"default\" ?)" );
+        intf_UserFatal( p_aout, VLC_FALSE, _("No Audio Device"), 
+                        _("No audio device name was given. You might want to " \
+                          "enter \"default\".") );
         free( p_sys );
         return VLC_EGENERIC;
     }
@@ -354,7 +357,7 @@ static int Open( vlc_object_t *p_this )
 
     /* Choose the linear PCM format (read the comment above about FPU
        and float32) */
-    if( p_aout->p_libvlc->i_cpu & CPU_CAPABILITY_FPU )
+    if( vlc_CPU() & CPU_CAPABILITY_FPU )
     {
         i_vlc_pcm_format = VLC_FOURCC('f','l','3','2');
         i_snd_pcm_format = SND_PCM_FORMAT_FLOAT;
@@ -427,6 +430,9 @@ static int Open( vlc_object_t *p_this )
         {
             msg_Err( p_aout, "cannot open ALSA device `%s' (%s)",
                              psz_iec_device, snd_strerror( i_snd_rc ) );
+            intf_UserFatal( p_aout, VLC_FALSE, _("Audio output failed"), 
+                            _("VLC could not open the ALSA device \"%s\" (%s)."),
+                            psz_iec_device, snd_strerror( i_snd_rc ) );
             free( p_sys );
             free( psz_device );
             return VLC_EGENERIC;
@@ -459,8 +465,14 @@ static int Open( vlc_object_t *p_this )
                    SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK ) ) == -EBUSY )
             {
                 if( i ) msleep( 100000 /* 100ms */ );
-                else msg_Err( p_aout, "audio device: %s is already in use",
+                else
+                {
+                    msg_Err( p_aout, "audio device: %s is already in use",
                               psz_device );
+                    intf_UserFatal( p_aout, VLC_FALSE, _("Audio output failed"), 
+                                    _("The audio device \"%s\" is already in use."),
+                                    psz_device );
+                }
                 continue;
             }
             break;
@@ -469,6 +481,9 @@ static int Open( vlc_object_t *p_this )
         {
             msg_Err( p_aout, "cannot open ALSA device `%s' (%s)",
                              psz_device, snd_strerror( i_snd_rc ) );
+            intf_UserFatal( p_aout, VLC_FALSE, _("Audio output failed"), 
+                            _("VLC could not open the ALSA device \"%s\" (%s)."),
+                            psz_device, snd_strerror( i_snd_rc ) );
             free( p_sys );
             free( psz_device );
             return VLC_EGENERIC;
@@ -566,9 +581,9 @@ static int Open( vlc_object_t *p_this )
 #endif
         if( i_snd_rc < 0 || p_aout->output.output.i_rate != i_old_rate )
         {
-            msg_Warn( p_aout, "The rate %d Hz is not supported by your hardware. "
-                  "Using %d Hz instead.\n", i_old_rate,
-                  p_aout->output.output.i_rate );
+            msg_Warn( p_aout, "The rate %d Hz is not supported by your " \
+                "hardware. Using %d Hz instead.\n", i_old_rate, \
+                p_aout->output.output.i_rate );
         }
 
         /* Set buffer size. */
@@ -710,7 +725,7 @@ static void Close( vlc_object_t *p_this )
     vlc_cond_signal( &p_aout->output.p_sys->wait );
     vlc_mutex_unlock( &p_aout->output.p_sys->lock );
 
-    p_aout->b_die = VLC_TRUE;
+    vlc_object_kill( p_aout );
     vlc_thread_join( p_aout );
     p_aout->b_die = VLC_FALSE;
 
@@ -761,10 +776,8 @@ static int ALSAThread( aout_instance_t * p_aout )
 static void ALSAFill( aout_instance_t * p_aout )
 {
     struct aout_sys_t * p_sys = p_aout->output.p_sys;
-
     aout_buffer_t * p_buffer;
     snd_pcm_status_t * p_status = p_sys->p_status;
-    snd_timestamp_t ts_next;
     int i_snd_rc;
     mtime_t next_date;
 
@@ -789,7 +802,7 @@ static void ALSAFill( aout_instance_t * p_aout )
 
             if( i_snd_rc == 0 )
             {
-                msg_Warn( p_aout, "recovered from buffer underrun" );
+                msg_Dbg( p_aout, "recovered from buffer underrun" );
 
                 /* Reget the status */
                 i_snd_rc = snd_pcm_status( p_sys->p_snd_pcm, p_status );
@@ -818,6 +831,8 @@ static void ALSAFill( aout_instance_t * p_aout )
             /* Here the device should be either in the RUNNING state.
              * p_status is valid. */
 
+#if 0
+    /* This apparently does not work correctly in Alsa 1.0.11 */
             snd_pcm_status_get_tstamp( p_status, &ts_next );
             next_date = (mtime_t)ts_next.tv_sec * 1000000 + ts_next.tv_usec;
             if( next_date )
@@ -826,19 +841,15 @@ static void ALSAFill( aout_instance_t * p_aout )
                         * 1000000 / p_aout->output.output.i_rate;
             }
             else
+#endif
             {
                 /* With screwed ALSA drivers the timestamp is always zero;
                  * use another method then */
-                snd_pcm_sframes_t delay;
-                ssize_t i_bytes = 0;
+                snd_pcm_sframes_t delay = 0;
 
-                if( !snd_pcm_delay( p_sys->p_snd_pcm, &delay ) )
-                {
-                    i_bytes = snd_pcm_frames_to_bytes(p_sys->p_snd_pcm, delay);
-                }
-                next_date = mdate() + (mtime_t)i_bytes * 1000000
-                        / p_aout->output.output.i_bytes_per_frame
-                        / p_aout->output.output.i_rate
+                snd_pcm_delay( p_sys->p_snd_pcm, &delay );
+                next_date = mdate() + (mtime_t)(delay) * 1000000 /
+                          p_aout->output.output.i_rate
                         * p_aout->output.output.i_frame_length;
             }
         }
@@ -971,7 +982,6 @@ static void GetDevicesForCard(module_config_t *p_item, int i_card)
         p_item->i_list++;
         p_item->ppsz_list[ p_item->i_list ] = NULL;
         p_item->ppsz_list_text[ p_item->i_list ] = NULL;
-                
     }
 
     snd_ctl_close( p_ctl );