Interfaces.cs 30 KB

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