VLCLibrary.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. #import "VLCLibrary.h"
  25. #import "VLCLibVLCBridging.h"
  26. #ifdef HAVE_CONFIG_H
  27. # include "config.h"
  28. #endif
  29. #include <vlc/vlc.h>
  30. #include <vlc/libvlc_structures.h>
  31. static VLCLibrary * sharedLibrary = nil;
  32. @implementation VLCLibrary
  33. + (VLCLibrary *)sharedLibrary
  34. {
  35. if (!sharedLibrary)
  36. {
  37. /* Initialize a shared instance */
  38. sharedLibrary = [[self alloc] init];
  39. }
  40. return sharedLibrary;
  41. }
  42. - (id)init
  43. {
  44. if (self = [super init])
  45. {
  46. NSArray *vlcParams = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"VLCParams"];
  47. if (!vlcParams) {
  48. NSMutableArray *defaultParams = [NSMutableArray array];
  49. [defaultParams addObject:@"--no-video-title-show"]; // Don't show the title on overlay when starting to play
  50. [defaultParams addObject:@"--no-sout-keep"];
  51. [defaultParams addObject:@"--vout=macosx"]; // Select Mac OS X video output
  52. [defaultParams addObject:@"--text-renderer=quartztext"]; // our CoreText-based renderer
  53. [defaultParams addObject:@"--verbose=-1"]; // Don't polute the stdio log
  54. [defaultParams addObject:@"--no-color"]; // Don't use color in output (Xcode doesn't show it)
  55. [defaultParams addObject:@"--no-media-library"]; // We don't need the media library
  56. [defaultParams addObject:@"--play-and-pause"]; // We want every movie to pause instead of stopping at eof
  57. [defaultParams addObject:@"--extraintf=macosx_dialog_provider"]; // Some extra dialog (login, progress) may come up from here
  58. vlcParams = defaultParams;
  59. }
  60. NSUInteger paramNum = 0;
  61. NSUInteger count = [vlcParams count];
  62. const char *lib_vlc_params[count];
  63. while (paramNum < count) {
  64. NSString *vlcParam = [vlcParams objectAtIndex:paramNum];
  65. lib_vlc_params[paramNum] = [vlcParam cStringUsingEncoding:NSASCIIStringEncoding];
  66. paramNum++;
  67. }
  68. instance = (void *)libvlc_new( sizeof(lib_vlc_params)/sizeof(lib_vlc_params[0]), lib_vlc_params);
  69. NSAssert(instance, @"libvlc failed to initialize");
  70. }
  71. return self;
  72. }
  73. - (NSString *)version
  74. {
  75. return [NSString stringWithUTF8String:libvlc_get_version()];
  76. }
  77. - (NSString *)changeset
  78. {
  79. return [NSString stringWithUTF8String:libvlc_get_changeset()];
  80. }
  81. - (void)dealloc
  82. {
  83. if( instance )
  84. libvlc_release( instance );
  85. if( self == sharedLibrary )
  86. sharedLibrary = nil;
  87. instance = nil;
  88. [super dealloc];
  89. }
  90. @end
  91. @implementation VLCLibrary (VLCLibVLCBridging)
  92. + (void *)sharedInstance
  93. {
  94. return [self sharedLibrary].instance;
  95. }
  96. - (void *)instance
  97. {
  98. return instance;
  99. }
  100. @end