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.13 2002/12/09 07:57:04 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 *****************************************************************************/
27 #include <SupportKit.h>
31 #include <audio_output.h>
32 #include <aout_internal.h>
34 #include "VlcWrapper.h"
37 VlcWrapper::VlcWrapper( intf_thread_t *p_interface )
42 p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
47 VlcWrapper::~VlcWrapper()
51 vlc_object_release( p_input );
55 vlc_object_release( p_playlist );
59 vlc_object_release( p_aout );
63 /* UpdateInputAndAOut: updates p_input and p_aout, returns true if the
64 interface needs to be updated */
65 bool VlcWrapper::UpdateInputAndAOut()
69 p_input = (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
74 p_aout = (aout_instance_t*)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
82 vlc_object_release( p_input );
87 vlc_object_release( p_aout );
97 /***************************
98 * input infos and control *
99 ***************************/
101 /* status (UNDEF_S, PLAYING_S, PAUSE_S, FORWARD_S, BACKWARD_S,
102 REWIND_S, NOT_STARTED_S, START_S) */
103 int VlcWrapper::InputStatus()
109 return p_input->stream.control.i_status;
112 int VlcWrapper::InputRate()
118 return p_input->stream.control.i_rate;
121 /* tell: location in the current stream (in arbitrary units) */
122 int VlcWrapper::InputTell()
128 return p_input->stream.p_selected_area->i_tell;
131 /* size: total size of the current stream (in arbitrary units) */
132 int VlcWrapper::InputSize()
138 return p_input->stream.p_selected_area->i_size;
141 void VlcWrapper::InputSlower()
143 if( p_input != NULL )
145 input_SetStatus( p_input, INPUT_STATUS_SLOWER );
150 void VlcWrapper::InputFaster()
152 if( p_input != NULL )
154 input_SetStatus( p_input, INPUT_STATUS_FASTER );
159 void VlcWrapper::openFiles( BList* o_files, bool replace )
163 while( ( o_file = (BString *)o_files->LastItem() ) )
165 o_files->RemoveItem(o_files->CountItems() - 1);
166 playlist_Add( p_playlist, o_file->String(),
167 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
172 void VlcWrapper::openDisc(BString o_type, BString o_device, int i_title, int i_chapter)
174 BString o_source("");
175 o_source << o_type << ":" << o_device ;
177 playlist_Add( p_playlist, o_source.String(),
178 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
183 void VlcWrapper::toggleLanguage(int i_language)
187 int i_cat = AUDIO_ES;
189 vlc_mutex_lock( &p_input->stream.stream_lock );
190 for( unsigned int i = 0; i < p_input->stream.i_selected_es_number ; i++ )
192 if( p_input->stream.pp_selected_es[i]->i_cat == i_cat )
198 vlc_mutex_unlock( &p_input->stream.stream_lock );
200 msg_Info( p_intf, "Old: %d, New: %d", i_old, i_language);
201 if( i_language != -1 )
203 input_ToggleES( p_input,
204 p_input->stream.pp_selected_es[i_language],
208 if( (i_old != -1) && (i_old != i_language) )
210 input_ToggleES( p_input,
211 p_input->stream.pp_selected_es[i_old],
216 void VlcWrapper::toggleSubtitle(int i_subtitle)
221 vlc_mutex_lock( &p_input->stream.stream_lock );
222 for( unsigned int i = 0; i < p_input->stream.i_selected_es_number ; i++ )
224 if( p_input->stream.pp_selected_es[i]->i_cat == i_cat )
230 vlc_mutex_unlock( &p_input->stream.stream_lock );
232 msg_Info( p_intf, "Old: %d, New: %d", i_old, i_subtitle);
233 if( i_subtitle != -1 )
235 input_ToggleES( p_input,
236 p_input->stream.pp_selected_es[i_subtitle],
240 if( (i_old != -1) && (i_old != i_subtitle) )
242 input_ToggleES( p_input,
243 p_input->stream.pp_selected_es[i_old],
248 const char* VlcWrapper::getTimeAsString()
250 static char psz_currenttime[ OFFSETTOTIME_MAX_SIZE ];
252 if( p_input == NULL )
257 input_OffsetToTime( p_input,
259 p_input->stream.p_selected_area->i_tell );
261 return(psz_currenttime);
264 float VlcWrapper::getTimeAsFloat()
268 if( p_input != NULL )
270 f_time = (float)p_input->stream.p_selected_area->i_tell /
271 (float)p_input->stream.p_selected_area->i_size;
280 void VlcWrapper::setTimeAsFloat(float f_position)
282 if( p_input != NULL )
285 (long long int)(p_input->stream.p_selected_area->i_size
286 * f_position / SEEKSLIDER_RANGE ),
291 bool VlcWrapper::IsPlaying()
294 bool playing = false;
297 switch ( p_input->stream.control.i_status )
316 /******************************
317 * playlist infos and control *
318 ******************************/
319 int VlcWrapper::PlaylistSize()
321 vlc_mutex_lock( &p_playlist->object_lock );
322 int i_size = p_playlist->i_size;
323 vlc_mutex_unlock( &p_playlist->object_lock );
327 char *VlcWrapper::PlaylistItemName( int i )
329 return p_playlist->pp_items[i]->psz_name;
332 int VlcWrapper::PlaylistCurrent()
334 return p_playlist->i_index;
337 int VlcWrapper::PlaylistStatus()
339 return p_playlist->i_status;
342 bool VlcWrapper::PlaylistPlay()
346 playlist_Play( p_playlist );
352 void VlcWrapper::PlaylistPause()
356 input_SetStatus( p_input, INPUT_STATUS_PAUSE );
360 void VlcWrapper::PlaylistStop()
362 playlist_Stop( p_playlist );
365 void VlcWrapper::PlaylistNext()
367 playlist_Next( p_playlist );
370 void VlcWrapper::PlaylistPrev()
372 playlist_Prev( p_playlist );
375 void VlcWrapper::PlaylistSkip( int i )
377 playlist_Skip( p_playlist, i );
380 void VlcWrapper::PlaylistGoto( int i )
382 playlist_Goto( p_playlist, i );
385 void VlcWrapper::PlaylistLoop()
387 if ( p_intf->p_sys->b_loop )
389 playlist_Delete( p_playlist, p_playlist->i_size - 1 );
393 playlist_Add( p_playlist, "vlc:loop",
394 PLAYLIST_APPEND | PLAYLIST_GO,
397 p_intf->p_sys->b_loop = !p_intf->p_sys->b_loop;
400 BList * VlcWrapper::PlaylistAsArray()
403 BList* p_list = new BList(p_playlist->i_size);
405 vlc_mutex_lock( &p_playlist->object_lock );
407 for( i = 0; i < p_playlist->i_size; i++ )
409 p_list->AddItem(new BString(p_playlist->pp_items[i]->psz_name));
412 vlc_mutex_unlock( &p_playlist->object_lock );
416 void VlcWrapper::getPlaylistInfo( int32& currentIndex, int32& maxIndex )
422 maxIndex = p_playlist->i_size;
424 currentIndex = p_playlist->i_index + 1;
431 void VlcWrapper::PlaylistJumpTo( int pos )
437 int size = playlistSize();
441 if( p_input_bank->pp_input[0] != NULL )
443 // stop current stream
445 // modify current position in playlist
447 p_main->p_playlist->i_index = pos;
454 void VlcWrapper::getNavCapabilities( bool *canSkipPrev, bool *canSkipNext )
456 if ( canSkipPrev && canSkipNext )
458 // init the parameters
459 *canSkipPrev = false;
460 *canSkipNext = false;
462 int pos = PlaylistCurrent();
463 int size = PlaylistSize();
465 // see if we have got a stream going
468 vlc_mutex_lock( &p_input->stream.stream_lock );
470 bool hasTitles = p_input->stream.i_area_nb > 1;
471 int numChapters = p_input->stream.p_selected_area->i_part_nb;
472 bool hasChapters = numChapters > 1;
473 // first, look for chapters
476 *canSkipPrev = p_input->stream.p_selected_area->i_part > 0;
477 *canSkipNext = p_input->stream.p_selected_area->i_part <
478 p_input->stream.p_selected_area->i_part_nb - 1;
480 // if one of the skip capabilities is false,
481 // make it depend on titles instead
482 if ( !*canSkipPrev && hasTitles )
483 *canSkipPrev = p_input->stream.p_selected_area->i_id > 1;
484 if ( !*canSkipNext && hasTitles )
485 *canSkipNext = p_input->stream.p_selected_area->i_id <
486 p_input->stream.i_area_nb - 1;
488 vlc_mutex_unlock( &p_input->stream.stream_lock );
490 // last but not least, make capabilities depend on playlist
492 *canSkipPrev = pos > 0;
494 *canSkipNext = pos < size - 1;
498 void VlcWrapper::navigatePrev()
500 bool hasSkiped = false;
502 // see if we have got a stream going
505 // get information from stream (lock it while looking at it)
506 vlc_mutex_lock( &p_input->stream.stream_lock );
508 int currentTitle = p_input->stream.p_selected_area->i_id;
509 int currentChapter = p_input->stream.p_selected_area->i_part;
510 int numTitles = p_input->stream.i_area_nb;
511 bool hasTitles = numTitles > 1;
512 int numChapters = p_input->stream.p_selected_area->i_part_nb;
513 bool hasChapters = numChapters > 1;
515 vlc_mutex_unlock( &p_input->stream.stream_lock );
517 // first, look for chapters
520 // skip to the previous chapter
523 if ( currentChapter >= 0 )
525 toggleChapter( currentChapter );
529 // if we couldn't skip chapters, try titles instead
530 if ( !hasSkiped && hasTitles )
532 // skip to the previous title
534 // disallow area 0 since it is used for video_ts.vob
535 if( currentTitle > 0 )
537 toggleTitle(currentTitle);
543 // last but not least, skip to previous file
548 void VlcWrapper::navigateNext()
550 bool hasSkiped = false;
552 // see if we have got a stream going
555 // get information from stream (lock it while looking at it)
556 vlc_mutex_lock( &p_input->stream.stream_lock );
558 int currentTitle = p_input->stream.p_selected_area->i_id;
559 int currentChapter = p_input->stream.p_selected_area->i_part;
560 int numTitles = p_input->stream.i_area_nb;
561 bool hasTitles = numTitles > 1;
562 int numChapters = p_input->stream.p_selected_area->i_part_nb;
563 bool hasChapters = numChapters > 1;
565 vlc_mutex_unlock( &p_input->stream.stream_lock );
567 // first, look for chapters
570 // skip to the next chapter
572 if ( currentChapter < numChapters )
574 toggleChapter( currentChapter );
578 // if we couldn't skip chapters, try titles instead
579 if ( !hasSkiped && hasTitles )
581 // skip to the next title
583 // disallow area 0 since it is used for video_ts.vob
584 if ( currentTitle < numTitles - 1 )
586 toggleTitle(currentTitle);
592 // last but not least, skip to next file
598 /***************************
599 * audio infos and control *
600 ***************************/
602 void VlcWrapper::SetVolume(int value)
606 if ( p_intf->p_sys->b_mute )
608 p_intf->p_sys->b_mute = 0;
610 aout_VolumeSet( p_aout, value );
614 void VlcWrapper::VolumeMute()
618 aout_VolumeGet( p_aout, &p_intf->p_sys->i_saved_volume );
619 aout_VolumeMute( p_aout, NULL );
620 p_intf->p_sys->b_mute = 1;
624 void VlcWrapper::VolumeRestore()
628 aout_VolumeSet( p_aout, p_intf->p_sys->i_saved_volume );
629 p_intf->p_sys->b_mute = 0;
633 bool VlcWrapper::IsMuted()
635 return p_intf->p_sys->b_mute;
638 bool VlcWrapper::HasAudio()
640 return( p_aout != NULL );
646 bool VlcWrapper::HasTitles()
652 return ( p_input->stream.i_area_nb > 1 );
655 void VlcWrapper::PrevTitle()
658 i_id = p_input->stream.p_selected_area->i_id - 1;
665 void VlcWrapper::NextTitle()
668 i_id = p_input->stream.p_selected_area->i_id + 1;
669 if( i_id < p_input->stream.i_area_nb )
675 bool VlcWrapper::HasChapters()
681 return ( p_input->stream.p_selected_area->i_part_nb > 1 );
684 void VlcWrapper::PrevChapter()
687 i_id = p_input->stream.p_selected_area->i_part - 1;
694 void VlcWrapper::NextChapter()
697 i_id = p_input->stream.p_selected_area->i_part + 1;
704 void VlcWrapper::TitleInfo( int32 ¤tIndex, int32 &maxIndex )
710 vlc_mutex_lock( &p_input->stream.stream_lock );
712 maxIndex = p_input->stream.i_area_nb - 1;
714 currentIndex = p_input->stream.p_selected_area->i_id;
718 vlc_mutex_unlock( &p_input->stream.stream_lock );
722 void VlcWrapper::ChapterInfo( int32 ¤tIndex, int32 &maxIndex )
728 vlc_mutex_lock( &p_input->stream.stream_lock );
730 maxIndex = p_input->stream.p_selected_area->i_part_nb - 1;
732 currentIndex = p_input->stream.p_selected_area->i_part;
736 vlc_mutex_unlock( &p_input->stream.stream_lock );
740 void VlcWrapper::toggleTitle(int i_title)
742 if( p_input != NULL )
744 input_ChangeArea( p_input,
745 p_input->stream.pp_areas[i_title] );
747 vlc_mutex_lock( &p_input->stream.stream_lock );
749 vlc_mutex_unlock( &p_input->stream.stream_lock );
753 void VlcWrapper::toggleChapter(int i_chapter)
755 if( p_input != NULL )
757 p_input->stream.p_selected_area->i_part = i_chapter;
758 input_ChangeArea( p_input,
759 p_input->stream.p_selected_area );
761 vlc_mutex_lock( &p_input->stream.stream_lock );
762 vlc_mutex_unlock( &p_input->stream.stream_lock );