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
This commit is contained in:
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* Copyright 2009, Stephan Aßmus <[email protected]>
|
||||
* All rights reserved. Distributed under the terms of the GNU L-GPL license.
|
||||
*/
|
||||
|
||||
#include "AVFormatWriter.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <new>
|
||||
|
||||
#include <AutoDeleter.h>
|
||||
#include <Autolock.h>
|
||||
#include <ByteOrder.h>
|
||||
#include <DataIO.h>
|
||||
#include <MediaDefs.h>
|
||||
#include <MediaFormats.h>
|
||||
|
||||
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<StreamCookie*>(_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;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2009, Stephan Aßmus <[email protected]>
|
||||
* All rights reserved. Distributed under the terms of the GNU L-GPL license.
|
||||
*/
|
||||
#ifndef AV_FORMAT_WRITER_H
|
||||
#define AV_FORMAT_WRITER_H
|
||||
|
||||
|
||||
#include <Locker.h>
|
||||
|
||||
#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
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2009 Stephan Aßmus <[email protected]>
|
||||
* 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);
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright 2009 Stephan Aßmus <[email protected]>
|
||||
* All rights reserved. Distributed under the terms of the MIT license.
|
||||
*/
|
||||
#ifndef MUXER_TABLE_H
|
||||
#define MUXER_TABLE_H
|
||||
|
||||
|
||||
#include <MediaDefs.h>
|
||||
|
||||
|
||||
extern const media_file_format gMuxerTable[];
|
||||
extern const size_t gMuxerCount;
|
||||
|
||||
|
||||
#endif // MUXER_TABLE_H
|
||||
Reference in New Issue
Block a user