]> git.sesse.net Git - vlc/blob - plugins/macosx/intf_vlc_wrapper.c
fadf403fba5e4b5d87ccc3ca3a20fd904deab9c5
[vlc] / plugins / macosx / intf_vlc_wrapper.c
1 /*****************************************************************************
2  * intf_vlc_wrapper.c: MacOS X plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2001 VideoLAN
5  * $Id: intf_vlc_wrapper.c,v 1.10 2002/04/23 03:21:21 jlj Exp $
6  *
7  * Authors: Florian G. Pflug <fgp@phlo.org>
8  *          Jon Lech Johansen <jon-vl@nanocrew.net>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  * 
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 #include <stdlib.h>                                      /* malloc(), free() */
26 #include <sys/param.h>                                    /* for MAXPATHLEN */
27 #include <string.h>
28
29 #include <videolan/vlc.h>
30
31 #include "interface.h"
32 #include "intf_playlist.h"
33
34 #include "video.h"
35 #include "video_output.h"
36 #include "stream_control.h"
37 #include "input_ext-intf.h"
38
39 #include "macosx.h"
40 #include "intf_open.h"
41 #include "intf_vlc_wrapper.h"
42
43 #include "netutils.h"
44
45 @implementation Intf_VLCWrapper
46
47 static Intf_VLCWrapper *o_intf = nil;
48
49 /* Initialization */
50
51 + (Intf_VLCWrapper *)instance
52 {
53     if( o_intf == nil )
54     {
55         o_intf = [[[Intf_VLCWrapper alloc] init] autorelease];
56     }
57
58     return( o_intf );
59 }
60
61 - (void)dealloc
62 {
63     o_intf = nil;
64     [super dealloc];
65 }
66
67 - (bool)manage
68 {
69     p_main->p_intf->pf_manage( p_main->p_intf );
70
71     if( p_main->p_intf->b_die )
72     {
73         /* Vout depends on intf */
74         input_EndBank();
75         vout_EndBank();
76         input_InitBank();
77         vout_InitBank();
78
79         return( 1 );
80     }
81
82     return( 0 );
83 }
84
85 - (void)quit
86 {
87     p_main->p_intf->b_die = 1;
88 }
89
90 /* playlist control */
91     
92 - (bool)playlistPlay
93 {
94     if( p_input_bank->pp_input[0] != NULL )
95     {
96         input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PLAY );
97         p_main->p_playlist->b_stopped = 0;
98     }
99     else
100     {
101         vlc_mutex_lock( &p_main->p_playlist->change_lock );
102
103         if( p_main->p_playlist->b_stopped )
104         {
105             if( p_main->p_playlist->i_size )
106             {
107                 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
108                 intf_PlaylistJumpto( p_main->p_playlist,
109                                      p_main->p_playlist->i_index );
110             }
111             else
112             {
113                 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
114                 [[Intf_Open instance] openFile: nil];
115             }
116         }
117         else
118         {
119             vlc_mutex_unlock( &p_main->p_playlist->change_lock );
120         }
121     }
122
123     return( TRUE );
124 }
125
126 - (void)playlistPause
127 {
128     if ( p_input_bank->pp_input[0] != NULL )
129     {
130         input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PAUSE );
131
132         vlc_mutex_lock( &p_main->p_playlist->change_lock );
133         p_main->p_playlist->b_stopped = 0;
134         vlc_mutex_unlock( &p_main->p_playlist->change_lock );
135     }
136 }
137     
138 - (void)playlistStop
139 {
140     if( p_input_bank->pp_input[0] != NULL )
141     {
142         /* end playing item */
143         p_input_bank->pp_input[0]->b_eof = 1;
144
145         /* update playlist */
146         vlc_mutex_lock( &p_main->p_playlist->change_lock );
147
148         p_main->p_playlist->i_index--;
149         p_main->p_playlist->b_stopped = 1;
150
151         vlc_mutex_unlock( &p_main->p_playlist->change_lock );
152     }
153 }
154
155 - (void)playlistNext
156 {
157     if( p_input_bank->pp_input[0] != NULL )
158     {
159         p_input_bank->pp_input[0]->b_eof = 1;
160     }
161 }
162
163 - (void)playlistPrev
164 {
165     if( p_input_bank->pp_input[0] != NULL )
166     {
167         /* FIXME: temporary hack */
168         intf_PlaylistPrev( p_main->p_playlist );
169         intf_PlaylistPrev( p_main->p_playlist );
170         p_input_bank->pp_input[0]->b_eof = 1;
171     }
172 }
173
174 - (void)playSlower
175 {
176     if( p_input_bank->pp_input[0] != NULL )
177     {
178         input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_SLOWER );
179
180         vlc_mutex_lock( &p_main->p_playlist->change_lock );
181         p_main->p_playlist->b_stopped = 0;
182         vlc_mutex_unlock( &p_main->p_playlist->change_lock );
183     }
184 }
185
186 - (void)playFaster
187 {
188     if( p_input_bank->pp_input[0] != NULL )
189     {
190         input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_FASTER );
191
192         vlc_mutex_lock( &p_main->p_playlist->change_lock );
193         p_main->p_playlist->b_stopped = 0;
194         vlc_mutex_unlock( &p_main->p_playlist->change_lock );
195     }
196 }
197
198 /* playback info */
199
200 #define p_area p_input_bank->pp_input[0]->stream.p_selected_area
201
202 - (NSString *)getTimeAsString
203 {
204     static char psz_currenttime[ OFFSETTOTIME_MAX_SIZE ];
205         
206     if( p_input_bank->pp_input[0] == NULL )
207     {
208         return [NSString stringWithCString:"00:00:00"];
209     }     
210    
211     input_OffsetToTime( p_input_bank->pp_input[0], 
212                         psz_currenttime, p_area->i_tell );        
213
214     return( [NSString stringWithCString: psz_currenttime] );
215 }
216     
217 - (float)getTimeAsFloat
218 {
219     float f_time = 0.0;
220
221     vlc_mutex_lock( &p_input_bank->lock );
222
223     if( p_input_bank->pp_input[0] != NULL )
224     {
225         f_time = (float)p_area->i_tell / (float)p_area->i_size;
226     }    
227
228     vlc_mutex_unlock( &p_input_bank->lock );
229
230     return( f_time );
231 }
232
233 - (void)setTimeAsFloat:(float)f_position
234 {
235     vlc_mutex_lock( &p_input_bank->lock );
236
237     if( p_input_bank->pp_input[0] != NULL )
238     {
239         input_Seek( p_input_bank->pp_input[0], p_area->i_size * f_position );
240     }
241
242     vlc_mutex_unlock( &p_input_bank->lock );
243 }
244
245 #undef p_area
246
247 - (bool)playlistPlaying
248 {
249     return( !p_main->p_playlist->b_stopped );
250 }
251
252 - (NSArray *)playlistAsArray
253 {
254     int i;
255     NSMutableArray* p_list = 
256         [NSMutableArray arrayWithCapacity: p_main->p_playlist->i_size];
257     
258     vlc_mutex_lock( &p_main->p_playlist->change_lock );
259
260     for( i = 0; i < p_main->p_playlist->i_size; i++ )
261     {
262         [p_list addObject: [NSString 
263             stringWithCString: p_main->p_playlist->p_item[i].psz_name]];
264     }
265
266     vlc_mutex_unlock( &p_main->p_playlist->change_lock );
267         
268     return( [NSArray arrayWithArray: p_list] );
269 }
270
271 /*
272 - (int)playlistLength
273 {
274     return( p_main->p_playlist->i_size );
275 }
276
277 - (NSString*)playlistItem:(int)i_pos
278 {
279     NSString *o_item = nil;
280
281     vlc_mutex_lock( &p_main->p_playlist->change_lock );
282     
283     if( i_pos < p_main->p_playlist->i_size )
284     {
285         o_item = [NSString 
286             stringWithCString: p_main->p_playlist->p_item[i_pos].psz_name];
287     }
288
289     vlc_mutex_unlock( &p_main->p_playlist->change_lock );
290
291     return( o_item );
292 }
293
294 - (void)playlistPlayItem:(int)i_item
295 {
296     [self playlistStop];
297
298     vlc_mutex_lock( &p_main->p_playlist->change_lock );
299
300     if( i_item<p_main->p_playlist->i_size )
301     {
302         p_main->p_playlist->i_index--;
303     }
304
305     vlc_mutex_unlock( &p_main->p_playlist->change_lock );        
306
307     [self playlistPlayCurrent];
308 }
309     
310 - (void)playlistAdd:(NSString *)o_filename
311 {
312     intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, 
313                       [o_filename lossyCString] );
314 }
315     
316 - (void)clearPlaylist
317 {
318     int i;
319     
320     vlc_mutex_lock( &p_main->p_playlist->change_lock );
321
322     for( i = 0; i < p_main->p_playlist->i_size; i++ )
323     {
324         intf_PlaylistDelete( p_main->p_playlist, i );
325     }
326
327     vlc_mutex_unlock( &p_main->p_playlist->change_lock );        
328 }
329 */
330
331 /* open file/disc/network */
332
333 - (void)openFiles:(NSArray*)o_files
334 {
335     NSString *o_file;
336     int i_end = p_main->p_playlist->i_size;
337     NSEnumerator *o_enum = [o_files objectEnumerator];
338
339     while( ( o_file = (NSString *)[o_enum nextObject] ) )
340     {
341         intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, 
342                           [o_file lossyCString] );
343     }
344
345     /* end current item, select first added item */
346     if( p_input_bank->pp_input[0] != NULL )
347     {
348         p_input_bank->pp_input[0]->b_eof = 1;
349     }
350
351     intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
352 }
353
354 - (void)openDisc:(NSString*)o_type device:(NSString*)o_device title:(int)i_title chapter:(int)i_chapter
355 {
356     NSString *o_source;
357     int i_end = p_main->p_playlist->i_size;
358
359     o_source = [NSString stringWithFormat: @"%@:%@@%d,%d", 
360                     o_type, o_device, i_title, i_chapter];
361
362     intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END,
363                       [o_source lossyCString] );
364
365     /* stop current item, select added item */
366     if( p_input_bank->pp_input[0] != NULL )
367     {
368         p_input_bank->pp_input[0]->b_eof = 1;
369     }
370
371     intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
372 }
373
374 - (void)openNet:(NSString*)o_protocol addr:(NSString*)o_addr port:(int)i_port baddr:(NSString*)o_baddr
375 {
376     NSString *o_source;
377     int i_end = p_main->p_playlist->i_size;
378
379     if( p_input_bank->pp_input[0] != NULL )
380     {
381         p_input_bank->pp_input[0]->b_eof = 1;
382     }
383
384     config_PutIntVariable( "network_channel", 0 );
385
386     if( o_baddr != nil )
387     {
388         o_source = [NSString stringWithFormat: @"%@://%@@:%i/%@",
389                         o_protocol, o_addr, i_port, o_baddr];
390     }
391     else
392     {
393         o_source = [NSString stringWithFormat: @"%@://%@@:%i",
394                         o_protocol, o_addr, i_port];
395     }
396
397     intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END,
398                       [o_source lossyCString] );
399
400     intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
401 }
402
403 - (void)openNetChannel:(NSString*)o_addr port:(int)i_port
404 {
405     if( p_input_bank->pp_input[0] != NULL )
406     {
407         p_input_bank->pp_input[0]->b_eof = 1;
408     }
409
410     config_PutIntVariable( "network_channel", 1 );
411
412     if( p_main->p_channel == NULL )
413     {
414         network_ChannelCreate();
415     }
416
417     config_PutPszVariable( "channel_server", (char*)[o_addr lossyCString] );
418     config_PutIntVariable( "channel_port", i_port ); 
419 }
420
421 @end