VLCLibrary.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*****************************************************************************
  2. * VLCLibrary.h: VLC.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. #include <vlc/vlc.h>
  27. #include <vlc/libvlc_structures.h>
  28. static VLCLibrary * sharedLibrary = nil;
  29. void __catch_exception( void * e, const char * function, const char * file, int line_number )
  30. {
  31. libvlc_exception_t * ex = (libvlc_exception_t *)e;
  32. if (libvlc_exception_raised( ex ))
  33. {
  34. NSException* libvlcException = [NSException
  35. exceptionWithName:@"LibVLCException"
  36. reason:[NSString stringWithFormat:@"libvlc has thrown us an error: %s (%s:%d %s)",
  37. libvlc_exception_get_message( ex ), file, line_number, function]
  38. userInfo:nil];
  39. @throw libvlcException;
  40. }
  41. }
  42. static void * DestroySharedLibraryAtExit( void )
  43. {
  44. /* Release the global object that may have been alloc-ed
  45. * in -[VLCLibrary init] */
  46. [sharedLibrary release];
  47. sharedLibrary = nil;
  48. return NULL;
  49. }
  50. @implementation VLCLibrary
  51. + (VLCLibrary *)sharedLibrary
  52. {
  53. if (!sharedLibrary)
  54. {
  55. /* Initialize a shared instance */
  56. sharedLibrary = [[self alloc] init];
  57. /* Make sure, this will get released at some point */
  58. atexit( (void *)DestroySharedLibraryAtExit );
  59. }
  60. return [[sharedLibrary retain] autorelease];
  61. }
  62. - (id)init
  63. {
  64. if (self = [super init])
  65. {
  66. libvlc_exception_t ex;
  67. libvlc_exception_init( &ex );
  68. const char * lib_vlc_params[] = {
  69. "-I", "dummy", "--vout=opengllayer",
  70. "--no-video-title-show"
  71. };
  72. instance = (void *)libvlc_new( sizeof(lib_vlc_params)/sizeof(lib_vlc_params[0]), lib_vlc_params, &ex );
  73. catch_exception( &ex );
  74. // Assignment unneeded, as the audio unit will do it for us
  75. /*audio = */ [[VLCAudio alloc] initWithLibrary:self];
  76. }
  77. return self;
  78. }
  79. - (void)dealloc
  80. {
  81. if (instance)
  82. {
  83. libvlc_exception_t ex;
  84. libvlc_exception_init( &ex );
  85. libvlc_release( instance, &ex );
  86. }
  87. instance = nil;
  88. [audio release];
  89. [super dealloc];
  90. }
  91. @synthesize audio;
  92. @end
  93. @implementation VLCLibrary (VLCLibVLCBridging)
  94. + (void *)sharedInstance
  95. {
  96. return [self sharedLibrary].instance;
  97. }
  98. - (void *)instance
  99. {
  100. return instance;
  101. }
  102. @end
  103. @implementation VLCLibrary (VLCAudioBridging)
  104. - (void)setAudio:(VLCAudio *)value
  105. {
  106. if (!audio)
  107. audio = value;
  108. }
  109. @end