status_t PluginManager::CreateStreamer(Streamer** streamer, BUrl* url, BDataIO** source) { TRACE("PluginManager::CreateStreamer enter\n"); entry_ref refs[MAX_STREAMERS]; int32 count; status_t ret = AddOnManager::GetInstance()->GetStreamers(refs, &count, MAX_STREAMERS); if (ret != B_OK) { printf("PluginManager::CreateStreamer: can't get list of streamers:" " %s\n", strerror(ret)); return ret; } // try each reader by calling it's Sniff function... for (int32 i = 0; i < count; i++) { entry_ref ref = refs[i]; MediaPlugin* plugin = GetPlugin(ref); if (plugin == NULL) { printf("PluginManager::CreateStreamer: GetPlugin failed\n"); return B_ERROR; } StreamerPlugin* streamerPlugin = dynamic_cast<StreamerPlugin*>(plugin); if (streamerPlugin == NULL) { printf("PluginManager::CreateStreamer: dynamic_cast failed\n"); PutPlugin(plugin); return B_ERROR; } *streamer = streamerPlugin->NewStreamer(); if (*streamer == NULL) { printf("PluginManager::CreateStreamer: NewReader failed\n"); PutPlugin(plugin); return B_ERROR; } (*streamer)->fMediaPlugin = plugin; BDataIO* streamSource = NULL; if ((*streamer)->Sniff(url, &streamSource) == B_OK) { TRACE("PluginManager::CreateStreamer: Sniff success "); *source = streamSource; return B_OK; } DestroyStreamer(*streamer); *streamer = NULL; } TRACE("PluginManager::CreateStreamer leave\n"); return B_MEDIA_NO_HANDLER; }
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; status_t ret = QueryServer(SERVER_GET_DECODER_FOR_FORMAT, &request, sizeof(request), &reply, sizeof(reply)); if (ret != B_OK) { printf("PluginManager::CreateDecoder: can't get decoder for format: " "%s\n", strerror(ret)); return ret; } MediaPlugin* plugin = GetPlugin(reply.ref); if (plugin == NULL) { printf("PluginManager::CreateDecoder: GetPlugin failed\n"); return B_ERROR; } DecoderPlugin* decoderPlugin = dynamic_cast<DecoderPlugin*>(plugin); if (decoderPlugin == NULL) { printf("PluginManager::CreateDecoder: dynamic_cast failed\n"); PutPlugin(plugin); return B_ERROR; } // TODO: In theory, one DecoderPlugin could support multiple Decoders, // but this is not yet handled (passing "0" as index/ID). *_decoder = decoderPlugin->NewDecoder(0); if (*_decoder == NULL) { printf("PluginManager::CreateDecoder: NewDecoder() failed\n"); PutPlugin(plugin); return B_ERROR; } TRACE(" created decoder: %p\n", *_decoder); (*_decoder)->fMediaPlugin = plugin; TRACE("PluginManager::CreateDecoder leave\n"); return B_OK; }
status_t PluginManager::CreateEncoder(Encoder** _encoder, const media_codec_info* codecInfo, uint32 flags) { TRACE("PluginManager::CreateEncoder enter\n"); // Get encoder for this codec info from the server server_get_encoder_for_codec_info_request request; server_get_encoder_for_codec_info_reply reply; request.id = codecInfo->id; status_t ret = QueryServer(SERVER_GET_ENCODER_FOR_CODEC_INFO, &request, sizeof(request), &reply, sizeof(reply)); if (ret != B_OK) { printf("PluginManager::CreateEncoder: can't get encoder for codec %s: " "%s\n", codecInfo->pretty_name, strerror(ret)); return ret; } MediaPlugin* plugin = GetPlugin(reply.ref); if (!plugin) { printf("PluginManager::CreateEncoder: GetPlugin failed\n"); return B_ERROR; } EncoderPlugin* encoderPlugin = dynamic_cast<EncoderPlugin*>(plugin); if (encoderPlugin == NULL) { printf("PluginManager::CreateEncoder: dynamic_cast failed\n"); PutPlugin(plugin); return B_ERROR; } *_encoder = encoderPlugin->NewEncoder(*codecInfo); if (*_encoder == NULL) { printf("PluginManager::CreateEncoder: NewEncoder() failed\n"); PutPlugin(plugin); return B_ERROR; } TRACE(" created encoder: %p\n", *_encoder); (*_encoder)->fMediaPlugin = plugin; TRACE("PluginManager::CreateEncoder leave\n"); return B_OK; }
status_t PluginManager::CreateWriter(Writer** writer, const media_file_format& mff, BDataIO* target) { TRACE("PluginManager::CreateWriter enter\n"); // Get the Writer responsible for this media_file_format from the server. server_get_writer_request request; request.internal_id = mff.id.internal_id; server_get_writer_reply reply; status_t ret = QueryServer(SERVER_GET_WRITER_FOR_FORMAT_FAMILY, &request, sizeof(request), &reply, sizeof(reply)); if (ret != B_OK) { printf("PluginManager::CreateWriter: can't get writer for file " "family: %s\n", strerror(ret)); return ret; } MediaPlugin* plugin = GetPlugin(reply.ref); if (plugin == NULL) { printf("PluginManager::CreateWriter: GetPlugin failed\n"); return B_ERROR; } WriterPlugin* writerPlugin = dynamic_cast<WriterPlugin*>(plugin); if (writerPlugin == NULL) { printf("PluginManager::CreateWriter: dynamic_cast failed\n"); PutPlugin(plugin); return B_ERROR; } *writer = writerPlugin->NewWriter(); if (*writer == NULL) { printf("PluginManager::CreateWriter: NewWriter failed\n"); PutPlugin(plugin); return B_ERROR; } (*writer)->Setup(target); (*writer)->fMediaPlugin = plugin; TRACE("PluginManager::CreateWriter leave\n"); return B_OK; }
status_t PluginManager::CreateDecoder(Decoder** _decoder, const media_format& format) { TRACE("PluginManager::CreateDecoder enter\n"); // get decoder for this format entry_ref ref; status_t ret = AddOnManager::GetInstance()->GetDecoderForFormat( &ref, format); if (ret != B_OK) { printf("PluginManager::CreateDecoder: can't get decoder for format: " "%s\n", strerror(ret)); return ret; } MediaPlugin* plugin = GetPlugin(ref); if (plugin == NULL) { printf("PluginManager::CreateDecoder: GetPlugin failed\n"); return B_ERROR; } DecoderPlugin* decoderPlugin = dynamic_cast<DecoderPlugin*>(plugin); if (decoderPlugin == NULL) { printf("PluginManager::CreateDecoder: dynamic_cast failed\n"); PutPlugin(plugin); return B_ERROR; } // TODO: In theory, one DecoderPlugin could support multiple Decoders, // but this is not yet handled (passing "0" as index/ID). *_decoder = decoderPlugin->NewDecoder(0); if (*_decoder == NULL) { printf("PluginManager::CreateDecoder: NewDecoder() failed\n"); PutPlugin(plugin); return B_ERROR; } TRACE(" created decoder: %p\n", *_decoder); (*_decoder)->fMediaPlugin = plugin; TRACE("PluginManager::CreateDecoder leave\n"); return B_OK; }
status_t PluginManager::CreateEncoder(Encoder** encoder, const media_format& format) { TRACE("PluginManager::CreateEncoder enter nr2\n"); entry_ref ref; status_t ret = AddOnManager::GetInstance()->GetEncoderForFormat( &ref, format); if (ret != B_OK) { ERROR("PluginManager::CreateEncoder: can't get decoder for format: " "%s\n", strerror(ret)); return ret; } MediaPlugin* plugin = GetPlugin(ref); if (plugin == NULL) { ERROR("PluginManager::CreateEncoder: GetPlugin failed\n"); return B_ERROR; } EncoderPlugin* encoderPlugin = dynamic_cast<EncoderPlugin*>(plugin); if (encoderPlugin == NULL) { ERROR("PluginManager::CreateEncoder: dynamic_cast failed\n"); PutPlugin(plugin); return B_ERROR; } *encoder = encoderPlugin->NewEncoder(format); if (*encoder == NULL) { ERROR("PluginManager::CreateEncoder: NewEncoder() failed\n"); PutPlugin(plugin); return B_ERROR; } TRACE(" created encoder: %p\n", *encoder); (*encoder)->fMediaPlugin = plugin; TRACE("PluginManager::CreateEncoder leave nr2\n"); return B_OK; }
status_t PluginManager::CreateEncoder(Encoder** _encoder, const media_codec_info* codecInfo, uint32 flags) { TRACE("PluginManager::CreateEncoder enter\n"); // Get encoder for this codec info from the server entry_ref ref; status_t ret = AddOnManager::GetInstance()->GetEncoder(&ref, codecInfo->id); if (ret != B_OK) { printf("PluginManager::CreateEncoder: can't get encoder for codec %s: " "%s\n", codecInfo->pretty_name, strerror(ret)); return ret; } MediaPlugin* plugin = GetPlugin(ref); if (!plugin) { printf("PluginManager::CreateEncoder: GetPlugin failed\n"); return B_ERROR; } EncoderPlugin* encoderPlugin = dynamic_cast<EncoderPlugin*>(plugin); if (encoderPlugin == NULL) { printf("PluginManager::CreateEncoder: dynamic_cast failed\n"); PutPlugin(plugin); return B_ERROR; } *_encoder = encoderPlugin->NewEncoder(*codecInfo); if (*_encoder == NULL) { printf("PluginManager::CreateEncoder: NewEncoder() failed\n"); PutPlugin(plugin); return B_ERROR; } TRACE(" created encoder: %p\n", *_encoder); (*_encoder)->fMediaPlugin = plugin; TRACE("PluginManager::CreateEncoder leave\n"); return B_OK; }
status_t PluginManager::CreateWriter(Writer** writer, const media_file_format& mff, BDataIO* target) { TRACE("PluginManager::CreateWriter enter\n"); // Get the Writer responsible for this media_file_format from the server. entry_ref ref; status_t ret = AddOnManager::GetInstance()->GetWriter(&ref, mff.id.internal_id); if (ret != B_OK) { printf("PluginManager::CreateWriter: can't get writer for file " "family: %s\n", strerror(ret)); return ret; } MediaPlugin* plugin = GetPlugin(ref); if (plugin == NULL) { printf("PluginManager::CreateWriter: GetPlugin failed\n"); return B_ERROR; } WriterPlugin* writerPlugin = dynamic_cast<WriterPlugin*>(plugin); if (writerPlugin == NULL) { printf("PluginManager::CreateWriter: dynamic_cast failed\n"); PutPlugin(plugin); return B_ERROR; } *writer = writerPlugin->NewWriter(); if (*writer == NULL) { printf("PluginManager::CreateWriter: NewWriter failed\n"); PutPlugin(plugin); return B_ERROR; } (*writer)->Setup(target); (*writer)->fMediaPlugin = plugin; TRACE("PluginManager::CreateWriter leave\n"); return B_OK; }
status_t PluginManager::CreateDecoder(Decoder** decoder, const media_codec_info& mci) { TRACE("PluginManager::CreateDecoder enter\n"); entry_ref ref; status_t status = AddOnManager::GetInstance()->GetEncoder(&ref, mci.id); if (status != B_OK) return status; MediaPlugin* plugin = GetPlugin(ref); if (plugin == NULL) { ERROR("PluginManager::CreateDecoder: GetPlugin failed\n"); return B_ERROR; } DecoderPlugin* decoderPlugin = dynamic_cast<DecoderPlugin*>(plugin); if (decoderPlugin == NULL) { ERROR("PluginManager::CreateDecoder: dynamic_cast failed\n"); PutPlugin(plugin); return B_ERROR; } // TODO: In theory, one DecoderPlugin could support multiple Decoders, // but this is not yet handled (passing "0" as index/ID). *decoder = decoderPlugin->NewDecoder(0); if (*decoder == NULL) { ERROR("PluginManager::CreateDecoder: NewDecoder() failed\n"); PutPlugin(plugin); return B_ERROR; } TRACE(" created decoder: %p\n", *decoder); (*decoder)->fMediaPlugin = plugin; TRACE("PluginManager::CreateDecoder leave\n"); return B_OK; }
void PluginManager::DestroyReader(Reader* reader) { if (reader != NULL) { TRACE("PluginManager::DestroyReader(%p (plugin: %p))\n", reader, reader->fMediaPlugin); // NOTE: We have to put the plug-in after deleting the reader, // since otherwise we may actually unload the code for the // destructor... MediaPlugin* plugin = reader->fMediaPlugin; delete reader; PutPlugin(plugin); } }
status_t PluginManager::CreateReader(Reader** reader, int32* streamCount, media_file_format* mff, BDataIO* source) { TRACE("PluginManager::CreateReader enter\n"); BPositionIO *seekable_source = dynamic_cast<BPositionIO *>(source); if (seekable_source == 0) { printf("PluginManager::CreateReader: non-seekable sources not " "supported yet\n"); return B_ERROR; } // get list of available readers from the server entry_ref refs[MAX_READERS]; int32 count; status_t ret = AddOnManager::GetInstance()->GetReaders(refs, &count, MAX_READERS); if (ret != B_OK) { printf("PluginManager::CreateReader: can't get list of readers: %s\n", strerror(ret)); return ret; } // try each reader by calling it's Sniff function... for (int32 i = 0; i < count; i++) { entry_ref ref = refs[i]; MediaPlugin* plugin = GetPlugin(ref); if (plugin == NULL) { printf("PluginManager::CreateReader: GetPlugin failed\n"); return B_ERROR; } ReaderPlugin* readerPlugin = dynamic_cast<ReaderPlugin*>(plugin); if (readerPlugin == NULL) { printf("PluginManager::CreateReader: dynamic_cast failed\n"); PutPlugin(plugin); return B_ERROR; } *reader = readerPlugin->NewReader(); if (*reader == NULL) { printf("PluginManager::CreateReader: NewReader failed\n"); PutPlugin(plugin); return B_ERROR; } seekable_source->Seek(0, SEEK_SET); (*reader)->Setup(seekable_source); (*reader)->fMediaPlugin = plugin; if ((*reader)->Sniff(streamCount) == B_OK) { TRACE("PluginManager::CreateReader: Sniff success " "(%ld stream(s))\n", *streamCount); (*reader)->GetFileFormatInfo(mff); return B_OK; } DestroyReader(*reader); *reader = NULL; } TRACE("PluginManager::CreateReader leave\n"); return B_MEDIA_NO_HANDLER; }
status_t PluginManager::CreateReader(Reader** reader, int32* streamCount, media_file_format* mff, BDataIO* source) { TRACE("PluginManager::CreateReader enter\n"); // The wrapper class will present our source in a more useful // way, we create an instance which is buffering our reads and // writes. BMediaIOWrapper* buffered_source = new BMediaIOWrapper(source); status_t ret = buffered_source->InitCheck(); if (ret != B_OK) return ret; // get list of available readers from the server entry_ref refs[MAX_READERS]; int32 count; ret = AddOnManager::GetInstance()->GetReaders(refs, &count, MAX_READERS); if (ret != B_OK) { printf("PluginManager::CreateReader: can't get list of readers: %s\n", strerror(ret)); return ret; } // try each reader by calling it's Sniff function... for (int32 i = 0; i < count; i++) { entry_ref ref = refs[i]; MediaPlugin* plugin = GetPlugin(ref); if (plugin == NULL) { printf("PluginManager::CreateReader: GetPlugin failed\n"); return B_ERROR; } ReaderPlugin* readerPlugin = dynamic_cast<ReaderPlugin*>(plugin); if (readerPlugin == NULL) { printf("PluginManager::CreateReader: dynamic_cast failed\n"); PutPlugin(plugin); return B_ERROR; } *reader = readerPlugin->NewReader(); if (*reader == NULL) { printf("PluginManager::CreateReader: NewReader failed\n"); PutPlugin(plugin); return B_ERROR; } buffered_source->Seek(0, SEEK_SET); (*reader)->Setup(buffered_source); (*reader)->fMediaPlugin = plugin; if ((*reader)->Sniff(streamCount) == B_OK) { TRACE("PluginManager::CreateReader: Sniff success " "(%ld stream(s))\n", *streamCount); (*reader)->GetFileFormatInfo(mff); return B_OK; } DestroyReader(*reader); *reader = NULL; } TRACE("PluginManager::CreateReader leave\n"); return B_MEDIA_NO_HANDLER; }