PvmfMediaInputNodeOutPort::PvmfMediaInputNodeOutPort(PvmfMediaInputNode* aNode, const char* aName)
        : OsclTimerObject(OsclActiveObject::EPriorityNominal, "PvmfMediaInputNodeOutPort")
        , PvmfPortBaseImpl(PVMF_MEDIAIO_NODE_OUTPUT_PORT_TAG
                           //this port handles its own port activity
                           , this, aName)
        , iNode(aNode)
        , iState(PvmfMediaInputNodeOutPort::PORT_STATE_BUFFERING)
        , inum_text_sample(0)
        , imax_num_sample(0)
{
    iNALType = 0;
    iCmdId = 0;
    iMioInfoErrorCmdId = 0;
    AddToScheduler();
    iFormatType = PVMF_MIME_FORMAT_UNKNOWN;
    iPeer = NULL;
    iWriteState = EWriteOK;
    iMediaDataAllocMemPool = OSCL_NEW(OsclMemPoolFixedChunkAllocator, (PVMIO_MEDIADATA_POOLNUM));
    iMediaDataMemPool = OSCL_NEW(OsclMemPoolFixedChunkAllocator, (PVMIO_MEDIADATA_POOLNUM));
    iMediaDataAlloc = OSCL_NEW(PvmfMediaInputDataBufferAlloc, (iMediaDataAllocMemPool));
    iDataPathLogger = PVLogger::GetLoggerObject("datapath.sourcenode");
#ifdef _TEST_AE_EROR_HANDLING
    iTimeStampJunk = 0x000FFFFF;
#endif
}
H223LowerLayer::H223LowerLayer(int32 aPortTag, TPVLoopbackMode aLoopbackMode)
        :   PvmfPortBaseImpl(aPortTag, this),
        OsclTimerObject(OsclActiveObject::EPriorityHigh, "H223AO"),
        iTimerIntervalNum(0),
        iMinTimerResolution(TIMER_RES),
        iObserver(NULL),
        iMemFragmentAlloc(NULL),
        iDispatchPacketAlloc(NULL),
        iMediaDataImplMemAlloc(NULL),
        iMediaMsgPoolAlloc(NULL),
        iSendPduSz(0),
        iPduSize(H223_DEFAULT_PDU_SIZE),
        iStuffingSize(0),
        iTimer("H223LL"),
        iLoopbackMode(aLoopbackMode),
        iTimerCnt(0),
        iBytesSent(0),
        iMediaDataAlloc(&iMemAlloc),
        iLogger(NULL),
        iDemuxBuffer(NULL),
        iDemuxBufferPos(NULL),
        iIdleSyncCheckBuffer(NULL)
{
    iLogger = PVLogger::GetLoggerObject("3g324m.h223.lowerlayer");
    AddToScheduler();
    InitParams();
    ResetStats();
}
PVAuthorEngineNodeUtility::PVAuthorEngineNodeUtility() :
        OsclTimerObject(OsclActiveObject::EPriorityNominal, "PVAuthorEngineNodeUtility"),
        iObserver(NULL),
        iCmdQueue(PVAE_CMD_VECTOR_RESERVE)
{
    iLogger = PVLogger::GetLoggerObject("PVAuthorEngineNodeUtility");
    AddToScheduler();
}
PvmfJBJitterBufferDurationTimer::PvmfJBJitterBufferDurationTimer(PvmfJBJitterBufferDurationTimerObserver* aObserver)
        : OsclTimerObject(OsclActiveObject::EPriorityNominal, "PvmfJBJitterBufferDurationTimer"),
        iJitterBufferDurationInMS(0),
        iObserver(aObserver),
        iStarted(false)
{
    iLogger = PVLogger::GetLoggerObject("PvmfJBJitterBufferDurationTimer");
    AddToScheduler();
}
PvmfFirewallPacketTimer::PvmfFirewallPacketTimer(PvmfFirewallPacketTimerObserver* aObserver)
        : OsclTimerObject(OsclActiveObject::EPriorityNominal, "PvmfFirewallPacketTimer"),
        iFirewallPacketRecvTimeOutInMS(0),
        iObserver(aObserver),
        iStarted(false)
{
    iLogger = PVLogger::GetLoggerObject("PvmfFirewallPacketTimer");
    AddToScheduler();
}
/////////////////////////////////////////////////////////////////////////////
// Add AO to the scheduler
/////////////////////////////////////////////////////////////////////////////
OSCL_EXPORT_REF void ThreadSafeCallbackAO::ThreadLogon()
{
    if (!IsAdded())
    {
        AddToScheduler();
    }

    iLogger = PVLogger::GetLoggerObject(iLoggerString);
}
PvmfJBInactivityTimer::PvmfJBInactivityTimer(PvmfJBInactivityTimerObserver* aObserver)
        : OsclTimerObject(OsclActiveObject::EPriorityNominal, "PvmfJBInactivityTimer"),
        iInactivityDurationInMS(DEFAULT_MAX_INACTIVITY_DURATION_IN_MS),
        iObserver(aObserver),
        iStarted(false)
{
    iLogger = PVLogger::GetLoggerObject("PvmfJBInactivityTimer");
    AddToScheduler();
}
void PVMFLoopbackIOPort::Construct(PVMFLoopbackNode*aNode)
{
    iNode = aNode;
    iWaiting = false;
    iLogger = PVLogger::GetLoggerObject("PVMFLoopbackPort");
    PvmiCapabilityAndConfigPortFormatImpl::Construct(
        PVMF_LOOPBACK_PORT_INPUT_FORMATS
        , PVMF_LOOPBACK_PORT_INPUT_FORMATS_VALTYPE);
    AddToScheduler();
}
//
// pv_metadata_engine_test section
//
void pv_metadata_engine_test::StartTest()
{
    AddToScheduler();
    iState = STATE_CREATE;

    // Retrieve the logger object
    iLogger = PVLogger::GetLoggerObject("PVMetadataEngineTest");
    iPerfLogger = PVLogger::GetLoggerObject("pvmetestdiagnostics");

    RunIfNotReady();
}
PVMFAvcEncPort::PVMFAvcEncPort(int32 aTag, PVMFAvcEncNode* aNode, int32 aPriority, const char* aName)
        :  PvmfPortBaseImpl(aTag, this,
                            PVMF_AVCENC_PORT_CAPACITY, PVMF_AVCENC_PORT_RESERVE, PVMF_AVCENC_PORT_THRESHOLD,
                            PVMF_AVCENC_PORT_CAPACITY, PVMF_AVCENC_PORT_RESERVE, PVMF_AVCENC_PORT_THRESHOLD, aName),
        OsclActiveObject(aPriority, "PVMFAvcEncPort"),
        iFormat(PVMF_FORMAT_UNKNOWN),
        iNode(aNode)
{
    AddToScheduler();
    iLogger = PVLogger::GetLoggerObject("PVMFAvcEncPort");
#if PVMF_PORT_BASE_IMPL_STATS
    oscl_memset((OsclAny*)&(PvmfPortBaseImpl::iStats), 0, sizeof(PvmfPortBaseImplStats));
#endif
}
OSCL_EXPORT_REF ThreadSafeQueue::ThreadSafeQueue()
        : OsclActiveObject(OsclActiveObject::EPriorityNominal, "ThreadSafeQueue")
{
    iObserver = NULL;
    iCounter = 1;
    if (OsclThread::GetId(iThreadId) != OsclProcStatus::SUCCESS_ERROR)
        OsclError::Leave(OsclErrSystemCallFailed);
#if USE_SEM_WAIT
    iQueueReadySem.Create();
#endif
    iQueueMut.Create();
    AddToScheduler();
    PendForExec();
    iQueueReadySem.Signal();
}
void OmxDecTestBase::StartTestApp()
{
    if (!IsAdded())
    {
        AddToScheduler();
    }

    RunIfNotReady();

    OsclExecScheduler* sched = OsclExecScheduler::Current();
    if (sched)
    {
        sched->StartScheduler();
    }
}
PvmfJBSessionDurationTimer::PvmfJBSessionDurationTimer(PvmfJBSessionDurationTimerObserver* aObserver)
        : OsclTimerObject(OsclActiveObject::EPriorityNominal, "PvmfJBSessionDurationTimer"),
        iCurrentMonitoringIntervalInMS(0),
        iSessionDurationInMS(0),
        iElapsedSessionDurationInMS(0),
        iObserver(aObserver),
        iStarted(false),
        iTimerStartTimeInMS(0),
        iMonitoringIntervalElapsed(0),
        iEstimatedServerClock(NULL),
        iEstimatedServClockValAtLastCancel(0),
        iExpectedEstimatedServClockValAtSessionEnd(0)
{
    iLogger = PVLogger::GetLoggerObject("PvmfJBSessionDurationTimer");
    iClockLoggerSessionDuration = PVLogger::GetLoggerObject("clock.streaming_manager.sessionduration");
    AddToScheduler();
    iClock.SetClockTimebase(iClockTimeBase);
}
PVMp4FFComposerPort::PVMp4FFComposerPort(int32 aTag, PVMp4FFComposerNode* aNode, int32 aPriority, const char* aName)
        :   PvmfPortBaseImpl(aTag, this,
                             PVMF_MP4FFCN_PORT_CAPACITY, PVMF_MP4FFCN_PORT_RESERVE, PVMF_MP4FFCN_PORT_THRESHOLD,
                             PVMF_MP4FFCN_PORT_CAPACITY, PVMF_MP4FFCN_PORT_RESERVE, PVMF_MP4FFCN_PORT_THRESHOLD, aName),
        OsclActiveObject(aPriority, "PVMp4FFComposerPort"),
        iNode(aNode),
        iTrackId(0),
        iFormat(PVMF_MIME_FORMAT_UNKNOWN),
        iCodecType(0),
        iReferencePort(NULL),
        iLastTS(0),
        iEndOfDataReached(false)
{
    AddToScheduler();
    iLogger = PVLogger::GetLoggerObject("PVMp4FFComposerPort");
    oscl_memset((OsclAny*)&iFormatSpecificConfig, 0, sizeof(PVMP4FFCNFormatSpecificConfig));
    memfrag_pps = NULL;
}
/* ///////////////////////////////////////////////////////////////////////// */
bool CPVM4VEncoder::Construct(int32 aThreadId)
{
    oscl_memset((void *)&iEncoderControl, 0, sizeof(VideoEncControls));
    iInitialized = false;
    iObserver = NULL;
    iNumOutputData = 0;
    iYUVIn = NULL;
    for (int i = 0; i < KCVEIMaxOutputBuffer; i++)
    {
        iOutputData[i] = NULL;
    }
    iState = EIdle;

    if (aThreadId >= 0)
        AddToScheduler();

    return true;
}
bool OsclDNSMethod::StartMethod(int32 aTimeoutMsec)
{
    //make sure there's not already a request
    //in progress
    if (IsAdded() || iDNSRequestAO->IsAdded())
        return false;

    AddToScheduler();
    iDNSRequestAO->AddToScheduler();

    //set the timeout
    if (aTimeoutMsec > 0)
        After(aTimeoutMsec*1000);

    iDNSRequestAO->iSocketError = 0;

    return true;
}
PVMFRecognizerRegistryImpl::PVMFRecognizerRegistryImpl() :
        OsclTimerObject(OsclActiveObject::EPriorityNominal, "PVMFRecognizerRegistryImpl")
{
    AddToScheduler();

    iRefCount = 1;

    iNextSessionId = 0;
    iRecognizerSessionList.reserve(1);

    iNextCommandId = 0;
    iRecognizerPendingCmdList.reserve(2);
    iRecognizerCurrentCmd.reserve(1);
    iRecognizerCmdToCancel.reserve(1);

    iDataStreamFactory = NULL;
    iDataStream = NULL;
    oRecognizePending = false;
    iDataStreamCallBackStatus = PVMFSuccess;

    iLogger = PVLogger::GetLoggerObject("PVMFRecognizer");
}
OSCL_EXPORT_REF
PVMIExternalDownloadSimulator::PVMIExternalDownloadSimulator(PVMIExternalDownloadSimulatorParams& aParams)
        : OsclTimerObject(OsclActiveObject::EPriorityNominal, "PVMIExternalDownloadSimulator")
{
    if ((aParams.iSizeUpdateIntervalInMS == 0) ||
            (aParams.iDownloadRateInKbps == 0) ||
            (aParams.iFileSizeInBytes == 0))
    {
        OSCL_ASSERT(false);
        OSCL_LEAVE(OsclErrArgument);
    }
    iExtensionRefCount = 0;
    iFileSizeInBytes = aParams.iFileSizeInBytes;
    iDownloadRateInKbps = aParams.iDownloadRateInKbps;
    iSizeUpdateIntervalInMS = aParams.iSizeUpdateIntervalInMS;
    iObserverVec.reserve(128);
    iDownloadedFileSizeInBytes = 0;
    iDownloadComplete = false;
    iLogger = PVLogger::GetLoggerObject("PVMIExternalDownloadSimulator");
    iDownloadClock.SetClockTimebase(iDownloadClockTimebase);
    AddToScheduler();
}
bool OsclSocketMethod::StartMethod(int32 aTimeoutMsec)
{
    //make sure there's not already a request
    //in progress
    if (iSocketRequestAO->IsBusy()
            || IsBusy())
        return false;

    if (!iSocketRequestAO->IsAdded())
        iSocketRequestAO->AddToScheduler();

    //set the timeout if any.  Timeout <= 0 indicates infinite wait.
    if (aTimeoutMsec > 0)
    {
        if (!IsAdded())
            AddToScheduler();
        After(aTimeoutMsec*MSEC_TO_MICROSEC);
    }

    iSocketRequestAO->iSocketError = 0;

    return true;
}
OSCL_EXPORT_REF void PVMIExternalDownloadFileMonitor::MonitorFile
(
    const char*  aFileName,
    uint32       aTimeOutms
)
{
    if (iState == STATE_MONITORING)
    {
        //Already monitoring a file.
        OSCL_LEAVE(OsclErrGeneral);
    }

    iDownloadComplete = false;
    iBytesDownloaded  = 0;
    iState = STATE_OPENING;
    iLastChange = OsclTickCount::TicksToMsec(OsclTickCount::TickCount());
    iTimeOutms = aTimeOutms;
    iFileServer.Connect();
    iFileName = aFileName;
    //Run immediately.
    AddToScheduler();
    RunIfNotReady();
}
void pv_mediainput_async_test_delete::StartTest()
{
    AddToScheduler();
    iState = PVAE_CMD_CREATE;
    RunIfNotReady();
}
// Stream-in ctor
CompositionOffsetAtom::CompositionOffsetAtom(MP4_FF_FILE *fp,
        uint32 mediaType,
        uint32 size,
        uint32 type,
        OSCL_wString& filename,
        uint32 parsingMode):
        FullAtom(fp, size, type),
        OsclTimerObject(OsclActiveObject::EPriorityNominal, "CompositionOffsetAtom")
{
    _psampleCountVec = NULL;
    _psampleOffsetVec = NULL;
    MT_SampleCount  = NULL;
    MT_EntryCount  = NULL;
    iMarkerTableCreation = false;
    MT_Table_Size = 0;

    _currGetSampleCount = 0;
    _currGetIndex = -1;
    _currGetTimeOffset = 0;
    _currPeekSampleCount = 0;
    _currPeekIndex = -1;
    _currPeekTimeOffset = 0;

    MT_Counter = 1;
    addSampleCount = 0;
    prevSampleCount = 0;
    entrycountTraversed = 0;
    refSample = MT_SAMPLECOUNT_INCREMENT;
    MT_j = 1;

    _mediaType = mediaType;
    _parsed_entry_cnt = 0;
    _fileptr = NULL;
    _parsing_mode = 0;
    _parsing_mode = parsingMode;


    _stbl_buff_size = CTTS_MIN_SAMPLE_TABLE_SIZE;
    _next_buff_number = 0;
    _curr_buff_number = 0;
    _curr_entry_point = 0;
    _stbl_fptr_vec = NULL;

    iLogger = PVLogger::GetLoggerObject("mp4ffparser");
    iStateVarLogger = PVLogger::GetLoggerObject("mp4ffparser_mediasamplestats");
    iParsedDataLogger = PVLogger::GetLoggerObject("mp4ffparser_parseddata");

    iMarkerTableCreation = false;

    /* Add this AO to the scheduler */
    if (OsclExecScheduler::Current() != NULL)
    {
        if (!IsAdded())
        {
            AddToScheduler();
        }
    }

    if (_success)
    {
        if (!AtomUtils::read32(fp, _entryCount))
        {
            _success = false;
        }

        PVMF_MP4FFPARSER_LOGPARSEDINFO((0, "CompositionOffsetAtom::CompositionOffsetAtom- _entryCount =%d", _entryCount));
        uint32 dataSize = _size - (DEFAULT_FULL_ATOM_SIZE + 4);

        uint32 entrySize = (4 + 4);

        if ((_entryCount*entrySize) > dataSize)
        {
            _success = false;
        }

        if (_success)
        {
            if (_entryCount > 0)
            {
                if (parsingMode == 1)
                {
                    // cache size is 4K so that optimization
                    // should work if entry_count is greater than 4K
                    if (_entryCount > _stbl_buff_size)
                    {

                        uint32 fptrBuffSize = (_entryCount / _stbl_buff_size) + 1;

                        PV_MP4_FF_ARRAY_NEW(NULL, uint32, (fptrBuffSize), _stbl_fptr_vec);
                        if (_stbl_fptr_vec == NULL)
                        {
                            _success = false;
                            _mp4ErrorCode = MEMORY_ALLOCATION_FAILED;
                            return;
                        }


                        PV_MP4_FF_ARRAY_NEW(NULL, uint32, (_stbl_buff_size), _psampleCountVec);
                        if (_psampleCountVec == NULL)
                        {
                            _success = false;
                            _mp4ErrorCode = MEMORY_ALLOCATION_FAILED;
                            return;
                        }


                        PV_MP4_FF_ARRAY_NEW(NULL, uint32, (_stbl_buff_size), _psampleOffsetVec);
                        if (_psampleOffsetVec == NULL)
                        {
                            PV_MP4_ARRAY_DELETE(NULL, _psampleOffsetVec);
                            _psampleOffsetVec = NULL;
                            _success = false;
                            _mp4ErrorCode = MEMORY_ALLOCATION_FAILED;
                            return;
                        }

                        for (uint32 idx = 0; idx < _stbl_buff_size; idx++)  //initialization
                        {
                            _psampleCountVec[idx] = 0;
                            _psampleOffsetVec[idx] = 0;
                        }

                        OsclAny* ptr = (MP4_FF_FILE *)(oscl_malloc(sizeof(MP4_FF_FILE)));
                        if (ptr == NULL)
                        {
                            _success = false;
                            _mp4ErrorCode = MEMORY_ALLOCATION_FAILED;
                            return;
                        }

                        _fileptr = OSCL_PLACEMENT_NEW(ptr, MP4_FF_FILE());
                        _fileptr->_fileServSession = fp->_fileServSession;
                        _fileptr->_pvfile.SetCPM(fp->_pvfile.GetCPM());
                        _fileptr->_pvfile.SetFileHandle(fp->_pvfile.iFileHandle);
                        if (AtomUtils::OpenMP4File(filename,
                                                   Oscl_File::MODE_READ | Oscl_File::MODE_BINARY,
                                                   _fileptr) != 0)
                        {
                            _success = false;
                            _mp4ErrorCode = FILE_OPEN_FAILED;
                        }

                        _fileptr->_fileSize = fp->_fileSize;

                        int32 _head_offset = AtomUtils::getCurrentFilePosition(fp);
                        AtomUtils::seekFromCurrPos(fp, dataSize);
                        AtomUtils::seekFromStart(_fileptr, _head_offset);

                        return;
                    }
                    else
                    {
                        _parsing_mode = 0;
                        _stbl_buff_size = _entryCount;
                    }
                }
                else
                {
                    _stbl_buff_size = _entryCount;
                }

                PV_MP4_FF_ARRAY_NEW(NULL, uint32, (_entryCount), _psampleCountVec);
                if (_psampleCountVec == NULL)
                {
                    _success = false;
                    _mp4ErrorCode = MEMORY_ALLOCATION_FAILED;
                    return;
                }

                PV_MP4_FF_ARRAY_NEW(NULL, uint32, (_entryCount), _psampleOffsetVec);
                if (_psampleOffsetVec == NULL)
                {
                    PV_MP4_ARRAY_DELETE(NULL, _psampleOffsetVec);
                    _psampleOffsetVec = NULL;
                    _success = false;
                    _mp4ErrorCode = MEMORY_ALLOCATION_FAILED;
                    return;
                }

                for (uint32 idx = 0; idx < _entryCount; idx++)  //initialization
                {
                    _psampleCountVec[idx] = 0;
                    _psampleOffsetVec[idx] = 0;
                }

                uint32 number = 0;
                uint32 offset = 0;
                for (_parsed_entry_cnt = 0; _parsed_entry_cnt < _entryCount; _parsed_entry_cnt++)
                {
                    if (!AtomUtils::read32(fp, number))
                    {
                        _success = false;
                        break;
                    }
                    if (!AtomUtils::read32(fp, offset))
                    {
                        _success = false;
                        break;
                    }
                    _psampleCountVec[_parsed_entry_cnt] = (number);
                    _psampleOffsetVec[_parsed_entry_cnt] = (offset);
                }
            }
        }

        if (!_success)
        {
            _mp4ErrorCode = READ_TIME_TO_SAMPLE_ATOM_FAILED;
        }
    }
    else
    {
        if (_mp4ErrorCode != ATOM_VERSION_NOT_SUPPORTED)
            _mp4ErrorCode = READ_TIME_TO_SAMPLE_ATOM_FAILED;
    }
}
int32 OsclSocketServI::StartServImp()
{
#if(PV_SOCKET_SERVER_IS_THREAD)

    //setup the loopback socket and/or polling interval.
    iLoopbackSocket.iEnable = false;
    iSelectPollIntervalMsec = 0;

    //check the select timeout in the configuration.
    int32 selectTimeoutMsec = PV_SOCKET_SERVER_SELECT_TIMEOUT_MSEC;
    if (selectTimeoutMsec <= 0)
    {
        //non-polling option selected.
        //create the select cancel pipe.
        iLoopbackSocket.Init(this);

        //if loopback socket isn't available, we must poll.
        if (!iLoopbackSocket.iEnable)
            iSelectPollIntervalMsec = 10;
    }
    else
    {
        //polling option selected.
        iSelectPollIntervalMsec = selectTimeoutMsec;
#if(PV_SOCKET_SERVER_SELECT_LOOPBACK_SOCKET)
        //create the loopback socket.
        iLoopbackSocket.Init(this);
#endif
    }

    //Start the server thread.
    OsclThread thread;
    OsclProcStatus::eOsclProcError err = thread.Create((TOsclThreadFuncPtr)sockthreadmain,
                                         1024,
                                         (TOsclThreadFuncArg)this);
    if (err != OsclErrNone)
        return OsclErrGeneral;

    thread.SetPriority(PV_SOCKET_SERVER_THREAD_PRIORITY);

    //wait til thread starts
    iStart.Wait();

    return OsclErrNone;

#else//PV_SOCKET_SERVER_IS_THREAD

    //Socket server AO startup.

    iLoopbackSocket.iEnable = false;

    ServerEntry();

    if (!IsAdded())
    {
        AddToScheduler();
    }
    return OsclErrNone;

#endif //PV_SOCKET_SERVER_IS_THREAD
}