1 /*****************************************************************************
2 * intf_vlc_wrapper.h: BeOS plugin for vlc (derived from MacOS X port )
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
5 * $Id: VlcWrapper.cpp,v 1.4 2002/09/30 18:30:27 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>
12 * This program is free software{} you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation{} either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY{} without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program{} if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
25 *****************************************************************************/
27 #include <SupportKit.h>
32 #include "VlcWrapper.h"
34 Intf_VLCWrapper *Intf_VLCWrapper::getVLCWrapper(intf_thread_t *p_if)
36 static Intf_VLCWrapper *one_wrapper;
37 if (one_wrapper == NULL )
39 one_wrapper = new Intf_VLCWrapper(p_if);
44 Intf_VLCWrapper::Intf_VLCWrapper(intf_thread_t *p_if)
49 Intf_VLCWrapper::~Intf_VLCWrapper()
54 bool Intf_VLCWrapper::manage()
56 p_main->p_intf->pf_manage( p_main->p_intf );
58 if ( p_main->p_intf->b_die )
64 if ( p_input_bank->pp_input[0] != NULL )
66 vlc_mutex_lock( &p_input_bank->pp_input[0]->stream.stream_lock );
67 if( !p_input_bank->pp_input[0]->b_die )
69 /* New input or stream map change */
70 if( p_input_bank->pp_input[0]->stream.b_changed ||
71 p_main->p_intf->p_sys->i_part !=
72 p_input_bank->pp_input[0]->stream.p_selected_area->i_part )
75 p_main->p_intf->p_sys->b_disabled_menus = 0;
78 vlc_mutex_unlock( &p_input_bank->pp_input[0]->stream.stream_lock );
80 else if ( !p_main->p_intf->p_sys->b_disabled_menus )
83 p_main->p_intf->p_sys->b_disabled_menus = 1;
89 void Intf_VLCWrapper::quit()
94 /* playlist control */
95 bool Intf_VLCWrapper::playlistPlay()
97 playlist_t *p_playlist =
98 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
101 vlc_mutex_lock( &p_playlist->object_lock );
102 if( p_playlist->i_size )
104 vlc_mutex_unlock( &p_playlist->object_lock );
105 playlist_Play( p_playlist );
106 vlc_object_release( p_playlist );
110 vlc_mutex_unlock( &p_playlist->object_lock );
111 vlc_object_release( p_playlist );
117 void Intf_VLCWrapper::playlistPause()
120 playlist_t *p_playlist =
121 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
123 playlist_Pause( p_playlist );
124 vlc_object_release( p_playlist );
127 void Intf_VLCWrapper::playlistStop()
129 playlist_t *p_playlist =
130 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
133 playlist_Stop( p_playlist );
134 vlc_object_release( p_playlist );
137 void Intf_VLCWrapper::playlistNext()
139 playlist_t *p_playlist =
140 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
143 playlist_Next( p_playlist );
144 vlc_object_release( p_playlist );
147 void Intf_VLCWrapper::playlistPrev()
149 playlist_t *p_playlist =
150 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
153 playlist_Prev( p_playlist );
154 vlc_object_release( p_playlist );
157 void Intf_VLCWrapper::playlistSkip(int i)
159 playlist_t *p_playlist =
160 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
163 playlist_Skip( p_playlist, i );
164 vlc_object_release( p_playlist );
167 void Intf_VLCWrapper::playlistGoto(int i)
169 playlist_t *p_playlist =
170 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
173 playlist_Goto( p_playlist, i );
174 vlc_object_release( p_playlist );
177 void Intf_VLCWrapper::playlistJumpTo( int pos )
183 int size = playlistSize();
187 if( p_input_bank->pp_input[0] != NULL )
189 // stop current stream
191 // modify current position in playlist
193 p_main->p_playlist->i_index = pos;
200 int Intf_VLCWrapper::playlistCurrentPos()
203 int pos = p_main->p_playlist->i_index;
208 int Intf_VLCWrapper::playlistSize()
211 int size = p_main->p_playlist->i_size;
216 void Intf_VLCWrapper::playlistLock()
218 /*vlc_mutex_lock( &p_main->p_playlist->change_lock );*/
221 void Intf_VLCWrapper::playlistUnlock()
223 /*vlc_mutex_unlock( &p_main->p_playlist->change_lock );*/
226 void Intf_VLCWrapper::getNavCapabilities( bool* canSkipPrev,
230 if ( canSkipPrev && canSkipNext )
232 // init the parameters
233 *canSkipPrev = false;
234 *canSkipNext = false;
237 int pos = p_main->p_playlist->i_index;
238 int size = p_main->p_playlist->i_size;
241 input_thread_t* input = p_input_bank->pp_input[0];
242 // see if we have got a stream going
245 vlc_mutex_lock( &input->stream.stream_lock );
247 bool hasTitles = input->stream.i_area_nb > 1;
248 int numChapters = input->stream.p_selected_area->i_part_nb;
249 bool hasChapters = numChapters > 1;
250 // first, look for chapters
253 *canSkipPrev = input->stream.p_selected_area->i_part > 0;
254 *canSkipNext = input->stream.p_selected_area->i_part <
255 input->stream.p_selected_area->i_part_nb - 1;
257 // if one of the skip capabilities is false,
258 // make it depend on titles instead
259 if ( !*canSkipPrev && hasTitles )
260 *canSkipPrev = input->stream.p_selected_area->i_id > 1;
261 if ( !*canSkipNext && hasTitles )
262 *canSkipNext = input->stream.p_selected_area->i_id < input->stream.i_area_nb - 1;
264 vlc_mutex_unlock( &input->stream.stream_lock );
266 // last but not least, make capabilities depend on playlist
268 *canSkipPrev = pos > 0;
270 *canSkipNext = pos < size - 1;
275 void Intf_VLCWrapper::navigatePrev()
278 bool hasSkiped = false;
280 input_thread_t* input = p_input_bank->pp_input[0];
281 // see if we have got a stream going
284 // get information from stream (lock it while looking at it)
285 vlc_mutex_lock( &input->stream.stream_lock );
287 int currentTitle = input->stream.p_selected_area->i_id;
288 int currentChapter = input->stream.p_selected_area->i_part;
289 int numTitles = input->stream.i_area_nb;
290 bool hasTitles = numTitles > 1;
291 int numChapters = input->stream.p_selected_area->i_part_nb;
292 bool hasChapters = numChapters > 1;
294 vlc_mutex_unlock( &input->stream.stream_lock );
296 // first, look for chapters
299 // skip to the previous chapter
302 if ( currentChapter >= 0 )
304 toggleChapter( currentChapter );
308 // if we couldn't skip chapters, try titles instead
309 if ( !hasSkiped && hasTitles )
311 // skip to the previous title
313 // disallow area 0 since it is used for video_ts.vob
314 if( currentTitle > 0 )
316 toggleTitle(currentTitle);
322 // last but not least, skip to previous file
328 void Intf_VLCWrapper::navigateNext()
331 bool hasSkiped = false;
333 input_thread_t* input = p_input_bank->pp_input[0];
334 // see if we have got a stream going
337 // get information from stream (lock it while looking at it)
338 vlc_mutex_lock( &input->stream.stream_lock );
340 int currentTitle = input->stream.p_selected_area->i_id;
341 int currentChapter = input->stream.p_selected_area->i_part;
342 int numTitles = input->stream.i_area_nb;
343 bool hasTitles = numTitles > 1;
344 int numChapters = input->stream.p_selected_area->i_part_nb;
345 bool hasChapters = numChapters > 1;
347 vlc_mutex_unlock( &input->stream.stream_lock );
349 // first, look for chapters
352 // skip to the next chapter
354 if ( currentChapter < numChapters )
356 toggleChapter( currentChapter );
360 // if we couldn't skip chapters, try titles instead
361 if ( !hasSkiped && hasTitles )
363 // skip to the next title
365 // disallow area 0 since it is used for video_ts.vob
366 if ( currentTitle < numTitles - 1 )
368 toggleTitle(currentTitle);
374 // last but not least, skip to next file
381 //void Intf_VLCWrapper::channelNext()
383 // intf_thread_t * p_intf = p_main->p_intf;
385 // p_intf->p_sys->i_channel++;
387 // intf_WarnMsg( 3, "intf info: joining channel %d", p_intf->p_sys->i_channel );
389 // vlc_mutex_lock( &p_intf->change_lock );
391 // network_ChannelJoin( p_intf->p_sys->i_channel );
392 // p_intf->pf_manage( p_intf );
394 // vlc_mutex_unlock( &p_intf->change_lock );
397 //void Intf_VLCWrapper::channelPrev()
399 // intf_thread_t * p_intf = p_main->p_intf;
401 // if ( p_intf->p_sys->i_channel )
403 // p_intf->p_sys->i_channel--;
406 // intf_WarnMsg( 3, "intf info: joining channel %d", p_intf->p_sys->i_channel );
408 // vlc_mutex_lock( &p_intf->change_lock );
410 // network_ChannelJoin( p_intf->p_sys->i_channel );
411 // p_intf->pf_manage( p_intf );
413 // vlc_mutex_unlock( &p_intf->change_lock );
417 void Intf_VLCWrapper::loop()
420 intf_thread_t * p_intf = p_main->p_intf;
422 if ( p_intf->p_sys->b_loop )
424 intf_PlaylistDelete( p_main->p_playlist,
425 p_main->p_playlist->i_size - 1 );
429 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END,
432 p_intf->p_sys->b_loop = !p_intf->p_sys->b_loop;
437 /* playback control */
438 void Intf_VLCWrapper::playSlower()
440 if( p_intf->p_sys->p_input != NULL )
442 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_SLOWER );
444 if (p_intf->p_sys->p_input->stream.control.i_rate == DEFAULT_RATE)
454 void Intf_VLCWrapper::playFaster()
456 if( p_intf->p_sys->p_input != NULL )
458 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_FASTER );
460 if (p_intf->p_sys->p_input->stream.control.i_rate == DEFAULT_RATE)
470 void Intf_VLCWrapper::volume_mute()
473 if( p_aout_bank->i_count > 0
474 && p_aout_bank->pp_aout[0] != NULL )
476 if( !p_main->p_intf->p_sys->b_mute )
478 p_main->p_intf->p_sys->i_saved_volume =
479 p_aout_bank->pp_aout[0]->i_volume;
480 p_aout_bank->pp_aout[0]->i_volume = 0;
481 p_main->p_intf->p_sys->b_mute = 1;
487 void Intf_VLCWrapper::volume_restore()
490 if( p_aout_bank->i_count > 0
491 && p_aout_bank->pp_aout[0] != NULL )
493 p_aout_bank->pp_aout[0]->i_volume =
494 p_main->p_intf->p_sys->i_saved_volume;
495 p_main->p_intf->p_sys->i_saved_volume = 0;
496 p_main->p_intf->p_sys->b_mute = 0;
501 void Intf_VLCWrapper::set_volume(int value)
504 if( p_aout_bank->i_count > 0
505 && p_aout_bank->pp_aout[0] != NULL )
507 // make sure value is within bounds
510 if (value > AOUT_VOLUME_MAX)
511 value = AOUT_VOLUME_MAX;
512 vlc_mutex_lock( &p_aout_bank->lock );
513 // unmute volume if muted
514 if ( p_main->p_intf->p_sys->b_mute )
515 p_main->p_intf->p_sys->b_mute = 0;
516 // set every stream to the given value
517 for ( int i = 0 ; i < p_aout_bank->i_count ; i++ )
519 if ( p_aout_bank->pp_aout[i] )
520 p_aout_bank->pp_aout[i]->i_volume = value;
522 vlc_mutex_unlock( &p_aout_bank->lock );
527 void Intf_VLCWrapper::toggle_mute()
530 if( p_aout_bank->i_count > 0
531 && p_aout_bank->pp_aout[0] != NULL )
533 if ( p_main->p_intf->p_sys->b_mute )
535 Intf_VLCWrapper::volume_restore();
539 Intf_VLCWrapper::volume_mute();
545 bool Intf_VLCWrapper::is_muted()
549 if ( p_aout_bank->i_count > 0 )
551 vlc_mutex_lock( &p_aout_bank->lock );
552 for ( int i = 0 ; i < p_aout_bank->i_count ; i++ )
554 if ( p_aout_bank->pp_aout[i]
555 && p_aout_bank->pp_aout[i]->i_volume > 0 )
561 vlc_mutex_unlock( &p_aout_bank->lock );
562 // unfortunately, this is not reliable!
563 // return p_main->p_intf->p_sys->b_mute;
569 bool Intf_VLCWrapper::is_playing()
572 bool playing = false;
573 if ( p_input_bank->pp_input[0] )
575 switch ( p_input_bank->pp_input[0]->stream.control.i_status )
594 void Intf_VLCWrapper::maxvolume()
597 if( p_aout_bank->i_count > 0
598 && p_aout_bank->pp_aout[0] != NULL )
600 if( p_main->p_intf->p_sys->b_mute )
602 p_main->p_intf->p_sys->i_saved_volume = VOLUME_MAX;
606 p_aout_bank->pp_aout[0]->i_volume = VOLUME_MAX;
612 bool Intf_VLCWrapper::has_audio()
614 /* return (p_aout_bank->i_count > 0); */
617 //void Intf_VLCWrapper::fullscreen()
619 // if( p_vout_bank->pp_vout[0] != NULL )
621 // p_vout_bank->pp_vout[0]->i_changes |= VOUT_FULLSCREEN_CHANGE;
625 void Intf_VLCWrapper::eject(){}
629 BString* Intf_VLCWrapper::getTimeAsString()
631 static char psz_currenttime[ OFFSETTOTIME_MAX_SIZE ];
633 if( p_intf->p_sys->p_input == NULL )
635 return (new BString("00:00:00"));
638 input_OffsetToTime( p_intf->p_sys->p_input,
640 p_intf->p_sys->p_input->stream.p_selected_area->i_tell );
642 return(new BString(psz_currenttime));
645 float Intf_VLCWrapper::getTimeAsFloat()
649 if( p_intf->p_sys->p_input != NULL )
651 f_time = (float)p_intf->p_sys->p_input->stream.p_selected_area->i_tell /
652 (float)p_intf->p_sys->p_input->stream.p_selected_area->i_size;
661 void Intf_VLCWrapper::setTimeAsFloat(float f_position)
663 if( p_intf->p_sys->p_input != NULL )
665 input_Seek( p_intf->p_sys->p_input,
666 (long long int)(p_intf->p_sys->p_input->stream.p_selected_area->i_size * f_position / 100),
671 bool Intf_VLCWrapper::playlistPlaying()
673 /* return( !p_main->p_playlist->b_stopped ); */
676 BList *Intf_VLCWrapper::playlistAsArray()
679 playlist_t *p_playlist =
680 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
683 BList* p_list = new BList(p_playlist->i_size);
685 vlc_mutex_lock( &p_playlist->object_lock );
687 for( i = 0; i < p_playlist->i_size; i++ )
689 p_list->AddItem(new BString(p_playlist->pp_items[i]->psz_name));
692 vlc_mutex_unlock( &p_playlist->object_lock );
693 vlc_object_release( p_playlist );
697 /* open file/disc/network */
698 void Intf_VLCWrapper::openFiles( BList* o_files, bool replace )
701 playlist_t *p_playlist =
702 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
705 while( ( o_file = (BString *)o_files->LastItem() ) )
707 o_files->RemoveItem(o_files->CountItems() - 1);
708 playlist_Add( p_playlist, o_file->String(),
709 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
713 vlc_object_release( p_playlist );
716 void Intf_VLCWrapper::openDisc(BString o_type, BString o_device, int i_title, int i_chapter)
718 BString o_source("");
719 o_source << o_type << ":" << o_device ;
721 playlist_t *p_playlist =
722 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
724 playlist_Add( p_playlist, o_source.String(),
725 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
726 vlc_object_release( p_playlist );
729 void Intf_VLCWrapper::openNet(BString o_addr, int i_port)
733 void Intf_VLCWrapper::openNetChannel(BString o_addr, int i_port)
737 void Intf_VLCWrapper::openNetHTTP(BString o_addr)
742 /* menus management */
743 void Intf_VLCWrapper::toggleProgram(int i_program){}
745 void Intf_VLCWrapper::toggleTitle(int i_title)
747 if( p_intf->p_sys->p_input != NULL )
749 input_ChangeArea( p_intf->p_sys->p_input,
750 p_intf->p_sys->p_input->stream.pp_areas[i_title] );
752 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
755 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
759 void Intf_VLCWrapper::toggleChapter(int i_chapter)
761 if( p_intf->p_sys->p_input != NULL )
763 p_intf->p_sys->p_input->stream.p_selected_area->i_part = i_chapter;
764 input_ChangeArea( p_intf->p_sys->p_input,
765 p_intf->p_sys->p_input->stream.p_selected_area );
767 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
769 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
773 void Intf_VLCWrapper::toggleLanguage(int i_language)
777 int i_cat = AUDIO_ES;
779 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
780 for( int i = 0; i < p_intf->p_sys->p_input->stream.i_selected_es_number ; i++ )
782 if( p_intf->p_sys->p_input->stream.pp_selected_es[i]->i_cat == i_cat )
788 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
790 msg_Info( p_intf, "Old: %d, New: %d", i_old, i_language);
791 if( i_language != -1 )
793 input_ToggleES( p_intf->p_sys->p_input,
794 p_intf->p_sys->p_input->stream.pp_selected_es[i_language],
798 if( (i_old != -1) && (i_old != i_language) )
800 input_ToggleES( p_intf->p_sys->p_input,
801 p_intf->p_sys->p_input->stream.pp_selected_es[i_old],
806 void Intf_VLCWrapper::toggleSubtitle(int i_subtitle)
811 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
812 for( int i = 0; i < p_intf->p_sys->p_input->stream.i_selected_es_number ; i++ )
814 if( p_intf->p_sys->p_input->stream.pp_selected_es[i]->i_cat == i_cat )
820 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
822 msg_Info( p_intf, "Old: %d, New: %d", i_old, i_subtitle);
823 if( i_subtitle != -1 )
825 input_ToggleES( p_intf->p_sys->p_input,
826 p_intf->p_sys->p_input->stream.pp_selected_es[i_subtitle],
830 if( (i_old != -1) && (i_old != i_subtitle) )
832 input_ToggleES( p_intf->p_sys->p_input,
833 p_intf->p_sys->p_input->stream.pp_selected_es[i_old],
839 void Intf_VLCWrapper::setupMenus(){}
840 int Intf_VLCWrapper::inputGetStatus() {}