Exemplo n.º 1
0
    void testStartAndStop()
    {
        MpFlowGraphBase*    pFlowGraph = 0;
        OsStatus        res;

        pFlowGraph = new MpFlowGraphBase(80, 8000);

        CPPUNIT_ASSERT(!pFlowGraph->isStarted());  // verify the flow graph is not STARTED
        CPPUNIT_ASSERT(MpFlowGraphBase::STOPPED == pFlowGraph->getState());

        res = pFlowGraph->start();         // now start it
        CPPUNIT_ASSERT(res == OS_SUCCESS);
        res = pFlowGraph->processNextFrame();
        CPPUNIT_ASSERT((res == OS_SUCCESS) && pFlowGraph->isStarted());
        CPPUNIT_ASSERT(MpFlowGraphBase::STARTED == pFlowGraph->getState());

        res = pFlowGraph->stop();          // now stop it again
        CPPUNIT_ASSERT(res == OS_SUCCESS);
        res = pFlowGraph->processNextFrame();
        CPPUNIT_ASSERT((res == OS_SUCCESS) && !pFlowGraph->isStarted());
        CPPUNIT_ASSERT(MpFlowGraphBase::STOPPED == pFlowGraph->getState());

        delete pFlowGraph;
    }
Exemplo n.º 2
0
    void testCreators()
    {
        MpFlowGraphBase*    pFlowGraph = 0;
        MpTestResource* pResource1 = 0;
        MpTestResource* pResource2 = 0;
        OsStatus        res;

        // verify that we can create and delete MpFlowGraphBase objects
        pFlowGraph = new MpFlowGraphBase(80, 8000);

        // verify that the initial state information is sensible
        CPPUNIT_ASSERT(pFlowGraph->getState() == MpFlowGraphBase::STOPPED);
        CPPUNIT_ASSERT(pFlowGraph->numLinks() == 0);
        CPPUNIT_ASSERT(pFlowGraph->numFramesProcessed() == 0);
        CPPUNIT_ASSERT(pFlowGraph->numResources() == 0);
        CPPUNIT_ASSERT(!pFlowGraph->isStarted());

        delete pFlowGraph;

        // when we have a flow graph that contains resources and links,
        // verify that destroying the flow graph also gets rid of the resources
        // and links.
        pFlowGraph = new MpFlowGraphBase(80, 8000);
        pResource1 = new MpTestResource("test1", 1, 1, 1, 1);
        pResource2 = new MpTestResource("test2", 1, 1, 1, 1);

        res = pFlowGraph->addResource(*pResource1);
        CPPUNIT_ASSERT(res == OS_SUCCESS);

        res = pFlowGraph->addResource(*pResource2);
        CPPUNIT_ASSERT(res == OS_SUCCESS);

        res = pFlowGraph->addLink(*pResource1, 0, *pResource2, 0);
        CPPUNIT_ASSERT(res == OS_SUCCESS);

        delete pFlowGraph;
    }
Exemplo n.º 3
0
// Handles the WAIT_FOR_SIGNAL message.
// Performs the one-per-tick media processing as directed by the flow graph.
// Returns TRUE if the message was handled, otherwise FALSE.
UtlBoolean MpMediaTask::handleWaitForSignal(MpMediaTaskMsg* pMsg)
{
   OsStatus         res;

#ifdef TEST_TASK_LOAD
   OsTime maxAllowedTime(mLimitUsecs*1000);
   OsTime processingStartTime;
   OsDateTime::getCurTime(processingStartTime);
#endif

   // reset the handleMessage error count
   // mHandleMsgErrs = 0;

   mWaitForSignal = FALSE;

   // When this message is received we know that:
   // 1) We have received a frame start signal
   // 2) All of the messages that had been queued for this task at the
   //    time the frame start signal occurred have been processed.

   // Call processNextFrame() for each of the "started" flow graphs
   UtlHashBagIterator itor(mManagedFlowGraphs);
   UtlPtr<MpFlowGraphBase>* ptr = NULL;
   MpFlowGraphBase* pFlowGraph = NULL;

#if FRAME_PROCESSING_THREADS > 0
   // let worker threads process frames
   int counter = 0;

   while(ptr = (UtlPtr<MpFlowGraphBase>*)itor())
   {
      pFlowGraph = ptr->getValue();
      assert(pFlowGraph);

      if (pFlowGraph && pFlowGraph->isStarted())
      {
         m_processingThreads[counter]->addFlowgraphForProcessing(pFlowGraph);
         counter = (counter + 1) % FRAME_PROCESSING_THREADS;
      }
   }

   // process all frames in threads
   for (int i = 0; i < FRAME_PROCESSING_THREADS; i++)
   {
      m_processingThreads[i]->processWork();
   }

   // now synchronize all threads - a barrier
   for (int i = 0; i < FRAME_PROCESSING_THREADS; i++)
   {
      m_processingThreads[i]->waitUntilDone();
   }
#else
   // let MpMediaTask process all frames
   while(ptr = (UtlPtr<MpFlowGraphBase>*)itor())
   {
      pFlowGraph = ptr->getValue();
      assert(pFlowGraph);

      if (pFlowGraph->isStarted())
      {
         res = pFlowGraph->processNextFrame();
         assert(res == OS_SUCCESS);
      }

   }
#endif

   assert(!mWaitForSignal);
   mProcessedCnt++;
   mWaitForSignal = TRUE;

   if (nFrameStartMsgs > 0)
   {
      nFrameStartMsgs--;
   }
   
#ifdef TEST_TASK_LOAD
   OsTime processingStopTime;
   OsDateTime::getCurTime(processingStopTime);
   if (processingStopTime - processingStartTime > maxAllowedTime)
   {
      // signal overload to skip processing frames
      m_bTaskOverloaded = TRUE;
   }
   else
   {
      // disable overload flag, we will process even big backlog of frame start signals
      m_bTaskOverloaded = FALSE;
   }
   
#endif

   return TRUE;
}
Exemplo n.º 4
0
    void testStartAndStopFlowGraph()
    {

        MpFlowGraphBase* pFlowGraph = 0;
        MpMediaTask*     pMediaTask = 0;
        OsStatus         res;

        // Test 1: Set the time limit to twice its original value
        pMediaTask = MpMediaTask::getMediaTask(10);

        pFlowGraph = new MpFlowGraphBase(30, 30);

        pMediaTask->numHandledMsgErrs(); // clear count
        // Test 1: Attempt to start a flow graph that is not being managed
        //CPPUNIT_ASSERT_EQUAL(1, pMediaTask->numStartedFlowGraphs());
        res = pMediaTask->startFlowGraph(*pFlowGraph);
        CPPUNIT_ASSERT(res == OS_SUCCESS);
        res = MpMediaTask::signalFrameStart();  // signal the media task and
        CPPUNIT_ASSERT(res == OS_SUCCESS);      // give it a chance to run
        OsTask::delay(20);
        // NOTE: Original test code had "1", not sure what's correct
        CPPUNIT_ASSERT_EQUAL(1, pMediaTask->numHandledMsgErrs());
        CPPUNIT_ASSERT_EQUAL(0, pMediaTask->numStartedFlowGraphs());

        // Test 2: Start a flow graph that is managed
        pMediaTask->numHandledMsgErrs(); // clear the count

        res = pMediaTask->manageFlowGraph(*pFlowGraph);
        CPPUNIT_ASSERT(res == OS_SUCCESS);
        res = pMediaTask->startFlowGraph(*pFlowGraph);
        CPPUNIT_ASSERT(res == OS_SUCCESS);
        res = MpMediaTask::signalFrameStart();  // signal the media task and
        CPPUNIT_ASSERT(res == OS_SUCCESS);      // give it a chance to run
        OsTask::delay(20);
        CPPUNIT_ASSERT_EQUAL(0, pMediaTask->numHandledMsgErrs());
        CPPUNIT_ASSERT_EQUAL(1, pMediaTask->numStartedFlowGraphs());
        CPPUNIT_ASSERT(pFlowGraph->isStarted());

        // Test 3: Attempt to start the same flow graph again
        pMediaTask->numHandledMsgErrs(); // clear the count

        res = pMediaTask->startFlowGraph(*pFlowGraph);
        CPPUNIT_ASSERT(res == OS_SUCCESS);
        res = MpMediaTask::signalFrameStart();  // signal the media task and
        CPPUNIT_ASSERT(res == OS_SUCCESS);      // give it a chance to run
        OsTask::delay(20);
        //CPPUNIT_ASSERT_EQUAL(0, pMediaTask->numHandledMsgErrs());
        CPPUNIT_ASSERT_EQUAL(1, pMediaTask->numStartedFlowGraphs());


        // Test 4: Stop the flow graph
        pMediaTask->numHandledMsgErrs(); // clear the count

        res = pMediaTask->stopFlowGraph(*pFlowGraph);
        CPPUNIT_ASSERT(res == OS_SUCCESS);
        res = MpMediaTask::signalFrameStart();  // signal the media task and
        CPPUNIT_ASSERT(res == OS_SUCCESS);      // give it a chance to run
        OsTask::delay(20);
        CPPUNIT_ASSERT_EQUAL(0, pMediaTask->numHandledMsgErrs());
        CPPUNIT_ASSERT_EQUAL(0, pMediaTask->numStartedFlowGraphs());
        CPPUNIT_ASSERT(!pFlowGraph->isStarted());

        // Test 5: Attempt to stop the same flow graph again
        pMediaTask->numHandledMsgErrs(); // clear the count

        res = pMediaTask->stopFlowGraph(*pFlowGraph);
        CPPUNIT_ASSERT(res == OS_SUCCESS);
        res = MpMediaTask::signalFrameStart();  // signal the media task and
        CPPUNIT_ASSERT(res == OS_SUCCESS);      // give it a chance to run

        OsTask::delay(20);
        //CPPUNIT_ASSERT_EQUAL(1, pMediaTask->numHandledMsgErrs());
        CPPUNIT_ASSERT_EQUAL(0, pMediaTask->numStartedFlowGraphs());
        CPPUNIT_ASSERT(!pFlowGraph->isStarted());

        // Test 6: Attempt to stop a flow graph that is not being managed
        pMediaTask->numHandledMsgErrs(); // clear the count

        res = pMediaTask->unmanageFlowGraph(*pFlowGraph);
        CPPUNIT_ASSERT(res == OS_SUCCESS);
        res = pMediaTask->stopFlowGraph(*pFlowGraph);
        CPPUNIT_ASSERT(res == OS_SUCCESS);
        res = MpMediaTask::signalFrameStart();  // signal the media task and
        CPPUNIT_ASSERT(res == OS_SUCCESS);      // give it a chance to run
        OsTask::delay(20);
        CPPUNIT_ASSERT_EQUAL(1, pMediaTask->numHandledMsgErrs());
        CPPUNIT_ASSERT_EQUAL(0, pMediaTask->numStartedFlowGraphs());
        CPPUNIT_ASSERT(!pFlowGraph->isStarted());

        delete pFlowGraph;
    }