VLCMedia.m 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145
  1. /*****************************************************************************
  2. * VLCMedia.m: VLCKit.framework VLCMedia implementation
  3. *****************************************************************************
  4. * Copyright (C) 2007 Pierre d'Herbemont
  5. * Copyright (C) 2013, 2017 Felix Paul Kühne
  6. * Copyright (C) 2007, 2013 VLC authors and VideoLAN
  7. * $Id$
  8. *
  9. * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
  10. * Felix Paul Kühne <fkuehne # videolan.org>
  11. * Soomin Lee <TheHungryBu # gmail.com>
  12. *
  13. * This program is free software; you can redistribute it and/or modify it
  14. * under the terms of the GNU Lesser General Public License as published by
  15. * the Free Software Foundation; either version 2.1 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Lesser General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Lesser General Public License
  24. * along with this program; if not, write to the Free Software Foundation,
  25. * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  26. *****************************************************************************/
  27. #import "VLCMedia.h"
  28. #import "VLCMediaList.h"
  29. #import "VLCEventManager.h"
  30. #import "VLCLibrary.h"
  31. #import "VLCLibVLCBridging.h"
  32. #import <vlc/libvlc.h>
  33. #import <sys/sysctl.h> // for sysctlbyname
  34. /* Meta Dictionary Keys */
  35. NSString *const VLCMetaInformationTitle = @"title";
  36. NSString *const VLCMetaInformationArtist = @"artist";
  37. NSString *const VLCMetaInformationGenre = @"genre";
  38. NSString *const VLCMetaInformationCopyright = @"copyright";
  39. NSString *const VLCMetaInformationAlbum = @"album";
  40. NSString *const VLCMetaInformationTrackNumber = @"trackNumber";
  41. NSString *const VLCMetaInformationDescription = @"description";
  42. NSString *const VLCMetaInformationRating = @"rating";
  43. NSString *const VLCMetaInformationDate = @"date";
  44. NSString *const VLCMetaInformationSetting = @"setting";
  45. NSString *const VLCMetaInformationURL = @"url";
  46. NSString *const VLCMetaInformationLanguage = @"language";
  47. NSString *const VLCMetaInformationNowPlaying = @"nowPlaying";
  48. NSString *const VLCMetaInformationPublisher = @"publisher";
  49. NSString *const VLCMetaInformationEncodedBy = @"encodedBy";
  50. NSString *const VLCMetaInformationArtworkURL = @"artworkURL";
  51. NSString *const VLCMetaInformationArtwork = @"artwork";
  52. NSString *const VLCMetaInformationTrackID = @"trackID";
  53. NSString *const VLCMetaInformationTrackTotal = @"trackTotal";
  54. NSString *const VLCMetaInformationDirector = @"director";
  55. NSString *const VLCMetaInformationSeason = @"season";
  56. NSString *const VLCMetaInformationEpisode = @"episode";
  57. NSString *const VLCMetaInformationShowName = @"showName";
  58. NSString *const VLCMetaInformationActors = @"actors";
  59. NSString *const VLCMetaInformationAlbumArtist = @"AlbumArtist";
  60. NSString *const VLCMetaInformationDiscNumber = @"discNumber";
  61. /* Notification Messages */
  62. NSString *const VLCMediaMetaChanged = @"VLCMediaMetaChanged";
  63. /******************************************************************************
  64. * VLC callbacks for streaming.
  65. */
  66. int open_cb(void *opaque, void **datap, uint64_t *sizep) {
  67. NSInputStream *stream = (__bridge NSInputStream *)(opaque);
  68. *datap = opaque;
  69. *sizep = UINT64_MAX;
  70. // Once a stream is closed, it cannot be reopened.
  71. if (stream && stream.streamStatus == NSStreamStatusNotOpen) {
  72. [stream open];
  73. return 0;
  74. } else {
  75. return stream.streamStatus == NSStreamStatusOpen ? 0 : -1;
  76. }
  77. }
  78. ssize_t read_cb(void *opaque, unsigned char *buf, size_t len) {
  79. NSInputStream *stream = (__bridge NSInputStream *)(opaque);
  80. if (!stream) {
  81. return -1;
  82. }
  83. return [stream read:buf maxLength:len];
  84. }
  85. int seek_cb(void *opaque, uint64_t offset) {
  86. NSInputStream *stream = (__bridge NSInputStream *)(opaque);
  87. if (!stream) {
  88. return -1;
  89. }
  90. /*
  91. By default, NSStream instances that are not file-based are non-seekable, one-way streams (although custom seekable subclasses are possible).
  92. Once the data has been provided or consumed, the data cannot be retrieved from the stream.
  93. However, you may want a peer subclass to NSInputStream whose instances are capable of seeking through a stream.
  94. */
  95. return [stream setProperty:@(offset) forKey:NSStreamFileCurrentOffsetKey] ? 0 : -1;
  96. }
  97. void close_cb(void *opaque) {
  98. NSInputStream *stream = (__bridge NSInputStream *)(opaque);
  99. if (stream && stream.streamStatus != NSStreamStatusClosed && stream.streamStatus != NSStreamStatusNotOpen) {
  100. [stream close];
  101. }
  102. return;
  103. }
  104. /******************************************************************************
  105. * VLCMedia ()
  106. */
  107. @interface VLCMedia()
  108. {
  109. void * p_md; ///< Internal media descriptor instance
  110. BOOL isArtFetched; ///< Value used to determine of the artwork has been parsed
  111. BOOL areOthersMetaFetched; ///< Value used to determine of the other meta has been parsed
  112. BOOL isArtURLFetched; ///< Value used to determine of the other meta has been preparsed
  113. BOOL eventsAttached; ///< YES when events are attached
  114. NSMutableDictionary *_metaDictionary; ///< Dictionary to cache metadata read from libvlc
  115. NSInputStream *stream; ///< Stream object if instance is initialized via NSInputStream to pass to callbacks
  116. }
  117. /* Make our properties internally readwrite */
  118. @property (nonatomic, readwrite) VLCMediaState state;
  119. @property (nonatomic, readwrite, strong) VLCMediaList * subitems;
  120. /* Statics */
  121. + (libvlc_meta_t)stringToMetaType:(NSString *)string;
  122. + (NSString *)metaTypeToString:(libvlc_meta_t)type;
  123. /* Initializers */
  124. - (void)initInternalMediaDescriptor;
  125. /* Operations */
  126. - (void)fetchMetaInformationFromLibVLCWithType:(NSString*)metaType;
  127. #if !TARGET_OS_IPHONE
  128. - (void)fetchMetaInformationForArtWorkWithURL:(NSString *)anURL;
  129. - (void)setArtwork:(NSImage *)art;
  130. #endif
  131. - (void)parseIfNeeded;
  132. /* Callback Methods */
  133. - (void)parsedChanged:(NSNumber *)isParsedAsNumber;
  134. - (void)metaChanged:(NSString *)metaType;
  135. - (void)subItemAdded;
  136. - (void)setStateAsNumber:(NSNumber *)newStateAsNumber;
  137. @end
  138. static VLCMediaState libvlc_state_to_media_state[] =
  139. {
  140. [libvlc_NothingSpecial] = VLCMediaStateNothingSpecial,
  141. [libvlc_Stopped] = VLCMediaStateNothingSpecial,
  142. [libvlc_Opening] = VLCMediaStateNothingSpecial,
  143. [libvlc_Buffering] = VLCMediaStateBuffering,
  144. [libvlc_Ended] = VLCMediaStateNothingSpecial,
  145. [libvlc_Error] = VLCMediaStateError,
  146. [libvlc_Playing] = VLCMediaStatePlaying,
  147. [libvlc_Paused] = VLCMediaStatePlaying,
  148. };
  149. static inline VLCMediaState LibVLCStateToMediaState( libvlc_state_t state )
  150. {
  151. return libvlc_state_to_media_state[state];
  152. }
  153. /******************************************************************************
  154. * LibVLC Event Callback
  155. */
  156. static void HandleMediaMetaChanged(const libvlc_event_t * event, void * self)
  157. {
  158. @autoreleasepool {
  159. [[VLCEventManager sharedManager] callOnMainThreadObject:(__bridge id)(self)
  160. withMethod:@selector(metaChanged:)
  161. withArgumentAsObject:[VLCMedia metaTypeToString:event->u.media_meta_changed.meta_type]];
  162. }
  163. }
  164. static void HandleMediaDurationChanged(const libvlc_event_t * event, void * self)
  165. {
  166. @autoreleasepool {
  167. [[VLCEventManager sharedManager] callOnMainThreadObject:(__bridge id)(self)
  168. withMethod:@selector(setLength:)
  169. withArgumentAsObject:[VLCTime timeWithNumber:
  170. @(event->u.media_duration_changed.new_duration)]];
  171. }
  172. }
  173. static void HandleMediaStateChanged(const libvlc_event_t * event, void * self)
  174. {
  175. @autoreleasepool {
  176. [[VLCEventManager sharedManager] callOnMainThreadObject:(__bridge id)(self)
  177. withMethod:@selector(setStateAsNumber:)
  178. withArgumentAsObject:@(LibVLCStateToMediaState(event->u.media_state_changed.new_state))];
  179. }
  180. }
  181. static void HandleMediaSubItemAdded(const libvlc_event_t * event, void * self)
  182. {
  183. @autoreleasepool {
  184. [[VLCEventManager sharedManager] callOnMainThreadObject:(__bridge id)(self)
  185. withMethod:@selector(subItemAdded)
  186. withArgumentAsObject:nil];
  187. }
  188. }
  189. static void HandleMediaParsedChanged(const libvlc_event_t * event, void * self)
  190. {
  191. @autoreleasepool {
  192. [[VLCEventManager sharedManager] callOnMainThreadObject:(__bridge id)(self)
  193. withMethod:@selector(parsedChanged:)
  194. withArgumentAsObject:@((BOOL)event->u.media_parsed_changed.new_status)];
  195. }
  196. }
  197. /******************************************************************************
  198. * Implementation
  199. */
  200. @implementation VLCMedia
  201. + (NSString *)codecNameForFourCC:(uint32_t)fourcc trackType:(NSString *)trackType
  202. {
  203. libvlc_track_type_t track_type = libvlc_track_unknown;
  204. if ([trackType isEqualToString:VLCMediaTracksInformationTypeAudio])
  205. track_type = libvlc_track_audio;
  206. else if ([trackType isEqualToString:VLCMediaTracksInformationTypeVideo])
  207. track_type = libvlc_track_video;
  208. else if ([trackType isEqualToString:VLCMediaTracksInformationTypeText])
  209. track_type = libvlc_track_text;
  210. const char *ret = libvlc_media_get_codec_description(track_type, fourcc);
  211. if (ret)
  212. return [NSString stringWithUTF8String:ret];
  213. return @"";
  214. }
  215. + (instancetype)mediaWithURL:(NSURL *)anURL;
  216. {
  217. return [[VLCMedia alloc] initWithURL:anURL];
  218. }
  219. + (instancetype)mediaWithPath:(NSString *)aPath;
  220. {
  221. return [[VLCMedia alloc] initWithPath:aPath];
  222. }
  223. + (instancetype)mediaAsNodeWithName:(NSString *)aName;
  224. {
  225. return [[VLCMedia alloc] initAsNodeWithName:aName];
  226. }
  227. - (instancetype)initWithPath:(NSString *)aPath
  228. {
  229. return [self initWithURL:[NSURL fileURLWithPath:aPath isDirectory:NO]];
  230. }
  231. - (instancetype)initWithURL:(NSURL *)anURL
  232. {
  233. if (self = [super init]) {
  234. const char *url;
  235. VLCLibrary *library = [VLCLibrary sharedLibrary];
  236. NSAssert(library.instance, @"no library instance when creating media");
  237. url = [[anURL absoluteString] UTF8String];
  238. p_md = libvlc_media_new_location(library.instance, url);
  239. _metaDictionary = [[NSMutableDictionary alloc] initWithCapacity:3];
  240. [self initInternalMediaDescriptor];
  241. }
  242. return self;
  243. }
  244. - (instancetype)initWithStream:(NSInputStream *)stream
  245. {
  246. if (self = [super init]) {
  247. VLCLibrary *library = [VLCLibrary sharedLibrary];
  248. NSAssert(library.instance, @"no library instance when creating media");
  249. NSAssert(stream.streamStatus != NSStreamStatusClosed, @"Passing closed stream to VLCMedia.init does not work");
  250. self->stream = stream;
  251. p_md = libvlc_media_new_callbacks(library.instance, open_cb, read_cb, seek_cb, close_cb, (__bridge void *)(stream));
  252. _metaDictionary = [[NSMutableDictionary alloc] initWithCapacity:3];
  253. [self initInternalMediaDescriptor];
  254. }
  255. return self;
  256. }
  257. - (instancetype)initAsNodeWithName:(NSString *)aName
  258. {
  259. if (self = [super init]) {
  260. p_md = libvlc_media_new_as_node([VLCLibrary sharedInstance], [aName UTF8String]);
  261. _metaDictionary = [[NSMutableDictionary alloc] initWithCapacity:3];
  262. [self initInternalMediaDescriptor];
  263. }
  264. return self;
  265. }
  266. - (void)dealloc
  267. {
  268. if (eventsAttached)
  269. {
  270. libvlc_event_manager_t * p_em = libvlc_media_event_manager(p_md);
  271. if (p_em) {
  272. libvlc_event_detach(p_em, libvlc_MediaMetaChanged, HandleMediaMetaChanged, (__bridge void *)(self));
  273. libvlc_event_detach(p_em, libvlc_MediaDurationChanged, HandleMediaDurationChanged, (__bridge void *)(self));
  274. libvlc_event_detach(p_em, libvlc_MediaStateChanged, HandleMediaStateChanged, (__bridge void *)(self));
  275. libvlc_event_detach(p_em, libvlc_MediaSubItemAdded, HandleMediaSubItemAdded, (__bridge void *)(self));
  276. libvlc_event_detach(p_em, libvlc_MediaParsedChanged, HandleMediaParsedChanged, (__bridge void *)(self));
  277. }
  278. }
  279. [[VLCEventManager sharedManager] cancelCallToObject:self];
  280. if (p_md)
  281. libvlc_media_release(p_md);
  282. }
  283. - (VLCMediaType)mediaType
  284. {
  285. libvlc_media_type_t libmediatype = libvlc_media_get_type(p_md);
  286. switch (libmediatype) {
  287. case libvlc_media_type_file:
  288. return VLCMediaTypeFile;
  289. case libvlc_media_type_directory:
  290. return VLCMediaTypeDirectory;
  291. case libvlc_media_type_disc:
  292. return VLCMediaTypeDisc;
  293. case libvlc_media_type_stream:
  294. return VLCMediaTypeStream;
  295. case libvlc_media_type_playlist:
  296. return VLCMediaTypePlaylist;
  297. default:
  298. return VLCMediaTypeUnknown;
  299. }
  300. }
  301. - (NSString *)description
  302. {
  303. return [NSString stringWithFormat:@"<%@ %p>, md: %p, url: %@", [self class], self, p_md, [[_url absoluteString] stringByRemovingPercentEncoding]];
  304. }
  305. - (NSComparisonResult)compare:(VLCMedia *)media
  306. {
  307. if (self == media)
  308. return NSOrderedSame;
  309. if (!media)
  310. return NSOrderedDescending;
  311. return p_md == [media libVLCMediaDescriptor] ? NSOrderedSame : NSOrderedAscending;
  312. }
  313. - (BOOL)isEqual:(id)other
  314. {
  315. return ([other isKindOfClass: [VLCMedia class]] &&
  316. [other libVLCMediaDescriptor] == p_md);
  317. }
  318. - (VLCTime *)length
  319. {
  320. if (!_length) {
  321. // Try figuring out what the length is
  322. long long duration = libvlc_media_get_duration( p_md );
  323. if (duration < 0)
  324. return [VLCTime nullTime];
  325. _length = [VLCTime timeWithNumber:@(duration)];
  326. }
  327. return _length;
  328. }
  329. - (VLCTime *)lengthWaitUntilDate:(NSDate *)aDate
  330. {
  331. static const long long thread_sleep = 10000;
  332. if (!_length) {
  333. // Force parsing of this item.
  334. [self parseIfNeeded];
  335. // wait until we are preparsed
  336. libvlc_media_parsed_status_t status = libvlc_media_get_parsed_status(p_md);
  337. while (!_length && !(status == VLCMediaParsedStatusFailed || status == VLCMediaParsedStatusDone) && [aDate timeIntervalSinceNow] > 0) {
  338. usleep( thread_sleep );
  339. status = libvlc_media_get_parsed_status(p_md);
  340. }
  341. // So we're done waiting, but sometimes we trap the fact that the parsing
  342. // was done before the length gets assigned, so lets go ahead and assign
  343. // it ourselves.
  344. if (!_length)
  345. return [self length];
  346. }
  347. return _length;
  348. }
  349. - (VLCMediaParsedStatus)parsedStatus
  350. {
  351. if (!p_md)
  352. return VLCMediaParsedStatusFailed;
  353. libvlc_media_parsed_status_t status = libvlc_media_get_parsed_status(p_md);
  354. return (VLCMediaParsedStatus)status;
  355. }
  356. - (int)parseWithOptions:(VLCMediaParsingOptions)options timeout:(int)timeoutValue
  357. {
  358. if (!p_md)
  359. return -1;
  360. // we are using the default time-out value
  361. return libvlc_media_parse_with_options(p_md,
  362. options,
  363. timeoutValue);
  364. }
  365. - (int)parseWithOptions:(VLCMediaParsingOptions)options
  366. {
  367. if (!p_md)
  368. return -1;
  369. // we are using the default time-out value
  370. return libvlc_media_parse_with_options(p_md,
  371. options,
  372. -1);
  373. }
  374. - (void)parseStop
  375. {
  376. if (p_md) {
  377. libvlc_media_parse_stop(p_md);
  378. }
  379. }
  380. - (void)addOption:(NSString *)option
  381. {
  382. if (p_md) {
  383. libvlc_media_add_option(p_md, [option UTF8String]);
  384. }
  385. }
  386. - (void)addOptions:(NSDictionary*)options
  387. {
  388. if (p_md) {
  389. [options enumerateKeysAndObjectsUsingBlock:^(NSString *key, id obj, BOOL *stop) {
  390. if (![obj isKindOfClass:[NSNull class]])
  391. libvlc_media_add_option(p_md, [[NSString stringWithFormat:@"%@=%@", key, obj] UTF8String]);
  392. else
  393. libvlc_media_add_option(p_md, [key UTF8String]);
  394. }];
  395. }
  396. }
  397. - (int)storeCookie:(NSString * _Nonnull)cookie
  398. forHost:(NSString *_Nonnull)host
  399. path:(NSString *_Nonnull)path
  400. {
  401. if (!p_md || cookie == NULL || host == NULL || path == NULL) {
  402. return -1;
  403. }
  404. #if TARGET_OS_IPHONE
  405. return libvlc_media_cookie_jar_store(p_md,
  406. [cookie UTF8String],
  407. [host UTF8String],
  408. [path UTF8String]);
  409. #else
  410. return -1;
  411. #endif
  412. }
  413. - (void)clearStoredCookies
  414. {
  415. if (!p_md) {
  416. return;
  417. }
  418. #if TARGET_OS_IPHONE
  419. libvlc_media_cookie_jar_clear(p_md);
  420. #endif
  421. }
  422. - (NSDictionary *)stats
  423. {
  424. if (!p_md)
  425. return nil;
  426. libvlc_media_stats_t p_stats;
  427. libvlc_media_get_stats(p_md, &p_stats);
  428. return @{
  429. @"demuxBitrate" : @(p_stats.f_demux_bitrate),
  430. @"inputBitrate" : @(p_stats.f_input_bitrate),
  431. @"decodedAudio" : @(p_stats.i_decoded_audio),
  432. @"decodedVideo" : @(p_stats.i_decoded_video),
  433. @"demuxCorrupted" : @(p_stats.i_demux_corrupted),
  434. @"demuxDiscontinuity" : @(p_stats.i_demux_discontinuity),
  435. @"demuxReadBytes" : @(p_stats.i_demux_read_bytes),
  436. @"displayedPictures" : @(p_stats.i_displayed_pictures),
  437. @"lostAbuffers" : @(p_stats.i_lost_abuffers),
  438. @"lostPictures" : @(p_stats.i_lost_pictures),
  439. @"playedAbuffers" : @(p_stats.i_played_abuffers),
  440. @"readBytes" : @(p_stats.i_read_bytes)
  441. };
  442. }
  443. - (NSInteger)numberOfReadBytesOnInput
  444. {
  445. if (!p_md)
  446. return 0;
  447. libvlc_media_stats_t p_stats;
  448. libvlc_media_get_stats(p_md, &p_stats);
  449. return p_stats.i_read_bytes;
  450. }
  451. - (float)inputBitrate
  452. {
  453. if (!p_md)
  454. return .0;
  455. libvlc_media_stats_t p_stats;
  456. libvlc_media_get_stats(p_md, &p_stats);
  457. return p_stats.f_input_bitrate;
  458. }
  459. - (NSInteger)numberOfReadBytesOnDemux
  460. {
  461. if (!p_md)
  462. return 0;
  463. libvlc_media_stats_t p_stats;
  464. libvlc_media_get_stats(p_md, &p_stats);
  465. return p_stats.i_demux_read_bytes;
  466. }
  467. - (float)demuxBitrate
  468. {
  469. if (!p_md)
  470. return .0;
  471. libvlc_media_stats_t p_stats;
  472. libvlc_media_get_stats(p_md, &p_stats);
  473. return p_stats.f_demux_bitrate;
  474. }
  475. - (NSInteger)numberOfDecodedVideoBlocks
  476. {
  477. if (!p_md)
  478. return 0;
  479. libvlc_media_stats_t p_stats;
  480. libvlc_media_get_stats(p_md, &p_stats);
  481. return p_stats.i_decoded_video;
  482. }
  483. - (NSInteger)numberOfDecodedAudioBlocks
  484. {
  485. if (!p_md)
  486. return 0;
  487. libvlc_media_stats_t p_stats;
  488. libvlc_media_get_stats(p_md, &p_stats);
  489. return p_stats.i_decoded_audio;
  490. }
  491. - (NSInteger)numberOfDisplayedPictures
  492. {
  493. if (!p_md)
  494. return 0;
  495. libvlc_media_stats_t p_stats;
  496. libvlc_media_get_stats(p_md, &p_stats);
  497. return p_stats.i_displayed_pictures;
  498. }
  499. - (NSInteger)numberOfLostPictures
  500. {
  501. if (!p_md)
  502. return 0;
  503. libvlc_media_stats_t p_stats;
  504. libvlc_media_get_stats(p_md, &p_stats);
  505. return p_stats.i_lost_pictures;
  506. }
  507. - (NSInteger)numberOfPlayedAudioBuffers
  508. {
  509. if (!p_md)
  510. return 0;
  511. libvlc_media_stats_t p_stats;
  512. libvlc_media_get_stats(p_md, &p_stats);
  513. return p_stats.i_played_abuffers;
  514. }
  515. - (NSInteger)numberOfLostAudioBuffers
  516. {
  517. if (!p_md)
  518. return 0;
  519. libvlc_media_stats_t p_stats;
  520. libvlc_media_get_stats(p_md, &p_stats);
  521. return p_stats.i_lost_abuffers;
  522. }
  523. - (NSInteger)numberOfCorruptedDataPackets
  524. {
  525. if (!p_md)
  526. return 0;
  527. libvlc_media_stats_t p_stats;
  528. libvlc_media_get_stats(p_md, &p_stats);
  529. return p_stats.i_demux_corrupted;
  530. }
  531. - (NSInteger)numberOfDiscontinuties
  532. {
  533. if (!p_md)
  534. return 0;
  535. libvlc_media_stats_t p_stats;
  536. libvlc_media_get_stats(p_md, &p_stats);
  537. return p_stats.i_demux_discontinuity;
  538. }
  539. NSString *const VLCMediaTracksInformationCodec = @"codec"; // NSNumber
  540. NSString *const VLCMediaTracksInformationId = @"id"; // NSNumber
  541. NSString *const VLCMediaTracksInformationType = @"type"; // NSString
  542. NSString *const VLCMediaTracksInformationCodecProfile = @"profile"; // NSNumber
  543. NSString *const VLCMediaTracksInformationCodecLevel = @"level"; // NSNumber
  544. NSString *const VLCMediaTracksInformationTypeAudio = @"audio";
  545. NSString *const VLCMediaTracksInformationTypeVideo = @"video";
  546. NSString *const VLCMediaTracksInformationTypeText = @"text";
  547. NSString *const VLCMediaTracksInformationTypeUnknown = @"unknown";
  548. NSString *const VLCMediaTracksInformationBitrate = @"bitrate"; // NSNumber
  549. NSString *const VLCMediaTracksInformationLanguage = @"language"; // NSString
  550. NSString *const VLCMediaTracksInformationDescription = @"description"; // NSString
  551. NSString *const VLCMediaTracksInformationAudioChannelsNumber = @"channelsNumber"; // NSNumber
  552. NSString *const VLCMediaTracksInformationAudioRate = @"rate"; // NSNumber
  553. NSString *const VLCMediaTracksInformationVideoHeight = @"height"; // NSNumber
  554. NSString *const VLCMediaTracksInformationVideoWidth = @"width"; // NSNumber
  555. NSString *const VLCMediaTracksInformationVideoOrientation = @"orientation"; // NSNumber
  556. NSString *const VLCMediaTracksInformationVideoProjection = @"projection"; // NSNumber
  557. NSString *const VLCMediaTracksInformationSourceAspectRatio = @"sar_num"; // NSNumber
  558. NSString *const VLCMediaTracksInformationSourceAspectRatioDenominator = @"sar_den"; // NSNumber
  559. NSString *const VLCMediaTracksInformationFrameRate = @"frame_rate_num"; // NSNumber
  560. NSString *const VLCMediaTracksInformationFrameRateDenominator = @"frame_rate_den"; // NSNumber
  561. NSString *const VLCMediaTracksInformationTextEncoding = @"encoding"; // NSString
  562. - (NSArray *)tracksInformation
  563. {
  564. libvlc_media_track_t **tracksInfo;
  565. unsigned int count = libvlc_media_tracks_get(p_md, &tracksInfo);
  566. NSMutableArray *array = [NSMutableArray array];
  567. for (NSUInteger i = 0; i < count; i++) {
  568. NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:
  569. @(tracksInfo[i]->i_codec),
  570. VLCMediaTracksInformationCodec,
  571. @(tracksInfo[i]->i_id),
  572. VLCMediaTracksInformationId,
  573. @(tracksInfo[i]->i_profile),
  574. VLCMediaTracksInformationCodecProfile,
  575. @(tracksInfo[i]->i_level),
  576. VLCMediaTracksInformationCodecLevel,
  577. @(tracksInfo[i]->i_bitrate),
  578. VLCMediaTracksInformationBitrate,
  579. nil];
  580. if (tracksInfo[i]->psz_language)
  581. dictionary[VLCMediaTracksInformationLanguage] = [NSString stringWithUTF8String:tracksInfo[i]->psz_language];
  582. if (tracksInfo[i]->psz_description)
  583. dictionary[VLCMediaTracksInformationDescription] = [NSString stringWithUTF8String:tracksInfo[i]->psz_description];
  584. NSString *type;
  585. switch (tracksInfo[i]->i_type) {
  586. case libvlc_track_audio:
  587. type = VLCMediaTracksInformationTypeAudio;
  588. dictionary[VLCMediaTracksInformationAudioChannelsNumber] = @(tracksInfo[i]->audio->i_channels);
  589. dictionary[VLCMediaTracksInformationAudioRate] = @(tracksInfo[i]->audio->i_rate);
  590. break;
  591. case libvlc_track_video:
  592. type = VLCMediaTracksInformationTypeVideo;
  593. dictionary[VLCMediaTracksInformationVideoWidth] = @(tracksInfo[i]->video->i_width);
  594. dictionary[VLCMediaTracksInformationVideoHeight] = @(tracksInfo[i]->video->i_height);
  595. dictionary[VLCMediaTracksInformationVideoOrientation] = @(tracksInfo[i]->video->i_orientation);
  596. dictionary[VLCMediaTracksInformationVideoProjection] = @(tracksInfo[i]->video->i_projection);
  597. dictionary[VLCMediaTracksInformationSourceAspectRatio] = @(tracksInfo[i]->video->i_sar_num);
  598. dictionary[VLCMediaTracksInformationSourceAspectRatioDenominator] = @(tracksInfo[i]->video->i_sar_den);
  599. dictionary[VLCMediaTracksInformationFrameRate] = @(tracksInfo[i]->video->i_frame_rate_num);
  600. dictionary[VLCMediaTracksInformationFrameRateDenominator] = @(tracksInfo[i]->video->i_frame_rate_den);
  601. break;
  602. case libvlc_track_text:
  603. type = VLCMediaTracksInformationTypeText;
  604. if (tracksInfo[i]->subtitle->psz_encoding)
  605. dictionary[VLCMediaTracksInformationTextEncoding] = [NSString stringWithUTF8String: tracksInfo[i]->subtitle->psz_encoding];
  606. break;
  607. case libvlc_track_unknown:
  608. default:
  609. type = VLCMediaTracksInformationTypeUnknown;
  610. break;
  611. }
  612. [dictionary setValue:type forKey:VLCMediaTracksInformationType];
  613. [array addObject:dictionary];
  614. }
  615. libvlc_media_tracks_release(tracksInfo, count);
  616. return array;
  617. }
  618. - (BOOL)isMediaSizeSuitableForDevice
  619. {
  620. #if TARGET_OS_IPHONE
  621. // Trigger parsing if needed
  622. VLCMediaParsedStatus parsedStatus = [self parsedStatus];
  623. if (parsedStatus == VLCMediaParsedStatusSkipped || parsedStatus == VLCMediaParsedStatusInit) {
  624. [self parseWithOptions:VLCMediaParseLocal|VLCMediaParseNetwork];
  625. sleep(2);
  626. }
  627. NSUInteger biggestWidth = 0;
  628. NSUInteger biggestHeight = 0;
  629. libvlc_media_track_t **tracksInfo;
  630. unsigned int count = libvlc_media_tracks_get(p_md, &tracksInfo);
  631. for (NSUInteger i = 0; i < count; i++) {
  632. switch (tracksInfo[i]->i_type) {
  633. case libvlc_track_video:
  634. if (tracksInfo[i]->video->i_width > biggestWidth)
  635. biggestWidth = tracksInfo[i]->video->i_width;
  636. if (tracksInfo[i]->video->i_height > biggestHeight)
  637. biggestHeight = tracksInfo[i]->video->i_height;
  638. break;
  639. default:
  640. break;
  641. }
  642. }
  643. if (biggestHeight > 0 && biggestWidth > 0) {
  644. size_t size;
  645. sysctlbyname("hw.machine", NULL, &size, NULL, 0);
  646. char *answer = malloc(size);
  647. sysctlbyname("hw.machine", answer, &size, NULL, 0);
  648. NSString *currentMachine = @(answer);
  649. free(answer);
  650. NSUInteger totalNumberOfPixels = biggestWidth * biggestHeight;
  651. if ([currentMachine hasPrefix:@"iPhone2"] || [currentMachine hasPrefix:@"iPhone3"] || [currentMachine hasPrefix:@"iPad1"] || [currentMachine hasPrefix:@"iPod3"] || [currentMachine hasPrefix:@"iPod4"]) {
  652. // iPhone 3GS, iPhone 4, first gen. iPad, 3rd and 4th generation iPod touch
  653. return (totalNumberOfPixels < 600000); // between 480p and 720p
  654. } else if ([currentMachine hasPrefix:@"iPhone4"] || [currentMachine hasPrefix:@"iPad3,1"] || [currentMachine hasPrefix:@"iPad3,2"] || [currentMachine hasPrefix:@"iPad3,3"] || [currentMachine hasPrefix:@"iPod4"] || [currentMachine hasPrefix:@"iPad2"] || [currentMachine hasPrefix:@"iPod5"]) {
  655. // iPhone 4S, iPad 2 and 3, iPod 4 and 5
  656. return (totalNumberOfPixels < 922000); // 720p
  657. } else {
  658. // iPhone 5, iPad 4
  659. return (totalNumberOfPixels < 2074000); // 1080p
  660. }
  661. }
  662. #endif
  663. return YES;
  664. }
  665. - (NSString *)metadataForKey:(NSString *)key
  666. {
  667. if (!p_md)
  668. return nil;
  669. char *returnValue = libvlc_media_get_meta(p_md, [VLCMedia stringToMetaType:key]);
  670. if (!returnValue)
  671. return nil;
  672. NSString *actualReturnValue = @(returnValue);
  673. free(returnValue);
  674. return actualReturnValue;
  675. }
  676. - (void)setMetadata:(NSString *)data forKey:(NSString *)key
  677. {
  678. if (!p_md)
  679. return;
  680. libvlc_media_set_meta(p_md, [VLCMedia stringToMetaType:key], [data UTF8String]);
  681. }
  682. - (BOOL)saveMetadata
  683. {
  684. if (p_md)
  685. return libvlc_media_save_meta(p_md) != 0;
  686. return NO;
  687. }
  688. /******************************************************************************
  689. * Implementation VLCMedia ()
  690. */
  691. + (libvlc_meta_t)stringToMetaType:(NSString *)string
  692. {
  693. static NSDictionary * stringToMetaDictionary = nil;
  694. // TODO: Thread safe-ize
  695. if (!stringToMetaDictionary) {
  696. #define VLCStringToMeta( name ) [NSNumber numberWithInt: libvlc_meta_##name], VLCMetaInformation##name
  697. stringToMetaDictionary =
  698. [NSDictionary dictionaryWithObjectsAndKeys:
  699. VLCStringToMeta(Title),
  700. VLCStringToMeta(Artist),
  701. VLCStringToMeta(Genre),
  702. VLCStringToMeta(Copyright),
  703. VLCStringToMeta(Album),
  704. VLCStringToMeta(TrackNumber),
  705. VLCStringToMeta(Description),
  706. VLCStringToMeta(Rating),
  707. VLCStringToMeta(Date),
  708. VLCStringToMeta(Setting),
  709. VLCStringToMeta(URL),
  710. VLCStringToMeta(Language),
  711. VLCStringToMeta(NowPlaying),
  712. VLCStringToMeta(Publisher),
  713. VLCStringToMeta(ArtworkURL),
  714. VLCStringToMeta(TrackID),
  715. VLCStringToMeta(TrackTotal),
  716. VLCStringToMeta(Director),
  717. VLCStringToMeta(Season),
  718. VLCStringToMeta(Episode),
  719. VLCStringToMeta(ShowName),
  720. VLCStringToMeta(Actors),
  721. VLCStringToMeta(AlbumArtist),
  722. VLCStringToMeta(DiscNumber),
  723. nil];
  724. #undef VLCStringToMeta
  725. }
  726. NSNumber * number = stringToMetaDictionary[string];
  727. return (libvlc_meta_t) (number ? [number intValue] : -1);
  728. }
  729. + (NSString *)metaTypeToString:(libvlc_meta_t)type
  730. {
  731. #define VLCMetaToString( name, type ) if (libvlc_meta_##name == type) return VLCMetaInformation##name;
  732. VLCMetaToString(Title, type);
  733. VLCMetaToString(Artist, type);
  734. VLCMetaToString(Genre, type);
  735. VLCMetaToString(Copyright, type);
  736. VLCMetaToString(Album, type);
  737. VLCMetaToString(TrackNumber, type);
  738. VLCMetaToString(Description, type);
  739. VLCMetaToString(Rating, type);
  740. VLCMetaToString(Date, type);
  741. VLCMetaToString(Setting, type);
  742. VLCMetaToString(URL, type);
  743. VLCMetaToString(Language, type);
  744. VLCMetaToString(NowPlaying, type);
  745. VLCMetaToString(Publisher, type);
  746. VLCMetaToString(ArtworkURL, type);
  747. VLCMetaToString(TrackID, type);
  748. VLCMetaToString(TrackTotal, type);
  749. VLCMetaToString(Director, type);
  750. VLCMetaToString(Season, type);
  751. VLCMetaToString(Episode, type);
  752. VLCMetaToString(ShowName, type);
  753. VLCMetaToString(Actors, type);
  754. VLCMetaToString(AlbumArtist, type);
  755. VLCMetaToString(DiscNumber, type);
  756. #undef VLCMetaToString
  757. return nil;
  758. }
  759. - (void)initInternalMediaDescriptor
  760. {
  761. char * p_url = libvlc_media_get_mrl( p_md );
  762. if (!p_url)
  763. return;
  764. NSString *urlString = [NSString stringWithUTF8String:p_url];
  765. if (!urlString) {
  766. free(p_url);
  767. return;
  768. }
  769. _url = [NSURL URLWithString:urlString];
  770. if (!_url) /* Attempt to interpret as a file path then */ {
  771. _url = [NSURL fileURLWithPath:urlString];
  772. if(!_url) {
  773. free(p_url);
  774. return;
  775. }
  776. }
  777. free(p_url);
  778. libvlc_media_set_user_data(p_md, (__bridge void*)self);
  779. libvlc_event_manager_t * p_em = libvlc_media_event_manager( p_md );
  780. if (p_em) {
  781. libvlc_event_attach(p_em, libvlc_MediaMetaChanged, HandleMediaMetaChanged, (__bridge void *)(self));
  782. libvlc_event_attach(p_em, libvlc_MediaDurationChanged, HandleMediaDurationChanged, (__bridge void *)(self));
  783. libvlc_event_attach(p_em, libvlc_MediaStateChanged, HandleMediaStateChanged, (__bridge void *)(self));
  784. libvlc_event_attach(p_em, libvlc_MediaSubItemAdded, HandleMediaSubItemAdded, (__bridge void *)(self));
  785. libvlc_event_attach(p_em, libvlc_MediaParsedChanged, HandleMediaParsedChanged, (__bridge void *)(self));
  786. eventsAttached = YES;
  787. }
  788. libvlc_media_list_t * p_mlist = libvlc_media_subitems( p_md );
  789. if (p_mlist) {
  790. self.subitems = [VLCMediaList mediaListWithLibVLCMediaList:p_mlist];
  791. libvlc_media_list_release( p_mlist );
  792. }
  793. self.state = LibVLCStateToMediaState(libvlc_media_get_state( p_md ));
  794. }
  795. - (void)fetchMetaInformationFromLibVLCWithType:(NSString *)metaType
  796. {
  797. char * psz_value = libvlc_media_get_meta( p_md, [VLCMedia stringToMetaType:metaType] );
  798. NSString * newValue = psz_value ? @(psz_value) : nil;
  799. NSString * oldValue = [_metaDictionary valueForKey:metaType];
  800. free(psz_value);
  801. if (newValue != oldValue && !(oldValue && newValue && [oldValue compare:newValue] == NSOrderedSame)) {
  802. #if !TARGET_OS_IPHONE
  803. // Only fetch the art if needed. (ie, create the NSImage, if it was requested before)
  804. if (isArtFetched && [metaType isEqualToString:VLCMetaInformationArtworkURL]) {
  805. [NSThread detachNewThreadSelector:@selector(fetchMetaInformationForArtWorkWithURL:)
  806. toTarget:self
  807. withObject:newValue];
  808. }
  809. #endif
  810. [_metaDictionary setValue:newValue forKeyPath:metaType];
  811. }
  812. }
  813. #if !TARGET_OS_IPHONE
  814. - (void)fetchMetaInformationForArtWorkWithURL:(NSString *)anURL
  815. {
  816. @autoreleasepool {
  817. NSImage * art = nil;
  818. if (anURL) {
  819. // Go ahead and load up the art work
  820. NSURL * artUrl = [NSURL URLWithString:[anURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
  821. // Don't attempt to fetch artwork from remote. Core will do that alone
  822. if ([artUrl isFileURL])
  823. art = [[NSImage alloc] initWithContentsOfURL:artUrl];
  824. }
  825. // If anything was found, lets save it to the meta data dictionary
  826. [self performSelectorOnMainThread:@selector(setArtwork:) withObject:art waitUntilDone:NO];
  827. }
  828. }
  829. - (void)setArtwork:(NSImage *)art
  830. {
  831. if (!art)
  832. [(NSMutableDictionary *)_metaDictionary removeObjectForKey:@"artwork"];
  833. else
  834. ((NSMutableDictionary *)_metaDictionary)[@"artwork"] = art;
  835. }
  836. #endif
  837. - (void)parseIfNeeded
  838. {
  839. VLCMediaParsedStatus parsedStatus = [self parsedStatus];
  840. if (parsedStatus == VLCMediaParsedStatusSkipped || parsedStatus == VLCMediaParsedStatusInit)
  841. [self parseWithOptions:VLCMediaParseLocal | VLCMediaFetchLocal];
  842. }
  843. - (void)metaChanged:(NSString *)metaType
  844. {
  845. [self fetchMetaInformationFromLibVLCWithType:metaType];
  846. if ([_delegate respondsToSelector:@selector(mediaMetaDataDidChange:)])
  847. [_delegate mediaMetaDataDidChange:self];
  848. }
  849. - (void)subItemAdded
  850. {
  851. if (_subitems)
  852. return; /* Nothing to do */
  853. libvlc_media_list_t * p_mlist = libvlc_media_subitems( p_md );
  854. NSAssert( p_mlist, @"The mlist shouldn't be nil, we are receiving a subItemAdded");
  855. self.subitems = [VLCMediaList mediaListWithLibVLCMediaList:p_mlist];
  856. libvlc_media_list_release( p_mlist );
  857. }
  858. - (void)parsedChanged:(NSNumber *)isParsedAsNumber
  859. {
  860. [self willChangeValueForKey:@"parsedStatus"];
  861. [self parsedStatus];
  862. [self didChangeValueForKey:@"parsedStatus"];
  863. if (!_delegate)
  864. return;
  865. if ([_delegate respondsToSelector:@selector(mediaDidFinishParsing:)])
  866. [_delegate mediaDidFinishParsing:self];
  867. }
  868. - (void)setStateAsNumber:(NSNumber *)newStateAsNumber
  869. {
  870. [self setState: [newStateAsNumber intValue]];
  871. }
  872. #if TARGET_OS_IPHONE
  873. - (NSDictionary *)metaDictionary
  874. {
  875. if (!areOthersMetaFetched) {
  876. areOthersMetaFetched = YES;
  877. [self fetchMetaInformationFromLibVLCWithType: VLCMetaInformationTitle];
  878. [self fetchMetaInformationFromLibVLCWithType: VLCMetaInformationArtist];
  879. [self fetchMetaInformationFromLibVLCWithType: VLCMetaInformationAlbum];
  880. [self fetchMetaInformationFromLibVLCWithType: VLCMetaInformationDate];
  881. [self fetchMetaInformationFromLibVLCWithType: VLCMetaInformationGenre];
  882. [self fetchMetaInformationFromLibVLCWithType: VLCMetaInformationTrackNumber];
  883. [self fetchMetaInformationFromLibVLCWithType: VLCMetaInformationDiscNumber];
  884. [self fetchMetaInformationFromLibVLCWithType: VLCMetaInformationNowPlaying];
  885. [self fetchMetaInformationFromLibVLCWithType: VLCMetaInformationLanguage];
  886. }
  887. if (!isArtURLFetched) {
  888. isArtURLFetched = YES;
  889. /* Force isArtURLFetched, that will trigger artwork download eventually
  890. * And all the other meta will be added through the libvlc event system */
  891. [self fetchMetaInformationFromLibVLCWithType: VLCMetaInformationArtworkURL];
  892. }
  893. return [NSDictionary dictionaryWithDictionary:_metaDictionary];
  894. }
  895. #else
  896. - (NSDictionary *)metaDictionary
  897. {
  898. return [NSDictionary dictionaryWithDictionary:_metaDictionary];
  899. }
  900. - (id)valueForKeyPath:(NSString *)keyPath
  901. {
  902. if (!isArtFetched && [keyPath isEqualToString:@"metaDictionary.artwork"]) {
  903. isArtFetched = YES;
  904. /* Force the retrieval of the artwork now that someone asked for it */
  905. [self fetchMetaInformationFromLibVLCWithType: VLCMetaInformationArtworkURL];
  906. } else if (!areOthersMetaFetched && [keyPath hasPrefix:@"metaDictionary."]) {
  907. areOthersMetaFetched = YES;
  908. /* Force VLCMetaInformationTitle, that will trigger preparsing
  909. * And all the other meta will be added through the libvlc event system */
  910. [self fetchMetaInformationFromLibVLCWithType: VLCMetaInformationTitle];
  911. } else if (!isArtURLFetched && [keyPath hasPrefix:@"metaDictionary.artworkURL"]) {
  912. isArtURLFetched = YES;
  913. /* Force isArtURLFetched, that will trigger artwork download eventually
  914. * And all the other meta will be added through the libvlc event system */
  915. [self fetchMetaInformationFromLibVLCWithType: VLCMetaInformationArtworkURL];
  916. }
  917. return [super valueForKeyPath:keyPath];
  918. }
  919. #endif
  920. @end
  921. /******************************************************************************
  922. * Implementation VLCMedia (LibVLCBridging)
  923. */
  924. @implementation VLCMedia (LibVLCBridging)
  925. + (id)mediaWithLibVLCMediaDescriptor:(void *)md
  926. {
  927. return [[VLCMedia alloc] initWithLibVLCMediaDescriptor:md];
  928. }
  929. + (id)mediaWithMedia:(VLCMedia *)media andLibVLCOptions:(NSDictionary *)options
  930. {
  931. libvlc_media_t * p_md;
  932. p_md = libvlc_media_duplicate([media libVLCMediaDescriptor]);
  933. for (NSString * key in [options allKeys]) {
  934. if (options[key] != [NSNull null])
  935. libvlc_media_add_option(p_md, [[NSString stringWithFormat:@"%@=%@", key, options[key]] UTF8String]);
  936. else
  937. libvlc_media_add_option(p_md, [[NSString stringWithFormat:@"%@", key] UTF8String]);
  938. }
  939. return [VLCMedia mediaWithLibVLCMediaDescriptor:p_md];
  940. }
  941. - (id)initWithLibVLCMediaDescriptor:(void *)md
  942. {
  943. if (self = [super init]) {
  944. libvlc_media_retain(md);
  945. p_md = md;
  946. _metaDictionary = [[NSMutableDictionary alloc] initWithCapacity:3];
  947. [self initInternalMediaDescriptor];
  948. }
  949. return self;
  950. }
  951. - (void *)libVLCMediaDescriptor
  952. {
  953. return p_md;
  954. }
  955. @end