]> git.sesse.net Git - vlc/blob - modules/gui/beos/VlcWrapper.cpp
* ./modules/audio_output/oss.c: compilation fixes.
[vlc] / modules / gui / beos / VlcWrapper.cpp
1 /*****************************************************************************
2  * vlc_wrapper.h: BeOS plugin for vlc (derived from MacOS X port )
3  *****************************************************************************
4  * Copyright (C) 2001 VideoLAN
5  * $Id: VlcWrapper.cpp,v 1.2 2002/08/06 10:54:34 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 "VlcWrapper.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     toggleMute(  );
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         toggleMute(  );
212     }
213     else
214     {
215         toggleMute ( );
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         toggleMute(  );
228     }
229     else
230     {
231         toggleMute ( );
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     msg_Info( p_intf, "Old: %d,  New: %d", i_old, i_language);
283     if( i_language != -1 )
284     {
285         input_ToggleES( p_intf->p_sys->p_input, 
286                         p_intf->p_sys->p_input->stream.pp_selected_es[i_language],
287                         VLC_TRUE );
288     }
289
290     if( (i_old != -1) && (i_old != i_language) )
291     {
292         input_ToggleES( p_intf->p_sys->p_input, 
293                         p_intf->p_sys->p_input->stream.pp_selected_es[i_old],
294                         VLC_FALSE );
295     }
296 }
297
298 void Intf_VLCWrapper::toggleSubtitle(int i_subtitle)
299 {
300     int32 i_old = -1;
301     int i_cat = SPU_ES;
302
303     vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
304     for( int i = 0; i < p_intf->p_sys->p_input->stream.i_selected_es_number ; i++ )
305     {
306         if( p_intf->p_sys->p_input->stream.pp_selected_es[i]->i_cat == i_cat )
307         {
308             i_old = i;
309             break;
310         }
311     }
312     vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
313     
314     msg_Info( p_intf, "Old: %d,  New: %d", i_old, i_subtitle);
315     if( i_subtitle != -1 )
316     {
317         input_ToggleES( p_intf->p_sys->p_input, 
318                         p_intf->p_sys->p_input->stream.pp_selected_es[i_subtitle],
319                         VLC_TRUE );
320     }
321
322     if( (i_old != -1) && (i_old != i_subtitle) )
323     {
324         input_ToggleES( p_intf->p_sys->p_input, 
325                         p_intf->p_sys->p_input->stream.pp_selected_es[i_old],
326                         VLC_FALSE );
327     }
328 }
329
330
331 void Intf_VLCWrapper::channelNext()
332 {
333 }
334
335 void Intf_VLCWrapper::channelPrev()
336 {
337 }
338
339 void Intf_VLCWrapper::eject(){}
340
341
342
343 /* playback info */
344
345 BString*  Intf_VLCWrapper::getTimeAsString()
346 {
347     static char psz_currenttime[ OFFSETTOTIME_MAX_SIZE ];
348         
349     if( p_intf->p_sys->p_input == NULL )
350     {
351         return (new BString("00:00:00"));
352     }     
353    
354     input_OffsetToTime( p_intf->p_sys->p_input, 
355                         psz_currenttime, 
356                         p_intf->p_sys->p_input->stream.p_selected_area->i_tell );        
357
358     return(new BString(psz_currenttime));
359 }
360
361 float  Intf_VLCWrapper::getTimeAsFloat()
362 {
363     float f_time = 0.0;
364
365     if( p_intf->p_sys->p_input != NULL )
366     {
367         f_time = (float)p_intf->p_sys->p_input->stream.p_selected_area->i_tell / 
368                  (float)p_intf->p_sys->p_input->stream.p_selected_area->i_size;
369     }    
370     else
371     {
372         f_time = 0.0;
373     }
374     return( f_time );
375 }
376
377 void   Intf_VLCWrapper::setTimeAsFloat(float f_position)
378 {
379     if( p_intf->p_sys->p_input != NULL )
380     {
381         input_Seek( p_intf->p_sys->p_input, 
382                    (long long int)(p_intf->p_sys->p_input->stream.p_selected_area->i_size * f_position / 100), 
383                    INPUT_SEEK_SET);
384     }
385 }
386
387 BList  *Intf_VLCWrapper::playlistAsArray()
388
389     int i;
390     playlist_t *p_playlist = 
391                 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
392                                                        FIND_ANYWHERE );
393
394     BList* p_list = new BList(p_playlist->i_size);
395     
396     vlc_mutex_lock( &p_playlist->object_lock );
397
398     for( i = 0; i < p_playlist->i_size; i++ )
399     {
400         p_list->AddItem(new BString(p_playlist->pp_items[i]->psz_name));
401     }
402
403     vlc_mutex_unlock( &p_playlist->object_lock );
404     vlc_object_release( p_playlist );
405     return( p_list );
406 }
407
408     /* open file/disc/network */
409 void Intf_VLCWrapper::openFiles(BList *o_files)
410 {
411     BString *o_file;
412     playlist_t *p_playlist = 
413                (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
414                                                       FIND_ANYWHERE );
415
416     while( ( o_file = (BString *)o_files->LastItem() ) )
417     {
418         o_files->RemoveItem(o_files->CountItems() - 1);
419         playlist_Add( p_playlist, o_file->String(),
420                   PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
421         delete o_file;
422     }
423
424     vlc_object_release( p_playlist );
425
426 }
427
428 void Intf_VLCWrapper::openDisc(BString o_type, BString o_device, int i_title, int i_chapter)
429 {
430     BString o_source("");
431     o_source << o_type << ":" << o_device ;
432
433     playlist_t *p_playlist = 
434                (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
435                                                       FIND_ANYWHERE );
436     playlist_Add( p_playlist, o_source.String(),
437                   PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
438     vlc_object_release( p_playlist );
439 }
440
441 void Intf_VLCWrapper::openNet(BString o_addr, int i_port)
442 {
443 }
444
445 void Intf_VLCWrapper::openNetChannel(BString o_addr, int i_port)
446 {
447 }
448
449 void Intf_VLCWrapper::openNetHTTP(BString o_addr)
450 {
451 }
452
453 void Intf_VLCWrapper::toggleMute( )
454 {
455     input_ToggleMute( p_intf->p_sys->p_input );
456 }
457
458 /* menus management */
459