X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fbeos%2FVlcWrapper.cpp;h=299901eb90e244b9bb99681a4964108e157be91a;hb=65fd1e940bd5dfe2b436c9776820de3bb94acb61;hp=9d18dfe2a51b0a32386a8ed7a9e8123dc74c9214;hpb=2ea2975bed5c4e80b1edc318437db95987302daa;p=vlc diff --git a/modules/gui/beos/VlcWrapper.cpp b/modules/gui/beos/VlcWrapper.cpp index 9d18dfe2a5..299901eb90 100644 --- a/modules/gui/beos/VlcWrapper.cpp +++ b/modules/gui/beos/VlcWrapper.cpp @@ -1,8 +1,8 @@ /***************************************************************************** - * intf_vlc_wrapper.h: BeOS plugin for vlc (derived from MacOS X port ) + * VlcWrapper.cpp: BeOS plugin for vlc (derived from MacOS X port) ***************************************************************************** * Copyright (C) 2001 VideoLAN - * $Id: VlcWrapper.cpp,v 1.9 2002/10/30 00:59:22 titer Exp $ + * $Id$ * * Authors: Florian G. Pflug * Jon Lech Johansen @@ -24,158 +24,447 @@ * along with this program{} if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************/ -/* VLC headers */ +#include +#include #include #include #include -#include -#include +#include +extern "C" +{ + #include // needed here when compiling without plugins + #include + #include +} #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; +} -Intf_VLCWrapper::Intf_VLCWrapper(intf_thread_t *p_interface) +/* constructor */ +VlcWrapper::VlcWrapper( intf_thread_t *p_interface ) { p_intf = p_interface; + p_input = NULL; + p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, + FIND_ANYWHERE ); +} + +/* destructor */ +VlcWrapper::~VlcWrapper() +{ + if( p_input ) + vlc_object_release( p_input ); + + if( p_playlist ) + vlc_object_release( p_playlist ); +} + +/* UpdateInput: updates p_input */ +void VlcWrapper::UpdateInput() +{ + if( !p_input ) + p_input = (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT, + FIND_ANYWHERE ); + + if( p_input ) + if( p_input->b_dead ) + { + vlc_object_release( p_input ); + p_input = NULL; + } } -Intf_VLCWrapper::~Intf_VLCWrapper() + +/*************************** + * input infos and control * + ***************************/ + +bool VlcWrapper::HasInput() { + return ( p_input != NULL ); } + +int VlcWrapper::InputStatus() +{ + if( !p_input ) + { + return UNDEF_S; + } -/* playlist control */ -bool Intf_VLCWrapper::playlistPlay() + vlc_value_t state; + var_Get( p_input, "state", &state ); + return state.i_int; +} + +int VlcWrapper::InputRate() { - playlist_t *p_playlist = - (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, - FIND_ANYWHERE ); + if( !p_input ) + { + return DEFAULT_RATE; + } + + return p_input->stream.control.i_rate; +} - vlc_mutex_lock( &p_playlist->object_lock ); - if( p_playlist->i_size ) +void VlcWrapper::InputSetRate( int rate ) +{ + if( !p_input ) { - vlc_mutex_unlock( &p_playlist->object_lock ); - playlist_Play( p_playlist ); - vlc_object_release( p_playlist ); + return; } - else + var_SetInteger( p_input, "rate", rate ); +} + +BList * VlcWrapper::GetChannels( int i_cat ) +{ + if( p_input ) { - vlc_mutex_unlock( &p_playlist->object_lock ); - vlc_object_release( p_playlist ); + 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( !p_input->stream.pp_es[i]->psz_desc || + !*p_input->stream.pp_es[i]->psz_desc ) + trackName = _(""); + else + 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 ); + list->AddItem( menuItem ); + } + } + + vlc_mutex_unlock( &p_input->stream.stream_lock ); + + return list; } + return NULL; +} - return( true ); +void VlcWrapper::ToggleLanguage( int i_language ) +{ + es_descriptor_t * p_es = NULL; + es_descriptor_t * p_es_old = NULL; + + vlc_mutex_lock( &p_input->stream.stream_lock ); + for( unsigned int i = 0; i < p_input->stream.i_selected_es_number ; i++ ) + { + if( p_input->stream.pp_selected_es[i]->i_cat == AUDIO_ES ) + { + p_es_old = p_input->stream.pp_selected_es[i]; + break; + } + } + vlc_mutex_unlock( &p_input->stream.stream_lock ); + + if( i_language != -1 ) + { + p_es = p_input->stream.pp_es[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_es, VLC_TRUE ); + } } -void Intf_VLCWrapper::playlistPause() +void VlcWrapper::ToggleSubtitle( int i_subtitle ) { - toggle_mute( ); - playlist_t *p_playlist = - (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, - FIND_ANYWHERE ); - playlist_Pause( p_playlist ); - vlc_object_release( p_playlist ); + es_descriptor_t * p_es = NULL; + es_descriptor_t * p_es_old = NULL; + + vlc_mutex_lock( &p_input->stream.stream_lock ); + for( unsigned int i = 0; i < p_input->stream.i_selected_es_number ; i++ ) + { + if( p_input->stream.pp_selected_es[i]->i_cat == SPU_ES ) + { + p_es_old = p_input->stream.pp_selected_es[i]; + break; + } + } + vlc_mutex_unlock( &p_input->stream.stream_lock ); + + if( i_subtitle != -1 ) + { + p_es = p_input->stream.pp_es[i_subtitle]; + } + 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_es, VLC_TRUE ); + } } -void Intf_VLCWrapper::playlistStop() +const char * VlcWrapper::GetTimeAsString() { - playlist_t *p_playlist = - (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, - FIND_ANYWHERE ); - playlist_Stop( p_playlist ); - vlc_object_release( p_playlist ); + static char psz_time[ MSTRTIME_MAX_SIZE ]; + + if( !p_input ) + { + return ("-:--:--"); + } + + 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_time; } -void Intf_VLCWrapper::playlistNext() +float VlcWrapper::GetTimeAsFloat() { - playlist_t *p_playlist = - (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, - FIND_ANYWHERE ); + if( !p_input ) + { + return 0.0; + } + + vlc_value_t pos; + var_Get( p_input, "position", &pos ); + return pos.f_float; +} - playlist_Next( p_playlist ); - vlc_object_release( p_playlist ); +void VlcWrapper::SetTimeAsFloat( float f_position ) +{ + if( !p_input ) + { + return; + } + + vlc_value_t pos; + pos.f_float = f_position / SEEKSLIDER_RANGE; + var_Set( p_input, "position", pos ); } -void Intf_VLCWrapper::playlistPrev() +bool VlcWrapper::IsPlaying() { - playlist_t *p_playlist = - (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, - FIND_ANYWHERE ); + bool playing = false; + if( p_input ) + { + switch( p_input->stream.control.i_status ) + { + case PLAYING_S: + case FORWARD_S: + case BACKWARD_S: + playing = true; + break; + case PAUSE_S: + case UNDEF_S: + default: + break; + } + } + return playing; - playlist_Prev( p_playlist ); - vlc_object_release( p_playlist ); } -void Intf_VLCWrapper::playlistSkip(int i) +/************ + * 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(), + 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( config_GetInt( p_intf, "beos-dvdmenus" ) ) + o_device.Prepend( "dvdplay:" ); + else + o_device.Prepend( "dvdold:" ); + playlist_Add( p_playlist, o_device.String(), o_device.String(), + PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END ); +} + +int VlcWrapper::PlaylistSize() { - playlist_t *p_playlist = - (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, - FIND_ANYWHERE ); + vlc_mutex_lock( &p_playlist->object_lock ); + int i_size = p_playlist->i_size; + vlc_mutex_unlock( &p_playlist->object_lock ); + return i_size; +} - playlist_Skip( p_playlist, i ); - vlc_object_release( p_playlist ); +char * VlcWrapper::PlaylistItemName( int i ) +{ + return p_playlist->pp_items[i]->input.psz_name; +} + +int VlcWrapper::PlaylistCurrent() +{ + return p_playlist->i_index; } -void Intf_VLCWrapper::playlistGoto(int i) +bool VlcWrapper::PlaylistPlay() { - playlist_t *p_playlist = - (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, - FIND_ANYWHERE ); + if( PlaylistSize() ) + { + playlist_Play( p_playlist ); + } + return( true ); +} - playlist_Goto( p_playlist, i ); - vlc_object_release( p_playlist ); +void VlcWrapper::PlaylistPause() +{ + if( p_input ) + { + var_SetInteger( p_input, "state", PAUSE_S ); + } } -void Intf_VLCWrapper::playlistJumpTo( int pos ) +void VlcWrapper::PlaylistStop() { -#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 + playlist_Stop( p_playlist ); } -int Intf_VLCWrapper::playlistCurrentPos() +void VlcWrapper::PlaylistNext() { - playlistLock(); - int pos = p_intf->p_sys->p_playlist->i_index; - playlistUnlock(); - return pos; + playlist_Next( p_playlist ); } -int Intf_VLCWrapper::playlistSize() +void VlcWrapper::PlaylistPrev() { - playlistLock(); - int size = p_intf->p_sys->p_playlist->i_size; - playlistUnlock(); - return size; + playlist_Prev( p_playlist ); } -void Intf_VLCWrapper::playlistLock() +void VlcWrapper::GetPlaylistInfo( int32& currentIndex, int32& maxIndex ) { - vlc_mutex_lock( &p_intf->p_sys->p_playlist->object_lock ); + 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 -> why?!?*/; + else + maxIndex = -1; + + vlc_mutex_unlock( &p_playlist->object_lock ); + } } -void Intf_VLCWrapper::playlistUnlock() +void VlcWrapper::PlaylistJumpTo( int pos ) { - vlc_mutex_unlock( &p_intf->p_sys->p_playlist->object_lock ); + playlist_Goto( p_playlist, pos ); } -void Intf_VLCWrapper::getNavCapabilities( bool* canSkipPrev, - bool* canSkipNext ) +void VlcWrapper::GetNavCapabilities( bool *canSkipPrev, bool *canSkipNext ) { if ( canSkipPrev && canSkipNext ) { @@ -183,36 +472,33 @@ void Intf_VLCWrapper::getNavCapabilities( bool* canSkipPrev, *canSkipPrev = false; *canSkipNext = false; // get playlist info - playlistLock(); - int pos = p_intf->p_sys->p_playlist->i_index; - int size = p_intf->p_sys->p_playlist->i_size; - playlistUnlock(); + int pos = PlaylistCurrent(); + int size = PlaylistSize(); - /* input_thread_t* input = p_input_bank->pp_input[0]; */ - input_thread_t* input = p_intf->p_sys->p_input; // see if we have got a stream going - if ( input ) + if ( p_input ) { - vlc_mutex_lock( &input->stream.stream_lock ); + vlc_mutex_lock( &p_input->stream.stream_lock ); - bool hasTitles = input->stream.i_area_nb > 1; - int numChapters = input->stream.p_selected_area->i_part_nb; + bool hasTitles = p_input->stream.i_area_nb > 1; + int numChapters = p_input->stream.p_selected_area->i_part_nb; bool hasChapters = numChapters > 1; // first, look for chapters if ( hasChapters ) { - *canSkipPrev = input->stream.p_selected_area->i_part > 0; - *canSkipNext = input->stream.p_selected_area->i_part < - input->stream.p_selected_area->i_part_nb - 1; + *canSkipPrev = p_input->stream.p_selected_area->i_part > 0; + *canSkipNext = p_input->stream.p_selected_area->i_part < + p_input->stream.p_selected_area->i_part_nb - 1; } // if one of the skip capabilities is false, // make it depend on titles instead if ( !*canSkipPrev && hasTitles ) - *canSkipPrev = input->stream.p_selected_area->i_id > 1; + *canSkipPrev = p_input->stream.p_selected_area->i_id > 1; if ( !*canSkipNext && hasTitles ) - *canSkipNext = input->stream.p_selected_area->i_id < input->stream.i_area_nb - 1; + *canSkipNext = p_input->stream.p_selected_area->i_id < + p_input->stream.i_area_nb - 1; - vlc_mutex_unlock( &input->stream.stream_lock ); + vlc_mutex_unlock( &p_input->stream.stream_lock ); } // last but not least, make capabilities depend on playlist if ( !*canSkipPrev ) @@ -222,26 +508,24 @@ void Intf_VLCWrapper::getNavCapabilities( bool* canSkipPrev, } } -void Intf_VLCWrapper::navigatePrev() +void VlcWrapper::NavigatePrev() { -#if 0 bool hasSkiped = false; - input_thread_t* input = p_input_bank->pp_input[0]; // see if we have got a stream going - if ( input ) + if ( p_input ) { // get information from stream (lock it while looking at it) - vlc_mutex_lock( &input->stream.stream_lock ); + vlc_mutex_lock( &p_input->stream.stream_lock ); - int currentTitle = input->stream.p_selected_area->i_id; - int currentChapter = input->stream.p_selected_area->i_part; - int numTitles = input->stream.i_area_nb; + int currentTitle = p_input->stream.p_selected_area->i_id; + int currentChapter = p_input->stream.p_selected_area->i_part; + int numTitles = p_input->stream.i_area_nb; bool hasTitles = numTitles > 1; - int numChapters = input->stream.p_selected_area->i_part_nb; + int numChapters = p_input->stream.p_selected_area->i_part_nb; bool hasChapters = numChapters > 1; - vlc_mutex_unlock( &input->stream.stream_lock ); + vlc_mutex_unlock( &p_input->stream.stream_lock ); // first, look for chapters if ( hasChapters ) @@ -251,7 +535,7 @@ void Intf_VLCWrapper::navigatePrev() if ( currentChapter >= 0 ) { - toggleChapter( currentChapter ); + ToggleChapter( currentChapter ); hasSkiped = true; } } @@ -263,7 +547,7 @@ void Intf_VLCWrapper::navigatePrev() // disallow area 0 since it is used for video_ts.vob if( currentTitle > 0 ) { - toggleTitle(currentTitle); + ToggleTitle(currentTitle); hasSkiped = true; } } @@ -271,30 +555,27 @@ void Intf_VLCWrapper::navigatePrev() } // last but not least, skip to previous file if ( !hasSkiped ) - playlistPrev(); -#endif + PlaylistPrev(); } -void Intf_VLCWrapper::navigateNext() +void VlcWrapper::NavigateNext() { -#if 0 bool hasSkiped = false; - input_thread_t* input = p_input_bank->pp_input[0]; // see if we have got a stream going - if ( input ) + if ( p_input ) { // get information from stream (lock it while looking at it) - vlc_mutex_lock( &input->stream.stream_lock ); + vlc_mutex_lock( &p_input->stream.stream_lock ); - int currentTitle = input->stream.p_selected_area->i_id; - int currentChapter = input->stream.p_selected_area->i_part; - int numTitles = input->stream.i_area_nb; + int currentTitle = p_input->stream.p_selected_area->i_id; + int currentChapter = p_input->stream.p_selected_area->i_part; + int numTitles = p_input->stream.i_area_nb; bool hasTitles = numTitles > 1; - int numChapters = input->stream.p_selected_area->i_part_nb; + int numChapters = p_input->stream.p_selected_area->i_part_nb; bool hasChapters = numChapters > 1; - vlc_mutex_unlock( &input->stream.stream_lock ); + vlc_mutex_unlock( &p_input->stream.stream_lock ); // first, look for chapters if ( hasChapters ) @@ -303,7 +584,7 @@ void Intf_VLCWrapper::navigateNext() currentChapter++; if ( currentChapter < numChapters ) { - toggleChapter( currentChapter ); + ToggleChapter( currentChapter ); hasSkiped = true; } } @@ -315,7 +596,7 @@ void Intf_VLCWrapper::navigateNext() // disallow area 0 since it is used for video_ts.vob if ( currentTitle < numTitles - 1 ) { - toggleTitle(currentTitle); + ToggleTitle(currentTitle); hasSkiped = true; } } @@ -323,506 +604,409 @@ void Intf_VLCWrapper::navigateNext() } // last but not least, skip to next file if ( !hasSkiped ) - playlistNext(); -#endif + PlaylistNext(); } +/************************* + * Playlist manipulation * + *************************/ -//void Intf_VLCWrapper::channelNext() -//{ -// intf_thread_t * p_intf = p_main->p_intf; -// -// p_intf->p_sys->i_channel++; -// -// intf_WarnMsg( 3, "intf info: joining channel %d", p_intf->p_sys->i_channel ); -// -// vlc_mutex_lock( &p_intf->change_lock ); -// -// network_ChannelJoin( p_intf->p_sys->i_channel ); -// p_intf->pf_manage( p_intf ); -// -// vlc_mutex_unlock( &p_intf->change_lock ); -//} -// -//void Intf_VLCWrapper::channelPrev() -//{ -// intf_thread_t * p_intf = p_main->p_intf; -// -// if ( p_intf->p_sys->i_channel ) -// { -// p_intf->p_sys->i_channel--; -// } -// -// intf_WarnMsg( 3, "intf info: joining channel %d", p_intf->p_sys->i_channel ); -// -// vlc_mutex_lock( &p_intf->change_lock ); -// -// network_ChannelJoin( p_intf->p_sys->i_channel ); -// p_intf->pf_manage( p_intf ); -// -// vlc_mutex_unlock( &p_intf->change_lock ); -// -//} - -void Intf_VLCWrapper::loop() +// PlaylistLock +bool +VlcWrapper::PlaylistLock() const { - if ( p_intf->p_sys->b_loop ) - { - playlist_Delete( p_intf->p_sys->p_playlist, - p_intf->p_sys->p_playlist->i_size - 1 ); - } - else - { - playlist_Add( p_intf->p_sys->p_playlist, "vlc:loop", - PLAYLIST_APPEND | PLAYLIST_GO, - PLAYLIST_END ); - } - p_intf->p_sys->b_loop = !p_intf->p_sys->b_loop; +// TODO: search and destroy -> deadlock! +return true; + if ( p_playlist ) + { + vlc_mutex_lock( &p_playlist->object_lock ); + return true; + } + return false; } - - /* playback control */ -void Intf_VLCWrapper::playSlower() +// PlaylistUnlock +void +VlcWrapper::PlaylistUnlock() const { - if( p_intf->p_sys->p_input != NULL ) - { - input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_SLOWER ); - } - if (p_intf->p_sys->p_input->stream.control.i_rate == DEFAULT_RATE) - { - toggle_mute( ); - } - else - { - toggle_mute ( ); - } +// TODO: search and destroy -> deadlock! +return; + vlc_mutex_unlock( &p_playlist->object_lock ); } -void Intf_VLCWrapper::playFaster() +// PlaylistItemAt +void* +VlcWrapper::PlaylistItemAt( int index ) const { - if( p_intf->p_sys->p_input != NULL ) - { - input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_FASTER ); - } - if (p_intf->p_sys->p_input->stream.control.i_rate == DEFAULT_RATE) - { - toggle_mute( ); - } - else - { - toggle_mute ( ); - } + playlist_item_t* item = NULL; + if ( index >= 0 && index < p_playlist->i_size ) + item = p_playlist->pp_items[index]; + return (void*)item; } -void Intf_VLCWrapper::volume_mute() +// PlaylistRemoveItem +void* +VlcWrapper::PlaylistRemoveItem( int index ) const { - p_intf->p_sys->p_aout = - (aout_instance_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT, - FIND_ANYWHERE ); - if( p_intf->p_sys->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 ) { - p_intf->p_sys->i_saved_volume = p_intf->p_sys->p_aout->output.i_volume; - p_intf->p_sys->p_aout->output.i_volume = 0; - p_intf->p_sys->b_mute = 1; + // 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 ); } - } - -} - -void Intf_VLCWrapper::volume_restore() -{ - p_intf->p_sys->p_aout = - (aout_instance_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT, - FIND_ANYWHERE ); - if( p_intf->p_sys->p_aout != NULL ) - { - p_intf->p_sys->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; - } - + } + return (void*)copy; } -void Intf_VLCWrapper::set_volume(int value) +// PlaylistRemoveItem +void* +VlcWrapper::PlaylistRemoveItem( void* item ) const { - p_intf->p_sys->p_aout = - (aout_instance_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT, - FIND_ANYWHERE ); - if( p_intf->p_sys->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_intf->p_sys->p_aout->mixer_lock ); - // unmute volume if muted - if ( p_intf->p_sys->b_mute ) + playlist_item_t* copy = NULL; + for ( int32 i = 0; i < p_playlist->i_size; i++ ) + { + if ( p_playlist->pp_items[i] == item ) { - p_intf->p_sys->b_mute = 0; - p_intf->p_sys->p_aout->output.i_volume = value; + copy = (playlist_item_t*)PlaylistRemoveItem( i ); + break; } - vlc_mutex_unlock( &p_intf->p_sys->p_aout->mixer_lock ); - } + } + return (void*)copy; } -void Intf_VLCWrapper::toggle_mute() +// PlaylistAddItem +bool +VlcWrapper::PlaylistAddItem( void* item, int index ) const { - p_intf->p_sys->p_aout = - (aout_instance_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT, - FIND_ANYWHERE ); - if( p_intf->p_sys->p_aout != NULL ) - { - if ( p_intf->p_sys->b_mute ) - { - volume_restore(); - } - else - { - volume_mute(); - } + 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; } -bool Intf_VLCWrapper::is_muted() +// PlaylistCloneItem +void* +VlcWrapper::PlaylistCloneItem( void* castToItem ) const { - bool muted = true; - - p_intf->p_sys->p_aout = - (aout_instance_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT, - FIND_ANYWHERE ); - if( p_intf->p_sys->p_aout != NULL ) + playlist_item_t* copy = NULL; + playlist_item_t* item = (playlist_item_t*)castToItem; + if ( item ) { - vlc_mutex_lock( &p_intf->p_sys->p_aout->mixer_lock ); - if( p_intf->p_sys->p_aout->output.i_volume > 0 ) + copy = (playlist_item_t*)malloc( sizeof( playlist_item_t ) ); + if ( copy ) { - muted = false; + // make a copy of the item at index + *copy = *item; + copy->input.psz_name = strdup( item->input.psz_name ); + copy->input.psz_uri = strdup( item->input.psz_uri ); } - vlc_mutex_unlock( &p_intf->p_sys->p_aout->mixer_lock ); -// unfortunately, this is not reliable! -// return p_main->p_intf->p_sys->b_mute; } - return muted; + return (void*)copy; } -bool Intf_VLCWrapper::is_playing() +// 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; +} - bool playing = false; - if ( p_intf->p_sys->p_input ) - { - switch ( p_intf->p_sys->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; +/********* + * audio * + *********/ + +unsigned short VlcWrapper::GetVolume() +{ + unsigned short i_volume; + aout_VolumeGet( p_intf, (audio_volume_t*)&i_volume ); + return i_volume; } -void Intf_VLCWrapper::maxvolume() +void VlcWrapper::SetVolume( int value ) { - p_intf->p_sys->p_aout = - (aout_instance_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT, - FIND_ANYWHERE ); - if( p_intf->p_sys->p_aout != NULL ) + if ( p_intf->p_sys->b_mute ) { - if( p_intf->p_sys->b_mute ) - { - p_intf->p_sys->i_saved_volume = AOUT_VOLUME_MAX; - } - else - { - p_intf->p_sys->p_aout->output.i_volume = AOUT_VOLUME_MAX; - } + p_intf->p_sys->b_mute = 0; } + aout_VolumeSet( p_intf, value ); } -bool Intf_VLCWrapper::has_audio() +void VlcWrapper::VolumeMute() { - p_intf->p_sys->p_aout = - (aout_instance_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT, - FIND_ANYWHERE ); - return( p_intf->p_sys->p_aout != NULL ); + aout_VolumeMute( p_intf, NULL ); + p_intf->p_sys->b_mute = 1; } - /* playback info */ - -const char* Intf_VLCWrapper::getTimeAsString() +void VlcWrapper::VolumeRestore() { - static char psz_currenttime[ OFFSETTOTIME_MAX_SIZE ]; - - if( p_intf->p_sys->p_input == NULL ) - { - return ("-:--:--"); - } - - input_OffsetToTime( p_intf->p_sys->p_input, - psz_currenttime, - p_intf->p_sys->p_input->stream.p_selected_area->i_tell ); + audio_volume_t dummy; + aout_VolumeMute( p_intf, &dummy ); + p_intf->p_sys->b_mute = 0; +} - return(psz_currenttime); +bool VlcWrapper::IsMuted() +{ + return p_intf->p_sys->b_mute; } -float Intf_VLCWrapper::getTimeAsFloat() +/******* + * DVD * + *******/ + +bool VlcWrapper::IsUsingMenus() { - float f_time = 0.0; + if( !p_input ) + return false; - if( p_intf->p_sys->p_input != NULL ) + vlc_mutex_lock( &p_playlist->object_lock ); + if( p_playlist->i_index < 0 ) { - f_time = (float)p_intf->p_sys->p_input->stream.p_selected_area->i_tell / - (float)p_intf->p_sys->p_input->stream.p_selected_area->i_size; - } - else + 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 ) ) { - f_time = 0.0; + vlc_mutex_unlock( &p_playlist->object_lock ); + return true; } - return( f_time ); + vlc_mutex_unlock( &p_playlist->object_lock ); + + return false; } -void Intf_VLCWrapper::setTimeAsFloat(float f_position) +bool VlcWrapper::HasTitles() { - if( p_intf->p_sys->p_input != NULL ) - { - input_Seek( p_intf->p_sys->p_input, - (long long int)(p_intf->p_sys->p_input->stream.p_selected_area->i_size - * f_position / SEEKSLIDER_RANGE ), - INPUT_SEEK_SET); - } -} + if( !p_input ) + return false; -/* bool Intf_VLCWrapper::playlistPlaying() -{ - return( !p_intf->p_sys->p_playlist->b_stopped ); -} */ + return ( p_input->stream.i_area_nb > 1 ); +} -BList *Intf_VLCWrapper::playlistAsArray() -{ - int i; - playlist_t *p_playlist = - (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, - FIND_ANYWHERE ); +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 ); - BList* p_list = new BList(p_playlist->i_size); - - vlc_mutex_lock( &p_playlist->object_lock ); + return list; + } + return NULL; +} - for( i = 0; i < p_playlist->i_size; i++ ) +void VlcWrapper::PrevTitle() +{ + int i_id; + i_id = p_input->stream.p_selected_area->i_id - 1; + if( i_id > 0 ) { - p_list->AddItem(new BString(p_playlist->pp_items[i]->psz_name)); + ToggleTitle(i_id); } - - vlc_mutex_unlock( &p_playlist->object_lock ); - vlc_object_release( p_playlist ); - return( p_list ); } -// getPlaylistInfo -void -Intf_VLCWrapper::getPlaylistInfo( int32& currentIndex, int32& maxIndex ) +void VlcWrapper::NextTitle() { - currentIndex = -1; - maxIndex = -1; - if ( playlist_t* list = (playlist_t*)p_intf->p_sys->p_playlist ) - { - maxIndex = list->i_size; - if ( maxIndex > 0 ) - currentIndex = list->i_index + 1; - else - maxIndex = -1; - } + unsigned int i_id; + i_id = p_input->stream.p_selected_area->i_id + 1; + if( i_id < p_input->stream.i_area_nb ) + { + ToggleTitle(i_id); + } } -// getTitleInfo -void -Intf_VLCWrapper::getTitleInfo( int32& currentIndex, int32& maxIndex ) +void VlcWrapper::ToggleTitle(int i_title) { - currentIndex = -1; - maxIndex = -1; - if ( input_thread_t* input = p_intf->p_sys->p_input ) - { - vlc_mutex_lock( &input->stream.stream_lock ); + if( p_input != NULL ) + { + input_ChangeArea( p_input, + p_input->stream.pp_areas[i_title] ); - maxIndex = input->stream.i_area_nb - 1; - if ( maxIndex > 0) - currentIndex = input->stream.p_selected_area->i_id; - else - maxIndex = -1; + vlc_mutex_lock( &p_input->stream.stream_lock ); - vlc_mutex_unlock( &input->stream.stream_lock ); - } + vlc_mutex_unlock( &p_input->stream.stream_lock ); + } } -// getChapterInfo -void -Intf_VLCWrapper::getChapterInfo( int32& currentIndex, int32& maxIndex ) +void VlcWrapper::TitleInfo( int32 ¤tIndex, int32 &maxIndex ) { currentIndex = -1; maxIndex = -1; - if ( input_thread_t* input = p_intf->p_sys->p_input ) + if ( p_input ) { - vlc_mutex_lock( &input->stream.stream_lock ); + vlc_mutex_lock( &p_input->stream.stream_lock ); - maxIndex = input->stream.p_selected_area->i_part_nb - 1; + maxIndex = p_input->stream.i_area_nb - 1; if ( maxIndex > 0) - currentIndex = input->stream.p_selected_area->i_part; + currentIndex = p_input->stream.p_selected_area->i_id; else maxIndex = -1; - vlc_mutex_unlock( &input->stream.stream_lock ); + vlc_mutex_unlock( &p_input->stream.stream_lock ); } } - /* open file/disc/network */ -void Intf_VLCWrapper::openFiles( BList* o_files, bool replace ) +bool VlcWrapper::HasChapters() { - BString *o_file; - playlist_t *p_playlist = p_intf->p_sys->p_playlist; - - while( ( o_file = (BString *)o_files->LastItem() ) ) + if( !p_input ) { - o_files->RemoveItem(o_files->CountItems() - 1); - playlist_Add( p_playlist, o_file->String(), - PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END ); - delete o_file; + return false; } - - vlc_object_release( p_playlist ); + return ( p_input->stream.p_selected_area->i_part_nb > 1 ); } -void Intf_VLCWrapper::openDisc(BString o_type, BString o_device, int i_title, int i_chapter) +BList * VlcWrapper::GetChapters() { - BString o_source(""); - o_source << o_type << ":" << o_device ; - - playlist_t *p_playlist = - (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, - FIND_ANYWHERE ); - playlist_Add( p_playlist, o_source.String(), - PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END ); - vlc_object_release( p_playlist ); -} - -void Intf_VLCWrapper::openNet(BString o_addr, int i_port) -{ -} + 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 ); -void Intf_VLCWrapper::openNetChannel(BString o_addr, int i_port) -{ + return list; + } + return NULL; } -void Intf_VLCWrapper::openNetHTTP(BString o_addr) +void VlcWrapper::PrevChapter() { + int i_id; + i_id = p_input->stream.p_selected_area->i_part - 1; + if( i_id >= 0 ) + { + ToggleChapter(i_id); + } } - - /* menus management */ -void Intf_VLCWrapper::toggleProgram(int i_program){} - -void Intf_VLCWrapper::toggleTitle(int i_title) +void VlcWrapper::NextChapter() { - if( p_intf->p_sys->p_input != NULL ) + int i_id; + i_id = p_input->stream.p_selected_area->i_part + 1; + if( i_id >= 0 ) { - input_ChangeArea( p_intf->p_sys->p_input, - p_intf->p_sys->p_input->stream.pp_areas[i_title] ); - - vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock ); - - vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock ); + ToggleChapter(i_id); } } -void Intf_VLCWrapper::toggleChapter(int i_chapter) +void VlcWrapper::ToggleChapter(int i_chapter) { - if( p_intf->p_sys->p_input != NULL ) + if( p_input != NULL ) { - p_intf->p_sys->p_input->stream.p_selected_area->i_part = i_chapter; - input_ChangeArea( p_intf->p_sys->p_input, - p_intf->p_sys->p_input->stream.p_selected_area ); + p_input->stream.p_selected_area->i_part = i_chapter; + input_ChangeArea( p_input, + p_input->stream.p_selected_area ); - vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock ); - vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock ); + vlc_mutex_lock( &p_input->stream.stream_lock ); + vlc_mutex_unlock( &p_input->stream.stream_lock ); } } -void Intf_VLCWrapper::toggleLanguage(int i_language) +void VlcWrapper::ChapterInfo( int32 ¤tIndex, int32 &maxIndex ) { + currentIndex = -1; + maxIndex = -1; + if ( p_input ) + { + vlc_mutex_lock( &p_input->stream.stream_lock ); - int32 i_old = -1; - int i_cat = AUDIO_ES; - - vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock ); - for( int i = 0; i < p_intf->p_sys->p_input->stream.i_selected_es_number ; i++ ) - { - if( p_intf->p_sys->p_input->stream.pp_selected_es[i]->i_cat == i_cat ) - { - i_old = i; - break; - } - } - vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock ); - - msg_Info( p_intf, "Old: %d, New: %d", i_old, i_language); - if( i_language != -1 ) - { - input_ToggleES( p_intf->p_sys->p_input, - p_intf->p_sys->p_input->stream.pp_selected_es[i_language], - VLC_TRUE ); - } + maxIndex = p_input->stream.p_selected_area->i_part_nb - 1; + if ( maxIndex > 0) + currentIndex = p_input->stream.p_selected_area->i_part; + else + maxIndex = -1; - if( (i_old != -1) && (i_old != i_language) ) - { - input_ToggleES( p_intf->p_sys->p_input, - p_intf->p_sys->p_input->stream.pp_selected_es[i_old], - VLC_FALSE ); - } + vlc_mutex_unlock( &p_input->stream.stream_lock ); + } } -void Intf_VLCWrapper::toggleSubtitle(int i_subtitle) +/**************** + * Miscellanous * + ****************/ + +void VlcWrapper::LoadSubFile( const char * psz_file ) { - int32 i_old = -1; - int i_cat = SPU_ES; + config_PutPsz( p_intf, "sub-file", strdup( psz_file ) ); +} - vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock ); - for( int i = 0; i < p_intf->p_sys->p_input->stream.i_selected_es_number ; i++ ) - { - if( p_intf->p_sys->p_input->stream.pp_selected_es[i]->i_cat == i_cat ) - { - i_old = i; - break; - } - } - vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock ); +void VlcWrapper::FilterChange() +{ + if( !p_input ) + return; - msg_Info( p_intf, "Old: %d, New: %d", i_old, i_subtitle); - if( i_subtitle != -1 ) + 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 ) { - input_ToggleES( p_intf->p_sys->p_input, - p_intf->p_sys->p_input->stream.pp_selected_es[i_subtitle], - VLC_TRUE ); + p_vout->b_filter_change = VLC_TRUE; + vlc_object_release( p_vout ); } - if( (i_old != -1) && (i_old != i_subtitle) ) + // restart all video stream + for( unsigned int i = 0; i < p_input->stream.i_es_number; i++ ) { - input_ToggleES( p_intf->p_sys->p_input, - p_intf->p_sys->p_input->stream.pp_selected_es[i_old], - VLC_FALSE ); + 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] ); + } } -} - -int Intf_VLCWrapper::inputGetStatus() -{ - return 0; + vlc_mutex_unlock( &p_input->stream.stream_lock ); }