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.10 2002/10/30 06:12: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>
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 = p_intf->p_sys->p_playlist;
51 vlc_mutex_lock( &p_playlist->object_lock );
52 if( p_playlist->i_size )
54 vlc_mutex_unlock( &p_playlist->object_lock );
55 playlist_Play( p_playlist );
59 vlc_mutex_unlock( &p_playlist->object_lock );
65 void Intf_VLCWrapper::playlistPause()
68 if( p_intf->p_sys->p_input )
70 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PAUSE );
74 void Intf_VLCWrapper::playlistStop()
76 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
78 playlist_Stop( p_playlist );
81 void Intf_VLCWrapper::playlistNext()
83 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
85 playlist_Next( p_playlist );
88 void Intf_VLCWrapper::playlistPrev()
90 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
92 playlist_Prev( p_playlist );
95 void Intf_VLCWrapper::playlistSkip(int i)
97 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
99 playlist_Skip( p_playlist, i );
102 void Intf_VLCWrapper::playlistGoto(int i)
104 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
106 playlist_Goto( p_playlist, i );
109 void Intf_VLCWrapper::playlistJumpTo( int pos )
115 int size = playlistSize();
119 if( p_input_bank->pp_input[0] != NULL )
121 // stop current stream
123 // modify current position in playlist
125 p_main->p_playlist->i_index = pos;
132 int Intf_VLCWrapper::playlistCurrentPos()
135 int pos = p_intf->p_sys->p_playlist->i_index;
140 int Intf_VLCWrapper::playlistSize()
143 int size = p_intf->p_sys->p_playlist->i_size;
148 void Intf_VLCWrapper::playlistLock()
150 vlc_mutex_lock( &p_intf->p_sys->p_playlist->object_lock );
153 void Intf_VLCWrapper::playlistUnlock()
155 vlc_mutex_unlock( &p_intf->p_sys->p_playlist->object_lock );
158 void Intf_VLCWrapper::getNavCapabilities( bool* canSkipPrev,
161 if ( canSkipPrev && canSkipNext )
163 // init the parameters
164 *canSkipPrev = false;
165 *canSkipNext = false;
168 int pos = p_intf->p_sys->p_playlist->i_index;
169 int size = p_intf->p_sys->p_playlist->i_size;
172 /* input_thread_t* input = p_input_bank->pp_input[0]; */
173 input_thread_t* input = p_intf->p_sys->p_input;
174 // see if we have got a stream going
177 vlc_mutex_lock( &input->stream.stream_lock );
179 bool hasTitles = input->stream.i_area_nb > 1;
180 int numChapters = input->stream.p_selected_area->i_part_nb;
181 bool hasChapters = numChapters > 1;
182 // first, look for chapters
185 *canSkipPrev = input->stream.p_selected_area->i_part > 0;
186 *canSkipNext = input->stream.p_selected_area->i_part <
187 input->stream.p_selected_area->i_part_nb - 1;
189 // if one of the skip capabilities is false,
190 // make it depend on titles instead
191 if ( !*canSkipPrev && hasTitles )
192 *canSkipPrev = input->stream.p_selected_area->i_id > 1;
193 if ( !*canSkipNext && hasTitles )
194 *canSkipNext = input->stream.p_selected_area->i_id < input->stream.i_area_nb - 1;
196 vlc_mutex_unlock( &input->stream.stream_lock );
198 // last but not least, make capabilities depend on playlist
200 *canSkipPrev = pos > 0;
202 *canSkipNext = pos < size - 1;
206 void Intf_VLCWrapper::navigatePrev()
209 bool hasSkiped = false;
211 input_thread_t* input = p_input_bank->pp_input[0];
212 // see if we have got a stream going
215 // get information from stream (lock it while looking at it)
216 vlc_mutex_lock( &input->stream.stream_lock );
218 int currentTitle = input->stream.p_selected_area->i_id;
219 int currentChapter = input->stream.p_selected_area->i_part;
220 int numTitles = input->stream.i_area_nb;
221 bool hasTitles = numTitles > 1;
222 int numChapters = input->stream.p_selected_area->i_part_nb;
223 bool hasChapters = numChapters > 1;
225 vlc_mutex_unlock( &input->stream.stream_lock );
227 // first, look for chapters
230 // skip to the previous chapter
233 if ( currentChapter >= 0 )
235 toggleChapter( currentChapter );
239 // if we couldn't skip chapters, try titles instead
240 if ( !hasSkiped && hasTitles )
242 // skip to the previous title
244 // disallow area 0 since it is used for video_ts.vob
245 if( currentTitle > 0 )
247 toggleTitle(currentTitle);
253 // last but not least, skip to previous file
259 void Intf_VLCWrapper::navigateNext()
262 bool hasSkiped = false;
264 input_thread_t* input = p_input_bank->pp_input[0];
265 // see if we have got a stream going
268 // get information from stream (lock it while looking at it)
269 vlc_mutex_lock( &input->stream.stream_lock );
271 int currentTitle = input->stream.p_selected_area->i_id;
272 int currentChapter = input->stream.p_selected_area->i_part;
273 int numTitles = input->stream.i_area_nb;
274 bool hasTitles = numTitles > 1;
275 int numChapters = input->stream.p_selected_area->i_part_nb;
276 bool hasChapters = numChapters > 1;
278 vlc_mutex_unlock( &input->stream.stream_lock );
280 // first, look for chapters
283 // skip to the next chapter
285 if ( currentChapter < numChapters )
287 toggleChapter( currentChapter );
291 // if we couldn't skip chapters, try titles instead
292 if ( !hasSkiped && hasTitles )
294 // skip to the next title
296 // disallow area 0 since it is used for video_ts.vob
297 if ( currentTitle < numTitles - 1 )
299 toggleTitle(currentTitle);
305 // last but not least, skip to next file
312 //void Intf_VLCWrapper::channelNext()
314 // intf_thread_t * p_intf = p_main->p_intf;
316 // p_intf->p_sys->i_channel++;
318 // intf_WarnMsg( 3, "intf info: joining channel %d", p_intf->p_sys->i_channel );
320 // vlc_mutex_lock( &p_intf->change_lock );
322 // network_ChannelJoin( p_intf->p_sys->i_channel );
323 // p_intf->pf_manage( p_intf );
325 // vlc_mutex_unlock( &p_intf->change_lock );
328 //void Intf_VLCWrapper::channelPrev()
330 // intf_thread_t * p_intf = p_main->p_intf;
332 // if ( p_intf->p_sys->i_channel )
334 // 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 );
348 void Intf_VLCWrapper::loop()
350 if ( p_intf->p_sys->b_loop )
352 playlist_Delete( p_intf->p_sys->p_playlist,
353 p_intf->p_sys->p_playlist->i_size - 1 );
357 playlist_Add( p_intf->p_sys->p_playlist, "vlc:loop",
358 PLAYLIST_APPEND | PLAYLIST_GO,
361 p_intf->p_sys->b_loop = !p_intf->p_sys->b_loop;
365 /* playback control */
366 void Intf_VLCWrapper::playSlower()
368 if( p_intf->p_sys->p_input != NULL )
370 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_SLOWER );
372 if (p_intf->p_sys->p_input->stream.control.i_rate == DEFAULT_RATE)
382 void Intf_VLCWrapper::playFaster()
384 if( p_intf->p_sys->p_input != NULL )
386 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_FASTER );
388 if (p_intf->p_sys->p_input->stream.control.i_rate == DEFAULT_RATE)
398 void Intf_VLCWrapper::volume_mute()
400 if( p_intf->p_sys->p_aout != NULL )
402 if( !p_intf->p_sys->b_mute )
404 p_intf->p_sys->i_saved_volume = p_intf->p_sys->p_aout->output.i_volume;
405 p_intf->p_sys->p_aout->output.i_volume = 0;
406 p_intf->p_sys->b_mute = 1;
412 void Intf_VLCWrapper::volume_restore()
414 if( p_intf->p_sys->p_aout != NULL )
416 p_intf->p_sys->p_aout->output.i_volume = p_intf->p_sys->i_saved_volume;
417 p_intf->p_sys->i_saved_volume = 0;
418 p_intf->p_sys->b_mute = 0;
423 void Intf_VLCWrapper::set_volume(int value)
425 if( p_intf->p_sys->p_aout != NULL )
427 // make sure value is within bounds
430 if (value > AOUT_VOLUME_MAX)
431 value = AOUT_VOLUME_MAX;
432 vlc_mutex_lock( &p_intf->p_sys->p_aout->mixer_lock );
433 // unmute volume if muted
434 if ( p_intf->p_sys->b_mute )
436 p_intf->p_sys->b_mute = 0;
437 p_intf->p_sys->p_aout->output.i_volume = value;
439 vlc_mutex_unlock( &p_intf->p_sys->p_aout->mixer_lock );
443 void Intf_VLCWrapper::toggle_mute()
445 if( p_intf->p_sys->p_aout != NULL )
447 if ( p_intf->p_sys->b_mute )
458 bool Intf_VLCWrapper::is_muted()
462 if( p_intf->p_sys->p_aout != NULL )
464 vlc_mutex_lock( &p_intf->p_sys->p_aout->mixer_lock );
465 if( p_intf->p_sys->p_aout->output.i_volume > 0 )
469 vlc_mutex_unlock( &p_intf->p_sys->p_aout->mixer_lock );
470 // unfortunately, this is not reliable!
471 // return p_main->p_intf->p_sys->b_mute;
476 bool Intf_VLCWrapper::is_playing()
479 bool playing = false;
480 if ( p_intf->p_sys->p_input )
482 switch ( p_intf->p_sys->p_input->stream.control.i_status )
501 void Intf_VLCWrapper::maxvolume()
503 if( p_intf->p_sys->p_aout != NULL )
505 if( p_intf->p_sys->b_mute )
507 p_intf->p_sys->i_saved_volume = AOUT_VOLUME_MAX;
511 p_intf->p_sys->p_aout->output.i_volume = AOUT_VOLUME_MAX;
516 bool Intf_VLCWrapper::has_audio()
518 return( p_intf->p_sys->p_aout != NULL );
523 const char* Intf_VLCWrapper::getTimeAsString()
525 static char psz_currenttime[ OFFSETTOTIME_MAX_SIZE ];
527 if( p_intf->p_sys->p_input == NULL )
532 input_OffsetToTime( p_intf->p_sys->p_input,
534 p_intf->p_sys->p_input->stream.p_selected_area->i_tell );
536 return(psz_currenttime);
539 float Intf_VLCWrapper::getTimeAsFloat()
543 if( p_intf->p_sys->p_input != NULL )
545 f_time = (float)p_intf->p_sys->p_input->stream.p_selected_area->i_tell /
546 (float)p_intf->p_sys->p_input->stream.p_selected_area->i_size;
555 void Intf_VLCWrapper::setTimeAsFloat(float f_position)
557 if( p_intf->p_sys->p_input != NULL )
559 input_Seek( p_intf->p_sys->p_input,
560 (long long int)(p_intf->p_sys->p_input->stream.p_selected_area->i_size
561 * f_position / SEEKSLIDER_RANGE ),
566 /* bool Intf_VLCWrapper::playlistPlaying()
568 return( !p_intf->p_sys->p_playlist->b_stopped );
571 BList *Intf_VLCWrapper::playlistAsArray()
574 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
576 BList* p_list = new BList(p_playlist->i_size);
578 vlc_mutex_lock( &p_playlist->object_lock );
580 for( i = 0; i < p_playlist->i_size; i++ )
582 p_list->AddItem(new BString(p_playlist->pp_items[i]->psz_name));
585 vlc_mutex_unlock( &p_playlist->object_lock );
591 Intf_VLCWrapper::getPlaylistInfo( int32& currentIndex, int32& maxIndex )
595 if ( playlist_t* list = (playlist_t*)p_intf->p_sys->p_playlist )
597 maxIndex = list->i_size;
599 currentIndex = list->i_index + 1;
607 Intf_VLCWrapper::getTitleInfo( int32& currentIndex, int32& maxIndex )
611 if ( input_thread_t* input = p_intf->p_sys->p_input )
613 vlc_mutex_lock( &input->stream.stream_lock );
615 maxIndex = input->stream.i_area_nb - 1;
617 currentIndex = input->stream.p_selected_area->i_id;
621 vlc_mutex_unlock( &input->stream.stream_lock );
627 Intf_VLCWrapper::getChapterInfo( int32& currentIndex, int32& maxIndex )
631 if ( input_thread_t* input = p_intf->p_sys->p_input )
633 vlc_mutex_lock( &input->stream.stream_lock );
635 maxIndex = input->stream.p_selected_area->i_part_nb - 1;
637 currentIndex = input->stream.p_selected_area->i_part;
641 vlc_mutex_unlock( &input->stream.stream_lock );
645 /* open file/disc/network */
646 void Intf_VLCWrapper::openFiles( BList* o_files, bool replace )
649 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
651 while( ( o_file = (BString *)o_files->LastItem() ) )
653 o_files->RemoveItem(o_files->CountItems() - 1);
654 playlist_Add( p_playlist, o_file->String(),
655 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
660 void Intf_VLCWrapper::openDisc(BString o_type, BString o_device, int i_title, int i_chapter)
662 BString o_source("");
663 o_source << o_type << ":" << o_device ;
665 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
666 playlist_Add( p_playlist, o_source.String(),
667 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
670 void Intf_VLCWrapper::openNet(BString o_addr, int i_port)
674 void Intf_VLCWrapper::openNetChannel(BString o_addr, int i_port)
678 void Intf_VLCWrapper::openNetHTTP(BString o_addr)
683 /* menus management */
684 void Intf_VLCWrapper::toggleProgram(int i_program){}
686 void Intf_VLCWrapper::toggleTitle(int i_title)
688 if( p_intf->p_sys->p_input != NULL )
690 input_ChangeArea( p_intf->p_sys->p_input,
691 p_intf->p_sys->p_input->stream.pp_areas[i_title] );
693 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
695 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
699 void Intf_VLCWrapper::toggleChapter(int i_chapter)
701 if( p_intf->p_sys->p_input != NULL )
703 p_intf->p_sys->p_input->stream.p_selected_area->i_part = i_chapter;
704 input_ChangeArea( p_intf->p_sys->p_input,
705 p_intf->p_sys->p_input->stream.p_selected_area );
707 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
708 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
712 void Intf_VLCWrapper::toggleLanguage(int i_language)
716 int i_cat = AUDIO_ES;
718 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
719 for( int i = 0; i < p_intf->p_sys->p_input->stream.i_selected_es_number ; i++ )
721 if( p_intf->p_sys->p_input->stream.pp_selected_es[i]->i_cat == i_cat )
727 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
729 msg_Info( p_intf, "Old: %d, New: %d", i_old, i_language);
730 if( i_language != -1 )
732 input_ToggleES( p_intf->p_sys->p_input,
733 p_intf->p_sys->p_input->stream.pp_selected_es[i_language],
737 if( (i_old != -1) && (i_old != i_language) )
739 input_ToggleES( p_intf->p_sys->p_input,
740 p_intf->p_sys->p_input->stream.pp_selected_es[i_old],
745 void Intf_VLCWrapper::toggleSubtitle(int i_subtitle)
750 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
751 for( int i = 0; i < p_intf->p_sys->p_input->stream.i_selected_es_number ; i++ )
753 if( p_intf->p_sys->p_input->stream.pp_selected_es[i]->i_cat == i_cat )
759 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
761 msg_Info( p_intf, "Old: %d, New: %d", i_old, i_subtitle);
762 if( i_subtitle != -1 )
764 input_ToggleES( p_intf->p_sys->p_input,
765 p_intf->p_sys->p_input->stream.pp_selected_es[i_subtitle],
769 if( (i_old != -1) && (i_old != i_subtitle) )
771 input_ToggleES( p_intf->p_sys->p_input,
772 p_intf->p_sys->p_input->stream.pp_selected_es[i_old],
777 int Intf_VLCWrapper::inputGetStatus()
779 return p_intf->p_sys->p_playlist->i_status;