Interfaces.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980
  1. using UnityEngine;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. //-----------------------------------------------------------------------------
  6. // Copyright 2015-2021 RenderHeads Ltd. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. namespace RenderHeads.Media.AVProVideo
  9. {
  10. public interface IMediaPlayer
  11. {
  12. void OnEnable();
  13. void Update();
  14. void EndUpdate();
  15. void Render();
  16. IntPtr GetNativePlayerHandle();
  17. }
  18. /// <summary>
  19. /// Interface for side loading of subtitles in SRT format
  20. /// </summary>
  21. public interface IMediaSubtitles
  22. {
  23. bool LoadSubtitlesSRT(string data);
  24. int GetSubtitleIndex();
  25. string GetSubtitleText();
  26. }
  27. public enum BufferedFrameSelectionMode : int
  28. {
  29. // No buffering, just selects the latest decoded frame
  30. None = 0,
  31. // Selects the newest buffered frame, and displays it until a newer frame is available
  32. NewestFrame = 10,
  33. // Selects the oldest buffered frame, and displays it until a newer frame is available
  34. OldestFrame = 11,
  35. // Selects the next buffered frame, and displays it until the number of buffered frames changes
  36. MediaClock = 20,
  37. // Uses Time.deltaTime to keep a clock which is used to select the buffered frame
  38. ElapsedTime = 30,
  39. // Uses VSync delta time to keep a clock which is used to select the buffered frame
  40. // Time.deltaTime is used to calculate the number of vsyncs that have elapsed
  41. ElapsedTimeVsynced = 40,
  42. // Selects the buffered frame corresponding to the external timeStamp (useful for frame-syncing players)
  43. FromExternalTime = 50,
  44. // Selects the closest buffered frame corresponding to the external timeStamp (useful for frame-syncing players)
  45. FromExternalTimeClosest = 51,
  46. }
  47. /// <summary>
  48. /// Interface for buffering frames for more control over the timing of their display
  49. /// </summary>
  50. public interface IBufferedDisplay
  51. {
  52. /// <summary>
  53. /// We need to manually call UpdateBufferedDisplay() in the case of master-slave synced playback so that master is updated before slaves
  54. /// </summary>
  55. long UpdateBufferedDisplay();
  56. BufferedFramesState GetBufferedFramesState();
  57. void SetSlaves(IBufferedDisplay[] slaves);
  58. void SetBufferedDisplayMode(BufferedFrameSelectionMode mode, IBufferedDisplay master = null);
  59. void SetBufferedDisplayOptions(bool pauseOnPrerollComplete);
  60. }
  61. public interface IMediaControl
  62. {
  63. /// <summary>
  64. /// Be careful using this method directly. It is best to instead use the OpenMedia() method in the MediaPlayer component as this will set up the events correctly and also perform other checks
  65. /// customHttpHeaders is in the format "key1:value1\r\nkey2:value2\r\n"=
  66. /// </summary>
  67. bool OpenMedia(string path, long offset, string customHttpHeaders, MediaHints mediahints, int forceFileFormat = 0, bool startWithHighestBitrate = false);
  68. bool OpenMediaFromBuffer(byte[] buffer);
  69. bool StartOpenMediaFromBuffer(ulong length);
  70. bool AddChunkToMediaBuffer(byte[] chunk, ulong offset, ulong length);
  71. bool EndOpenMediaFromBuffer();
  72. #if NETFX_CORE
  73. bool OpenMedia(Windows.Storage.Streams.IRandomAccessStream ras, string path, long offset, string customHttpHeaders);
  74. #endif
  75. void CloseMedia();
  76. void SetLooping(bool bLooping);
  77. bool IsLooping();
  78. bool HasMetaData();
  79. bool CanPlay();
  80. bool IsPlaying();
  81. bool IsSeeking();
  82. bool IsPaused();
  83. bool IsFinished();
  84. bool IsBuffering();
  85. void Play();
  86. void Pause();
  87. void Stop();
  88. void Rewind();
  89. /// <summary>
  90. /// The time in seconds seeked will be to the exact time
  91. /// This can take a long time is the keyframes are far apart
  92. /// Some platforms don't support this and instead seek to the closest keyframe
  93. /// </summary>
  94. void Seek(double time);
  95. /// <summary>
  96. /// The time in seconds seeked will be to the closest keyframe
  97. /// </summary>
  98. void SeekFast(double time);
  99. /// <summary>
  100. /// The time in seconds seeked to will be within the range [time-timeDeltaBefore, time+timeDeltaAfter] for efficiency.
  101. /// Only supported on macOS, iOS and tvOS.
  102. /// Other platforms will automatically pass through to Seek()
  103. /// </summary>
  104. void SeekWithTolerance(double time, double timeDeltaBefore, double timeDeltaAfter);
  105. /// <summary>
  106. /// Seek to a specific frame, range is [0, GetMaxFrameNumber()]
  107. /// NOTE: For best results the video should be encoded as keyframes only
  108. /// and have no audio track, or an audio track with the same length as the video track
  109. /// </summary>
  110. void SeekToFrame(int frame, float overrideFrameRate = 0f);
  111. /// <summary>
  112. /// Seek forwards or backwards relative to the current frame
  113. /// NOTE: For best results the video should be encoded as keyframes only
  114. /// and have no audio track, or an audio track with the same length as the video track
  115. /// </summary>
  116. void SeekToFrameRelative(int frameOffset, float overrideFrameRate = 0f);
  117. /// <summary>
  118. /// Returns the current video time in seconds
  119. /// </summary>
  120. double GetCurrentTime();
  121. /// <summary>
  122. /// Returns the current video time in frames, range is [0, GetMaxFrameNumber()]
  123. /// NOTE: For best results the video should be encoded as keyframes only
  124. /// and have no audio track, or an audio track with the same length as the video track
  125. /// </summary>
  126. int GetCurrentTimeFrames(float overrideFrameRate = 0f);
  127. /// <summary>
  128. /// Returns the current video date and time usually from the
  129. /// EXT-X-PROGRAM-DATE-TIME tag on HLS streams
  130. /// Only supported on macOS, iOS, tvOS and Android (using ExoPlayer API)
  131. /// And Windows 10 using WinRT API
  132. /// </summary>
  133. System.DateTime GetProgramDateTime();
  134. float GetPlaybackRate();
  135. void SetPlaybackRate(float rate);
  136. void MuteAudio(bool bMute);
  137. bool IsMuted();
  138. void SetVolume(float volume);
  139. void SetBalance(float balance);
  140. float GetVolume();
  141. float GetBalance();
  142. /*int GetCurrentVideoTrack();
  143. void SetVideoTrack(int index);
  144. int GetCurrentAudioTrack();
  145. void SetAudioTrack(int index);*/
  146. /// <summary>
  147. /// Returns a range of time values that can be seeked in seconds
  148. /// </summary>
  149. TimeRanges GetSeekableTimes();
  150. /// <summary>
  151. /// Returns a range of time values that contain fully downloaded segments,
  152. /// which can be seeked to immediately without requiring additional downloading
  153. /// </summary>
  154. TimeRanges GetBufferedTimes();
  155. ErrorCode GetLastError();
  156. long GetLastExtendedErrorCode();
  157. void SetTextureProperties(FilterMode filterMode = FilterMode.Bilinear, TextureWrapMode wrapMode = TextureWrapMode.Clamp, int anisoLevel = 1);
  158. void GetTextureProperties(out FilterMode filterMode, out TextureWrapMode wrapMode, out int anisoLevel);
  159. // Audio Grabbing
  160. /// <summary>
  161. /// Copies the specified amount of audio into the buffer
  162. /// If the specified amount is not yet available then nothing no samples are copied
  163. /// The number of audio samples grabbed are returned
  164. /// </summary>
  165. int GrabAudio(float[] buffer, int sampleCount, int channelCount);
  166. int GetAudioBufferedSampleCount();
  167. int GetAudioChannelCount();
  168. AudioChannelMaskFlags GetAudioChannelMask();
  169. // Audio 360
  170. void SetAudioChannelMode(Audio360ChannelMode channelMode);
  171. void SetAudioHeadRotation(Quaternion q);
  172. void ResetAudioHeadRotation();
  173. void SetAudioFocusEnabled(bool enabled);
  174. void SetAudioFocusProperties(float offFocusLevel, float widthDegrees);
  175. void SetAudioFocusRotation(Quaternion q);
  176. void ResetAudioFocus();
  177. bool WaitForNextFrame(Camera dummyCamera, int previousFrameCount);
  178. [Obsolete("SetPlayWithoutBuffering has been deprecated, see platform specific options for how to enable playback without buffering (if supported).")]
  179. void SetPlayWithoutBuffering(bool playWithoutBuffering);
  180. // Encrypted stream support
  181. //void SetKeyServerURL(string url);
  182. void SetKeyServerAuthToken(string token);
  183. void SetOverrideDecryptionKey(byte[] key);
  184. // External playback support.
  185. /// <summary>
  186. /// Check to see if external playback is currently active on the player.
  187. /// </summary>
  188. bool IsExternalPlaybackActive();
  189. /// <summary>
  190. /// Set whether the player is allowed to switch to external playback, e.g. AirPlay.
  191. /// </summary>
  192. void SetAllowsExternalPlayback(bool enable);
  193. /// <summary>
  194. /// Sets the video gravity of the player for external playback only.
  195. /// </summary>
  196. void SetExternalPlaybackVideoGravity(ExternalPlaybackVideoGravity gravity);
  197. }
  198. public interface IMediaInfo
  199. {
  200. /// <summary>
  201. /// Returns media duration in seconds
  202. /// </summary>
  203. double GetDuration();
  204. /// <summary>
  205. /// Returns media duration in frames
  206. /// NOTE: For best results the video should be encoded as keyframes only
  207. /// and have no audio track, or an audio track with the same length as the video track
  208. /// </summary>
  209. int GetDurationFrames(float overrideFrameRate = 0f);
  210. /// <summary>
  211. /// Returns highest frame number that can be seeked to
  212. /// NOTE: For best results the video should be encoded as keyframes only
  213. /// and have no audio track, or an audio track with the same length as the video track
  214. /// </summary>
  215. int GetMaxFrameNumber(float overrideFrameRate = 0f);
  216. /// <summary>
  217. /// Returns video width in pixels
  218. /// </summary>
  219. int GetVideoWidth();
  220. /// <summary>
  221. /// Returns video height in pixels
  222. /// </summary>
  223. int GetVideoHeight();
  224. /// <summary>
  225. /// Returns the frame rate of the media.
  226. /// </summary>
  227. float GetVideoFrameRate();
  228. /// <summary>
  229. /// Returns the current achieved display rate in frames per second
  230. /// </summary>
  231. float GetVideoDisplayRate();
  232. /// <summary>
  233. /// Returns true if the media has a visual track
  234. /// </summary>
  235. bool HasVideo();
  236. /// <summary>
  237. /// Returns true if the media has a audio track
  238. /// </summary>
  239. bool HasAudio();
  240. /// <summary>
  241. /// Returns the a description of which playback path is used internally.
  242. /// This can for example expose whether CPU or GPU decoding is being performed
  243. /// For Windows the available player descriptions are:
  244. /// "DirectShow" - legacy Microsoft API but still very useful especially with modern filters such as LAV
  245. /// "MF-MediaEngine-Software" - uses the Windows 8.1 features of the Microsoft Media Foundation API, but software decoding
  246. /// "MF-MediaEngine-Hardware" - uses the Windows 8.1 features of the Microsoft Media Foundation API, but GPU decoding
  247. /// Android has "MediaPlayer" and "ExoPlayer"
  248. /// macOS / tvOS / iOS just has "AVFoundation"
  249. /// </summary>
  250. string GetPlayerDescription();
  251. #if !AVPRO_NEW_GAMMA
  252. /// <summary>
  253. /// Whether this MediaPlayer instance supports linear color space
  254. /// If it doesn't then a correction may have to be made in the shader
  255. /// </summary>
  256. bool PlayerSupportsLinearColorSpace();
  257. #endif
  258. /// <summary>
  259. /// Checks if the playback is in a stalled state
  260. /// </summary>
  261. bool IsPlaybackStalled();
  262. /// <summary>
  263. /// The affine transform of the texture as an array of six floats: a, b, c, d, tx, ty.
  264. /// </summary>
  265. float[] GetTextureTransform();
  266. /// <summary>
  267. /// Gets the estimated bandwidth used by all video players (in bits per second)
  268. /// Currently only supported on Android when using ExoPlayer API
  269. /// </summary>
  270. long GetEstimatedTotalBandwidthUsed();
  271. /*
  272. string GetMediaDescription();
  273. string GetVideoDescription();
  274. string GetAudioDescription();*/
  275. /// <summary>
  276. /// Checks if the media is compatible with external playback, for instance via AirPlay.
  277. /// </summary>
  278. bool IsExternalPlaybackSupported();
  279. // Internal method
  280. bool GetDecoderPerformance(ref int activeDecodeThreadCount, ref int decodedFrameCount, ref int droppedFrameCount);
  281. // Internal method
  282. PlaybackQualityStats GetPlaybackQualityStats();
  283. }
  284. #region MediaCaching
  285. /// <summary>Options for configuring media caching.</summary>
  286. public class MediaCachingOptions
  287. {
  288. /// <summary>The minimum bitrate of the media to cache in bits per second.</summary>
  289. public double minimumRequiredBitRate;
  290. /// <summary>The minimum resolution of the media to cache.</summary>
  291. /// <remark>Only supported on Android and iOS 14 and later.</remark>
  292. public Vector2 minimumRequiredResolution;
  293. /// <summary>The maximum bitrate of the media to cache in bits per second.</summary>
  294. /// <remark>Only supported on Android.</remark>
  295. public double maximumRequiredBitRate;
  296. /// <summary>The maximum resolution of the media to cache.</summary>
  297. /// <remark>Only supported on Android.</remark>
  298. public Vector2 maximumRequiredResolution;
  299. /// <summary>Human readable title for the cached media.</summary>
  300. /// <remark>iOS: This value will be displayed in the usage pane of the settings app.</remark>
  301. public string title;
  302. /// <summary>Optional artwork for the cached media in PNG format.</summary>
  303. /// <remark>iOS: This value will be displayed in the usage pane of the settings app.</remark>
  304. public byte[] artwork;
  305. }
  306. /// <summary>Status of the media item in the cache.</summary>
  307. public enum CachedMediaStatus: int
  308. {
  309. /// <summary>The media has not been cached.</summary>
  310. NotCached,
  311. /// <summary>The media is being cached.</summary>
  312. Caching,
  313. /// <summary>The media is cached.</summary>
  314. Cached,
  315. /// <summary>The media is not cached, something went wrong - check the log.</summary>
  316. Failed,
  317. /// <summary>The media caching is paused.</summary>
  318. Paused
  319. }
  320. /// <summary>Interface for the media cache.</summary>
  321. public interface IMediaCache
  322. {
  323. /// <summary>Test to see if the player can cache media.</summary>
  324. /// <returns>True if media caching is supported.</returns>
  325. bool IsMediaCachingSupported();
  326. /// <summary>Cache the media specified by url.</summary>
  327. /// <param name="url">The url of the media.</param>
  328. /// <param name="headers"></param>
  329. /// <param name="options"></param>
  330. void AddMediaToCache(string url, string headers = null, MediaCachingOptions options = null);
  331. /// <summary>Cancels the download of the media specified by url.</summary>
  332. /// <param name="url">The url of the media.</param>
  333. void CancelDownloadOfMediaToCache(string url);
  334. /// <summary>Pause the download of the media specified by url.</summary>
  335. /// <param name="url">The url of the media.</param>
  336. void PauseDownloadOfMediaToCache(string url);
  337. /// <summary>Resume the download of the media specified by url.</summary>
  338. /// <param name="url">The url of the media.</param>
  339. void ResumeDownloadOfMediaToCache(string url);
  340. /// <summary>Remove the cached media specified by url.</summary>
  341. /// <param name="url">The url of the media.</param>
  342. void RemoveMediaFromCache(string url);
  343. /// <summary>Get the cached status for the media specified.</summary>
  344. /// <param name="url">The url of the media.</param>
  345. /// <param name="progress">The amount of the media that has been cached in the range [0...1].</param>
  346. /// <returns>The status of the media.</returns>
  347. CachedMediaStatus GetCachedMediaStatus(string url, ref float progress);
  348. // /// <summary>Test if the currently open media is cached.</summary>
  349. // /// <returns>True if the media is cached, false otherwise.</returns>
  350. // bool IsMediaCached();
  351. }
  352. #endregion
  353. public interface ITextureProducer
  354. {
  355. /// <summary>
  356. /// Gets the number of textures produced by the media player.
  357. /// </summary>
  358. int GetTextureCount();
  359. /// <summary>
  360. /// Returns the Unity texture containing the current frame image.
  361. /// The texture pointer will return null while the video is loading
  362. /// This texture usually remains the same for the duration of the video.
  363. /// There are cases when this texture can change, for instance: if the graphics device is recreated,
  364. /// a new video is loaded, or if an adaptive stream (eg HLS) is used and it switches video streams.
  365. /// </summary>
  366. Texture GetTexture(int index = 0);
  367. /// <summary>
  368. /// Returns a count of how many times the texture has been updated
  369. /// </summary>
  370. int GetTextureFrameCount();
  371. /// <summary>
  372. /// Returns whether this platform supports counting the number of times the texture has been updated
  373. /// </summary>
  374. bool SupportsTextureFrameCount();
  375. /// <summary>
  376. /// Returns the presentation time stamp of the current texture
  377. /// </summary>
  378. long GetTextureTimeStamp();
  379. /// <summary>
  380. /// Returns the DAR/SAR ratio
  381. /// </summary>
  382. float GetTexturePixelAspectRatio();
  383. /// <summary>
  384. /// Returns true if the image on the texture is upside-down
  385. /// </summary>
  386. bool RequiresVerticalFlip();
  387. /// <summary>
  388. /// Returns the type of packing used for stereo content
  389. /// </summary>
  390. StereoPacking GetTextureStereoPacking();
  391. /// <summary>
  392. /// Returns the whether the texture has transparency
  393. /// </summary>
  394. TransparencyMode GetTextureTransparency();
  395. /// <summary>
  396. /// Returns the type of packing used for alpha content
  397. /// </summary>
  398. AlphaPacking GetTextureAlphaPacking();
  399. /// <summary>
  400. /// Returns the current transformation required to convert from YpCbCr to RGB colorspaces.
  401. /// </summary>
  402. Matrix4x4 GetYpCbCrTransform();
  403. #if AVPRO_NEW_GAMMA
  404. /// <summary>
  405. /// Returns the gamma type of a sampled pixel
  406. /// Is the texture returns samples in linear gamma then no conversion is need when using Unity's linear color space mode
  407. /// If it doesn't then a correction may have to be made in the shader
  408. /// </summary>
  409. TextureGamma GetTextureSampleGamma();
  410. bool TextureRequiresGammaConversion();
  411. #endif
  412. }
  413. public enum Platform
  414. {
  415. Windows,
  416. MacOSX,
  417. iOS,
  418. tvOS,
  419. Android,
  420. WindowsUWP,
  421. WebGL,
  422. Count = 7,
  423. Unknown = 100,
  424. }
  425. public enum MediaSource
  426. {
  427. Reference,
  428. Path,
  429. }
  430. public enum MediaPathType
  431. {
  432. AbsolutePathOrURL,
  433. RelativeToProjectFolder,
  434. RelativeToStreamingAssetsFolder,
  435. RelativeToDataFolder,
  436. RelativeToPersistentDataFolder,
  437. }
  438. [System.Serializable]
  439. public class MediaPath
  440. {
  441. [SerializeField] MediaPathType _pathType = MediaPathType.RelativeToStreamingAssetsFolder;
  442. public MediaPathType PathType { get { return _pathType; } internal set { _pathType = value; } }
  443. [SerializeField] string _path = string.Empty;
  444. public string Path { get { return _path; } internal set { _path = value; } }
  445. public MediaPath()
  446. {
  447. _pathType = MediaPathType.RelativeToStreamingAssetsFolder;
  448. _path = string.Empty;
  449. }
  450. public MediaPath(MediaPath copy)
  451. {
  452. _pathType = copy.PathType;
  453. _path = copy.Path;
  454. }
  455. public MediaPath(string path, MediaPathType pathType)
  456. {
  457. _pathType = pathType;
  458. _path = path;
  459. }
  460. public string GetResolvedFullPath()
  461. {
  462. string result = Helper.GetFilePath(_path, _pathType);
  463. #if (UNITY_EDITOR_WIN || (!UNITY_EDITOR && UNITY_STANDALONE_WIN))
  464. if (result.Length > 200 && !result.Contains("://"))
  465. {
  466. result = Helper.ConvertLongPathToShortDOS83Path(result);
  467. }
  468. #endif
  469. return result;
  470. }
  471. public static bool operator == (MediaPath a, MediaPath b)
  472. {
  473. if ((object)a == null)
  474. return (object)b == null;
  475. return a.Equals(b);
  476. }
  477. public static bool operator != (MediaPath a, MediaPath b)
  478. {
  479. return !(a == b);
  480. }
  481. public override bool Equals(object obj)
  482. {
  483. if (obj == null || GetType() != obj.GetType())
  484. return false;
  485. var a = (MediaPath)obj;
  486. return (_pathType == a._pathType && _path == a._path);
  487. }
  488. public override int GetHashCode()
  489. {
  490. return _pathType.GetHashCode() ^ _path.GetHashCode();
  491. }
  492. }
  493. public enum OverrideMode
  494. {
  495. None, // No overide, just use internal logic
  496. Override, // Manually override
  497. }
  498. public enum TextureGamma
  499. {
  500. SRGB,
  501. Linear,
  502. // Future HDR support
  503. // PQ,
  504. // HLG,
  505. }
  506. public enum StereoPacking : int
  507. {
  508. None = 0, // Monoscopic
  509. TopBottom = 1, // Top is the left eye, bottom is the right eye
  510. LeftRight = 2, // Left is the left eye, right is the right eye
  511. CustomUV = 3, // Use the mesh UV to unpack, uv0=left eye, uv1=right eye
  512. TwoTextures = 4, // First texture left eye, second texture is right eye
  513. Unknown = 10,
  514. }
  515. [System.Serializable]
  516. public struct MediaHints
  517. {
  518. public TransparencyMode transparency;
  519. public AlphaPacking alphaPacking;
  520. public StereoPacking stereoPacking;
  521. private static MediaHints defaultHints = new MediaHints();
  522. public static MediaHints Default { get { return defaultHints; } }
  523. }
  524. [System.Serializable]
  525. public struct VideoResolveOptions
  526. {
  527. [SerializeField] public bool applyHSBC;
  528. [SerializeField, Range(0f, 1f)] public float hue;
  529. [SerializeField, Range(0f, 1f)] public float saturation;
  530. [SerializeField, Range(0f, 1f)] public float brightness;
  531. [SerializeField, Range(0f, 1f)] public float contrast;
  532. [SerializeField, Range(0.0001f, 10f)] public float gamma;
  533. [SerializeField] public Color tint;
  534. [SerializeField] public bool generateMipmaps;
  535. public bool IsColourAdjust()
  536. {
  537. return (applyHSBC && (hue != 0.0f || saturation != 0.5f || brightness != 0.5f || contrast != 0.5f || gamma != 1.0f));
  538. }
  539. internal void ResetColourAdjust()
  540. {
  541. hue = 0.0f;
  542. saturation = 0.5f;
  543. brightness = 0.5f;
  544. contrast = 0.5f;
  545. gamma = 1.0f;
  546. }
  547. public static VideoResolveOptions Create()
  548. {
  549. VideoResolveOptions result = new VideoResolveOptions()
  550. {
  551. tint = Color.white,
  552. };
  553. result.ResetColourAdjust();
  554. return result;
  555. }
  556. }
  557. /// Transparency Mode
  558. public enum TransparencyMode
  559. {
  560. Opaque,
  561. Transparent,
  562. }
  563. public enum StereoEye
  564. {
  565. Both,
  566. Left,
  567. Right,
  568. }
  569. public enum AlphaPacking
  570. {
  571. None,
  572. TopBottom,
  573. LeftRight,
  574. }
  575. public enum ErrorCode
  576. {
  577. None = 0,
  578. LoadFailed = 100,
  579. DecodeFailed = 200,
  580. }
  581. public enum Orientation
  582. {
  583. Landscape, // Landscape Right (0 degrees)
  584. LandscapeFlipped, // Landscape Left (180 degrees)
  585. Portrait, // Portrait Up (90 degrees)
  586. PortraitFlipped, // Portrait Down (-90 degrees)
  587. PortraitHorizontalMirror, // Portrait that is mirrored horizontally
  588. }
  589. public enum VideoMapping
  590. {
  591. Unknown,
  592. Normal,
  593. EquiRectangular360,
  594. EquiRectangular180,
  595. CubeMap3x2,
  596. }
  597. public enum FileFormat
  598. {
  599. Unknown,
  600. HLS,
  601. DASH,
  602. SmoothStreaming,
  603. }
  604. public static class Windows
  605. {
  606. public enum VideoApi
  607. {
  608. MediaFoundation, // Windows 8.1 and above
  609. DirectShow, // Legacy API
  610. WinRT, // Windows 10 and above
  611. };
  612. public enum AudioOutput
  613. {
  614. System, // Default
  615. Unity, // Media Foundation API only
  616. FacebookAudio360, // Media Foundation API only
  617. None, // Media Foundation API only
  618. }
  619. // WIP: Experimental feature to allow overriding audio device for VR headsets
  620. public const string AudioDeviceOutputName_Vive = "HTC VIVE USB Audio";
  621. public const string AudioDeviceOutputName_Rift = "Headphones (Rift Audio)";
  622. }
  623. public static class WindowsUWP
  624. {
  625. public enum VideoApi
  626. {
  627. MediaFoundation, // UWP 8.1 and above
  628. WinRT, // UWP 10 and above
  629. };
  630. public enum AudioOutput
  631. {
  632. System, // Default
  633. Unity, // Media Foundation API only
  634. FacebookAudio360, // Media Foundation API only
  635. None, // Media Foundation API only
  636. }
  637. }
  638. public static class Android
  639. {
  640. public enum VideoApi
  641. {
  642. MediaPlayer = 1,
  643. ExoPlayer,
  644. }
  645. public enum AudioOutput
  646. {
  647. System, // Default
  648. Unity, // ExoPlayer API only
  649. FacebookAudio360, // ExoPlayer API only
  650. }
  651. public enum TextureFiltering
  652. {
  653. Point,
  654. Bilinear,
  655. Trilinear,
  656. }
  657. public const int Default_MinBufferTimeMs = 50000; // Only valid when using ExoPlayer (default comes from DefaultLoadControl.DEFAULT_MIN_BUFFER_MS)
  658. public const int Default_MaxBufferTimeMs = 50000; // Only valid when using ExoPlayer (default comes from DefaultLoadControl.DEFAULT_MAX_BUFFER_MS)
  659. public const int Default_BufferForPlaybackMs = 2500; // Only valid when using ExoPlayer (default comes from DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_MS)
  660. public const int Default_BufferForPlaybackAfterRebufferMs = 5000; // Only valid when using ExoPlayer (default comes from DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS)
  661. }
  662. public static class WebGL
  663. {
  664. public enum ExternalLibrary
  665. {
  666. None,
  667. DashJs,
  668. HlsJs,
  669. Custom,
  670. }
  671. }
  672. // Facebook Audio 360 channel mapping
  673. public enum Audio360ChannelMode
  674. {
  675. TBE_8_2 = 0, /// 8 channels of hybrid TBE ambisonics and 2 channels of head-locked stereo audio
  676. TBE_8, /// 8 channels of hybrid TBE ambisonics. NO head-locked stereo audio
  677. TBE_6_2, /// 6 channels of hybrid TBE ambisonics and 2 channels of head-locked stereo audio
  678. TBE_6, /// 6 channels of hybrid TBE ambisonics. NO head-locked stereo audio
  679. TBE_4_2, /// 4 channels of hybrid TBE ambisonics and 2 channels of head-locked stereo audio
  680. TBE_4, /// 4 channels of hybrid TBE ambisonics. NO head-locked stereo audio
  681. TBE_8_PAIR0, /// Channels 1 and 2 of TBE hybrid ambisonics
  682. TBE_8_PAIR1, /// Channels 3 and 4 of TBE hybrid ambisonics
  683. TBE_8_PAIR2, /// Channels 5 and 6 of TBE hybrid ambisonics
  684. TBE_8_PAIR3, /// Channels 7 and 8 of TBE hybrid ambisonics
  685. TBE_CHANNEL0, /// Channels 1 of TBE hybrid ambisonics
  686. TBE_CHANNEL1, /// Channels 2 of TBE hybrid ambisonics
  687. TBE_CHANNEL2, /// Channels 3 of TBE hybrid ambisonics
  688. TBE_CHANNEL3, /// Channels 4 of TBE hybrid ambisonics
  689. TBE_CHANNEL4, /// Channels 5 of TBE hybrid ambisonics
  690. TBE_CHANNEL5, /// Channels 6 of TBE hybrid ambisonics
  691. TBE_CHANNEL6, /// Channels 7 of TBE hybrid ambisonics
  692. TBE_CHANNEL7, /// Channels 8 of TBE hybrid ambisonics
  693. HEADLOCKED_STEREO, /// Head-locked stereo audio
  694. HEADLOCKED_CHANNEL0, /// Channels 1 or left of head-locked stereo audio
  695. HEADLOCKED_CHANNEL1, /// Channels 2 or right of head-locked stereo audio
  696. AMBIX_4, /// 4 channels of first order ambiX
  697. AMBIX_4_2, /// 4 channels of first order ambiX with 2 channels of head-locked audio
  698. AMBIX_9, /// 9 channels of second order ambiX
  699. AMBIX_9_2, /// 9 channels of second order ambiX with 2 channels of head-locked audio
  700. AMBIX_16, /// 16 channels of third order ambiX
  701. AMBIX_16_2, /// 16 channels of third order ambiX with 2 channels of head-locked audio
  702. MONO, /// Mono audio
  703. STEREO, /// Stereo audio
  704. UNKNOWN, /// Unknown channel map
  705. INVALID, /// Invalid/unknown map. This must always be last.
  706. }
  707. [System.Flags]
  708. public enum AudioChannelMaskFlags : int
  709. {
  710. Unspecified = 0x0,
  711. FrontLeft = 0x1,
  712. FrontRight = 0x2,
  713. FrontCenter = 0x4,
  714. LowFrequency = 0x8,
  715. BackLeft = 0x10,
  716. BackRight = 0x20,
  717. FrontLeftOfCenter = 0x40,
  718. FrontRightOfCenter = 0x80,
  719. BackCenter = 0x100,
  720. SideLeft = 0x200,
  721. SideRight = 0x400,
  722. TopCenter = 0x800,
  723. TopFrontLeft = 0x1000,
  724. TopFrontCenter = 0x2000,
  725. TopFrontRight = 0x4000,
  726. TopBackLeft = 0x8000,
  727. TopBackCenter = 0x10000,
  728. TopBackRight = 0x20000,
  729. }
  730. public enum TextureFlags : int
  731. {
  732. Unknown = 0,
  733. TopDown = 1 << 0,
  734. SamplingIsLinear = 1 << 1,
  735. }
  736. [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential, Pack = 1)]
  737. public struct BufferedFramesState
  738. {
  739. public System.Int32 freeFrameCount;
  740. public System.Int32 bufferedFrameCount;
  741. public System.Int64 minTimeStamp;
  742. public System.Int64 maxTimeStamp;
  743. public System.Int32 prerolledCount;
  744. }
  745. [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential, Pack = 1)]
  746. public struct TextureFrame
  747. {
  748. internal System.IntPtr texturePointer;
  749. internal System.IntPtr auxTexturePointer;
  750. internal System.Int64 timeStamp;
  751. internal System.UInt32 frameCounter;
  752. internal System.UInt32 writtenFrameCount;
  753. internal TextureFlags flags;
  754. internal System.IntPtr internalNativePointer;
  755. }
  756. [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential, Pack = 1)]
  757. public struct TimeRange
  758. {
  759. public TimeRange(double startTime, double duration)
  760. {
  761. this.startTime = startTime;
  762. this.duration = duration;
  763. }
  764. public double startTime, duration;
  765. public double StartTime { get { return startTime; } }
  766. public double EndTime { get { return startTime + duration; } }
  767. public double Duration { get { return duration; } }
  768. }
  769. public class TimeRanges : IEnumerable
  770. {
  771. internal TimeRanges() {}
  772. public IEnumerator GetEnumerator()
  773. {
  774. return _ranges.GetEnumerator();
  775. }
  776. public TimeRange this[int index]
  777. {
  778. get
  779. {
  780. return _ranges[index];
  781. }
  782. }
  783. internal TimeRanges(TimeRange[] ranges)
  784. {
  785. _ranges = ranges;
  786. CalculateRange();
  787. }
  788. internal void CalculateRange()
  789. {
  790. _minTime = _maxTime = 0.0;
  791. if (_ranges != null && _ranges.Length > 0)
  792. {
  793. double maxTime = 0.0;
  794. double minTime = double.MaxValue;
  795. for (int i = 0; i < _ranges.Length; i++)
  796. {
  797. minTime = System.Math.Min(minTime, _ranges[i].startTime);
  798. maxTime = System.Math.Max(maxTime, _ranges[i].startTime + _ranges[i].duration);
  799. }
  800. _minTime = minTime;
  801. _maxTime = maxTime;
  802. }
  803. }
  804. public int Count { get { return _ranges.Length; } }
  805. public double MinTime { get { return _minTime; } }
  806. public double MaxTime { get { return _maxTime; } }
  807. public double Duration { get { return (_maxTime - _minTime); } }
  808. internal TimeRange[] _ranges = new TimeRange[0];
  809. internal double _minTime = 0.0;
  810. internal double _maxTime = 0.0;
  811. }
  812. /// <summary>
  813. /// Video gravity to use with external playback.
  814. /// </summary>
  815. public enum ExternalPlaybackVideoGravity
  816. {
  817. /// <summary>Resizes the video to fit the display, may cause stretching.</summary>
  818. Resize,
  819. /// <summary>Resizes the video whilst preserving the video's aspect ratio to fit the display bounds.</summary>
  820. ResizeAspect,
  821. /// <summary>Resizes the video whilst preserving aspect to fill the display bounds.</summary>
  822. ResizeAspectFill,
  823. };
  824. }