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.23 2003/01/29 00:02:09 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 <audio_output.h>
37 #include <aout_internal.h>
40 #include "VlcWrapper.h"
44 VlcWrapper::VlcWrapper( intf_thread_t *p_interface )
49 p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
54 VlcWrapper::~VlcWrapper()
58 vlc_object_release( p_input );
62 vlc_object_release( p_playlist );
66 vlc_object_release( p_aout );
70 /* UpdateInputAndAOut: updates p_input and p_aout, returns true if the
71 interface needs to be updated */
72 bool VlcWrapper::UpdateInputAndAOut()
76 p_input = (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
81 p_aout = (aout_instance_t*)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
89 vlc_object_release( p_input );
94 vlc_object_release( p_aout );
104 /***************************
105 * input infos and control *
106 ***************************/
108 bool VlcWrapper::HasInput()
110 return ( p_input != NULL );
113 int VlcWrapper::InputStatus()
119 return p_input->stream.control.i_status;
122 int VlcWrapper::InputRate()
128 return p_input->stream.control.i_rate;
131 void VlcWrapper::InputSlower()
133 if( p_input != NULL )
135 input_SetStatus( p_input, INPUT_STATUS_SLOWER );
139 void VlcWrapper::InputFaster()
141 if( p_input != NULL )
143 input_SetStatus( p_input, INPUT_STATUS_FASTER );
147 BList * VlcWrapper::GetChannels( int i_cat )
153 const char* fieldName;
159 what = SELECT_CHANNEL;
160 fieldName = "channel";
165 what = SELECT_SUBTITLE;
166 fieldName = "subtitle";
173 vlc_mutex_lock( &p_input->stream.stream_lock );
175 /* find which track is currently playing */
176 es_descriptor_t *p_es = NULL;
177 for( i = 0; i < p_input->stream.i_selected_es_number; i++ )
179 if( p_input->stream.pp_selected_es[i]->i_cat == i_cat )
180 p_es = p_input->stream.pp_selected_es[i];
183 /* build a list of all tracks */
184 BList *list = new BList( p_input->stream.i_es_number );
190 message = new BMessage( what );
191 message->AddInt32( fieldName, -1 );
192 menuItem = new BMenuItem( "None", message );
194 menuItem->SetMarked( true );
195 list->AddItem( menuItem );
197 for( i = 0; i < p_input->stream.i_es_number; i++ )
199 if( p_input->stream.pp_es[i]->i_cat == i_cat )
201 message = new BMessage( what );
202 message->AddInt32( fieldName, i );
203 if( strlen( p_input->stream.pp_es[i]->psz_desc ) )
204 trackName = strdup( p_input->stream.pp_es[i]->psz_desc );
206 trackName = "<unknown>";
207 menuItem = new BMenuItem( trackName, message );
208 if( p_input->stream.pp_es[i] == p_es )
209 menuItem->SetMarked( true );
210 list->AddItem( menuItem );
214 vlc_mutex_unlock( &p_input->stream.stream_lock );
221 void VlcWrapper::ToggleLanguage( int i_language )
223 es_descriptor_t * p_es = NULL;
224 es_descriptor_t * p_es_old = NULL;
226 vlc_mutex_lock( &p_input->stream.stream_lock );
227 for( unsigned int i = 0; i < p_input->stream.i_selected_es_number ; i++ )
229 if( p_input->stream.pp_selected_es[i]->i_cat == AUDIO_ES )
231 p_es_old = p_input->stream.pp_selected_es[i];
235 vlc_mutex_unlock( &p_input->stream.stream_lock );
237 if( i_language != -1 )
239 p_es = p_input->stream.pp_es[i_language];
241 if( p_es == p_es_old )
247 input_ToggleES( p_input, p_es_old, VLC_FALSE );
251 input_ToggleES( p_input, p_es, VLC_TRUE );
255 void VlcWrapper::ToggleSubtitle( int i_subtitle )
257 es_descriptor_t * p_es = NULL;
258 es_descriptor_t * p_es_old = NULL;
260 vlc_mutex_lock( &p_input->stream.stream_lock );
261 for( unsigned int i = 0; i < p_input->stream.i_selected_es_number ; i++ )
263 if( p_input->stream.pp_selected_es[i]->i_cat == SPU_ES )
265 p_es_old = p_input->stream.pp_selected_es[i];
269 vlc_mutex_unlock( &p_input->stream.stream_lock );
271 if( i_subtitle != -1 )
273 p_es = p_input->stream.pp_es[i_subtitle];
275 if( p_es == p_es_old )
281 input_ToggleES( p_input, p_es_old, VLC_FALSE );
285 input_ToggleES( p_input, p_es, VLC_TRUE );
289 const char * VlcWrapper::GetTimeAsString()
291 static char psz_currenttime[ OFFSETTOTIME_MAX_SIZE ];
293 if( p_input == NULL )
298 input_OffsetToTime( p_input,
300 p_input->stream.p_selected_area->i_tell );
302 return(psz_currenttime);
305 float VlcWrapper::GetTimeAsFloat()
309 if( p_input != NULL )
311 f_time = (float)p_input->stream.p_selected_area->i_tell /
312 (float)p_input->stream.p_selected_area->i_size;
321 void VlcWrapper::SetTimeAsFloat( float f_position )
323 if( p_input != NULL )
326 (long long int)(p_input->stream.p_selected_area->i_size
327 * f_position / SEEKSLIDER_RANGE ),
332 bool VlcWrapper::IsPlaying()
335 bool playing = false;
338 switch ( p_input->stream.control.i_status )
361 void VlcWrapper::OpenFiles( BList* o_files, bool replace )
364 int size = PlaylistSize();
365 bool wasEmpty = ( size < 1 );
367 /* delete current playlist */
370 for( int i = 0; i < size; i++ )
372 playlist_Delete( p_playlist, 0 );
377 while( ( o_file = (BString *)o_files->LastItem() ) )
379 playlist_Add( p_playlist, o_file->String(),
380 PLAYLIST_APPEND, PLAYLIST_END );
381 o_files->RemoveItem(o_files->CountItems() - 1);
384 /* eventually restart playing */
385 if( replace || wasEmpty )
387 playlist_Stop( p_playlist );
388 playlist_Play( p_playlist );
392 void VlcWrapper::OpenDisc(BString o_type, BString o_device, int i_title, int i_chapter)
394 if( p_intf->p_sys->b_dvdmenus )
395 o_device.Prepend( "dvd:" );
397 o_device.Prepend( "dvdold:" );
398 playlist_Add( p_playlist, o_device.String(),
399 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
402 int VlcWrapper::PlaylistSize()
404 vlc_mutex_lock( &p_playlist->object_lock );
405 int i_size = p_playlist->i_size;
406 vlc_mutex_unlock( &p_playlist->object_lock );
410 char * VlcWrapper::PlaylistItemName( int i )
412 return p_playlist->pp_items[i]->psz_name;
415 int VlcWrapper::PlaylistCurrent()
417 return p_playlist->i_index;
420 bool VlcWrapper::PlaylistPlay()
424 playlist_Play( p_playlist );
429 void VlcWrapper::PlaylistPause()
433 input_SetStatus( p_input, INPUT_STATUS_PAUSE );
437 void VlcWrapper::PlaylistStop()
439 playlist_Stop( p_playlist );
442 void VlcWrapper::PlaylistNext()
444 playlist_Next( p_playlist );
447 void VlcWrapper::PlaylistPrev()
449 playlist_Prev( p_playlist );
452 void VlcWrapper::GetPlaylistInfo( int32& currentIndex, int32& maxIndex )
458 maxIndex = p_playlist->i_size;
460 currentIndex = p_playlist->i_index + 1;
466 void VlcWrapper::PlaylistJumpTo( int pos )
468 playlist_Goto( p_playlist, pos );
471 void VlcWrapper::GetNavCapabilities( bool *canSkipPrev, bool *canSkipNext )
473 if ( canSkipPrev && canSkipNext )
475 // init the parameters
476 *canSkipPrev = false;
477 *canSkipNext = false;
479 int pos = PlaylistCurrent();
480 int size = PlaylistSize();
482 // see if we have got a stream going
485 vlc_mutex_lock( &p_input->stream.stream_lock );
487 bool hasTitles = p_input->stream.i_area_nb > 1;
488 int numChapters = p_input->stream.p_selected_area->i_part_nb;
489 bool hasChapters = numChapters > 1;
490 // first, look for chapters
493 *canSkipPrev = p_input->stream.p_selected_area->i_part > 0;
494 *canSkipNext = p_input->stream.p_selected_area->i_part <
495 p_input->stream.p_selected_area->i_part_nb - 1;
497 // if one of the skip capabilities is false,
498 // make it depend on titles instead
499 if ( !*canSkipPrev && hasTitles )
500 *canSkipPrev = p_input->stream.p_selected_area->i_id > 1;
501 if ( !*canSkipNext && hasTitles )
502 *canSkipNext = p_input->stream.p_selected_area->i_id <
503 p_input->stream.i_area_nb - 1;
505 vlc_mutex_unlock( &p_input->stream.stream_lock );
507 // last but not least, make capabilities depend on playlist
509 *canSkipPrev = pos > 0;
511 *canSkipNext = pos < size - 1;
515 void VlcWrapper::NavigatePrev()
517 bool hasSkiped = false;
519 // see if we have got a stream going
522 // get information from stream (lock it while looking at it)
523 vlc_mutex_lock( &p_input->stream.stream_lock );
525 int currentTitle = p_input->stream.p_selected_area->i_id;
526 int currentChapter = p_input->stream.p_selected_area->i_part;
527 int numTitles = p_input->stream.i_area_nb;
528 bool hasTitles = numTitles > 1;
529 int numChapters = p_input->stream.p_selected_area->i_part_nb;
530 bool hasChapters = numChapters > 1;
532 vlc_mutex_unlock( &p_input->stream.stream_lock );
534 // first, look for chapters
537 // skip to the previous chapter
540 if ( currentChapter >= 0 )
542 ToggleChapter( currentChapter );
546 // if we couldn't skip chapters, try titles instead
547 if ( !hasSkiped && hasTitles )
549 // skip to the previous title
551 // disallow area 0 since it is used for video_ts.vob
552 if( currentTitle > 0 )
554 ToggleTitle(currentTitle);
560 // last but not least, skip to previous file
565 void VlcWrapper::NavigateNext()
567 bool hasSkiped = false;
569 // see if we have got a stream going
572 // get information from stream (lock it while looking at it)
573 vlc_mutex_lock( &p_input->stream.stream_lock );
575 int currentTitle = p_input->stream.p_selected_area->i_id;
576 int currentChapter = p_input->stream.p_selected_area->i_part;
577 int numTitles = p_input->stream.i_area_nb;
578 bool hasTitles = numTitles > 1;
579 int numChapters = p_input->stream.p_selected_area->i_part_nb;
580 bool hasChapters = numChapters > 1;
582 vlc_mutex_unlock( &p_input->stream.stream_lock );
584 // first, look for chapters
587 // skip to the next chapter
589 if ( currentChapter < numChapters )
591 ToggleChapter( currentChapter );
595 // if we couldn't skip chapters, try titles instead
596 if ( !hasSkiped && hasTitles )
598 // skip to the next title
600 // disallow area 0 since it is used for video_ts.vob
601 if ( currentTitle < numTitles - 1 )
603 ToggleTitle(currentTitle);
609 // last but not least, skip to next file
619 bool VlcWrapper::HasAudio()
621 return( p_aout != NULL );
624 unsigned short VlcWrapper::GetVolume()
628 unsigned short i_volume;
629 aout_VolumeGet( p_aout, (audio_volume_t*)&i_volume );
635 void VlcWrapper::SetVolume(int value)
639 if ( p_intf->p_sys->b_mute )
641 p_intf->p_sys->b_mute = 0;
643 aout_VolumeSet( p_aout, value );
647 void VlcWrapper::VolumeMute()
651 aout_VolumeGet( p_aout, &p_intf->p_sys->i_saved_volume );
652 aout_VolumeMute( p_aout, NULL );
653 p_intf->p_sys->b_mute = 1;
657 void VlcWrapper::VolumeRestore()
661 aout_VolumeSet( p_aout, p_intf->p_sys->i_saved_volume );
662 p_intf->p_sys->b_mute = 0;
666 bool VlcWrapper::IsMuted()
668 return p_intf->p_sys->b_mute;
675 bool VlcWrapper::HasTitles()
681 return ( p_input->stream.i_area_nb > 1 );
684 BList * VlcWrapper::GetTitles()
688 vlc_mutex_lock( &p_input->stream.stream_lock );
690 BList *list = new BList( p_input->stream.i_area_nb );
694 for( unsigned int i = 1; i < p_input->stream.i_area_nb; i++ )
696 message = new BMessage( TOGGLE_TITLE );
697 message->AddInt32( "index", i );
698 BString helper( "" );
700 menuItem = new BMenuItem( helper.String(), message );
701 menuItem->SetMarked( p_input->stream.p_selected_area->i_id == i );
702 list->AddItem( menuItem );
705 vlc_mutex_unlock( &p_input->stream.stream_lock );
712 void VlcWrapper::PrevTitle()
715 i_id = p_input->stream.p_selected_area->i_id - 1;
722 void VlcWrapper::NextTitle()
725 i_id = p_input->stream.p_selected_area->i_id + 1;
726 if( i_id < p_input->stream.i_area_nb )
732 void VlcWrapper::ToggleTitle(int i_title)
734 if( p_input != NULL )
736 input_ChangeArea( p_input,
737 p_input->stream.pp_areas[i_title] );
739 vlc_mutex_lock( &p_input->stream.stream_lock );
741 vlc_mutex_unlock( &p_input->stream.stream_lock );
745 void VlcWrapper::TitleInfo( int32 ¤tIndex, int32 &maxIndex )
751 vlc_mutex_lock( &p_input->stream.stream_lock );
753 maxIndex = p_input->stream.i_area_nb - 1;
755 currentIndex = p_input->stream.p_selected_area->i_id;
759 vlc_mutex_unlock( &p_input->stream.stream_lock );
763 bool VlcWrapper::HasChapters()
769 return ( p_input->stream.p_selected_area->i_part_nb > 1 );
772 BList * VlcWrapper::GetChapters()
776 vlc_mutex_lock( &p_input->stream.stream_lock );
778 BList *list = new BList( p_input->stream.p_selected_area->i_part_nb );
782 for( unsigned int i = 1;
783 i < p_input->stream.p_selected_area->i_part_nb + 1; i++ )
785 message = new BMessage( TOGGLE_CHAPTER );
786 message->AddInt32( "index", i );
787 BString helper( "" );
789 menuItem = new BMenuItem( helper.String(), message );
790 menuItem->SetMarked( p_input->stream.p_selected_area->i_part == i );
791 list->AddItem( menuItem );
794 vlc_mutex_unlock( &p_input->stream.stream_lock );
801 void VlcWrapper::PrevChapter()
804 i_id = p_input->stream.p_selected_area->i_part - 1;
811 void VlcWrapper::NextChapter()
814 i_id = p_input->stream.p_selected_area->i_part + 1;
821 void VlcWrapper::ToggleChapter(int i_chapter)
823 if( p_input != NULL )
825 p_input->stream.p_selected_area->i_part = i_chapter;
826 input_ChangeArea( p_input,
827 p_input->stream.p_selected_area );
829 vlc_mutex_lock( &p_input->stream.stream_lock );
830 vlc_mutex_unlock( &p_input->stream.stream_lock );
834 void VlcWrapper::ChapterInfo( int32 ¤tIndex, int32 &maxIndex )
840 vlc_mutex_lock( &p_input->stream.stream_lock );
842 maxIndex = p_input->stream.p_selected_area->i_part_nb - 1;
844 currentIndex = p_input->stream.p_selected_area->i_part;
848 vlc_mutex_unlock( &p_input->stream.stream_lock );
856 void VlcWrapper::LoadSubFile( char * psz_file )
858 config_PutPsz( p_intf, "sub-file", strdup( psz_file ) );
861 void VlcWrapper::FilterChange()
866 vout_thread_t * p_vout;
867 vlc_mutex_lock( &p_input->stream.stream_lock );
869 /* Warn the vout we are about to change the filter chain */
870 p_vout = (vout_thread_t*)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
874 p_vout->b_filter_change = VLC_TRUE;
875 vlc_object_release( p_vout );
878 /* restart all video stream */
879 for( unsigned int i = 0; i < p_input->stream.i_es_number; i++ )
881 if( ( p_input->stream.pp_es[i]->i_cat == VIDEO_ES ) &&
882 ( p_input->stream.pp_es[i]->p_decoder_fifo != NULL ) )
884 input_UnselectES( p_input, p_input->stream.pp_es[i] );
885 input_SelectES( p_input, p_input->stream.pp_es[i] );
888 vlc_mutex_unlock( &p_input->stream.stream_lock );