// %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%
namespace UnityEngine.XR.MagicLeap
{
using System;
using System.Runtime.InteropServices;
using UnityEngine.XR.MagicLeap.Native;
///
/// MLWebRTC class contains the API to interface with the
/// WebRTC C API.
///
public partial class MLWebRTC
{
///
/// Copy of android_LogPriority from android/log.h.
///
public enum AndroidLogPriority : uint
{
Unkown = 0,
Default,
Verbose,
Debug,
Info,
Warn,
Error,
Fatal,
Silent,
}
///
/// Native bindings for the MLWebRTC class.
///
internal class NativeBindings : MagicLeapNativeBindings
{
///
/// Delegate describing the callback necessary to monitor when an debug message is received.
///
/// The log level of the debug utils.
/// The debug message.
/// Pointer to a context object.
public delegate void OnDebugMessageDelegate(AndroidLogPriority logLevel, [MarshalAs(UnmanagedType.LPStr)] string message, IntPtr context);
///
/// Creates the MLWebRTC instance.
///
///
/// MLResult.Result will be MLResult.Code.Ok if the instance was successfully created.
/// MLResult.Result will be MLResult.Code.PermissionDenied if necessary permission is missing.
/// MLResult.Result will be MLResult.Code.UnspecifiedFailure if failed due to other internal error.
///
[DllImport(MLWebRTCDLL, CallingConvention = CallingConvention.Cdecl)]
public static extern MLResult.Code MLWebRTCInstanceCreate();
///
/// Creates the MLWebRTC instance with more debug logs.
///
/// The MLWebRTCDebugUtils object to initialize with.
///
/// MLResult.Result will be MLResult.Code.Ok if the instance was successfully created.
/// MLResult.Result will be MLResult.Code.PermissionDenied if necessary permission is missing.
/// MLResult.Result will be MLResult.Code.UnspecifiedFailure if failed due to other internal error.
///
[DllImport(MLWebRTCDLL, CallingConvention = CallingConvention.Cdecl)]
public static extern MLResult.Code MLWebRTCInstanceCreateWithDebugUtils(in MLWebRTCDebugUtils debugUtils);
///
/// Destroys the MLWebRTC instance.
///
///
/// MLResult.Result will be MLResult.Code.Ok if the instance was successfully destroyed.
/// MLResult.Result will be MLResult.Code.PermissionDenied if necessary permission is missing.
/// MLResult.Result will be MLResult.Code.UnspecifiedFailure if failed due to other internal error.
///
[DllImport(MLWebRTCDLL, CallingConvention = CallingConvention.Cdecl)]
public static extern MLResult.Code MLWebRTCInstanceDestroy();
///
/// Gets the string value of MLWebRTC specific result codes.
///
/// The MLWebRTC specific result code.
///
/// MLResult.Result will be MLResult.Code.Ok if the instance was successfully destroyed.
/// MLResult.Result will be MLResult.Code.PermissionDenied if necessary permission is missing.
/// MLResult.Result will be MLResult.Code.UnspecifiedFailure if failed due to other internal error.
///
[DllImport(MLWebRTCDLL, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr MLWebRTCGetResultString(MLResult.Code result);
///
/// Native callback that is invoked when a data channel closes.
///
/// The log level of the debug utils.
/// The debug message.
/// Pointer to a context object.
[AOT.MonoPInvokeCallback(typeof(OnDebugMessageDelegate))]
private static void OnDebugMessage(AndroidLogPriority logLevel, [MarshalAs(UnmanagedType.LPStr)] string message, IntPtr context)
{
Debug.LogError("MLWebRTC Debug: " + message);
}
///
/// The native representation of the MLWebRTC debug utilities object.
///
[StructLayout(LayoutKind.Sequential)]
public struct MLWebRTCDebugUtils
{
///
/// Version of the struct.
///
public uint Version;
///
/// Pointer to a context object.
///
public IntPtr Context;
///
/// The log level to respect for debugging.
///
public AndroidLogPriority LogLevel;
///
/// The callback for when a debug message is received.
///
public OnDebugMessageDelegate OnDebugMessage;
///
/// Creates an initialized MLWebRTCDebugUtils object.
///
/// An initialized MLWebRTCDebugUtils object.
public static MLWebRTCDebugUtils Create()
{
MLWebRTCDebugUtils debugUtils = new MLWebRTCDebugUtils
{
Version = 1,
LogLevel = AndroidLogPriority.Error,
OnDebugMessage = NativeBindings.OnDebugMessage
};
return debugUtils;
}
}
}
}
}