* extras/MacOSX/vlc.pbproj/project.pbxproj:
[vlc.git] / modules / gui / macosx / intf.m
1 /*****************************************************************************
2  * intf.m: MacOS X interface plugin
3  *****************************************************************************
4  * Copyright (C) 2002-2003 VideoLAN
5  * $Id: intf.m,v 1.81 2003/05/11 23:17:30 hartman Exp $
6  *
7  * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
8  *          Christophe Massiot <massiot@via.ecp.fr>
9  *          Derk-Jan Hartman <thedj@users.sourceforge.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
26 /*****************************************************************************
27  * Preamble
28  *****************************************************************************/
29 #include <stdlib.h>                                      /* malloc(), free() */
30 #include <sys/param.h>                                    /* for MAXPATHLEN */
31 #include <string.h>
32
33 #include "intf.h"
34 #include "vout.h"
35 #include "prefs.h"
36 #include "playlist.h"
37 #include "info.h"
38
39 /*****************************************************************************
40  * Local prototypes.
41  *****************************************************************************/
42 static void Run ( intf_thread_t *p_intf );
43
44 /*****************************************************************************
45  * OpenIntf: initialize interface
46  *****************************************************************************/
47 int E_(OpenIntf) ( vlc_object_t *p_this )
48 {   
49     intf_thread_t *p_intf = (intf_thread_t*) p_this;
50
51     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
52     if( p_intf->p_sys == NULL )
53     {
54         return( 1 );
55     }
56
57     memset( p_intf->p_sys, 0, sizeof( *p_intf->p_sys ) );
58     
59     p_intf->p_sys->o_pool = [[NSAutoreleasePool alloc] init];
60     
61     /* Put Cocoa into multithread mode as soon as possible.
62      * http://developer.apple.com/techpubs/macosx/Cocoa/
63      * TasksAndConcepts/ProgrammingTopics/Multithreading/index.html
64      * This thread does absolutely nothing at all. */
65     [NSThread detachNewThreadSelector:@selector(self) toTarget:[NSString string] withObject:nil];
66     
67     p_intf->p_sys->o_sendport = [[NSPort port] retain];
68     p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
69     p_intf->pf_run = Run;
70     
71     [[VLCApplication sharedApplication] autorelease];
72     [NSApp initIntlSupport];
73     [NSApp setIntf: p_intf];
74
75     [NSBundle loadNibNamed: @"MainMenu" owner: NSApp];
76
77     return( 0 );
78 }
79
80 /*****************************************************************************
81  * CloseIntf: destroy interface
82  *****************************************************************************/
83 void E_(CloseIntf) ( vlc_object_t *p_this )
84 {
85     intf_thread_t *p_intf = (intf_thread_t*) p_this;
86
87     msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
88
89     [p_intf->p_sys->o_sendport release];
90     [p_intf->p_sys->o_pool release];
91
92     free( p_intf->p_sys );
93 }
94
95 /*****************************************************************************
96  * Run: main loop
97  *****************************************************************************/
98 static void Run( intf_thread_t *p_intf )
99 {
100     /* Do it again - for some unknown reason, vlc_thread_create() often
101      * fails to go to real-time priority with the first launched thread
102      * (???) --Meuuh */
103     vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
104
105     [NSApp run];
106 }
107
108 /*****************************************************************************
109  * VLCApplication implementation 
110  *****************************************************************************/
111 @implementation VLCApplication
112
113 - (id)init
114 {
115     /* default encoding: ISO-8859-1 */
116     i_encoding = NSISOLatin1StringEncoding;
117
118     return( [super init] );
119 }
120
121 - (void)initIntlSupport
122 {
123     char *psz_lang = getenv( "LANG" );
124
125     if( psz_lang == NULL )
126     {
127         return;
128     }
129
130     if( strncmp( psz_lang, "pl", 2 ) == 0 )
131     {
132         i_encoding = NSISOLatin2StringEncoding;
133     }
134     else if( strncmp( psz_lang, "ja", 2 ) == 0 ) 
135     {
136         i_encoding = NSJapaneseEUCStringEncoding;
137     }
138     else if( strncmp( psz_lang, "ru", 2 ) == 0 )
139     {
140 #define CFSENC2NSSENC(e) CFStringConvertEncodingToNSStringEncoding(e)
141         i_encoding = CFSENC2NSSENC( kCFStringEncodingKOI8_R ); 
142 #undef CFSENC2NSSENC
143     }
144 }
145
146 - (NSString *)localizedString:(char *)psz
147 {
148     NSString * o_str = nil;
149
150     if( psz != NULL )
151     {
152         UInt32 uiLength = (UInt32)strlen( psz );
153         NSData * o_data = [NSData dataWithBytes: psz length: uiLength];
154         o_str = [[[NSString alloc] initWithData: o_data
155                                        encoding: i_encoding] autorelease];
156     }
157
158     return( o_str );
159 }
160
161 - (char *)delocalizeString:(NSString *)id
162 {
163     NSData * o_data = [id dataUsingEncoding: i_encoding
164                           allowLossyConversion: NO];
165     char * psz_string;
166
167     if ( o_data == nil )
168     {
169         o_data = [id dataUsingEncoding: i_encoding
170                      allowLossyConversion: YES];
171         psz_string = malloc( [o_data length] + 1 ); 
172         [o_data getBytes: psz_string];
173         psz_string[ [o_data length] ] = '\0';
174         msg_Err( p_intf, "cannot convert to wanted encoding: %s",
175                  psz_string );
176     }
177     else
178     {
179         psz_string = malloc( [o_data length] + 1 ); 
180         [o_data getBytes: psz_string];
181         psz_string[ [o_data length] ] = '\0';
182     }
183
184     return psz_string;
185 }
186
187 - (NSStringEncoding)getEncoding
188 {
189     return i_encoding;
190 }
191
192 - (void)setIntf:(intf_thread_t *)_p_intf
193 {
194     p_intf = _p_intf;
195 }
196
197 - (intf_thread_t *)getIntf
198 {
199     return( p_intf );
200 }
201
202 - (void)terminate:(id)sender
203 {
204     p_intf->p_vlc->b_die = VLC_TRUE;
205 }
206
207 @end
208
209 int ExecuteOnMainThread( id target, SEL sel, void * p_arg )
210 {
211     int i_ret = 0;
212
213     NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
214
215     if( [target respondsToSelector: @selector(performSelectorOnMainThread:
216                                              withObject:waitUntilDone:)] )
217     {
218         [target performSelectorOnMainThread: sel
219                 withObject: [NSValue valueWithPointer: p_arg]
220                 waitUntilDone: YES];
221     }
222     else if( NSApp != nil && [NSApp respondsToSelector: @selector(getIntf)] ) 
223     {
224         NSValue * o_v1;
225         NSValue * o_v2;
226         NSArray * o_array;
227         NSPort * o_recv_port;
228         NSInvocation * o_inv;
229         NSPortMessage * o_msg;
230         intf_thread_t * p_intf;
231         NSConditionLock * o_lock;
232         NSMethodSignature * o_sig;
233
234         id * val[] = { &o_lock, &o_v2 };
235
236         p_intf = (intf_thread_t *)[NSApp getIntf];
237
238         o_recv_port = [[NSPort port] retain];
239         o_v1 = [NSValue valueWithPointer: val]; 
240         o_v2 = [NSValue valueWithPointer: p_arg];
241
242         o_sig = [target methodSignatureForSelector: sel];
243         o_inv = [NSInvocation invocationWithMethodSignature: o_sig];
244         [o_inv setArgument: &o_v1 atIndex: 2];
245         [o_inv setTarget: target];
246         [o_inv setSelector: sel];
247
248         o_array = [NSArray arrayWithObject:
249             [NSData dataWithBytes: &o_inv length: sizeof(o_inv)]];
250         o_msg = [[NSPortMessage alloc]
251             initWithSendPort: p_intf->p_sys->o_sendport
252             receivePort: o_recv_port components: o_array];
253
254         o_lock = [[NSConditionLock alloc] initWithCondition: 0];
255         [o_msg sendBeforeDate: [NSDate distantPast]];
256         [o_lock lockWhenCondition: 1];
257         [o_lock unlock];
258         [o_lock release];
259
260         [o_msg release];
261         [o_recv_port release];
262     } 
263     else
264     {
265         i_ret = 1;
266     }
267
268     [o_pool release];
269
270     return( i_ret );
271 }
272
273 /*****************************************************************************
274  * VLCMain implementation 
275  *****************************************************************************/
276 @implementation VLCMain
277
278 - (void)awakeFromNib
279 {
280     [o_window setTitle: _NS("VLC - Controller")];
281     [o_window setExcludedFromWindowsMenu: TRUE];
282
283     /* button controls */
284     [o_btn_playlist setToolTip: _NS("Playlist")];
285     [o_btn_prev setToolTip: _NS("Previous")];
286     [o_btn_slower setToolTip: _NS("Slower")];
287     [o_btn_play setToolTip: _NS("Play")];
288     [o_btn_stop setToolTip: _NS("Stop")];
289     [o_btn_faster setToolTip: _NS("Faster")];
290     [o_btn_next setToolTip: _NS("Next")];
291     [o_btn_prefs setToolTip: _NS("Preferences")];
292     [o_volumeslider setToolTip: _NS("Volume")];
293     [o_timeslider setToolTip: _NS("Position")];
294
295     /* messages panel */ 
296     [o_msgs_panel setDelegate: self];
297     [o_msgs_panel setTitle: _NS("Messages")];
298     [o_msgs_panel setExcludedFromWindowsMenu: TRUE];
299     [o_msgs_btn_crashlog setTitle: _NS("Open CrashLog")];
300
301     /* main menu */
302     [o_mi_about setTitle: _NS("About VLC media player")];
303     [o_mi_prefs setTitle: _NS("Preferences...")];
304     [o_mi_hide setTitle: _NS("Hide VLC")];
305     [o_mi_hide_others setTitle: _NS("Hide Others")];
306     [o_mi_show_all setTitle: _NS("Show All")];
307     [o_mi_quit setTitle: _NS("Quit VLC")];
308
309     [o_mu_file setTitle: _ANS("1:File")];
310     [o_mi_open_generic setTitle: _NS("Open...")];
311     [o_mi_open_file setTitle: _NS("Open File...")];
312     [o_mi_open_disc setTitle: _NS("Open Disc...")];
313     [o_mi_open_net setTitle: _NS("Open Network...")];
314     [o_mi_open_recent setTitle: _NS("Open Recent")];
315     [o_mi_open_recent_cm setTitle: _NS("Clear Menu")];
316
317     [o_mu_edit setTitle: _NS("Edit")];
318     [o_mi_cut setTitle: _NS("Cut")];
319     [o_mi_copy setTitle: _NS("Copy")];
320     [o_mi_paste setTitle: _NS("Paste")];
321     [o_mi_clear setTitle: _NS("Clear")];
322     [o_mi_select_all setTitle: _NS("Select All")];
323
324     [o_mu_controls setTitle: _NS("Controls")];
325     [o_mi_play setTitle: _NS("Play")];
326     [o_mi_stop setTitle: _NS("Stop")];
327     [o_mi_faster setTitle: _NS("Faster")];
328     [o_mi_slower setTitle: _NS("Slower")];
329     [o_mi_previous setTitle: _NS("Previous")];
330     [o_mi_next setTitle: _NS("Next")];
331     [o_mi_loop setTitle: _NS("Loop")];
332     [o_mi_fwd setTitle: _NS("Step Forward")];
333     [o_mi_bwd setTitle: _NS("Step Backward")];
334     [o_mi_program setTitle: _NS("Program")];
335     [o_mu_program setTitle: _NS("Program")];
336     [o_mi_title setTitle: _NS("Title")];
337     [o_mu_title setTitle: _NS("Title")];
338     [o_mi_chapter setTitle: _NS("Chapter")];
339     [o_mu_chapter setTitle: _NS("Chapter")];
340     
341     [o_mu_audio setTitle: _NS("Audio")];
342     [o_mi_vol_up setTitle: _NS("Volume Up")];
343     [o_mi_vol_down setTitle: _NS("Volume Down")];
344     [o_mi_mute setTitle: _NS("Mute")];
345     [o_mi_audiotrack setTitle: _NS("Audio Track")];
346     [o_mu_audiotrack setTitle: _NS("Audio Track")];
347     [o_mi_channels setTitle: _NS("Channels")];
348     [o_mu_channels setTitle: _NS("Channels")];
349     [o_mi_device setTitle: _NS("Device")];
350     [o_mu_device setTitle: _NS("Device")];
351     
352     [o_mu_video setTitle: _NS("Video")];
353     [o_mi_half_window setTitle: _NS("Half Size")];
354     [o_mi_normal_window setTitle: _NS("Normal Size")];
355     [o_mi_double_window setTitle: _NS("Double Size")];
356     [o_mi_fittoscreen setTitle: _NS("Fit To Screen")];
357     [o_mi_fullscreen setTitle: _NS("Fullscreen")];
358     [o_mi_floatontop setTitle: _NS("Float On Top")];
359     [o_mi_videotrack setTitle: _NS("Video Track")];
360     [o_mu_videotrack setTitle: _NS("Video Track")];
361     [o_mi_screen setTitle: _NS("Screen")];
362     [o_mu_screen setTitle: _NS("Screen")];
363     [o_mi_subtitle setTitle: _NS("Subtitles")];
364     [o_mu_subtitle setTitle: _NS("Subtitles")];
365     [o_mi_deinterlace setTitle: _NS("Deinterlace")];
366     [o_mu_deinterlace setTitle: _NS("Deinterlace")];
367
368     [o_mu_window setTitle: _NS("Window")];
369     [o_mi_minimize setTitle: _NS("Minimize Window")];
370     [o_mi_close_window setTitle: _NS("Close Window")];
371     [o_mi_controller setTitle: _NS("Controller")];
372     [o_mi_playlist setTitle: _NS("Playlist")];
373     [o_mi_info setTitle: _NS("Info")];
374     [o_mi_messages setTitle: _NS("Messages")];
375
376     [o_mi_bring_atf setTitle: _NS("Bring All to Front")];
377
378     [o_mu_help setTitle: _NS("Help")];
379     [o_mi_readme setTitle: _NS("ReadMe...")];
380     [o_mi_reportabug setTitle: _NS("Report a Bug")];
381     [o_mi_website setTitle: _NS("VideoLAN Website")];
382     [o_mi_license setTitle: _NS("License")];
383
384     /* dock menu */
385     [o_dmi_play setTitle: _NS("Play")];
386     [o_dmi_stop setTitle: _NS("Stop")];
387     [o_dmi_next setTitle: _NS("Next")];
388     [o_dmi_previous setTitle: _NS("Previous")];
389
390     /* error panel */
391     [o_error setTitle: _NS("Error")];
392     [o_err_lbl setStringValue: _NS("An error has occurred which probably prevented the execution of your request:")];
393     [o_err_bug_lbl setStringValue: _NS("If you believe that it is a bug, please follow the instructions at:")]; 
394     [o_err_btn_msgs setTitle: _NS("Open Messages Window")];
395     [o_err_btn_dismiss setTitle: _NS("Dismiss")];
396
397     [o_info_window setTitle: _NS("Info")];
398
399     [self setSubmenusEnabled: FALSE];
400     [self manageVolumeSlider];
401 }
402
403 - (void)applicationWillFinishLaunching:(NSNotification *)o_notification
404 {
405     intf_thread_t * p_intf = [NSApp getIntf];
406
407     o_msg_lock = [[NSLock alloc] init];
408     o_msg_arr = [[NSMutableArray arrayWithCapacity: 200] retain];
409
410     o_img_play = [[NSImage imageNamed: @"play"] retain];
411     o_img_pause = [[NSImage imageNamed: @"pause"] retain];
412
413     [p_intf->p_sys->o_sendport setDelegate: self];
414     [[NSRunLoop currentRunLoop] 
415         addPort: p_intf->p_sys->o_sendport
416         forMode: NSDefaultRunLoopMode];
417
418     [NSTimer scheduledTimerWithTimeInterval: 0.5
419         target: self selector: @selector(manageIntf:)
420         userInfo: nil repeats: FALSE];
421
422     [NSThread detachNewThreadSelector: @selector(manage)
423         toTarget: self withObject: nil];
424
425     vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
426 }
427
428 - (BOOL)application:(NSApplication *)o_app openFile:(NSString *)o_filename
429 {
430     intf_thread_t * p_intf = [NSApp getIntf];
431     
432     [o_playlist appendArray:
433         [NSArray arrayWithObject: o_filename] atPos: -1 enqueue: NO];
434     
435     config_PutPsz( [NSApp getIntf], "sub-file", "" );
436     config_PutInt( p_intf, "sub-delay", 0 );
437     config_PutFloat( p_intf, "sub-fps", 0.0 );
438     config_PutPsz( p_intf, "sout", "" );
439             
440     return( TRUE );
441 }
442
443 - (id)getControls
444 {
445     if ( o_controls )
446     {
447         return o_controls;
448     }
449     return nil;
450 }
451
452 - (void)manage
453 {
454     NSDate * o_sleep_date;
455     intf_thread_t * p_intf = [NSApp getIntf];
456     NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
457
458     vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
459
460     while( !p_intf->b_die )
461     {
462         playlist_t * p_playlist;
463
464         vlc_mutex_lock( &p_intf->change_lock );
465
466         p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, 
467                                               FIND_ANYWHERE );
468
469         if( p_playlist != NULL )
470         {
471             vlc_mutex_lock( &p_playlist->object_lock );
472             
473             [self manage: p_playlist];
474             
475             vlc_mutex_unlock( &p_playlist->object_lock );
476             vlc_object_release( p_playlist );
477         }
478
479         vlc_mutex_unlock( &p_intf->change_lock );
480
481         o_sleep_date = [NSDate dateWithTimeIntervalSinceNow: .5];
482         [NSThread sleepUntilDate: o_sleep_date];
483     }
484
485     [self terminate];
486
487     [o_pool release];
488 }
489
490 - (void)manage:(playlist_t *)p_playlist
491 {
492     vlc_value_t val;
493
494     intf_thread_t * p_intf = [NSApp getIntf];
495
496     if( var_Get( (vlc_object_t *)p_playlist, "intf-change", &val ) >= 0 &&
497         val.b_bool )
498     {
499         p_intf->p_sys->b_playlist_update = VLC_TRUE;
500         p_intf->p_sys->b_intf_update = VLC_TRUE;
501     }
502
503 #define p_input p_playlist->p_input
504
505     if( p_input )
506     {
507         vout_thread_t   * p_vout  = NULL;
508         aout_instance_t * p_aout  = NULL; 
509
510         vlc_mutex_lock( &p_input->stream.stream_lock );
511
512         if( !p_input->b_die )
513         {
514             audio_volume_t i_volume;
515
516             /* New input or stream map change */
517             if( p_input->stream.b_changed )
518             {
519                 p_intf->p_sys->b_playing = TRUE;
520                 [self manageMode: p_playlist];
521             }
522
523             vlc_value_t val;
524
525             if( var_Get( (vlc_object_t *)p_input, "intf-change", &val )
526                 >= 0 && val.b_bool )
527             {
528                 p_intf->p_sys->b_input_update = TRUE;
529             }
530
531             p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT,
532                                               FIND_ANYWHERE );
533             if( p_aout != NULL )
534             {
535                 vlc_value_t val;
536
537                 if( var_Get( (vlc_object_t *)p_aout, "intf-change", &val )
538                     >= 0 && val.b_bool )
539                 {
540                     p_intf->p_sys->b_aout_update = TRUE;
541                 }
542
543                 vlc_object_release( (vlc_object_t *)p_aout );
544             }
545
546             aout_VolumeGet( p_intf, &i_volume );
547             p_intf->p_sys->b_mute = ( i_volume == 0 );
548
549             p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
550                                               FIND_ANYWHERE );
551             if( p_vout != NULL )
552             {
553                 vlc_value_t val;
554
555                 if( var_Get( (vlc_object_t *)p_vout, "intf-change", &val )
556                     >= 0 && val.b_bool )
557                 {
558                     p_intf->p_sys->b_vout_update = TRUE;
559                 }
560
561                 vlc_object_release( (vlc_object_t *)p_vout );
562             }
563             [self setupMenus: p_input];
564         }
565         vlc_mutex_unlock( &p_input->stream.stream_lock );
566     }
567     else if( p_intf->p_sys->b_playing && !p_intf->b_die )
568     {
569         p_intf->p_sys->b_playing = FALSE;
570         [self manageMode: p_playlist];
571     }
572
573 #undef p_input
574 }
575
576 - (void)manageMode:(playlist_t *)p_playlist
577 {
578     intf_thread_t * p_intf = [NSApp getIntf];
579
580     if( p_playlist->p_input != NULL )
581     {
582         p_intf->p_sys->b_current_title_update = 1;
583         p_playlist->p_input->stream.b_changed = 0;
584         
585         msg_Dbg( p_intf, "stream has changed, refreshing interface" );
586     }
587     else
588     {
589         vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
590                                                           FIND_ANYWHERE );
591         if( p_vout != NULL )
592         {
593             vlc_object_detach( p_vout );
594             vlc_object_release( p_vout );
595
596             vlc_mutex_unlock( &p_playlist->object_lock );
597             vout_Destroy( p_vout );
598             vlc_mutex_lock( &p_playlist->object_lock );
599         }
600     }
601
602     p_intf->p_sys->b_intf_update = VLC_TRUE;
603 }
604
605 - (void)manageIntf:(NSTimer *)o_timer
606 {
607     intf_thread_t * p_intf = [NSApp getIntf];
608
609     if( p_intf->p_vlc->b_die == VLC_TRUE )
610     {
611         [o_timer invalidate];
612         return;
613     }
614
615     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
616                                                        FIND_ANYWHERE );
617
618     if( p_playlist == NULL )
619     {
620         return;
621     }
622
623     if ( p_intf->p_sys->b_playlist_update )
624     {
625         vlc_value_t val;
626
627         val.b_bool = FALSE;
628         var_Set( (vlc_object_t *)p_playlist, "intf-change", val );
629
630         [o_playlist playlistUpdated];
631
632         p_intf->p_sys->b_playlist_update = VLC_FALSE;
633     }
634
635     if( p_intf->p_sys->b_current_title_update )
636     {
637         vout_thread_t   *p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
638                                               FIND_ANYWHERE );
639         if( p_vout != NULL )
640         {
641             id o_vout_wnd;
642             NSEnumerator * o_enum = [[NSApp windows] objectEnumerator];
643             
644             while( ( o_vout_wnd = [o_enum nextObject] ) )
645             {
646                 if( [[o_vout_wnd className] isEqualToString: @"VLCWindow"] )
647                 {
648                     [o_vout_wnd updateTitle];
649                 }
650             }
651             vlc_object_release( (vlc_object_t *)p_vout );
652         }
653         [o_playlist updateRowSelection];
654         [o_info updateInfo];
655
656         p_intf->p_sys->b_current_title_update = FALSE;
657     }
658
659     vlc_mutex_lock( &p_playlist->object_lock );
660
661 #define p_input p_playlist->p_input
662
663     if( p_input != NULL )
664     {
665         vlc_mutex_lock( &p_input->stream.stream_lock );
666     }
667
668     if( p_intf->p_sys->b_intf_update )
669     {
670         vlc_bool_t b_input = VLC_FALSE;
671         vlc_bool_t b_plmul = VLC_FALSE;
672         vlc_bool_t b_control = VLC_FALSE;
673         vlc_bool_t b_seekable = VLC_FALSE;
674         vlc_bool_t b_chapters = VLC_FALSE;
675
676         b_plmul = p_playlist->i_size > 1;
677
678         if( ( b_input = ( p_input != NULL ) ) )
679         {
680             /* seekable streams */
681             b_seekable = p_input->stream.b_seekable;
682
683             /* control buttons for free pace streams */
684             b_control = p_input->stream.b_pace_control; 
685
686             /* chapters */
687             b_chapters = p_input->stream.p_selected_area->i_part_nb > 1; 
688
689             /* play status */
690             p_intf->p_sys->b_play_status = 
691                 p_input->stream.control.i_status != PAUSE_S;
692         }
693         else
694         {
695             /* play status */
696             p_intf->p_sys->b_play_status = FALSE;
697             [self setSubmenusEnabled: FALSE];
698         }
699
700         [self playStatusUpdated: p_intf->p_sys->b_play_status];
701
702         [o_btn_stop setEnabled: b_input];
703         [o_btn_faster setEnabled: b_control];
704         [o_btn_slower setEnabled: b_control];
705         [o_btn_prev setEnabled: (b_plmul || b_chapters)];
706         [o_btn_next setEnabled: (b_plmul || b_chapters)];
707
708         [o_timeslider setFloatValue: 0.0];
709         [o_timeslider setEnabled: b_seekable];
710         [o_timefield setStringValue: @"0:00:00"];
711
712         [self manageVolumeSlider];
713
714         p_intf->p_sys->b_intf_update = VLC_FALSE;
715     }
716
717 #define p_area p_input->stream.p_selected_area
718
719     if( p_intf->p_sys->b_playing && p_input != NULL )
720     {
721         vlc_bool_t b_field_update = TRUE;
722
723         if( !p_input->b_die && ( p_intf->p_sys->b_play_status !=
724             ( p_input->stream.control.i_status != PAUSE_S ) ) ) 
725         {
726             p_intf->p_sys->b_play_status =
727                 !p_intf->p_sys->b_play_status;
728
729             [self playStatusUpdated: p_intf->p_sys->b_play_status]; 
730         }
731
732         if( p_input->stream.b_seekable )
733         {
734             if( f_slider == f_slider_old )
735             {
736                 float f_updated = ( 10000. * p_area->i_tell ) /
737                                            p_area->i_size;
738
739                 if( f_slider != f_updated )
740                 {
741                     [o_timeslider setFloatValue: f_updated];
742                 }
743             }
744             else
745             {
746                 off_t i_seek = ( f_slider * p_area->i_size ) / 10000;
747
748                 /* release the lock to be able to seek */
749                 vlc_mutex_unlock( &p_input->stream.stream_lock );
750                 input_Seek( p_input, i_seek, INPUT_SEEK_SET );
751                 vlc_mutex_lock( &p_input->stream.stream_lock );
752
753                 /* update the old value */
754                 f_slider_old = f_slider; 
755
756                 b_field_update = VLC_FALSE;
757             }
758         }
759
760         if( b_field_update )
761         {
762             NSString * o_time;
763             char psz_time[ OFFSETTOTIME_MAX_SIZE ];
764
765             input_OffsetToTime( p_input, psz_time, p_area->i_tell );
766
767             o_time = [NSString stringWithCString: psz_time];
768             [o_timefield setStringValue: o_time];
769         }
770
771         /* disable screen saver */
772         UpdateSystemActivity( UsrActivity );
773     }
774
775 #undef p_area
776
777     if( p_input != NULL )
778     {
779         vlc_mutex_unlock( &p_input->stream.stream_lock );
780     }
781
782 #undef p_input
783
784     vlc_mutex_unlock( &p_playlist->object_lock );
785     vlc_object_release( p_playlist );
786
787     [self updateMessageArray];
788
789     [NSTimer scheduledTimerWithTimeInterval: 0.5
790         target: self selector: @selector(manageIntf:)
791         userInfo: nil repeats: FALSE];
792 }
793
794 - (void)updateMessageArray
795 {
796     int i_start, i_stop;
797     intf_thread_t * p_intf = [NSApp getIntf];
798
799     vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
800     i_stop = *p_intf->p_sys->p_sub->pi_stop;
801     vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
802
803     if( p_intf->p_sys->p_sub->i_start != i_stop )
804     {
805         NSColor *o_white = [NSColor whiteColor];
806         NSColor *o_red = [NSColor redColor];
807         NSColor *o_yellow = [NSColor yellowColor];
808         NSColor *o_gray = [NSColor grayColor];
809
810         NSColor * pp_color[4] = { o_white, o_red, o_yellow, o_gray };
811         static const char * ppsz_type[4] = { ": ", " error: ",
812                                              " warning: ", " debug: " };
813
814         for( i_start = p_intf->p_sys->p_sub->i_start;
815              i_start != i_stop;
816              i_start = (i_start+1) % VLC_MSG_QSIZE )
817         {
818             NSString *o_msg;
819             NSDictionary *o_attr;
820             NSAttributedString *o_msg_color;
821
822             int i_type = p_intf->p_sys->p_sub->p_msg[i_start].i_type;
823
824             [o_msg_lock lock];
825
826             if( [o_msg_arr count] + 2 > 400 )
827             {
828                 unsigned rid[] = { 0, 1 };
829                 [o_msg_arr removeObjectsFromIndices: (unsigned *)&rid
830                            numIndices: sizeof(rid)/sizeof(rid[0])];
831             }
832
833             o_attr = [NSDictionary dictionaryWithObject: o_gray
834                 forKey: NSForegroundColorAttributeName];
835             o_msg = [NSString stringWithFormat: @"%s%s",
836                 p_intf->p_sys->p_sub->p_msg[i_start].psz_module,
837                 ppsz_type[i_type]];
838             o_msg_color = [[NSAttributedString alloc]
839                 initWithString: o_msg attributes: o_attr];
840             [o_msg_arr addObject: [o_msg_color autorelease]];
841
842             o_attr = [NSDictionary dictionaryWithObject: pp_color[i_type]
843                 forKey: NSForegroundColorAttributeName];
844             o_msg = [NSString stringWithFormat: @"%s\n",
845                 p_intf->p_sys->p_sub->p_msg[i_start].psz_msg];
846             o_msg_color = [[NSAttributedString alloc]
847                 initWithString: o_msg attributes: o_attr];
848             [o_msg_arr addObject: [o_msg_color autorelease]];
849
850             [o_msg_lock unlock];
851
852             if( i_type == 1 )
853             {
854                 NSString *o_my_msg = [NSString stringWithFormat: @"%s: %s\n",
855                     p_intf->p_sys->p_sub->p_msg[i_start].psz_module,
856                     p_intf->p_sys->p_sub->p_msg[i_start].psz_msg];
857
858                 NSRange s_r = NSMakeRange( [[o_err_msg string] length], 0 );
859                 [o_err_msg setEditable: YES];
860                 [o_err_msg setSelectedRange: s_r];
861                 [o_err_msg insertText: o_my_msg];
862
863                 [o_error makeKeyAndOrderFront: self];
864                 [o_err_msg setEditable: NO];
865             }
866         }
867
868         vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
869         p_intf->p_sys->p_sub->i_start = i_start;
870         vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
871     }
872 }
873
874 - (void)playStatusUpdated:(BOOL)b_pause
875 {
876     if( b_pause )
877     {
878         [o_btn_play setImage: o_img_pause];
879         [o_btn_play setToolTip: _NS("Pause")];
880         [o_mi_play setTitle: _NS("Pause")];
881         [o_dmi_play setTitle: _NS("Pause")];
882     }
883     else
884     {
885         [o_btn_play setImage: o_img_play];
886         [o_btn_play setToolTip: _NS("Play")];
887         [o_mi_play setTitle: _NS("Play")];
888         [o_dmi_play setTitle: _NS("Play")];
889     }
890 }
891
892 - (void)setSubmenusEnabled:(BOOL)b_enabled
893 {
894     [o_mi_program setEnabled: b_enabled];
895     [o_mi_title setEnabled: b_enabled];
896     [o_mi_chapter setEnabled: b_enabled];
897     [o_mi_audiotrack setEnabled: b_enabled];
898     [o_mi_videotrack setEnabled: b_enabled];
899     [o_mi_subtitle setEnabled: b_enabled];
900     [o_mi_channels setEnabled: b_enabled];
901     [o_mi_device setEnabled: b_enabled];
902     [o_mi_screen setEnabled: b_enabled];
903 }
904
905 - (void)manageVolumeSlider
906 {
907     audio_volume_t i_volume;
908     intf_thread_t * p_intf = [NSApp getIntf];
909
910     aout_VolumeGet( p_intf, &i_volume );
911
912     [o_volumeslider setFloatValue: (float)i_volume / AOUT_VOLUME_STEP]; 
913     [o_volumeslider setEnabled: TRUE];
914
915     p_intf->p_sys->b_mute = ( i_volume == 0 );
916 }
917
918 - (void)terminate
919 {
920     NSEvent * o_event;
921     vout_thread_t * p_vout;
922     playlist_t * p_playlist;
923     intf_thread_t * p_intf = [NSApp getIntf];
924
925     /*
926      * Free playlists
927      */
928     msg_Dbg( p_intf, "removing all playlists" );
929     while( (p_playlist = vlc_object_find( p_intf->p_vlc, VLC_OBJECT_PLAYLIST,
930                                           FIND_CHILD )) )
931     {
932         vlc_object_detach( p_playlist );
933         vlc_object_release( p_playlist );
934         playlist_Destroy( p_playlist );
935     }
936
937     /*
938      * Free video outputs
939      */
940     msg_Dbg( p_intf, "removing all video outputs" );
941     while( (p_vout = vlc_object_find( p_intf->p_vlc, 
942                                       VLC_OBJECT_VOUT, FIND_CHILD )) )
943     {
944         vlc_object_detach( p_vout );
945         vlc_object_release( p_vout );
946         vout_Destroy( p_vout );
947     }
948
949     if( o_img_pause != nil )
950     {
951         [o_img_pause release];
952         o_img_pause = nil;
953     }
954
955     if( o_img_play != nil )
956     {
957         [o_img_play release];
958         o_img_play = nil;
959     }
960
961     if( o_msg_arr != nil )
962     {
963         [o_msg_arr removeAllObjects];
964         [o_msg_arr release];
965         o_msg_arr = nil;
966     }
967
968     if( o_msg_lock != nil )
969     {
970         [o_msg_lock release];
971         o_msg_lock = nil;
972     }
973
974     if( o_prefs != nil )
975     {
976         [o_prefs release];
977         o_prefs = nil;
978     }
979
980     [NSApp stop: nil];
981
982     /* write cached user defaults to disk */
983     [[NSUserDefaults standardUserDefaults] synchronize];
984
985     /* send a dummy event to break out of the event loop */
986     o_event = [NSEvent mouseEventWithType: NSLeftMouseDown
987                 location: NSMakePoint( 1, 1 ) modifierFlags: 0
988                 timestamp: 1 windowNumber: [[NSApp mainWindow] windowNumber]
989                 context: [NSGraphicsContext currentContext] eventNumber: 1
990                 clickCount: 1 pressure: 0.0];
991     [NSApp postEvent: o_event atStart: YES];
992 }
993
994 - (void)setupMenus:(input_thread_t *)p_input
995 {
996     intf_thread_t * p_intf = [NSApp getIntf];
997     vlc_value_t val;
998
999     if( p_intf->p_sys->b_input_update )
1000     {
1001         val.b_bool = FALSE;
1002
1003         [self setupVarMenu: o_mi_program target: (vlc_object_t *)p_input
1004             var: "program" selector: @selector(toggleVar:)];
1005
1006         [self setupVarMenu: o_mi_title target: (vlc_object_t *)p_input
1007             var: "title" selector: @selector(toggleVar:)];
1008
1009         [self setupVarMenu: o_mi_chapter target: (vlc_object_t *)p_input
1010             var: "chapter" selector: @selector(toggleVar:)];
1011
1012         [self setupVarMenu: o_mi_audiotrack target: (vlc_object_t *)p_input
1013             var: "audio-es" selector: @selector(toggleVar:)];
1014
1015         [self setupVarMenu: o_mi_videotrack target: (vlc_object_t *)p_input
1016             var: "video-es" selector: @selector(toggleVar:)];
1017
1018         [self setupVarMenu: o_mi_subtitle target: (vlc_object_t *)p_input
1019             var: "spu-es" selector: @selector(toggleVar:)];
1020
1021         p_intf->p_sys->b_input_update = FALSE;
1022         var_Set( (vlc_object_t *)p_input, "intf-change", val );
1023     }
1024
1025     if ( p_intf->p_sys->b_aout_update )
1026     {
1027         aout_instance_t * p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT,
1028                                                     FIND_ANYWHERE );
1029
1030         if ( p_aout != NULL )
1031         {
1032             val.b_bool = FALSE;
1033             
1034             [self setupVarMenu: o_mi_channels target: (vlc_object_t *)p_aout
1035                 var: "audio-channels" selector: @selector(toggleVar:)];
1036
1037             [self setupVarMenu: o_mi_device target: (vlc_object_t *)p_aout
1038                 var: "audio-device" selector: @selector(toggleVar:)];
1039             var_Set( (vlc_object_t *)p_aout, "intf-change", val );
1040             
1041             vlc_object_release( (vlc_object_t *)p_aout );
1042         }
1043         p_intf->p_sys->b_aout_update = FALSE;
1044     }
1045
1046     if( p_intf->p_sys->b_vout_update )
1047     {
1048         vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
1049                                                           FIND_ANYWHERE );
1050
1051         if ( p_vout != NULL )
1052         {
1053             val.b_bool = FALSE;
1054
1055             [self setupVarMenu: o_mi_screen target: (vlc_object_t *)p_vout
1056                 var: "video-device" selector: @selector(toggleVar:)];
1057             var_Set( (vlc_object_t *)p_vout, "intf-change", val );
1058             
1059             vlc_object_release( (vlc_object_t *)p_vout );
1060             [o_mi_close_window setEnabled: TRUE];
1061         }
1062         
1063         p_intf->p_sys->b_vout_update = FALSE;
1064     }
1065 }
1066
1067 - (void)setupVarMenu:(NSMenuItem *)o_mi
1068                      target:(vlc_object_t *)p_object
1069                      var:(const char *)psz_variable
1070                      selector:(SEL)pf_callback
1071 {
1072     int i, i_nb_items, i_value;
1073     NSMenu * o_menu = [o_mi submenu];
1074     vlc_value_t val, text;
1075     
1076     [o_mi setTag: (int)psz_variable];
1077     
1078     /* remove previous items */
1079     i_nb_items = [o_menu numberOfItems];
1080     for( i = 0; i < i_nb_items; i++ )
1081     {
1082         [o_menu removeItemAtIndex: 0];
1083     }
1084
1085     if ( var_Get( p_object, psz_variable, &val ) < 0 )
1086     {
1087         return;
1088     }
1089     i_value = val.i_int;
1090
1091     if ( var_Change( p_object, psz_variable,
1092                      VLC_VAR_GETLIST, &val, &text ) < 0 )
1093     {
1094         return;
1095     }
1096
1097     /* make (un)sensitive */
1098     [o_mi setEnabled: ( val.p_list->i_count > 1 )];
1099
1100     for ( i = 0; i < val.p_list->i_count; i++ )
1101     {
1102         NSMenuItem * o_lmi;
1103         NSString * o_title;
1104
1105         if ( text.p_list->p_values[i].psz_string )
1106         {
1107             o_title = [NSApp localizedString: text.p_list->p_values[i].psz_string];
1108         }
1109         else
1110         {
1111             o_title = [NSString stringWithFormat: @"%s - %d",
1112                         strdup(psz_variable), val.p_list->p_values[i].i_int ];
1113         }
1114         o_lmi = [o_menu addItemWithTitle: [o_title copy]
1115                 action: pf_callback keyEquivalent: @""];
1116         
1117         /* FIXME: this isn't 64-bit clean ! */
1118         [o_lmi setTag: val.p_list->p_values[i].i_int];
1119         [o_lmi setRepresentedObject:
1120             [NSValue valueWithPointer: p_object]];
1121         [o_lmi setTarget: o_controls];
1122
1123         if ( i_value == val.p_list->p_values[i].i_int )
1124             [o_lmi setState: NSOnState];
1125     }
1126
1127     var_Change( p_object, psz_variable, VLC_VAR_FREELIST,
1128                 &val, &text );
1129
1130 }
1131
1132 - (IBAction)clearRecentItems:(id)sender
1133 {
1134     [[NSDocumentController sharedDocumentController]
1135                           clearRecentDocuments: nil];
1136 }
1137
1138 - (void)openRecentItem:(id)sender
1139 {
1140     [self application: nil openFile: [sender title]]; 
1141 }
1142
1143 - (IBAction)viewPreferences:(id)sender
1144 {
1145     if( o_prefs == nil )
1146     {
1147         o_prefs = [[VLCPrefs alloc] init];
1148     }
1149
1150     [o_prefs createPrefPanel: @"main"];
1151 }
1152
1153 - (IBAction)timesliderUpdate:(id)sender
1154 {
1155     float f_updated;
1156
1157     switch( [[NSApp currentEvent] type] )
1158     {
1159         case NSLeftMouseUp:
1160         case NSLeftMouseDown:
1161             f_slider = [sender floatValue];
1162             return;
1163
1164         case NSLeftMouseDragged:
1165             f_updated = [sender floatValue];
1166             break;
1167
1168         default:
1169             return;
1170     }
1171
1172     intf_thread_t * p_intf = [NSApp getIntf];
1173
1174     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1175                                                        FIND_ANYWHERE );
1176
1177     if( p_playlist == NULL )
1178     {
1179         return;
1180     }
1181
1182     vlc_mutex_lock( &p_playlist->object_lock );
1183
1184     if( p_playlist->p_input != NULL )
1185     {
1186         off_t i_tell;
1187         NSString * o_time;
1188         char psz_time[ OFFSETTOTIME_MAX_SIZE ];
1189
1190 #define p_area p_playlist->p_input->stream.p_selected_area
1191         vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
1192         i_tell = f_updated / 10000. * p_area->i_size;
1193         input_OffsetToTime( p_playlist->p_input, psz_time, i_tell );
1194         vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1195 #undef p_area
1196
1197         o_time = [NSString stringWithCString: psz_time];
1198         [o_timefield setStringValue: o_time]; 
1199     }
1200
1201     vlc_mutex_unlock( &p_playlist->object_lock );
1202     vlc_object_release( p_playlist );
1203 }
1204
1205 - (IBAction)closeError:(id)sender
1206 {
1207     [o_err_msg setString: @""];
1208     [o_error performClose: self];
1209 }
1210
1211 - (IBAction)openReadMe:(id)sender
1212 {
1213     NSString * o_path = [[NSBundle mainBundle] 
1214         pathForResource: @"README.MacOSX" ofType: @"rtf"]; 
1215
1216     [[NSWorkspace sharedWorkspace] openFile: o_path 
1217                                    withApplication: @"TextEdit"];
1218 }
1219
1220 - (IBAction)reportABug:(id)sender
1221 {
1222     NSURL * o_url = [NSURL URLWithString: 
1223         @"http://www.videolan.org/support/bug-reporting.html"];
1224
1225     [[NSWorkspace sharedWorkspace] openURL: o_url];
1226 }
1227
1228 - (IBAction)openWebsite:(id)sender
1229 {
1230     NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org"];
1231
1232     [[NSWorkspace sharedWorkspace] openURL: o_url];
1233 }
1234
1235 - (IBAction)openLicense:(id)sender
1236 {
1237     NSString * o_path = [[NSBundle mainBundle] 
1238         pathForResource: @"COPYING" ofType: nil];
1239
1240     [[NSWorkspace sharedWorkspace] openFile: o_path 
1241                                    withApplication: @"TextEdit"];
1242 }
1243
1244 - (IBAction)openCrashLog:(id)sender
1245 {
1246     NSString * o_path = [@"~/Library/Logs/CrashReporter/VLC.crash.log"
1247                                     stringByExpandingTildeInPath]; 
1248
1249     
1250     if ( [[NSFileManager defaultManager] fileExistsAtPath: o_path ] )
1251     {
1252         [[NSWorkspace sharedWorkspace] openFile: o_path 
1253                                     withApplication: @"Console"];
1254     }
1255     else
1256     {
1257         NSBeginInformationalAlertSheet(_NS("No CrashLog found"), @"Continue", nil, nil, o_msgs_panel, self, NULL, NULL, nil, _NS("Either you are running Mac OS X pre 10.2 or you haven't experienced any heavy crashes yet.") );
1258
1259     }
1260 }
1261
1262 - (void)windowDidBecomeKey:(NSNotification *)o_notification
1263 {
1264     if( [o_notification object] == o_msgs_panel )
1265     {
1266         id o_msg;
1267         NSEnumerator * o_enum;
1268
1269         [o_messages setString: @""]; 
1270
1271         [o_msg_lock lock];
1272
1273         o_enum = [o_msg_arr objectEnumerator];
1274
1275         while( ( o_msg = [o_enum nextObject] ) != nil )
1276         {
1277             [o_messages insertText: o_msg];
1278         }
1279
1280         [o_msg_lock unlock];
1281     }
1282 }
1283
1284 @end
1285
1286 @implementation VLCMain (NSMenuValidation)
1287
1288 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
1289 {
1290     BOOL bEnabled = TRUE;
1291
1292     /* Recent Items Menu */
1293
1294     if( [[o_mi title] isEqualToString: _NS("Clear Menu")] )
1295     {
1296         NSMenu * o_menu = [o_mi_open_recent submenu];
1297         int i_nb_items = [o_menu numberOfItems];
1298         NSArray * o_docs = [[NSDocumentController sharedDocumentController]
1299                                                        recentDocumentURLs];
1300         UInt32 i_nb_docs = [o_docs count];
1301
1302         if( i_nb_items > 1 )
1303         {
1304             while( --i_nb_items )
1305             {
1306                 [o_menu removeItemAtIndex: 0];
1307             }
1308         }
1309
1310         if( i_nb_docs > 0 )
1311         {
1312             NSURL * o_url;
1313             NSString * o_doc;
1314
1315             [o_menu insertItem: [NSMenuItem separatorItem] atIndex: 0];
1316
1317             while( TRUE )
1318             {
1319                 i_nb_docs--;
1320
1321                 o_url = [o_docs objectAtIndex: i_nb_docs];
1322
1323                 if( [o_url isFileURL] )
1324                 {
1325                     o_doc = [o_url path];
1326                 }
1327                 else
1328                 {
1329                     o_doc = [o_url absoluteString];
1330                 }
1331
1332                 [o_menu insertItemWithTitle: o_doc
1333                     action: @selector(openRecentItem:)
1334                     keyEquivalent: @"" atIndex: 0]; 
1335
1336                 if( i_nb_docs == 0 )
1337                 {
1338                     break;
1339                 }
1340             } 
1341         }
1342         else
1343         {
1344             bEnabled = FALSE;
1345         }
1346     }
1347
1348     return( bEnabled );
1349 }
1350
1351 @end
1352
1353 @implementation VLCMain (Internal)
1354
1355 - (void)handlePortMessage:(NSPortMessage *)o_msg
1356 {
1357     id ** val;
1358     NSData * o_data;
1359     NSValue * o_value;
1360     NSInvocation * o_inv;
1361     NSConditionLock * o_lock;
1362  
1363     o_data = [[o_msg components] lastObject];
1364     o_inv = *((NSInvocation **)[o_data bytes]); 
1365     [o_inv getArgument: &o_value atIndex: 2];
1366     val = (id **)[o_value pointerValue];
1367     [o_inv setArgument: val[1] atIndex: 2];
1368     o_lock = *(val[0]);
1369
1370     [o_lock lock];
1371     [o_inv invoke];
1372     [o_lock unlockWithCondition: 1];
1373 }
1374
1375 @end