bool pff_pause_disconnect_test::start_async_test()
{
    int error = 0;

    OSCL_TRY(error, terminal = CPV2WayEngineFactory::CreateTerminalL(PV_324M,
                               (MPVCmnCmdStatusObserver *) this,
                               (MPVCmnInfoEventObserver *) this,
                               (MPVCmnErrorEventObserver *) this));

    if (error)
    {
        test_is_true(false);
        return false;
    }

    create_sink_source();

    OSCL_TRY(error, terminal->InitL(iSdkInitInfo, iCommServer));
    if (error)
    {
        test_is_true(false);
        CPV2WayEngineFactory::DeleteTerminal(terminal);
        terminal = NULL;
        return false;
    }

    return true;
}
void pff_pause_disconnect_test::is_av_started()
{
    int error = 0;
    if (check_audio_started() && check_video_started())
    {
        if (iUsePlayFileBeforeAddSource)
        {
            OSCL_TRY(error, terminal->StartPlayL());
            if (error)
            {
                test_is_true(false);
                disconnect();
            }
        }
        else
        {
            OSCL_TRY(error, terminal->UsePlayFileAsSourceL(true));
            if (error)
            {
                test_is_true(false);
                disconnect();
            }
        }
    }

    return;
}
void PVMFBufferDataSource::TimeoutOccurred(int32 timerID, int32 timeoutInfo)
{
    OSCL_UNUSED_ARG(timerID);
    unsigned bytesToSend = timeoutInfo;
    if (bytesToSend <= 0)
        return;

    if (!IsConnected())
        return;

    // Create new media data buffer
    OsclSharedPtr<PVMFMediaDataImpl> mediaDataImpl = iMediaDataAlloc->allocate(bytesToSend);
    PVMFSharedMediaDataPtr mediaData;
    int leavecode = 0;
    OSCL_TRY(leavecode, mediaData = PVMFMediaData::createMediaData(mediaDataImpl));
    OSCL_FIRST_CATCH_ANY(leavecode, return);

    // Send FSI if available
    if (iFsi)
    {
        OsclSharedPtr<PVMFMediaDataImpl> fsiMediaDataImpl = iMediaDataAlloc->allocate(iFsiLen);
        PVMFSharedMediaDataPtr fsiMediaData;
        OSCL_TRY(leavecode, fsiMediaData = PVMFMediaData::createMediaData(fsiMediaDataImpl));
        OSCL_FIRST_CATCH_ANY(leavecode, return);
        OsclRefCounterMemFrag fsi_frag;
        fsiMediaData->getMediaFragment(0, fsi_frag);
        oscl_memcpy((uint8*)fsi_frag.getMemFragPtr(), iFsi, iFsiLen);
        fsi_frag.getMemFrag().len = iFsiLen;
        mediaData->setFormatSpecificInfo(fsi_frag);
        OSCL_DEFAULT_FREE(iFsi);
        iFsi = NULL;
        iFsiLen = 0;
    }

    // Retrieve memory fragment to write to
    OsclRefCounterMemFrag refCtrMemFrag;
    mediaData->getMediaFragment(0, refCtrMemFrag);
    if (refCtrMemFrag.getCapacity() < bytesToSend)
        return;

    oscl_memset((uint8*)refCtrMemFrag.getMemFragPtr(), 7, bytesToSend);
    mediaDataImpl->setMediaFragFilledLen(0, bytesToSend);
    mediaData->setTimestamp(iTimestamp);
    iTimestamp += iSampleInterval;

    // Send frame to downstream node
    PVMFSharedMediaMsgPtr mediaMsg;
    convertToPVMFMediaMsg(mediaMsg, mediaData);
    QueueOutgoingMsg(mediaMsg);
}
void pff_eos_test::test()
{
    int error = 0;
    char *filename = new char[iFilename.get_size() + 1];
    if ((filename == NULL) || (oscl_UnicodeToUTF8(iFilename.get_cstr(), iFilename.get_size(), filename, iFilename.get_size() + 1) == 0))
    {
        OSCL_LEAVE(-1);
    }

    fprintf(fileoutput, "Start pff eos test, num runs %d, audio eos %d, vidoe eos %d, proxy %d, file %s\n", iMaxRuns, iWaitForAudioEOS, iWaitForVideoEOS, iUseProxy, filename);

    delete filename;

    scheduler = OsclExecScheduler::Current();

    this->AddToScheduler();

    if (start_async_test())
    {
        OSCL_TRY(error, scheduler->StartScheduler());
        if (error != 0)
        {
            OSCL_LEAVE(error);
        }
    }

    destroy_sink_source();

    this->RemoveFromScheduler();
}
void pff_eos_test::check_eos()
{
    int error = 0;

    if (iStopPlayLCalled) return;

    if (iWaitForAudioEOS)
    {
        if (!iAudioEOSRecv) return;
    }

    if (iWaitForVideoEOS)
    {
        if (!iVideoEOSRecv) return;
    }

    OSCL_TRY(error, terminal->StopPlayL());
    if (error)
    {
        test_is_true(false);
        disconnect();
    }
    else
    {
        iStopPlayLCalled = true;
    }

    return;
}
void pff_pause_disconnect_test::test()
{
    int error = 0;
    char *filename = new char[iFilename.get_size() + 1];
    if ((filename == NULL) || (oscl_UnicodeToUTF8(iFilename.get_cstr(), iFilename.get_size(), filename, iFilename.get_size() + 1) == 0))
    {
        OSCL_LEAVE(-1);
    }

    fprintf(fileoutput, "Start play from file pause disconnect test, before add source %d, file %s\n", iUsePlayFileBeforeAddSource, filename);

    delete filename;

    scheduler = OsclExecScheduler::Current();

    this->AddToScheduler();

    if (start_async_test())
    {
        OSCL_TRY(error, scheduler->StartScheduler());
        if (error != 0)
        {
            OSCL_LEAVE(error);
        }
    }

    destroy_sink_source();

    this->RemoveFromScheduler();
}
void CPV2WayRecDatapath::CheckPause()
{
    uint32 i;
    int32 error;

    PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "CPV2WayDatapath::CheckPause state %d\n", iState));

    for (i = 0; i < iNodeList.size(); i++)
    {
        if (!iNodeList[i].iCanNodePause) continue;

        PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "CPV2WayDatapath::CheckPause node %d state %d\n", i, iNodeList[i].iNode.node->GetState()));
        switch (iNodeList[i].iNode.node->GetState())
        {
            case EPVMFNodeStarted:
                OSCL_TRY(error, i2Way->SendNodeCmdL(PV2WAY_NODE_CMD_PAUSE, iNodeList[i].iNode.node, iNodeList[i].iNode.session, this));
                OSCL_FIRST_CATCH_ANY(error,
                                     PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0, "CPV2WayDatapath::CheckPause unable to pause node\n"));
                                     DatapathError();
                                     return;);
                break;

            default:
                PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_NOTICE, (0, "CPV2WayDatapath::CheckPause transitional node state!\n"));
                break;
        }
    }
void connect_test::InitSucceeded()
{
    i324mConfigInterface = iH324MConfig;
    //OSCL_TRY(error, i324mIFCommandId = terminal->QueryInterface(h324mUuid, i324mConfigInterface,NULL));
    if (i324mConfigInterface == NULL)
    {
        test_is_true(false);
        reset();
        return;

    }
    // set some timers via the interface
    H324MConfigInterface * i324Interface = (H324MConfigInterface *)i324mConfigInterface;
    if (iRunTimerTest)
    {
        i324Interface->SetTimerCounter(EH324Timer, 1, 1, 10, NULL);
        i324Interface->SetTimerCounter(EH324Counter, 4, 1, 10, NULL);
    }
    i324Interface->removeRef();
    iStackIFSet = true;
    int error;
    PVUuid mp4h263EncUuid = PVMp4H263EncExtensionUUID;
    OSCL_TRY(error, iEncoderIFCommandId = terminal->QueryInterface(mp4h263EncUuid, iMP4H263EncoderInterface, NULL));
    if (error)
    {
        test_is_true(false);
        reset();
    }
}
bool test_base::Init()
{
    int32 error = 0;
    OSCL_FastString aStr;

    /*!

      Step 7: Initialize terminal
      @param PV2Way324InitInfo
      Initialize the terminal using PV2Way324InitInfo structure to set
      the formats that the application supports
    */
    OSCL_TRY(error, iInitCmdId = terminal->Init(iSdkInitInfo));
    if (error)
    {
        printf("\n*************** Test FAILED: could not initialize terminal *************** \n");
        test_is_true(false);

        if (iUseProxy)
        {
            CPV2WayProxyFactory::DeleteTerminal(terminal);
        }
        else
        {
            CPV2WayEngineFactory::DeleteTerminal(terminal);
        }

        terminal = NULL;
        return false;
    }
    return true;
}
bool init_play_test::start_async_test()
{
    int error = 0;

    if (iUseProxy)
    {
        OSCL_TRY(error, terminal = CPV2WayProxyFactory::CreateTerminalL(PV_324M,
                                   (MPVCmnCmdStatusObserver *) this,
                                   (MPVCmnInfoEventObserver *) this,
                                   (MPVCmnErrorEventObserver *) this));
    }
    else
    {
        OSCL_TRY(error, terminal = CPV2WayEngineFactory::CreateTerminalL(PV_324M,
                                   (MPVCmnCmdStatusObserver *) this,
                                   (MPVCmnInfoEventObserver *) this,
                                   (MPVCmnErrorEventObserver *) this));
    }

    if (error)
    {
        test_is_true(false);
        return false;
    }

    create_sink_source();

    OSCL_TRY(error, terminal->InitL(iSdkInitInfo, iCommServer));
    if (error)
    {
        test_is_true(false);

        if (iUseProxy)
        {
            CPV2WayProxyFactory::DeleteTerminal(terminal);
        }
        else
        {
            CPV2WayEngineFactory::DeleteTerminal(terminal);
        }

        terminal = NULL;
        return false;
    }

    return true;
}
PVMFNodeInterface* PV2WayDummyInputMIONodeFactory::Create(LipSyncDummyMIOSettings& aSettings)
{
    CreateMedia(aSettings);
    PVMFNodeInterface* mioNode = NULL;
    int error = 0;
    OSCL_TRY(error, mioNode = PvmfMediaInputNodeFactory::Create(iMediaControl));
    return mioNode;
}
OSCL_EXPORT_REF PVCommandId PV2WayMIO::Add()
{

    if (iMioNode == 0)
        return -1;
    int32 error = 0;
    if (!iAdded)
    {
        /*!

          Step 11: Add MIO Node to terminal
          Add appropriate MIO Node to terminal (audio/video, incoming/outgoing)
        */
        if (iMyDir == INCOMING)
        {
            OSCL_TRY(error, iAddId = iTerminal->AddDataSink(iChannelId,
                                     *iMioNode));
            if (error)
            {
                OutputInfo("PV2WayMIO::Add():: Error Adding Data Sink!");
            }
            return iAddId;
        }
        else
        {
            OSCL_TRY(error, iAddId = iTerminal->AddDataSource(iChannelId,
                                     *iMioNode));
            if (error)
            {
                OutputInfo("PV2WayMIO::Add():: Error Adding Data Source!");
            }
            return iAddId;
        }
    }
    else if (!iRemoving)
    {
        OutputInfo("\nError: MIO already added!\n");
    }
    else if (iRemoving)
    {
        OutputInfo("\nCannot add because attempting to remove MIO!\n");
    }
    return -1;
}
void video_preview_disconnect_test::HandleInformationalEventL(const CPVCmnAsyncInfoEvent& aEvent)
{
    int error = 0;

    switch (aEvent.GetEventType())
    {
        case PVT_INDICATION_INCOMING_TRACK:
            TPVChannelId id;

            if (((CPVCmnAsyncEvent&)aEvent).GetLocalBuffer()[0] == PV_VIDEO)
            {
                OSCL_TRY(error, iVideoAddSinkId = terminal->AddDataSinkL(*iVideoSink, id));
                if (error)
                {
                    test_is_true(false);
                    disconnect();
                }
            }
            break;

        case PVT_INDICATION_DISCONNECT:
            iAudioSourceAdded = false;
            iVideoSourceAdded = false;
            iAudioSinkAdded = false;
            iVideoSinkAdded = false;
            break;

        case PVT_INDICATION_CLOSE_TRACK:
            if (((CPVCmnAsyncEvent&)aEvent).GetLocalBuffer()[0] == PV_VIDEO)
            {
                if (((CPVCmnAsyncEvent&)aEvent).GetLocalBuffer()[1] == INCOMING)
                {
                    iVideoSinkAdded = false;
                }
                else
                {
                    iVideoSourceAdded = false;
                }

                if (check_video_stopped())
                {
                    disconnect();
                }
            }
            break;

        case PVT_INDICATION_INTERNAL_ERROR:
            break;

        default:
            break;
    }
}
void init_cancel_test::QueryInterfaceSucceeded()
{
    test_base::QueryInterfaceSucceeded();

    int error = 0;
    OSCL_TRY(error, iCnclCmdId = terminal->CancelAllCommands());
    if (error)
    {
        test_is_true(false);
    }

}
void test_base::VideoRemoveSourceCompleted()
{
    int error = 0;
    iVideoSourceAdded = false;
    OSCL_TRY(error, iVideoRemoveSinkId = iSourceAndSinks->RemoveVideoSink());
    if (error)
    {
        printf("\n*************** Test FAILED: error removing video sink *************** \n");
        test_is_true(false);
        disconnect();
    }
}
PVMFStatus PVMP4FFRecognizerPlugin::Recognize(PVMFDataStreamFactory& aSourceDataStreamFactory, PVMFRecognizerMIMEStringList* aFormatHint,
        Oscl_Vector<PVMFRecognizerResult, OsclMemAllocator>& aRecognizerResult)
{
    OSCL_UNUSED_ARG(aFormatHint);

    // Check if the specified file is MP4 file by using MP4 parser lib's static function
    bool ismp4file = false;
    OSCL_wHeapString<OsclMemAllocator> tmpfilename;
    int32 leavecode = 0;
    OSCL_TRY(leavecode, ismp4file = IMpeg4File::IsMP4File(&aSourceDataStreamFactory));
    OSCL_FIRST_CATCH_ANY(leavecode,
                         return PVMFErrNoMemory;
                        );
OSCL_EXPORT_REF void ThreadSafeMemPoolFixedChunkAllocator::createmempool()
{
    if (iChunkSize == 0 || iNumChunk == 0)
    {
        OSCL_LEAVE(OsclErrArgument);
    }

    // Create one block of memory for the memory pool
    iChunkSizeMemAligned = oscl_mem_aligned_size(iChunkSize);
    int32 leavecode = 0;
    if (iMemPoolAllocator)
    {
        OSCL_TRY(leavecode, iMemPool = iMemPoolAllocator->ALLOCATE(iNumChunk * iChunkSizeMemAligned));
    }
    else
    {
        OSCL_TRY(leavecode, iMemPool = OSCL_MALLOC(iNumChunk * iChunkSizeMemAligned));
    }

    if (leavecode || iMemPool == NULL)
    {
        OSCL_LEAVE(OsclErrNoMemory);
    }

#if OSCL_MEM_FILL_WITH_PATTERN
    oscl_memset(iMemPool, 0x55, iNumChunk*iChunkSizeMemAligned);
#endif

    // Set up the free mem chunk list vector
    iFreeMemChunkList.reserve(iNumChunk);
    uint8* chunkptr = (uint8*)iMemPool;

    for (uint32 i = 0; i < iNumChunk; ++i)
    {
        iFreeMemChunkList.push_back((OsclAny*)chunkptr);
        chunkptr += iChunkSizeMemAligned;
    }
}
OSCL_EXPORT_REF PVCommandId PV2WayMIO::Remove()
{
    int32 error = 0;
    iRemoving = true;
    /*!

      Step 12: Cleanup
      Step 12a: Remove source and sinks
    */
    if (iMioNode && iRemoveId == -1)
    {
        if (iMyDir == INCOMING)
        {
            OSCL_TRY(error, iRemoveId = iTerminal->RemoveDataSink(*iMioNode));
            if (error)
            {
                OutputInfo("\n Error in RemoveDataSink!\n");
            }
            return iRemoveId;
        }
        else
        {
            OSCL_TRY(error, iRemoveId = iTerminal->RemoveDataSource(*iMioNode));
            if (error)
            {
                OutputInfo("\n Error in RemoveDataSource!\n");
            }
            return iRemoveId;
        }
    }
    else if (!iAdded)
    {
        OutputInfo("\nError: MIO cannot be removed because has not been added!\n");
    }
    return -1;
}
PVMFStatus PVFMVideoMIO::CreateYUVToRGBColorConverter(ColorConvertBase*& aCC, PVMFFormatType aRGBFormatType)
{
    int32 leavecode = 0;
    if (aRGBFormatType == PVMF_MIME_RGB16)
    {
        OSCL_TRY(leavecode, aCC = ColorConvert16::NewL());
    }
    else
    {
        PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0, "PVFMVideoMIO::CreateYUVToRGBColorConverter() Unsupported RGB mode for color converter. Asserting"));
        return PVMFErrNotSupported;
    }

    OSCL_FIRST_CATCH_ANY(leavecode,
                         PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0, "PVFMVideoMIO::CreateYUVToRGBColorConverter() Color converter instantiation did a leave"));
                         return PVMFErrNoResources;
                        );
PVMFStatus PVMFRecognizerRegistryImpl::OpenSession(PVMFSessionId& aSessionId, PVMFRecognizerCommmandHandler& aCmdHandler)
{
    // TEMP: Currently only allow one session at a time
    if (iRecognizerSessionList.empty() == false)
    {
        LOGERROR((0, "PVMFRecognizerRegistryImpl::OpenSession Failed!"));
        return PVMFErrBusy;
    }

    // Add this session to the list
    PVMFRecRegSessionInfo recsessioninfo;
    recsessioninfo.iRecRegSessionId = iNextSessionId;
    recsessioninfo.iRecRegCmdHandler = &aCmdHandler;
    int32 leavecode = 0;
    OSCL_TRY(leavecode, iRecognizerSessionList.push_back(recsessioninfo));
    OSCL_FIRST_CATCH_ANY(leavecode,
                         return PVMFErrNoMemory;
                        );
void init_test::InitSucceeded()
{
    iRstCmdId = 0;
    int error;
    cleanup();
    OSCL_TRY(error, iRstCmdId =  terminal->Reset());
    if (error)
    {
        test_is_true(false);
        RunIfNotReady();
    }
    else
    {
        if (iCurrentRun >= (iMaxRuns - 1))
        {
            test_is_true(true);
        }
    }
}
void connect_test::test()
{
    fprintf(fileoutput, "Start %s test, num runs %d, proxy %d.\n", iRunTimerTest ? "timer configuration and encoder extension IF" : "connect", iMaxRuns, iUseProxy);
    int error = 0;

    scheduler = OsclExecScheduler::Current();

    this->AddToScheduler();

    if (start_async_test())
    {
        OSCL_TRY(error, scheduler->StartScheduler());
        if (error != 0)
        {
            OSCL_LEAVE(error);
        }
    }

    this->RemoveFromScheduler();
}
void init_cancel_test::test()
{
    fprintf(fileoutput, "Start init cancel test, proxy %d.\n", iUseProxy);
    int error = 0;

    scheduler = OsclExecScheduler::Current();

    this->AddToScheduler();

    if (start_async_test())
    {
        OSCL_TRY(error, scheduler->StartScheduler());
        if (error != 0)
        {
            OSCL_LEAVE(error);
        }
    }

    this->RemoveFromScheduler();
}
void init_cancel_test::test()
{
    fprintf(fileoutput, "----- Start %s test, proxy %d. ----- \n", iTestName.get_cstr(), iUseProxy);
    fprintf(fileoutput, "\n** Test Number: %d. ** \n", iTestNum);
    int error = 0;

    scheduler = OsclExecScheduler::Current();

    this->AddToScheduler();

    if (start_async_test())
    {
        OSCL_TRY(error, scheduler->StartScheduler());
        if (error != 0)
        {
            OSCL_LEAVE(error);
        }
    }

    TestCompleted();
    this->RemoveFromScheduler();
}
void video_preview_disconnect_test::test()
{
    fprintf(fileoutput, "Start video preview disconnect test, proxy %d.\n", iUseProxy);
    int error = 0;

    scheduler = OsclExecScheduler::Current();

    this->AddToScheduler();

    if (start_async_test())
    {
        OSCL_TRY(error, scheduler->StartScheduler());
        if (error != 0)
        {
            OSCL_LEAVE(error);
        }
    }

    destroy_sink_source();

    this->RemoveFromScheduler();
}
void init_rec_test::test()
{
    fprintf(fileoutput, "Start init rec test, num runs %d, proxy %d.\n", iMaxRuns, iUseProxy);
    int error = 0;

    scheduler = OsclExecScheduler::Current();

    this->AddToScheduler();

    if (start_async_test())
    {
        OSCL_TRY(error, scheduler->StartScheduler());
        if (error != 0)
        {
            OSCL_LEAVE(error);
        }
    }

    destroy_sink_source();

    this->RemoveFromScheduler();
}
void pv_metadata_engine_test::Run()
{
    int error = 0;

    switch (iState)
    {
        case STATE_CREATE:
        {
            iPVMEContainer.iCmdStatusObserver = this;
            iPVMEContainer.iInfoEventObserver = this;
            iPVMEContainer.iErrorEventObserver = this;
            iPVMEContainer.iMode = iMode;

            if (iPVMEContainer.iMode == PV_METADATA_ENGINE_THREADED_MODE)
            {
                //Configure the threadsafe queues that are used for engine
                //thread callbacks.
                iThreadSafeCommandQueue.Configure(this);
                iThreadSafeErrorQueue.Configure(this);
                iThreadSafeInfoQueue.Configure(this);

                iPVMEContainer.iSem.Create();

                iPVMEContainer.iAppenderType = iLoggerInfo.iAppenderType;
                iPVMEContainer.iLogfilename = iLoggerInfo.logfilename;
                iPVMEContainer.iLoggerConfigElements = iLoggerInfo.iLoggerConfigElements;
            }

            OSCL_TRY(error, PVMetadataEngineFactory::CreatePVMetadataEngine(iPVMEContainer));

            PVLOGGER_LOGMSG(PVLOGMSG_INST_PROF, iPerfLogger, PVLOGMSG_INFO,
                            (0, "PVMetadataEngineTest::Create Called ClockInMS=%d", OsclTickCount::TicksToMsec(OsclTickCount::TickCount())));

            if (error || iPVMEContainer.iPVMEInterface == NULL)
            {
                PVMEATB_TEST_IS_TRUE(false);
                iObserver->TestCompleted(*iTestCase);
            }
            else
            {
                iState = STATE_INIT;
                RunIfNotReady();
            }
        }
        break;


        case STATE_INIT:
        {

            PVLOGGER_LOGMSG(PVLOGMSG_INST_PROF, iPerfLogger, PVLOGMSG_INFO,
                            (0, "PVMetadataEngineTest::Init Issued ClockInMS=%d", OsclTickCount::TicksToMsec(OsclTickCount::TickCount())));

            iCurrentCmdId = iPVMEContainer.iPVMEInterface->Init((OsclAny*) & iContextObject);

        }
        break;

        case STATE_SETMETADATAKEYS:
        {
            ReadMetadataFile();
            ReadClipsFile();

            if (iClipFilePresent == false)
            {
                fprintf(file, "\nClip File Not Present \n");
                iState = STATE_RESET;
                RunIfNotReady();
            }

            else if (iMetadataKeyList.size() != 0)
            {
                PVMFStatus status;
                PVLOGGER_LOGMSG(PVLOGMSG_INST_PROF, iPerfLogger, PVLOGMSG_INFO,
                                (0, "PVMetadataEngineTest::SetMetadataKeys Issued ClockInMS=%d", OsclTickCount::TicksToMsec(OsclTickCount::TickCount())));
                status = iPVMEContainer.iPVMEInterface->SetMetaDataKeys(iMetadataKeyList);

                if (status == PVMFErrInvalidState)
                {
                    PVLOGGER_LOGMSG(PVLOGMSG_INST_PROF, iPerfLogger, PVLOGMSG_INFO,
                                    (0, "PVMetadataEngineTest::SetMetadataKeys called in wrong state"));
                }
                else
                {
                    iState = STATE_GETMETADATA;
                    RunIfNotReady();
                }
            }

            else
            {
                iState = STATE_GETMETADATA;
                RunIfNotReady();
            }
        }
        break;

        case STATE_GETMETADATA:
        {
            //If GetMetadata is being called second time in MultipleGetMetadataTest, we don't want these statements to execute again
            if (iDataSource == NULL)
            {
                // Create a player data source and add it
                iDataSource = new PVPlayerDataSourceURL;
            }

            OSCL_wHeapString<OsclMemAllocator> inputfilename;

            // Convert the source file name to UCS2 and extract the filename part
            PVMFFormatType iFileType;
            iFileName = *it;
            it++;
            GetSourceFormatType(iFileName, iFileType);

            oscl_UTF8ToUnicode(iFileName, oscl_strlen(iFileName), iTempWCharBuf, 512);
            wFileName.set(iTempWCharBuf, oscl_strlen(iTempWCharBuf));
            RetrieveFilename(wFileName.get_str(), inputfilename);

            printf("\nInput File Name is %s", iFileName);

            iDataSource->SetDataSourceURL(wFileName);
            iDataSource->SetDataSourceFormatType(iFileType);

            start_time = OsclTickCount::TicksToMsec(OsclTickCount::TickCount());

            PVLOGGER_LOGMSG(PVLOGMSG_INST_PROF, iPerfLogger, PVLOGMSG_INFO,
                            (0, "PVMetadataEngineTest::GetMetadata Issued ClockInMS = (%d)", start_time));


            OSCL_TRY(error, iCurrentCmdId = iPVMEContainer.iPVMEInterface->GetMetadata(*iDataSource, iMetadataValueList, (OsclAny*) & iContextObject));
            OSCL_FIRST_CATCH_ANY(error, PVMEATB_TEST_IS_TRUE(false); iState = STATE_RESET; RunIfNotReady());
        }

        break;

        case STATE_RESET:
        {
            PVLOGGER_LOGMSG(PVLOGMSG_INST_PROF, iPerfLogger, PVLOGMSG_INFO,
                            (0, "PVMetadataEngineTest::Reset Issued ClockInMS=%d", OsclTickCount::TicksToMsec(OsclTickCount::TickCount())));

            iCurrentCmdId = iPVMEContainer.iPVMEInterface->Reset((OsclAny*) & iContextObject);

        }
        break;

        case STATE_DELETE:
        {

            PVLOGGER_LOGMSG(PVLOGMSG_INST_PROF, iPerfLogger, PVLOGMSG_INFO,
                            (0, "PVMetadataEngineTest::Delete Called ClockInMS=%d", OsclTickCount::TicksToMsec(OsclTickCount::TickCount())));
            PVMFStatus status = PVMetadataEngineFactory::DeletePVMetadataEngine(iPVMEContainer);
            if (status != PVMFSuccess)
            {
                PVMEATB_TEST_IS_TRUE(false);
            }
            delete iDataSource;
            iDataSource = NULL;

            iFS.Close();

            if (iPVMEContainer.iMode == PV_METADATA_ENGINE_THREADED_MODE)
            {
                iPVMEContainer.iSem.Close();
            }




            PVLOGGER_LOGMSG(PVLOGMSG_INST_PROF, iPerfLogger, PVLOGMSG_INFO,
                            (0, "PVMetadataEngineTest::TotalNumClips=%d", numOfClips));

            PVLOGGER_LOGMSG(PVLOGMSG_INST_PROF, iPerfLogger, PVLOGMSG_INFO,
                            (0, "PVMetadataEngineTest::AverageGetMetaDataTimeInMS=%d", (AverageGetMetaDataTimeInMS / numOfClips)));

            PVLOGGER_LOGMSG(PVLOGMSG_INST_PROF, iPerfLogger, PVLOGMSG_INFO,
                            (0, "PVMetadataEngineTest::MaxGetMetaDataTime=%d", MaxGetMetaDataTime));

            PVLOGGER_LOGMSG(PVLOGMSG_INST_PROF, iPerfLogger, PVLOGMSG_INFO,
                            (0, "PVMetadataEngineTest::MinGetMetaDataTime=%d", MinGetMetaDataTime));

            iObserver->TestCompleted(*iTestCase);
        }
        break;

        default:
            break;

    }
}
OSCL_EXPORT_REF void OsclMemPoolFixedChunkAllocator::createmempool()
{
    if (iChunkSize == 0 || iNumChunk == 0)
    {
        OSCL_LEAVE(OsclErrArgument);
    }

    if (iChunkAlignment > 0)
    {
        uint32 temp = iChunkAlignment - 1;
        iChunkSizeMemAligned = ((iChunkSize + temp) & (~temp));
    }
    else
    {
        // Create one block of memory for the memory pool
        iChunkSizeMemAligned = oscl_mem_aligned_size(iChunkSize);
    }

    int32 leavecode = 0;
    if (iMemPoolAllocator)
    {
        OSCL_TRY(leavecode, iMemPool = iMemPoolAllocator->ALLOCATE((iNumChunk * iChunkSizeMemAligned) + iChunkAlignment));
    }
    else
    {
        iMemPool = OSCL_MALLOC((iNumChunk * iChunkSizeMemAligned) + iChunkAlignment);
    }

    if (leavecode || iMemPool == NULL)
    {
        OSCL_LEAVE(OsclErrNoMemory);
    }

#if OSCL_MEM_FILL_WITH_PATTERN
    oscl_memset(iMemPool, 0x55, (iNumChunk*iChunkSizeMemAligned) + iChunkAlignment);
#endif

    // Set up the free mem chunk list vector
    iFreeMemChunkList.reserve(iNumChunk);
    uint8* chunkptr = (uint8*)iMemPool;

    // do the alignment if necessary
    if (iChunkAlignment > 0)
    {

        uint32 chunkptrAddr = (uint32) chunkptr;
        uint32 tempAlign = (iChunkAlignment - 1);
        uint32 difference = ((chunkptrAddr + tempAlign) & (~tempAlign)) - chunkptrAddr;

        chunkptr = chunkptr + difference;
        iMemPoolAligned = (OsclAny*) chunkptr;
    }
    else
    {
        iMemPoolAligned = iMemPool;
    }

    for (uint32 i = 0; i < iNumChunk; ++i)
    {
        iFreeMemChunkList.push_back((OsclAny*)chunkptr);
        chunkptr += iChunkSizeMemAligned;
    }
}
void pff_eos_test::HandleInformationalEventL(const CPVCmnAsyncInfoEvent& aEvent)
{
    int error = 0;

    switch (aEvent.GetEventType())
    {
        case PVT_INDICATION_INCOMING_TRACK:
            TPVChannelId id;

            if (((CPVCmnAsyncEvent&)aEvent).GetLocalBuffer()[0] == PV_VIDEO)
            {
                OSCL_TRY(error, iVideoAddSinkId = terminal->AddDataSinkL(*iVideoSink, id));
                if (error)
                {
                    test_is_true(false);
                    disconnect();
                }
            }

            if (((CPVCmnAsyncEvent&)aEvent).GetLocalBuffer()[0] == PV_AUDIO)
            {
                OSCL_TRY(error, iAudioAddSinkId = terminal->AddDataSinkL(*iAudioSink, id));
                if (error)
                {
                    test_is_true(false);
                    disconnect();
                }
            }
            break;

        case PVT_INDICATION_DISCONNECT:
            iAudioSourceAdded = false;
            iVideoSourceAdded = false;
            iAudioSinkAdded = false;
            iVideoSinkAdded = false;
            break;

        case PVT_INDICATION_CLOSE_TRACK:
            if (((CPVCmnAsyncEvent&)aEvent).GetLocalBuffer()[0] == PV_VIDEO)
            {
                if (((CPVCmnAsyncEvent&)aEvent).GetLocalBuffer()[1] == INCOMING)
                {
                    iVideoSinkAdded = false;
                }
                else
                {
                    iVideoSourceAdded = false;
                }
            }
            else if (((CPVCmnAsyncEvent&)aEvent).GetLocalBuffer()[0] == PV_AUDIO)
            {
                if (((CPVCmnAsyncEvent&)aEvent).GetLocalBuffer()[1] == INCOMING)
                {
                    iAudioSinkAdded = false;
                }
                else
                {
                    iAudioSourceAdded = false;
                }
            }
            break;

        case PVT_INDICATION_PLAY_EOS:
            if (((CPVCmnAsyncEvent&)aEvent).GetLocalBuffer()[0] == PV_VIDEO)
            {
                iVideoEOSRecv = true;
                if (iWaitForVideoEOS) check_eos();
            }
            else if (((CPVCmnAsyncEvent&)aEvent).GetLocalBuffer()[0] == PV_AUDIO)
            {
                iAudioEOSRecv = true;
                if (iWaitForAudioEOS) check_eos();
            }

            break;

        default:
            break;
    }
}
void pff_eos_test::CommandCompletedL(const CPVCmnCmdResp& aResponse)
{
    int error = 0;
    switch (aResponse.GetCmdType())
    {
        case PVT_COMMAND_INIT:
            if (aResponse.GetCmdStatus() == PVMFSuccess)
            {
                OSCL_TRY(error, terminal->InitPlayFileL(iFilename));
                if (error)
                {
                    test_is_true(false);
                    reset();
                }
            }
            else
            {
                test_is_true(false);
                RunIfNotReady();
            }
            break;

        case PVT_COMMAND_RESET:
            RunIfNotReady();
            break;

        case PVT_COMMAND_ADD_DATA_SOURCE:
            if (aResponse.GetCmdId() == iAudioAddSourceId)
            {
                if (aResponse.GetCmdStatus() == PVMFSuccess)
                {
                    iAudioSourceAdded = true;

                    if (check_audio_started() && check_video_started())
                    {
                        OSCL_TRY(error, terminal->StartPlayL());
                        if (error)
                        {
                            test_is_true(false);
                            disconnect();
                        }
                    }
                }
                else
                {
                    test_is_true(false);
                    disconnect();
                }
                iAudioAddSourceId = 0;
            }
            else if (aResponse.GetCmdId() == iVideoAddSourceId)
            {
                if (aResponse.GetCmdStatus() == PVMFSuccess)
                {
                    iVideoSourceAdded = true;

                    if (check_audio_started() && check_video_started())
                    {
                        OSCL_TRY(error, terminal->StartPlayL());
                        if (error)
                        {
                            test_is_true(false);
                            disconnect();
                        }
                    }
                }
                else
                {
                    test_is_true(false);
                    disconnect();
                }
                iVideoAddSourceId = 0;
            }
            break;

        case PVT_COMMAND_REMOVE_DATA_SOURCE:
            if (aResponse.GetCmdId() == iAudioRemoveSourceId)
            {
                iAudioRemoveSourceId = 0;
                iAudioSourceAdded = false;
            }
            else if (aResponse.GetCmdId() == iVideoRemoveSourceId)
            {
                iVideoRemoveSourceId = 0;
                iVideoSourceAdded = false;
            }
            break;

        case PVT_COMMAND_ADD_DATA_SINK:
            if (aResponse.GetCmdId() == iAudioAddSinkId)
            {
                if (aResponse.GetCmdStatus() == PVMFSuccess)
                {
                    iAudioSinkAdded = true;

                    if (check_audio_started() && check_video_started())
                    {
                        OSCL_TRY(error, terminal->StartPlayL());
                        if (error)
                        {
                            test_is_true(false);
                            disconnect();
                        }
                    }
                }
                else
                {
                    test_is_true(false);
                    disconnect();
                }
                iAudioAddSinkId = 0;
            }
            else if (aResponse.GetCmdId() == iVideoAddSinkId)
            {
                if (aResponse.GetCmdStatus() == PVMFSuccess)
                {
                    iVideoSinkAdded = true;

                    if (check_audio_started() && check_video_started())
                    {
                        OSCL_TRY(error, terminal->StartPlayL());
                        if (error)
                        {
                            test_is_true(false);
                            disconnect();
                        }
                    }
                }
                else
                {
                    test_is_true(false);
                    disconnect();
                }
                iVideoAddSinkId = 0;
            }
            break;

        case PVT_COMMAND_REMOVE_DATA_SINK:
            if (aResponse.GetCmdId() == iAudioRemoveSinkId)
            {
                iAudioRemoveSinkId = 0;
                iAudioSinkAdded = false;
            }
            else if (aResponse.GetCmdId() == iVideoRemoveSinkId)
            {
                iVideoRemoveSinkId  = 0;
                iVideoSinkAdded = false;
            }
            break;

        case PVT_COMMAND_CONNECT:
            if (aResponse.GetCmdStatus() == PVMFSuccess)
            {
                OSCL_TRY(error, iAudioAddSourceId = terminal->AddDataSourceL(*iAudioSource));
                if (error)
                {
                    test_is_true(false);
                    disconnect();
                }

                OSCL_TRY(error, iVideoAddSourceId = terminal->AddDataSourceL(*iVideoSource));
                if (error)
                {
                    test_is_true(false);
                    disconnect();
                }
            }
            else
            {
                test_is_true(false);
                reset();
            }
            break;

        case PVT_COMMAND_DISCONNECT:
            iAudioSourceAdded = false;
            iVideoSourceAdded = false;
            iAudioSinkAdded = false;
            iVideoSinkAdded = false;

            OSCL_TRY(error, terminal->ResetPlayFileL());
            if (error)
            {
                reset();
            }
            break;

        case PVT_COMMAND_INIT_PLAY_FILE:
            if (aResponse.GetCmdStatus() == PVMFSuccess)
            {
                OSCL_TRY(error, terminal->ConnectL(iConnectOptions));
                if (error)
                {
                    test_is_true(false);
                    reset();
                }
            }
            else
            {
                test_is_true(false);
                reset();
            }
            break;

        case PVT_COMMAND_RESET_PLAY_FILE:
            reset();
            break;

        case PVT_COMMAND_START_PLAY:
            if (aResponse.GetCmdStatus() == PVMFSuccess)
            {
                //Wait for EOS
            }
            else
            {
                test_is_true(false);
                disconnect();
            }
            break;

        case PVT_COMMAND_STOP_PLAY:
            iStopPlayLCalled = false;
            if (aResponse.GetCmdStatus() == PVMFSuccess)
            {
                iAudioEOSRecv = false;
                iVideoEOSRecv = false;
                iCurrentRun++;
                if (iCurrentRun < iMaxRuns)
                {
                    OSCL_TRY(error, terminal->StartPlayL());
                    if (error)
                    {
                        test_is_true(false);
                        disconnect();
                    }
                }
                else
                {
                    test_is_true(true);
                    disconnect();
                }
            }
            else
            {
                test_is_true(false);
                disconnect();
            }
            break;
    }
}