PluginManager/AddOnManager: Add streamers support code

This commit is contained in:
Dario Casalinuovo
2016-03-25 22:20:03 +01:00
parent b777602827
commit 3733e4b2ab
5 changed files with 111 additions and 31 deletions
+6 -1
View File
@@ -14,6 +14,7 @@
#include "DecoderPlugin.h"
#include "EncoderPlugin.h"
#include "ReaderPlugin.h"
#include "StreamerPlugin.h"
#include "WriterPlugin.h"
#include <TList.h>
@@ -58,7 +59,11 @@ public:
const media_format& format);
void DestroyEncoder(Encoder* encoder);
status_t CreateStreamer(Streamer** streamer,
BUrl* url, BDataIO** source);
void DestroyStreamer(Streamer* streamer);
private:
status_t _LoadPlugin(const entry_ref& ref,
MediaPlugin** plugin, image_id* image);
+17
View File
@@ -203,6 +203,23 @@ AddOnManager::GetReaders(entry_ref* outRefs, int32* outCount,
}
status_t
AddOnManager::GetStreamers(entry_ref* outRefs, int32* outCount,
int32 maxCount)
{
BAutolock locker(fLock);
RegisterAddOns();
streamer_info* info;
for (fStreamerList.Rewind(); fStreamerList.GetNext(&info);) {
*outRefs = info->ref;
outRefs++;
}
return B_ERROR;
}
status_t
AddOnManager::GetEncoder(entry_ref* _encoderRef, int32 id)
{
+3
View File
@@ -45,6 +45,9 @@ public:
status_t GetReaders(entry_ref* _ref,
int32* _count, int32 maxCount);
status_t GetStreamers(entry_ref* _ref,
int32* _count, int32 maxCount);
status_t GetEncoder(entry_ref* _ref, int32 id);
status_t GetWriter(entry_ref* _ref,
+74
View File
@@ -20,6 +20,7 @@
PluginManager gPluginManager;
#define BLOCK_SIZE 4096
#define MAX_STREAMERS 40
class BMediaIOWrapper : public BMediaIO {
@@ -580,6 +581,79 @@ PluginManager::DestroyEncoder(Encoder* encoder)
}
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 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::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;
BMediaIO* 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;
}
void
PluginManager::DestroyStreamer(Streamer* streamer)
{
if (streamer != NULL) {
TRACE("PluginManager::DestroyStreamer(%p, plugin: %p)\n", streamer,
streamer->fMediaPlugin);
// NOTE: We have to put the plug-in after deleting the encoder,
// since otherwise we may actually unload the code for the
// destructor...
MediaPlugin* plugin = streamer->fMediaPlugin;
delete streamer;
PutPlugin(plugin);
}
}
// #pragma mark -
+11 -30
View File
@@ -1,8 +1,14 @@
/*
* Copyright 2016, Dario Casalinuovo. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#include "StreamerPlugin.h"
Streamer::Streamer()
:
fMediaPlugin(NULL)
{
}
@@ -12,33 +18,8 @@ Streamer::~Streamer()
}
void
Streamer::_ReservedStreamer1()
{
}
void
Streamer::_ReservedStreamer2()
{
}
void
Streamer::_ReservedStreamer3()
{
}
void
Streamer::_ReservedStreamer4()
{
}
void
Streamer::_ReservedStreamer5()
{
}
void Streamer::_ReservedStreamer1() {}
void Streamer::_ReservedStreamer2() {}
void Streamer::_ReservedStreamer3() {}
void Streamer::_ReservedStreamer4() {}
void Streamer::_ReservedStreamer5() {}