/// <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);
            }
Ejemplo n.º 2
0
 private Task StopAudioStream()
 {
     if (AudioDepacketizer != null)
     {
         AudioDepacketizer.Destroy();
         AudioDepacketizer = null;
     }
     if (AudioDecoder != null)
     {
         AudioDecoder.Destroy();
         AudioDecoder = null;
     }
     if (AudioConverter != null)
     {
         AudioConverter.Destroy();
         AudioConverter = null;
     }
     if (ResetAudioPipe != null)
     {
         ResetAudioPipe.Destroy();
         ResetAudioPipe = null;
     }
     if (AudioEncoder != null)
     {
         AudioEncoder.Destroy();
         AudioEncoder = null;
     }
     if (AudioPacketizer != null)
     {
         AudioPacketizer.Destroy();
         AudioPacketizer = null;
     }
     if (AudioSink != null)
     {
         AudioSink.Destroy();
         AudioSink = null;
     }
     return(Task.CompletedTask);
 }