Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: infinite read loop at end of some FFmpeg streams #24

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion nativesrc/aurioffmpegproxy/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ int file_close(FILE* f) {
}

int file_read_packet(void* f, uint8_t* buf, int buf_size) {
return (int)fread(buf, 1, buf_size, f);
int bytesRead = (int)fread(buf, 1, buf_size, f);
return bytesRead > 0 ? bytesRead : AVERROR_EOF;
}

int64_t file_seek(void* f, int64_t offset, int whence) {
Expand Down
6 changes: 6 additions & 0 deletions src/Aurio.FFmpeg/FFmpegReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace Aurio.FFmpeg
{
public class FFmpegReader : IDisposable
{
private const int AVERROR_EOF = -('E' | ('O' << 8) | ('F' << 16) | (' ' << 24));
private string filename; // store source filename for debugging
private bool disposed = false;
private Type mode;
Expand Down Expand Up @@ -87,6 +88,11 @@ public unsafe FFmpegReader(Stream stream, Type mode, string fileName)
var bufferSpan = new Span<byte>(buffer.ToPointer(), bufferSize);
int bytesRead = stream.Read(bufferSpan);

if (bytesRead <= 0)
{
return AVERROR_EOF;
}

return bytesRead;
};
seekDelegate = delegate(IntPtr opaque, long offset, int whence)
Expand Down
Loading