示例#1
0
SSBSIP_MFC_ERROR_CODE SsbSipMfcEncGetInBuf(void *openHandle, SSBSIP_MFC_ENC_INPUT_INFO *input_info)
{
    int ret_code;
    _MFCLIB *pCTX;
    mfc_common_args user_addr_arg, phys_addr_arg;
    int y_size, c_size;
    int aligned_y_size, aligned_c_size;

    if (openHandle == NULL) {
        fprintf(stderr,"SsbSipMfcEncGetInBuf: openHandle is NULL\n");
        return MFC_RET_INVALID_PARAM;
    }

    pCTX = (_MFCLIB *)openHandle;

    user_addr_arg.args.mem_alloc.codec_type = pCTX->codec_type;

    y_size = pCTX->width * pCTX->height;
    c_size = (pCTX->width * pCTX->height) >> 1;

    aligned_y_size = ALIGN_TO_8KB(ALIGN_TO_128B(pCTX->width) * ALIGN_TO_32B(pCTX->height));
    aligned_c_size = ALIGN_TO_8KB(ALIGN_TO_128B(pCTX->width) * ALIGN_TO_32B(pCTX->height/2));

    /* Allocate luma & chroma buf */
    user_addr_arg.args.mem_alloc.buff_size = aligned_y_size + aligned_c_size;
    user_addr_arg.args.mem_alloc.mapped_addr = pCTX->mapped_addr;
    ret_code = ioctl(pCTX->hMFC, IOCTL_MFC_GET_IN_BUF, &user_addr_arg);
    if (ret_code < 0) {
        fprintf(stderr,"SsbSipMfcEncGetInBuf: IOCTL_MFC_GET_IN_BUF failed\n");
        return MFC_RET_ENC_GET_INBUF_FAIL;
    }
    pCTX->virFrmBuf.luma = user_addr_arg.args.mem_alloc.out_uaddr;
    pCTX->virFrmBuf.chroma = user_addr_arg.args.mem_alloc.out_uaddr + (unsigned int)aligned_y_size;
    pCTX->phyFrmBuf.luma = user_addr_arg.args.mem_alloc.out_paddr;
    pCTX->phyFrmBuf.chroma = user_addr_arg.args.mem_alloc.out_paddr + (unsigned int)aligned_y_size;

    pCTX->sizeFrmBuf.luma = (unsigned int)y_size;
    pCTX->sizeFrmBuf.chroma = (unsigned int)c_size;
    pCTX->inter_buff_status |= MFC_USE_YUV_BUFF;

    input_info->YPhyAddr = (void*)pCTX->phyFrmBuf.luma;
    input_info->CPhyAddr = (void*)pCTX->phyFrmBuf.chroma;
    input_info->YVirAddr = (void*)pCTX->virFrmBuf.luma;
    input_info->CVirAddr = (void*)pCTX->virFrmBuf.chroma;

    input_info->YSize    = aligned_y_size;
    input_info->CSize    = aligned_c_size;

    return MFC_RET_OK;
}
OMX_ERRORTYPE SEC_MFC_Mpeg4_Encode(OMX_COMPONENTTYPE *pOMXComponent, SEC_OMX_DATA *pInputData, SEC_OMX_DATA *pOutputData)
{
    OMX_ERRORTYPE              ret = OMX_ErrorNone;
    SEC_OMX_BASECOMPONENT     *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
    SEC_MPEG4ENC_HANDLE       *pMpeg4Enc = (SEC_MPEG4ENC_HANDLE *)pSECComponent->hCodecHandle;
    OMX_HANDLETYPE             hMFCHandle = pMpeg4Enc->hMFCMpeg4Handle.hMFCHandle;
    SSBSIP_MFC_ENC_INPUT_INFO *pInputInfo = &(pMpeg4Enc->hMFCMpeg4Handle.inputInfo);
    SSBSIP_MFC_ENC_OUTPUT_INFO outputInfo;
    SEC_OMX_BASEPORT          *pSECPort = NULL;
    MFC_ENC_ADDR_INFO          addrInfo;
    OMX_U32                    oneFrameSize = pInputData->dataLen;
    OMX_S32                    returnCodec = 0;

    FunctionIn();

    if (pMpeg4Enc->hMFCMpeg4Handle.bConfiguredMFC == OMX_FALSE) {
        returnCodec = SsbSipMfcEncGetOutBuf(hMFCHandle, &outputInfo);
        if (returnCodec != MFC_RET_OK)
        {
            SEC_OSAL_Log(SEC_LOG_ERROR, "%s: SsbSipMfcEncGetOutBuf failed, ret:%d", __FUNCTION__, returnCodec);
            ret = OMX_ErrorUndefined;
            goto EXIT;
        }

        pOutputData->dataBuffer = outputInfo.StrmVirAddr;
        pOutputData->allocSize = outputInfo.headerSize;
        pOutputData->dataLen = outputInfo.headerSize;
        pOutputData->timeStamp = pInputData->timeStamp;
        pOutputData->nFlags |= OMX_BUFFERFLAG_CODECCONFIG;
        pOutputData->nFlags |= OMX_BUFFERFLAG_ENDOFFRAME;

        pMpeg4Enc->hMFCMpeg4Handle.bConfiguredMFC = OMX_TRUE;

        if (pOutputData->dataLen > 0) {
            ret = OMX_ErrorNone;
            goto EXIT;
        } else {
            ret = OMX_ErrorInputDataEncodeYet;
            goto EXIT;
        }
    }

    if ((pInputData->nFlags & OMX_BUFFERFLAG_ENDOFFRAME) &&
        (pSECComponent->bUseFlagEOF == OMX_FALSE)) {
        pSECComponent->bUseFlagEOF = OMX_TRUE;
    }

    pSECComponent->timeStamp[pMpeg4Enc->hMFCMpeg4Handle.indexTimestamp] = pInputData->timeStamp;
    pSECComponent->nFlags[pMpeg4Enc->hMFCMpeg4Handle.indexTimestamp] = pInputData->nFlags;
    SsbSipMfcEncSetConfig(hMFCHandle, MFC_ENC_SETCONF_FRAME_TAG, &(pMpeg4Enc->hMFCMpeg4Handle.indexTimestamp));
    pMpeg4Enc->hMFCMpeg4Handle.indexTimestamp++;
    if (pMpeg4Enc->hMFCMpeg4Handle.indexTimestamp >= MAX_TIMESTAMP)
        pMpeg4Enc->hMFCMpeg4Handle.indexTimestamp = 0;

    if (oneFrameSize <= 0) {
        pOutputData->timeStamp = pInputData->timeStamp;
        pOutputData->nFlags = pInputData->nFlags;

        ret = OMX_ErrorNone;
        goto EXIT;
    }

    pSECPort = &pSECComponent->pSECPort[INPUT_PORT_INDEX];
    if (pSECPort->portDefinition.format.video.eColorFormat == SEC_OMX_COLOR_FormatNV12PhysicalAddress) {
    /* input data from Real camera */
#define USE_FIMC_FRAME_BUFFER
#ifdef USE_FIMC_FRAME_BUFFER
        SEC_OSAL_Memcpy(&addrInfo.pAddrY, pInputData->dataBuffer, sizeof(addrInfo.pAddrY));
        SEC_OSAL_Memcpy(&addrInfo.pAddrC, pInputData->dataBuffer + sizeof(addrInfo.pAddrY), sizeof(addrInfo.pAddrC));
        pInputInfo->YPhyAddr = addrInfo.pAddrY;
        pInputInfo->CPhyAddr = addrInfo.pAddrC;
        returnCodec = SsbSipMfcEncSetInBuf(hMFCHandle, pInputInfo);
        if (returnCodec != MFC_RET_OK) {
            SEC_OSAL_Log(SEC_LOG_ERROR, "%s: SsbSipMfcEncSetInBuf failed, ret:%d", __FUNCTION__, returnCodec);
            ret = OMX_ErrorUndefined;
            goto EXIT;
        }
#else
        OMX_U32 width, height;

        width = pSECPort->portDefinition.format.video.nFrameWidth;
        height = pSECPort->portDefinition.format.video.nFrameHeight;

        SEC_OSAL_Memcpy(pInputInfo->YVirAddr, pInputData->dataBuffer, ALIGN_TO_8KB(ALIGN_TO_128B(width) * ALIGN_TO_32B(height)));
        SEC_OSAL_Memcpy(pInputInfo->CVirAddr, pInputData->dataBuffer + ALIGN_TO_8KB(ALIGN_TO_128B(width) * ALIGN_TO_32B(height)), ALIGN_TO_8KB(ALIGN_TO_128B(width) * ALIGN_TO_32B(height / 2)));
#endif
    }

    returnCodec = SsbSipMfcEncExe(hMFCHandle);
    if (returnCodec == MFC_RET_OK) {
        OMX_S32 indexTimestamp = 0;

        returnCodec = SsbSipMfcEncGetOutBuf(hMFCHandle, &outputInfo);

        if ((SsbSipMfcEncGetConfig(hMFCHandle, MFC_ENC_GETCONF_FRAME_TAG, &indexTimestamp) != MFC_RET_OK) ||
            (((indexTimestamp < 0) || (indexTimestamp > MAX_TIMESTAMP)))) {
            pOutputData->timeStamp = pInputData->timeStamp;
            pOutputData->nFlags = pInputData->nFlags;
        } else {
            pOutputData->timeStamp = pSECComponent->timeStamp[indexTimestamp];
            pOutputData->nFlags = pSECComponent->nFlags[indexTimestamp];
        }

        if (returnCodec == MFC_RET_OK) {
            /** Fill Output Buffer **/
            pOutputData->dataBuffer = outputInfo.StrmVirAddr;
            pOutputData->allocSize = outputInfo.dataSize;
            pOutputData->dataLen = outputInfo.dataSize;
            pOutputData->nFlags |= OMX_BUFFERFLAG_ENDOFFRAME;
            if (outputInfo.frameType == MFC_FRAME_TYPE_I_FRAME)
                    pOutputData->nFlags |= OMX_BUFFERFLAG_SYNCFRAME;

            ret = OMX_ErrorNone;
        } else {
            SEC_OSAL_Log(SEC_LOG_ERROR, "%s: SsbSipMfcEncGetOutBuf failed, ret:%d", __FUNCTION__, returnCodec);
            ret = OMX_ErrorUndefined;
        }
    } else {
        SEC_OSAL_Log(SEC_LOG_ERROR, "%s: SsbSipMfcEncExe failed, ret:%d", __FUNCTION__, returnCodec);
        ret = OMX_ErrorUndefined;
    }

EXIT:
    FunctionOut();

    return ret;
}
OMX_ERRORTYPE SEC_MFC_H264_Encode(OMX_COMPONENTTYPE *pOMXComponent, SEC_OMX_DATA *pInputData, SEC_OMX_DATA *pOutputData)
{
    OMX_ERRORTYPE              ret = OMX_ErrorNone;
    SEC_OMX_BASECOMPONENT     *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate;
    SEC_H264ENC_HANDLE        *pH264Enc = (SEC_H264ENC_HANDLE *)pSECComponent->hCodecHandle;
    SSBSIP_MFC_ENC_INPUT_INFO *pInputInfo = &pH264Enc->hMFCH264Handle.inputInfo;
    SSBSIP_MFC_ENC_OUTPUT_INFO outputInfo;
    SEC_OMX_BASEPORT          *pSECPort = NULL;
    MFC_ENC_ADDR_INFO          addrInfo;
    OMX_U32                    oneFrameSize = pInputData->dataLen;
    OMX_S32                    returnCodec = 0;

    FunctionIn();

    if (pH264Enc->hMFCH264Handle.bConfiguredMFC == OMX_FALSE) {
        returnCodec = SsbSipMfcEncGetOutBuf(pH264Enc->hMFCH264Handle.hMFCHandle, &outputInfo);
        if (returnCodec != MFC_RET_OK)
        {
            SEC_OSAL_Log(SEC_LOG_TRACE, "%s - SsbSipMfcEncGetOutBuf Failed\n", __func__);
            ret = OMX_ErrorUndefined;
            goto EXIT;
        } else {
            unsigned char *p = NULL;
            int iSpsSize = 0;
            int iPpsSize = 0;

            p = FindDelimiter((OMX_U8 *)outputInfo.StrmVirAddr + 4, outputInfo.headerSize - 4);

            iSpsSize = (unsigned int)p - (unsigned int)outputInfo.StrmVirAddr;
            pH264Enc->hMFCH264Handle.headerData.pHeaderSPS = (OMX_PTR)outputInfo.StrmVirAddr;
            pH264Enc->hMFCH264Handle.headerData.SPSLen = iSpsSize;

            iPpsSize = outputInfo.headerSize - iSpsSize;
            pH264Enc->hMFCH264Handle.headerData.pHeaderPPS = outputInfo.StrmVirAddr + iSpsSize;
            pH264Enc->hMFCH264Handle.headerData.PPSLen = iPpsSize;
        }

        /* SEC_OSAL_Memcpy((void*)(pOutputData->dataBuffer), (const void*)(outputInfo.StrmVirAddr), outputInfo.headerSize); */
        pOutputData->dataBuffer = outputInfo.StrmVirAddr;
        pOutputData->allocSize = outputInfo.headerSize;
        pOutputData->dataLen = outputInfo.headerSize;
        pOutputData->timeStamp = pInputData->timeStamp;
        pOutputData->nFlags |= OMX_BUFFERFLAG_CODECCONFIG;
        pOutputData->nFlags |= OMX_BUFFERFLAG_ENDOFFRAME;

        pH264Enc->hMFCH264Handle.bConfiguredMFC = OMX_TRUE;

        ret = OMX_ErrorNone;
        goto EXIT;
    }

    if ((pInputData->nFlags & OMX_BUFFERFLAG_ENDOFFRAME) &&
        (pSECComponent->bUseFlagEOF == OMX_FALSE)) {
        pSECComponent->bUseFlagEOF = OMX_TRUE;
    }

    pSECComponent->timeStamp[pH264Enc->hMFCH264Handle.indexTimestamp] = pInputData->timeStamp;
    pSECComponent->nFlags[pH264Enc->hMFCH264Handle.indexTimestamp] = pInputData->nFlags;
    SsbSipMfcEncSetConfig(pH264Enc->hMFCH264Handle.hMFCHandle, MFC_ENC_SETCONF_FRAME_TAG, &(pH264Enc->hMFCH264Handle.indexTimestamp));
    pH264Enc->hMFCH264Handle.indexTimestamp++;
    if (pH264Enc->hMFCH264Handle.indexTimestamp >= MAX_TIMESTAMP)
        pH264Enc->hMFCH264Handle.indexTimestamp = 0;

    if (oneFrameSize <= 0) {
        pOutputData->timeStamp = pInputData->timeStamp;
        pOutputData->nFlags = pInputData->nFlags;

        ret = OMX_ErrorNone;
        goto EXIT;
    }

    pSECPort = &pSECComponent->pSECPort[INPUT_PORT_INDEX];
    if (pSECPort->portDefinition.format.video.eColorFormat == SEC_OMX_COLOR_FormatNV12PhysicalAddress) {
#define USE_FIMC_FRAME_BUFFER
#ifdef USE_FIMC_FRAME_BUFFER
        SEC_OSAL_Memcpy(&addrInfo.pAddrY, pInputData->dataBuffer, sizeof(addrInfo.pAddrY));
        SEC_OSAL_Memcpy(&addrInfo.pAddrC, pInputData->dataBuffer + sizeof(addrInfo.pAddrY), sizeof(addrInfo.pAddrC));
        pInputInfo->YPhyAddr = addrInfo.pAddrY;
        pInputInfo->CPhyAddr = addrInfo.pAddrC;
        ret = SsbSipMfcEncSetInBuf(pH264Enc->hMFCH264Handle.hMFCHandle, pInputInfo);
        if (ret != MFC_RET_OK) {
            SEC_OSAL_Log(SEC_LOG_TRACE, "Error : SsbSipMfcEncSetInBuf() \n");
            ret = OMX_ErrorUndefined;
            goto EXIT;
        }
#else
        OMX_U32 width, height;

        width = pSECPort->portDefinition.format.video.nFrameWidth;
        height = pSECPort->portDefinition.format.video.nFrameHeight;

        SEC_OSAL_Memcpy(pInputInfo->YVirAddr, pInputData->dataBuffer, ALIGN_TO_8KB(ALIGN_TO_128B(width) * ALIGN_TO_32B(height)));
        SEC_OSAL_Memcpy(pInputInfo->CVirAddr, pInputData->dataBuffer + ALIGN_TO_8KB(ALIGN_TO_128B(width) * ALIGN_TO_32B(height)), ALIGN_TO_8KB(ALIGN_TO_128B(width) * ALIGN_TO_32B(height / 2)));
#endif
    }

    returnCodec = SsbSipMfcEncExe(pH264Enc->hMFCH264Handle.hMFCHandle);
    if (returnCodec == MFC_RET_OK) {
        OMX_S32 indexTimestamp = 0;

        returnCodec = SsbSipMfcEncGetOutBuf(pH264Enc->hMFCH264Handle.hMFCHandle, &outputInfo);
        if ((SsbSipMfcEncGetConfig(pH264Enc->hMFCH264Handle.hMFCHandle, MFC_ENC_GETCONF_FRAME_TAG, &indexTimestamp) != MFC_RET_OK) ||
            (((indexTimestamp < 0) || (indexTimestamp > MAX_TIMESTAMP)))){
            pOutputData->timeStamp = pInputData->timeStamp;
            pOutputData->nFlags = pInputData->nFlags;
        } else {
            pOutputData->timeStamp = pSECComponent->timeStamp[indexTimestamp];
            pOutputData->nFlags = pSECComponent->nFlags[indexTimestamp];
        }

        if (returnCodec == MFC_RET_OK) {
            /** Fill Output Buffer **/
            pOutputData->dataBuffer = outputInfo.StrmVirAddr;
            pOutputData->allocSize = outputInfo.dataSize;
            pOutputData->dataLen = outputInfo.dataSize;
            pOutputData->usedDataLen = 0;

            pOutputData->nFlags |= OMX_BUFFERFLAG_ENDOFFRAME;
            if (outputInfo.frameType == MFC_FRAME_TYPE_I_FRAME)
                    pOutputData->nFlags |= OMX_BUFFERFLAG_SYNCFRAME;

            SEC_OSAL_Log(SEC_LOG_TRACE, "MFC Encode OK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");

            ret = OMX_ErrorNone;
        }
    }

    if (returnCodec != MFC_RET_OK) {
        SEC_OSAL_Log(SEC_LOG_ERROR, "In %s : SsbSipMfcEncExe OR SsbSipMfcEncGetOutBuf Failed!!!\n", __func__);
        ret = OMX_ErrorUndefined;
    }

EXIT:
    FunctionOut();

    return ret;
}
示例#4
0
static 
int samsung_enc_frame(AVCodecContext *ctx, uint8_t *buf,
                      int orig_bufsize, void *data)
{
    int nRet = 0;
	AVFrame *frame = (AVFrame *)data;
    int lenHeader = 0;
	if((!(frame && frame->data[0])))  return 0;
    //__android_log_print(ANDROID_LOG_INFO, "tt", "samsung_enc_init1 is %d", pdlhandle1);
	if( hMFCH264Handle.bConfiguredMFC == OMX_FALSE ) {
#if 1
		if(p_SsbSipMfcEncOpen)
		   hMFCHandle = p_SsbSipMfcEncOpen();
		if( hMFCHandle == NULL )
		   return -1;
		//__android_log_print(ANDROID_LOG_INFO, "tt", "samsung_enc_init1 is %d", pdlhandle1);
		hMFCH264Handle.hMFCHandle = hMFCHandle;
		hMFCH264Handle.bConfiguredMFC = OMX_FALSE;
		
		SetH264EncParam( &(hMFCH264Handle.mfcVideoAvc), ctx);

		if(p_SsbSipMfcEncInit){
			nRet = p_SsbSipMfcEncInit( hMFCH264Handle.hMFCHandle, &(hMFCH264Handle.mfcVideoAvc) );
			if( nRet != MFC_RET_OK )  return -1;
		}
		//__android_log_print(ANDROID_LOG_INFO, "tt", "samsung_enc_init2 is %d", pdlhandle1);
		
		if(p_SsbSipMfcEncGetInBuf) {
			nRet = p_SsbSipMfcEncGetInBuf( hMFCH264Handle.hMFCHandle, &(hMFCH264Handle.inputInfo) );
			if( nRet != MFC_RET_OK ) return -1;
		}
	    inputInfo = hMFCH264Handle.inputInfo;
	    hMFCH264Handle.indexTimestamp = 0;
#endif 
		if(p_SsbSipMfcEncGetOutBuf) {
			nRet = p_SsbSipMfcEncGetOutBuf( hMFCH264Handle.hMFCHandle, &outputInfo );
			if( nRet != MFC_RET_OK )  return 0;
		}

		char* p = NULL;
		int nSpsSize = 0;
		int nPpsSize = 0;

		p = (char*)FindDelimiter( (OMX_U8*)outputInfo.StrmVirAddr+4, outputInfo.headerSize-4 );

		nSpsSize = (unsigned int)p - (unsigned int)outputInfo.StrmVirAddr;
		hMFCH264Handle.headerData.pHeaderSPS = (OMX_PTR)outputInfo.StrmVirAddr;
		hMFCH264Handle.headerData.SPSLen = nSpsSize;

		nPpsSize = outputInfo.headerSize - nSpsSize;
		hMFCH264Handle.headerData.pHeaderPPS = (OMX_PTR)outputInfo.StrmVirAddr + nSpsSize;
		hMFCH264Handle.headerData.PPSLen = nPpsSize;

        memcpy(buf, (OMX_BYTE)outputInfo.StrmVirAddr, outputInfo.headerSize);
#if 0
				FILE *f = fopen("/sdcard/2.264", "ab+");
				if(f!=NULL)
				   fwrite(buf, 1, outputInfo.headerSize, f);
				fclose(f);
				f = NULL;
#endif	
        if(outputInfo.headerSize > 0) {
			av_freep(&ctx->extradata);
			ctx->extradata		= ( uint8_t *)av_malloc(outputInfo.headerSize);
			ctx->extradata_size = outputInfo.headerSize;//encode_nals(avctx, avctx->extradata, s, nal, nnal, 1);  
			memcpy(ctx->extradata,buf,outputInfo.headerSize);
        }

		//__android_log_print(ANDROID_LOG_INFO, "tt", "outputData.dataLen is %d,%d,%d,%d,%d",*(buf+1), *(buf+2),*(buf+3),*(buf+4),outputInfo.headerSize);
		buf += outputInfo.headerSize;
		lenHeader = outputInfo.headerSize;
		//outputData.dataBuffer = (OMX_BYTE)outputInfo.StrmVirAddr;
		//outputData.allocSize = outputInfo.headerSize;
		//outputData.dataLen = outputInfo.headerSize;
		//outputData.timeStamp = inputData.timeStamp;
		//outputData.nFlags |= OMX_BUFFERFLAG_CODECCONFIG;
		//outputData.nFlags |= OMX_BUFFERFLAG_ENDOFFRAME;

		hMFCH264Handle.bConfiguredMFC = OMX_TRUE;

        return 0;
		//__android_log_print(ANDROID_LOG_INFO, "tt", "outputData.dataLen is %d", lenHeader);

		//return outputData.dataLen;
	}

    if ((frame && frame->data[0])) {
        if (0 && frame->interlaced_frame == -1) { //硬件地址
			//__android_log_print(ANDROID_LOG_INFO, "tt", "data is %d,%d", frame->data[0],frame->data[1]);

            inputInfo.YPhyAddr = frame->sample_aspect_ratio.num;//ALIGN_TO_64KB((int)(frame->data[0]));
            inputInfo.CPhyAddr = frame->sample_aspect_ratio.den;//ALIGN_TO_64KB((int)(frame->data[1]));
			//__android_log_print(ANDROID_LOG_INFO, "tt", "data is %d,%d", frame->sample_aspect_ratio.num,frame->data[1]);
            nRet = p_SsbSipMfcEncSetInBuf(hMFCH264Handle.hMFCHandle, &inputInfo);
			if (nRet != MFC_RET_OK) {
				//__android_log_print(ANDROID_LOG_INFO, "tt", "error is %d", nRet);
                return 0;
            }
		} else {  //虚拟地址
		    //__android_log_print(ANDROID_LOG_INFO, "tt", "dd is %d,%d",frame->linesize[0],frame->linesize[1]);
			if(picBuf1 == NULL)
				picBuf1 = (unsigned char*)av_mallocz(ctx->width*ctx->height*4/2);
			//临时拷
			unsigned char* picY = ALIGN_TO_64KB((int)picBuf1);
			unsigned char* picU = ALIGN_TO_64KB((int)picBuf1) + ALIGN_TO_64KB(ALIGN_TO_128B(ctx->width) * ALIGN_TO_32B(ctx->height));
			unsigned char* picV = ALIGN_TO_64KB((int)picBuf1) + ALIGN_TO_64KB(ALIGN_TO_128B(ctx->width) * ALIGN_TO_32B(ctx->height))+ctx->width*ctx->height/4;
			int vuWidth = ctx->width/2;
			int vuheight = ctx->height/2;
			int vuWidthDoub = vuWidth*2;
			int vuheightDoub = vuheight*2;

			for(int i = 0; i<ctx->height; i++)
			   	memcpy(inputInfo.YVirAddr + ctx->width*i, (unsigned char*)frame->data[0]+frame->linesize[0]*i,ctx->width);
#if 1
			for(int i = 0; i < vuheight; i++) {
	            for(int j = 0; j < vuWidth; j++) {
	                *(((unsigned char *)inputInfo.CVirAddr) + vuWidthDoub*i + j*2) = *((unsigned char*)(frame->data[1]+frame->linesize[1]*i + j));
					*(((unsigned char *)inputInfo.CVirAddr) + vuWidthDoub*i + j*2 + 1) = *((unsigned char*)(frame->data[2]+frame->linesize[2]*i + j));
				}
			}
#endif
		}
		//memset(inputInfo.CVirAddr,128,vuWidth*vuheight*2);
#if 0
		for(int i = 0; i<ctx->height; i++)
		   	memcpy(picY + ctx->width*i, (unsigned char*)frame->data[0]+frame->linesize[0]*i,ctx->width);
		for(int i = 0; i < vuheight; i++) {
            memcpy(picU + vuWidth*i, (unsigned char*)frame->data[1]+frame->linesize[1]*i,vuWidth);
			memcpy(picV + vuWidth*i, (unsigned char*)frame->data[2]+frame->linesize[2]*i,vuWidth);
		}
#endif

#if 0
				FILE *f = fopen("/sdcard/1.yuv", "ab+");
				if(f!=NULL) {
				   for(int i = 0; i<ctx->height; i++)
					   fwrite((unsigned char*)frame->data[0]+frame->linesize[0]*i, 1, ctx->width, f);
				   for(int i = 0; i<ctx->height/2; i++)
					   fwrite((unsigned char*)frame->data[1]+frame->linesize[1]*i, 1, ctx->width/2, f);
				   for(int i = 0; i<ctx->height/2; i++)
					   fwrite((unsigned char*)frame->data[2]+frame->linesize[2]*i, 1, ctx->width/2, f);
				}
				fclose(f);
				f = NULL;
#endif

#if 0

	    inputInfo.YPhyAddr = picY;
		inputInfo.CPhyAddr = picU;
		if(p_SsbSipMfcEncSetInBuf) {
			nRet = p_SsbSipMfcEncSetInBuf( hMFCH264Handle.hMFCHandle, &inputInfo );
			if( nRet != MFC_RET_OK )  return 0;
		}
#else
        //memcpy(inputInfo.YVirAddr, picY, ALIGN_TO_64KB(ALIGN_TO_128B(ctx->width) * ALIGN_TO_32B(ctx->height)));
        //memcpy(inputInfo.CVirAddr, picU, ctx->width*ctx->height/2);

#endif
        //if(p_SsbSipMfcEncSetConfig)
		  // p_SsbSipMfcEncSetConfig( hMFCH264Handle.hMFCHandle, MFC_ENC_SETCONF_FRAME_TAG, &(indexTimestamp));

		indexTimestamp++;
        indexTimestamp %= MAX_TIMESTAMP;
		//__android_log_print(ANDROID_LOG_INFO, "tt", "p_SsbSipMfcEncExe is %d", nRet);
		if(p_SsbSipMfcEncExe) {        
			nRet = p_SsbSipMfcEncExe( hMFCH264Handle.hMFCHandle );
			if( nRet != MFC_RET_OK )  return 0;
		}
		//__android_log_print(ANDROID_LOG_INFO, "tt", "p_SsbSipMfcEncExe1 is %d", nRet);

		if(p_SsbSipMfcEncGetOutBuf) {
			nRet = p_SsbSipMfcEncGetOutBuf( hMFCH264Handle.hMFCHandle, &outputInfo );
			if( nRet != MFC_RET_OK )  return 0;
		}
        //__android_log_print(ANDROID_LOG_INFO, "tt", "p_SsbSipMfcEncExe2 is %d", outputInfo.dataSize);
		memcpy(buf, (OMX_BYTE)outputInfo.StrmVirAddr, outputInfo.dataSize);

#if 0
				FILE *f = fopen("/sdcard/2.264", "ab+");
				if(f!=NULL)
				   fwrite(buf, 1, outputInfo.dataSize, f);
				fclose(f);
				f = NULL;
#endif	
		if (buf[0]==0&&buf[1]==0&&buf[2]==0&&buf[3]==1&&((buf[4]&0x0f)==0x05)) {
			frame->key_frame = 1;
			frame->pict_type = AV_PICTURE_TYPE_I;
		}
		else {
			frame->key_frame = 0;
			frame->pict_type = AV_PICTURE_TYPE_P;
		}

		ctx->coded_frame = frame;
		//__android_log_print(ANDROID_LOG_INFO, "tt", "samsung_enc_frame is %d,%d,%d,%d,%d,%d,%d,%d",outputInfo.dataSize+lenHeader,ctx->width,ctx->height,*(buf+2), *(buf+3), \
		//	                                                                               *(buf+4),*(buf+5), outputInfo.frameType);
		//__android_log_print(ANDROID_LOG_INFO, "tt", "p_SsbSipMfcEncExe2 is %d", nRet);

		return outputInfo.dataSize+lenHeader;
		//outputData.dataBuffer = (OMX_BYTE)outputInfo.StrmVirAddr;
		//outputData.allocSize = outputInfo.dataSize;
		//outputData.dataLen = outputInfo.dataSize;

    }


	return 0;
}