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.18 2003/01/14 14:48:55 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 );
109 // return ( PlaylistSize() > 0 );
112 /* status (UNDEF_S, PLAYING_S, PAUSE_S, FORWARD_S, BACKWARD_S,
113 REWIND_S, NOT_STARTED_S, START_S) */
114 int VlcWrapper::InputStatus()
120 return p_input->stream.control.i_status;
123 int VlcWrapper::InputRate()
129 return p_input->stream.control.i_rate;
132 void VlcWrapper::InputSlower()
134 if( p_input != NULL )
136 input_SetStatus( p_input, INPUT_STATUS_SLOWER );
140 void VlcWrapper::InputFaster()
142 if( p_input != NULL )
144 input_SetStatus( p_input, INPUT_STATUS_FASTER );
148 BList * VlcWrapper::InputGetChannels( int i_cat )
154 const char* fieldName;
160 what = SELECT_CHANNEL;
161 fieldName = "channel";
166 what = SELECT_SUBTITLE;
167 fieldName = "subtitle";
174 vlc_mutex_lock( &p_input->stream.stream_lock );
176 /* find which track is currently playing */
177 es_descriptor_t *p_es = NULL;
178 for( i = 0; i < p_input->stream.i_selected_es_number; i++ )
180 if( p_input->stream.pp_selected_es[i]->i_cat == i_cat )
181 p_es = p_input->stream.pp_selected_es[i];
184 /* build a list of all tracks */
185 BList *list = new BList( p_input->stream.i_es_number );
191 message = new BMessage( what );
192 message->AddInt32( fieldName, -1 );
193 menuItem = new BMenuItem( "None", message );
195 menuItem->SetMarked( true );
196 list->AddItem( menuItem );
198 for( i = 0; i < p_input->stream.i_es_number; i++ )
200 if( p_input->stream.pp_es[i]->i_cat == i_cat )
202 message = new BMessage( what );
203 message->AddInt32( fieldName, i );
204 if( strlen( p_input->stream.pp_es[i]->psz_desc ) )
205 trackName = strdup( p_input->stream.pp_es[i]->psz_desc );
207 trackName = "<unknown>";
208 menuItem = new BMenuItem( trackName, message );
209 if( p_input->stream.pp_es[i] == p_es )
210 menuItem->SetMarked( true );
211 list->AddItem( menuItem );
215 vlc_mutex_unlock( &p_input->stream.stream_lock );
222 void VlcWrapper::openFiles( BList* o_files, bool replace )
226 while( ( o_file = (BString *)o_files->LastItem() ) )
228 o_files->RemoveItem(o_files->CountItems() - 1);
229 playlist_Add( p_playlist, o_file->String(),
230 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
235 void VlcWrapper::openDisc(BString o_type, BString o_device, int i_title, int i_chapter)
237 BString o_source("");
238 o_source << o_type << ":" << o_device ;
240 playlist_Add( p_playlist, o_source.String(),
241 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
244 void VlcWrapper::LoadSubFile( char * psz_file )
246 config_PutPsz( p_intf, "sub-file", strdup( psz_file ) );
249 void VlcWrapper::ToggleLanguage( int i_language )
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 == AUDIO_ES )
259 p_es_old = p_input->stream.pp_selected_es[i];
263 vlc_mutex_unlock( &p_input->stream.stream_lock );
265 if( i_language != -1 )
267 p_es = p_input->stream.pp_es[i_language];
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 void VlcWrapper::ToggleSubtitle( int i_subtitle )
285 es_descriptor_t * p_es = NULL;
286 es_descriptor_t * p_es_old = NULL;
288 vlc_mutex_lock( &p_input->stream.stream_lock );
289 for( unsigned int i = 0; i < p_input->stream.i_selected_es_number ; i++ )
291 if( p_input->stream.pp_selected_es[i]->i_cat == SPU_ES )
293 p_es_old = p_input->stream.pp_selected_es[i];
297 vlc_mutex_unlock( &p_input->stream.stream_lock );
299 if( i_subtitle != -1 )
301 p_es = p_input->stream.pp_es[i_subtitle];
303 if( p_es == p_es_old )
309 input_ToggleES( p_input, p_es_old, VLC_FALSE );
313 input_ToggleES( p_input, p_es, VLC_TRUE );
317 const char* VlcWrapper::getTimeAsString()
319 static char psz_currenttime[ OFFSETTOTIME_MAX_SIZE ];
321 if( p_input == NULL )
326 input_OffsetToTime( p_input,
328 p_input->stream.p_selected_area->i_tell );
330 return(psz_currenttime);
333 float VlcWrapper::getTimeAsFloat()
337 if( p_input != NULL )
339 f_time = (float)p_input->stream.p_selected_area->i_tell /
340 (float)p_input->stream.p_selected_area->i_size;
349 void VlcWrapper::setTimeAsFloat(float f_position)
351 if( p_input != NULL )
354 (long long int)(p_input->stream.p_selected_area->i_size
355 * f_position / SEEKSLIDER_RANGE ),
360 bool VlcWrapper::IsPlaying()
363 bool playing = false;
366 switch ( p_input->stream.control.i_status )
385 /******************************
386 * playlist infos and control *
387 ******************************/
388 int VlcWrapper::PlaylistSize()
390 vlc_mutex_lock( &p_playlist->object_lock );
391 int i_size = p_playlist->i_size;
392 vlc_mutex_unlock( &p_playlist->object_lock );
396 char *VlcWrapper::PlaylistItemName( int i )
398 return p_playlist->pp_items[i]->psz_name;
401 int VlcWrapper::PlaylistCurrent()
403 return p_playlist->i_index;
406 int VlcWrapper::PlaylistStatus()
408 return p_playlist->i_status;
411 bool VlcWrapper::PlaylistPlay()
415 playlist_Play( p_playlist );
420 void VlcWrapper::PlaylistPause()
424 input_SetStatus( p_input, INPUT_STATUS_PAUSE );
428 void VlcWrapper::PlaylistStop()
430 playlist_Stop( p_playlist );
433 void VlcWrapper::PlaylistNext()
435 playlist_Next( p_playlist );
438 void VlcWrapper::PlaylistPrev()
440 playlist_Prev( p_playlist );
443 void VlcWrapper::PlaylistSkip( int i )
445 playlist_Skip( p_playlist, i );
448 void VlcWrapper::PlaylistGoto( int i )
450 playlist_Goto( p_playlist, i );
453 void VlcWrapper::PlaylistLoop()
455 if ( p_intf->p_sys->b_loop )
457 playlist_Delete( p_playlist, p_playlist->i_size - 1 );
461 playlist_Add( p_playlist, "vlc:loop",
462 PLAYLIST_APPEND | PLAYLIST_GO,
465 p_intf->p_sys->b_loop = !p_intf->p_sys->b_loop;
468 BList * VlcWrapper::PlaylistAsArray()
471 BList* p_list = new BList(p_playlist->i_size);
473 vlc_mutex_lock( &p_playlist->object_lock );
475 for( i = 0; i < p_playlist->i_size; i++ )
477 p_list->AddItem(new BString(p_playlist->pp_items[i]->psz_name));
480 vlc_mutex_unlock( &p_playlist->object_lock );
484 void VlcWrapper::getPlaylistInfo( int32& currentIndex, int32& maxIndex )
490 maxIndex = p_playlist->i_size;
492 currentIndex = p_playlist->i_index + 1;
499 void VlcWrapper::PlaylistJumpTo( int pos )
505 int size = playlistSize();
509 if( p_input_bank->pp_input[0] != NULL )
511 // stop current stream
513 // modify current position in playlist
515 p_main->p_playlist->i_index = pos;
522 void VlcWrapper::getNavCapabilities( bool *canSkipPrev, bool *canSkipNext )
524 if ( canSkipPrev && canSkipNext )
526 // init the parameters
527 *canSkipPrev = false;
528 *canSkipNext = false;
530 int pos = PlaylistCurrent();
531 int size = PlaylistSize();
533 // see if we have got a stream going
536 vlc_mutex_lock( &p_input->stream.stream_lock );
538 bool hasTitles = p_input->stream.i_area_nb > 1;
539 int numChapters = p_input->stream.p_selected_area->i_part_nb;
540 bool hasChapters = numChapters > 1;
541 // first, look for chapters
544 *canSkipPrev = p_input->stream.p_selected_area->i_part > 0;
545 *canSkipNext = p_input->stream.p_selected_area->i_part <
546 p_input->stream.p_selected_area->i_part_nb - 1;
548 // if one of the skip capabilities is false,
549 // make it depend on titles instead
550 if ( !*canSkipPrev && hasTitles )
551 *canSkipPrev = p_input->stream.p_selected_area->i_id > 1;
552 if ( !*canSkipNext && hasTitles )
553 *canSkipNext = p_input->stream.p_selected_area->i_id <
554 p_input->stream.i_area_nb - 1;
556 vlc_mutex_unlock( &p_input->stream.stream_lock );
558 // last but not least, make capabilities depend on playlist
560 *canSkipPrev = pos > 0;
562 *canSkipNext = pos < size - 1;
566 void VlcWrapper::navigatePrev()
568 bool hasSkiped = false;
570 // see if we have got a stream going
573 // get information from stream (lock it while looking at it)
574 vlc_mutex_lock( &p_input->stream.stream_lock );
576 int currentTitle = p_input->stream.p_selected_area->i_id;
577 int currentChapter = p_input->stream.p_selected_area->i_part;
578 int numTitles = p_input->stream.i_area_nb;
579 bool hasTitles = numTitles > 1;
580 int numChapters = p_input->stream.p_selected_area->i_part_nb;
581 bool hasChapters = numChapters > 1;
583 vlc_mutex_unlock( &p_input->stream.stream_lock );
585 // first, look for chapters
588 // skip to the previous chapter
591 if ( currentChapter >= 0 )
593 toggleChapter( currentChapter );
597 // if we couldn't skip chapters, try titles instead
598 if ( !hasSkiped && hasTitles )
600 // skip to the previous title
602 // disallow area 0 since it is used for video_ts.vob
603 if( currentTitle > 0 )
605 toggleTitle(currentTitle);
611 // last but not least, skip to previous file
616 void VlcWrapper::navigateNext()
618 bool hasSkiped = false;
620 // see if we have got a stream going
623 // get information from stream (lock it while looking at it)
624 vlc_mutex_lock( &p_input->stream.stream_lock );
626 int currentTitle = p_input->stream.p_selected_area->i_id;
627 int currentChapter = p_input->stream.p_selected_area->i_part;
628 int numTitles = p_input->stream.i_area_nb;
629 bool hasTitles = numTitles > 1;
630 int numChapters = p_input->stream.p_selected_area->i_part_nb;
631 bool hasChapters = numChapters > 1;
633 vlc_mutex_unlock( &p_input->stream.stream_lock );
635 // first, look for chapters
638 // skip to the next chapter
640 if ( currentChapter < numChapters )
642 toggleChapter( currentChapter );
646 // if we couldn't skip chapters, try titles instead
647 if ( !hasSkiped && hasTitles )
649 // skip to the next title
651 // disallow area 0 since it is used for video_ts.vob
652 if ( currentTitle < numTitles - 1 )
654 toggleTitle(currentTitle);
660 // last but not least, skip to next file
666 /***************************
667 * audio infos and control *
668 ***************************/
670 unsigned short VlcWrapper::GetVolume()
674 unsigned short i_volume;
675 aout_VolumeGet( p_aout, (audio_volume_t*)&i_volume );
681 void VlcWrapper::SetVolume(int value)
685 if ( p_intf->p_sys->b_mute )
687 p_intf->p_sys->b_mute = 0;
689 aout_VolumeSet( p_aout, value );
693 void VlcWrapper::VolumeMute()
697 aout_VolumeGet( p_aout, &p_intf->p_sys->i_saved_volume );
698 aout_VolumeMute( p_aout, NULL );
699 p_intf->p_sys->b_mute = 1;
703 void VlcWrapper::VolumeRestore()
707 aout_VolumeSet( p_aout, p_intf->p_sys->i_saved_volume );
708 p_intf->p_sys->b_mute = 0;
712 bool VlcWrapper::IsMuted()
714 return p_intf->p_sys->b_mute;
717 bool VlcWrapper::HasAudio()
719 return( p_aout != NULL );
725 bool VlcWrapper::HasTitles()
731 return ( p_input->stream.i_area_nb > 1 );
734 void VlcWrapper::PrevTitle()
737 i_id = p_input->stream.p_selected_area->i_id - 1;
744 void VlcWrapper::NextTitle()
747 i_id = p_input->stream.p_selected_area->i_id + 1;
748 if( i_id < p_input->stream.i_area_nb )
754 bool VlcWrapper::HasChapters()
760 return ( p_input->stream.p_selected_area->i_part_nb > 1 );
763 void VlcWrapper::PrevChapter()
766 i_id = p_input->stream.p_selected_area->i_part - 1;
773 void VlcWrapper::NextChapter()
776 i_id = p_input->stream.p_selected_area->i_part + 1;
783 void VlcWrapper::TitleInfo( int32 ¤tIndex, int32 &maxIndex )
789 vlc_mutex_lock( &p_input->stream.stream_lock );
791 maxIndex = p_input->stream.i_area_nb - 1;
793 currentIndex = p_input->stream.p_selected_area->i_id;
797 vlc_mutex_unlock( &p_input->stream.stream_lock );
801 void VlcWrapper::ChapterInfo( int32 ¤tIndex, int32 &maxIndex )
807 vlc_mutex_lock( &p_input->stream.stream_lock );
809 maxIndex = p_input->stream.p_selected_area->i_part_nb - 1;
811 currentIndex = p_input->stream.p_selected_area->i_part;
815 vlc_mutex_unlock( &p_input->stream.stream_lock );
819 void VlcWrapper::toggleTitle(int i_title)
821 if( p_input != NULL )
823 input_ChangeArea( p_input,
824 p_input->stream.pp_areas[i_title] );
826 vlc_mutex_lock( &p_input->stream.stream_lock );
828 vlc_mutex_unlock( &p_input->stream.stream_lock );
832 void VlcWrapper::toggleChapter(int i_chapter)
834 if( p_input != NULL )
836 p_input->stream.p_selected_area->i_part = i_chapter;
837 input_ChangeArea( p_input,
838 p_input->stream.p_selected_area );
840 vlc_mutex_lock( &p_input->stream.stream_lock );
841 vlc_mutex_unlock( &p_input->stream.stream_lock );