1 /*****************************************************************************
2 * VlcWrapper.cpp: BeOS plugin for vlc (derived from MacOS X port)
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
5 * $Id: VlcWrapper.cpp,v 1.30 2003/05/07 14:49:19 titer Exp $
7 * Authors: Florian G. Pflug <fgp@phlo.org>
8 * Jon Lech Johansen <jon-vl@nanocrew.net>
9 * Tony Casltey <tony@castley.net>
10 * Stephan Aßmus <stippi@yellowbites.com>
11 * Eric Petit <titer@videolan.org>
13 * This program is free software{} you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation{} either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY{} without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program{} if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
26 *****************************************************************************/
28 #include <InterfaceKit.h>
29 #include <SupportKit.h>
36 #include <input_ext-plugins.h> // needed here when compiling without plugins
37 #include <audio_output.h>
38 #include <aout_internal.h>
41 #include "VlcWrapper.h"
44 const char * _AddEllipsis( char * string )
47 temp = (char*) calloc( strlen( string ) + 4, 1 );
48 sprintf( temp, "%s%s", string, B_UTF8_ELLIPSIS );
53 VlcWrapper::VlcWrapper( intf_thread_t *p_interface )
57 p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
62 VlcWrapper::~VlcWrapper()
66 vlc_object_release( p_input );
70 vlc_object_release( p_playlist );
74 /* UpdateInput: updates p_input, returns true if the interface needs to
76 bool VlcWrapper::UpdateInput()
80 p_input = (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
88 vlc_object_release( p_input );
97 /***************************
98 * input infos and control *
99 ***************************/
101 bool VlcWrapper::HasInput()
103 return ( p_input != NULL );
106 int VlcWrapper::InputStatus()
112 return p_input->stream.control.i_status;
115 int VlcWrapper::InputRate()
121 return p_input->stream.control.i_rate;
124 void VlcWrapper::InputSlower()
126 if( p_input != NULL )
128 input_SetStatus( p_input, INPUT_STATUS_SLOWER );
132 void VlcWrapper::InputFaster()
134 if( p_input != NULL )
136 input_SetStatus( p_input, INPUT_STATUS_FASTER );
140 BList * VlcWrapper::GetChannels( int i_cat )
146 const char* fieldName;
152 what = SELECT_CHANNEL;
153 fieldName = "channel";
158 what = SELECT_SUBTITLE;
159 fieldName = "subtitle";
166 vlc_mutex_lock( &p_input->stream.stream_lock );
168 /* find which track is currently playing */
169 es_descriptor_t *p_es = NULL;
170 for( i = 0; i < p_input->stream.i_selected_es_number; i++ )
172 if( p_input->stream.pp_selected_es[i]->i_cat == i_cat )
173 p_es = p_input->stream.pp_selected_es[i];
176 /* build a list of all tracks */
177 BList *list = new BList( p_input->stream.i_es_number );
183 message = new BMessage( what );
184 message->AddInt32( fieldName, -1 );
185 menuItem = new BMenuItem( _("None"), message );
187 menuItem->SetMarked( true );
188 list->AddItem( menuItem );
190 for( i = 0; i < p_input->stream.i_es_number; i++ )
192 if( p_input->stream.pp_es[i]->i_cat == i_cat )
194 message = new BMessage( what );
195 message->AddInt32( fieldName, i );
196 if( !p_input->stream.pp_es[i]->psz_desc ||
197 !*p_input->stream.pp_es[i]->psz_desc )
198 trackName = _("<unknown>");
200 trackName = strdup( p_input->stream.pp_es[i]->psz_desc );
201 menuItem = new BMenuItem( trackName, message );
202 if( p_input->stream.pp_es[i] == p_es )
203 menuItem->SetMarked( true );
204 list->AddItem( menuItem );
208 vlc_mutex_unlock( &p_input->stream.stream_lock );
215 void VlcWrapper::ToggleLanguage( int i_language )
217 es_descriptor_t * p_es = NULL;
218 es_descriptor_t * p_es_old = NULL;
220 vlc_mutex_lock( &p_input->stream.stream_lock );
221 for( unsigned int i = 0; i < p_input->stream.i_selected_es_number ; i++ )
223 if( p_input->stream.pp_selected_es[i]->i_cat == AUDIO_ES )
225 p_es_old = p_input->stream.pp_selected_es[i];
229 vlc_mutex_unlock( &p_input->stream.stream_lock );
231 if( i_language != -1 )
233 p_es = p_input->stream.pp_es[i_language];
235 if( p_es == p_es_old )
241 input_ToggleES( p_input, p_es_old, VLC_FALSE );
245 input_ToggleES( p_input, p_es, VLC_TRUE );
249 void VlcWrapper::ToggleSubtitle( int i_subtitle )
251 es_descriptor_t * p_es = NULL;
252 es_descriptor_t * p_es_old = NULL;
254 vlc_mutex_lock( &p_input->stream.stream_lock );
255 for( unsigned int i = 0; i < p_input->stream.i_selected_es_number ; i++ )
257 if( p_input->stream.pp_selected_es[i]->i_cat == SPU_ES )
259 p_es_old = p_input->stream.pp_selected_es[i];
263 vlc_mutex_unlock( &p_input->stream.stream_lock );
265 if( i_subtitle != -1 )
267 p_es = p_input->stream.pp_es[i_subtitle];
269 if( p_es == p_es_old )
275 input_ToggleES( p_input, p_es_old, VLC_FALSE );
279 input_ToggleES( p_input, p_es, VLC_TRUE );
283 const char * VlcWrapper::GetTimeAsString()
285 static char psz_currenttime[ OFFSETTOTIME_MAX_SIZE ];
287 if( p_input == NULL )
292 input_OffsetToTime( p_input,
294 p_input->stream.p_selected_area->i_tell );
296 return(psz_currenttime);
299 float VlcWrapper::GetTimeAsFloat()
303 if( p_input != NULL )
305 f_time = (float)p_input->stream.p_selected_area->i_tell /
306 (float)p_input->stream.p_selected_area->i_size;
315 void VlcWrapper::SetTimeAsFloat( float f_position )
317 if( p_input != NULL )
320 (long long int)(p_input->stream.p_selected_area->i_size
321 * f_position / SEEKSLIDER_RANGE ),
326 bool VlcWrapper::IsPlaying()
329 bool playing = false;
332 switch ( p_input->stream.control.i_status )
355 void VlcWrapper::OpenFiles( BList* o_files, bool replace, int32 index )
357 if ( o_files && o_files->CountItems() > 0)
359 int size = PlaylistSize();
360 bool wasEmpty = ( size < 1 );
362 index = PLAYLIST_END;
363 int mode = index == PLAYLIST_END ? PLAYLIST_APPEND : PLAYLIST_INSERT;
365 /* delete current playlist */
368 for( int i = 0; i < size; i++ )
370 playlist_Delete( p_playlist, 0 );
375 int32 count = o_files->CountItems();
376 for ( int32 i = count - 1; i >= 0; i-- )
378 if ( BString* o_file = (BString *)o_files->RemoveItem( i ) )
380 playlist_Add( p_playlist, o_file->String(),
382 if ( mode == PLAYLIST_INSERT )
387 // TODO: implement a user setting
388 // if to start automatically
389 /* eventually restart playing */
390 if( replace || wasEmpty )
392 playlist_Stop( p_playlist );
393 playlist_Play( p_playlist );
398 void VlcWrapper::OpenDisc(BString o_type, BString o_device, int i_title, int i_chapter)
400 if( config_GetInt( p_intf, "beos-dvdmenus" ) )
401 o_device.Prepend( "dvdplay:" );
403 o_device.Prepend( "dvdold:" );
404 playlist_Add( p_playlist, o_device.String(),
405 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
408 int VlcWrapper::PlaylistSize()
410 vlc_mutex_lock( &p_playlist->object_lock );
411 int i_size = p_playlist->i_size;
412 vlc_mutex_unlock( &p_playlist->object_lock );
416 char * VlcWrapper::PlaylistItemName( int i )
418 return p_playlist->pp_items[i]->psz_name;
421 int VlcWrapper::PlaylistCurrent()
423 return p_playlist->i_index;
426 bool VlcWrapper::PlaylistPlay()
430 playlist_Play( p_playlist );
435 void VlcWrapper::PlaylistPause()
439 input_SetStatus( p_input, INPUT_STATUS_PAUSE );
443 void VlcWrapper::PlaylistStop()
445 playlist_Stop( p_playlist );
448 void VlcWrapper::PlaylistNext()
450 playlist_Next( p_playlist );
453 void VlcWrapper::PlaylistPrev()
455 playlist_Prev( p_playlist );
458 void VlcWrapper::GetPlaylistInfo( int32& currentIndex, int32& maxIndex )
464 vlc_mutex_lock( &p_playlist->object_lock );
466 maxIndex = p_playlist->i_size;
468 currentIndex = p_playlist->i_index/* + 1 -> why?!?*/;
472 vlc_mutex_unlock( &p_playlist->object_lock );
476 void VlcWrapper::PlaylistJumpTo( int pos )
478 playlist_Goto( p_playlist, pos );
481 void VlcWrapper::GetNavCapabilities( bool *canSkipPrev, bool *canSkipNext )
483 if ( canSkipPrev && canSkipNext )
485 // init the parameters
486 *canSkipPrev = false;
487 *canSkipNext = false;
489 int pos = PlaylistCurrent();
490 int size = PlaylistSize();
492 // see if we have got a stream going
495 vlc_mutex_lock( &p_input->stream.stream_lock );
497 bool hasTitles = p_input->stream.i_area_nb > 1;
498 int numChapters = p_input->stream.p_selected_area->i_part_nb;
499 bool hasChapters = numChapters > 1;
500 // first, look for chapters
503 *canSkipPrev = p_input->stream.p_selected_area->i_part > 0;
504 *canSkipNext = p_input->stream.p_selected_area->i_part <
505 p_input->stream.p_selected_area->i_part_nb - 1;
507 // if one of the skip capabilities is false,
508 // make it depend on titles instead
509 if ( !*canSkipPrev && hasTitles )
510 *canSkipPrev = p_input->stream.p_selected_area->i_id > 1;
511 if ( !*canSkipNext && hasTitles )
512 *canSkipNext = p_input->stream.p_selected_area->i_id <
513 p_input->stream.i_area_nb - 1;
515 vlc_mutex_unlock( &p_input->stream.stream_lock );
517 // last but not least, make capabilities depend on playlist
519 *canSkipPrev = pos > 0;
521 *canSkipNext = pos < size - 1;
525 void VlcWrapper::NavigatePrev()
527 bool hasSkiped = false;
529 // see if we have got a stream going
532 // get information from stream (lock it while looking at it)
533 vlc_mutex_lock( &p_input->stream.stream_lock );
535 int currentTitle = p_input->stream.p_selected_area->i_id;
536 int currentChapter = p_input->stream.p_selected_area->i_part;
537 int numTitles = p_input->stream.i_area_nb;
538 bool hasTitles = numTitles > 1;
539 int numChapters = p_input->stream.p_selected_area->i_part_nb;
540 bool hasChapters = numChapters > 1;
542 vlc_mutex_unlock( &p_input->stream.stream_lock );
544 // first, look for chapters
547 // skip to the previous chapter
550 if ( currentChapter >= 0 )
552 ToggleChapter( currentChapter );
556 // if we couldn't skip chapters, try titles instead
557 if ( !hasSkiped && hasTitles )
559 // skip to the previous title
561 // disallow area 0 since it is used for video_ts.vob
562 if( currentTitle > 0 )
564 ToggleTitle(currentTitle);
570 // last but not least, skip to previous file
575 void VlcWrapper::NavigateNext()
577 bool hasSkiped = false;
579 // see if we have got a stream going
582 // get information from stream (lock it while looking at it)
583 vlc_mutex_lock( &p_input->stream.stream_lock );
585 int currentTitle = p_input->stream.p_selected_area->i_id;
586 int currentChapter = p_input->stream.p_selected_area->i_part;
587 int numTitles = p_input->stream.i_area_nb;
588 bool hasTitles = numTitles > 1;
589 int numChapters = p_input->stream.p_selected_area->i_part_nb;
590 bool hasChapters = numChapters > 1;
592 vlc_mutex_unlock( &p_input->stream.stream_lock );
594 // first, look for chapters
597 // skip to the next chapter
599 if ( currentChapter < numChapters )
601 ToggleChapter( currentChapter );
605 // if we couldn't skip chapters, try titles instead
606 if ( !hasSkiped && hasTitles )
608 // skip to the next title
610 // disallow area 0 since it is used for video_ts.vob
611 if ( currentTitle < numTitles - 1 )
613 ToggleTitle(currentTitle);
619 // last but not least, skip to next file
624 /*************************
625 * Playlist manipulation *
626 *************************/
630 VlcWrapper::PlaylistLock() const
632 // TODO: search and destroy -> deadlock!
636 vlc_mutex_lock( &p_playlist->object_lock );
644 VlcWrapper::PlaylistUnlock() const
646 // TODO: search and destroy -> deadlock!
648 vlc_mutex_unlock( &p_playlist->object_lock );
653 VlcWrapper::PlaylistItemAt( int index ) const
655 playlist_item_t* item = NULL;
656 if ( index >= 0 && index < p_playlist->i_size )
657 item = p_playlist->pp_items[index];
661 // PlaylistRemoveItem
663 VlcWrapper::PlaylistRemoveItem( int index ) const
665 playlist_item_t* copy = NULL;
666 // check if item exists at the provided index
667 if ( index >= 0 && index < p_playlist->i_size )
669 playlist_item_t* item = p_playlist->pp_items[index];
672 // make a copy of the removed item
673 copy = (playlist_item_t*)PlaylistCloneItem( (void*)item );
674 // remove item from playlist (unfortunately, this frees it)
675 playlist_Delete( p_playlist, index );
681 // PlaylistRemoveItem
683 VlcWrapper::PlaylistRemoveItem( void* item ) const
685 playlist_item_t* copy = NULL;
686 for ( int32 i = 0; i < p_playlist->i_size; i++ )
688 if ( p_playlist->pp_items[i] == item )
690 copy = (playlist_item_t*)PlaylistRemoveItem( i );
699 VlcWrapper::PlaylistAddItem( void* item, int index ) const
703 playlist_AddItem( p_playlist, (playlist_item_t*)item,
704 PLAYLIST_INSERT, index );
706 // TODO: once playlist is returning useful info, return that instead
712 VlcWrapper::PlaylistCloneItem( void* castToItem ) const
714 playlist_item_t* copy = NULL;
715 playlist_item_t* item = (playlist_item_t*)castToItem;
718 copy = (playlist_item_t*)malloc( sizeof( playlist_item_t ) );
721 // make a copy of the item at index
722 copy->psz_name = strdup( item->psz_name );
723 copy->psz_uri = strdup( item->psz_uri );
724 copy->i_type = item->i_type;
725 copy->i_status = item->i_status;
726 copy->b_autodeletion = item->b_autodeletion;
732 // Careful! You need to know what you're doing here!
733 // The reason for having it, is to be able to deal with
734 // the rather lame list implementation of the playlist.
735 // It is meant to help manipulate the playlist with the above
736 // methods while keeping it valid.
738 // PlaylistSetPlaying
740 VlcWrapper::PlaylistSetPlaying( int index ) const
744 if ( index >= p_playlist->i_size )
745 index = p_playlist->i_size - 1;
746 p_playlist->i_index = index;
754 unsigned short VlcWrapper::GetVolume()
756 unsigned short i_volume;
757 aout_VolumeGet( p_intf, (audio_volume_t*)&i_volume );
761 void VlcWrapper::SetVolume( int value )
763 if ( p_intf->p_sys->b_mute )
765 p_intf->p_sys->b_mute = 0;
767 aout_VolumeSet( p_intf, value );
770 void VlcWrapper::VolumeMute()
772 aout_VolumeGet( p_intf, &p_intf->p_sys->i_saved_volume );
773 aout_VolumeMute( p_intf, NULL );
774 p_intf->p_sys->b_mute = 1;
777 void VlcWrapper::VolumeRestore()
779 aout_VolumeSet( p_intf, p_intf->p_sys->i_saved_volume );
780 p_intf->p_sys->b_mute = 0;
783 bool VlcWrapper::IsMuted()
785 return p_intf->p_sys->b_mute;
792 bool VlcWrapper::HasTitles()
798 return ( p_input->stream.i_area_nb > 1 );
801 BList * VlcWrapper::GetTitles()
805 vlc_mutex_lock( &p_input->stream.stream_lock );
807 BList *list = new BList( p_input->stream.i_area_nb );
811 for( unsigned int i = 1; i < p_input->stream.i_area_nb; i++ )
813 message = new BMessage( TOGGLE_TITLE );
814 message->AddInt32( "index", i );
815 BString helper( "" );
817 menuItem = new BMenuItem( helper.String(), message );
818 menuItem->SetMarked( p_input->stream.p_selected_area->i_id == i );
819 list->AddItem( menuItem );
822 vlc_mutex_unlock( &p_input->stream.stream_lock );
829 void VlcWrapper::PrevTitle()
832 i_id = p_input->stream.p_selected_area->i_id - 1;
839 void VlcWrapper::NextTitle()
842 i_id = p_input->stream.p_selected_area->i_id + 1;
843 if( i_id < p_input->stream.i_area_nb )
849 void VlcWrapper::ToggleTitle(int i_title)
851 if( p_input != NULL )
853 input_ChangeArea( p_input,
854 p_input->stream.pp_areas[i_title] );
856 vlc_mutex_lock( &p_input->stream.stream_lock );
858 vlc_mutex_unlock( &p_input->stream.stream_lock );
862 void VlcWrapper::TitleInfo( int32 ¤tIndex, int32 &maxIndex )
868 vlc_mutex_lock( &p_input->stream.stream_lock );
870 maxIndex = p_input->stream.i_area_nb - 1;
872 currentIndex = p_input->stream.p_selected_area->i_id;
876 vlc_mutex_unlock( &p_input->stream.stream_lock );
880 bool VlcWrapper::HasChapters()
886 return ( p_input->stream.p_selected_area->i_part_nb > 1 );
889 BList * VlcWrapper::GetChapters()
893 vlc_mutex_lock( &p_input->stream.stream_lock );
895 BList *list = new BList( p_input->stream.p_selected_area->i_part_nb );
899 for( unsigned int i = 1;
900 i < p_input->stream.p_selected_area->i_part_nb + 1; i++ )
902 message = new BMessage( TOGGLE_CHAPTER );
903 message->AddInt32( "index", i );
904 BString helper( "" );
906 menuItem = new BMenuItem( helper.String(), message );
907 menuItem->SetMarked( p_input->stream.p_selected_area->i_part == i );
908 list->AddItem( menuItem );
911 vlc_mutex_unlock( &p_input->stream.stream_lock );
918 void VlcWrapper::PrevChapter()
921 i_id = p_input->stream.p_selected_area->i_part - 1;
928 void VlcWrapper::NextChapter()
931 i_id = p_input->stream.p_selected_area->i_part + 1;
938 void VlcWrapper::ToggleChapter(int i_chapter)
940 if( p_input != NULL )
942 p_input->stream.p_selected_area->i_part = i_chapter;
943 input_ChangeArea( p_input,
944 p_input->stream.p_selected_area );
946 vlc_mutex_lock( &p_input->stream.stream_lock );
947 vlc_mutex_unlock( &p_input->stream.stream_lock );
951 void VlcWrapper::ChapterInfo( int32 ¤tIndex, int32 &maxIndex )
957 vlc_mutex_lock( &p_input->stream.stream_lock );
959 maxIndex = p_input->stream.p_selected_area->i_part_nb - 1;
961 currentIndex = p_input->stream.p_selected_area->i_part;
965 vlc_mutex_unlock( &p_input->stream.stream_lock );
973 void VlcWrapper::LoadSubFile( const char * psz_file )
975 config_PutPsz( p_intf, "sub-file", strdup( psz_file ) );
978 void VlcWrapper::FilterChange()
983 vout_thread_t * p_vout;
984 vlc_mutex_lock( &p_input->stream.stream_lock );
986 // Warn the vout we are about to change the filter chain
987 p_vout = (vout_thread_t*)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
991 p_vout->b_filter_change = VLC_TRUE;
992 vlc_object_release( p_vout );
995 // restart all video stream
996 for( unsigned int i = 0; i < p_input->stream.i_es_number; i++ )
998 if( ( p_input->stream.pp_es[i]->i_cat == VIDEO_ES ) &&
999 ( p_input->stream.pp_es[i]->p_decoder_fifo != NULL ) )
1001 input_UnselectES( p_input, p_input->stream.pp_es[i] );
1002 input_SelectES( p_input, p_input->stream.pp_es[i] );
1005 vlc_mutex_unlock( &p_input->stream.stream_lock );