]> git.sesse.net Git - vlc/blob - projects/macosx/framework/Sources/VLCLibrary.m
framework: Fix the configure script. Fix a bunch of warnings.
[vlc] / projects / macosx / framework / Sources / VLCLibrary.m
1 /*****************************************************************************
2  * VLCLibrary.h: VLC.framework VLCLibrary implementation
3  *****************************************************************************
4  * Copyright (C) 2007 Pierre d'Herbemont
5  * Copyright (C) 2007 the VideoLAN team
6  * $Id$
7  *
8  * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #import "VLCLibrary.h"
26 #import "VLCLibVLCBridging.h"
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <vlc/vlc.h>
33 #include <vlc/libvlc_structures.h>
34
35 static VLCLibrary * sharedLibrary = nil;
36
37 void __catch_exception( void * e, const char * function, const char * file, int line_number )
38 {
39     libvlc_exception_t * ex = (libvlc_exception_t *)e;
40     if( libvlc_exception_raised( ex ) )
41     {
42         NSException* libvlcException = [NSException
43             exceptionWithName:@"LibVLCException"
44             reason:[NSString stringWithFormat:@"libvlc has thrown us an error: %s (%s:%d %s)", 
45                 libvlc_exception_get_message( ex ), file, line_number, function]
46             userInfo:nil];
47         libvlc_exception_clear( ex );
48         @throw libvlcException;
49     }
50 }
51
52 static void * DestroySharedLibraryAtExit( void )
53 {
54     /* Release the global object that may have been alloc-ed
55      * in -[VLCLibrary init] */
56     [sharedLibrary release];
57     sharedLibrary = nil;
58
59     return NULL;
60 }
61
62 @implementation VLCLibrary
63 + (VLCLibrary *)sharedLibrary
64 {
65     if (!sharedLibrary) 
66     {
67         /* Initialize a shared instance */
68         sharedLibrary = [[self alloc] init];
69         
70         /* Make sure, this will get released at some point */
71         atexit( (void *)DestroySharedLibraryAtExit );
72     }
73     return [[sharedLibrary retain] autorelease];
74 }
75
76 - (id)init 
77 {
78     if (self = [super init]) 
79     {
80         libvlc_exception_t ex;
81         libvlc_exception_init( &ex );
82         
83         const char * lib_vlc_params[] = { 
84             "-I", "dummy", "--vout=opengllayer", 
85             "--no-video-title-show", "--no-sout-keep"
86             //, "--control=motion", "--motion-use-rotate", "--video-filter=rotate"
87         };
88         
89         instance = (void *)libvlc_new( sizeof(lib_vlc_params)/sizeof(lib_vlc_params[0]), lib_vlc_params, &ex );
90         catch_exception( &ex );
91         
92         // Assignment unneeded, as the audio unit will do it for us
93         /*audio = */ [[VLCAudio alloc] initWithLibrary:self];
94     }
95     return self;
96 }
97
98 - (void)dealloc 
99 {
100     if( instance ) 
101         libvlc_release( instance );
102     
103     if( self == sharedLibrary ) 
104         sharedLibrary = nil;
105     
106     instance = nil;
107     [audio release];
108     [super dealloc];
109 }
110
111 @synthesize audio;
112 @end
113
114 @implementation VLCLibrary (VLCLibVLCBridging)
115 + (void *)sharedInstance
116 {
117     return [self sharedLibrary].instance;
118 }
119
120 - (void *)instance
121 {
122     return instance;
123 }
124 @end
125
126 @implementation VLCLibrary (VLCAudioBridging)
127 - (void)setAudio:(VLCAudio *)value
128 {
129     if (!audio)
130         audio = value;
131 }
132 @end