]> git.sesse.net Git - vlc/blobdiff - modules/gui/beos/VlcWrapper.cpp
* use var_Set/Get "state"/"position"/"rate" instead of old functions.
[vlc] / modules / gui / beos / VlcWrapper.cpp
index fc99088ca6a8344396b59065fb78d622dd4f3808..299901eb90e244b9bb99681a4964108e157be91a 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.25 2003/02/09 11:51:36 titer Exp $
+ * $Id$
  *
  * Authors: Florian G. Pflug <fgp@phlo.org>
  *          Jon Lech Johansen <jon-vl@nanocrew.net>
@@ -33,6 +33,7 @@
 #include <vlc/vout.h>
 extern "C"
 {
+  #include <input_ext-plugins.h> // needed here when compiling without plugins
   #include <audio_output.h>
   #include <aout_internal.h>
 }
@@ -40,6 +41,14 @@ extern "C"
 #include "VlcWrapper.h"
 #include "MsgVals.h"
 
+const char * _AddEllipsis( char * string )
+{
+    char * temp;
+    temp = (char*) calloc( strlen( string ) + 4, 1 );
+    sprintf( temp, "%s%s", string, B_UTF8_ELLIPSIS );
+    return temp;
+}
+
 /* constructor */
 VlcWrapper::VlcWrapper( intf_thread_t *p_interface )
 {
@@ -53,35 +62,25 @@ VlcWrapper::VlcWrapper( intf_thread_t *p_interface )
 VlcWrapper::~VlcWrapper()
 {
     if( p_input )
-    {
         vlc_object_release( p_input );
-    }
+
     if( p_playlist )
-    {
         vlc_object_release( p_playlist );
-    }
 }
 
-/* UpdateInput: updates p_input, returns true if the interface needs to
-   be updated */
-bool VlcWrapper::UpdateInput()
+/* UpdateInput: updates p_input */
+void VlcWrapper::UpdateInput()
 {
-    if( p_input == NULL )
-    {
+    if( !p_input )
         p_input = (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
                                                      FIND_ANYWHERE );
-    }
         
-    if( p_input != NULL )
-    {
+    if( p_input )
         if( p_input->b_dead )
         {
             vlc_object_release( p_input );
             p_input = NULL;
         }
-        return true;
-    }
-    return false;
 }
 
 
@@ -100,7 +99,10 @@ int VlcWrapper::InputStatus()
     {
         return UNDEF_S;
     }
-    return p_input->stream.control.i_status;
+    
+    vlc_value_t state;
+    var_Get( p_input, "state", &state );
+    return state.i_int;
 }
 
 int VlcWrapper::InputRate()
@@ -109,23 +111,17 @@ int VlcWrapper::InputRate()
     {
         return DEFAULT_RATE;
     }
+    
     return p_input->stream.control.i_rate;
 }
 
-void VlcWrapper::InputSlower()
+void VlcWrapper::InputSetRate( int rate )
 {
-    if( p_input != NULL )
-    {
-        input_SetStatus( p_input, INPUT_STATUS_SLOWER );
-    }
-}
-
-void VlcWrapper::InputFaster()
-{
-    if( p_input != NULL )
+    if( !p_input )
     {
-        input_SetStatus( p_input, INPUT_STATUS_FASTER );
+        return;
     }
+    var_SetInteger( p_input, "rate", rate );
 }
 
 BList * VlcWrapper::GetChannels( int i_cat )
@@ -173,7 +169,7 @@ BList * VlcWrapper::GetChannels( int i_cat )
         /* "None" */
         message = new BMessage( what );
         message->AddInt32( fieldName, -1 );
-        menuItem = new BMenuItem( "None", message );
+        menuItem = new BMenuItem( _("None"), message );
         if( !p_es )
             menuItem->SetMarked( true );
         list->AddItem( menuItem );
@@ -184,10 +180,11 @@ BList * VlcWrapper::GetChannels( int 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 );
+                if( !p_input->stream.pp_es[i]->psz_desc ||
+                    !*p_input->stream.pp_es[i]->psz_desc )
+                    trackName = _("<unknown>");
                 else
-                    trackName = "<unknown>";
+                    trackName = strdup( p_input->stream.pp_es[i]->psz_desc );
                 menuItem = new BMenuItem( trackName, message );
                 if( p_input->stream.pp_es[i] == p_es )
                     menuItem->SetMarked( true );
@@ -272,64 +269,63 @@ void VlcWrapper::ToggleSubtitle( int i_subtitle )
 
 const char * VlcWrapper::GetTimeAsString()
 {
-    static char psz_currenttime[ OFFSETTOTIME_MAX_SIZE ];
+    static char psz_time[ MSTRTIME_MAX_SIZE ];
         
-    if( p_input == NULL )
+    if( !p_input )
     {
         return ("-:--:--");
     }     
    
-    input_OffsetToTime( p_input, 
-                        psz_currenttime, 
-                        p_input->stream.p_selected_area->i_tell );        
+    vlc_value_t time;
+    var_Get( p_input, "time", &time );
+    
+    mtime_t seconds = time.i_time / 1000000;
+    sprintf( psz_time, "%d:%02d:%02d",
+             (int) ( seconds / (60 * 60 ) ),
+             (int) ( ( seconds / 60 ) % 60 ),
+             (int) ( seconds % 60 ) );
 
-    return(psz_currenttime);
+    return psz_time;
 }
 
 float VlcWrapper::GetTimeAsFloat()
 {
-    float f_time = 0.0;
-
-    if( p_input != NULL )
-    {
-        f_time = (float)p_input->stream.p_selected_area->i_tell / 
-                 (float)p_input->stream.p_selected_area->i_size;
-    }    
-    else
+    if( !p_input )
     {
-        f_time = 0.0;
+        return 0.0;
     }
-    return( f_time );
+    
+    vlc_value_t pos;
+    var_Get( p_input, "position", &pos );
+    return pos.f_float;
 }
 
 void VlcWrapper::SetTimeAsFloat( float f_position )
 {
-    if( p_input != NULL )
+    if( !p_input )
     {
-        input_Seek( p_input, 
-                   (long long int)(p_input->stream.p_selected_area->i_size
-                       * f_position / SEEKSLIDER_RANGE ), 
-                   INPUT_SEEK_SET);
+        return;
     }
+    
+    vlc_value_t pos;
+    pos.f_float = f_position / SEEKSLIDER_RANGE;
+    var_Set( p_input, "position", pos );
 }
 
 bool VlcWrapper::IsPlaying()
 {
-
        bool playing = false;
-       if ( p_input )
+       if( p_input )
        {
-               switch ( p_input->stream.control.i_status )
+               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;
                }
@@ -368,7 +364,7 @@ void VlcWrapper::OpenFiles( BList* o_files, bool replace, int32 index )
                if ( BString* o_file = (BString *)o_files->RemoveItem( i ) )
                {
                        playlist_Add( p_playlist, o_file->String(),
-                                     mode, index );
+                                     o_file->String(), mode, index );
                        if ( mode == PLAYLIST_INSERT )
                                index++;
                        delete o_file;
@@ -387,11 +383,11 @@ void VlcWrapper::OpenFiles( BList* o_files, bool replace, int32 index )
  
 void VlcWrapper::OpenDisc(BString o_type, BString o_device, int i_title, int i_chapter)
 {
-    if( p_intf->p_sys->b_dvdmenus )
-        o_device.Prepend( "dvd:" );
+    if( config_GetInt( p_intf, "beos-dvdmenus" ) )
+        o_device.Prepend( "dvdplay:" );
     else
         o_device.Prepend( "dvdold:" );
-    playlist_Add( p_playlist, o_device.String(),
+    playlist_Add( p_playlist, o_device.String(), o_device.String(),
                   PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
 }
 
@@ -405,7 +401,7 @@ int VlcWrapper::PlaylistSize()
 
 char * VlcWrapper::PlaylistItemName( int i )
 {
-   return p_playlist->pp_items[i]->psz_name;
+   return p_playlist->pp_items[i]->input.psz_name;
 }
 
 int VlcWrapper::PlaylistCurrent()
@@ -426,7 +422,7 @@ void VlcWrapper::PlaylistPause()
 {
     if( p_input )
     {
-        input_SetStatus( p_input, INPUT_STATUS_PAUSE );
+        var_SetInteger( p_input, "state", PAUSE_S );
     }
 }
 
@@ -709,11 +705,9 @@ VlcWrapper::PlaylistCloneItem( void* castToItem ) const
                if ( copy )
                {
                        // make a copy of the item at index
-                       copy->psz_name = strdup( item->psz_name );
-                       copy->psz_uri  = strdup( item->psz_uri );
-                       copy->i_type = item->i_type;
-                       copy->i_status = item->i_status;
-                       copy->b_autodeletion = item->b_autodeletion;
+                        *copy = *item;
+                       copy->input.psz_name = strdup( item->input.psz_name );
+                       copy->input.psz_uri  = strdup( item->input.psz_uri );
                }
        }
        return (void*)copy;
@@ -759,14 +753,14 @@ void VlcWrapper::SetVolume( int value )
 
 void VlcWrapper::VolumeMute()
 {
-       aout_VolumeGet( p_intf, &p_intf->p_sys->i_saved_volume );
     aout_VolumeMute( p_intf, NULL );
     p_intf->p_sys->b_mute = 1;
 }
 
 void VlcWrapper::VolumeRestore()
 {
-    aout_VolumeSet( p_intf, p_intf->p_sys->i_saved_volume );
+    audio_volume_t dummy;
+    aout_VolumeMute( p_intf, &dummy );
     p_intf->p_sys->b_mute = 0;
 }
 
@@ -779,12 +773,34 @@ bool VlcWrapper::IsMuted()
  * DVD *
  *******/
 
-bool VlcWrapper::HasTitles()
+bool VlcWrapper::IsUsingMenus()
 {
     if( !p_input )
+        return false;
+
+    vlc_mutex_lock( &p_playlist->object_lock );
+    if( p_playlist->i_index < 0 )
     {
+        vlc_mutex_unlock( &p_playlist->object_lock );
         return false;
     }
+    
+    char * psz_name = p_playlist->pp_items[p_playlist->i_index]->input.psz_name;
+    if( !strncmp( psz_name, "dvdplay:", 8 ) )
+    {
+        vlc_mutex_unlock( &p_playlist->object_lock );
+        return true;
+    }
+    vlc_mutex_unlock( &p_playlist->object_lock );
+
+    return false;
+}
+
+bool VlcWrapper::HasTitles()
+{
+    if( !p_input )
+        return false;
+
     return ( p_input->stream.i_area_nb > 1 );
 }
 
@@ -973,7 +989,7 @@ void VlcWrapper::FilterChange()
     vout_thread_t * p_vout;
     vlc_mutex_lock( &p_input->stream.stream_lock );
 
-    /* Warn the vout we are about to change the filter chain */
+    // Warn the vout we are about to change the filter chain
     p_vout = (vout_thread_t*)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
                                               FIND_ANYWHERE );
     if( p_vout )
@@ -982,11 +998,11 @@ void VlcWrapper::FilterChange()
         vlc_object_release( p_vout );
     }
 
-    /* restart all video stream */
+    // restart all video stream
     for( unsigned int i = 0; i < p_input->stream.i_es_number; i++ )
     {
         if( ( p_input->stream.pp_es[i]->i_cat == VIDEO_ES ) &&
-            ( p_input->stream.pp_es[i]->p_decoder_fifo != NULL ) )
+            ( p_input->stream.pp_es[i]->p_dec != NULL ) )
         {
             input_UnselectES( p_input, p_input->stream.pp_es[i] );
             input_SelectES( p_input, p_input->stream.pp_es[i] );