-
-
Notifications
You must be signed in to change notification settings - Fork 416
Cannot read non-seekable streams #647
Comments
Maybe relevant https://code.videolan.org/videolan/vlc-unity/-/issues/55 |
Found a workaround here : https://github.com/graysuit/vlc_text_encr/pull/1 . Not sure how and if it should be integrated into Vlc.DotNet / LVS |
Declared non-seekable streams as non-seekable in callback input Increased the buffer size to match VLC buffer size Related to #647
The usage of libvlc_media_new_callback in Vlc.DotNet was not correct, and the stream was considered seekable while it was not. I fixed that with #648 . Now, the message has changed :
It seems that your mp4 cannot be consumed that way, in non-seekable streams, and I don't think that Vlc.DotNet should make a compatibility layer for that. If you can't change your stream, you can use the workaround I implemented here : A using System;
using System.IO;
namespace vlcplayerCsharp1
{
/// <summary>
/// A wrapper that destroys and creates a stream on demand to be able to seek into non-seekable stream...
/// </summary>
public class SeekableStreamWrapper : Stream
{
private readonly Func<Stream> _createStream;
private Stream _innerStream;
private long _position = 0;
/// <summary>
/// The constructor
/// </summary>
/// <param name="createStream"></param>
public SeekableStreamWrapper(Func<Stream> createStream)
{
this._createStream = createStream;
this._innerStream = createStream();
}
public override bool CanRead => true;
public override bool CanSeek => true;
public override bool CanWrite => false;
public override long Length => this._innerStream.Length;
public override long Position { get => this._position; set => this.Seek(value, SeekOrigin.Begin); }
public override void Flush() => this._innerStream.Flush();
public override int Read(byte[] buffer, int offset, int count)
{
var read = this._innerStream.Read(buffer, offset, count);
this._position += read;
return read;
}
public override long Seek(long offset, SeekOrigin origin)
{
if (origin != SeekOrigin.Begin)
{
throw new NotSupportedException("Only supports seeking from the beginning");
}
long remaining = 0;
if (offset > this._position)
{
remaining = offset - this._position;
}
else
{
try
{
this._innerStream.Dispose();
}
catch (Exception)
{
// Shit happens... On .NET framework, calling Dispose() on a crypto stream without having read anything can throw...
}
this._innerStream = this._createStream();
remaining = offset;
}
var buffer = new byte[Math.Min(0x100_000, remaining)];
while (remaining > 0)
{
var read = this._innerStream.Read(buffer, 0, Math.Min(0x100_000, (remaining > int.MaxValue) ? int.MaxValue : (int)remaining));
remaining -= read;
}
this._position = offset;
return offset;
}
public override void SetLength(long value)
{
throw new NotSupportedException();
}
public override void Write(byte[] buffer, int offset, int count)
{
throw new NotSupportedException();
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
this._innerStream.Dispose();
}
base.Dispose(disposing);
}
}
} |
Declared non-seekable streams as non-seekable in callback input Increased the buffer size to match VLC buffer size Related to #647
I have an issue about Vlc.DotNet.
Generic information
Summary
When using Play(Stream), when Stream is a non-seekable stream like a mp4 in a CryptoStream, the player cannot play:
Repro:
This seems to be because LibVLC does a probing of the media to know what kind of stream it is.
/cc :
@graysuit (thanks for the repro project)
@mfkl : We have the same issue in LibVLCSharp
I confirm that my issue doesn't happen in VLC itself.
The text was updated successfully, but these errors were encountered: