VLCLibrary.m 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*****************************************************************************
  2. * VLCLibrary.m: VLCKit.framework VLCLibrary implementation
  3. *****************************************************************************
  4. * Copyright (C) 2007 Pierre d'Herbemont
  5. * Copyright (C) 2007 VLC authors and VideoLAN
  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 it
  11. * under the terms of the GNU Lesser General Public License as published by
  12. * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public License
  21. * along with this program; if not, write to the Free Software Foundation,
  22. * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  23. *****************************************************************************/
  24. #import "VLCLibrary.h"
  25. #import "VLCLibVLCBridging.h"
  26. #if TARGET_OS_IPHONE
  27. # include "vlc-plugins.h"
  28. #endif
  29. #ifdef HAVE_CONFIG_H
  30. # include "config.h"
  31. #endif
  32. #include <vlc/vlc.h>
  33. #include <vlc/libvlc_structures.h>
  34. static VLCLibrary * sharedLibrary = nil;
  35. @interface VLCLibrary()
  36. @property (nonatomic, assign) void *instance;
  37. @end
  38. @implementation VLCLibrary
  39. + (VLCLibrary *)sharedLibrary
  40. {
  41. static dispatch_once_t onceToken;
  42. dispatch_once(&onceToken, ^{
  43. sharedLibrary = [[self alloc] init];
  44. });
  45. return sharedLibrary;
  46. }
  47. + (void *)sharedInstance
  48. {
  49. return [self sharedLibrary].instance;
  50. }
  51. - (instancetype)init
  52. {
  53. if (self = [super init]) {
  54. [self prepareInstanceWithOptions:nil];
  55. }
  56. return self;
  57. }
  58. - (instancetype)initWithOptions:(NSArray*)options
  59. {
  60. if (self = [super init]) {
  61. [self prepareInstanceWithOptions:options];
  62. }
  63. return self;
  64. }
  65. - (void)prepareInstanceWithOptions:(NSArray *)options
  66. {
  67. NSArray *allOptions = options ? [[self _defaultOptions] arrayByAddingObjectsFromArray:options] : [self _defaultOptions];
  68. NSUInteger paramNum = 0;
  69. int count = (int)allOptions.count;
  70. const char *lib_vlc_params[count];
  71. while (paramNum < count) {
  72. lib_vlc_params[paramNum] = [allOptions[paramNum] cStringUsingEncoding:NSASCIIStringEncoding];
  73. paramNum++;
  74. }
  75. _instance = libvlc_new(count, lib_vlc_params);
  76. if (_instance)
  77. libvlc_retain(_instance);
  78. NSAssert(_instance, @"libvlc failed to initialize");
  79. }
  80. - (NSArray *)_defaultOptions
  81. {
  82. NSArray *vlcParams = [[NSUserDefaults standardUserDefaults] objectForKey:@"VLCParams"];
  83. #if TARGET_OS_IPHONE
  84. if (!vlcParams) {
  85. vlcParams = @[@"--no-color",
  86. @"--no-osd",
  87. @"--no-video-title-show",
  88. @"--no-stats",
  89. @"--avcodec-fast",
  90. @"--verbose=0",
  91. @"--text-renderer=quartztext",
  92. @"--avi-index=3",
  93. @"--extraintf=ios_dialog_provider"];
  94. }
  95. #else
  96. if (!vlcParams) {
  97. NSMutableArray *defaultParams = [NSMutableArray array];
  98. [defaultParams addObject:@"--play-and-pause"]; // We want every movie to pause instead of stopping at eof
  99. [defaultParams addObject:@"--no-color"]; // Don't use color in output (Xcode doesn't show it)
  100. [defaultParams addObject:@"--no-video-title-show"]; // Don't show the title on overlay when starting to play
  101. [defaultParams addObject:@"--verbose=4"]; // Let's not wreck the logs
  102. [defaultParams addObject:@"--no-sout-keep"];
  103. [defaultParams addObject:@"--vout=macosx"]; // Select Mac OS X video output
  104. [defaultParams addObject:@"--text-renderer=quartztext"]; // our CoreText-based renderer
  105. [defaultParams addObject:@"--extraintf=macosx_dialog_provider"]; // Some extra dialog (login, progress) may come up from here
  106. [[NSUserDefaults standardUserDefaults] setObject:defaultParams forKey:@"VLCParams"];
  107. [[NSUserDefaults standardUserDefaults] synchronize];
  108. vlcParams = defaultParams;
  109. }
  110. #endif
  111. return vlcParams;
  112. }
  113. - (NSString *)version
  114. {
  115. return @(libvlc_get_version());
  116. }
  117. - (NSString *)compiler
  118. {
  119. return @(libvlc_get_compiler());
  120. }
  121. - (NSString *)changeset
  122. {
  123. return @(libvlc_get_changeset());
  124. }
  125. - (void)setHumanReadableName:(NSString *)readableName withHTTPUserAgent:(NSString *)userAgent
  126. {
  127. if (_instance)
  128. libvlc_set_user_agent(_instance, [readableName UTF8String], [userAgent UTF8String]);
  129. }
  130. - (void)setApplicationIdentifier:(NSString *)identifier withVersion:(NSString *)version andApplicationIconName:(NSString *)icon
  131. {
  132. if (_instance)
  133. libvlc_set_app_id(_instance, [identifier UTF8String], [version UTF8String], [icon UTF8String]);
  134. }
  135. - (void)dealloc
  136. {
  137. if (_instance)
  138. libvlc_release(_instance);
  139. }
  140. @end