Permalink
Browse files

Rewrite of StreamingRingBuffer::safe_read

safe_read was based on FFmpeg's ffurl_read_complete, however when an EOF or an error is encountered, ffurl_read_complete returns the error code rather than the number of bytes read so far.
Rather than wait for FFmpeg to fix it (ref: https://ffmpeg.org/trac/ffmpeg/ticket/2537) ; work around it.
safe_read now will set errno as expected and always return a value >= 0 representing the number of bytes actually read.

Fixes #11263
  • Loading branch information...
jyavenard committed May 6, 2013
1 parent dc71567 commit 8b8ec72b005ecf1cb9d36bb4f82469b3718fefb4
Showing with 19 additions and 2 deletions.
  1. +19 −2 mythtv/libs/libmythtv/streamingringbuffer.cpp
@@ -101,9 +101,26 @@ long long StreamingRingBuffer::Seek(long long pos, int whence, bool has_lock)
int StreamingRingBuffer::safe_read(void *data, uint sz)
{
uint len = 0;
if (m_context)
return ffurl_read_complete(m_context, (unsigned char*)data, sz);
return 0;
{
while (len < sz)
{
int ret = ffurl_read(m_context, (unsigned char*)data + len, sz - len);
if (ret < 0)
{
if (ret == AVERROR_EOF)
{
ateof = true;
}
errno = ret;
break;
}
len += ret;
}
}
return len;
}
long long StreamingRingBuffer::GetRealFileSize(void) const

0 comments on commit 8b8ec72

Please sign in to comment.