preliminary partial MediaDecoder implementation

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6147 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
shatty
2004-01-19 19:10:18 +00:00
parent ceb9cf7abc
commit a498eb5fda
+87 -39
View File
@@ -5,8 +5,12 @@
***********************************************************************/ ***********************************************************************/
#include <MediaDecoder.h> #include <MediaDecoder.h>
#include <DecoderPlugin.h> #include <DecoderPlugin.h>
#include "PluginManager.h"
#include "DataExchange.h"
#include "debug.h" #include "debug.h"
static PluginManager _plugin_manager;
/************************************************************* /*************************************************************
* public BMediaDecoder * public BMediaDecoder
*************************************************************/ *************************************************************/
@@ -47,13 +51,27 @@ BMediaDecoder::InitCheck() const
return fInitStatus; return fInitStatus;
} }
DecoderPlugin * GetDecoderPlugin(int32 id) static DecoderPlugin * GetDecoderPlugin(const media_format * format)
{ {
UNIMPLEMENTED(); server_get_decoder_for_format_request request;
// if our decoder plugin area id is not valid, server_get_decoder_for_format_reply reply;
// ask the server for a new one. request.format = *format;
// retrieve the id'th plugin here. status_t result = QueryServer(SERVER_GET_DECODER_FOR_FORMAT, &request, sizeof(request), &reply, sizeof(reply));
return NULL; 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 // ask the server for a good decoder for the arguments
@@ -63,8 +81,38 @@ BMediaDecoder::SetTo(const media_format *in_format,
const void *info, const void *info,
size_t info_size) size_t info_size)
{ {
status_t result;
fInitStatus = B_NO_INIT;
delete fDecoder;
DecoderPlugin * plugin = GetDecoderPlugin(in_format);
if (plugin == NULL) {
return fInitStatus = B_ERROR;
}
Decoder * decoder = plugin->NewDecoder();
if (decoder == NULL) {
return fInitStatus = B_ERROR;
}
fDecoder = decoder;
// fDecoderID = mci->sub_id;
result = SetInputFormat(in_format,info,info_size);
if (result != B_OK) {
return fInitStatus = result;
}
result = AttachToDecoder();
if (result != B_OK) {
return fInitStatus = result;
}
return fInitStatus = B_OK;
}
// ask the server for the id'th plugin
static DecoderPlugin * GetDecoderPlugin(int32 id)
{
if (id == 0) {
return NULL;
}
UNIMPLEMENTED(); UNIMPLEMENTED();
return fInitStatus = B_NO_INIT; return NULL;
} }
// ask the server for a good decoder for the arguments // ask the server for a good decoder for the arguments
@@ -73,37 +121,23 @@ BMediaDecoder::SetTo(const media_format *in_format,
status_t status_t
BMediaDecoder::SetTo(const media_codec_info *mci) BMediaDecoder::SetTo(const media_codec_info *mci)
{ {
class MediaDecoderChunkProvider : public ChunkProvider { status_t result;
private: fInitStatus = B_NO_INIT;
BMediaDecoder * fDecoder; delete fDecoder;
public:
MediaDecoderChunkProvider(BMediaDecoder * decoder) {
fDecoder = decoder;
}
virtual status_t GetNextChunk(void **chunkBuffer, int32 *chunkSize,
media_header *mediaHeader) {
const void ** buffer = const_cast<const void**>(chunkBuffer);
size_t * size = reinterpret_cast<size_t*>(chunkSize);
return fDecoder->GetNextChunk(buffer,size,mediaHeader);
}
} * provider = new MediaDecoderChunkProvider(this);
if (provider == NULL) {
return fInitStatus = B_NO_MEMORY;
}
DecoderPlugin * plugin = GetDecoderPlugin(mci->id); DecoderPlugin * plugin = GetDecoderPlugin(mci->id);
if (plugin == NULL) { if (plugin == NULL) {
return fInitStatus = B_BAD_VALUE; return fInitStatus = B_ERROR;
} }
Decoder * decoder = plugin->NewDecoder(); Decoder * decoder = plugin->NewDecoder();
if (decoder == NULL) { if (decoder == NULL) {
return fInitStatus = B_ERROR; return fInitStatus = B_ERROR;
} }
decoder->Setup(provider);
delete fDecoder;
fDecoderPluginID = mci->id;
fDecoderPlugin = plugin;
fDecoderID = mci->sub_id;
fDecoder = decoder; fDecoder = decoder;
fDecoderID = mci->sub_id;
result = AttachToDecoder();
if (result != B_OK) {
return fInitStatus = result;
}
return fInitStatus = B_OK; return fInitStatus = B_OK;
} }
@@ -121,6 +155,7 @@ BMediaDecoder::SetInputFormat(const media_format *in_format,
if (fInitStatus != B_OK) { if (fInitStatus != B_OK) {
return fInitStatus; return fInitStatus;
} }
printf("DISCARDING FORMAT %s\n",__PRETTY_FUNCTION__);
media_format format = *in_format; media_format format = *in_format;
return fDecoder->Setup(&format,in_info,in_size); return fDecoder->Setup(&format,in_info,in_size);
} }
@@ -168,6 +203,8 @@ BMediaDecoder::GetDecoderInfo(media_codec_info *out_info) const
return fInitStatus; return fInitStatus;
} }
UNIMPLEMENTED(); UNIMPLEMENTED();
out_info->id = fDecoderPluginID;
out_info->sub_id = fDecoderID;
return B_OK; return B_OK;
} }
@@ -187,19 +224,30 @@ BMediaDecoder::BMediaDecoder(const BMediaDecoder &);
BMediaDecoder::BMediaDecoder & operator=(const BMediaDecoder &); BMediaDecoder::BMediaDecoder & operator=(const BMediaDecoder &);
*/ */
/* static */ status_t status_t
BMediaDecoder::next_chunk(void *classptr, void **chunkData, size_t *chunkLen, media_header *mh) BMediaDecoder::AttachToDecoder()
{ {
UNIMPLEMENTED(); class MediaDecoderChunkProvider : public ChunkProvider {
private:
BMediaDecoder * fDecoder;
public:
MediaDecoderChunkProvider(BMediaDecoder * decoder) {
fDecoder = decoder;
}
virtual status_t GetNextChunk(void **chunkBuffer, int32 *chunkSize,
media_header *mediaHeader) {
const void ** buffer = const_cast<const void**>(chunkBuffer);
size_t * size = reinterpret_cast<size_t*>(chunkSize);
return fDecoder->GetNextChunk(buffer,size,mediaHeader);
}
} * provider = new MediaDecoderChunkProvider(this);
if (provider == NULL) {
return B_NO_MEMORY;
}
fDecoder->Setup(provider);
return B_OK; return B_OK;
} }
void
BMediaDecoder::ReleaseDecoder()
{
UNIMPLEMENTED();
}
status_t BMediaDecoder::_Reserved_BMediaDecoder_0(int32 arg, ...) { return B_ERROR; } status_t BMediaDecoder::_Reserved_BMediaDecoder_0(int32 arg, ...) { return B_ERROR; }
status_t BMediaDecoder::_Reserved_BMediaDecoder_1(int32 arg, ...) { return B_ERROR; } status_t BMediaDecoder::_Reserved_BMediaDecoder_1(int32 arg, ...) { return B_ERROR; }