MediaPlayer_PlatformOptions.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  1. using UnityEngine;
  2. using System;
  3. using System.Collections.Generic;
  4. //-----------------------------------------------------------------------------
  5. // Copyright 2015-2022 RenderHeads Ltd. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. namespace RenderHeads.Media.AVProVideo
  8. {
  9. public partial class MediaPlayer : MonoBehaviour
  10. {
  11. #region PlatformOptions
  12. [System.Serializable]
  13. public class PlatformOptions
  14. {
  15. public enum TextureFormat : int
  16. {
  17. BGRA,
  18. YCbCr420_OES,
  19. }
  20. public enum Resolution : int
  21. {
  22. NoPreference,
  23. _480p,
  24. _720p,
  25. _1080p,
  26. _1440p,
  27. _2160p,
  28. Custom
  29. }
  30. public enum AudioMode : int
  31. {
  32. SystemDirect,
  33. Unity,
  34. SystemDirectWithCapture,
  35. FacebookAudio360,
  36. }
  37. public enum BitRateUnits : int
  38. {
  39. bps,
  40. Kbps,
  41. Mbps
  42. }
  43. public virtual bool IsModified()
  44. {
  45. return (httpHeaders.IsModified()
  46. || keyAuth.IsModified()
  47. );
  48. }
  49. public virtual bool HasChanged()
  50. {
  51. return false;
  52. }
  53. public virtual void ClearChanges()
  54. {
  55. }
  56. public HttpHeaderData httpHeaders = new HttpHeaderData();
  57. public KeyAuthData keyAuth = new KeyAuthData();
  58. // Decryption support
  59. public virtual string GetKeyServerAuthToken() { return keyAuth.keyServerToken; }
  60. //public virtual string GetKeyServerURL() { return null; }
  61. public virtual byte[] GetOverrideDecryptionKey() { return keyAuth.overrideDecryptionKey; }
  62. public virtual bool StartWithHighestBandwidth() { return false; }
  63. }
  64. [System.Serializable]
  65. public class OptionsWindows : PlatformOptions, ISerializationCallbackReceiver
  66. {
  67. public Windows.VideoApi videoApi = Windows.VideoApi.MediaFoundation;
  68. public bool useHardwareDecoding = true;
  69. public bool useRendererSync = true;
  70. public bool useTextureMips = false;
  71. public bool use10BitTextures = false;
  72. public bool hintAlphaChannel = false;
  73. public bool useLowLatency = false;
  74. public bool useCustomMovParser = false;
  75. public bool useHapNotchLC = false;
  76. public bool useStereoDetection = true;
  77. public bool useTextTrackSupport = true;
  78. public bool useFacebookAudio360Support = true;
  79. public bool useAudioDelay = false;
  80. public BufferedFrameSelectionMode bufferedFrameSelection = BufferedFrameSelectionMode.None;
  81. public bool pauseOnPrerollComplete = false;
  82. public string forceAudioOutputDeviceName = string.Empty;
  83. public List<string> preferredFilters = new List<string>();
  84. public Windows.AudioOutput _audioMode = Windows.AudioOutput.System;
  85. public Audio360ChannelMode audio360ChannelMode = Audio360ChannelMode.TBE_8_2;
  86. /// WinRT only
  87. public bool startWithHighestBitrate = false;
  88. /// WinRT only
  89. public bool useLowLiveLatency = false;
  90. /// Hap & NotchLC only
  91. [Range(1, 16)]
  92. public int parallelFrameCount = 3;
  93. /// Hap & NotchLC only
  94. [Range(1, 16)]
  95. public int prerollFrameCount = 4;
  96. public override bool IsModified()
  97. {
  98. return (base.IsModified()
  99. || !useHardwareDecoding
  100. || !useRendererSync
  101. || useTextureMips
  102. || use10BitTextures
  103. || hintAlphaChannel
  104. || useLowLatency
  105. || useCustomMovParser
  106. || useHapNotchLC
  107. || !useStereoDetection
  108. || !useTextTrackSupport
  109. || !useFacebookAudio360Support
  110. || useAudioDelay
  111. || pauseOnPrerollComplete
  112. || bufferedFrameSelection != BufferedFrameSelectionMode.None
  113. || videoApi != Windows.VideoApi.MediaFoundation
  114. || _audioMode != Windows.AudioOutput.System
  115. || audio360ChannelMode != Audio360ChannelMode.TBE_8_2
  116. || !string.IsNullOrEmpty(forceAudioOutputDeviceName)
  117. || preferredFilters.Count != 0
  118. || startWithHighestBitrate
  119. || useLowLiveLatency
  120. || parallelFrameCount != 3
  121. || prerollFrameCount != 4
  122. );
  123. }
  124. public override bool StartWithHighestBandwidth() { return startWithHighestBitrate; }
  125. #region Upgrade from Version 1.x
  126. [SerializeField, HideInInspector]
  127. private bool useUnityAudio = false;
  128. [SerializeField, HideInInspector]
  129. private bool enableAudio360 = false;
  130. void ISerializationCallbackReceiver.OnBeforeSerialize() { }
  131. void ISerializationCallbackReceiver.OnAfterDeserialize()
  132. {
  133. if (useUnityAudio && _audioMode == Windows.AudioOutput.System)
  134. {
  135. _audioMode = Windows.AudioOutput.Unity;
  136. useUnityAudio = false;
  137. }
  138. if (enableAudio360 && _audioMode == Windows.AudioOutput.System)
  139. {
  140. _audioMode = Windows.AudioOutput.FacebookAudio360;
  141. enableAudio360 = false;
  142. }
  143. }
  144. #endregion // Upgrade from Version 1.x
  145. }
  146. [System.Serializable]
  147. public class OptionsWindowsUWP : PlatformOptions
  148. {
  149. public bool useHardwareDecoding = true;
  150. public bool useRendererSync = true;
  151. public bool useTextureMips = false;
  152. public bool use10BitTextures = false;
  153. public bool hintOutput10Bit = false;
  154. public bool useLowLatency = false;
  155. public WindowsUWP.VideoApi videoApi = WindowsUWP.VideoApi.WinRT;
  156. public WindowsUWP.AudioOutput audioOutput = WindowsUWP.AudioOutput.System;
  157. public Audio360ChannelMode audio360ChannelMode = Audio360ChannelMode.TBE_8_2;
  158. /// WinRT only
  159. public bool startWithHighestBitrate = false;
  160. /// WinRT only
  161. public bool useLowLiveLatency = false;
  162. public override bool IsModified()
  163. {
  164. return (base.IsModified()
  165. || !useHardwareDecoding
  166. || !useRendererSync
  167. || useTextureMips
  168. || use10BitTextures
  169. || useLowLatency
  170. || audioOutput != WindowsUWP.AudioOutput.System
  171. || (audio360ChannelMode != Audio360ChannelMode.TBE_8_2)
  172. || videoApi != WindowsUWP.VideoApi.WinRT
  173. || startWithHighestBitrate
  174. || useLowLiveLatency
  175. );
  176. }
  177. public override bool StartWithHighestBandwidth() { return startWithHighestBitrate; }
  178. }
  179. [System.Serializable]
  180. public class OptionsApple: PlatformOptions
  181. {
  182. [Flags]
  183. public enum Flags: int
  184. {
  185. // Common
  186. None = 0,
  187. GenerateMipMaps = 1 << 0,
  188. // iOS & macOS
  189. AllowExternalPlayback = 1 << 8,
  190. PlayWithoutBuffering = 1 << 9,
  191. UseSinglePlayerItem = 1 << 10,
  192. // iOS
  193. ResumeMediaPlaybackAfterAudioSessionRouteChange = 1 << 16,
  194. }
  195. private readonly TextureFormat DefaultTextureFormat;
  196. private readonly Flags DefaultFlags;
  197. public TextureFormat textureFormat;
  198. private AudioMode _previousAudioMode = AudioMode.SystemDirect;
  199. public AudioMode previousAudioMode
  200. {
  201. get { return _previousAudioMode; }
  202. }
  203. [SerializeField]
  204. private AudioMode _audioMode;
  205. public AudioMode audioMode
  206. {
  207. get { return _audioMode; }
  208. set
  209. {
  210. if (_audioMode != value)
  211. {
  212. _previousAudioMode = _audioMode;
  213. _audioMode = value;
  214. _changed |= ChangeFlags.AudioMode;
  215. }
  216. }
  217. }
  218. [SerializeField]
  219. private Flags _flags;
  220. public Flags flags
  221. {
  222. get { return _flags; }
  223. set
  224. {
  225. Flags changed = _flags ^ value;
  226. if (changed != 0)
  227. {
  228. if ((changed & Flags.PlayWithoutBuffering) == Flags.PlayWithoutBuffering)
  229. {
  230. _changed |= ChangeFlags.PlayWithoutBuffering;
  231. }
  232. if ((changed & Flags.ResumeMediaPlaybackAfterAudioSessionRouteChange) == Flags.ResumeMediaPlaybackAfterAudioSessionRouteChange)
  233. {
  234. _changed |= ChangeFlags.ResumeMediaPlaybackAfterAudioSessionRouteChange;
  235. }
  236. _flags = value;
  237. }
  238. }
  239. }
  240. public float maximumPlaybackRate = 2.0f;
  241. [Flags]
  242. public enum ChangeFlags: int
  243. {
  244. None = 0,
  245. PreferredPeakBitRate = 1 << 1,
  246. PreferredForwardBufferDuration = 1 << 2,
  247. PlayWithoutBuffering = 1 << 3,
  248. PreferredMaximumResolution = 1 << 4,
  249. AudioMode = 1 << 5,
  250. ResumeMediaPlaybackAfterAudioSessionRouteChange = 1 << 6,
  251. All = -1
  252. }
  253. private ChangeFlags _changed = ChangeFlags.None;
  254. [SerializeField]
  255. private float _preferredPeakBitRate = 0.0f;
  256. public float preferredPeakBitRate
  257. {
  258. get { return _preferredPeakBitRate; }
  259. set
  260. {
  261. if (_preferredPeakBitRate != value)
  262. {
  263. _changed |= ChangeFlags.PreferredPeakBitRate;
  264. _preferredPeakBitRate = value;
  265. }
  266. }
  267. }
  268. [SerializeField]
  269. private BitRateUnits _preferredPeakBitRateUnits = BitRateUnits.Kbps;
  270. public BitRateUnits preferredPeakBitRateUnits
  271. {
  272. get { return _preferredPeakBitRateUnits; }
  273. set
  274. {
  275. if (_preferredPeakBitRateUnits != value)
  276. {
  277. _changed |= ChangeFlags.PreferredPeakBitRate;
  278. _preferredPeakBitRateUnits = value;
  279. }
  280. }
  281. }
  282. [SerializeField]
  283. private double _preferredForwardBufferDuration = 0.0;
  284. public double preferredForwardBufferDuration
  285. {
  286. get
  287. {
  288. return _preferredForwardBufferDuration;
  289. }
  290. set
  291. {
  292. if (_preferredForwardBufferDuration != value)
  293. {
  294. _changed |= ChangeFlags.PreferredForwardBufferDuration;
  295. _preferredForwardBufferDuration = value;
  296. }
  297. }
  298. }
  299. [SerializeField]
  300. private Resolution _preferredMaximumResolution = Resolution.NoPreference;
  301. public Resolution preferredMaximumResolution
  302. {
  303. get
  304. {
  305. return _preferredMaximumResolution;
  306. }
  307. set
  308. {
  309. if (_preferredMaximumResolution != value)
  310. {
  311. _changed |= ChangeFlags.PreferredMaximumResolution;
  312. _preferredMaximumResolution = value;
  313. }
  314. }
  315. }
  316. #if UNITY_2017_2_OR_NEWER
  317. [SerializeField]
  318. private Vector2Int _customPreferredMaximumResolution = Vector2Int.zero;
  319. public Vector2Int customPreferredMaximumResolution
  320. {
  321. get
  322. {
  323. return _customPreferredMaximumResolution;
  324. }
  325. set
  326. {
  327. if (_customPreferredMaximumResolution != value)
  328. {
  329. _changed |= ChangeFlags.PreferredMaximumResolution;
  330. _customPreferredMaximumResolution = value;
  331. }
  332. }
  333. }
  334. #endif
  335. private static double BitRateInBitsPerSecond(float value, BitRateUnits units)
  336. {
  337. switch (units)
  338. {
  339. case BitRateUnits.bps:
  340. return (double)value;
  341. case BitRateUnits.Kbps:
  342. return (double)value * 1000.0;
  343. case BitRateUnits.Mbps:
  344. return (double)value * 1000000.0;
  345. default:
  346. return 0.0;
  347. }
  348. }
  349. public double GetPreferredPeakBitRateInBitsPerSecond()
  350. {
  351. return BitRateInBitsPerSecond(preferredPeakBitRate, preferredPeakBitRateUnits);
  352. }
  353. public OptionsApple(TextureFormat defaultTextureFormat, Flags defaultFlags)
  354. {
  355. DefaultTextureFormat = defaultTextureFormat;
  356. DefaultFlags = defaultFlags;
  357. textureFormat = defaultTextureFormat;
  358. audioMode = AudioMode.SystemDirect;
  359. flags = defaultFlags;
  360. }
  361. public override bool IsModified()
  362. {
  363. return base.IsModified()
  364. || textureFormat != DefaultTextureFormat
  365. || audioMode != AudioMode.SystemDirect
  366. || flags != DefaultFlags
  367. || preferredMaximumResolution != Resolution.NoPreference
  368. || preferredPeakBitRate != 0.0f
  369. || preferredForwardBufferDuration != 0.0;
  370. }
  371. public override bool HasChanged()
  372. {
  373. return HasChanged(ChangeFlags.All);
  374. }
  375. public bool HasChanged(ChangeFlags flags)
  376. {
  377. return (_changed & flags) != ChangeFlags.None;
  378. }
  379. public override void ClearChanges()
  380. {
  381. _changed = ChangeFlags.None;
  382. }
  383. }
  384. [System.Serializable]
  385. public class OptionsAndroid : PlatformOptions, ISerializationCallbackReceiver
  386. {
  387. [Flags]
  388. public enum ChangeFlags : int
  389. {
  390. None = 0,
  391. PreferredPeakBitRate = 1 << 1,
  392. PreferredMaximumResolution = 1 << 2,
  393. PreferredCustomResolution = 1 << 3,
  394. AudioMode = 1 << 4,
  395. All = -1
  396. }
  397. private ChangeFlags _changed = ChangeFlags.None;
  398. private readonly TextureFormat DefaultTextureFormat;
  399. public TextureFormat textureFormat;
  400. private AudioMode _previousAudioMode = AudioMode.SystemDirect;
  401. public AudioMode previousAudioMode
  402. {
  403. get { return _previousAudioMode; }
  404. }
  405. [SerializeField]
  406. private AudioMode _audioMode;
  407. public AudioMode audioMode
  408. {
  409. get { return _audioMode; }
  410. set
  411. {
  412. if (_audioMode != value)
  413. {
  414. _previousAudioMode = _audioMode;
  415. _audioMode = value;
  416. _changed |= ChangeFlags.AudioMode;
  417. }
  418. }
  419. }
  420. [SerializeField]
  421. private Resolution _preferredMaximumResolution = Resolution.NoPreference;
  422. public Resolution preferredMaximumResolution
  423. {
  424. get { return _preferredMaximumResolution; }
  425. set
  426. {
  427. if (_preferredMaximumResolution != value)
  428. {
  429. _changed |= ChangeFlags.PreferredMaximumResolution;
  430. _preferredMaximumResolution = value;
  431. }
  432. }
  433. }
  434. #if UNITY_2017_2_OR_NEWER
  435. [SerializeField]
  436. private Vector2Int _customPreferredMaximumResolution = Vector2Int.zero;
  437. public Vector2Int customPreferredMaximumResolution
  438. {
  439. get { return _customPreferredMaximumResolution; }
  440. set
  441. {
  442. if (_customPreferredMaximumResolution != value)
  443. {
  444. _changed |= ChangeFlags.PreferredCustomResolution;
  445. _customPreferredMaximumResolution = value;
  446. }
  447. }
  448. }
  449. #endif
  450. [SerializeField]
  451. private float _preferredPeakBitRate = 0.0f;
  452. public float preferredPeakBitRate
  453. {
  454. get { return _preferredPeakBitRate; }
  455. set
  456. {
  457. if (_preferredPeakBitRate != value)
  458. {
  459. _changed |= ChangeFlags.PreferredPeakBitRate;
  460. _preferredPeakBitRate = value;
  461. }
  462. }
  463. }
  464. [SerializeField]
  465. private BitRateUnits _preferredPeakBitRateUnits = BitRateUnits.Kbps;
  466. public BitRateUnits preferredPeakBitRateUnits
  467. {
  468. get { return _preferredPeakBitRateUnits; }
  469. set
  470. {
  471. if (_preferredPeakBitRateUnits != value)
  472. {
  473. _changed |= ChangeFlags.PreferredPeakBitRate;
  474. _preferredPeakBitRateUnits = value;
  475. }
  476. }
  477. }
  478. public Android.VideoApi videoApi = Android.VideoApi.ExoPlayer;
  479. // public bool showPosterFrame = false;
  480. public Audio360ChannelMode audio360ChannelMode = Audio360ChannelMode.TBE_8_2;
  481. public int audio360LatencyMS = 0;
  482. public bool preferSoftwareDecoder = false;
  483. public bool forceRtpTCP = false;
  484. public bool forceEnableMediaCodecAsynchronousQueueing = false;
  485. [SerializeField, Tooltip("Byte offset into the file where the media file is located. This is useful when hiding or packing media files within another file.")]
  486. public int fileOffset = 0;
  487. public bool startWithHighestBitrate = false;
  488. public int minBufferMs = Android.Default_MinBufferTimeMs;
  489. public int maxBufferMs = Android.Default_MaxBufferTimeMs;
  490. public int bufferForPlaybackMs = Android.Default_BufferForPlaybackMs;
  491. public int bufferForPlaybackAfterRebufferMs = Android.Default_BufferForPlaybackAfterRebufferMs;
  492. [Obsolete("useFastOesPath is deprecated and replaced with TextureFormat")]
  493. public bool useFastOesPath;
  494. [Obsolete("audioOutput is deprecated and replaced with audioMode")]
  495. public int audioOutput;
  496. [Obsolete("blitTextureFiltering is deprecated and its functionality has been removed")]
  497. public int blitTextureFiltering;
  498. [Obsolete("forceEnableMediaCodecAsyncQueueing is deprecated and replaced with forceEnableMediaCodecAsynchronousQueueing")]
  499. public bool forceEnableMediaCodecAsyncQueueing;
  500. public override bool IsModified()
  501. {
  502. return (base.IsModified()
  503. || (fileOffset != 0)
  504. || textureFormat != DefaultTextureFormat
  505. || audioMode != AudioMode.SystemDirect
  506. // || showPosterFrame
  507. || (videoApi != Android.VideoApi.ExoPlayer)
  508. || (audio360ChannelMode != Audio360ChannelMode.TBE_8_2)
  509. || (audio360LatencyMS != 0 )
  510. || preferSoftwareDecoder
  511. || forceRtpTCP
  512. || forceEnableMediaCodecAsynchronousQueueing
  513. || startWithHighestBitrate
  514. || (minBufferMs != Android.Default_MinBufferTimeMs)
  515. || (maxBufferMs != Android.Default_MaxBufferTimeMs)
  516. || (bufferForPlaybackMs != Android.Default_BufferForPlaybackMs)
  517. || (bufferForPlaybackAfterRebufferMs != Android.Default_BufferForPlaybackAfterRebufferMs)
  518. || (preferredMaximumResolution != Resolution.NoPreference)
  519. || (preferredPeakBitRate != 0.0f)
  520. );
  521. }
  522. private static double BitRateInBitsPerSecond(float value, BitRateUnits units)
  523. {
  524. switch (units)
  525. {
  526. case BitRateUnits.bps:
  527. return (double)value;
  528. case BitRateUnits.Kbps:
  529. return (double)value * 1000.0;
  530. case BitRateUnits.Mbps:
  531. return (double)value * 1000000.0;
  532. default:
  533. return 0.0;
  534. }
  535. }
  536. public double GetPreferredPeakBitRateInBitsPerSecond()
  537. {
  538. _changed &= ~ChangeFlags.PreferredPeakBitRate;
  539. return BitRateInBitsPerSecond(preferredPeakBitRate, preferredPeakBitRateUnits);
  540. }
  541. public override bool StartWithHighestBandwidth()
  542. {
  543. return startWithHighestBitrate;
  544. }
  545. public override bool HasChanged()
  546. {
  547. return HasChanged(ChangeFlags.All, false);
  548. }
  549. public bool HasChanged(ChangeFlags flags, bool bClearFlags = false)
  550. {
  551. bool bReturn = ((_changed & flags) != ChangeFlags.None);
  552. if (bClearFlags)
  553. {
  554. _changed = ChangeFlags.None;
  555. }
  556. return bReturn;
  557. }
  558. public override void ClearChanges()
  559. {
  560. _changed = ChangeFlags.None;
  561. }
  562. #region Upgrade from Version 1.x
  563. [SerializeField, HideInInspector]
  564. private bool enableAudio360 = false;
  565. void ISerializationCallbackReceiver.OnBeforeSerialize() { }
  566. void ISerializationCallbackReceiver.OnAfterDeserialize()
  567. {
  568. #if false
  569. if (enableAudio360 && audioOutput == Android.AudioOutput.System)
  570. {
  571. audioOutput = Android.AudioOutput.FacebookAudio360;
  572. enableAudio360 = false;
  573. }
  574. #else
  575. if (enableAudio360 && audioMode == AudioMode.SystemDirect)
  576. {
  577. audioMode = AudioMode.FacebookAudio360;
  578. enableAudio360 = false;
  579. }
  580. #endif
  581. }
  582. #endregion // Upgrade from Version 1.x
  583. }
  584. [System.Serializable]
  585. public class OptionsWebGL : PlatformOptions
  586. {
  587. public WebGL.ExternalLibrary externalLibrary = WebGL.ExternalLibrary.None;
  588. public bool useTextureMips = false;
  589. public override bool IsModified()
  590. {
  591. return (base.IsModified() || externalLibrary != WebGL.ExternalLibrary.None || useTextureMips);
  592. }
  593. // Decryption support
  594. public override string GetKeyServerAuthToken() { return null; }
  595. public override byte[] GetOverrideDecryptionKey() { return null; }
  596. }
  597. // TODO: move these to a Setup object
  598. [SerializeField] OptionsWindows _optionsWindows = new OptionsWindows();
  599. [SerializeField] OptionsApple _options_macOS = new OptionsApple(OptionsApple.TextureFormat.BGRA, OptionsApple.Flags.None);
  600. [SerializeField] OptionsApple _options_iOS = new OptionsApple(OptionsApple.TextureFormat.BGRA, OptionsApple.Flags.None);
  601. [SerializeField] OptionsApple _options_tvOS = new OptionsApple(OptionsApple.TextureFormat.BGRA, OptionsApple.Flags.None);
  602. [SerializeField] OptionsApple _options_visionOS = new OptionsApple(OptionsApple.TextureFormat.BGRA, OptionsApple.Flags.None);
  603. [SerializeField] OptionsAndroid _optionsAndroid = new OptionsAndroid();
  604. [SerializeField] OptionsWindowsUWP _optionsWindowsUWP = new OptionsWindowsUWP();
  605. [SerializeField] OptionsWebGL _optionsWebGL = new OptionsWebGL();
  606. public OptionsWindows PlatformOptionsWindows { get { return _optionsWindows; } }
  607. public OptionsApple PlatformOptions_macOS { get { return _options_macOS; } }
  608. public OptionsApple PlatformOptions_iOS { get { return _options_iOS; } }
  609. public OptionsApple PlatformOptions_tvOS { get { return _options_tvOS; } }
  610. public OptionsApple PlatformOptions_visionOS { get { return _options_visionOS; } }
  611. public OptionsAndroid PlatformOptionsAndroid { get { return _optionsAndroid; } }
  612. public OptionsWindowsUWP PlatformOptionsWindowsUWP { get { return _optionsWindowsUWP; } }
  613. public OptionsWebGL PlatformOptionsWebGL { get { return _optionsWebGL; } }
  614. #endregion // PlatformOptions
  615. }
  616. #region PlatformOptionsExtensions
  617. public static class OptionsAppleExtensions
  618. {
  619. public static bool GenerateMipmaps(this MediaPlayer.OptionsApple.Flags flags)
  620. {
  621. return (flags & MediaPlayer.OptionsApple.Flags.GenerateMipMaps) == MediaPlayer.OptionsApple.Flags.GenerateMipMaps;
  622. }
  623. public static MediaPlayer.OptionsApple.Flags SetGenerateMipMaps(this MediaPlayer.OptionsApple.Flags flags, bool b)
  624. {
  625. if (flags.GenerateMipmaps() ^ b)
  626. {
  627. flags = b ? flags | MediaPlayer.OptionsApple.Flags.GenerateMipMaps
  628. : flags & ~MediaPlayer.OptionsApple.Flags.GenerateMipMaps;
  629. }
  630. return flags;
  631. }
  632. public static bool AllowExternalPlayback(this MediaPlayer.OptionsApple.Flags flags)
  633. {
  634. return (flags & MediaPlayer.OptionsApple.Flags.AllowExternalPlayback) == MediaPlayer.OptionsApple.Flags.AllowExternalPlayback;
  635. }
  636. public static MediaPlayer.OptionsApple.Flags SetAllowExternalPlayback(this MediaPlayer.OptionsApple.Flags flags, bool b)
  637. {
  638. if (flags.AllowExternalPlayback() ^ b)
  639. {
  640. flags = b ? flags | MediaPlayer.OptionsApple.Flags.AllowExternalPlayback
  641. : flags & ~MediaPlayer.OptionsApple.Flags.AllowExternalPlayback;
  642. }
  643. return flags;
  644. }
  645. public static bool PlayWithoutBuffering(this MediaPlayer.OptionsApple.Flags flags)
  646. {
  647. return (flags & MediaPlayer.OptionsApple.Flags.PlayWithoutBuffering) == MediaPlayer.OptionsApple.Flags.PlayWithoutBuffering;
  648. }
  649. public static MediaPlayer.OptionsApple.Flags SetPlayWithoutBuffering(this MediaPlayer.OptionsApple.Flags flags, bool b)
  650. {
  651. if (flags.PlayWithoutBuffering() ^ b)
  652. {
  653. flags = b ? flags | MediaPlayer.OptionsApple.Flags.PlayWithoutBuffering
  654. : flags & ~MediaPlayer.OptionsApple.Flags.PlayWithoutBuffering;
  655. }
  656. return flags;
  657. }
  658. public static bool UseSinglePlayerItem(this MediaPlayer.OptionsApple.Flags flags)
  659. {
  660. return (flags & MediaPlayer.OptionsApple.Flags.UseSinglePlayerItem) == MediaPlayer.OptionsApple.Flags.UseSinglePlayerItem;
  661. }
  662. public static MediaPlayer.OptionsApple.Flags SetUseSinglePlayerItem(this MediaPlayer.OptionsApple.Flags flags, bool b)
  663. {
  664. if (flags.UseSinglePlayerItem() ^ b)
  665. {
  666. flags = b ? flags | MediaPlayer.OptionsApple.Flags.UseSinglePlayerItem
  667. : flags & ~MediaPlayer.OptionsApple.Flags.UseSinglePlayerItem;
  668. }
  669. return flags;
  670. }
  671. public static bool ResumePlaybackAfterAudioSessionRouteChange(this MediaPlayer.OptionsApple.Flags flags)
  672. {
  673. return (flags & MediaPlayer.OptionsApple.Flags.ResumeMediaPlaybackAfterAudioSessionRouteChange) == MediaPlayer.OptionsApple.Flags.ResumeMediaPlaybackAfterAudioSessionRouteChange;
  674. }
  675. public static MediaPlayer.OptionsApple.Flags SetResumePlaybackAfterAudioSessionRouteChange(this MediaPlayer.OptionsApple.Flags flags, bool b)
  676. {
  677. if (flags.ResumePlaybackAfterAudioSessionRouteChange() ^ b)
  678. {
  679. flags = b ? flags | MediaPlayer.OptionsApple.Flags.ResumeMediaPlaybackAfterAudioSessionRouteChange
  680. : flags & ~MediaPlayer.OptionsApple.Flags.ResumeMediaPlaybackAfterAudioSessionRouteChange;
  681. }
  682. return flags;
  683. }
  684. }
  685. #endregion // PlatformOptionsExtensions
  686. }