123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980 |
- using UnityEngine;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- namespace RenderHeads.Media.AVProVideo
- {
- public interface IMediaPlayer
- {
- void OnEnable();
- void Update();
- void EndUpdate();
- void Render();
- IntPtr GetNativePlayerHandle();
- }
-
-
-
- public interface IMediaSubtitles
- {
- bool LoadSubtitlesSRT(string data);
- int GetSubtitleIndex();
- string GetSubtitleText();
- }
- public enum BufferedFrameSelectionMode : int
- {
-
- None = 0,
-
- NewestFrame = 10,
-
- OldestFrame = 11,
-
- MediaClock = 20,
-
- ElapsedTime = 30,
-
-
- ElapsedTimeVsynced = 40,
-
- FromExternalTime = 50,
-
- FromExternalTimeClosest = 51,
- }
-
-
-
- public interface IBufferedDisplay
- {
-
-
-
- long UpdateBufferedDisplay();
- BufferedFramesState GetBufferedFramesState();
- void SetSlaves(IBufferedDisplay[] slaves);
- void SetBufferedDisplayMode(BufferedFrameSelectionMode mode, IBufferedDisplay master = null);
- void SetBufferedDisplayOptions(bool pauseOnPrerollComplete);
- }
- public interface IMediaControl
- {
-
-
-
-
- bool OpenMedia(string path, long offset, string customHttpHeaders, MediaHints mediahints, int forceFileFormat = 0, bool startWithHighestBitrate = false);
- bool OpenMediaFromBuffer(byte[] buffer);
- bool StartOpenMediaFromBuffer(ulong length);
- bool AddChunkToMediaBuffer(byte[] chunk, ulong offset, ulong length);
- bool EndOpenMediaFromBuffer();
- #if NETFX_CORE
- bool OpenMedia(Windows.Storage.Streams.IRandomAccessStream ras, string path, long offset, string customHttpHeaders);
- #endif
- void CloseMedia();
- void SetLooping(bool bLooping);
- bool IsLooping();
- bool HasMetaData();
- bool CanPlay();
- bool IsPlaying();
- bool IsSeeking();
- bool IsPaused();
- bool IsFinished();
- bool IsBuffering();
- void Play();
- void Pause();
- void Stop();
- void Rewind();
-
-
-
-
-
- void Seek(double time);
-
-
-
- void SeekFast(double time);
-
-
-
-
-
- void SeekWithTolerance(double time, double timeDeltaBefore, double timeDeltaAfter);
-
-
-
-
-
- void SeekToFrame(int frame, float overrideFrameRate = 0f);
-
-
-
-
-
- void SeekToFrameRelative(int frameOffset, float overrideFrameRate = 0f);
-
-
-
- double GetCurrentTime();
-
-
-
-
-
- int GetCurrentTimeFrames(float overrideFrameRate = 0f);
-
-
-
-
-
-
- System.DateTime GetProgramDateTime();
- float GetPlaybackRate();
- void SetPlaybackRate(float rate);
- void MuteAudio(bool bMute);
- bool IsMuted();
- void SetVolume(float volume);
- void SetBalance(float balance);
- float GetVolume();
- float GetBalance();
-
-
-
-
- TimeRanges GetSeekableTimes();
-
-
-
-
- TimeRanges GetBufferedTimes();
- ErrorCode GetLastError();
- long GetLastExtendedErrorCode();
- void SetTextureProperties(FilterMode filterMode = FilterMode.Bilinear, TextureWrapMode wrapMode = TextureWrapMode.Clamp, int anisoLevel = 1);
- void GetTextureProperties(out FilterMode filterMode, out TextureWrapMode wrapMode, out int anisoLevel);
-
-
-
-
-
-
- int GrabAudio(float[] buffer, int sampleCount, int channelCount);
- int GetAudioBufferedSampleCount();
- int GetAudioChannelCount();
- AudioChannelMaskFlags GetAudioChannelMask();
-
- void SetAudioChannelMode(Audio360ChannelMode channelMode);
- void SetAudioHeadRotation(Quaternion q);
- void ResetAudioHeadRotation();
- void SetAudioFocusEnabled(bool enabled);
- void SetAudioFocusProperties(float offFocusLevel, float widthDegrees);
- void SetAudioFocusRotation(Quaternion q);
- void ResetAudioFocus();
- bool WaitForNextFrame(Camera dummyCamera, int previousFrameCount);
- [Obsolete("SetPlayWithoutBuffering has been deprecated, see platform specific options for how to enable playback without buffering (if supported).")]
- void SetPlayWithoutBuffering(bool playWithoutBuffering);
-
-
- void SetKeyServerAuthToken(string token);
- void SetOverrideDecryptionKey(byte[] key);
-
-
-
-
- bool IsExternalPlaybackActive();
-
-
-
- void SetAllowsExternalPlayback(bool enable);
-
-
-
- void SetExternalPlaybackVideoGravity(ExternalPlaybackVideoGravity gravity);
- }
- public interface IMediaInfo
- {
-
-
-
- double GetDuration();
-
-
-
-
-
- int GetDurationFrames(float overrideFrameRate = 0f);
-
-
-
-
-
- int GetMaxFrameNumber(float overrideFrameRate = 0f);
-
-
-
- int GetVideoWidth();
-
-
-
- int GetVideoHeight();
-
-
-
- float GetVideoFrameRate();
-
-
-
- float GetVideoDisplayRate();
-
-
-
- bool HasVideo();
-
-
-
- bool HasAudio();
-
-
-
-
-
-
-
-
-
-
- string GetPlayerDescription();
- #if !AVPRO_NEW_GAMMA
-
-
-
-
- bool PlayerSupportsLinearColorSpace();
- #endif
-
-
-
- bool IsPlaybackStalled();
-
-
-
- float[] GetTextureTransform();
-
-
-
-
- long GetEstimatedTotalBandwidthUsed();
-
-
-
-
- bool IsExternalPlaybackSupported();
-
- bool GetDecoderPerformance(ref int activeDecodeThreadCount, ref int decodedFrameCount, ref int droppedFrameCount);
-
- PlaybackQualityStats GetPlaybackQualityStats();
- }
- #region MediaCaching
-
- public class MediaCachingOptions
- {
-
- public double minimumRequiredBitRate;
-
-
- public Vector2 minimumRequiredResolution;
-
-
- public double maximumRequiredBitRate;
-
-
- public Vector2 maximumRequiredResolution;
-
-
- public string title;
-
-
- public byte[] artwork;
- }
-
- public enum CachedMediaStatus: int
- {
-
- NotCached,
-
- Caching,
-
- Cached,
-
- Failed,
-
- Paused
- }
-
- public interface IMediaCache
- {
-
-
- bool IsMediaCachingSupported();
-
-
-
-
- void AddMediaToCache(string url, string headers = null, MediaCachingOptions options = null);
-
-
- void CancelDownloadOfMediaToCache(string url);
-
-
- void PauseDownloadOfMediaToCache(string url);
-
-
- void ResumeDownloadOfMediaToCache(string url);
-
-
- void RemoveMediaFromCache(string url);
-
-
-
-
- CachedMediaStatus GetCachedMediaStatus(string url, ref float progress);
- }
- #endregion
- public interface ITextureProducer
- {
-
-
-
- int GetTextureCount();
-
-
-
-
-
-
-
- Texture GetTexture(int index = 0);
-
-
-
- int GetTextureFrameCount();
-
-
-
- bool SupportsTextureFrameCount();
-
-
-
- long GetTextureTimeStamp();
-
-
-
- float GetTexturePixelAspectRatio();
-
-
-
- bool RequiresVerticalFlip();
-
-
-
- StereoPacking GetTextureStereoPacking();
-
-
-
- TransparencyMode GetTextureTransparency();
-
-
-
- AlphaPacking GetTextureAlphaPacking();
-
-
-
- Matrix4x4 GetYpCbCrTransform();
- #if AVPRO_NEW_GAMMA
-
-
-
-
-
- TextureGamma GetTextureSampleGamma();
- bool TextureRequiresGammaConversion();
- #endif
- }
- public enum Platform
- {
- Windows,
- MacOSX,
- iOS,
- tvOS,
- Android,
- WindowsUWP,
- WebGL,
- Count = 7,
- Unknown = 100,
- }
- public enum MediaSource
- {
- Reference,
- Path,
- }
- public enum MediaPathType
- {
- AbsolutePathOrURL,
- RelativeToProjectFolder,
- RelativeToStreamingAssetsFolder,
- RelativeToDataFolder,
- RelativeToPersistentDataFolder,
- }
- [System.Serializable]
- public class MediaPath
- {
- [SerializeField] MediaPathType _pathType = MediaPathType.RelativeToStreamingAssetsFolder;
- public MediaPathType PathType { get { return _pathType; } internal set { _pathType = value; } }
- [SerializeField] string _path = string.Empty;
- public string Path { get { return _path; } internal set { _path = value; } }
- public MediaPath()
- {
- _pathType = MediaPathType.RelativeToStreamingAssetsFolder;
- _path = string.Empty;
- }
- public MediaPath(MediaPath copy)
- {
- _pathType = copy.PathType;
- _path = copy.Path;
- }
- public MediaPath(string path, MediaPathType pathType)
- {
- _pathType = pathType;
- _path = path;
- }
- public string GetResolvedFullPath()
- {
- string result = Helper.GetFilePath(_path, _pathType);
- #if (UNITY_EDITOR_WIN || (!UNITY_EDITOR && UNITY_STANDALONE_WIN))
- if (result.Length > 200 && !result.Contains("://"))
- {
- result = Helper.ConvertLongPathToShortDOS83Path(result);
- }
- #endif
- return result;
- }
- public static bool operator == (MediaPath a, MediaPath b)
- {
- if ((object)a == null)
- return (object)b == null;
- return a.Equals(b);
- }
- public static bool operator != (MediaPath a, MediaPath b)
- {
- return !(a == b);
- }
- public override bool Equals(object obj)
- {
- if (obj == null || GetType() != obj.GetType())
- return false;
- var a = (MediaPath)obj;
- return (_pathType == a._pathType && _path == a._path);
- }
- public override int GetHashCode()
- {
- return _pathType.GetHashCode() ^ _path.GetHashCode();
- }
- }
- public enum OverrideMode
- {
- None,
- Override,
- }
- public enum TextureGamma
- {
- SRGB,
- Linear,
-
-
-
- }
- public enum StereoPacking : int
- {
- None = 0,
- TopBottom = 1,
- LeftRight = 2,
- CustomUV = 3,
- TwoTextures = 4,
- Unknown = 10,
- }
- [System.Serializable]
- public struct MediaHints
- {
- public TransparencyMode transparency;
- public AlphaPacking alphaPacking;
- public StereoPacking stereoPacking;
- private static MediaHints defaultHints = new MediaHints();
- public static MediaHints Default { get { return defaultHints; } }
- }
- [System.Serializable]
- public struct VideoResolveOptions
- {
- [SerializeField] public bool applyHSBC;
- [SerializeField, Range(0f, 1f)] public float hue;
- [SerializeField, Range(0f, 1f)] public float saturation;
- [SerializeField, Range(0f, 1f)] public float brightness;
- [SerializeField, Range(0f, 1f)] public float contrast;
- [SerializeField, Range(0.0001f, 10f)] public float gamma;
- [SerializeField] public Color tint;
- [SerializeField] public bool generateMipmaps;
- public bool IsColourAdjust()
- {
- return (applyHSBC && (hue != 0.0f || saturation != 0.5f || brightness != 0.5f || contrast != 0.5f || gamma != 1.0f));
- }
- internal void ResetColourAdjust()
- {
- hue = 0.0f;
- saturation = 0.5f;
- brightness = 0.5f;
- contrast = 0.5f;
- gamma = 1.0f;
- }
- public static VideoResolveOptions Create()
- {
- VideoResolveOptions result = new VideoResolveOptions()
- {
- tint = Color.white,
- };
- result.ResetColourAdjust();
- return result;
- }
- }
-
- public enum TransparencyMode
- {
- Opaque,
- Transparent,
- }
- public enum StereoEye
- {
- Both,
- Left,
- Right,
- }
- public enum AlphaPacking
- {
- None,
- TopBottom,
- LeftRight,
- }
- public enum ErrorCode
- {
- None = 0,
- LoadFailed = 100,
- DecodeFailed = 200,
- }
- public enum Orientation
- {
- Landscape,
- LandscapeFlipped,
- Portrait,
- PortraitFlipped,
- PortraitHorizontalMirror,
- }
- public enum VideoMapping
- {
- Unknown,
- Normal,
- EquiRectangular360,
- EquiRectangular180,
- CubeMap3x2,
- }
- public enum FileFormat
- {
- Unknown,
- HLS,
- DASH,
- SmoothStreaming,
- }
- public static class Windows
- {
- public enum VideoApi
- {
- MediaFoundation,
- DirectShow,
- WinRT,
- };
- public enum AudioOutput
- {
- System,
- Unity,
- FacebookAudio360,
- None,
- }
-
- public const string AudioDeviceOutputName_Vive = "HTC VIVE USB Audio";
- public const string AudioDeviceOutputName_Rift = "Headphones (Rift Audio)";
- }
- public static class WindowsUWP
- {
- public enum VideoApi
- {
- MediaFoundation,
- WinRT,
- };
- public enum AudioOutput
- {
- System,
- Unity,
- FacebookAudio360,
- None,
- }
- }
- public static class Android
- {
- public enum VideoApi
- {
- MediaPlayer = 1,
- ExoPlayer,
- }
- public enum AudioOutput
- {
- System,
- Unity,
- FacebookAudio360,
- }
- public enum TextureFiltering
- {
- Point,
- Bilinear,
- Trilinear,
- }
- public const int Default_MinBufferTimeMs = 50000;
- public const int Default_MaxBufferTimeMs = 50000;
- public const int Default_BufferForPlaybackMs = 2500;
- public const int Default_BufferForPlaybackAfterRebufferMs = 5000;
- }
- public static class WebGL
- {
- public enum ExternalLibrary
- {
- None,
- DashJs,
- HlsJs,
- Custom,
- }
- }
-
- public enum Audio360ChannelMode
- {
- TBE_8_2 = 0,
- TBE_8,
- TBE_6_2,
- TBE_6,
- TBE_4_2,
- TBE_4,
- TBE_8_PAIR0,
- TBE_8_PAIR1,
- TBE_8_PAIR2,
- TBE_8_PAIR3,
- TBE_CHANNEL0,
- TBE_CHANNEL1,
- TBE_CHANNEL2,
- TBE_CHANNEL3,
- TBE_CHANNEL4,
- TBE_CHANNEL5,
- TBE_CHANNEL6,
- TBE_CHANNEL7,
- HEADLOCKED_STEREO,
- HEADLOCKED_CHANNEL0,
- HEADLOCKED_CHANNEL1,
- AMBIX_4,
- AMBIX_4_2,
- AMBIX_9,
- AMBIX_9_2,
- AMBIX_16,
- AMBIX_16_2,
- MONO,
- STEREO,
- UNKNOWN,
- INVALID,
- }
- [System.Flags]
- public enum AudioChannelMaskFlags : int
- {
- Unspecified = 0x0,
- FrontLeft = 0x1,
- FrontRight = 0x2,
- FrontCenter = 0x4,
- LowFrequency = 0x8,
- BackLeft = 0x10,
- BackRight = 0x20,
- FrontLeftOfCenter = 0x40,
- FrontRightOfCenter = 0x80,
- BackCenter = 0x100,
- SideLeft = 0x200,
- SideRight = 0x400,
- TopCenter = 0x800,
- TopFrontLeft = 0x1000,
- TopFrontCenter = 0x2000,
- TopFrontRight = 0x4000,
- TopBackLeft = 0x8000,
- TopBackCenter = 0x10000,
- TopBackRight = 0x20000,
- }
- public enum TextureFlags : int
- {
- Unknown = 0,
- TopDown = 1 << 0,
- SamplingIsLinear = 1 << 1,
- }
- [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential, Pack = 1)]
- public struct BufferedFramesState
- {
- public System.Int32 freeFrameCount;
- public System.Int32 bufferedFrameCount;
- public System.Int64 minTimeStamp;
- public System.Int64 maxTimeStamp;
- public System.Int32 prerolledCount;
- }
- [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential, Pack = 1)]
- public struct TextureFrame
- {
- internal System.IntPtr texturePointer;
- internal System.IntPtr auxTexturePointer;
- internal System.Int64 timeStamp;
- internal System.UInt32 frameCounter;
- internal System.UInt32 writtenFrameCount;
- internal TextureFlags flags;
- internal System.IntPtr internalNativePointer;
- }
- [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential, Pack = 1)]
- public struct TimeRange
- {
- public TimeRange(double startTime, double duration)
- {
- this.startTime = startTime;
- this.duration = duration;
- }
- public double startTime, duration;
- public double StartTime { get { return startTime; } }
- public double EndTime { get { return startTime + duration; } }
- public double Duration { get { return duration; } }
- }
- public class TimeRanges : IEnumerable
- {
- internal TimeRanges() {}
- public IEnumerator GetEnumerator()
- {
- return _ranges.GetEnumerator();
- }
- public TimeRange this[int index]
- {
- get
- {
- return _ranges[index];
- }
- }
- internal TimeRanges(TimeRange[] ranges)
- {
- _ranges = ranges;
- CalculateRange();
- }
- internal void CalculateRange()
- {
- _minTime = _maxTime = 0.0;
- if (_ranges != null && _ranges.Length > 0)
- {
- double maxTime = 0.0;
- double minTime = double.MaxValue;
- for (int i = 0; i < _ranges.Length; i++)
- {
- minTime = System.Math.Min(minTime, _ranges[i].startTime);
- maxTime = System.Math.Max(maxTime, _ranges[i].startTime + _ranges[i].duration);
- }
- _minTime = minTime;
- _maxTime = maxTime;
- }
- }
- public int Count { get { return _ranges.Length; } }
- public double MinTime { get { return _minTime; } }
- public double MaxTime { get { return _maxTime; } }
- public double Duration { get { return (_maxTime - _minTime); } }
- internal TimeRange[] _ranges = new TimeRange[0];
- internal double _minTime = 0.0;
- internal double _maxTime = 0.0;
- }
-
-
-
- public enum ExternalPlaybackVideoGravity
- {
-
- Resize,
-
- ResizeAspect,
-
- ResizeAspectFill,
- };
- }
|