BaseMediaPlayer.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace RenderHeads.Media.AVProVideo
  5. {
  6. public abstract class BaseMediaPlayer : IMediaPlayer, IMediaControl, IMediaInfo, IMediaProducer, IMediaSubtitles, IDisposable
  7. {
  8. public abstract string GetVersion();
  9. public abstract bool OpenVideoFromFile(string path, long offset, string httpHeaderJson);
  10. public virtual bool OpenVideoFromBuffer(byte[] buffer)
  11. {
  12. return false;
  13. }
  14. public abstract void CloseVideo();
  15. public abstract void SetLooping(bool bLooping);
  16. public abstract bool IsLooping();
  17. public abstract bool HasMetaData();
  18. public abstract bool CanPlay();
  19. public abstract void Play();
  20. public abstract void Pause();
  21. public abstract void Stop();
  22. public abstract void Rewind();
  23. public abstract void Seek(float timeMs);
  24. public abstract void SeekFast(float timeMs);
  25. public abstract float GetCurrentTimeMs();
  26. public abstract float GetPlaybackRate();
  27. public abstract void SetPlaybackRate(float rate);
  28. public abstract float GetDurationMs();
  29. public abstract int GetVideoWidth();
  30. public abstract int GetVideoHeight();
  31. public virtual Rect GetCropRect()
  32. {
  33. return new Rect(0f, 0f, 0f, 0f);
  34. }
  35. public abstract float GetVideoDisplayRate();
  36. public abstract bool HasAudio();
  37. public abstract bool HasVideo();
  38. public abstract bool IsSeeking();
  39. public abstract bool IsPlaying();
  40. public abstract bool IsPaused();
  41. public abstract bool IsFinished();
  42. public abstract bool IsBuffering();
  43. public virtual bool WaitForNextFrame(Camera dummyCamera, int previousFrameCount)
  44. {
  45. return false;
  46. }
  47. public virtual int GetTextureCount()
  48. {
  49. return 1;
  50. }
  51. public abstract Texture GetTexture(int index = 0);
  52. public abstract int GetTextureFrameCount();
  53. public virtual long GetTextureTimeStamp()
  54. {
  55. return long.MinValue;
  56. }
  57. public abstract bool RequiresVerticalFlip();
  58. public virtual float[] GetTextureTransform()
  59. {
  60. float[] array = new float[6];
  61. array[0] = 1f;
  62. array[3] = 1f;
  63. return array;
  64. }
  65. public abstract void MuteAudio(bool bMuted);
  66. public abstract bool IsMuted();
  67. public abstract void SetVolume(float volume);
  68. public virtual void SetBalance(float balance)
  69. {
  70. }
  71. public abstract float GetVolume();
  72. public virtual float GetBalance()
  73. {
  74. return 0f;
  75. }
  76. public abstract int GetAudioTrackCount();
  77. public virtual string GetAudioTrackId(int index)
  78. {
  79. return index.ToString();
  80. }
  81. public abstract int GetCurrentAudioTrack();
  82. public abstract void SetAudioTrack(int index);
  83. public abstract string GetCurrentAudioTrackId();
  84. public abstract int GetCurrentAudioTrackBitrate();
  85. public virtual int GetNumAudioChannels()
  86. {
  87. return -1;
  88. }
  89. public virtual void SetAudioHeadRotation(Quaternion q)
  90. {
  91. }
  92. public virtual void ResetAudioHeadRotation()
  93. {
  94. }
  95. public virtual void SetAudioChannelMode(Audio360ChannelMode channelMode)
  96. {
  97. }
  98. public virtual void SetAudioFocusEnabled(bool enabled)
  99. {
  100. }
  101. public virtual void SetAudioFocusProperties(float offFocusLevel, float widthDegrees)
  102. {
  103. }
  104. public virtual void SetAudioFocusRotation(Quaternion q)
  105. {
  106. }
  107. public virtual void ResetAudioFocus()
  108. {
  109. }
  110. public abstract int GetVideoTrackCount();
  111. public virtual string GetVideoTrackId(int index)
  112. {
  113. return index.ToString();
  114. }
  115. public abstract int GetCurrentVideoTrack();
  116. public abstract void SetVideoTrack(int index);
  117. public abstract string GetCurrentVideoTrackId();
  118. public abstract int GetCurrentVideoTrackBitrate();
  119. public abstract float GetVideoFrameRate();
  120. public abstract float GetBufferingProgress();
  121. public abstract void Update();
  122. public abstract void Render();
  123. public abstract void Dispose();
  124. public ErrorCode GetLastError()
  125. {
  126. return this._lastError;
  127. }
  128. public string GetPlayerDescription()
  129. {
  130. return this._playerDescription;
  131. }
  132. public virtual bool PlayerSupportsLinearColorSpace()
  133. {
  134. return true;
  135. }
  136. public virtual int GetBufferedTimeRangeCount()
  137. {
  138. return 0;
  139. }
  140. public virtual bool GetBufferedTimeRange(int index, ref float startTimeMs, ref float endTimeMs)
  141. {
  142. return false;
  143. }
  144. public void SetTextureProperties(FilterMode filterMode = FilterMode.Bilinear, TextureWrapMode wrapMode = TextureWrapMode.Clamp, int anisoLevel = 0)
  145. {
  146. this._defaultTextureFilterMode = filterMode;
  147. this._defaultTextureWrapMode = wrapMode;
  148. this._defaultTextureAnisoLevel = anisoLevel;
  149. for (int i = 0; i < this.GetTextureCount(); i++)
  150. {
  151. this.ApplyTextureProperties(this.GetTexture(i));
  152. }
  153. }
  154. protected virtual void ApplyTextureProperties(Texture texture)
  155. {
  156. if (texture != null)
  157. {
  158. texture.filterMode = this._defaultTextureFilterMode;
  159. texture.wrapMode = this._defaultTextureWrapMode;
  160. texture.anisoLevel = this._defaultTextureAnisoLevel;
  161. }
  162. }
  163. public virtual void GrabAudio(float[] buffer, int floatCount, int channelCount)
  164. {
  165. }
  166. public virtual bool IsPlaybackStalled()
  167. {
  168. return false;
  169. }
  170. public bool LoadSubtitlesSRT(string data)
  171. {
  172. if (string.IsNullOrEmpty(data))
  173. {
  174. this._subtitles = null;
  175. this._currentSubtitle = null;
  176. }
  177. else
  178. {
  179. this._subtitles = Helper.LoadSubtitlesSRT(data);
  180. }
  181. return this._subtitles != null;
  182. }
  183. public virtual void UpdateSubtitles()
  184. {
  185. if (this._subtitles != null)
  186. {
  187. float currentTimeMs = this.GetCurrentTimeMs();
  188. int num = 0;
  189. if (this._currentSubtitle != null && !this._currentSubtitle.IsTime(currentTimeMs))
  190. {
  191. if (currentTimeMs > (float)this._currentSubtitle.timeEndMs)
  192. {
  193. num = this._currentSubtitle.index + 1;
  194. }
  195. this._currentSubtitle = null;
  196. }
  197. if (this._currentSubtitle == null)
  198. {
  199. for (int i = num; i < this._subtitles.Count; i++)
  200. {
  201. if (this._subtitles[i].IsTime(currentTimeMs))
  202. {
  203. this._currentSubtitle = this._subtitles[i];
  204. break;
  205. }
  206. }
  207. }
  208. }
  209. }
  210. public virtual int GetSubtitleIndex()
  211. {
  212. int result = -1;
  213. if (this._currentSubtitle != null)
  214. {
  215. result = this._currentSubtitle.index;
  216. }
  217. return result;
  218. }
  219. public virtual string GetSubtitleText()
  220. {
  221. string result = string.Empty;
  222. if (this._currentSubtitle != null)
  223. {
  224. result = this._currentSubtitle.text;
  225. }
  226. return result;
  227. }
  228. public virtual void OnEnable()
  229. {
  230. }
  231. protected string _playerDescription = string.Empty;
  232. protected ErrorCode _lastError;
  233. protected FilterMode _defaultTextureFilterMode = FilterMode.Bilinear;
  234. protected TextureWrapMode _defaultTextureWrapMode = TextureWrapMode.Clamp;
  235. protected int _defaultTextureAnisoLevel = 1;
  236. protected List<Subtitle> _subtitles;
  237. protected Subtitle _currentSubtitle;
  238. }
  239. }