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 $
7 * Authors: Florian G. Pflug <fgp@phlo.org>
8 * Jon Lech Johansen <jon-vl@nanocrew.net>
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.
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.
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 *****************************************************************************/
25 #include <stdlib.h> /* malloc(), free() */
26 #include <sys/param.h> /* for MAXPATHLEN */
29 #include <videolan/vlc.h>
31 #include "interface.h"
32 #include "intf_playlist.h"
35 #include "video_output.h"
36 #include "stream_control.h"
37 #include "input_ext-intf.h"
40 #include "intf_open.h"
41 #include "intf_vlc_wrapper.h"
45 @implementation Intf_VLCWrapper
47 static Intf_VLCWrapper *o_intf = nil;
51 + (Intf_VLCWrapper *)instance
55 o_intf = [[[Intf_VLCWrapper alloc] init] autorelease];
69 p_main->p_intf->pf_manage( p_main->p_intf );
71 if( p_main->p_intf->b_die )
73 /* Vout depends on intf */
87 p_main->p_intf->b_die = 1;
90 /* playlist control */
94 if( p_input_bank->pp_input[0] != NULL )
96 input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PLAY );
97 p_main->p_playlist->b_stopped = 0;
101 vlc_mutex_lock( &p_main->p_playlist->change_lock );
103 if( p_main->p_playlist->b_stopped )
105 if( p_main->p_playlist->i_size )
107 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
108 intf_PlaylistJumpto( p_main->p_playlist,
109 p_main->p_playlist->i_index );
113 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
114 [[Intf_Open instance] openFile: nil];
119 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
126 - (void)playlistPause
128 if ( p_input_bank->pp_input[0] != NULL )
130 input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PAUSE );
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 );
140 if( p_input_bank->pp_input[0] != NULL )
142 /* end playing item */
143 p_input_bank->pp_input[0]->b_eof = 1;
145 /* update playlist */
146 vlc_mutex_lock( &p_main->p_playlist->change_lock );
148 p_main->p_playlist->i_index--;
149 p_main->p_playlist->b_stopped = 1;
151 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
157 if( p_input_bank->pp_input[0] != NULL )
159 p_input_bank->pp_input[0]->b_eof = 1;
165 if( p_input_bank->pp_input[0] != NULL )
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;
176 if( p_input_bank->pp_input[0] != NULL )
178 input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_SLOWER );
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 );
188 if( p_input_bank->pp_input[0] != NULL )
190 input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_FASTER );
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 );
200 #define p_area p_input_bank->pp_input[0]->stream.p_selected_area
202 - (NSString *)getTimeAsString
204 static char psz_currenttime[ OFFSETTOTIME_MAX_SIZE ];
206 if( p_input_bank->pp_input[0] == NULL )
208 return [NSString stringWithCString:"00:00:00"];
211 input_OffsetToTime( p_input_bank->pp_input[0],
212 psz_currenttime, p_area->i_tell );
214 return( [NSString stringWithCString: psz_currenttime] );
217 - (float)getTimeAsFloat
221 vlc_mutex_lock( &p_input_bank->lock );
223 if( p_input_bank->pp_input[0] != NULL )
225 f_time = (float)p_area->i_tell / (float)p_area->i_size;
228 vlc_mutex_unlock( &p_input_bank->lock );
233 - (void)setTimeAsFloat:(float)f_position
235 vlc_mutex_lock( &p_input_bank->lock );
237 if( p_input_bank->pp_input[0] != NULL )
239 input_Seek( p_input_bank->pp_input[0], p_area->i_size * f_position );
242 vlc_mutex_unlock( &p_input_bank->lock );
247 - (bool)playlistPlaying
249 return( !p_main->p_playlist->b_stopped );
252 - (NSArray *)playlistAsArray
255 NSMutableArray* p_list =
256 [NSMutableArray arrayWithCapacity: p_main->p_playlist->i_size];
258 vlc_mutex_lock( &p_main->p_playlist->change_lock );
260 for( i = 0; i < p_main->p_playlist->i_size; i++ )
262 [p_list addObject: [NSString
263 stringWithCString: p_main->p_playlist->p_item[i].psz_name]];
266 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
268 return( [NSArray arrayWithArray: p_list] );
272 - (int)playlistLength
274 return( p_main->p_playlist->i_size );
277 - (NSString*)playlistItem:(int)i_pos
279 NSString *o_item = nil;
281 vlc_mutex_lock( &p_main->p_playlist->change_lock );
283 if( i_pos < p_main->p_playlist->i_size )
286 stringWithCString: p_main->p_playlist->p_item[i_pos].psz_name];
289 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
294 - (void)playlistPlayItem:(int)i_item
298 vlc_mutex_lock( &p_main->p_playlist->change_lock );
300 if( i_item<p_main->p_playlist->i_size )
302 p_main->p_playlist->i_index--;
305 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
307 [self playlistPlayCurrent];
310 - (void)playlistAdd:(NSString *)o_filename
312 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END,
313 [o_filename lossyCString] );
316 - (void)clearPlaylist
320 vlc_mutex_lock( &p_main->p_playlist->change_lock );
322 for( i = 0; i < p_main->p_playlist->i_size; i++ )
324 intf_PlaylistDelete( p_main->p_playlist, i );
327 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
331 /* open file/disc/network */
333 - (void)openFiles:(NSArray*)o_files
336 int i_end = p_main->p_playlist->i_size;
337 NSEnumerator *o_enum = [o_files objectEnumerator];
339 while( ( o_file = (NSString *)[o_enum nextObject] ) )
341 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END,
342 [o_file lossyCString] );
345 /* end current item, select first added item */
346 if( p_input_bank->pp_input[0] != NULL )
348 p_input_bank->pp_input[0]->b_eof = 1;
351 intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
354 - (void)openDisc:(NSString*)o_type device:(NSString*)o_device title:(int)i_title chapter:(int)i_chapter
357 int i_end = p_main->p_playlist->i_size;
359 o_source = [NSString stringWithFormat: @"%@:%@@%d,%d",
360 o_type, o_device, i_title, i_chapter];
362 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END,
363 [o_source lossyCString] );
365 /* stop current item, select added item */
366 if( p_input_bank->pp_input[0] != NULL )
368 p_input_bank->pp_input[0]->b_eof = 1;
371 intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
374 - (void)openNet:(NSString*)o_protocol addr:(NSString*)o_addr port:(int)i_port baddr:(NSString*)o_baddr
377 int i_end = p_main->p_playlist->i_size;
379 if( p_input_bank->pp_input[0] != NULL )
381 p_input_bank->pp_input[0]->b_eof = 1;
384 config_PutIntVariable( "network_channel", 0 );
388 o_source = [NSString stringWithFormat: @"%@://%@@:%i/%@",
389 o_protocol, o_addr, i_port, o_baddr];
393 o_source = [NSString stringWithFormat: @"%@://%@@:%i",
394 o_protocol, o_addr, i_port];
397 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END,
398 [o_source lossyCString] );
400 intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
403 - (void)openNetChannel:(NSString*)o_addr port:(int)i_port
405 if( p_input_bank->pp_input[0] != NULL )
407 p_input_bank->pp_input[0]->b_eof = 1;
410 config_PutIntVariable( "network_channel", 1 );
412 if( p_main->p_channel == NULL )
414 network_ChannelCreate();
417 config_PutPszVariable( "channel_server", (char*)[o_addr lossyCString] );
418 config_PutIntVariable( "channel_port", i_port );