VLCKit: Import MobileVLCKit.
[vlc/asuraparaju-public.git] / projects / macosx / framework / Sources / VLCLibrary.m
blobc7ef7e726378fbb3f17cb2292b52d13a5c2f567c
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  *****************************************************************************/
25 #import "VLCLibrary.h"
26 #import "VLCLibVLCBridging.h"
28 #if TARGET_OS_IPHONE
29 # include "vlc-plugins.h"
30 #endif
32 #ifdef HAVE_CONFIG_H
33 # include "config.h"
34 #endif
36 #include <vlc/vlc.h>
37 #include <vlc/libvlc_structures.h>
39 static VLCLibrary * sharedLibrary = nil;
41 @implementation VLCLibrary
42 + (VLCLibrary *)sharedLibrary
44     if (!sharedLibrary)
45     {
46         /* Initialize a shared instance */
47         sharedLibrary = [[self alloc] init];
48     }
49     return sharedLibrary;
52 - (id)init
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-media-library"];                        // We don't need the media library
62             [defaultParams addObject:@"--no-video-title-show"];                     // Don't show the title on overlay when starting to play
63             [defaultParams addObject:@"--verbose=-1"];                               // Let's not wreck the logs
64 #if TARGET_OS_IPHONE
65             [defaultParams addObject:@"--ignore-config"];                           // We don't need the config
66 //            [defaultParams addObject:@"--ffmpeg-fast"];                             // Let's disable this as it is error-prone
67             [defaultParams addObject:@"--ffmpeg-skiploopfilter=all"];
68 #else
69             [defaultParams addObject:@"--no-sout-keep"];
70             [defaultParams addObject:@"--vout=macosx"];                             // Select Mac OS X video output
71             [defaultParams addObject:@"--text-renderer=quartztext"];                // our CoreText-based renderer
72             [defaultParams addObject:@"--extraintf=macosx_dialog_provider"];        // Some extra dialog (login, progress) may come up from here
73 #endif
74             vlcParams = defaultParams;
75         }
77         NSUInteger paramNum = 0;
78         NSUInteger count = [vlcParams count];
79         const char *lib_vlc_params[count];
80         while (paramNum < count) {
81             NSString *vlcParam = [vlcParams objectAtIndex:paramNum];
82             lib_vlc_params[paramNum] = [vlcParam cStringUsingEncoding:NSASCIIStringEncoding];
83             paramNum++;
84         }
85         unsigned argc = sizeof(lib_vlc_params)/sizeof(lib_vlc_params[0]);
86 #if TARGET_OS_IPHONE
87         instance = libvlc_new_with_builtins(argc, lib_vlc_params, vlc_builtins_modules);
88 #else
89         instance = libvlc_new(argc, lib_vlc_params);
90 #endif
91         NSAssert(instance, @"libvlc failed to initialize");
92     }
93     return self;
96 - (NSString *)version
98     return [NSString stringWithUTF8String:libvlc_get_version()];
101 - (NSString *)changeset
103     return [NSString stringWithUTF8String:libvlc_get_changeset()];
106 - (void)dealloc
108     if( instance )
109         libvlc_release( instance );
111     if( self == sharedLibrary )
112         sharedLibrary = nil;
114     instance = nil;
115     [super dealloc];
118 @end
120 @implementation VLCLibrary (VLCLibVLCBridging)
121 + (void *)sharedInstance
123     return [self sharedLibrary].instance;
126 - (void *)instance
128     return instance;
130 @end