]> git.sesse.net Git - vlc/blob - projects/macosx/framework/Sources/VLCLibrary.m
removed unused exceptions
[vlc] / projects / macosx / framework / Sources / VLCLibrary.m
1 /*****************************************************************************
2  * VLCLibrary.m: VLCKit.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 @implementation VLCLibrary
38 + (VLCLibrary *)sharedLibrary
39 {
40     if (!sharedLibrary)
41     {
42         /* Initialize a shared instance */
43         sharedLibrary = [[self alloc] init];
44     }
45     return sharedLibrary;
46 }
47
48 - (id)init
49 {
50     if (self = [super init])
51     {
52
53         NSArray *vlcParams = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"VLCParams"];
54         if (!vlcParams) {
55             NSMutableArray *defaultParams = [NSMutableArray array];
56             [defaultParams addObject:@"--no-video-title-show"];                     // Don't show the title on overlay when starting to play
57             [defaultParams addObject:@"--no-sout-keep"];
58             [defaultParams addObject:@"--ignore-config"];                           // Don't read and write VLC config files
59             [defaultParams addObject:@"--vout=macosx"];                             // Select Mac OS X video output
60             [defaultParams addObject:@"--text-renderer=quartztext"];                // our CoreText-based renderer
61             [defaultParams addObject:@"--verbose=-1"];                              // Don't polute the stdio log
62             [defaultParams addObject:@"--syslog"];                                  // log to syslog
63             [defaultParams addObject:@"--log-verbose=4"];                           // log everything
64             [defaultParams addObject:@"--no-color"];                                // Don't use color in output (Xcode doesn't show it)
65             [defaultParams addObject:@"--no-media-library"];                        // We don't need the media library
66             [defaultParams addObject:@"--play-and-pause"];                          // We want every movie to pause instead of stopping at eof
67             [defaultParams addObject:@"--extraintf=macosx_dialog_provider"];        // Some extra dialog (login, progress) may come up from here
68             vlcParams = defaultParams;
69         }
70
71         NSUInteger paramNum = 0;
72         NSUInteger count = [vlcParams count];
73         const char *lib_vlc_params[count];
74         while (paramNum < count) {
75             NSString *vlcParam = [vlcParams objectAtIndex:paramNum];
76             lib_vlc_params[paramNum] = [vlcParam cStringUsingEncoding:NSASCIIStringEncoding];
77             paramNum++;
78         }
79         instance = (void *)libvlc_new( sizeof(lib_vlc_params)/sizeof(lib_vlc_params[0]), lib_vlc_params);
80         NSAssert(instance, @"libvlc failed to initialize");
81     }
82     return self;
83 }
84
85 - (NSString *)version
86 {
87     return [NSString stringWithUTF8String:libvlc_get_version()];
88 }
89
90 - (NSString *)changeset
91 {
92     return [NSString stringWithUTF8String:libvlc_get_changeset()];
93 }
94
95 - (void)dealloc
96 {
97     if( instance )
98         libvlc_release( instance );
99
100     if( self == sharedLibrary )
101         sharedLibrary = nil;
102
103     instance = nil;
104     [super dealloc];
105 }
106
107 @end
108
109 @implementation VLCLibrary (VLCLibVLCBridging)
110 + (void *)sharedInstance
111 {
112     return [self sharedLibrary].instance;
113 }
114
115 - (void *)instance
116 {
117     return instance;
118 }
119 @end
120