0

I'm trying to play .mp4 files from low-end camera. Because VLC does not support http digest md5 auth, I had to implement MediaInput class (some code here). But buffer that is passed from LibVLCSharp in Read() method is too short to hold whole downloaded file inside.

I'm reading file using HttpClient. Read data are stored in byte [] readedBytes. Bytes are copied to byteSpan constructed using pointer and length passed from LibVLCSharp. On each Read() call, program reads 1MB chunk of data and copies in to the buffer, which size decreased till is less than 1 MB. That causes exception and results in not playing full video file.

    public unsafe override int Read(IntPtr buf, uint len)
        {
            ...

            Span<byte> byteSpan = new Span<byte>(buf.ToPointer(), (int)len);
            readedBytes.CopyTo(byteSpan);
        }

How to handle this problem properly?

Is there any way to increase buffer size?

ElPato
  • 11
  • 4

1 Answers1

0

You cannot increase the LibVLC buffer size, but you can buffer your "extra" data somewhere else.

Some ideas:

  • Put the next data to be read in your buffer (MemoryStream for example), and at the next Read, check if the MemoryStream has remaining data
  • Implement a producer/consumer pattern : One part of your program reads the files from the camera, and the other part consumes the data for the LibVLC media input. This can be achieved with System.IO.Pipelines pipes. You can find an usage example in my PipeMediaInput project on my repo here : https://github.com/jeremyVignelles/libvlcsharp-nonfree-samples
cube45
  • 3,429
  • 2
  • 24
  • 35