]> git.sesse.net Git - vlc/blob - projects/macosx/framework/Sources/VLCLibrary.m
MobileVLCKit: updated libvlc initialization to current API
[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 #if TARGET_OS_IPHONE
29 # include "vlc-plugins.h"
30 #endif
31
32 #ifdef HAVE_CONFIG_H
33 # include "config.h"
34 #endif
35
36 #include <vlc/vlc.h>
37 #include <vlc/libvlc_structures.h>
38
39 static VLCLibrary * sharedLibrary = nil;
40
41 @implementation VLCLibrary
42 + (VLCLibrary *)sharedLibrary
43 {
44     if (!sharedLibrary)
45     {
46         /* Initialize a shared instance */
47         sharedLibrary = [[self alloc] init];
48     }
49     return sharedLibrary;
50 }
51
52 - (id)init
53 {
54     if (self = [super init])
55     {
56         NSArray *vlcParams = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"VLCParams"];
57         if (!vlcParams) {
58             NSMutableArray *defaultParams = [NSMutableArray array];
59             [defaultParams addObject:@"--play-and-pause"];                          // We want every movie to pause instead of stopping at eof
60             [defaultParams addObject:@"--no-color"];                                // Don't use color in output (Xcode doesn't show it)
61             [defaultParams addObject:@"--no-video-title-show"];                     // Don't show the title on overlay when starting to play
62             [defaultParams addObject:@"--verbose=-1"];                               // Let's not wreck the logs
63 #if TARGET_OS_IPHONE
64 //            [defaultParams addObject:@"--ffmpeg-fast"];                             // Let's disable this as it is error-prone
65             [defaultParams addObject:@"--ffmpeg-skiploopfilter=all"];
66 #else
67             [defaultParams addObject:@"--no-sout-keep"];
68             [defaultParams addObject:@"--vout=macosx"];                             // Select Mac OS X video output
69             [defaultParams addObject:@"--text-renderer=quartztext"];                // our CoreText-based renderer
70             [defaultParams addObject:@"--extraintf=macosx_dialog_provider"];        // Some extra dialog (login, progress) may come up from here
71 #endif
72             vlcParams = defaultParams;
73         }
74
75         NSUInteger paramNum = 0;
76         NSUInteger count = [vlcParams count];
77         const char *lib_vlc_params[count];
78         while (paramNum < count) {
79             NSString *vlcParam = [vlcParams objectAtIndex:paramNum];
80             lib_vlc_params[paramNum] = [vlcParam cStringUsingEncoding:NSASCIIStringEncoding];
81             paramNum++;
82         }
83         unsigned argc = sizeof(lib_vlc_params)/sizeof(lib_vlc_params[0]);
84         instance = libvlc_new(argc, lib_vlc_params);
85         NSAssert(instance, @"libvlc failed to initialize");
86     }
87     return self;
88 }
89
90 - (NSString *)version
91 {
92     return [NSString stringWithUTF8String:libvlc_get_version()];
93 }
94
95 - (NSString *)changeset
96 {
97     return [NSString stringWithUTF8String:libvlc_get_changeset()];
98 }
99
100 - (void)dealloc
101 {
102     if( instance )
103         libvlc_release( instance );
104
105     if( self == sharedLibrary )
106         sharedLibrary = nil;
107
108     instance = nil;
109     [super dealloc];
110 }
111
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