// Handles the SET_FOCUS message. // Returns TRUE if the message was handled, otherwise FALSE. UtlBoolean MpMediaTask::handleSetFocus(MpFlowGraphBase* pFlowGraph) { if (pFlowGraph != NULL) { if (!isManagedFlowGraph(pFlowGraph) || !pFlowGraph->isStarted()) { Nprintf("MpMT::handleSetFocus(0x%X) INVALID: %smanaged, %sstarted\n", (int) pFlowGraph, (int) (isManagedFlowGraph(pFlowGraph)? "" : "NOT "), (int) (pFlowGraph->isStarted() ? "" : "NOT "), 0,0,0); return FALSE; // we aren't managing this flow graph, return FALSE } } if (mpFocus != NULL) { #ifndef DISABLE_LOCAL_AUDIO // stop input stream MpAudioDriverManager* pAudioManager = MpAudioDriverManager::getInstance(); if (pAudioManager) { pAudioManager->abortInputStream(); } #endif // remove focus from the flow graph that currently has it Nprintf("MpMT::handleSetFocus(0x%X): removing old focus (0x%X)\n", (int) pFlowGraph, (int) mpFocus, 0,0,0,0); mpFocus->loseFocus(); } mpFocus = pFlowGraph; if (mpFocus != NULL) { // try to give focus to the indicated flow graph if (OS_SUCCESS != mpFocus->gainFocus()) { Nprintf("MpMT::handleSetFocus(0x%X): attempt to give focus FAILED\n", (int) pFlowGraph, 0,0,0,0,0); mpFocus = NULL; return FALSE; // the flow graph did not accept focus. } #ifndef DISABLE_LOCAL_AUDIO // start input stream MpAudioDriverManager* pAudioManager = MpAudioDriverManager::getInstance(); if (pAudioManager) { pAudioManager->startInputStream(); } #endif Nprintf("MpMT::handleSetFocus(0x%X): attempt to give focus SUCCEEDED\n", (int) pFlowGraph, 0,0,0,0,0); } return TRUE; }
// Handles the UNMANAGE message. // Returns TRUE if the message was handled, otherwise FALSE. UtlBoolean MpMediaTask::handleUnmanage(MpFlowGraphBase* pFlowGraph) { OsLock lock(mMutex); UtlBoolean found; OsStatus res; if (pFlowGraph == mpFocus) handleSetFocus(NULL); if (!isManagedFlowGraph(pFlowGraph)) { return FALSE; // flow graph is not presently managed, return FALSE } if (pFlowGraph->getState() != MpFlowGraphBase::STOPPED) { handleStop(pFlowGraph); // since we have "unmanaged" this flow graph, we need to coerce the // flow graph into processing its messages so that it gets the // indication that it has been stopped. res = pFlowGraph->processNextFrame(); assert(res == OS_SUCCESS); } UtlPtr<MpFlowGraphBase> ptr(pFlowGraph); // deletes the old UtlPtr we allocated earlier found = mManagedFlowGraphs.destroy(&ptr); return found; }
// Handles the SET_FOCUS message. // Returns TRUE if the message was handled, otherwise FALSE. UtlBoolean MpMediaTask::handleSetFocus(MpFlowGraphBase* pFlowGraph) { if (pFlowGraph != NULL) { if (!isManagedFlowGraph(pFlowGraph) || !pFlowGraph->isStarted()) { Nprintf("MpMT::handleSetFocus(0x%p) INVALID: %smanaged, %sstarted\n", pFlowGraph, (int) (isManagedFlowGraph(pFlowGraph)? "" : "NOT "), (int) (pFlowGraph->isStarted() ? "" : "NOT "), 0,0,0); return FALSE; // we aren't managing this flow graph, return FALSE } } if (mpFocus != NULL) { // remove focus from the flow graph that currently has it Nprintf("MpMT::handleSetFocus(0x%p): removing old focus (0x%p)\n", pFlowGraph, mpFocus, 0,0,0,0); mpFocus->loseFocus(); } mpFocus = pFlowGraph; if (mpFocus != NULL) { // try to give focus to the indicated flow graph if (OS_SUCCESS != mpFocus->gainFocus()) { Nprintf("MpMT::handleSetFocus(0x%p): attempt to give focus FAILED\n", pFlowGraph, 0,0,0,0,0); mpFocus = NULL; return FALSE; // the flow graph did not accept focus. } Nprintf("MpMT::handleSetFocus(0x%p): attempt to give focus SUCCEEDED\n", pFlowGraph, 0,0,0,0,0); } return TRUE; }
// Handles the UNMANAGE message. // Returns TRUE if the message was handled, otherwise FALSE. UtlBoolean MpMediaTask::handleUnmanage(MpFlowGraphBase* pFlowGraph) { OsLock lock(mMutex); UtlBoolean found; int i; OsStatus res; if (pFlowGraph == mpFocus) handleSetFocus(NULL); if (!isManagedFlowGraph(pFlowGraph)) { return FALSE; // flow graph is not presently managed, return FALSE } if (pFlowGraph->getState() != MpFlowGraphBase::STOPPED) { handleStop(pFlowGraph); // since we have "unmanaged" this flow graph, we need to coerce the // flow graph into processing its messages so that it gets the // indication that it has been stopped. res = pFlowGraph->processNextFrame(); assert(res == OS_SUCCESS); } found = FALSE; for (i=0; i < mManagedCnt; i++) { if (found) { // compact the managed flow graphs array mManagedFGs[i-1] = mManagedFGs[i]; } if (mManagedFGs[i] == pFlowGraph) { // PRINTF("MpMediaTask::handleUnmanage: Removing flow graph # %d!\n", i, 0,0,0,0,0); found = TRUE; mManagedFGs[i] = NULL; } } if (!found) { // we aren't managing this flow graph, return FALSE; // return FALSE } mManagedCnt--; return TRUE; }
// Handles the START message. // Returns TRUE if the message was handled, otherwise FALSE. UtlBoolean MpMediaTask::handleStart(MpFlowGraphBase* pFlowGraph) { OsStatus res; if (!isManagedFlowGraph(pFlowGraph)) return FALSE; // flow graph is not presently managed, return FALSE if (pFlowGraph->isStarted()) // if already started, return FALSE return FALSE; res = pFlowGraph->start(); assert(res == OS_SUCCESS); mStartedCnt++; return TRUE; }
// Handles the MANAGE message. // Returns TRUE if the message was handled, otherwise FALSE. UtlBoolean MpMediaTask::handleManage(MpFlowGraphBase* pFlowGraph) { OsLock lock(mMutex); if (isManagedFlowGraph(pFlowGraph)) { // we are already managing // PRINTF("MpMediaTask::handleManage: ERROR: flow graph already managed!\n", 0,0,0,0,0,0); return FALSE; // the flow graph, return FALSE } // PRINTF("MpMediaTask::handleManage: Adding flow graph # %d!\n", mManagedCnt, 0,0,0,0,0); // add flowgraph to hashbag UtlContainable* pRes = mManagedFlowGraphs.insert(new UtlPtr<MpFlowGraphBase>(pFlowGraph)); assert(pRes); return pRes != NULL; }
// Handles the STOP message. // Returns TRUE if the message was handled, otherwise FALSE. UtlBoolean MpMediaTask::handleStop(MpFlowGraphBase* pFlowGraph) { OsStatus res; if (pFlowGraph == mpFocus) handleSetFocus(NULL); if (!isManagedFlowGraph(pFlowGraph)) return FALSE; // flow graph is not presently managed, return FALSE if (pFlowGraph->getState() == MpFlowGraphBase::STOPPED) return FALSE; // if already stopped, return FALSE res = pFlowGraph->stop(); assert(res == OS_SUCCESS); mStartedCnt--; return TRUE; }
// Handles the MANAGE message. // Returns TRUE if the message was handled, otherwise FALSE. UtlBoolean MpMediaTask::handleManage(MpFlowGraphBase* pFlowGraph) { OsLock lock(mMutex); if (mManagedCnt >= mMaxFlowGraph) { // PRINTF("MpMediaTask::handleManage: ERROR: too many flow graphs!\n", 0,0,0,0,0,0); return FALSE; } if (isManagedFlowGraph(pFlowGraph)) { // we are already managing // PRINTF("MpMediaTask::handleManage: ERROR: flow graph already managed!\n", 0,0,0,0,0,0); return FALSE; // the flow graph, return FALSE } // PRINTF("MpMediaTask::handleManage: Adding flow graph # %d!\n", mManagedCnt, 0,0,0,0,0); mManagedFGs[mManagedCnt] = pFlowGraph; mManagedCnt++; return TRUE; }