📄 vlcwrapper.cpp
字号:
*canSkipNext = pos < size - 1; }}void VlcWrapper::NavigatePrev(){ bool hasSkiped = false; // see if we have got a stream going if ( p_input ) { // get information from stream (lock it while looking at it) vlc_mutex_lock( &p_input->stream.stream_lock ); 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 = p_input->stream.p_selected_area->i_part_nb; bool hasChapters = numChapters > 1; vlc_mutex_unlock( &p_input->stream.stream_lock ); // first, look for chapters if ( hasChapters ) { // skip to the previous chapter currentChapter--; if ( currentChapter >= 0 ) { ToggleChapter( currentChapter ); hasSkiped = true; } } // if we couldn't skip chapters, try titles instead if ( !hasSkiped && hasTitles ) { // skip to the previous title currentTitle--; // disallow area 0 since it is used for video_ts.vob if( currentTitle > 0 ) { ToggleTitle(currentTitle); hasSkiped = true; } } } // last but not least, skip to previous file if ( !hasSkiped ) PlaylistPrev();}void VlcWrapper::NavigateNext(){ bool hasSkiped = false; // see if we have got a stream going if ( p_input ) { // get information from stream (lock it while looking at it) vlc_mutex_lock( &p_input->stream.stream_lock ); 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 = p_input->stream.p_selected_area->i_part_nb; bool hasChapters = numChapters > 1; vlc_mutex_unlock( &p_input->stream.stream_lock ); // first, look for chapters if ( hasChapters ) { // skip to the next chapter currentChapter++; if ( currentChapter < numChapters ) { ToggleChapter( currentChapter ); hasSkiped = true; } } // if we couldn't skip chapters, try titles instead if ( !hasSkiped && hasTitles ) { // skip to the next title currentTitle++; // disallow area 0 since it is used for video_ts.vob if ( currentTitle < numTitles - 1 ) { ToggleTitle(currentTitle); hasSkiped = true; } } } // last but not least, skip to next file if ( !hasSkiped ) PlaylistNext();}/************************* * Playlist manipulation * *************************/// PlaylistLockboolVlcWrapper::PlaylistLock() const{// TODO: search and destroy -> deadlock!return true; if ( p_playlist ) { vlc_mutex_lock( &p_playlist->object_lock ); return true; } return false;}// PlaylistUnlockvoidVlcWrapper::PlaylistUnlock() const{// TODO: search and destroy -> deadlock!return; vlc_mutex_unlock( &p_playlist->object_lock );}// PlaylistItemAtvoid*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;}// PlaylistRemoveItemvoid*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;}// PlaylistRemoveItemvoid*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;}// PlaylistAddItemboolVlcWrapper::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;}// PlaylistCloneItemvoid*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 = *item; copy->psz_name = strdup( item->psz_name ); copy->psz_uri = strdup( item->psz_uri ); } } 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.//// PlaylistSetPlayingvoidVlcWrapper::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(){ aout_VolumeMute( p_intf, NULL ); p_intf->p_sys->b_mute = 1;}void VlcWrapper::VolumeRestore(){ audio_volume_t dummy; aout_VolumeMute( p_intf, &dummy ); p_intf->p_sys->b_mute = 0;}bool VlcWrapper::IsMuted(){ return p_intf->p_sys->b_mute;}/******* * DVD * *******/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 );}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); }}void VlcWrapper::NextTitle(){ 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); }}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 ¤tIndex, 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 ) { return false; } 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); }}void VlcWrapper::NextChapter(){ int i_id; i_id = p_input->stream.p_selected_area->i_part + 1; if( i_id >= 0 ) { ToggleChapter(i_id); }}void VlcWrapper::ToggleChapter(int i_chapter){ 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_lock( &p_input->stream.stream_lock ); vlc_mutex_unlock( &p_input->stream.stream_lock ); }}void VlcWrapper::ChapterInfo( int32 ¤tIndex, int32 &maxIndex ){ currentIndex = -1; maxIndex = -1; if ( p_input ) { vlc_mutex_lock( &p_input->stream.stream_lock ); 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; vlc_mutex_unlock( &p_input->stream.stream_lock ); }}/**************** * Miscellanous * ****************/ 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 );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -