diff --git a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/camera_manager.cpp b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/camera_manager.cpp index 6de1410ec2f7900297b836682ea58260cf32827c..784c5b75061ce2883a0adb95640730d01c6a3b1b 100644 --- a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/camera_manager.cpp +++ b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/camera_manager.cpp @@ -14,22 +14,21 @@ */ #include "camera_manager.h" -#include #define LOG_TAG "DEMO:" #define LOG_DOMAIN 0x3200 NDKCamera* NDKCamera::ndkCamera_ = nullptr; std::mutex NDKCamera::mtx_; -NDKCamera::NDKCamera(char* str) - : previewSurfaceId_(str), cameras_(nullptr), +NDKCamera::NDKCamera(char* str, uint32_t focusMode) + : previewSurfaceId_(str), cameras_(nullptr), focusMode_(focusMode), cameraOutputCapability_(nullptr), cameraInput_(nullptr), captureSession_(nullptr), size_(0), isCameraMuted_(nullptr), profile_(nullptr), - photoSurfaceId_(nullptr), - previewOutput_(nullptr), photoOutput_(nullptr), - metaDataObjectType_(nullptr), metadataOutput_(nullptr), - ret_(CAMERA_OK) + photoSurfaceId_(nullptr), previewOutput_(nullptr), photoOutput_(nullptr), + metaDataObjectType_(nullptr), metadataOutput_(nullptr), isExposureModeSupported_(false), + isFocusModeSupported_(false), exposureMode_(EXPOSURE_MODE_LOCKED), + minExposureBias_(0), maxExposureBias_(0), step_(0), ret_(CAMERA_OK) { valid_ = false; Camera_ErrorCode ret = OH_Camera_GetCameraMananger(&cameraManager_); @@ -78,7 +77,7 @@ Camera_ErrorCode NDKCamera::HasFlashFn(uint32_t mode) OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_HasFlash failed."); } if (hasFlash) { - OH_LOG_ERROR(LOG_APP, "hasFlash success-----"); + OH_LOG_INFO(LOG_APP, "hasFlash success-----"); } else { OH_LOG_ERROR(LOG_APP, "hasFlash fail-----"); } @@ -90,7 +89,7 @@ Camera_ErrorCode NDKCamera::HasFlashFn(uint32_t mode) OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_IsFlashModeSupported failed."); } if (isSupported) { - OH_LOG_ERROR(LOG_APP, "isFlashModeSupported success-----"); + OH_LOG_INFO(LOG_APP, "isFlashModeSupported success-----"); } else { OH_LOG_ERROR(LOG_APP, "isFlashModeSupported fail-----"); } @@ -98,21 +97,54 @@ Camera_ErrorCode NDKCamera::HasFlashFn(uint32_t mode) // 设置闪光灯模式 ret = OH_CaptureSession_SetFlashMode(captureSession_, flashMode); if (ret == CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_SetFlashMode success."); + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_SetFlashMode success."); } else { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_SetFlashMode failed. %d ", ret); + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_SetFlashMode failed. %{public}d ", ret); } // 获取当前设备的闪光灯模式 ret = OH_CaptureSession_GetFlashMode(captureSession_, &flashMode); if (ret == CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetFlashMode success. flashMode:%d ", flashMode); + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_GetFlashMode success. flashMode:%{public}d ", flashMode); } else { OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetFlashMode failed. %d ", ret); } return ret; } +Camera_ErrorCode NDKCamera::IsVideoStabilizationModeSupportedFn(uint32_t mode) +{ + Camera_VideoStabilizationMode videoMode = static_cast(mode); + // 查询是否支持指定的视频防抖模式 + bool isSupported = false; + Camera_ErrorCode ret = OH_CaptureSession_IsVideoStabilizationModeSupported( + captureSession_, videoMode, &isSupported); + if (ret != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_IsVideoStabilizationModeSupported failed."); + } + if (isSupported) { + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_IsVideoStabilizationModeSupported success-----"); + } else { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_IsVideoStabilizationModeSupported fail-----"); + } + + // 设置视频防抖 + ret = OH_CaptureSession_SetVideoStabilizationMode(captureSession_, videoMode); + if (ret == CAMERA_OK) { + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_SetVideoStabilizationMode success."); + } else { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_SetVideoStabilizationMode failed. %{public}d ", ret); + } + + ret = OH_CaptureSession_GetVideoStabilizationMode(captureSession_, &videoMode); + if (ret == CAMERA_OK) { + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_GetVideoStabilizationMode success. videoMode:%{public}f ", videoMode); + } else { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetVideoStabilizationMode failed. %{public}d ", ret); + } + return ret; +} + Camera_ErrorCode NDKCamera::setZoomRatioFn(uint32_t zoomRatio) { float zoom = float(zoomRatio); @@ -123,98 +155,103 @@ Camera_ErrorCode NDKCamera::setZoomRatioFn(uint32_t zoomRatio) if (captureSession_ == nullptr || ret != CAMERA_OK) { OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetZoomRatioRange failed."); } else { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetZoomRatioRange success. minZoom: %f, maxZoom: %f", + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_GetZoomRatioRange success. minZoom: %{public}f, maxZoom:%{public}f", minZoom, maxZoom); } // 设置变焦 ret = OH_CaptureSession_SetZoomRatio(captureSession_, zoom); if (ret == CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_SetZoomRatio success."); + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_SetZoomRatio success."); } else { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_SetZoomRatio failed. %d ", ret); + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_SetZoomRatio failed. %{public}d ", ret); } // 获取当前设备的变焦值 ret = OH_CaptureSession_GetZoomRatio(captureSession_, &zoom); if (ret == CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetZoomRatio success. zoom: %f ", zoom); + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_GetZoomRatio success. zoom:%{public}f ", zoom); } else { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetZoomRatio failed. %d ", ret); + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetZoomRatio failed. %{public}d ", ret); } return ret; } -Camera_ErrorCode NDKCamera::SessionBegin() +Camera_ErrorCode NDKCamera::SessionBegin(void) { Camera_ErrorCode ret = OH_CaptureSession_BeginConfig(captureSession_); if (ret == CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_BeginConfig success."); + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_BeginConfig success."); } else { OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_BeginConfig failed. %d ", ret); } return ret; } -Camera_ErrorCode NDKCamera::SessionCommitConfig() +Camera_ErrorCode NDKCamera::SessionCommitConfig(void) { Camera_ErrorCode ret = OH_CaptureSession_CommitConfig(captureSession_); if (ret == CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_CommitConfig success."); + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_CommitConfig success."); } else { OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_CommitConfig failed. %d ", ret); } return ret; } -Camera_ErrorCode NDKCamera::SessionStart() +Camera_ErrorCode NDKCamera::SessionStart(void) { Camera_ErrorCode ret = OH_CaptureSession_Start(captureSession_); if (ret == CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_Start success."); + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_Start success."); } else { OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_Start failed. %d ", ret); } return ret; } -Camera_ErrorCode NDKCamera::SessionStop() +Camera_ErrorCode NDKCamera::SessionStop(void) { Camera_ErrorCode ret = OH_CaptureSession_Stop(captureSession_); if (ret == CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_Stop success."); + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_Stop success."); } else { OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_Stop failed. %d ", ret); } return ret; } -Camera_ErrorCode NDKCamera::SessionFlowFn() +Camera_ErrorCode NDKCamera::SessionFlowFn(void) { - OH_LOG_ERROR(LOG_APP, "Start SessionFlowFn IN."); + OH_LOG_INFO(LOG_APP, "Start SessionFlowFn IN."); // 开始配置会话 - OH_LOG_ERROR(LOG_APP, "session beginConfig."); + OH_LOG_INFO(LOG_APP, "session beginConfig."); Camera_ErrorCode ret = OH_CaptureSession_BeginConfig(captureSession_); // 把CameraInput加入到会话 - OH_LOG_ERROR(LOG_APP, "session addInput."); + OH_LOG_INFO(LOG_APP, "session addInput."); ret = OH_CaptureSession_AddInput(captureSession_, cameraInput_); // 把previewOutput加入到会话 - OH_LOG_ERROR(LOG_APP, "session add Preview Output."); + OH_LOG_INFO(LOG_APP, "session add Preview Output."); ret = OH_CaptureSession_AddPreviewOutput(captureSession_, previewOutput_); // 把photoOutput加入到会话 - OH_LOG_ERROR(LOG_APP, "session add Photo Output."); + OH_LOG_INFO(LOG_APP, "session add Photo Output."); // 提交配置信息 - OH_LOG_ERROR(LOG_APP, "session commitConfig"); + OH_LOG_INFO(LOG_APP, "session commitConfig"); ret = OH_CaptureSession_CommitConfig(captureSession_); // 开始会话工作 - OH_LOG_ERROR(LOG_APP, "session start"); + OH_LOG_INFO(LOG_APP, "session start"); ret = OH_CaptureSession_Start(captureSession_); - OH_LOG_ERROR(LOG_APP, "session success"); + OH_LOG_INFO(LOG_APP, "session success"); + + // 启动对焦 + OH_LOG_INFO(LOG_APP, "IsFocusMode start"); + ret = IsFocusMode(focusMode_); + OH_LOG_INFO(LOG_APP, "IsFocusMode success"); return ret; } @@ -328,7 +365,7 @@ Camera_ErrorCode NDKCamera::CreateVideoOutput(char* videoId) return ret_; } -Camera_ErrorCode NDKCamera::AddVideoOutput() +Camera_ErrorCode NDKCamera::AddVideoOutput(void) { Camera_ErrorCode ret = OH_CaptureSession_AddVideoOutput(captureSession_, videoOutput_); if (ret == CAMERA_OK) { @@ -395,16 +432,16 @@ Camera_ErrorCode NDKCamera::PhotoOutputRelease(void) } Camera_ErrorCode NDKCamera::startVideo(char* videoId) { - OH_LOG_ERROR(LOG_APP, "startVideo begin."); + OH_LOG_INFO(LOG_APP, "startVideo begin."); Camera_ErrorCode ret = SessionStop(); if (ret == CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "SessionStop success."); + OH_LOG_INFO(LOG_APP, "SessionStop success."); } else { OH_LOG_ERROR(LOG_APP, "SessionStop failed. %d ", ret); } ret = SessionBegin(); if (ret == CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "SessionBegin success."); + OH_LOG_INFO(LOG_APP, "SessionBegin success."); } else { OH_LOG_ERROR(LOG_APP, "SessionBegin failed. %d ", ret); } @@ -415,12 +452,12 @@ Camera_ErrorCode NDKCamera::startVideo(char* videoId) return ret; } -Camera_ErrorCode NDKCamera::VideoOutputStart() +Camera_ErrorCode NDKCamera::VideoOutputStart(void) { - OH_LOG_ERROR(LOG_APP, "VideoOutputStart begin."); + OH_LOG_INFO(LOG_APP, "VideoOutputStart begin."); Camera_ErrorCode ret = OH_VideoOutput_Start(videoOutput_); if (ret == CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "OH_VideoOutput_Start success."); + OH_LOG_INFO(LOG_APP, "OH_VideoOutput_Start success."); } else { OH_LOG_ERROR(LOG_APP, "OH_VideoOutput_Start failed. %d ", ret); } @@ -433,34 +470,211 @@ Camera_ErrorCode NDKCamera::startPhoto(char *mSurfaceId) if (takePictureTimes == 0) { ret = SessionStop(); if (ret == CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "SessionStop success."); + OH_LOG_INFO(LOG_APP, "SessionStop success."); } else { OH_LOG_ERROR(LOG_APP, "SessionStop failed. %d ", ret); } ret = SessionBegin(); if (ret == CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "SessionBegin success."); + OH_LOG_INFO(LOG_APP, "SessionBegin success."); } else { OH_LOG_ERROR(LOG_APP, "SessionBegin failed. %d ", ret); } - OH_LOG_ERROR(LOG_APP, "startPhoto begin."); + OH_LOG_INFO(LOG_APP, "startPhoto begin."); ret = CreatePhotoOutput(mSurfaceId); - OH_LOG_ERROR(LOG_APP, "startPhoto CreatePhotoOutput ret = %{public}d.", ret); + OH_LOG_INFO(LOG_APP, "startPhoto CreatePhotoOutput ret = %{public}d.", ret); ret = OH_CaptureSession_AddPhotoOutput(captureSession_, photoOutput_); - OH_LOG_ERROR(LOG_APP, "startPhoto AddPhotoOutput ret = %{public}d.", ret); + OH_LOG_INFO(LOG_APP, "startPhoto AddPhotoOutput ret = %{public}d.", ret); ret = SessionCommitConfig(); - OH_LOG_ERROR(LOG_APP, "startPhoto SessionCommitConfig ret = %{public}d.", ret); + OH_LOG_INFO(LOG_APP, "startPhoto SessionCommitConfig ret = %{public}d.", ret); ret = SessionStart(); - OH_LOG_ERROR(LOG_APP, "startPhoto SessionStart ret = %{public}d.", ret); + OH_LOG_INFO(LOG_APP, "startPhoto SessionStart ret = %{public}d.", ret); } ret = OH_PhotoOutput_Capture(photoOutput_); - OH_LOG_ERROR(LOG_APP, "startPhoto OH_PhotoOutput_Capture ret = %{public}d.", ret); + OH_LOG_INFO(LOG_APP, "startPhoto OH_PhotoOutput_Capture ret = %{public}d.", ret); if (ret_ != CAMERA_OK) { OH_LOG_ERROR(LOG_APP, "startPhoto failed."); return CAMERA_INVALID_ARGUMENT; } - takePictureTimes ++; + takePictureTimes++; + return ret_; +} + +// exposure mode +Camera_ErrorCode NDKCamera::IsExposureModeSupportedFn(uint32_t mode) +{ + OH_LOG_INFO(LOG_APP, "IsExposureModeSupportedFn start."); + exposureMode_ = static_cast(mode); + ret_ = OH_CaptureSession_IsExposureModeSupported(captureSession_, exposureMode_, &isExposureModeSupported_); + if (&isExposureModeSupported_ == nullptr || ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "IsExposureModeSupported failed."); + return CAMERA_INVALID_ARGUMENT; + } + ret_ = OH_CaptureSession_SetExposureMode(captureSession_, exposureMode_); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "SetExposureMode failed."); + return CAMERA_INVALID_ARGUMENT; + } + ret_ = OH_CaptureSession_GetExposureMode(captureSession_, &exposureMode_); + if (&exposureMode_ == nullptr || ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "GetExposureMode failed."); + return CAMERA_INVALID_ARGUMENT; + } + OH_LOG_INFO(LOG_APP, "IsExposureModeSupportedFn end."); + return ret_; +} + +Camera_ErrorCode NDKCamera::IsMeteringPoint(int x, int y) +{ + OH_LOG_INFO(LOG_APP, "IsMeteringPoint start."); + ret_ = OH_CaptureSession_GetExposureMode(captureSession_, &exposureMode_); + if (&exposureMode_ == nullptr || ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "GetExposureMode failed."); + return CAMERA_INVALID_ARGUMENT; + } + Camera_Point exposurePoint; + exposurePoint.x = x; + exposurePoint.y = y; + ret_ = OH_CaptureSession_SetMeteringPoint(captureSession_, exposurePoint); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "SetMeteringPoint failed."); + return CAMERA_INVALID_ARGUMENT; + } + ret_ = OH_CaptureSession_GetMeteringPoint(captureSession_, &exposurePoint); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "GetMeteringPoint failed."); + return CAMERA_INVALID_ARGUMENT; + } + OH_LOG_INFO(LOG_APP, "IsMeteringPoint end."); + return ret_; +} + +Camera_ErrorCode NDKCamera::IsExposureBiasRange(int exposureBias) +{ + OH_LOG_INFO(LOG_APP, "IsExposureBiasRange end."); + float exposureBiasValue = (float)exposureBias; + ret_ = OH_CaptureSession_GetExposureBiasRange(captureSession_, &minExposureBias_, &maxExposureBias_, &step_); + if (&minExposureBias_ == nullptr || &maxExposureBias_ == nullptr || &step_ == nullptr || ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "GetExposureBiasRange failed."); + return CAMERA_INVALID_ARGUMENT; + } + ret_ = OH_CaptureSession_SetExposureBias(captureSession_, exposureBiasValue); + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_SetExposureBias end."); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "SetExposureBias failed."); + return CAMERA_INVALID_ARGUMENT; + } + ret_ = OH_CaptureSession_GetExposureBias(captureSession_, &exposureBiasValue); + if (&exposureBiasValue == nullptr || ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "GetExposureBias failed."); + return CAMERA_INVALID_ARGUMENT; + } + OH_LOG_INFO(LOG_APP, "IsExposureBiasRange end."); + return ret_; +} + +// focus mode +Camera_ErrorCode NDKCamera::IsFocusModeSupported(uint32_t mode) +{ + Camera_FocusMode focusMode = static_cast(mode); + ret_ = OH_CaptureSession_IsFocusModeSupported(captureSession_, focusMode, &isFocusModeSupported_); + if (&isFocusModeSupported_ == nullptr || ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "IsFocusModeSupported failed."); + return CAMERA_INVALID_ARGUMENT; + } + return ret_; +} + +Camera_ErrorCode NDKCamera::IsFocusMode(uint32_t mode) +{ + OH_LOG_INFO(LOG_APP, "IsFocusMode start."); + Camera_FocusMode focusMode = static_cast(mode); + ret_ = OH_CaptureSession_IsFocusModeSupported(captureSession_, focusMode, &isFocusModeSupported_); + if (&isFocusModeSupported_ == nullptr || ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "IsFocusModeSupported failed."); + return CAMERA_INVALID_ARGUMENT; + } + ret_ = OH_CaptureSession_SetFocusMode(captureSession_, focusMode); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "SetFocusMode failed."); + return CAMERA_INVALID_ARGUMENT; + } + ret_ = OH_CaptureSession_GetFocusMode(captureSession_, &focusMode); + if (&focusMode == nullptr || ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "GetFocusMode failed."); + return CAMERA_INVALID_ARGUMENT; + } + OH_LOG_INFO(LOG_APP, "IsFocusMode end."); + return ret_; +} + +Camera_ErrorCode NDKCamera::IsFocusPoint(int x, int y) +{ + OH_LOG_INFO(LOG_APP, "IsFocusPoint start."); + Camera_Point focusPoint; + focusPoint.x = x; + focusPoint.y = y; + ret_ = OH_CaptureSession_SetFocusPoint(captureSession_, focusPoint); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "SetFocusPoint failed."); + return CAMERA_INVALID_ARGUMENT; + } + ret_ = OH_CaptureSession_GetFocusPoint(captureSession_, &focusPoint); + if (&focusPoint == nullptr || ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "GetFocusPoint failed."); + return CAMERA_INVALID_ARGUMENT; + } + OH_LOG_INFO(LOG_APP, "IsFocusPoint end."); + return ret_; +} +int32_t NDKCamera::GetVideoFrameWidth(void) +{ + videoProfile_ = cameraOutputCapability_->videoProfiles[0]; + if (videoProfile_ == nullptr) { + OH_LOG_ERROR(LOG_APP, "Get videoProfiles failed."); + return CAMERA_INVALID_ARGUMENT; + } + return videoProfile_->size.width; +} + +int32_t NDKCamera::GetVideoFrameHeight(void) +{ + videoProfile_ = cameraOutputCapability_->videoProfiles[0]; + if (videoProfile_ == nullptr) { + OH_LOG_ERROR(LOG_APP, "Get videoProfiles failed."); + return CAMERA_INVALID_ARGUMENT; + } + return videoProfile_->size.height; +} + +int32_t NDKCamera::GetVideoFrameRate(void) +{ + videoProfile_ = cameraOutputCapability_->videoProfiles[0]; + if (videoProfile_ == nullptr) { + OH_LOG_ERROR(LOG_APP, "Get videoProfiles failed."); + return CAMERA_INVALID_ARGUMENT; + } + return videoProfile_->range.min; +} + +Camera_ErrorCode NDKCamera::VideoOutputStop(void) +{ + ret_ = OH_VideoOutput_Stop(videoOutput_); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "VideoOutputStop failed."); + return CAMERA_INVALID_ARGUMENT; + } + return ret_; +} + +Camera_ErrorCode NDKCamera::VideoOutputRelease(void) +{ + ret_ = OH_VideoOutput_Release(videoOutput_); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "VideoOutputRelease failed."); + return CAMERA_INVALID_ARGUMENT; + } return ret_; } \ No newline at end of file diff --git a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/camera_manager.h b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/camera_manager.h index 3c44ffefb433ab90ae40bb49ef49e8b86df35828..a92989b4c78332ad2edaa93e889e9a3c34898eeb 100644 --- a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/camera_manager.h +++ b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/camera_manager.h @@ -41,12 +41,12 @@ class NDKCamera { public: ~NDKCamera(); - static NDKCamera* GetInstance(char *str) + static NDKCamera* GetInstance(char *str, uint32_t focusMode) { if (ndkCamera_ == nullptr) { std::lock_guard lock(mtx_); if (ndkCamera_ == nullptr) { - ndkCamera_ = new NDKCamera(str); + ndkCamera_ = new NDKCamera(str, focusMode); } } return ndkCamera_; @@ -76,19 +76,31 @@ public: Camera_ErrorCode PreviewOutputRelease(void); Camera_ErrorCode PhotoOutputRelease(void); Camera_ErrorCode HasFlashFn(uint32_t mode); + Camera_ErrorCode IsVideoStabilizationModeSupportedFn(uint32_t mode); Camera_ErrorCode setZoomRatioFn(uint32_t zoomRatio); - Camera_ErrorCode SessionFlowFn(); - Camera_ErrorCode SessionBegin(); - Camera_ErrorCode SessionCommitConfig(); - Camera_ErrorCode SessionStart(); - Camera_ErrorCode SessionStop(); + Camera_ErrorCode SessionFlowFn(void); + Camera_ErrorCode SessionBegin(void); + Camera_ErrorCode SessionCommitConfig(void); + Camera_ErrorCode SessionStart(void); + Camera_ErrorCode SessionStop(void); Camera_ErrorCode startVideo(char* videoId); - Camera_ErrorCode AddVideoOutput(); - Camera_ErrorCode VideoOutputStart(); + Camera_ErrorCode AddVideoOutput(void); + Camera_ErrorCode VideoOutputStart(void); Camera_ErrorCode startPhoto(char *mSurfaceId); + Camera_ErrorCode IsExposureModeSupportedFn(uint32_t mode); + Camera_ErrorCode IsMeteringPoint(int x, int y); + Camera_ErrorCode IsExposureBiasRange(int exposureBias); + Camera_ErrorCode IsFocusMode(uint32_t mode); + Camera_ErrorCode IsFocusPoint(int x, int y); + Camera_ErrorCode IsFocusModeSupported(uint32_t mode); + int32_t GetVideoFrameWidth(void); + int32_t GetVideoFrameHeight(void); + int32_t GetVideoFrameRate(void); + Camera_ErrorCode VideoOutputStop(void); + Camera_ErrorCode VideoOutputRelease(void); private: - explicit NDKCamera(char *str); + NDKCamera(char *str, uint32_t focusMode); NDKCamera(const NDKCamera&) = delete; NDKCamera& operator = (const NDKCamera&) = delete; @@ -112,6 +124,13 @@ private: char* photoSurfaceId_; Camera_ErrorCode ret_; uint32_t takePictureTimes = 0; + Camera_ExposureMode exposureMode_; + bool isExposureModeSupported_; + bool isFocusModeSupported_; + float minExposureBias_; + float maxExposureBias_; + float step_; + uint32_t focusMode_; // callback CameraManager_Callbacks* callback_; diff --git a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/main.cpp b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/main.cpp index b729920484402ea4d6280bfebdecc7072f0ad853..450265753da909a45ffb02418357b083549d196b 100644 --- a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/main.cpp +++ b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/main.cpp @@ -14,10 +14,7 @@ */ #include -#include -#include "napi/native_api.h" #include "camera_manager.h" -#include "hilog/log.h" #define LOG_TAG "DEMO:" #define LOG_DOMAIN 0x3200 @@ -38,11 +35,59 @@ static napi_value SetZoomRatio(napi_env env, napi_callback_info info) int32_t zoomRatio; napi_get_value_int32(env, args[0], &zoomRatio); - OH_LOG_ERROR(LOG_APP, "zoomRatio : %d", zoomRatio); - + OH_LOG_ERROR(LOG_APP, "SetZoomRatio : %{public}d", zoomRatio); + + ndkCamera_->setZoomRatioFn(zoomRatio); + return result; } +static napi_value HasFlash(napi_env env, napi_callback_info info) +{ + OH_LOG_ERROR(LOG_APP, "HasFlash"); + size_t requireArgc = 2; + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_value resutl; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + napi_valuetype valuetype0; + napi_typeof(env, args[0], &valuetype0); + + int32_t flashMode; + napi_get_value_int32(env, args[0], &flashMode); + + OH_LOG_ERROR(LOG_APP, "HasFlash flashMode : %{public}d", flashMode); + + ndkCamera_->HasFlashFn(flashMode); + + return resutl; +} + +static napi_value IsVideoStabilizationModeSupported(napi_env env, napi_callback_info info) +{ + OH_LOG_ERROR(LOG_APP, "IsVideoStabilizationModeSupportedFn"); + size_t requireArgc = 2; + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_value resutl; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + napi_valuetype valuetype0; + napi_typeof(env, args[0], &valuetype0); + + int32_t videoMode; + napi_get_value_int32(env, args[0], &videoMode); + + OH_LOG_ERROR(LOG_APP, "IsVideoStabilizationModeSupportedFn videoMode : %{public}d", videoMode); + + ndkCamera_->IsVideoStabilizationModeSupportedFn(videoMode); + + return resutl; +} + static napi_value InitCamera(napi_env env, napi_callback_info info) { OH_LOG_ERROR(LOG_APP, "InitCamera Start"); @@ -58,11 +103,14 @@ static napi_value InitCamera(napi_env env, napi_callback_info info) napi_get_value_string_utf8(env, args[0], nullptr, 0, &typeLen); surfaceId = new char[typeLen + 1]; napi_get_value_string_utf8(env, args[0], surfaceId, typeLen + 1, &typeLen); - - int32_t cameraDeviceIndex; - napi_get_value_int32(env, args[1], &cameraDeviceIndex); - - ndkCamera_ = NDKCamera::GetInstance(surfaceId); + + napi_valuetype valuetype1; + napi_typeof(env, args[1], &valuetype1); + int32_t focusMode; + napi_get_value_int32(env, args[1], &focusMode); + OH_LOG_ERROR(LOG_APP, "InitCamera focusMode : %{public}d", focusMode); + OH_LOG_ERROR(LOG_APP, "InitCamera surfaceId : %{public}s", surfaceId); + ndkCamera_ = NDKCamera::GetInstance(surfaceId, focusMode); OH_LOG_ERROR(LOG_APP, "InitCamera End"); return result; @@ -105,10 +153,184 @@ static napi_value VideoOutputStart(napi_env env, napi_callback_info info) OH_LOG_INFO(LOG_APP, "VideoOutputStart Start"); size_t requireArgc = 0; size_t argc = 0; + napi_value args[2] = {nullptr}; napi_value result; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); ndkCamera_->VideoOutputStart(); return result; } + +static napi_value IsExposureModeSupported(napi_env env, napi_callback_info info) +{ + OH_LOG_INFO(LOG_APP, "IsExposureModeSupported exposureMode start."); + size_t requireArgc = 2; + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_value result; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + napi_valuetype valuetype0; + napi_typeof(env, args[0], &valuetype0); + + int32_t exposureMode; + napi_get_value_int32(env, args[0], &exposureMode); + + OH_LOG_ERROR(LOG_APP, "IsExposureModeSupported exposureMode : %{public}d", exposureMode); + + ndkCamera_->IsExposureModeSupportedFn(exposureMode); + OH_LOG_INFO(LOG_APP, "IsExposureModeSupported exposureMode end."); + return result; +} + +static napi_value IsMeteringPoint(napi_env env, napi_callback_info info) +{ + size_t requireArgc = 2; + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_value result; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + napi_valuetype valuetype0; + napi_typeof(env, args[0], &valuetype0); + int x; + napi_get_value_int32(env, args[0], &x); + + napi_valuetype valuetype1; + napi_typeof(env, args[0], &valuetype0); + int y; + napi_get_value_int32(env, args[1], &y); + ndkCamera_->IsMeteringPoint(x, y); + return result; +} + +static napi_value IsExposureBiasRange(napi_env env, napi_callback_info info) +{ + OH_LOG_INFO(LOG_APP, "IsExposureBiasRange start."); + size_t requireArgc = 2; + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_value result; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + napi_valuetype valuetype0; + napi_typeof(env, args[0], &valuetype0); + + int exposureBiasValue; + napi_get_value_int32(env, args[0], &exposureBiasValue); + ndkCamera_->IsExposureBiasRange(exposureBiasValue); + OH_LOG_INFO(LOG_APP, "IsExposureBiasRange end."); + return result; +} + +static napi_value IsFocusModeSupported(napi_env env, napi_callback_info info) +{ + OH_LOG_INFO(LOG_APP, "IsFocusModeSupported start."); + size_t requireArgc = 2; + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_value result; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + napi_valuetype valuetype0; + napi_typeof(env, args[0], &valuetype0); + + int32_t focusMode; + napi_get_value_int32(env, args[0], &focusMode); + + OH_LOG_ERROR(LOG_APP, "IsFocusModeSupportedFn videoMode : %{public}d", focusMode); + + ndkCamera_->IsFocusModeSupported(focusMode); + OH_LOG_INFO(LOG_APP, "IsFocusModeSupported end."); + return result; +} + +static napi_value IsFocusPoint(napi_env env, napi_callback_info info) +{ + size_t requireArgc = 2; + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_value result; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + napi_valuetype valuetype0; + napi_typeof(env, args[0], &valuetype0); + int x; + napi_get_value_int32(env, args[0], &x); + + napi_valuetype valuetype1; + napi_typeof(env, args[0], &valuetype0); + int y; + napi_get_value_int32(env, args[1], &y); + ndkCamera_->IsFocusPoint(x, y); + return result; +} + +static napi_value GetVideoFrameWidth(napi_env env, napi_callback_info info) +{ + OH_LOG_ERROR(LOG_APP, "GetVideoFrameWidth Start"); + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + napi_value result = nullptr; + napi_create_int32(env, ndkCamera_->GetVideoFrameWidth(), &result); + + OH_LOG_ERROR(LOG_APP, "GetVideoFrameWidth End"); + + return result; +} + +static napi_value GetVideoFrameHeight(napi_env env, napi_callback_info info) +{ + OH_LOG_ERROR(LOG_APP, "GetVideoFrameHeight Start"); + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + napi_value result = nullptr; + napi_create_int32(env, ndkCamera_->GetVideoFrameHeight(), &result); + + OH_LOG_ERROR(LOG_APP, "GetVideoFrameHeight End"); + + return result; +} + +static napi_value GetVideoFrameRate(napi_env env, napi_callback_info info) +{ + OH_LOG_ERROR(LOG_APP, "GetVideoFrameRate Start"); + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + napi_value result = nullptr; + napi_create_int32(env, ndkCamera_->GetVideoFrameRate(), &result); + + OH_LOG_ERROR(LOG_APP, "GetVideoFrameRate End"); + + return result; +} + +static napi_value VideoOutputStopAndRelease(napi_env env, napi_callback_info info) +{ + OH_LOG_ERROR(LOG_APP, "VideoOutputStopAndRelease Start"); + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + napi_value result = nullptr; + ndkCamera_->VideoOutputStop(); + ndkCamera_->VideoOutputRelease(); + + OH_LOG_ERROR(LOG_APP, "VideoOutputStopAndRelease End"); + + return result; +} + EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) { @@ -116,7 +338,21 @@ static napi_value Init(napi_env env, napi_value exports) { "initCamera", nullptr, InitCamera, nullptr, nullptr, nullptr, napi_default, nullptr }, { "startPhotoOrVideo", nullptr, StartPhotoOrVideo, nullptr, nullptr, nullptr, napi_default, nullptr }, { "videoOutputStart", nullptr, VideoOutputStart, nullptr, nullptr, nullptr, napi_default, nullptr }, - { "setZoomRatio", nullptr, SetZoomRatio, nullptr, nullptr, nullptr, napi_default, nullptr } + { "setZoomRatio", nullptr, SetZoomRatio, nullptr, nullptr, nullptr, napi_default, nullptr }, + { "hasFlash", nullptr, HasFlash, nullptr, nullptr, nullptr, napi_default, nullptr }, + { "isVideoStabilizationModeSupported", nullptr, IsVideoStabilizationModeSupported, + nullptr, nullptr, nullptr, napi_default, nullptr }, + { "isExposureModeSupported", nullptr, IsExposureModeSupported, + nullptr, nullptr, nullptr, napi_default, nullptr }, + { "isMeteringPoint", nullptr, IsMeteringPoint, nullptr, nullptr, nullptr, napi_default, nullptr }, + { "isExposureBiasRange", nullptr, IsExposureBiasRange, nullptr, nullptr, nullptr, napi_default, nullptr }, + { "IsFocusModeSupported", nullptr, IsFocusModeSupported, nullptr, nullptr, nullptr, napi_default, nullptr }, + { "isFocusPoint", nullptr, IsFocusPoint, nullptr, nullptr, nullptr, napi_default, nullptr }, + { "getVideoFrameWidth", nullptr, GetVideoFrameWidth, nullptr, nullptr, nullptr, napi_default, nullptr }, + { "getVideoFrameHeight", nullptr, GetVideoFrameHeight, nullptr, nullptr, nullptr, napi_default, nullptr }, + { "getVideoFrameRate", nullptr, GetVideoFrameRate, nullptr, nullptr, nullptr, napi_default, nullptr }, + { "videoOutputStopAndRelease", nullptr, VideoOutputStopAndRelease, + nullptr, nullptr, nullptr, napi_default, nullptr }, }; napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); return exports; diff --git a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/types/libentry/index.d.ts b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/types/libentry/index.d.ts index 1e804bf3ea50e05487fc8bc5ecf0a6765e9fb1c3..0e6afb5ccbeffc9cf603c66d6235636d1ce5384a 100644 --- a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/types/libentry/index.d.ts +++ b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/types/libentry/index.d.ts @@ -1,5 +1,15 @@ -export const add: (a: number, b: number) => number; -export const initCamera:(surfaceId: string) => number; +export const initCamera:(surfaceId: string, focusMode: number) => number; export const startPhotoOrVideo:(modeFlag: string, videoId: string) => number; export const videoOutputStart: () => number; -export const setZoomRatio: (a: number) => number; \ No newline at end of file +export const setZoomRatio: (a: number) => number; +export const hasFlash: (a: number) => number; +export const isVideoStabilizationModeSupported: (a: number) => number; +export const isExposureModeSupported:(a: number) => number; +export const isMeteringPoint: (a: number, b: number) => number; +export const isExposureBiasRange: (a: number) => number; +export const isFocusModeSupported: (a: number) => number; +export const isFocusPoint: (a: number, b: number) => number; +export const getVideoFrameWidth: () => number; +export const getVideoFrameHeight: () => number; +export const getVideoFrameRate: () => number; +export const videoOutputStopAndRelease: () => number; \ No newline at end of file diff --git a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/ets/common/Constants.ts b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/ets/common/Constants.ts new file mode 100644 index 0000000000000000000000000000000000000000..754c8c4c8d77a3ecb6926adf8861dbeaa8203a6a --- /dev/null +++ b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/ets/common/Constants.ts @@ -0,0 +1,19 @@ +export class Constants { + // aspect ratio: width/height + static readonly MIN_ASPECT_RATIO = 4 / 3; + static readonly MAX_ASPECT_RATIO = 16 / 9; + + static readonly VIDEO_MAX_WIDTH = 2048; + static readonly PHOTO_MAX_WIDTH = 2048; + static readonly SURFACE_BOTTOM_MARGIN = 50; + + // device type + static readonly TABLET = 'tablet'; + static readonly DEFAULT = 'default'; + static readonly PHONE = 'phone'; + + // video frame + static readonly VIDEO_FRAME_30 = 30; + static readonly VIDEO_FRAME_15 = 15; +} + diff --git a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/ets/common/DisplayCalculator.ts b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/ets/common/DisplayCalculator.ts new file mode 100644 index 0000000000000000000000000000000000000000..2749ecdaf11bc184af1b07b74c1a6bf31717facc --- /dev/null +++ b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/ets/common/DisplayCalculator.ts @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Constants } from '../common/Constants'; + +export default class DisplayCalculator { + public static calcSurfaceDisplaySize(screenWidth: number, screenHeight: number, defaultAspectRatio: number): { + width: number, + height: number + } { + const displaySize = { + width: 1920, height: 1080 + }; + // @ts-ignore + if (AppStorage.get('deviceType') === Constants.TABLET || screenWidth > screenHeight) { + if (screenWidth / screenHeight > defaultAspectRatio) { + displaySize.width = Math.floor(screenHeight * defaultAspectRatio); + displaySize.height = Math.floor(screenHeight); + } else { + displaySize.width = Math.floor(screenWidth); + displaySize.height = Math.floor(screenWidth / defaultAspectRatio); + } + } else { + if (screenWidth / screenHeight > defaultAspectRatio) { + displaySize.width = Math.floor(screenHeight / defaultAspectRatio); + displaySize.height = Math.floor(screenHeight); + } else { + displaySize.width = Math.floor(screenWidth); + displaySize.height = Math.floor(screenWidth * defaultAspectRatio); + } + } + return displaySize; + } +} \ No newline at end of file diff --git a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/ets/common/settingItem.ets b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/ets/common/settingItem.ets index 0e32ad02f67c9ef76881a87321b80c04becc2dd6..acde96cf9a35b2e120f07deecff9b68da256b4de 100644 --- a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/ets/common/settingItem.ets +++ b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/ets/common/settingItem.ets @@ -12,8 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -// import CameraService from '../model/CameraService' + +import cameraDemo from 'libentry.so' @Component export struct settingItem { @@ -27,15 +27,15 @@ export struct settingItem { switch (this.settingMessageNum) { case 2: globalThis.settingDataObj.videoStabilizationMode = this.index - // CameraService.isVideoStabilizationModeSupportedFn(globalThis.settingDataObj.videoStabilizationMode) + cameraDemo.isVideoStabilizationModeSupported(globalThis.settingDataObj.videoStabilizationMode) break case 3: globalThis.settingDataObj.exposureMode = this.index - // CameraService.isExposureModeSupportedFn(globalThis.settingDataObj.exposureMode) + cameraDemo.isExposureModeSupported(globalThis.settingDataObj.exposureMode) break case 4: globalThis.settingDataObj.focusMode = this.index - // CameraService.isFocusMode(globalThis.settingDataObj.focusMode) + cameraDemo.isFocusModeSupported(globalThis.settingDataObj.focusMode) break case 5: globalThis.settingDataObj.photoQuality = this.index diff --git a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/ets/pages/tableIndex.ets b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/ets/pages/tableIndex.ets index 6b49e1713fe39e5dc1889d48572d9839fd95b61e..277cf3fc2a671951e7262f9fdbee90153470c631 100644 --- a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/ets/pages/tableIndex.ets +++ b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/ets/pages/tableIndex.ets @@ -23,18 +23,11 @@ import { CountdownPage } from '../views/CountdownPage' import { FlashingLightPage } from '../views/FlashingLightPage' import { SlidePage } from '../views/SlidePage' import { modeSwitchPage } from '../views/modeSwitchPage' -import mediaLibrary from '@ohos.multimedia.mediaLibrary' -import fileio from '@ohos.fileio' - -import media from '@ohos.multimedia.media' -import MediaUtils from '../model/MediaUtils' - -// import CameraService from '../model/CameraService' -// import { CountdownPage } from '../views/CountdownPage' -// import { focusPage } from '../views/focusPage' -// import { focusAreaPage } from '../views/focusAreaPage' -// import { setting } from '../model/Setting' - +import { focusPage } from '../views/focusPage' +import { FocusAreaPage } from '../views/focusAreaPage' +import { Constants } from '../common/Constants' +import DisplayCalculator from '../common/DisplayCalculator' +import display from '@ohos.display' const TAG: string = 'UI indexPage' @@ -81,6 +74,12 @@ struct Index { @State countdownNum: number = 0 // 相机摄像头 @State cameraDeviceIndex: number = 0 + @State xComponentWidth: number = 384; + @State xComponentHeight: number = 450; + private deviceType: string; + private screenHeight: number; + private screenWidth: number; + // 设置弹框 private settingDialogController: CustomDialogController = new CustomDialogController({ builder: settingDialog({ @@ -94,11 +93,27 @@ struct Index { // 参考线 @State referenceLineBol: boolean = false + @StorageLink('defaultAspectRatio') @Watch('initXComponentSize') defaultAspectRatio: number = Constants.MIN_ASPECT_RATIO; @State onShow: boolean = false atManager = abilityAccessCtrl.createAtManager(); // 入口初始化函数 async aboutToAppear() { await this.requestPermissionsFn(); + let mDisplay = display.getDefaultDisplaySync(); + this.screenWidth = px2vp(mDisplay.width); + this.screenHeight = px2vp(mDisplay.height); + // @ts-ignore + this.deviceType = AppStorage.get('deviceType'); + if (this.deviceType === Constants.TABLET) { + this.defaultAspectRatio = Constants.MAX_ASPECT_RATIO; + } + this.initXComponentSize(); + } + + initXComponentSize(): void { + let defaultSize = DisplayCalculator.calcSurfaceDisplaySize(this.screenWidth, this.screenHeight, this.defaultAspectRatio); + this.xComponentWidth = defaultSize.width; + this.xComponentHeight = defaultSize.height; } async aboutToDisAppear() { @@ -123,17 +138,14 @@ struct Index { } catch (err) { Logger.info(TAG, `requestPermissionsFromUser call Failed! error: ${err.code}`) } - // 默认打开选择网络弹框 - //this.mainDialogController.open() } async onPageShow() { Logger.info(TAG, `onPageShow App`) if (this.surfaceId && this.onShow) { - Logger.error(TAG, `zss initCamera`) - cameraDemo.initCamera(this.surfaceId) - Logger.error(TAG, `zss initCamera 111`) - // await CameraService.initCamera(this.surfaceId, this.cameraDeviceIndex) + Logger.error(TAG, `initCamera`) + cameraDemo.initCamera(this.surfaceId, globalThis.settingDataObj.focusMode) + Logger.error(TAG, `initCamera 111`) } } @@ -155,10 +167,9 @@ struct Index { Logger.info(TAG, 'onLoad is called'); this.surfaceId = this.mXComponentController.getXComponentSurfaceId() Logger.info(TAG, `onLoad surfaceId: ${this.surfaceId}`) - Logger.error(TAG, `zss initCamera 222`) - cameraDemo.initCamera(this.surfaceId) - Logger.error(TAG, `zss initCamera 333`) - // await CameraService.initCamera(this.surfaceId, this.cameraDeviceIndex) + Logger.error(TAG, `initCamera 222`) + cameraDemo.initCamera(this.surfaceId, globalThis.settingDataObj.focusMode) + Logger.error(TAG, `initCamera 333`) }) .backgroundColor(Color.Blue) .width('100%') @@ -180,20 +191,22 @@ struct Index { // 打开设置弹框 this.settingDialogController.open() }) - // // 曝光框和对焦框 - // focusPage({ - // focusPointBol: $focusPointBol, - // focusPointVal: $focusPointVal, - // exposureBol: $exposureBol, - // exposureNum: $exposureNum - // }) - // // 曝光对焦手指点击区域 - // focusAreaPage({ - // focusPointBol: $focusPointBol, - // focusPointVal: $focusPointVal, - // exposureBol: $exposureBol, - // exposureNum: $exposureNum - // }) + // 曝光框和对焦框 + focusPage({ + focusPointBol: $focusPointBol, + focusPointVal: $focusPointVal, + exposureBol: $exposureBol, + exposureNum: $exposureNum + }) + // 曝光对焦手指点击区域 + FocusAreaPage({ + focusPointBol: $focusPointBol, + focusPointVal: $focusPointVal, + exposureBol: $exposureBol, + exposureNum: $exposureNum, + xComponentWidth: this.xComponentWidth, + xComponentHeight: this.xComponentHeight + }) // 倒计时 CountdownPage({ countdownNum: $countdownNum }) // 闪光灯 diff --git a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/ets/views/FlashingLightPage.ets b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/ets/views/FlashingLightPage.ets index 179ccd807507bd968e192695feb8e1033a35427e..dd94bd673920e35732999a5169fbe6ebaaf9ab4c 100644 --- a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/ets/views/FlashingLightPage.ets +++ b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/ets/views/FlashingLightPage.ets @@ -15,8 +15,7 @@ // 闪关灯页面 // 对于图标遍历渲染,后续需要对此进行改进 -// import CameraService from '../model/CameraService' - +import cameraDemo from 'libentry.so' @Component export struct FlashingLightPage { // 页面判断 @@ -64,7 +63,7 @@ export struct FlashingLightPage { .onClick(() => { this.flashingNum = 2 this.flashingBol = true - // CameraService.hasFlashFn(this.flashingNum) + cameraDemo.hasFlash(this.flashingNum) }) Image($r('app.media.ic_camera_public_flash_off')) .width('60px') @@ -73,7 +72,7 @@ export struct FlashingLightPage { .onClick(() => { this.flashingNum = 0 this.flashingBol = true - // CameraService.hasFlashFn(this.flashingNum) + cameraDemo.hasFlash(this.flashingNum) }) Image($r('app.media.ic_camera_public_flash_on')) .width('60px') @@ -82,7 +81,7 @@ export struct FlashingLightPage { .onClick(() => { this.flashingNum = 1 this.flashingBol = true - // CameraService.hasFlashFn(this.flashingNum) + cameraDemo.hasFlash(this.flashingNum) }) Image($r('app.media.flash_always_on')) .width('50px') @@ -91,7 +90,7 @@ export struct FlashingLightPage { .onClick(() => { this.flashingNum = 3 this.flashingBol = true - // CameraService.hasFlashFn(this.flashingNum) + cameraDemo.hasFlash(this.flashingNum) }) } .backgroundColor('#FFFFFF') diff --git a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/ets/views/SlidePage.ets b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/ets/views/SlidePage.ets index b4002aad2ca787d7f796f96aeb250e9ff7f21359..667e5c4429ff28c3008bc1515327abd20b70c3cc 100644 --- a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/ets/views/SlidePage.ets +++ b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/ets/views/SlidePage.ets @@ -15,7 +15,10 @@ // 变焦组件 // 对于组件的变化——只能1到6整数 , 后续需要对此进行修改 -// import CameraService from '../model/CameraService' +import cameraDemo from 'libentry.so' +import Logger from '../model/Logger'; + +const TAG: string = 'SlidePage'; @Component export struct SlidePage { @@ -25,7 +28,7 @@ export struct SlidePage { @State sliderTextPos: string = '-10' slideChange(value) { - // CameraService.setZoomRatioFn(value) + cameraDemo.setZoomRatio(value); switch (value) { case 1: this.sliderTextPos = '-10' @@ -46,6 +49,7 @@ export struct SlidePage { this.sliderTextPos = '380' break default: + break; // this.sliderTextPos += 1 } } diff --git a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/ets/views/focusAreaPage.ets b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/ets/views/focusAreaPage.ets new file mode 100644 index 0000000000000000000000000000000000000000..90f5a7de4376e13337a082f28ec62f1d9f25edb2 --- /dev/null +++ b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/ets/views/focusAreaPage.ets @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import cameraDemo from 'libentry.so' +import Logger from '../model/Logger'; + +const TAG: string = 'FocusAreaPage'; + +// 对焦区域 +@Component +export struct FocusAreaPage { + @Link focusPointBol: boolean; + @Link focusPointVal: Array; + // 刻度、焦距值 和 对焦框不能共存的显示 + @Link exposureBol: boolean; + // 曝光值 + @Link exposureNum: number; + @Prop xComponentWidth: number; + @Prop xComponentHeight: number; + // 对焦区域显示框定时器 + private areaTimer: number = -1; + // 上下滑动曝光 + private panOption: PanGestureOptions = new PanGestureOptions({ + direction: PanDirection.Up | PanDirection.Down, + fingers: 1 + }); + + build() { + Row() {} + .width(this.xComponentWidth) + .height(this.xComponentHeight) + .opacity(1) + .onTouch((e: TouchEvent) => { + if (e.type === TouchType.Down) { + this.focusPointBol = true; + this.focusPointVal[0] = e.touches[0].screenX; + this.focusPointVal[1] = e.touches[0].screenY; + // 焦点 + // @ts-ignore + cameraDemo.isFocusPoint( + e.touches[0].screenX / this.xComponentWidth, + e.touches[0].screenY / this.xComponentHeight + ); + // @ts-ignore + cameraDemo.isMeteringPoint( + e.touches[0].screenX / this.xComponentWidth, + e.touches[0].screenY / this.xComponentHeight + 50 + ); + } + if (e.type === TouchType.Up) { + if (this.areaTimer) { + clearTimeout(this.areaTimer); + } + this.areaTimer = setTimeout(() => { + this.focusPointBol = false; + }, 3500); + } + }) + // 单指竖直方向拖动触发该手势事件 + .gesture( + PanGesture(this.panOption) + .onActionStart(() => { + Logger.info(TAG, 'PanGesture onActionStart'); + this.exposureBol = false; + }) + .onActionUpdate((event: GestureEvent) => { + let offset = -event.offsetY; + if (offset > 200) { + this.exposureNum = 4; + } + if (offset < -200) { + this.exposureNum = -4; + } + if (offset > -200 && offset < 200) { + this.exposureNum = Number((offset / 50).toFixed(1)); + } + // 曝光补偿 -4 +4 + cameraDemo.isExposureBiasRange(this.exposureNum); + Logger.info(TAG, `PanGesture onActionUpdate offset: ${offset}, exposureNum: ${this.exposureNum}`); + }) + .onActionEnd(() => { + this.exposureNum = 0; + this.exposureBol = true; + Logger.info(TAG, 'PanGesture onActionEnd end'); + }) + ) + } +} \ No newline at end of file diff --git a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/ets/views/focusPage.ets b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/ets/views/focusPage.ets new file mode 100644 index 0000000000000000000000000000000000000000..95fc458a5760a999e65a07061449ca622357e034 --- /dev/null +++ b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/ets/views/focusPage.ets @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// 曝光选择 +@Component +export struct focusPage { + @Link focusPointBol: boolean + @Link focusPointVal: Array + // 刻度、焦距值 和 对焦框不能共存的显示 + @Link exposureBol: boolean + // 曝光值 + @Link exposureNum: number + + build() { + if (this.focusPointBol) { + Row() { + if (this.exposureBol) { + // 对焦框 + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.SpaceBetween }) { + Flex({ justifyContent: FlexAlign.SpaceBetween }) { + Row() { + }.border({ + width: { left: 1.6, right: 0, top: 1.6, bottom: 0 }, + color: Color.White, + radius: { topLeft: 10, topRight: 0, bottomLeft: 0, bottomRight: 0 } + }).size({ width: 15, height: 15 }) + + Row() { + }.border({ + width: { left: 0, right: 1.6, top: 1.6, bottom: 0 }, + color: Color.White, + radius: { topLeft: 0, topRight: 10, bottomLeft: 0, bottomRight: 0 } + }).size({ width: 15, height: 15 }) + } + + Flex({ justifyContent: FlexAlign.SpaceBetween }) { + Row() { + }.border({ + width: { left: 1.6, right: 0, top: 0, bottom: 1.6 }, + color: Color.White, + radius: { topLeft: 0, topRight: 0, bottomLeft: 10, bottomRight: 0 } + }).size({ width: 15, height: 15 }) + + Row() { + }.border({ + width: { left: 0, right: 1.6, top: 0, bottom: 1.6 }, + color: Color.White, + radius: { topLeft: 0, topRight: 0, bottomLeft: 0, bottomRight: 10 } + }).size({ width: 15, height: 15 }) + } + } + .width(50) + .height(50) + .position({ x: this.focusPointVal[0] - 60, y: this.focusPointVal[1] - 60 }) + } else { + // 焦距值 + Text(this.exposureNum + '').fontSize(60).fontColor(Color.White).fontWeight(400).position({ + x: this.focusPointVal[0] - 58, + y: this.focusPointVal[1] - 30 + }) + // 刻度值 + Flex() { + Column() { + Text('+4').fontColor(Color.White) + Text('0').margin({ top: 50, bottom: 50 }).fontColor(Color.White) + Text('-4').fontColor(Color.White) + }.margin({ right: 9 }) + // 刻度 + Column() { + Text('').height(67).border({ + width: { left: '0', right: 4, top: '0', bottom: '0' }, + color: Color.White, + radius: 2, + style: BorderStyle.Dotted + }) + Text('').height(8).border({ + width: { left: '0', right: 8, top: '0', bottom: '0' }, + color: Color.White, + radius: 4, + style: BorderStyle.Solid + }).margin({ top: 4 }) + Text('').height(67).border({ + width: { left: '0', right: 4, top: '0', bottom: '0' }, + color: Color.White, + radius: 2, + style: BorderStyle.Dotted + }).margin({ top: 4 }) + } + }.position({ + x: this.focusPointVal[0] + 56.6, + y: this.focusPointVal[1] - 73 + }) + } + // 曝光图标 + Image($r('app.media.ic_public_brightness')).size({ width: 24, height: 24 }) + .position({ + x: this.focusPointVal[0] + 10, + y: this.focusPointVal[1] - 30 + }) + }.zIndex(99) + + } + } +} diff --git a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/ets/views/modeSwitchPage.ets b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/ets/views/modeSwitchPage.ets index 7e7c70c54fef800c50618f15d60083e1158772bb..8cfe83bb120290628a3ed37eb92ee1400fbcd944 100644 --- a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/ets/views/modeSwitchPage.ets +++ b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/ets/views/modeSwitchPage.ets @@ -15,20 +15,16 @@ // 反转摄像头_多机位_拍照_摄像 -// import { isRecodeStopDialog } from '../Dialog/isRecodeStopDialog' -// -// import { MultiCameraDialog } from '../Dialog/MultiCameraDialog' -// import { PortraitCameraDialog } from '../Dialog/PortraitCameraDialog' import DateTimeUtil from '../model/DateTimeUtil' import Logger from '../model/Logger' import cameraDemo from 'libentry.so' -// import CameraService from '../model/CameraService' import mediaLibrary from '@ohos.multimedia.mediaLibrary'; import image from '@ohos.multimedia.image'; import media from '@ohos.multimedia.media' import MediaUtils from '../model/MediaUtils' +import deviceInfo from '@ohos.deviceInfo'; import AVRecorder from '@ohos.multimedia.media' import fileio from '@ohos.fileio' @@ -47,31 +43,30 @@ export struct modeSwitchPage { @State mSurfaceId: string = '' private mReceiver: image.ImageReceiver = undefined private videoRecorder: media.AVRecorder = undefined - private videoConfig: AVRecorder.AVRecorderConfig = { - audioSourceType: 1, - videoSourceType: 1, + private videoConfig: media.AVRecorderConfig = { + audioSourceType: media.AudioSourceType.AUDIO_SOURCE_TYPE_MIC, + videoSourceType: media.VideoSourceType.VIDEO_SOURCE_TYPE_SURFACE_YUV, profile: { audioBitrate: 48000, audioChannels: 2, - // @ts-ignore - audioCodec: 'audio/mp4a-latm', + audioCodec: media.CodecMimeType.AUDIO_AAC, audioSampleRate: 48000, - durationTime: 1000, - // @ts-ignore - fileFormat: 'mp4', - videoBitrate: 3000000, - // @ts-ignore - videoCodec: 'video/avc', + fileFormat: media.ContainerFormatType.CFT_MPEG_4, + videoBitrate: 512000, + videoCodec: media.CodecMimeType.VIDEO_AVC, videoFrameWidth: 640, videoFrameHeight: 480, videoFrameRate: 30 }, - url: 'file:///data/media/01.mp4', - orientationHint: 0, - maxSize: 100, - maxDuration: 500, + url: '', rotation: 0 - } + }; + private photoRotationMap = { + rotation0: 0, + rotation90: 90, + rotation180: 180, + rotation270: 270, + }; // 相机摄像头 @Link cameraDeviceIndex: number // surfaceID值 @@ -188,7 +183,25 @@ export struct modeSwitchPage { this.videoConfig.url = `fd://${this.fd}` Logger.info(this.tag, `getVideoSurfaceID videoConfig.url : ${this.videoConfig.url }`) - this.videoConfig.profile.videoFrameRate = 15 + + if (deviceInfo.deviceType == 'default') { + Logger.info(this.tag, `deviceType = default`) + this.videoConfig.videoSourceType = media.VideoSourceType.VIDEO_SOURCE_TYPE_SURFACE_ES + } + if (deviceInfo.deviceType == 'phone') { + Logger.info(this.tag, `deviceType = phone`) + this.videoConfig.videoSourceType = media.VideoSourceType.VIDEO_SOURCE_TYPE_SURFACE_YUV + this.videoConfig.profile.videoCodec = media.CodecMimeType.VIDEO_MPEG4; + this.videoConfig.rotation = this.photoRotationMap.rotation90; + } + if (deviceInfo.deviceType == 'tablet') { + Logger.info(this.tag, `deviceType = tablet`) + this.videoConfig.videoSourceType = media.VideoSourceType.VIDEO_SOURCE_TYPE_SURFACE_YUV + } + this.videoConfig.profile.videoFrameWidth = cameraDemo.getVideoFrameWidth(); + this.videoConfig.profile.videoFrameHeight = cameraDemo.getVideoFrameHeight(); + this.videoConfig.profile.videoFrameRate = cameraDemo.getVideoFrameRate(); + Logger.info(this.tag, `getVideoSurfaceID 111`) await this.videoRecorder.prepare(this.videoConfig) Logger.info(this.tag, `getVideoSurfaceID 222`) @@ -255,12 +268,7 @@ export struct modeSwitchPage { } // 判断录像或者照片模式 - async isVideoPhotoFn() { - //this.mReceiver = image.createImageReceiver(640, 480, 2000, 8) - // @ts-ignore - //this.videoId = this.mReceiver.getReceivingSurfaceId(); - - if (this.modelBagCol == 'photo') { + async isVideoPhotoFn() {if (this.modelBagCol == 'photo') { if(this.mReceiver) {} else { this.createImageReceiver() } @@ -273,8 +281,6 @@ export struct modeSwitchPage { } cameraDemo.startPhotoOrVideo(this.modelBagCol, this.mSurfaceId) - - //cameraDemo.startPhotoOrVideo(this.modelBagCol, this.videoId) } else if (this.modelBagCol == 'video') { this.isModeBol = false if (this.timer) { @@ -285,12 +291,6 @@ export struct modeSwitchPage { cameraDemo.startPhotoOrVideo(this.modelBagCol, this.videoId) cameraDemo.videoOutputStart() this.videoRecorder.start() -// cameraDemo.startPhotoOrVideo(this.modelBagCol).then(() => { -// // 计时器 -// this.timer = setInterval(() => { -// this.videoRecodeTime += 1000 -// }, 1000) -// }) } } @@ -453,7 +453,7 @@ export struct modeSwitchPage { .height('200px') .backgroundColor('rgba(255,255,255,0.20)') .onClick(() => { - //CameraService.takePicture() + cameraDemo.startPhotoOrVideo(this.modelBagCol, this.videoId) }) }.position({ x: '10%', y: '82%' }) @@ -540,10 +540,7 @@ export struct modeSwitchPage { await this.videoRecorder.stop() await this.videoRecorder.release() } -// if (this.videoOutput) { -// await this.videoOutput.stop() -// await this.videoOutput.release() -// } + cameraDemo.videoOutputStopAndRelease(); if (this.fileAsset) { await this.fileAsset.close(this.fd) return this.fileAsset diff --git a/frameworks/native/ndk/impl/camera_manager_impl.cpp b/frameworks/native/ndk/impl/camera_manager_impl.cpp index 609685e7bbb53d61081ec315f58721e0fd99929f..c65e6f970be1e0edbcb85f40d51cecdcaaed065a 100644 --- a/frameworks/native/ndk/impl/camera_manager_impl.cpp +++ b/frameworks/native/ndk/impl/camera_manager_impl.cpp @@ -107,6 +107,7 @@ Camera_ErrorCode Camera_Manager::GetSupportedCameras(Camera_Device** cameras, ui outCameras[i].cameraType = static_cast(cameraObjList[i]->GetCameraType()); outCameras[i].connectionType = static_cast(cameraObjList[i]->GetConnectionType()); } + *size = cameraSize; *cameras = outCameras; return CAMERA_OK; } diff --git a/frameworks/native/ndk/impl/capture_session_impl.cpp b/frameworks/native/ndk/impl/capture_session_impl.cpp index b27a0bdfddb9fb5390425045e0fa68cf640d031a..5d47aab00e7a0303913894c42ebfea8014b495c4 100644 --- a/frameworks/native/ndk/impl/capture_session_impl.cpp +++ b/frameworks/native/ndk/impl/capture_session_impl.cpp @@ -160,16 +160,17 @@ Camera_ErrorCode Camera_CaptureSession::IsVideoStabilizationModeSupported(Camera Camera_ErrorCode Camera_CaptureSession::GetVideoStabilizationMode(Camera_VideoStabilizationMode* mode) { MEDIA_DEBUG_LOG("Camera_CaptureSession::GetVideoStabilizationMode is called"); - VideoStabilizationMode innerVideoStabilizationMode = static_cast(*mode); - int32_t ret = innerCaptureSession_->GetActiveVideoStabilizationMode(innerVideoStabilizationMode); - return FrameworkToNdkCameraError(ret); + + *mode = static_cast(innerCaptureSession_->GetActiveVideoStabilizationMode()); + return CAMERA_OK; } Camera_ErrorCode Camera_CaptureSession::SetVideoStabilizationMode(Camera_VideoStabilizationMode mode) { MEDIA_DEBUG_LOG("Camera_CaptureSession::SetVideoStabilizationMode is called"); + VideoStabilizationMode innerVideoStabilizationMode = static_cast(mode); - int32_t ret = innerCaptureSession_->IsVideoStabilizationModeSupported(innerVideoStabilizationMode); + int32_t ret = innerCaptureSession_->SetVideoStabilizationMode(innerVideoStabilizationMode); return FrameworkToNdkCameraError(ret); } @@ -194,7 +195,11 @@ Camera_ErrorCode Camera_CaptureSession::GetZoomRatio(float* zoom) Camera_ErrorCode Camera_CaptureSession::SetZoomRatio(float zoom) { MEDIA_DEBUG_LOG("Camera_CaptureSession::SetZoomRatio is called"); + + innerCaptureSession_->LockForControl(); int32_t ret = innerCaptureSession_->SetZoomRatio(zoom); + innerCaptureSession_->UnlockForControl(); + if (ret != CameraErrorCode::SUCCESS) { return CAMERA_SERVICE_FATAL_ERROR; } @@ -215,19 +220,20 @@ Camera_ErrorCode Camera_CaptureSession::IsFocusModeSupported(Camera_FocusMode fo Camera_ErrorCode Camera_CaptureSession::GetFocusMode(Camera_FocusMode* focusMode) { MEDIA_DEBUG_LOG("Camera_CaptureSession::GetFocusMode is called"); - FocusMode innerFocusMode = static_cast(*focusMode); - int32_t ret = innerCaptureSession_->GetFocusMode(innerFocusMode); - if (ret != CameraErrorCode::SUCCESS) { - return CAMERA_SERVICE_FATAL_ERROR; - } - return FrameworkToNdkCameraError(ret); + + *focusMode = static_cast(innerCaptureSession_->GetFocusMode()); + return CAMERA_OK; } Camera_ErrorCode Camera_CaptureSession::SetFocusMode(Camera_FocusMode focusMode) { MEDIA_DEBUG_LOG("Camera_CaptureSession::SetFocusMode is called"); + FocusMode innerFocusMode = static_cast(focusMode); + innerCaptureSession_->LockForControl(); int32_t ret = innerCaptureSession_->SetFocusMode(innerFocusMode); + innerCaptureSession_->UnlockForControl(); + if (ret != CameraErrorCode::SUCCESS) { return CAMERA_SERVICE_FATAL_ERROR; } @@ -237,10 +243,15 @@ Camera_ErrorCode Camera_CaptureSession::SetFocusMode(Camera_FocusMode focusMode) Camera_ErrorCode Camera_CaptureSession::SetFocusPoint(Camera_Point focusPoint) { MEDIA_DEBUG_LOG("Camera_CaptureSession::SetFocusPoint is called"); + Point innerFocusPoint; innerFocusPoint.x = focusPoint.x; innerFocusPoint.y = focusPoint.y; + + innerCaptureSession_->LockForControl(); int32_t ret = innerCaptureSession_->SetFocusPoint(innerFocusPoint); + innerCaptureSession_->UnlockForControl(); + if (ret != CameraErrorCode::SUCCESS) { return CAMERA_SERVICE_FATAL_ERROR; } @@ -250,14 +261,11 @@ Camera_ErrorCode Camera_CaptureSession::SetFocusPoint(Camera_Point focusPoint) Camera_ErrorCode Camera_CaptureSession::GetFocusPoint(Camera_Point* focusPoint) { MEDIA_DEBUG_LOG("Camera_CaptureSession::GetFocusPoint is called"); - Point innerFocusPoint; - innerFocusPoint.x = focusPoint->x; - innerFocusPoint.y = focusPoint->y; - int32_t ret = innerCaptureSession_->GetFocusPoint(innerFocusPoint); - if (ret != CameraErrorCode::SUCCESS) { - return CAMERA_SERVICE_FATAL_ERROR; - } - return FrameworkToNdkCameraError(ret); + Point innerFocusPoint = innerCaptureSession_->GetFocusPoint(); + (*focusPoint).x = innerFocusPoint.x; + (*focusPoint).y = innerFocusPoint.y; + + return CAMERA_OK; } Camera_ErrorCode Camera_CaptureSession::HasFlash(bool* hasFlash) @@ -290,8 +298,12 @@ Camera_ErrorCode Camera_CaptureSession::GetFlashMode(Camera_FlashMode* flashMode Camera_ErrorCode Camera_CaptureSession::SetFlashMode(Camera_FlashMode flashMode) { MEDIA_DEBUG_LOG("Camera_CaptureSession::SetFlashMode is called"); + FlashMode innerFlashMode = static_cast(flashMode); + innerCaptureSession_->LockForControl(); int32_t ret = innerCaptureSession_->SetFlashMode(innerFlashMode); + innerCaptureSession_->UnlockForControl(); + if (ret != CameraErrorCode::SUCCESS) { return CAMERA_SERVICE_FATAL_ERROR; } @@ -312,19 +324,20 @@ Camera_ErrorCode Camera_CaptureSession::IsExposureModeSupported(Camera_ExposureM Camera_ErrorCode Camera_CaptureSession::GetExposureMode(Camera_ExposureMode* exposureMode) { MEDIA_DEBUG_LOG("Camera_CaptureSession::GetExposureMode is called"); - ExposureMode innerExposureMode = static_cast(*exposureMode); - int32_t ret = innerCaptureSession_->GetExposureMode(innerExposureMode); - if (ret != CameraErrorCode::SUCCESS) { - return CAMERA_SERVICE_FATAL_ERROR; - } - return FrameworkToNdkCameraError(ret); + + *exposureMode = static_cast(innerCaptureSession_->GetExposureMode()); + return CAMERA_OK; } Camera_ErrorCode Camera_CaptureSession::SetExposureMode(Camera_ExposureMode exposureMode) { MEDIA_DEBUG_LOG("Camera_CaptureSession::SetExposureMode is called"); + ExposureMode innerExposureMode = static_cast(exposureMode); + innerCaptureSession_->LockForControl(); int32_t ret = innerCaptureSession_->SetExposureMode(innerExposureMode); + innerCaptureSession_->UnlockForControl(); + if (ret != CameraErrorCode::SUCCESS) { return CAMERA_SERVICE_FATAL_ERROR; } @@ -334,14 +347,11 @@ Camera_ErrorCode Camera_CaptureSession::SetExposureMode(Camera_ExposureMode expo Camera_ErrorCode Camera_CaptureSession::GetMeteringPoint(Camera_Point* point) { MEDIA_DEBUG_LOG("Camera_CaptureSession::GetMeteringPoint is called"); - Point innerExposurePoint; - innerExposurePoint.x = point->x; - innerExposurePoint.y = point->y; - int32_t ret = innerCaptureSession_->GetMeteringPoint(innerExposurePoint); - if (ret != CameraErrorCode::SUCCESS) { - return CAMERA_SERVICE_FATAL_ERROR; - } - return FrameworkToNdkCameraError(ret); + + Point innerFocusPoint = innerCaptureSession_->GetMeteringPoint(); + (*point).x = innerFocusPoint.x; + (*point).y = innerFocusPoint.y; + return CAMERA_OK; } Camera_ErrorCode Camera_CaptureSession::SetMeteringPoint(Camera_Point point) @@ -350,7 +360,11 @@ Camera_ErrorCode Camera_CaptureSession::SetMeteringPoint(Camera_Point point) Point innerExposurePoint; innerExposurePoint.x = point.x; innerExposurePoint.y = point.y; + + innerCaptureSession_->LockForControl(); int32_t ret = innerCaptureSession_->SetMeteringPoint(innerExposurePoint); + innerCaptureSession_->UnlockForControl(); + if (ret != CameraErrorCode::SUCCESS) { return CAMERA_SERVICE_FATAL_ERROR; } @@ -361,24 +375,22 @@ Camera_ErrorCode Camera_CaptureSession::GetExposureBiasRange(float* minExposureB float* maxExposureBias, float* step) { MEDIA_DEBUG_LOG("Camera_CaptureSession::GetExposureBiasRange is called"); - std::vector vecExposureBiasList; - int32_t ret = innerCaptureSession_->GetExposureBiasRange(vecExposureBiasList); - if (ret != CameraErrorCode::SUCCESS) { - return CAMERA_SERVICE_FATAL_ERROR; - } - size_t len = vecExposureBiasList.size(); - for (size_t i = 0; i < len; i++) { - *minExposureBias = vecExposureBiasList[0]; - *maxExposureBias = vecExposureBiasList[0]; - } - return FrameworkToNdkCameraError(ret); + std::vector vecExposureBiasList = innerCaptureSession_->GetExposureBiasRange(); + *minExposureBias = vecExposureBiasList[0]; + *maxExposureBias = vecExposureBiasList[1]; + + return CAMERA_OK; } Camera_ErrorCode Camera_CaptureSession::SetExposureBias(float exposureBias) { MEDIA_DEBUG_LOG("Camera_CaptureSession::SetExposureBias is called"); + + innerCaptureSession_->LockForControl(); int32_t ret = innerCaptureSession_->SetExposureBias(exposureBias); + innerCaptureSession_->UnlockForControl(); + if (ret != CameraErrorCode::SUCCESS) { return CAMERA_SERVICE_FATAL_ERROR; } @@ -388,11 +400,10 @@ Camera_ErrorCode Camera_CaptureSession::SetExposureBias(float exposureBias) Camera_ErrorCode Camera_CaptureSession::GetExposureBias(float* exposureBias) { MEDIA_DEBUG_LOG("Camera_CaptureSession::GetExposureBias is called"); - int32_t ret = innerCaptureSession_->GetExposureValue(*exposureBias); - if (ret != CameraErrorCode::SUCCESS) { - return CAMERA_SERVICE_FATAL_ERROR; - } - return FrameworkToNdkCameraError(ret); + + *exposureBias = innerCaptureSession_->GetExposureValue(); + + return CAMERA_OK; } Camera_ErrorCode Camera_CaptureSession::AddVideoOutput(Camera_VideoOutput* videoOutput)