// %BANNER_BEGIN% // --------------------------------------------------------------------- // %COPYRIGHT_BEGIN% // Copyright (c) (2018-2022) Magic Leap, Inc. All Rights Reserved. // Use of this file is governed by the Software License Agreement, located here: https://www.magicleap.com/software-license-agreement-ml2 // Terms and conditions applicable to third-party materials accompanying this distribution may also be found in the top-level NOTICE file appearing herein. // %COPYRIGHT_END% // --------------------------------------------------------------------- // %BANNER_END% using UnityEngine.XR.MagicLeap.Native; namespace UnityEngine.XR.MagicLeap { using System; using System.Runtime.InteropServices; /// /// APIs for creating and retrieving media format information. /// public partial class MLMediaFormat { /// /// See ml_media_format.h for additional comments. /// private class NativeBindings : MagicLeapNativeBindings { /// /// Internal max size of key string. /// public static int MAX_KEY_STRING_SIZE = 64; /// /// Internal max size of format string. /// public static int MAX_FORMAT_STRING_SIZE = 512; /// /// Data type containing byte array buffer and the size. /// [StructLayout(LayoutKind.Sequential)] internal struct MLMediaFormatByteArray { /// /// Buffer starting pointer. /// public readonly IntPtr Ptr; /// /// Buffer length. /// public readonly ulong Length; /// /// Constructor /// /// Buffer starting pointer /// Buffer length public MLMediaFormatByteArray(IntPtr ptr, ulong length) { this.Ptr = ptr; this.Length = length; } }; /// /// Create a video format object. /// [DllImport(MLMediaFormatDll, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLMediaFormatCreateVideo([MarshalAs(unmanagedType: UnmanagedType.LPStr)] string mimeType, int Width, int Height, out ulong outHandle); /// /// Create a audio format object. /// [DllImport(MLMediaFormatDll, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLMediaFormatCreateAudio([MarshalAs(unmanagedType: UnmanagedType.LPStr)] string MimeType, int SampleRate, int ChannelCount, out ulong outHandle); /// /// Create a subtitle format object. /// [DllImport(MLMediaFormatDll, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLMediaFormatCreateSubtitle([MarshalAs(unmanagedType: UnmanagedType.LPStr)] string MimeType, [MarshalAs(unmanagedType: UnmanagedType.LPStr)] string Language, out ulong outHandle); /// /// Create an empty format object. /// [DllImport(MLMediaFormatDll, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLMediaFormatCreate(out ulong outHandle); /// /// Create a copy of the format handle provided. /// [DllImport(MLMediaFormatDll, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLMediaFormatCreateCopy(ulong handle, out ulong outHandle); /// /// Destroy a format object. /// [DllImport(MLMediaFormatDll, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLMediaFormatDestroy(ulong handle); /// /// Obtain the human readable representation of the format. User shall allocate at least #MAX_FORMAT_STRING_SIZE bytes of /// memory for storing the output format string. The format string contains a list of key-value pairs, which can be /// extracted individually via the suitable "GetKeyValue" APIs. /// [DllImport(MLMediaFormatDll, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLMediaFormatObjectToString(ulong handle, IntPtr outString); /// /// Obtain the value of an integer key. For example, use #MLMediaFormat_Key_Frame_Rate key to get the framerate of a video /// track. /// [DllImport(MLMediaFormatDll, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLMediaFormatGetKeyValueInt32(ulong handle, [MarshalAs(unmanagedType: UnmanagedType.LPStr)] string name, out int outKey); /// /// Obtain the value of an long key. For example, use MLMediaFormat_Key_Duration key to get duration of a track. /// [DllImport(MLMediaFormatDll, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLMediaFormatGetKeyValueInt64(ulong handle, [MarshalAs(unmanagedType: UnmanagedType.LPStr)] string name, out long outKey); /// /// Obtain the value of an float key. /// [DllImport(MLMediaFormatDll, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLMediaFormatGetKeyValueFloat(ulong handle, [MarshalAs(unmanagedType: UnmanagedType.LPStr)] string name, out float outKey); /// /// Obtain the size of a key. /// [DllImport(MLMediaFormatDll, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLMediaFormatGetKeySize(ulong handle, [MarshalAs(unmanagedType: UnmanagedType.LPStr)] string name, out ulong outSize); /// /// Obtain the value of a string key. User shall allocate at least #MAX_KEY_STRING_SIZE bytes of memory for storing the /// output key string. /// [DllImport(MLMediaFormatDll, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLMediaFormatGetKeyString(ulong handle, [MarshalAs(unmanagedType: UnmanagedType.LPStr)] string name, IntPtr outString); /// /// Obtain the value of a ByteBuffer key. /// [DllImport(MLMediaFormatDll, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLMediaFormatGetKeyByteBuffer(ulong handle, [MarshalAs(unmanagedType: UnmanagedType.LPStr)] string name, out MLMediaFormatByteArray OutBuffer); /// /// Release the ByteBuffer acquired by MLMediaFormatGetKeyByteBuffer. /// [DllImport(MLMediaFormatDll, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLMediaFormatKeyByteBufferRelease(ulong handle, ref MLMediaFormatByteArray buffer); /// /// Set the value of an integer key. /// [DllImport(MLMediaFormatDll, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLMediaFormatSetKeyInt32(ulong handle, [MarshalAs(unmanagedType: UnmanagedType.LPStr)] string name, int keyValue); /// /// Set the value of a long key. /// [DllImport(MLMediaFormatDll, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLMediaFormatSetKeyInt64(ulong handle, [MarshalAs(unmanagedType: UnmanagedType.LPStr)] string name, long keyValue); /// /// Set the value of a float key. /// [DllImport(MLMediaFormatDll, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLMediaFormatSetKeyFloat(ulong handle, [MarshalAs(unmanagedType: UnmanagedType.LPStr)] string name, float keyValue); /// /// Set the size of a key. /// [DllImport(MLMediaFormatDll, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLMediaFormatSetKeySize(ulong handle, [MarshalAs(unmanagedType: UnmanagedType.LPStr)] string name, ulong keySize); /// /// Set the value of a string key. /// [DllImport(MLMediaFormatDll, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLMediaFormatSetKeyString(ulong handle, [MarshalAs(unmanagedType: UnmanagedType.LPStr)] string name, [MarshalAs(unmanagedType: UnmanagedType.LPStr)] string KeyValue); /// /// Set the value of a ByteBuffer key. /// [DllImport(MLMediaFormatDll, CallingConvention = CallingConvention.Cdecl)] public static extern MLResult.Code MLMediaFormatSetKeyByteBuffer(ulong handle, [MarshalAs(unmanagedType: UnmanagedType.LPStr)] string name, ref MLMediaFormatByteArray Buffer); } } }