/// <summary> /// Creates an initialized AudioSink object. /// </summary> /// <param name="result">The MLResult object of the inner platform call(s).</param> /// <returns> An initialized AudioSink object.</returns> public static AudioSink Create(out MLResult result, BufferNotifyMode mode = BufferNotifyMode.None) { AudioSink audioSink = null; #if PLATFORM_LUMIN List <MLWebRTC.Sink> sinks = MLWebRTC.Instance.sinks; ulong handle = MagicLeapNativeBindings.InvalidHandle; // We have a chicken-and-egg problem here. We need the audioSink object in order to create the // userContext ptr from it GCHandle, which will later be used in the audio data callback to // invoke the delegate on this particular object. // So, create the AudioSink obj with an invalid handle for now, and then update it if the // native sink creation is successful. audioSink = new AudioSink(handle, mode); NativeBindings.MLWebRTCAudioSinkParams sinkParams = new NativeBindings.MLWebRTCAudioSinkParams(audioSink); MLResult.Code resultCode = NativeBindings.MLWebRTCAudioSinkCreateEx(ref sinkParams, out handle); if (!DidNativeCallSucceed(resultCode, "MLWebRTCAudioSinkCreateEx()")) { result = MLResult.Create(resultCode); return(null); } audioSink.Handle = handle; if (MagicLeapNativeBindings.MLHandleIsValid(audioSink.Handle)) { sinks.Add(audioSink); } result = MLResult.Create(resultCode); #else result = new MLResult(); #endif return(audioSink); }
/// <summary> /// Initializes a new instance of the <see cref="AudioSink" /> class. /// </summary> internal AudioSink(ulong handle, BufferNotifyMode mode) : base(handle) { this.Type = MediaStream.Track.Type.Audio; this.Mode = mode; this.CurrentServiceStatus = ServiceStatus.Unknown; this.gcHandle = GCHandle.Alloc(this); }