Persistent Unmanaged Memory Increase in LibVLCSharp During Long Video Playback

37 Views Asked by At

enter image description here

I am developing a video playback application using LibVLCSharp and have encountered a problem with unmanaged memory increasing steadily over time. The application is intended to run for extended periods, but as it plays, unmanaged memory usage continues to grow. I've implemented video playback using SetVideoCallback, and I suspect this might be related to the issue.

The attached image shows the memory profile over a 37-hour period, illustrating the memory growth. Despite various attempts to diagnose the issue, I've been unable to pinpoint the cause or a potential memory leak source.

Here is a simplified version of my video playback setup code:

private IntPtr Lock(IntPtr opaque, IntPtr planes, VLCStream stream)
{
    Debug.WriteLine("[Debug] callback-Lock");

    stream.CurrentTime = DateTime.UtcNow.ToLocalTime();

    Marshal.WriteIntPtr(planes, stream.Handle.AddrOfPinnedObject());

    return IntPtr.Zero;
}

private void Display(IntPtr opaque, IntPtr picture, VLCStream stream)
{
    try
    {
        if (_isPauseStream)
        {
            return;
        }

        if (!stream.PlayerPrepared)
        {
            return;
        }

        TimeSpan timeDifference = stream.CurrentTime - stream.PrevTime;

        double millisecondsDifference = timeDifference.TotalMilliseconds;

        if (millisecondsDifference < stream.Config.StreamDurationTime)
        {
            return;
        }

        if (OnReceiveFrame != null)
        {
            stream.FrameID = stream.FrameID + 1;

            RaiseOnReceiveFrame(stream.Config.FrameWidth, stream.Config.FrameHeight, stream.Config.FrameChannels, stream.Buffer, stream.Config.Idx, stream.FrameID, stream.CurrentTime);
                    
            Debug.WriteLine($"[Debug] callback-Display");
        }

        stream.PrevTime = stream.CurrentTime;
    }
    catch (Exception ex)
    {
        Debug.WriteLine($"[Error] Display Callback Exception: {ex.Message}");
    }
}

Does anyone have insights into why LibVLCSharp might be causing a steady increase in unmanaged memory during video playback? Are there any known issues with SetVideoCallback or best practices I should be following to ensure proper memory management in long-running applications?

I tried everything to clear unmanaged memory leak, and trying to make c++ library using libvlc

0

There are 0 best solutions below