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.14 2002/12/26 18:17:38 stippi 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>
32 #include <audio_output.h>
33 #include <aout_internal.h>
36 #include "VlcWrapper.h"
39 VlcWrapper::VlcWrapper( intf_thread_t *p_interface )
44 p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
49 VlcWrapper::~VlcWrapper()
53 vlc_object_release( p_input );
57 vlc_object_release( p_playlist );
61 vlc_object_release( p_aout );
65 /* UpdateInputAndAOut: updates p_input and p_aout, returns true if the
66 interface needs to be updated */
67 bool VlcWrapper::UpdateInputAndAOut()
71 p_input = (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
76 p_aout = (aout_instance_t*)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
84 vlc_object_release( p_input );
89 vlc_object_release( p_aout );
99 /***************************
100 * input infos and control *
101 ***************************/
103 /* status (UNDEF_S, PLAYING_S, PAUSE_S, FORWARD_S, BACKWARD_S,
104 REWIND_S, NOT_STARTED_S, START_S) */
105 int VlcWrapper::InputStatus()
111 return p_input->stream.control.i_status;
114 int VlcWrapper::InputRate()
120 return p_input->stream.control.i_rate;
123 /* tell: location in the current stream (in arbitrary units) */
124 int VlcWrapper::InputTell()
130 return p_input->stream.p_selected_area->i_tell;
133 /* size: total size of the current stream (in arbitrary units) */
134 int VlcWrapper::InputSize()
140 return p_input->stream.p_selected_area->i_size;
143 void VlcWrapper::InputSlower()
145 if( p_input != NULL )
147 input_SetStatus( p_input, INPUT_STATUS_SLOWER );
152 void VlcWrapper::InputFaster()
154 if( p_input != NULL )
156 input_SetStatus( p_input, INPUT_STATUS_FASTER );
161 void VlcWrapper::openFiles( BList* o_files, bool replace )
165 while( ( o_file = (BString *)o_files->LastItem() ) )
167 o_files->RemoveItem(o_files->CountItems() - 1);
168 playlist_Add( p_playlist, o_file->String(),
169 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
174 void VlcWrapper::openDisc(BString o_type, BString o_device, int i_title, int i_chapter)
176 BString o_source("");
177 o_source << o_type << ":" << o_device ;
179 playlist_Add( p_playlist, o_source.String(),
180 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
185 void VlcWrapper::toggleLanguage(int i_language)
189 int i_cat = AUDIO_ES;
191 vlc_mutex_lock( &p_input->stream.stream_lock );
192 for( unsigned int i = 0; i < p_input->stream.i_selected_es_number ; i++ )
194 if( p_input->stream.pp_selected_es[i]->i_cat == i_cat )
200 vlc_mutex_unlock( &p_input->stream.stream_lock );
202 msg_Info( p_intf, "Old: %d, New: %d", i_old, i_language);
203 if( i_language != -1 )
205 input_ToggleES( p_input,
206 p_input->stream.pp_selected_es[i_language],
210 if( (i_old != -1) && (i_old != i_language) )
212 input_ToggleES( p_input,
213 p_input->stream.pp_selected_es[i_old],
218 void VlcWrapper::toggleSubtitle(int i_subtitle)
223 vlc_mutex_lock( &p_input->stream.stream_lock );
224 for( unsigned int i = 0; i < p_input->stream.i_selected_es_number ; i++ )
226 if( p_input->stream.pp_selected_es[i]->i_cat == i_cat )
232 vlc_mutex_unlock( &p_input->stream.stream_lock );
234 msg_Info( p_intf, "Old: %d, New: %d", i_old, i_subtitle);
235 if( i_subtitle != -1 )
237 input_ToggleES( p_input,
238 p_input->stream.pp_selected_es[i_subtitle],
242 if( (i_old != -1) && (i_old != i_subtitle) )
244 input_ToggleES( p_input,
245 p_input->stream.pp_selected_es[i_old],
250 const char* VlcWrapper::getTimeAsString()
252 static char psz_currenttime[ OFFSETTOTIME_MAX_SIZE ];
254 if( p_input == NULL )
259 input_OffsetToTime( p_input,
261 p_input->stream.p_selected_area->i_tell );
263 return(psz_currenttime);
266 float VlcWrapper::getTimeAsFloat()
270 if( p_input != NULL )
272 f_time = (float)p_input->stream.p_selected_area->i_tell /
273 (float)p_input->stream.p_selected_area->i_size;
282 void VlcWrapper::setTimeAsFloat(float f_position)
284 if( p_input != NULL )
287 (long long int)(p_input->stream.p_selected_area->i_size
288 * f_position / SEEKSLIDER_RANGE ),
293 bool VlcWrapper::IsPlaying()
296 bool playing = false;
299 switch ( p_input->stream.control.i_status )
318 /******************************
319 * playlist infos and control *
320 ******************************/
321 int VlcWrapper::PlaylistSize()
323 vlc_mutex_lock( &p_playlist->object_lock );
324 int i_size = p_playlist->i_size;
325 vlc_mutex_unlock( &p_playlist->object_lock );
329 char *VlcWrapper::PlaylistItemName( int i )
331 return p_playlist->pp_items[i]->psz_name;
334 int VlcWrapper::PlaylistCurrent()
336 return p_playlist->i_index;
339 int VlcWrapper::PlaylistStatus()
341 return p_playlist->i_status;
344 bool VlcWrapper::PlaylistPlay()
348 playlist_Play( p_playlist );
354 void VlcWrapper::PlaylistPause()
358 input_SetStatus( p_input, INPUT_STATUS_PAUSE );
362 void VlcWrapper::PlaylistStop()
364 playlist_Stop( p_playlist );
367 void VlcWrapper::PlaylistNext()
369 playlist_Next( p_playlist );
372 void VlcWrapper::PlaylistPrev()
374 playlist_Prev( p_playlist );
377 void VlcWrapper::PlaylistSkip( int i )
379 playlist_Skip( p_playlist, i );
382 void VlcWrapper::PlaylistGoto( int i )
384 playlist_Goto( p_playlist, i );
387 void VlcWrapper::PlaylistLoop()
389 if ( p_intf->p_sys->b_loop )
391 playlist_Delete( p_playlist, p_playlist->i_size - 1 );
395 playlist_Add( p_playlist, "vlc:loop",
396 PLAYLIST_APPEND | PLAYLIST_GO,
399 p_intf->p_sys->b_loop = !p_intf->p_sys->b_loop;
402 BList * VlcWrapper::PlaylistAsArray()
405 BList* p_list = new BList(p_playlist->i_size);
407 vlc_mutex_lock( &p_playlist->object_lock );
409 for( i = 0; i < p_playlist->i_size; i++ )
411 p_list->AddItem(new BString(p_playlist->pp_items[i]->psz_name));
414 vlc_mutex_unlock( &p_playlist->object_lock );
418 void VlcWrapper::getPlaylistInfo( int32& currentIndex, int32& maxIndex )
424 maxIndex = p_playlist->i_size;
426 currentIndex = p_playlist->i_index + 1;
433 void VlcWrapper::PlaylistJumpTo( int pos )
439 int size = playlistSize();
443 if( p_input_bank->pp_input[0] != NULL )
445 // stop current stream
447 // modify current position in playlist
449 p_main->p_playlist->i_index = pos;
456 void VlcWrapper::getNavCapabilities( bool *canSkipPrev, bool *canSkipNext )
458 if ( canSkipPrev && canSkipNext )
460 // init the parameters
461 *canSkipPrev = false;
462 *canSkipNext = false;
464 int pos = PlaylistCurrent();
465 int size = PlaylistSize();
467 // see if we have got a stream going
470 vlc_mutex_lock( &p_input->stream.stream_lock );
472 bool hasTitles = p_input->stream.i_area_nb > 1;
473 int numChapters = p_input->stream.p_selected_area->i_part_nb;
474 bool hasChapters = numChapters > 1;
475 // first, look for chapters
478 *canSkipPrev = p_input->stream.p_selected_area->i_part > 0;
479 *canSkipNext = p_input->stream.p_selected_area->i_part <
480 p_input->stream.p_selected_area->i_part_nb - 1;
482 // if one of the skip capabilities is false,
483 // make it depend on titles instead
484 if ( !*canSkipPrev && hasTitles )
485 *canSkipPrev = p_input->stream.p_selected_area->i_id > 1;
486 if ( !*canSkipNext && hasTitles )
487 *canSkipNext = p_input->stream.p_selected_area->i_id <
488 p_input->stream.i_area_nb - 1;
490 vlc_mutex_unlock( &p_input->stream.stream_lock );
492 // last but not least, make capabilities depend on playlist
494 *canSkipPrev = pos > 0;
496 *canSkipNext = pos < size - 1;
500 void VlcWrapper::navigatePrev()
502 bool hasSkiped = false;
504 // see if we have got a stream going
507 // get information from stream (lock it while looking at it)
508 vlc_mutex_lock( &p_input->stream.stream_lock );
510 int currentTitle = p_input->stream.p_selected_area->i_id;
511 int currentChapter = p_input->stream.p_selected_area->i_part;
512 int numTitles = p_input->stream.i_area_nb;
513 bool hasTitles = numTitles > 1;
514 int numChapters = p_input->stream.p_selected_area->i_part_nb;
515 bool hasChapters = numChapters > 1;
517 vlc_mutex_unlock( &p_input->stream.stream_lock );
519 // first, look for chapters
522 // skip to the previous chapter
525 if ( currentChapter >= 0 )
527 toggleChapter( currentChapter );
531 // if we couldn't skip chapters, try titles instead
532 if ( !hasSkiped && hasTitles )
534 // skip to the previous title
536 // disallow area 0 since it is used for video_ts.vob
537 if( currentTitle > 0 )
539 toggleTitle(currentTitle);
545 // last but not least, skip to previous file
550 void VlcWrapper::navigateNext()
552 bool hasSkiped = false;
554 // see if we have got a stream going
557 // get information from stream (lock it while looking at it)
558 vlc_mutex_lock( &p_input->stream.stream_lock );
560 int currentTitle = p_input->stream.p_selected_area->i_id;
561 int currentChapter = p_input->stream.p_selected_area->i_part;
562 int numTitles = p_input->stream.i_area_nb;
563 bool hasTitles = numTitles > 1;
564 int numChapters = p_input->stream.p_selected_area->i_part_nb;
565 bool hasChapters = numChapters > 1;
567 vlc_mutex_unlock( &p_input->stream.stream_lock );
569 // first, look for chapters
572 // skip to the next chapter
574 if ( currentChapter < numChapters )
576 toggleChapter( currentChapter );
580 // if we couldn't skip chapters, try titles instead
581 if ( !hasSkiped && hasTitles )
583 // skip to the next title
585 // disallow area 0 since it is used for video_ts.vob
586 if ( currentTitle < numTitles - 1 )
588 toggleTitle(currentTitle);
594 // last but not least, skip to next file
600 /***************************
601 * audio infos and control *
602 ***************************/
604 void VlcWrapper::SetVolume(int value)
608 if ( p_intf->p_sys->b_mute )
610 p_intf->p_sys->b_mute = 0;
612 aout_VolumeSet( p_aout, value );
616 void VlcWrapper::VolumeMute()
620 aout_VolumeGet( p_aout, &p_intf->p_sys->i_saved_volume );
621 aout_VolumeMute( p_aout, NULL );
622 p_intf->p_sys->b_mute = 1;
626 void VlcWrapper::VolumeRestore()
630 aout_VolumeSet( p_aout, p_intf->p_sys->i_saved_volume );
631 p_intf->p_sys->b_mute = 0;
635 bool VlcWrapper::IsMuted()
637 return p_intf->p_sys->b_mute;
640 bool VlcWrapper::HasAudio()
642 return( p_aout != NULL );
648 bool VlcWrapper::HasTitles()
654 return ( p_input->stream.i_area_nb > 1 );
657 void VlcWrapper::PrevTitle()
660 i_id = p_input->stream.p_selected_area->i_id - 1;
667 void VlcWrapper::NextTitle()
670 i_id = p_input->stream.p_selected_area->i_id + 1;
671 if( i_id < p_input->stream.i_area_nb )
677 bool VlcWrapper::HasChapters()
683 return ( p_input->stream.p_selected_area->i_part_nb > 1 );
686 void VlcWrapper::PrevChapter()
689 i_id = p_input->stream.p_selected_area->i_part - 1;
696 void VlcWrapper::NextChapter()
699 i_id = p_input->stream.p_selected_area->i_part + 1;
706 void VlcWrapper::TitleInfo( int32 ¤tIndex, int32 &maxIndex )
712 vlc_mutex_lock( &p_input->stream.stream_lock );
714 maxIndex = p_input->stream.i_area_nb - 1;
716 currentIndex = p_input->stream.p_selected_area->i_id;
720 vlc_mutex_unlock( &p_input->stream.stream_lock );
724 void VlcWrapper::ChapterInfo( int32 ¤tIndex, int32 &maxIndex )
730 vlc_mutex_lock( &p_input->stream.stream_lock );
732 maxIndex = p_input->stream.p_selected_area->i_part_nb - 1;
734 currentIndex = p_input->stream.p_selected_area->i_part;
738 vlc_mutex_unlock( &p_input->stream.stream_lock );
742 void VlcWrapper::toggleTitle(int i_title)
744 if( p_input != NULL )
746 input_ChangeArea( p_input,
747 p_input->stream.pp_areas[i_title] );
749 vlc_mutex_lock( &p_input->stream.stream_lock );
751 vlc_mutex_unlock( &p_input->stream.stream_lock );
755 void VlcWrapper::toggleChapter(int i_chapter)
757 if( p_input != NULL )
759 p_input->stream.p_selected_area->i_part = i_chapter;
760 input_ChangeArea( p_input,
761 p_input->stream.p_selected_area );
763 vlc_mutex_lock( &p_input->stream.stream_lock );
764 vlc_mutex_unlock( &p_input->stream.stream_lock );