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.17 2003/01/12 02:08:39 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 );
246 void VlcWrapper::ToggleLanguage( int i_language )
248 es_descriptor_t * p_es = NULL;
249 es_descriptor_t * p_es_old = NULL;
251 vlc_mutex_lock( &p_input->stream.stream_lock );
252 for( unsigned int i = 0; i < p_input->stream.i_selected_es_number ; i++ )
254 if( p_input->stream.pp_selected_es[i]->i_cat == AUDIO_ES )
256 p_es_old = p_input->stream.pp_selected_es[i];
260 vlc_mutex_unlock( &p_input->stream.stream_lock );
262 if( i_language != -1 )
264 p_es = p_input->stream.pp_es[i_language];
266 if( p_es == p_es_old )
272 input_ToggleES( p_input, p_es_old, VLC_FALSE );
276 input_ToggleES( p_input, p_es, VLC_TRUE );
280 void VlcWrapper::ToggleSubtitle( int i_subtitle )
282 es_descriptor_t * p_es = NULL;
283 es_descriptor_t * p_es_old = NULL;
285 vlc_mutex_lock( &p_input->stream.stream_lock );
286 for( unsigned int i = 0; i < p_input->stream.i_selected_es_number ; i++ )
288 if( p_input->stream.pp_selected_es[i]->i_cat == SPU_ES )
290 p_es_old = p_input->stream.pp_selected_es[i];
294 vlc_mutex_unlock( &p_input->stream.stream_lock );
296 if( i_subtitle != -1 )
298 p_es = p_input->stream.pp_es[i_subtitle];
300 if( p_es == p_es_old )
306 input_ToggleES( p_input, p_es_old, VLC_FALSE );
310 input_ToggleES( p_input, p_es, VLC_TRUE );
314 const char* VlcWrapper::getTimeAsString()
316 static char psz_currenttime[ OFFSETTOTIME_MAX_SIZE ];
318 if( p_input == NULL )
323 input_OffsetToTime( p_input,
325 p_input->stream.p_selected_area->i_tell );
327 return(psz_currenttime);
330 float VlcWrapper::getTimeAsFloat()
334 if( p_input != NULL )
336 f_time = (float)p_input->stream.p_selected_area->i_tell /
337 (float)p_input->stream.p_selected_area->i_size;
346 void VlcWrapper::setTimeAsFloat(float f_position)
348 if( p_input != NULL )
351 (long long int)(p_input->stream.p_selected_area->i_size
352 * f_position / SEEKSLIDER_RANGE ),
357 bool VlcWrapper::IsPlaying()
360 bool playing = false;
363 switch ( p_input->stream.control.i_status )
382 /******************************
383 * playlist infos and control *
384 ******************************/
385 int VlcWrapper::PlaylistSize()
387 vlc_mutex_lock( &p_playlist->object_lock );
388 int i_size = p_playlist->i_size;
389 vlc_mutex_unlock( &p_playlist->object_lock );
393 char *VlcWrapper::PlaylistItemName( int i )
395 return p_playlist->pp_items[i]->psz_name;
398 int VlcWrapper::PlaylistCurrent()
400 return p_playlist->i_index;
403 int VlcWrapper::PlaylistStatus()
405 return p_playlist->i_status;
408 bool VlcWrapper::PlaylistPlay()
412 playlist_Play( p_playlist );
417 void VlcWrapper::PlaylistPause()
421 input_SetStatus( p_input, INPUT_STATUS_PAUSE );
425 void VlcWrapper::PlaylistStop()
427 playlist_Stop( p_playlist );
430 void VlcWrapper::PlaylistNext()
432 playlist_Next( p_playlist );
435 void VlcWrapper::PlaylistPrev()
437 playlist_Prev( p_playlist );
440 void VlcWrapper::PlaylistSkip( int i )
442 playlist_Skip( p_playlist, i );
445 void VlcWrapper::PlaylistGoto( int i )
447 playlist_Goto( p_playlist, i );
450 void VlcWrapper::PlaylistLoop()
452 if ( p_intf->p_sys->b_loop )
454 playlist_Delete( p_playlist, p_playlist->i_size - 1 );
458 playlist_Add( p_playlist, "vlc:loop",
459 PLAYLIST_APPEND | PLAYLIST_GO,
462 p_intf->p_sys->b_loop = !p_intf->p_sys->b_loop;
465 BList * VlcWrapper::PlaylistAsArray()
468 BList* p_list = new BList(p_playlist->i_size);
470 vlc_mutex_lock( &p_playlist->object_lock );
472 for( i = 0; i < p_playlist->i_size; i++ )
474 p_list->AddItem(new BString(p_playlist->pp_items[i]->psz_name));
477 vlc_mutex_unlock( &p_playlist->object_lock );
481 void VlcWrapper::getPlaylistInfo( int32& currentIndex, int32& maxIndex )
487 maxIndex = p_playlist->i_size;
489 currentIndex = p_playlist->i_index + 1;
496 void VlcWrapper::PlaylistJumpTo( int pos )
502 int size = playlistSize();
506 if( p_input_bank->pp_input[0] != NULL )
508 // stop current stream
510 // modify current position in playlist
512 p_main->p_playlist->i_index = pos;
519 void VlcWrapper::getNavCapabilities( bool *canSkipPrev, bool *canSkipNext )
521 if ( canSkipPrev && canSkipNext )
523 // init the parameters
524 *canSkipPrev = false;
525 *canSkipNext = false;
527 int pos = PlaylistCurrent();
528 int size = PlaylistSize();
530 // see if we have got a stream going
533 vlc_mutex_lock( &p_input->stream.stream_lock );
535 bool hasTitles = p_input->stream.i_area_nb > 1;
536 int numChapters = p_input->stream.p_selected_area->i_part_nb;
537 bool hasChapters = numChapters > 1;
538 // first, look for chapters
541 *canSkipPrev = p_input->stream.p_selected_area->i_part > 0;
542 *canSkipNext = p_input->stream.p_selected_area->i_part <
543 p_input->stream.p_selected_area->i_part_nb - 1;
545 // if one of the skip capabilities is false,
546 // make it depend on titles instead
547 if ( !*canSkipPrev && hasTitles )
548 *canSkipPrev = p_input->stream.p_selected_area->i_id > 1;
549 if ( !*canSkipNext && hasTitles )
550 *canSkipNext = p_input->stream.p_selected_area->i_id <
551 p_input->stream.i_area_nb - 1;
553 vlc_mutex_unlock( &p_input->stream.stream_lock );
555 // last but not least, make capabilities depend on playlist
557 *canSkipPrev = pos > 0;
559 *canSkipNext = pos < size - 1;
563 void VlcWrapper::navigatePrev()
565 bool hasSkiped = false;
567 // see if we have got a stream going
570 // get information from stream (lock it while looking at it)
571 vlc_mutex_lock( &p_input->stream.stream_lock );
573 int currentTitle = p_input->stream.p_selected_area->i_id;
574 int currentChapter = p_input->stream.p_selected_area->i_part;
575 int numTitles = p_input->stream.i_area_nb;
576 bool hasTitles = numTitles > 1;
577 int numChapters = p_input->stream.p_selected_area->i_part_nb;
578 bool hasChapters = numChapters > 1;
580 vlc_mutex_unlock( &p_input->stream.stream_lock );
582 // first, look for chapters
585 // skip to the previous chapter
588 if ( currentChapter >= 0 )
590 toggleChapter( currentChapter );
594 // if we couldn't skip chapters, try titles instead
595 if ( !hasSkiped && hasTitles )
597 // skip to the previous title
599 // disallow area 0 since it is used for video_ts.vob
600 if( currentTitle > 0 )
602 toggleTitle(currentTitle);
608 // last but not least, skip to previous file
613 void VlcWrapper::navigateNext()
615 bool hasSkiped = false;
617 // see if we have got a stream going
620 // get information from stream (lock it while looking at it)
621 vlc_mutex_lock( &p_input->stream.stream_lock );
623 int currentTitle = p_input->stream.p_selected_area->i_id;
624 int currentChapter = p_input->stream.p_selected_area->i_part;
625 int numTitles = p_input->stream.i_area_nb;
626 bool hasTitles = numTitles > 1;
627 int numChapters = p_input->stream.p_selected_area->i_part_nb;
628 bool hasChapters = numChapters > 1;
630 vlc_mutex_unlock( &p_input->stream.stream_lock );
632 // first, look for chapters
635 // skip to the next chapter
637 if ( currentChapter < numChapters )
639 toggleChapter( currentChapter );
643 // if we couldn't skip chapters, try titles instead
644 if ( !hasSkiped && hasTitles )
646 // skip to the next title
648 // disallow area 0 since it is used for video_ts.vob
649 if ( currentTitle < numTitles - 1 )
651 toggleTitle(currentTitle);
657 // last but not least, skip to next file
663 /***************************
664 * audio infos and control *
665 ***************************/
667 unsigned short VlcWrapper::GetVolume()
671 unsigned short i_volume;
672 aout_VolumeGet( p_aout, (audio_volume_t*)&i_volume );
678 void VlcWrapper::SetVolume(int value)
682 if ( p_intf->p_sys->b_mute )
684 p_intf->p_sys->b_mute = 0;
686 aout_VolumeSet( p_aout, value );
690 void VlcWrapper::VolumeMute()
694 aout_VolumeGet( p_aout, &p_intf->p_sys->i_saved_volume );
695 aout_VolumeMute( p_aout, NULL );
696 p_intf->p_sys->b_mute = 1;
700 void VlcWrapper::VolumeRestore()
704 aout_VolumeSet( p_aout, p_intf->p_sys->i_saved_volume );
705 p_intf->p_sys->b_mute = 0;
709 bool VlcWrapper::IsMuted()
711 return p_intf->p_sys->b_mute;
714 bool VlcWrapper::HasAudio()
716 return( p_aout != NULL );
722 bool VlcWrapper::HasTitles()
728 return ( p_input->stream.i_area_nb > 1 );
731 void VlcWrapper::PrevTitle()
734 i_id = p_input->stream.p_selected_area->i_id - 1;
741 void VlcWrapper::NextTitle()
744 i_id = p_input->stream.p_selected_area->i_id + 1;
745 if( i_id < p_input->stream.i_area_nb )
751 bool VlcWrapper::HasChapters()
757 return ( p_input->stream.p_selected_area->i_part_nb > 1 );
760 void VlcWrapper::PrevChapter()
763 i_id = p_input->stream.p_selected_area->i_part - 1;
770 void VlcWrapper::NextChapter()
773 i_id = p_input->stream.p_selected_area->i_part + 1;
780 void VlcWrapper::TitleInfo( int32 ¤tIndex, int32 &maxIndex )
786 vlc_mutex_lock( &p_input->stream.stream_lock );
788 maxIndex = p_input->stream.i_area_nb - 1;
790 currentIndex = p_input->stream.p_selected_area->i_id;
794 vlc_mutex_unlock( &p_input->stream.stream_lock );
798 void VlcWrapper::ChapterInfo( int32 ¤tIndex, int32 &maxIndex )
804 vlc_mutex_lock( &p_input->stream.stream_lock );
806 maxIndex = p_input->stream.p_selected_area->i_part_nb - 1;
808 currentIndex = p_input->stream.p_selected_area->i_part;
812 vlc_mutex_unlock( &p_input->stream.stream_lock );
816 void VlcWrapper::toggleTitle(int i_title)
818 if( p_input != NULL )
820 input_ChangeArea( p_input,
821 p_input->stream.pp_areas[i_title] );
823 vlc_mutex_lock( &p_input->stream.stream_lock );
825 vlc_mutex_unlock( &p_input->stream.stream_lock );
829 void VlcWrapper::toggleChapter(int i_chapter)
831 if( p_input != NULL )
833 p_input->stream.p_selected_area->i_part = i_chapter;
834 input_ChangeArea( p_input,
835 p_input->stream.p_selected_area );
837 vlc_mutex_lock( &p_input->stream.stream_lock );
838 vlc_mutex_unlock( &p_input->stream.stream_lock );