]> git.sesse.net Git - vlc/blobdiff - modules/gui/beos/VlcWrapper.cpp
Install new required files for skins2 on make install
[vlc] / modules / gui / beos / VlcWrapper.cpp
index 3b5fbf5e6850f901a36526548b394dfe78c821b1..f4304e4bcd345d67c9eeee0ef78ab07b3bb0314a 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.22 2003/01/27 10:29:22 titer Exp $
+ * $Id: VlcWrapper.cpp,v 1.42 2004/01/17 12:28:57 gbazin Exp $
  *
  * Authors: Florian G. Pflug <fgp@phlo.org>
  *          Jon Lech Johansen <jon-vl@nanocrew.net>
 
 #include <vlc/vlc.h>
 #include <vlc/intf.h>
-extern "C" {
-#include <audio_output.h>
-#include <aout_internal.h>
+#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>
 }
 
 #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 )
 {
     p_intf = p_interface;
     p_input = NULL;
-    p_aout = NULL;
     p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                                 FIND_ANYWHERE );
 }
@@ -52,50 +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 );
-    }
-    if( p_aout )
-    {
-        vlc_object_release( p_aout );
-    }
 }
 
-/* UpdateInputAndAOut: updates p_input and p_aout, returns true if the
-   interface needs to be updated */
-bool VlcWrapper::UpdateInputAndAOut()
+/* 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_aout == NULL )
-    {
-        p_aout = (aout_instance_t*)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
-                                                    FIND_ANYWHERE );
-    }
         
-    if( p_input != NULL )
-    {
+    if( p_input )
         if( p_input->b_dead )
         {
             vlc_object_release( p_input );
             p_input = NULL;
-            
-            if( p_aout )
-            {
-                vlc_object_release( p_aout );
-                p_aout = NULL;
-            }
         }
-        return true;
-    }
-    return false;
 }
 
 
@@ -114,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()
@@ -123,23 +111,18 @@ 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 )
+    if( !p_input )
     {
-        input_SetStatus( p_input, INPUT_STATUS_SLOWER );
+        return;
     }
-}
 
-void VlcWrapper::InputFaster()
-{
-    if( p_input != NULL )
-    {
-        input_SetStatus( p_input, INPUT_STATUS_FASTER );
-    }
+    input_SetRate( p_input, rate );
 }
 
 BList * VlcWrapper::GetChannels( int i_cat )
@@ -187,7 +170,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 );
@@ -198,10 +181,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 );
@@ -286,64 +270,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;
                }
@@ -356,44 +339,56 @@ bool VlcWrapper::IsPlaying()
  * playlist *
  ************/
 
-void VlcWrapper::OpenFiles( BList* o_files, bool replace )
+void VlcWrapper::OpenFiles( BList* o_files, bool replace, int32 index )
 {
-    BString *o_file;
-    int size = PlaylistSize();
-       bool wasEmpty = ( size < 1 );
-
-    /* delete current playlist */
-    if( replace )
-    {
-        for( int i = 0; i < size; i++ )
-        {
-            playlist_Delete( p_playlist, 0 );
-        }
-    }
-
-    /* append files */
-    while( ( o_file = (BString *)o_files->LastItem() ) )
-    {
-        playlist_Add( p_playlist, o_file->String(),
-                      PLAYLIST_APPEND, PLAYLIST_END );
-        o_files->RemoveItem(o_files->CountItems() - 1);
-    }
-    
-    /* eventually restart playing */
-    if( replace || wasEmpty )
-    {
-        playlist_Stop( p_playlist );
-        playlist_Play( p_playlist );
-    }
+       if ( o_files && o_files->CountItems() > 0)
+       {
+           int size = PlaylistSize();
+               bool wasEmpty = ( size < 1 );
+               if ( index == -1 )
+                       index = PLAYLIST_END;
+               int mode = index == PLAYLIST_END ? PLAYLIST_APPEND : PLAYLIST_INSERT;
+       
+           /* delete current playlist */
+           if( replace )
+           {
+               for( int i = 0; i < size; i++ )
+               {
+                   playlist_Delete( p_playlist, 0 );
+               }
+           }
+       
+           /* insert files */
+           int32 count = o_files->CountItems();
+           for ( int32 i = count - 1; i >= 0; i-- )
+           {
+               if ( BString* o_file = (BString *)o_files->RemoveItem( i ) )
+               {
+                       playlist_Add( p_playlist, o_file->String(),
+                                     o_file->String(), mode, index );
+                       if ( mode == PLAYLIST_INSERT )
+                               index++;
+                       delete o_file;
+               }
+           }
+           // TODO: implement a user setting
+           // if to start automatically
+           /* eventually restart playing */
+           if( replace || wasEmpty )
+           {
+               playlist_Stop( p_playlist );
+               playlist_Play( p_playlist );
+           }
+       }
 }
  
 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 );
 }
 
@@ -453,11 +448,15 @@ void VlcWrapper::GetPlaylistInfo( int32& currentIndex, int32& maxIndex )
        maxIndex = -1;
        if ( p_playlist )
        {
+           vlc_mutex_lock( &p_playlist->object_lock );
+
                maxIndex = p_playlist->i_size;
                if ( maxIndex > 0 )
-                       currentIndex = p_playlist->i_index + 1;
+                       currentIndex = p_playlist->i_index/* + 1 -> why?!?*/;
                else
                        maxIndex = -1;
+
+           vlc_mutex_unlock( &p_playlist->object_lock );
        }
 }
 
@@ -609,56 +608,161 @@ void VlcWrapper::NavigateNext()
                PlaylistNext();
 }
 
+/*************************
+ * Playlist manipulation *
+ *************************/
 
-/*********
- * audio *
- *********/
+// PlaylistLock
+bool
+VlcWrapper::PlaylistLock() const
+{
+// TODO: search and destroy -> deadlock!
+return true;
+       if ( p_playlist )
+       {
+               vlc_mutex_lock( &p_playlist->object_lock );
+               return true;
+       }
+       return false;
+}
 
-bool VlcWrapper::HasAudio()
+// PlaylistUnlock
+void
+VlcWrapper::PlaylistUnlock() const
 {
-    return( p_aout != NULL );
+// TODO: search and destroy -> deadlock!
+return;
+       vlc_mutex_unlock( &p_playlist->object_lock );
 }
 
-unsigned short VlcWrapper::GetVolume()
+// PlaylistItemAt
+void*
+VlcWrapper::PlaylistItemAt( int index ) const
 {
-    if( p_aout != NULL )
-    {
-        unsigned short i_volume;
-        aout_VolumeGet( p_aout, (audio_volume_t*)&i_volume );
-        return i_volume;
-    }
-    return 0;
+       playlist_item_t* item = NULL;
+       if ( index >= 0 && index < p_playlist->i_size )
+               item = p_playlist->pp_items[index];
+       return (void*)item;
 }
 
-void VlcWrapper::SetVolume(int value)
+// PlaylistRemoveItem
+void*
+VlcWrapper::PlaylistRemoveItem( int index ) const
 {
-    if( p_aout != NULL )
-    {
-               if ( p_intf->p_sys->b_mute )
+       playlist_item_t* copy = NULL;
+       // check if item exists at the provided index
+       if ( index >= 0 && index < p_playlist->i_size )
+       {
+               playlist_item_t* item = p_playlist->pp_items[index];
+               if ( item )
+               {
+                       // make a copy of the removed item
+                       copy = (playlist_item_t*)PlaylistCloneItem( (void*)item );
+                       // remove item from playlist (unfortunately, this frees it)
+                       playlist_Delete( p_playlist, index );
+               }
+       }
+       return (void*)copy;
+}
+
+// PlaylistRemoveItem
+void*
+VlcWrapper::PlaylistRemoveItem( void* item ) const
+{
+       playlist_item_t* copy = NULL;
+       for ( int32 i = 0; i < p_playlist->i_size; i++ )
+       {
+               if ( p_playlist->pp_items[i] == item )
+               {
+                       copy = (playlist_item_t*)PlaylistRemoveItem( i );
+                       break;
+               }
+       }
+       return (void*)copy;
+}
+
+// PlaylistAddItem
+bool
+VlcWrapper::PlaylistAddItem( void* item, int index ) const
+{
+       if ( item )
+       {
+               playlist_AddItem( p_playlist, (playlist_item_t*)item,
+                                                 PLAYLIST_INSERT, index );
+       }
+       // TODO: once playlist is returning useful info, return that instead
+       return true;
+}
+
+// PlaylistCloneItem
+void*
+VlcWrapper::PlaylistCloneItem( void* castToItem ) const
+{
+       playlist_item_t* copy = NULL;
+       playlist_item_t* item = (playlist_item_t*)castToItem;
+       if ( item )
+       {
+               copy = (playlist_item_t*)malloc( sizeof( playlist_item_t ) );
+               if ( copy )
                {
-                       p_intf->p_sys->b_mute = 0;
+                       // make a copy of the item at index
+                        *copy = *item;
+                       copy->psz_name = strdup( item->psz_name );
+                       copy->psz_uri  = strdup( item->psz_uri );
                }
-        aout_VolumeSet( p_aout, value );
+       }
+       return (void*)copy;
+}
+
+// Careful! You need to know what you're doing here!
+// The reason for having it, is to be able to deal with
+// the rather lame list implementation of the playlist.
+// It is meant to help manipulate the playlist with the above
+// methods while keeping it valid.
+//
+// PlaylistSetPlaying
+void
+VlcWrapper::PlaylistSetPlaying( int index ) const
+{
+       if ( index < 0 )
+               index = 0;
+       if ( index >= p_playlist->i_size )
+               index = p_playlist->i_size - 1;
+       p_playlist->i_index = index;
+}
+
+
+/*********
+ * audio *
+ *********/
+
+unsigned short VlcWrapper::GetVolume()
+{
+    unsigned short i_volume;
+    aout_VolumeGet( p_intf, (audio_volume_t*)&i_volume );
+    return i_volume;
+}
+
+void VlcWrapper::SetVolume( int value )
+{
+    if ( p_intf->p_sys->b_mute )
+    {
+        p_intf->p_sys->b_mute = 0;
     }
+    aout_VolumeSet( p_intf, value );
 }
 
 void VlcWrapper::VolumeMute()
 {
-    if( p_aout != NULL )
-       {
-           aout_VolumeGet( p_aout, &p_intf->p_sys->i_saved_volume );
-           aout_VolumeMute( p_aout, NULL );
-           p_intf->p_sys->b_mute = 1;
-       }
+    aout_VolumeMute( p_intf, NULL );
+    p_intf->p_sys->b_mute = 1;
 }
 
 void VlcWrapper::VolumeRestore()
 {
-    if( p_aout != NULL )
-       {
-        aout_VolumeSet( p_aout, p_intf->p_sys->i_saved_volume );
-        p_intf->p_sys->b_mute = 0;
-       }
+    audio_volume_t dummy;
+    aout_VolumeMute( p_intf, &dummy );
+    p_intf->p_sys->b_mute = 0;
 }
 
 bool VlcWrapper::IsMuted()
@@ -670,12 +774,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]->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 );
 }
 
@@ -851,7 +977,37 @@ void VlcWrapper::ChapterInfo( int32 &currentIndex, int32 &maxIndex )
  * Miscellanous *
  ****************/
  
-void VlcWrapper::LoadSubFile( char * psz_file )
+void VlcWrapper::LoadSubFile( const char * psz_file )
 {
     config_PutPsz( p_intf, "sub-file", strdup( psz_file ) );
 }
+
+void VlcWrapper::FilterChange()
+{
+    if( !p_input )
+        return;
+    
+    vout_thread_t * p_vout;
+    vlc_mutex_lock( &p_input->stream.stream_lock );
+
+    // 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 )
+    {
+        p_vout->b_filter_change = VLC_TRUE;
+        vlc_object_release( p_vout );
+    }
+
+    // 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_dec != NULL ) )
+        {
+            input_UnselectES( p_input, p_input->stream.pp_es[i] );
+            input_SelectES( p_input, p_input->stream.pp_es[i] );
+        }
+    }
+    vlc_mutex_unlock( &p_input->stream.stream_lock );
+}