OMX_PTR appData,
OMX_COMPONENTTYPE **component) = 0;
+ virtual OMX_ERRORTYPE destroyComponentInstance(
+ OMX_COMPONENTTYPE *component) = 0;
+
virtual OMX_ERRORTYPE enumerateComponents(
OMX_STRING name,
size_t size,
namespace android {
class IOMXObserver;
+struct OMXMaster;
struct OMXNodeInstance {
OMXNodeInstance(
sp<IOMXObserver> observer();
OMX::node_id nodeID();
- status_t freeNode();
+ status_t freeNode(OMXMaster *master);
status_t sendCommand(OMX_COMMANDTYPE cmd, OMX_S32 param);
status_t getParameter(OMX_INDEXTYPE index, void *params, size_t size);
const char *parameterName, OMX_INDEXTYPE *index);
void onMessage(const omx_message &msg);
- void onObserverDied();
+ void onObserverDied(OMXMaster *master);
void onGetHandleFailed();
static OMX_CALLBACKTYPE kCallbacks;
invalidateNodeID_l(instance->nodeID());
}
- instance->onObserverDied();
+ instance->onObserverDied(mMaster);
}
status_t OMX::listNodes(List<String8> *list) {
mLiveNodes.removeItemsAt(index);
instance->observer()->asBinder()->unlinkToDeath(this);
- return instance->freeNode();
+ return instance->freeNode(mMaster);
}
status_t OMX::sendCommand(
(CreateOMXPluginFunc)dlsym(
mVendorLibHandle, "_ZN7android15createOMXPluginEv");
- addPlugin((*createOMXPlugin)());
+ if (createOMXPlugin) {
+ addPlugin((*createOMXPlugin)());
+ }
}
void OMXMaster::addPlugin(OMXPluginBase *plugin) {
}
OMXPluginBase *plugin = mPluginByComponentName.valueAt(index);
- return plugin->makeComponentInstance(name, callbacks, appData, component);
+ OMX_ERRORTYPE err =
+ plugin->makeComponentInstance(name, callbacks, appData, component);
+
+ if (err != OMX_ErrorNone) {
+ return err;
+ }
+
+ mPluginByInstance.add(*component, plugin);
+
+ return err;
+}
+
+OMX_ERRORTYPE OMXMaster::destroyComponentInstance(
+ OMX_COMPONENTTYPE *component) {
+ Mutex::Autolock autoLock(mLock);
+
+ ssize_t index = mPluginByInstance.indexOfKey(component);
+
+ if (index < 0) {
+ return OMX_ErrorBadParameter;
+ }
+
+ OMXPluginBase *plugin = mPluginByInstance.valueAt(index);
+ mPluginByInstance.removeItemsAt(index);
+
+ return plugin->destroyComponentInstance(component);
}
OMX_ERRORTYPE OMXMaster::enumerateComponents(
OMX_PTR appData,
OMX_COMPONENTTYPE **component);
+ virtual OMX_ERRORTYPE destroyComponentInstance(
+ OMX_COMPONENTTYPE *component);
+
virtual OMX_ERRORTYPE enumerateComponents(
OMX_STRING name,
size_t size,
Mutex mLock;
List<OMXPluginBase *> mPlugins;
KeyedVector<String8, OMXPluginBase *> mPluginByComponentName;
+ KeyedVector<OMX_COMPONENTTYPE *, OMXPluginBase *> mPluginByInstance;
+
void *mVendorLibHandle;
void addVendorPlugin();
#include <utils/Log.h>
#include "../include/OMXNodeInstance.h"
+#include "OMXMaster.h"
#include <OMX_Component.h>
return (err == OMX_ErrorNone) ? OK : UNKNOWN_ERROR;
}
-status_t OMXNodeInstance::freeNode() {
+status_t OMXNodeInstance::freeNode(OMXMaster *master) {
// Transition the node from its current state all the way down
// to "Loaded".
// This ensures that all active buffers are properly freed even
break;
}
- OMX_ERRORTYPE err =
- (*static_cast<OMX_COMPONENTTYPE *>(mHandle)->ComponentDeInit)(mHandle);
+ OMX_ERRORTYPE err = master->destroyComponentInstance(
+ static_cast<OMX_COMPONENTTYPE *>(mHandle));
+
mHandle = NULL;
if (err != OMX_ErrorNone) {
mObserver->onMessage(msg);
}
-void OMXNodeInstance::onObserverDied() {
+void OMXNodeInstance::onObserverDied(OMXMaster *master) {
LOGE("!!! Observer died. Quickly, do something, ... anything...");
// Try to force shutdown of the node and hope for the best.
- freeNode();
+ freeNode(master);
}
void OMXNodeInstance::onGetHandleFailed() {
const OMX_CALLBACKTYPE *callbacks,
OMX_PTR appData,
OMX_COMPONENTTYPE **component) {
- OMX_ERRORTYPE err = OMX_MasterGetHandle(
+ return OMX_MasterGetHandle(
reinterpret_cast<OMX_HANDLETYPE *>(component),
const_cast<char *>(name),
appData,
const_cast<OMX_CALLBACKTYPE *>(callbacks));
+}
- if (err != OMX_ErrorNone) {
- return err;
- }
-
- // PV is not even filling this in...
- (*component)->ComponentDeInit = &OMX_MasterFreeHandle;
-
- return OMX_ErrorNone;
+OMX_ERRORTYPE OMXPVCodecsPlugin::destroyComponentInstance(
+ OMX_COMPONENTTYPE *component) {
+ return OMX_MasterFreeHandle(component);
}
OMX_ERRORTYPE OMXPVCodecsPlugin::enumerateComponents(
OMX_PTR appData,
OMX_COMPONENTTYPE **component);
+ virtual OMX_ERRORTYPE destroyComponentInstance(
+ OMX_COMPONENTTYPE *component);
+
virtual OMX_ERRORTYPE enumerateComponents(
OMX_STRING name,
size_t size,
return OMX_ErrorInvalidComponentName;
}
+OMX_ERRORTYPE OMXSoftwareCodecsPlugin::destroyComponentInstance(
+ OMX_COMPONENTTYPE *component) {
+ return (*component->ComponentDeInit)(component);
+}
+
OMX_ERRORTYPE OMXSoftwareCodecsPlugin::enumerateComponents(
OMX_STRING name,
size_t size,
OMX_PTR appData,
OMX_COMPONENTTYPE **component);
+ virtual OMX_ERRORTYPE destroyComponentInstance(
+ OMX_COMPONENTTYPE *component);
+
virtual OMX_ERRORTYPE enumerateComponents(
OMX_STRING name,
size_t size,