Skip to content

Commit

Permalink
Rewrite of StreamingRingBuffer::safe_read
Browse files Browse the repository at this point in the history
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 8b8ec72
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions mythtv/libs/libmythtv/streamingringbuffer.cpp
Expand Up @@ -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
Expand Down

0 comments on commit 8b8ec72

Please sign in to comment.