SRTParser::SRTParser(CP_PIPETYPE *hPipe, OMX_STRING url)
{
    mInit = OMX_FALSE;
    mState = SRT_STATE_SEQ_NUM;
    mBuffer = NULL;
    mSource = NULL;
    mTimeTable = NULL;
    mTimeTableEntrySize = 0;
    mTimeTableIndex = 0;
    mTimeTableSize = SRT_TIME_TABLE_SIZE;
    mBuffer = (OMX_U8*)FSL_MALLOC(BUFFER_SIZE_SRT);
    if(mBuffer == NULL) {
        LOG_ERROR("failed allocate buffer for SRTParser.\n");
        return;
    }
    mSource = FSL_NEW(TextSource, (hPipe, url));
    if(mSource == NULL) {
        LOG_ERROR("failed create TextSource.\n");
        return;
    }
    mTimeTable = (TIME_NODE*)FSL_MALLOC(mTimeTableSize * sizeof(TIME_NODE));
    if(mTimeTable == NULL) {
        LOG_ERROR("failed to create time table for srt.\n");
        return;
    }
    mInit = OMX_TRUE;
}
OMX_ERRORTYPE TextSource::Init()
{
    CPresult ret = 0;
    ret = mPipe->Open(&mHandle, mUrl, CP_AccessRead);
    if(ret != 0) {
        LOG_ERROR("Can't open content: %s\n", mUrl);
        return OMX_ErrorUndefined;
    }

    mBuffer = (OMX_U8*)FSL_MALLOC(mBufferSize);
    if(mBuffer == NULL) {
        DeInit();
        return OMX_ErrorInsufficientResources;
    }

    mCache = (OMX_U8*)FSL_MALLOC(mCacheSize);
    if(mCache == NULL) {
        DeInit();
        return OMX_ErrorInsufficientResources;
    }
    mCacheRead = mCacheFill = 0;
    mOffset = 0;

    return OMX_ErrorNone;
}
RINGBUFFER_ERRORTYPE RingBuffer::BufferCreate(fsl_osal_u32 nPushModeLen, fsl_osal_u32 nRingBufferScale)
{
	RINGBUFFER_ERRORTYPE ret = RINGBUFFER_SUCCESS;

	nPushModeInputLen = nPushModeLen;
	nRingBufferLen = nPushModeInputLen * nRingBufferScale;

	/** Create queue for TS. */
	TS_Queue = FSL_NEW(Queue, ());
	if (TS_Queue == NULL)
	{
		LOG_ERROR("Can't get memory.\n");
		return RINGBUFFER_INSUFFICIENT_RESOURCES;
	}

	if (TS_Queue->Create(TS_QUEUE_SIZE, sizeof(TS_QUEUE), E_FSL_OSAL_FALSE) != QUEUE_SUCCESS)
	{
		FSL_DELETE(TS_Queue);
		LOG_ERROR("Can't create audio ts queue.\n");
		return RINGBUFFER_INSUFFICIENT_RESOURCES;
	}

	/** Create ring buffer for audio decoder input stream. */
	LOG_DEBUG("Ring buffer len: %d\n", nRingBufferLen);
	RingBufferPtr = (fsl_osal_u8 *)FSL_MALLOC(nRingBufferLen+8);
	if (RingBufferPtr == NULL)
	{
		FSL_DELETE(TS_Queue);
		TS_Queue->Free();
		LOG_ERROR("Can't get memory.\n");
		return RINGBUFFER_INSUFFICIENT_RESOURCES;
	}

	Reserved = (fsl_osal_u8 *)FSL_MALLOC(nPushModeInputLen);
	if (Reserved == NULL)
	{
		FSL_DELETE(TS_Queue);
		TS_Queue->Free();
		FSL_FREE(RingBufferPtr);
		LOG_ERROR("Can't get memory.\n");
		return RINGBUFFER_INSUFFICIENT_RESOURCES;
	}

	CurrentTS = 0;
	bHaveTS = E_FSL_OSAL_FALSE;
	TotalConsumeLen = 0;
	RingBufferBeginPre = -1;
	ReservedLen = nPushModeInputLen;
	Begin = RingBufferPtr;
	End = RingBufferPtr;
	Consumered = RingBufferPtr;
	nPrevOffset = 0;

	return ret;
}
OMX_ERRORTYPE prepare_port_buffers(HTEST *hTest, OMX_U32 nPortIndex)
{
    OMX_COMPONENTTYPE *hComponent = NULL;
    OMX_PARAM_PORTDEFINITIONTYPE sPortDef;
    OMX_BUFFERHEADERTYPE *pBufferHdr = NULL;
    OMX_U8 *pBuffer = NULL;
    OMX_U32 i;

    hComponent = hTest->hComponent;
    OMX_INIT_STRUCT(&sPortDef, OMX_PARAM_PORTDEFINITIONTYPE);
    sPortDef.nPortIndex = nPortIndex;
    OMX_GetParameter(hComponent, OMX_IndexParamPortDefinition, &sPortDef);

    for(i=0; i<sPortDef.nBufferCountActual; i++) {
        if(hTest->bAllocater[nPortIndex] == OMX_TRUE) {
            OMX_AllocateBuffer(hComponent, &pBufferHdr, nPortIndex, NULL, sPortDef.nBufferSize);
            printf("Allocate buffer done.\n");
        }
        else {
            pBuffer = (OMX_U8*)FSL_MALLOC(sPortDef.nBufferSize);
            OMX_UseBuffer(hComponent, &pBufferHdr, nPortIndex, NULL, sPortDef.nBufferSize, pBuffer);
            printf("Use buffer done.\n");
        }
        hTest->pBufferHdr[nPortIndex][i] = pBufferHdr;
    }
    hTest->nBufferHdr[nPortIndex] = sPortDef.nBufferCountActual;


    return OMX_ErrorNone;
}
OMX_ERRORTYPE UniaDecoder::AudioFilterCheckCodecConfig()
{
    OMX_S32 ret = OMX_ErrorNone;
    if(IDecoder == NULL || uniaHandle == NULL)
        return OMX_ErrorUndefined;

    if (codecConfig.buf != NULL) {
        codecConfig.buf = (char *)FSL_REALLOC(codecConfig.buf, \
            codecConfig.size + pInBufferHdr->nFilledLen);
        if (codecConfig.buf == NULL)
        {
            LOG_ERROR("Can't get memory.\n");
            return OMX_ErrorInsufficientResources;
        }
        fsl_osal_memcpy(codecConfig.buf + codecConfig.size, pInBufferHdr->pBuffer, pInBufferHdr->nFilledLen);
        codecConfig.size += pInBufferHdr->nFilledLen;

    } else {
         codecConfig.buf = (char *)FSL_MALLOC(pInBufferHdr->nFilledLen);
        if (codecConfig.buf == NULL)
        {
            LOG_ERROR("Can't get memory.\n");
            return OMX_ErrorInsufficientResources;
        }
        fsl_osal_memcpy(codecConfig.buf, pInBufferHdr->pBuffer, pInBufferHdr->nFilledLen);
        codecConfig.size = pInBufferHdr->nFilledLen;
    }

    ret = IDecoder->SetParameter(uniaHandle,UNIA_CODEC_DATA,(UniACodecParameter*)&codecConfig);

    LOG_DEBUG("UniaDec::AudioDecoderBaseCheckCodecConfig nFilledLen=%d,ret=%d",pInBufferHdr->nFilledLen,ret);
    pInBufferHdr->nFilledLen = 0;

    return (OMX_ERRORTYPE)ret;
}
OMX_ERRORTYPE GMInbandSubtitleSource::SetType(OMX_STRING type)
{
    SUBTITLE_TYPE mType1;
    OMX_S32 nLen = 0;

    LOG_DEBUG("GMInbandSubtitleSource set type: %s\n", type);

    mType1 = GetSubtitleType(type);
    switch(mType1) {
        case TYPE_3GPP:
            nLen = BUFFER_SIZE_3GP;
        case TYPE_SRT:
            nLen = BUFFER_SIZE_SRT;
        default:
            break;
    }

    if(mType1 == TYPE_UNKNOWN)
        return OMX_ErrorNotImplemented;

    if(mType != mType1) {
        if(pBuffer)
            FSL_FREE(pBuffer);

        pBuffer = (OMX_U8*)FSL_MALLOC(nLen);
        if(pBuffer == NULL)
            return OMX_ErrorInsufficientResources;

        mType = mType1;
    }

    fsl_osal_memset(pBuffer, 0, nLen);

    return OMX_ErrorNone;
}
Exemplo n.º 7
0
VO_U32 cmnMemAlloc (VO_S32 uID,  VO_MEM_INFO * pMemInfo)
{
	if (!pMemInfo)
		return VO_ERR_INVALID_ARG;

	pMemInfo->VBuffer = FSL_MALLOC(pMemInfo->Size);
	return 0;
}
OMX_ERRORTYPE WbAmrEncWrapper::InstanceInit()
{
    OMX_ERRORTYPE ret = OMX_ErrorNone;
	OMX_S32 i;

	pAmrEncConfig = (WBAMRE_Encoder_Config *)FSL_MALLOC(sizeof(WBAMRE_Encoder_Config));
	if (pAmrEncConfig == NULL)
	{
		LOG_ERROR("Can't get memory.\n");
		return OMX_ErrorInsufficientResources;
	}
	fsl_osal_memset(pAmrEncConfig, 0, sizeof(WBAMRE_Encoder_Config));

	pAmrEncConfig->wbappe_initialized_data_start = NULL;

	WBAMRE_RET_TYPE AmrRet;
	AmrRet = wbamre_query_enc_mem(pAmrEncConfig);
	if (AmrRet != WBAMRE_OK)
	{
		LOG_ERROR("Amr encoder query memory fail.\n");
		return OMX_ErrorUndefined;
	}

	OMX_S32 MemoryCnt = pAmrEncConfig->wbamre_mem_info.wbamre_num_reqs;
	for (i = 0; i < MemoryCnt; i ++)
	{
		OMX_U32 BufferSize;
		OMX_U8 *pBuffer;

		BufferSize = pAmrEncConfig->wbamre_mem_info.mem_info_sub[i].wbamre_size;
		pBuffer = (OMX_U8 *)FSL_MALLOC(BufferSize);
		if (pBuffer == NULL)
		{
			LOG_ERROR("Can't get memory.\n");
			return OMX_ErrorInsufficientResources;
		}
		fsl_osal_memset(pBuffer, 0, BufferSize);
		pAmrEncConfig->wbamre_mem_info.mem_info_sub[i].wbappe_base_ptr = pBuffer;
	}

	return ret;

}
HTEST * create_test(
    OMX_STRING component,
    OMX_STRING in_file,
    OMX_STRING out_file,
    FORMAT fmt)
{
	HTEST *hTest = NULL;

	hTest = (HTEST*)FSL_MALLOC(sizeof(HTEST));
	if(hTest == NULL)
	{
		printf("Failed to allocate memory for test handle.\n");
		return 0;
	}
	fsl_osal_memset(hTest, 0, sizeof(HTEST));

	hTest->name = component;

	hTest->pMsgQ = FSL_NEW(Queue, ());
	if(hTest->pMsgQ == NULL)
	{
		printf("Create message queue failed.\n");
		return 0;
	}
	hTest->pMsgQ->Create(128, sizeof(MSG), E_FSL_OSAL_TRUE);

	hTest->pInFile = fopen(in_file, "rb");
	if(hTest->pInFile == NULL)
	{
		printf("Failed to open file: %s\n", in_file);
		return 0;
	}

	hTest->pOutFile = fopen(out_file, "wb");
	if(hTest->pOutFile == NULL)
	{
		printf("Failed to open file: %s\n", out_file);
		return 0;
	}

	hTest->fmt = fmt;
	if(fmt == MPEG4)
	{
		hTest->role = "video_decoder.mpeg4";
		hTest->get_video_frame_len = get_mpeg4_frame_length;
	}
	if(fmt == H264)
	{
		hTest->role = "video_decoder.avc";
		hTest->get_video_frame_len = get_h264_frame_length;
	}

	return hTest;
}
HTEST * create_test(
        OMX_STRING component,
        OMX_STRING in_file,
		OMX_S32 width,
		OMX_S32 height,
        OMX_STRING out_file,
        FORMAT fmt,
		OMX_S32 bitrate)
{
    HTEST *hTest = NULL;

    hTest = (HTEST*)FSL_MALLOC(sizeof(HTEST));
    if(hTest == NULL) {
        printf("Failed to allocate memory for test handle.\n");
        return 0;
    }
    fsl_osal_memset(hTest, 0, sizeof(HTEST));

    hTest->name = component;

    hTest->pMsgQ = FSL_NEW(Queue, ());
    if(hTest->pMsgQ == NULL) {
        printf("Create message queue failed.\n");
        return 0;
    }
    hTest->pMsgQ->Create(128, sizeof(MSG), E_FSL_OSAL_TRUE);

    hTest->pInFile = fopen(in_file, "rb");
    if(hTest->pInFile == NULL) {
        printf("Failed to open file: %s\n", in_file);
        return 0;
    }

    hTest->pOutFile = fopen(out_file, "wb");
    if(hTest->pOutFile == NULL) {
        printf("Failed to open file: %s\n", out_file);
        return 0;
    }

    hTest->width = width;
    hTest->height = height;
    hTest->bitrate = bitrate;

    hTest->fmt = fmt;
    if(fmt == H263) {
        hTest->role = "video_encoder.h263";
    }
    if(fmt == H264) {
        hTest->role = "video_encoder.avc";
    }

    return hTest;
}
OMX_PTR CreatePMeoryContext()
{
    OMX_PTR Context = NULL;

    Context = (OMX_PTR)FSL_MALLOC(sizeof(PMCONTEXT));
    if(Context == NULL) {
        LOG_ERROR("Failed allocate PMemory context.\n");
        return NULL;
    }
    fsl_osal_memset(Context, 0, sizeof(PMCONTEXT));

    return Context;
}
Exemplo n.º 12
0
OMX_ERRORTYPE WmaDec::AudioFilterInstanceInit()
{
    OMX_ERRORTYPE ret = OMX_ErrorNone;
	pWmaDecConfig = (WMADDecoderConfig *)FSL_MALLOC(sizeof(WMADDecoderConfig));
	if (pWmaDecConfig == NULL)
	{
		LOG_ERROR("Can't get memory.\n");
		return OMX_ErrorInsufficientResources;
	}
	fsl_osal_memset(pWmaDecConfig, 0, sizeof(WMADDecoderConfig));

	pWmaDecParams = (WMADDecoderParams *)FSL_MALLOC(sizeof(WMADDecoderParams));
	if (pWmaDecParams == NULL)
	{
		LOG_ERROR("Can't get memory.\n");
		return OMX_ErrorInsufficientResources;
	}
	fsl_osal_memset(pWmaDecParams, 0, sizeof(WMADDecoderParams));

	if (nPushModeInputLen < WmaType.nBlockAlign * 2)
		nPushModeInputLen = WmaType.nBlockAlign * 2;

    return ret;
}
static void* appLocalMalloc (uint32 TotalSize)
{

    void *PtrMalloc = NULL;

    if(0 == TotalSize)
        LOG_WARNING("\nWarning: ZERO size IN LOCAL MALLOC");

    PtrMalloc = FSL_MALLOC(TotalSize);

    if (PtrMalloc == NULL) {

        LOG_ERROR("\nError: MEMORY FAILURE IN LOCAL MALLOC");
    }
    return (PtrMalloc);
}
static void *appLocalCalloc(uint32 TotalNumber, uint32 TotalSize)
{
    void *PtrCalloc = NULL;

    if((0 == TotalSize)||(0==TotalNumber))
        LOG_WARNING("\nWarning: ZERO size IN LOCAL CALLOC");

    PtrCalloc = FSL_MALLOC(TotalNumber*TotalSize);

    if (PtrCalloc == NULL) {

        LOG_ERROR("\nError: MEMORY FAILURE IN LOCAL CALLOC");
                return NULL;
    }
    fsl_osal_memset(PtrCalloc, 0, TotalSize*TotalNumber);
    return (PtrCalloc);
}
OMX_ERRORTYPE AudioSource::DoLoaded2Idle()
{
    OMX_ERRORTYPE ret = OMX_ErrorNone;

    ret = OpenDevice();
    if(ret != OMX_ErrorNone) {
        CloseDevice();
        SendEvent(OMX_EventError, ret, 0, NULL);
        return ret;
	}

	nDeviceReadLen = nPeriodSize * nSampleSize;
	OMX_U32 BufferSize;
	OMX_U8 *pBuffer;

	BufferSize = nDeviceReadLen;
	pBuffer = (OMX_U8 *)FSL_MALLOC(BufferSize);
	if (pBuffer == NULL) {
		LOG_ERROR("Can't get memory.\n");
		return OMX_ErrorInsufficientResources;
	}
	fsl_osal_memset(pBuffer, 0, BufferSize);
	pDeviceReadBuffer = pBuffer;

	OMX_U32 nRingBufferSize = nFadeInFadeOutProcessLen + nDeviceReadLen;
	RINGBUFFER_ERRORTYPE BufferRet = RINGBUFFER_SUCCESS;
	LOG_DEBUG("Audio source nRingBufferSize = %d\n", nRingBufferSize);
	BufferRet = AudioRenderRingBuffer.BufferCreate(nRingBufferSize);
	if (BufferRet != RINGBUFFER_SUCCESS) {
		LOG_ERROR("Create ring buffer fail.\n");
		return OMX_ErrorInsufficientResources;
	} 

	FADEINFADEOUT_ERRORTYPE FadeRet = FADEINFADEOUT_SUCCESS;
	FadeRet = AudioRenderFadeInFadeOut.Create(PcmMode.nChannels, PcmMode.nSamplingRate, \
			PcmMode.nBitPerSample, nFadeInFadeOutProcessLen, 0);
	if (FadeRet != FADEINFADEOUT_SUCCESS) {
		LOG_ERROR("Create fade in fade out process fail.\n");
		return OMX_ErrorInsufficientResources;
	}

    return OMX_ErrorNone;
}
Exemplo n.º 16
0
OMX_ERRORTYPE PlatformResourceMgr::AddHwBuffer(
        OMX_PTR pPhyiscAddr,
        OMX_PTR pVirtualAddr)
{
    PLATFORM_DATA *pData = NULL;

    pData = (PLATFORM_DATA*)FSL_MALLOC(sizeof(PLATFORM_DATA));
    if(pData == NULL)
        return OMX_ErrorInsufficientResources;

    pData->pVirtualAddr = pVirtualAddr;
    pData->pPhyiscAddr = pPhyiscAddr;

    fsl_osal_mutex_lock(lock);
    if(LIST_SUCCESS != PlatformDataList->Add(pData)) {
        FSL_FREE(pData);
        fsl_osal_mutex_unlock(lock);
        return OMX_ErrorUndefined;
    }
    fsl_osal_mutex_unlock(lock);

    return OMX_ErrorNone;
}
Exemplo n.º 17
0
OMX_ERRORTYPE Mp3Parser::SetSource(OMX_PARAM_CONTENTURITYPE *Content, OMX_PARAM_CONTENTPIPETYPE *Pipe)
{
	OMX_ERRORTYPE ret = OMX_ErrorNone;

	hPipe =(CP_PIPETYPE* ) (((OMX_PARAM_CONTENTPIPETYPE *)Pipe)->hPipe);

	OMX_PARAM_CONTENTURITYPE * pContentURI = (OMX_PARAM_CONTENTURITYPE *)Content;
	nMediaNameLen = fsl_osal_strlen((const char *)&(pContentURI->contentURI)) + 1;

	pMediaName = (OMX_S8 *)FSL_MALLOC(nMediaNameLen);
	if (!pMediaName)
	{
		return OMX_ErrorInsufficientResources;
	}
	fsl_osal_strcpy((char *)pMediaName, (const char *)&(pContentURI->contentURI));
	if(fsl_osal_strncmp((fsl_osal_char*)pMediaName, "http://", 7) == 0
	        || fsl_osal_strncmp((fsl_osal_char*)pMediaName, "rtsp://", 7) == 0)
		isStreamingSource = OMX_TRUE;

	bGetMetadata = OMX_TRUE;
	fsl_osal_strcpy((fsl_osal_char*)sCompRole.cRole, role[0]);

	return ret;
}
Exemplo n.º 18
0
OMX_ERRORTYPE WmaDec::AudioFilterCodecInit()
{
    OMX_ERRORTYPE ret = OMX_ErrorNone;
	tWMAFileStatus WmaRet;

	pWmaDecConfig->psWMADecodeInfoStructPtr = NULL;
	pWmaDecParams->bDropPacket = 0;
	pWmaDecParams->nDRCSetting = 0;
	pWmaDecParams->nDecoderFlags =0;
	pWmaDecParams->nDstChannelMask = 0;
	pWmaDecParams->nInterpResampRate = 0;
	pWmaDecParams->nMBRTargetStream = 1;
	pWmaDecParams->bIsRawDecoder = WMAD_TRUE;
	pWmaDecParams->us16Version = WmaType.eFormat;
	pWmaDecParams->us16Channels = WmaType.nChannels;
	pWmaDecParams->us32SamplesPerSec = WmaType.nSamplingRate;
	pWmaDecParams->us32AvgBytesPerSec = WmaType.nBitRate >> 3;
	pWmaDecParams->us16EncodeOpt = WmaType.nEncodeOptions;
	if (WmaType.eFormat == OMX_AUDIO_WMAFormat7)
		pWmaDecParams->us16wFormatTag = 0x160;
	else if (WmaType.eFormat == OMX_AUDIO_WMAFormat8)
		pWmaDecParams->us16wFormatTag = 0x161;
	else if (WmaType.eFormat == OMX_AUDIO_WMAFormat9)
		pWmaDecParams->us16wFormatTag = 0x162;

	pWmaDecParams->us32nBlockAlign = WmaType.nBlockAlign;
	pWmaDecParams->us32ChannelMask = dwChannelMask;
	pWmaDecParams->us16AdvancedEncodeOpt = nAdvancedEncodeOpt;
	pWmaDecParams->us32AdvancedEncodeOpt2 = nAdvancedEncodeOpt2;
	pWmaDecParams->us32ValidBitsPerSample = WmaTypeExt.nBitsPerSample;
	if((pWmaDecParams->us32ValidBitsPerSample!=16)&&(pWmaDecParams->us32ValidBitsPerSample!=24))
	{
		pWmaDecParams->us32ValidBitsPerSample = 16;
	}
	if(pWmaDecParams->us16Channels > 2)
	{
		pWmaDecParams->nDecoderFlags |= DECOPT_CHANNEL_DOWNMIXING;
		pWmaDecParams->nDstChannelMask = 0x03;
	}

	pWmaDecConfig->app_swap_buf = (tWMAFileStatus (*)(void*, WMAD_UINT64, WMAD_UINT32*, WMAD_UINT8**, void*, WMAD_UINT32*))WMA10FileCBGetNewPayload;
	pWmaDecConfig->pContext = (OMX_PTR)(this);
	pWmaDecConfig->sDecodeParams = pWmaDecParams;
	fsl_osal_memset(&sWfx,0,sizeof(WAVEFORMATEXTENSIBLE));
    pWmaDecParams->pWfx = &sWfx;

	OMX_S32 MemoryCnt = pWmaDecConfig->sWMADMemInfo.s32NumReqs;
	for (OMX_S32 i = 0; i < MemoryCnt; i ++)
	{
		FSL_FREE(pWmaDecConfig->sWMADMemInfo.sMemInfoSub[i].app_base_ptr);
	}

	LOG_DEBUG("nVersion=%d,wFormatTag=%p,nSamplesPerSec=%d,nAvgBytesPerSec=%d,nBlockAlign=%d,nChannels=%d,nEncodeOpt=%p,wBitsPerSample=%d,dwChannelMask=%p,nAdvancedEncodeOpt=%p,nAdvancedEncodeOpt2=%p\n",pWmaDecConfig->sDecodeParams->us16Version,pWmaDecConfig->sDecodeParams->us16wFormatTag,pWmaDecConfig->sDecodeParams->us32SamplesPerSec,pWmaDecConfig->sDecodeParams->us32AvgBytesPerSec,pWmaDecConfig->sDecodeParams->us32nBlockAlign,pWmaDecConfig->sDecodeParams->us16Channels,pWmaDecConfig->sDecodeParams->us16EncodeOpt,pWmaDecConfig->sDecodeParams->us32ValidBitsPerSample,pWmaDecConfig->sDecodeParams->us32ChannelMask,pWmaDecConfig->sDecodeParams->us16AdvancedEncodeOpt,pWmaDecConfig->sDecodeParams->us32AdvancedEncodeOpt2);

	WmaRet = pWMADQueryMem(pWmaDecConfig);
	if (WmaRet != cWMA_NoErr)
	{
		LOG_ERROR("Wma decoder query memory fail.\n");
		return OMX_ErrorUndefined;
	}

	MemoryCnt = pWmaDecConfig->sWMADMemInfo.s32NumReqs;
	for (OMX_S32 i = 0; i < MemoryCnt; i ++)
	{
		OMX_U32 BufferSize;
		OMX_U8 *pBuffer;

		BufferSize = pWmaDecConfig->sWMADMemInfo.sMemInfoSub[i].s32WMADSize;
		pBuffer = (OMX_U8 *)FSL_MALLOC(BufferSize);
		if (pBuffer == NULL)
		{
			LOG_ERROR("Can't get memory.\n");
			return OMX_ErrorInsufficientResources;
		}
		fsl_osal_memset(pBuffer, 0, BufferSize);
		pWmaDecConfig->sWMADMemInfo.sMemInfoSub[i].app_base_ptr = pBuffer;
	}

	WmaRet = pInitWMADecoder(pWmaDecConfig, pWmaDecParams, NULL, 0);
	if (WmaRet != cWMA_NoErr)
	{
		LOG_ERROR("Wma decoder initialize fail.\n");
		return OMX_ErrorUnsupportedSetting;
	}

	AudioRingBuffer.nPrevOffset = 0;

	return ret;
}
OMX_ERRORTYPE UniaDecoder::CreateDecoderInterface()
{
    OMX_S32 ret = OMX_ErrorNone;

    do{

        tUniACodecQueryInterface  myQueryInterface;

        if(NULL == role || decoderLibName == NULL){
            ret = OMX_ErrorInsufficientResources;
            break;
        }
        if(optionaDecoderlLibName){
            hLib = libMgr->load((fsl_osal_char *)optionaDecoderlLibName);
            LOG_DEBUG("Audio Decoder library name 1: %s\n", optionaDecoderlLibName);
        }

        if(hLib == NULL){
            hLib = libMgr->load((fsl_osal_char *)decoderLibName);
            LOG_DEBUG("Audio Decoder library name 2: %s\n", decoderLibName);
        }

        if(NULL == hLib){
            LOG_ERROR("Fail to open Decoder library for %s\n", role);
            ret = OMX_ErrorComponentNotFound;
            break;
        }

        IDecoder = (UniaDecInterface *)FSL_MALLOC(sizeof(UniaDecInterface));
        if(IDecoder == NULL){
            ret = OMX_ErrorUndefined;
        }
        fsl_osal_memset(IDecoder,0 ,sizeof(UniaDecInterface));

        myQueryInterface = (tUniACodecQueryInterface)libMgr->getSymbol(hLib, (fsl_osal_char *)"UniACodecQueryInterface");
        if(NULL == myQueryInterface)
        {
            LOG_ERROR("Fail to query decoder interface\n");
            ret = OMX_ErrorNotImplemented;
            break;
        }

        ret = myQueryInterface(ACODEC_API_GET_VERSION_INFO, (void **)&IDecoder->GetVersionInfo);

        ret |= myQueryInterface(ACODEC_API_CREATE_CODEC, (void **)&IDecoder->CreateDecoder);
        ret |= myQueryInterface(ACODEC_API_DELETE_CODEC, (void **)&IDecoder->DeleteDecoder);
        ret |= myQueryInterface(ACODEC_API_RESET_CODEC, (void **)&IDecoder->ResetDecoder);
        ret |= myQueryInterface(ACODEC_API_SET_PARAMETER, (void **)&IDecoder->SetParameter);
        ret |= myQueryInterface(ACODEC_API_GET_PARAMETER, (void **)&IDecoder->GetParameter);
        ret |= myQueryInterface(ACODEC_API_DEC_FRAME, (void **)&IDecoder->DecodeFrame);
        ret |= myQueryInterface(ACODEC_API_GET_LAST_ERROR, (void **)&IDecoder->GetLastError);

        if(ret != OMX_ErrorNone){
            LOG_ERROR("Fail to query decoder API\n");
            ret = OMX_ErrorNotImplemented;
            break;
        }

    }while(0);

    if(ret != OMX_ErrorNone){
        LOG_ERROR("UniaDecoder::CreateDecoderInterface ret=%d",ret);
        if (hLib)
            libMgr->unload(hLib);
        hLib = NULL;
        FSL_FREE(IDecoder);
        FSL_DELETE(libMgr);
    }

    return (OMX_ERRORTYPE)ret;
}
OMX_PTR VideoFilter::AllocateOutputBuffer(OMX_U32 nSize)
{
    return FSL_MALLOC(nSize);
}
OMX_ERRORTYPE VideoFilter::ProcessInBufferFlags()
{
    if(pInBufferHdr->nFlags & OMX_BUFFERFLAG_STARTTIME)
        bGetNewSegment = OMX_TRUE;

    if(bGetNewSegment == OMX_TRUE && (!(pInBufferHdr->nFlags & OMX_BUFFERFLAG_CODECCONFIG)))
    {
        LOG_DEBUG("Get New sement buffer, ts %lld\n", pInBufferHdr->nTimeStamp);
        bGetNewSegment = OMX_FALSE;
        bNewSegment = OMX_TRUE;
        bLastInput = OMX_FALSE;
        bLastOutput = OMX_FALSE;
        if(pInBufferHdr->nFlags & OMX_BUFFERFLAG_STARTTRICK)
        {
            LOG_DEBUG("Set ts manager to FIFO mode.\n");
            tsmFlush(hTsHandle, pInBufferHdr->nTimeStamp, MODE_FIFO);
        }
        else
        {
            LOG_DEBUG("Set ts manager to AI mode.\n");
            tsmFlush(hTsHandle, pInBufferHdr->nTimeStamp, MODE_AI);
        }
    }

    if(bLastInput != OMX_FALSE)
    {
        LOG_DEBUG("Filter drop input buffers in EOS state.\n");
        ReturnInputBuffer();
        return OMX_ErrorNoMore;
    }

    if(pInBufferHdr->nFlags & OMX_BUFFERFLAG_EOS)
    {
        bLastInput = OMX_TRUE;
        bNeedInputBuffer = OMX_FALSE;
        pInBufferHdr->nTimeStamp = -1;
        pInBufferHdr->nFilledLen = 0;
        return OMX_ErrorNone;
    }

    if(!(pInBufferHdr->nFlags & OMX_BUFFERFLAG_ENDOFFRAME) && bFilterSupportPartilInput != OMX_TRUE)
    {
        ProcessPartialInput();
        return OMX_ErrorNotReady;
    }

    if(PartialInputHdr.pBuffer != NULL)
    {
        ProcessPartialInput();
        pInBufferHdr = &PartialInputHdr;
    }

    if(pInBufferHdr->nFlags & OMX_BUFFERFLAG_DECODEONLY)
        nDecodeOnly ++;

    if(pInBufferHdr->nFlags & OMX_BUFFERFLAG_CODECCONFIG && pInBufferHdr->nFilledLen > 0)
    {
        if(pCodecData == NULL)
        {
            pCodecData = FSL_MALLOC(pInBufferHdr->nFilledLen);
            if(pCodecData == NULL)
            {
                SendEvent(OMX_EventError, OMX_ErrorInsufficientResources, 0, NULL);
                return OMX_ErrorInsufficientResources;
            }
        }
        else
        {
            pCodecData = FSL_REALLOC(pCodecData, nCodecDataLen + pInBufferHdr->nFilledLen);
            if(pCodecData == NULL)
            {
                SendEvent(OMX_EventError, OMX_ErrorInsufficientResources, 0, NULL);
                return OMX_ErrorInsufficientResources;
            }
        }
        fsl_osal_memcpy((char *)pCodecData + nCodecDataLen, pInBufferHdr->pBuffer, pInBufferHdr->nFilledLen);
        nCodecDataLen += pInBufferHdr->nFilledLen;
        LOG_INFO("Get Codec configure data, len: %d\n", nCodecDataLen);
        ReturnInputBuffer();
        return OMX_ErrorNotReady;
    }

    return OMX_ErrorNone;
}
Exemplo n.º 22
0
QUEUE_ERRORTYPE Queue::Create(
        fsl_osal_u32 maxQSize,
        fsl_osal_u32 msgSize,
        efsl_osal_bool block)
{
    QUEUE_ERRORTYPE ret = QUEUE_SUCCESS;
    fsl_osal_u32 i, aligned_msg_size;
    fsl_osal_ptr ptr = NULL;
    QNODE *pQNode = NULL;
    fsl_osal_u8 *pMsg = NULL;

    pQNodeMem = pQMsgMem = NULL;
    pFreeNodes = pHead = pTail = NULL;
    nQSize = 0;
    lock = usedNodesSem = freeNodesSem = NULL;

    nMaxQSize = maxQSize;
    nMsgSize = msgSize;
    bBlocking = block;

    /* allocate for queue nodes */
    ptr = FSL_MALLOC(sizeof(QNODE) * nMaxQSize);
    if(ptr == NULL) {
        LOG_ERROR("Failed to allocate memory for queue node.\n");
        ret = QUEUE_INSUFFICIENT_RESOURCES;
        goto err;
    }
    pQNodeMem = ptr;
    pQNode = (QNODE*)ptr;

    /* alloate for node messages */
    aligned_msg_size = (nMsgSize + 3)/4*4;
    ptr = FSL_MALLOC(nMaxQSize * aligned_msg_size);
    if(ptr == NULL) {
        LOG_ERROR("Failed to allocate memory for queue node message.\n");
        ret = QUEUE_INSUFFICIENT_RESOURCES;
        goto err;
    }
    pQMsgMem = ptr;
    pMsg = (fsl_osal_u8*)ptr;

    for(i=0; i<nMaxQSize-1; i++) {
        pQNode[i].NextNode = &(pQNode[i+1]);
        pQNode[i].pMsg = pMsg;
        pMsg += aligned_msg_size;
    }
    pQNode[nMaxQSize-1].NextNode = NULL;
    pQNode[nMaxQSize-1].pMsg = pMsg;
    pFreeNodes = pQNode;

    if(fsl_osal_mutex_init(&lock, fsl_osal_mutex_normal) != E_FSL_OSAL_SUCCESS) {
        LOG_ERROR("Failed to create mutex for queue.\n");
        ret = QUEUE_INSUFFICIENT_RESOURCES;
        goto err;
    }

    if(fsl_osal_sem_init(&usedNodesSem, 0, 0) != E_FSL_OSAL_SUCCESS) {
        LOG_ERROR("Failed to create mutex for used nodes.\n");
        ret = QUEUE_INSUFFICIENT_RESOURCES;
        goto err;
    }

    if(fsl_osal_sem_init(&freeNodesSem, 0, nMaxQSize) != E_FSL_OSAL_SUCCESS) {
        LOG_ERROR("Failed to create mutex for free nodes.\n");
        ret = QUEUE_INSUFFICIENT_RESOURCES;
        goto err;
    }

    return ret;

err:
    Free();
    return ret;
}
OMX_ERRORTYPE SRTParser::BuildSeekTable()
{
    TextSource::TEXT_LINE sLine;
    OMX_BOOL bEOS = OMX_FALSE;

    while(1) {
        OMX_S64 nPos = 0;
        mSource->GetCurPosition(nPos);
        mSource->GetNextLine(sLine, bEOS);
        if(bEOS != OMX_FALSE) {
            LOG_DEBUG("%s, EOS.\n", __FUNCTION__);
            break;
        }
        if(sLine.pData == NULL)
            continue;

        int hour1, hour2, min1, min2, sec1, sec2, msec1, msec2;
        if(sscanf((OMX_STRING)sLine.pData, "%02d:%02d:%02d,%03d --> %02d:%02d:%02d,%03d",
                    &hour1, &min1, &sec1, &msec1, &hour2, &min2, &sec2, &msec2) != 8) {
            continue;
        }

        TIME_NODE *node = mTimeTable + mTimeTableEntrySize;
        node->nTime = TIME2US(hour1, min1, sec1, msec1);
        node->nOffset = nPos;
        mTimeTableEntrySize++;
        if(mTimeTableEntrySize >= mTimeTableSize) {
            OMX_PTR temp = FSL_MALLOC(sizeof(TIME_NODE)*(mTimeTableSize + SRT_TIME_TABLE_SIZE));
            if(!temp) {
                LOG_ERROR("failed to allocate time table size to %d\n", mTimeTableSize + SRT_TIME_TABLE_SIZE);
                break;
            }
            fsl_osal_memcpy(temp, mTimeTable, mTimeTableEntrySize*sizeof(TIME_NODE));
            FSL_FREE(mTimeTable);
            mTimeTable = (TIME_NODE*)temp;
            mTimeTableSize += SRT_TIME_TABLE_SIZE;
        }
        LOG_DEBUG("[%d], time: %lld, offset: %lld\n", mTimeTableEntrySize, node->nTime, node->nOffset);
    }

    LOG_DEBUG("mTimeTableEntrySize: %d\n", mTimeTableEntrySize);

    OMX_BOOL needSort = OMX_FALSE;

    if(mTimeTableEntrySize > 1){
        for(OMX_U32 i = 0; i < mTimeTableEntrySize -2; i++){
            if(mTimeTable[i].nTime > mTimeTable[i+1].nTime){
                needSort = OMX_TRUE;
                break;
            }
        }
    }

    if(needSort == OMX_TRUE){
        for(OMX_U32 roundEnd = mTimeTableEntrySize - 1; roundEnd >0; roundEnd--){
            // search for biggest one from 0 to roundEnd
            OMX_U32 biggest = 0;
            for(OMX_U32 i = 1; i <= roundEnd; i++){
                if(mTimeTable[i].nTime > mTimeTable[biggest].nTime)
                    biggest = i;
            }
            if(biggest != roundEnd){
                // exchange biggest with roundEnd
                TIME_NODE node;
                fsl_osal_memcpy(&node, mTimeTable + biggest, sizeof(TIME_NODE));
                fsl_osal_memcpy(mTimeTable + biggest, mTimeTable + roundEnd, sizeof(TIME_NODE));
                fsl_osal_memcpy(mTimeTable + roundEnd, &node,  sizeof(TIME_NODE));
            }
        }
    }

    mSource->SeekTo(0);

    return OMX_ErrorNone;
}