]> git.sesse.net Git - vlc/blobdiff - modules/gui/beos/VlcWrapper.cpp
fixed flickering of skip buttons (and consequently crashing if you pressed them)
[vlc] / modules / gui / beos / VlcWrapper.cpp
index fd22c494ceee78db514f8b03f744e26956571cc6..f8d2bf3d3f2cb3b22e31fef691eb0114f75aed0e 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.16 2003/01/11 19:33:09 stippi Exp $
  *
  * Authors: Florian G. Pflug <fgp@phlo.org>
  *          Jon Lech Johansen <jon-vl@nanocrew.net>
  * along with this program{} if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
+#include <AppKit.h>
+#include <InterfaceKit.h>
 #include <SupportKit.h>
 
 #include <vlc/vlc.h>
 #include <vlc/intf.h>
+extern "C" {
 #include <audio_output.h>
 #include <aout_internal.h>
+}
 
 #include "VlcWrapper.h"
+#include "MsgVals.h"
 
 /* constructor */
 VlcWrapper::VlcWrapper( intf_thread_t *p_interface )
@@ -98,6 +103,12 @@ bool VlcWrapper::UpdateInputAndAOut()
  * input infos and control *
  ***************************/
 
+bool VlcWrapper::HasInput()
+{
+    return ( p_input != NULL );
+//    return ( PlaylistSize() > 0 );
+}
+
 /* status (UNDEF_S, PLAYING_S, PAUSE_S, FORWARD_S, BACKWARD_S,
    REWIND_S, NOT_STARTED_S, START_S) */
 int VlcWrapper::InputStatus()
@@ -144,14 +155,6 @@ void VlcWrapper::InputSlower()
     {
         input_SetStatus( p_input, INPUT_STATUS_SLOWER );
     }
-    if( p_input->stream.control.i_rate == DEFAULT_RATE)
-    {
-        toggle_mute();
-    }
-    else
-    {
-        toggle_mute();
-    }
 }
 
 void VlcWrapper::InputFaster()
@@ -160,14 +163,80 @@ void VlcWrapper::InputFaster()
     {
         input_SetStatus( p_input, INPUT_STATUS_FASTER );
     }
-    if( p_input->stream.control.i_rate == DEFAULT_RATE)
-    {
-        toggle_mute();
-    }
-    else
+}
+
+BList * VlcWrapper::InputGetChannels( int i_cat )
+{
+    if( p_input )
     {
-        toggle_mute();
+        unsigned int i;
+        uint32 what;
+        const char* fieldName;
+
+        switch( i_cat )
+        {
+            case AUDIO_ES:
+            {
+                what = SELECT_CHANNEL;
+                fieldName = "channel";
+                break;
+            }
+            case SPU_ES:
+            {
+                what = SELECT_SUBTITLE;
+                fieldName = "subtitle";
+                break;
+            }
+            default:
+            return NULL;
+       }
+
+        vlc_mutex_lock( &p_input->stream.stream_lock );
+      
+        /* find which track is currently playing */
+        es_descriptor_t *p_es = NULL;
+        for( i = 0; i < p_input->stream.i_selected_es_number; i++ )
+        {
+            if( p_input->stream.pp_selected_es[i]->i_cat == i_cat )
+                p_es = p_input->stream.pp_selected_es[i];
+        }
+        
+        /* build a list of all tracks */
+        BList *list = new BList( p_input->stream.i_es_number );
+        BMenuItem *menuItem;
+        BMessage *message;
+        char *trackName;
+        
+        /* "None" */
+        message = new BMessage( what );
+        message->AddInt32( fieldName, -1 );
+        menuItem = new BMenuItem( "None", message );
+        if( !p_es )
+            menuItem->SetMarked( true );
+        list->AddItem( menuItem );
+        
+        for( i = 0; i < p_input->stream.i_es_number; i++ )
+        {
+            if( p_input->stream.pp_es[i]->i_cat == i_cat )
+            {
+                message = new BMessage( what );
+                message->AddInt32( fieldName, i );
+                if( strlen( p_input->stream.pp_es[i]->psz_desc ) )
+                    trackName = strdup( p_input->stream.pp_es[i]->psz_desc );
+                else
+                    trackName = "<unknown>";
+                menuItem = new BMenuItem( trackName, message );
+                if( p_input->stream.pp_es[i] == p_es )
+                    menuItem->SetMarked( true );
+                list->AddItem( menuItem );
+            }
+        }
+        
+        vlc_mutex_unlock( &p_input->stream.stream_lock );
+
+        return list;
     }
+    return NULL;
 }
 
 void VlcWrapper::openFiles( BList* o_files, bool replace )
@@ -194,68 +263,71 @@ void VlcWrapper::openDisc(BString o_type, BString o_device, int i_title, int i_c
 
 
 
-void VlcWrapper::toggleLanguage(int i_language)
+void VlcWrapper::ToggleLanguage( int i_language )
 {
-
-    int32 i_old = -1;
-    int i_cat = AUDIO_ES;
+    es_descriptor_t * p_es = NULL;
+    es_descriptor_t * p_es_old = NULL;
 
     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 )
+        if( p_input->stream.pp_selected_es[i]->i_cat == AUDIO_ES )
         {
-            i_old = i;
+            p_es_old = p_input->stream.pp_selected_es[i];
             break;
         }
     }
     vlc_mutex_unlock( &p_input->stream.stream_lock );
-
-    msg_Info( p_intf, "Old: %d,  New: %d", i_old, i_language);
+    
     if( i_language != -1 )
     {
-        input_ToggleES( p_input, 
-                        p_input->stream.pp_selected_es[i_language],
-                        VLC_TRUE );
+        p_es = p_input->stream.pp_es[i_language];
     }
-
-    if( (i_old != -1) && (i_old != i_language) )
+    if( p_es == p_es_old )
+    {
+        return;
+    }
+    if( p_es_old )
+    {
+        input_ToggleES( p_input, p_es_old, VLC_FALSE );
+    }
+    if( p_es )
     {
-        input_ToggleES( p_input, 
-                        p_input->stream.pp_selected_es[i_old],
-                        VLC_FALSE );
+        input_ToggleES( p_input, p_es, VLC_TRUE );
     }
 }
 
-void VlcWrapper::toggleSubtitle(int i_subtitle)
+void VlcWrapper::ToggleSubtitle( int i_subtitle )
 {
-    int32 i_old = -1;
-    int i_cat = SPU_ES;
+    es_descriptor_t * p_es = NULL;
+    es_descriptor_t * p_es_old = NULL;
 
     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 )
+        if( p_input->stream.pp_selected_es[i]->i_cat == SPU_ES )
         {
-            i_old = i;
+            p_es_old = p_input->stream.pp_selected_es[i];
             break;
         }
     }
     vlc_mutex_unlock( &p_input->stream.stream_lock );
     
-    msg_Info( p_intf, "Old: %d,  New: %d", i_old, i_subtitle);
     if( i_subtitle != -1 )
     {
-        input_ToggleES( p_input, 
-                        p_input->stream.pp_selected_es[i_subtitle],
-                        VLC_TRUE );
+        p_es = p_input->stream.pp_es[i_subtitle];
     }
-
-    if( (i_old != -1) && (i_old != i_subtitle) )
+    if( p_es == p_es_old )
+    {
+        return;
+    }
+    if( p_es_old )
     {
-        input_ToggleES( p_input, 
-                        p_input->stream.pp_selected_es[i_old],
-                        VLC_FALSE );
+        input_ToggleES( p_input, p_es_old, VLC_FALSE );
+    }
+    if( p_es )
+    {
+        input_ToggleES( p_input, p_es, VLC_TRUE );
     }
 }
 
@@ -302,6 +374,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 *
@@ -340,7 +436,6 @@ bool VlcWrapper::PlaylistPlay()
 
 void VlcWrapper::PlaylistPause()
 {
-    toggle_mute();
     if( p_input )
     {
         input_SetStatus( p_input, INPUT_STATUS_PAUSE );
@@ -349,7 +444,6 @@ void VlcWrapper::PlaylistPause()
 
 void VlcWrapper::PlaylistStop()
 {
-    volume_mute();
     playlist_Stop( p_playlist );
 }
 
@@ -590,125 +684,54 @@ void VlcWrapper::navigateNext()
  * audio infos and control *
  ***************************/
 
-void VlcWrapper::volume_mute()
+unsigned short VlcWrapper::GetVolume()
 {
     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()
-{
-    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;
+        unsigned short i_volume;
+        aout_VolumeGet( p_aout, (audio_volume_t*)&i_volume );
+        return i_volume;
     }
-
+    return 0;
 }
 
-void VlcWrapper::set_volume(int value)
+void VlcWrapper::SetVolume(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 +760,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 )
     {