OMX_ERRORTYPE Component::allocOutputBuffers() { if(!handle) { ofLogError(__func__) << getName() << " NO HANDLE"; return OMX_ErrorNone; } OMX_ERRORTYPE error = OMX_ErrorNone; OMX_PARAM_PORTDEFINITIONTYPE portFormat; OMX_INIT_STRUCTURE(portFormat); portFormat.nPortIndex = outputPort; error = OMX_GetParameter(handle, OMX_IndexParamPortDefinition, &portFormat); OMX_TRACE(error); if(error != OMX_ErrorNone) { return error; } if(getState() != OMX_StateIdle) { if(getState() != OMX_StateLoaded) { setState(OMX_StateLoaded); } setState(OMX_StateIdle); } error = enablePort(outputPort); OMX_TRACE(error); if(error != OMX_ErrorNone) { return error; } for (size_t i = 0; i < portFormat.nBufferCountActual; i++) { OMX_BUFFERHEADERTYPE *buffer = NULL; error = OMX_AllocateBuffer(handle, &buffer, outputPort, NULL, portFormat.nBufferSize); OMX_TRACE(error); if(error != OMX_ErrorNone) { return error; } buffer->nOutputPortIndex = outputPort; buffer->nFilledLen = 0; buffer->nOffset = 0; buffer->pAppPrivate = (void*)i; outputBuffers.push_back(buffer); outputBuffersAvailable.push(buffer); } return error; }
OMX_ERRORTYPE ofxRPiCameraVideoGrabber::setFlickerCancellation(OMX_COMMONFLICKERCANCELTYPE eFlickerCancel) { OMX_ERRORTYPE error = OMX_GetConfig(camera, OMX_IndexConfigCommonFlickerCancellation, &flickerCancelConfig); OMX_TRACE(error); if(error == OMX_ErrorNone) { switch (flickerCancelConfig.eFlickerCancel) { case OMX_COMMONFLICKERCANCEL_OFF: { ofLogVerbose(__func__) << "OMX_COMMONFLICKERCANCEL_OFF"; break; } case OMX_COMMONFLICKERCANCEL_AUTO: { ofLogVerbose(__func__) << "OMX_COMMONFLICKERCANCEL_AUTO"; break; } case OMX_COMMONFLICKERCANCEL_50: { ofLogVerbose(__func__) << "OMX_COMMONFLICKERCANCEL_50"; break; } case OMX_COMMONFLICKERCANCEL_60: { ofLogVerbose(__func__) << "OMX_COMMONFLICKERCANCEL_60"; break; } default: break; } flickerCancelConfig.eFlickerCancel = eFlickerCancel; error = OMX_SetConfig(camera, OMX_IndexConfigCommonFlickerCancellation, &flickerCancelConfig); if(error == OMX_ErrorNone) { if(flickerCancelConfig.eFlickerCancel == OMX_COMMONFLICKERCANCEL_OFF) { flickerCancellation = false; }else { flickerCancellation = true; } }else { //error so assume it's not working flickerCancellation = false; } OMX_TRACE(error); } else { //error so assume it's not working flickerCancellation = false; } return error; }
OMX_ERRORTYPE ofxRPiCameraVideoGrabber::setShutterSpeed(int shutterSpeedMicroSeconds_) { OMX_ERRORTYPE error = OMX_GetConfig(camera, OMX_IndexConfigCommonExposureValue, &exposureConfig); OMX_TRACE(error); exposureConfig.nShutterSpeedMsec = shutterSpeedMicroSeconds_; error = applyExposure(__func__); OMX_TRACE(error); if(error == OMX_ErrorNone) { shutterSpeed = getShutterSpeed(); } ofLogVerbose(__func__) << "POST getShutterSpeed(): " << getShutterSpeed(); return error; }
//Input buffer has been emptied OMX_ERRORTYPE Component::EmptyBufferDoneCallback(OMX_HANDLETYPE hComponent, OMX_PTR pAppData, OMX_BUFFERHEADERTYPE* pBuffer) { OMX_ERRORTYPE error = OMX_ErrorNone; if(!pAppData) { return error; } Component *component = static_cast<Component*>(pAppData); if(component->CustomEmptyBufferDoneHandler) { error = (*(component->CustomEmptyBufferDoneHandler))(hComponent, pAppData, pBuffer); }else { pthread_mutex_lock(&component->m_omx_input_mutex); component->inputBuffersAvailable.push(pBuffer); // this allows (all) blocked tasks to be awoken pthread_cond_broadcast(&component->m_input_buffer_cond); pthread_mutex_unlock(&component->m_omx_input_mutex); } OMX_TRACE(error, component->getName()); return error; }
//output buffer has been filled OMX_ERRORTYPE Component::FillBufferDoneCallback(OMX_HANDLETYPE hComponent, OMX_PTR pAppData, OMX_BUFFERHEADERTYPE* pBuffer) { OMX_ERRORTYPE error = OMX_ErrorNone; if(!pAppData) { return error; } Component* component = static_cast<Component*>(pAppData); if(component->CustomFillBufferDoneHandler) { error = (*(component->CustomFillBufferDoneHandler))(hComponent, pAppData, pBuffer); OMX_TRACE(error); }else { pthread_mutex_lock(&component->m_omx_output_mutex); component->outputBuffersAvailable.push(pBuffer); // this allows (all) blocked tasks to be awoken pthread_cond_broadcast(&component->m_output_buffer_cond); pthread_mutex_unlock(&component->m_omx_output_mutex); sem_post(&component->m_omx_fill_buffer_done); } if (error == OMX_ErrorIncorrectStateOperation) { ofLogError() << component->getName() << " THREW OMX_ErrorIncorrectStateOperation"; } return error; }
OMX_ERRORTYPE ofxRPiCameraVideoGrabber::setSensorCrop(ofRectangle& rectangle) { sensorCropConfig.xLeft = ((uint32_t)rectangle.getLeft() << 16)/100; sensorCropConfig.xTop = ((uint32_t)rectangle.getTop() << 16)/100; sensorCropConfig.xWidth = ((uint32_t)rectangle.getWidth() << 16)/100; sensorCropConfig.xHeight = ((uint32_t)rectangle.getHeight() << 16)/100; OMX_ERRORTYPE error = OMX_SetConfig(camera, OMX_IndexConfigInputCropPercentages, &sensorCropConfig); OMX_TRACE(error); if(error != OMX_ErrorNone) { ofLogError(__func__) << omxErrorToString(error); if(error == OMX_ErrorBadParameter) { ofLogWarning(__func__) << "resetting cropRectangle to known good params (0, 0, 100, 100)"; cropRectangle.set(0, 0, 100, 100); return updateSensorCrop(); } } return error; }
bool Component::tunnelToNull(int port) { bool result = false; OMX_ERRORTYPE error; if(CustomFillBufferDoneHandler) { CustomFillBufferDoneHandler = NULL; } if(setToStateIdle()) { disableAllPorts(); if(getName() != "OMX.broadcom.clock" && getName() != "OMX.broadcom.audio_render" && getName() != "OMX.broadcom.audio_mixer") { error = OMX_SetupTunnel(handle, port, NULL, 0); OMX_TRACE(error); if(error == OMX_ErrorNone) { result = true; } }else { result = true; } } ofLogVerbose(__func__) << getName() << " TUNNELED TO NULL: " << result; return result; }
void VideoDecoderDirect::updateFrameCount() { if (!isOpen) { return; } OMX_ERRORTYPE error; OMX_CONFIG_BRCMPORTSTATSTYPE stats; OMX_INIT_STRUCTURE(stats); stats.nPortIndex = renderComponent.getInputPort(); error = renderComponent.getParameter(OMX_IndexConfigBrcmPortStats, &stats); OMX_TRACE(error); if (error == OMX_ErrorNone) { /*OMX_U32 nImageCount; OMX_U32 nBufferCount; OMX_U32 nFrameCount; OMX_U32 nFrameSkips; OMX_U32 nDiscards; OMX_U32 nEOS; OMX_U32 nMaxFrameSize; OMX_TICKS nByteCount; OMX_TICKS nMaxTimeDelta; OMX_U32 nCorruptMBs;*/ //ofLogVerbose(__func__) << "nFrameCount: " << stats.nFrameCount; frameCounter = stats.nFrameCount; }else { ofLogError(__func__) << "renderComponent OMX_CONFIG_BRCMPORTSTATSTYPE fail: "; } }
bool Component::init( std::string& component_name, OMX_INDEXTYPE index) { componentName = component_name; callbacks.EventHandler = &Component::EventHandlerCallback; callbacks.EmptyBufferDone = &Component::EmptyBufferDoneCallback; callbacks.FillBufferDone = &Component::FillBufferDoneCallback; // Get video component handle setting up callbacks, component is in loaded state on return. OMX_ERRORTYPE error = OMX_GetHandle(&handle, (char*)component_name.c_str(), this, &callbacks); OMX_TRACE(error); if (error != OMX_ErrorNone) { ofLogError(__func__) << componentName << " FAIL "; return false; } OMX_PORT_PARAM_TYPE port_param; OMX_INIT_STRUCTURE(port_param); error = OMX_GetParameter(handle, index, &port_param); OMX_TRACE(error); disableAllPorts(); inputPort = port_param.nStartPortNumber; outputPort = inputPort + 1; if(componentName == "OMX.broadcom.audio_mixer") { inputPort = 232; outputPort = 231; } if (outputPort > port_param.nStartPortNumber+port_param.nPorts-1) { outputPort = port_param.nStartPortNumber+port_param.nPorts-1; } return true; }
OMX_ERRORTYPE Component::disablePort(unsigned int port)//default: wait=false { lock(); #ifdef DEBUG_PORTS ofLogVerbose(__func__) << componentName << " port: " << port; #endif OMX_ERRORTYPE error; error = OMX_SendCommand(handle, OMX_CommandPortDisable, port, NULL); OMX_TRACE(error); unlock(); return error; #if 0 if(error == OMX_ErrorNone) { unlock(); return error; } OMX_PARAM_PORTDEFINITIONTYPE portFormat; OMX_INIT_STRUCTURE(portFormat); portFormat.nPortIndex = port; error = OMX_GetParameter(handle, OMX_IndexParamPortDefinition, &portFormat); OMX_TRACE(error); if(portFormat.bEnabled == OMX_TRUE) { error = OMX_SendCommand(handle, OMX_CommandPortDisable, port, NULL); OMX_TRACE(error); if(error != OMX_ErrorNone) { unlock(); return error; } } unlock(); return error; #endif }
OMX_ERRORTYPE ofxRPiCameraVideoGrabber::setSoftwareSharpening(bool state) { OMX_ERRORTYPE error = OMX_GetConfig(camera, OMX_IndexParamSWSharpenDisable, &disableSoftwareSharpenConfig); OMX_TRACE(error); if(error == OMX_ErrorNone) { disableSoftwareSharpenConfig.bEnabled = toOMXBool(state); error = OMX_SetConfig(camera, OMX_IndexParamSWSharpenDisable, &disableSoftwareSharpenConfig); OMX_TRACE(error); if(error == OMX_ErrorNone) { doDisableSoftwareSharpen = state; ofLogVerbose() << "doDisableSoftwareSharpen: " << doDisableSoftwareSharpen; } } return error; }
void ofxRPiCameraVideoGrabber::applyImageFilter(OMX_IMAGEFILTERTYPE imageFilter) { imagefilterConfig.eImageFilter = imageFilter; OMX_ERRORTYPE error = OMX_SetConfig(camera, OMX_IndexConfigCommonImageFilter, &imagefilterConfig); OMX_TRACE(error); }
OMX_ERRORTYPE ofxRPiCameraVideoGrabber::applyMirror() { OMX_ERRORTYPE error = OMX_SetConfig(camera, OMX_IndexConfigCommonMirror, &mirrorConfig); OMX_TRACE(error); if(error == OMX_ErrorNone) { mirror = GetMirrorString(mirrorConfig.eMirror); } return error; }
OMX_ERRORTYPE Component::sendCommand(OMX_COMMANDTYPE cmd, OMX_U32 cmdParam, OMX_PTR cmdParamData) { lock(); OMX_ERRORTYPE error = OMX_SendCommand(handle, cmd, cmdParam, cmdParamData); OMX_TRACE(error); unlock(); return error; }
OMX_ERRORTYPE ofxRPiCameraVideoGrabber::setAutoISO(bool doAutoISO) { OMX_ERRORTYPE error = OMX_GetConfig(camera, OMX_IndexConfigCommonExposureValue, &exposureConfig); OMX_TRACE(error); if(error == OMX_ErrorNone) { if(doAutoISO) { exposureConfig.bAutoSensitivity = OMX_TRUE; }else { exposureConfig.bAutoSensitivity = OMX_FALSE; } error = applyExposure(__func__); OMX_TRACE(error); } return error; }
OMX_ERRORTYPE Component::setParameter(OMX_INDEXTYPE paramIndex, OMX_PTR paramStruct) { lock(); OMX_ERRORTYPE error = OMX_SetParameter(handle, paramIndex, paramStruct); OMX_TRACE(error); unlock(); return error; }
OMX_ERRORTYPE Component::getConfig(OMX_INDEXTYPE configIndex, OMX_PTR configStruct) { lock(); OMX_ERRORTYPE error = OMX_GetConfig(handle, configIndex, configStruct); OMX_TRACE(error); unlock(); return error; }
OMX_ERRORTYPE Component::freeInputBuffers() { if(!handle) { ofLogError(__func__) << getName() << " NO HANDLE"; return OMX_ErrorNone; } OMX_ERRORTYPE error = OMX_ErrorNone; if(inputBuffers.empty()) { return OMX_ErrorNone; } //m_flush_input = true; pthread_mutex_lock(&m_omx_input_mutex); pthread_cond_broadcast(&m_input_buffer_cond); error = disablePort(inputPort); OMX_TRACE(error); for (size_t i = 0; i < inputBuffers.size(); i++) { error = OMX_FreeBuffer(handle, inputPort, inputBuffers[i]); OMX_TRACE(error); } inputBuffers.clear(); //error = waitForCommand(OMX_CommandPortDisable, inputPort); //OMX_TRACE(error); while (!inputBuffersAvailable.empty()) { inputBuffersAvailable.pop(); } pthread_mutex_unlock(&m_omx_input_mutex); return error; }
OMX_ERRORTYPE Component::useEGLImage(OMX_BUFFERHEADERTYPE** ppBufferHdr, OMX_U32 nPortIndex, OMX_PTR pAppPrivate, void* eglImage) { lock(); OMX_ERRORTYPE error = OMX_UseEGLImage(handle, ppBufferHdr, nPortIndex, pAppPrivate, eglImage); OMX_TRACE(error); unlock(); return error; }
OMX_ERRORTYPE ofxRPiCameraVideoGrabber::applyRotation() { OMX_ERRORTYPE error = OMX_SetConfig(camera, OMX_IndexConfigCommonRotate, &rotationConfig); OMX_TRACE(error); if(error == OMX_ErrorNone) { rotation = getRotation(); } return error; }
void ofxRPiCameraVideoGrabber::setSharpness(int sharpness_) //-100 to 100 { sharpness = sharpness_; OMX_ERRORTYPE error = OMX_ErrorNone; sharpnessConfig.nSharpness = sharpness; error = OMX_SetConfig(camera, OMX_IndexConfigCommonSharpness, &sharpnessConfig); OMX_TRACE(error); }
void ofxRPiCameraVideoGrabber::setContrast(int contrast_ ) //-100 to 100 { contrast = contrast_; OMX_ERRORTYPE error = OMX_ErrorNone; contrastConfig.nContrast = contrast; error = OMX_SetConfig(camera, OMX_IndexConfigCommonContrast, &contrastConfig); OMX_TRACE(error); }
void ofxRPiCameraVideoGrabber::setBurstMode(bool doBurstMode) { OMX_ERRORTYPE error = OMX_GetConfig(camera, OMX_IndexConfigBurstCapture, &burstModeConfig); OMX_TRACE(error); if(doBurstMode) { burstModeConfig.bEnabled = OMX_TRUE; }else { burstModeConfig.bEnabled = OMX_FALSE; } error = OMX_SetConfig(camera, OMX_IndexConfigBurstCapture, &burstModeConfig); OMX_TRACE(error); if(error == OMX_ErrorNone) { burstModeEnabled = doBurstMode; } ofLogVerbose() << "burstModeEnabled: " << burstModeEnabled; }
void ofxRPiCameraVideoGrabber::setBrightness(int brightness_ ) //0 to 100 { brightness = brightness_; OMX_ERRORTYPE error = OMX_ErrorNone; brightnessConfig.nBrightness = brightness; error = OMX_SetConfig(camera, OMX_IndexConfigCommonBrightness, &brightnessConfig); OMX_TRACE(error); }
void ofxRPiCameraVideoGrabber::setSaturation(int saturation_) //-100 to 100 { saturation = saturation_; OMX_ERRORTYPE error = OMX_ErrorNone; saturationConfig.nSaturation = saturation_; error = OMX_SetConfig(camera, OMX_IndexConfigCommonSaturation, &saturationConfig); OMX_TRACE(error); }
OMX_ERRORTYPE ofxRPiCameraVideoGrabber::setColorEnhancement(bool doColorEnhance, int U, int V) { colorEnhancementConfig.bColorEnhancement = toOMXBool(doColorEnhance); colorEnhancementConfig.nCustomizedU = U; colorEnhancementConfig.nCustomizedV = V; OMX_ERRORTYPE error = OMX_SetConfig(camera, OMX_IndexConfigCommonColorEnhancement, &colorEnhancementConfig); OMX_TRACE(error); return error; }
OMX_ERRORTYPE ofxRPiCameraVideoGrabber::setWhiteBalance(OMX_WHITEBALCONTROLTYPE whiteBalance_) { whiteBalanceConfig.eWhiteBalControl = whiteBalance_; OMX_ERRORTYPE error = OMX_SetConfig(camera, OMX_IndexConfigCommonWhiteBalance, &whiteBalanceConfig); OMX_TRACE(error); if(error == OMX_ErrorNone) { whiteBalance = whiteBalance_; } return error; }
OMX_STATETYPE Component::getState() { lock(); OMX_STATETYPE state; OMX_ERRORTYPE error = OMX_GetState(handle, &state); OMX_TRACE(error); unlock(); return state; }
OMX_ERRORTYPE ofxRPiCameraVideoGrabber::setImageFilter(OMX_IMAGEFILTERTYPE imageFilter_) { imagefilterConfig.eImageFilter = imageFilter_; OMX_ERRORTYPE error = OMX_SetConfig(camera, OMX_IndexConfigCommonImageFilter, &imagefilterConfig); OMX_TRACE(error); if(error == OMX_ErrorNone) { imageFilter = GetImageFilterString(imageFilter_); } return error; }
OMX_ERRORTYPE ofxRPiCameraVideoGrabber::setExposurePreset(OMX_EXPOSURECONTROLTYPE exposurePreset_) { exposurePresetConfig.eExposureControl = exposurePreset_; OMX_ERRORTYPE error = OMX_SetConfig(camera, OMX_IndexConfigCommonExposure, &exposurePresetConfig); OMX_TRACE(error); if(error == OMX_ErrorNone) { exposurePreset = GetExposurePresetString(exposurePreset_); } return error; }