123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439 |
- //-----------------------------------------------------------------------------
- // Copyright 2015-2022 RenderHeads Ltd. All rights reserved.
- //-----------------------------------------------------------------------------
- #if UNITY_2017_2_OR_NEWER && (UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || (!UNITY_EDITOR && (UNITY_IOS || UNITY_TVOS)))
- using System;
- using System.Runtime.InteropServices;
- using UnityEngine;
- namespace RenderHeads.Media.AVProVideo
- {
- public sealed partial class AppleMediaPlayer
- {
- internal partial struct Native
- {
- #if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
- private const string PluginName = "AVProVideo";
- #elif UNITY_IOS || UNITY_TVOS
- private const string PluginName = "__Internal";
- #endif
- // Video settings
- internal enum AVPPlayerVideoPixelFormat: int
- {
- Invalid,
- Bgra,
- YCbCr420
- }
- [Flags]
- internal enum AVPPlayerVideoOutputSettingsFlags: int
- {
- None = 0,
- LinearColorSpace = 1 << 0,
- GenerateMipmaps = 1 << 1,
- }
- // Audio settings
- internal enum AVPPlayerAudioOutputMode : int
- {
- SystemDirect,
- Unity,
- SystemDirectWithCapture,
- }
- // Network settings
- [Flags]
- internal enum AVPPlayerNetworkSettingsFlags: int
- {
- None = 0,
- PlayWithoutBuffering = 1 << 0,
- UseSinglePlayerItem = 1 << 1,
- }
- [StructLayout(LayoutKind.Sequential)]
- internal struct AVPPlayerSettings
- {
- // Video
- internal AVPPlayerVideoPixelFormat pixelFormat;
- internal AVPPlayerVideoOutputSettingsFlags videoFlags;
- internal float preferredMaximumResolution_width;
- internal float preferredMaximumResolution_height;
- internal float maximumPlaybackRate;
- // Audio
- internal AVPPlayerAudioOutputMode audioOutputMode;
- internal int sampleRate;
- internal int bufferLength;
- internal int audioFlags;
- // Network
- internal double preferredPeakBitRate;
- internal double preferredForwardBufferDuration;
- internal AVPPlayerNetworkSettingsFlags networkFlags;
- }
- [Flags]
- internal enum AVPPlayerStatus : int
- {
- Unknown = 0,
- ReadyToPlay = 1 << 0,
- Playing = 1 << 1,
- Paused = 1 << 2,
- Finished = 1 << 3,
- Seeking = 1 << 4,
- Buffering = 1 << 5,
- Stalled = 1 << 6,
- ExternalPlaybackActive = 1 << 7,
- Cached = 1 << 8,
- FinishedSeeking = 1 << 9,
- UpdatedAssetInfo = 1 << 16,
- UpdatedTexture = 1 << 17,
- UpdatedBufferedTimeRanges = 1 << 18,
- UpdatedSeekableTimeRanges = 1 << 19,
- UpdatedText = 1 << 20,
- HasVideo = 1 << 24,
- HasAudio = 1 << 25,
- HasText = 1 << 26,
- HasMetadata = 1 << 27,
- Failed = 1 << 31
- }
- [Flags]
- internal enum AVPPlayerFlags : int
- {
- None = 0,
- Looping = 1 << 0,
- Muted = 1 << 1,
- AllowExternalPlayback = 1 << 2,
- ResumePlayback = 1 << 16, // iOS only, resumes playback after audio session route change
- Dirty = 1 << 31
- }
- internal enum AVPPlayerExternalPlaybackVideoGravity : int
- {
- Resize,
- ResizeAspect,
- ResizeAspectFill
- };
- [StructLayout(LayoutKind.Sequential)]
- internal struct AVPPlayerSize
- {
- internal float width;
- internal float height;
- }
- [StructLayout(LayoutKind.Sequential)]
- internal struct AVPAffineTransform
- {
- internal float a;
- internal float b;
- internal float c;
- internal float d;
- internal float tx;
- internal float ty;
- }
- [Flags]
- internal enum AVPPlayerAssetFlags : int
- {
- None = 0,
- CompatibleWithAirPlay = 1 << 0,
- };
- [StructLayout(LayoutKind.Sequential)]
- internal struct AVPPlayerAssetInfo
- {
- internal double duration;
- internal AVPPlayerSize dimensions;
- internal float frameRate;
- internal int videoTrackCount;
- internal int audioTrackCount;
- internal int textTrackCount;
- internal AVPPlayerAssetFlags flags;
- }
- [Flags]
- internal enum AVPPlayerTrackFlags: int
- {
- Default = 1 << 0,
- }
- internal enum AVPPlayerVideoTrackStereoMode: int
- {
- Unknown,
- Monoscopic,
- StereoscopicTopBottom,
- StereoscopicLeftRight,
- StereoscopicCustom,
- StereoscopicRightLeft,
- }
- [Flags]
- internal enum AVPPlayerVideoTrackFlags: int
- {
- HasAlpha = 1 << 0,
- }
- [StructLayout(LayoutKind.Sequential)]
- internal struct AVPPlayerVideoTrackInfo
- {
- [MarshalAs(UnmanagedType.LPWStr)] internal string name;
- [MarshalAs(UnmanagedType.LPWStr)] internal string language;
- internal int trackId;
- internal float estimatedDataRate;
- internal uint codecSubtype;
- internal AVPPlayerTrackFlags flags;
- internal AVPPlayerSize dimensions;
- internal float frameRate;
- internal AVPAffineTransform transform;
- internal AVPPlayerVideoTrackStereoMode stereoMode;
- internal int bitsPerComponent;
- internal AVPPlayerVideoTrackFlags videoTrackFlags;
- internal Matrix4x4 yCbCrTransform;
- }
- [StructLayout(LayoutKind.Sequential)]
- internal struct AVPPlayerAudioTrackInfo
- {
- [MarshalAs(UnmanagedType.LPWStr)] internal string name;
- [MarshalAs(UnmanagedType.LPWStr)] internal string language;
- internal int trackId;
- internal float estimatedDataRate;
- internal uint codecSubtype;
- internal AVPPlayerTrackFlags flags;
- internal double sampleRate;
- internal uint channelCount;
- internal uint channelLayoutTag;
- internal AudioChannelMaskFlags channelBitmap;
- }
- [StructLayout(LayoutKind.Sequential)]
- internal struct AVPPlayerTextTrackInfo
- {
- [MarshalAs(UnmanagedType.LPWStr)] internal string name;
- [MarshalAs(UnmanagedType.LPWStr)] internal string language;
- internal int trackId;
- internal float estimatedDataRate;
- internal uint codecSubtype;
- internal AVPPlayerTrackFlags flags;
- }
- [StructLayout(LayoutKind.Sequential)]
- internal struct AVPPlayerTimeRange
- {
- internal double start;
- internal double duration;
- };
- [StructLayout(LayoutKind.Sequential)]
- internal struct AVPPlayerState
- {
- internal AVPPlayerStatus status;
- internal double currentTime;
- internal double currentDate;
- internal int selectedVideoTrack;
- internal int selectedAudioTrack;
- internal int selectedTextTrack;
- internal int bufferedTimeRangesCount;
- internal int seekableTimeRangesCount;
- internal int audioCaptureBufferedSamplesCount;
- }
- internal enum AVPPlayerTextureFormat: int
- {
- Unknown,
- BGRA8,
- R8,
- RG8,
- BC1,
- BC3,
- BC4,
- BC5,
- BC7,
- BGR10A2,
- R16,
- RG16,
- BGR10XR,
- }
- [StructLayout(LayoutKind.Sequential)]
- internal struct AVPPlayerTexturePlane
- {
- internal IntPtr plane;
- internal int width;
- internal int height;
- internal AVPPlayerTextureFormat textureFormat;
- }
- [Flags]
- internal enum AVPPlayerTextureFlags: int
- {
- None = 0,
- Flipped = 1 << 0,
- Linear = 1 << 1,
- Mipmapped = 1 << 2,
- }
- internal enum AVPPlayerTextureYCbCrMatrix: int
- {
- Identity,
- ITU_R_601,
- ITU_R_709,
- }
- [StructLayout(LayoutKind.Sequential)]
- internal struct AVPPlayerTexture
- {
- [MarshalAs(UnmanagedType.ByValArray, SizeConst=2)]
- internal AVPPlayerTexturePlane[] planes;
- internal long itemTime;
- internal int frameCount;
- internal int planeCount;
- internal AVPPlayerTextureFlags flags;
- internal AVPPlayerTextureYCbCrMatrix YCbCrMatrix;
- };
- [StructLayout(LayoutKind.Sequential)]
- internal struct AVPPlayerText
- {
- internal IntPtr buffer;
- internal long itemTime;
- internal int length;
- internal int sequence;
- };
- internal enum AVPPlayerTrackType: int
- {
- Video,
- Audio,
- Text
- };
- #if !UNITY_EDITOR && (UNITY_IOS || UNITY_TVOS)
- [DllImport(PluginName)]
- internal static extern void AVPPluginBootstrap();
- #endif
- [DllImport(PluginName)]
- private static extern IntPtr AVPPluginGetVersionStringPointer();
- internal static string GetPluginVersion()
- {
- return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(AVPPluginGetVersionStringPointer());
- }
- [DllImport(PluginName)]
- internal static extern IntPtr AVPPluginMakePlayer(Native.AVPPlayerSettings settings);
- [DllImport(PluginName)]
- internal static extern IntPtr AVPPlayerRelease(IntPtr player);
- [DllImport(PluginName)]
- internal static extern void AVPPlayerGetState(IntPtr player, ref AVPPlayerState state);
- [DllImport(PluginName)]
- internal static extern void AVPPlayerSetFlags(IntPtr player, int flags);
- [DllImport(PluginName)]
- internal static extern void AVPPlayerGetAssetInfo(IntPtr player, ref AVPPlayerAssetInfo info);
- [DllImport(PluginName)]
- internal static extern void AVPPlayerGetVideoTrackInfo(IntPtr player, int index, ref AVPPlayerVideoTrackInfo info);
- [DllImport(PluginName)]
- internal static extern void AVPPlayerGetAudioTrackInfo(IntPtr player, int index, ref AVPPlayerAudioTrackInfo info);
- [DllImport(PluginName)]
- internal static extern void AVPPlayerGetTextTrackInfo(IntPtr player, int index, ref AVPPlayerTextTrackInfo info);
- [DllImport(PluginName)]
- internal static extern void AVPPlayerGetBufferedTimeRanges(IntPtr player, AVPPlayerTimeRange[] ranges, int count);
- [DllImport(PluginName)]
- internal static extern void AVPPlayerGetSeekableTimeRanges(IntPtr player, AVPPlayerTimeRange[] ranges, int count);
- [DllImport(PluginName)]
- internal static extern void AVPPlayerGetTexture(IntPtr player, ref AVPPlayerTexture texture);
- [DllImport(PluginName)]
- internal static extern void AVPPlayerGetText(IntPtr player, ref AVPPlayerText text);
- [DllImport(PluginName)]
- internal static extern void AVPPlayerSetPlayerSettings(IntPtr player, AVPPlayerSettings settings);
-
- [DllImport(PluginName)]
- [return: MarshalAs(UnmanagedType.U1)]
- internal static extern bool AVPPlayerOpenURL(IntPtr player, string url, string headers);
- [DllImport(PluginName)]
- internal static extern void AVPPlayerClose(IntPtr player);
- [DllImport(PluginName)]
- internal static extern int AVPPlayerGetAudio(IntPtr player, float[] buffer, int length);
- [DllImport(PluginName)]
- internal static extern void AVPPlayerSetRate(IntPtr player, float rate);
- [DllImport(PluginName)]
- internal static extern void AVPPlayerSetVolume(IntPtr player, float volume);
- [DllImport(PluginName)]
- internal static extern void AVPPlayerSetExternalPlaybackVideoGravity(IntPtr player, AVPPlayerExternalPlaybackVideoGravity gravity);
- [DllImport(PluginName)]
- internal static extern void AVPPlayerSeek(IntPtr player, double toTime, double toleranceBefore, double toleranceAfter);
- [DllImport(PluginName)]
- internal static extern void AVPPlayerSetKeyServerAuthToken(IntPtr player, string token);
- [DllImport(PluginName)]
- internal static extern void AVPPlayerSetKeyServerURL(IntPtr player, string url);
- [DllImport(PluginName)]
- internal static extern void AVPPlayerSetDecryptionKey(IntPtr player, byte[] key, int length);
- [DllImport(PluginName)]
- [return: MarshalAs(UnmanagedType.I1)]
- internal static extern bool AVPPlayerSetTrack(IntPtr player, AVPPlayerTrackType type, int index);
- #if !UNITY_EDITOR && UNITY_IOS
- public struct MediaCachingOptions
- {
- public double minimumRequiredBitRate;
- public float minimumRequiredResolution_width;
- public float minimumRequiredResolution_height;
- public string title;
- public IntPtr artwork;
- public int artworkLength;
- }
- [DllImport(PluginName)]
- public static extern void AVPPluginCacheMediaForURL(string url, string headers, MediaCachingOptions options);
- [DllImport(PluginName)]
- public static extern void AVPPluginCancelDownloadOfMediaForURL(string url);
- [DllImport(PluginName)]
- public static extern void AVPPluginRemoveCachedMediaForURL(string url);
- [DllImport(PluginName)]
- public static extern int AVPPluginGetCachedMediaStatusForURL(string url, ref float progress);
- #endif
- }
- }
- }
- #endif
|