void OmxDecTestWithoutMarker::Run() { switch (iState) { case StateUnLoaded: { PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestWithoutMarker::Run() - StateUnLoaded IN")); OMX_ERRORTYPE Err; OMX_BOOL Status; if (!iCallbacks->initCallbacks()) { PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0, "OmxDecTestWithoutMarker::Run() - ERROR initCallbacks failed, OUT")); StopOnError(); break; } ipAppPriv = (AppPrivateType*) oscl_malloc(sizeof(AppPrivateType)); CHECK_MEM(ipAppPriv, "Component_Handle"); ipAppPriv->Handle = NULL; //Allocate bitstream buffer for AVC component if (0 == oscl_strcmp(iFormat, "H264")) { ipAVCBSO = OSCL_NEW(AVCBitstreamObject, (ipInputFile)); CHECK_MEM(ipAVCBSO, "Bitstream_Buffer"); } //Allocate bitstream buffer for MPEG4/H263 component if (0 == oscl_strcmp(iFormat, "M4V") || 0 == oscl_strcmp(iFormat, "H263")) { ipBitstreamBuffer = (OMX_U8*) oscl_malloc(BIT_BUFF_SIZE); CHECK_MEM(ipBitstreamBuffer, "Bitstream_Buffer") ipBitstreamBufferPointer = ipBitstreamBuffer; } iNoMarkerBitTest = OMX_TRUE; //This should be the first call to the component to load it. Err = OMX_MasterInit(); CHECK_ERROR(Err, "OMX_MasterInit"); PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestWithoutMarker::Run() - OMX_MasterInit done")); Status = PrepareComponent(); if (OMX_FALSE == Status) { PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestWithoutMarker::Run() Error while loading component OUT")); iState = StateError; if (iInputParameters.inPtr) { oscl_free(iInputParameters.inPtr); iInputParameters.inPtr = NULL; } RunIfNotReady(); break; } #if PROXY_INTERFACE ipThreadSafeHandlerEventHandler = OSCL_NEW(EventHandlerThreadSafeCallbackAO, (this, EVENT_HANDLER_QUEUE_DEPTH, "EventHandlerAO")); ipThreadSafeHandlerEmptyBufferDone = OSCL_NEW(EmptyBufferDoneThreadSafeCallbackAO, (this, iInBufferCount, "EmptyBufferDoneAO")); ipThreadSafeHandlerFillBufferDone = OSCL_NEW(FillBufferDoneThreadSafeCallbackAO, (this, iOutBufferCount, "FillBufferDoneAO")); if ((NULL == ipThreadSafeHandlerEventHandler) || (NULL == ipThreadSafeHandlerEmptyBufferDone) || (NULL == ipThreadSafeHandlerFillBufferDone)) { PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0, "OmxDecTestWithoutMarker::Run() - Error ThreadSafe Callback Handler initialization failed, OUT")); iState = StateUnLoaded; OsclExecScheduler* sched = OsclExecScheduler::Current(); sched->StopScheduler(); } #endif if (StateError != iState) { iState = StateLoaded; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestWithoutMarker::Run() - StateUnLoaded OUT, moving to next state")); } RunIfNotReady(); } break; case StateLoaded: { OMX_ERRORTYPE Err; OMX_U32 ii; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestWithoutMarker::Run() - StateLoaded IN")); // allocate memory for ipInBuffer ipInBuffer = (OMX_BUFFERHEADERTYPE**) oscl_malloc(sizeof(OMX_BUFFERHEADERTYPE*) * iInBufferCount); CHECK_MEM(ipInBuffer, "InputBufferHeader"); ipInputAvail = (OMX_BOOL*) oscl_malloc(sizeof(OMX_BOOL) * iInBufferCount); CHECK_MEM(ipInputAvail, "InputBufferFlag"); /* Initialize all the buffers to NULL */ for (ii = 0; ii < iInBufferCount; ii++) { ipInBuffer[ii] = NULL; } //allocate memory for output buffer ipOutBuffer = (OMX_BUFFERHEADERTYPE**) oscl_malloc(sizeof(OMX_BUFFERHEADERTYPE*) * iOutBufferCount); CHECK_MEM(ipOutBuffer, "OutputBuffer"); ipOutReleased = (OMX_BOOL*) oscl_malloc(sizeof(OMX_BOOL) * iOutBufferCount); CHECK_MEM(ipOutReleased, "OutputBufferFlag"); /* Initialize all the buffers to NULL */ for (ii = 0; ii < iOutBufferCount; ii++) { ipOutBuffer[ii] = NULL; } Err = OMX_SendCommand(ipAppPriv->Handle, OMX_CommandStateSet, OMX_StateIdle, NULL); CHECK_ERROR(Err, "SendCommand Loaded->Idle"); PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestWithoutMarker::Run() - Sent State Transition Command from Loaded->Idle")); iPendingCommands = 1; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestWithoutMarker::Run() - Allocating %d input and %d output buffers", iInBufferCount, iOutBufferCount)); //These calls are required because the control of in & out buffer should be with the testapp. for (ii = 0; ii < iInBufferCount; ii++) { Err = OMX_AllocateBuffer(ipAppPriv->Handle, &ipInBuffer[ii], iInputPortIndex, NULL, iInBufferSize); CHECK_ERROR(Err, "AllocateBuffer_Input"); PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestWithoutMarker::Run() - Called AllocateBuffer for buffer index %d on port %d", ii, iInputPortIndex)); ipInputAvail[ii] = OMX_TRUE; ipInBuffer[ii]->nInputPortIndex = iInputPortIndex; } if (StateError == iState) { PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0, "OmxDecTestWithoutMarker::Run() - AllocateBuffer Error, StateLoaded OUT")); RunIfNotReady(); break; } for (ii = 0; ii < iOutBufferCount; ii++) { Err = OMX_AllocateBuffer(ipAppPriv->Handle, &ipOutBuffer[ii], iOutputPortIndex, NULL, iOutBufferSize); CHECK_ERROR(Err, "AllocateBuffer_Output"); PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestWithoutMarker::Run() - Called AllocateBuffer for buffer index %d on port %d", ii, iOutputPortIndex)); ipOutReleased[ii] = OMX_TRUE; ipOutBuffer[ii]->nOutputPortIndex = iOutputPortIndex; ipOutBuffer[ii]->nInputPortIndex = 0; } if (StateError == iState) { PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0, "OmxDecTestWithoutMarker::Run() - AllocateBuffer Error, StateLoaded OUT")); RunIfNotReady(); break; } PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestWithoutMarker::Run() - StateLoaded OUT, Moving to next state")); } break; case StateIdle: { PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestWithoutMarker::Run() - StateIdle IN")); OMX_ERRORTYPE Err = OMX_ErrorNone; /*Send an output buffer before dynamic reconfig */ Err = OMX_FillThisBuffer(ipAppPriv->Handle, ipOutBuffer[0]); CHECK_ERROR(Err, "FillThisBuffer"); PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestWithoutMarker::Run() - FillThisBuffer command called for initiating dynamic port reconfiguration")); ipOutReleased[0] = OMX_FALSE; Err = OMX_SendCommand(ipAppPriv->Handle, OMX_CommandStateSet, OMX_StateExecuting, NULL); CHECK_ERROR(Err, "SendCommand Idle->Executing"); PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestWithoutMarker::Run() - Sent State Transition Command from Idle->Executing")); iPendingCommands = 1; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestWithoutMarker::Run() - StateIdle OUT")); } break; case StateDecodeHeader: { PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestWithoutMarker::Run() - StateDecodeHeader IN, Sending configuration input buffers to the component to start dynamic port reconfiguration")); if (!iFlagDecodeHeader) { if (0 == oscl_strcmp(iFormat, "WMV") || 0 == oscl_strcmp(iFormat, "WMA") || 0 == oscl_strcmp(iFormat, "RV") || 0 == oscl_strcmp(iFormat, "RA")) { (*this.*pGetInputFrame)(); } else { GetInput(); } iFlagDecodeHeader = OMX_TRUE; //Proceed to executing state and if Port settings changed callback comes, //then do the dynamic port reconfiguration iState = StateExecuting; RunIfNotReady(); } PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestWithoutMarker::Run() - StateDecodeHeader OUT")); } break; case StateDisablePort: { OMX_ERRORTYPE Err = OMX_ErrorNone; OMX_U32 ii; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestWithoutMarker::Run() - StateDisablePort IN")); if (!iDisableRun) { if (!iFlagDisablePort) { Err = OMX_SendCommand(ipAppPriv->Handle, OMX_CommandPortDisable, iOutputPortIndex, NULL); CHECK_ERROR(Err, "SendCommand_PortDisable"); PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestWithoutMarker::Run() - Sent Command for OMX_CommandPortDisable on port %d as a part of dynamic port reconfiguration", iOutputPortIndex)); iPendingCommands = 1; iFlagDisablePort = OMX_TRUE; RunIfNotReady(); } else { //Wait for all the buffers to be returned on output port before freeing them //This wait is required because of the queueing delay in all the Callbacks for (ii = 0; ii < iOutBufferCount; ii++) { if (OMX_FALSE == ipOutReleased[ii]) { break; } } if (ii != iOutBufferCount) { PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestWithoutMarker::Run() - Not all the output buffers returned by component yet, wait for it")); RunIfNotReady(); break; } for (ii = 0; ii < iOutBufferCount; ii++) { if (ipOutBuffer[ii]) { Err = OMX_FreeBuffer(ipAppPriv->Handle, iOutputPortIndex, ipOutBuffer[ii]); CHECK_ERROR(Err, "FreeBuffer_Output_DynamicReconfig"); ipOutBuffer[ii] = NULL; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestWithoutMarker::Run() - Called FreeBuffer for buffer index %d on port %d", ii, iOutputPortIndex)); } } if (StateError == iState) { PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0, "OmxDecTestWithoutMarker::Run() - Error occured in this state, StateDisablePort OUT")); RunIfNotReady(); break; } iDisableRun = OMX_TRUE; } } PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestWithoutMarker::Run() - StateDisablePort OUT")); } break; case StateDynamicReconfig: { OMX_ERRORTYPE Err = OMX_ErrorNone; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestWithoutMarker::Run() - StateDynamicReconfig IN")); INIT_GETPARAMETER_STRUCT(OMX_PARAM_PORTDEFINITIONTYPE, iParamPort); iParamPort.nPortIndex = iOutputPortIndex; Err = OMX_GetParameter(ipAppPriv->Handle, OMX_IndexParamPortDefinition, &iParamPort); CHECK_ERROR(Err, "GetParameter_DynamicReconfig"); PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestWithoutMarker::Run() - GetParameter called for OMX_IndexParamPortDefinition on port %d", iParamPort.nPortIndex)); Err = OMX_SendCommand(ipAppPriv->Handle, OMX_CommandPortEnable, iOutputPortIndex, NULL); CHECK_ERROR(Err, "SendCommand_PortEnable"); PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestWithoutMarker::Run() - Sent Command for OMX_CommandPortEnable on port %d as a part of dynamic port reconfiguration", iOutputPortIndex)); iPendingCommands = 1; if (0 == oscl_strcmp(iFormat, "H264") || 0 == oscl_strcmp(iFormat, "H263") || 0 == oscl_strcmp(iFormat, "M4V") || 0 == oscl_strcmp(iFormat, "RV")) { iOutBufferSize = ((iParamPort.format.video.nFrameWidth + 15) & ~15) * ((iParamPort.format.video.nFrameHeight + 15) & ~15) * 3 / 2; if (iOutBufferSize < iParamPort.nBufferSize) { iOutBufferSize = iParamPort.nBufferSize; } } else if (0 == oscl_strcmp(iFormat, "WMV")) { iOutBufferSize = ((iParamPort.format.video.nFrameWidth + 3) & ~3) * ((iParamPort.format.video.nFrameHeight + 3) & ~3) * 3 / 2; if (iOutBufferSize < iParamPort.nBufferSize) { iOutBufferSize = iParamPort.nBufferSize; } } else { //For audio components take the size from the component iOutBufferSize = iParamPort.nBufferSize; } PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestWithoutMarker::Run() - Allocating buffer again after port reconfigutauion has been complete")); for (OMX_U32 ii = 0; ii < iOutBufferCount; ii++) { Err = OMX_AllocateBuffer(ipAppPriv->Handle, &ipOutBuffer[ii], iOutputPortIndex, NULL, iOutBufferSize); CHECK_ERROR(Err, "AllocateBuffer_Output_DynamicReconfig"); ipOutReleased[ii] = OMX_TRUE; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestWithoutMarker::Run() - AllocateBuffer called for buffer index %d on port %d", ii, iOutputPortIndex)); } if (StateError == iState) { PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0, "OmxDecTestWithoutMarker::Run() - Error occured in this state, StateDynamicReconfig OUT")); RunIfNotReady(); break; } PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestWithoutMarker::Run() - StateDynamicReconfig OUT")); } break; case StateExecuting: { OMX_U32 Index; OMX_BOOL MoreOutput; OMX_ERRORTYPE Err = OMX_ErrorNone; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestWithoutMarker::Run() - StateExecuting IN")); MoreOutput = OMX_TRUE; while (MoreOutput) { Index = 0; while (OMX_FALSE == ipOutReleased[Index] && Index < iOutBufferCount) { Index++; } if (Index != iOutBufferCount) { //This call is being made only once per frame Err = OMX_FillThisBuffer(ipAppPriv->Handle, ipOutBuffer[Index]); CHECK_ERROR(Err, "FillThisBuffer"); //Make this flag OMX_TRUE till u receive the callback for output buffer free ipOutReleased[Index] = OMX_FALSE; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestWithoutMarker::Run() - FillThisBuffer command called for output buffer index %d", Index)); } else { MoreOutput = OMX_FALSE; } } if (!iStopProcessingInput || (OMX_ErrorInsufficientResources == iStatusExecuting)) { if (0 == oscl_strcmp(iFormat, "WMV") || 0 == oscl_strcmp(iFormat, "WMA") || 0 == oscl_strcmp(iFormat, "RV") || 0 == oscl_strcmp(iFormat, "RA")) { iStatusExecuting = (*this.*pGetInputFrame)(); } else { iStatusExecuting = GetInput(); } } else if (OMX_FALSE == iEosFlagExecuting) { //Only send one successful dummy buffer with flag set to signal EOS Index = 0; while (OMX_FALSE == ipInputAvail[Index] && Index < iInBufferCount) { Index++; } if (Index != iInBufferCount) { ipInBuffer[Index]->nFlags |= OMX_BUFFERFLAG_EOS; ipInBuffer[Index]->nFilledLen = 0; Err = OMX_EmptyThisBuffer(ipAppPriv->Handle, ipInBuffer[Index]); CHECK_ERROR(Err, "EmptyThisBuffer_EOS"); ipInputAvail[Index] = OMX_FALSE; // mark unavailable iEosFlagExecuting = OMX_TRUE; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestWithoutMarker::Run() - Input buffer sent to the component with OMX_BUFFERFLAG_EOS flag set")); } } else { //nothing to do here } PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestWithoutMarker::Run() - StateExecuting OUT")); RunIfNotReady(); } break; case StateStopping: { OMX_ERRORTYPE Err = OMX_ErrorNone; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestWithoutMarker::Run() - StateStopping IN")); //stop execution by state transition to Idle state. if (!iFlagStopping) { Err = OMX_SendCommand(ipAppPriv->Handle, OMX_CommandStateSet, OMX_StateIdle, NULL); CHECK_ERROR(Err, "SendCommand Executing->Idle"); PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestWithoutMarker::Run() - Sent State Transition Command from Executing->Idle")); iPendingCommands = 1; iFlagStopping = OMX_TRUE; } PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestWithoutMarker::Run() - StateStopping OUT")); } break; case StateCleanUp: { OMX_U32 ii; OMX_ERRORTYPE Err = OMX_ErrorNone; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestWithoutMarker::Run() - StateCleanUp IN")); if (!iFlagCleanUp) { //Added a check here to verify whether all the ip/op buffers are returned back by the component or not //in case of Executing->Idle state transition if (OMX_FALSE == VerifyAllBuffersReturned()) { // not all buffers have been returned yet, reschedule RunIfNotReady(); break; } //Destroy the component by state transition to Loaded state Err = OMX_SendCommand(ipAppPriv->Handle, OMX_CommandStateSet, OMX_StateLoaded, NULL); CHECK_ERROR(Err, "SendCommand Idle->Loaded"); PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestWithoutMarker::Run() - Sent State Transition Command from Idle->Loaded")); iPendingCommands = 1; if (ipInBuffer) { for (ii = 0; ii < iInBufferCount; ii++) { if (ipInBuffer[ii]) { Err = OMX_FreeBuffer(ipAppPriv->Handle, iInputPortIndex, ipInBuffer[ii]); CHECK_ERROR(Err, "FreeBuffer_Input"); ipInBuffer[ii] = NULL; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestWithoutMarker::Run() - Called FreeBuffer for buffer index %d on port %d", ii, iInputPortIndex)); } } oscl_free(ipInBuffer); ipInBuffer = NULL; } if (ipInputAvail) { oscl_free(ipInputAvail); ipInputAvail = NULL; } if (ipOutBuffer) { for (ii = 0; ii < iOutBufferCount; ii++) { if (ipOutBuffer[ii]) { Err = OMX_FreeBuffer(ipAppPriv->Handle, iOutputPortIndex, ipOutBuffer[ii]); CHECK_ERROR(Err, "FreeBuffer_Output"); ipOutBuffer[ii] = NULL; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestWithoutMarker::Run() - Called FreeBuffer for buffer index %d on port %d", ii, iOutputPortIndex)); } } oscl_free(ipOutBuffer); ipOutBuffer = NULL; } if (ipOutReleased) { oscl_free(ipOutReleased); ipOutReleased = NULL; } iFlagCleanUp = OMX_TRUE; } PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestWithoutMarker::Run() - StateCleanUp OUT")); } break; /********* FREE THE HANDLE & CLOSE FILES FOR THE COMPONENT ********/ case StateStop: { OMX_U8 TestName[] = "WITHOUT_MARKER_BIT_TEST"; OMX_ERRORTYPE Err = OMX_ErrorNone; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestWithoutMarker::Run() - StateStop IN")); if (ipAppPriv) { if (ipAppPriv->Handle) { PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestWithoutMarker::Run() - Free the Component Handle")); Err = OMX_MasterFreeHandle(ipAppPriv->Handle); if (OMX_ErrorNone != Err) { PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0, "OmxDecTestWithoutMarker::Run() - FreeHandle Error")); iTestStatus = OMX_FALSE; } } } PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestWithoutMarker::Run() - De-initialize the omx component")); Err = OMX_MasterDeinit(); if (OMX_ErrorNone != Err) { PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0, "OmxDecTestWithoutMarker::Run() - OMX_MasterDeinit Error")); iTestStatus = OMX_FALSE; } if (0 == oscl_strcmp(iFormat, "H264")) { if (ipAVCBSO) { OSCL_DELETE(ipAVCBSO); ipAVCBSO = NULL; } } if (0 == oscl_strcmp(iFormat, "M4V") || 0 == oscl_strcmp(iFormat, "H263")) { if (ipBitstreamBuffer) { oscl_free(ipBitstreamBufferPointer); ipBitstreamBuffer = NULL; ipBitstreamBufferPointer = NULL; } } if (iOutputParameters) { oscl_free(iOutputParameters); iOutputParameters = NULL; } if (ipAppPriv) { oscl_free(ipAppPriv); ipAppPriv = NULL; } #if PROXY_INTERFACE if (ipThreadSafeHandlerEventHandler) { OSCL_DELETE(ipThreadSafeHandlerEventHandler); ipThreadSafeHandlerEventHandler = NULL; } if (ipThreadSafeHandlerEmptyBufferDone) { OSCL_DELETE(ipThreadSafeHandlerEmptyBufferDone); ipThreadSafeHandlerEmptyBufferDone = NULL; } if (ipThreadSafeHandlerFillBufferDone) { OSCL_DELETE(ipThreadSafeHandlerFillBufferDone); ipThreadSafeHandlerFillBufferDone = NULL; } #endif VerifyOutput(TestName); PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestWithoutMarker::Run() - StateStop OUT")); iState = StateUnLoaded; OsclExecScheduler* sched = OsclExecScheduler::Current(); sched->StopScheduler(); } break; case StateError: { //Do all the cleanup's and exit from here OMX_U32 ii; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestWithoutMarker::Run() - StateError IN")); iTestStatus = OMX_FALSE; if (ipInBuffer) { for (ii = 0; ii < iInBufferCount; ii++) { if (ipInBuffer[ii]) { OMX_FreeBuffer(ipAppPriv->Handle, iInputPortIndex, ipInBuffer[ii]); ipInBuffer[ii] = NULL; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestWithoutMarker::Run() - Called FreeBuffer for buffer index %d on port %d", ii, iInputPortIndex)); } } oscl_free(ipInBuffer); ipInBuffer = NULL; } if (ipInputAvail) { oscl_free(ipInputAvail); ipInputAvail = NULL; } if (ipOutBuffer) { for (ii = 0; ii < iOutBufferCount; ii++) { if (ipOutBuffer[ii]) { OMX_FreeBuffer(ipAppPriv->Handle, iOutputPortIndex, ipOutBuffer[ii]); ipOutBuffer[ii] = NULL; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestWithoutMarker::Run() - Called FreeBuffer for buffer index %d on port %d", ii, iOutputPortIndex)); } } oscl_free(ipOutBuffer); ipOutBuffer = NULL; } if (ipOutReleased) { oscl_free(ipOutReleased); ipOutReleased = NULL; } iState = StateStop; RunIfNotReady(); PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestWithoutMarker::Run() - StateError OUT")); } break; default: { break; } } return ; }
int csm_update_service(csm_service_list *services, csm_service *s, csm_ctx *ctx, int validate) { if (validate) CHECK(csm_validate_fields(ctx, s), "Service doesn't validate"); // assert(s->lifetime); long lifetime = s->lifetime; // check if service is attached to service_list CHECK(co_list_contains(services->services, (co_obj_t*)container_of(s, co_service_t, service)), "Cannot update service not in service list"); // detach s->fields from s and attach to services->service_fields if (!co_list_contains(services->service_fields, s->fields)) { co_obj_t *fields = s->fields; hattach(fields, NULL); CHECK(co_list_append(services->service_fields, fields), "Failed to add service fields to service list"); } /* Create or verify signature */ if (s->signature) CHECK(csm_verify_signature(s),"Invalid signature"); else CHECK(csm_create_signature(s),"Failed to create signature"); /* Set expiration timer on the service */ #ifdef USE_UCI long def_lifetime = default_lifetime(); if (lifetime == 0 || (def_lifetime < lifetime && def_lifetime > 0)) lifetime = def_lifetime; #endif if (lifetime > 0) { struct timeval tv; avahi_elapse_time(&tv, 1000*lifetime, 0); time_t current_time = time(NULL); // create expiration event for service s->timeout = avahi_simple_poll_get(simple_poll)->timeout_new(avahi_simple_poll_get(simple_poll), &tv, _csm_expire_service, s); /* Convert lifetime period into timestamp */ if (current_time != ((time_t)-1)) { struct tm *timestr = localtime(¤t_time); timestr->tm_sec += lifetime; current_time = mktime(timestr); char *c_time_string = ctime(¤t_time); if (c_time_string) { c_time_string[strlen(c_time_string)-1] = '\0'; /* ctime adds \n to end of time string; remove it */ s->expiration = h_strdup(c_time_string); CHECK_MEM(s->expiration); service_attach(s->expiration, s); } } } // finalize service by running update handlers csm_services_commit(services); return 1; error: return 0; }
BOOLEAN pc_mv(byte *old_name, byte *new_name) #endif { int old_driveno; DROBJ *old_obj; DROBJ *old_parent_obj; DROBJ *dot_dot_obj; byte *path; byte *filename; byte fileext[4]; int new_driveno; DROBJ *new_obj; DROBJ *new_parent_obj; BOOLEAN ret_val; DDRIVE *pdrive; int p_set_errno; CHECK_MEM(BOOLEAN, 0) /* Make sure memory is initted */ p_set_errno = 0; /* Drives must be the same */ if ( !pc_parsedrive( &old_driveno, old_name, CS_CHARSET_ARGS) || !pc_parsedrive( &new_driveno, new_name, CS_CHARSET_ARGS) || old_driveno != new_driveno) { rtfs_set_errno(PEINVALIDDRIVEID, __FILE__, __LINE__); return(FALSE); } /* Get the drive and make sure it is mounted */ old_driveno = check_drive_name_mount(old_name, CS_CHARSET_ARGS); if (old_driveno < 0) { /* errno was set by check_drive */ return(FALSE); } rtfs_clear_errno(); /* pc_mv: clear error status */ dot_dot_obj = 0; old_obj = 0; old_parent_obj = 0; new_obj = 0; new_parent_obj = 0; ret_val = FALSE; pdrive = pc_drno2dr(old_driveno); /* Allocate scratch buffers in the DRIVE structure. */ if (!pc_alloc_path_buffers(pdrive)) goto errex; path = pdrive->pathname_buffer; filename = pdrive->filename_buffer; /* Get out the filename and d:parent */ if (!pc_parsepath(path, filename,fileext,old_name, CS_CHARSET_ARGS)) { p_set_errno = PEINVALIDPATH; /*rtfs_set_errno(PEINVALIDPATH" __FILE__, __LINE__);*/ goto errex; } /* Find the parent and make sure it is a directory */ old_parent_obj = pc_fndnode(path, CS_CHARSET_ARGS); if (!old_parent_obj) goto errex; /* pc_fndinode - set errno */ if (!pc_isadir(old_parent_obj)) { p_set_errno = PENOENT; /*rtfs_set_errno(PENOENT, __FILE__, __LINE__); */ goto errex; } /* Find the file */ old_obj = pc_get_inode(0, old_parent_obj, filename, (byte*)fileext, GET_INODE_MATCH, CS_CHARSET_ARGS); if (!old_obj) goto errex; /* pc_get_inode - set errno */ /* Be sure it exists and is a normal directory or file and is not open */ if (pc_isroot(old_obj) || (old_obj->finode->opencount > 1) || (old_obj->finode->fattribute&(ARDONLY|AVOLUME))) { p_set_errno = PEACCES; /*rtfs_set_errno(PEACCES, __FILE__, __LINE__); */ goto errex; } #if (INCLUDE_EXFATORFAT64) if (!ISEXFATORFAT64(pdrive) && old_obj->finode->fattribute & ADIRENT) #else if (old_obj->finode->fattribute & ADIRENT) #endif { /* Bug fix November 2009. Previous method failed with unicode because we were passing the ascii ".." and matching on UNICODE. This always failed so you could not rename a directory using the unicode interface. An efficient solution is to pass GET_INODE_DOTDOT for a search command and eliminate string argument preparation and passing. */ dot_dot_obj = pc_get_inode(0, old_obj, 0, 0, GET_INODE_DOTDOT, CS_CHARSET_ARGS); if (!dot_dot_obj) goto errex; } /* At this point old_obj contains the file we are renaming */ /* See if the new directory entry already exists */ new_obj = pc_fndnode(new_name, CS_CHARSET_ARGS); if (new_obj) { p_set_errno = PEEXIST; /*rtfs_set_errno(PEEXIST, __FILE__, __LINE__); */ goto errex; } rtfs_clear_errno(); /* pc_mv - clear errno condition after failed pc_fndnode */ /* Get out the filename and d:parent */ if (!pc_parsepath(path,filename,fileext,new_name, CS_CHARSET_ARGS)) { p_set_errno = PEINVALIDPATH; /*rtfs_set_errno(PEINVALIDPATH, __FILE__, __LINE__); */ goto errex; } /* Find the parent and make sure it is a directory */ new_parent_obj = pc_fndnode(path, CS_CHARSET_ARGS); if (!new_parent_obj || !pc_isadir(new_parent_obj) || pc_isavol(new_parent_obj)) { p_set_errno = PEINVALIDPATH; goto errex; } #if (INCLUDE_EXFATORFAT64) if (ISEXFATORFAT64(pdrive)) { /* Call exfat move routine, it sets errno if an error occurs. */ rtfs_clear_errno(); p_set_errno = 0; ret_val = pcexfat_mvnode(old_parent_obj,old_obj,new_parent_obj, filename,use_charset); goto errex; } /* Create the new entry and assign cluster to it. If it is a directory .. will be linked correctly */ new_obj = pc_mknode( new_parent_obj, filename, fileext, old_obj->finode->fattribute, old_obj->finode,CS_CHARSET_ARGS); #else { dword cluster; /* The cluster value old */ cluster = pc_finode_cluster(old_obj->pdrive,old_obj->finode); /* Create the new entry and assign cluster to it. If it is a directory .. will be linked correctly */ new_obj = pc_mknode( new_parent_obj, filename, fileext, old_obj->finode->fattribute, cluster,CS_CHARSET_ARGS); } #endif if (!new_obj) goto errex; /* Copy the old directory entry stuf over */ new_obj->finode->fattribute = old_obj->finode->fattribute; new_obj->finode->reservednt = old_obj->finode->reservednt; new_obj->finode->create10msincrement = old_obj->finode->create10msincrement; new_obj->finode->ftime = old_obj->finode->ftime; new_obj->finode->fdate = old_obj->finode->fdate; new_obj->finode->ctime = old_obj->finode->ctime; new_obj->finode->cdate = old_obj->finode->cdate; new_obj->finode->adate = old_obj->finode->adate; new_obj->finode->atime = old_obj->finode->atime; new_obj->finode->fsizeu.fsize = old_obj->finode->fsizeu.fsize; /* Update the new inode. Do not set archive bit or change date */ if (!pc_update_inode(new_obj, FALSE, 0)) goto errex; if (new_obj->finode->fattribute & ADIRENT) { dword cltemp; /* If we are renaming a directory then update '..' */ cltemp = pc_get_parent_cluster(pdrive, new_obj); dot_dot_obj->finode->fclusterhi = (word)(cltemp >> 16); dot_dot_obj->finode->fcluster = (word)cltemp ; if (!pc_update_inode(dot_dot_obj, FALSE, 0)) goto errex; }
// create an epilogue from the path static int new_epilog(int log_set, tcfg_edge_t **path, int path_len) { int i, k, num = 0, num1 = 0, m = 0, max_len, hit_mlat, set, tag; tcfg_node_t *bbi; Queue queue; code_link_t *elog; mas_inst_t mas_inst; addr_t sa; max_len = max_elog_len[tcfg_edges[log_set]->src->id]; memset(tmp_cs, 0, cache.ns * sizeof(mblk_tag_t)); init_queue(&queue, sizeof(de_inst_t)); for (i = 0; i < path_len; i++) { hit_mlat = 0; // copy code of e->dst bbi = path[i]->dst; sa = bbi->bb->sa; for (k = 0; (k < bbi->bb->num_inst) && (m < max_len); k++, m++) { mas_inst.inst = &bbi->bb->code[k]; mas_inst.bbi_id = bbi->id; mas_inst.mblk_id = MBLK_ID(sa, mas_inst.inst->addr); // bpred related mas_inst.bp_flag = BP_CPRED; // cache related tag = TAG(mas_inst.inst->addr); set = SET(mas_inst.inst->addr); if (tmp_cs[set].valid == 0) mas_inst.ic_flag = IC_UNCLEAR; else if (tmp_cs[set].tag == tag) mas_inst.ic_flag = IC_HIT; else mas_inst.ic_flag = IC_MISS; tmp_cs[set].valid = 1; tmp_cs[set].tag = tag; enqueue(&queue, &mas_inst); if (max_inst_lat(mas_inst.inst) > 1) { num1 = num + k + 1; hit_mlat = 1; } } num += k; } if ((num1 == 0) || (hit_mlat == 0)) { free_queue(&queue); return 0; } // copy code from tmporary storage to the new epilogue node elog = (code_link_t *) calloc(1, sizeof(code_link_t)); CHECK_MEM(elog); elog->code = (mas_inst_t *) calloc(num1, sizeof(mas_inst_t)); CHECK_MEM(elog->code); for (k = 0; k < num1; k++) { elog->code[k] = *((mas_inst_t *) dequeue(&queue)); } elog->num_inst = num1; elog->next = epilogs[log_set]; epilogs[log_set] = elog; free_queue(&queue); return 1; }
audited_err_t audited_start_cmd(const Audited__StartReq *startreq, Audited__StartRes *startres) { audited_err_t rv=0; ProtobufCMessage *req=NULL; audited_cmd_t *cmd_desc=NULL; char *audit_string=NULL; uint32_t pending_cmd_id; bool saved_pending_cmd=false; if(!did_init) { rv = AUDITED_EBADSTATE; goto out; } if (startreq->cmd >= audited_cmds_num) { rv = AUDITED_EBADAUDITEDCMD; goto out; } cmd_desc = &audited_cmds[startreq->cmd]; assert(cmd_desc); req = protobuf_c_message_unpack(cmd_desc->req_descriptor, NULL, startreq->cmd_input.len, startreq->cmd_input.data); CHECK(req, AUDITED_EDECODE, "protobuf_c_message_unpack"); assert(cmd_desc->audit_string); startres->svc_err = cmd_desc->audit_string(req, &audit_string); CHECK_RV((unsigned int)startres->svc_err, rv, "audit_string()"); pending_cmd_id = audited_save_pending_cmd(cmd_desc, req, audit_string); CHECK(pending_cmd_id >= 0, AUDITED_ESAVE, "audited_save_pending_cmd"); saved_pending_cmd=true; startres->res = malloc(sizeof(Audited__StartRes__Res)); CHECK_MEM(startres->res, AUDITED_ENOMEM); *(startres->res) = (Audited__StartRes__Res) { .base = PROTOBUF_C_MESSAGE_INIT (&audited__start_res__res__descriptor), .pending_cmd_id = pending_cmd_id, .audit_nonce.data = pending_cmds[pending_cmd_id].audit_nonce, .audit_nonce.len = pending_cmds[pending_cmd_id].audit_nonce_len, .audit_string = audit_string, }; out: if (rv || startres->svc_err) { if (saved_pending_cmd) { audited_release_pending_cmd_id(pending_cmd_id); } else { free(audit_string); if(req) { protobuf_c_message_free_unpacked(req, NULL); } } free(startres->res); startres->res=NULL; } return rv; } audited_err_t audited_execute_cmd(const Audited__ExecuteReq *exec_req, Audited__ExecuteRes *exec_res) { audited_err_t rv; audited_pending_cmd_t *cmd=NULL; ProtobufCMessage *res=NULL; bool got_res=false; if(!did_init) { rv = AUDITED_EBADSTATE; goto out; } cmd = audited_pending_cmd_of_id(exec_req->pending_cmd_id); CHECK(cmd >= 0, AUDITED_EBADCMDHANDLE, "audited_pending_cmd_of_id(%d)", (unsigned int)exec_req->pending_cmd_id); rv = audited_check_cmd_auth(cmd, exec_req->audit_token.data, exec_req->audit_token.len); CHECK_RV(rv, rv, "audited_check_cmd_auth"); assert(cmd->fns); assert(cmd->fns->execute); assert(cmd->fns->res_descriptor); res = malloc(cmd->fns->res_descriptor->sizeof_message); CHECK_MEM(res, AUDITED_ENOMEM); protobuf_c_message_init(cmd->fns->res_descriptor, res); exec_res->svc_err = cmd->fns->execute(cmd->req, res); CHECK_RV((unsigned int)exec_res->svc_err, rv, "execute()"); got_res=true; exec_res->cmd_output.len = protobuf_c_message_get_packed_size(res); exec_res->cmd_output.data = malloc(exec_res->cmd_output.len); CHECK_MEM(exec_res->cmd_output.data, AUDITED_ENOMEM); protobuf_c_message_pack(res, exec_res->cmd_output.data); exec_res->has_cmd_output=true; out: if (got_res && cmd->fns->release_res) { cmd->fns->release_res(res); } if (res) { free(res); res=NULL; } audited_release_pending_cmd_id(exec_req->pending_cmd_id); return rv; }
arg_options *parse_args(int argc, char **argv) { if (argc >= 2 && arg_matches(argv[1], "--help", "-h")) { print_usage(0); } arg_options *args = (arg_options*) malloc(sizeof(arg_options)); CHECK_MEM(args); if (argc < 2) { print_missing_argument("mode"); } if (arg_matches(argv[1], "gen", 0)) { // SNOWFLAKE_GEN args->mode = SNOWFLAKE_GEN; // required args args->gen.output = 0; int output_set = 0; // optional args args->gen.impl = BSP; args->gen.num_particles = -1; args->gen.symmetry_degree = 6; args->gen.symmetry_type = NONE; args->gen.silent = 0; int argi = 2; while (argi < argc) { if (arg_matches(argv[argi], "--num-particles", "-n")) { check_enough_parameters(argv[argi], argc, argi, 1); args->gen.num_particles = atoi(argv[argi+1]); argi += 2; } else if (arg_matches(argv[argi], "--output", "-o")) { check_enough_parameters(argv[argi], argc, argi, 1); args->gen.output = (char*) realloc(args->gen.output, strlen(argv[argi+1]) + 1); CHECK_MEM(args->gen.output); strcpy(args->gen.output, argv[argi+1]); output_set = 1; argi += 2; } else if (arg_matches(argv[argi], "--impl", 0)) { check_enough_parameters(argv[argi], argc, argi, 1); if (arg_matches(argv[argi+1], "BSP", 0)) { args->gen.impl = BSP; } else if (arg_matches(argv[argi+1], "LINEAR", 0)) { args->gen.impl = LINEAR; } else { print_unrecognised_argument(argv[argi+1]); } argi += 2; } else if (arg_matches(argv[argi], "--symmetry-degree", "-d")) { check_enough_parameters(argv[argi], argc, argi, 1); args->gen.symmetry_degree = atoi(argv[argi+1]); argi += 2; } else if (arg_matches(argv[argi], "--symmetry-type", "-t")) { check_enough_parameters(argv[argi], argc, argi, 1); if (arg_matches(argv[argi+1], "none", 0)) { args->gen.symmetry_type = NONE; } else if (arg_matches(argv[argi+1], "rotational", 0)) { args->gen.symmetry_type = ROTATIONAL; } else if (arg_matches(argv[argi+1], "full", 0)) { args->gen.symmetry_type = FULL; } else { print_unrecognised_argument(argv[argi+1]); } argi += 2; } else if (arg_matches(argv[argi], "--silent", "-s")) { args->gen.silent = 1; argi += 1; } else { print_unrecognised_argument(argv[argi]); } } if (!output_set) { print_missing_argument("--output"); } } else if (arg_matches(argv[1], "render", 0)) { // RENDER args->mode = RENDER; // required args args->render.input = 0; int input_set = 0; // optional args args->render.output = 0; int output_set = 0; args->render.colorize = 0; args->render.movie = 0; args->render.num_frames = 0; int num_frames_set = 0; args->render.silent = 0; int argi = 2; while (argi < argc) { if (arg_matches(argv[argi], "--output", "-o")) { check_enough_parameters(argv[argi], argc, argi, 1); args->render.output = (char*) realloc(args->render.output, strlen(argv[argi+1]) + 1); CHECK_MEM(args->render.output); strcpy(args->render.output, argv[argi+1]); output_set = 1; argi += 2; } else if (arg_matches(argv[argi], "--input", "-i")) { check_enough_parameters(argv[argi], argc, argi, 1); args->render.input = (char*) realloc(args->render.input, strlen(argv[argi+1]) + 1); CHECK_MEM(args->render.input); strcpy(args->render.input, argv[argi+1]); input_set = 1; argi += 2; } else if (arg_matches(argv[argi], "--colorize", "-c")) { args->render.colorize = 1; argi += 1; } else if (arg_matches(argv[argi], "--movie", "-m")) { args->render.movie = 1; argi += 1; } else if (arg_matches(argv[argi], "--frames", "-f")) { check_enough_parameters(argv[argi], argc, argi, 1); args->render.num_frames = atoi(argv[argi+1]); num_frames_set = 1; argi += 2; } else if (arg_matches(argv[argi], "--silent", "-s")) { args->render.silent = 1; argi += 1; } else { print_unrecognised_argument(argv[argi]); } } if (!input_set) { print_missing_argument("--input"); } if (!output_set) { args->render.output = replace_extension(args->render.input, "png"); } if (args->render.movie && !num_frames_set) { print_missing_argument("--frames"); } } else if (arg_matches(argv[1], "tests", 0)) { // TESTS args->mode = TESTS; // optional args args->tests.impl = BSP; int argi = 2; while (argi < argc) { if (arg_matches(argv[argi], "--impl", 0)) { check_enough_parameters(argv[argi], argc, argi, 1); if (arg_matches(argv[argi+1], "BSP", 0)) { args->tests.impl = BSP; } else if (arg_matches(argv[argi+1], "LINEAR", 0)) { args->tests.impl = LINEAR; } else { print_unrecognised_argument(argv[argi+1]); } argi += 2; } else { print_unrecognised_argument(argv[argi]); } } } else { print_unrecognised_argument(argv[1]); } return args; }
// create a prologue from the reverse of path; and for the first node, skip the // first num_skip instructions static void new_prolog(int log_set, tcfg_edge_t **path, int path_len, int num_skip) { int i, k, num = 0, num_mp = 0, tag, set, edge_id, max_num_mp; tcfg_node_t *bbi, *mbbi; Queue queue; code_link_t *plog; mas_inst_t mas_inst; addr_t sa; if (num_skip < 0) num_skip = 0; memset(tmp_cs, 0, cache.ns * sizeof(mblk_tag_t)); init_queue(&queue, sizeof(mas_inst_t)); for (i = path_len-1; i >= 0; i--) { bbi = path[i]->src; sa = bbi->bb->sa; // copy code of e->src into prologue for (k = num_skip; k < bbi->bb->num_inst; k++) { // bpred related mas_inst.inst = &bbi->bb->code[k]; mas_inst.bbi_id = bbi->id; mas_inst.mblk_id = MBLK_ID(sa, mas_inst.inst->addr); mas_inst.bp_flag = BP_CPRED; // cache related tag = TAG(mas_inst.inst->addr); set = SET(mas_inst.inst->addr); if (tmp_cs[set].valid == 0) mas_inst.ic_flag = IC_UNCLEAR; else if (tmp_cs[set].tag == tag) mas_inst.ic_flag = IC_HIT; else mas_inst.ic_flag = IC_MISS; tmp_cs[set].valid = 1; tmp_cs[set].tag = tag; enqueue(&queue, &mas_inst); num++; } num_skip = 0; if ((bpred_scheme == NO_BPRED) || !cond_bbi(bbi)) continue; // mispred instructions edge_id = path[i]->id; if (mlat_mpinst[edge_id] > max_elog_len[bbi->id]) continue; max_num_mp = min(num_mp_insts[edge_id], max_elog_len[bbi->id]); if (bbi->out == path[i]) mbbi = bbi->out->next_out->dst; else mbbi = bbi->out->dst; num_mp = 0; for (k = 0; k < max_num_mp; k++) { if (num_mp >= mbbi->bb->num_inst) { mbbi = mbbi->out->dst; num_mp = 0; } mas_inst.inst = mp_insts[edge_id][k]; mas_inst.bbi_id = mbbi->id; mas_inst.mblk_id = MBLK_ID(mbbi->bb->sa, mas_inst.inst->addr); if (i == 0) mas_inst.bp_flag = BP_MPRED; else mas_inst.bp_flag = BP_UNCLEAR; tag = TAG(mas_inst.inst->addr); set = SET(mas_inst.inst->addr); if (tmp_cs[set].valid == 0) mas_inst.ic_flag = IC_UNCLEAR; else if (tmp_cs[set].tag == tag) mas_inst.ic_flag = IC_HIT; else { mas_inst.ic_flag = IC_MISS; tmp_cs[set].valid = 1; } enqueue(&queue, &mas_inst); num++; num_mp++; } if (i == 0) num_plog_trunc[log_set] = max_num_mp; } // copy code from temporary storage to the new prologue node plog = (code_link_t *) calloc(1, sizeof(code_link_t)); CHECK_MEM(plog); plog->code = (mas_inst_t *) calloc(num, sizeof(mas_inst_t)); CHECK_MEM(plog->code); for (k = 0; k < num; k++) plog->code[k] = *((mas_inst_t *) dequeue(&queue)); plog->num_inst = num; plog->next = prologs[log_set]; prologs[log_set] = plog; free_queue(&queue); }
int main( int argc, const char* argv[] ){ MQTTAsync client; MQTTAsync_connectOptions conn_opts = MQTTAsync_connectOptions_initializer; MQTTAsync_disconnectOptions disc_opts = MQTTAsync_disconnectOptions_initializer; MQTTAsync_message pubmsg = MQTTAsync_message_initializer; int rc = ICP_SUCCESS; char str[128]; char topic[128]; char ch = 'a'; char cmd[128] = ""; char sub_cmd[8][8]; char *pch; int i; mac_addr_t receiver; printf("\n\n\n\n\n"); // MQTT setup, connection and subscribe's MQTTAsync_create(&client, ADDRESS, mac_addrs[local_mac_addr], MQTTCLIENT_PERSISTENCE_NONE, NULL); MQTTAsync_setCallbacks(client, NULL, connlost, msgarrvd, NULL); p_client = &client; CHECK_MEM(p_client); mqtt_enable_debug_output(TRUE); conn_opts.keepAliveInterval = 20; conn_opts.cleansession = 1; conn_opts.onSuccess = onConnect; conn_opts.onFailure = onConnectFailure; conn_opts.context = client; if ((rc = MQTTAsync_connect(client, &conn_opts)) != MQTTASYNC_SUCCESS){ MQTT_DEBUG("Failed to start connect, return code %d\n", rc); exit(-1); } while (!connected); // CHECK_ERR(print_packet(NULL) == -1, "failed with p_packet=NULL"); // CHECK_ERR(print_packet(&packet) == 0, "failed with valid args"); // CHECK_ERR(icp_bytes_out_cb( (const uint8_t *)NULL, 10, NULL) == 0, "failed with output_byte_array=NULL"); // CHECK_ERR(icp_bytes_out_cb( (const uint8_t *)str, 0, NULL) == 0, "failed with array_len=0"); // strcpy(str, "Hello"); // CHECK_ERR(icp_bytes_out_cb( (const uint8_t *)str, 10, NULL) == 0, "failed with array_len:10!=strlen(output_byte_array):%s", str); // strcpy(str, "Hello"); // CHECK_ERR(icp_bytes_out_cb( (const uint8_t *)str, strlen(str), NULL) == strlen(str), "failed with valid args"); // CHECK_ERR(icp_packet_received_cb(NULL, NULL) == -1, "failed with p_packet=NULL"); // CHECK_ERR(icp_packet_received_cb(&packet, NULL) == 0, "failed with valid args"); // CHECK_ERR(icp_error_cb(ICP_SUCCESS, packet.data, packet.data_length, NULL) == -1, "failed with invalid packet"); // packet.data = (uint8_t *)&str; // CHECK_ERR(icp_error_cb(ICP_SUCCESS, packet.data, packet.data_length, NULL) == 0, "failed with valid args"); // while(TRUE); if (finished) goto exit; if (FALSE) { LOG_INFO("Sending clean..."); sent = FALSE; strcpy(str, "clean"); strcpy(topic, topic_names[TOPIC_SIMULATOR_BASE]); pubmsg.payload = (char*)str; pubmsg.payloadlen = strlen(str); pubmsg.qos = QOS; pubmsg.retained = 0; sendmsg(client, topic, &pubmsg); while (!sent) ; LOG_INFO("Sending 'eps' to pc..."); sent = FALSE; strcpy(str, "eps"); strcpy(topic, topic_names[TOPIC_SIMULATOR_BASE]); strcat(topic, mac_addrs[NODE_PC]); pubmsg.payload = (char*)str; pubmsg.payloadlen = strlen(str); pubmsg.qos = QOS; pubmsg.retained = 0; sendmsg(client, topic, &pubmsg); while (!sent) ; LOG_INFO("Sending 'cdhs' to cam..."); sent = FALSE; strcpy(str, "cdhs"); strcpy(topic, topic_names[TOPIC_SIMULATOR_BASE]); strcat(topic, mac_addrs[NODE_CAM]); pubmsg.payload = (char*)str; pubmsg.payloadlen = strlen(str); pubmsg.qos = QOS; pubmsg.retained = 0; sendmsg(client, topic, &pubmsg); while (!sent) ; LOG_INFO("Sending 'pc' to cdhs..."); sent = FALSE; strcpy(str, "pc"); strcpy(topic, topic_names[TOPIC_SIMULATOR_BASE]); strcat(topic, mac_addrs[NODE_CDHS]); pubmsg.payload = (char*)str; pubmsg.payloadlen = strlen(str); pubmsg.qos = QOS; pubmsg.retained = 0; sendmsg(client, topic, &pubmsg); while (!sent) ; LOG_INFO("Sending 'cdhs' to eps..."); sent = FALSE; strcpy(str, "cdhs"); strcpy(topic, topic_names[TOPIC_SIMULATOR_BASE]); strcat(topic, mac_addrs[NODE_EPS]); pubmsg.payload = (char*)str; pubmsg.payloadlen = strlen(str); pubmsg.qos = QOS; pubmsg.retained = 0; sendmsg(client, topic, &pubmsg); while (!sent) ; LOG_INFO("Sending update..."); sent = FALSE; strcpy(str, "update"); strcpy(topic, topic_names[TOPIC_SIMULATOR_BASE]); pubmsg.payload = (char*)str; pubmsg.payloadlen = strlen(str); pubmsg.qos = QOS; pubmsg.retained = 0; sendmsg(client, topic, &pubmsg); while (!sent) ; } LOG_INFO("Running..."); while (TRUE) { ch = getchar(); if (strncmp(&ch, "\n", 1) != 0) { strcat(cmd, &ch); } else { LOG_INFO("Got cmd: %s", cmd); pch = strtok (cmd," "); i = 0; while (pch != NULL) { strcpy(sub_cmd[i++], pch); DEBUG("sub_cmd[%d] = %s - %s", i-1, sub_cmd[i-1], (strncmp(sub_cmd[i-1], "set", 3) == 0 ? "TRUE" : "FALSE")); pch = strtok (NULL, " "); } receiver = INVALID_MAC_ADDR; if ( strncmp(sub_cmd[0], "cam", 3) == 0 ) { receiver = NODE_CAM; } else if ( strncmp(sub_cmd[0], "cdhs", 4) == 0 ) { receiver = NODE_CDHS; } else if ( strncmp(sub_cmd[0], "pc", 2) == 0 ) { receiver = NODE_PC; } else if ( strncmp(sub_cmd[0], "eps", 3) == 0 ) { receiver = NODE_EPS; } else if ( strncmp(sub_cmd[0], "test", 4) == 0 ) { receiver = NODE_TEST; } else if ( strncmp(sub_cmd[0], "bus", 3) == 0 ) { receiver = NODE_BUS; } else if ( strncmp(sub_cmd[0], "all", 4) == 0 ) { receiver = BROADCAST; } strcpy(topic, topic_names[TOPIC_SIMULATOR_BASE]); if (receiver != INVALID_MAC_ADDR && receiver != BROADCAST) { strcat(topic, mac_addrs[receiver]); } if (strncmp(sub_cmd[0], "q", 1) == 0) { LOG_INFO("Quiting..."); break; } else if (strlen(cmd) == 0) { LOG_INFO("Empty cmd..."); goto end; }else if (strncmp(sub_cmd[0], "clean", 5) == 0 || strncmp(sub_cmd[0], "update", 6) == 0 || strncmp(sub_cmd[0], "reset", 5) == 0 || strncmp(sub_cmd[0], "stopupdate", 10) == 0 || strncmp(sub_cmd[0], "sync", 4) == 0 || strncmp(sub_cmd[0], "time", 4) == 0) { LOG_INFO("Sending '%s' to all.", sub_cmd[0]); sent = FALSE; strcpy(str, sub_cmd[0]); if (strncmp(sub_cmd[0], "sync", 4) == 0) { synctime(); } } else if (strncmp(sub_cmd[1], "clean", 5) == 0 || strncmp(sub_cmd[1], "update", 6) == 0|| strncmp(sub_cmd[1], "stopupdate", 10) == 0 || strncmp(sub_cmd[1], "reset", 5) == 0 || strncmp(sub_cmd[1], "time", 4) == 0) { CHECK_EXIT(receiver != NUM_OF_NODES, "Invalid receiver."); LOG_INFO("Sending '%s' to %s.", sub_cmd[1], mac_addrs[receiver]); strcpy(str, sub_cmd[1]); }else if (strncmp(sub_cmd[1], "ping", 4) == 0 ) { CHECK_EXIT(receiver != NUM_OF_NODES, "Invalid receiver."); if ( strncmp(sub_cmd[2], "cdhs", 4) == 0 || strncmp(sub_cmd[2], "cam", 3) == 0 || strncmp(sub_cmd[2], "pc", 2) == 0 || strncmp(sub_cmd[2], "eps", 3) == 0 || strncmp(sub_cmd[2], "bus", 3) == 0 ) { LOG_INFO("Sending '%s' to %s...", sub_cmd[2], mac_addrs[receiver]); } else { LOG_INFO("Failed to cmd to send.") goto fail; } strcpy(str, sub_cmd[2]); }else if (strncmp(sub_cmd[1], "set", 3) == 0 ) { CHECK_EXIT(receiver != INVALID_MAC_ADDR, "Invalid receiver."); if ( (strncmp(sub_cmd[2], "icp", 3) == 0 || strncmp(sub_cmd[2], "mqtt", 4) == 0 || strncmp(sub_cmd[2], "sys", 3) == 0 || strncmp(sub_cmd[2], "all", 3) == 0) && (strncmp(sub_cmd[3], "debug", 5) == 0 || strncmp(sub_cmd[3], "err", 3) == 0 || strncmp(sub_cmd[3], "warn", 4) == 0 || strncmp(sub_cmd[3], "info", 4) == 0 || strncmp(sub_cmd[3], "all", 3) == 0) && (strncmp(sub_cmd[4], "true", 4) == 0 || strncmp(sub_cmd[4], "false", 5) == 0)) { LOG_INFO("Sending '%s %s %s %s' to %s...", sub_cmd[1], sub_cmd[2], sub_cmd[3], sub_cmd[4], mac_addrs[receiver]); strcpy(str, sub_cmd[1]); strcat(str, " "); strcat(str, sub_cmd[2]); strcat(str, " "); strcat(str, sub_cmd[3]); strcat(str, " "); strcat(str, sub_cmd[4]); } else /*if ( (strncmp(sub_cmd[2], "icp", 3) == 0 || strncmp(sub_cmd[2], "mqtt", 4) == 0 || strncmp(sub_cmd[2], "sys", 3) == 0) && (strncmp(sub_cmd[3], "debug", 5) == 0 || strncmp(sub_cmd[3], "err", 3) == 0 || strncmp(sub_cmd[3], "warn", 4) == 0 || strncmp(sub_cmd[3], "info", 4) == 0) && (strncmp(sub_cmd[4], "true", 4) == 0 || strncmp(sub_cmd[4], "false", 5) == 0)) { LOG_INFO("Sending '%s %s %s %s' to %s...", sub_cmd[1], sub_cmd[2], sub_cmd[3], sub_cmd[4], mac_addrs[receiver]); */{ LOG_WARN("Failed to send cmd.") LOG_INFO("command example: [eps|pc|...|all] set [icp|sys|mqtt|all] [debug|err|warn|info|all] [true|false]"); goto fail; } } else { goto fail; } sent = FALSE; pubmsg.payload = (char*)str; pubmsg.payloadlen = strlen(str); pubmsg.qos = QOS; pubmsg.retained = 0; LOG_INFO("Sending '%s' to '%s'", str, topic); sendmsg(client, topic, &pubmsg); while (!sent) ; fail: end: LOG_INFO("Clearing cmd buffer."); strcpy(cmd, ""); for(i=0;i<8;i++) { strcpy(sub_cmd[i], ""); } }
void OmxDecTestEosAfterFlushPort::Run() { switch (iState) { case StateUnLoaded: { PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestEosAfterFlushPort::Run() - StateUnLoaded IN")); OMX_ERRORTYPE Err; OMX_BOOL Status; if (!iCallbacks->initCallbacks()) { PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0, "OmxDecTestEosAfterFlushPort::Run() - ERROR initCallbacks failed, OUT")); StopOnError(); break; } ipAppPriv = (AppPrivateType*) oscl_malloc(sizeof(AppPrivateType)); CHECK_MEM(ipAppPriv, "Component_Handle"); ipAppPriv->Handle = NULL; //Allocate bitstream buffer for AVC component if (0 == oscl_strcmp(iFormat, "H264")) { ipAVCBSO = OSCL_NEW(AVCBitstreamObject, (ipInputFile)); CHECK_MEM(ipAVCBSO, "Bitstream_Buffer"); } //Allocate bitstream buffer for MPEG4/H263 component if (0 == oscl_strcmp(iFormat, "M4V") || 0 == oscl_strcmp(iFormat, "H263")) { ipBitstreamBuffer = (OMX_U8*) oscl_malloc(BIT_BUFF_SIZE); CHECK_MEM(ipBitstreamBuffer, "Bitstream_Buffer") ipBitstreamBufferPointer = ipBitstreamBuffer; } //Allocate bitstream buffer for MP3 component if (0 == oscl_strcmp(iFormat, "MP3")) { ipMp3Bitstream = OSCL_NEW(Mp3BitstreamObject, (ipInputFile)); CHECK_MEM(ipMp3Bitstream, "Bitstream_Buffer"); } //This should be the first call to the component to load it. Err = OMX_MasterInit(); CHECK_ERROR(Err, "OMX_MasterInit"); PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestEosAfterFlushPort::Run() - OMX_MasterInit done")); Status = PrepareComponent(); if (OMX_FALSE == Status) { PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestEosAfterFlushPort::Run() Error while loading component OUT")); iState = StateError; if (iInputParameters.inPtr) { oscl_free(iInputParameters.inPtr); iInputParameters.inPtr = NULL; } RunIfNotReady(); break; } #if PROXY_INTERFACE ipThreadSafeHandlerEventHandler = OSCL_NEW(OmxEventHandlerThreadSafeCallbackAO, (this, EVENT_HANDLER_QUEUE_DEPTH, "EventHandlerAO")); ipThreadSafeHandlerEmptyBufferDone = OSCL_NEW(OmxEmptyBufferDoneThreadSafeCallbackAO, (this, iInBufferCount, "EmptyBufferDoneAO")); ipThreadSafeHandlerFillBufferDone = OSCL_NEW(OmxFillBufferDoneThreadSafeCallbackAO, (this, iOutBufferCount, "FillBufferDoneAO")); if ((NULL == ipThreadSafeHandlerEventHandler) || (NULL == ipThreadSafeHandlerEmptyBufferDone) || (NULL == ipThreadSafeHandlerFillBufferDone)) { PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0, "OmxDecTestEosAfterFlushPort::Run() - Error, ThreadSafe Callback Handler initialization failed, OUT")); iState = StateUnLoaded; OsclExecScheduler* sched = OsclExecScheduler::Current(); sched->StopScheduler(); } #endif if (StateError != iState) { iState = StateLoaded; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestEosAfterFlushPort::Run() - StateUnLoaded OUT, moving to next state")); } RunIfNotReady(); } break; case StateLoaded: { OMX_ERRORTYPE Err; OMX_U32 ii; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestEosAfterFlushPort::Run() - StateLoaded IN")); // allocate memory for ipInBuffer ipInBuffer = (OMX_BUFFERHEADERTYPE**) oscl_malloc(sizeof(OMX_BUFFERHEADERTYPE*) * iInBufferCount); CHECK_MEM(ipInBuffer, "InputBufferHeader"); ipInputAvail = (OMX_BOOL*) oscl_malloc(sizeof(OMX_BOOL) * iInBufferCount); CHECK_MEM(ipInputAvail, "InputBufferFlag"); /* Initialize all the buffers to NULL */ for (ii = 0; ii < iInBufferCount; ii++) { ipInBuffer[ii] = NULL; } //allocate memory for output buffer ipOutBuffer = (OMX_BUFFERHEADERTYPE**) oscl_malloc(sizeof(OMX_BUFFERHEADERTYPE*) * iOutBufferCount); CHECK_MEM(ipOutBuffer, "OutputBuffer"); ipOutReleased = (OMX_BOOL*) oscl_malloc(sizeof(OMX_BOOL) * iOutBufferCount); CHECK_MEM(ipOutReleased, "OutputBufferFlag"); /* Initialize all the buffers to NULL */ for (ii = 0; ii < iOutBufferCount; ii++) { ipOutBuffer[ii] = NULL; } Err = OMX_SendCommand(ipAppPriv->Handle, OMX_CommandStateSet, OMX_StateIdle, NULL); CHECK_ERROR(Err, "SendCommand Loaded->Idle"); PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestEosAfterFlushPort::Run() - Sent State Transition Command from Loaded->Idle")); iPendingCommands = 1; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestEosAfterFlushPort::Run() - Allocating %d input and %d output buffers", iInBufferCount, iOutBufferCount)); //These calls are required because the control of in & out buffer should be with the testapp. for (ii = 0; ii < iInBufferCount; ii++) { Err = OMX_AllocateBuffer(ipAppPriv->Handle, &ipInBuffer[ii], iInputPortIndex, NULL, iInBufferSize); CHECK_ERROR(Err, "AllocateBuffer_Input"); PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestEosAfterFlushPort::Run() - Called AllocateBuffer for buffer index %d on port %d", ii, iInputPortIndex)); ipInputAvail[ii] = OMX_TRUE; ipInBuffer[ii]->nInputPortIndex = iInputPortIndex; } if (StateError == iState) { PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0, "OmxDecTestEosAfterFlushPort::Run() - AllocateBuffer Error, StateLoaded OUT")); RunIfNotReady(); break; } for (ii = 0; ii < iOutBufferCount; ii++) { Err = OMX_AllocateBuffer(ipAppPriv->Handle, &ipOutBuffer[ii], iOutputPortIndex, NULL, iOutBufferSize); CHECK_ERROR(Err, "AllocateBuffer_Output"); PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestEosAfterFlushPort::Run() - Called AllocateBuffer for buffer index %d on port %d", ii, iOutputPortIndex)); ipOutReleased[ii] = OMX_TRUE; ipOutBuffer[ii]->nOutputPortIndex = iOutputPortIndex; ipOutBuffer[ii]->nInputPortIndex = 0; } if (StateError == iState) { PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0, "OmxDecTestEosAfterFlushPort::Run() - AllocateBuffer Error, StateLoaded OUT")); RunIfNotReady(); break; } PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestEosAfterFlushPort::Run() - StateLoaded OUT, Moving to next state")); } break; case StateIdle: { PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestEosAfterFlushPort::Run() - StateIdle IN")); OMX_ERRORTYPE Err = OMX_ErrorNone; Err = OMX_FillThisBuffer(ipAppPriv->Handle, ipOutBuffer[0]); CHECK_ERROR(Err, "FillThisBuffer"); PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestEosAfterFlushPort::Run() - FillThisBuffer command called for initiating dynamic port reconfiguration")); ipOutReleased[0] = OMX_FALSE; Err = OMX_SendCommand(ipAppPriv->Handle, OMX_CommandStateSet, OMX_StateExecuting, NULL); CHECK_ERROR(Err, "SendCommand Idle->Executing"); PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestEosAfterFlushPort::Run() - Sent State Transition Command from Idle->Executing")); iPendingCommands = 1; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestEosAfterFlushPort::Run() - StateIdle OUT")); } break; case StateDecodeHeader: { PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestEosAfterFlushPort::Run() - StateDecodeHeader IN, Sending configuration input buffers to the component to start dynamic port reconfiguration")); if (!iFlagDecodeHeader) { (*this.*pGetInputFrame)(); if (0 == oscl_strcmp(iFormat, "AAC") || 0 == oscl_strcmp(iFormat, "AMR")) { (*this.*pGetInputFrame)(); } iFlagDecodeHeader = OMX_TRUE; iFrameCount++; //Proceed to executing state and if Port settings changed callback comes, //then do the dynamic port reconfiguration iState = StateExecuting; RunIfNotReady(); } PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestEosAfterFlushPort::Run() - StateDecodeHeader OUT")); } break; case StateDisablePort: { OMX_ERRORTYPE Err = OMX_ErrorNone; OMX_U32 ii; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestEosAfterFlushPort::Run() - StateDisablePort IN")); if (!iDisableRun) { if (!iFlagDisablePort) { Err = OMX_SendCommand(ipAppPriv->Handle, OMX_CommandPortDisable, iOutputPortIndex, NULL); CHECK_ERROR(Err, "SendCommand_PortDisable"); PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestEosAfterFlushPort::Run() - Sent Command for OMX_CommandPortDisable on port %d as a part of dynamic port reconfiguration", iOutputPortIndex)); iPendingCommands = 1; iFlagDisablePort = OMX_TRUE; RunIfNotReady(); } else { //Wait for all the buffers to be returned on output port before freeing them //This wait is required because of the queueing delay in all the Callbacks for (ii = 0; ii < iOutBufferCount; ii++) { if (OMX_FALSE == ipOutReleased[ii]) { break; } } if (ii != iOutBufferCount) { PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestEosAfterFlushPort::Run() - Not all the output buffers returned by component yet, wait for it")); RunIfNotReady(); break; } for (ii = 0; ii < iOutBufferCount; ii++) { if (ipOutBuffer[ii]) { Err = OMX_FreeBuffer(ipAppPriv->Handle, iOutputPortIndex, ipOutBuffer[ii]); CHECK_ERROR(Err, "FreeBuffer_Output_DynamicReconfig"); ipOutBuffer[ii] = NULL; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestEosAfterFlushPort::Run() - Called FreeBuffer for buffer index %d on port %d", ii, iOutputPortIndex)); } } if (ipOutBuffer) { oscl_free(ipOutBuffer); ipOutBuffer = NULL; } if (ipOutReleased) { oscl_free(ipOutReleased); ipOutReleased = NULL; } if (StateError == iState) { PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0, "OmxDecTestEosAfterFlushPort::Run() - Error occured in this state, StateDisablePort OUT")); RunIfNotReady(); break; } iDisableRun = OMX_TRUE; } } PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestEosAfterFlushPort::Run() - StateDisablePort OUT")); } break; case StateDynamicReconfig: { OMX_BOOL Status = OMX_TRUE; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestEosAfterFlushPort::Run() - StateDynamicReconfig IN")); Status = HandlePortReEnable(); if (OMX_FALSE == Status) { PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0, "OmxDecTestEosAfterFlushPort::Run() - Error occured in this state, StateDynamicReconfig OUT")); iState = StateError; RunIfNotReady(); break; } PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestEosAfterFlushPort::Run() - StateDynamicReconfig OUT")); } break; case StateExecuting: { OMX_U32 Index; OMX_BOOL MoreOutput; OMX_ERRORTYPE Err = OMX_ErrorNone; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestEosAfterFlushPort::Run() - StateExecuting IN")); //After Processing N number of buffers, send the flush command on both the ports if ((iFrameCount > TEST_NUM_BUFFERS_TO_PROCESS) && (OMX_FALSE == iFlushCommandSent)) { Err = OMX_SendCommand(ipAppPriv->Handle, OMX_CommandFlush, OMX_ALL, NULL); CHECK_ERROR(Err, "SendCommand OMX_CommandFlush"); PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestEosAfterFlushPort::Run() - Sending Flush Command on each port")); //Expecting 2 callbacks from each port iPendingCommands = 2; iFlushCommandSent = OMX_TRUE; } else { MoreOutput = OMX_TRUE; while (MoreOutput) { Index = 0; while (OMX_FALSE == ipOutReleased[Index] && Index < iOutBufferCount) { Index++; } if (Index != iOutBufferCount) { //This call is being made only once per frame Err = OMX_FillThisBuffer(ipAppPriv->Handle, ipOutBuffer[Index]); CHECK_ERROR(Err, "FillThisBuffer"); //Reset this till u receive the callback for output buffer free ipOutReleased[Index] = OMX_FALSE; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestEosAfterFlushPort::Run() - FillThisBuffer command called for output buffer index %d", Index)); } else { MoreOutput = OMX_FALSE; } } //while (MoreOutput) loop end here if (!iStopProcessingInput || (OMX_ErrorInsufficientResources == iStatusExecuting)) { // find available input buffer Index = 0; while (OMX_FALSE == ipInputAvail[Index] && Index < iInBufferCount) { Index++; } if (Index != iInBufferCount) { iStatusExecuting = (*this.*pGetInputFrame)(); iFrameCount++; } } else { //Some error occured in between before sending the Flush Command, either due to //file end or some other error in EmptyBufferDone command, stop the test case here //No need to proceed and test PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0, "OmxDecTestEosAfterFlushPort::Run() - Error occured before sending Flush Command, Stop the test case")); iState = StateError; } RunIfNotReady(); } //else of if ((iFrameCount > TEST_NUM_BUFFERS_TO_PROCESS) && (OMX_FALSE == iFlushCommandSent)) ends here PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestEosAfterFlushPort::Run() - StateExecuting OUT")); } break; case StateIntermediate: { /* check whether all the buffers are returned on each port after a flush comand, * then send an empty EOS buffer right after flush completed*/ OMX_U32 ii; OMX_ERRORTYPE Err = OMX_ErrorNone; OMX_BOOL AllBuffersReturned = OMX_TRUE; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestEosAfterFlushPort::Run() - StateIntermediate IN, for verification if ip/op buffers")); //Verifing whether all the input buffers are received back or not for (ii = 0; ii < iInBufferCount; ii++) { if (OMX_FALSE == ipInputAvail[ii]) { PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestEosAfterFlushPort::Run() - Not all the input buffers returned by component yet, rescheduling")); AllBuffersReturned = OMX_FALSE; break; } } //Verifing whether all the output buffers are received back or not for (ii = 0; ii < iOutBufferCount; ii++) { if (OMX_FALSE == ipOutReleased[ii]) { PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestEosAfterFlushPort::Run() - Not all the output buffers returned by component yet, rescheduling")); AllBuffersReturned = OMX_FALSE; break; } } if (OMX_FALSE == AllBuffersReturned) { PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestEosAfterFlushPort::Run() - Waiting for buffers to be returned, StateIntermediate OUT")); RunIfNotReady(); break; } else { //If all buffers have been returned, send an empty EOS buffer right after flush PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestEosAfterFlushPort::Run() - After completing the Flush Command, now testing with EOS buffer")); //send output buffers for component to continue processing for (ii = 0; ii < iOutBufferCount; ii++) { Err = OMX_FillThisBuffer(ipAppPriv->Handle, ipOutBuffer[ii]); CHECK_ERROR(Err, "FillThisBuffer"); ipOutReleased[ii] = OMX_FALSE; } PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestEosAfterFlushPort::Run() - FillThisBuffer command called for output buffer index 0")); //Only send one successful dummy buffer with flag set to signal EOS ipInBuffer[0]->nFlags |= OMX_BUFFERFLAG_EOS; ipInBuffer[0]->nFilledLen = 0; Err = OMX_EmptyThisBuffer(ipAppPriv->Handle, ipInBuffer[0]); CHECK_ERROR(Err, "EmptyThisBuffer_EOS"); ipInputAvail[0] = OMX_FALSE; // mark unavailable iPendingCommands = 1; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestEosAfterFlushPort::Run() - Empty Input buffer sent to the component with OMX_BUFFERFLAG_EOS flag set")); } iState = StateWaitingForEOSCallback; RunIfNotReady(); PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestEosAfterFlushPort::Run() - StateIntermediate OUT")); } break; case StateWaitingForEOSCallback: { //keep giving it more output buffers in case there is still data left in the decoder, and EOS callback is received OMX_U32 ii; OMX_ERRORTYPE Err = OMX_ErrorNone; for (ii = 0; ii < iOutBufferCount; ii++) { if (OMX_TRUE == ipOutReleased[ii]) { Err = OMX_FillThisBuffer(ipAppPriv->Handle, ipOutBuffer[ii]); CHECK_ERROR(Err, "FillThisBuffer"); //Reset this till u receive the callback for output buffer free ipOutReleased[ii] = OMX_FALSE; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestEosAfterFlushPort::Run() - FillThisBuffer command called for output buffer index %d", ii)); } } RunIfNotReady(); } break; case StateStopping: { OMX_ERRORTYPE Err = OMX_ErrorNone; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestEosAfterFlushPort::Run() - StateStopping IN")); //stop execution by state transition to Idle state. if (!iFlagStopping) { Err = OMX_SendCommand(ipAppPriv->Handle, OMX_CommandStateSet, OMX_StateIdle, NULL); CHECK_ERROR(Err, "SendCommand Executing->Idle"); PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestEosAfterFlushPort::Run() - Sent State Transition Command from Executing->Idle")); iPendingCommands = 1; iFlagStopping = OMX_TRUE; } PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestEosAfterFlushPort::Run() - StateStopping OUT")); } break; case StateCleanUp: { OMX_U32 ii; OMX_ERRORTYPE Err = OMX_ErrorNone; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestEosAfterFlushPort::Run() - StateCleanUp IN")); if (!iFlagCleanUp) { //Added a check here to verify whether all the ip/op buffers are returned back by the component or not //in case of Executing->Idle state transition if (OMX_FALSE == VerifyAllBuffersReturned()) { // not all buffers have been returned yet, reschedule RunIfNotReady(); break; } //Destroy the component by state transition to Loaded state Err = OMX_SendCommand(ipAppPriv->Handle, OMX_CommandStateSet, OMX_StateLoaded, NULL); CHECK_ERROR(Err, "SendCommand Idle->Loaded"); PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestEosAfterFlushPort::Run() - Sent State Transition Command from Idle->Loaded")); iPendingCommands = 1; if (ipInBuffer) { for (ii = 0; ii < iInBufferCount; ii++) { if (ipInBuffer[ii]) { Err = OMX_FreeBuffer(ipAppPriv->Handle, iInputPortIndex, ipInBuffer[ii]); CHECK_ERROR(Err, "FreeBuffer_Input"); ipInBuffer[ii] = NULL; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestEosAfterFlushPort::Run() - Called FreeBuffer for buffer index %d on port %d", ii, iInputPortIndex)); } } oscl_free(ipInBuffer); ipInBuffer = NULL; } if (ipInputAvail) { oscl_free(ipInputAvail); ipInputAvail = NULL; } if (ipOutBuffer) { for (ii = 0; ii < iOutBufferCount; ii++) { if (ipOutBuffer[ii]) { Err = OMX_FreeBuffer(ipAppPriv->Handle, iOutputPortIndex, ipOutBuffer[ii]); CHECK_ERROR(Err, "FreeBuffer_Output"); ipOutBuffer[ii] = NULL; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestEosAfterFlushPort::Run() - Called FreeBuffer for buffer index %d on port %d", ii, iOutputPortIndex)); } } oscl_free(ipOutBuffer); ipOutBuffer = NULL; } if (ipOutReleased) { oscl_free(ipOutReleased); ipOutReleased = NULL; } iFlagCleanUp = OMX_TRUE; } PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestEosAfterFlushPort::Run() - StateCleanUp OUT")); } break; /********* FREE THE HANDLE & CLOSE FILES FOR THE COMPONENT ********/ case StateStop: { OMX_U8 TestName[] = "FLUSH_PORT_TEST"; OMX_ERRORTYPE Err = OMX_ErrorNone; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestEosAfterFlushPort::Run() - StateStop IN")); if (ipAppPriv) { if (ipAppPriv->Handle) { PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestEosAfterFlushPort::Run() - Free the Component Handle")); Err = OMX_MasterFreeHandle(ipAppPriv->Handle); if (OMX_ErrorNone != Err) { PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0, "OmxDecTestEosAfterFlushPort::Run() - FreeHandle Error")); iTestStatus = OMX_FALSE; } } } PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestEosAfterFlushPort::Run() - De-initialize the omx component")); Err = OMX_MasterDeinit(); if (OMX_ErrorNone != Err) { PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0, "OmxDecTestEosAfterFlushPort::Run() - OMX_MasterDeinit Error")); iTestStatus = OMX_FALSE; } if (0 == oscl_strcmp(iFormat, "H264")) { if (ipAVCBSO) { OSCL_DELETE(ipAVCBSO); ipAVCBSO = NULL; } } if (0 == oscl_strcmp(iFormat, "M4V") || 0 == oscl_strcmp(iFormat, "H263")) { if (ipBitstreamBuffer) { oscl_free(ipBitstreamBufferPointer); ipBitstreamBuffer = NULL; ipBitstreamBufferPointer = NULL; } } if (iOutputParameters) { oscl_free(iOutputParameters); iOutputParameters = NULL; } if (ipAppPriv) { oscl_free(ipAppPriv); ipAppPriv = NULL; } #if PROXY_INTERFACE if (ipThreadSafeHandlerEventHandler) { OSCL_DELETE(ipThreadSafeHandlerEventHandler); ipThreadSafeHandlerEventHandler = NULL; } if (ipThreadSafeHandlerEmptyBufferDone) { OSCL_DELETE(ipThreadSafeHandlerEmptyBufferDone); ipThreadSafeHandlerEmptyBufferDone = NULL; } if (ipThreadSafeHandlerFillBufferDone) { OSCL_DELETE(ipThreadSafeHandlerFillBufferDone); ipThreadSafeHandlerFillBufferDone = NULL; } #endif if (OMX_FALSE == iTestStatus) { #ifdef PRINT_RESULT fprintf(iConsOutFile, "%s: Fail \n", TestName); OMX_DEC_TEST(false); iTestCase->TestCompleted(); #endif PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_INFO, (0, "OmxDecTestEosAfterFlushPort::Run() - %s : Fail", TestName)); } else { #ifdef PRINT_RESULT fprintf(iConsOutFile, "%s: Success \n", TestName); OMX_DEC_TEST(true); iTestCase->TestCompleted(); #endif PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_INFO, (0, "OmxDecTestEosAfterFlushPort::Run() - %s : Success", TestName)); } iState = StateUnLoaded; OsclExecScheduler* sched = OsclExecScheduler::Current(); sched->StopScheduler(); } break; case StateError: { //Do all the cleanup's and exit from here OMX_U32 ii; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestEosAfterFlushPort::Run() - StateError IN")); iTestStatus = OMX_FALSE; if (ipInBuffer) { for (ii = 0; ii < iInBufferCount; ii++) { if (ipInBuffer[ii]) { OMX_FreeBuffer(ipAppPriv->Handle, iInputPortIndex, ipInBuffer[ii]); ipInBuffer[ii] = NULL; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestEosAfterFlushPort::Run() - Called FreeBuffer for buffer index %d on port %d", ii, iInputPortIndex)); } } oscl_free(ipInBuffer); ipInBuffer = NULL; } if (ipInputAvail) { oscl_free(ipInputAvail); ipInputAvail = NULL; } if (ipOutBuffer) { for (ii = 0; ii < iOutBufferCount; ii++) { if (ipOutBuffer[ii]) { OMX_FreeBuffer(ipAppPriv->Handle, iOutputPortIndex, ipOutBuffer[ii]); ipOutBuffer[ii] = NULL; PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestEosAfterFlushPort::Run() - Called FreeBuffer for buffer index %d on port %d", ii, iOutputPortIndex)); } } oscl_free(ipOutBuffer); ipOutBuffer = NULL; } if (ipOutReleased) { oscl_free(ipOutReleased); ipOutReleased = NULL; } iState = StateStop; RunIfNotReady(); PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestEosAfterFlushPort::Run() - StateError OUT")); } break; default: { break; } } return ; }
static BOOLEAN _pc_efilio_extract(int op_code, int fd1, int fd2, dword clusters_to_move) { PC_FILE *pefile1,*pefile2; BOOLEAN ret_val; DDRIVE *pdr; REGION_FRAGMENT *pfrag1_cat,*pfrag1_middle,*pfrag1_to_delete; REGION_FRAGMENT *pfrag1_start, *pfrag1_end; REGION_FRAGMENT *pfrag2_cat,*pfrag2_middle; REGION_FRAGMENT *pfrag2_start, *pfrag2_end; dword ltemp_hi, ltemp_lo; dword fp1hi, fp1lo, fp1_cluster, size1_hi, size1_lo; dword fp2hi, fp2lo, fp2_cluster, size2_hi, size2_lo; dword two_gig_in_clusters; int is_error = 0; CHECK_MEM(BOOLEAN,0) /* Make sure memory is initted */ rtfs_clear_errno(); /* clear errno */ /* Check initial arguments.. swap must specify cluster count, the other operations can take to the end of file */ if (op_code == EFEXT_SWAP && clusters_to_move == 0) { rtfs_set_errno(PEINVALIDPARMS, __FILE__, __LINE__); return(FALSE); } /* Null all lists we may create */ pfrag1_cat = 0; pfrag1_middle = pfrag1_start = pfrag1_end = pfrag1_to_delete = 0; pfrag2_cat = 0; pfrag2_middle = pfrag2_start= pfrag2_end = 0; pefile1 = pc_fd2file(fd1, PO_WRONLY|PO_RDWR); if (!pefile1) return(FALSE); pdr = pefile1->pobj->pdrive; pefile2 = 0; /* Access the second file for swap and move operations */ if (op_code == EFEXT_SWAP || op_code == EFEXT_EXTRACT) { release_drive_mount(pefile1->pobj->pdrive->driveno);/* Release lock */ pefile2 = pc_fd2file(fd2, PO_WRONLY|PO_RDWR); if (!pefile2) return(FALSE); /* If the two files aren't on the same volume it's no good */ if (pefile2->pobj->pdrive != pdr) { // Note.. fix bug in cfilio_extract release_drive_mount(pefile2->pobj->pdrive->driveno); rtfs_set_errno(PEINVALIDPARMS, __FILE__, __LINE__); return(FALSE); } } ret_val = FALSE; pdr = pefile1->pobj->pdrive; /* Calculate the minimum number of clusters to hold 2 Gigabytes */ two_gig_in_clusters = pc_byte2clmod(pdr, 0x80000000); /* Get the current file pointer for file 1 */ if (!_pc_efilio_lseek(pefile1, 0, 0, PSEEK_CUR, &fp1hi, &fp1lo)) goto return_locked; /* Seek to the end and restore to get the size and insure the cluster chain is loaded */ if (!_pc_efilio_lseek(pefile1, 0, 0, PSEEK_END, &size1_hi, &size1_lo)) goto return_locked; if (!_pc_efilio_lseek(pefile1, fp1hi, fp1lo, PSEEK_SET, <emp_hi, <emp_lo)) goto return_locked; if (size1_hi == 0 && size1_lo == 0) { /* Nothing to do but not an error */ ret_val = TRUE; goto return_locked; } else { /* Make a copy of all fragments in fd1 */ pfrag1_cat = pc_linext_concatenate_fragments(pefile1); if (!pfrag1_cat) goto return_locked; /* Join all adjacent fragments in file 1 list */ pc_linext_fraglist_coalesce(pfrag1_cat); } /* Calculate the cluster ofset of fp1 */ #if (INCLUDE_EXFATORFAT64) if (ISEXFATORFAT64(pdr)) fp1_cluster = pc_byte2clmod64(pdr, fp1hi, fp1lo); else #endif fp1_cluster = pc_byte2clmod(pdr, fp1lo); if (op_code == EFEXT_SWAP || op_code == EFEXT_EXTRACT) { /* Get the current file pointer for file 2 */ if (!_pc_efilio_lseek(pefile2, 0, 0, PSEEK_CUR, &fp2hi, &fp2lo)) goto return_locked; /* Get the file size for file 2 */ if (!_pc_efilio_lseek(pefile2, 0, 0, PSEEK_END, &size2_hi, &size2_lo)) goto return_locked; if (size2_hi || size2_lo) { /* Make a copy of all fragments in fd2 */ pfrag2_cat = pc_linext_concatenate_fragments(pefile2); if (!pfrag2_cat) goto return_locked; /* Join all adjacent fragments in file 1 list */ pc_linext_fraglist_coalesce(pfrag2_cat); } #if (INCLUDE_EXFATORFAT64) if (ISEXFATORFAT64(pdr)) fp2_cluster = pc_byte2clmod64(pdr, fp2hi, fp2lo); else #endif fp2_cluster = pc_byte2clmod(pdr, fp2lo); /* Restore the file pointer */ if (!_pc_efilio_lseek(pefile2, fp2hi, fp2lo, PSEEK_SET, <emp_hi, <emp_lo)) goto return_locked; } else { size2_hi = size2_lo = fp2hi = fp2lo = fp2_cluster = 0; } /* Modify fragment lists as prescribed by the opcode and clusters_to_move */ /* Split file1 into start and middle if required */ switch (op_code) { case EFEXT_REMOVE: case EFEXT_SWAP: case EFEXT_EXTRACT: { /* Split file1 at the cluster immediately following the file pointer */ if (fp1_cluster) { pfrag1_start = pfrag1_cat; pfrag1_middle = pc_fraglist_split(pdr, pfrag1_start, fp1_cluster, &is_error); if (!pfrag1_middle) /* error must be out of frag structures */ goto return_locked; } else { pfrag1_start = 0; pfrag1_middle = pfrag1_cat; } if (!pfrag1_middle) { /* Asking to move more clusters than are available or out of frag structures */ if (!is_error) rtfs_set_errno(PEINVALIDPARMS, __FILE__, __LINE__); goto return_locked; } } break; default: break; }; /* Split file1 middle into middle and end if required */ /* if (clusters_to_move == 0) don't split because we are moving all */ if (clusters_to_move) { switch (op_code) { case EFEXT_REMOVE: case EFEXT_SWAP: case EFEXT_EXTRACT: { /* if (clusters_to_move == 0) we take all clusters until the end */ if (clusters_to_move != 0) { dword size_second_chain = 0; size_second_chain = pc_fraglist_count_clusters(pfrag1_middle, 0); if (size_second_chain < clusters_to_move) { /* Asking to move more clusters than are available */ rtfs_set_errno(PEINVALIDPARMS, __FILE__, __LINE__); goto return_locked; } else if (size_second_chain > clusters_to_move) { /* We are moving a portion. Split it so we can join start and end */ pfrag1_end = pc_fraglist_split(pdr, pfrag1_middle, clusters_to_move, &is_error); if (!pfrag1_end) goto return_locked; } /* Else we are moving rest of the file exactly */ } } break; default: break; }; } /* Split file2 into start and middle if required */ /* Sets pfrag2_cat to start point for rebuilding */ switch (op_code) { case EFEXT_SWAP: case EFEXT_EXTRACT: { /* Split file2 at the cluster immediately following the file pointer */ if (fp2_cluster) { pfrag2_start = pfrag2_cat; pfrag2_middle = pc_fraglist_split(pdr, pfrag2_start, fp2_cluster, &is_error); if (!pfrag2_middle) { if (is_error) /* error must be out of frag structures */ goto return_locked; /* There must be a middle for a swap, but for an extract we can append to the end */ if (op_code == EFEXT_SWAP) goto return_locked; } } else { pfrag2_start = 0; pfrag2_middle = pfrag2_cat; } } break; default: break; }; /* Split file2 middle into middle and end if required */ if (op_code == EFEXT_SWAP) { dword size_second_chain = 0; size_second_chain = pc_fraglist_count_clusters(pfrag2_middle, 0); if (size_second_chain < clusters_to_move) { /* Asking to swap more clusters than are available */ rtfs_set_errno(PEINVALIDPARMS, __FILE__, __LINE__); goto return_locked; } else if (size_second_chain > clusters_to_move) { /* We are moving a portion. Split it so we can join start and end */ pfrag2_end = pc_fraglist_split(pdr, pfrag2_middle, clusters_to_move, &is_error); if (!pfrag2_end) goto return_locked; } } /* Join the start and end fragments if delete or extract is removing the middle of the file */ switch (op_code) { case EFEXT_REMOVE: case EFEXT_EXTRACT: { /* Rejoin the start and end fragments */ if (pfrag1_end) { if (pfrag1_start) pc_end_fragment_chain(pfrag1_start)->pnext = pfrag1_end; else pfrag1_start = pfrag1_end; } /* prepare to reassemble file 1.. */ pfrag1_cat = pfrag1_start; } break; default: break; } /* Insert the middle fragment of file 1 in between start and middle it is extract */ switch (op_code) { case EFEXT_EXTRACT: { if (pfrag1_middle) pc_end_fragment_chain(pfrag1_middle)->pnext = pfrag2_middle; /* Rejoin the start and end fragments */ if (pfrag2_start) pc_end_fragment_chain(pfrag2_start)->pnext = pfrag1_middle; else pfrag2_start = pfrag1_middle; /* prepare to reassemble file 2 */ pfrag2_cat = pfrag2_start; } break; default: break; } /* Insert the middle fragment of file 1 in between start and middle of file 2 it is a swap */ switch (op_code) { case EFEXT_SWAP: { if (pfrag1_middle) pc_end_fragment_chain(pfrag1_middle)->pnext = pfrag2_end; /* Rejoin the start and end fragments */ if (pfrag2_start) pc_end_fragment_chain(pfrag2_start)->pnext = pfrag1_middle; else pfrag2_start = pfrag1_middle; /* prepare to reassemble file 2 */ pfrag2_cat = pfrag2_start; } break; default: break; } /* Insert the middle fragment of file 2 in between start and middle of file 1 it is a swap */ switch (op_code) { case EFEXT_SWAP: { if (pfrag2_middle) pc_end_fragment_chain(pfrag2_middle)->pnext = pfrag1_end; /* Rejoin the start and end fragments */ if (pfrag1_start) pc_end_fragment_chain(pfrag1_start)->pnext = pfrag2_middle; else pfrag1_start = pfrag2_middle; /* prepare to reassemble file 1 */ pfrag1_cat = pfrag1_start; } break; default: break; } /* Check that extract does not make the target file too large */ #if (INCLUDE_EXFATORFAT64) /* No limit for exFAT */ if (!ISEXFATORFAT64(pefile1->pobj->pdrive)) #endif if (op_code == EFEXT_EXTRACT) { dword new_fd2_size_clusters; dword max_fd2_size_clusters; new_fd2_size_clusters = pc_fraglist_count_clusters(pfrag2_cat, 0); /* default max file size is 4 gig */ max_fd2_size_clusters = two_gig_in_clusters*2; /* We can not append to file 2 if it is 32 bit and our new fragment is larger */ if (new_fd2_size_clusters > max_fd2_size_clusters) { rtfs_set_errno(PETOOLARGE, __FILE__, __LINE__); goto return_locked; } } /* pfrag1_cat and pfrag2_cat are rethreaded and contain chains that must be built into files */ /* Save middle of fd1 in case we are freeing it */ if (op_code == EFEXT_REMOVE && pfrag1_middle) pfrag1_to_delete = pfrag1_middle; else pfrag1_to_delete = 0; /* clear other fragment pointers so we clean up correctly */ pfrag1_middle = pfrag1_start = pfrag1_end = pfrag2_middle = pfrag2_start = pfrag2_end = 0; /* pfrag1_cat and pfrag2_cat now contain chains that must be built into files */ /* Join all adjacent fragments in file 1 list again, in case a swap operation inserted an adjacent segment */ pc_linext_fraglist_coalesce(pfrag1_cat); /* Rethread files from the fragment lists and update sizes */ pc_linext_rebuild_file(pefile1, pfrag1_cat); pc_set_file_dirty(pefile1, TRUE); _pc_efilio_reset_seek(pefile1); pfrag1_cat = 0; /* Used, don't release on future errors */ /* pfrag1_middle will be non_zero if we are freeing a section of the file queue it for release when the file is flushed */ if (op_code == EFEXT_REMOVE && pfrag1_to_delete) { pc_linext_queue_delete(pefile1, pfrag1_to_delete); pfrag1_to_delete = 0; } /* Rebuild file 2 on swap or extract */ if (op_code == EFEXT_SWAP || op_code == EFEXT_EXTRACT) { /* Join all adjacent fragments in file 2 list */ pc_linext_fraglist_coalesce(pfrag2_cat); /* Rethread the file list and update sizes */ pc_linext_rebuild_file(pefile2, pfrag2_cat); pc_set_file_dirty(pefile2, TRUE); _pc_efilio_reset_seek(pefile2); pfrag2_cat = 0; /* Used, don't release on future errors */ } ret_val = TRUE; if (!_pc_efilio_lseek(pefile1, fp1hi, fp1lo, PSEEK_SET, <emp_hi, <emp_lo)) ret_val = FALSE; if (op_code == EFEXT_SWAP || op_code == EFEXT_EXTRACT) { if (!_pc_efilio_lseek(pefile2, fp2hi, fp2lo, PSEEK_SET, <emp_hi, <emp_lo)) ret_val = FALSE; } if (op_code == EFEXT_SWAP) { /* Restore origninal file sizes for both files */ pc_linext_set_file_size(pefile1, size1_hi, size1_lo); pc_linext_set_file_size(pefile2, size2_hi, size2_lo); } else if (op_code == EFEXT_REMOVE || op_code == EFEXT_EXTRACT) { dword bytesmoved_hi,bytesmoved_lo,newsize_hi,newsize_lo ; /* Get the byte count of clusters moved */ pc_clusters2bytes64(pdr, clusters_to_move, &bytesmoved_hi, &bytesmoved_lo); /* Reduce the size of fd1 by bytesmoved_hi:bytesmoved_lo*/ pc_subtract_64(size1_hi, size1_lo, bytesmoved_hi, bytesmoved_lo, &newsize_hi, &newsize_lo); pc_linext_set_file_size(pefile1, newsize_hi, newsize_lo); /* If it was an extract increase the size of fd2 by bytesmoved_hi:bytesmoved_lo */ if (op_code == EFEXT_EXTRACT) { /* Increase the size of fd2 by bytesmoved_hi:bytesmoved_lo*/ pc_add_64(size2_hi, size2_lo, bytesmoved_hi, bytesmoved_lo, &newsize_hi, &newsize_lo); pc_linext_set_file_size(pefile2, newsize_hi, newsize_lo); } } return_locked: if (!ret_val) { /* If we failed free all fragments that we allocated */ if (pfrag1_to_delete) /* Only set if rebuild of fd1 failed before queing the delete */ pc_fraglist_free_list(pfrag1_to_delete); if (pfrag1_start) { pc_fraglist_free_list(pfrag1_start); pfrag1_cat = 0; /* If _start or _middle or _end are defined then cat was split and must not be freed */ } if (pfrag1_middle) { pc_fraglist_free_list(pfrag1_middle); pfrag1_cat = 0; } if (pfrag1_end) { pc_fraglist_free_list(pfrag1_end); pfrag1_cat = 0; } if (pfrag1_cat) pc_fraglist_free_list(pfrag1_cat); if (pfrag2_start) { pc_fraglist_free_list(pfrag2_start); pfrag2_cat = 0; } if (pfrag2_middle) { pc_fraglist_free_list(pfrag2_middle); pfrag2_cat = 0; } if (pfrag2_end) { pc_fraglist_free_list(pfrag2_end); pfrag2_cat = 0; } if (pfrag2_cat) pc_fraglist_free_list(pfrag2_cat); } if (!release_drive_mount_write(pdr->driveno))/* Release lock, unmount if aborted */ ret_val = FALSE; return(ret_val); }
int main(int argc, char *argv[]) { // Scan commandline arguments // Default values struct arguments arguments; arguments.quiet = false; arguments.verbose = false; arguments.binary = false; arguments.output_path = "-"; arguments.channels = NULL; arguments.chno = 0; arguments.inputno = 0; argp_parse(&argp, argc, argv, 0, 0, &arguments); if((!arguments.quiet) && arguments.channels && (arguments.inputno != arguments.chno)) { LOG_WARN("Number of input files (%lu) different from number of sync channels (%lu)", arguments.inputno, arguments.chno); } int i; size_t tsno[arguments.inputno]; size_t total = 0; FILE *infile; Timestamp **ts = malloc(arguments.inputno * sizeof(Timestamp **)); Channel **ch = malloc(arguments.inputno * sizeof(Channel **)); CHECK_MEM(ts); CHECK_MEM(ch); for(i = 0; i < arguments.inputno; i++) { ts[i] = malloc(TS_MIN_SIZE * sizeof(Timestamp)); ch[i] = malloc(TS_MIN_SIZE * sizeof(Channel)); CHECK_MEM(ts[i]); CHECK_MEM(ch[i]); infile = fopen(arguments.input_paths[i], "r"); CHECK(infile, "Cannot open file %s for reading", arguments.input_paths[i]); tsno[i] = load_ts(infile, ts + i, ch + i, TS_MIN_SIZE); fclose(infile); CHECK(tsno[i] != 0, "No timestamp loaded for file %s", arguments.input_paths[i]); total += tsno[i]; } // Syncronize timestamps if the sync option was used if(arguments.chno > 0) { size_t min_tsno = tsno[0]; Channel signal_ch[arguments.inputno]; for(i = 0; i < arguments.inputno; i++) { min_tsno = tsno[i] < min_tsno ? tsno[i] : min_tsno; signal_ch[i] = i < arguments.chno? arguments.channels[i] : arguments.channels[arguments.chno - 1]; } CHECK(linear_sync( ts, ch, signal_ch, arguments.inputno, min_tsno, SYNC_FIT_SAMPLE, SYNC_STEP_SIZE ), "Syncronization failed."); } // Merge timestamps Timestamp *merged_ts = malloc(total * sizeof(Timestamp)); Channel *merged_ch = malloc(total * sizeof(Channel)); CHECK_MEM(merged_ts); CHECK_MEM(merged_ch); size_t merged = 0; merged = merge_timestamps(ts, ch, tsno, arguments.inputno, merged_ts, merged_ch); for(i = 0; i < arguments.inputno; i++) { free(ts[i]); free(ch[i]); } if(merged < total) LOG_WARN("%lu timestamps were lost.", total - merged); // Write to file FILE *outfile = fopen(arguments.output_path, "w"); CHECK(outfile, "Cannot open file %s for writing", arguments.output_path); if(arguments.binary) { CHECK(write_ts_bin(outfile, merged_ts, merged_ch, merged), "Cannot write to binary file %s.", arguments.output_path); } else { CHECK(write_ts_ascii(outfile, merged_ts, merged_ch, merged), "Cannot write to ASCII file %s.", arguments.output_path); } fclose(outfile); return EXIT_SUCCESS; error: return EXIT_FAILURE; }
bool CChunkyFile::CChunk::_Load(IFileStore::IStream* pStream, long iChunkyVersion) { char sType[5]; sType[4] = 0; try { pStream->VRead(4, 1, (void*)sType); } catch(CRainmanException *pE) { pE->destroy(); return false; } if(strcmp(sType, "DATA") == 0) m_eType = T_Data; else if(strcmp(sType, "FOLD") == 0) m_eType = T_Folder; else throw new CRainmanException(0, __FILE__, __LINE__, "Unrecognised chunk type \'%s\'", sType); unsigned long iDescriptorLength = 0; try { pStream->VRead(4, 1, (void*)m_sName); pStream->VRead(1, sizeof(long), &m_iVersion); pStream->VRead(1, sizeof(unsigned long), &m_iDataLength); pStream->VRead(1, sizeof(unsigned long), &iDescriptorLength); if(iChunkyVersion >= 3) { pStream->VRead(1, sizeof(unsigned long), &m_iUnknown1); pStream->VRead(1, sizeof(unsigned long), &m_iUnknown2); } } catch(CRainmanException *pE) { throw new CRainmanException(__FILE__, __LINE__, "Error reading from stream", pE); } if(m_sDescriptor) delete[] m_sDescriptor; m_sDescriptor = 0; m_sDescriptor = CHECK_MEM(new char[iDescriptorLength + 1]); m_sDescriptor[iDescriptorLength] = 0; try { pStream->VRead(iDescriptorLength, 1, (void*)m_sDescriptor); } catch(CRainmanException *pE) { throw new CRainmanException(__FILE__, __LINE__, "Error reading from stream", pE); } if(m_eType == T_Folder) { long iDataEnd = 0; try { iDataEnd = pStream->VTell() + (long) m_iDataLength; } catch(CRainmanException *pE) { throw new CRainmanException(__FILE__, __LINE__, "Cannot get position from stream", pE); } unsigned long iChildN = 0; while(1) { try { if(pStream->VTell() >= iDataEnd) break; } catch(CRainmanException *pE) { throw new CRainmanException(__FILE__, __LINE__, "Cannot get position from stream", pE); } CChunk *pChunk = CHECK_MEM(new CChunk); try { if(!pChunk->_Load(pStream, iChunkyVersion)) throw new CRainmanException(__FILE__, __LINE__, "End of stream reached"); } catch(CRainmanException *pE) { delete pChunk; throw new CRainmanException(pE, __FILE__, __LINE__, "Error reading child #%lu of FOLD%s", iChildN, m_sName); } m_vChildren.push_back(pChunk); ++iChildN; } } else { if(m_pData) delete[] m_pData; m_pData = 0; m_pData = CHECK_MEM(new char[m_iDataLength]); try { pStream->VRead(m_iDataLength, 1, (void*)m_pData); } catch(CRainmanException *pE) { throw new CRainmanException(__FILE__, __LINE__, "Error reading from stream", pE); } } return true; }