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.9 2002/10/30 00:59:22 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 <SupportKit.h>
32 #include <audio_output.h>
33 #include <aout_internal.h>
35 #include "VlcWrapper.h"
37 Intf_VLCWrapper::Intf_VLCWrapper(intf_thread_t *p_interface)
42 Intf_VLCWrapper::~Intf_VLCWrapper()
46 /* playlist control */
47 bool Intf_VLCWrapper::playlistPlay()
49 playlist_t *p_playlist =
50 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
53 vlc_mutex_lock( &p_playlist->object_lock );
54 if( p_playlist->i_size )
56 vlc_mutex_unlock( &p_playlist->object_lock );
57 playlist_Play( p_playlist );
58 vlc_object_release( p_playlist );
62 vlc_mutex_unlock( &p_playlist->object_lock );
63 vlc_object_release( p_playlist );
69 void Intf_VLCWrapper::playlistPause()
72 playlist_t *p_playlist =
73 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
75 playlist_Pause( p_playlist );
76 vlc_object_release( p_playlist );
79 void Intf_VLCWrapper::playlistStop()
81 playlist_t *p_playlist =
82 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
84 playlist_Stop( p_playlist );
85 vlc_object_release( p_playlist );
88 void Intf_VLCWrapper::playlistNext()
90 playlist_t *p_playlist =
91 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
94 playlist_Next( p_playlist );
95 vlc_object_release( p_playlist );
98 void Intf_VLCWrapper::playlistPrev()
100 playlist_t *p_playlist =
101 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
104 playlist_Prev( p_playlist );
105 vlc_object_release( p_playlist );
108 void Intf_VLCWrapper::playlistSkip(int i)
110 playlist_t *p_playlist =
111 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
114 playlist_Skip( p_playlist, i );
115 vlc_object_release( p_playlist );
118 void Intf_VLCWrapper::playlistGoto(int i)
120 playlist_t *p_playlist =
121 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
124 playlist_Goto( p_playlist, i );
125 vlc_object_release( p_playlist );
128 void Intf_VLCWrapper::playlistJumpTo( int pos )
134 int size = playlistSize();
138 if( p_input_bank->pp_input[0] != NULL )
140 // stop current stream
142 // modify current position in playlist
144 p_main->p_playlist->i_index = pos;
151 int Intf_VLCWrapper::playlistCurrentPos()
154 int pos = p_intf->p_sys->p_playlist->i_index;
159 int Intf_VLCWrapper::playlistSize()
162 int size = p_intf->p_sys->p_playlist->i_size;
167 void Intf_VLCWrapper::playlistLock()
169 vlc_mutex_lock( &p_intf->p_sys->p_playlist->object_lock );
172 void Intf_VLCWrapper::playlistUnlock()
174 vlc_mutex_unlock( &p_intf->p_sys->p_playlist->object_lock );
177 void Intf_VLCWrapper::getNavCapabilities( bool* canSkipPrev,
180 if ( canSkipPrev && canSkipNext )
182 // init the parameters
183 *canSkipPrev = false;
184 *canSkipNext = false;
187 int pos = p_intf->p_sys->p_playlist->i_index;
188 int size = p_intf->p_sys->p_playlist->i_size;
191 /* input_thread_t* input = p_input_bank->pp_input[0]; */
192 input_thread_t* input = p_intf->p_sys->p_input;
193 // see if we have got a stream going
196 vlc_mutex_lock( &input->stream.stream_lock );
198 bool hasTitles = input->stream.i_area_nb > 1;
199 int numChapters = input->stream.p_selected_area->i_part_nb;
200 bool hasChapters = numChapters > 1;
201 // first, look for chapters
204 *canSkipPrev = input->stream.p_selected_area->i_part > 0;
205 *canSkipNext = input->stream.p_selected_area->i_part <
206 input->stream.p_selected_area->i_part_nb - 1;
208 // if one of the skip capabilities is false,
209 // make it depend on titles instead
210 if ( !*canSkipPrev && hasTitles )
211 *canSkipPrev = input->stream.p_selected_area->i_id > 1;
212 if ( !*canSkipNext && hasTitles )
213 *canSkipNext = input->stream.p_selected_area->i_id < input->stream.i_area_nb - 1;
215 vlc_mutex_unlock( &input->stream.stream_lock );
217 // last but not least, make capabilities depend on playlist
219 *canSkipPrev = pos > 0;
221 *canSkipNext = pos < size - 1;
225 void Intf_VLCWrapper::navigatePrev()
228 bool hasSkiped = false;
230 input_thread_t* input = p_input_bank->pp_input[0];
231 // see if we have got a stream going
234 // get information from stream (lock it while looking at it)
235 vlc_mutex_lock( &input->stream.stream_lock );
237 int currentTitle = input->stream.p_selected_area->i_id;
238 int currentChapter = input->stream.p_selected_area->i_part;
239 int numTitles = input->stream.i_area_nb;
240 bool hasTitles = numTitles > 1;
241 int numChapters = input->stream.p_selected_area->i_part_nb;
242 bool hasChapters = numChapters > 1;
244 vlc_mutex_unlock( &input->stream.stream_lock );
246 // first, look for chapters
249 // skip to the previous chapter
252 if ( currentChapter >= 0 )
254 toggleChapter( currentChapter );
258 // if we couldn't skip chapters, try titles instead
259 if ( !hasSkiped && hasTitles )
261 // skip to the previous title
263 // disallow area 0 since it is used for video_ts.vob
264 if( currentTitle > 0 )
266 toggleTitle(currentTitle);
272 // last but not least, skip to previous file
278 void Intf_VLCWrapper::navigateNext()
281 bool hasSkiped = false;
283 input_thread_t* input = p_input_bank->pp_input[0];
284 // see if we have got a stream going
287 // get information from stream (lock it while looking at it)
288 vlc_mutex_lock( &input->stream.stream_lock );
290 int currentTitle = input->stream.p_selected_area->i_id;
291 int currentChapter = input->stream.p_selected_area->i_part;
292 int numTitles = input->stream.i_area_nb;
293 bool hasTitles = numTitles > 1;
294 int numChapters = input->stream.p_selected_area->i_part_nb;
295 bool hasChapters = numChapters > 1;
297 vlc_mutex_unlock( &input->stream.stream_lock );
299 // first, look for chapters
302 // skip to the next chapter
304 if ( currentChapter < numChapters )
306 toggleChapter( currentChapter );
310 // if we couldn't skip chapters, try titles instead
311 if ( !hasSkiped && hasTitles )
313 // skip to the next title
315 // disallow area 0 since it is used for video_ts.vob
316 if ( currentTitle < numTitles - 1 )
318 toggleTitle(currentTitle);
324 // last but not least, skip to next file
331 //void Intf_VLCWrapper::channelNext()
333 // intf_thread_t * p_intf = p_main->p_intf;
335 // p_intf->p_sys->i_channel++;
337 // intf_WarnMsg( 3, "intf info: joining channel %d", p_intf->p_sys->i_channel );
339 // vlc_mutex_lock( &p_intf->change_lock );
341 // network_ChannelJoin( p_intf->p_sys->i_channel );
342 // p_intf->pf_manage( p_intf );
344 // vlc_mutex_unlock( &p_intf->change_lock );
347 //void Intf_VLCWrapper::channelPrev()
349 // intf_thread_t * p_intf = p_main->p_intf;
351 // if ( p_intf->p_sys->i_channel )
353 // p_intf->p_sys->i_channel--;
356 // intf_WarnMsg( 3, "intf info: joining channel %d", p_intf->p_sys->i_channel );
358 // vlc_mutex_lock( &p_intf->change_lock );
360 // network_ChannelJoin( p_intf->p_sys->i_channel );
361 // p_intf->pf_manage( p_intf );
363 // vlc_mutex_unlock( &p_intf->change_lock );
367 void Intf_VLCWrapper::loop()
369 if ( p_intf->p_sys->b_loop )
371 playlist_Delete( p_intf->p_sys->p_playlist,
372 p_intf->p_sys->p_playlist->i_size - 1 );
376 playlist_Add( p_intf->p_sys->p_playlist, "vlc:loop",
377 PLAYLIST_APPEND | PLAYLIST_GO,
380 p_intf->p_sys->b_loop = !p_intf->p_sys->b_loop;
384 /* playback control */
385 void Intf_VLCWrapper::playSlower()
387 if( p_intf->p_sys->p_input != NULL )
389 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_SLOWER );
391 if (p_intf->p_sys->p_input->stream.control.i_rate == DEFAULT_RATE)
401 void Intf_VLCWrapper::playFaster()
403 if( p_intf->p_sys->p_input != NULL )
405 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_FASTER );
407 if (p_intf->p_sys->p_input->stream.control.i_rate == DEFAULT_RATE)
417 void Intf_VLCWrapper::volume_mute()
419 p_intf->p_sys->p_aout =
420 (aout_instance_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
422 if( p_intf->p_sys->p_aout != NULL )
424 if( !p_intf->p_sys->b_mute )
426 p_intf->p_sys->i_saved_volume = p_intf->p_sys->p_aout->output.i_volume;
427 p_intf->p_sys->p_aout->output.i_volume = 0;
428 p_intf->p_sys->b_mute = 1;
434 void Intf_VLCWrapper::volume_restore()
436 p_intf->p_sys->p_aout =
437 (aout_instance_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
439 if( p_intf->p_sys->p_aout != NULL )
441 p_intf->p_sys->p_aout->output.i_volume = p_intf->p_sys->i_saved_volume;
442 p_intf->p_sys->i_saved_volume = 0;
443 p_intf->p_sys->b_mute = 0;
448 void Intf_VLCWrapper::set_volume(int value)
450 p_intf->p_sys->p_aout =
451 (aout_instance_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
453 if( p_intf->p_sys->p_aout != NULL )
455 // make sure value is within bounds
458 if (value > AOUT_VOLUME_MAX)
459 value = AOUT_VOLUME_MAX;
460 vlc_mutex_lock( &p_intf->p_sys->p_aout->mixer_lock );
461 // unmute volume if muted
462 if ( p_intf->p_sys->b_mute )
464 p_intf->p_sys->b_mute = 0;
465 p_intf->p_sys->p_aout->output.i_volume = value;
467 vlc_mutex_unlock( &p_intf->p_sys->p_aout->mixer_lock );
471 void Intf_VLCWrapper::toggle_mute()
473 p_intf->p_sys->p_aout =
474 (aout_instance_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
476 if( p_intf->p_sys->p_aout != NULL )
478 if ( p_intf->p_sys->b_mute )
489 bool Intf_VLCWrapper::is_muted()
493 p_intf->p_sys->p_aout =
494 (aout_instance_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
496 if( p_intf->p_sys->p_aout != NULL )
498 vlc_mutex_lock( &p_intf->p_sys->p_aout->mixer_lock );
499 if( p_intf->p_sys->p_aout->output.i_volume > 0 )
503 vlc_mutex_unlock( &p_intf->p_sys->p_aout->mixer_lock );
504 // unfortunately, this is not reliable!
505 // return p_main->p_intf->p_sys->b_mute;
510 bool Intf_VLCWrapper::is_playing()
513 bool playing = false;
514 if ( p_intf->p_sys->p_input )
516 switch ( p_intf->p_sys->p_input->stream.control.i_status )
535 void Intf_VLCWrapper::maxvolume()
537 p_intf->p_sys->p_aout =
538 (aout_instance_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
540 if( p_intf->p_sys->p_aout != NULL )
542 if( p_intf->p_sys->b_mute )
544 p_intf->p_sys->i_saved_volume = AOUT_VOLUME_MAX;
548 p_intf->p_sys->p_aout->output.i_volume = AOUT_VOLUME_MAX;
553 bool Intf_VLCWrapper::has_audio()
555 p_intf->p_sys->p_aout =
556 (aout_instance_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
558 return( p_intf->p_sys->p_aout != NULL );
563 const char* Intf_VLCWrapper::getTimeAsString()
565 static char psz_currenttime[ OFFSETTOTIME_MAX_SIZE ];
567 if( p_intf->p_sys->p_input == NULL )
572 input_OffsetToTime( p_intf->p_sys->p_input,
574 p_intf->p_sys->p_input->stream.p_selected_area->i_tell );
576 return(psz_currenttime);
579 float Intf_VLCWrapper::getTimeAsFloat()
583 if( p_intf->p_sys->p_input != NULL )
585 f_time = (float)p_intf->p_sys->p_input->stream.p_selected_area->i_tell /
586 (float)p_intf->p_sys->p_input->stream.p_selected_area->i_size;
595 void Intf_VLCWrapper::setTimeAsFloat(float f_position)
597 if( p_intf->p_sys->p_input != NULL )
599 input_Seek( p_intf->p_sys->p_input,
600 (long long int)(p_intf->p_sys->p_input->stream.p_selected_area->i_size
601 * f_position / SEEKSLIDER_RANGE ),
606 /* bool Intf_VLCWrapper::playlistPlaying()
608 return( !p_intf->p_sys->p_playlist->b_stopped );
611 BList *Intf_VLCWrapper::playlistAsArray()
614 playlist_t *p_playlist =
615 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
618 BList* p_list = new BList(p_playlist->i_size);
620 vlc_mutex_lock( &p_playlist->object_lock );
622 for( i = 0; i < p_playlist->i_size; i++ )
624 p_list->AddItem(new BString(p_playlist->pp_items[i]->psz_name));
627 vlc_mutex_unlock( &p_playlist->object_lock );
628 vlc_object_release( p_playlist );
634 Intf_VLCWrapper::getPlaylistInfo( int32& currentIndex, int32& maxIndex )
638 if ( playlist_t* list = (playlist_t*)p_intf->p_sys->p_playlist )
640 maxIndex = list->i_size;
642 currentIndex = list->i_index + 1;
650 Intf_VLCWrapper::getTitleInfo( int32& currentIndex, int32& maxIndex )
654 if ( input_thread_t* input = p_intf->p_sys->p_input )
656 vlc_mutex_lock( &input->stream.stream_lock );
658 maxIndex = input->stream.i_area_nb - 1;
660 currentIndex = input->stream.p_selected_area->i_id;
664 vlc_mutex_unlock( &input->stream.stream_lock );
670 Intf_VLCWrapper::getChapterInfo( int32& currentIndex, int32& maxIndex )
674 if ( input_thread_t* input = p_intf->p_sys->p_input )
676 vlc_mutex_lock( &input->stream.stream_lock );
678 maxIndex = input->stream.p_selected_area->i_part_nb - 1;
680 currentIndex = input->stream.p_selected_area->i_part;
684 vlc_mutex_unlock( &input->stream.stream_lock );
688 /* open file/disc/network */
689 void Intf_VLCWrapper::openFiles( BList* o_files, bool replace )
692 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
694 while( ( o_file = (BString *)o_files->LastItem() ) )
696 o_files->RemoveItem(o_files->CountItems() - 1);
697 playlist_Add( p_playlist, o_file->String(),
698 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
702 vlc_object_release( p_playlist );
705 void Intf_VLCWrapper::openDisc(BString o_type, BString o_device, int i_title, int i_chapter)
707 BString o_source("");
708 o_source << o_type << ":" << o_device ;
710 playlist_t *p_playlist =
711 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
713 playlist_Add( p_playlist, o_source.String(),
714 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
715 vlc_object_release( p_playlist );
718 void Intf_VLCWrapper::openNet(BString o_addr, int i_port)
722 void Intf_VLCWrapper::openNetChannel(BString o_addr, int i_port)
726 void Intf_VLCWrapper::openNetHTTP(BString o_addr)
731 /* menus management */
732 void Intf_VLCWrapper::toggleProgram(int i_program){}
734 void Intf_VLCWrapper::toggleTitle(int i_title)
736 if( p_intf->p_sys->p_input != NULL )
738 input_ChangeArea( p_intf->p_sys->p_input,
739 p_intf->p_sys->p_input->stream.pp_areas[i_title] );
741 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
743 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
747 void Intf_VLCWrapper::toggleChapter(int i_chapter)
749 if( p_intf->p_sys->p_input != NULL )
751 p_intf->p_sys->p_input->stream.p_selected_area->i_part = i_chapter;
752 input_ChangeArea( p_intf->p_sys->p_input,
753 p_intf->p_sys->p_input->stream.p_selected_area );
755 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
756 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
760 void Intf_VLCWrapper::toggleLanguage(int i_language)
764 int i_cat = AUDIO_ES;
766 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
767 for( int i = 0; i < p_intf->p_sys->p_input->stream.i_selected_es_number ; i++ )
769 if( p_intf->p_sys->p_input->stream.pp_selected_es[i]->i_cat == i_cat )
775 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
777 msg_Info( p_intf, "Old: %d, New: %d", i_old, i_language);
778 if( i_language != -1 )
780 input_ToggleES( p_intf->p_sys->p_input,
781 p_intf->p_sys->p_input->stream.pp_selected_es[i_language],
785 if( (i_old != -1) && (i_old != i_language) )
787 input_ToggleES( p_intf->p_sys->p_input,
788 p_intf->p_sys->p_input->stream.pp_selected_es[i_old],
793 void Intf_VLCWrapper::toggleSubtitle(int i_subtitle)
798 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
799 for( int i = 0; i < p_intf->p_sys->p_input->stream.i_selected_es_number ; i++ )
801 if( p_intf->p_sys->p_input->stream.pp_selected_es[i]->i_cat == i_cat )
807 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
809 msg_Info( p_intf, "Old: %d, New: %d", i_old, i_subtitle);
810 if( i_subtitle != -1 )
812 input_ToggleES( p_intf->p_sys->p_input,
813 p_intf->p_sys->p_input->stream.pp_selected_es[i_subtitle],
817 if( (i_old != -1) && (i_old != i_subtitle) )
819 input_ToggleES( p_intf->p_sys->p_input,
820 p_intf->p_sys->p_input->stream.pp_selected_es[i_old],
825 int Intf_VLCWrapper::inputGetStatus()