/// <inheritdoc/> public void Dispose() { if (_nativeHandle.IsClosed) { return; } // Remove the track from the peer connection, if any if (Transceiver != null) { Debug.Assert(PeerConnection != null); Debug.Assert(Transceiver.LocalTrack == this); Transceiver.LocalAudioTrack = null; } Debug.Assert(PeerConnection == null); Debug.Assert(Transceiver == null); // Unregister interop callbacks if (_selfHandle != IntPtr.Zero) { LocalAudioTrackInterop.LocalAudioTrack_RegisterFrameCallback(_nativeHandle, null, IntPtr.Zero); Utils.ReleaseWrapperRef(_selfHandle); _selfHandle = IntPtr.Zero; _interopCallbackArgs = null; } // Destroy the native object. This may be delayed if a P/Invoke callback is underway, // but will be handled at some point anyway, even if the managed instance is gone. _nativeHandle.Dispose(); }
private void RegisterInteropCallbacks() { _interopCallbackArgs = new LocalAudioTrackInterop.InteropCallbackArgs() { Track = this, FrameCallback = LocalAudioTrackInterop.FrameCallback, }; _selfHandle = Utils.MakeWrapperRef(this); LocalAudioTrackInterop.LocalAudioTrack_RegisterFrameCallback( _nativeHandle, _interopCallbackArgs.FrameCallback, _selfHandle); }