VLCLibrary.m 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. @implementation VLCLibrary
  36. + (VLCLibrary *)sharedLibrary
  37. {
  38. if (!sharedLibrary)
  39. {
  40. /* Initialize a shared instance */
  41. sharedLibrary = [[self alloc] init];
  42. }
  43. return sharedLibrary;
  44. }
  45. - (id)init
  46. {
  47. if (self = [super init])
  48. {
  49. NSArray *vlcParams;
  50. #if TARGET_OS_IPHONE
  51. vlcParams = [NSArray arrayWithObjects:@"--play-and-pause", @"--no-color", @"--no-video-title-show", @"--verbose=2", @"--avcodec-fast", @"--avcodec-skiploopfilter=all", @"--vout=vout_ios", @"--aout=audioqueue", nil];
  52. #else
  53. vlcParams = [[NSUserDefaults standardUserDefaults] objectForKey:@"VLCParams"];
  54. if (!vlcParams) {
  55. NSMutableArray *defaultParams = [NSMutableArray array];
  56. [defaultParams addObject:@"--play-and-pause"]; // We want every movie to pause instead of stopping at eof
  57. [defaultParams addObject:@"--no-color"]; // Don't use color in output (Xcode doesn't show it)
  58. [defaultParams addObject:@"--no-video-title-show"]; // Don't show the title on overlay when starting to play
  59. [defaultParams addObject:@"--verbose=4"]; // Let's not wreck the logs
  60. [defaultParams addObject:@"--no-sout-keep"];
  61. [defaultParams addObject:@"--vout=macosx"]; // Select Mac OS X video output
  62. [defaultParams addObject:@"--text-renderer=quartztext"]; // our CoreText-based renderer
  63. [defaultParams addObject:@"--extraintf=macosx_dialog_provider"]; // Some extra dialog (login, progress) may come up from here
  64. [[NSUserDefaults standardUserDefaults] setObject:defaultParams forKey:@"VLCParams"];
  65. [[NSUserDefaults standardUserDefaults] synchronize];
  66. vlcParams = defaultParams;
  67. }
  68. #endif
  69. NSUInteger paramNum = 0;
  70. NSUInteger count = [vlcParams count];
  71. const char *lib_vlc_params[count];
  72. while (paramNum < count) {
  73. NSString *vlcParam = [vlcParams objectAtIndex:paramNum];
  74. lib_vlc_params[paramNum] = [vlcParam cStringUsingEncoding:NSASCIIStringEncoding];
  75. paramNum++;
  76. }
  77. unsigned argc = sizeof(lib_vlc_params)/sizeof(lib_vlc_params[0]);
  78. instance = libvlc_new(argc, lib_vlc_params);
  79. NSAssert(instance, @"libvlc failed to initialize");
  80. }
  81. return self;
  82. }
  83. - (NSString *)version
  84. {
  85. return [NSString stringWithUTF8String:libvlc_get_version()];
  86. }
  87. - (NSString *)changeset
  88. {
  89. return [NSString stringWithUTF8String:libvlc_get_changeset()];
  90. }
  91. - (void)dealloc
  92. {
  93. if( instance )
  94. libvlc_release( instance );
  95. if( self == sharedLibrary )
  96. sharedLibrary = nil;
  97. instance = nil;
  98. [super dealloc];
  99. }
  100. @end
  101. @implementation VLCLibrary (VLCLibVLCBridging)
  102. + (void *)sharedInstance
  103. {
  104. return [self sharedLibrary].instance;
  105. }
  106. - (void *)instance
  107. {
  108. return instance;
  109. }
  110. @end