VLCLibrary.m 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. void __catch_exception( void * e, const char * function, const char * file, int line_number )
  33. {
  34. libvlc_exception_t * ex = (libvlc_exception_t *)e;
  35. if( libvlc_exception_raised( ex ) )
  36. {
  37. NSException* libvlcException = [NSException
  38. exceptionWithName:@"LibVLCException"
  39. reason:[NSString stringWithFormat:@"libvlc has thrown us an error: %s (%s:%d %s)",
  40. libvlc_errmsg(), file, line_number, function]
  41. userInfo:nil];
  42. libvlc_exception_clear( ex );
  43. @throw libvlcException;
  44. }
  45. }
  46. @implementation VLCLibrary
  47. + (VLCLibrary *)sharedLibrary
  48. {
  49. if (!sharedLibrary)
  50. {
  51. /* Initialize a shared instance */
  52. sharedLibrary = [[self alloc] init];
  53. }
  54. return sharedLibrary;
  55. }
  56. - (id)init
  57. {
  58. if (self = [super init])
  59. {
  60. libvlc_exception_t ex;
  61. libvlc_exception_init( &ex );
  62. NSArray *vlcParams = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"VLCParams"];
  63. if (!vlcParams) {
  64. NSMutableArray *defaultParams = [NSMutableArray array];
  65. [defaultParams addObject:@"-I dummy"]; // No interface
  66. [defaultParams addObject:@"--no-video-title-show"]; // Don't show the title on overlay when starting to play
  67. [defaultParams addObject:@"--no-sout-keep"];
  68. [defaultParams addObject:@"--ignore-config"]; // Don't read and write VLC config files
  69. [defaultParams addObject:@"--opengl-provider=minimal_macosx"]; // Use minimal_macosx
  70. [defaultParams addObject:@"--vout=minimal_macosx"];
  71. [defaultParams addObject:@"--text-renderer=quartztext"]; // our CoreText-based renderer
  72. [defaultParams addObject:@"--verbose=2"]; // Don't polute the log
  73. [defaultParams addObject:@"--no-color"];
  74. [defaultParams addObject:@"--no-media-library"];
  75. vlcParams = defaultParams;
  76. }
  77. int paramNum = 0;
  78. const char *lib_vlc_params[[vlcParams count]];
  79. while (paramNum < [vlcParams count]) {
  80. NSString *vlcParam = [vlcParams objectAtIndex:paramNum];
  81. lib_vlc_params[paramNum] = [vlcParam cStringUsingEncoding:NSASCIIStringEncoding];
  82. paramNum++;
  83. }
  84. instance = (void *)libvlc_new( sizeof(lib_vlc_params)/sizeof(lib_vlc_params[0]), lib_vlc_params, &ex );
  85. catch_exception( &ex );
  86. NSAssert(instance, @"libvlc failed to initialize");
  87. // Assignment unneeded, as the audio unit will do it for us
  88. /*audio = */ [[VLCAudio alloc] initWithLibrary:self];
  89. }
  90. return self;
  91. }
  92. - (NSString *)version
  93. {
  94. return [NSString stringWithUTF8String:libvlc_get_version()];
  95. }
  96. - (NSString *)changeset
  97. {
  98. return [NSString stringWithUTF8String:libvlc_get_changeset()];
  99. }
  100. - (void)dealloc
  101. {
  102. if( instance )
  103. libvlc_release( instance );
  104. if( self == sharedLibrary )
  105. sharedLibrary = nil;
  106. instance = nil;
  107. [audio release];
  108. [super dealloc];
  109. }
  110. @synthesize audio;
  111. @end
  112. @implementation VLCLibrary (VLCLibVLCBridging)
  113. + (void *)sharedInstance
  114. {
  115. return [self sharedLibrary].instance;
  116. }
  117. - (void *)instance
  118. {
  119. return instance;
  120. }
  121. @end
  122. @implementation VLCLibrary (VLCAudioBridging)
  123. - (void)setAudio:(VLCAudio *)value
  124. {
  125. if (!audio)
  126. audio = value;
  127. }
  128. @end