* AudioOutput.cpp: send zeros to BSoundPlayer if nothing comes from
authorEric Petit <titer@videolan.org>
Mon, 9 Dec 2002 07:57:04 +0000 (07:57 +0000)
committerEric Petit <titer@videolan.org>
Mon, 9 Dec 2002 07:57:04 +0000 (07:57 +0000)
    audio output;
 * VlcWrapper.cpp: handle volume using aout3 features.

modules/gui/beos/AudioOutput.cpp
modules/gui/beos/InterfaceWindow.cpp
modules/gui/beos/PlayListWindow.cpp
modules/gui/beos/VlcWrapper.cpp
modules/gui/beos/VlcWrapper.h

index 1c62e89..5606d65 100644 (file)
@@ -2,7 +2,7 @@
  * AudioOutput.cpp: BeOS audio output
  *****************************************************************************
  * Copyright (C) 1999, 2000, 2001 VideoLAN
- * $Id: AudioOutput.cpp,v 1.18 2002/11/27 06:27:52 titer Exp $
+ * $Id: AudioOutput.cpp,v 1.19 2002/12/09 07:57:04 titer Exp $
  *
  * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
  *          Samuel Hocevar <sam@zoy.org>
@@ -135,10 +135,19 @@ static void Play( void *aout, void *p_buffer, size_t i_size,
 
     if( p_aout_buffer != NULL )
     {
-       memcpy( (float*)p_buffer,
-               p_aout_buffer->p_buffer,
-               MIN( BUFFER_SIZE, p_aout_buffer->i_nb_bytes ) );
-       aout_BufferFree( p_aout_buffer );
+        memcpy( (float*)p_buffer,
+                p_aout_buffer->p_buffer,
+                MIN( BUFFER_SIZE, p_aout_buffer->i_nb_bytes ) );
+        if( p_aout_buffer->i_nb_bytes < BUFFER_SIZE )
+        {
+            memset( (float*)p_buffer + p_aout_buffer->i_nb_bytes,
+                    0, BUFFER_SIZE - p_aout_buffer->i_nb_bytes );
+        }
+        aout_BufferFree( p_aout_buffer );
+    }
+    else
+    {
+        memset( (float*)p_buffer, 0, BUFFER_SIZE );
     }
 }
 
index afb96f5..049d049 100644 (file)
@@ -2,7 +2,7 @@
  * InterfaceWindow.cpp: beos interface
  *****************************************************************************
  * Copyright (C) 1999, 2000, 2001 VideoLAN
- * $Id: InterfaceWindow.cpp,v 1.11 2002/12/04 02:16:23 titer Exp $
+ * $Id: InterfaceWindow.cpp,v 1.12 2002/12/09 07:57:04 titer Exp $
  *
  * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
  *          Samuel Hocevar <sam@zoy.org>
@@ -264,7 +264,6 @@ void InterfaceWindow::MessageReceived( BMessage * p_message )
                        // this currently stops playback not nicely
                        if (playback_status > UNDEF_S)
                        {
-                               p_wrapper->volume_mute();
                                snooze( 400000 );
                                p_wrapper->PlaylistStop();
                                p_mediaControl->SetStatus(NOT_STARTED_S, DEFAULT_RATE);
@@ -281,13 +280,10 @@ void InterfaceWindow::MessageReceived( BMessage * p_message )
                                /* pause if currently playing */
                                if ( playback_status == PLAYING_S )
                                {
-                                       p_wrapper->volume_mute();
-                                       snooze( 400000 );
                                        p_wrapper->PlaylistPause();
                                }
                                else
                                {
-                                       p_wrapper->volume_restore();
                                        p_wrapper->PlaylistPlay();
                                }
                        }
@@ -302,8 +298,6 @@ void InterfaceWindow::MessageReceived( BMessage * p_message )
                        /* cycle the fast playback modes */
                        if (playback_status > UNDEF_S)
                        {
-                               p_wrapper->volume_mute();
-                               snooze( 400000 );
                                p_wrapper->InputFaster();
                        }
                        break;
@@ -312,8 +306,6 @@ void InterfaceWindow::MessageReceived( BMessage * p_message )
                        /*  cycle the slow playback modes */
                        if (playback_status > UNDEF_S)
                        {
-                               p_wrapper->volume_mute();
-                               snooze( 400000 );
                                p_wrapper->InputSlower();
                        }
                        break;
@@ -322,7 +314,6 @@ void InterfaceWindow::MessageReceived( BMessage * p_message )
                        /*  restore speed to normal if already playing */
                        if (playback_status > UNDEF_S)
                        {
-                               p_wrapper->volume_restore();
                                p_wrapper->PlaylistPlay();
                        }
                        break;
@@ -335,15 +326,18 @@ void InterfaceWindow::MessageReceived( BMessage * p_message )
                        /* adjust the volume */
                        if (playback_status > UNDEF_S)
                        {
-                               p_wrapper->set_volume( p_mediaControl->GetVolume() );
-                               p_mediaControl->SetMuted( p_wrapper->is_muted() );
+                               p_wrapper->SetVolume( p_mediaControl->GetVolume() );
+                               p_mediaControl->SetMuted( p_wrapper->IsMuted() );
                        }
                        break;
        
                case VOLUME_MUTE:
                        // toggle muting
-                       p_wrapper->toggle_mute();
-                       p_mediaControl->SetMuted( p_wrapper->is_muted() );
+                       if( p_wrapper->IsMuted() )
+                           p_wrapper->VolumeRestore();
+                       else
+                           p_wrapper->VolumeMute();
+                       p_mediaControl->SetMuted( p_wrapper->IsMuted() );
                        break;
        
                case SELECT_CHANNEL:
@@ -353,13 +347,6 @@ void InterfaceWindow::MessageReceived( BMessage * p_message )
                                if ( p_message->FindInt32( "channel", &channel ) == B_OK )
                                {
                                        p_wrapper->toggleLanguage( channel );
-                                       // vlc seems to remember the volume for every channel,
-                                       // but I would assume that to be somewhat annoying to the user
-                                       // the next call will also unmute the volume, which is probably
-                                       // desired as well, because if the user selects another language,
-                                       // he probably wants to hear the change as well
-                                       snooze( 400000 );       // we have to wait a bit, or the change will be reverted
-                                       p_wrapper->set_volume( p_mediaControl->GetVolume() );
                                }
                        }
                        break;
@@ -510,10 +497,10 @@ void InterfaceWindow::updateInterface()
                        p_wrapper->getNavCapabilities( &canSkipPrev, &canSkipNext );
                        p_mediaControl->SetSkippable( canSkipPrev, canSkipNext );
 
-                       if ( p_wrapper->has_audio() )
+                       if ( p_wrapper->HasAudio() )
                        {
                                p_mediaControl->SetAudioEnabled( true );
-                               p_mediaControl->SetMuted( p_wrapper->is_muted() );
+                               p_mediaControl->SetMuted( p_wrapper->IsMuted() );
                        } else
                                p_mediaControl->SetAudioEnabled( false );
 
@@ -633,7 +620,7 @@ InterfaceWindow::_InputStreamChanged()
 //printf("InterfaceWindow::_InputStreamChanged()\n");
        // TODO: move more stuff from updateInterface() here!
        snooze( 400000 );
-       p_wrapper->set_volume( p_mediaControl->GetVolume() );
+       p_wrapper->SetVolume( p_mediaControl->GetVolume() );
 }
 
 /*****************************************************************************
index a73e9d0..da289eb 100644 (file)
@@ -2,7 +2,7 @@
  * PlayListWindow.cpp: beos interface
  *****************************************************************************
  * Copyright (C) 1999, 2000, 2001 VideoLAN
- * $Id: PlayListWindow.cpp,v 1.4 2002/11/26 01:06:08 titer Exp $
+ * $Id: PlayListWindow.cpp,v 1.5 2002/12/09 07:57:04 titer Exp $
  *
  * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
  *          Samuel Hocevar <sam@zoy.org>
@@ -246,5 +246,5 @@ PlayListWindow::UpdatePlaylist( bool rebuild )
                        fListView->AddItem( new PlaylistItem( p_wrapper->PlaylistItemName( i ) ) );
        }
        fListView->SetCurrent( p_wrapper->PlaylistCurrent() );
-       fListView->SetPlaying( p_wrapper->is_playing() );
+       fListView->SetPlaying( p_wrapper->IsPlaying() );
 }
index fd22c49..6f92da5 100644 (file)
@@ -2,7 +2,7 @@
  * VlcWrapper.cpp: BeOS plugin for vlc (derived from MacOS X port)
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: VlcWrapper.cpp,v 1.12 2002/11/27 05:36:41 titer Exp $
+ * $Id: VlcWrapper.cpp,v 1.13 2002/12/09 07:57:04 titer Exp $
  *
  * Authors: Florian G. Pflug <fgp@phlo.org>
  *          Jon Lech Johansen <jon-vl@nanocrew.net>
@@ -144,14 +144,7 @@ void VlcWrapper::InputSlower()
     {
         input_SetStatus( p_input, INPUT_STATUS_SLOWER );
     }
-    if( p_input->stream.control.i_rate == DEFAULT_RATE)
-    {
-        toggle_mute();
-    }
-    else
-    {
-        toggle_mute();
-    }
+    //VolumeMute();
 }
 
 void VlcWrapper::InputFaster()
@@ -160,14 +153,7 @@ void VlcWrapper::InputFaster()
     {
         input_SetStatus( p_input, INPUT_STATUS_FASTER );
     }
-    if( p_input->stream.control.i_rate == DEFAULT_RATE)
-    {
-        toggle_mute();
-    }
-    else
-    {
-        toggle_mute();
-    }
+    //VolumeMute();
 }
 
 void VlcWrapper::openFiles( BList* o_files, bool replace )
@@ -201,7 +187,7 @@ void VlcWrapper::toggleLanguage(int i_language)
     int i_cat = AUDIO_ES;
 
     vlc_mutex_lock( &p_input->stream.stream_lock );
-    for( int i = 0; i < p_input->stream.i_selected_es_number ; i++ )
+    for( unsigned int i = 0; i < p_input->stream.i_selected_es_number ; i++ )
     {
         if( p_input->stream.pp_selected_es[i]->i_cat == i_cat )
         {
@@ -233,7 +219,7 @@ void VlcWrapper::toggleSubtitle(int i_subtitle)
     int i_cat = SPU_ES;
 
     vlc_mutex_lock( &p_input->stream.stream_lock );
-    for( int i = 0; i < p_input->stream.i_selected_es_number ; i++ )
+    for( unsigned int i = 0; i < p_input->stream.i_selected_es_number ; i++ )
     {
         if( p_input->stream.pp_selected_es[i]->i_cat == i_cat )
         {
@@ -302,6 +288,30 @@ void VlcWrapper::setTimeAsFloat(float f_position)
     }
 }
 
+bool VlcWrapper::IsPlaying()
+{
+
+       bool playing = false;
+       if ( p_input )
+       {
+               switch ( p_input->stream.control.i_status )
+               {
+                       case PLAYING_S:
+                       case FORWARD_S:
+                       case BACKWARD_S:
+                       case START_S:
+                               playing = true;
+                   break;
+                       case PAUSE_S:
+                       case UNDEF_S:
+                       case NOT_STARTED_S:
+                       default:
+                               break;
+               }
+       }
+       return playing;
+
+}
 
 /******************************
  * playlist infos and control *
@@ -334,13 +344,13 @@ bool VlcWrapper::PlaylistPlay()
     if( PlaylistSize() )
     {
         playlist_Play( p_playlist );
+        //VolumeRestore();
     }
     return( true );
 }
 
 void VlcWrapper::PlaylistPause()
 {
-    toggle_mute();
     if( p_input )
     {
         input_SetStatus( p_input, INPUT_STATUS_PAUSE );
@@ -349,7 +359,6 @@ void VlcWrapper::PlaylistPause()
 
 void VlcWrapper::PlaylistStop()
 {
-    volume_mute();
     playlist_Stop( p_playlist );
 }
 
@@ -590,125 +599,43 @@ void VlcWrapper::navigateNext()
  * audio infos and control *
  ***************************/
 
-void VlcWrapper::volume_mute()
-{
-    if( p_aout != NULL )
-    {
-           if( !p_intf->p_sys->b_mute )
-               {
-                   p_intf->p_sys->i_saved_volume = p_aout->output.i_volume;
-                   p_aout->output.i_volume = 0;
-                   p_intf->p_sys->b_mute = 1;
-               }
-    }
-
-}
-
-void VlcWrapper::volume_restore()
+void VlcWrapper::SetVolume(int value)
 {
     if( p_aout != NULL )
     {
-           p_aout->output.i_volume = p_intf->p_sys->i_saved_volume;
-               p_intf->p_sys->i_saved_volume = 0;
-           p_intf->p_sys->b_mute = 0;
-    }
-
-}
-
-void VlcWrapper::set_volume(int value)
-{
-    if( p_aout != NULL )
-    {
-               // make sure value is within bounds
-               if (value < 0)
-                       value = 0;
-               if (value > AOUT_VOLUME_MAX)
-                       value = AOUT_VOLUME_MAX;
-               vlc_mutex_lock( &p_aout->mixer_lock );
-               // unmute volume if muted
                if ( p_intf->p_sys->b_mute )
                {
                        p_intf->p_sys->b_mute = 0;
-            p_aout->output.i_volume = value;
                }
-               vlc_mutex_unlock( &p_aout->mixer_lock );
+        aout_VolumeSet( p_aout, value );
     }
 }
 
-void VlcWrapper::toggle_mute()
+void VlcWrapper::VolumeMute()
 {
     if( p_aout != NULL )
        {
-           if ( p_intf->p_sys->b_mute )
-           {
-               volume_restore();
-           }
-           else
-           {
-               volume_mute();
-           }
-       }
+           aout_VolumeGet( p_aout, &p_intf->p_sys->i_saved_volume );
+           aout_VolumeMute( p_aout, NULL );
+           p_intf->p_sys->b_mute = 1;
+       }
 }
 
-bool VlcWrapper::is_muted()
+void VlcWrapper::VolumeRestore()
 {
-       bool muted = true;
-       
     if( p_aout != NULL )
-       {
-               vlc_mutex_lock( &p_aout->mixer_lock );
-               if( p_aout->output.i_volume > 0 )
-               {
-                       muted = false;
-               }
-               vlc_mutex_unlock( &p_aout->mixer_lock );
-// unfortunately, this is not reliable!
-//             return p_main->p_intf->p_sys->b_mute;
-       }
-       return muted;
-}
-
-bool VlcWrapper::is_playing()
-{
-
-       bool playing = false;
-       if ( p_input )
-       {
-               switch ( p_input->stream.control.i_status )
-               {
-                       case PLAYING_S:
-                       case FORWARD_S:
-                       case BACKWARD_S:
-                       case START_S:
-                               playing = true;
-                   break;
-                       case PAUSE_S:
-                       case UNDEF_S:
-                       case NOT_STARTED_S:
-                       default:
-                               break;
-               }
+       {
+        aout_VolumeSet( p_aout, p_intf->p_sys->i_saved_volume );
+        p_intf->p_sys->b_mute = 0;
        }
-       return playing;
-
 }
 
-void VlcWrapper::maxvolume()
+bool VlcWrapper::IsMuted()
 {
-    if( p_aout != NULL )
-    {
-           if( p_intf->p_sys->b_mute )
-           {
-               p_intf->p_sys->i_saved_volume = AOUT_VOLUME_MAX;
-           }
-           else
-           {
-               p_aout->output.i_volume = AOUT_VOLUME_MAX;
-           }
-    }
+    return p_intf->p_sys->b_mute;
 }
 
-bool VlcWrapper::has_audio()
+bool VlcWrapper::HasAudio()
 {
     return( p_aout != NULL );
 }
@@ -737,7 +664,7 @@ void VlcWrapper::PrevTitle()
 
 void VlcWrapper::NextTitle()
 {
-    int i_id;
+    unsigned int i_id;
     i_id = p_input->stream.p_selected_area->i_id + 1;
     if( i_id < p_input->stream.i_area_nb )
     {
index 16d0f26..5081865 100644 (file)
@@ -2,7 +2,7 @@
  * VlcWrapper.h: BeOS plugin for vlc (derived from MacOS X port)
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: VlcWrapper.h,v 1.8 2002/11/27 05:36:41 titer Exp $
+ * $Id: VlcWrapper.h,v 1.9 2002/12/09 07:57:04 titer Exp $
  *
  * Authors: Florian G. Pflug <fgp@phlo.org>
  *          Jon Lech Johansen <jon-vl@nanocrew.net>
@@ -41,7 +41,7 @@ struct intf_sys_t
     vlc_bool_t        b_loop;
     vlc_bool_t        b_mute;
     int                      i_part;
-    int               i_saved_volume;
+    audio_volume_t    i_saved_volume;
     int               i_channel;
     
     VlcWrapper * p_wrapper;
@@ -77,7 +77,7 @@ public:
     const char* getTimeAsString();
     float getTimeAsFloat();
     void setTimeAsFloat( float i_offset );
-
+    bool IsPlaying();
         
     /* Playlist */
     int PlaylistSize();
@@ -103,14 +103,11 @@ public:
        void navigateNext();
 
     /* audio */
-    void volume_mute();
-    void volume_restore();
-    void set_volume(int value);
-    void toggle_mute( );
-    bool is_muted();
-    bool is_playing();
-    void maxvolume();
-    bool has_audio();
+    void SetVolume( int value );
+    void VolumeMute();
+    void VolumeRestore();
+    bool IsMuted();
+    bool HasAudio();
 
     /* DVD */
     bool HasTitles();