]> git.sesse.net Git - vlc/blobdiff - modules/gui/beos/VlcWrapper.cpp
Changes done since Feb 28 2003:
[vlc] / modules / gui / beos / VlcWrapper.cpp
index f8d2bf3d3f2cb3b22e31fef691eb0114f75aed0e..0c5b2ca8f9a7253114a2063b723b38eb532c1280 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.16 2003/01/11 19:33:09 stippi Exp $
+ * $Id: VlcWrapper.cpp,v 1.24 2003/02/01 12:01:11 stippi 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 <audio_output.h>
+  #include <aout_internal.h>
 }
 
 #include "VlcWrapper.h"
@@ -106,11 +108,8 @@ bool VlcWrapper::UpdateInputAndAOut()
 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()
 {
     if( !p_input )
@@ -129,26 +128,6 @@ int VlcWrapper::InputRate()
     return p_input->stream.control.i_rate;
 }
 
-/* tell: location in the current stream (in arbitrary units) */
-int VlcWrapper::InputTell()
-{
-    if( !p_input )
-    {
-        return -1;
-    }
-    return p_input->stream.p_selected_area->i_tell;
-}
-
-/* size: total size of the current stream (in arbitrary units) */
-int VlcWrapper::InputSize()
-{
-    if( !p_input )
-    {
-        return -1;
-    }
-    return p_input->stream.p_selected_area->i_size;
-}
-
 void VlcWrapper::InputSlower()
 {
     if( p_input != NULL )
@@ -165,7 +144,7 @@ void VlcWrapper::InputFaster()
     }
 }
 
-BList * VlcWrapper::InputGetChannels( int i_cat )
+BList * VlcWrapper::GetChannels( int i_cat )
 {
     if( p_input )
     {
@@ -239,30 +218,6 @@ BList * VlcWrapper::InputGetChannels( int i_cat )
     return NULL;
 }
 
-void VlcWrapper::openFiles( BList* o_files, bool replace )
-{
-    BString *o_file;
-
-    while( ( o_file = (BString *)o_files->LastItem() ) )
-    {
-        o_files->RemoveItem(o_files->CountItems() - 1);
-        playlist_Add( p_playlist, o_file->String(),
-                  PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
-        delete o_file;
-    }
-}
-
-void VlcWrapper::openDisc(BString o_type, BString o_device, int i_title, int i_chapter)
-{
-    BString o_source("");
-    o_source << o_type << ":" << o_device ;
-
-    playlist_Add( p_playlist, o_source.String(),
-                  PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
-}
-
-
-
 void VlcWrapper::ToggleLanguage( int i_language )
 {
     es_descriptor_t * p_es = NULL;
@@ -331,7 +286,7 @@ void VlcWrapper::ToggleSubtitle( int i_subtitle )
     }
 }
 
-const char*  VlcWrapper::getTimeAsString()
+const char * VlcWrapper::GetTimeAsString()
 {
     static char psz_currenttime[ OFFSETTOTIME_MAX_SIZE ];
         
@@ -347,7 +302,7 @@ const char*  VlcWrapper::getTimeAsString()
     return(psz_currenttime);
 }
 
-float  VlcWrapper::getTimeAsFloat()
+float VlcWrapper::GetTimeAsFloat()
 {
     float f_time = 0.0;
 
@@ -363,7 +318,7 @@ float  VlcWrapper::getTimeAsFloat()
     return( f_time );
 }
 
-void VlcWrapper::setTimeAsFloat(float f_position)
+void VlcWrapper::SetTimeAsFloat( float f_position )
 {
     if( p_input != NULL )
     {
@@ -399,9 +354,63 @@ bool VlcWrapper::IsPlaying()
 
 }
 
-/******************************
- * playlist infos and control *
- ******************************/
+/************
+ * playlist *
+ ************/
+
+void VlcWrapper::OpenFiles( BList* o_files, bool replace, int32 index )
+{
+       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(),
+                                     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:" );
+    else
+        o_device.Prepend( "dvdold:" );
+    playlist_Add( p_playlist, o_device.String(),
+                  PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
+}
+
 int VlcWrapper::PlaylistSize()
 {
     vlc_mutex_lock( &p_playlist->object_lock );
@@ -410,7 +419,7 @@ int VlcWrapper::PlaylistSize()
     return i_size;
 }
 
-char *VlcWrapper::PlaylistItemName( int i )
+char * VlcWrapper::PlaylistItemName( int i )
 {
    return p_playlist->pp_items[i]->psz_name;
 }
@@ -420,11 +429,6 @@ int VlcWrapper::PlaylistCurrent()
     return p_playlist->i_index;
 }
 
-int  VlcWrapper::PlaylistStatus()
-{
-    return p_playlist->i_status;
-}
-
 bool VlcWrapper::PlaylistPlay()
 {
     if( PlaylistSize() )
@@ -457,86 +461,30 @@ void VlcWrapper::PlaylistPrev()
     playlist_Prev( p_playlist );
 }
 
-void VlcWrapper::PlaylistSkip( int i )
-{
-    playlist_Skip( p_playlist, i );
-}
-
-void VlcWrapper::PlaylistGoto( int i )
-{
-    playlist_Goto( p_playlist, i );
-}
-
-void VlcWrapper::PlaylistLoop()
-{
-    if ( p_intf->p_sys->b_loop )
-    {
-        playlist_Delete( p_playlist, p_playlist->i_size - 1 );
-    }
-    else
-    {
-        playlist_Add( p_playlist, "vlc:loop",
-                      PLAYLIST_APPEND | PLAYLIST_GO,
-                      PLAYLIST_END );
-    }
-    p_intf->p_sys->b_loop = !p_intf->p_sys->b_loop;
-}
-
-BList * VlcWrapper::PlaylistAsArray()
-{ 
-    int i;
-    BList* p_list = new BList(p_playlist->i_size);
-    
-    vlc_mutex_lock( &p_playlist->object_lock );
-
-    for( i = 0; i < p_playlist->i_size; i++ )
-    {
-        p_list->AddItem(new BString(p_playlist->pp_items[i]->psz_name));
-    }
-
-    vlc_mutex_unlock( &p_playlist->object_lock );
-    return( p_list );
-}
-
-void VlcWrapper::getPlaylistInfo( int32& currentIndex, int32& maxIndex )
+void VlcWrapper::GetPlaylistInfo( int32& currentIndex, int32& maxIndex )
 {
        currentIndex = -1;
        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 );
        }
 }
 
-
 void VlcWrapper::PlaylistJumpTo( int pos )
 {
-#if 0
-       // sanity checks
-       if ( pos < 0 )
-               pos = 0;
-       int size = playlistSize();
-       if (pos >= size)
-               pos = size - 1;
-       // weird hack
-    if( p_input_bank->pp_input[0] != NULL )
-               pos--;
-       // stop current stream
-       playlistStop();
-       // modify current position in playlist
-       playlistLock();
-       p_main->p_playlist->i_index = pos;
-       playlistUnlock();
-       // start playing
-       playlistPlay();
-#endif
-}
-
-void VlcWrapper::getNavCapabilities( bool *canSkipPrev, bool *canSkipNext )
+    playlist_Goto( p_playlist, pos );
+}
+
+void VlcWrapper::GetNavCapabilities( bool *canSkipPrev, bool *canSkipNext )
 {
        if ( canSkipPrev && canSkipNext )
        {
@@ -580,7 +528,7 @@ void VlcWrapper::getNavCapabilities( bool *canSkipPrev, bool *canSkipNext )
        }
 }
 
-void VlcWrapper::navigatePrev()
+void VlcWrapper::NavigatePrev()
 {
        bool hasSkiped = false;
 
@@ -607,7 +555,7 @@ void VlcWrapper::navigatePrev()
 
                        if ( currentChapter >= 0 )
                        {
-                               toggleChapter( currentChapter );
+                               ToggleChapter( currentChapter );
                                hasSkiped = true;
                        }
                }
@@ -619,7 +567,7 @@ void VlcWrapper::navigatePrev()
                        // disallow area 0 since it is used for video_ts.vob
                        if( currentTitle > 0 )
                        {
-                               toggleTitle(currentTitle);
+                               ToggleTitle(currentTitle);
                                hasSkiped = true;
                        }
                }
@@ -630,7 +578,7 @@ void VlcWrapper::navigatePrev()
                PlaylistPrev();
 }
 
-void VlcWrapper::navigateNext()
+void VlcWrapper::NavigateNext()
 {
        bool hasSkiped = false;
 
@@ -656,7 +604,7 @@ void VlcWrapper::navigateNext()
                        currentChapter++;
                        if ( currentChapter < numChapters )
                        {
-                               toggleChapter( currentChapter );
+                               ToggleChapter( currentChapter );
                                hasSkiped = true;
                        }
                }
@@ -668,7 +616,7 @@ void VlcWrapper::navigateNext()
                        // disallow area 0 since it is used for video_ts.vob
                        if ( currentTitle < numTitles - 1 )
                        {
-                               toggleTitle(currentTitle);
+                               ToggleTitle(currentTitle);
                                hasSkiped = true;
                        }
                }
@@ -679,10 +627,140 @@ void VlcWrapper::navigateNext()
                PlaylistNext();
 }
 
+/*************************
+ * Playlist manipulation *
+ *************************/
 
-/***************************
- * audio infos and control *
- ***************************/
+// 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;
+}
+
+// PlaylistUnlock
+void
+VlcWrapper::PlaylistUnlock() const
+{
+// TODO: search and destroy -> deadlock!
+return;
+       vlc_mutex_unlock( &p_playlist->object_lock );
+}
+
+// PlaylistItemAt
+void*
+VlcWrapper::PlaylistItemAt( int index ) const
+{
+       playlist_item_t* item = NULL;
+       if ( index >= 0 && index < p_playlist->i_size )
+               item = p_playlist->pp_items[index];
+       return (void*)item;
+}
+
+// PlaylistRemoveItem
+void*
+VlcWrapper::PlaylistRemoveItem( int index ) const
+{
+       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 )
+               {
+                       // 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;
+               }
+       }
+       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 *
+ *********/
+
+bool VlcWrapper::HasAudio()
+{
+    return( p_aout != NULL );
+}
 
 unsigned short VlcWrapper::GetVolume()
 {
@@ -731,14 +809,10 @@ bool VlcWrapper::IsMuted()
     return p_intf->p_sys->b_mute;
 }
 
-bool VlcWrapper::HasAudio()
-{
-    return( p_aout != NULL );
-}
-
 /*******
  * DVD *
  *******/
+
 bool VlcWrapper::HasTitles()
 {
     if( !p_input )
@@ -748,13 +822,41 @@ bool VlcWrapper::HasTitles()
     return ( p_input->stream.i_area_nb > 1 );
 }
 
+BList * VlcWrapper::GetTitles()
+{
+    if( p_input )
+    {
+        vlc_mutex_lock( &p_input->stream.stream_lock );
+      
+        BList *list = new BList( p_input->stream.i_area_nb );
+        BMenuItem *menuItem;
+        BMessage *message;
+        
+        for( unsigned int i = 1; i < p_input->stream.i_area_nb; i++ )
+        {
+            message = new BMessage( TOGGLE_TITLE );
+            message->AddInt32( "index", i );
+            BString helper( "" );
+            helper << i;
+            menuItem = new BMenuItem( helper.String(), message );
+            menuItem->SetMarked( p_input->stream.p_selected_area->i_id == i );
+            list->AddItem( menuItem );
+        }
+        
+        vlc_mutex_unlock( &p_input->stream.stream_lock );
+
+        return list;
+    }
+    return NULL;
+}
+
 void VlcWrapper::PrevTitle()
 {
     int i_id;
     i_id = p_input->stream.p_selected_area->i_id - 1;
     if( i_id > 0 )
     {
-        toggleTitle(i_id);
+        ToggleTitle(i_id);
     }
 }
 
@@ -764,10 +866,41 @@ void VlcWrapper::NextTitle()
     i_id = p_input->stream.p_selected_area->i_id + 1;
     if( i_id < p_input->stream.i_area_nb )
     {
-        toggleTitle(i_id);
+        ToggleTitle(i_id);
     }
 }
 
+void VlcWrapper::ToggleTitle(int i_title)
+{
+    if( p_input != NULL )
+    {
+        input_ChangeArea( p_input,
+                          p_input->stream.pp_areas[i_title] );
+
+        vlc_mutex_lock( &p_input->stream.stream_lock );
+
+        vlc_mutex_unlock( &p_input->stream.stream_lock );
+    }
+}
+
+void VlcWrapper::TitleInfo( int32 &currentIndex, int32 &maxIndex )
+{
+       currentIndex = -1;
+       maxIndex = -1;
+       if ( p_input )
+       {
+               vlc_mutex_lock( &p_input->stream.stream_lock );
+
+               maxIndex = p_input->stream.i_area_nb - 1;
+               if ( maxIndex > 0)
+                       currentIndex = p_input->stream.p_selected_area->i_id;
+               else
+                       maxIndex = -1;
+
+               vlc_mutex_unlock( &p_input->stream.stream_lock );
+       }
+}
+
 bool VlcWrapper::HasChapters()
 {
     if( !p_input )
@@ -777,13 +910,42 @@ bool VlcWrapper::HasChapters()
     return ( p_input->stream.p_selected_area->i_part_nb > 1 );
 }
 
+BList * VlcWrapper::GetChapters()
+{
+    if( p_input )
+    {
+        vlc_mutex_lock( &p_input->stream.stream_lock );
+      
+        BList *list = new BList( p_input->stream.p_selected_area->i_part_nb );
+        BMenuItem *menuItem;
+        BMessage *message;
+        
+        for( unsigned int i = 1;
+             i < p_input->stream.p_selected_area->i_part_nb + 1; i++ )
+        {
+            message = new BMessage( TOGGLE_CHAPTER );
+            message->AddInt32( "index", i );
+            BString helper( "" );
+            helper << i;
+            menuItem = new BMenuItem( helper.String(), message );
+            menuItem->SetMarked( p_input->stream.p_selected_area->i_part == i );
+            list->AddItem( menuItem );
+        }
+        
+        vlc_mutex_unlock( &p_input->stream.stream_lock );
+
+        return list;
+    }
+    return NULL;
+}
+
 void VlcWrapper::PrevChapter()
 {
     int i_id;
     i_id = p_input->stream.p_selected_area->i_part - 1;
     if( i_id >= 0 )
     {
-        toggleChapter(i_id);
+        ToggleChapter(i_id);
     }
 }
 
@@ -793,26 +955,21 @@ void VlcWrapper::NextChapter()
     i_id = p_input->stream.p_selected_area->i_part + 1;
     if( i_id >= 0 )
     {
-        toggleChapter(i_id);
+        ToggleChapter(i_id);
     }
 }
 
-void VlcWrapper::TitleInfo( int32 &currentIndex, int32 &maxIndex )
+void VlcWrapper::ToggleChapter(int i_chapter)
 {
-       currentIndex = -1;
-       maxIndex = -1;
-       if ( p_input )
-       {
-               vlc_mutex_lock( &p_input->stream.stream_lock );
-
-               maxIndex = p_input->stream.i_area_nb - 1;
-               if ( maxIndex > 0)
-                       currentIndex = p_input->stream.p_selected_area->i_id;
-               else
-                       maxIndex = -1;
+    if( p_input != NULL )
+    {
+        p_input->stream.p_selected_area->i_part = i_chapter;
+        input_ChangeArea( p_input,
+                          p_input->stream.p_selected_area );
 
-               vlc_mutex_unlock( &p_input->stream.stream_lock );
-       }
+        vlc_mutex_lock( &p_input->stream.stream_lock );
+        vlc_mutex_unlock( &p_input->stream.stream_lock );
+    }
 }
 
 void VlcWrapper::ChapterInfo( int32 &currentIndex, int32 &maxIndex )
@@ -833,28 +990,41 @@ void VlcWrapper::ChapterInfo( int32 &currentIndex, int32 &maxIndex )
        }
 }
 
-void VlcWrapper::toggleTitle(int i_title)
+/****************
+ * Miscellanous *
+ ****************/
+void VlcWrapper::LoadSubFile( const char * psz_file )
 {
-    if( p_input != NULL )
-    {
-        input_ChangeArea( p_input,
-                          p_input->stream.pp_areas[i_title] );
-
-        vlc_mutex_lock( &p_input->stream.stream_lock );
-
-        vlc_mutex_unlock( &p_input->stream.stream_lock );
-    }
+    config_PutPsz( p_intf, "sub-file", strdup( psz_file ) );
 }
 
-void VlcWrapper::toggleChapter(int i_chapter)
+void VlcWrapper::FilterChange()
 {
-    if( p_input != NULL )
+    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_input->stream.p_selected_area->i_part = i_chapter;
-        input_ChangeArea( p_input,
-                          p_input->stream.p_selected_area );
+        p_vout->b_filter_change = VLC_TRUE;
+        vlc_object_release( p_vout );
+    }
 
-        vlc_mutex_lock( &p_input->stream.stream_lock );
-        vlc_mutex_unlock( &p_input->stream.stream_lock );
+    /* 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 ) )
+        {
+            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 );
 }