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.6 2002/10/14 20:09:17 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>
31 #include <audio_output.h>
32 #include <aout_internal.h>
34 #include "VlcWrapper.h"
36 Intf_VLCWrapper *Intf_VLCWrapper::getVLCWrapper(intf_thread_t *p_interface)
38 static Intf_VLCWrapper *one_wrapper;
39 if (one_wrapper == NULL )
41 one_wrapper = new Intf_VLCWrapper(p_interface);
46 Intf_VLCWrapper::Intf_VLCWrapper(intf_thread_t *p_interface)
51 Intf_VLCWrapper::~Intf_VLCWrapper()
56 bool Intf_VLCWrapper::manage()
58 /* p_main->p_intf->pf_manage( p_intf ); */
66 if ( p_intf->p_sys->p_input != NULL )
68 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
69 if( !p_intf->p_sys->p_input->b_die )
71 /* New input or stream map change */
72 if( p_intf->p_sys->p_input->stream.b_changed ||
73 p_intf->p_sys->i_part !=
74 p_intf->p_sys->p_input->stream.p_selected_area->i_part )
77 p_intf->p_sys->b_disabled_menus = 0;
80 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
82 else if ( !p_intf->p_sys->b_disabled_menus )
85 p_intf->p_sys->b_disabled_menus = 1;
91 void Intf_VLCWrapper::quit()
96 /* playlist control */
97 bool Intf_VLCWrapper::playlistPlay()
99 playlist_t *p_playlist =
100 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
103 vlc_mutex_lock( &p_playlist->object_lock );
104 if( p_playlist->i_size )
106 vlc_mutex_unlock( &p_playlist->object_lock );
107 playlist_Play( p_playlist );
108 vlc_object_release( p_playlist );
112 vlc_mutex_unlock( &p_playlist->object_lock );
113 vlc_object_release( p_playlist );
119 void Intf_VLCWrapper::playlistPause()
122 playlist_t *p_playlist =
123 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
125 playlist_Pause( p_playlist );
126 vlc_object_release( p_playlist );
129 void Intf_VLCWrapper::playlistStop()
131 playlist_t *p_playlist =
132 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
135 playlist_Stop( p_playlist );
136 vlc_object_release( p_playlist );
139 void Intf_VLCWrapper::playlistNext()
141 playlist_t *p_playlist =
142 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
145 playlist_Next( p_playlist );
146 vlc_object_release( p_playlist );
149 void Intf_VLCWrapper::playlistPrev()
151 playlist_t *p_playlist =
152 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
155 playlist_Prev( p_playlist );
156 vlc_object_release( p_playlist );
159 void Intf_VLCWrapper::playlistSkip(int i)
161 playlist_t *p_playlist =
162 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
165 playlist_Skip( p_playlist, i );
166 vlc_object_release( p_playlist );
169 void Intf_VLCWrapper::playlistGoto(int i)
171 playlist_t *p_playlist =
172 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
175 playlist_Goto( p_playlist, i );
176 vlc_object_release( p_playlist );
179 void Intf_VLCWrapper::playlistJumpTo( int pos )
185 int size = playlistSize();
189 if( p_input_bank->pp_input[0] != NULL )
191 // stop current stream
193 // modify current position in playlist
195 p_main->p_playlist->i_index = pos;
202 int Intf_VLCWrapper::playlistCurrentPos()
205 int pos = p_intf->p_sys->p_playlist->i_index;
210 int Intf_VLCWrapper::playlistSize()
213 int size = p_intf->p_sys->p_playlist->i_size;
218 void Intf_VLCWrapper::playlistLock()
220 vlc_mutex_lock( &p_intf->p_sys->p_playlist->object_lock );
223 void Intf_VLCWrapper::playlistUnlock()
225 vlc_mutex_unlock( &p_intf->p_sys->p_playlist->object_lock );
228 void Intf_VLCWrapper::getNavCapabilities( bool* canSkipPrev,
231 if ( canSkipPrev && canSkipNext )
233 // init the parameters
234 *canSkipPrev = false;
235 *canSkipNext = false;
238 int pos = p_intf->p_sys->p_playlist->i_index;
239 int size = p_intf->p_sys->p_playlist->i_size;
242 /* input_thread_t* input = p_input_bank->pp_input[0]; */
243 input_thread_t* input = p_intf->p_sys->p_input;
244 // see if we have got a stream going
247 vlc_mutex_lock( &input->stream.stream_lock );
249 bool hasTitles = input->stream.i_area_nb > 1;
250 int numChapters = input->stream.p_selected_area->i_part_nb;
251 bool hasChapters = numChapters > 1;
252 // first, look for chapters
255 *canSkipPrev = input->stream.p_selected_area->i_part > 0;
256 *canSkipNext = input->stream.p_selected_area->i_part <
257 input->stream.p_selected_area->i_part_nb - 1;
259 // if one of the skip capabilities is false,
260 // make it depend on titles instead
261 if ( !*canSkipPrev && hasTitles )
262 *canSkipPrev = input->stream.p_selected_area->i_id > 1;
263 if ( !*canSkipNext && hasTitles )
264 *canSkipNext = input->stream.p_selected_area->i_id < input->stream.i_area_nb - 1;
266 vlc_mutex_unlock( &input->stream.stream_lock );
268 // last but not least, make capabilities depend on playlist
270 *canSkipPrev = pos > 0;
272 *canSkipNext = pos < size - 1;
276 void Intf_VLCWrapper::navigatePrev()
279 bool hasSkiped = false;
281 input_thread_t* input = p_input_bank->pp_input[0];
282 // see if we have got a stream going
285 // get information from stream (lock it while looking at it)
286 vlc_mutex_lock( &input->stream.stream_lock );
288 int currentTitle = input->stream.p_selected_area->i_id;
289 int currentChapter = input->stream.p_selected_area->i_part;
290 int numTitles = input->stream.i_area_nb;
291 bool hasTitles = numTitles > 1;
292 int numChapters = input->stream.p_selected_area->i_part_nb;
293 bool hasChapters = numChapters > 1;
295 vlc_mutex_unlock( &input->stream.stream_lock );
297 // first, look for chapters
300 // skip to the previous chapter
303 if ( currentChapter >= 0 )
305 toggleChapter( currentChapter );
309 // if we couldn't skip chapters, try titles instead
310 if ( !hasSkiped && hasTitles )
312 // skip to the previous title
314 // disallow area 0 since it is used for video_ts.vob
315 if( currentTitle > 0 )
317 toggleTitle(currentTitle);
323 // last but not least, skip to previous file
329 void Intf_VLCWrapper::navigateNext()
332 bool hasSkiped = false;
334 input_thread_t* input = p_input_bank->pp_input[0];
335 // see if we have got a stream going
338 // get information from stream (lock it while looking at it)
339 vlc_mutex_lock( &input->stream.stream_lock );
341 int currentTitle = input->stream.p_selected_area->i_id;
342 int currentChapter = input->stream.p_selected_area->i_part;
343 int numTitles = input->stream.i_area_nb;
344 bool hasTitles = numTitles > 1;
345 int numChapters = input->stream.p_selected_area->i_part_nb;
346 bool hasChapters = numChapters > 1;
348 vlc_mutex_unlock( &input->stream.stream_lock );
350 // first, look for chapters
353 // skip to the next chapter
355 if ( currentChapter < numChapters )
357 toggleChapter( currentChapter );
361 // if we couldn't skip chapters, try titles instead
362 if ( !hasSkiped && hasTitles )
364 // skip to the next title
366 // disallow area 0 since it is used for video_ts.vob
367 if ( currentTitle < numTitles - 1 )
369 toggleTitle(currentTitle);
375 // last but not least, skip to next file
382 //void Intf_VLCWrapper::channelNext()
384 // intf_thread_t * p_intf = p_main->p_intf;
386 // p_intf->p_sys->i_channel++;
388 // intf_WarnMsg( 3, "intf info: joining channel %d", p_intf->p_sys->i_channel );
390 // vlc_mutex_lock( &p_intf->change_lock );
392 // network_ChannelJoin( p_intf->p_sys->i_channel );
393 // p_intf->pf_manage( p_intf );
395 // vlc_mutex_unlock( &p_intf->change_lock );
398 //void Intf_VLCWrapper::channelPrev()
400 // intf_thread_t * p_intf = p_main->p_intf;
402 // if ( p_intf->p_sys->i_channel )
404 // p_intf->p_sys->i_channel--;
407 // intf_WarnMsg( 3, "intf info: joining channel %d", p_intf->p_sys->i_channel );
409 // vlc_mutex_lock( &p_intf->change_lock );
411 // network_ChannelJoin( p_intf->p_sys->i_channel );
412 // p_intf->pf_manage( p_intf );
414 // vlc_mutex_unlock( &p_intf->change_lock );
418 void Intf_VLCWrapper::loop()
420 if ( p_intf->p_sys->b_loop )
422 playlist_Delete( p_intf->p_sys->p_playlist,
423 p_intf->p_sys->p_playlist->i_size - 1 );
427 playlist_Add( p_intf->p_sys->p_playlist, "vlc:loop",
428 PLAYLIST_APPEND | PLAYLIST_GO,
431 p_intf->p_sys->b_loop = !p_intf->p_sys->b_loop;
435 /* playback control */
436 void Intf_VLCWrapper::playSlower()
438 if( p_intf->p_sys->p_input != NULL )
440 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_SLOWER );
442 if (p_intf->p_sys->p_input->stream.control.i_rate == DEFAULT_RATE)
452 void Intf_VLCWrapper::playFaster()
454 if( p_intf->p_sys->p_input != NULL )
456 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_FASTER );
458 if (p_intf->p_sys->p_input->stream.control.i_rate == DEFAULT_RATE)
468 void Intf_VLCWrapper::volume_mute()
470 p_intf->p_sys->p_aout =
471 (aout_instance_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
473 if( p_intf->p_sys->p_aout != NULL )
475 if( !p_intf->p_sys->b_mute )
477 p_intf->p_sys->i_saved_volume = p_intf->p_sys->p_aout->output.i_volume;
478 p_intf->p_sys->p_aout->output.i_volume = 0;
479 p_intf->p_sys->b_mute = 1;
485 void Intf_VLCWrapper::volume_restore()
487 p_intf->p_sys->p_aout =
488 (aout_instance_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
490 if( p_intf->p_sys->p_aout != NULL )
492 p_intf->p_sys->p_aout->output.i_volume = p_intf->p_sys->i_saved_volume;
493 p_intf->p_sys->i_saved_volume = 0;
494 p_intf->p_sys->b_mute = 0;
499 void Intf_VLCWrapper::set_volume(int value)
501 p_intf->p_sys->p_aout =
502 (aout_instance_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
504 if( p_intf->p_sys->p_aout != NULL )
506 // make sure value is within bounds
509 if (value > AOUT_VOLUME_MAX)
510 value = AOUT_VOLUME_MAX;
511 vlc_mutex_lock( &p_intf->p_sys->p_aout->mixer_lock );
512 // unmute volume if muted
513 if ( p_intf->p_sys->b_mute )
515 p_intf->p_sys->b_mute = 0;
516 p_intf->p_sys->p_aout->output.i_volume = value;
518 vlc_mutex_unlock( &p_intf->p_sys->p_aout->mixer_lock );
522 void Intf_VLCWrapper::toggle_mute()
524 p_intf->p_sys->p_aout =
525 (aout_instance_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
527 if( p_intf->p_sys->p_aout != NULL )
529 if ( p_intf->p_sys->b_mute )
540 bool Intf_VLCWrapper::is_muted()
544 p_intf->p_sys->p_aout =
545 (aout_instance_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
547 if( p_intf->p_sys->p_aout != NULL )
549 vlc_mutex_lock( &p_intf->p_sys->p_aout->mixer_lock );
550 if( p_intf->p_sys->p_aout->output.i_volume > 0 )
554 vlc_mutex_unlock( &p_intf->p_sys->p_aout->mixer_lock );
555 // unfortunately, this is not reliable!
556 // return p_main->p_intf->p_sys->b_mute;
561 bool Intf_VLCWrapper::is_playing()
564 bool playing = false;
565 if ( p_intf->p_sys->p_input )
567 switch ( p_intf->p_sys->p_input->stream.control.i_status )
586 void Intf_VLCWrapper::maxvolume()
588 p_intf->p_sys->p_aout =
589 (aout_instance_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
591 if( p_intf->p_sys->p_aout != NULL )
593 if( p_intf->p_sys->b_mute )
595 p_intf->p_sys->i_saved_volume = AOUT_VOLUME_MAX;
599 p_intf->p_sys->p_aout->output.i_volume = AOUT_VOLUME_MAX;
604 bool Intf_VLCWrapper::has_audio()
606 p_intf->p_sys->p_aout =
607 (aout_instance_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
609 return( p_intf->p_sys->p_aout != NULL );
612 //void Intf_VLCWrapper::fullscreen()
614 // if( p_vout_bank->pp_vout[0] != NULL )
616 // p_vout_bank->pp_vout[0]->i_changes |= VOUT_FULLSCREEN_CHANGE;
620 void Intf_VLCWrapper::eject(){}
624 BString* Intf_VLCWrapper::getTimeAsString()
626 static char psz_currenttime[ OFFSETTOTIME_MAX_SIZE ];
628 if( p_intf->p_sys->p_input == NULL )
630 return (new BString("00:00:00"));
633 input_OffsetToTime( p_intf->p_sys->p_input,
635 p_intf->p_sys->p_input->stream.p_selected_area->i_tell );
637 return(new BString(psz_currenttime));
640 float Intf_VLCWrapper::getTimeAsFloat()
644 if( p_intf->p_sys->p_input != NULL )
646 f_time = (float)p_intf->p_sys->p_input->stream.p_selected_area->i_tell /
647 (float)p_intf->p_sys->p_input->stream.p_selected_area->i_size;
656 void Intf_VLCWrapper::setTimeAsFloat(float f_position)
658 if( p_intf->p_sys->p_input != NULL )
660 input_Seek( p_intf->p_sys->p_input,
661 (long long int)(p_intf->p_sys->p_input->stream.p_selected_area->i_size
662 * f_position / SEEKSLIDER_RANGE ),
667 /* bool Intf_VLCWrapper::playlistPlaying()
669 return( !p_intf->p_sys->p_playlist->b_stopped );
672 BList *Intf_VLCWrapper::playlistAsArray()
675 playlist_t *p_playlist =
676 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
679 BList* p_list = new BList(p_playlist->i_size);
681 vlc_mutex_lock( &p_playlist->object_lock );
683 for( i = 0; i < p_playlist->i_size; i++ )
685 p_list->AddItem(new BString(p_playlist->pp_items[i]->psz_name));
688 vlc_mutex_unlock( &p_playlist->object_lock );
689 vlc_object_release( p_playlist );
693 /* open file/disc/network */
694 void Intf_VLCWrapper::openFiles( BList* o_files, bool replace )
697 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
699 while( ( o_file = (BString *)o_files->LastItem() ) )
701 o_files->RemoveItem(o_files->CountItems() - 1);
702 playlist_Add( p_playlist, o_file->String(),
703 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
707 vlc_object_release( p_playlist );
710 void Intf_VLCWrapper::openDisc(BString o_type, BString o_device, int i_title, int i_chapter)
712 BString o_source("");
713 o_source << o_type << ":" << o_device ;
715 playlist_t *p_playlist =
716 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
718 playlist_Add( p_playlist, o_source.String(),
719 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
720 vlc_object_release( p_playlist );
723 void Intf_VLCWrapper::openNet(BString o_addr, int i_port)
727 void Intf_VLCWrapper::openNetChannel(BString o_addr, int i_port)
731 void Intf_VLCWrapper::openNetHTTP(BString o_addr)
736 /* menus management */
737 void Intf_VLCWrapper::toggleProgram(int i_program){}
739 void Intf_VLCWrapper::toggleTitle(int i_title)
741 if( p_intf->p_sys->p_input != NULL )
743 input_ChangeArea( p_intf->p_sys->p_input,
744 p_intf->p_sys->p_input->stream.pp_areas[i_title] );
746 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
749 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
753 void Intf_VLCWrapper::toggleChapter(int i_chapter)
755 if( p_intf->p_sys->p_input != NULL )
757 p_intf->p_sys->p_input->stream.p_selected_area->i_part = i_chapter;
758 input_ChangeArea( p_intf->p_sys->p_input,
759 p_intf->p_sys->p_input->stream.p_selected_area );
761 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
763 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
767 void Intf_VLCWrapper::toggleLanguage(int i_language)
771 int i_cat = AUDIO_ES;
773 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
774 for( int i = 0; i < p_intf->p_sys->p_input->stream.i_selected_es_number ; i++ )
776 if( p_intf->p_sys->p_input->stream.pp_selected_es[i]->i_cat == i_cat )
782 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
784 msg_Info( p_intf, "Old: %d, New: %d", i_old, i_language);
785 if( i_language != -1 )
787 input_ToggleES( p_intf->p_sys->p_input,
788 p_intf->p_sys->p_input->stream.pp_selected_es[i_language],
792 if( (i_old != -1) && (i_old != i_language) )
794 input_ToggleES( p_intf->p_sys->p_input,
795 p_intf->p_sys->p_input->stream.pp_selected_es[i_old],
800 void Intf_VLCWrapper::toggleSubtitle(int i_subtitle)
805 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
806 for( int i = 0; i < p_intf->p_sys->p_input->stream.i_selected_es_number ; i++ )
808 if( p_intf->p_sys->p_input->stream.pp_selected_es[i]->i_cat == i_cat )
814 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
816 msg_Info( p_intf, "Old: %d, New: %d", i_old, i_subtitle);
817 if( i_subtitle != -1 )
819 input_ToggleES( p_intf->p_sys->p_input,
820 p_intf->p_sys->p_input->stream.pp_selected_es[i_subtitle],
824 if( (i_old != -1) && (i_old != i_subtitle) )
826 input_ToggleES( p_intf->p_sys->p_input,
827 p_intf->p_sys->p_input->stream.pp_selected_es[i_old],
833 void Intf_VLCWrapper::setupMenus(){}
834 int Intf_VLCWrapper::inputGetStatus() {}