/// <inheritdoc/>
        protected override void Dispose(bool disposing)
        {
            if (_nativeHandle != IntPtr.Zero)
            {
                // Unregister the callbacks
                if (_selfHandle != IntPtr.Zero)
                {
                    LocalVideoTrackInterop.LocalVideoTrack_RegisterI420AFrameCallback(_nativeHandle, null, IntPtr.Zero);
                    LocalVideoTrackInterop.LocalVideoTrack_RegisterARGBFrameCallback(_nativeHandle, null, IntPtr.Zero);
                    GCHandle.FromIntPtr(_selfHandle).Free();
                    if (disposing)
                    {
                        _interopCallbackArgs = null;
                    }
                    _selfHandle = IntPtr.Zero;
                }

                // Remove the track from the peer connection, and release the reference
                // to the peer connection.
                if (!_nativePeerHandle.IsClosed)
                {
                    PeerConnectionInterop.PeerConnection_RemoveLocalVideoTrack(_nativePeerHandle, _nativeHandle);
                    _nativePeerHandle.Close();
                }
            }

            if (disposing)
            {
                PeerConnection = null;
            }

            base.Dispose(disposing);
        }
 internal LocalVideoTrack(PeerConnection peer, PeerConnectionHandle nativePeerHandle, IntPtr nativeHandle, string trackName)
     : base(nativeHandle)
 {
     PeerConnection = peer;
     PeerConnectionInterop.PeerConnection_AddRef(nativePeerHandle);
     _nativePeerHandle = nativePeerHandle.MakeCopy();
     Name = trackName;
     RegisterInteropCallbacks();
 }
        internal void OnTrackRemoved(PeerConnection previousConnection)
        {
            Debug.Assert(PeerConnection == previousConnection);
            Debug.Assert(_nativeHandle != IntPtr.Zero);

            if (!_nativePeerHandle.IsInvalid)
            {
                PeerConnectionInterop.PeerConnection_RemoveLocalVideoTrack(_nativePeerHandle, _nativeHandle);
                _nativePeerHandle.Close();
            }

            PeerConnection = null;
        }