From 8ca0ccd187c969e14925dcc8a0933d074dbf683e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Fri, 10 Jul 2009 14:23:47 +0000 Subject: [PATCH] * Fixed compilation with TRACE_IO defined. * Improved Seek(). If wence is not SEEK_SET, make sure to check the current source position and adjust it to what the stream points to. Also, return just -1 on error since this is used for libavformat code. And don't set the stream position to the error return value. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31504 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../media/plugins/ffmpeg/AVFormatReader.cpp | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/add-ons/media/plugins/ffmpeg/AVFormatReader.cpp b/src/add-ons/media/plugins/ffmpeg/AVFormatReader.cpp index 57bfdacd80..a56fd6a6c9 100644 --- a/src/add-ons/media/plugins/ffmpeg/AVFormatReader.cpp +++ b/src/add-ons/media/plugins/ffmpeg/AVFormatReader.cpp @@ -48,6 +48,9 @@ static const size_t kIOBufferSize = 64 * 1024; // the allow to specify a buffering mode. +// #pragma mark - AVFormatReader::StreamCookie + + class AVFormatReader::StreamCookie { public: StreamCookie(BPositionIO* source, @@ -98,8 +101,8 @@ private: int bufferSize); static off_t _Seek(void* cookie, off_t offset, int whence); - status_t _NextPacket(bool reuse); + private: BPositionIO* fSource; off_t fPosition; @@ -152,7 +155,7 @@ status_t AVFormatReader::StreamCookie::Open() { // Init probing data - size_t probeSize = kIOBufferSize / 2; //1024; + size_t probeSize = 2048; AVProbeData probeData; probeData.filename = ""; probeData.buf = fIOBuffer; @@ -235,6 +238,8 @@ AVFormatReader::StreamCookie::Init(int32 virtualIndex) return B_BAD_INDEX; } + TRACE(" context stream index: %ld\n", streamIndex); + const DemuxerFormat* demuxerFormat = demuxer_format_for(fContext->iformat); if (demuxerFormat == NULL) { TRACE(" unknown AVInputFormat!\n"); @@ -817,7 +822,7 @@ AVFormatReader::StreamCookie::_Read(void* cookie, uint8* buffer, int bufferSize) { TRACE_IO("AVFormatReader::StreamCookie::_Read(%p, %p, %d)\n", - cookie, buffer, whence); + cookie, buffer, bufferSize); StreamCookie* stream = reinterpret_cast(cookie); @@ -859,10 +864,24 @@ AVFormatReader::StreamCookie::_Seek(void* cookie, off_t offset, int whence) return -1; } + // If not requested to seek to an absolute position, we need to + // confirm that the stream is currently at the position that we + // think it is. + if (whence != SEEK_SET + && stream->fPosition != stream->fSource->Position()) { + off_t position + = stream->fSource->Seek(stream->fPosition, SEEK_SET); + if (position != stream->fPosition) + return -1; + } + off_t position = stream->fSource->Seek(offset, whence); + TRACE_IO(" position: %lld\n", position); + if (position < 0) + return -1; + stream->fPosition = position; - TRACE_IO(" position: %lld\n", position); return position; }