VLCLibrary.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. // TODO: Change from a terminal error to raising an exception?
  30. void __quit_on_exception( void * e, const char * function, const char * file, int line_number )
  31. {
  32. libvlc_exception_t *ex = (libvlc_exception_t *)e;
  33. if (libvlc_exception_raised( ex ))
  34. {
  35. /* XXX: localization */
  36. NSRunCriticalAlertPanel( @"Error", [NSString stringWithFormat:@"libvlc has thrown us an error: %s (%s:%d %s)",
  37. libvlc_exception_get_message( ex ), file, line_number, function], @"Quit", nil, nil );
  38. exit( ex->i_code );
  39. }
  40. }
  41. static void * DestroySharedLibraryAtExit( void )
  42. {
  43. /* Release the global object that may have been alloc-ed
  44. * in -[VLCLibrary init] */
  45. [sharedLibrary release];
  46. sharedLibrary = nil;
  47. return NULL;
  48. }
  49. @implementation VLCLibrary
  50. + (VLCLibrary *)sharedLibrary
  51. {
  52. if (!sharedLibrary)
  53. {
  54. /* Initialize a shared instance */
  55. sharedLibrary = [[self alloc] init];
  56. /* Make sure, this will get released at some point */
  57. atexit( (void*)DestroySharedLibraryAtExit );
  58. }
  59. return [[sharedLibrary retain] autorelease];
  60. }
  61. - (id)init
  62. {
  63. if (self = [super init])
  64. {
  65. libvlc_exception_t ex;
  66. libvlc_exception_init( &ex );
  67. const char *lib_vlc_params[] = {
  68. "-I", "dummy", "-vvvv", "--opengl-provider", "minimal_macosx",
  69. "--no-video-title-show", NULL
  70. };
  71. instance = (void *)libvlc_new( 6, lib_vlc_params, &ex );
  72. quit_on_exception( &ex );
  73. // Assignment unneeded, as the audio unit will do it for us
  74. /*audio = */ [[VLCAudio alloc] initWithLibrary:self];
  75. }
  76. return self;
  77. }
  78. - (void)dealloc
  79. {
  80. if (instance)
  81. {
  82. libvlc_exception_t ex;
  83. libvlc_exception_init( &ex );
  84. libvlc_release( instance, &ex );
  85. }
  86. instance = nil;
  87. [audio release];
  88. [super dealloc];
  89. }
  90. - (VLCAudio *)audio
  91. {
  92. return audio;
  93. }
  94. @end
  95. @implementation VLCLibrary (VLCLibVLCBridging)
  96. + (void *)sharedInstance
  97. {
  98. return [[self sharedLibrary] instance];
  99. }
  100. - (void *)instance
  101. {
  102. return instance;
  103. }
  104. @end
  105. @implementation VLCLibrary (VLCAudioBridging)
  106. - (void)setAudio:(VLCAudio *)value
  107. {
  108. if (!audio)
  109. audio = value;
  110. }
  111. @end