1 /*****************************************************************************
2 * VLCLibrary.m: VLCKit.framework VLCLibrary implementation
3 *****************************************************************************
4 * Copyright (C) 2007 Pierre d'Herbemont
5 * Copyright (C) 2007 the VideoLAN team
8 * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #import "VLCLibrary.h"
26 #import "VLCLibVLCBridging.h"
33 #include <vlc/libvlc_structures.h>
35 static VLCLibrary * sharedLibrary = nil;
37 void __catch_exception( void * e, const char * function, const char * file, int line_number )
39 libvlc_exception_t * ex = (libvlc_exception_t *)e;
40 if( libvlc_exception_raised( ex ) )
42 NSException* libvlcException = [NSException
43 exceptionWithName:@"LibVLCException"
44 reason:[NSString stringWithFormat:@"libvlc has thrown us an error: %s (%s:%d %s)",
45 libvlc_errmsg(), file, line_number, function]
47 libvlc_exception_clear( ex );
48 @throw libvlcException;
52 void * CreateSharedLibraryOnStartup( void )
54 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
56 /* This library is not loaded for no reason, so let's create
57 * a VLCLibrary instance. */
58 [VLCLibrary sharedLibrary];
65 void * DestroySharedLibraryAtExit( void )
67 /* Release the global object that may have been alloc-ed
68 * in -[VLCLibrary init] */
69 [sharedLibrary release];
75 @implementation VLCLibrary
76 + (VLCLibrary *)sharedLibrary
80 /* Initialize a shared instance */
81 sharedLibrary = [[self alloc] init];
88 if (self = [super init])
90 libvlc_exception_t ex;
91 libvlc_exception_init( &ex );
93 const char * lib_vlc_params[] = {
94 "-I", "dummy", // No interface
95 "--no-video-title-show", // Don't show the title on overlay when starting to play
97 "--ignore-config", // Don't read and write VLC config files.
98 "--opengl-provider=minimal_macosx", // Use minimal_macosx
99 "--vout=minimal_macosx",
100 "-verbose=-1", // Don't polute the log
101 "--play-and-pause" // When ending a stream pause it instead of stopping it.
102 //, "--control=motion", "--motion-use-rotate", "--video-filter=rotate"
105 instance = (void *)libvlc_new( sizeof(lib_vlc_params)/sizeof(lib_vlc_params[0]), lib_vlc_params, &ex );
106 catch_exception( &ex );
108 // Assignment unneeded, as the audio unit will do it for us
109 /*audio = */ [[VLCAudio alloc] initWithLibrary:self];
117 libvlc_release( instance );
119 if( self == sharedLibrary )
130 @implementation VLCLibrary (VLCLibVLCBridging)
131 + (void *)sharedInstance
133 return [self sharedLibrary].instance;
142 @implementation VLCLibrary (VLCAudioBridging)
143 - (void)setAudio:(VLCAudio *)value