status_t CameraHardware::setParameters(const CameraParameters& params) { Mutex::Autolock lock(mLock); int width = 0; int height = 0; int framerate = 0; params.getPreviewSize(&width,&height); LOGD("Set Parameter...!! "); LOGD("PreviewFormat %s", params.getPreviewFormat()); if ( params.getPreviewFormat() != NULL ) { if (strcmp(params.getPreviewFormat(), (const char *) CameraParameters::PIXEL_FORMAT_YUV422SP) != 0) { LOGE("Only yuv422sp preview is supported"); return -EINVAL; } } LOGD("PictureFormat %s", params.getPictureFormat()); if ( params.getPictureFormat() != NULL ) { if (strcmp(params.getPictureFormat(), (const char *) CameraParameters::PIXEL_FORMAT_JPEG) != 0) { LOGE("Only jpeg still pictures are supported"); return -EINVAL; } } /* validate preview size */ params.getPreviewSize(&width, &height); LOGD("preview width:%d,height:%d",width,height); if ( validateSize(width, height, supportedPreviewRes, ARRAY_SIZE(supportedPreviewRes)) == false ) { LOGE("Preview size not supported"); return -EINVAL; } /* validate picture size */ params.getPictureSize(&width, &height); LOGD("picture width:%d,height:%d",width,height); if (validateSize(width, height, supportedPictureRes, ARRAY_SIZE(supportedPictureRes)) == false ) { LOGE("Picture size not supported"); return -EINVAL; } framerate = params.getPreviewFrameRate(); LOGD("FRAMERATE %d", framerate); mParameters = params; mParameters.getPictureSize(&width, &height); LOGD("Picture Size by CamHAL %d x %d", width, height); mParameters.getPreviewSize(&width, &height); LOGD("Preview Resolution by CamHAL %d x %d", width, height); return NO_ERROR; }
double CameraHandler::getProperty(int propIdx) { LOGD("CameraHandler::getProperty(%d)", propIdx); switch (propIdx) { case ANDROID_CAMERA_PROPERTY_FRAMEWIDTH: { int w,h; params.getPreviewSize(&w, &h); return w; } case ANDROID_CAMERA_PROPERTY_FRAMEHEIGHT: { int w,h; params.getPreviewSize(&w, &h); return h; } case ANDROID_CAMERA_PROPERTY_SUPPORTED_PREVIEW_SIZES_STRING: { cameraPropertySupportedPreviewSizesString = params.get(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES); union {const char* str;double res;} u; memset(&u.res, 0, sizeof(u.res)); u.str = cameraPropertySupportedPreviewSizesString.c_str(); return u.res; } case ANDROID_CAMERA_PROPERTY_PREVIEW_FORMAT_STRING: { const char* fmt = params.get(CameraParameters::KEY_PREVIEW_FORMAT); if (fmt == CameraParameters::PIXEL_FORMAT_YUV422SP) fmt = "yuv422sp"; else if (fmt == CameraParameters::PIXEL_FORMAT_YUV420SP) fmt = "yuv420sp"; else if (fmt == CameraParameters::PIXEL_FORMAT_YUV422I) fmt = "yuv422i"; else if (fmt == CameraParameters::PIXEL_FORMAT_RGB565) fmt = "rgb565"; else if (fmt == CameraParameters::PIXEL_FORMAT_JPEG) fmt = "jpeg"; cameraPropertyPreviewFormatString = fmt; union {const char* str;double res;} u; memset(&u.res, 0, sizeof(u.res)); u.str = cameraPropertyPreviewFormatString.c_str(); return u.res; } }; return -1; }
void CameraHandler::setProperty(int propIdx, double value) { LOGD("CameraHandler::setProperty(%d, %f)", propIdx, value); switch (propIdx) { case ANDROID_CAMERA_PROPERTY_FRAMEWIDTH: { int w,h; params.getPreviewSize(&w, &h); w = (int)value; params.setPreviewSize(w, h); } break; case ANDROID_CAMERA_PROPERTY_FRAMEHEIGHT: { int w,h; params.getPreviewSize(&w, &h); h = (int)value; params.setPreviewSize(w, h); } break; }; }
/* * Check whether the requested video frame size * has been successfully configured or not. If both width and height * are -1, check on the current width and height value setting * is performed. * * @param params CameraParameters to retrieve the information * @param the target video frame width in pixels to check against * @param the target video frame height in pixels to check against * @return OK if no error */ status_t CameraSource::checkVideoSize( const CameraParameters& params, int32_t width, int32_t height) { ALOGV("checkVideoSize"); // The actual video size is the same as the preview size // if the camera hal does not support separate video and // preview output. In this case, we retrieve the video // size from preview. int32_t frameWidthActual = -1; int32_t frameHeightActual = -1; Vector<Size> sizes; params.getSupportedVideoSizes(sizes); if (sizes.size() == 0) { // video size is the same as preview size params.getPreviewSize(&frameWidthActual, &frameHeightActual); } else { // video size may not be the same as preview params.getVideoSize(&frameWidthActual, &frameHeightActual); } if (frameWidthActual < 0 || frameHeightActual < 0) { ALOGE("Failed to retrieve video frame size (%dx%d)", frameWidthActual, frameHeightActual); return UNKNOWN_ERROR; } // Check the actual video frame size against the target/requested // video frame size. if (width != -1 && height != -1) { if (frameWidthActual != width || frameHeightActual != height) { ALOGE("Failed to set video frame size to %dx%d. " "The actual video size is %dx%d ", width, height, frameWidthActual, frameHeightActual); return UNKNOWN_ERROR; } } // Good now. mVideoSize.width = frameWidthActual; mVideoSize.height = frameHeightActual; return OK; }
status_t V4LCameraAdapter::setParameters(const CameraParameters ¶ms) { LOG_FUNCTION_NAME; status_t ret = NO_ERROR; int width, height; params.getPreviewSize(&width, &height); LOGINFO("Width * Height %d x %d format 0x%x", width, height, DEFAULT_PIXEL_FORMAT); mVideoInfo->width = width; mVideoInfo->height = height; mVideoInfo->framesizeIn = (width * height << 1); mVideoInfo->formatIn = DEFAULT_PIXEL_FORMAT; mVideoInfo->format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; mVideoInfo->format.fmt.pix.width = width; mVideoInfo->format.fmt.pix.height = height; mVideoInfo->format.fmt.pix.pixelformat = DEFAULT_PIXEL_FORMAT; ret = ioctl(mCameraHandle, VIDIOC_S_FMT, &mVideoInfo->format); if (ret < 0) { LOGINFO("Open: VIDIOC_S_FMT Failed: %s", strerror(errno)); return ret; } // Allocate memory for frame buffer mFrameBuffer = (char *)calloc(1, width * height * 2); // Udpate the current parameter set mParams = params; LOG_FUNCTION_NAME_EXIT; return ret; }
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; }
void CameraHandler::setProperty(int propIdx, double value) { LOGD("CameraHandler::setProperty(%d, %f)", propIdx, value); switch (propIdx) { case ANDROID_CAMERA_PROPERTY_FRAMEWIDTH: { int w,h; params.getPreviewSize(&w, &h); w = (int)value; params.setPreviewSize(w, h); } break; case ANDROID_CAMERA_PROPERTY_FRAMEHEIGHT: { int w,h; params.getPreviewSize(&w, &h); h = (int)value; params.setPreviewSize(w, h); } 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."); } } 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."); } } 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."); } } 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."); } } 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."); } } break; default: LOGW("CameraHandler::setProperty - Unsupported property."); }; }
double CameraHandler::getProperty(int propIdx) { LOGD("CameraHandler::getProperty(%d)", propIdx); switch (propIdx) { case ANDROID_CAMERA_PROPERTY_FRAMEWIDTH: { int w,h; params.getPreviewSize(&w, &h); return w; } case ANDROID_CAMERA_PROPERTY_FRAMEHEIGHT: { int w,h; params.getPreviewSize(&w, &h); return h; } case ANDROID_CAMERA_PROPERTY_SUPPORTED_PREVIEW_SIZES_STRING: { cameraPropertySupportedPreviewSizesString = params.get(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES); union {const char* str;double res;} u; memset(&u.res, 0, sizeof(u.res)); u.str = cameraPropertySupportedPreviewSizesString.c_str(); return u.res; } case ANDROID_CAMERA_PROPERTY_PREVIEW_FORMAT_STRING: { const char* fmt = params.get(CameraParameters::KEY_PREVIEW_FORMAT); if (fmt == CameraParameters::PIXEL_FORMAT_YUV422SP) fmt = "yuv422sp"; else if (fmt == CameraParameters::PIXEL_FORMAT_YUV420SP) fmt = "yuv420sp"; else if (fmt == CameraParameters::PIXEL_FORMAT_YUV422I) fmt = "yuv422i"; else if (fmt == CameraParameters::PIXEL_FORMAT_RGB565) fmt = "rgb565"; else if (fmt == CameraParameters::PIXEL_FORMAT_JPEG) fmt = "jpeg"; cameraPropertyPreviewFormatString = fmt; union {const char* str;double res;} u; memset(&u.res, 0, sizeof(u.res)); u.str = cameraPropertyPreviewFormatString.c_str(); return u.res; } case ANDROID_CAMERA_PROPERTY_EXPOSURE: { int exposure = params.getInt(CameraParameters::KEY_EXPOSURE_COMPENSATION); return exposure; } case ANDROID_CAMERA_PROPERTY_FPS: { return params.getPreviewFrameRate(); } case ANDROID_CAMERA_PROPERTY_FLASH_MODE: { int flash_mode = getModeNum(CameraHandler::flashModesNames, ANDROID_CAMERA_FLASH_MODES_NUM, params.get(CameraParameters::KEY_FLASH_MODE)); return flash_mode; } case ANDROID_CAMERA_PROPERTY_FOCUS_MODE: { int focus_mode = getModeNum(CameraHandler::focusModesNames, ANDROID_CAMERA_FOCUS_MODES_NUM, params.get(CameraParameters::KEY_FOCUS_MODE)); return focus_mode; } case ANDROID_CAMERA_PROPERTY_WHITE_BALANCE: { int white_balance = getModeNum(CameraHandler::whiteBalanceModesNames, ANDROID_CAMERA_WHITE_BALANCE_MODES_NUM, params.get(CameraParameters::KEY_WHITE_BALANCE)); return white_balance; } case ANDROID_CAMERA_PROPERTY_ANTIBANDING: { int antibanding = getModeNum(CameraHandler::antibandingModesNames, ANDROID_CAMERA_ANTIBANDING_MODES_NUM, params.get(CameraParameters::KEY_ANTIBANDING)); return antibanding; } case ANDROID_CAMERA_PROPERTY_FOCAL_LENGTH: { float focal_length = params.getFloat(CameraParameters::KEY_FOCAL_LENGTH); return focal_length; } case ANDROID_CAMERA_PROPERTY_FOCUS_DISTANCE_NEAR: { return getFocusDistance(ANDROID_CAMERA_FOCUS_DISTANCE_NEAR_INDEX); } case ANDROID_CAMERA_PROPERTY_FOCUS_DISTANCE_OPTIMAL: { return getFocusDistance(ANDROID_CAMERA_FOCUS_DISTANCE_OPTIMAL_INDEX); } case ANDROID_CAMERA_PROPERTY_FOCUS_DISTANCE_FAR: { return getFocusDistance(ANDROID_CAMERA_FOCUS_DISTANCE_FAR_INDEX); } default: LOGW("CameraHandler::getProperty - Unsupported property."); }; return -1; }
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()); }
status_t TVINDevice::setParameters(CameraParameters& params) { int w, h; int framerate, local_framerate; int max_zoom, zoom, max_fps, min_fps; char tmp[128]; Mutex::Autolock lock(mLock); max_zoom = params.getInt(CameraParameters::KEY_MAX_ZOOM); zoom = params.getInt(CameraParameters::KEY_ZOOM); if (zoom > max_zoom) { FLOGE("Invalid zoom setting, zoom %d, max zoom %d", zoom, max_zoom); return BAD_VALUE; } if (!((strcmp(params.getPreviewFormat(), "yuv420sp") == 0) || (strcmp(params.getPreviewFormat(), "yuv420p") == 0) || (strcmp(params.getPreviewFormat(), "yuv422i-yuyv") == 0))) { FLOGE("Only yuv420sp or yuv420pis supported, but input format is %s", params.getPreviewFormat()); return BAD_VALUE; } if (strcmp(params.getPictureFormat(), "jpeg") != 0) { FLOGE("Only jpeg still pictures are supported"); return BAD_VALUE; } params.getPreviewSize(&w, &h); sprintf(tmp, "%dx%d", w, h); FLOGI("Set preview size: %s", tmp); if (strstr(mSupportedPreviewSizes, tmp) == NULL) { FLOGE("The preview size w %d, h %d is not corrected", w, h); return BAD_VALUE; } params.getPictureSize(&w, &h); sprintf(tmp, "%dx%d", w, h); FLOGI("Set picture size: %s", tmp); if (strstr(mSupportedPictureSizes, tmp) == NULL) { FLOGE("The picture size w %d, h %d is not corrected", w, h); return BAD_VALUE; } local_framerate = mParams.getPreviewFrameRate(); FLOGI("get local frame rate:%d FPS", local_framerate); if ((local_framerate > 30) || (local_framerate < 0)) { FLOGE("The framerate is not corrected"); local_framerate = 15; } framerate = params.getPreviewFrameRate(); FLOGI("Set frame rate:%d FPS", framerate); if ((framerate > 30) || (framerate < 0)) { FLOGE("The framerate is not corrected"); return BAD_VALUE; } else if (local_framerate != framerate) { if (framerate == 15) { params.set(CameraParameters::KEY_PREVIEW_FPS_RANGE, "12000,17000"); } else if (framerate == 30) { params.set(CameraParameters::KEY_PREVIEW_FPS_RANGE, "25000,33000"); } } int actual_fps = 15; params.getPreviewFpsRange(&min_fps, &max_fps); FLOGI("FPS range: %d - %d", min_fps, max_fps); if ((max_fps < 1000) || (min_fps < 1000) || (max_fps > 33000) || (min_fps > 33000)) { FLOGE("The fps range from %d to %d is error", min_fps, max_fps); return BAD_VALUE; } actual_fps = min_fps > 15000 ? 30 : 15; FLOGI("setParameters: actual_fps=%d", actual_fps); params.setPreviewFrameRate(actual_fps); mParams = params; return NO_ERROR; }