/// <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);
        }
 private void RegisterInteropCallbacks()
 {
     _interopCallbackArgs = new LocalVideoTrackInterop.InteropCallbackArgs()
     {
         Track = this,
         I420AFrameCallback = LocalVideoTrackInterop.I420AFrameCallback,
         ARGBFrameCallback  = LocalVideoTrackInterop.ARGBFrameCallback,
     };
     _selfHandle = Utils.MakeWrapperRef(this);
     LocalVideoTrackInterop.LocalVideoTrack_RegisterI420AFrameCallback(
         _nativeHandle, _interopCallbackArgs.I420AFrameCallback, _selfHandle);
     LocalVideoTrackInterop.LocalVideoTrack_RegisterARGBFrameCallback(
         _nativeHandle, _interopCallbackArgs.ARGBFrameCallback, _selfHandle);
 }