VLCMedia.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. /*****************************************************************************
  2. * VLCMedia.h: VLCKit.framework VLCMedia header
  3. *****************************************************************************
  4. * Copyright (C) 2007 Pierre d'Herbemont
  5. * Copyright (C) 2013 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. *
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU Lesser General Public License as published by
  14. * the Free Software Foundation; either version 2.1 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Lesser General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Lesser General Public License
  23. * along with this program; if not, write to the Free Software Foundation,
  24. * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  25. *****************************************************************************/
  26. #import <Foundation/Foundation.h>
  27. #import "VLCMediaList.h"
  28. #import "VLCTime.h"
  29. /* Meta Dictionary Keys */
  30. /**
  31. * Standard dictionary keys for retreiving meta data.
  32. */
  33. extern NSString *const VLCMetaInformationTitle; /* NSString */
  34. extern NSString *const VLCMetaInformationArtist; /* NSString */
  35. extern NSString *const VLCMetaInformationGenre; /* NSString */
  36. extern NSString *const VLCMetaInformationCopyright; /* NSString */
  37. extern NSString *const VLCMetaInformationAlbum; /* NSString */
  38. extern NSString *const VLCMetaInformationTrackNumber; /* NSString */
  39. extern NSString *const VLCMetaInformationDescription; /* NSString */
  40. extern NSString *const VLCMetaInformationRating; /* NSString */
  41. extern NSString *const VLCMetaInformationDate; /* NSString */
  42. extern NSString *const VLCMetaInformationSetting; /* NSString */
  43. extern NSString *const VLCMetaInformationURL; /* NSString */
  44. extern NSString *const VLCMetaInformationLanguage; /* NSString */
  45. extern NSString *const VLCMetaInformationNowPlaying; /* NSString */
  46. extern NSString *const VLCMetaInformationPublisher; /* NSString */
  47. extern NSString *const VLCMetaInformationEncodedBy; /* NSString */
  48. extern NSString *const VLCMetaInformationArtworkURL; /* NSString */
  49. extern NSString *const VLCMetaInformationArtwork; /* NSImage */
  50. extern NSString *const VLCMetaInformationTrackID; /* NSString */
  51. /* Notification Messages */
  52. /**
  53. * Available notification messages.
  54. */
  55. extern NSString *const VLCMediaMetaChanged; //< Notification message for when the media's meta data has changed
  56. // Forward declarations, supresses compiler error messages
  57. @class VLCMediaList;
  58. @class VLCMedia;
  59. enum {
  60. VLCMediaStateNothingSpecial, //< Nothing
  61. VLCMediaStateBuffering, //< Stream is buffering
  62. VLCMediaStatePlaying, //< Stream is playing
  63. VLCMediaStateError, //< Can't be played because an error occurred
  64. };
  65. typedef NSInteger VLCMediaState;
  66. /**
  67. * Informal protocol declaration for VLCMedia delegates. Allows data changes to be
  68. * trapped.
  69. */
  70. @protocol VLCMediaDelegate
  71. // TODO: SubItemAdded/SubItemRemoved implementation. Not sure if we really want to implement this.
  72. ///**
  73. // * Delegate method called whenever a sub item has been added to the specified VLCMedia.
  74. // * \param aMedia The media resource that has received the new sub item.
  75. // * \param childMedia The new sub item added.
  76. // * \param index Location of the new subitem in the aMedia's sublist.
  77. // */
  78. // - (void)media:(VLCMedia *)media addedSubItem:(VLCMedia *)childMedia atIndex:(int)index;
  79. ///**
  80. // * Delegate method called whenever a sub item has been removed from the specified VLCMedia.
  81. // * \param aMedia The media resource that has had a sub item removed from.
  82. // * \param childMedia The sub item removed.
  83. // * \param index The previous location of the recently removed sub item.
  84. // */
  85. // - (void)media:(VLCMedia *)aMedia removedSubItem:(VLCMedia *)childMedia atIndex:(int)index;
  86. /**
  87. * Delegate method called whenever the meta has changed for the receiver.
  88. * \param aMedia The media resource whose meta data has been changed.
  89. * \param oldValue The old meta data value.
  90. * \param key The key of the value that was changed.
  91. */
  92. - (void)media:(VLCMedia *)aMedia metaValueChangedFrom:(id)oldValue forKey:(NSString *)key;
  93. /**
  94. * Delegate method called whenever the media was parsed.
  95. * \param aMedia The media resource whose meta data has been changed.
  96. */
  97. - (void)mediaDidFinishParsing:(VLCMedia *)aMedia;
  98. @end
  99. /**
  100. * Defines files and streams as a managed object. Each media object can be
  101. * administered seperately. VLCMediaPlayer or VLCMediaList must be used
  102. * to execute the appropriate playback functions.
  103. * \see VLCMediaPlayer
  104. * \see VLCMediaList
  105. */
  106. @interface VLCMedia : NSObject
  107. {
  108. void * p_md; //< Internal media descriptor instance
  109. NSURL * url; //< URL (MRL) for this media resource
  110. VLCMediaList * subitems; //< Sub list of items
  111. VLCTime * length; //< Cached duration of the media
  112. NSMutableDictionary * metaDictionary; //< Meta data storage
  113. id delegate; //< Delegate object
  114. BOOL isArtFetched; //< Value used to determine of the artwork has been parsed
  115. BOOL areOthersMetaFetched; //< Value used to determine of the other meta has been parsed
  116. BOOL isArtURLFetched; //< Value used to determine of the other meta has been preparsed
  117. VLCMediaState state; //< Current state of the media
  118. BOOL isParsed;
  119. }
  120. /* Factories */
  121. /**
  122. * Manufactures a new VLCMedia object using the URL specified.
  123. * \param anURL URL to media to be accessed.
  124. * \return A new VLCMedia object, only if there were no errors. This object will be automatically released.
  125. * \see initWithMediaURL
  126. */
  127. + (id)mediaWithURL:(NSURL *)anURL;
  128. /**
  129. * Manufactures a new VLCMedia object using the path specified.
  130. * \param aPath Path to the media to be accessed.
  131. * \return A new VLCMedia object, only if there were no errors. This object will be automatically released.
  132. * \see initWithPath
  133. */
  134. + (id)mediaWithPath:(NSString *)aPath;
  135. /**
  136. * TODO
  137. * \param aName TODO
  138. * \return a new VLCMedia object, only if there were no errors. This object
  139. * will be automatically released.
  140. * \see initAsNodeWithName
  141. */
  142. + (id)mediaAsNodeWithName:(NSString *)aName;
  143. /* Initializers */
  144. /**
  145. * Initializes a new VLCMedia object to use the specified URL.
  146. * \param aPath Path to media to be accessed.
  147. * \return A new VLCMedia object, only if there were no errors.
  148. */
  149. - (id)initWithURL:(NSURL *)anURL;
  150. /**
  151. * Initializes a new VLCMedia object to use the specified path.
  152. * \param aPath Path to media to be accessed.
  153. * \return A new VLCMedia object, only if there were no errors.
  154. */
  155. - (id)initWithPath:(NSString *)aPath;
  156. /**
  157. * TODO
  158. * \param aName TODO
  159. * \return A new VLCMedia object, only if there were no errors.
  160. */
  161. - (id)initAsNodeWithName:(NSString *)aName;
  162. /**
  163. * Returns an NSComparisonResult value that indicates the lexical ordering of
  164. * the receiver and a given meda.
  165. * \param media The media with which to compare with the receiver.
  166. * \return NSOrderedAscending if the URL of the receiver precedes media in
  167. * lexical ordering, NSOrderedSame if the URL of the receiver and media are
  168. * equivalent in lexical value, and NSOrderedDescending if the URL of the
  169. * receiver follows media. If media is nil, returns NSOrderedDescending.
  170. */
  171. - (NSComparisonResult)compare:(VLCMedia *)media;
  172. /* Properties */
  173. /**
  174. * Receiver's delegate.
  175. */
  176. @property (assign) id delegate;
  177. /**
  178. * A VLCTime object describing the length of the media resource, only if it is
  179. * available. Use lengthWaitUntilDate: to wait for a specified length of time.
  180. * \see lengthWaitUntilDate
  181. */
  182. @property (retain, readonly) VLCTime * length;
  183. /**
  184. * Returns a VLCTime object describing the length of the media resource,
  185. * however, this is a blocking operation and will wait until the preparsing is
  186. * completed before returning anything.
  187. * \param aDate Time for operation to wait until, if there are no results
  188. * before specified date then nil is returned.
  189. * \return The length of the media resource, nil if it couldn't wait for it.
  190. */
  191. - (VLCTime *)lengthWaitUntilDate:(NSDate *)aDate;
  192. /**
  193. * Determines if the media has already been preparsed.
  194. */
  195. @property (readonly) BOOL isParsed;
  196. /**
  197. * The URL for the receiver's media resource.
  198. */
  199. @property (retain, readonly) NSURL * url;
  200. /**
  201. * The receiver's sub list.
  202. */
  203. @property (retain, readonly) VLCMediaList * subitems;
  204. /**
  205. * get meta property for key
  206. * \note for performance reasons, fetching the metaDictionary will be faster!
  207. * \see metaDictionary
  208. * \see dictionary keys above
  209. */
  210. - (NSString *)metadataForKey:(NSString *)key;
  211. /**
  212. * set meta property for key
  213. * \param metadata to set as NSString
  214. * \param metadata key
  215. * \see dictionary keys above
  216. */
  217. - (void)setMetadata:(NSString *)data forKey:(NSString *)key;
  218. /**
  219. * Save the previously changed metadata
  220. * \return true if saving was successful
  221. */
  222. - (BOOL)saveMetadata;
  223. /**
  224. * The receiver's meta data as a NSDictionary object.
  225. */
  226. @property (retain, readonly) NSDictionary * metaDictionary;
  227. /**
  228. * The receiver's state, such as Playing, Error, NothingSpecial, Buffering.
  229. */
  230. @property (readonly) VLCMediaState state;
  231. /**
  232. * returns a bool whether is the media is expected to play fluently on this
  233. * device or not. It always returns YES on a Mac.*/
  234. - (BOOL)isMediaSizeSuitableForDevice;
  235. /**
  236. * Tracks information NSDictionary Possible Keys
  237. */
  238. /**
  239. * \returns a NSNumber
  240. */
  241. extern NSString *const VLCMediaTracksInformationCodec;
  242. /**
  243. * \returns a NSNumber
  244. */
  245. extern NSString *const VLCMediaTracksInformationId;
  246. /**
  247. * \returns a NSString
  248. * \see VLCMediaTracksInformationTypeAudio
  249. * \see VLCMediaTracksInformationTypeVideo
  250. * \see VLCMediaTracksInformationTypeText
  251. * \see VLCMediaTracksInformationTypeUnknown
  252. */
  253. extern NSString *const VLCMediaTracksInformationType;
  254. /**
  255. * \returns a NSNumber
  256. */
  257. extern NSString *const VLCMediaTracksInformationCodecProfile;
  258. /**
  259. * \returns a NSNumber
  260. */
  261. extern NSString *const VLCMediaTracksInformationCodecLevel;
  262. /**
  263. * \returns the bitrate as NSNumber
  264. */
  265. extern NSString *const VLCMediaTracksInformationBitrate;
  266. /**
  267. * \returns the language as NSString
  268. */
  269. extern NSString *const VLCMediaTracksInformationLanguage;
  270. /**
  271. * \returns the description as NSString
  272. */
  273. extern NSString *const VLCMediaTracksInformationDescription;
  274. /**
  275. * \returns the audio channel number as NSNumber
  276. */
  277. extern NSString *const VLCMediaTracksInformationAudioChannelsNumber;
  278. /**
  279. * \returns the audio rate as NSNumber
  280. */
  281. extern NSString *const VLCMediaTracksInformationAudioRate;
  282. /**
  283. * \returns the height as NSNumber
  284. */
  285. extern NSString *const VLCMediaTracksInformationVideoHeight;
  286. /**
  287. * \returns the width as NSNumber
  288. */
  289. extern NSString *const VLCMediaTracksInformationVideoWidth;
  290. /**
  291. * \returns the source aspect ratio as NSNumber
  292. */
  293. extern NSString *const VLCMediaTracksInformationSourceAspectRatio;
  294. /**
  295. * \returns the source aspect ratio denominator as NSNumber
  296. */
  297. extern NSString *const VLCMediaTracksInformationSourceAspectRatioDenominator;
  298. /**
  299. * \returns the frame rate as NSNumber
  300. */
  301. extern NSString *const VLCMediaTracksInformationFrameRate;
  302. /**
  303. * \returns the frame rate denominator as NSNumber
  304. */
  305. extern NSString *const VLCMediaTracksInformationFrameRateDenominator;
  306. /**
  307. * \returns the text encoding as NSString
  308. */
  309. extern NSString *const VLCMediaTracksInformationTextEncoding;
  310. /**
  311. * Tracks information NSDictionary values for
  312. * VLCMediaTracksInformationType
  313. */
  314. extern NSString *const VLCMediaTracksInformationTypeAudio;
  315. extern NSString *const VLCMediaTracksInformationTypeVideo;
  316. extern NSString *const VLCMediaTracksInformationTypeText;
  317. extern NSString *const VLCMediaTracksInformationTypeUnknown;
  318. /**
  319. * Returns the tracks information.
  320. *
  321. * This is an array of NSDictionary representing each track.
  322. * It can contain the following keys:
  323. *
  324. * \see VLCMediaTracksInformationCodec
  325. * \see VLCMediaTracksInformationId
  326. * \see VLCMediaTracksInformationType
  327. *
  328. * \see VLCMediaTracksInformationCodecProfile
  329. * \see VLCMediaTracksInformationCodecLevel
  330. *
  331. * \see VLCMediaTracksInformationBitrate
  332. * \see VLCMediaTracksInformationLanguage
  333. * \see VLCMediaTracksInformationDescription
  334. *
  335. * \see VLCMediaTracksInformationAudioChannelsNumber
  336. * \see VLCMediaTracksInformationAudioRate
  337. *
  338. * \see VLCMediaTracksInformationVideoHeight
  339. * \see VLCMediaTracksInformationVideoWidth
  340. *
  341. * \see VLCMediaTracksInformationSourceAspectRatio
  342. * \see VLCMediaTracksInformationSourceAspectDenominator
  343. *
  344. * \see VLCMediaTracksInformationFrameRate
  345. * \see VLCMediaTracksInformationFrameRateDenominator
  346. *
  347. * \see VLCMediaTracksInformationTextEncoding
  348. */
  349. - (NSArray *)tracksInformation;
  350. /**
  351. * Start asynchronously to parse the media.
  352. * This will attempt to fetch the meta data and tracks information.
  353. *
  354. * This is automatically done when an accessor requiring parsing
  355. * is called.
  356. *
  357. * \see -[VLCMediaDelegate mediaDidFinishParsing:]
  358. */
  359. - (void)parse;
  360. /**
  361. * Trigger a synchronous parsing of the media
  362. * the selector won't return until parsing finished
  363. */
  364. - (void)synchronousParse;
  365. /**
  366. * Add options to the media, that will be used to determine how
  367. * VLCMediaPlayer will read the media. This allow to use VLC advanced
  368. * reading/streaming options in a per-media basis
  369. *
  370. * The options are detailed in vlc --long-help, for instance "--sout-all"
  371. * And on the web: http://wiki.videolan.org/VLC_command-line_help
  372. */
  373. - (void) addOptions:(NSDictionary*) options;
  374. /**
  375. * Getter for statistics information
  376. * Returns a NSDictionary with NSNumbers for values.
  377. *
  378. */
  379. - (NSDictionary*) stats;
  380. #pragma mark - individual stats
  381. /**
  382. * returns the number of bytes read by the current input module
  383. * \return a NSInteger with the raw number of bytes
  384. */
  385. - (NSInteger)numberOfReadBytesOnInput;
  386. /**
  387. * returns the current input bitrate. may be 0 if the buffer is full
  388. * \return a float of the current input bitrate
  389. */
  390. - (float)inputBitrate;
  391. /**
  392. * returns the number of bytes read by the current demux module
  393. * \return a NSInteger with the raw number of bytes
  394. */
  395. - (NSInteger)numberOfReadBytesOnDemux;
  396. /**
  397. * returns the current demux bitrate. may be 0 if the buffer is empty
  398. * \return a float of the current demux bitrate
  399. */
  400. - (float)demuxBitrate;
  401. /**
  402. * returns the total number of decoded video blocks in the current media session
  403. * \return a NSInteger with the total number of decoded blocks
  404. */
  405. - (NSInteger)numberOfDecodedVideoBlocks;
  406. /**
  407. * returns the total number of decoded audio blocks in the current media session
  408. * \return a NSInteger with the total number of decoded blocks
  409. */
  410. - (NSInteger)numberOfDecodedAudioBlocks;
  411. /**
  412. * returns the total number of displayed pictures during the current media session
  413. * \return a NSInteger with the total number of displayed pictures
  414. */
  415. - (NSInteger)numberOfDisplayedPictures;
  416. /**
  417. * returns the total number of pictures lost during the current media session
  418. * \return a NSInteger with the total number of lost pictures
  419. */
  420. - (NSInteger)numberOfLostPictures;
  421. /**
  422. * returns the total number of played audio buffers during the current media session
  423. * \return a NSInteger with the total number of played audio buffers
  424. */
  425. - (NSInteger)numberOfPlayedAudioBuffers;
  426. /**
  427. * returns the total number of audio buffers lost during the current media session
  428. * \return a NSInteger with the total number of displayed pictures
  429. */
  430. - (NSInteger)numberOfLostAudioBuffers;
  431. /**
  432. * returns the total number of packets sent during the current media session
  433. * \return a NSInteger with the total number of sent packets
  434. */
  435. - (NSInteger)numberOfSentPackets;
  436. /**
  437. * returns the total number of raw bytes sent during the current media session
  438. * \return a NSInteger with the total number of sent bytes
  439. */
  440. - (NSInteger)numberOfSentBytes;
  441. /**
  442. * returns the current bitrate of sent bytes
  443. * \return a float of the current bitrate of sent bits
  444. */
  445. - (float)streamOutputBitrate;
  446. /**
  447. * returns the total number of corrupted data packets during current sout session
  448. * \note value is 0 on non-stream-output operations
  449. * \return a NSInteger with the total number of corrupted data packets
  450. */
  451. - (NSInteger)numberOfCorruptedDataPackets;
  452. /**
  453. * returns the total number of discontinuties during current sout session
  454. * \note value is 0 on non-stream-output operations
  455. * \return a NSInteger with the total number of discontinuties
  456. */
  457. - (NSInteger)numberOfDiscontinuties;
  458. @end