int PluginHost::freePlugin(int id, int stackType, pthread_mutex_t *mutex, Channel *ch) { vector <Plugin *> *pStack = getStack(stackType, ch); for (unsigned i=0; i<pStack->size(); i++) { Plugin *pPlugin = pStack->at(i); if (pPlugin->getId() != id) continue; if (pPlugin->getStatus() == 0) { // no frills if plugin is missing delete pPlugin; pStack->erase(pStack->begin() + i); gu_log("[pluginHost::freePlugin] plugin id=%d removed with no frills, since it had status=0\n", id); return i; } while (true) { if (pthread_mutex_trylock(mutex) != 0) continue; pPlugin->suspendProcessing(true); pPlugin->releaseResources(); delete pPlugin; pStack->erase(pStack->begin() + i); pthread_mutex_unlock(mutex); gu_log("[pluginHost::freePlugin] plugin id=%d removed\n", id); return i; } } gu_log("[pluginHost::freePlugin] plugin id=%d not found\n", id); return -1; }
int PluginHost::addPlugin(const char *fname, int stackType, Channel *ch) { Plugin *p = new Plugin(); bool success = true; gVector <Plugin *> *pStack; pStack = getStack(stackType, ch); if (!p->load(fname)) { //delete p; //return 0; success = false; } /* if the load failed we add a 'dead' plugin into the stack. This is * useful to report a missing plugin. */ if (!success) { pStack->add(p); return 0; } /* otherwise let's try to initialize it. */ else { /* try to init the plugin. If fails, delete it and return error. */ if (!p->init(&PluginHost::HostCallback)) { delete p; return 0; } /* plugin setup */ p->setup(G_Conf.samplerate, kernelAudio::realBufsize); /* try to add the new plugin until succeed */ int lockStatus; while (true) { lockStatus = pthread_mutex_trylock(&G_Mixer.mutex_plugins); if (lockStatus == 0) { pStack->add(p); pthread_mutex_unlock(&G_Mixer.mutex_plugins); break; } } char name[256]; p->getName(name); gLog("[pluginHost] plugin id=%d loaded (%s), stack type=%d, stack size=%d\n", p->getId(), name, stackType, pStack->size); /* p->resume() is suggested. Who knows... */ p->resume(); return 1; } }