OMX_ERRORTYPE VideoRender::ProcessClkBuffer()
{
    OMX_BUFFERHEADERTYPE *pClkBuffer = NULL;
    OMX_TIME_MEDIATIMETYPE *pUpdate = NULL;
    OMX_TIME_UPDATETYPE eType;

    if(ports[CLK_PORT]->IsEnabled() != OMX_TRUE)
        return OMX_ErrorNoMore;

    if(ports[CLK_PORT]->BufferNum() == 0)
        return OMX_ErrorNoMore;

    ports[CLK_PORT]->GetBuffer(&pClkBuffer);
    pUpdate = (OMX_TIME_MEDIATIMETYPE*)pClkBuffer->pBuffer;
    eType = pUpdate->eUpdateType;

    switch(eType) {
        case OMX_TIME_UpdateClockStateChanged:
            ClockState = pUpdate->eState;
            if(ClockState == OMX_TIME_ClockStateRunning 
                    || ClockState == OMX_TIME_ClockStateStopped) {
                if(pSyncFrame != NULL) {
                    SyncRequest(pSyncFrame);
                    pSyncFrame = NULL;
                }
            }
            break;
        case OMX_TIME_UpdateScaleChanged:
            ClockScale = pUpdate->xScale;
            break;
        case OMX_TIME_UpdateRequestFulfillment:
            {
                OMX_BUFFERHEADERTYPE *pBufferHdr = NULL;
                pBufferHdr = (OMX_BUFFERHEADERTYPE*)pUpdate->nClientPrivate;
                if(pBufferHdr->nFlags & OMX_BUFFERFLAG_EOS) {
                    nDeviceDropCnt = GetDeviceDropFames();
                    LOG_INFO("Total frames: %d, Total Droped frames: %d, Render device dropped frames: %d\n", 
                            nFrameCnt, nDropCnt + nDeviceDropCnt, nDeviceDropCnt);
                    RenderFrame(pBufferHdr);
                    SendEvent(OMX_EventBufferFlag, IN_PORT, OMX_BUFFERFLAG_EOS, NULL);
                    break;
                }

                if(OMX_TRUE == IsDropFrame(pBufferHdr->nTimeStamp, pUpdate->nMediaTimestamp)) {
                    LOG_DEBUG("Buffer is late, drop. Buffer ts: %lld, Media ts: %lld\n",
                            pBufferHdr->nTimeStamp, pUpdate->nMediaTimestamp);
                    nDropCnt ++;
                    pBufferHdr->nTimeStamp = -1;
                    ports[IN_PORT]->SendBuffer(pBufferHdr);
                    break;
                }
                RenderFrame(pBufferHdr);
            }
            break;
        default :
            break;
    }

    ports[CLK_PORT]->SendBuffer(pClkBuffer);

    return OMX_ErrorNone;
}
예제 #2
0
파일: VideoRender.cpp 프로젝트: FreeSrk/omx
OMX_ERRORTYPE VideoRender::ProcessClkBuffer()
{
    OMX_BUFFERHEADERTYPE *pClkBuffer = NULL;
    OMX_TIME_MEDIATIMETYPE *pUpdate = NULL;
    OMX_TIME_UPDATETYPE eType;

    if(ports[CLK_PORT]->IsEnabled() != OMX_TRUE)
        return OMX_ErrorNoMore;

    if(ports[CLK_PORT]->BufferNum() == 0)
        return OMX_ErrorNoMore;

    ports[CLK_PORT]->GetBuffer(&pClkBuffer);
    pUpdate = (OMX_TIME_MEDIATIMETYPE*)pClkBuffer->pBuffer;
    eType = pUpdate->eUpdateType;

    switch(eType) {
        case OMX_TIME_UpdateClockStateChanged:
            ClockState = pUpdate->eState;
            if(ClockState == OMX_TIME_ClockStateRunning
                    || ClockState == OMX_TIME_ClockStateStopped) {
                if(pSyncFrame != NULL) {
                    SyncRequest(pSyncFrame);
                    pSyncFrame = NULL;
                }
            }
            break;
        case OMX_TIME_UpdateScaleChanged:
            {
                OMX_TIME_CONFIG_PLAYBACKTYPE *pPlayback = NULL;
                pPlayback = (OMX_TIME_CONFIG_PLAYBACKTYPE *)pUpdate->nClientPrivate;
                ClockScale = pUpdate->xScale;
                playbackMode = pPlayback->ePlayMode;
            }
            break;
        case OMX_TIME_UpdateRequestFulfillment:
            {
                OMX_BUFFERHEADERTYPE *pBufferHdr = NULL;
                pBufferHdr = (OMX_BUFFERHEADERTYPE*)pUpdate->nClientPrivate;
                if(pBufferHdr->nFlags & OMX_BUFFERFLAG_EOS) {
                    RenderFrame(pBufferHdr);
                    SendEvent(OMX_EventBufferFlag, IN_PORT, OMX_BUFFERFLAG_EOS, NULL);
                    break;
                }
                if(ports[IN_PORT]->IsEnabled() != OMX_TRUE){
                    LOG_DEBUG("drop buffer when port is disable.");
                    nDropCnt ++;
                    pBufferHdr->nTimeStamp = -1;
                    ports[IN_PORT]->SendBuffer(pBufferHdr);
                    break;
                }

                if(OMX_TRUE == IsDropFrame(pBufferHdr->nTimeStamp, pUpdate->nMediaTimestamp)) {
                    LOG_DEBUG("Buffer is late, drop. Buffer ts: %lld, Media ts: %lld\n",
                            pBufferHdr->nTimeStamp, pUpdate->nMediaTimestamp);
                    nDropCnt ++;
                    pBufferHdr->nTimeStamp = -1;
                    ports[IN_PORT]->SendBuffer(pBufferHdr);
                    break;
                }
                RenderFrame(pBufferHdr);
            }
            break;
        default :
            break;
    }

    ports[CLK_PORT]->SendBuffer(pClkBuffer);

    return OMX_ErrorNone;
}