VLCMediaDiscoverer.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*****************************************************************************
  2. * VLCMediaDiscoverer.m: VLC.framework VLCMediaDiscoverer 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 <Cocoa/Cocoa.h>
  25. #import "VLCMediaDiscoverer.h"
  26. #import "VLCLibrary.h"
  27. #import "VLCLibVLCBridging.h"
  28. #include <vlc/libvlc.h>
  29. static NSArray * availableMediaDiscoverer = nil;
  30. @implementation VLCMediaDiscoverer
  31. + (NSArray *)availableMediaDiscoverer
  32. {
  33. if( !availableMediaDiscoverer )
  34. {
  35. availableMediaDiscoverer = [[NSArray arrayWithObjects:
  36. [[[VLCMediaDiscoverer alloc] initWithName:@"sap"] autorelease],
  37. [[[VLCMediaDiscoverer alloc] initWithName:@"shoutcast"] autorelease],
  38. [[[VLCMediaDiscoverer alloc] initWithName:@"shoutcasttv"] autorelease], nil] retain];
  39. }
  40. return availableMediaDiscoverer;
  41. }
  42. - (id)initWithName:(NSString *)aServiceName
  43. {
  44. if (self = [super init])
  45. {
  46. libvlc_exception_t ex;
  47. libvlc_exception_init( &ex );
  48. localizedName = nil;
  49. discoveredMedia = nil;
  50. mdis = libvlc_media_discoverer_new_from_name( [VLCLibrary sharedInstance],
  51. [aServiceName UTF8String],
  52. &ex );
  53. quit_on_exception( &ex );
  54. }
  55. return self;
  56. }
  57. - (void)dealloc
  58. {
  59. if( localizedName )
  60. [localizedName release];
  61. if( discoveredMedia )
  62. [discoveredMedia release];
  63. libvlc_media_discoverer_release( mdis );
  64. [super dealloc];
  65. }
  66. - (VLCMediaList *) discoveredMedia
  67. {
  68. if( discoveredMedia )
  69. return discoveredMedia;
  70. libvlc_media_list_t * p_mlist = libvlc_media_discoverer_media_list( mdis );
  71. VLCMediaList * ret = [VLCMediaList mediaListWithLibVLCMediaList: p_mlist];
  72. libvlc_media_list_release( p_mlist );
  73. if( ret )
  74. {
  75. discoveredMedia = [ret retain];
  76. }
  77. return discoveredMedia;
  78. }
  79. - (NSString *)localizedName
  80. {
  81. NSString * aString = nil;
  82. char * name = libvlc_media_discoverer_localized_name( mdis );
  83. if( localizedName )
  84. return localizedName;
  85. if (name)
  86. {
  87. aString = [NSString stringWithUTF8String:name];
  88. free( name );
  89. }
  90. if( aString )
  91. {
  92. localizedName = [aString retain];
  93. }
  94. return localizedName;
  95. }
  96. @end