From 6ac391b3eaaeb2cd188ad7e47b3b9f74299857cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Thu, 30 Jul 2009 00:17:53 +0000 Subject: [PATCH] Stubbed out Writer and WriterPlugin implementation. So far, Clockwerk shows "AVI (Audio Video Interleave)" in the available output formats popup... :-) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31956 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../media/plugins/ffmpeg/AVFormatWriter.cpp | 196 ++++++++++++++++++ .../media/plugins/ffmpeg/AVFormatWriter.h | 43 ++++ .../media/plugins/ffmpeg/FFmpegPlugin.cpp | 25 ++- .../media/plugins/ffmpeg/FFmpegPlugin.h | 13 +- src/add-ons/media/plugins/ffmpeg/Jamfile | 2 + .../media/plugins/ffmpeg/MuxerTable.cpp | 30 +++ src/add-ons/media/plugins/ffmpeg/MuxerTable.h | 16 ++ 7 files changed, 319 insertions(+), 6 deletions(-) create mode 100644 src/add-ons/media/plugins/ffmpeg/AVFormatWriter.cpp create mode 100644 src/add-ons/media/plugins/ffmpeg/AVFormatWriter.h create mode 100644 src/add-ons/media/plugins/ffmpeg/MuxerTable.cpp create mode 100644 src/add-ons/media/plugins/ffmpeg/MuxerTable.h diff --git a/src/add-ons/media/plugins/ffmpeg/AVFormatWriter.cpp b/src/add-ons/media/plugins/ffmpeg/AVFormatWriter.cpp new file mode 100644 index 0000000000..4292e0dc54 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/AVFormatWriter.cpp @@ -0,0 +1,196 @@ +/* + * Copyright 2009, Stephan Aßmus + * All rights reserved. Distributed under the terms of the GNU L-GPL license. + */ + +#include "AVFormatWriter.h" + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +extern "C" { + #include "avformat.h" +} + +#include "DemuxerTable.h" +#include "gfx_util.h" + + +#define TRACE_AVFORMAT_WRITER +#ifdef TRACE_AVFORMAT_WRITER +# define TRACE printf +# define TRACE_IO(a...) +# define TRACE_PACKET(a...) +#else +# define TRACE(a...) +# define TRACE_IO(a...) +# define TRACE_PACKET(a...) +#endif + +#define ERROR(a...) fprintf(stderr, a) + + +// #pragma mark - AVFormatWriter::StreamCookie + + +class AVFormatWriter::StreamCookie { +public: + StreamCookie(BPositionIO* target, + BLocker* streamLock); + virtual ~StreamCookie(); + +private: + BPositionIO* fTarget; + off_t fPosition; + // Since different threads may read from the source, + // we need to protect the file position and I/O by a lock. + BLocker* fStreamLock; +}; + + + +AVFormatWriter::StreamCookie::StreamCookie(BPositionIO* target, + BLocker* streamLock) + : + fTarget(target), + fPosition(0), + fStreamLock(streamLock) +{ +} + + +AVFormatWriter::StreamCookie::~StreamCookie() +{ +} + + +// #pragma mark - AVFormatWriter + + +AVFormatWriter::AVFormatWriter() + : + fStreams(NULL), + fStreamLock("stream lock") +{ + TRACE("AVFormatWriter::AVFormatWriter\n"); +} + + +AVFormatWriter::~AVFormatWriter() +{ + TRACE("AVFormatWriter::~AVFormatWriter\n"); + if (fStreams != NULL) { + delete fStreams[0]; + delete[] fStreams; + } +} + + +// #pragma mark - + + +status_t +AVFormatWriter::SetCopyright(const char* copyright) +{ + TRACE("AVFormatWriter::SetCopyright(%s)\n", copyright); + + return B_NOT_SUPPORTED; +} + + +status_t +AVFormatWriter::CommitHeader() +{ + TRACE("AVFormatWriter::CommitHeader\n"); + + return B_NOT_SUPPORTED; +} + + +status_t +AVFormatWriter::Flush() +{ + TRACE("AVFormatWriter::Flush\n"); + + return B_NOT_SUPPORTED; +} + + +status_t +AVFormatWriter::Close() +{ + TRACE("AVFormatWriter::Close\n"); + + return B_NOT_SUPPORTED; +} + + +status_t +AVFormatWriter::AllocateCookie(void** _cookie) +{ + TRACE("AVFormatWriter::AllocateCookie()\n"); + + BAutolock _(fStreamLock); + + if (fStreams == NULL) + return B_NO_INIT; + + if (_cookie == NULL) + return B_BAD_VALUE; + + return B_NOT_SUPPORTED; +} + + +status_t +AVFormatWriter::FreeCookie(void* _cookie) +{ + BAutolock _(fStreamLock); + + StreamCookie* cookie = reinterpret_cast(_cookie); + + if (cookie != NULL) { +// if (fStreams != NULL) +// fStreams[cookie->VirtualIndex()] = NULL; + delete cookie; + } + + return B_OK; +} + + +// #pragma mark - + + +status_t +AVFormatWriter::AddTrackInfo(void* cookie, uint32 code, + const void* data, size_t size, uint32 flags) +{ + TRACE("AVFormatWriter::AddTrackInfo(%lu, %p, %ld, %lu)\n", + code, data, size, flags); + + return B_NOT_SUPPORTED; +} + + +status_t +AVFormatWriter::WriteNextChunk(void* cookie, const void* chunkBuffer, + size_t chunkSize, uint32 flags) +{ + TRACE("AVFormatWriter::WriteNextChunk(%p, %ld, %lu)\n", + chunkBuffer, chunkSize, flags); + + return B_NOT_SUPPORTED; +} + + diff --git a/src/add-ons/media/plugins/ffmpeg/AVFormatWriter.h b/src/add-ons/media/plugins/ffmpeg/AVFormatWriter.h new file mode 100644 index 0000000000..e089bc43eb --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/AVFormatWriter.h @@ -0,0 +1,43 @@ +/* + * Copyright 2009, Stephan Aßmus + * All rights reserved. Distributed under the terms of the GNU L-GPL license. + */ +#ifndef AV_FORMAT_WRITER_H +#define AV_FORMAT_WRITER_H + + +#include + +#include "WriterPlugin.h" + + +class AVFormatWriter : public Writer { +public: + AVFormatWriter(); + ~AVFormatWriter(); + + virtual status_t SetCopyright(const char* copyright); + virtual status_t CommitHeader(); + virtual status_t Flush(); + virtual status_t Close(); + + virtual status_t AllocateCookie(void** cookie); + virtual status_t FreeCookie(void* cookie); + + virtual status_t AddTrackInfo(void* cookie, uint32 code, + const void* data, size_t size, + uint32 flags = 0); + + virtual status_t WriteNextChunk(void* cookie, + const void* chunkBuffer, size_t chunkSize, + uint32 flags); + +private: + class StreamCookie; + + StreamCookie** fStreams; + BLocker fStreamLock; +}; + + +#endif // AV_FORMAT_WRITER_H diff --git a/src/add-ons/media/plugins/ffmpeg/FFmpegPlugin.cpp b/src/add-ons/media/plugins/ffmpeg/FFmpegPlugin.cpp index 6f7f6dd027..09a8a16de7 100644 --- a/src/add-ons/media/plugins/ffmpeg/FFmpegPlugin.cpp +++ b/src/add-ons/media/plugins/ffmpeg/FFmpegPlugin.cpp @@ -22,7 +22,9 @@ extern "C" { #include "AVCodecDecoder.h" #include "AVFormatReader.h" +#include "AVFormatWriter.h" #include "CodecTable.h" +#include "MuxerTable.h" FFmpegPlugin::GlobalInitilizer::GlobalInitilizer() @@ -62,7 +64,7 @@ FFmpegPlugin::NewReader() status_t -FFmpegPlugin::GetSupportedFormats(media_format** formats, size_t* count) +FFmpegPlugin::GetSupportedFormats(media_format** _formats, size_t* _count) { BMediaFormats mediaFormats; if (mediaFormats.InitCheck() != B_OK) @@ -104,8 +106,25 @@ FFmpegPlugin::GetSupportedFormats(media_format** formats, size_t* count) gAVCodecFormats[i] = format; } - *formats = gAVCodecFormats; - *count = gCodecCount; + *_formats = gAVCodecFormats; + *_count = gCodecCount; + return B_OK; +} + + +Writer* +FFmpegPlugin::NewWriter() +{ + return new(std::nothrow) AVFormatWriter(); +} + + +status_t +FFmpegPlugin::GetSupportedFileFormats(const media_file_format** _fileFormats, + size_t* _count) +{ + *_fileFormats = gMuxerTable; + *_count = gMuxerCount; return B_OK; } diff --git a/src/add-ons/media/plugins/ffmpeg/FFmpegPlugin.h b/src/add-ons/media/plugins/ffmpeg/FFmpegPlugin.h index 622b4a205c..d205dbcbb0 100644 --- a/src/add-ons/media/plugins/ffmpeg/FFmpegPlugin.h +++ b/src/add-ons/media/plugins/ffmpeg/FFmpegPlugin.h @@ -16,14 +16,21 @@ #include "DecoderPlugin.h" #include "ReaderPlugin.h" +#include "WriterPlugin.h" -class FFmpegPlugin : public ReaderPlugin, public DecoderPlugin { +class FFmpegPlugin : public ReaderPlugin, public DecoderPlugin, + public WriterPlugin { public: virtual Reader* NewReader(); virtual Decoder* NewDecoder(uint index); - virtual status_t GetSupportedFormats(media_format** formats, - size_t* count); + virtual status_t GetSupportedFormats(media_format** _formats, + size_t* _count); + + virtual Writer* NewWriter(); + virtual status_t GetSupportedFileFormats( + const media_file_format** _fileFormats, + size_t* _count); private: class GlobalInitilizer { diff --git a/src/add-ons/media/plugins/ffmpeg/Jamfile b/src/add-ons/media/plugins/ffmpeg/Jamfile index 90f2c4e401..38caf33f38 100644 --- a/src/add-ons/media/plugins/ffmpeg/Jamfile +++ b/src/add-ons/media/plugins/ffmpeg/Jamfile @@ -12,9 +12,11 @@ SubDirHdrs [ FDirName $(SUBDIR) libswscale ] ; Addon ffmpeg : AVCodecDecoder.cpp AVFormatReader.cpp + AVFormatWriter.cpp CodecTable.cpp DemuxerTable.cpp FFmpegPlugin.cpp + MuxerTable.cpp gfx_conv_c.cpp gfx_conv_c_lookup.cpp diff --git a/src/add-ons/media/plugins/ffmpeg/MuxerTable.cpp b/src/add-ons/media/plugins/ffmpeg/MuxerTable.cpp new file mode 100644 index 0000000000..e3446f8546 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/MuxerTable.cpp @@ -0,0 +1,30 @@ +/* + * Copyright 2009 Stephan Aßmus + * All rights reserved. Distributed under the terms of the MIT license. + */ + + +#include "MuxerTable.h" + + +const media_file_format gMuxerTable[] = { + { + media_file_format::B_WRITABLE + | media_file_format::B_KNOWS_RAW_VIDEO + | media_file_format::B_KNOWS_RAW_AUDIO + | media_file_format::B_KNOWS_ENCODED_VIDEO + | media_file_format::B_KNOWS_ENCODED_AUDIO, + { 0 }, + B_AVI_FORMAT_FAMILY, + 100, + { 0 }, + "video/x-msvideo", + "AVI (Audio Video Interleaved)", + "AVI", + "avi", + { 0 } + }, +}; + +const size_t gMuxerCount = sizeof(gMuxerTable) / sizeof(media_file_format); + diff --git a/src/add-ons/media/plugins/ffmpeg/MuxerTable.h b/src/add-ons/media/plugins/ffmpeg/MuxerTable.h new file mode 100644 index 0000000000..d0c7b7b63e --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/MuxerTable.h @@ -0,0 +1,16 @@ +/* + * Copyright 2009 Stephan Aßmus + * All rights reserved. Distributed under the terms of the MIT license. + */ +#ifndef MUXER_TABLE_H +#define MUXER_TABLE_H + + +#include + + +extern const media_file_format gMuxerTable[]; +extern const size_t gMuxerCount; + + +#endif // MUXER_TABLE_H