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.21 2003/01/22 01:13:22 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>
34 #include <audio_output.h>
35 #include <aout_internal.h>
38 #include "VlcWrapper.h"
42 VlcWrapper::VlcWrapper( intf_thread_t *p_interface )
47 p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
52 VlcWrapper::~VlcWrapper()
56 vlc_object_release( p_input );
60 vlc_object_release( p_playlist );
64 vlc_object_release( p_aout );
68 /* UpdateInputAndAOut: updates p_input and p_aout, returns true if the
69 interface needs to be updated */
70 bool VlcWrapper::UpdateInputAndAOut()
74 p_input = (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
79 p_aout = (aout_instance_t*)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
87 vlc_object_release( p_input );
92 vlc_object_release( p_aout );
102 /***************************
103 * input infos and control *
104 ***************************/
106 bool VlcWrapper::HasInput()
108 return ( p_input != NULL );
111 int VlcWrapper::InputStatus()
117 return p_input->stream.control.i_status;
120 int VlcWrapper::InputRate()
126 return p_input->stream.control.i_rate;
129 void VlcWrapper::InputSlower()
131 if( p_input != NULL )
133 input_SetStatus( p_input, INPUT_STATUS_SLOWER );
137 void VlcWrapper::InputFaster()
139 if( p_input != NULL )
141 input_SetStatus( p_input, INPUT_STATUS_FASTER );
145 BList * VlcWrapper::GetChannels( int i_cat )
151 const char* fieldName;
157 what = SELECT_CHANNEL;
158 fieldName = "channel";
163 what = SELECT_SUBTITLE;
164 fieldName = "subtitle";
171 vlc_mutex_lock( &p_input->stream.stream_lock );
173 /* find which track is currently playing */
174 es_descriptor_t *p_es = NULL;
175 for( i = 0; i < p_input->stream.i_selected_es_number; i++ )
177 if( p_input->stream.pp_selected_es[i]->i_cat == i_cat )
178 p_es = p_input->stream.pp_selected_es[i];
181 /* build a list of all tracks */
182 BList *list = new BList( p_input->stream.i_es_number );
188 message = new BMessage( what );
189 message->AddInt32( fieldName, -1 );
190 menuItem = new BMenuItem( "None", message );
192 menuItem->SetMarked( true );
193 list->AddItem( menuItem );
195 for( i = 0; i < p_input->stream.i_es_number; i++ )
197 if( p_input->stream.pp_es[i]->i_cat == i_cat )
199 message = new BMessage( what );
200 message->AddInt32( fieldName, i );
201 if( strlen( p_input->stream.pp_es[i]->psz_desc ) )
202 trackName = strdup( p_input->stream.pp_es[i]->psz_desc );
204 trackName = "<unknown>";
205 menuItem = new BMenuItem( trackName, message );
206 if( p_input->stream.pp_es[i] == p_es )
207 menuItem->SetMarked( true );
208 list->AddItem( menuItem );
212 vlc_mutex_unlock( &p_input->stream.stream_lock );
219 void VlcWrapper::ToggleLanguage( int i_language )
221 es_descriptor_t * p_es = NULL;
222 es_descriptor_t * p_es_old = NULL;
224 vlc_mutex_lock( &p_input->stream.stream_lock );
225 for( unsigned int i = 0; i < p_input->stream.i_selected_es_number ; i++ )
227 if( p_input->stream.pp_selected_es[i]->i_cat == AUDIO_ES )
229 p_es_old = p_input->stream.pp_selected_es[i];
233 vlc_mutex_unlock( &p_input->stream.stream_lock );
235 if( i_language != -1 )
237 p_es = p_input->stream.pp_es[i_language];
239 if( p_es == p_es_old )
245 input_ToggleES( p_input, p_es_old, VLC_FALSE );
249 input_ToggleES( p_input, p_es, VLC_TRUE );
253 void VlcWrapper::ToggleSubtitle( int i_subtitle )
255 es_descriptor_t * p_es = NULL;
256 es_descriptor_t * p_es_old = NULL;
258 vlc_mutex_lock( &p_input->stream.stream_lock );
259 for( unsigned int i = 0; i < p_input->stream.i_selected_es_number ; i++ )
261 if( p_input->stream.pp_selected_es[i]->i_cat == SPU_ES )
263 p_es_old = p_input->stream.pp_selected_es[i];
267 vlc_mutex_unlock( &p_input->stream.stream_lock );
269 if( i_subtitle != -1 )
271 p_es = p_input->stream.pp_es[i_subtitle];
273 if( p_es == p_es_old )
279 input_ToggleES( p_input, p_es_old, VLC_FALSE );
283 input_ToggleES( p_input, p_es, VLC_TRUE );
287 const char * VlcWrapper::GetTimeAsString()
289 static char psz_currenttime[ OFFSETTOTIME_MAX_SIZE ];
291 if( p_input == NULL )
296 input_OffsetToTime( p_input,
298 p_input->stream.p_selected_area->i_tell );
300 return(psz_currenttime);
303 float VlcWrapper::GetTimeAsFloat()
307 if( p_input != NULL )
309 f_time = (float)p_input->stream.p_selected_area->i_tell /
310 (float)p_input->stream.p_selected_area->i_size;
319 void VlcWrapper::SetTimeAsFloat( float f_position )
321 if( p_input != NULL )
324 (long long int)(p_input->stream.p_selected_area->i_size
325 * f_position / SEEKSLIDER_RANGE ),
330 bool VlcWrapper::IsPlaying()
333 bool playing = false;
336 switch ( p_input->stream.control.i_status )
359 void VlcWrapper::OpenFiles( BList* o_files, bool replace )
362 int size = PlaylistSize();
363 bool wasEmpty = ( size < 1 );
365 /* delete current playlist */
368 for( int i = 0; i < size; i++ )
370 playlist_Delete( p_playlist, 0 );
375 while( ( o_file = (BString *)o_files->LastItem() ) )
377 playlist_Add( p_playlist, o_file->String(),
378 PLAYLIST_APPEND, PLAYLIST_END );
379 o_files->RemoveItem(o_files->CountItems() - 1);
382 /* eventually restart playing */
383 if( replace || wasEmpty )
385 playlist_Stop( p_playlist );
386 playlist_Play( p_playlist );
390 void VlcWrapper::OpenDisc(BString o_type, BString o_device, int i_title, int i_chapter)
392 if( p_intf->p_sys->b_dvdold )
393 o_device.Prepend( "dvdold:" );
394 playlist_Add( p_playlist, o_device.String(),
395 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
398 int VlcWrapper::PlaylistSize()
400 vlc_mutex_lock( &p_playlist->object_lock );
401 int i_size = p_playlist->i_size;
402 vlc_mutex_unlock( &p_playlist->object_lock );
406 char * VlcWrapper::PlaylistItemName( int i )
408 return p_playlist->pp_items[i]->psz_name;
411 int VlcWrapper::PlaylistCurrent()
413 return p_playlist->i_index;
416 bool VlcWrapper::PlaylistPlay()
420 playlist_Play( p_playlist );
425 void VlcWrapper::PlaylistPause()
429 input_SetStatus( p_input, INPUT_STATUS_PAUSE );
433 void VlcWrapper::PlaylistStop()
435 playlist_Stop( p_playlist );
438 void VlcWrapper::PlaylistNext()
440 playlist_Next( p_playlist );
443 void VlcWrapper::PlaylistPrev()
445 playlist_Prev( p_playlist );
448 void VlcWrapper::GetPlaylistInfo( int32& currentIndex, int32& maxIndex )
454 maxIndex = p_playlist->i_size;
456 currentIndex = p_playlist->i_index + 1;
462 void VlcWrapper::PlaylistJumpTo( int pos )
464 playlist_Goto( p_playlist, pos );
467 void VlcWrapper::GetNavCapabilities( bool *canSkipPrev, bool *canSkipNext )
469 if ( canSkipPrev && canSkipNext )
471 // init the parameters
472 *canSkipPrev = false;
473 *canSkipNext = false;
475 int pos = PlaylistCurrent();
476 int size = PlaylistSize();
478 // see if we have got a stream going
481 vlc_mutex_lock( &p_input->stream.stream_lock );
483 bool hasTitles = p_input->stream.i_area_nb > 1;
484 int numChapters = p_input->stream.p_selected_area->i_part_nb;
485 bool hasChapters = numChapters > 1;
486 // first, look for chapters
489 *canSkipPrev = p_input->stream.p_selected_area->i_part > 0;
490 *canSkipNext = p_input->stream.p_selected_area->i_part <
491 p_input->stream.p_selected_area->i_part_nb - 1;
493 // if one of the skip capabilities is false,
494 // make it depend on titles instead
495 if ( !*canSkipPrev && hasTitles )
496 *canSkipPrev = p_input->stream.p_selected_area->i_id > 1;
497 if ( !*canSkipNext && hasTitles )
498 *canSkipNext = p_input->stream.p_selected_area->i_id <
499 p_input->stream.i_area_nb - 1;
501 vlc_mutex_unlock( &p_input->stream.stream_lock );
503 // last but not least, make capabilities depend on playlist
505 *canSkipPrev = pos > 0;
507 *canSkipNext = pos < size - 1;
511 void VlcWrapper::NavigatePrev()
513 bool hasSkiped = false;
515 // see if we have got a stream going
518 // get information from stream (lock it while looking at it)
519 vlc_mutex_lock( &p_input->stream.stream_lock );
521 int currentTitle = p_input->stream.p_selected_area->i_id;
522 int currentChapter = p_input->stream.p_selected_area->i_part;
523 int numTitles = p_input->stream.i_area_nb;
524 bool hasTitles = numTitles > 1;
525 int numChapters = p_input->stream.p_selected_area->i_part_nb;
526 bool hasChapters = numChapters > 1;
528 vlc_mutex_unlock( &p_input->stream.stream_lock );
530 // first, look for chapters
533 // skip to the previous chapter
536 if ( currentChapter >= 0 )
538 ToggleChapter( currentChapter );
542 // if we couldn't skip chapters, try titles instead
543 if ( !hasSkiped && hasTitles )
545 // skip to the previous title
547 // disallow area 0 since it is used for video_ts.vob
548 if( currentTitle > 0 )
550 ToggleTitle(currentTitle);
556 // last but not least, skip to previous file
561 void VlcWrapper::NavigateNext()
563 bool hasSkiped = false;
565 // see if we have got a stream going
568 // get information from stream (lock it while looking at it)
569 vlc_mutex_lock( &p_input->stream.stream_lock );
571 int currentTitle = p_input->stream.p_selected_area->i_id;
572 int currentChapter = p_input->stream.p_selected_area->i_part;
573 int numTitles = p_input->stream.i_area_nb;
574 bool hasTitles = numTitles > 1;
575 int numChapters = p_input->stream.p_selected_area->i_part_nb;
576 bool hasChapters = numChapters > 1;
578 vlc_mutex_unlock( &p_input->stream.stream_lock );
580 // first, look for chapters
583 // skip to the next chapter
585 if ( currentChapter < numChapters )
587 ToggleChapter( currentChapter );
591 // if we couldn't skip chapters, try titles instead
592 if ( !hasSkiped && hasTitles )
594 // skip to the next title
596 // disallow area 0 since it is used for video_ts.vob
597 if ( currentTitle < numTitles - 1 )
599 ToggleTitle(currentTitle);
605 // last but not least, skip to next file
615 bool VlcWrapper::HasAudio()
617 return( p_aout != NULL );
620 unsigned short VlcWrapper::GetVolume()
624 unsigned short i_volume;
625 aout_VolumeGet( p_aout, (audio_volume_t*)&i_volume );
631 void VlcWrapper::SetVolume(int value)
635 if ( p_intf->p_sys->b_mute )
637 p_intf->p_sys->b_mute = 0;
639 aout_VolumeSet( p_aout, value );
643 void VlcWrapper::VolumeMute()
647 aout_VolumeGet( p_aout, &p_intf->p_sys->i_saved_volume );
648 aout_VolumeMute( p_aout, NULL );
649 p_intf->p_sys->b_mute = 1;
653 void VlcWrapper::VolumeRestore()
657 aout_VolumeSet( p_aout, p_intf->p_sys->i_saved_volume );
658 p_intf->p_sys->b_mute = 0;
662 bool VlcWrapper::IsMuted()
664 return p_intf->p_sys->b_mute;
671 bool VlcWrapper::HasTitles()
677 return ( p_input->stream.i_area_nb > 1 );
680 BList * VlcWrapper::GetTitles()
684 vlc_mutex_lock( &p_input->stream.stream_lock );
686 BList *list = new BList( p_input->stream.i_area_nb );
690 for( unsigned int i = 1; i < p_input->stream.i_area_nb; i++ )
692 message = new BMessage( TOGGLE_TITLE );
693 message->AddInt32( "index", i );
694 BString helper( "" );
696 menuItem = new BMenuItem( helper.String(), message );
697 menuItem->SetMarked( p_input->stream.p_selected_area->i_id == i );
698 list->AddItem( menuItem );
701 vlc_mutex_unlock( &p_input->stream.stream_lock );
708 void VlcWrapper::PrevTitle()
711 i_id = p_input->stream.p_selected_area->i_id - 1;
718 void VlcWrapper::NextTitle()
721 i_id = p_input->stream.p_selected_area->i_id + 1;
722 if( i_id < p_input->stream.i_area_nb )
728 void VlcWrapper::ToggleTitle(int i_title)
730 if( p_input != NULL )
732 input_ChangeArea( p_input,
733 p_input->stream.pp_areas[i_title] );
735 vlc_mutex_lock( &p_input->stream.stream_lock );
737 vlc_mutex_unlock( &p_input->stream.stream_lock );
741 void VlcWrapper::TitleInfo( int32 ¤tIndex, int32 &maxIndex )
747 vlc_mutex_lock( &p_input->stream.stream_lock );
749 maxIndex = p_input->stream.i_area_nb - 1;
751 currentIndex = p_input->stream.p_selected_area->i_id;
755 vlc_mutex_unlock( &p_input->stream.stream_lock );
759 bool VlcWrapper::HasChapters()
765 return ( p_input->stream.p_selected_area->i_part_nb > 1 );
768 BList * VlcWrapper::GetChapters()
772 vlc_mutex_lock( &p_input->stream.stream_lock );
774 BList *list = new BList( p_input->stream.p_selected_area->i_part_nb );
778 for( unsigned int i = 1;
779 i < p_input->stream.p_selected_area->i_part_nb + 1; i++ )
781 message = new BMessage( TOGGLE_CHAPTER );
782 message->AddInt32( "index", i );
783 BString helper( "" );
785 menuItem = new BMenuItem( helper.String(), message );
786 menuItem->SetMarked( p_input->stream.p_selected_area->i_part == i );
787 list->AddItem( menuItem );
790 vlc_mutex_unlock( &p_input->stream.stream_lock );
797 void VlcWrapper::PrevChapter()
800 i_id = p_input->stream.p_selected_area->i_part - 1;
807 void VlcWrapper::NextChapter()
810 i_id = p_input->stream.p_selected_area->i_part + 1;
817 void VlcWrapper::ToggleChapter(int i_chapter)
819 if( p_input != NULL )
821 p_input->stream.p_selected_area->i_part = i_chapter;
822 input_ChangeArea( p_input,
823 p_input->stream.p_selected_area );
825 vlc_mutex_lock( &p_input->stream.stream_lock );
826 vlc_mutex_unlock( &p_input->stream.stream_lock );
830 void VlcWrapper::ChapterInfo( int32 ¤tIndex, int32 &maxIndex )
836 vlc_mutex_lock( &p_input->stream.stream_lock );
838 maxIndex = p_input->stream.p_selected_area->i_part_nb - 1;
840 currentIndex = p_input->stream.p_selected_area->i_part;
844 vlc_mutex_unlock( &p_input->stream.stream_lock );
852 void VlcWrapper::LoadSubFile( char * psz_file )
854 config_PutPsz( p_intf, "sub-file", strdup( psz_file ) );