diff --git a/src/add-ons/media/plugins/ffmpeg/AVFormatWriter.cpp b/src/add-ons/media/plugins/ffmpeg/AVFormatWriter.cpp index 7e8b53ecdb..e57ee2e09b 100644 --- a/src/add-ons/media/plugins/ffmpeg/AVFormatWriter.cpp +++ b/src/add-ons/media/plugins/ffmpeg/AVFormatWriter.cpp @@ -203,3 +203,52 @@ AVFormatWriter::WriteChunk(void* cookie, const void* chunkBuffer, } +// #pragma mark - + + +/*static*/ int +AVFormatWriter::_Write(void* cookie, const uint8* buffer, int bufferSize) +{ + TRACE_IO("AVFormatWriter::_Write(%p, %p, %d)\n", + cookie, buffer, bufferSize); + + AVFormatWriter* writer = reinterpret_cast(cookie); + + ssize_t written = writer->fTarget->Write(buffer, bufferSize); + + TRACE_IO(" written: %ld\n", written); + return (int)written; + +} + + +/*static*/ off_t +AVFormatWriter::_Seek(void* cookie, off_t offset, int whence) +{ + TRACE_IO("AVFormatWriter::_Seek(%p, %lld, %d)\n", + cookie, offset, whence); + + AVFormatWriter* writer = reinterpret_cast(cookie); + + BPositionIO* positionIO = dynamic_cast(writer->fTarget); + if (positionIO == NULL) + return -1; + + // Support for special file size retrieval API without seeking + // anywhere: + if (whence == AVSEEK_SIZE) { + off_t size; + if (positionIO->GetSize(&size) == B_OK) + return size; + return -1; + } + + off_t position = positionIO->Seek(offset, whence); + TRACE_IO(" position: %lld\n", position); + if (position < 0) + return -1; + + return position; +} + + diff --git a/src/add-ons/media/plugins/ffmpeg/AVFormatWriter.h b/src/add-ons/media/plugins/ffmpeg/AVFormatWriter.h index 923e8c14df..d54140f1fb 100644 --- a/src/add-ons/media/plugins/ffmpeg/AVFormatWriter.h +++ b/src/add-ons/media/plugins/ffmpeg/AVFormatWriter.h @@ -10,6 +10,10 @@ #include "WriterPlugin.h" +extern "C" { + #include "avformat.h" +} + class AVFormatWriter : public Writer { public: @@ -35,9 +39,17 @@ public: const void* chunkBuffer, size_t chunkSize, media_encode_info* encodeInfo); +private: + static int _Write(void* cookie, const uint8* buffer, + int bufferSize); + + static off_t _Seek(void* cookie, off_t offset, int whence); + private: class StreamCookie; + AVFormatContext* fContext; + StreamCookie** fStreams; BLocker fStreamLock; };