Moved creating and destroying of Reader and Decoder plugins into the PluginManager class.

Removed deferred initialization from BMediaDecoder. 


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21296 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Marcus Overhagen 2007-06-02 20:00:48 +00:00
parent 1518e4101b
commit 1d18292953
8 changed files with 235 additions and 255 deletions

View File

@ -48,19 +48,11 @@ class BMediaDecoder {
status_t AttachToDecoder();
BPrivate::media::Decoder *fDecoder;
int32 fDecoderID;
BPrivate::media::DecoderPlugin *fDecoderPlugin;
int32 fDecoderPluginID;
status_t fInitStatus;
bool fNeedsInit;
media_format * fInitFormat;
char * fInitInfo;
size_t fInitInfoSize;
/* fbc data and virtuals */
uint32 _reserved_BMediaDecoder_[26];
uint32 _reserved_BMediaDecoder_[33];
virtual status_t _Reserved_BMediaDecoder_0(int32 arg, ...);
virtual status_t _Reserved_BMediaDecoder_1(int32 arg, ...);
@ -93,8 +85,8 @@ class BMediaBufferDecoder : public BMediaDecoder {
protected:
virtual status_t GetNextChunk(const void **chunkData, size_t *chunkLen,
media_header *mh);
const void *buffer;
int32 buffer_size;
const void *fBuffer;
int32 fBufferSize;
};
#endif

View File

@ -39,7 +39,7 @@ public:
status_t GetNextChunk(const void **chunkBuffer, size_t *chunkSize,
media_header *mediaHeader);
void Setup(ChunkProvider *provider);
void SetChunkProvider(ChunkProvider *provider);
private:
ChunkProvider * fChunkProvider;
};

View File

@ -6,12 +6,6 @@
#include <TList.h>
#include <Locker.h>
status_t _CreateReader(Reader **reader, int32 *streamCount, media_file_format *mff, BDataIO *source);
status_t _CreateDecoder(Decoder **decoder, const media_format &format);
void _DestroyReader(Reader *reader);
void _DestroyDecoder(Decoder *decoder);
class PluginManager
{
@ -21,6 +15,15 @@ public:
MediaPlugin * GetPlugin(const entry_ref &ref);
void PutPlugin(MediaPlugin *plugin);
status_t CreateReader(Reader **reader, int32 *streamCount, media_file_format *mff, BDataIO *source);
void DestroyReader(Reader *reader);
status_t CreateDecoder(Decoder **decoder, const media_format &format);
status_t CreateDecoder(Decoder **decoder, const media_codec_info &mci);
status_t GetDecoderInfo(Decoder *decoder, media_codec_info *out_info) const;
void DestroyDecoder(Decoder *decoder);
private:
bool LoadPlugin(const entry_ref &ref, MediaPlugin **plugin, image_id *image);
@ -37,4 +40,6 @@ private:
BLocker *fLocker;
};
extern PluginManager _plugin_manager;
#endif

View File

@ -12,8 +12,8 @@
Decoder::Decoder()
: fChunkProvider(NULL)
{
fChunkProvider = 0;
}
@ -32,7 +32,7 @@ Decoder::GetNextChunk(const void **chunkBuffer, size_t *chunkSize,
void
Decoder::Setup(ChunkProvider *provider)
Decoder::SetChunkProvider(ChunkProvider *provider)
{
delete fChunkProvider;
fChunkProvider = provider;
@ -45,4 +45,3 @@ Decoder::Setup(ChunkProvider *provider)
DecoderPlugin::DecoderPlugin()
{
}

View File

@ -5,26 +5,17 @@
***********************************************************************/
#include <MediaDecoder.h>
#include <DecoderPlugin.h>
#include <new>
#include "PluginManager.h"
#include "DataExchange.h"
#include "debug.h"
extern PluginManager _plugin_manager;
/*************************************************************
* public BMediaDecoder
*************************************************************/
BMediaDecoder::BMediaDecoder()
: fDecoder(NULL),
fDecoderID(0),
fDecoderPlugin(NULL),
fDecoderPluginID(0),
fInitStatus(B_NO_INIT),
fNeedsInit(false),
fInitFormat(NULL),
fInitInfo(NULL),
fInitInfoSize(0)
fInitStatus(B_OK)
{
}
@ -33,33 +24,15 @@ BMediaDecoder::BMediaDecoder(const media_format *in_format,
const void *info,
size_t info_size)
: fDecoder(NULL),
fDecoderID(0),
fDecoderPlugin(NULL),
fDecoderPluginID(0),
fInitStatus(B_NO_INIT),
fNeedsInit(true),
fInitFormat(new media_format(*in_format)),
fInitInfo(NULL),
fInitInfoSize(0)
fInitStatus(B_OK)
{
if (info_size) {
fInitInfoSize = info_size;
fInitInfo = new char[info_size];
memcpy(fInitInfo, info, info_size);
}
SetTo(in_format, info, info_size);
}
BMediaDecoder::BMediaDecoder(const media_codec_info *mci)
: fDecoder(NULL),
fDecoderID(0),
fDecoderPlugin(NULL),
fDecoderPluginID(0),
fInitStatus(B_NO_INIT),
fNeedsInit(false),
fInitFormat(NULL),
fInitInfo(NULL),
fInitInfoSize(0)
fInitStatus(B_OK)
{
SetTo(mci);
}
@ -68,108 +41,70 @@ BMediaDecoder::BMediaDecoder(const media_codec_info *mci)
/* virtual */
BMediaDecoder::~BMediaDecoder()
{
delete fDecoder;
delete fInitFormat;
delete fInitInfo;
_plugin_manager.DestroyDecoder(fDecoder);
}
status_t
BMediaDecoder::InitCheck() const
{
if (fNeedsInit) {
// casting away const: yes this solution does suck
// it is necessary while decoders need to call GetNextChunk in Setup
const_cast<BMediaDecoder*>(this)->SetTo(fInitFormat, fInitInfo, fInitInfoSize);
}
return fInitStatus;
}
static DecoderPlugin *
GetDecoderPlugin(const media_format * format)
{
server_get_decoder_for_format_request request;
server_get_decoder_for_format_reply reply;
request.format = *format;
status_t result = QueryServer(SERVER_GET_DECODER_FOR_FORMAT, &request, sizeof(request), &reply, sizeof(reply));
if (result != B_OK) {
printf("BMediaDecoder::SetTo: can't get decoder for format\n");
return NULL;
}
MediaPlugin * media_plugin = _plugin_manager.GetPlugin(reply.ref);
if (!media_plugin) {
printf("BMediaDecoder::SetTo: GetPlugin failed\n");
return NULL;
}
DecoderPlugin * plugin = dynamic_cast<DecoderPlugin *>(media_plugin);
if (!plugin) {
printf("BMediaDecoder::SetTo: dynamic_cast failed\n");
return NULL;
}
return plugin;
}
// ask the server for a good decoder for the arguments
// GETS THE CODEC for in_format->type + in_format->u.x.encoding
status_t
BMediaDecoder::SetTo(const media_format *in_format,
const void *info,
size_t info_size)
{
fNeedsInit = false;
_plugin_manager.DestroyDecoder(fDecoder);
fDecoder = NULL;
status_t err = _plugin_manager.CreateDecoder(&fDecoder, *in_format);
if (err < B_OK)
goto fail;
err = AttachToDecoder();
if (err < B_OK)
goto fail;
err = SetInputFormat(in_format, info, info_size);
if (err < B_OK)
goto fail;
fInitStatus = B_OK;
return B_OK;
fail:
_plugin_manager.DestroyDecoder(fDecoder);
fDecoder = NULL;
fInitStatus = B_NO_INIT;
delete fDecoder;
DecoderPlugin * plugin = GetDecoderPlugin(in_format);
if (plugin == NULL) {
return fInitStatus = B_ERROR;
}
Decoder * decoder = plugin->NewDecoder(0);
if (decoder == NULL) {
return fInitStatus = B_ERROR;
}
fDecoder = decoder;
// fDecoderID = mci->sub_id;
if ((fInitStatus = AttachToDecoder()) != B_OK) {
return fInitStatus;
}
fInitStatus = SetInputFormat(in_format,info,info_size);
return fInitStatus;
return err;
}
// ask the server for the id'th plugin
static DecoderPlugin *
GetDecoderPlugin(int32 id)
{
if (id == 0) {
return NULL;
}
UNIMPLEMENTED();
return NULL;
}
// ask the server for a good decoder for the arguments
// GETS THE CODEC for mci->id, mci->sub_id
// fails if the mci->id = 0
status_t
BMediaDecoder::SetTo(const media_codec_info *mci)
{
_plugin_manager.DestroyDecoder(fDecoder);
fDecoder = NULL;
status_t err = _plugin_manager.CreateDecoder(&fDecoder, *mci);
if (err < B_OK)
goto fail;
err = AttachToDecoder();
if (err < B_OK)
goto fail;
fInitStatus = B_OK;
return B_OK;
fail:
_plugin_manager.DestroyDecoder(fDecoder);
fDecoder = NULL;
fInitStatus = B_NO_INIT;
delete fDecoder;
DecoderPlugin * plugin = GetDecoderPlugin(mci->id);
if (plugin == NULL) {
return fInitStatus = B_ERROR;
}
Decoder * decoder = plugin->NewDecoder(0);
if (decoder == NULL) {
return fInitStatus = B_ERROR;
}
fDecoder = decoder;
fDecoderID = mci->sub_id;
if ((fInitStatus = AttachToDecoder()) != B_OK) {
return fInitStatus;
}
return fInitStatus;
return err;
}
@ -186,12 +121,11 @@ BMediaDecoder::SetInputFormat(const media_format *in_format,
const void *in_info,
size_t in_size)
{
if (InitCheck() != B_OK) {
return fInitStatus;
}
printf("DISCARDING FORMAT %s\n",__PRETTY_FUNCTION__);
if (!fDecoder)
return B_NO_INIT;
media_format format = *in_format;
return fDecoder->Setup(&format,in_info,in_size);
return fDecoder->Setup(&format, in_info, in_size);
}
@ -204,9 +138,9 @@ BMediaDecoder::SetInputFormat(const media_format *in_format,
status_t
BMediaDecoder::SetOutputFormat(media_format *output_format)
{
if (InitCheck() != B_OK) {
return fInitStatus;
}
if (!fDecoder)
return B_NO_INIT;
return fDecoder->NegotiateOutputFormat(output_format);
}
@ -230,23 +164,20 @@ BMediaDecoder::Decode(void *out_buffer,
media_header *out_mh,
media_decode_info *info)
{
if (InitCheck() != B_OK) {
return fInitStatus;
}
return fDecoder->Decode(out_buffer,out_frameCount,out_mh,info);
if (!fDecoder)
return B_NO_INIT;
return fDecoder->Decode(out_buffer, out_frameCount, out_mh, info);
}
status_t
BMediaDecoder::GetDecoderInfo(media_codec_info *out_info) const
{
if (InitCheck() != B_OK) {
return fInitStatus;
}
fDecoder->GetCodecInfo(out_info);
out_info->id = fDecoderPluginID;
out_info->sub_id = fDecoderID;
return B_OK;
if (!fDecoder)
return B_NO_INIT;
return _plugin_manager.GetDecoderInfo(fDecoder, out_info);
}
@ -279,11 +210,12 @@ BMediaDecoder::AttachToDecoder()
media_header *mediaHeader) {
return fDecoder->GetNextChunk(chunkBuffer, chunkSize, mediaHeader);
}
} * provider = new MediaDecoderChunkProvider(this);
if (provider == NULL) {
} * provider = new(std::nothrow) MediaDecoderChunkProvider(this);
if (!provider)
return B_NO_MEMORY;
}
fDecoder->Setup(provider);
fDecoder->SetChunkProvider(provider);
return B_OK;
}
@ -310,25 +242,25 @@ status_t BMediaDecoder::_Reserved_BMediaDecoder_15(int32 arg, ...) { return B_ER
*************************************************************/
BMediaBufferDecoder::BMediaBufferDecoder()
: BMediaDecoder()
: BMediaDecoder()
, fBufferSize(0)
{
buffer_size = 0;
}
BMediaBufferDecoder::BMediaBufferDecoder(const media_format *in_format,
const void *info,
size_t info_size)
: BMediaDecoder(in_format,info,info_size)
: BMediaDecoder(in_format, info, info_size)
, fBufferSize(0)
{
buffer_size = 0;
}
BMediaBufferDecoder::BMediaBufferDecoder(const media_codec_info *mci)
: BMediaDecoder(mci)
: BMediaDecoder(mci)
, fBufferSize(0)
{
buffer_size = 0;
}
@ -340,9 +272,9 @@ BMediaBufferDecoder::DecodeBuffer(const void *input_buffer,
media_header *out_mh,
media_decode_info *info)
{
buffer = input_buffer;
buffer_size = input_size;
return Decode(out_buffer,out_frameCount,out_mh,info);
fBuffer = input_buffer;
fBufferSize = input_size;
return Decode(out_buffer, out_frameCount, out_mh,info);
}
@ -352,14 +284,15 @@ BMediaBufferDecoder::DecodeBuffer(const void *input_buffer,
/* virtual */
status_t
BMediaBufferDecoder::GetNextChunk(const void **chunkData, size_t *chunkLen,
BMediaBufferDecoder::GetNextChunk(const void **chunkData,
size_t *chunkLen,
media_header *mh)
{
if (!buffer_size) {
if (!fBufferSize)
return B_LAST_BUFFER_ERROR;
}
*chunkData = buffer;
*chunkLen = buffer_size;
buffer_size = 0;
*chunkData = fBuffer;
*chunkLen = fBufferSize;
fBufferSize = 0;
return B_OK;
}

View File

@ -1,3 +1,7 @@
/*
** Copyright 2004-2007, Marcus Overhagen. All rights reserved.
** Distributed under the terms of the MIT License.
*/
#include "MediaExtractor.h"
#include "PluginManager.h"
#include "ChunkCache.h"
@ -7,6 +11,7 @@
#include <stdio.h>
#include <string.h>
#include <new>
// should be 0, to disable the chunk cache set it to 1
#define DISABLE_CHUNK_CACHE 0
@ -20,10 +25,10 @@ MediaExtractor::MediaExtractor(BDataIO *source, int32 flags)
fExtractorWaitSem = -1;
fTerminateExtractor = false;
fErr = _CreateReader(&fReader, &fStreamCount, &fMff, source);
fErr = _plugin_manager.CreateReader(&fReader, &fStreamCount, &fMff, source);
if (fErr) {
fStreamCount = 0;
fReader = 0;
fReader = NULL;
return;
}
@ -93,8 +98,7 @@ MediaExtractor::~MediaExtractor()
delete fStreamInfo[i].chunkCache;
}
if (fReader)
_DestroyReader(fReader);
_plugin_manager.DestroyReader(fReader);
delete [] fStreamInfo;
// fSource is owned by the BMediaFile
@ -227,10 +231,11 @@ public:
status_t
MediaExtractor::CreateDecoder(int32 stream, Decoder **decoder, media_codec_info *mci)
MediaExtractor::CreateDecoder(int32 stream, Decoder **out_decoder, media_codec_info *mci)
{
CALLED();
status_t res;
Decoder *decoder;
res = fStreamInfo[stream].status;
if (res != B_OK) {
@ -238,23 +243,36 @@ MediaExtractor::CreateDecoder(int32 stream, Decoder **decoder, media_codec_info
return res;
}
res = _CreateDecoder(decoder, fStreamInfo[stream].encodedFormat);
res = _plugin_manager.CreateDecoder(&decoder, fStreamInfo[stream].encodedFormat);
if (res != B_OK) {
printf("MediaExtractor::CreateDecoder failed for stream %ld\n", stream);
printf("MediaExtractor::CreateDecoder _plugin_manager.CreateDecoder failed for stream %ld\n", stream);
return res;
}
(*decoder)->Setup(new MediaExtractorChunkProvider(this, stream));
ChunkProvider *chunkProvider = new(std::nothrow) MediaExtractorChunkProvider(this, stream);
if (!chunkProvider) {
_plugin_manager.DestroyDecoder(decoder);
printf("MediaExtractor::CreateDecoder can't create chunk provider for stream %ld\n", stream);
return B_NO_MEMORY;
}
decoder->SetChunkProvider(chunkProvider);
res = (*decoder)->Setup(&fStreamInfo[stream].encodedFormat, fStreamInfo[stream].infoBuffer , fStreamInfo[stream].infoBufferSize);
res = decoder->Setup(&fStreamInfo[stream].encodedFormat, fStreamInfo[stream].infoBuffer, fStreamInfo[stream].infoBufferSize);
if (res != B_OK) {
printf("MediaExtractor::CreateDecoder Setup failed for stream %ld: %ld (%s)\n",
stream, res, strerror(res));
_plugin_manager.DestroyDecoder(decoder);
printf("MediaExtractor::CreateDecoder Setup failed for stream %ld: %ld (%s)\n", stream, res, strerror(res));
return res;
}
(*decoder)->GetCodecInfo(mci);
res = _plugin_manager.GetDecoderInfo(decoder, mci);
if (res != B_OK) {
_plugin_manager.DestroyDecoder(decoder);
printf("MediaExtractor::CreateDecoder GetCodecInfo failed for stream %ld: %ld (%s)\n", stream, res, strerror(res));
return res;
}
*out_decoder = decoder;
return B_OK;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002-2004, Marcus Overhagen <marcus@overhagen.de>
* Copyright (c) 2002-2007, Marcus Overhagen <marcus@overhagen.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@ -27,9 +27,9 @@
#include <Roster.h>
#include <string.h>
#include <stdlib.h>
#include <new>
#include "MediaExtractor.h"
#include "PluginManager.h"
#include "ReaderPlugin.h"
#include "debug.h"
#define CONVERT_TO_INT32 0 // XXX test! this triggers a few bugs!
@ -71,10 +71,8 @@ private:
BMediaTrack::~BMediaTrack()
{
CALLED();
if (fRawDecoder)
_DestroyDecoder(fRawDecoder);
if (fDecoder)
_DestroyDecoder(fDecoder);
_plugin_manager.DestroyDecoder(fRawDecoder);
_plugin_manager.DestroyDecoder(fDecoder);
}
/*************************************************************
@ -140,10 +138,8 @@ BMediaTrack::DecodedFormat(media_format *inout_format, uint32 flags)
if (!fExtractor || !fDecoder)
return B_NO_INIT;
if (fRawDecoder) {
_DestroyDecoder(fRawDecoder);
fRawDecoder = 0;
}
_plugin_manager.DestroyDecoder(fRawDecoder);
fRawDecoder = 0;
char s[200];
@ -641,7 +637,8 @@ BMediaTrack::BMediaTrack(BPrivate::media::MediaExtractor *extractor,
{
CALLED();
fWorkaroundFlags = 0;
fRawDecoder = 0;
fDecoder = NULL;
fRawDecoder = NULL;
fExtractor = extractor;
fStream = stream;
fErr = B_OK;
@ -712,24 +709,32 @@ BMediaTrack::SetupFormatTranslation(const media_format &from, media_format *to)
{
char s[200];
status_t res;
_plugin_manager.DestroyDecoder(fRawDecoder);
fRawDecoder = NULL;
string_for_format(from, s, sizeof(s));
printf("BMediaTrack::SetupFormatTranslation: from: %s\n", s);
res = _CreateDecoder(&fRawDecoder, from);
res = _plugin_manager.CreateDecoder(&fRawDecoder, from);
if (res != B_OK) {
printf("BMediaTrack::SetupFormatTranslation: _CreateDecoder failed\n");
printf("BMediaTrack::SetupFormatTranslation: CreateDecoder failed\n");
return false;
}
// XXX video?
int buffer_size = from.u.raw_audio.buffer_size;
int frame_size = (from.u.raw_audio.format & 15) * from.u.raw_audio.channel_count;
media_format notconstFrom = from;
fRawDecoder->Setup(new RawDecoderChunkProvider(fDecoder, buffer_size, frame_size));
ChunkProvider *chunkProvider = new(std::nothrow) RawDecoderChunkProvider(fDecoder, buffer_size, frame_size);
if (!chunkProvider) {
printf("BMediaTrack::SetupFormatTranslation: can't create chunk provider\n");
goto error;
}
fRawDecoder->SetChunkProvider(chunkProvider);
media_format from_temp = from;
res = fRawDecoder->Setup(&from_temp, 0, 0);
res = fRawDecoder->Setup(&notconstFrom, 0, 0);
if (res != B_OK) {
printf("BMediaTrack::SetupFormatTranslation: Setup failed\n");
goto error;
@ -750,8 +755,8 @@ BMediaTrack::SetupFormatTranslation(const media_format &from, media_format *to)
return true;
error:
_DestroyDecoder(fRawDecoder);
fRawDecoder = 0;
_plugin_manager.DestroyDecoder(fRawDecoder);
fRawDecoder = NULL;
return false;
}

View File

@ -1,5 +1,5 @@
/*
** Copyright 2004, Marcus Overhagen. All rights reserved.
** Copyright 2004-2007, Marcus Overhagen. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
*/
@ -12,46 +12,49 @@
#include "DataExchange.h"
#include "debug.h"
PluginManager _plugin_manager;
status_t
_CreateReader(Reader **reader, int32 *streamCount, media_file_format *mff, BDataIO *source)
PluginManager::CreateReader(Reader **reader, int32 *streamCount, media_file_format *mff, BDataIO *source)
{
TRACE("_CreateReader enter\n");
TRACE("PluginManager::CreateReader enter\n");
BPositionIO *seekable_source = dynamic_cast<BPositionIO *>(source);
if (seekable_source == 0) {
printf("_CreateReader: non-seekable sources not supported yet\n");
printf("PluginManager::CreateReader: non-seekable sources not supported yet\n");
return B_ERROR;
}
// get list of available readers from, the server
// get list of available readers from the server
server_get_readers_request request;
server_get_readers_reply reply;
if (B_OK != QueryServer(SERVER_GET_READERS, &request, sizeof(request), &reply, sizeof(reply))) {
printf("_CreateReader: can't get list of readers\n");
printf("PluginManager::CreateReader: can't get list of readers\n");
return B_ERROR;
}
// try each reader by calling it's Sniff function...
for (int32 i = 0; i < reply.count; i++) {
entry_ref ref = reply.ref[i];
MediaPlugin *plugin = _plugin_manager.GetPlugin(ref);
MediaPlugin *plugin = GetPlugin(ref);
if (!plugin) {
printf("_CreateReader: GetPlugin failed\n");
printf("PluginManager::CreateReader: GetPlugin failed\n");
return B_ERROR;
}
ReaderPlugin *readerPlugin = dynamic_cast<ReaderPlugin *>(plugin);
if (!readerPlugin) {
printf("_CreateReader: dynamic_cast failed\n");
printf("PluginManager::CreateReader: dynamic_cast failed\n");
PutPlugin(plugin);
return B_ERROR;
}
*reader = readerPlugin->NewReader();
if (! *reader) {
printf("_CreateReader: NewReader failed\n");
printf("PluginManager::CreateReader: NewReader failed\n");
PutPlugin(plugin);
return B_ERROR;
}
@ -59,69 +62,94 @@ _CreateReader(Reader **reader, int32 *streamCount, media_file_format *mff, BData
(*reader)->Setup(seekable_source);
if (B_OK == (*reader)->Sniff(streamCount)) {
TRACE("_CreateReader: Sniff success (%ld stream(s))\n", *streamCount);
TRACE("PluginManager::CreateReader: Sniff success (%ld stream(s))\n", *streamCount);
(*reader)->GetFileFormatInfo(mff);
return B_OK;
}
// _DestroyReader(*reader);
delete *reader;
_plugin_manager.PutPlugin(plugin);
PutPlugin(plugin);
}
TRACE("_CreateReader leave\n");
TRACE("PluginManager::CreateReader leave\n");
return B_MEDIA_NO_HANDLER;
}
status_t
_CreateDecoder(Decoder **_decoder, const media_format &format)
{
TRACE("_CreateDecoder enter\n");
// get decoder for this format from the server
server_get_decoder_for_format_request request;
server_get_decoder_for_format_reply reply;
request.format = format;
if (B_OK != QueryServer(SERVER_GET_DECODER_FOR_FORMAT, &request, sizeof(request), &reply, sizeof(reply))) {
printf("_CreateDecoder: can't get decoder for format\n");
return B_ERROR;
}
MediaPlugin *plugin = _plugin_manager.GetPlugin(reply.ref);
if (!plugin) {
printf("_CreateDecoder: GetPlugin failed\n");
return B_ERROR;
}
DecoderPlugin *decoderPlugin = dynamic_cast<DecoderPlugin *>(plugin);
if (!decoderPlugin) {
printf("_CreateDecoder: dynamic_cast failed\n");
return B_ERROR;
}
*_decoder = decoderPlugin->NewDecoder(0);
if (*_decoder == NULL) {
printf("_CreateDecoder: NewDecoder() failed\n");
return B_ERROR;
}
TRACE("_CreateDecoder leave\n");
return B_OK;
}
void
_DestroyReader(Reader *reader)
PluginManager::DestroyReader(Reader *reader)
{
// ToDo: must call put plugin
delete reader;
}
status_t
PluginManager::CreateDecoder(Decoder **_decoder, const media_format &format)
{
TRACE("PluginManager::CreateDecoder enter\n");
// get decoder for this format from the server
server_get_decoder_for_format_request request;
server_get_decoder_for_format_reply reply;
request.format = format;
if (B_OK != QueryServer(SERVER_GET_DECODER_FOR_FORMAT, &request, sizeof(request), &reply, sizeof(reply))) {
printf("PluginManager::CreateDecoder: can't get decoder for format\n");
return B_ERROR;
}
MediaPlugin *plugin = GetPlugin(reply.ref);
if (!plugin) {
printf("PluginManager::CreateDecoder: GetPlugin failed\n");
return B_ERROR;
}
DecoderPlugin *decoderPlugin = dynamic_cast<DecoderPlugin *>(plugin);
if (!decoderPlugin) {
printf("PluginManager::CreateDecoder: dynamic_cast failed\n");
_plugin_manager.PutPlugin(plugin);
return B_ERROR;
}
*_decoder = decoderPlugin->NewDecoder(0);
if (*_decoder == NULL) {
printf("PluginManager::CreateDecoder: NewDecoder() failed\n");
_plugin_manager.PutPlugin(plugin);
return B_ERROR;
}
TRACE("PluginManager::CreateDecoder leave\n");
return B_OK;
}
status_t
PluginManager::CreateDecoder(Decoder **decoder, const media_codec_info &mci)
{
// TODO
debugger("not implemented");
return B_ERROR;
}
status_t
PluginManager::GetDecoderInfo(Decoder *decoder, media_codec_info *out_info) const
{
if (!decoder)
return B_BAD_VALUE;
decoder->GetCodecInfo(out_info);
// TODO:
// out_info->id =
// out_info->sub_id =
return B_OK;
}
void
_DestroyDecoder(Decoder *decoder)
PluginManager::DestroyDecoder(Decoder *decoder)
{
// ToDo: must call put plugin
delete decoder;
@ -240,8 +268,8 @@ PluginManager::LoadPlugin(const entry_ref &ref, MediaPlugin **plugin, image_id *
MediaPlugin *pl;
pl = (*instantiate_plugin_func)();
if (pl == 0) {
printf("PluginManager: Error, LoadPlugin instantiate_plugin in %s returned 0\n", p.Path());
if (pl == NULL) {
printf("PluginManager: Error, LoadPlugin instantiate_plugin in %s returned NULL\n", p.Path());
unload_add_on(id);
return false;
}