Пример #1
0
OMX_ERRORTYPE VideoRender::InitComponent()
{
    OMX_ERRORTYPE ret = OMX_ErrorNone;
    OMX_PARAM_PORTDEFINITIONTYPE sPortDef;
    OMX_BUFFERSUPPLIERTYPE SupplierType;

    OMX_INIT_STRUCT(&sPortDef, OMX_PARAM_PORTDEFINITIONTYPE);
    sPortDef.nPortIndex = IN_PORT;
    sPortDef.eDir = OMX_DirInput;
    sPortDef.eDomain = OMX_PortDomainVideo;
    fsl_osal_memcpy(&sPortDef.format.video, &sVideoFmt, sizeof(OMX_VIDEO_PORTDEFINITIONTYPE));
    sPortDef.bPopulated = OMX_FALSE;
    sPortDef.bEnabled = OMX_TRUE;
    sPortDef.nBufferCountMin = nFrameBufferMin;
    sPortDef.nBufferCountActual = nFrameBufferActual;
    sPortDef.nBufferSize = sPortDef.format.video.nFrameWidth
        * sPortDef.format.video.nFrameHeight
        * pxlfmt2bpp(sVideoFmt.eColorFormat) / 8;
    ret = ports[IN_PORT]->SetPortDefinition(&sPortDef);
    if(ret != OMX_ErrorNone) {
        LOG_ERROR("Set port definition for in port failed.\n");
        return ret;
    }

    ports[IN_PORT]->SetSupplierType(TunneledSupplierType);

    sPortDef.nPortIndex = CLK_PORT;
    sPortDef.eDir = OMX_DirInput;
    sPortDef.eDomain = OMX_PortDomainOther;
    sPortDef.format.other.eFormat = OMX_OTHER_FormatTime;
    sPortDef.bPopulated = OMX_FALSE;
    sPortDef.bEnabled = OMX_FALSE;
    sPortDef.nBufferCountMin = 1;
    sPortDef.nBufferCountActual = 1;
    sPortDef.nBufferSize = sizeof(OMX_TIME_MEDIATIMETYPE);
    ret = ports[CLK_PORT]->SetPortDefinition(&sPortDef);
    if(ret != OMX_ErrorNone) {
        LOG_ERROR("Set port definition for clk port failed.\n");
        return ret;
    }

    SupplierType = OMX_BufferSupplyOutput;
    ports[CLK_PORT]->SetSupplierType(SupplierType);

    fsl_osal_memset(&hClock, 0, sizeof(TUNNEL_INFO));
    ClockState = OMX_TIME_ClockStateStopped;
    ClockScale = Q16_SHIFT;
    pSyncFrame = NULL;
    nFrameCnt = nDropCnt = nDeviceDropCnt = nContiniousDrop = 0;
    playbackMode = NORMAL_MODE;

    InitVideoVisitors();

    ret = InitRenderComponent();
    if(ret != OMX_ErrorNone)
        return ret;

    return ret;
}
OMX_ERRORTYPE VideoFilter::PortFormatChanged(OMX_U32 nPortIndex)
{
    OMX_PARAM_PORTDEFINITIONTYPE sPortDef;

    OMX_INIT_STRUCT(&sPortDef, OMX_PARAM_PORTDEFINITIONTYPE);

    if(nPortIndex == IN_PORT)
    {
        sPortDef.nPortIndex = IN_PORT;
        ports[IN_PORT]->GetPortDefinition(&sPortDef);
        //fsl_osal_memcpy(&sInFmt, &(sPortDef.format.video), sizeof(OMX_VIDEO_PORTDEFINITIONTYPE));
        sInFmt.nFrameWidth = sPortDef.format.video.nFrameWidth;
        sInFmt.nFrameHeight = sPortDef.format.video.nFrameHeight;
        sInFmt.eCompressionFormat = sPortDef.format.video.eCompressionFormat;
        sInFmt.eColorFormat = sPortDef.format.video.eColorFormat;
        sInFmt.xFramerate = sPortDef.format.video.xFramerate;

        OMX_INIT_STRUCT(&sPortDef, OMX_PARAM_PORTDEFINITIONTYPE);
        sPortDef.nPortIndex = OUT_PORT;
        ports[OUT_PORT]->GetPortDefinition(&sPortDef);
        if (Rotation.nRotation == 90 || Rotation.nRotation == 270)
        {
            sPortDef.format.video.nFrameWidth = sInFmt.nFrameHeight;
            sPortDef.format.video.nFrameHeight = sInFmt.nFrameWidth;

        }
        else
        {
            sPortDef.format.video.nFrameWidth = sInFmt.nFrameWidth;
            sPortDef.format.video.nFrameHeight = sInFmt.nFrameHeight;

        }
        sPortDef.format.video.xFramerate = sInFmt.xFramerate;
        if(sInFmt.eCompressionFormat != OMX_VIDEO_CodingUnused)
            sPortDef.nBufferSize = sPortDef.format.video.nFrameWidth * sPortDef.format.video.nFrameHeight
                                   * pxlfmt2bpp(sPortDef.format.video.eColorFormat) / 8;
        ports[OUT_PORT]->SetPortDefinition(&sPortDef);

        if(hTsHandle != NULL)
            tsmSetFrmRate(hTsHandle, sInFmt.xFramerate, Q16_SHIFT);
    }

    if(nPortIndex == OUT_PORT)
    {
        sPortDef.nPortIndex = OUT_PORT;
        ports[OUT_PORT]->GetPortDefinition(&sPortDef);
        //fsl_osal_memcpy(&sOutFmt, &(sPortDef.format.video), sizeof(OMX_VIDEO_PORTDEFINITIONTYPE));
        sOutFmt.nFrameWidth = sPortDef.format.video.nFrameWidth;
        sOutFmt.nFrameHeight = sPortDef.format.video.nFrameHeight;
        sOutFmt.xFramerate=sPortDef.format.video.xFramerate;
        sOutFmt.nBitrate=sPortDef.format.video.nBitrate;
        sOutFmt.eCompressionFormat = sPortDef.format.video.eCompressionFormat;
        sOutFmt.eColorFormat = sPortDef.format.video.eColorFormat;
        nOutBufferCnt = sPortDef.nBufferCountActual;
    }

    return OMX_ErrorNone;
}
OMX_ERRORTYPE VideoFilter::CheckPortResource(OMX_U32 nPortIndex)
{
    OMX_PARAM_PORTDEFINITIONTYPE sPortDef;
    OMX_VIDEO_PORTDEFINITIONTYPE *pFmt;
    OMX_U32 nBufferCnt = 0;
    OMX_BOOL bResourceChanged = OMX_FALSE;

    OMX_INIT_STRUCT(&sPortDef, OMX_PARAM_PORTDEFINITIONTYPE);
    sPortDef.nPortIndex = nPortIndex;
    ports[nPortIndex]->GetPortDefinition(&sPortDef);

    if(nPortIndex == IN_PORT)
    {
        pFmt = &sInFmt;
        nBufferCnt = nInBufferCnt;
    }
    else
    {
        pFmt = &sOutFmt;
        nBufferCnt = nOutBufferCnt;
    }

    if(pFmt->nFrameWidth != sPortDef.format.video.nFrameWidth
            || pFmt->nFrameHeight != sPortDef.format.video.nFrameHeight
            || nBufferCnt != sPortDef.nBufferCountActual)
    {
        LOG_INFO("Filter port #%d resource changed, need reconfigure.\n", nPortIndex);
        LOG_INFO("from %dx%dx%d to %dx%dx%d.\n",
                 sPortDef.format.video.nFrameWidth,
                 sPortDef.format.video.nFrameHeight,
                 sPortDef.nBufferCountActual,
                 pFmt->nFrameWidth, pFmt->nFrameHeight, nBufferCnt);

        bResourceChanged = OMX_TRUE;
        sPortDef.nBufferSize = pFmt->nFrameWidth * pFmt->nFrameHeight * pxlfmt2bpp(pFmt->eColorFormat) / 8;
        sPortDef.nBufferCountActual = nBufferCnt;
        LOG_DEBUG("Need buffer size: %d\n", sPortDef.nBufferSize);
    }

    fsl_osal_memcpy(&(sPortDef.format.video), pFmt, sizeof(OMX_VIDEO_PORTDEFINITIONTYPE));
    ports[nPortIndex]->SetPortDefinition(&sPortDef);

    if(bResourceChanged)
    {
        SendEvent(OMX_EventPortSettingsChanged, nPortIndex, 0, NULL);
        LOG_DEBUG("Send Port setting changed event.\n");
        bInReturnBufferState = OMX_TRUE;
        return OMX_ErrorNotReady;
    }

    return OMX_ErrorNoMore;
}
Пример #4
0
WmvDecoder::WmvDecoder()
{
    fsl_osal_strcpy((fsl_osal_char*)name, "OMX.Freescale.std.video_decoder.wmv.sw-based");
    ComponentVersion.s.nVersionMajor = 0x0;
    ComponentVersion.s.nVersionMinor = 0x1;
    ComponentVersion.s.nRevision = 0x0;
    ComponentVersion.s.nStep = 0x0;
    role_cnt = 1;
    role[0] = (OMX_STRING)"video_decoder.wmv";

    fsl_osal_memset(&sInFmt, 0, sizeof(OMX_VIDEO_PORTDEFINITIONTYPE));
    sInFmt.nFrameWidth = 320;
    sInFmt.nFrameHeight = 240;
    sInFmt.xFramerate = 30 * Q16_SHIFT;
    sInFmt.eColorFormat = OMX_COLOR_FormatUnused;
    sInFmt.eCompressionFormat = OMX_VIDEO_CodingWMV;

	nInPortFormatCnt = 0;
	nOutPortFormatCnt = 1;
	eOutPortPormat[0] = OMX_COLOR_FormatYUV420Planar;

    sOutFmt.nFrameWidth = 320;
    sOutFmt.nFrameHeight = 240;
    sOutFmt.eColorFormat = OMX_COLOR_FormatYUV420Planar;
    sOutFmt.eCompressionFormat = OMX_VIDEO_CodingUnused;

    bFilterSupportPartilInput = OMX_FALSE;
    nInBufferCnt = 1;
    nInBufferSize = 128*1024;
    nOutBufferCnt = 1;
    nOutBufferSize = sOutFmt.nFrameWidth * sOutFmt.nFrameHeight * pxlfmt2bpp(sOutFmt.eColorFormat) / 8;

    pInBuffer = pOutBuffer = NULL;
    nInputSize = nInputOffset = 0;
    bInEos = OMX_FALSE;
    nFrameSize = 0;;
    pFrameBuffer = NULL;

    OMX_INIT_STRUCT(&sOutCrop, OMX_CONFIG_RECTTYPE);
    sOutCrop.nPortIndex = OUT_PORT;
    sOutCrop.nLeft = sOutCrop.nTop = 0;
    sOutCrop.nWidth = sInFmt.nFrameWidth;
    sOutCrop.nHeight = sInFmt.nFrameHeight;

    fsl_osal_memset(&sDecObj, 0, sizeof(sWmv9DecObjectType));
    eFormat = E_WMV9D_COMP_FMT_UNSUPPORTED;
    eWmvDecState = WMVDEC_LOADED;
    hLib = NULL;
    libMgr  = NULL;
    nTop = nLeft = 0;
}
OMX_ERRORTYPE V4lRender::CaptureFrame(OMX_U32 nIndex)
{
	if(sCapture.pBuffer == NULL)
		return OMX_ErrorBadParameter;

	if(nIndex < 0)
		return OMX_ErrorBadParameter;

	fsl_osal_memcpy(sCapture.pBuffer,
	                fb_data[nIndex].pVirtualAddr,
	                sVideoFmt.nFrameWidth * sVideoFmt.nFrameHeight * pxlfmt2bpp(sVideoFmt.eColorFormat) / 8);

	return OMX_ErrorNone;
}
Пример #6
0
OMX_ERRORTYPE VideoSource::InitComponent()
{
    OMX_ERRORTYPE ret = OMX_ErrorNone;
    OMX_PARAM_PORTDEFINITIONTYPE sPortDef;

    OMX_INIT_STRUCT(&sPortDef, OMX_PARAM_PORTDEFINITIONTYPE);
    sPortDef.nPortIndex = PREVIEW_PORT;
    sPortDef.eDir = OMX_DirOutput;
    sPortDef.eDomain = OMX_PortDomainVideo;
    fsl_osal_memcpy(&sPortDef.format.video, &sVideoFmt, sizeof(OMX_VIDEO_PORTDEFINITIONTYPE));
    sPortDef.bPopulated = OMX_FALSE;
    sPortDef.bEnabled = OMX_FALSE;
    sPortDef.nBufferCountMin = nFrameBufferMin;
    sPortDef.nBufferCountActual = nFrameBufferActual;
    sPortDef.nBufferSize = sPortDef.format.video.nFrameWidth
        * sPortDef.format.video.nFrameHeight
        * pxlfmt2bpp(sVideoFmt.eColorFormat) / 8;
    ret = ports[PREVIEW_PORT]->SetPortDefinition(&sPortDef);
    if(ret != OMX_ErrorNone) {
        LOG_ERROR("Set port definition for in port failed.\n");
        return ret;
    }

    ports[PREVIEW_PORT]->SetSupplierType(PreviewPortSupplierType);

    OMX_INIT_STRUCT(&sPortDef, OMX_PARAM_PORTDEFINITIONTYPE);
    sPortDef.nPortIndex = CAPTURED_FRAME_PORT;
    sPortDef.eDir = OMX_DirOutput;
    sPortDef.eDomain = OMX_PortDomainVideo;
    fsl_osal_memcpy(&sPortDef.format.video, &sVideoFmt, sizeof(OMX_VIDEO_PORTDEFINITIONTYPE));
    sPortDef.bPopulated = OMX_FALSE;
    sPortDef.bEnabled = OMX_TRUE;
    sPortDef.nBufferCountMin = nFrameBufferMin;
    sPortDef.nBufferCountActual = nFrameBufferActual;
    sPortDef.nBufferSize = sPortDef.format.video.nFrameWidth
        * sPortDef.format.video.nFrameHeight
        * pxlfmt2bpp(sVideoFmt.eColorFormat) / 8;
    ret = ports[CAPTURED_FRAME_PORT]->SetPortDefinition(&sPortDef);
    if(ret != OMX_ErrorNone) {
        LOG_ERROR("Set port definition for in port failed.\n");
        return ret;
    }

    ports[CAPTURED_FRAME_PORT]->SetSupplierType(CapturePortSupplierType);

    sPortDef.nPortIndex = CLK_PORT;
    sPortDef.eDir = OMX_DirInput;
    sPortDef.eDomain = OMX_PortDomainOther;
    sPortDef.format.other.eFormat = OMX_OTHER_FormatTime;
    sPortDef.bPopulated = OMX_FALSE;
    sPortDef.bEnabled = OMX_FALSE;
    sPortDef.nBufferCountMin = 1;
    sPortDef.nBufferCountActual = 1;
    sPortDef.nBufferSize = sizeof(OMX_TIME_MEDIATIMETYPE);
    ret = ports[CLK_PORT]->SetPortDefinition(&sPortDef);
    if(ret != OMX_ErrorNone) {
        LOG_ERROR("Set port definition for clk port failed.\n");
        return ret;
    }

	OMX_INIT_STRUCT(&SensorMode, OMX_PARAM_SENSORMODETYPE);

	SensorMode.nPortIndex = OMX_ALL;
	SensorMode.nFrameRate = 30 * Q16_SHIFT;
	SensorMode.bOneShot = OMX_FALSE;

	OMX_INIT_STRUCT(&PortFormat, OMX_VIDEO_PARAM_PORTFORMATTYPE);

	PortFormat.nPortIndex = OMX_ALL;
	PortFormat.nIndex = 0;
	PortFormat.eCompressionFormat = OMX_VIDEO_CodingUnused;
	PortFormat.eColorFormat = OMX_COLOR_FormatYUV420Planar;
	PortFormat.xFramerate = 30 * Q16_SHIFT;

	OMX_INIT_STRUCT(&WhiteBalControl, OMX_CONFIG_WHITEBALCONTROLTYPE);

	WhiteBalControl.nPortIndex = OMX_ALL;
	WhiteBalControl.eWhiteBalControl = OMX_WhiteBalControlOff;

	OMX_INIT_STRUCT(&ScaleFactor, OMX_CONFIG_SCALEFACTORTYPE);

	ScaleFactor.nPortIndex = OMX_ALL;
	ScaleFactor.xWidth = 1.0 * Q16_SHIFT;
	ScaleFactor.xHeight = 1.0 * Q16_SHIFT;

	OMX_INIT_STRUCT(&ExposureValue, OMX_CONFIG_EXPOSUREVALUETYPE);

	ExposureValue.nPortIndex = OMX_ALL;
	ExposureValue.eMetering = OMX_MeteringModeAverage;
	ExposureValue.xEVCompensation = 1.0 * Q16_SHIFT;
	ExposureValue.nApertureFNumber = 1;
	ExposureValue.bAutoAperture = OMX_TRUE;
	ExposureValue.nShutterSpeedMsec = 33;
	ExposureValue.bAutoShutterSpeed = OMX_TRUE;
	ExposureValue.nSensitivity = 100;
	ExposureValue.bAutoSensitivity = OMX_TRUE;

	OMX_INIT_STRUCT(&Capturing, OMX_CONFIG_BOOLEANTYPE);

	Capturing.bEnabled = OMX_FALSE;

	OMX_INIT_STRUCT(&EOS, OMX_CONFIG_BOOLEANTYPE);

	EOS.bEnabled = OMX_FALSE;

	OMX_INIT_STRUCT(&AutoPauseAfterCapture, OMX_CONFIG_BOOLEANTYPE);

	AutoPauseAfterCapture.bEnabled = OMX_FALSE;

	OMX_INIT_STRUCT(&Rotation, OMX_CONFIG_ROTATIONTYPE);

	Rotation.nPortIndex = OMX_ALL;
	Rotation.nRotation = 0;

	bFirstFrame = OMX_TRUE;
	nFrameDelay = 0;
	nBaseTime = 0;
	nMediaTimestampPre = 0;
	pOutBufferHdr = NULL;
	nCaptureFrameCnt = 0;
	bSendEOS = OMX_FALSE;
	nMaxDuration = MAX_VALUE_S64;
	nTimeLapseUs = 0;
	nNextLapseTS = 0;
	nLastSendTS = 0;
	nFrameInterval = 0;
	cameraPtr = NULL;
	nCameraId = 0;
	previewSurface = NULL;

    ret = InitSourceComponent();
    if(ret != OMX_ErrorNone)
        return ret;

	return ret;
}
OMX_ERRORTYPE VideoProcessorComponent::VideoProcessor_ProcessData( OMX_PTR buf)
{
    OMX_ERRORTYPE eRetVal = OMX_ErrorNone;
    OMX_BUFFERHEADERTYPE *pOutBuffer;
    OMX_U32 size = 0;
    int ret;

    VP_DEBUG(" Process data %p\n",buf);

    /* call ipu task */
    ret = mxc_ipu_lib_task_buf_update(&ipu_handle, (int)buf, NULL, NULL, ipu_output_cb, this);
    if(ret < 0)
    {
        VP_ERROR("mxc_ipu_lib_task_buf_update failed.\n");
        SendEvent(OMX_EventError, OMX_ErrorHardware, 0, NULL);
        return OMX_ErrorHardware;
    }

    /* check if processing buffer is empty */
    if(pInBufHdr[0] == NULL)
    {
        VP_ERROR("processing buffer queue is empty.\n");
        SendEvent(OMX_EventError, OMX_ErrorUndefined, 0, NULL);
        return OMX_ErrorUndefined;
    }

    if(bUseEGLImage == OMX_TRUE)
    {
        pOutBuffer = pOutBufHdr[0];
        pOutBufHdr[0] = pOutBufHdr[1];
        pOutBufHdr[1] = NULL;
    }
    else
        ports[VP_OUT_PORT]->GetBuffer(&pOutBuffer);

    pOutBuffer->nTimeStamp = pInBufHdr[0]->nTimeStamp;
    pOutBuffer->nFlags = pInBufHdr[0]->nFlags;

    /* return processed input buffer */
    ports[VP_IN_PORT]->SendBuffer(pInBufHdr[0]);
    pInBufHdr[0] = pInBufHdr[1];
    pInBufHdr[1] = NULL;

    if(pInBufHdr[0]->nFlags & OMX_BUFFERFLAG_EOS)
    {
        printf("VPP send EOS buffer.\n");
        pOutBuffer->nFlags |= OMX_BUFFERFLAG_EOS;
    }

    /* check if need to flush previous frame */
    if(bFlush == OMX_FALSE)
    {
        size = (nOutWidth&(~7)) * nOutHeight * pxlfmt2bpp(eOutColorFmt)/8;
        if(bUseEGLImage != OMX_TRUE)
            fsl_osal_memcpy(pOutBuffer->pBuffer, ipu_handle.outbuf_start[nOutBufIdx], size);
        pOutBuffer->nFilledLen = size;
        pOutBuffer->nOffset = 0;
        nOutFrames++ ;

        //printf("Send eglImage: %p\n", pOutBuffer->pPlatformPrivate);

        ports[VP_OUT_PORT]->SendBuffer(pOutBuffer);
    }
    else
        bFlush = OMX_FALSE;

    VP_DEBUG(" Exit process data\n");
    return eRetVal;
}