VLCMedia.m 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144
  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. };
  441. }
  442. - (NSInteger)numberOfReadBytesOnInput
  443. {
  444. if (!p_md)
  445. return 0;
  446. libvlc_media_stats_t p_stats;
  447. libvlc_media_get_stats(p_md, &p_stats);
  448. return p_stats.i_read_bytes;
  449. }
  450. - (float)inputBitrate
  451. {
  452. if (!p_md)
  453. return .0;
  454. libvlc_media_stats_t p_stats;
  455. libvlc_media_get_stats(p_md, &p_stats);
  456. return p_stats.f_input_bitrate;
  457. }
  458. - (NSInteger)numberOfReadBytesOnDemux
  459. {
  460. if (!p_md)
  461. return 0;
  462. libvlc_media_stats_t p_stats;
  463. libvlc_media_get_stats(p_md, &p_stats);
  464. return p_stats.i_demux_read_bytes;
  465. }
  466. - (float)demuxBitrate
  467. {
  468. if (!p_md)
  469. return .0;
  470. libvlc_media_stats_t p_stats;
  471. libvlc_media_get_stats(p_md, &p_stats);
  472. return p_stats.f_demux_bitrate;
  473. }
  474. - (NSInteger)numberOfDecodedVideoBlocks
  475. {
  476. if (!p_md)
  477. return 0;
  478. libvlc_media_stats_t p_stats;
  479. libvlc_media_get_stats(p_md, &p_stats);
  480. return p_stats.i_decoded_video;
  481. }
  482. - (NSInteger)numberOfDecodedAudioBlocks
  483. {
  484. if (!p_md)
  485. return 0;
  486. libvlc_media_stats_t p_stats;
  487. libvlc_media_get_stats(p_md, &p_stats);
  488. return p_stats.i_decoded_audio;
  489. }
  490. - (NSInteger)numberOfDisplayedPictures
  491. {
  492. if (!p_md)
  493. return 0;
  494. libvlc_media_stats_t p_stats;
  495. libvlc_media_get_stats(p_md, &p_stats);
  496. return p_stats.i_displayed_pictures;
  497. }
  498. - (NSInteger)numberOfLostPictures
  499. {
  500. if (!p_md)
  501. return 0;
  502. libvlc_media_stats_t p_stats;
  503. libvlc_media_get_stats(p_md, &p_stats);
  504. return p_stats.i_lost_pictures;
  505. }
  506. - (NSInteger)numberOfPlayedAudioBuffers
  507. {
  508. if (!p_md)
  509. return 0;
  510. libvlc_media_stats_t p_stats;
  511. libvlc_media_get_stats(p_md, &p_stats);
  512. return p_stats.i_played_abuffers;
  513. }
  514. - (NSInteger)numberOfLostAudioBuffers
  515. {
  516. if (!p_md)
  517. return 0;
  518. libvlc_media_stats_t p_stats;
  519. libvlc_media_get_stats(p_md, &p_stats);
  520. return p_stats.i_lost_abuffers;
  521. }
  522. - (NSInteger)numberOfCorruptedDataPackets
  523. {
  524. if (!p_md)
  525. return 0;
  526. libvlc_media_stats_t p_stats;
  527. libvlc_media_get_stats(p_md, &p_stats);
  528. return p_stats.i_demux_corrupted;
  529. }
  530. - (NSInteger)numberOfDiscontinuties
  531. {
  532. if (!p_md)
  533. return 0;
  534. libvlc_media_stats_t p_stats;
  535. libvlc_media_get_stats(p_md, &p_stats);
  536. return p_stats.i_demux_discontinuity;
  537. }
  538. NSString *const VLCMediaTracksInformationCodec = @"codec"; // NSNumber
  539. NSString *const VLCMediaTracksInformationId = @"id"; // NSNumber
  540. NSString *const VLCMediaTracksInformationType = @"type"; // NSString
  541. NSString *const VLCMediaTracksInformationCodecProfile = @"profile"; // NSNumber
  542. NSString *const VLCMediaTracksInformationCodecLevel = @"level"; // NSNumber
  543. NSString *const VLCMediaTracksInformationTypeAudio = @"audio";
  544. NSString *const VLCMediaTracksInformationTypeVideo = @"video";
  545. NSString *const VLCMediaTracksInformationTypeText = @"text";
  546. NSString *const VLCMediaTracksInformationTypeUnknown = @"unknown";
  547. NSString *const VLCMediaTracksInformationBitrate = @"bitrate"; // NSNumber
  548. NSString *const VLCMediaTracksInformationLanguage = @"language"; // NSString
  549. NSString *const VLCMediaTracksInformationDescription = @"description"; // NSString
  550. NSString *const VLCMediaTracksInformationAudioChannelsNumber = @"channelsNumber"; // NSNumber
  551. NSString *const VLCMediaTracksInformationAudioRate = @"rate"; // NSNumber
  552. NSString *const VLCMediaTracksInformationVideoHeight = @"height"; // NSNumber
  553. NSString *const VLCMediaTracksInformationVideoWidth = @"width"; // NSNumber
  554. NSString *const VLCMediaTracksInformationVideoOrientation = @"orientation"; // NSNumber
  555. NSString *const VLCMediaTracksInformationVideoProjection = @"projection"; // NSNumber
  556. NSString *const VLCMediaTracksInformationSourceAspectRatio = @"sar_num"; // NSNumber
  557. NSString *const VLCMediaTracksInformationSourceAspectRatioDenominator = @"sar_den"; // NSNumber
  558. NSString *const VLCMediaTracksInformationFrameRate = @"frame_rate_num"; // NSNumber
  559. NSString *const VLCMediaTracksInformationFrameRateDenominator = @"frame_rate_den"; // NSNumber
  560. NSString *const VLCMediaTracksInformationTextEncoding = @"encoding"; // NSString
  561. - (NSArray *)tracksInformation
  562. {
  563. libvlc_media_track_t **tracksInfo;
  564. unsigned int count = libvlc_media_tracks_get(p_md, &tracksInfo);
  565. NSMutableArray *array = [NSMutableArray array];
  566. for (NSUInteger i = 0; i < count; i++) {
  567. NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:
  568. @(tracksInfo[i]->i_codec),
  569. VLCMediaTracksInformationCodec,
  570. @(tracksInfo[i]->i_id),
  571. VLCMediaTracksInformationId,
  572. @(tracksInfo[i]->i_profile),
  573. VLCMediaTracksInformationCodecProfile,
  574. @(tracksInfo[i]->i_level),
  575. VLCMediaTracksInformationCodecLevel,
  576. @(tracksInfo[i]->i_bitrate),
  577. VLCMediaTracksInformationBitrate,
  578. nil];
  579. if (tracksInfo[i]->psz_language)
  580. dictionary[VLCMediaTracksInformationLanguage] = [NSString stringWithUTF8String:tracksInfo[i]->psz_language];
  581. if (tracksInfo[i]->psz_description)
  582. dictionary[VLCMediaTracksInformationDescription] = [NSString stringWithUTF8String:tracksInfo[i]->psz_description];
  583. NSString *type;
  584. switch (tracksInfo[i]->i_type) {
  585. case libvlc_track_audio:
  586. type = VLCMediaTracksInformationTypeAudio;
  587. dictionary[VLCMediaTracksInformationAudioChannelsNumber] = @(tracksInfo[i]->audio->i_channels);
  588. dictionary[VLCMediaTracksInformationAudioRate] = @(tracksInfo[i]->audio->i_rate);
  589. break;
  590. case libvlc_track_video:
  591. type = VLCMediaTracksInformationTypeVideo;
  592. dictionary[VLCMediaTracksInformationVideoWidth] = @(tracksInfo[i]->video->i_width);
  593. dictionary[VLCMediaTracksInformationVideoHeight] = @(tracksInfo[i]->video->i_height);
  594. dictionary[VLCMediaTracksInformationVideoOrientation] = @(tracksInfo[i]->video->i_orientation);
  595. dictionary[VLCMediaTracksInformationVideoProjection] = @(tracksInfo[i]->video->i_projection);
  596. dictionary[VLCMediaTracksInformationSourceAspectRatio] = @(tracksInfo[i]->video->i_sar_num);
  597. dictionary[VLCMediaTracksInformationSourceAspectRatioDenominator] = @(tracksInfo[i]->video->i_sar_den);
  598. dictionary[VLCMediaTracksInformationFrameRate] = @(tracksInfo[i]->video->i_frame_rate_num);
  599. dictionary[VLCMediaTracksInformationFrameRateDenominator] = @(tracksInfo[i]->video->i_frame_rate_den);
  600. break;
  601. case libvlc_track_text:
  602. type = VLCMediaTracksInformationTypeText;
  603. if (tracksInfo[i]->subtitle->psz_encoding)
  604. dictionary[VLCMediaTracksInformationTextEncoding] = [NSString stringWithUTF8String: tracksInfo[i]->subtitle->psz_encoding];
  605. break;
  606. case libvlc_track_unknown:
  607. default:
  608. type = VLCMediaTracksInformationTypeUnknown;
  609. break;
  610. }
  611. [dictionary setValue:type forKey:VLCMediaTracksInformationType];
  612. [array addObject:dictionary];
  613. }
  614. libvlc_media_tracks_release(tracksInfo, count);
  615. return array;
  616. }
  617. - (BOOL)isMediaSizeSuitableForDevice
  618. {
  619. #if TARGET_OS_IPHONE
  620. // Trigger parsing if needed
  621. VLCMediaParsedStatus parsedStatus = [self parsedStatus];
  622. if (parsedStatus == VLCMediaParsedStatusSkipped || parsedStatus == VLCMediaParsedStatusInit) {
  623. [self parseWithOptions:VLCMediaParseLocal|VLCMediaParseNetwork];
  624. sleep(2);
  625. }
  626. NSUInteger biggestWidth = 0;
  627. NSUInteger biggestHeight = 0;
  628. libvlc_media_track_t **tracksInfo;
  629. unsigned int count = libvlc_media_tracks_get(p_md, &tracksInfo);
  630. for (NSUInteger i = 0; i < count; i++) {
  631. switch (tracksInfo[i]->i_type) {
  632. case libvlc_track_video:
  633. if (tracksInfo[i]->video->i_width > biggestWidth)
  634. biggestWidth = tracksInfo[i]->video->i_width;
  635. if (tracksInfo[i]->video->i_height > biggestHeight)
  636. biggestHeight = tracksInfo[i]->video->i_height;
  637. break;
  638. default:
  639. break;
  640. }
  641. }
  642. if (biggestHeight > 0 && biggestWidth > 0) {
  643. size_t size;
  644. sysctlbyname("hw.machine", NULL, &size, NULL, 0);
  645. char *answer = malloc(size);
  646. sysctlbyname("hw.machine", answer, &size, NULL, 0);
  647. NSString *currentMachine = @(answer);
  648. free(answer);
  649. NSUInteger totalNumberOfPixels = biggestWidth * biggestHeight;
  650. if ([currentMachine hasPrefix:@"iPhone2"] || [currentMachine hasPrefix:@"iPhone3"] || [currentMachine hasPrefix:@"iPad1"] || [currentMachine hasPrefix:@"iPod3"] || [currentMachine hasPrefix:@"iPod4"]) {
  651. // iPhone 3GS, iPhone 4, first gen. iPad, 3rd and 4th generation iPod touch
  652. return (totalNumberOfPixels < 600000); // between 480p and 720p
  653. } 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"]) {
  654. // iPhone 4S, iPad 2 and 3, iPod 4 and 5
  655. return (totalNumberOfPixels < 922000); // 720p
  656. } else {
  657. // iPhone 5, iPad 4
  658. return (totalNumberOfPixels < 2074000); // 1080p
  659. }
  660. }
  661. #endif
  662. return YES;
  663. }
  664. - (NSString *)metadataForKey:(NSString *)key
  665. {
  666. if (!p_md)
  667. return nil;
  668. char *returnValue = libvlc_media_get_meta(p_md, [VLCMedia stringToMetaType:key]);
  669. if (!returnValue)
  670. return nil;
  671. NSString *actualReturnValue = @(returnValue);
  672. free(returnValue);
  673. return actualReturnValue;
  674. }
  675. - (void)setMetadata:(NSString *)data forKey:(NSString *)key
  676. {
  677. if (!p_md)
  678. return;
  679. libvlc_media_set_meta(p_md, [VLCMedia stringToMetaType:key], [data UTF8String]);
  680. }
  681. - (BOOL)saveMetadata
  682. {
  683. if (p_md)
  684. return libvlc_media_save_meta(p_md) != 0;
  685. return NO;
  686. }
  687. /******************************************************************************
  688. * Implementation VLCMedia ()
  689. */
  690. + (libvlc_meta_t)stringToMetaType:(NSString *)string
  691. {
  692. static NSDictionary * stringToMetaDictionary = nil;
  693. // TODO: Thread safe-ize
  694. if (!stringToMetaDictionary) {
  695. #define VLCStringToMeta( name ) [NSNumber numberWithInt: libvlc_meta_##name], VLCMetaInformation##name
  696. stringToMetaDictionary =
  697. [NSDictionary dictionaryWithObjectsAndKeys:
  698. VLCStringToMeta(Title),
  699. VLCStringToMeta(Artist),
  700. VLCStringToMeta(Genre),
  701. VLCStringToMeta(Copyright),
  702. VLCStringToMeta(Album),
  703. VLCStringToMeta(TrackNumber),
  704. VLCStringToMeta(Description),
  705. VLCStringToMeta(Rating),
  706. VLCStringToMeta(Date),
  707. VLCStringToMeta(Setting),
  708. VLCStringToMeta(URL),
  709. VLCStringToMeta(Language),
  710. VLCStringToMeta(NowPlaying),
  711. VLCStringToMeta(Publisher),
  712. VLCStringToMeta(ArtworkURL),
  713. VLCStringToMeta(TrackID),
  714. VLCStringToMeta(TrackTotal),
  715. VLCStringToMeta(Director),
  716. VLCStringToMeta(Season),
  717. VLCStringToMeta(Episode),
  718. VLCStringToMeta(ShowName),
  719. VLCStringToMeta(Actors),
  720. VLCStringToMeta(AlbumArtist),
  721. VLCStringToMeta(DiscNumber),
  722. nil];
  723. #undef VLCStringToMeta
  724. }
  725. NSNumber * number = stringToMetaDictionary[string];
  726. return (libvlc_meta_t) (number ? [number intValue] : -1);
  727. }
  728. + (NSString *)metaTypeToString:(libvlc_meta_t)type
  729. {
  730. #define VLCMetaToString( name, type ) if (libvlc_meta_##name == type) return VLCMetaInformation##name;
  731. VLCMetaToString(Title, type);
  732. VLCMetaToString(Artist, type);
  733. VLCMetaToString(Genre, type);
  734. VLCMetaToString(Copyright, type);
  735. VLCMetaToString(Album, type);
  736. VLCMetaToString(TrackNumber, type);
  737. VLCMetaToString(Description, type);
  738. VLCMetaToString(Rating, type);
  739. VLCMetaToString(Date, type);
  740. VLCMetaToString(Setting, type);
  741. VLCMetaToString(URL, type);
  742. VLCMetaToString(Language, type);
  743. VLCMetaToString(NowPlaying, type);
  744. VLCMetaToString(Publisher, type);
  745. VLCMetaToString(ArtworkURL, type);
  746. VLCMetaToString(TrackID, type);
  747. VLCMetaToString(TrackTotal, type);
  748. VLCMetaToString(Director, type);
  749. VLCMetaToString(Season, type);
  750. VLCMetaToString(Episode, type);
  751. VLCMetaToString(ShowName, type);
  752. VLCMetaToString(Actors, type);
  753. VLCMetaToString(AlbumArtist, type);
  754. VLCMetaToString(DiscNumber, type);
  755. #undef VLCMetaToString
  756. return nil;
  757. }
  758. - (void)initInternalMediaDescriptor
  759. {
  760. char * p_url = libvlc_media_get_mrl( p_md );
  761. if (!p_url)
  762. return;
  763. NSString *urlString = [NSString stringWithUTF8String:p_url];
  764. if (!urlString) {
  765. free(p_url);
  766. return;
  767. }
  768. _url = [NSURL URLWithString:urlString];
  769. if (!_url) /* Attempt to interpret as a file path then */ {
  770. _url = [NSURL fileURLWithPath:urlString];
  771. if(!_url) {
  772. free(p_url);
  773. return;
  774. }
  775. }
  776. free(p_url);
  777. libvlc_media_set_user_data(p_md, (__bridge void*)self);
  778. libvlc_event_manager_t * p_em = libvlc_media_event_manager( p_md );
  779. if (p_em) {
  780. libvlc_event_attach(p_em, libvlc_MediaMetaChanged, HandleMediaMetaChanged, (__bridge void *)(self));
  781. libvlc_event_attach(p_em, libvlc_MediaDurationChanged, HandleMediaDurationChanged, (__bridge void *)(self));
  782. libvlc_event_attach(p_em, libvlc_MediaStateChanged, HandleMediaStateChanged, (__bridge void *)(self));
  783. libvlc_event_attach(p_em, libvlc_MediaSubItemAdded, HandleMediaSubItemAdded, (__bridge void *)(self));
  784. libvlc_event_attach(p_em, libvlc_MediaParsedChanged, HandleMediaParsedChanged, (__bridge void *)(self));
  785. eventsAttached = YES;
  786. }
  787. libvlc_media_list_t * p_mlist = libvlc_media_subitems( p_md );
  788. if (p_mlist) {
  789. self.subitems = [VLCMediaList mediaListWithLibVLCMediaList:p_mlist];
  790. libvlc_media_list_release( p_mlist );
  791. }
  792. self.state = LibVLCStateToMediaState(libvlc_media_get_state( p_md ));
  793. }
  794. - (void)fetchMetaInformationFromLibVLCWithType:(NSString *)metaType
  795. {
  796. char * psz_value = libvlc_media_get_meta( p_md, [VLCMedia stringToMetaType:metaType] );
  797. NSString * newValue = psz_value ? @(psz_value) : nil;
  798. NSString * oldValue = [_metaDictionary valueForKey:metaType];
  799. free(psz_value);
  800. if (newValue != oldValue && !(oldValue && newValue && [oldValue compare:newValue] == NSOrderedSame)) {
  801. #if !TARGET_OS_IPHONE
  802. // Only fetch the art if needed. (ie, create the NSImage, if it was requested before)
  803. if (isArtFetched && [metaType isEqualToString:VLCMetaInformationArtworkURL]) {
  804. [NSThread detachNewThreadSelector:@selector(fetchMetaInformationForArtWorkWithURL:)
  805. toTarget:self
  806. withObject:newValue];
  807. }
  808. #endif
  809. [_metaDictionary setValue:newValue forKeyPath:metaType];
  810. }
  811. }
  812. #if !TARGET_OS_IPHONE
  813. - (void)fetchMetaInformationForArtWorkWithURL:(NSString *)anURL
  814. {
  815. @autoreleasepool {
  816. NSImage * art = nil;
  817. if (anURL) {
  818. // Go ahead and load up the art work
  819. NSURL * artUrl = [NSURL URLWithString:[anURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
  820. // Don't attempt to fetch artwork from remote. Core will do that alone
  821. if ([artUrl isFileURL])
  822. art = [[NSImage alloc] initWithContentsOfURL:artUrl];
  823. }
  824. // If anything was found, lets save it to the meta data dictionary
  825. [self performSelectorOnMainThread:@selector(setArtwork:) withObject:art waitUntilDone:NO];
  826. }
  827. }
  828. - (void)setArtwork:(NSImage *)art
  829. {
  830. if (!art)
  831. [(NSMutableDictionary *)_metaDictionary removeObjectForKey:@"artwork"];
  832. else
  833. ((NSMutableDictionary *)_metaDictionary)[@"artwork"] = art;
  834. }
  835. #endif
  836. - (void)parseIfNeeded
  837. {
  838. VLCMediaParsedStatus parsedStatus = [self parsedStatus];
  839. if (parsedStatus == VLCMediaParsedStatusSkipped || parsedStatus == VLCMediaParsedStatusInit)
  840. [self parseWithOptions:VLCMediaParseLocal | VLCMediaFetchLocal];
  841. }
  842. - (void)metaChanged:(NSString *)metaType
  843. {
  844. [self fetchMetaInformationFromLibVLCWithType:metaType];
  845. if ([_delegate respondsToSelector:@selector(mediaMetaDataDidChange:)])
  846. [_delegate mediaMetaDataDidChange:self];
  847. }
  848. - (void)subItemAdded
  849. {
  850. if (_subitems)
  851. return; /* Nothing to do */
  852. libvlc_media_list_t * p_mlist = libvlc_media_subitems( p_md );
  853. NSAssert( p_mlist, @"The mlist shouldn't be nil, we are receiving a subItemAdded");
  854. self.subitems = [VLCMediaList mediaListWithLibVLCMediaList:p_mlist];
  855. libvlc_media_list_release( p_mlist );
  856. }
  857. - (void)parsedChanged:(NSNumber *)isParsedAsNumber
  858. {
  859. [self willChangeValueForKey:@"parsedStatus"];
  860. [self parsedStatus];
  861. [self didChangeValueForKey:@"parsedStatus"];
  862. if (!_delegate)
  863. return;
  864. if ([_delegate respondsToSelector:@selector(mediaDidFinishParsing:)])
  865. [_delegate mediaDidFinishParsing:self];
  866. }
  867. - (void)setStateAsNumber:(NSNumber *)newStateAsNumber
  868. {
  869. [self setState: [newStateAsNumber intValue]];
  870. }
  871. #if TARGET_OS_IPHONE
  872. - (NSDictionary *)metaDictionary
  873. {
  874. if (!areOthersMetaFetched) {
  875. areOthersMetaFetched = YES;
  876. [self fetchMetaInformationFromLibVLCWithType: VLCMetaInformationTitle];
  877. [self fetchMetaInformationFromLibVLCWithType: VLCMetaInformationArtist];
  878. [self fetchMetaInformationFromLibVLCWithType: VLCMetaInformationAlbum];
  879. [self fetchMetaInformationFromLibVLCWithType: VLCMetaInformationDate];
  880. [self fetchMetaInformationFromLibVLCWithType: VLCMetaInformationGenre];
  881. [self fetchMetaInformationFromLibVLCWithType: VLCMetaInformationTrackNumber];
  882. [self fetchMetaInformationFromLibVLCWithType: VLCMetaInformationDiscNumber];
  883. [self fetchMetaInformationFromLibVLCWithType: VLCMetaInformationNowPlaying];
  884. [self fetchMetaInformationFromLibVLCWithType: VLCMetaInformationLanguage];
  885. }
  886. if (!isArtURLFetched) {
  887. isArtURLFetched = YES;
  888. /* Force isArtURLFetched, that will trigger artwork download eventually
  889. * And all the other meta will be added through the libvlc event system */
  890. [self fetchMetaInformationFromLibVLCWithType: VLCMetaInformationArtworkURL];
  891. }
  892. return [NSDictionary dictionaryWithDictionary:_metaDictionary];
  893. }
  894. #else
  895. - (NSDictionary *)metaDictionary
  896. {
  897. return [NSDictionary dictionaryWithDictionary:_metaDictionary];
  898. }
  899. - (id)valueForKeyPath:(NSString *)keyPath
  900. {
  901. if (!isArtFetched && [keyPath isEqualToString:@"metaDictionary.artwork"]) {
  902. isArtFetched = YES;
  903. /* Force the retrieval of the artwork now that someone asked for it */
  904. [self fetchMetaInformationFromLibVLCWithType: VLCMetaInformationArtworkURL];
  905. } else if (!areOthersMetaFetched && [keyPath hasPrefix:@"metaDictionary."]) {
  906. areOthersMetaFetched = YES;
  907. /* Force VLCMetaInformationTitle, that will trigger preparsing
  908. * And all the other meta will be added through the libvlc event system */
  909. [self fetchMetaInformationFromLibVLCWithType: VLCMetaInformationTitle];
  910. } else if (!isArtURLFetched && [keyPath hasPrefix:@"metaDictionary.artworkURL"]) {
  911. isArtURLFetched = YES;
  912. /* Force isArtURLFetched, that will trigger artwork download eventually
  913. * And all the other meta will be added through the libvlc event system */
  914. [self fetchMetaInformationFromLibVLCWithType: VLCMetaInformationArtworkURL];
  915. }
  916. return [super valueForKeyPath:keyPath];
  917. }
  918. #endif
  919. @end
  920. /******************************************************************************
  921. * Implementation VLCMedia (LibVLCBridging)
  922. */
  923. @implementation VLCMedia (LibVLCBridging)
  924. + (id)mediaWithLibVLCMediaDescriptor:(void *)md
  925. {
  926. return [[VLCMedia alloc] initWithLibVLCMediaDescriptor:md];
  927. }
  928. + (id)mediaWithMedia:(VLCMedia *)media andLibVLCOptions:(NSDictionary *)options
  929. {
  930. libvlc_media_t * p_md;
  931. p_md = libvlc_media_duplicate([media libVLCMediaDescriptor]);
  932. for (NSString * key in [options allKeys]) {
  933. if (options[key] != [NSNull null])
  934. libvlc_media_add_option(p_md, [[NSString stringWithFormat:@"%@=%@", key, options[key]] UTF8String]);
  935. else
  936. libvlc_media_add_option(p_md, [[NSString stringWithFormat:@"%@", key] UTF8String]);
  937. }
  938. return [VLCMedia mediaWithLibVLCMediaDescriptor:p_md];
  939. }
  940. - (id)initWithLibVLCMediaDescriptor:(void *)md
  941. {
  942. if (self = [super init]) {
  943. libvlc_media_retain(md);
  944. p_md = md;
  945. _metaDictionary = [[NSMutableDictionary alloc] initWithCapacity:3];
  946. [self initInternalMediaDescriptor];
  947. }
  948. return self;
  949. }
  950. - (void *)libVLCMediaDescriptor
  951. {
  952. return p_md;
  953. }
  954. @end