VLCMedia.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  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. extern NSString *const VLCMetaInformationTrackTotal; /* NSString */
  52. extern NSString *const VLCMetaInformationDirector; /* NSString */
  53. extern NSString *const VLCMetaInformationSeason; /* NSString */
  54. extern NSString *const VLCMetaInformationEpisode; /* NSString */
  55. extern NSString *const VLCMetaInformationShowName; /* NSString */
  56. extern NSString *const VLCMetaInformationActors; /* NSString */
  57. extern NSString *const VLCMetaInformationAlbumArtist; /* NSString */
  58. extern NSString *const VLCMetaInformationDiscNumber; /* NSString */
  59. /* Notification Messages */
  60. /**
  61. * Available notification messages.
  62. */
  63. extern NSString *const VLCMediaMetaChanged; //< Notification message for when the media's meta data has changed
  64. // Forward declarations, supresses compiler error messages
  65. @class VLCMediaList;
  66. @class VLCMedia;
  67. typedef NS_ENUM(NSInteger, VLCMediaState) {
  68. VLCMediaStateNothingSpecial, //< Nothing
  69. VLCMediaStateBuffering, //< Stream is buffering
  70. VLCMediaStatePlaying, //< Stream is playing
  71. VLCMediaStateError, //< Can't be played because an error occurred
  72. };
  73. /**
  74. * Informal protocol declaration for VLCMedia delegates. Allows data changes to be
  75. * trapped.
  76. */
  77. @protocol VLCMediaDelegate <NSObject>
  78. // TODO: SubItemAdded/SubItemRemoved implementation. Not sure if we really want to implement this.
  79. ///**
  80. // * Delegate method called whenever a sub item has been added to the specified VLCMedia.
  81. // * \param aMedia The media resource that has received the new sub item.
  82. // * \param childMedia The new sub item added.
  83. // * \param index Location of the new subitem in the aMedia's sublist.
  84. // */
  85. // - (void)media:(VLCMedia *)media addedSubItem:(VLCMedia *)childMedia atIndex:(int)index;
  86. ///**
  87. // * Delegate method called whenever a sub item has been removed from the specified VLCMedia.
  88. // * \param aMedia The media resource that has had a sub item removed from.
  89. // * \param childMedia The sub item removed.
  90. // * \param index The previous location of the recently removed sub item.
  91. // */
  92. // - (void)media:(VLCMedia *)aMedia removedSubItem:(VLCMedia *)childMedia atIndex:(int)index;
  93. @optional
  94. /**
  95. * Delegate method called whenever the media's meta data was changed for whatever reason
  96. * \note this is called more often than mediaDidFinishParsing, so it may be less efficient
  97. * \param aMedia The media resource whose meta data has been changed.
  98. */
  99. - (void)mediaMetaDataDidChange:(VLCMedia *)aMedia;
  100. /**
  101. * Delegate method called whenever the media was parsed.
  102. * \param aMedia The media resource whose meta data has been changed.
  103. */
  104. - (void)mediaDidFinishParsing:(VLCMedia *)aMedia;
  105. @end
  106. /**
  107. * Defines files and streams as a managed object. Each media object can be
  108. * administered seperately. VLCMediaPlayer or VLCMediaList must be used
  109. * to execute the appropriate playback functions.
  110. * \see VLCMediaPlayer
  111. * \see VLCMediaList
  112. */
  113. @interface VLCMedia : NSObject
  114. /* Factories */
  115. /**
  116. * Manufactures a new VLCMedia object using the URL specified.
  117. * \param anURL URL to media to be accessed.
  118. * \return A new VLCMedia object, only if there were no errors. This object will be automatically released.
  119. * \see initWithMediaURL
  120. */
  121. + (instancetype)mediaWithURL:(NSURL *)anURL;
  122. /**
  123. * Manufactures a new VLCMedia object using the path specified.
  124. * \param aPath Path to the media to be accessed.
  125. * \return A new VLCMedia object, only if there were no errors. This object will be automatically released.
  126. * \see initWithPath
  127. */
  128. + (instancetype)mediaWithPath:(NSString *)aPath;
  129. /**
  130. * convienience method to return a user-readable codec name for the given FourCC
  131. * \param uint32_t the FourCC to process
  132. * \param NSString a VLC track type if known to speed-up the name search
  133. * \return a NSString containing the codec name if recognized, else an empty string
  134. */
  135. + (NSString *)codecNameForFourCC:(uint32_t)fourcc trackType:(NSString *)trackType;
  136. /**
  137. * TODO
  138. * \param aName TODO
  139. * \return a new VLCMedia object, only if there were no errors. This object
  140. * will be automatically released.
  141. * \see initAsNodeWithName
  142. */
  143. + (instancetype)mediaAsNodeWithName:(NSString *)aName;
  144. /* Initializers */
  145. /**
  146. * Initializes a new VLCMedia object to use the specified URL.
  147. * \param aPath Path to media to be accessed.
  148. * \return A new VLCMedia object, only if there were no errors.
  149. */
  150. - (instancetype)initWithURL:(NSURL *)anURL;
  151. /**
  152. * Initializes a new VLCMedia object to use the specified path.
  153. * \param aPath Path to media to be accessed.
  154. * \return A new VLCMedia object, only if there were no errors.
  155. */
  156. - (instancetype)initWithPath:(NSString *)aPath;
  157. /**
  158. * TODO
  159. * \param aName TODO
  160. * \return A new VLCMedia object, only if there were no errors.
  161. */
  162. - (instancetype)initAsNodeWithName:(NSString *)aName;
  163. typedef NS_ENUM(NSUInteger, VLCMediaType) {
  164. VLCMediaTypeUnknown,
  165. VLCMediaTypeFile,
  166. VLCMediaTypeDirectory,
  167. VLCMediaTypeDisc,
  168. VLCMediaTypeStream,
  169. VLCMediaTypePlaylist,
  170. };
  171. /**
  172. * media type
  173. * \return returns the type of a media (VLCMediaType)
  174. */
  175. @property (readonly) VLCMediaType mediaType;
  176. /**
  177. * Returns an NSComparisonResult value that indicates the lexical ordering of
  178. * the receiver and a given meda.
  179. * \param media The media with which to compare with the receiver.
  180. * \return NSOrderedAscending if the URL of the receiver precedes media in
  181. * lexical ordering, NSOrderedSame if the URL of the receiver and media are
  182. * equivalent in lexical value, and NSOrderedDescending if the URL of the
  183. * receiver follows media. If media is nil, returns NSOrderedDescending.
  184. */
  185. - (NSComparisonResult)compare:(VLCMedia *)media;
  186. /* Properties */
  187. /**
  188. * Receiver's delegate.
  189. */
  190. @property (nonatomic, weak) id<VLCMediaDelegate> delegate;
  191. /**
  192. * A VLCTime object describing the length of the media resource, only if it is
  193. * available. Use lengthWaitUntilDate: to wait for a specified length of time.
  194. * \see lengthWaitUntilDate
  195. */
  196. @property (nonatomic, readwrite, strong) VLCTime * length;
  197. /**
  198. * Returns a VLCTime object describing the length of the media resource,
  199. * however, this is a blocking operation and will wait until the preparsing is
  200. * completed before returning anything.
  201. * \param aDate Time for operation to wait until, if there are no results
  202. * before specified date then nil is returned.
  203. * \return The length of the media resource, nil if it couldn't wait for it.
  204. */
  205. - (VLCTime *)lengthWaitUntilDate:(NSDate *)aDate;
  206. /**
  207. * Determines if the media has already been preparsed.
  208. */
  209. @property (nonatomic, readonly) BOOL isParsed;
  210. /**
  211. * The URL for the receiver's media resource.
  212. */
  213. @property (nonatomic, readonly, strong) NSURL * url;
  214. /**
  215. * The receiver's sub list.
  216. */
  217. @property (nonatomic, readonly, strong) VLCMediaList * subitems;
  218. /**
  219. * get meta property for key
  220. * \note for performance reasons, fetching the metaDictionary will be faster!
  221. * \see metaDictionary
  222. * \see dictionary keys above
  223. */
  224. - (NSString *)metadataForKey:(NSString *)key;
  225. /**
  226. * set meta property for key
  227. * \param metadata to set as NSString
  228. * \param metadata key
  229. * \see dictionary keys above
  230. */
  231. - (void)setMetadata:(NSString *)data forKey:(NSString *)key;
  232. /**
  233. * Save the previously changed metadata
  234. * \return true if saving was successful
  235. */
  236. @property (NS_NONATOMIC_IOSONLY, readonly) BOOL saveMetadata;
  237. /**
  238. * The receiver's meta data as a NSDictionary object.
  239. */
  240. @property (nonatomic, readonly, copy) NSDictionary * metaDictionary;
  241. /**
  242. * The receiver's state, such as Playing, Error, NothingSpecial, Buffering.
  243. */
  244. @property (nonatomic, readonly) VLCMediaState state;
  245. /**
  246. * returns a bool whether is the media is expected to play fluently on this
  247. * device or not. It always returns YES on a Mac.*/
  248. @property (NS_NONATOMIC_IOSONLY, getter=isMediaSizeSuitableForDevice, readonly) BOOL mediaSizeSuitableForDevice;
  249. /**
  250. * Tracks information NSDictionary Possible Keys
  251. */
  252. /**
  253. * \returns a NSNumber
  254. */
  255. extern NSString *const VLCMediaTracksInformationCodec;
  256. /**
  257. * \returns a NSNumber
  258. */
  259. extern NSString *const VLCMediaTracksInformationId;
  260. /**
  261. * \returns a NSString
  262. * \see VLCMediaTracksInformationTypeAudio
  263. * \see VLCMediaTracksInformationTypeVideo
  264. * \see VLCMediaTracksInformationTypeText
  265. * \see VLCMediaTracksInformationTypeUnknown
  266. */
  267. extern NSString *const VLCMediaTracksInformationType;
  268. /**
  269. * \returns a NSNumber
  270. */
  271. extern NSString *const VLCMediaTracksInformationCodecProfile;
  272. /**
  273. * \returns a NSNumber
  274. */
  275. extern NSString *const VLCMediaTracksInformationCodecLevel;
  276. /**
  277. * \returns the bitrate as NSNumber
  278. */
  279. extern NSString *const VLCMediaTracksInformationBitrate;
  280. /**
  281. * \returns the language as NSString
  282. */
  283. extern NSString *const VLCMediaTracksInformationLanguage;
  284. /**
  285. * \returns the description as NSString
  286. */
  287. extern NSString *const VLCMediaTracksInformationDescription;
  288. /**
  289. * \returns the audio channel number as NSNumber
  290. */
  291. extern NSString *const VLCMediaTracksInformationAudioChannelsNumber;
  292. /**
  293. * \returns the audio rate as NSNumber
  294. */
  295. extern NSString *const VLCMediaTracksInformationAudioRate;
  296. /**
  297. * \returns the height as NSNumber
  298. */
  299. extern NSString *const VLCMediaTracksInformationVideoHeight;
  300. /**
  301. * \returns the width as NSNumber
  302. */
  303. extern NSString *const VLCMediaTracksInformationVideoWidth;
  304. /**
  305. * \returns the source aspect ratio as NSNumber
  306. */
  307. extern NSString *const VLCMediaTracksInformationSourceAspectRatio;
  308. /**
  309. * \returns the source aspect ratio denominator as NSNumber
  310. */
  311. extern NSString *const VLCMediaTracksInformationSourceAspectRatioDenominator;
  312. /**
  313. * \returns the frame rate as NSNumber
  314. */
  315. extern NSString *const VLCMediaTracksInformationFrameRate;
  316. /**
  317. * \returns the frame rate denominator as NSNumber
  318. */
  319. extern NSString *const VLCMediaTracksInformationFrameRateDenominator;
  320. /**
  321. * \returns the text encoding as NSString
  322. */
  323. extern NSString *const VLCMediaTracksInformationTextEncoding;
  324. /**
  325. * Tracks information NSDictionary values for
  326. * VLCMediaTracksInformationType
  327. */
  328. extern NSString *const VLCMediaTracksInformationTypeAudio;
  329. extern NSString *const VLCMediaTracksInformationTypeVideo;
  330. extern NSString *const VLCMediaTracksInformationTypeText;
  331. extern NSString *const VLCMediaTracksInformationTypeUnknown;
  332. /**
  333. * Returns the tracks information.
  334. *
  335. * This is an array of NSDictionary representing each track.
  336. * It can contain the following keys:
  337. *
  338. * \see VLCMediaTracksInformationCodec
  339. * \see VLCMediaTracksInformationId
  340. * \see VLCMediaTracksInformationType
  341. *
  342. * \see VLCMediaTracksInformationCodecProfile
  343. * \see VLCMediaTracksInformationCodecLevel
  344. *
  345. * \see VLCMediaTracksInformationBitrate
  346. * \see VLCMediaTracksInformationLanguage
  347. * \see VLCMediaTracksInformationDescription
  348. *
  349. * \see VLCMediaTracksInformationAudioChannelsNumber
  350. * \see VLCMediaTracksInformationAudioRate
  351. *
  352. * \see VLCMediaTracksInformationVideoHeight
  353. * \see VLCMediaTracksInformationVideoWidth
  354. *
  355. * \see VLCMediaTracksInformationSourceAspectRatio
  356. * \see VLCMediaTracksInformationSourceAspectDenominator
  357. *
  358. * \see VLCMediaTracksInformationFrameRate
  359. * \see VLCMediaTracksInformationFrameRateDenominator
  360. *
  361. * \see VLCMediaTracksInformationTextEncoding
  362. */
  363. @property (NS_NONATOMIC_IOSONLY, readonly, copy) NSArray *tracksInformation;
  364. /**
  365. * Start asynchronously to parse the media.
  366. * This will attempt to fetch the meta data and tracks information.
  367. *
  368. * This is automatically done when an accessor requiring parsing
  369. * is called.
  370. *
  371. * \see -[VLCMediaDelegate mediaDidFinishParsing:]
  372. */
  373. - (void)parse;
  374. /**
  375. * Trigger a synchronous parsing of the media
  376. * the selector won't return until parsing finished
  377. */
  378. - (void)synchronousParse;
  379. enum {
  380. VLCMediaParseLocal = 0x00,
  381. VLCMediaParseNetwork = 0x01,
  382. VLCMediaFetchLocal = 0x02,
  383. VLCMediaFetchNetwork = 0x04,
  384. };
  385. typedef int VLCMediaParsingOptions;
  386. /**
  387. * triggers an asynchronous parse of the media item
  388. * using the given options
  389. * \param the option mask based on VLCMediaParsingOptions
  390. * \see VLCMediaParsingOptions
  391. * \return an int. 0 on success, -1 in case of error
  392. * \note listen to the "parsed" key value or the mediaDidFinishParsing:
  393. * delegate method to be notified about parsing results. Those triggers
  394. * will _NOT_ be raised if parsing fails and this method returns an error.
  395. */
  396. - (int)parseWithOptions:(VLCMediaParsingOptions)options;
  397. /**
  398. * Add options to the media, that will be used to determine how
  399. * VLCMediaPlayer will read the media. This allow to use VLC advanced
  400. * reading/streaming options in a per-media basis
  401. *
  402. * The options are detailed in vlc --long-help, for instance "--sout-all"
  403. * And on the web: http://wiki.videolan.org/VLC_command-line_help
  404. */
  405. - (void) addOptions:(NSDictionary*) options;
  406. /**
  407. * Getter for statistics information
  408. * Returns a NSDictionary with NSNumbers for values.
  409. *
  410. */
  411. @property (NS_NONATOMIC_IOSONLY, readonly, copy) NSDictionary *stats;
  412. #pragma mark - individual stats
  413. /**
  414. * returns the number of bytes read by the current input module
  415. * \return a NSInteger with the raw number of bytes
  416. */
  417. @property (NS_NONATOMIC_IOSONLY, readonly) NSInteger numberOfReadBytesOnInput;
  418. /**
  419. * returns the current input bitrate. may be 0 if the buffer is full
  420. * \return a float of the current input bitrate
  421. */
  422. @property (NS_NONATOMIC_IOSONLY, readonly) float inputBitrate;
  423. /**
  424. * returns the number of bytes read by the current demux module
  425. * \return a NSInteger with the raw number of bytes
  426. */
  427. @property (NS_NONATOMIC_IOSONLY, readonly) NSInteger numberOfReadBytesOnDemux;
  428. /**
  429. * returns the current demux bitrate. may be 0 if the buffer is empty
  430. * \return a float of the current demux bitrate
  431. */
  432. @property (NS_NONATOMIC_IOSONLY, readonly) float demuxBitrate;
  433. /**
  434. * returns the total number of decoded video blocks in the current media session
  435. * \return a NSInteger with the total number of decoded blocks
  436. */
  437. @property (NS_NONATOMIC_IOSONLY, readonly) NSInteger numberOfDecodedVideoBlocks;
  438. /**
  439. * returns the total number of decoded audio blocks in the current media session
  440. * \return a NSInteger with the total number of decoded blocks
  441. */
  442. @property (NS_NONATOMIC_IOSONLY, readonly) NSInteger numberOfDecodedAudioBlocks;
  443. /**
  444. * returns the total number of displayed pictures during the current media session
  445. * \return a NSInteger with the total number of displayed pictures
  446. */
  447. @property (NS_NONATOMIC_IOSONLY, readonly) NSInteger numberOfDisplayedPictures;
  448. /**
  449. * returns the total number of pictures lost during the current media session
  450. * \return a NSInteger with the total number of lost pictures
  451. */
  452. @property (NS_NONATOMIC_IOSONLY, readonly) NSInteger numberOfLostPictures;
  453. /**
  454. * returns the total number of played audio buffers during the current media session
  455. * \return a NSInteger with the total number of played audio buffers
  456. */
  457. @property (NS_NONATOMIC_IOSONLY, readonly) NSInteger numberOfPlayedAudioBuffers;
  458. /**
  459. * returns the total number of audio buffers lost during the current media session
  460. * \return a NSInteger with the total number of displayed pictures
  461. */
  462. @property (NS_NONATOMIC_IOSONLY, readonly) NSInteger numberOfLostAudioBuffers;
  463. /**
  464. * returns the total number of packets sent during the current media session
  465. * \return a NSInteger with the total number of sent packets
  466. */
  467. @property (NS_NONATOMIC_IOSONLY, readonly) NSInteger numberOfSentPackets;
  468. /**
  469. * returns the total number of raw bytes sent during the current media session
  470. * \return a NSInteger with the total number of sent bytes
  471. */
  472. @property (NS_NONATOMIC_IOSONLY, readonly) NSInteger numberOfSentBytes;
  473. /**
  474. * returns the current bitrate of sent bytes
  475. * \return a float of the current bitrate of sent bits
  476. */
  477. @property (NS_NONATOMIC_IOSONLY, readonly) float streamOutputBitrate;
  478. /**
  479. * returns the total number of corrupted data packets during current sout session
  480. * \note value is 0 on non-stream-output operations
  481. * \return a NSInteger with the total number of corrupted data packets
  482. */
  483. @property (NS_NONATOMIC_IOSONLY, readonly) NSInteger numberOfCorruptedDataPackets;
  484. /**
  485. * returns the total number of discontinuties during current sout session
  486. * \note value is 0 on non-stream-output operations
  487. * \return a NSInteger with the total number of discontinuties
  488. */
  489. @property (NS_NONATOMIC_IOSONLY, readonly) NSInteger numberOfDiscontinuties;
  490. @end