status_t JordanCameraWrapper::setParameters(const CameraParameters& params) { CameraParameters pars(params.flatten()); int width, height; char buf[10]; bool isWide; /* * getInt returns -1 if the value isn't present and 0 on parse failure, * so if it's larger than 0, we can be sure the value was parsed properly */ mVideoMode = pars.getInt("cam-mode") > 0; pars.remove("cam-mode"); pars.getPreviewSize(&width, &height); isWide = width == 848 && height == 480; if (isWide && !mVideoMode) { pars.setPreviewFrameRate(24); } if (mCameraType == CAM_BAYER && mVideoMode) { pars.setPreviewFrameRate(24); } if (mCameraType == CAM_SOC) { /* * libsoccamera fails to turn flash on if 16:9 recording is enabled (no matter * whether it's photo or video recording), thus we do it ourselves in that case. * Luckily libsoccamera handles the automatic flash properly also in the 16:9 case. */ const char *flashMode = pars.get(CameraParameters::KEY_FLASH_MODE); if (flashMode != NULL) { if (isWide && mLastFlashMode != flashMode) { bool shouldBeOn = strcmp(flashMode, CameraParameters::FLASH_MODE_TORCH) == 0 || strcmp(flashMode, CameraParameters::FLASH_MODE_ON) == 0; setSocTorchMode(shouldBeOn); } mLastFlashMode = flashMode; } } float exposure = pars.getFloat(CameraParameters::KEY_EXPOSURE_COMPENSATION); /* exposure-compensation comes multiplied in the -9...9 range, while we need it in the -3...3 range -> adjust for that */ exposure /= 3; /* format the setting in a way the lib understands */ bool even = (exposure - round(exposure)) < 0.05; snprintf(buf, sizeof(buf), even ? "%.0f" : "%.2f", exposure); pars.set("mot-exposure-offset", buf); /* kill off the original setting */ pars.set(CameraParameters::KEY_EXPOSURE_COMPENSATION, "0"); return mMotoInterface->setParameters(pars); }
int GonkCameraHardware::PushParameters(const CameraParameters& aParams) { if (NS_WARN_IF(mClosing)) { return DEAD_OBJECT; } String8 s = aParams.flatten(); return mCamera->setParameters(s); }
/** Return the camera parameters. */ char *HAL_camera_device_get_parameters(struct camera_device *dev) { ExynosCameraAutoTimer autoTimer(__func__); ALOGV("DEBUG(%s):", __func__); String8 str; CameraParameters parms = obj(dev)->getParameters(); str = parms.flatten(); return strdup(str.string()); }
int TestGonkCameraHardware::PushParameters(const CameraParameters& aParams) { DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__); String8 s = aParams.flatten(); nsresult rv = WaitWhileRunningOnMainThread(new PushParametersDelegate(this, &s)); if (NS_WARN_IF(NS_FAILED(rv))) { return UNKNOWN_ERROR; } return OK; }
/** * Set a camera parameter */ int CaptureCommand::capture_setParameter(Value& name, Value& value) { LOG_ERROR((name.isNull()), "name not specified"); LOG_ERROR((value.isNull()), "value not specified"); LOG_ERROR((mCamera.get() == NULL), "camera not initialized"); CameraParameters params = mCamera->getParameters(); params.set(name.asCString(), value.asCString()); status_t err = mCamera->setParameters(params.flatten()); if (err != ::OK) { ALOGW("Error %d: Failed to set '%s' to '%s'", err, name.asCString(), value.asCString()); } return 0; }
status_t LibCameraWrapper::setParameters(const CameraParameters& params) { CameraParameters pars(params.flatten()); const char *flashMode = pars.get(CameraParameters::KEY_FLASH_MODE); if (flashMode != NULL) { if (mLastFlashMode != flashMode) { bool shouldBeOn = strcmp(flashMode, CameraParameters::FLASH_MODE_TORCH) == 0 || strcmp(flashMode, CameraParameters::FLASH_MODE_ON) == 0; setSocTorchMode(shouldBeOn); } mLastFlashMode = flashMode; } return mLibInterface->setParameters(pars); }
status_t ParamsManager:: setParameters(CameraParameters const& params) { IParamsManager::showParameters(params.flatten()); // status_t status = OK; bool bIsSceneChanged = false; Size oldPrvSize, tmpPrvSize, newPrvSize; Size oldPicSize, newPicSize; // // (1) Check to see if new parameters are valid or not. if ( OK != (status = checkParams(params)) ) { MY_LOGE("checkParams() return %d", status); return status; } // (2) Check to see if Scene Changes or not. MY_LOGD("%d: +", getOpenId()); RWLock::AutoWLock _lock(mRWLock); MY_LOGD("AutoWLock"); // char const*const pOldScene = mParameters.get(CameraParameters::KEY_SCENE_MODE); char const*const pNewScene = params.get(CameraParameters::KEY_SCENE_MODE); if ( 0 != ::strcmp(pOldScene, pNewScene) ) { // scene mode has changed MY_LOGD("Scene change: %s -> %s", pOldScene, pNewScene); bIsSceneChanged = true; } // // (3.1) Check to see if Preview Size Changes or not. Get old preview size mParameters.getPreviewSize(&oldPrvSize.width, &oldPrvSize.height); params.getPreviewSize(&tmpPrvSize.width, &tmpPrvSize.height); // (3.2) Get old&new picture size mParameters.getPictureSize(&oldPicSize.width, &oldPicSize.height); params.getPictureSize(&newPicSize.width, &newPicSize.height); // (4) Update Parameter mParameters = params; if ( bIsSceneChanged ) { if ( ! updateSceneAndParams() ) { status = BAD_VALUE; } } // (5) Update Parameter: preview size updatePreviewSize(); // (6) Update FOV according to picture size MY_LOGI("picSZ(%d,%d)->(%d,%d)",oldPicSize.width,oldPicSize.height,newPicSize.width,newPicSize.height); if(oldPicSize.width != newPicSize.width || oldPicSize.height != newPicSize.height) { updateFov(newPicSize); } // (3.2) Check to see if Preview Size Changes or not. Get new preview size mParameters.getPreviewSize(&newPrvSize.width, &newPrvSize.height); if ( oldPrvSize.width != newPrvSize.width || oldPrvSize.height != newPrvSize.height ) { MY_LOGD( "Preview Size change: %dx%d/%dx%d -> (%dx%d)", oldPrvSize.width, oldPrvSize.height, tmpPrvSize.width, tmpPrvSize.height, newPrvSize.width, newPrvSize.height ); } // MY_LOGD("-"); return status; }
int GonkCameraHardware::PushParameters(const CameraParameters& aParams) { String8 s = aParams.flatten(); return mCamera->setParameters(s); }
status_t MotoCameraWrapper::setParameters(const CameraParameters& params) { CameraParameters pars(params.flatten()); String8 oldFlashMode = mFlashMode; String8 sceneMode; status_t retval; int width, height; char buf[10]; bool isWide; /* * getInt returns -1 if the value isn't present and 0 on parse failure, * so if it's larger than 0, we can be sure the value was parsed properly */ mVideoMode = pars.getInt("cam-mode") > 0; pars.remove("cam-mode"); pars.getPreviewSize(&width, &height); isWide = width == 848 && height == 480; if (isWide && !mVideoMode) pars.setPreviewFrameRate(24); if (mCameraType == DEFY_RED && mVideoMode) pars.setPreviewFrameRate(24); sceneMode = pars.get(CameraParameters::KEY_SCENE_MODE); if (sceneMode != CameraParameters::SCENE_MODE_AUTO) { /* The lib doesn't seem to update the flash mode correctly when a scene * mode is set, so we need to do it here. Also do focus mode, just do * be on the safe side. */ pars.set(CameraParameters::KEY_FOCUS_MODE, CameraParameters::FOCUS_MODE_AUTO); if (sceneMode == CameraParameters::SCENE_MODE_PORTRAIT || sceneMode == CameraParameters::SCENE_MODE_NIGHT_PORTRAIT) { pars.set(CameraParameters::KEY_FLASH_MODE, CameraParameters::FLASH_MODE_AUTO); } else { pars.set(CameraParameters::KEY_FLASH_MODE, CameraParameters::FLASH_MODE_OFF); } } mFlashMode = pars.get(CameraParameters::KEY_FLASH_MODE); float exposure = pars.getFloat(CameraParameters::KEY_EXPOSURE_COMPENSATION); /* Exposure-compensation comes multiplied in the -9...9 range, while * we need it in the -3...3 range -> adjust for that */ exposure /= 3; /* format the setting in a way the lib understands */ bool even = (exposure - round(exposure)) < 0.05; snprintf(buf, sizeof(buf), even ? "%.0f" : "%.2f", exposure); pars.set("mot-exposure-offset", buf); /* kill off the original setting */ pars.set(CameraParameters::KEY_EXPOSURE_COMPENSATION, "0"); retval = mMotoInterface->setParameters(pars); if (oldFlashMode != mFlashMode) { toggleTorchIfNeeded(); } return retval; }
/** * Thread function that initializes the camera */ status_t CaptureCommand::initThreadCamera() { // Setup the camera int cameraId = 0; mCamera = Camera::connect(cameraId, String16(CAMERA_NAME), Camera::USE_CALLING_UID); if (mCamera == NULL) { ALOGE("Unable to connect to camera"); return -1; } mRemote = mCamera->remote(); FaceDetection faces(&mChannel); mCamera->setListener(&faces); { char previewSize[80]; snprintf(previewSize, sizeof(previewSize), "%dx%d", sVideoSize.width, sVideoSize.height); CameraParameters params = mCamera->getParameters(); params.set(CameraParameters::KEY_PREVIEW_SIZE, previewSize); params.set(CameraParameters::KEY_PREVIEW_FORMAT, "yuv420sp"); status_t err = mCamera->setParameters(params.flatten()); CHECK(err == 0); params = mCamera->getParameters(); params.dump(); } sOpenCVCameraCapture->setPreviewProducerListener(this); CHECK(setPreviewTarget() == 0); //CHECK(mCamera->sendCommand(CAMERA_CMD_START_FACE_DETECTION, CAMERA_FACE_DETECTION_SW, 0) == 0); CHECK(mCamera->sendCommand(CAMERA_CMD_ENABLE_FOCUS_MOVE_MSG, 1, 0) == 0); mCameraSource = CameraSource::CreateFromCamera(mRemote, mCamera->getRecordingProxy(), cameraId, String16(CAMERA_NAME, strlen(CAMERA_NAME)), Camera::USE_CALLING_UID, sVideoSize, sFPS, NULL, sUseMetaDataMode); CHECK_EQ(mCameraSource->initCheck(), ::OK); if (sInitCameraVideo) { mLooper = new ALooper; mLooper->setName("capture-looper"); mLooper->start(); sp<MediaSource> videoEncoder = prepareVideoEncoder(mLooper, mCameraSource); sp<MediaSource> audioSource( new AudioSource( AUDIO_SOURCE_MIC, #ifdef TARGET_GE_MARSHMALLOW String16("silk-capture"), #endif sAudioSampleRate, sAudioChannels ) ); sp<MediaSource> audioSourceEmitter = new AudioSourceEmitter(&mChannel, audioSource); sp<MediaSource> audioMutter = new AudioMutter(audioSourceEmitter); sp<MediaSource> audioEncoder = prepareAudioEncoder(mLooper, audioMutter); mSegmenter = new MPEG4SegmenterDASH(videoEncoder, audioEncoder, &mChannel); mSegmenter->run(); mHardwareActive = true; notifyCameraEvent("initialized"); // Block this thread while camera is running mSegmenter->join(); } else { pthread_create(&mAudioThread, NULL, initThreadAudioOnlyWrapper, this); CHECK_EQ(mCameraSource->start(), ::OK); MediaSourceNullPuller cameraPuller(mCameraSource, "camera"); if (!cameraPuller.loop()) { notifyCameraEvent("error"); } } sOpenCVCameraCapture->setPreviewProducerListener(NULL); return 0; }
/*! \return 0 on success, otherwise error code */ int camera_open(void) { LOGE("%s",__FUNCTION__); CameraParameters params; status_t rtn; /* Open video device */ #ifdef CAMERA_FOR_SCANNER //pCamera = CameraScanner::connect(0); #ifdef CAMERA_FOR_SCANNER fd = open("/sys/devices/platform/image_sensor/currDrvIndex",O_RDWR); if(fd<0) { LOGE("Cannot open currDrvIndex\n"); return -1; } int temp = 20002; write(fd,"20002",5); fd_scanner1 = open(SE955_CHANNEL_NAME, O_RDONLY); #endif pCamera = Camera::connect(1); #else pCamera = CameraScanner::connect(ANDROID_CAMERA_ID); //pCamera = CameraScanner::connect(0); #endif if( pCamera == 0) { LOGE("Cannot connect to camera %d of: %i, %s\n", ANDROID_CAMERA_ID, errno, strerror(errno)); return -errno; } LOGE("Camera %d \n", ANDROID_CAMERA_ID); #ifdef CAMERA_FOR_SCANNER pCamera->setListener(&scannerListener); //enable data callback #else pCamera->setScannerListener(&scannerListener); //enable data callback #endif #ifdef VIDEO_SUBDEV /* Open subdevice */ video_subdev_handle = ::open(VIDEO_SUBDEV, O_RDWR); if (video_subdev_handle == -1) { LOGE("ERROR opening %s: %d\n", VIDEO_SUBDEV, errno); return -errno; } LOGE("Subdevice: %s, handle = %d\n", VIDEO_SUBDEV, video_subdev_handle); #endif ImagerProps.width = 256; ImagerProps.height = 64; #ifdef CAMERA_FOR_SCANNER //ImagerProps.width = 624; //ImagerProps.height = 474; ImagerProps.width = 640; ImagerProps.height = 480; ImagerProps.mount = 2; ImagerProps.i2c_addr_sensor = 0x48; ImagerProps.i2c_addr_psoc = 0x40; ImagerProps.i2c_addr_clock = 0x69; #else if( 0 != camera_ioctl(HSM_GET_PROPERTIES, &ImagerProps) ) { pCamera->disconnect(); LOGE("HSM_GET_PROPERTIES error %d\n", errno); return -1; } #endif #ifdef CAMERA_FOR_SCANNER #else LOGE("Image size = %dx%d\n", ImagerProps.width, ImagerProps.height); #endif cbBufLength = ImagerProps.height * ImagerProps.width; params.unflatten(pCamera->getParameters()); params.set("mtk-cam-mode", 1); #if 0 //def CAMERA_FOR_SCANNER #else params.set("scanner-mode", "on"); #endif params.setPreviewSize(ImagerProps.width, ImagerProps.height); //params.setPreviewFormat("yuv422i-yuyv"); // FIXME: "raw" //params.setPreviewFormat("yuv420sp"); // FIXME: "raw" rtn = pCamera->setParameters(params.flatten()); if( rtn != OK ) { LOGE("setParameters error %d\n", rtn); } #ifdef CAMERA_FOR_SCANNER if(fd>=0)write(fd,"20001",5); #endif #if 0 rtn = pCamera->setPreviewTexture(dummy_texture); // FIXME: Is there a dummy texture? if( rtn != OK ) { KIL_ERR("setPreviewDisplay error %d\n", rtn); } #endif return 0; }
void CameraHandler::setProperty(int propIdx, double value) { LOGD("CameraHandler::setProperty(%d, %f)", propIdx, value); android::String8 params_str; params_str = camera->getParameters(); LOGI("Params before set: [%s]", params_str.string()); switch (propIdx) { case ANDROID_CAMERA_PROPERTY_FRAMEWIDTH: { int w,h; params->getPreviewSize(&w, &h); width = (int)value; } break; case ANDROID_CAMERA_PROPERTY_FRAMEHEIGHT: { int w,h; params->getPreviewSize(&w, &h); height = (int)value; } break; case ANDROID_CAMERA_PROPERTY_EXPOSURE: { int max_exposure = params->getInt("max-exposure-compensation"); int min_exposure = params->getInt("min-exposure-compensation"); if(max_exposure && min_exposure) { int exposure = (int)value; if(exposure >= min_exposure && exposure <= max_exposure) params->set("exposure-compensation", exposure); else LOGE("Exposure compensation not in valid range (%i,%i).", min_exposure, max_exposure); } else LOGE("Exposure compensation adjust is not supported."); camera->setParameters(params->flatten()); } break; case ANDROID_CAMERA_PROPERTY_FLASH_MODE: { int new_val = (int)value; if(new_val >= 0 && new_val < ANDROID_CAMERA_FLASH_MODES_NUM) { const char* mode_name = flashModesNames[new_val]; if(is_supported(CameraParameters::KEY_SUPPORTED_FLASH_MODES, mode_name)) params->set(CameraParameters::KEY_FLASH_MODE, mode_name); else LOGE("Flash mode %s is not supported.", mode_name); } else LOGE("Flash mode value not in valid range."); camera->setParameters(params->flatten()); } break; case ANDROID_CAMERA_PROPERTY_FOCUS_MODE: { int new_val = (int)value; if(new_val >= 0 && new_val < ANDROID_CAMERA_FOCUS_MODES_NUM) { const char* mode_name = focusModesNames[new_val]; if(is_supported(CameraParameters::KEY_SUPPORTED_FOCUS_MODES, mode_name)) params->set(CameraParameters::KEY_FOCUS_MODE, mode_name); else LOGE("Focus mode %s is not supported.", mode_name); } else LOGE("Focus mode value not in valid range."); camera->setParameters(params->flatten()); } break; case ANDROID_CAMERA_PROPERTY_WHITE_BALANCE: { int new_val = (int)value; if(new_val >= 0 && new_val < ANDROID_CAMERA_WHITE_BALANCE_MODES_NUM) { const char* mode_name = whiteBalanceModesNames[new_val]; if(is_supported(CameraParameters::KEY_SUPPORTED_WHITE_BALANCE, mode_name)) params->set(CameraParameters::KEY_WHITE_BALANCE, mode_name); else LOGE("White balance mode %s is not supported.", mode_name); } else LOGE("White balance mode value not in valid range."); camera->setParameters(params->flatten()); } break; case ANDROID_CAMERA_PROPERTY_ANTIBANDING: { int new_val = (int)value; if(new_val >= 0 && new_val < ANDROID_CAMERA_ANTIBANDING_MODES_NUM) { const char* mode_name = antibandingModesNames[new_val]; if(is_supported(CameraParameters::KEY_SUPPORTED_ANTIBANDING, mode_name)) params->set(CameraParameters::KEY_ANTIBANDING, mode_name); else LOGE("Antibanding mode %s is not supported.", mode_name); } else LOGE("Antibanding mode value not in valid range."); camera->setParameters(params->flatten()); } break; #if !defined(ANDROID_r2_2_0) && !defined(ANDROID_r2_3_3) && !defined(ANDROID_r3_0_1) case ANDROID_CAMERA_PROPERTY_EXPOSE_LOCK: { if (is_supported(CameraParameters::KEY_AUTO_EXPOSURE_LOCK_SUPPORTED, "true")) { if (value != 0) params->set(CameraParameters::KEY_AUTO_EXPOSURE_LOCK, CameraParameters::TRUE); else params->set(CameraParameters::KEY_AUTO_EXPOSURE_LOCK, CameraParameters::FALSE); LOGE("Expose lock is set"); } else LOGE("Expose lock is not supported"); camera->setParameters(params->flatten()); } break; case ANDROID_CAMERA_PROPERTY_WHITEBALANCE_LOCK: { if (is_supported(CameraParameters::KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED, "true")) { if (value != 0) params->set(CameraParameters::KEY_AUTO_WHITEBALANCE_LOCK, CameraParameters::TRUE); else params->set(CameraParameters::KEY_AUTO_WHITEBALANCE_LOCK, CameraParameters::FALSE); LOGE("White balance lock is set"); } else LOGE("White balance lock is not supported"); camera->setParameters(params->flatten()); } break; #endif default: LOGW("CameraHandler::setProperty - Unsupported property."); }; params_str = camera->getParameters(); LOGI("Params after set: [%s]", params_str.string()); }
void mergepara( camera_device_t *pdev, String8 &argstr) { char * tmp = pdev->ops->get_parameters(pdev); CameraParameters def = CameraParameters(String8(tmp)); char *a; char *b; pdev->ops->put_parameters(pdev,tmp); #if PRINTF_CONFIG CMR_LOGI("old config =>\n"); a= const_cast < char *> ( def.flatten().string()); for (;;) { b = strchr(a, ';'); if (b == 0) { // If there's no semicolon, this is the last item. String8 v(a); CMR_LOGI("%s",v.string()); break; } else { String8 v(a, (size_t)(b-a)); CMR_LOGI("%s",v.string()); a = b+1; } } CMR_LOGI("old config end\n"); #endif //a =const_cast < char *> (add.flatten().string()); a = (char *) argstr.string(); CMR_LOGI("new str: %s\n",a); for (;;) { // Find the bounds of the key name. b = strchr(a, '='); if (b == 0) break; // Create the key string. String8 k(a, (size_t)(b-a)); // Find the value. a = b+1; b = strchr(a, ','); if (b == 0) { // If there's no semicolon, this is the last item. // String8 v(a, strlen(a)); CMR_LOGI("k=%s,v=%s",k.string(), a); def.set( k.string(), a); break; } else { String8 v(a, (size_t)(b-a)); CMR_LOGI("k=%s,v=%s",k.string(), v.string()); def.set( k.string(), v.string()); a = b+1; } } #if PRINTF_CONFIG CMR_LOGI("new config =>\n"); a=const_cast < char *> ( def.flatten().string()); for (;;) { b = strchr(a, ';'); if (b == 0) { // If there's no semicolon, this is the last item. String8 v(a); CMR_LOGI("%s",v.string()); break; } else { String8 v(a, (size_t)(b-a)); CMR_LOGI("%s",v.string()); a = b+1; } } CMR_LOGI("new config end\n"); #endif pdev->ops->set_parameters(pdev,def.flatten().string()); if(opts.workmode == WK_TAKEPIC) { opts.pic_cnt = def.getInt("capture-mode"); CMR_LOGW("WK_TAKEPIC:opts.pic_cnt = %d\n",opts.pic_cnt); } }