简体   繁体   English

LibVLCSharp MediaInput - 缓冲区太小,将所有读取的文件保存在里面

[英]LibVLCSharp MediaInput - buffer to small too hold all readed file inside

I'm trying to play.mp4 files from low-end camera.我正在尝试从低端相机播放.mp4 文件。 Because VLC does not support http digest md5 auth, I had to implement MediaInput class ( some code here ).因为 VLC 不支持 http digest md5 auth,所以我必须实现 MediaInput class( 这里有一些代码)。 But buffer that is passed from LibVLCSharp in Read() method is too short to hold whole downloaded file inside.但是在 Read() 方法中从 LibVLCSharp 传递的缓冲区太短,无法容纳整个下载的文件。

I'm reading file using HttpClient.我正在使用 HttpClient 读取文件。 Read data are stored in byte [] readedBytes .读取数据存储在byte [] readedBytes中。 Bytes are copied to byteSpan constructed using pointer and length passed from LibVLCSharp.字节被复制到使用从 LibVLCSharp 传递的指针和长度构造的 byteSpan。 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.在每次 Read() 调用中,程序读取 1MB 的数据块并复制到缓冲区,缓冲区的大小减小到小于 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?有没有办法增加缓冲区大小?

You cannot increase the LibVLC buffer size, but you can buffer your "extra" data somewhere else.您不能增加 LibVLC 缓冲区大小,但可以在其他地方缓冲“额外”数据。

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将下一个要读取的数据放入缓冲区(例如MemoryStream),并在下一次读取时检查MemoryStream是否有剩余数据
  • 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.实现生产者/消费者模式:程序的一部分从相机读取文件,另一部分使用 LibVLC 媒体输入的数据。 This can be achieved with System.IO.Pipelines pipes.这可以通过System.IO.Pipelines管道来实现。 You can find an usage example in my PipeMediaInput project on my repo here: https://github.com/jeremyVignelles/libvlcsharp-nonfree-samples您可以在我的 repo 上的 PipeMediaInput 项目中找到一个使用示例: https://github.com/jeremyVignelles/libvlcsharp-nonfree-samples

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM