Changes to ensure BeOS plugins compile and function
[vlc.git] / plugins / beos / intf_vlc_wrapper.cpp
1 /*****************************************************************************
2  * intf_vlc_wrapper.h: BeOS plugin for vlc (derived from MacOS X port )
3  *****************************************************************************
4  * Copyright (C) 2001 VideoLAN
5  * $Id: intf_vlc_wrapper.cpp,v 1.2 2002/07/23 12:42:17 tcastley Exp $
6  *
7  * Authors: Florian G. Pflug <fgp@phlo.org>
8  *          Jon Lech Johansen <jon-vl@nanocrew.net>
9  *          Tony Casltey <tony@castley.net>
10  *
11  * This program is free software{} you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation{} either version 2 of the License, or
14  * (at your option) any later version.
15  * 
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY{} without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program{} if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
24  *****************************************************************************/
25 /* VLC headers */
26 #include <SupportKit.h>
27
28 #include <vlc/vlc.h>
29 #include <vlc/intf.h>
30
31 #include "intf_vlc_wrapper.h"
32
33 Intf_VLCWrapper *Intf_VLCWrapper::getVLCWrapper(intf_thread_t *p_if)
34 {
35     static Intf_VLCWrapper *one_wrapper;
36     if (one_wrapper == NULL )
37     {
38        one_wrapper = new Intf_VLCWrapper(p_if);
39     }
40     return one_wrapper;
41 }
42
43 Intf_VLCWrapper::Intf_VLCWrapper(intf_thread_t *p_if)
44 {
45     p_intf = p_if;
46 }
47
48 Intf_VLCWrapper::~Intf_VLCWrapper()
49 {
50 }
51
52 //bool Intf_VLCWrapper::manage()
53 //{
54 //
55 //   p_intf->pf_manage( p_intf );
56 //   
57 //   if ( p_intf->b_die )
58 //   {
59 //       // exit the lot
60 //       return( 1 );
61 //   }
62     /* Update the input */
63 //    if( p_intf->p_sys->p_input != NULL )
64 //    {
65 //        if( p_intf->p_sys->p_input->b_dead )
66 //        {
67 //            vlc_object_release( p_intf->p_sys->p_input );
68 //            p_intf->p_sys->p_input = NULL;
69 //        }
70 //    }
71 //   
72 //    p_intf->p_sys->p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
73 //                                                      FIND_ANYWHERE );
74
75 //   if ( p_intf->p_sys->p_input != NULL )
76 //   {
77 //       vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
78 //        if( !p_intf->p_sys->p_input->b_die )
79 //        {
80 //            /* New input or stream map change */
81 //            if( p_intf->p_sys->p_input->stream.b_changed ||
82 //                p_intf->p_sys->i_part !=
83 //                p_intf->p_sys->p_input->stream.p_selected_area->i_part )
84 //            {
85 //                setupMenus();
86 //                p_intf->p_sys->b_disabled_menus = 0;
87 //            }
88 //        }
89 //        vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
90 //    }
91 //    else if ( !p_intf->p_sys->b_disabled_menus )
92 //    {
93 //        setupMenus();
94 //        p_intf->p_sys->b_disabled_menus = 1;
95 //    }
96 //    return( 0 );
97 //}
98
99 void Intf_VLCWrapper::quit()
100 {
101     p_intf->b_die = 1;
102 }
103     
104 /* playlist control */
105
106 int Intf_VLCWrapper::inputGetStatus()
107 {
108     if( p_intf->p_sys->p_input != NULL )
109     {
110         return( p_intf->p_sys->p_input->stream.control.i_status );
111     }
112     else
113     {
114         return( UNDEF_S );
115     }
116 }
117
118 bool Intf_VLCWrapper::playlistPlay()
119 {
120     playlist_t *p_playlist = 
121                 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
122                                                        FIND_ANYWHERE );
123
124     vlc_mutex_lock( &p_playlist->object_lock );
125     if( p_playlist->i_size )
126     {
127         vlc_mutex_unlock( &p_playlist->object_lock );
128         playlist_Play( p_playlist );
129         vlc_object_release( p_playlist );
130     }
131     else
132     {
133         vlc_mutex_unlock( &p_playlist->object_lock );
134         vlc_object_release( p_playlist );
135     }
136
137     return( true );
138     
139 }
140
141 void Intf_VLCWrapper::playlistPause()
142 {
143     volumeMute( true );
144     playlist_t *p_playlist = 
145                 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
146                                                        FIND_ANYWHERE );
147     playlist_Pause( p_playlist );
148     vlc_object_release( p_playlist );
149 }
150
151 void Intf_VLCWrapper::playlistStop()
152 {
153     playlist_t *p_playlist = 
154                 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
155                                                        FIND_ANYWHERE );
156
157     playlist_Stop( p_playlist );
158     vlc_object_release( p_playlist );
159
160 }
161
162 void Intf_VLCWrapper::playlistNext()
163 {
164     playlist_t *p_playlist = 
165                 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
166                                                        FIND_ANYWHERE );
167
168     playlist_Next( p_playlist );
169     vlc_object_release( p_playlist );
170 }
171
172 void Intf_VLCWrapper::playlistPrev()
173 {
174     playlist_t *p_playlist = 
175                 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
176                                                        FIND_ANYWHERE );
177
178     playlist_Prev( p_playlist );
179     vlc_object_release( p_playlist );
180 }
181
182 void Intf_VLCWrapper::playlistSkip(int i)
183 {
184     playlist_t *p_playlist = 
185                 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
186                                                        FIND_ANYWHERE );
187
188     playlist_Skip( p_playlist, i );
189     vlc_object_release( p_playlist );
190 }
191
192 void Intf_VLCWrapper::playlistGoto(int i)
193 {
194     playlist_t *p_playlist = 
195                 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
196                                                        FIND_ANYWHERE );
197
198     playlist_Goto( p_playlist, i );
199     vlc_object_release( p_playlist );
200 }
201
202     /* playback control */
203 void Intf_VLCWrapper::playSlower()
204 {
205     if( p_intf->p_sys->p_input != NULL )
206     {
207         input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_SLOWER );
208     }
209     if (p_intf->p_sys->p_input->stream.control.i_rate == DEFAULT_RATE)
210     {
211         volumeMute( false );
212     }
213     else
214     {
215         volumeMute (true );
216     }
217 }
218
219 void Intf_VLCWrapper::playFaster()
220 {
221     if( p_intf->p_sys->p_input != NULL )
222     {
223         input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_FASTER );
224     }
225     if (p_intf->p_sys->p_input->stream.control.i_rate == DEFAULT_RATE)
226     {
227         volumeMute( false );
228     }
229     else
230     {
231         volumeMute (true );
232     }
233 }
234
235 void Intf_VLCWrapper::toggleProgram(int i_program){}
236
237 void Intf_VLCWrapper::toggleTitle(int i_title)
238 {
239     if( p_intf->p_sys->p_input != NULL )
240     {
241         input_ChangeArea( p_intf->p_sys->p_input,
242                           p_intf->p_sys->p_input->stream.pp_areas[i_title] );
243
244         vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
245         //setupMenus();
246
247         vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
248     }
249 }
250
251 void Intf_VLCWrapper::toggleChapter(int i_chapter)
252 {
253     if( p_intf->p_sys->p_input != NULL )
254     {
255         p_intf->p_sys->p_input->stream.p_selected_area->i_part = i_chapter;
256         input_ChangeArea( p_intf->p_sys->p_input,
257                           p_intf->p_sys->p_input->stream.p_selected_area );
258
259         vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
260 //        setupMenus();
261         vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
262     }
263 }
264
265 void Intf_VLCWrapper::toggleLanguage(int i_language)
266 {
267
268     int32 i_old = -1;
269     int i_cat = AUDIO_ES;
270
271     vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
272     for( int i = 0; i < p_intf->p_sys->p_input->stream.i_selected_es_number ; i++ )
273     {
274         if( p_intf->p_sys->p_input->stream.pp_selected_es[i]->i_cat == i_cat )
275         {
276             i_old = i;
277             break;
278         }
279     }
280     vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
281
282     if( i_language != -1 )
283     {
284         input_ToggleES( p_intf->p_sys->p_input, 
285                         p_intf->p_sys->p_input->stream.pp_selected_es[i_language],
286                         VLC_TRUE );
287     }
288
289     if( i_old != -1 )
290     {
291         input_ToggleES( p_intf->p_sys->p_input, 
292                         p_intf->p_sys->p_input->stream.pp_selected_es[i_old],
293                         VLC_FALSE );
294     }
295 }
296
297 void Intf_VLCWrapper::toggleSubtitle(int i_subtitle)
298 {
299     int32 i_old = -1;
300     int i_cat = SPU_ES;
301
302     vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
303     for( int i = 0; i < p_intf->p_sys->p_input->stream.i_selected_es_number ; i++ )
304     {
305         if( p_intf->p_sys->p_input->stream.pp_selected_es[i]->i_cat == i_cat )
306         {
307             i_old = i;
308             break;
309         }
310     }
311     vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
312
313     if( i_subtitle != -1 )
314     {
315         input_ToggleES( p_intf->p_sys->p_input, 
316                         p_intf->p_sys->p_input->stream.pp_selected_es[i_subtitle],
317                         VLC_TRUE );
318     }
319
320     if( i_old != -1 )
321     {
322         input_ToggleES( p_intf->p_sys->p_input, 
323                         p_intf->p_sys->p_input->stream.pp_selected_es[i_old],
324                         VLC_FALSE );
325     }
326 }
327
328
329 void Intf_VLCWrapper::channelNext()
330 {
331 }
332
333 void Intf_VLCWrapper::channelPrev()
334 {
335 }
336
337 void Intf_VLCWrapper::eject(){}
338
339
340
341 /* playback info */
342
343 BString*  Intf_VLCWrapper::getTimeAsString()
344 {
345     static char psz_currenttime[ OFFSETTOTIME_MAX_SIZE ];
346         
347     if( p_intf->p_sys->p_input == NULL )
348     {
349         return (new BString("00:00:00"));
350     }     
351    
352     input_OffsetToTime( p_intf->p_sys->p_input, 
353                         psz_currenttime, 
354                         p_intf->p_sys->p_input->stream.p_selected_area->i_tell );        
355
356     return(new BString(psz_currenttime));
357 }
358
359 float  Intf_VLCWrapper::getTimeAsFloat()
360 {
361     float f_time = 0.0;
362
363     if( p_intf->p_sys->p_input != NULL )
364     {
365         f_time = (float)p_intf->p_sys->p_input->stream.p_selected_area->i_tell / 
366                  (float)p_intf->p_sys->p_input->stream.p_selected_area->i_size;
367     }    
368     else
369     {
370         f_time = 0.0;
371     }
372     return( f_time );
373 }
374
375 void   Intf_VLCWrapper::setTimeAsFloat(float f_position)
376 {
377     if( p_intf->p_sys->p_input != NULL )
378     {
379         input_Seek( p_intf->p_sys->p_input, 
380                    (long long int)(p_intf->p_sys->p_input->stream.p_selected_area->i_size * f_position / 100), 
381                    INPUT_SEEK_SET);
382     }
383 }
384
385 BList  *Intf_VLCWrapper::playlistAsArray()
386
387     int i;
388     playlist_t *p_playlist = 
389                 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
390                                                        FIND_ANYWHERE );
391
392     BList* p_list = new BList(p_playlist->i_size);
393     
394     vlc_mutex_lock( &p_playlist->object_lock );
395
396     for( i = 0; i < p_playlist->i_size; i++ )
397     {
398         p_list->AddItem(new BString(p_playlist->pp_items[i]->psz_name));
399     }
400
401     vlc_mutex_unlock( &p_playlist->object_lock );
402     vlc_object_release( p_playlist );
403     return( p_list );
404 }
405
406     /* open file/disc/network */
407 void Intf_VLCWrapper::openFiles(BList *o_files)
408 {
409     BString *o_file;
410     playlist_t *p_playlist = 
411                (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
412                                                       FIND_ANYWHERE );
413
414     while( ( o_file = (BString *)o_files->LastItem() ) )
415     {
416         o_files->RemoveItem(o_files->CountItems() - 1);
417         playlist_Add( p_playlist, o_file->String(),
418                   PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
419         delete o_file;
420     }
421
422     vlc_object_release( p_playlist );
423
424 }
425
426 void Intf_VLCWrapper::openDisc(BString o_type, BString o_device, int i_title, int i_chapter)
427 {
428     BString o_source("");
429     o_source << o_type << ":" << o_device ;
430
431     playlist_t *p_playlist = 
432                (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
433                                                       FIND_ANYWHERE );
434     playlist_Add( p_playlist, o_source.String(),
435                   PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
436     vlc_object_release( p_playlist );
437 }
438
439 void Intf_VLCWrapper::openNet(BString o_addr, int i_port)
440 {
441 }
442
443 void Intf_VLCWrapper::openNetChannel(BString o_addr, int i_port)
444 {
445 }
446
447 void Intf_VLCWrapper::openNetHTTP(BString o_addr)
448 {
449 }
450
451 void Intf_VLCWrapper::volumeMute( bool mute )
452 {
453     if ( mute )
454     {
455     }
456     else
457     {
458     }
459 }
460
461 /* menus management */
462