OSCL_EXPORT_REF void CPVInterfaceProxy::ConstructL(uint32 nreserve1, uint32 nreserve2, int32 handlerPri, int32 notifierPri)
{
    // Create the semaphores and critical sections
    if (iInitSem.Create() != OsclProcStatus::SUCCESS_ERROR
            || iExitedSem.Create() != OsclProcStatus::SUCCESS_ERROR
            || iCounterCrit.Create() != OsclProcStatus::SUCCESS_ERROR
            || iHandlerQueueCrit.Create() != OsclProcStatus::SUCCESS_ERROR
            || iNotifierQueueCrit.Create() != OsclProcStatus::SUCCESS_ERROR
            || iProxyListCrit.Create() != OsclProcStatus::SUCCESS_ERROR)
    {
        OsclError::Leave(OsclErrGeneral);
    }
    //reserve space in vectors...
    if (nreserve1 > 0)
        iProxyList.reserve(nreserve1);
    if (nreserve2 > 0)
    {
        iCommandQueue.reserve(nreserve2);
//      iNotificationQueue.reserve(nreserve2);
    }

    //create handler
    OsclAny *ptr = iAlloc->ALLOCATE(sizeof(CPVInterfaceProxyHandler));
    OsclError::LeaveIfNull(ptr);
    iHandler = OSCL_PLACEMENT_NEW(ptr, CPVInterfaceProxyHandler(this, handlerPri));

    //create notifier
    ptr = iAlloc->ALLOCATE(sizeof(CPVInterfaceProxyNotifier));
    OsclError::LeaveIfNull(ptr);
    iNotifier = OSCL_PLACEMENT_NEW(ptr, CPVInterfaceProxyNotifier(this, notifierPri));
}
OSCL_EXPORT_REF OsclSharedPtr<PVMFMediaCmd>
PVMFMediaCmd::createMediaCmd(const PVMFMediaMsgHeader* msgHeader,
                             Oscl_DefAlloc* gen_alloc)
{
    // allocate enough room
    uint8* my_ptr;
    OsclRefCounter* my_refcnt;

    uint aligned_media_data_size =
        oscl_mem_aligned_size(sizeof(PVMFMediaCmd));

    // must compute the aligned size for PVMFMediaCmd.
    if (gen_alloc)
    {
        uint aligned_refcnt_size =
            oscl_mem_aligned_size(sizeof(OsclRefCounterDA));
        uint aligned_cleanup_size =
            oscl_mem_aligned_size(sizeof(MediaCmdCleanupDA));

        my_ptr = (uint8*) gen_alloc->ALLOCATE(aligned_refcnt_size +
                                              aligned_cleanup_size +
                                              aligned_media_data_size +
                                              sizeof(PVMFMediaMsgHeader));

        MediaCmdCleanupDA *my_cleanup =
            OSCL_PLACEMENT_NEW(my_ptr + aligned_refcnt_size, MediaCmdCleanupDA(gen_alloc));
        my_refcnt = OSCL_PLACEMENT_NEW(my_ptr, OsclRefCounterDA(my_ptr, my_cleanup));
        my_ptr += aligned_refcnt_size + aligned_cleanup_size;

    }
    else
    {
        OsclMemAllocator my_alloc;
        uint aligned_refcnt_size =
            oscl_mem_aligned_size(sizeof(OsclRefCounterSA<MediaCmdCleanupSA>));
        my_ptr = (uint8*) my_alloc.ALLOCATE(aligned_refcnt_size +
                                            aligned_media_data_size +
                                            sizeof(PVMFMediaMsgHeader));
        my_refcnt = OSCL_PLACEMENT_NEW(my_ptr, OsclRefCounterSA<MediaCmdCleanupSA>(my_ptr));
        my_ptr += aligned_refcnt_size;
    }

    PVMFMediaCmd *media_cmd_ptr = OSCL_PLACEMENT_NEW(my_ptr, PVMFMediaCmd());

    media_cmd_ptr->hdr_ptr =
        OSCL_PLACEMENT_NEW(my_ptr + aligned_media_data_size, PVMFMediaMsgHeader());

    media_cmd_ptr->hdr_ptr->timestamp = msgHeader->timestamp;
    media_cmd_ptr->hdr_ptr->duration = msgHeader->duration;
    media_cmd_ptr->hdr_ptr->stream_id = msgHeader->stream_id;
    media_cmd_ptr->hdr_ptr->seqnum    = msgHeader->seqnum;
    media_cmd_ptr->hdr_ptr->format_id = msgHeader->format_id;
    media_cmd_ptr->hdr_ptr->format_spec_info = msgHeader->format_spec_info;

    OsclSharedPtr<PVMFMediaCmd> shared_media_data(media_cmd_ptr, my_refcnt);

    return shared_media_data;
}
OSCL_EXPORT_REF OMX_ERRORTYPE ProxyApplication_OMX::ProxySetParameter(
    OMX_IN  OMX_HANDLETYPE hComponent,
    OMX_IN  OMX_INDEXTYPE nParamIndex,
    OMX_IN  OMX_PTR ComponentParameterStructure)
{
    OsclAny *ptr = iMemoryPool->allocate(MAX_SIZE_OF_OMX_PROXY_MSG * sizeof(uint8));
    if (NULL == ptr)
    {
        return OMX_ErrorInsufficientResources;
    }

    SetParameterMsg* Msg = OSCL_PLACEMENT_NEW(ptr, SetParameterMsg(hComponent, nParamIndex, ComponentParameterStructure));



    iMemCmd++;
    iNumClientMsg++;

    if ((ipProxy->SendCommand(iProxyId, SET_PARAMS, (OsclAny*) Msg)) == false)
    {
        return OMX_ErrorUndefined;
    }

    iInitSemOmx.Wait();

    return ReturnValueOmxApi;
}
OSCL_EXPORT_REF OMX_ERRORTYPE ProxyApplication_OMX::ProxyGetState(
    OMX_IN  OMX_HANDLETYPE hComponent,
    OMX_OUT OMX_STATETYPE* pState)
{

    OsclAny *ptr = iMemoryPool->allocate(MAX_SIZE_OF_OMX_PROXY_MSG * sizeof(uint8));
    if (NULL == ptr)
    {
        return OMX_ErrorInsufficientResources;
    }

    GetStateMsg* Msg = OSCL_PLACEMENT_NEW(ptr, GetStateMsg(hComponent, pState));


    iMemCmd++;
    iNumClientMsg++;

    if ((ipProxy->SendCommand(iProxyId, GET_ST, (OsclAny*) Msg)) == false)
    {
        return OMX_ErrorUndefined;
    }

    iInitSemOmx.Wait();
    return ReturnValueOmxApi;
}
OSCL_EXPORT_REF OMX_ERRORTYPE ProxyApplication_OMX::ProxySendCommand(
    OMX_IN  OMX_HANDLETYPE hComponent,
    OMX_IN  OMX_COMMANDTYPE Cmd,
    OMX_IN  OMX_U32 nParam,
    OMX_IN  OMX_PTR pCmdData)
{
    OsclAny *ptr = iMemoryPool->allocate(MAX_SIZE_OF_OMX_PROXY_MSG * sizeof(uint8));
    if (NULL == ptr)
    {
        return OMX_ErrorInsufficientResources;
    }

    SetCommMsg* Msg = OSCL_PLACEMENT_NEW(ptr, SetCommMsg(hComponent, Cmd, nParam, pCmdData));

    iMemCmd++;
    iNumClientMsg++;

    if ((ipProxy->SendCommand(iProxyId, SEND_COMM, (OsclAny*) Msg)) == false)
    {
        return OMX_ErrorUndefined;
    }
    iInitSemOmx.Wait();

    return ReturnValueOmxApi;
}
OSCL_EXPORT_REF OMX_ERRORTYPE ProxyApplication_OMX::ProxyGetHandle(
    OMX_OUT OMX_HANDLETYPE* pHandle,
    OMX_IN  OMX_STRING cComponentName, OMX_IN  OMX_PTR pAppData,
    OMX_IN  OMX_CALLBACKTYPE* pCallBacks)
{
    OsclAny *ptr = iMemoryPool->allocate(MAX_SIZE_OF_OMX_PROXY_MSG * sizeof(uint8));
    if (NULL == ptr)
    {
        return OMX_ErrorInsufficientResources;
    }

    GetHandleMsg* Msg = OSCL_PLACEMENT_NEW(ptr, GetHandleMsg(pHandle, cComponentName, pAppData, pCallBacks));


    iMemCmd++;
    iNumClientMsg++;

    if ((ipProxy->SendCommand(iProxyId, GET_HANDLE, (OsclAny*) Msg)) == false)
    {
        return OMX_ErrorUndefined;
    }

    iInitSemOmx.Wait();
    return ReturnValueOmxApi;
}
OSCL_EXPORT_REF CPVInterfaceProxy * CPVInterfaceProxy::NewL(
    PVProxiedEngine& app
    , Oscl_DefAlloc *alloc
    , int32 stacksize
    , uint32 nreserve1
    , uint32 nreserve2
    , int32 handlerPri
    , int32 notifierPri)
//called under app thread context
{
    OsclMemAllocator defallocL;
    OsclAny *ptr = NULL;
    if (alloc)
    {
        ptr = alloc->ALLOCATE(sizeof(CPVInterfaceProxy));
        OsclError::LeaveIfNull(ptr);
    }
    else
    {
        ptr = defallocL.ALLOCATE(sizeof(CPVInterfaceProxy));
    }
    CPVInterfaceProxy *self = OSCL_PLACEMENT_NEW(ptr, CPVInterfaceProxy(app, alloc, stacksize));
    int32 err;
    err = self->CPVIConstructL(nreserve1, nreserve2, handlerPri, notifierPri);
    if (err != OSCL_ERR_NONE)
    {
        self->Delete();
        return NULL;
    }
    return self;
}
OSCL_EXPORT_REF OMX_ERRORTYPE ProxyApplication_OMX::ProxyFreeBuffer(
    OMX_IN  OMX_HANDLETYPE hComponent,
    OMX_IN  OMX_U32 nPortIndex,
    OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer)
{
    OsclAny *ptr = iMemoryPool->allocate(MAX_SIZE_OF_OMX_PROXY_MSG * sizeof(uint8));
    if (NULL == ptr)
    {
        return OMX_ErrorInsufficientResources;
    }

    FreeBufMsg* Msg = OSCL_PLACEMENT_NEW(ptr, FreeBufMsg(hComponent, nPortIndex, pBuffer));


    iMemCmd++;
    iNumClientMsg++;

    if ((ipProxy->SendCommand(iProxyId, FREE_BUF, (OsclAny*) Msg)) == false)
    {
        return OMX_ErrorUndefined;
    }

    iInitSemOmx.Wait();
    return ReturnValueOmxApi;
}
OSCL_EXPORT_REF OMX_ERRORTYPE ProxyApplication_OMX::ProxyFillThisBuffer(
    OMX_IN  OMX_HANDLETYPE hComponent,
    OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer)
{
    OsclAny *ptr = iMemoryPool->allocate(MAX_SIZE_OF_OMX_PROXY_MSG * sizeof(uint8));
    if (NULL == ptr)
    {
        return OMX_ErrorInsufficientResources;
    }


    FillBufMsg* Msg = OSCL_PLACEMENT_NEW(ptr, FillBufMsg(hComponent, pBuffer));

    iMemCmd++;
    iNumClientMsg++;

    if ((ipProxy->SendCommand(iProxyId, FILL_BUF, (OsclAny*) Msg)) == false)
    {
        return OMX_ErrorUndefined;
    }

    // Do not use wait/signal semaphore for queuing input/output buffers
    // allow the client thread to keep going without having to wait for the status (assume its OK)



    return ReturnValueOmxApi;
}
OsclDNSI* OsclDNSI::NewL(Oscl_DefAlloc &a)
{
    OsclAny*p = a.ALLOCATE(sizeof(OsclDNSI));
    OsclError::LeaveIfNull(p);
    OsclDNSI *self = OSCL_PLACEMENT_NEW(p, OsclDNSI(a));
    OsclError::LeaveIfNull(self);
    return self;
}
OsclSocketServI* OsclSocketServI::NewL(Oscl_DefAlloc &a)
{
    OsclAny*p = a.ALLOCATE(sizeof(OsclSocketServI));
    OsclError::LeaveIfNull(p);
    OsclSocketServI *self = OSCL_PLACEMENT_NEW(p, OsclSocketServI(a));
    OsclError::LeaveIfNull(self);
    OsclError::PushL(self);
    self->ConstructL();
    OsclError::Pop();
    return self;
}
OsclAcceptMethod *OsclAcceptMethod::NewL(OsclIPSocketI& c)
{
    OsclAny*p = c.Alloc().ALLOCATE(sizeof(OsclAcceptMethod));
    OsclError::LeaveIfNull(p);
    OsclAcceptMethod* self = OSCL_PLACEMENT_NEW(p, OsclAcceptMethod(c));
    OsclError::LeaveIfNull(self);
    OsclError::PushL(self);
    self->ConstructL();
    OsclError::Pop();
    return self;
}
void OsclAcceptMethod::ConstructL()
{
    OsclAny*p = iContainer.Alloc().ALLOCATE(sizeof(OsclAcceptRequest));
    OsclError::LeaveIfNull(p);
    OsclAcceptRequest* self = OSCL_PLACEMENT_NEW(p, OsclAcceptRequest(*this));
    OsclError::LeaveIfNull(self);
    OsclError::PushL(self);
    self->ConstructL();
    OsclError::Pop();
    iSocketRequestAO = self;
    OsclSocketMethod::ConstructL(iSocketRequestAO);
}
OsclGetHostByNameRequest *OsclGetHostByNameRequest::NewL(
    OsclDNSI *aDNS,
    OsclGetHostByNameMethod *aMethod)
{
    OsclAny*p = aMethod->iAlloc.ALLOCATE(sizeof(OsclGetHostByNameRequest));
    OsclError::LeaveIfNull(p);
    OsclGetHostByNameRequest* self = OSCL_PLACEMENT_NEW(p, OsclGetHostByNameRequest());
    OsclError::LeaveIfNull(self);
    OsclError::PushL(self);
    self->ConstructL(aDNS,  aMethod);
    OsclError::Pop();
    return self;
}
void OsclAcceptRequest::Accept(OsclSocketI &aSocket)
{
    OsclAny *p = NewRequest(sizeof(AcceptParam));
    if (!p)
        PendComplete(OsclErrNoMemory);
    else
    {
        iParam = OSCL_PLACEMENT_NEW(p, AcceptParam(aSocket));
        if (!iParam)
            PendComplete(OsclErrNoMemory);
        else
            SocketI()->Accept(*Param(), *this);
    }
}
OSCL_EXPORT_REF OsclDNS* OsclDNS::NewL(
    Oscl_DefAlloc &alloc,
    OsclSocketServ& serv,
    OsclDNSObserver& obs,
    uint32 id)
{
    OsclAny *p = alloc.ALLOCATE(sizeof(OsclDNS));
    OsclError::LeaveIfNull(p);
    OsclDNS *self = OSCL_PLACEMENT_NEW(p, OsclDNS(alloc, obs, id));
    OsclError::PushL(self);
    self->ConstructL(serv);
    OsclError::Pop();
    return self;
}
OsclGetHostByNameMethod *OsclGetHostByNameMethod::NewL(Oscl_DefAlloc &a,
        OsclDNSI *aDNS,
        OsclDNSObserver *aObserver,
        uint32 aId)
{
    OsclAny*p = a.ALLOCATE(sizeof(OsclGetHostByNameMethod));
    OsclError::LeaveIfNull(p);
    OsclGetHostByNameMethod* self = OSCL_PLACEMENT_NEW(p, OsclGetHostByNameMethod(a));
    OsclError::LeaveIfNull(self);
    OsclError::PushL(self);
    self->ConstructL(aDNS, aObserver, aId);
    OsclError::Pop();
    return self;
}
void OsclSendToRequest::SendTo(const uint8* &aPtr, uint32 aLen, OsclNetworkAddress &aAddress)
{
    OsclAny *p = NewRequest(sizeof(SendToParam));
    if (!p)
        PendComplete(OsclErrNoMemory);
    else
    {
        iParam = OSCL_PLACEMENT_NEW(p, SendToParam(aPtr, aLen, aAddress, 0));
        if (!iParam)
            PendComplete(OsclErrNoMemory);
        else
            SocketI()->SendTo(*Param(), *this);
    }
}
void OsclConnectRequest::Connect(OsclNetworkAddress &aAddress)
{
    OsclAny *p = NewRequest(sizeof(ConnectParam));
    if (!p)
        PendComplete(OsclErrNoMemory);
    else
    {
        iParam = OSCL_PLACEMENT_NEW(p, ConnectParam(aAddress));
        if (!iParam)
            PendComplete(OsclErrNoMemory);
        else
        {
            SocketI()->Connect(*Param(), *this);
        }
    }
}
void OsclMemGlobalAuditObject::createGlobalMemAuditObject()
{
    audit_type* audit = (audit_type*)OsclSingletonRegistryEx::lockAndGetInstance(OSCL_SINGLETON_ID_OSCLMEM);
    if (audit)
    {
        audit->iRefCount++;
    }
    else
    {
        OsclAny *ptr = _oscl_malloc(sizeof(audit_type));
        if (!ptr)
        {
            OsclSingletonRegistryEx::registerInstanceAndUnlock(audit, OSCL_SINGLETON_ID_OSCLMEM);
            OsclError::Leave(OsclErrNoMemory);
            return;
        }
        audit = OSCL_PLACEMENT_NEW(ptr, audit_type());
    }
    OsclSingletonRegistryEx::registerInstanceAndUnlock(audit, OSCL_SINGLETON_ID_OSCLMEM);
}
OSCL_EXPORT_REF ThreadSafeMemPoolFixedChunkAllocator *ThreadSafeMemPoolFixedChunkAllocator::Create(const uint32 numchunk, const uint32 chunksize, Oscl_DefAlloc *gen_alloc)
{

    OsclAny *ptr = NULL;
    if (gen_alloc)
    {
        ptr = gen_alloc->ALLOCATE(sizeof(ThreadSafeMemPoolFixedChunkAllocator));


    }
    else
    {
        ptr = OSCL_MALLOC(sizeof(ThreadSafeMemPoolFixedChunkAllocator));

    }

    if (ptr == NULL)
    {
        return NULL;
    }

    ThreadSafeMemPoolFixedChunkAllocator *self = OSCL_PLACEMENT_NEW(ptr, ThreadSafeMemPoolFixedChunkAllocator(numchunk, chunksize, gen_alloc));
    return self;
}
// Stream-in ctor
TimeToSampleAtom::TimeToSampleAtom(MP4_FF_FILE *fp,
                                   uint32 mediaType,
                                   uint32 size,
                                   uint32 type,
                                   OSCL_wString& filename,
                                   uint32 parsingMode)
        : FullAtom(fp, size, type)
{

    _psampleCountVec = NULL;
    _psampleDeltaVec = NULL;

    _currGetSampleCount = 0;
    _currGetIndex = -1;
    _currGetTimeDelta = 0;
    _currPeekSampleCount = 0;
    _currPeekIndex = -1;
    _currPeekTimeDelta = 0;

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

    _stbl_buff_size = MAX_CACHED_TABLE_ENTRIES_FILE;
    _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");


    if (_success)
    {
        if (!AtomUtils::read32(fp, _entryCount))
        {
            _success = false;
        }
        PVMF_MP4FFPARSER_LOGPARSEDINFO((0, "TimeToSampleAtom::TimeToSampleAtom- _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), _psampleDeltaVec);
                        if (_psampleDeltaVec == NULL)
                        {
                            PV_MP4_ARRAY_DELETE(NULL, _psampleDeltaVec);
                            _psampleDeltaVec = NULL;
                            _success = false;
                            _mp4ErrorCode = MEMORY_ALLOCATION_FAILED;
                            return;
                        }
                        for (uint32 idx = 0; idx < _stbl_buff_size; idx++)  //initialization
                        {
                            _psampleCountVec[idx] = 0;
                            _psampleDeltaVec[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), _psampleDeltaVec);
                if (_psampleDeltaVec == NULL)
                {
                    PV_MP4_ARRAY_DELETE(NULL, _psampleDeltaVec);
                    _psampleDeltaVec = NULL;
                    _success = false;
                    _mp4ErrorCode = MEMORY_ALLOCATION_FAILED;
                    return;
                }
                for (uint32 idx = 0; idx < _entryCount; idx++)  //initialization
                {
                    _psampleCountVec[idx] = 0;
                    _psampleDeltaVec[idx] = 0;
                }

                uint32 number = 0;
                uint32 delta = 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, delta))
                    {
                        _success = false;
                        break;
                    }
                    _psampleCountVec[_parsed_entry_cnt] = (number);
                    _psampleDeltaVec[_parsed_entry_cnt] = (delta);
                }
            }
        }

        if (!_success)
        {
            _mp4ErrorCode = READ_TIME_TO_SAMPLE_ATOM_FAILED;
        }
    }
    else
    {
        if (_mp4ErrorCode != ATOM_VERSION_NOT_SUPPORTED)
            _mp4ErrorCode = READ_TIME_TO_SAMPLE_ATOM_FAILED;
    }
}
/* ======================================================================== */
SDP_ERROR_CODE
SDPMPEG4MediaInfoParser::parseMediaInfo(const char *buff, const int index, SDPInfo *sdp, payloadVector payload_vec, bool isSipSdp, int alt_id, bool alt_def_id)
{

    const char *current_start = buff; //Pointer to the beginning of the media text
    const char *end = buff + index;   //Pointer to the end of the media text
    const char *line_start_ptr, *line_end_ptr;
    int VOLLength = 0;
    int fmtp_cnt = 0 ;
    bool framesize_found_in_fmtp = false;
    SDPAllocDestructDealloc<uint8> SDP_alloc;


    while (get_next_line(current_start, end,
                         line_start_ptr, line_end_ptr))
    {
        if ((!oscl_strncmp(line_start_ptr, "a=alt:", oscl_strlen("a=alt:"))) && (alt_def_id == false))
        {
            line_start_ptr += oscl_strlen("a=alt:");
            for (; *line_start_ptr != ':'; line_start_ptr++);
            line_start_ptr = line_start_ptr + 1;
        }
        if (!oscl_strncmp(line_start_ptr, "a=fmtp:", oscl_strlen("a=fmtp:")))
        {
            char *tmp_start_line, *tmp_end_line;
            fmtp_cnt++ ;

            tmp_start_line = (char *)line_start_ptr + oscl_strlen("a=fmtp:");
            tmp_start_line = (char *)skip_whitespace(tmp_start_line, line_end_ptr);
            if (tmp_start_line >= line_end_ptr)
            {
                break;
            }
            tmp_end_line = (char *)skip_to_whitespace(tmp_start_line, line_end_ptr);
            if (tmp_end_line < tmp_start_line)
            {
                break;
            }
            tmp_start_line = tmp_end_line + 1;
            tmp_start_line = (char *)skip_whitespace(tmp_start_line, line_end_ptr);
            if (tmp_start_line >= line_end_ptr)
            {
                break;
            }
            int ii = 0;
            const char *temp = tmp_start_line;
            for (ii = 0; ii < (line_end_ptr - tmp_start_line) ; ii++)
            {
                if ((tmp_start_line[ii] == ';') || (ii == (line_end_ptr - tmp_start_line - 1)))
                {
                    tmp_end_line = tmp_start_line + ii;
                    if ((line_end_ptr - tmp_start_line - 1) == ii)
                    {
                        tmp_end_line++;
                    }
                    if (!oscl_strncmp(temp, "config=", oscl_strlen("config=")))
                    {
                        int currentVOLLength;
                        temp += oscl_strlen("config=");
                        temp = skip_whitespace(temp, line_end_ptr);
                        if (temp >= line_end_ptr)
                        {
                            PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Bad a=fmtp line format - Bad config field"));
                            return SDP_BAD_MEDIA_FMTP;
                        }

                        currentVOLLength = (int)(tmp_end_line - temp) / 2;
                        if (VOLLength < currentVOLLength)
                            VOLLength = currentVOLLength;
                    }
                    if (tmp_end_line != line_end_ptr) temp = tmp_end_line + 1;
                    temp = skip_whitespace(temp, line_end_ptr);
                    if (temp >= line_end_ptr)
                    {
                        PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Bad a=fmtp line format"));
                        return SDP_BAD_MEDIA_FMTP;
                    }

                }
            }
        }


        current_start = line_end_ptr + 1;
    }

    if (fmtp_cnt == 0 && isSipSdp == false)
    {
        PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - No fmtp line found"));
        return SDP_BAD_MEDIA_FORMAT;
    }

    if (VOLLength < 0)
    {
        VOLLength = 0;
    }

    bool altMedia = false;
    if (!alt_id || (alt_def_id == true))
        altMedia = false;
    else
        altMedia = true;

    void *memory = sdp->alloc(sizeof(m4v_mediaInfo), altMedia);
    if (NULL == memory)
    {
        PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - memory allocation failure"));
        return SDP_NO_MEMORY;
    }
    else
    {
        m4v_mediaInfo *m4Video = OSCL_PLACEMENT_NEW(memory, m4v_mediaInfo());

        m4Video->setMediaInfoID(sdp->getMediaObjectIndex());

        // Allocate memory to the payload specific objects
        for (uint32 ii = 0; ii < payload_vec.size(); ii++)
        {
            void* mem = m4Video->alloc(sizeof(M4vPayloadSpecificInfoType));
            if (mem == NULL)
            {
                PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Memory allocation failure"));
                return SDP_NO_MEMORY;
            }
            else
            {
                M4vPayloadSpecificInfoType* payload = OSCL_PLACEMENT_NEW(mem, M4vPayloadSpecificInfoType(payload_vec[ii]));
                (void) payload;
            }
        }


        if (alt_id && !alt_def_id)
        {
            sdp->copyFmDefMedia(m4Video);
            //empty alternate & default track ID vectors.
            m4Video->resetAlternateTrackId();
            m4Video->resetDependentTrackId();
        }

        SDP_ERROR_CODE status = baseMediaInfoParser(buff, m4Video, index, alt_id, alt_def_id, isSipSdp);
        if (status != SDP_SUCCESS)
        {
            return status;
        }

        current_start = buff;


        while (get_next_line(current_start, end,
                             line_start_ptr, line_end_ptr))
        {
            switch (*line_start_ptr)
            {
                case 'a':
                {
                    const char *sptr;
                    if ((!oscl_strncmp(line_start_ptr, "a=alt:", oscl_strlen("a=alt:"))) && (alt_def_id == false))
                    {
                        line_start_ptr += oscl_strlen("a=alt:");
                        for (; *line_start_ptr != ':'; line_start_ptr++);
                        line_start_ptr = line_start_ptr + 1;
                    }
                    if (!oscl_strncmp(line_start_ptr, "a=framerate:", oscl_strlen("a=framerate:")))
                    {
                        sptr = line_start_ptr + oscl_strlen("a=framerate:");
                        sptr = skip_whitespace(sptr, line_end_ptr);
                        if (sptr >= line_end_ptr)
                        {
                            PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Bad a=framerate line format"));
                            return SDP_BAD_MEDIA_FRAME_RATE;
                        }
                        OsclFloat rate;
                        if (!PV_atof(sptr, line_end_ptr - sptr, rate))
                            return SDP_BAD_MEDIA_FORMAT;
                        ((m4v_mediaInfo *)m4Video)->setFrameRate(rate);
                    }
                    if (!oscl_strncmp(line_start_ptr, "a=I_frame_interval:", oscl_strlen("a=I_frame_interval:")))
                    {
                        sptr = line_start_ptr + oscl_strlen("a=I_frame_interval:");
                        sptr = skip_whitespace(sptr, line_end_ptr);
                        if (sptr >= line_end_ptr)
                        {
                            PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Bad a=I_frame_interval line format"));
                            return SDP_BAD_MEDIA_FRAME_INTERVAL;
                        }
                        uint32 ifi;
                        if (PV_atoi(sptr, 'd', (line_end_ptr - sptr), ifi) == true)((m4v_mediaInfo *)m4Video)->setIFrameInterval(ifi);
                    }
                    if (!oscl_strncmp(line_start_ptr, "a=fmtp:", oscl_strlen("a=fmtp:")))
                    {
                        const char *tmp_start_line, *tmp_end_line;
                        tmp_start_line = line_start_ptr + oscl_strlen("a=fmtp:");
                        tmp_start_line = skip_whitespace(tmp_start_line, line_end_ptr);
                        if (tmp_start_line >= line_end_ptr)
                        {
                            break;
                        }
                        tmp_end_line = skip_to_whitespace(tmp_start_line, line_end_ptr);
                        if (tmp_end_line < tmp_start_line)
                        {
                            break;
                        }
                        uint32 payloadNumber;
                        if (PV_atoi(tmp_start_line, 'd', (tmp_end_line - tmp_start_line), payloadNumber) == false)
                        {
                            PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Bad a=fmtp line format - Bad payload number"));
                            return SDP_BAD_MEDIA_FMTP;
                        }
                        else
                        {
                            int p;
                            if (!m4Video->lookupPayloadNumber(payloadNumber, p))
                            {
                                fmtp_cnt--;
                                break;
                            }
                        }

                        M4vPayloadSpecificInfoType* payloadPtr =
                            (M4vPayloadSpecificInfoType*)m4Video->getPayloadSpecificInfoTypePtr(payloadNumber);
                        if (payloadPtr == NULL)
                        {
                            PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Bad a=fmtp line format - payload pointer not found for payload"));
                            return SDP_PAYLOAD_MISMATCH;
                        }

                        PVMF_SDP_PARSER_LOGINFO((0, "SDPM4VMediaInfoParser::parseMediaInfo - processing payload number : %d", payloadNumber));

                        tmp_start_line = tmp_end_line + 1;
                        tmp_start_line = skip_whitespace(tmp_start_line, line_end_ptr);
                        if (tmp_start_line >= line_end_ptr)
                        {
                            break;
                        }
                        int ii = 0;
                        const char *temp = tmp_start_line;
                        for (ii = 0; ii < (line_end_ptr - tmp_start_line) ; ii++)
                        {
                            if ((tmp_start_line[ii] == ';') || (ii == (line_end_ptr - tmp_start_line - 1)))
                            {
                                tmp_end_line = tmp_start_line + ii;
                                if (ii == (line_end_ptr - tmp_start_line - 1))
                                {
                                    tmp_end_line += 1;
                                }
                                if (!oscl_strncmp(temp, "config=", oscl_strlen("config=")))
                                {
                                    uint8 *mptr = SDP_alloc.allocate(VOLLength);
                                    OsclRefCounterSA< SDPAllocDestructDealloc<uint8> > *refcnt = new OsclRefCounterSA< SDPAllocDestructDealloc<uint8> >(mptr);
                                    OsclSharedPtr<uint8> VOLPtr(mptr, refcnt);

                                    temp += oscl_strlen("config=");
                                    temp = skip_whitespace(temp, line_end_ptr);
                                    if (temp >= line_end_ptr)
                                    {
                                        PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Bad a=fmtp line format - Bad config field"));
                                        return SDP_BAD_MEDIA_FMTP;
                                    }
                                    VOLLength = (int)(tmp_end_line - temp) / 2;
                                    int idx = 0;
                                    for (idx = 0; idx < VOLLength; idx++)
                                    {
                                        uint32 val;
                                        //Set this value in the vol header array
                                        if (PV_atoi((temp + 2*idx), 'x', 2 , val) == false)
                                        {
                                            PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Bad a=fmtp line format - Bad config field"));
                                            return SDP_BAD_MEDIA_FMTP;
                                        }

                                        *(VOLPtr + idx) = (uint8)val;

                                    }

                                    payloadPtr->setVOLHeader(VOLPtr);
                                    payloadPtr->setVOLHeaderSize(VOLLength);
                                    payloadPtr->setDecoderSpecificInfo(VOLPtr);
                                    payloadPtr->setDecoderSpecificInfoSize(VOLLength);

                                }
                                if (!oscl_strncmp(temp, "profile-level-id=", oscl_strlen("profile-level-id=")))
                                {
                                    temp += oscl_strlen("profile-level-id=");
                                    temp = skip_whitespace(temp, line_end_ptr);
                                    if (temp > line_end_ptr)
                                    {
                                        PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Bad a=fmtp line format - Bad profile-level-id field"));
                                        return SDP_BAD_MEDIA_FMTP;
                                    }
                                    uint32 pl;
                                    if (PV_atoi(temp, 'd', tmp_end_line - temp ,  pl) == true)
                                        payloadPtr->setProfileLevelID(pl);

                                }
                                if (!oscl_strncmp(temp, "framesize=", oscl_strlen("framesize=")))
                                {
                                    temp += oscl_strlen("framesize=");
                                    temp = skip_whitespace(temp, tmp_end_line);
                                    framesize_found_in_fmtp  = true;
                                    if (temp > tmp_end_line)
                                    {
                                        PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Bad a=fmtp line format - Bad framesize field"));
                                        return SDP_BAD_MEDIA_FMTP;
                                    }
                                    const char *end = NULL;
                                    int idx = 0;
                                    for (idx = 0; idx < (tmp_end_line - temp); idx++)
                                    {
                                        if (temp[idx] == '-')
                                        {
                                            end = temp + idx;
                                        }
                                    }
                                    if (end == NULL)
                                    {
                                        PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Bad a=fmtp line format - framesize width info missing"));
                                        return SDP_MISSING_MEDIA_DESCRIPTION;
                                    }
                                    uint32 width;
                                    if (PV_atoi(temp, 'd', (end - temp),  width) == true)
                                        payloadPtr->setFrameWidth(width);
                                    temp = end + 1;
                                    temp = skip_whitespace(temp, tmp_end_line);
                                    if (temp > tmp_end_line)
                                    {
                                        PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Bad a=fmtp line format - framesize height info missing"));
                                        return SDP_BAD_MEDIA_FMTP;
                                    }
                                    uint32 height;
                                    if (PV_atoi(temp, 'd', tmp_end_line - temp, height) == true)
                                        payloadPtr->setFrameHeight(height);
                                }
                                if (!oscl_strncmp(temp, "decode_buf=", oscl_strlen("decode_buf=")))
                                {
                                    temp += oscl_strlen("decode_buf=");
                                    temp = skip_whitespace(temp, tmp_end_line);
                                    if (temp > tmp_end_line)
                                    {
                                        PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Bad a=fmtp line format - Bad decode_buf field"));
                                        return SDP_BAD_MEDIA_FMTP;
                                    }
                                    uint32 dec;
                                    if (PV_atoi(temp, 'd', tmp_end_line - temp, dec) == true)
                                        payloadPtr->setMaxBufferSize(dec);
                                }
                                if (tmp_end_line != line_end_ptr) temp = tmp_end_line + 1;
                                temp = skip_whitespace(temp, line_end_ptr);
                                if (temp >= line_end_ptr)
                                {
                                    PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Bad a=fmtp line format"));
                                    return SDP_BAD_MEDIA_FMTP;
                                }
                            }
                        }
                    }
                    StrPtrLen fmsize("a=framesize:");
                    if (!oscl_strncmp(line_start_ptr, fmsize.c_str(), fmsize.length()))
                    {
                        uint32 width, height;
                        const char *sptr = line_start_ptr + fmsize.length();
                        const char *eptr = skip_to_whitespace(sptr, line_end_ptr);


                        if (sptr > eptr)
                        {
                            PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Bad a=framesize line format"));
                            return SDP_BAD_MEDIA_FRAMESIZE;
                        }
                        uint32 payloadNo;
                        if (PV_atoi(sptr, 'd', (eptr - sptr), payloadNo))
                        {
                            int p;
                            if (!((m4v_mediaInfo *)m4Video)->lookupPayloadNumber(payloadNo, p))
                                break;

                        }
                        else
                        {
                            PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Bad a=framesize line format - Bad payload number"));
                            return SDP_BAD_MEDIA_FRAMESIZE;
                        }

                        M4vPayloadSpecificInfoType* payloadPtr2 =
                            (M4vPayloadSpecificInfoType*)m4Video->getPayloadSpecificInfoTypePtr(payloadNo);
                        if (payloadPtr2 == NULL)
                        {
                            PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Bad a=framesize line format - payload pointer not found for payload"));
                            return SDP_PAYLOAD_MISMATCH;
                        }

                        sptr = eptr;
                        sptr = skip_whitespace(sptr , line_end_ptr);

                        for (;*eptr != '-' ; ++eptr);

                        if (!PV_atoi(sptr, 'd', eptr - sptr, width))
                        {
                            PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - Bad a=framesize line format"));
                            return SDP_BAD_MEDIA_FRAMESIZE;
                        }

                        eptr = eptr + 1;
                        sptr = eptr;
                        if (sptr > line_end_ptr)
                            return SDP_BAD_MEDIA_FRAMESIZE;
                        eptr = skip_to_line_term(sptr, line_end_ptr);
                        if (!PV_atoi(sptr, 'd', eptr - sptr, height))
                            return SDP_BAD_MEDIA_FRAMESIZE;

                        if (framesize_found_in_fmtp)
                        {
                            if ((int)width != payloadPtr2->getFrameWidth() || (int)height != payloadPtr2->getFrameHeight())
                            {
                                return SDP_BAD_MEDIA_FRAMESIZE;
                            }

                        }
                        else
                        {
                            payloadPtr2->setFrameWidth(width);
                            payloadPtr2->setFrameHeight(height);
                        }

                    }
                }
                break;
                default:
                    break;
            }
            current_start = line_end_ptr;
        }

        sessionDescription *session = sdp->getSessionInfo();

        const char *altGroupBW = session->getAltGroupBW();
        int length = session->getAltGroupBWLength();

        if (length > 0)
        {
            status = setDependentMediaId(altGroupBW, length, m4Video, alt_id);
            if (status != SDP_SUCCESS)
                return SDP_BAD_MEDIA_ALT_ID;
        }

        const char *altGroupLANG = session->getAltGroupLANG();
        length = session->getAltGroupLANGLength();

        if (length > 0)
        {
            status = setDependentMediaId(altGroupLANG, length, m4Video, alt_id);
            if (status != SDP_SUCCESS)
                return SDP_BAD_MEDIA_ALT_ID;
        }

        if (m4Video->getCFieldStatus()	|| session->getCFieldStatus())
        {
            //if sample rate is zero override with defaults
            Oscl_Vector<PayloadSpecificInfoTypeBase*, SDPParserAlloc> payloadSpecificInfoVector =
                m4Video->getPayloadSpecificInfoVector();
            for (int ii = 0; ii < (int)payloadSpecificInfoVector.size();ii++)
            {
                if (payloadSpecificInfoVector[ii]->getSampleRate() == 0)
                {
                    payloadSpecificInfoVector[ii]->sampleRate =
                        PVMF_SDP_DEFAULT_MPEG4_VIDEO_SAMPLE_RATE;
                }
            }
            return SDP_SUCCESS;
        }
        else
        {
            PVMF_SDP_PARSER_LOGERROR((0, "SDPM4VMediaInfoParser::parseMediaInfo - No C field present"));
            return SDP_FAILURE_NO_C_FIELD;
        }
    }

}
// 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;
    }
}
// Stream-in ctor
// Create and return a new SampleToChunkAtom by reading in from an ifstream
SampleToChunkAtom::SampleToChunkAtom(MP4_FF_FILE *fp, uint32 size, uint32 type, OSCL_wString& filename, uint32 parsingMode)
        : FullAtom(fp, size, type)
{
    _pfirstChunkVec = NULL;
    _psamplesPerChunkVec = NULL;
    _psampleDescriptionIndexVec = NULL;

    _Index = 0;
    _numChunksInRun = 0;
    _majorGetIndex = 0;
    _currGetChunk = -1;
    _numGetChunksInRun = 0;
    _currGetSampleCount  = 0;
    _firstGetSampleInCurrChunk = 0;
    _numGetSamplesPerChunk = 0;
    _currGetSDI = 0;

    _majorPeekIndex = 0;
    _currPeekChunk = -1;
    _numPeekChunksInRun = 0;
    _currPeekSampleCount  = 0;
    _firstPeekSampleInCurrChunk = 0;
    _numPeekSamplesPerChunk = 0;
    _currPeekSDI = 0;

    _parsed_entry_cnt = 0;
    _fileptr = NULL;

    _stbl_buff_size = MAX_CACHED_TABLE_ENTRIES_FILE;
    _next_buff_number = 0;
    _curr_buff_number = 0;
    _curr_entry_point = 0;
    _stbl_fptr_vec = NULL;
    _parsing_mode = parsingMode;

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

    if (_success)
    {
        _currentChunkNumber = 0;
        _maxNumSamplesPerChunk = DEFAULT_MAX_NUM_SAMPLES_PER_CHUNK;
        _maxChunkDataSize = DEFAULT_MAX_CHUNK_DATA_SIZE;

        if (!AtomUtils::read32(fp, _entryCount))
        {
            _success = false;
        }
        PVMF_MP4FFPARSER_LOGPARSEDINFO((0, "SampleToChunkAtom::SampleToChunkAtom- _entryCount =%d", _entryCount));
        TOsclFileOffset dataSize = _size - (DEFAULT_FULL_ATOM_SIZE + 4);

        uint32 entrySize = (4 + 4 + 4);

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

        if (_success)
        {
            if (_entryCount > 0)
            {
                if (_parsing_mode)
                {
                    if ((_entryCount > _stbl_buff_size)) // cahce size is 4K so that optimization should work if entry_count is greater than 4K
                    {

                        uint32 fptrBuffSize = (_entryCount / _stbl_buff_size) + 1;

                        PV_MP4_FF_ARRAY_NEW(NULL, TOsclFileOffset, (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), _pfirstChunkVec);
                        if (_pfirstChunkVec == NULL)
                        {
                            _success = false;
                            _mp4ErrorCode = MEMORY_ALLOCATION_FAILED;
                            return;
                        }

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

                        {
                            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;
                        }
                        TOsclFileOffset _head_offset = AtomUtils::getCurrentFilePosition(fp);
                        AtomUtils::seekFromCurrPos(fp, dataSize);
                        AtomUtils::seekFromStart(_fileptr, _head_offset);

                        ParseEntryUnit(0);
                        uint32 firstsamplenum = 0;
                        resetStateVariables(firstsamplenum);

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

                PV_MP4_FF_ARRAY_NEW(NULL, uint32, (_entryCount), _pfirstChunkVec);
                PV_MP4_FF_ARRAY_NEW(NULL, uint32, (_entryCount), _psamplesPerChunkVec);
                PV_MP4_FF_ARRAY_NEW(NULL, uint32, (_entryCount), _psampleDescriptionIndexVec);

                uint32 firstChunk;
                uint32 samplesPerChunk;
                uint32 sampleDescrIndex;

                uint32 offSet = 0;

                uint32 prevFirstChunk = 0;
                uint32 j = 0;

                for (uint32 i = 0; i < _entryCount; i++)
                {
                    if (!AtomUtils::read32(fp, firstChunk))
                    {
                        _success = false;
                        break;
                    }

                    if (i == 0)
                        offSet = firstChunk;

                    if (!AtomUtils::read32(fp, samplesPerChunk))
                    {
                        _success = false;
                        break;
                    }
                    if (!AtomUtils::read32(fp, sampleDescrIndex))
                    {
                        _success = false;
                        break;
                    }

                    if (firstChunk > prevFirstChunk)
                    {
                        _pfirstChunkVec[j] = (firstChunk - offSet);
                        _psamplesPerChunkVec[j] = (samplesPerChunk);
                        _psampleDescriptionIndexVec[j] = (sampleDescrIndex);
                        prevFirstChunk = firstChunk;
                        j++;
                    }
                }
                _entryCount = j;
                uint32 firstsamplenum = 0;
                resetStateVariables(firstsamplenum);
            }
            else
            {
                _pfirstChunkVec = NULL;
                _psamplesPerChunkVec = NULL;
                _psampleDescriptionIndexVec = NULL;
            }
        }

        if (!_success)
        {
            _mp4ErrorCode = READ_SAMPLE_TO_CHUNK_ATOM_FAILED;
            PVMF_MP4FFPARSER_LOGERROR((0, "ERROR =>SampleToChunkAtom::SampleToChunkAtom- Read SampleToChunk Atom failed %d", _mp4ErrorCode));
        }
    }
    else
    {
        if (_mp4ErrorCode != ATOM_VERSION_NOT_SUPPORTED)
        {
            _mp4ErrorCode = READ_SAMPLE_TO_CHUNK_ATOM_FAILED;
            PVMF_MP4FFPARSER_LOGERROR((0, "ERROR =>SampleToChunkAtom::SampleToChunkAtom- Read SampleToChunk Atom failed %d", _mp4ErrorCode));
        }
    }
}
// Constructor
TrackFragmentAtom::TrackFragmentAtom(MP4_FF_FILE *fp,
                                     uint32 &size,
                                     uint32 type,
                                     uint32 movieFragmentCurrentOffset,
                                     uint32 movieFragmentBaseOffset,
                                     uint32 moofSize,
                                     TrackDurationContainer *trackDurationContainer,
                                     Oscl_Vector<TrackExtendsAtom*, OsclMemAllocator> *trackExtendAtomVec,
                                     bool &parseTrafCompletely,
                                     bool &trafParsingCompleted,
                                     uint32 &countOfTrunsParsed)
        : Atom(fp, size, type)
{
    OSCL_UNUSED_ARG(movieFragmentCurrentOffset);

    _pTrackFragmentHeaderAtom       = NULL;
    _pTrackFragmentRunAtom          = NULL;
    _pinput = NULL;
    _commonFilePtr = NULL;
    _fileSize = 0;
    _currentTrackFragmentRunSampleNumber = 0;
    _currentPlaybackSampleTimestamp = 0;
    _movieFragmentOffset = 0;
    _prevSampleOffset = 0;
    _trackEndDuration = 0;
    _startTrackFragmentTSOffset = 0;
    _pFragmentptrOffsetVec = NULL;
    _peekPlaybackSampleNumber = 0;
    _default_duration = 0;
    _use_default_duratoin = false;
    _pTrackDurationContainer = trackDurationContainer;

    tf_flags = 0;
    trun_offset = 0;

    trunParsingCompleted = true;

    iLogger = PVLogger::GetLoggerObject("mp4ffparser_traf");
    iStateVarLogger = PVLogger::GetLoggerObject("mp4ffparser_mediasamplestats_traf");
    iParsedDataLogger = PVLogger::GetLoggerObject("mp4ffparser_parseddata_traf");
    OsclAny*ptr = oscl_malloc(sizeof(MP4_FF_FILE));
    if (ptr == NULL)
    {
        _success = false;
        _mp4ErrorCode = MEMORY_ALLOCATION_FAILED;
        return;
    }
    _pinput = OSCL_PLACEMENT_NEW(ptr, MP4_FF_FILE(*fp));

    _pinput->_fileServSession = fp->_fileServSession;
    _pinput->_pvfile.SetCPM(fp->_pvfile.GetCPM());
    _pinput->_fileSize = fp->_fileSize;
    _pinput->_pvfile.Copy(fp->_pvfile);

    uint32 trun_start = 0;
    uint32 count = size - DEFAULT_ATOM_SIZE;

    uint32 _movieFragmentBaseOffset = movieFragmentBaseOffset - DEFAULT_ATOM_SIZE;
    bool bdo_present = false;
    uint32 base_data_offset = _movieFragmentBaseOffset;
    trackId = 0;
    trun_offset = moofSize + DEFAULT_ATOM_SIZE;

    if (_success)
    {
        PV_MP4_FF_NEW(fp->auditCB, trackFragmentRunAtomVecType, (), _pTrackFragmentRunAtomVec);
        while (count > 0)
        {
            uint32 atomType = UNKNOWN_ATOM;
            uint32 atomSize = 0;
            AtomUtils::getNextAtomType(fp, atomSize, atomType);

            if (atomType == TRACK_FRAGMENT_HEADER_ATOM)
            {
                if (_pTrackFragmentHeaderAtom == NULL)
                {
                    PV_MP4_FF_NEW(fp->auditCB, TrackFragmentHeaderAtom, (fp, atomSize, atomType), _pTrackFragmentHeaderAtom);
                    if (!_pTrackFragmentHeaderAtom->MP4Success())
                    {
                        _success = false;
                        _mp4ErrorCode = READ_MOVIE_EXTENDS_HEADER_FAILED;
                        return;
                    }
                    count -= _pTrackFragmentHeaderAtom->getSize();
                    trackId = _pTrackFragmentHeaderAtom->getTrackId();
                    tf_flags = _pTrackFragmentHeaderAtom->getFlags();
                    PVMF_MP4FFPARSER_LOGMEDIASAMPELSTATEVARIABLES((0, "@@@@@@@@@@@@@@@****** Track ID= %d ********@@@@@@@@@@@@@@@@", trackId));
                    PVMF_MP4FFPARSER_LOGMEDIASAMPELSTATEVARIABLES((0, "#### tf_flag =0x%x######", tf_flags));

                    if (tf_flags & 0x000001)
                    {
                        uint64 bdo = _pTrackFragmentHeaderAtom->getBaseDataOffset();
                        base_data_offset = Oscl_Int64_Utils::get_uint64_lower32(bdo);
                        bdo_present = true;
                    }
                    else
                        base_data_offset = _movieFragmentBaseOffset;

                    trun_start = base_data_offset;
                    if (trackDurationContainer != NULL)
                    {
                        for (int32 i = 0; i < trackDurationContainer->getNumTrackInfoVec(); i++)
                        {
                            TrackDurationInfo* trackInfo = trackDurationContainer->getTrackdurationInfoAt(i);
                            if (trackInfo->trackId == trackId)
                            {
                                _trackEndDuration = trackInfo->trackDuration;
                                _startTrackFragmentTSOffset = _trackEndDuration;
                            }
                        }
                    }
                }
                else
                {
                    //duplicate atom
                    count -= atomSize;
                    atomSize -= DEFAULT_ATOM_SIZE;
                    AtomUtils::seekFromCurrPos(fp, atomSize);
                }
            }
            else if (atomType == TRACK_FRAGMENT_RUN_ATOM)
            {
                uint32 trunsParsed = countOfTrunsParsed;
                if (countOfTrunsParsed > COUNT_OF_TRUNS_PARSED_THRESHOLD)
                {
                    countOfTrunsParsed = COUNT_OF_TRUNS_PARSED_THRESHOLD;
                }
                // here we want parser to parse complete TRUN atom.

                PV_MP4_FF_NEW(fp->auditCB, TrackFragmentRunAtom, (fp, atomSize, atomType,
                              base_data_offset,
                              trun_start,
                              trun_offset,
                              _trackEndDuration,
                              bdo_present,
                              trunParsingCompleted,
                              countOfTrunsParsed),
                              _pTrackFragmentRunAtom);

                countOfTrunsParsed = trunsParsed + 1;

                if (!_pTrackFragmentRunAtom->MP4Success())
                {
                    _success = false;
                    _mp4ErrorCode = READ_TRACK_EXTENDS_ATOM_FAILED;
                    return;
                }
                bdo_present = false;
                count -= _pTrackFragmentRunAtom->getSize();

                size = count;
                uint32 trunFlags = _pTrackFragmentRunAtom->getFlags();
                if (!(trunFlags & 0x000100))
                {
                    _use_default_duratoin = true;
                    if (tf_flags & 0x000008)
                    {
                        _default_duration = _pTrackFragmentHeaderAtom->getDefaultSampleDuration();
                        _pTrackFragmentRunAtom->setDefaultDuration(_default_duration);
                    }
                    else
                    {
                        for (uint32 idx = 0; idx < trackExtendAtomVec->size(); idx++)
                        {
                            TrackExtendsAtom* pTrackExtendAtom = (*trackExtendAtomVec)[idx];
                            uint32 id = pTrackExtendAtom->getTrackId();
                            if (id == trackId)
                            {
                                uint32 trexDefaultDuration = pTrackExtendAtom->getDefaultSampleDuration();
                                _default_duration = trexDefaultDuration;
                                _pTrackFragmentRunAtom->setDefaultDuration(trexDefaultDuration);
                            }
                        }
                    }
                }
                if (!(trunFlags & 0x000200))
                {
                    if (tf_flags & 0x000010)
                        _pTrackFragmentRunAtom->setDefaultSampleSize(_pTrackFragmentHeaderAtom->getDefaultSampleSize(), trun_offset);
                    else
                    {
                        for (uint32 idx = 0; idx < trackExtendAtomVec->size(); idx++)
                        {
                            TrackExtendsAtom* pTrackExtendAtom = (*trackExtendAtomVec)[idx];
                            uint32 id = pTrackExtendAtom->getTrackId();
                            if (id == trackId)
                            {
                                uint32 trexDefaultSampleSize = pTrackExtendAtom->getDefaultSampleSize();
                                _pTrackFragmentRunAtom->setDefaultSampleSize(trexDefaultSampleSize, trun_offset);
                            }
                        }
                    }
                }
                _pTrackFragmentRunAtomVec->push_back(_pTrackFragmentRunAtom);
                _trackEndDuration = _pTrackFragmentRunAtom->GetSampleTimeStamp();

                PVMF_MP4FFPARSER_LOGMEDIASAMPELSTATEVARIABLES((0, "****** tr_flag =0x%x ********", trunFlags));
                if (!parseTrafCompletely)
                {
                    trafParsingCompleted = false;
                    uint64 duration = _trackEndDuration;
                    trackDurationContainer->updateTrackDurationForTrackId(trackId, duration);
                    break;
                }
            }
            else
            {
                count -= atomSize;
                atomSize -= DEFAULT_ATOM_SIZE;
                AtomUtils::seekFromCurrPos(fp, atomSize);
            }
            uint64 track_duration = _trackEndDuration;
            trackDurationContainer->updateTrackDurationForTrackId(trackId, track_duration);
            trafParsingCompleted = true;
        }
    }
    else
    {
OMX_ERRORTYPE H263EncRegister(OMXGlobalData *data)
{
    OMX_S32 ii;
    ComponentRegistrationType* pCRT = (ComponentRegistrationType*) oscl_malloc(sizeof(ComponentRegistrationType));

    if (pCRT)
    {
        pCRT->ComponentName = (OMX_STRING)"OMX.PV.h263enc";
        pCRT->RoleString[0] = (OMX_STRING)"video_encoder.h263";
        pCRT->NumberOfRolesSupported = 1;
        pCRT->SharedLibraryOsclUuid = NULL;
#if USE_DYNAMIC_LOAD_OMX_COMPONENTS
        pCRT->FunctionPtrCreateComponent = &OmxComponentFactoryDynamicCreate;
        pCRT->FunctionPtrDestroyComponent = &OmxComponentFactoryDynamicDestructor;
        pCRT->SharedLibraryName = (OMX_STRING)"libomx_m4venc_sharedlibrary";
        pCRT->SharedLibraryPtr = NULL;

        OsclUuid *temp = (OsclUuid *) oscl_malloc(sizeof(OsclUuid));
        if (temp == NULL)
        {
            oscl_free(pCRT); // free allocated memory
            return OMX_ErrorInsufficientResources;
        }
        OSCL_PLACEMENT_NEW(temp, PV_OMX_H263ENC_UUID);

        pCRT->SharedLibraryOsclUuid = (OMX_PTR) temp;
        pCRT->SharedLibraryRefCounter = 0;

#endif
#if REGISTER_OMX_H263ENC_COMPONENT
#if (DYNAMIC_LOAD_OMX_H263ENC_COMPONENT == 0)

        pCRT->FunctionPtrCreateComponent = &H263EncOmxComponentFactory;
        pCRT->FunctionPtrDestroyComponent = &H263EncOmxComponentDestructor;
        pCRT->SharedLibraryName = NULL;
        pCRT->SharedLibraryPtr = NULL;

        if (pCRT->SharedLibraryOsclUuid)
            oscl_free(pCRT->SharedLibraryOsclUuid);

        pCRT->SharedLibraryOsclUuid = NULL;
        pCRT->SharedLibraryRefCounter = 0;
#endif
#endif
    }
    else
    {
        return OMX_ErrorInsufficientResources;
    }

    for (ii = 0; ii < MAX_SUPPORTED_COMPONENTS; ii++)
    {
        if (NULL == data->ipRegTemplateList[ii])
        {
            data->ipRegTemplateList[ii] = pCRT;
            break;
        }
    }

    if (MAX_SUPPORTED_COMPONENTS == ii)
    {
        return OMX_ErrorInsufficientResources;
    }

    return OMX_ErrorNone;
}
// Ctor to create a new ChunkOffsetAtom by reading in from an ifstream
ChunkOffsetAtom::ChunkOffsetAtom(MP4_FF_FILE *fp, uint32 size, uint32 type,
                                 OSCL_wString& filename,
                                 uint32 parsingMode)
        : FullAtom(fp, size, type)
{
    _pchunkOffsets = NULL;
    _stbl_buff_size = MAX_CACHED_TABLE_ENTRIES_FILE;
    _next_buff_number = 0;
    _curr_buff_number = 0;
    _curr_entry_point = 0;
    _stbl_fptr_vec = NULL;
    _parsed_entry_cnt = 0;
    _parsingMode = parsingMode;
    _fileptr = NULL;

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

        uint32 dataSize = _size - (DEFAULT_FULL_ATOM_SIZE + 4);

        uint32 entrySize = 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), _pchunkOffsets);
                        if (_pchunkOffsets == NULL)
                        {
                            _success = false;
                            _mp4ErrorCode = MEMORY_ALLOCATION_FAILED;
                            return;
                        }

                        {
                            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());
                            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
                    {
                        _parsingMode = 0;
                        _stbl_buff_size = _entryCount;
                    }

                }
                else
                {
                    _stbl_buff_size = _entryCount;
                }

                _parsingMode = 0;
                PV_MP4_FF_ARRAY_NEW(NULL, uint32, (_entryCount), _pchunkOffsets);

                uint32 offset = 0;
                for (uint32 i = 0; i < _entryCount; i++)
                {
                    if (!AtomUtils::read32(fp, offset))
                    {
                        _success = false;
                        break;
                    }
                    _pchunkOffsets[i] = offset;
                }
                _parsed_entry_cnt = _entryCount;
            }
            else
            {
                _pchunkOffsets = NULL;
            }

        }

        if (!_success)
        {
            _mp4ErrorCode = READ_CHUNK_OFFSET_ATOM_FAILED;
        }
    }
    else
    {
        if (_mp4ErrorCode != ATOM_VERSION_NOT_SUPPORTED)
            _mp4ErrorCode = READ_CHUNK_OFFSET_ATOM_FAILED;
    }
}