From dfa378fcf9e11672f45bd957bb438ea89e6577a2 Mon Sep 17 00:00:00 2001 From: sunchao Date: Thu, 18 Dec 2025 15:58:10 +0800 Subject: [PATCH 1/2] add videoMode enableMirror Signed-off-by: sunchao --- .../entry/src/main/cpp/camera_manager.cpp | 7 +++++++ .../entry/src/main/cpp/camera_manager.cpp | 7 +++++++ .../entry/src/main/cpp/camera_manager.cpp | 7 +++++++ .../entry/src/main/cpp/camera_manager.cpp | 6 ++++++ 4 files changed, 27 insertions(+) diff --git a/CameraKit/NDKMinResolutionSample/entry/src/main/cpp/camera_manager.cpp b/CameraKit/NDKMinResolutionSample/entry/src/main/cpp/camera_manager.cpp index f232aa3bd..677515768 100644 --- a/CameraKit/NDKMinResolutionSample/entry/src/main/cpp/camera_manager.cpp +++ b/CameraKit/NDKMinResolutionSample/entry/src/main/cpp/camera_manager.cpp @@ -836,6 +836,13 @@ Camera_ErrorCode NDKCamera::StartVideo(char *videoId, char *photoId) CreateVideoOutput(videoId); AddVideoOutput(); SessionCommitConfig(); + bool isMirrorSupported = false; + ret = OH_VideoOutput_IsMirrorSupported(videoOutput_, &isMirrorSupported); + OH_LOG_INFO(LOG_APP, "VideoOutput IsMirrorSupported: %{public}d", isMirrorSupported); + if (isMirrorSupported) { + OH_VideoOutput_EnableMirror(videoOutput_, isMirrorSupported); + } + SessionStart(); VideoOutputRegisterCallback(); return ret; diff --git a/CameraKit/NDKPhotoVideoSample/entry/src/main/cpp/camera_manager.cpp b/CameraKit/NDKPhotoVideoSample/entry/src/main/cpp/camera_manager.cpp index da2d640d6..2e91a40c0 100644 --- a/CameraKit/NDKPhotoVideoSample/entry/src/main/cpp/camera_manager.cpp +++ b/CameraKit/NDKPhotoVideoSample/entry/src/main/cpp/camera_manager.cpp @@ -678,6 +678,13 @@ Camera_ErrorCode NDKCamera::StartVideo(char *videoId, char *photoId) IsVideoStabilizationModeSupportedFn(mode); } EnableControlCenter(isControl); + bool isMirrorSupported = false; + ret = OH_VideoOutput_IsMirrorSupported(videoOutput_, &isMirrorSupported); + OH_LOG_INFO(LOG_APP, "VideoOutput IsMirrorSupported: %{public}d", isMirrorSupported); + if (isMirrorSupported) { + OH_VideoOutput_EnableMirror(videoOutput_, isMirrorSupported); + } + SessionStart(); VideoOutputRegisterCallback(); return ret; diff --git a/CameraKit/NDKPreconfigSample/entry/src/main/cpp/camera_manager.cpp b/CameraKit/NDKPreconfigSample/entry/src/main/cpp/camera_manager.cpp index 8ae387968..9b56d2a4d 100644 --- a/CameraKit/NDKPreconfigSample/entry/src/main/cpp/camera_manager.cpp +++ b/CameraKit/NDKPreconfigSample/entry/src/main/cpp/camera_manager.cpp @@ -1178,6 +1178,13 @@ Camera_ErrorCode NDKCamera::StartVideo(char *videoId, char *photoId) DRAWING_LOGD("ERROR: SessionCommitConfig failed! ret=%{public}d", ret); return ret; } + bool isMirrorSupported = false; + ret = OH_VideoOutput_IsMirrorSupported(videoOutput_, &isMirrorSupported); + OH_LOG_INFO(LOG_APP, "VideoOutput IsMirrorSupported: %{public}d", isMirrorSupported); + if (isMirrorSupported) { + OH_VideoOutput_EnableMirror(videoOutput_, isMirrorSupported); + } + ret = SessionStart(); if (ret != CAMERA_OK) { OH_LOG_ERROR(LOG_APP, "CRITICAL: SessionStart failed with ret: %{public}d", ret); diff --git a/CameraKit/NDKPreviewImageSample/entry/src/main/cpp/camera_manager.cpp b/CameraKit/NDKPreviewImageSample/entry/src/main/cpp/camera_manager.cpp index c25808d07..0e854e496 100644 --- a/CameraKit/NDKPreviewImageSample/entry/src/main/cpp/camera_manager.cpp +++ b/CameraKit/NDKPreviewImageSample/entry/src/main/cpp/camera_manager.cpp @@ -758,6 +758,12 @@ Camera_ErrorCode NDKCamera::VideoOutputStart(char *videoId) ret = OH_CaptureSession_AddVideoOutput(captureSession_, videoOutput_); ret = OH_CaptureSession_CommitConfig(captureSession_); + bool isMirrorSupported = false; + ret = OH_VideoOutput_IsMirrorSupported(videoOutput_, &isMirrorSupported); + OH_LOG_INFO(LOG_APP, "VideoOutput IsMirrorSupported: %{public}d", isMirrorSupported); + if (isMirrorSupported) { + OH_VideoOutput_EnableMirror(videoOutput_, isMirrorSupported); + } ret = OH_CaptureSession_Start(captureSession_); ret = OH_VideoOutput_Start(videoOutput_); if (ret == CAMERA_OK) { -- Gitee From 9ce9c744b2b9832a13ddd7472b040619fd427598 Mon Sep 17 00:00:00 2001 From: sunchao Date: Wed, 14 Jan 2026 17:28:40 +0800 Subject: [PATCH 2/2] sync Signed-off-by: sunchao --- .idea/.gitignore | 3 - .idea/.name | 1 - .idea/guide-snippets.iml | 8 - .idea/modules.xml | 8 - .idea/vcs.xml | 6 - .../build-profile.json5 | 24 +- .../entry/build-profile.json5 | 2 +- .../entry/src/main/cpp/camera_manager.cpp | 4 +- .../build-profile.json5 | 24 +- .../entry/build-profile.json5 | 2 +- .../entry/src/main/cpp/camera_manager.cpp | 292 ++++-- .../entry/src/main/cpp/camera_manager.h | 7 +- .../entry/src/main/cpp/main.cpp | 75 +- .../src/main/cpp/types/libentry/index.d.ts | 3 +- .../entry/src/main/ets/pages/Index.ets | 32 +- .../src/main/ets/views/ModeSwitchPage.ets | 131 ++- .../NDKPhotoVideoSample/build-profile.json5 | 24 +- .../entry/build-profile.json5 | 2 +- .../entry/src/main/cpp/camera_manager.cpp | 517 +++++---- .../entry/src/main/cpp/camera_manager.h | 4 +- .../entry/src/main/cpp/main.cpp | 47 +- .../src/main/cpp/types/libentry/index.d.ts | 3 +- .../entry/src/main/ets/pages/Index.ets | 15 +- .../entry/src/main/ets/views/HdrVideoPage.ets | 2 + .../src/main/ets/views/ModeSwitchPage.ets | 115 +- .../NDKPreconfigSample/build-profile.json5 | 24 +- .../entry/build-profile.json5 | 2 +- .../entry/src/main/cpp/camera_manager.cpp | 978 +++++------------- .../entry/src/main/cpp/camera_manager.h | 3 +- .../entry/src/main/cpp/main.cpp | 20 +- .../src/main/cpp/types/libentry/index.d.ts | 2 +- .../entry/src/main/ets/pages/Index.ets | 55 +- .../src/main/ets/views/ModeSwitchPage.ets | 120 ++- .../NDKPreviewImageSample/build-profile.json5 | 54 +- .../entry/build-profile.json5 | 2 +- .../entry/src/main/cpp/camera_manager.cpp | 58 +- .../entry/src/main/cpp/camera_manager.h | 20 + .../entry/src/main/ets/pages/Index.ets | 78 +- 38 files changed, 1457 insertions(+), 1310 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/.name delete mode 100644 .idea/guide-snippets.iml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 26d33521a..000000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml diff --git a/.idea/.name b/.idea/.name deleted file mode 100644 index 5501d527e..000000000 --- a/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -CodecUtility.ets \ No newline at end of file diff --git a/.idea/guide-snippets.iml b/.idea/guide-snippets.iml deleted file mode 100644 index 610219404..000000000 --- a/.idea/guide-snippets.iml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index db8aa031e..000000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1ddfb..000000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/CameraKit/NDKDeferredCaptureSample/build-profile.json5 b/CameraKit/NDKDeferredCaptureSample/build-profile.json5 index 375a8f182..33fb61731 100644 --- a/CameraKit/NDKDeferredCaptureSample/build-profile.json5 +++ b/CameraKit/NDKDeferredCaptureSample/build-profile.json5 @@ -19,14 +19,22 @@ { "name": "default", "signingConfig": "default", - "compatibleSdkVersion": "6.0.0(20)", - "runtimeOS": "HarmonyOS", - "targetSdkVersion": "6.0.0(20)", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } + "compileSdkVersion": 23, + "compatibleSdkVersion": 23, + "runtimeOS": "OpenHarmony" + } + ], + "signingConfigs": [ + { + "name": "default", + "material": { + "certpath": "C:/Users/wWX1366912/.ohos/config/openharmony/default_NDKDeferredCaptureSample_4HOBCOHqMEF5cMvmR_b83nO115LMo6bn4xc9qSiyCqs=.cer", + "keyAlias": "debugKey", + "keyPassword": "0000001BBAA056C210DDCBAF3505ABB38E1BEB18C1D75F9C561CF5CA8E8A36C877A91F9CAE4AECC15818FA", + "profile": "C:/Users/wWX1366912/.ohos/config/openharmony/default_NDKDeferredCaptureSample_4HOBCOHqMEF5cMvmR_b83nO115LMo6bn4xc9qSiyCqs=.p7b", + "signAlg": "SHA256withECDSA", + "storeFile": "C:/Users/wWX1366912/.ohos/config/openharmony/default_NDKDeferredCaptureSample_4HOBCOHqMEF5cMvmR_b83nO115LMo6bn4xc9qSiyCqs=.p12", + "storePassword": "0000001BFF10F977AF46B1B237FA4F9C88E5ECF2CB358D8D7351905ED753A2207F17C6F0D778E7514E815A" } } ] diff --git a/CameraKit/NDKDeferredCaptureSample/entry/build-profile.json5 b/CameraKit/NDKDeferredCaptureSample/entry/build-profile.json5 index dad51a108..59ad6bb56 100644 --- a/CameraKit/NDKDeferredCaptureSample/entry/build-profile.json5 +++ b/CameraKit/NDKDeferredCaptureSample/entry/build-profile.json5 @@ -37,7 +37,7 @@ "targets": [ { "name": "default", - "runtimeOS": "HarmonyOS" + "runtimeOS": "OpenHarmony" }, { "name": "ohosTest", diff --git a/CameraKit/NDKDeferredCaptureSample/entry/src/main/cpp/camera_manager.cpp b/CameraKit/NDKDeferredCaptureSample/entry/src/main/cpp/camera_manager.cpp index fef78a328..8f69a51b2 100644 --- a/CameraKit/NDKDeferredCaptureSample/entry/src/main/cpp/camera_manager.cpp +++ b/CameraKit/NDKDeferredCaptureSample/entry/src/main/cpp/camera_manager.cpp @@ -820,7 +820,7 @@ Camera_ErrorCode NDKCamera::VideoOutputStart(void) Camera_ErrorCode NDKCamera::StartPhoto(char *mSurfaceId) { Camera_ErrorCode ret = CAMERA_OK; - if (takePictureTimes == 0) { +// if (takePictureTimes == 0) { ret = SessionStop(); if (ret == CAMERA_OK) { OH_LOG_INFO(LOG_APP, "SessionStop success."); @@ -854,7 +854,7 @@ Camera_ErrorCode NDKCamera::StartPhoto(char *mSurfaceId) OH_LOG_INFO(LOG_APP, "startPhoto SessionCommitConfig ret = %{public}d.", ret); ret = SessionStart(); OH_LOG_INFO(LOG_APP, "startPhoto SessionStart ret = %{public}d.", ret); - } +// } ret = TakePicture(); OH_LOG_INFO(LOG_APP, "startPhoto OH_PhotoOutput_Capture ret = %{public}d.", ret); if (ret_ != CAMERA_OK) { diff --git a/CameraKit/NDKMinResolutionSample/build-profile.json5 b/CameraKit/NDKMinResolutionSample/build-profile.json5 index 375a8f182..b724ff56a 100644 --- a/CameraKit/NDKMinResolutionSample/build-profile.json5 +++ b/CameraKit/NDKMinResolutionSample/build-profile.json5 @@ -19,14 +19,22 @@ { "name": "default", "signingConfig": "default", - "compatibleSdkVersion": "6.0.0(20)", - "runtimeOS": "HarmonyOS", - "targetSdkVersion": "6.0.0(20)", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } + "compileSdkVersion": 23, + "compatibleSdkVersion": 23, + "runtimeOS": "OpenHarmony" + } + ], + "signingConfigs": [ + { + "name": "default", + "material": { + "certpath": "C:/Users/wWX1366912/.ohos/config/openharmony/default_NDKMinResolutionSample_0CmYkEKuEBOPva0auLTOqVWFVJI1hAFYzsqWXL62_L0=.cer", + "keyAlias": "debugKey", + "keyPassword": "0000001BE6F1B1728C866736BC1C64560D928A37DDBB996086F1E129A1D39F5C654C4B045877EE3C601F4E", + "profile": "C:/Users/wWX1366912/.ohos/config/openharmony/default_NDKMinResolutionSample_0CmYkEKuEBOPva0auLTOqVWFVJI1hAFYzsqWXL62_L0=.p7b", + "signAlg": "SHA256withECDSA", + "storeFile": "C:/Users/wWX1366912/.ohos/config/openharmony/default_NDKMinResolutionSample_0CmYkEKuEBOPva0auLTOqVWFVJI1hAFYzsqWXL62_L0=.p12", + "storePassword": "0000001B30EF5BAF373BDB8F44D4A188C14835AF8A7C1278B21F6241C278486F9B08EC882F283F1E22F691" } } ] diff --git a/CameraKit/NDKMinResolutionSample/entry/build-profile.json5 b/CameraKit/NDKMinResolutionSample/entry/build-profile.json5 index c143a076c..4a362e10b 100644 --- a/CameraKit/NDKMinResolutionSample/entry/build-profile.json5 +++ b/CameraKit/NDKMinResolutionSample/entry/build-profile.json5 @@ -26,7 +26,7 @@ "targets": [ { "name": "default", - "runtimeOS": "HarmonyOS" + "runtimeOS": "OpenHarmony" }, { "name": "ohosTest", diff --git a/CameraKit/NDKMinResolutionSample/entry/src/main/cpp/camera_manager.cpp b/CameraKit/NDKMinResolutionSample/entry/src/main/cpp/camera_manager.cpp index 677515768..b1328b70f 100644 --- a/CameraKit/NDKMinResolutionSample/entry/src/main/cpp/camera_manager.cpp +++ b/CameraKit/NDKMinResolutionSample/entry/src/main/cpp/camera_manager.cpp @@ -31,7 +31,8 @@ std::mutex NDKCamera::mtx_; const int32_t NUM_1080P_WIDTH = 1920; const int32_t NUM_1080P_HEIGHT = 1080; -NDKCamera::NDKCamera(char *str, uint32_t focusMode, uint32_t cameraDeviceIndex, uint32_t width, uint32_t height) +NDKCamera::NDKCamera(char *str, uint32_t focusMode, uint32_t cameraDeviceIndex, uint32_t width, uint32_t height, + char *videoId, char *photoId, Camera_SceneMode sceneMode) : previewSurfaceId_(str), cameras_(nullptr), focusMode_(focusMode), @@ -42,7 +43,7 @@ NDKCamera::NDKCamera(char *str, uint32_t focusMode, uint32_t cameraDeviceIndex, size_(0), isCameraMuted_(nullptr), profile_(nullptr), - photoSurfaceId_(nullptr), + photoSurfaceId_(photoId), previewOutput_(nullptr), photoOutput_(nullptr), metaDataObjectType_(nullptr), @@ -55,7 +56,9 @@ NDKCamera::NDKCamera(char *str, uint32_t focusMode, uint32_t cameraDeviceIndex, step_(0), ret_(CAMERA_OK), desiredPreviewW_(width), - desiredPreviewH_(height) + desiredPreviewH_(height), + videoSurfaceId_(videoId), + sceneMode_(sceneMode) { valid_ = false; ReleaseCamera(); @@ -68,11 +71,16 @@ NDKCamera::NDKCamera(char *str, uint32_t focusMode, uint32_t cameraDeviceIndex, if (captureSession_ == nullptr || ret != CAMERA_OK) { OH_LOG_ERROR(LOG_APP, "Create captureSession failed."); } - ret = OH_CaptureSession_SetSessionMode(captureSession_, Camera_SceneMode::NORMAL_PHOTO); + ret = OH_CaptureSession_SetSessionMode(captureSession_, sceneMode_); CaptureSessionRegisterCallback(); GetSupportedCameras(); GetSupportedOutputCapability(); CreatePreviewOutput(); + if (sceneMode_ == Camera_SceneMode::NORMAL_VIDEO) { + CreateVideoOutput(videoId); + } else { + CreatePhotoOutput(photoSurfaceId_); + } CreateCameraInput(); CameraInputOpen(); CameraManagerRegisterCallback(); @@ -261,7 +269,7 @@ Camera_ErrorCode NDKCamera::SetVideoResolution(uint32_t width, uint32_t height) desiredVideoW_ = width; desiredVideoH_ = height; cachedVideoProfile_ = videoProfile; - OH_LOG_INFO(LOG_APP, "SetVideoResolution cachedPreviewProfile1 %{public}p", cachedPreviewProfile_); + OH_LOG_INFO(LOG_APP, "SetVideoResolution cachedVideoProfile1 %{public}p", cachedVideoProfile_); OH_LOG_INFO(LOG_APP, "SetVideoResolution desiredPreviewW_ desiredPreviewH_: %{public}u*%{public}u", desiredPreviewW_, desiredPreviewH_); return CAMERA_OK; @@ -474,6 +482,24 @@ Camera_ErrorCode NDKCamera::SessionFlowFn(void) // Add previewOutput to the session OH_LOG_INFO(LOG_APP, "session add Preview Output."); ret = OH_CaptureSession_AddPreviewOutput(captureSession_, previewOutput_); + + if (sceneMode_ == Camera_SceneMode::NORMAL_VIDEO) { + if (videoOutput_ == nullptr) { + OH_LOG_INFO(LOG_APP, "videoOutput_ is nullptr"); + } + ret = OH_CaptureSession_AddVideoOutput(captureSession_, videoOutput_); + bool isMirrorSupported = false; + ret = OH_VideoOutput_IsMirrorSupported(videoOutput_, &isMirrorSupported); + OH_LOG_INFO(LOG_APP, "VideoOutput IsMirrorSupported: %{public}d", isMirrorSupported); + if (isMirrorSupported) { + OH_VideoOutput_EnableMirror(videoOutput_, isMirrorSupported); + } + } else { + if (photoOutput_ == nullptr) { + OH_LOG_INFO(LOG_APP, "photoOutput_ is nullptr"); + } + ret = AddPhotoOutput(); + } // Submit configuration information OH_LOG_INFO(LOG_APP, "session commitConfig"); @@ -508,6 +534,7 @@ Camera_ErrorCode NDKCamera::PreviewOutputGetSupportedFrameRates(Camera_PreviewOu if (ret != CAMERA_OK) { OH_LOG_ERROR(LOG_APP, "OH_PreviewOutput_GetSupportedFrameRates failed."); return CAMERA_INVALID_ARGUMENT; + return CAMERA_INVALID_ARGUMENT; } for (uint32_t i = 0; i < *size; i++) { OH_LOG_DEBUG(LOG_APP, "PreviewOutputGetSupportedFrameRates: SupportedFrameRates min %{public}d", @@ -611,35 +638,53 @@ Camera_ErrorCode NDKCamera::CreatePreviewOutput(void) selectedProfile = temp; } previewProfile_ = selectedProfile; - videoProfile_ = cachedVideoProfile_ ? cachedVideoProfile_ : cameraOutputCapability_->videoProfiles[0]; +// videoProfile_ = cachedVideoProfile_ ? cachedVideoProfile_ : cameraOutputCapability_->videoProfiles[0]; OH_LOG_INFO(LOG_APP, "CreatePreviewOutput cachedVideoProfile %{public}p", videoProfile_); +// OH_LOG_INFO(LOG_APP, "CreatePreviewOutput videoProfile_%{public}u*%{public}u", videoProfile_->size.width, +// videoProfile_->size.height); OH_LOG_INFO(LOG_APP, "CreatePreviewOutput previewProfile_%{public}u*%{public}u", previewProfile_->size.width, previewProfile_->size.height); if (previewProfile_ == nullptr) { OH_LOG_ERROR(LOG_APP, "CreatePreviewOutput Get previewProfiles failed."); return CAMERA_INVALID_ARGUMENT; } - - for (int i = 0; i < cameraOutputCapability_->videoProfilesSize; i++) { - if (cachedVideoProfile_ == nullptr) { - videoProfile_ = cameraOutputCapability_->videoProfiles[i]; + for (int i = 0; i < cameraOutputCapability_->photoProfilesSize; i++) { + profile_ = cameraOutputCapability_->photoProfiles[i]; + OH_LOG_INFO(LOG_APP, "CreatePreviewOutput photoProfile_%{public}u*%{public}u format: %{public}d", + profile_->size.width, profile_->size.height, profile_->format); + if (profile_->size.width == selectedProfile->size.width && + profile_->size.height == selectedProfile->size.height) { + break; } - OH_LOG_INFO(LOG_APP, "CreatePreviewOutputpreviewProfile_%{public}u*%{public}u", previewProfile_->size.width, - previewProfile_->size.height); - OH_LOG_INFO(LOG_APP, "CreatePreviewOutputvideoProfile_%{public}u*%{public}u", videoProfile_->size.width, + } + + for (int i = 0; i < cameraOutputCapability_->videoProfilesSize; i++) { + videoProfile_ = cameraOutputCapability_->videoProfiles[i]; + if (videoProfile_->size.width == selectedProfile->size.width && + videoProfile_->size.height == selectedProfile->size.height) { + OH_LOG_INFO(LOG_APP, "CreatePreviewOutput videoProfile_%{public}u*%{public}u", videoProfile_->size.width, videoProfile_->size.height); - if (AreFloatsEqual(static_cast(previewProfile_->size.width) / previewProfile_->size.height, - static_cast(videoProfile_->size.width) / videoProfile_->size.height)) { - OH_LOG_ERROR(LOG_APP, "CreatePreviewOutput video width %{public}d, height: %{public}d", - videoProfile_->size.width, videoProfile_->size.height); - OH_LOG_ERROR(LOG_APP, "CreatePreviewOutput preview width %{public}f, height: %{public}f", - static_cast(previewProfile_->size.width), static_cast(previewProfile_->size.height)); break; } +// if (cachedVideoProfile_ == nullptr) { +// videoProfile_ = cameraOutputCapability_->videoProfiles[i]; +// } +// OH_LOG_INFO(LOG_APP, "CreatePreviewOutputpreviewProfile_%{public}u*%{public}u", previewProfile_->size.width, +// previewProfile_->size.height); +// OH_LOG_INFO(LOG_APP, "CreatePreviewOutputvideoProfile_%{public}u*%{public}u", videoProfile_->size.width, +// videoProfile_->size.height); +// if (AreFloatsEqual(static_cast(previewProfile_->size.width) / previewProfile_->size.height, +// static_cast(videoProfile_->size.width) / videoProfile_->size.height)) { +// OH_LOG_ERROR(LOG_APP, "CreatePreviewOutput video width %{public}d, height: %{public}d", +// videoProfile_->size.width, videoProfile_->size.height); +// OH_LOG_ERROR(LOG_APP, "CreatePreviewOutput preview width %{public}f, height: %{public}f", +// static_cast(previewProfile_->size.width), static_cast(previewProfile_->size.height)); +// break; +// } } ret_ = OH_CameraManager_CreatePreviewOutput(cameraManager_, previewProfile_, previewSurfaceId_, &previewOutput_); OH_LOG_ERROR(LOG_APP, - "CreatePreviewOutput previewProfile_ video width %{public}d, height: %{public}d, format: {%public}d", + "CreatePreviewOutput previewProfile_ video width %{public}d, height: %{public}d, format: %{public}d", previewProfile_->size.width, previewProfile_->size.height, previewProfile_->format); if (previewSurfaceId_ == nullptr || previewOutput_ == nullptr || ret_ != CAMERA_OK) { OH_LOG_ERROR(LOG_APP, "CreatePreviewOutput failed."); @@ -662,6 +707,10 @@ Camera_ErrorCode NDKCamera::CreatePhotoOutput(char *photoSurfaceId) OH_LOG_ERROR(LOG_APP, "CreatePhotoOutput failed."); return CAMERA_INVALID_ARGUMENT; } + + OH_LOG_ERROR(LOG_APP, + "CreatePhotoOutput Profile_ video width %{public}d, height: %{public}d, format: %{public}d", + profile_->size.width, profile_->size.height, profile_->format); ret_ = OH_CameraManager_CreatePhotoOutput(cameraManager_, profile_, photoSurfaceId, &photoOutput_); if (ret_ != CAMERA_OK || photoOutput_ == nullptr) { @@ -691,9 +740,11 @@ Camera_ErrorCode NDKCamera::CreatePhotoOutputWithoutSurfaceId() Camera_ErrorCode NDKCamera::CreateVideoOutput(char *videoId) { - if (videoProfile_ == nullptr) { - videoProfile_ = cameraOutputCapability_->videoProfiles[0]; - } +// if (cachedVideoProfile_ != nullptr) { +// videoProfile_ = cachedVideoProfile_; +// OH_LOG_INFO(LOG_APP, "CreateVideoOutput use cached profile %{public}u*%{public}u", videoProfile_->size.width, +// videoProfile_->size.height); +// } if (videoProfile_ == nullptr) { OH_LOG_ERROR(LOG_APP, "Get videoProfiles failed."); return CAMERA_INVALID_ARGUMENT; @@ -793,58 +844,59 @@ Camera_ErrorCode NDKCamera::PhotoOutputRelease(void) Camera_ErrorCode NDKCamera::StartVideo(char *videoId, char *photoId) { OH_LOG_INFO(LOG_APP, "StartVideo begin ."); - if (cachedVideoProfile_ != nullptr) { - videoProfile_ = cachedVideoProfile_; - OH_LOG_INFO(LOG_APP, "StartVideo use cached profile %{public}u*%{public}u", videoProfile_->size.width, - videoProfile_->size.height); - } else if (videoProfile_ == nullptr) { - videoProfile_ = cameraOutputCapability_->videoProfiles[0]; - if (!videoProfile_) { - OH_LOG_ERROR(LOG_APP, "StartVideo: fallback profile is null"); - return CAMERA_INVALID_ARGUMENT; - } - } - - Camera_ErrorCode ret = SessionStop(); - if (ret == CAMERA_OK) { - OH_LOG_INFO(LOG_APP, "SessionStop success."); - } else { - OH_LOG_ERROR(LOG_APP, "SessionStop failed. %d ", ret); - } - SessionRelease(); - ret = OH_CameraManager_CreateCaptureSession(cameraManager_, &captureSession_); - if (captureSession_ == nullptr || ret != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "Create captureSession failed."); - } - ret = OH_CaptureSession_SetSessionMode(captureSession_, NORMAL_VIDEO); - CaptureSessionRegisterCallback(); - GetSupportedCameras(); - GetSupportedOutputCapability(); - CreatePreviewOutput(); - CreateCameraInput(); - CameraInputOpen(); - CameraManagerRegisterCallback(); - - ret = SessionBegin(); - if (ret == CAMERA_OK) { - OH_LOG_INFO(LOG_APP, "SessionBegin success."); - } else { - OH_LOG_ERROR(LOG_APP, "SessionBegin failed. %d ", ret); - } - ret = OH_CaptureSession_AddInput(captureSession_, cameraInput_); - ret = OH_CaptureSession_AddPreviewOutput(captureSession_, previewOutput_); - CreateVideoOutput(videoId); - AddVideoOutput(); - SessionCommitConfig(); - bool isMirrorSupported = false; - ret = OH_VideoOutput_IsMirrorSupported(videoOutput_, &isMirrorSupported); - OH_LOG_INFO(LOG_APP, "VideoOutput IsMirrorSupported: %{public}d", isMirrorSupported); - if (isMirrorSupported) { - OH_VideoOutput_EnableMirror(videoOutput_, isMirrorSupported); - } - - SessionStart(); - VideoOutputRegisterCallback(); + Camera_ErrorCode ret = CAMERA_OK; +// if (cachedVideoProfile_ != nullptr) { +// videoProfile_ = cachedVideoProfile_; +// OH_LOG_INFO(LOG_APP, "StartVideo use cached profile %{public}u*%{public}u", videoProfile_->size.width, +// videoProfile_->size.height); +// } else if (videoProfile_ == nullptr) { +// videoProfile_ = cameraOutputCapability_->videoProfiles[0]; +// if (!videoProfile_) { +// OH_LOG_ERROR(LOG_APP, "StartVideo: fallback profile is null"); +// return CAMERA_INVALID_ARGUMENT; +// } +// } +// +// ret = SessionStop(); +// if (ret == CAMERA_OK) { +// OH_LOG_INFO(LOG_APP, "SessionStop success."); +// } else { +// OH_LOG_ERROR(LOG_APP, "SessionStop failed. %d ", ret); +// } +// SessionRelease(); +// ret = OH_CameraManager_CreateCaptureSession(cameraManager_, &captureSession_); +// if (captureSession_ == nullptr || ret != CAMERA_OK) { +// OH_LOG_ERROR(LOG_APP, "Create captureSession failed."); +// } +// ret = OH_CaptureSession_SetSessionMode(captureSession_, NORMAL_VIDEO); +// CaptureSessionRegisterCallback(); +// GetSupportedCameras(); +// GetSupportedOutputCapability(); +// CreatePreviewOutput(); +// CreateCameraInput(); +// CameraInputOpen(); +// CameraManagerRegisterCallback(); +// +// ret = SessionBegin(); +// if (ret == CAMERA_OK) { +// OH_LOG_INFO(LOG_APP, "SessionBegin success."); +// } else { +// OH_LOG_ERROR(LOG_APP, "SessionBegin failed. %d ", ret); +// } +// ret = OH_CaptureSession_AddInput(captureSession_, cameraInput_); +// ret = OH_CaptureSession_AddPreviewOutput(captureSession_, previewOutput_); +// CreateVideoOutput(videoId); +// AddVideoOutput(); +// SessionCommitConfig(); +// bool isMirrorSupported = false; +// ret = OH_VideoOutput_IsMirrorSupported(videoOutput_, &isMirrorSupported); +// OH_LOG_INFO(LOG_APP, "VideoOutput IsMirrorSupported: %{public}d", isMirrorSupported); +// if (isMirrorSupported) { +// OH_VideoOutput_EnableMirror(videoOutput_, isMirrorSupported); +// } +// +// SessionStart(); +// VideoOutputRegisterCallback(); return ret; } @@ -864,44 +916,43 @@ Camera_ErrorCode NDKCamera::StartPhoto(char *mSurfaceId) { Camera_ErrorCode ret = CAMERA_OK; - if (cachedPhotoProfile_ != nullptr) { - profile_ = cachedPhotoProfile_; - OH_LOG_INFO(LOG_APP, "StartPhoto use cached profile %u*%u", profile_->size.width, profile_->size.height); - } else if (profile_ == nullptr) { - profile_ = cameraOutputCapability_->photoProfiles[0]; - if (!profile_) { - OH_LOG_ERROR(LOG_APP, "StartPhoto: fallback profile is null"); - return CAMERA_INVALID_ARGUMENT; - } - } - - if (takePictureTimes == 0 || photoResolutionChanged_) { - ret = SessionStop(); - if (ret == CAMERA_OK) { - 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_INFO(LOG_APP, "SessionBegin success."); - } else { - OH_LOG_ERROR(LOG_APP, "SessionBegin failed. %d ", ret); - } - OH_LOG_INFO(LOG_APP, "startPhoto begin."); - - ret = CreatePhotoOutput(mSurfaceId); - - OH_LOG_INFO(LOG_APP, "startPhoto CreatePhotoOutput ret = %{public}d.", ret); - ret = OH_CaptureSession_AddPhotoOutput(captureSession_, photoOutput_); - OH_LOG_INFO(LOG_APP, "startPhoto AddPhotoOutput ret = %{public}d.", ret); - ret = SessionCommitConfig(); - - OH_LOG_INFO(LOG_APP, "startPhoto SessionCommitConfig ret = %{public}d.", ret); - ret = SessionStart(); - OH_LOG_INFO(LOG_APP, "startPhoto SessionStart ret = %{public}d.", ret); - photoResolutionChanged_ = false; - } +// if (cachedPhotoProfile_ != nullptr) { +// profile_ = cachedPhotoProfile_; +// OH_LOG_INFO(LOG_APP, "StartPhoto use cached profile %u*%u", profile_->size.width, profile_->size.height); +// } else if (profile_ == nullptr) { +// profile_ = cameraOutputCapability_->photoProfiles[0]; +// if (!profile_) { +// OH_LOG_ERROR(LOG_APP, "StartPhoto: fallback profile is null"); +// return CAMERA_INVALID_ARGUMENT; +// } +// } +// if (takePictureTimes == 0 || photoResolutionChanged_) { +// ret = SessionStop(); +// if (ret == CAMERA_OK) { +// 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_INFO(LOG_APP, "SessionBegin success."); +// } else { +// OH_LOG_ERROR(LOG_APP, "SessionBegin failed. %d ", ret); +// } +// OH_LOG_INFO(LOG_APP, "startPhoto begin."); +// +// ret = CreatePhotoOutput(mSurfaceId); +// +// OH_LOG_INFO(LOG_APP, "startPhoto CreatePhotoOutput ret = %{public}d.", ret); +// ret = OH_CaptureSession_AddPhotoOutput(captureSession_, photoOutput_); +// OH_LOG_INFO(LOG_APP, "startPhoto AddPhotoOutput ret = %{public}d.", ret); +// ret = SessionCommitConfig(); +// +// OH_LOG_INFO(LOG_APP, "startPhoto SessionCommitConfig ret = %{public}d.", ret); +// ret = SessionStart(); +// OH_LOG_INFO(LOG_APP, "startPhoto SessionStart ret = %{public}d.", ret); +// photoResolutionChanged_ = false; +// } ret = TakePicture(); OH_LOG_INFO(LOG_APP, "startPhoto OH_PhotoOutput_Capture ret = %{public}d.", ret); if (ret_ != CAMERA_OK) { @@ -1095,6 +1146,21 @@ int32_t NDKCamera::GetVideoFrameRate(void) return videoProfile_->range.min; } +Camera_ImageRotation NDKCamera::GetVideoRotation(int32_t deviceDegree) +{ + OH_LOG_INFO(LOG_APP, "GetVideoRotation start deviceDegree:%{public}d", deviceDegree); + Camera_ImageRotation videoRotation; + if (!videoOutput_) { + OH_LOG_INFO(LOG_APP, "GetVideoRotation failed 111."); + } + ret_ = OH_VideoOutput_GetVideoRotation(videoOutput_, deviceDegree, &videoRotation); + if (ret_ != CAMERA_OK) { + OH_LOG_INFO(LOG_APP, "GetVideoRotation failed."); + } + OH_LOG_INFO(LOG_APP, "GetVideoRotation start videoRotation:%{public}d", videoRotation); + return videoRotation; +} + Camera_ErrorCode NDKCamera::VideoOutputStop(void) { OH_LOG_ERROR(LOG_APP, "enter VideoOutputStop."); diff --git a/CameraKit/NDKMinResolutionSample/entry/src/main/cpp/camera_manager.h b/CameraKit/NDKMinResolutionSample/entry/src/main/cpp/camera_manager.h index 7075d945c..1a75248b3 100644 --- a/CameraKit/NDKMinResolutionSample/entry/src/main/cpp/camera_manager.h +++ b/CameraKit/NDKMinResolutionSample/entry/src/main/cpp/camera_manager.h @@ -42,7 +42,8 @@ namespace OHOS_CAMERA_SAMPLE { class NDKCamera { public: ~NDKCamera(); -NDKCamera(char *str, uint32_t focusMode, uint32_t cameraDeviceIndex, uint32_t width, uint32_t height); +NDKCamera(char *str, uint32_t focusMode, uint32_t cameraDeviceIndex, uint32_t width, uint32_t height, char *videoId, + char *photoId, Camera_SceneMode sceneMode); static void Destroy() { @@ -109,6 +110,8 @@ NDKCamera(char *str, uint32_t focusMode, uint32_t cameraDeviceIndex, uint32_t wi Camera_ErrorCode VideoOutputRelease(void); Camera_ErrorCode TakePicture(void); Camera_ErrorCode TakePictureWithPhotoSettings(Camera_PhotoCaptureSetting photoSetting); + Camera_ImageRotation GetVideoRotation(int32_t deviceDegree); + // callback Camera_ErrorCode CameraManagerRegisterCallback(void); Camera_ErrorCode CameraInputRegisterCallback(void); @@ -147,6 +150,7 @@ NDKCamera(char *str, uint32_t focusMode, uint32_t cameraDeviceIndex, uint32_t wi NDKCamera(const NDKCamera &) = delete; NDKCamera &operator=(const NDKCamera &) = delete; + Camera_SceneMode sceneMode_; uint32_t cameraDeviceIndex_; Camera_Manager *cameraManager_; Camera_CaptureSession *captureSession_; @@ -166,6 +170,7 @@ NDKCamera(char *str, uint32_t focusMode, uint32_t cameraDeviceIndex, uint32_t wi Camera_Position position_; Camera_Type type_; char *previewSurfaceId_; + char *videoSurfaceId_; char *photoSurfaceId_; Camera_ErrorCode ret_; uint32_t takePictureTimes = 0; diff --git a/CameraKit/NDKMinResolutionSample/entry/src/main/cpp/main.cpp b/CameraKit/NDKMinResolutionSample/entry/src/main/cpp/main.cpp index 1e417b773..1982d7390 100644 --- a/CameraKit/NDKMinResolutionSample/entry/src/main/cpp/main.cpp +++ b/CameraKit/NDKMinResolutionSample/entry/src/main/cpp/main.cpp @@ -22,6 +22,9 @@ using namespace OHOS_CAMERA_SAMPLE; static NDKCamera* ndkCamera_ = nullptr; const int32_t ARGS_TWO = 2; +const int32_t ARGS_THREE = 3; +const int32_t ARGS_FOUR = 4; +const int32_t ARGS_FIVE = 5; static napi_ref bufferCbRef_ = nullptr; static napi_env env_; size_t g_size = 0; @@ -36,9 +39,9 @@ struct Capture_Setting { }; struct DesiredRes { - uint32_t previewW = 0, previewH = 0; - uint32_t photoW = 0, photoH = 0; - uint32_t videoW = 0, videoH = 0; + uint32_t previewW = 1920, previewH = 1080; + uint32_t photoW = 1920, photoH = 1080; + uint32_t videoW = 1920, videoH = 1080; }; static DesiredRes g_desired; @@ -135,8 +138,8 @@ static napi_value InitCamera(napi_env env, napi_callback_info info) { OH_LOG_ERROR(LOG_APP, "InitCamera Start"); size_t requireArgc = 3; - size_t argc = 3; - napi_value args[3] = {nullptr}; + size_t argc = 6; + napi_value args[6] = {nullptr}; napi_value result; size_t typeLen = 0; char* surfaceId = nullptr; @@ -146,15 +149,25 @@ 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); + + char* videoId = nullptr; + napi_get_value_string_utf8(env, args[1], nullptr, 0, &typeLen); + videoId = new char[typeLen + 1]; + napi_get_value_string_utf8(env, args[1], videoId, typeLen + 1, &typeLen); + + char* photoId = nullptr; + napi_get_value_string_utf8(env, args[ARGS_TWO], nullptr, 0, &typeLen); + photoId = new char[typeLen + ARGS_TWO]; + napi_get_value_string_utf8(env, args[ARGS_TWO], photoId, typeLen + 1, &typeLen); - napi_valuetype valuetype1; - napi_typeof(env, args[1], &valuetype1); - + int32_t sceneMode; + napi_get_value_int32(env, args[ARGS_THREE], &sceneMode); + int32_t focusMode; - napi_get_value_int32(env, args[1], &focusMode); + napi_get_value_int32(env, args[ARGS_FOUR], &focusMode); uint32_t cameraDeviceIndex; - napi_get_value_uint32(env, args[ARGS_TWO], &cameraDeviceIndex); + napi_get_value_uint32(env, args[ARGS_FIVE], &cameraDeviceIndex); OH_LOG_ERROR(LOG_APP, "InitCamera focusMode : %{public}d", focusMode); OH_LOG_ERROR(LOG_APP, "InitCamera surfaceId : %{public}s", surfaceId); @@ -165,16 +178,19 @@ static napi_value InitCamera(napi_env env, napi_callback_info info) delete ndkCamera_; ndkCamera_ = nullptr; } - ndkCamera_ = new NDKCamera(surfaceId, focusMode, cameraDeviceIndex, g_desired.previewW, g_desired.previewH); + ndkCamera_ = new NDKCamera(surfaceId, focusMode, cameraDeviceIndex, g_desired.previewW, g_desired.previewH, + videoId, photoId, static_cast(sceneMode)); if (g_desired.previewW && g_desired.previewH) { ndkCamera_->SetPreviewResolution(g_desired.previewW, g_desired.previewH); OH_LOG_INFO(LOG_APP, "SetPreviewResolution %{public}u*%{public}u", g_desired.previewW, g_desired.previewH); } if (g_desired.photoW && g_desired.photoH) { ndkCamera_->SetPhotoResolution(g_desired.photoW, g_desired.photoH); + OH_LOG_INFO(LOG_APP, "SetPhotoResolution %{public}u*%{public}u", g_desired.photoW, g_desired.photoH); } if (g_desired.videoW && g_desired.videoH) { ndkCamera_->SetVideoResolution(g_desired.videoW, g_desired.videoH); + OH_LOG_INFO(LOG_APP, "SetVideoResolution %{public}u*%{public}u", g_desired.videoW, g_desired.videoH); } OH_LOG_ERROR(LOG_APP, "InitCamera End"); napi_create_int32(env, argc, &result); @@ -395,8 +411,9 @@ static napi_value GetVideoFrameWidth(napi_env env, napi_callback_info info) napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); napi_value result = nullptr; - napi_create_int32(env, ndkCamera_->GetVideoFrameWidth(), &result); - +// napi_create_int32(env, ndkCamera_->GetVideoFrameWidth(), &result); + napi_create_int32(env,g_desired.videoW, &result); + OH_LOG_ERROR(LOG_APP, "GetVideoFrameWidth End"); return result; } @@ -409,8 +426,9 @@ static napi_value GetVideoFrameHeight(napi_env env, napi_callback_info info) napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); napi_value result = nullptr; - napi_create_int32(env, ndkCamera_->GetVideoFrameHeight(), &result); - +// napi_create_int32(env, ndkCamera_->GetVideoFrameHeight(), &result); + napi_create_int32(env,g_desired.videoH, &result); + OH_LOG_ERROR(LOG_APP, "GetVideoFrameHeight End"); return result; } @@ -429,6 +447,30 @@ static napi_value GetVideoFrameRate(napi_env env, napi_callback_info info) return result; } +static napi_value GetVideoRotation(napi_env env, napi_callback_info info) +{ + OH_LOG_ERROR(LOG_APP, "GetVideoRotation start"); + napi_value result; + napi_get_undefined(env, &result); + napi_value js_value; // 保存传递的 JavaScript 值 + size_t argc = 1; + napi_get_cb_info(env, info, &argc, &js_value, nullptr, nullptr); + + int32_t deviceDegree = 0; + napi_status status = napi_get_value_int32(env, js_value, &deviceDegree); + OH_LOG_ERROR(LOG_APP, "GetVideoRotation deviceDegree:%{public}d", deviceDegree); + + int32_t videoRotation = 0; // 用于保存视频旋转角度 + if (ndkCamera_) { + OH_LOG_ERROR(LOG_APP, "ndkCamera_ is not null"); + // 调用 ndkCamera_ 获取视频旋转角度 + videoRotation = ndkCamera_->GetVideoRotation(deviceDegree); + } + // 创建一个返回的 napi_value,将 videoRotation 转换为 JavaScript 中的整数 + napi_create_int32(env, videoRotation, &result); + return result; +} + static napi_value VideoOutputStopAndRelease(napi_env env, napi_callback_info info) { OH_LOG_ERROR(LOG_APP, "VideoOutputStopAndRelease Start"); @@ -438,7 +480,7 @@ static napi_value VideoOutputStopAndRelease(napi_env env, napi_callback_info inf napi_value result = nullptr; ndkCamera_->VideoOutputStop(); - ndkCamera_->VideoOutputRelease(); +// ndkCamera_->VideoOutputRelease(); OH_LOG_ERROR(LOG_APP, "VideoOutputStopAndRelease End"); napi_create_int32(env, argc, &result); @@ -663,6 +705,7 @@ static napi_value Init(napi_env env, napi_value exports) {"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}, + {"getVideoRotation", nullptr, GetVideoRotation, nullptr, nullptr, nullptr, napi_default, nullptr}, {"videoOutputStopAndRelease", nullptr, VideoOutputStopAndRelease, nullptr, nullptr, nullptr, napi_default, nullptr}, {"takePicture", nullptr, TakePicture, nullptr, nullptr, nullptr, napi_default, nullptr}, diff --git a/CameraKit/NDKMinResolutionSample/entry/src/main/cpp/types/libentry/index.d.ts b/CameraKit/NDKMinResolutionSample/entry/src/main/cpp/types/libentry/index.d.ts index 3ec0fa79e..31d6df5da 100644 --- a/CameraKit/NDKMinResolutionSample/entry/src/main/cpp/types/libentry/index.d.ts +++ b/CameraKit/NDKMinResolutionSample/entry/src/main/cpp/types/libentry/index.d.ts @@ -13,7 +13,7 @@ * limitations under the License. */ -export const initCamera:(surfaceId: string, focusMode: number, cameraDeviceIndex: number) => number; +export const initCamera:(surfaceId: string, videoId: string, photoId: string, sceneMode: number, focusMode: number, cameraDeviceIndex: number) => number; export const startPhotoOrVideo: (modeFlag: string, videoId: string, photoId: string) => number; export const videoOutputStart: () => number; export const setZoomRatio: (a: number) => number; @@ -30,6 +30,7 @@ export const isFocusPoint: (a: number, b: number) => number; export const getVideoFrameWidth: () => number; export const getVideoFrameHeight: () => number; export const getVideoFrameRate: () => number; +export const getVideoRotation: (deviceDegree: number) => number; export const videoOutputStopAndRelease: () => number; export const releaseCamera: () => number; export const releaseSession: () => number; diff --git a/CameraKit/NDKMinResolutionSample/entry/src/main/ets/pages/Index.ets b/CameraKit/NDKMinResolutionSample/entry/src/main/ets/pages/Index.ets index 44bade0e7..9b5a5f327 100644 --- a/CameraKit/NDKMinResolutionSample/entry/src/main/ets/pages/Index.ets +++ b/CameraKit/NDKMinResolutionSample/entry/src/main/ets/pages/Index.ets @@ -34,6 +34,7 @@ import common from '@ohos.app.ability.common' import { GridLine } from '../views/GridLine'; import { GridLinePage } from '../views/GridLinePage'; import { photoAccessHelper } from '@kit.MediaLibraryKit'; +import { camera } from '@kit.CameraKit'; const TAG: string = 'UI indexPage'; @@ -62,6 +63,11 @@ struct Index { @State exposureNum: number = 0; // Front and rear cameras @State cameraDeviceIndex: number = 0; + @State videoId: string = ''; + @State mSurfaceId: string = ''; + @State videoTrigger: number = 0; + @State photoTrigger: number = 0; + @State sceneMode: camera.SceneMode = camera.SceneMode.NORMAL_PHOTO; @State isGridLineVisible: boolean = false; @State xComponentWidth: number = 384; @State xComponentHeight: number = 450; @@ -176,7 +182,12 @@ struct Index { Logger.info(TAG, `onPageShow App`); if (this.surfaceId && this.onShow) { Logger.error(TAG, `initCamera start`); - cameraDemo.initCamera(this.surfaceId, this.settingDataObj.focusMode, this.cameraDeviceIndex); + if (this.sceneMode == camera.SceneMode.NORMAL_VIDEO) { + this.videoTrigger++; + } else { + this.photoTrigger++; + // cameraDemo.initCamera(this.surfaceId, this.videoId, this.sceneMode, this.settingDataObj.focusMode, this.cameraDeviceIndex); + } Logger.error(TAG, `initCamera end`); } @@ -201,7 +212,7 @@ struct Index { this.surfaceId = this.mXComponentController.getXComponentSurfaceId(); Logger.info(TAG, `onLoad surfaceId: ${this.surfaceId}`); Logger.error(TAG, `initCamera start`); - cameraDemo.initCamera(this.surfaceId, this.settingDataObj.focusMode, this.cameraDeviceIndex); + cameraDemo.initCamera(this.surfaceId, this.videoId, this.mSurfaceId, this.sceneMode, this.settingDataObj.focusMode, this.cameraDeviceIndex) let device = Common.cameraDeviceIndex; device = this.cameraDeviceIndex; Logger.error(TAG, `initCamera end`); @@ -247,6 +258,7 @@ struct Index { } catch (err) { Logger.error(TAG, `Init get resolution failed.`); } + this.photoTrigger++; }) .backgroundColor(Color.Black) .width(this.xComponentWidth) @@ -284,7 +296,12 @@ struct Index { // Reverse camera_Multiple workstations_Take photos_Video modeSwitchPage({ surfaceId: this.surfaceId, - cameraDeviceIndex: $cameraDeviceIndex + cameraDeviceIndex: $cameraDeviceIndex, + videoId: this.videoId, + sceneMode: this.sceneMode, + videoTrigger: this.videoTrigger, + photoTrigger: this.photoTrigger, + mSurfaceId: this.mSurfaceId }); Row({ space: 24 }) { @@ -303,7 +320,8 @@ struct Index { .onSelect(async (index, value) => { this.photoResSelectedIndex = index; const ret = ResolutionService.applyPhotoResolution(value); - cameraDemo.initCamera(this.surfaceId, this.settingDataObj.focusMode, this.cameraDeviceIndex); + this.photoTrigger++; + // cameraDemo.initCamera(this.surfaceId, this.videoId, this.sceneMode, this.settingDataObj.focusMode, this.cameraDeviceIndex) Logger.info(TAG, `apply photoResolution: ${value}`, value); const size = ResolutionService.parseLabel(value); if (size) { @@ -338,7 +356,11 @@ struct Index { .onSelect(async (index, value) => { this.videoResSelectedIndex = index; const ret = ResolutionService.applyVideoResolution(value); - cameraDemo.initCamera(this.surfaceId, this.settingDataObj.focusMode, this.cameraDeviceIndex); + this.videoTrigger++; + // setTimeout(() => { + // Logger.info(TAG, `wait for avrecorder`); + // }, 3000); + // cameraDemo.initCamera(this.surfaceId, this.videoId, this.sceneMode, this.settingDataObj.focusMode, this.cameraDeviceIndex) Logger.info(TAG, `apply videoResolution: ${value}`, value); const size = ResolutionService.parseLabel(value); if (size) { diff --git a/CameraKit/NDKMinResolutionSample/entry/src/main/ets/views/ModeSwitchPage.ets b/CameraKit/NDKMinResolutionSample/entry/src/main/ets/views/ModeSwitchPage.ets index 6117454a7..1f5dcabe5 100644 --- a/CameraKit/NDKMinResolutionSample/entry/src/main/ets/views/ModeSwitchPage.ets +++ b/CameraKit/NDKMinResolutionSample/entry/src/main/ets/views/ModeSwitchPage.ets @@ -25,6 +25,9 @@ import { fileIo, ReadOptions, WriteOptions } from '@kit.CoreFileKit'; import deviceInfo from '@ohos.deviceInfo'; import { Constants, SettingDataObj } from '../common/Constants' import common from '@ohos.app.ability.common' +import { Decimal } from '@kit.ArkTS'; +import { sensor } from '@kit.SensorServiceKit'; +import { camera } from '@kit.CameraKit'; interface CameraSize { WIDTH: number, @@ -53,8 +56,7 @@ export struct modeSwitchPage { private tag: string = 'sample modeSwitchPage:'; private fileAsset?: photoAccessHelper.PhotoAsset; private fd: number = -1; - @State videoId: string = ''; - @State mSurfaceId: string = ''; + @Link mSurfaceId: string; private cameraSize: CameraSize = { WIDTH: 1280, HEIGHT: 720 @@ -95,8 +97,13 @@ export struct modeSwitchPage { }; // Front and rear cameras @Link cameraDeviceIndex: number; + + @Link videoId: string; + @Link sceneMode: camera.SceneMode; // SurfaceID @Prop surfaceId: string; + @Prop @Watch('onTriggerChange') videoTrigger: number; + @Prop @Watch('onPhotoChange') photoTrigger: number; // Photo Thumbnails @State imgThumbnail: string = ''; // Recording time @@ -109,7 +116,6 @@ export struct modeSwitchPage { @State modelBagCol: string = 'photo'; // Choose camera or capture @State @Watch('onChangeIsModeBol') isModeBol: boolean = true; - // Video Thumbnails // private videoThumbnail?: image.PixelMap; @State videoThumbnail: image.PixelMap | undefined | null = undefined; private fileName: string = ''; @@ -133,6 +139,16 @@ export struct modeSwitchPage { onChangeIsModeBol() { } + async onTriggerChange() { + await this.getVideoSurfaceID(); + cameraDemo.initCamera(this.surfaceId, this.videoId, this.mSurfaceId, this.sceneMode, this.settingDataObj.focusMode, this.cameraDeviceIndex) + } + + async onPhotoChange() { + await this.getPhotoSurfaceID(); + cameraDemo.initCamera(this.surfaceId, this.videoId, this.mSurfaceId, this.sceneMode, this.settingDataObj.focusMode, this.cameraDeviceIndex) + } + //创建视频文件Fd initFd(): number { Logger.info(this.tag, 'initFd is called'); @@ -146,6 +162,67 @@ export struct modeSwitchPage { return file.fd; } + getRealData(data: sensor.GravityResponse): number { + let getDeviceDegree: number = 0; + let x = data.x; + let y = data.y; + let z = data.z; + if ((x * x + y * y) * 3 < z * z) { + return getDeviceDegree; + } else { + try { + let sd: Decimal = Decimal.atan2(y, -x); + let sc: Decimal = Decimal.round(Number(sd) / 3.141592653589 * 180); + getDeviceDegree = 90 - Number(sc); + getDeviceDegree = getDeviceDegree >= 0 ? getDeviceDegree % 360 : getDeviceDegree % 360 + 360; + } catch (error) { + let err = error as BusinessError; + console.error(`decimal failed, error: ${err.code}`); + } + } + return getDeviceDegree; + } + + async getGravity() : Promise { + let isSupported: boolean = false; + let data: sensor.Sensor[]; + try { + data = await sensor.getSensorList(); + } catch (error) { + let err = error as BusinessError; + console.error(`getSensorList failed, error: ${err.code}`); + return -1; // 异常场景下返回默认值 + } + + for (let i = 0; i < data.length; i++) { + if (data[i].sensorId === sensor.SensorId.GRAVITY) { + isSupported = true; + break; + } + } + try { + if (isSupported === true) { + const promise: Promise = new Promise((resolve) => { + sensor.once(sensor.SensorId.GRAVITY, (data: sensor.GravityResponse) => { + resolve(this.getRealData(data)); + }); + }) + return promise; + } else { + const promise: Promise = new Promise((resolve) => { + sensor.once(sensor.SensorId.ACCELEROMETER, (data: sensor.AccelerometerResponse) => { + resolve(this.getRealData(data as sensor.GravityResponse)); + }); + }) + return promise; + } + } catch (error) { + let err = error as BusinessError; + console.error(`gePromise failed, error: ${err.code}`); + return -1; // 异常场景下返回默认值 + } + } + async getVideoSurfaceID() { Logger.info(this.tag, `getVideoSurfaceID`); this.videoRecorder = await media.createAVRecorder(); @@ -173,7 +250,7 @@ export struct modeSwitchPage { this.videoConfig.profile.videoFrameWidth = cameraDemo.getVideoFrameWidth(); this.videoConfig.profile.videoFrameHeight = cameraDemo.getVideoFrameHeight(); - this.videoConfig.profile.videoFrameRate = cameraDemo.getVideoFrameRate(); + // this.videoConfig.profile.videoFrameRate = cameraDemo.getVideoFrameRate(); Logger.info(this.tag, `Profile_ video width getVideoSurfaceID videoId: ${this.videoConfig.profile.videoFrameWidth}`); Logger.info(this.tag, `Profile_ video width getVideoSurfaceID videoId: ${this.videoConfig.profile.videoFrameHeight}`); try{ @@ -183,6 +260,13 @@ export struct modeSwitchPage { Logger.error(this.tag, 'prepare failed: ' + err); } + // // updateRotation + // let deviceDegree = await this.getGravity(); + // Logger.info(this.tag, `startVideo deviceDegree:${deviceDegree}`); + // let videoRotation = cameraDemo.getVideoRotation(deviceDegree); + // Logger.info(this.tag, `startVideo getVideoRotation:${videoRotation}`); + // this.videoRecorder?.updateRotation(videoRotation); + this.videoId = await this.videoRecorder.getInputSurface(); Logger.info(this.tag, `getVideoSurfaceID videoId: ${this.videoId}`); } @@ -305,7 +389,6 @@ export struct modeSwitchPage { // Determine the video or photo mode async isVideoPhotoFn() { - await this.getPhotoSurfaceID(); if (this.modelBagCol == 'photo') { cameraDemo.startPhotoOrVideo(this.modelBagCol, this.videoId, this.mSurfaceId); @@ -315,7 +398,13 @@ export struct modeSwitchPage { clearInterval(this.timer); } // Start record - await this.getVideoSurfaceID(); + // await this.getVideoSurfaceID(); + // updateRotation + let deviceDegree = await this.getGravity(); + Logger.info(this.tag, `startVideo deviceDegree:${deviceDegree}`); + let videoRotation = cameraDemo.getVideoRotation(deviceDegree); + Logger.info(this.tag, `startVideo getVideoRotation:${videoRotation}`); + this.videoRecorder?.updateRotation(videoRotation); cameraDemo.startPhotoOrVideo(this.modelBagCol, this.videoId, this.mSurfaceId); cameraDemo.videoOutputStart(); if (this.videoRecorder) { @@ -324,7 +413,12 @@ export struct modeSwitchPage { } } - aboutToAppear() { + async aboutToAppear() { + if (this.sceneMode == camera.SceneMode.NORMAL_VIDEO) { + await this.getVideoSurfaceID() + } else { + await this.getPhotoSurfaceID(); + } } build() { @@ -335,9 +429,11 @@ export struct modeSwitchPage { .borderRadius(14) .fontSize(15) .fontColor(Color.White) - .onClick(() => { + .onClick(async () => { cameraDemo.releaseSession() - cameraDemo.initCamera(this.surfaceId, this.settingDataObj.focusMode, this.cameraDeviceIndex) + this.sceneMode = camera.SceneMode.NORMAL_PHOTO + await this.getPhotoSurfaceID(); + cameraDemo.initCamera(this.surfaceId, this.videoId, this.mSurfaceId, this.sceneMode, this.settingDataObj.focusMode, this.cameraDeviceIndex) this.modelBagCol = 'photo' }) }.position({ x: '45%', y: '77%' }) @@ -348,9 +444,11 @@ export struct modeSwitchPage { .fontColor(Color.White) .borderRadius(14) .size({ width: 64, height: 28 }) - .onClick(() => { + .onClick(async () => { cameraDemo.releaseSession() - cameraDemo.initCamera(this.surfaceId, this.settingDataObj.focusMode, this.cameraDeviceIndex) + this.sceneMode = camera.SceneMode.NORMAL_VIDEO + await this.getVideoSurfaceID() + cameraDemo.initCamera(this.surfaceId, this.videoId, this.mSurfaceId, this.sceneMode, this.settingDataObj.focusMode, this.cameraDeviceIndex) this.modelBagCol = 'video' }) }.position({ x: '60%', y: '77%' }) @@ -421,8 +519,13 @@ export struct modeSwitchPage { this.cameraDeviceIndex ? this.cameraDeviceIndex = 0 : this.cameraDeviceIndex = 1; // Clear configuration cameraDemo.releaseSession(); + if (this.sceneMode == camera.SceneMode.NORMAL_VIDEO) { + await this.getVideoSurfaceID(); + } else { + await this.getPhotoSurfaceID(); + } // Start preview - cameraDemo.initCamera(this.surfaceId, this.settingDataObj.focusMode, this.cameraDeviceIndex); + cameraDemo.initCamera(this.surfaceId, this.videoId, this.mSurfaceId, this.sceneMode, this.settingDataObj.focusMode, this.cameraDeviceIndex); }) } }.position({ x: '70%', y: '85%' }) @@ -489,7 +592,9 @@ export struct modeSwitchPage { try { if (this.videoRecorder) { await this.videoRecorder.stop(); - await this.videoRecorder.release(); + await this.videoRecorder.prepare(this.videoConfig); + await this.videoRecorder.getInputSurface(); + // await this.videoRecorder.release(); } cameraDemo.videoOutputStopAndRelease(); if (this.fileAsset) { diff --git a/CameraKit/NDKPhotoVideoSample/build-profile.json5 b/CameraKit/NDKPhotoVideoSample/build-profile.json5 index 375a8f182..b5bb25293 100644 --- a/CameraKit/NDKPhotoVideoSample/build-profile.json5 +++ b/CameraKit/NDKPhotoVideoSample/build-profile.json5 @@ -19,14 +19,22 @@ { "name": "default", "signingConfig": "default", - "compatibleSdkVersion": "6.0.0(20)", - "runtimeOS": "HarmonyOS", - "targetSdkVersion": "6.0.0(20)", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } + "compileSdkVersion": 23, + "compatibleSdkVersion": 20, + "runtimeOS": "OpenHarmony" + } + ], + "signingConfigs": [ + { + "name": "default", + "material": { + "certpath": "C:/Users/wWX1366912/.ohos/config/openharmony/default_NDKPhotoVideoSample_npjtT8uj-RNyGjTv90CAu6PM0boj11fIEnWCScobau0=.cer", + "keyAlias": "debugKey", + "keyPassword": "0000001BFBC512212F341820DDB2A697D9DF25F6ED6CAC1BB40E56BAA1A2DD5D72C94F3BC31C8224E926DA", + "profile": "C:/Users/wWX1366912/.ohos/config/openharmony/default_NDKPhotoVideoSample_npjtT8uj-RNyGjTv90CAu6PM0boj11fIEnWCScobau0=.p7b", + "signAlg": "SHA256withECDSA", + "storeFile": "C:/Users/wWX1366912/.ohos/config/openharmony/default_NDKPhotoVideoSample_npjtT8uj-RNyGjTv90CAu6PM0boj11fIEnWCScobau0=.p12", + "storePassword": "0000001B6BE2961D34D0A0079B0DBF976406D4488A1B50D58CC75E0E8BD1CBACC7EE9AA78BD9E8F77C5C64" } } ] diff --git a/CameraKit/NDKPhotoVideoSample/entry/build-profile.json5 b/CameraKit/NDKPhotoVideoSample/entry/build-profile.json5 index c143a076c..4a362e10b 100644 --- a/CameraKit/NDKPhotoVideoSample/entry/build-profile.json5 +++ b/CameraKit/NDKPhotoVideoSample/entry/build-profile.json5 @@ -26,7 +26,7 @@ "targets": [ { "name": "default", - "runtimeOS": "HarmonyOS" + "runtimeOS": "OpenHarmony" }, { "name": "ohosTest", diff --git a/CameraKit/NDKPhotoVideoSample/entry/src/main/cpp/camera_manager.cpp b/CameraKit/NDKPhotoVideoSample/entry/src/main/cpp/camera_manager.cpp index 2e91a40c0..a1643f3c6 100644 --- a/CameraKit/NDKPhotoVideoSample/entry/src/main/cpp/camera_manager.cpp +++ b/CameraKit/NDKPhotoVideoSample/entry/src/main/cpp/camera_manager.cpp @@ -32,7 +32,7 @@ static void *g_bufferCb = nullptr; const int32_t NUM_1920 = 1920; const int32_t NUM_1080 = 1080; -NDKCamera::NDKCamera(char *str, uint32_t focusMode, uint32_t cameraDeviceIndex, bool isVideo) +NDKCamera::NDKCamera(char *str, char *videoId, uint32_t focusMode, uint32_t cameraDeviceIndex, bool isVideo, bool isHdr) : previewSurfaceId_(str), cameras_(nullptr), focusMode_(focusMode), @@ -55,8 +55,9 @@ NDKCamera::NDKCamera(char *str, uint32_t focusMode, uint32_t cameraDeviceIndex, maxExposureBias_(0), step_(0), ret_(CAMERA_OK), - isHdrVideo(false), - isVideo(isVideo) + isHdrVideo(isHdr), + isVideo(isVideo), + videoId_(videoId) { valid_ = false; ReleaseCamera(); @@ -79,11 +80,18 @@ NDKCamera::NDKCamera(char *str, uint32_t focusMode, uint32_t cameraDeviceIndex, GetSupportedCameras(); GetSupportedOutputCapability(); CreatePreviewOutput(); + if (isVideo) { + CreateVideoOutput(videoId_); + } else { + CreatePhotoOutputWithoutSurfaceId(); + PhotoOutputRegisterPhotoAvailableCallback(); + } CreateCameraInput(); CameraInputOpen(); CameraManagerRegisterCallback(); RegisterTorchStatusCallback(); SessionFlowFn(); + RegisterControlCenterEffectStatusChangeCallback(); valid_ = true; } @@ -160,51 +168,6 @@ Camera_ErrorCode NDKCamera::SessionRelease(void) return ret; } -Camera_ErrorCode NDKCamera::HasFlashFn(uint32_t mode) -{ - Camera_FlashMode flashMode = static_cast(mode); - // Check for flashing lights - bool hasFlash = false; - Camera_ErrorCode ret = OH_CaptureSession_HasFlash(captureSession_, &hasFlash); - if (captureSession_ == nullptr || ret != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_HasFlash failed."); - } - if (hasFlash) { - OH_LOG_INFO(LOG_APP, "hasFlash success-----"); - } else { - OH_LOG_ERROR(LOG_APP, "hasFlash fail-----"); - } - - // Check if the flash mode is supported - bool isSupported = false; - ret = OH_CaptureSession_IsFlashModeSupported(captureSession_, flashMode, &isSupported); - if (ret != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_IsFlashModeSupported failed."); - } - if (isSupported) { - OH_LOG_INFO(LOG_APP, "isFlashModeSupported success-----"); - } else { - OH_LOG_ERROR(LOG_APP, "isFlashModeSupported fail-----"); - } - - // Set flash mode - ret = OH_CaptureSession_SetFlashMode(captureSession_, flashMode); - if (ret == CAMERA_OK) { - OH_LOG_INFO(LOG_APP, "OH_CaptureSession_SetFlashMode success."); - } else { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_SetFlashMode failed. %{public}d ", ret); - } - - // Obtain the flash mode of the current device - ret = OH_CaptureSession_GetFlashMode(captureSession_, &flashMode); - if (ret == CAMERA_OK) { - 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); @@ -238,38 +201,6 @@ Camera_ErrorCode NDKCamera::IsVideoStabilizationModeSupportedFn(uint32_t mode) return ret; } -Camera_ErrorCode NDKCamera::setZoomRatioFn(uint32_t zoomRatio) -{ - float zoom = float(zoomRatio); - // Obtain supported zoom range - float minZoom; - float maxZoom; - Camera_ErrorCode ret = OH_CaptureSession_GetZoomRatioRange(captureSession_, &minZoom, &maxZoom); - if (captureSession_ == nullptr || ret != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetZoomRatioRange failed."); - } else { - OH_LOG_INFO(LOG_APP, "OH_CaptureSession_GetZoomRatioRange success. minZoom: %{public}f, maxZoom:%{public}f", - minZoom, maxZoom); - } - - // Set Zoom - ret = OH_CaptureSession_SetZoomRatio(captureSession_, zoom); - if (ret == CAMERA_OK) { - OH_LOG_INFO(LOG_APP, "OH_CaptureSession_SetZoomRatio success."); - } else { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_SetZoomRatio failed. %{public}d ", ret); - } - - // Obtain the zoom value of the current device - ret = OH_CaptureSession_GetZoomRatio(captureSession_, &zoom); - if (ret == CAMERA_OK) { - OH_LOG_INFO(LOG_APP, "OH_CaptureSession_GetZoomRatio success. zoom:%{public}f ", zoom); - } else { - OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetZoomRatio failed. %{public}d ", ret); - } - return ret; -} - Camera_ErrorCode NDKCamera::SessionBegin(void) { Camera_ErrorCode ret = OH_CaptureSession_BeginConfig(captureSession_); @@ -329,12 +260,45 @@ Camera_ErrorCode NDKCamera::SessionFlowFn(void) OH_LOG_INFO(LOG_APP, "session add Preview Output."); ret = OH_CaptureSession_AddPreviewOutput(captureSession_, previewOutput_); - // Adding PhotoOutput to the Session - OH_LOG_INFO(LOG_APP, "session add Photo Output."); + + if (isVideo) { + // Adding VideoOutput to the Session + OH_LOG_INFO(LOG_APP, "session add Video Output."); + AddVideoOutput(); + if (isHdrVideo) { + // HDR Vivid 视频需要设置色彩空间为OH_COLORSPACE_BT2020_HLG_LIMIT + OH_NativeBuffer_ColorSpace colorSpace = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT2020_HLG_LIMIT; + SetColorSpace(colorSpace); + } + } else { + // Adding PhotoOutput to the Session + OH_LOG_INFO(LOG_APP, "session add Photo Output."); + AddPhotoOutput(); + ret = CreateMetadataOutput(); + OH_LOG_INFO(LOG_APP, "startPhoto CreateMetadataOutput ret = %{public}d.", ret); + ret = OH_CaptureSession_AddMetadataOutput(captureSession_, metadataOutput_); + OH_LOG_INFO(LOG_APP, "startPhoto AddMetadataOutput ret = %{public}d.", ret); + + OH_NativeBuffer_ColorSpace colorSpace = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_FULL; + SetColorSpace(colorSpace); + } // Submit configuration information OH_LOG_INFO(LOG_APP, "session commitConfig"); ret = OH_CaptureSession_CommitConfig(captureSession_); + + if (isVideo) { + bool isMirrorSupported = false; + ret = OH_VideoOutput_IsMirrorSupported(videoOutput_, &isMirrorSupported); + OH_LOG_INFO(LOG_APP, "VideoOutput IsMirrorSupported: %{public}d", isMirrorSupported); + if (isMirrorSupported) { + OH_VideoOutput_EnableMirror(videoOutput_, isMirrorSupported); + } + } + if (isHdrVideo) { + uint32_t mode = static_cast(Camera_VideoStabilizationMode::STABILIZATION_MODE_AUTO); + IsVideoStabilizationModeSupportedFn(mode); + } // Start Session Work OH_LOG_INFO(LOG_APP, "session start"); @@ -440,9 +404,11 @@ Camera_ErrorCode NDKCamera::GetSupportedCameras(void) Camera_ErrorCode NDKCamera::GetSupportedOutputCapability(void) { if (isHdrVideo) { + OH_LOG_ERROR(LOG_APP, "colorspace 11111 failed."); ret_ = OH_CameraManager_GetSupportedCameraOutputCapabilityWithSceneMode(cameraManager_, &cameras_[cameraDeviceIndex_], Camera_SceneMode::NORMAL_VIDEO, &cameraOutputCapability_); } else { + OH_LOG_ERROR(LOG_APP, "colorspace 22222222 failed."); ret_ = OH_CameraManager_GetSupportedCameraOutputCapability(cameraManager_, &cameras_[cameraDeviceIndex_], &cameraOutputCapability_); } @@ -458,54 +424,33 @@ void NDKCamera::GetProfiles() { previewProfile_ = cameraOutputCapability_->previewProfiles[0]; if (isHdrVideo) { - for (int i = 0; i < cameraOutputCapability_->previewProfilesSize; i++) { - if (cameraOutputCapability_->previewProfiles[i]->format == Camera_Format::CAMERA_FORMAT_YCRCB_P010) { - previewProfile_ = cameraOutputCapability_->previewProfiles[i]; - } - } - } - if (isControl) { - for (int i = 0; i < cameraOutputCapability_->previewProfilesSize; i++) { - if (cameraOutputCapability_->previewProfiles[i]->size.width == NUM_1920 && - cameraOutputCapability_->previewProfiles[i]->size.height == NUM_1080) { - previewProfile_ = cameraOutputCapability_->previewProfiles[i]; - if (isHdrVideo) { - if (previewProfile_->format != Camera_Format::CAMERA_FORMAT_YCRCB_P010) { - continue; - } - } - } - } + Camera_Profile* profile = cameraOutputCapability_->previewProfiles[0]; + profile->size.width = NUM_1920; + profile->size.height = NUM_1080; + profile->format = Camera_Format::CAMERA_FORMAT_YCRCB_P010; + previewProfile_ = profile; + } else { + Camera_Profile* profile = cameraOutputCapability_->previewProfiles[0]; + profile->size.width = NUM_1920; + profile->size.height = NUM_1080; + previewProfile_ = profile; } // VideoOutput的宽高比需要和PreviewOutput一致 - for (int i = 0; i < cameraOutputCapability_->videoProfilesSize; i++) { - videoProfile_ = cameraOutputCapability_->videoProfiles[i]; - if (AreFloatsEqual(static_cast(previewProfile_->size.width) / previewProfile_->size.height, - static_cast(videoProfile_->size.width) / videoProfile_->size.height)) { - if (isHdrVideo) { - // HDR Vivid 视频需指定格式为CAMERA_FORMAT_YCRCB_P010 - if (videoProfile_->format == Camera_Format::CAMERA_FORMAT_YCRCB_P010) { - break; - } else { - continue; - } - } else { - break; - } - } - } - if (isControl) { - for (int i = 0; i < cameraOutputCapability_->videoProfilesSize; i++) { - videoProfile_ = cameraOutputCapability_->videoProfiles[i]; - if (videoProfile_->size.width == NUM_1920 && videoProfile_->size.height == NUM_1080) { - if (isHdrVideo) { - if (videoProfile_->format != Camera_Format::CAMERA_FORMAT_YCRCB_P010) { - continue; - } - } - break; - } - } + if (isHdrVideo) { + Camera_VideoProfile* profile = cameraOutputCapability_->videoProfiles[0]; + profile->size.width = NUM_1920; + profile->size.height = NUM_1080; + profile->format = Camera_Format::CAMERA_FORMAT_YCRCB_P010; + profile->range.min = 1; + profile->range.max = 30; + videoProfile_ = profile; + } else { + Camera_VideoProfile* profile = cameraOutputCapability_->videoProfiles[0]; + profile->size.width = NUM_1920; + profile->size.height = NUM_1080; + profile->range.min = 1; + profile->range.max = 30; + videoProfile_ = profile; } } @@ -556,7 +501,7 @@ Camera_ErrorCode NDKCamera::CreateVideoOutput(char *videoId) OH_LOG_ERROR(LOG_APP, "CreateVideoOutput failed."); return CAMERA_INVALID_ARGUMENT; } - + VideoOutputRegisterCallback(); return ret_; } @@ -634,60 +579,61 @@ Camera_ErrorCode NDKCamera::PhotoOutputRelease(void) Camera_ErrorCode NDKCamera::StartVideo(char *videoId, char *photoId) { OH_LOG_INFO(LOG_APP, "StartVideo begin isHdr. %{public}d", isHdrVideo); - Camera_ErrorCode ret = SessionStop(); - if (ret == CAMERA_OK) { - OH_LOG_INFO(LOG_APP, "SessionStop success."); - } else { - OH_LOG_ERROR(LOG_APP, "SessionStop failed. %d ", ret); - } - PhotoOutputUnRegisterPhotoAvailableCallback(); - SessionRelease(); - ret = OH_CameraManager_CreateCaptureSession(cameraManager_, &captureSession_); - if (captureSession_ == nullptr || ret != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "Create captureSession failed."); - } - ret = OH_CaptureSession_SetSessionMode(captureSession_, NORMAL_VIDEO); - CaptureSessionRegisterCallback(); - GetSupportedCameras(); - GetSupportedOutputCapability(); - CreatePreviewOutput(); - CreateCameraInput(); - CameraInputOpen(); - CameraManagerRegisterCallback(); - RegisterTorchStatusCallback(); - RegisterControlCenterEffectStatusChangeCallback(); - - ret = SessionBegin(); - if (ret == CAMERA_OK) { - OH_LOG_INFO(LOG_APP, "SessionBegin success."); - } else { - OH_LOG_ERROR(LOG_APP, "SessionBegin failed. %d ", ret); - } - ret = OH_CaptureSession_AddInput(captureSession_, cameraInput_); - ret = OH_CaptureSession_AddPreviewOutput(captureSession_, previewOutput_); - CreateVideoOutput(videoId); - AddVideoOutput(); - if (isHdrVideo) { - // HDR Vivid 视频需要设置色彩空间为OH_COLORSPACE_BT2020_HLG_LIMIT - OH_NativeBuffer_ColorSpace colorSpace = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT2020_HLG_LIMIT; - SetColorSpace(colorSpace); - } - SessionCommitConfig(); - if (isHdrVideo) { - uint32_t mode = static_cast(Camera_VideoStabilizationMode::STABILIZATION_MODE_AUTO); - IsVideoStabilizationModeSupportedFn(mode); - } - EnableControlCenter(isControl); - bool isMirrorSupported = false; - ret = OH_VideoOutput_IsMirrorSupported(videoOutput_, &isMirrorSupported); - OH_LOG_INFO(LOG_APP, "VideoOutput IsMirrorSupported: %{public}d", isMirrorSupported); - if (isMirrorSupported) { - OH_VideoOutput_EnableMirror(videoOutput_, isMirrorSupported); - } - - SessionStart(); - VideoOutputRegisterCallback(); - return ret; +// Camera_ErrorCode ret = SessionStop(); +// if (ret == CAMERA_OK) { +// OH_LOG_INFO(LOG_APP, "SessionStop success."); +// } else { +// OH_LOG_ERROR(LOG_APP, "SessionStop failed. %d ", ret); +// } +// PhotoOutputUnRegisterPhotoAvailableCallback(); +// SessionRelease(); +// ret = OH_CameraManager_CreateCaptureSession(cameraManager_, &captureSession_); +// if (captureSession_ == nullptr || ret != CAMERA_OK) { +// OH_LOG_ERROR(LOG_APP, "Create captureSession failed."); +// } +// ret = OH_CaptureSession_SetSessionMode(captureSession_, NORMAL_VIDEO); +// CaptureSessionRegisterCallback(); +// GetSupportedCameras(); +// GetSupportedOutputCapability(); +// CreatePreviewOutput(); +// CreateCameraInput(); +// CameraInputOpen(); +// CameraManagerRegisterCallback(); +// RegisterTorchStatusCallback(); +// RegisterControlCenterEffectStatusChangeCallback(); +// +// ret = SessionBegin(); +// if (ret == CAMERA_OK) { +// OH_LOG_INFO(LOG_APP, "SessionBegin success."); +// } else { +// OH_LOG_ERROR(LOG_APP, "SessionBegin failed. %d ", ret); +// } +// ret = OH_CaptureSession_AddInput(captureSession_, cameraInput_); +// ret = OH_CaptureSession_AddPreviewOutput(captureSession_, previewOutput_); +// CreateVideoOutput(videoId); +// AddVideoOutput(); +// if (isHdrVideo) { +// // HDR Vivid 视频需要设置色彩空间为OH_COLORSPACE_BT2020_HLG_LIMIT +// OH_NativeBuffer_ColorSpace colorSpace = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT2020_HLG_LIMIT; +// SetColorSpace(colorSpace); +// } +// SessionCommitConfig(); +// if (isHdrVideo) { +// uint32_t mode = static_cast(Camera_VideoStabilizationMode::STABILIZATION_MODE_AUTO); +// IsVideoStabilizationModeSupportedFn(mode); +// } +// EnableControlCenter(isControl); +// bool isMirrorSupported = false; +// ret = OH_VideoOutput_IsMirrorSupported(videoOutput_, &isMirrorSupported); +// OH_LOG_INFO(LOG_APP, "VideoOutput IsMirrorSupported: %{public}d", isMirrorSupported); +// if (isMirrorSupported) { +// OH_VideoOutput_EnableMirror(videoOutput_, isMirrorSupported); +// } +// +// SessionStart(); +// VideoOutputRegisterCallback(); +// return ret; + return CAMERA_OK; } Camera_ErrorCode NDKCamera::VideoOutputStart(void) @@ -705,48 +651,48 @@ Camera_ErrorCode NDKCamera::VideoOutputStart(void) Camera_ErrorCode NDKCamera::StartPhotoWithOutSurfaceId() { Camera_ErrorCode ret = CAMERA_OK; - if (takePictureTimes == 0) { - ret = SessionStop(); - if (ret == CAMERA_OK) { - 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_INFO(LOG_APP, "SessionBegin success."); - } else { - OH_LOG_ERROR(LOG_APP, "SessionBegin failed. %d ", ret); - } - OH_LOG_INFO(LOG_APP, "startPhoto begin."); - - ret = CreatePhotoOutputWithoutSurfaceId(); - PhotoOutputRegisterPhotoAvailableCallback(); - OH_LOG_INFO(LOG_APP, "startPhoto CreatePhotoOutputWithoutSurfaceId ret = %{public}d.", ret); - ret = AddPhotoOutput(); - OH_LOG_INFO(LOG_APP, "startPhoto AddPhotoOutput ret = %{public}d.", ret); - - ret = CreateMetadataOutput(); - OH_LOG_INFO(LOG_APP, "startPhoto CreateMetadataOutput ret = %{public}d.", ret); - ret = OH_CaptureSession_AddMetadataOutput(captureSession_, metadataOutput_); - OH_LOG_INFO(LOG_APP, "startPhoto AddMetadataOutput ret = %{public}d.", ret); - - OH_NativeBuffer_ColorSpace colorSpace = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_FULL; - SetColorSpace(colorSpace); - - ret = SessionCommitConfig(); - - OH_LOG_INFO(LOG_APP, "startPhoto SessionCommitConfig ret = %{public}d.", ret); - ret = SessionStart(); - OH_LOG_INFO(LOG_APP, "startPhoto SessionStart ret = %{public}d.", ret); - } +// if (takePictureTimes == 0) { +// ret = SessionStop(); +// if (ret == CAMERA_OK) { +// 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_INFO(LOG_APP, "SessionBegin success."); +// } else { +// OH_LOG_ERROR(LOG_APP, "SessionBegin failed. %d ", ret); +// } +// OH_LOG_INFO(LOG_APP, "startPhoto begin."); +// +// ret = CreatePhotoOutputWithoutSurfaceId(); +// PhotoOutputRegisterPhotoAvailableCallback(); +// OH_LOG_INFO(LOG_APP, "startPhoto CreatePhotoOutputWithoutSurfaceId ret = %{public}d.", ret); +// ret = AddPhotoOutput(); +// OH_LOG_INFO(LOG_APP, "startPhoto AddPhotoOutput ret = %{public}d.", ret); +// +// ret = CreateMetadataOutput(); +// OH_LOG_INFO(LOG_APP, "startPhoto CreateMetadataOutput ret = %{public}d.", ret); +// ret = OH_CaptureSession_AddMetadataOutput(captureSession_, metadataOutput_); +// OH_LOG_INFO(LOG_APP, "startPhoto AddMetadataOutput ret = %{public}d.", ret); +// +// OH_NativeBuffer_ColorSpace colorSpace = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_P3_FULL; +// SetColorSpace(colorSpace); +// +// ret = SessionCommitConfig(); +// +// OH_LOG_INFO(LOG_APP, "startPhoto SessionCommitConfig ret = %{public}d.", ret); +// ret = SessionStart(); +// OH_LOG_INFO(LOG_APP, "startPhoto SessionStart ret = %{public}d.", ret); +// } ret = TakePicture(); 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_; } @@ -823,6 +769,51 @@ Camera_ErrorCode NDKCamera::IsExposureBiasRange(int exposureBias) return ret_; } +Camera_ErrorCode NDKCamera::HasFlashFn(uint32_t mode) +{ + Camera_FlashMode flashMode = static_cast(mode); + // Check for flashing lights + bool hasFlash = false; + Camera_ErrorCode ret = OH_CaptureSession_HasFlash(captureSession_, &hasFlash); + if (captureSession_ == nullptr || ret != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_HasFlash failed."); + } + if (hasFlash) { + OH_LOG_INFO(LOG_APP, "hasFlash success-----"); + } else { + OH_LOG_ERROR(LOG_APP, "hasFlash fail-----"); + } + + // Check if the flash mode is supported + bool isSupported = false; + ret = OH_CaptureSession_IsFlashModeSupported(captureSession_, flashMode, &isSupported); + if (ret != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_IsFlashModeSupported failed."); + } + if (isSupported) { + OH_LOG_INFO(LOG_APP, "isFlashModeSupported success-----"); + } else { + OH_LOG_ERROR(LOG_APP, "isFlashModeSupported fail-----"); + } + + // Set flash mode + ret = OH_CaptureSession_SetFlashMode(captureSession_, flashMode); + if (ret == CAMERA_OK) { + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_SetFlashMode success."); + } else { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_SetFlashMode failed. %{public}d ", ret); + } + + // Obtain the flash mode of the current device + ret = OH_CaptureSession_GetFlashMode(captureSession_, &flashMode); + if (ret == CAMERA_OK) { + 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; +} + // focus mode Camera_ErrorCode NDKCamera::IsFocusModeSupported(uint32_t mode) { @@ -858,6 +849,38 @@ Camera_ErrorCode NDKCamera::IsFocusMode(uint32_t mode) return ret_; } +Camera_ErrorCode NDKCamera::setZoomRatioFn(uint32_t zoomRatio) +{ + float zoom = float(zoomRatio); + // Obtain supported zoom range + float minZoom; + float maxZoom; + Camera_ErrorCode ret = OH_CaptureSession_GetZoomRatioRange(captureSession_, &minZoom, &maxZoom); + if (captureSession_ == nullptr || ret != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetZoomRatioRange failed."); + } else { + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_GetZoomRatioRange success. minZoom: %{public}f, maxZoom:%{public}f", + minZoom, maxZoom); + } + + // Set Zoom + ret = OH_CaptureSession_SetZoomRatio(captureSession_, zoom); + if (ret == CAMERA_OK) { + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_SetZoomRatio success."); + } else { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_SetZoomRatio failed. %{public}d ", ret); + } + + // Obtain the zoom value of the current device + ret = OH_CaptureSession_GetZoomRatio(captureSession_, &zoom); + if (ret == CAMERA_OK) { + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_GetZoomRatio success. zoom:%{public}f ", zoom); + } else { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetZoomRatio failed. %{public}d ", ret); + } + return ret; +} + Camera_ErrorCode NDKCamera::PreviewOutputSetFrameRate(uint32_t minFps, uint32_t maxFps) { Camera_ErrorCode ret = OH_PreviewOutput_SetFrameRate(previewOutput_, minFps, maxFps); @@ -911,8 +934,39 @@ void NDKCamera::EnableHdrVideo(bool isHdr) { OH_LOG_INFO(LOG_APP, "EnableHdrVideo: isHdr is %{public}d", isHdr); isHdrVideo = isHdr; - // 更新profile - GetSupportedOutputCapability(); +// if (isHdr) { +// Camera_ErrorCode ret = SessionStop(); +// if (ret == CAMERA_OK) { +// 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_INFO(LOG_APP, "SessionBegin success."); +// } else { +// OH_LOG_ERROR(LOG_APP, "SessionBegin failed. %d ", ret); +// } +// if (videoOutput_) { +// OH_CaptureSession_RemoveVideoOutput(captureSession_, videoOutput_); +// } +// if (previewOutput_) { +// OH_CaptureSession_RemovePreviewOutput(captureSession_, previewOutput_); +// } +// GetProfiles(); +// CreatePreviewOutput(); +// CreateVideoOutput(videoId_); +// OH_CaptureSession_AddPreviewOutput(captureSession_, previewOutput_); +// AddVideoOutput(); +// +// // HDR Vivid 视频需要设置色彩空间为OH_COLORSPACE_BT2020_HLG_LIMIT +// OH_NativeBuffer_ColorSpace colorSpace = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT2020_HLG_LIMIT; +// SetColorSpace(colorSpace); +// SessionCommitConfig(); +// uint32_t mode = static_cast(Camera_VideoStabilizationMode::STABILIZATION_MODE_AUTO); +// IsVideoStabilizationModeSupportedFn(mode); +// SessionStart(); +// } } bool NDKCamera::IsMacroSupported(Camera_CaptureSession* captureSession) @@ -974,10 +1028,14 @@ void NDKCamera::EnableControlCenter(bool isControlCenter) return; } if (IsControlCenterSupported()) { + SessionStop(); + SessionBegin(); + SessionCommitConfig(); Camera_ErrorCode ret = OH_CaptureSession_EnableControlCenter(captureSession_, isControlCenter); if (ret != CAMERA_OK) { OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_EnableControlCenter failed."); } + SessionStart(); } } @@ -985,8 +1043,6 @@ void NDKCamera::SetIsControl(bool isControlCenter) { isControl = isControlCenter; EnableControlCenter(isControl); - // 更新profile - GetSupportedOutputCapability(); } // 设置色彩空间 @@ -1056,6 +1112,21 @@ int32_t NDKCamera::GetVideoFrameRate(void) return videoProfile_->range.min; } +Camera_ImageRotation NDKCamera::GetVideoRotation(int32_t deviceDegree) +{ + OH_LOG_INFO(LOG_APP, "GetVideoRotation start deviceDegree:%{public}d", deviceDegree); + Camera_ImageRotation videoRotation; + if (!videoOutput_) { + OH_LOG_INFO(LOG_APP, "GetVideoRotation failed 111."); + } + ret_ = OH_VideoOutput_GetVideoRotation(videoOutput_, deviceDegree, &videoRotation); + if (ret_ != CAMERA_OK) { + OH_LOG_INFO(LOG_APP, "GetVideoRotation failed."); + } + OH_LOG_INFO(LOG_APP, "GetVideoRotation start videoRotation:%{public}d", videoRotation); + return videoRotation; +} + Camera_ErrorCode NDKCamera::VideoOutputStop(void) { OH_LOG_ERROR(LOG_APP, "enter VideoOutputStop."); diff --git a/CameraKit/NDKPhotoVideoSample/entry/src/main/cpp/camera_manager.h b/CameraKit/NDKPhotoVideoSample/entry/src/main/cpp/camera_manager.h index be401d452..4dd954023 100644 --- a/CameraKit/NDKPhotoVideoSample/entry/src/main/cpp/camera_manager.h +++ b/CameraKit/NDKPhotoVideoSample/entry/src/main/cpp/camera_manager.h @@ -44,7 +44,7 @@ namespace OHOS_CAMERA_SAMPLE { class NDKCamera { public: ~NDKCamera(); - NDKCamera(char *str, uint32_t focusMode, uint32_t cameraDeviceIndex, bool isVideo); + NDKCamera(char *str, char *videoId, uint32_t focusMode, uint32_t cameraDeviceIndex, bool isVideo, bool isHdr); static void Destroy() { @@ -93,6 +93,7 @@ class NDKCamera { int32_t GetVideoFrameWidth(void); int32_t GetVideoFrameHeight(void); int32_t GetVideoFrameRate(void); + Camera_ImageRotation GetVideoRotation(int32_t deviceDegree); Camera_ErrorCode SetWhiteBalance(int32_t whiteBalance); Camera_ErrorCode SetColorSpace(OH_NativeBuffer_ColorSpace colorSpace); void EnableHdrVideo(bool isHdr); @@ -155,6 +156,7 @@ class NDKCamera { bool *isCameraMuted_; Camera_Position position_; Camera_Type type_; + char *videoId_; char *previewSurfaceId_; char *photoSurfaceId_; Camera_ErrorCode ret_; diff --git a/CameraKit/NDKPhotoVideoSample/entry/src/main/cpp/main.cpp b/CameraKit/NDKPhotoVideoSample/entry/src/main/cpp/main.cpp index ed9bc6832..2e685bb75 100644 --- a/CameraKit/NDKPhotoVideoSample/entry/src/main/cpp/main.cpp +++ b/CameraKit/NDKPhotoVideoSample/entry/src/main/cpp/main.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include #include #include "camera_manager.h" @@ -22,6 +23,7 @@ using namespace OHOS_CAMERA_SAMPLE; static NDKCamera* ndkCamera_ = nullptr; const int32_t ARGS_TWO = 2; +const int32_t ARGS_THREE = 3; static napi_ref bufferCbRef_ = nullptr; static napi_env env_; static bool g_isControlCenter = false; @@ -242,8 +244,8 @@ static napi_value InitCamera(napi_env env, napi_callback_info info) { OH_LOG_ERROR(LOG_APP, "InitCamera Start"); size_t requireArgc = 3; - size_t argc = 3; - napi_value args[3] = {nullptr}; + size_t argc = 4; + napi_value args[4] = {nullptr}; napi_value result; size_t typeLen = 0; char* surfaceId = nullptr; @@ -253,15 +255,17 @@ 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); - - napi_valuetype valuetype1; - napi_typeof(env, args[1], &valuetype1); + + char* videoId = nullptr; + napi_get_value_string_utf8(env, args[1], nullptr, 0, &typeLen); + videoId = new char[typeLen + 1]; + napi_get_value_string_utf8(env, args[1], videoId, typeLen + 1, &typeLen); int32_t focusMode; - napi_get_value_int32(env, args[1], &focusMode); + napi_get_value_int32(env, args[ARGS_TWO], &focusMode); uint32_t cameraDeviceIndex; - napi_get_value_uint32(env, args[ARGS_TWO], &cameraDeviceIndex); + napi_get_value_uint32(env, args[ARGS_THREE], &cameraDeviceIndex); OH_LOG_ERROR(LOG_APP, "InitCamera focusMode : %{public}d", focusMode); OH_LOG_ERROR(LOG_APP, "InitCamera surfaceId : %{public}s", surfaceId); @@ -272,7 +276,7 @@ static napi_value InitCamera(napi_env env, napi_callback_info info) delete ndkCamera_; ndkCamera_ = nullptr; } - ndkCamera_ = new NDKCamera(surfaceId, focusMode, cameraDeviceIndex, g_isVideo); + ndkCamera_ = new NDKCamera(surfaceId, videoId, focusMode, cameraDeviceIndex, g_isVideo, g_isHdr); if (g_isHdr) { ndkCamera_->EnableHdrVideo(g_isHdr); } @@ -539,6 +543,30 @@ static napi_value GetVideoFrameRate(napi_env env, napi_callback_info info) return result; } +static napi_value GetVideoRotation(napi_env env, napi_callback_info info) +{ + OH_LOG_ERROR(LOG_APP, "GetVideoRotation start"); + napi_value result; + napi_get_undefined(env, &result); + napi_value js_value; // 保存传递的 JavaScript 值 + size_t argc = 1; + napi_get_cb_info(env, info, &argc, &js_value, nullptr, nullptr); + + int32_t deviceDegree = 0; + napi_status status = napi_get_value_int32(env, js_value, &deviceDegree); + OH_LOG_ERROR(LOG_APP, "GetVideoRotation deviceDegree:%{public}d", deviceDegree); + + int32_t videoRotation = 0; // 用于保存视频旋转角度 + if (ndkCamera_) { + OH_LOG_ERROR(LOG_APP, "ndkCamera_ is not null"); + // 调用 ndkCamera_ 获取视频旋转角度 + videoRotation = ndkCamera_->GetVideoRotation(deviceDegree); + } + // 创建一个返回的 napi_value,将 videoRotation 转换为 JavaScript 中的整数 + napi_create_int32(env, videoRotation, &result); + return result; +} + static napi_value VideoOutputStopAndRelease(napi_env env, napi_callback_info info) { OH_LOG_ERROR(LOG_APP, "VideoOutputStopAndRelease Start"); @@ -548,7 +576,7 @@ static napi_value VideoOutputStopAndRelease(napi_env env, napi_callback_info inf napi_value result = nullptr; ndkCamera_->VideoOutputStop(); - ndkCamera_->VideoOutputRelease(); +// ndkCamera_->VideoOutputRelease(); OH_LOG_ERROR(LOG_APP, "VideoOutputStopAndRelease End"); napi_create_int32(env, argc, &result); @@ -705,6 +733,7 @@ static napi_value Init(napi_env env, napi_value exports) { "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 }, + { "getVideoRotation", nullptr, GetVideoRotation, nullptr, nullptr, nullptr, napi_default, nullptr }, { "videoOutputStopAndRelease", nullptr, VideoOutputStopAndRelease, nullptr, nullptr, nullptr, napi_default, nullptr }, { "takePicture", nullptr, TakePicture, nullptr, nullptr, nullptr, napi_default, nullptr }, diff --git a/CameraKit/NDKPhotoVideoSample/entry/src/main/cpp/types/libentry/index.d.ts b/CameraKit/NDKPhotoVideoSample/entry/src/main/cpp/types/libentry/index.d.ts index 4657a6323..95a3c1834 100644 --- a/CameraKit/NDKPhotoVideoSample/entry/src/main/cpp/types/libentry/index.d.ts +++ b/CameraKit/NDKPhotoVideoSample/entry/src/main/cpp/types/libentry/index.d.ts @@ -13,7 +13,7 @@ * limitations under the License. */ -export const initCamera:(surfaceId: string, focusMode: number, cameraDeviceIndex: number) => number; +export const initCamera:(surfaceId: string, videoId: string, focusMode: number, cameraDeviceIndex: number) => number; export const startPhotoOrVideo: (modeFlag: string, videoId: string, photoId: string) => number; export const videoOutputStart: () => number; export const setZoomRatio: (a: number) => number; @@ -34,6 +34,7 @@ export const isFocusPoint: (a: number, b: number) => number; export const getVideoFrameWidth: () => number; export const getVideoFrameHeight: () => number; export const getVideoFrameRate: () => number; +export const getVideoRotation: (deviceDegree: number) => number; export const videoOutputStopAndRelease: () => number; export const releaseCamera: () => number; export const releaseSession: () => number; diff --git a/CameraKit/NDKPhotoVideoSample/entry/src/main/ets/pages/Index.ets b/CameraKit/NDKPhotoVideoSample/entry/src/main/ets/pages/Index.ets index 9fe59f02a..99a204561 100644 --- a/CameraKit/NDKPhotoVideoSample/entry/src/main/ets/pages/Index.ets +++ b/CameraKit/NDKPhotoVideoSample/entry/src/main/ets/pages/Index.ets @@ -59,6 +59,8 @@ struct Index { //HDR video @Provide isHdrVideo: boolean = false; @Provide isVideoMode: boolean = false; + @State videoId: string = ''; + @State videoTrigger: number = 0; // Front and rear cameras @State cameraDeviceIndex: number = 0; @State xComponentWidth: number = 384; @@ -139,10 +141,11 @@ struct Index { Logger.error(TAG, `initCamera start`); if (this.isVideoMode) { cameraDemo.setIsVideo(true); + this.videoTrigger++; } else { cameraDemo.setIsVideo(false); + cameraDemo.initCamera(this.surfaceId, this.videoId, this.settingDataObj.focusMode, this.cameraDeviceIndex); } - cameraDemo.initCamera(this.surfaceId, this.settingDataObj.focusMode, this.cameraDeviceIndex); Logger.error(TAG, `initCamera end`); } } @@ -171,7 +174,7 @@ struct Index { } else { cameraDemo.setIsVideo(false); } - cameraDemo.initCamera(this.surfaceId, this.settingDataObj.focusMode, this.cameraDeviceIndex); + cameraDemo.initCamera(this.surfaceId, this.videoId, this.settingDataObj.focusMode, this.cameraDeviceIndex); let device = Common.cameraDeviceIndex; device = this.cameraDeviceIndex;5 Logger.error(TAG, `setBufferCb start`); @@ -208,7 +211,9 @@ struct Index { // Video Rate VideoRatePage() // HdrVideoPage - HdrVideoPage(); + HdrVideoPage({ + videoTrigger: this.videoTrigger + }); // FlashLight FlashingLightPage(); //WhiteBalance @@ -249,7 +254,9 @@ struct Index { // Reverse camera_Multiple workstations_Take photos_Video modeSwitchPage({ surfaceId: this.surfaceId, - cameraDeviceIndex: $cameraDeviceIndex + cameraDeviceIndex: $cameraDeviceIndex, + videoId: this.videoId, + videoTrigger: this.videoTrigger }); if (this.isGridLineVisible) { GridLine(); diff --git a/CameraKit/NDKPhotoVideoSample/entry/src/main/ets/views/HdrVideoPage.ets b/CameraKit/NDKPhotoVideoSample/entry/src/main/ets/views/HdrVideoPage.ets index 4b9cc295e..f4af248fc 100644 --- a/CameraKit/NDKPhotoVideoSample/entry/src/main/ets/views/HdrVideoPage.ets +++ b/CameraKit/NDKPhotoVideoSample/entry/src/main/ets/views/HdrVideoPage.ets @@ -23,6 +23,7 @@ const TAG: string = 'CameraSample'; export struct HdrVideoPage { // HDR video mode @Consume isHdrVideo: boolean; + @Link videoTrigger: number; build() { @@ -35,6 +36,7 @@ export struct HdrVideoPage { let isHdr = this.isHdrVideo ? false : true; cameraDemo.enableHdrVideo(isHdr); this.isHdrVideo = !this.isHdrVideo; + this.videoTrigger++; }) .width('80px') .height('80px') diff --git a/CameraKit/NDKPhotoVideoSample/entry/src/main/ets/views/ModeSwitchPage.ets b/CameraKit/NDKPhotoVideoSample/entry/src/main/ets/views/ModeSwitchPage.ets index 148912ae4..59a7d6b2c 100644 --- a/CameraKit/NDKPhotoVideoSample/entry/src/main/ets/views/ModeSwitchPage.ets +++ b/CameraKit/NDKPhotoVideoSample/entry/src/main/ets/views/ModeSwitchPage.ets @@ -23,6 +23,8 @@ import deviceInfo from '@ohos.deviceInfo'; import { fileIo, ReadOptions, WriteOptions } from '@kit.CoreFileKit'; import { Constants, SettingDataObj } from '../common/Constants'; import common from '@ohos.app.ability.common'; +import { Decimal } from '@kit.ArkTS'; +import { sensor } from '@kit.SensorServiceKit'; const TAG: string = 'CameraSample'; @@ -39,7 +41,6 @@ export struct modeSwitchPage { private tag: string = 'CameraSample'; private phAccessHelper = photoAccessHelper.getPhotoAccessHelper(this.context); private fd: number = -1; - @State videoId: string = ''; @State mSurfaceId: string = ''; @Consume isVideoMode: boolean; private videoRecorder?: media.AVRecorder; @@ -72,6 +73,8 @@ export struct modeSwitchPage { @Link cameraDeviceIndex: number; // SurfaceID @Prop surfaceId: string; + @Link videoId: string; + @Prop @Watch('onTriggerChange') videoTrigger: number; //HDR video @Consume isHdrVideo: boolean; // Recording time timer @@ -100,6 +103,72 @@ export struct modeSwitchPage { onChangeIsModeBol() { } + async onTriggerChange() { + await this.getVideoSurfaceID(); + cameraDemo.initCamera(this.surfaceId, this.videoId, this.settingDataObj.focusMode, this.cameraDeviceIndex) + } + + getRealData(data: sensor.GravityResponse): number { + let getDeviceDegree: number = 0; + let x = data.x; + let y = data.y; + let z = data.z; + if ((x * x + y * y) * 3 < z * z) { + return getDeviceDegree; + } else { + try { + let sd: Decimal = Decimal.atan2(y, -x); + let sc: Decimal = Decimal.round(Number(sd) / 3.141592653589 * 180); + getDeviceDegree = 90 - Number(sc); + getDeviceDegree = getDeviceDegree >= 0 ? getDeviceDegree % 360 : getDeviceDegree % 360 + 360; + } catch (error) { + let err = error as BusinessError; + console.error(`decimal failed, error: ${err.code}`); + } + } + return getDeviceDegree; + } + + async getGravity() : Promise { + let isSupported: boolean = false; + let data: sensor.Sensor[]; + try { + data = await sensor.getSensorList(); + } catch (error) { + let err = error as BusinessError; + console.error(`getSensorList failed, error: ${err.code}`); + return -1; // 异常场景下返回默认值 + } + + for (let i = 0; i < data.length; i++) { + if (data[i].sensorId === sensor.SensorId.GRAVITY) { + isSupported = true; + break; + } + } + try { + if (isSupported === true) { + const promise: Promise = new Promise((resolve) => { + sensor.once(sensor.SensorId.GRAVITY, (data: sensor.GravityResponse) => { + resolve(this.getRealData(data)); + }); + }) + return promise; + } else { + const promise: Promise = new Promise((resolve) => { + sensor.once(sensor.SensorId.ACCELEROMETER, (data: sensor.AccelerometerResponse) => { + resolve(this.getRealData(data as sensor.GravityResponse)); + }); + }) + return promise; + } + } catch (error) { + let err = error as BusinessError; + console.error(`gePromise failed, error: ${err.code}`); + return -1; // 异常场景下返回默认值 + } + } + //创建视频文件Fd initFd(): number { Logger.info(this.tag, 'initFd is called'); @@ -133,11 +202,6 @@ export struct modeSwitchPage { Logger.info(this.tag, `deviceType = phone`) this.videoConfig.videoSourceType = media.VideoSourceType.VIDEO_SOURCE_TYPE_SURFACE_YUV; this.videoConfig.profile.videoCodec = media.CodecMimeType.VIDEO_AVC; - if (this.cameraDeviceIndex == 1) { - this.videoConfig.rotation = this.photoRotationMap.rotation270; - } else { - this.videoConfig.rotation = this.photoRotationMap.rotation90; - } } if (deviceInfo.deviceType == 'tablet') { Logger.info(this.tag, `deviceType = tablet`); @@ -145,9 +209,9 @@ export struct modeSwitchPage { } //获取创建VideoOutput用的Profile,保证AVRecorder和VideoOutput的宽高以及帧率一致 - this.videoConfig.profile.videoFrameWidth = cameraDemo.getVideoFrameWidth(); - this.videoConfig.profile.videoFrameHeight = cameraDemo.getVideoFrameHeight(); - this.videoConfig.profile.videoFrameRate = cameraDemo.getVideoFrameRate(); + this.videoConfig.profile.videoFrameWidth = 1920; + this.videoConfig.profile.videoFrameHeight = 1080; + // this.videoConfig.profile.videoFrameRate = cameraDemo.getVideoFrameRate(); this.videoConfig.profile.isHdr = false; //HDR Vivid视频时的处理,videoCodec和isHdr需要注意 if (this.isHdrVideo) { @@ -159,9 +223,9 @@ export struct modeSwitchPage { fileFormat: media.ContainerFormatType.CFT_MPEG_4, videoBitrate: 2000000, videoCodec: media.CodecMimeType.VIDEO_HEVC, - videoFrameWidth: cameraDemo.getVideoFrameWidth(), - videoFrameHeight: cameraDemo.getVideoFrameHeight(), - videoFrameRate: cameraDemo.getVideoFrameRate(), + videoFrameWidth: 1920, + videoFrameHeight: 1080, + videoFrameRate: 30, isHdr: true }; this.videoConfig.audioSourceType = media.AudioSourceType.AUDIO_SOURCE_TYPE_MIC; @@ -189,7 +253,13 @@ export struct modeSwitchPage { clearInterval(this.timer); } // Start record - await this.getVideoSurfaceID(); + // await this.getVideoSurfaceID(); + // updateRotation + let deviceDegree = await this.getGravity(); + Logger.info(this.tag, `startVideo deviceDegree:${deviceDegree}`); + let videoRotation = cameraDemo.getVideoRotation(deviceDegree); + Logger.info(this.tag, `startVideo getVideoRotation:${videoRotation}`); + this.videoRecorder?.updateRotation(videoRotation); cameraDemo.startPhotoOrVideo(this.modelBagCol, this.videoId, this.mSurfaceId); cameraDemo.videoOutputStart(); if (this.videoRecorder) { @@ -198,7 +268,10 @@ export struct modeSwitchPage { } } - aboutToAppear() { + async aboutToAppear() { + if (this.isVideoMode) { + await this.getVideoSurfaceID(); + } } build() { @@ -212,7 +285,7 @@ export struct modeSwitchPage { .onClick(() => { cameraDemo.releaseSession() cameraDemo.setIsVideo(false); - cameraDemo.initCamera(this.surfaceId, this.settingDataObj.focusMode, this.cameraDeviceIndex) + cameraDemo.initCamera(this.surfaceId, this.videoId, this.settingDataObj.focusMode, this.cameraDeviceIndex) this.modelBagCol = 'photo' this.isVideoMode = false; }) @@ -224,10 +297,11 @@ export struct modeSwitchPage { .fontColor(Color.White) .borderRadius(14) .size({ width: 64, height: 28 }) - .onClick(() => { + .onClick(async () => { cameraDemo.releaseSession() cameraDemo.setIsVideo(true); - cameraDemo.initCamera(this.surfaceId, this.settingDataObj.focusMode, this.cameraDeviceIndex) + await this.getVideoSurfaceID(); + cameraDemo.initCamera(this.surfaceId, this.videoId, this.settingDataObj.focusMode, this.cameraDeviceIndex) this.modelBagCol = 'video' this.isVideoMode = true; }) @@ -303,11 +377,12 @@ export struct modeSwitchPage { cameraDemo.releaseSession(); // Start preview if (this.isVideoMode) { + await this.getVideoSurfaceID(); cameraDemo.setIsVideo(true); } else { cameraDemo.setIsVideo(false); } - cameraDemo.initCamera(this.surfaceId, this.settingDataObj.focusMode, this.cameraDeviceIndex); + cameraDemo.initCamera(this.surfaceId, this.videoId, this.settingDataObj.focusMode, this.cameraDeviceIndex); cameraDemo.enableHdrVideo(this.isHdrVideo); }) } @@ -382,7 +457,9 @@ export struct modeSwitchPage { try { if (this.videoRecorder) { await this.videoRecorder.stop(); - await this.videoRecorder.release(); + await this.videoRecorder.prepare(this.videoConfig); + await this.videoRecorder.getInputSurface(); + // await this.videoRecorder.release(); } cameraDemo.videoOutputStopAndRelease(); Logger.info(this.tag, 'stopVideo end'); diff --git a/CameraKit/NDKPreconfigSample/build-profile.json5 b/CameraKit/NDKPreconfigSample/build-profile.json5 index 375a8f182..f2b738d8d 100644 --- a/CameraKit/NDKPreconfigSample/build-profile.json5 +++ b/CameraKit/NDKPreconfigSample/build-profile.json5 @@ -19,14 +19,22 @@ { "name": "default", "signingConfig": "default", - "compatibleSdkVersion": "6.0.0(20)", - "runtimeOS": "HarmonyOS", - "targetSdkVersion": "6.0.0(20)", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } + "compileSdkVersion": 23, + "compatibleSdkVersion": 23, + "runtimeOS": "OpenHarmony" + } + ], + "signingConfigs": [ + { + "name": "default", + "material": { + "certpath": "C:/Users/wWX1366912/.ohos/config/openharmony/default_NDKPreconfigSample_RA0z0Wv2D78B_ht1X_3QXqtCZuiDp-3tSte9rmLhLzE=.cer", + "keyAlias": "debugKey", + "keyPassword": "0000001B214A71A03E0D5D7B130FF450331C409E9A3700A294B7BB4A335CDBEAA58D6F4A53A729D06C0F3A", + "profile": "C:/Users/wWX1366912/.ohos/config/openharmony/default_NDKPreconfigSample_RA0z0Wv2D78B_ht1X_3QXqtCZuiDp-3tSte9rmLhLzE=.p7b", + "signAlg": "SHA256withECDSA", + "storeFile": "C:/Users/wWX1366912/.ohos/config/openharmony/default_NDKPreconfigSample_RA0z0Wv2D78B_ht1X_3QXqtCZuiDp-3tSte9rmLhLzE=.p12", + "storePassword": "0000001B1D6E4C411BE25A89AF212963BCDFB3C70942AD6A149329A1131AC631703F8267B9CA21D6A2FF60" } } ] diff --git a/CameraKit/NDKPreconfigSample/entry/build-profile.json5 b/CameraKit/NDKPreconfigSample/entry/build-profile.json5 index a2dfc062f..dfd005b4a 100644 --- a/CameraKit/NDKPreconfigSample/entry/build-profile.json5 +++ b/CameraKit/NDKPreconfigSample/entry/build-profile.json5 @@ -37,7 +37,7 @@ "targets": [ { "name": "default", - "runtimeOS": "HarmonyOS" + "runtimeOS": "OpenHarmony" }, { "name": "ohosTest", diff --git a/CameraKit/NDKPreconfigSample/entry/src/main/cpp/camera_manager.cpp b/CameraKit/NDKPreconfigSample/entry/src/main/cpp/camera_manager.cpp index 9b56d2a4d..a49874a23 100644 --- a/CameraKit/NDKPreconfigSample/entry/src/main/cpp/camera_manager.cpp +++ b/CameraKit/NDKPreconfigSample/entry/src/main/cpp/camera_manager.cpp @@ -32,8 +32,6 @@ const OH_ImageSourceNative *imageSourceNaive; OH_MediaAssetManager *mediaAssetManager; MediaLibrary_RequestId g_requestId; MediaLibrary_RequestOptions requestOptions; -bool g_isMovingPhoto = false; -bool g_isSavingPhoto = true; const char *g_uri; char *g_mediaQualityCb; MediaLibrary_DeliveryMode g_deliveryMode = MEDIA_LIBRARY_BALANCED_MODE; @@ -72,7 +70,7 @@ const std::unordered_map g_int32ToCameraPreconf NDKCamera::NDKCamera(char *str, uint32_t focusMode, uint32_t cameraDeviceIndex, uint32_t sceneMode, uint32_t preconfigMode, uint32_t preconfigType, uint32_t preconfigRatio, uint32_t photoOutputType, - bool isMovingPhoto, bool isSavingPhoto) + char *videoId, char *photoId) : previewSurfaceId_(str), cameras_(nullptr), focusMode_(focusMode), @@ -83,7 +81,7 @@ NDKCamera::NDKCamera(char *str, uint32_t focusMode, uint32_t cameraDeviceIndex, size_(0), isCameraMuted_(nullptr), profile_(nullptr), - photoSurfaceId_(nullptr), + photoSurfaceId_(photoId), previewOutput_(nullptr), photoOutput_(nullptr), metaDataObjectType_(nullptr), @@ -105,13 +103,11 @@ NDKCamera::NDKCamera(char *str, uint32_t focusMode, uint32_t cameraDeviceIndex, sceneModeSize_(0), preconfigMode_(preconfigMode), isSuccess_(false), - preconfigged_(false), + preconfigged_(true), photoOutputType_(photoOutputType), - isMovingPhoto_(isMovingPhoto) + videoSurfaceId_(videoId) { valid_ = false; - g_isMovingPhoto = isMovingPhoto; - g_isSavingPhoto = isSavingPhoto; ReleaseCamera(); Camera_ErrorCode ret = OH_Camera_GetCameraManager(&cameraManager_); if (cameraManager_ == nullptr || ret != CAMERA_OK) { @@ -126,15 +122,15 @@ NDKCamera::NDKCamera(char *str, uint32_t focusMode, uint32_t cameraDeviceIndex, auto sceneModeItr = g_int32ToCameraSceneMode.find(sceneMode); if (sceneModeItr != g_int32ToCameraSceneMode.end()) { sceneMode_ = sceneModeItr->second; - DRAWING_LOGD("Constructor: sceneMode %{public}d converted to sceneMode_=%{public}d", sceneMode, sceneMode_); + OH_LOG_INFO(LOG_APP, "Constructor: sceneMode %{public}d converted to sceneMode_=%{public}d", sceneMode, sceneMode_); } - DRAWING_LOGD("Constructor received: preconfigMode=%{public}d, preconfigType=%{public}d, preconfigRatio=%{public}d", + OH_LOG_INFO(LOG_APP, "Constructor received: preconfigMode=%{public}d, preconfigType=%{public}d, preconfigRatio=%{public}d", preconfigMode, preconfigType, preconfigRatio); auto preconfigTypeItr = g_int32ToCameraPreconfigType.find(preconfigType); if (preconfigTypeItr != g_int32ToCameraPreconfigType.end()) { preconfigType_ = preconfigTypeItr->second; - DRAWING_LOGD("preconfigType_ converted to: %{public}d", preconfigType_); + OH_LOG_INFO(LOG_APP, "preconfigType_ converted to: %{public}d", preconfigType_); } isHdrVideo = (preconfigType_ == Camera_PreconfigType::PRECONFIG_HIGH_QUALITY); @@ -142,12 +138,12 @@ NDKCamera::NDKCamera(char *str, uint32_t focusMode, uint32_t cameraDeviceIndex, auto preconfigRatioItr = g_int32ToCameraPreconfigRatio.find(preconfigRatio); if (preconfigRatioItr != g_int32ToCameraPreconfigRatio.end()) { preconfigRatio_ = preconfigRatioItr->second; - DRAWING_LOGD("preconfigRatio_ converted to: %{public}d", preconfigRatio_); + OH_LOG_INFO(LOG_APP, "preconfigRatio_ converted to: %{public}d", preconfigRatio_); } // expect CAMERA_OK ret = OH_CaptureSession_SetSessionMode(captureSession_, sceneMode_); - DRAWING_LOGD("OH_CaptureSession_SetSessionMode sceneMode_: %{public}d! ret code: %{public}d", sceneMode_, ret); + OH_LOG_INFO(LOG_APP, "OH_CaptureSession_SetSessionMode sceneMode_: %{public}d! ret code: %{public}d", sceneMode_, ret); CaptureSessionRegisterCallback(); GetSupportedCameras(); @@ -156,6 +152,11 @@ NDKCamera::NDKCamera(char *str, uint32_t focusMode, uint32_t cameraDeviceIndex, GetSupportedOutputCapability(); CreatePreviewOutput(); + if (sceneMode_ == Camera_SceneMode::NORMAL_VIDEO) { + CreateVideoOutput(videoSurfaceId_); + } else { + CreatePhotoOutput(photoSurfaceId_); + } CreateCameraInput(); CameraInputOpen(); CameraManagerRegisterCallback(); @@ -319,7 +320,7 @@ Camera_ErrorCode NDKCamera::SessionBegin(void) Camera_ErrorCode NDKCamera::SessionCommitConfig(void) { - DRAWING_LOGD("SessionCommitConfig: captureSession_=%{public}p", captureSession_); + OH_LOG_INFO(LOG_APP, "SessionCommitConfig: captureSession_=%{public}p", captureSession_); if (captureSession_ == nullptr) { OH_LOG_ERROR(LOG_APP, "ERROR: captureSession_ is nullptr in CommitConfig!"); @@ -337,7 +338,7 @@ Camera_ErrorCode NDKCamera::SessionCommitConfig(void) Camera_ErrorCode NDKCamera::SessionStart(void) { - DRAWING_LOGD("SessionStart: captureSession_=%{public}p", captureSession_); + OH_LOG_INFO(LOG_APP, "SessionStart: captureSession_=%{public}p", captureSession_); if (captureSession_ == nullptr) { OH_LOG_ERROR(LOG_APP, "ERROR: captureSession_ is nullptr in Start!"); @@ -374,7 +375,7 @@ Camera_ErrorCode NDKCamera::SessionFlowFn(void) isSuccess_ = false; CanAddInput(&isSuccess_); if (!isSuccess_) { - DRAWING_LOGD("NDKCamera::SessionFlowFn can not add input!"); + OH_LOG_INFO(LOG_APP, "NDKCamera::SessionFlowFn can not add input!"); return Camera_ErrorCode::CAMERA_OPERATION_NOT_ALLOWED; } @@ -385,18 +386,44 @@ Camera_ErrorCode NDKCamera::SessionFlowFn(void) isSuccess_ = false; CanAddPreviewOutput(&isSuccess_); if (!isSuccess_) { - DRAWING_LOGD("NDKCamera::SessionFlowFn can not add preview output!"); + OH_LOG_INFO(LOG_APP, "NDKCamera::SessionFlowFn can not add preview output!"); return Camera_ErrorCode::CAMERA_OPERATION_NOT_ALLOWED; } // Add previewOutput to the session OH_LOG_INFO(LOG_APP, "session add Preview Output."); ret = OH_CaptureSession_AddPreviewOutput(captureSession_, previewOutput_); - + if (sceneMode_ == Camera_SceneMode::NORMAL_VIDEO) { + if (videoOutput_ == nullptr) { + OH_LOG_INFO(LOG_APP, "videoOutput_ is nullptr"); + } + ret = OH_CaptureSession_AddVideoOutput(captureSession_, videoOutput_); + bool isMirrorSupported = false; + ret = OH_VideoOutput_IsMirrorSupported(videoOutput_, &isMirrorSupported); + OH_LOG_INFO(LOG_APP, "VideoOutput IsMirrorSupported: %{public}d", isMirrorSupported); + if (isMirrorSupported) { + OH_VideoOutput_EnableMirror(videoOutput_, isMirrorSupported); + } + if (preconfigType_ == Camera_PreconfigType::PRECONFIG_HIGH_QUALITY) { + OH_NativeBuffer_ColorSpace colorSpace = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT2020_HLG_LIMIT; + SetColorSpace(colorSpace); + } + VideoOutputRegisterCallback(); + } else { + if (photoOutput_ == nullptr) { + OH_LOG_INFO(LOG_APP, "photoOutput_ is nullptr"); + } + ret = AddPhotoOutput(); + } + // Submit configuration information OH_LOG_INFO(LOG_APP, "session commitConfig"); ret = OH_CaptureSession_CommitConfig(captureSession_); + if (preconfigType_ == Camera_PreconfigType::PRECONFIG_HIGH_QUALITY) { + uint32_t mode = static_cast(Camera_VideoStabilizationMode::STABILIZATION_MODE_AUTO); + IsVideoStabilizationModeSupportedFn(mode); + } // Start Session Work OH_LOG_INFO(LOG_APP, "session start"); ret = OH_CaptureSession_Start(captureSession_); @@ -405,9 +432,14 @@ Camera_ErrorCode NDKCamera::SessionFlowFn(void) } // Get and print active profiles after session started - DRAWING_LOGD("===== Getting Active Profiles ====="); + OH_LOG_INFO(LOG_APP, "===== Getting Active Profiles ====="); GetActivePreviewOutputProfile(); - GetActivePhotoOutputProfile(); + if (photoOutput_&& sceneMode_ == Camera_SceneMode::NORMAL_PHOTO) { + GetActivePhotoOutputProfile(); + } + if (videoOutput_ && sceneMode_ == Camera_SceneMode::NORMAL_VIDEO) { + GetActiveVideoOutputProfile(); + } // Start focusing OH_LOG_INFO(LOG_APP, "IsFocusMode start"); @@ -513,297 +545,89 @@ Camera_ErrorCode NDKCamera::GetSupportedOutputCapability(void) Camera_ErrorCode NDKCamera::CreatePreviewOutput(void) { - DRAWING_LOGD("NDKCamera::CreatePreviewOutput start!"); - DRAWING_LOGD("preconfigMode_=%{public}d (1=NO_PRECONFIG, 2=TYPE_PRECONFIG, 3=TYPE_RATIO_PRECONFIG)", - preconfigMode_); + OH_LOG_INFO(LOG_APP, "NDKCamera::CreatePreviewOutput start!"); + OH_LOG_INFO(LOG_APP, "preconfigMode_=%{public}d, preconfigType_=%{public}d, preconfigRatio_=%{public}d", preconfigMode_, + preconfigType_, preconfigRatio_); isSuccess_ = false; - if (preconfigMode_ == TYPE_RATIO_PRECONFIG_MODE) { - DRAWING_LOGD("Entering TYPE_RATIO_PRECONFIG_MODE branch"); - ret_ = CanPreconfigWithRatio(&isSuccess_); - if (ret_ != CAMERA_OK) { - DRAWING_LOGD("NDKCamera::CreatePreviewOutput CanPreconfigWithRatio failed!"); - return CAMERA_INVALID_ARGUMENT; - } - DRAWING_LOGD("CanPreconfigWithRatio returned isSuccess=%{public}d", isSuccess_); - } else if (preconfigMode_ == TYPE_PRECONFIG_MODE) { - DRAWING_LOGD("Entering TYPE_PRECONFIG_MODE branch"); - ret_ = CanPreconfig(&isSuccess_); - if (ret_ != CAMERA_OK) { - DRAWING_LOGD("NDKCamera::CreatePreviewOutput CanPreconfig failed!"); - return CAMERA_INVALID_ARGUMENT; - } - DRAWING_LOGD("CanPreconfig returned isSuccess=%{public}d", isSuccess_); - } else { - DRAWING_LOGD("No preconfig check, preconfigMode_=%{public}d", preconfigMode_); + ret_ = CanPreconfigWithRatio(&isSuccess_); + if (ret_ != CAMERA_OK) { + OH_LOG_INFO(LOG_APP, "NDKCamera::CreatePreviewOutput CanPreconfigWithRatio failed!"); } - - if (preconfigMode_ == NO_PRECONFIG_MODE || !isSuccess_) { - DRAWING_LOGD("*** ENTERING NORMAL BRANCH *** (preconfigMode_=%{public}d, isSuccess=%{public}d)", preconfigMode_, - isSuccess_); - DRAWING_LOGD("NDKCamera::CreatePreviewOutput into normal branch!"); - profile_ = cameraOutputCapability_->previewProfiles[0]; - if (profile_ == nullptr) { - OH_LOG_ERROR(LOG_APP, "Get previewProfiles failed."); - return CAMERA_INVALID_ARGUMENT; - } - cameraProfile_ = cameraOutputCapability_->previewProfiles[0]; - for (int i = 0; i < cameraOutputCapability_->videoProfilesSize; i++) { - videoProfile_ = cameraOutputCapability_->videoProfiles[i]; - if (AreFloatsEqual(static_cast(cameraProfile_->size.width) / cameraProfile_->size.height, - static_cast(videoProfile_->size.width) / videoProfile_->size.height)) { - OH_LOG_ERROR(LOG_APP, "video width: %{public}d, height: %{public}d", videoProfile_->size.width, - videoProfile_->size.height); - OH_LOG_ERROR(LOG_APP, "preview width: %{public}f, height: %{public}f", - static_cast(cameraProfile_->size.width), static_cast(cameraProfile_->size.height)); - break; - } - } - ret_ = OH_CameraManager_CreatePreviewOutput(cameraManager_, cameraProfile_, previewSurfaceId_, &previewOutput_); - if (previewSurfaceId_ == nullptr || previewOutput_ == nullptr || ret_ != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "CreatePreviewOutput failed."); - return CAMERA_INVALID_ARGUMENT; - } - PreviewOutputRegisterCallback(); - return ret_; - } else { - DRAWING_LOGD("*** ENTERING PRECONFIG BRANCH *** (preconfigMode_=%{public}d)", preconfigMode_); - DRAWING_LOGD("NDKCamera::CreatePreviewOutput into preconfig branch!"); - DRAWING_LOGD("===== PreviewOutput in Preconfig Mode ====="); - DRAWING_LOGD("preconfigMode_=%{public}d, preconfigType_=%{public}d, preconfigRatio_=%{public}d", preconfigMode_, - preconfigType_, preconfigRatio_); - - if (preconfigMode_ == TYPE_RATIO_PRECONFIG_MODE) { - DRAWING_LOGD("Calling PreconfigWithRatio()"); - DRAWING_LOGD("Using PreconfigWithRatio for preview"); - ret_ = PreconfigWithRatio(); - if (ret_ != CAMERA_OK) { - DRAWING_LOGD("NDKCamera::CreatePreviewOutput PreconfigWithRatio failed!"); - DRAWING_LOGD("ERROR: PreconfigWithRatio failed! ret=%{public}d", ret_); - return CAMERA_INVALID_ARGUMENT; - } - DRAWING_LOGD("PreconfigWithRatio success"); - } else { - DRAWING_LOGD("Calling Preconfig()"); - DRAWING_LOGD("Using Preconfig for preview"); - ret_ = Preconfig(); - if (ret_ != CAMERA_OK) { - DRAWING_LOGD("NDKCamera::CreatePreviewOutput Preconfig failed!"); - DRAWING_LOGD("ERROR: Preconfig failed! ret=%{public}d", ret_); - return CAMERA_INVALID_ARGUMENT; - } - DRAWING_LOGD("Preconfig success"); - } - - // 在预配置模式下,需要初始化 cameraProfile_ 用于后续匹配 - DRAWING_LOGD("Initializing cameraProfile_..."); - if (cameraOutputCapability_ == nullptr) { - DRAWING_LOGD("ERROR: cameraOutputCapability_ is nullptr!"); - return CAMERA_INVALID_ARGUMENT; - } - if (cameraOutputCapability_->previewProfilesSize == 0 || cameraOutputCapability_->previewProfiles == nullptr) { - DRAWING_LOGD("ERROR: No preview profiles available!"); - return CAMERA_INVALID_ARGUMENT; - } - cameraProfile_ = cameraOutputCapability_->previewProfiles[0]; - if (cameraProfile_ == nullptr) { - DRAWING_LOGD("ERROR: cameraProfile_ is nullptr after initialization!"); - return CAMERA_INVALID_ARGUMENT; - } - DRAWING_LOGD("cameraProfile_ initialized: %{public}dx%{public}d", cameraProfile_->size.width, - cameraProfile_->size.height); - - // 注意:在预配置模式下,videoProfile 不应该基于预览宽高比匹配 - // 预配置 API 会根据 preconfigType 和 preconfigRatio 自动选择合适的 profile - // 这里只是为了兼容性保留 videoProfile_ 的设置,但实际不应该依赖它 - DRAWING_LOGD("In preconfig mode, videoProfile will be determined by preconfig API"); - DRAWING_LOGD("preconfigType_=%{public}d, preconfigRatio_=%{public}d", preconfigType_, preconfigRatio_); - - // 暂时设置为 nullptr,让预配置 API 处理 - // 如果需要,可以在这里根据 preconfigType 和 preconfigRatio 推断期望的分辨率 - videoProfile_ = nullptr; - - // 可选:根据 preconfigType 和 preconfigRatio 查找匹配的 videoProfile(用于日志参考) - if (cameraOutputCapability_->videoProfilesSize > 0 && cameraOutputCapability_->videoProfiles != nullptr) { - // 根据 preconfigType 确定期望的分辨率 - int expectedWidth = 0; - int expectedHeight = 0; - switch (preconfigType_) { - case Camera_PreconfigType::PRECONFIG_720P: - expectedHeight = NUM_720; - break; - case Camera_PreconfigType::PRECONFIG_1080P: - expectedHeight = NUM_1080; - break; - case Camera_PreconfigType::PRECONFIG_4K: - expectedHeight = NUM_2160; - break; - case Camera_PreconfigType::PRECONFIG_HIGH_QUALITY: - expectedHeight = 0; // 高质量模式,使用最高分辨率 - break; - } - - // 根据 preconfigRatio 确定宽高比 - float expectedRatio = 1.0f; - switch (preconfigRatio_) { - case Camera_PreconfigRatio::PRECONFIG_RATIO_1_1: - expectedRatio = 1.0f; // 1:1 - break; - case Camera_PreconfigRatio::PRECONFIG_RATIO_4_3: - expectedRatio = 4.0f / 3.0f; // 4:3 - break; - case Camera_PreconfigRatio::PRECONFIG_RATIO_16_9: - expectedRatio = 16.0f / 9.0f; // 16:9 - break; - } - - if (expectedHeight > 0) { - expectedWidth = static_cast(expectedHeight * expectedRatio); - } - - DRAWING_LOGD("Expected video resolution from preconfig: %{public}dx%{public}d (ratio=%.2f)", expectedWidth, - expectedHeight, expectedRatio); - - // 查找最接近的 videoProfile(仅用于参考,不影响实际使用) - for (int i = 0; i < cameraOutputCapability_->videoProfilesSize; i++) { - if (cameraOutputCapability_->videoProfiles[i] != nullptr) { - int w = cameraOutputCapability_->videoProfiles[i]->size.width; - int h = cameraOutputCapability_->videoProfiles[i]->size.height; - float ratio = (float)w / h; - - DRAWING_LOGD( - "Available video profile[%{public}d]: %{public}dx%{public}d (ratio=%.2f, format=%{public}d)", i, - w, h, ratio, cameraOutputCapability_->videoProfiles[i]->format); - - // 如果找到匹配的,记录下来(但不强制使用) - if (expectedHeight > 0 && h == expectedHeight && AreFloatsEqual(ratio, expectedRatio)) { - videoProfile_ = cameraOutputCapability_->videoProfiles[i]; - DRAWING_LOGD("Found matching video profile (for reference): %{public}dx%{public}d", w, h); - } - } - } - } - - if (videoProfile_ == nullptr) { - DRAWING_LOGD("No exact matching video profile found, will rely on preconfig API"); - } else { - DRAWING_LOGD("Reference video profile: %{public}dx%{public}d, format=%{public}d", videoProfile_->size.width, - videoProfile_->size.height, videoProfile_->format); - } - - preconfigged_ = true; - DRAWING_LOGD("Set preconfigged_=true, creating preview output..."); - ret_ = OH_CameraManager_CreatePreviewOutputUsedInPreconfig(cameraManager_, previewSurfaceId_, &previewOutput_); - if (previewOutput_ == nullptr || ret_ != CAMERA_OK) { - DRAWING_LOGD("OH_CameraManager_CreatePreviewOutputUsedInPreconfig failed!"); - DRAWING_LOGD("ERROR: CreatePreviewOutputUsedInPreconfig failed! ret=%{public}d", ret_); - OH_LOG_ERROR(LOG_APP, "CreatePreviewOutput failed."); - return CAMERA_INVALID_ARGUMENT; - } - DRAWING_LOGD("OH_CameraManager_CreatePreviewOutputUsedInPreconfig return with ret code: %{public}d!", ret_); - PreviewOutputRegisterCallback(); - return ret_; + OH_LOG_INFO(LOG_APP, "CanPreconfigWithRatio returned isSuccess=%{public}d", isSuccess_); + + ret_ = PreconfigWithRatio(); + if (ret_ != CAMERA_OK) { + OH_LOG_INFO(LOG_APP, "NDKCamera::CreatePreviewOutput PreconfigWithRatio failed!"); } + OH_LOG_INFO(LOG_APP, "PreconfigWithRatio success"); + ret_ = OH_CameraManager_CreatePreviewOutputUsedInPreconfig(cameraManager_, previewSurfaceId_, &previewOutput_); + if (previewOutput_ == nullptr || ret_ != CAMERA_OK) { + OH_LOG_INFO(LOG_APP, "OH_CameraManager_CreatePreviewOutputUsedInPreconfig failed!"); + OH_LOG_INFO(LOG_APP, "ERROR: CreatePreviewOutputUsedInPreconfig failed! ret=%{public}d", ret_); + OH_LOG_ERROR(LOG_APP, "CreatePreviewOutput failed."); + return CAMERA_INVALID_ARGUMENT; + } + OH_LOG_INFO(LOG_APP, "OH_CameraManager_CreatePreviewOutputUsedInPreconfig return with ret code: %{public}d!", ret_); + PreviewOutputRegisterCallback(); + return ret_; } Camera_ErrorCode NDKCamera::CreatePhotoOutput(char *photoSurfaceId) { - if (preconfigged_) { - DRAWING_LOGD("NDKCamera::CreatePhotoOutput into preconfigged branch!"); - ret_ = OH_CameraManager_CreatePhotoOutputUsedInPreconfig(cameraManager_, photoSurfaceId, &photoOutput_); - if (photoOutput_ == nullptr || ret_ != CAMERA_OK) { - DRAWING_LOGD("OH_CameraManager_CreatePhotoOutputUsedInPreconfig failed!"); - OH_LOG_ERROR(LOG_APP, "CreatePhotoOutput failed."); - return CAMERA_INVALID_ARGUMENT; - } - DRAWING_LOGD("OH_CameraManager_CreatePhotoOutputUsedInPreconfig return with ret code: %{public}d!", ret_); - PhotoOutputRegisterCallback(); - return ret_; - } else { - DRAWING_LOGD("NDKCamera::CreatePhotoOutput into normal branch!"); - profile_ = cameraOutputCapability_->photoProfiles[0]; - if (profile_ == nullptr) { - OH_LOG_ERROR(LOG_APP, "Get photoProfiles failed."); - return CAMERA_INVALID_ARGUMENT; - } - - if (photoSurfaceId == nullptr) { - OH_LOG_ERROR(LOG_APP, "CreatePhotoOutput failed."); - return CAMERA_INVALID_ARGUMENT; - } - - ret_ = OH_CameraManager_CreatePhotoOutput(cameraManager_, profile_, photoSurfaceId, &photoOutput_); - PhotoOutputRegisterCallback(); - return ret_; + OH_LOG_INFO(LOG_APP, "NDKCamera::CreatePhotoOutput into preconfigged branch!"); + ret_ = OH_CameraManager_CreatePhotoOutputUsedInPreconfig(cameraManager_, photoSurfaceId, &photoOutput_); + if (photoOutput_ == nullptr || ret_ != CAMERA_OK) { + OH_LOG_INFO(LOG_APP, "OH_CameraManager_CreatePhotoOutputUsedInPreconfig failed!"); + OH_LOG_ERROR(LOG_APP, "CreatePhotoOutput failed."); + return CAMERA_INVALID_ARGUMENT; } + OH_LOG_INFO(LOG_APP, "OH_CameraManager_CreatePhotoOutputUsedInPreconfig return with ret code: %{public}d!", ret_); + PhotoOutputRegisterCallback(); + return ret_; } Camera_ErrorCode NDKCamera::CreatePhotoOutputWithoutSurfaceId() { - DRAWING_LOGD("NDKCamera::CreatePhotoOutput into createWithoutSurfaceID branch!"); + OH_LOG_INFO(LOG_APP, "NDKCamera::CreatePhotoOutput into createWithoutSurfaceID branch!"); cameraProfile_ = cameraOutputCapability_->photoProfiles[0]; ret_ = OH_CameraManager_CreatePhotoOutputWithoutSurface(cameraManager_, cameraProfile_, &photoOutput_); if (photoOutput_ == nullptr || ret_ != CAMERA_OK) { - DRAWING_LOGD("OH_CameraManager_CreatePhotoOutputWithoutSurface failed!"); + OH_LOG_INFO(LOG_APP, "OH_CameraManager_CreatePhotoOutputWithoutSurface failed!"); OH_LOG_ERROR(LOG_APP, "CreatePhotoOutput failed."); return CAMERA_INVALID_ARGUMENT; } - DRAWING_LOGD("NDKCamera::CreatePhotoOutput register photo asset available callback!"); + OH_LOG_INFO(LOG_APP, "NDKCamera::CreatePhotoOutput register photo asset available callback!"); PhotoOutputRegisterPhotoAssetAvailableCallback(); return ret_; } Camera_ErrorCode NDKCamera::CreateVideoOutput(char *videoId) { - DRAWING_LOGD("NDKCamera::CreateVideoOutput start!"); + OH_LOG_INFO(LOG_APP, "NDKCamera::CreateVideoOutput start!"); // 添加参数检查 if (videoId == nullptr) { - DRAWING_LOGD("ERROR: videoId is nullptr!"); + OH_LOG_INFO(LOG_APP, "ERROR: videoId is nullptr!"); return CAMERA_INVALID_ARGUMENT; } if (cameraManager_ == nullptr) { - DRAWING_LOGD("ERROR: cameraManager_ is nullptr!"); + OH_LOG_INFO(LOG_APP, "ERROR: cameraManager_ is nullptr!"); return CAMERA_INVALID_ARGUMENT; } - if (preconfigged_) { - DRAWING_LOGD("NDKCamera::CreateVideoOutput into preconfigged_ branch!"); - ret_ = OH_CameraManager_CreateVideoOutputUsedInPreconfig(cameraManager_, videoId, &videoOutput_); - if (videoOutput_ == nullptr || ret_ != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "CreateVideoOutput failed."); - return CAMERA_INVALID_ARGUMENT; - } - DRAWING_LOGD("Successfully created video output for preconfig mode"); - return ret_; - } else { - DRAWING_LOGD("NDKCamera::CreateVideoOutput into normal branch!"); - if (cameraOutputCapability_ == nullptr) { - OH_LOG_ERROR(LOG_APP, "ERROR: cameraOutputCapability_ is nullptr!"); - return CAMERA_INVALID_ARGUMENT; - } - if (videoProfile_ == nullptr) { - OH_LOG_ERROR(LOG_APP, "ERROR: Get videoProfiles failed - videoProfile is nullptr!"); - return CAMERA_INVALID_ARGUMENT; - } - DRAWING_LOGD( - "videoProfile: width=%{public}d, height=%{public}d, format=%{public}d, frameRate=[%{public}d,%{public}d]", - videoProfile_->size.width, videoProfile_->size.height, videoProfile_->format, videoProfile_->range.min, - videoProfile_->range.max); - ret_ = OH_CameraManager_CreateVideoOutput(cameraManager_, videoProfile_, videoId, &videoOutput_); - if (videoId == nullptr || videoOutput_ == nullptr || ret_ != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, - "ERROR: CreateVideoOutput failed! ret=%{public}d, videoId=%{public}s, videoOutput_=%{public}p", ret_, - videoId ? videoId : "null", videoOutput_); - return CAMERA_INVALID_ARGUMENT; - } - - DRAWING_LOGD("CreateVideoOutput success! ret=%{public}d, videoOutput_=%{public}p", ret_, videoOutput_); - return ret_; + OH_LOG_INFO(LOG_APP, "NDKCamera::CreateVideoOutput into preconfigged_ branch!"); + OH_LOG_INFO(LOG_APP, "CreateVideoOutput %{public}s", videoId); + ret_ = OH_CameraManager_CreateVideoOutputUsedInPreconfig(cameraManager_, videoId, &videoOutput_); + if (videoOutput_ == nullptr || ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "CreateVideoOutput failed."); + return CAMERA_INVALID_ARGUMENT; } + OH_LOG_INFO(LOG_APP, "Successfully created video output for preconfig mode"); + return ret_; } Camera_ErrorCode NDKCamera::AddVideoOutput(void) { - DRAWING_LOGD("AddVideoOutput: captureSession_=%{public}p, videoOutput_=%{public}p", captureSession_, videoOutput_); + OH_LOG_INFO(LOG_APP, "AddVideoOutput: captureSession_=%{public}p, videoOutput_=%{public}p", captureSession_, videoOutput_); if (captureSession_ == nullptr) { OH_LOG_ERROR(LOG_APP, "ERROR: captureSession_ is nullptr!"); @@ -948,251 +772,8 @@ Camera_ErrorCode NDKCamera::SetColorSpace(OH_NativeBuffer_ColorSpace colorSpace) Camera_ErrorCode NDKCamera::StartVideo(char *videoId, char *photoId) { OH_LOG_INFO(LOG_APP, "StartVideo: isHdrVideo is %{public}d", isHdrVideo); - if (videoId == nullptr) { - DRAWING_LOGD("ERROR: videoId is nullptr!"); - return CAMERA_INVALID_ARGUMENT; - } - if (captureSession_ == nullptr) { - DRAWING_LOGD("ERROR: captureSession_ is nullptr!"); - return CAMERA_INVALID_ARGUMENT; - } - if (cameraManager_ == nullptr) { - DRAWING_LOGD("ERROR: cameraManager_ is nullptr!"); - return CAMERA_INVALID_ARGUMENT; - } - - Camera_ErrorCode ret = SessionStop(); - if (ret == CAMERA_OK) { - OH_LOG_INFO(LOG_APP, "SessionStop success."); - } else { - OH_LOG_ERROR(LOG_APP, "SessionStop failed. %d ", ret); - } - if (sceneMode_ != Camera_SceneMode::NORMAL_VIDEO) { - // 1. 释放当前会话 - DRAWING_LOGD("Releasing current session..."); - if (captureSession_ != nullptr) { - ret = OH_CaptureSession_Release(captureSession_); - DRAWING_LOGD("OH_CaptureSession_Release returned: ret=%{public}d", ret); - captureSession_ = nullptr; - } - - // 2. 重新创建会话 - DRAWING_LOGD("Creating new session with NORMAL_VIDEO mode..."); - ret = OH_CameraManager_CreateCaptureSession(cameraManager_, &captureSession_); - if (captureSession_ == nullptr || ret != CAMERA_OK) { - DRAWING_LOGD("ERROR: Failed to create new capture session! ret=%{public}d", ret); - OH_LOG_ERROR(LOG_APP, "Create captureSession failed."); - return ret; - } - - // 3. 设置场景模式为 NORMAL_VIDEO - sceneMode_ = Camera_SceneMode::NORMAL_VIDEO; - ret = OH_CaptureSession_SetSessionMode(captureSession_, sceneMode_); - if (ret != CAMERA_OK) { - DRAWING_LOGD("ERROR: SetSessionMode failed! ret=%{public}d", ret); - return ret; - } - - // 4. 重新注册会话回调 - CaptureSessionRegisterCallback(); - - // 5. 重新获取输出能力 - ret = GetSupportedOutputCapabilityWithSceneMode(sceneMode_); - if (ret != CAMERA_OK) { - DRAWING_LOGD("ERROR: GetSupportedOutputCapabilityWithSceneMode failed: ret=%{public}d", ret); - return ret; - } - - // 6. 在预配置模式下,重置 preconfigged_ 标志,因为需要重新预配置 - if (preconfigMode_ != NO_PRECONFIG_MODE) { - DRAWING_LOGD("Resetting preconfigged_ flag for new session"); - preconfigged_ = false; - } - } else { - DRAWING_LOGD("sceneMode_ is already NORMAL_VIDEO, no need to recreate session"); - } - - ret = SessionBegin(); - if (ret == CAMERA_OK) { - OH_LOG_INFO(LOG_APP, "SessionBegin success."); - } else { - OH_LOG_ERROR(LOG_APP, "SessionBegin failed. %d ", ret); - return ret; - } - - // 在预配置模式下,SessionBegin 之后需要预配置(针对录像模式) - if (preconfigMode_ != NO_PRECONFIG_MODE) { - if (preconfigMode_ == TYPE_RATIO_PRECONFIG_MODE) { - // 先检查是否支持该预配置 - bool canPreconfig = false; - ret = OH_CaptureSession_CanPreconfigWithRatio(captureSession_, preconfigType_, preconfigRatio_, - &canPreconfig); - DRAWING_LOGD( - "CanPreconfigWithRatio (type=%{public}d, ratio=%{public}d): canPreconfig=%{public}d, ret=%{public}d", - preconfigType_, preconfigRatio_, canPreconfig, ret); - - if (ret != CAMERA_OK) { - DRAWING_LOGD("ERROR: CanPreconfigWithRatio failed! ret=%{public}d", ret); - return ret; - } - - if (!canPreconfig) { - DRAWING_LOGD( - "WARNING: PreconfigWithRatio (type=%{public}d, ratio=%{public}d) is NOT supported by device!", - preconfigType_, preconfigRatio_); - } - ret = OH_CaptureSession_PreconfigWithRatio(captureSession_, preconfigType_, preconfigRatio_); - DRAWING_LOGD("PreconfigWithRatio returned: ret=%{public}d", ret); - if (ret != CAMERA_OK) { - DRAWING_LOGD("ERROR: PreconfigWithRatio failed! ret=%{public}d", ret); - return ret; - } - preconfigged_ = true; - } else if (preconfigMode_ == TYPE_PRECONFIG_MODE) { - ret = OH_CaptureSession_Preconfig(captureSession_, preconfigType_); - DRAWING_LOGD("Preconfig returned: ret=%{public}d", ret); - if (ret != CAMERA_OK) { - DRAWING_LOGD("ERROR: Preconfig failed! ret=%{public}d", ret); - return ret; - } - preconfigged_ = true; - } - } else { - DRAWING_LOGD("Not in preconfig mode, skip preconfig step"); - } - bool needAddInputOutput = false; - isSuccess_ = false; - ret = OH_CaptureSession_CanAddInput(captureSession_, cameraInput_, &isSuccess_); - if (ret == CAMERA_OK && isSuccess_) { - needAddInputOutput = true; - DRAWING_LOGD("Session was recreated, need to re-add CameraInput and PreviewOutput"); - } - if (needAddInputOutput) { - // 添加 CameraInput - ret = OH_CaptureSession_AddInput(captureSession_, cameraInput_); - if (ret != CAMERA_OK) { - DRAWING_LOGD("ERROR: Failed to add CameraInput! ret=%{public}d", ret); - return ret; - } - DRAWING_LOGD("Need to recreate PreviewOutput for new session..."); - - // 释放旧的 PreviewOutput - if (previewOutput_ != nullptr) { - DRAWING_LOGD("Releasing old PreviewOutput..."); - ret = OH_PreviewOutput_Release(previewOutput_); - DRAWING_LOGD("OH_PreviewOutput_Release returned: ret=%{public}d", ret); - previewOutput_ = nullptr; - } - - // 重新创建 PreviewOutput(使用预配置模式) - if (preconfigged_) { - ret = - OH_CameraManager_CreatePreviewOutputUsedInPreconfig(cameraManager_, previewSurfaceId_, &previewOutput_); - DRAWING_LOGD("OH_CameraManager_CreatePreviewOutputUsedInPreconfig returned: ret=%{public}d, " - "previewOutput_=%{public}p", - ret, previewOutput_); - } else { - // 如果不是预配置模式,使用普通方式创建 - profile_ = cameraOutputCapability_->previewProfiles[0]; - ret = OH_CameraManager_CreatePreviewOutput(cameraManager_, profile_, previewSurfaceId_, &previewOutput_); - DRAWING_LOGD("OH_CameraManager_CreatePreviewOutput returned: ret=%{public}d, previewOutput_=%{public}p", - ret, previewOutput_); - } - - if (previewOutput_ == nullptr || ret != CAMERA_OK) { - DRAWING_LOGD("ERROR: Failed to recreate PreviewOutput! ret=%{public}d", ret); - return ret; - } - - // 注册 PreviewOutput 回调 - PreviewOutputRegisterCallback(); - - // 添加 PreviewOutput 到新会话 - ret = OH_CaptureSession_AddPreviewOutput(captureSession_, previewOutput_); - if (ret != CAMERA_OK) { - DRAWING_LOGD("ERROR: Failed to add new PreviewOutput! ret=%{public}d", ret); - return ret; - } - } else { - ret = OH_CaptureSession_RemovePhotoOutput(captureSession_, photoOutput_); - DRAWING_LOGD("RemovePhotoOutput ret=%{public}d (ignore if fails)", ret); - } - if (preconfigged_ && videoProfile_ == nullptr) { - DRAWING_LOGD("WARNING: In preconfig mode but videoProfile_ is nullptr!"); - } - - ret = CreateVideoOutput(videoId); - if (ret != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "CRITICAL: CreateVideoOutput failed. ret=%{public}d", ret); - DRAWING_LOGD("ERROR: CreateVideoOutput failed with ret=%{public}d", ret); - return ret; - } - - isSuccess_ = false; - CanAddVideoOutput(&isSuccess_); - if (!isSuccess_) { - if (!preconfigged_) { - DRAWING_LOGD("ERROR: Not in preconfig mode, cannot add video output!"); - return Camera_ErrorCode::CAMERA_OPERATION_NOT_ALLOWED; - } - DRAWING_LOGD("In preconfig mode, will try to add video output anyway..."); - } else { - DRAWING_LOGD("CanAddVideoOutput check passed"); - } - - ret = AddVideoOutput(); - if (ret != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "CRITICAL: AddVideoOutput failed. ret=%{public}d", ret); - DRAWING_LOGD("ERROR: AddVideoOutput failed with ret=%{public}d", ret); - return ret; - } - ret = CreatePhotoOutput(photoId); - if (ret == CAMERA_OK) { - isSuccess_ = false; - CanAddPhotoOutput(&isSuccess_); - if (isSuccess_) { - ret = AddPhotoOutput(); - if (ret != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "WARNING: AddPhotoOutput failed. ret=%{public}d (continue anyway)", ret); - } - } else { - DRAWING_LOGD("WARNING: Can not add photo output (continue anyway)"); - } - } else { - OH_LOG_ERROR(LOG_APP, "WARNING: CreatePhotoOutput failed. ret=%{public}d (continue anyway)", ret); - } - GetActiveVideoOutputProfile(); - if (isHdrVideo) { - // HDR Vivid 视频需要设置色彩空间为OH_COLORSPACE_BT2020_HLG_LIMIT - OH_NativeBuffer_ColorSpace colorSpace = OH_NativeBuffer_ColorSpace::OH_COLORSPACE_BT2020_HLG_LIMIT; - SetColorSpace(colorSpace); - } - ret = SessionCommitConfig(); - if (isHdrVideo) { - uint32_t mode = static_cast(Camera_VideoStabilizationMode::STABILIZATION_MODE_AUTO); - IsVideoStabilizationModeSupportedFn(mode); - } - if (ret != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "CRITICAL: SessionCommitConfig failed with ret: %{public}d", ret); - DRAWING_LOGD("ERROR: SessionCommitConfig failed! ret=%{public}d", ret); - return ret; - } - bool isMirrorSupported = false; - ret = OH_VideoOutput_IsMirrorSupported(videoOutput_, &isMirrorSupported); - OH_LOG_INFO(LOG_APP, "VideoOutput IsMirrorSupported: %{public}d", isMirrorSupported); - if (isMirrorSupported) { - OH_VideoOutput_EnableMirror(videoOutput_, isMirrorSupported); - } - - ret = SessionStart(); - if (ret != CAMERA_OK) { - OH_LOG_ERROR(LOG_APP, "CRITICAL: SessionStart failed with ret: %{public}d", ret); - DRAWING_LOGD("ERROR: SessionStart failed! ret=%{public}d", ret); - return ret; - } - VideoOutputRegisterCallback(); - return ret; + return CAMERA_OK; } Camera_ErrorCode NDKCamera::VideoOutputStart(void) @@ -1202,14 +783,14 @@ Camera_ErrorCode NDKCamera::VideoOutputStart(void) return CAMERA_INVALID_ARGUMENT; } Camera_ErrorCode ret = OH_VideoOutput_Start(videoOutput_); - DRAWING_LOGD("OH_VideoOutput_Start returned: ret=%{public}d", ret); + OH_LOG_INFO(LOG_APP, "OH_VideoOutput_Start returned: ret=%{public}d", ret); if (ret == CAMERA_OK) { OH_LOG_INFO(LOG_APP, "OH_VideoOutput_Start success."); - DRAWING_LOGD("Video output started successfully!"); + OH_LOG_INFO(LOG_APP, "Video output started successfully!"); } else { OH_LOG_ERROR(LOG_APP, "OH_VideoOutput_Start failed. ret=%{public}d ", ret); - DRAWING_LOGD("ERROR: OH_VideoOutput_Start failed! ret=%{public}d", ret); + OH_LOG_INFO(LOG_APP, "ERROR: OH_VideoOutput_Start failed! ret=%{public}d", ret); } return ret; } @@ -1217,47 +798,12 @@ Camera_ErrorCode NDKCamera::VideoOutputStart(void) Camera_ErrorCode NDKCamera::StartPhoto(char *mSurfaceId) { Camera_ErrorCode ret = CAMERA_OK; - if (takePictureTimes == 0) { - ret = SessionStop(); - if (ret == CAMERA_OK) { - 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_INFO(LOG_APP, "SessionBegin success."); - } else { - OH_LOG_ERROR(LOG_APP, "SessionBegin failed. %d ", ret); - } - OH_LOG_INFO(LOG_APP, "startPhoto begin."); - ret = CreatePhotoOutput(mSurfaceId); - OH_LOG_INFO(LOG_APP, "startPhoto CreatePhotoOutput ret = %{public}d.", ret); - // expect CAMERA_SERVICE_FATAL_ERROR - ret = OH_CaptureSession_SetSessionMode(captureSession_, Camera_SceneMode::NORMAL_PHOTO); - DRAWING_LOGD("OH_CaptureSession_SetSessionMode NORMAL_PHOTO return with ret code: %{public}d!", ret); - - isSuccess_ = false; - CanAddPhotoOutput(&isSuccess_); - if (!isSuccess_) { - DRAWING_LOGD("NDKCamera::StartPhoto can not add photo output!"); - return Camera_ErrorCode::CAMERA_OPERATION_NOT_ALLOWED; - } - ret = OH_CaptureSession_AddPhotoOutput(captureSession_, photoOutput_); - OH_LOG_INFO(LOG_APP, "startPhoto AddPhotoOutput ret = %{public}d.", ret); - GetActivePhotoOutputProfile(); - ret = SessionCommitConfig(); - - ret = SessionStart(); - OH_LOG_INFO(LOG_APP, "startPhoto SessionStart ret = %{public}d.", ret); - } ret = TakePicture(); 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++; return ret_; } @@ -1542,7 +1088,7 @@ void PreviewOutputOnFrameStart(Camera_PreviewOutput *previewOutput) { static int previewStartCount = 0; if (previewStartCount < NUM_FIVE) { - DRAWING_LOGD("PreviewOutputOnFrameStart - Preview is receiving frames (count=%{public}d)", previewStartCount); + OH_LOG_INFO(LOG_APP, "PreviewOutputOnFrameStart - Preview is receiving frames (count=%{public}d)", previewStartCount); previewStartCount++; } } @@ -1551,7 +1097,7 @@ void PreviewOutputOnFrameEnd(Camera_PreviewOutput *previewOutput, int32_t frameC { static int previewEndCount = 0; if (previewEndCount < NUM_FIVE) { - DRAWING_LOGD("PreviewOutputOnFrameEnd - frameCount = %{public}d", frameCount); + OH_LOG_INFO(LOG_APP, "PreviewOutputOnFrameEnd - frameCount = %{public}d", frameCount); previewEndCount++; } } @@ -1559,7 +1105,7 @@ void PreviewOutputOnFrameEnd(Camera_PreviewOutput *previewOutput, int32_t frameC void PreviewOutputOnError(Camera_PreviewOutput *previewOutput, Camera_ErrorCode errorCode) { OH_LOG_ERROR(LOG_APP, "PreviewOutputOnError - errorCode = %{public}d", errorCode); - DRAWING_LOGD("ERROR: PreviewOutputOnError - errorCode = %{public}d", errorCode); + OH_LOG_INFO(LOG_APP, "ERROR: PreviewOutputOnError - errorCode = %{public}d", errorCode); } PreviewOutput_Callbacks *NDKCamera::GetPreviewOutputListener(void) @@ -1626,19 +1172,19 @@ Camera_ErrorCode NDKCamera::PhotoOutputRegisterCallback(void) void VideoOutputOnFrameStart(Camera_VideoOutput *videoOutput) { OH_LOG_INFO(LOG_APP, "VideoOutputOnFrameStart - Video frame started"); - DRAWING_LOGD("VideoOutputOnFrameStart called - recording frames are being captured"); + OH_LOG_INFO(LOG_APP, "VideoOutputOnFrameStart called - recording frames are being captured"); } void VideoOutputOnFrameEnd(Camera_VideoOutput *videoOutput, int32_t frameCount) { OH_LOG_INFO(LOG_APP, "VideoOutputOnFrameEnd - frameCount = %{public}d", frameCount); - DRAWING_LOGD("VideoOutputOnFrameEnd - frameCount = %{public}d", frameCount); + OH_LOG_INFO(LOG_APP, "VideoOutputOnFrameEnd - frameCount = %{public}d", frameCount); } void VideoOutputOnError(Camera_VideoOutput *videoOutput, Camera_ErrorCode errorCode) { OH_LOG_ERROR(LOG_APP, "VideoOutputOnError - errorCode = %{public}d", errorCode); - DRAWING_LOGD("ERROR: VideoOutputOnError - errorCode = %{public}d", errorCode); + OH_LOG_INFO(LOG_APP, "ERROR: VideoOutputOnError - errorCode = %{public}d", errorCode); } VideoOutput_Callbacks *NDKCamera::GetVideoOutputListener(void) @@ -1653,7 +1199,7 @@ VideoOutput_Callbacks *NDKCamera::GetVideoOutputListener(void) Camera_ErrorCode NDKCamera::VideoOutputRegisterCallback(void) { - DRAWING_LOGD("VideoOutputRegisterCallback: videoOutput_=%{public}p", videoOutput_); + OH_LOG_INFO(LOG_APP, "VideoOutputRegisterCallback: videoOutput_=%{public}p", videoOutput_); if (videoOutput_ == nullptr) { OH_LOG_ERROR(LOG_APP, "ERROR: videoOutput_ is nullptr in RegisterCallback!"); @@ -1702,13 +1248,13 @@ Camera_ErrorCode NDKCamera::RegisterMetadataOutputCallback(void) // Session Callback void CaptureSessionOnFocusStateChange(Camera_CaptureSession *session, Camera_FocusState focusState) { - DRAWING_LOGD("CaptureSession_Callbacks CaptureSessionOnFocusStateChange"); + OH_LOG_INFO(LOG_APP, "CaptureSession_Callbacks CaptureSessionOnFocusStateChange"); OH_LOG_INFO(LOG_APP, "CaptureSessionOnFocusStateChange"); } void CaptureSessionOnError(Camera_CaptureSession *session, Camera_ErrorCode errorCode) { - DRAWING_LOGD("CaptureSession_Callbacks CaptureSessionOnError"); + OH_LOG_INFO(LOG_APP, "CaptureSession_Callbacks CaptureSessionOnError"); OH_LOG_INFO(LOG_APP, "CaptureSession errorCode = %{public}d", errorCode); } @@ -1734,14 +1280,14 @@ Camera_ErrorCode NDKCamera::GetSupportedSceneModes(void) { ret_ = OH_CameraManager_GetSupportedSceneModes(&cameras_[cameraDeviceIndex_], &sceneModes_, &sceneModeSize_); if (sceneModes_ == nullptr || &sceneModeSize_ == nullptr || ret_ != CAMERA_OK) { - DRAWING_LOGD("NDKCamera::GetSupportedSceneModes failed."); + OH_LOG_INFO(LOG_APP, "NDKCamera::GetSupportedSceneModes failed."); return CAMERA_INVALID_ARGUMENT; } - DRAWING_LOGD("NDKCamera::GetSupportedSceneModes sceneModeSize_: %{public}d", sceneModeSize_); + OH_LOG_INFO(LOG_APP, "NDKCamera::GetSupportedSceneModes sceneModeSize_: %{public}d", sceneModeSize_); for (uint32_t i = 0; i < sceneModeSize_; i++) { - DRAWING_LOGD("NDKCamera::GetSupportedSceneModes sceneMode_: %{public}d", sceneModes_[i]); + OH_LOG_INFO(LOG_APP, "NDKCamera::GetSupportedSceneModes sceneMode_: %{public}d", sceneModes_[i]); } - DRAWING_LOGD("NDKCamera::GetSupportedSceneModes return with ret code: %{public}d!", ret_); + OH_LOG_INFO(LOG_APP, "NDKCamera::GetSupportedSceneModes return with ret code: %{public}d!", ret_); return ret_; } Camera_ErrorCode NDKCamera::GetSupportedOutputCapabilityWithSceneMode(Camera_SceneMode sceneMode) @@ -1749,191 +1295,191 @@ Camera_ErrorCode NDKCamera::GetSupportedOutputCapabilityWithSceneMode(Camera_Sce ret_ = OH_CameraManager_GetSupportedCameraOutputCapabilityWithSceneMode(cameraManager_, &cameras_[cameraDeviceIndex_], sceneMode, &cameraOutputCapability_); if (cameraOutputCapability_ == nullptr || ret_ != CAMERA_OK) { - DRAWING_LOGD("NDKCamera::GetSupportedOutputCapabilityWithSceneMode failed."); + OH_LOG_INFO(LOG_APP, "NDKCamera::GetSupportedOutputCapabilityWithSceneMode failed."); return CAMERA_INVALID_ARGUMENT; } if (sceneMode == Camera_SceneMode::NORMAL_VIDEO) { - DRAWING_LOGD("===== ALL AVAILABLE VIDEO PROFILES ====="); + OH_LOG_INFO(LOG_APP, "===== ALL AVAILABLE VIDEO PROFILES ====="); for (uint32_t i = 0; i < cameraOutputCapability_->videoProfilesSize && i < NUM_FIFTY; i++) { if (cameraOutputCapability_->videoProfiles[i] != nullptr) { Camera_VideoProfile *vp = cameraOutputCapability_->videoProfiles[i]; float ratio = (float)vp->size.width / vp->size.height; - DRAWING_LOGD("Video profile[%{public}d]: %{public}dx%{public}d (ratio=%.2f), format=%{public}d, " + OH_LOG_INFO(LOG_APP, "Video profile[%{public}d]: %{public}dx%{public}d (ratio=%.2f), format=%{public}d, " "fps=[%{public}d,%{public}d]", i, vp->size.width, vp->size.height, ratio, vp->format, vp->range.min, vp->range.max); } } - DRAWING_LOGD("===== END OF VIDEO PROFILES ====="); + OH_LOG_INFO(LOG_APP, "===== END OF VIDEO PROFILES ====="); if (cameraOutputCapability_->videoProfilesSize > 0) { - DRAWING_LOGD("NDKCamera::GetSupportedOutputCapabilityWithSceneMode sceneMode: %{public}d " + OH_LOG_INFO(LOG_APP, "NDKCamera::GetSupportedOutputCapabilityWithSceneMode sceneMode: %{public}d " "videoProfiles[0] format: %{public}d!", sceneMode, cameraOutputCapability_->videoProfiles[0]->format); - DRAWING_LOGD("NDKCamera::GetSupportedOutputCapabilityWithSceneMode sceneMode: %{public}d " + OH_LOG_INFO(LOG_APP, "NDKCamera::GetSupportedOutputCapabilityWithSceneMode sceneMode: %{public}d " "videoProfiles[0] width: %{public}d!", sceneMode, cameraOutputCapability_->videoProfiles[0]->size.width); - DRAWING_LOGD("NDKCamera::GetSupportedOutputCapabilityWithSceneMode sceneMode: %{public}d " + OH_LOG_INFO(LOG_APP, "NDKCamera::GetSupportedOutputCapabilityWithSceneMode sceneMode: %{public}d " "videoProfiles[0] height: %{public}d!", sceneMode, cameraOutputCapability_->videoProfiles[0]->size.height); - DRAWING_LOGD("NDKCamera::GetSupportedOutputCapabilityWithSceneMode sceneMode: %{public}d " + OH_LOG_INFO(LOG_APP, "NDKCamera::GetSupportedOutputCapabilityWithSceneMode sceneMode: %{public}d " "videoProfiles[0] range.min: %{public}d!", sceneMode, cameraOutputCapability_->videoProfiles[0]->range.min); - DRAWING_LOGD("NDKCamera::GetSupportedOutputCapabilityWithSceneMode sceneMode: %{public}d " + OH_LOG_INFO(LOG_APP, "NDKCamera::GetSupportedOutputCapabilityWithSceneMode sceneMode: %{public}d " "videoProfiles[0] range.max: %{public}d!", sceneMode, cameraOutputCapability_->videoProfiles[0]->range.max); } - DRAWING_LOGD("NDKCamera::GetSupportedOutputCapabilityWithSceneMode sceneMode: %{public}d " + OH_LOG_INFO(LOG_APP, "NDKCamera::GetSupportedOutputCapabilityWithSceneMode sceneMode: %{public}d " "metadataProfilesSize: %{public}d!", sceneMode, cameraOutputCapability_->metadataProfilesSize); } - DRAWING_LOGD("NDKCamera::GetSupportedOutputCapabilityWithSceneMode sceneMode: %{public}d " + OH_LOG_INFO(LOG_APP, "NDKCamera::GetSupportedOutputCapabilityWithSceneMode sceneMode: %{public}d " "return with ret code: %{public}d!", sceneMode, ret_); return ret_; } Camera_ErrorCode NDKCamera::CanAddInput(bool *isSuccess) { - DRAWING_LOGD("NDKCamera::CanAddInput start!"); + OH_LOG_INFO(LOG_APP, "NDKCamera::CanAddInput start!"); ret_ = OH_CaptureSession_CanAddInput(captureSession_, cameraInput_, isSuccess); if (ret_ != CAMERA_OK) { - DRAWING_LOGD("NDKCamera::CanAddInput failed."); + OH_LOG_INFO(LOG_APP, "NDKCamera::CanAddInput failed."); return CAMERA_INVALID_ARGUMENT; } - DRAWING_LOGD("NDKCamera::CanAddInput isSuccess: %{public}d!", *isSuccess); - DRAWING_LOGD("NDKCamera::CanAddInput return with ret code: %{public}d!", ret_); + OH_LOG_INFO(LOG_APP, "NDKCamera::CanAddInput isSuccess: %{public}d!", *isSuccess); + OH_LOG_INFO(LOG_APP, "NDKCamera::CanAddInput return with ret code: %{public}d!", ret_); return ret_; } Camera_ErrorCode NDKCamera::CanAddPreviewOutput(bool *isSuccess) { - DRAWING_LOGD("NDKCamera::CanAddPreviewOutput start!"); + OH_LOG_INFO(LOG_APP, "NDKCamera::CanAddPreviewOutput start!"); ret_ = OH_CaptureSession_CanAddPreviewOutput(captureSession_, previewOutput_, isSuccess); if (ret_ != CAMERA_OK) { - DRAWING_LOGD("NDKCamera::CanAddPreviewOutput failed."); + OH_LOG_INFO(LOG_APP, "NDKCamera::CanAddPreviewOutput failed."); return CAMERA_INVALID_ARGUMENT; } - DRAWING_LOGD("NDKCamera::CanAddPreviewOutput isSuccess: %{public}d!", *isSuccess); - DRAWING_LOGD("NDKCamera::CanAddPreviewOutput return with ret code: %{public}d!", ret_); + OH_LOG_INFO(LOG_APP, "NDKCamera::CanAddPreviewOutput isSuccess: %{public}d!", *isSuccess); + OH_LOG_INFO(LOG_APP, "NDKCamera::CanAddPreviewOutput return with ret code: %{public}d!", ret_); return ret_; } Camera_ErrorCode NDKCamera::CanAddPhotoOutput(bool *isSuccess) { - DRAWING_LOGD("NDKCamera::CanAddPhotoOutput start!"); + OH_LOG_INFO(LOG_APP, "NDKCamera::CanAddPhotoOutput start!"); ret_ = OH_CaptureSession_CanAddPhotoOutput(captureSession_, photoOutput_, isSuccess); if (ret_ != CAMERA_OK) { - DRAWING_LOGD("NDKCamera::CanAddPhotoOutput failed."); + OH_LOG_INFO(LOG_APP, "NDKCamera::CanAddPhotoOutput failed."); return CAMERA_INVALID_ARGUMENT; } - DRAWING_LOGD("NDKCamera::CanAddPhotoOutput isSuccess: %{public}d!", *isSuccess); - DRAWING_LOGD("NDKCamera::CanAddPhotoOutput return with ret code: %{public}d!", ret_); + OH_LOG_INFO(LOG_APP, "NDKCamera::CanAddPhotoOutput isSuccess: %{public}d!", *isSuccess); + OH_LOG_INFO(LOG_APP, "NDKCamera::CanAddPhotoOutput return with ret code: %{public}d!", ret_); return ret_; } Camera_ErrorCode NDKCamera::CanAddVideoOutput(bool *isSuccess) { - DRAWING_LOGD("NDKCamera::CanAddVideoOutput start!"); + OH_LOG_INFO(LOG_APP, "NDKCamera::CanAddVideoOutput start!"); ret_ = OH_CaptureSession_CanAddVideoOutput(captureSession_, videoOutput_, isSuccess); if (ret_ != CAMERA_OK) { - DRAWING_LOGD("NDKCamera::CanAddVideoOutput failed."); + OH_LOG_INFO(LOG_APP, "NDKCamera::CanAddVideoOutput failed."); return CAMERA_INVALID_ARGUMENT; } - DRAWING_LOGD("NDKCamera::CanAddVideoOutput isSuccess: %{public}d!", *isSuccess); - DRAWING_LOGD("NDKCamera::CanAddVideoOutput return with ret code: %{public}d!", ret_); + OH_LOG_INFO(LOG_APP, "NDKCamera::CanAddVideoOutput isSuccess: %{public}d!", *isSuccess); + OH_LOG_INFO(LOG_APP, "NDKCamera::CanAddVideoOutput return with ret code: %{public}d!", ret_); return ret_; } Camera_ErrorCode NDKCamera::CanPreconfig(bool *isSuccess) { - DRAWING_LOGD("NDKCamera::CanPreconfig start!"); + OH_LOG_INFO(LOG_APP, "NDKCamera::CanPreconfig start!"); ret_ = OH_CaptureSession_CanPreconfig(captureSession_, preconfigType_, isSuccess); if (ret_ != CAMERA_OK) { - DRAWING_LOGD("NDKCamera::CanPreconfig failed."); + OH_LOG_INFO(LOG_APP, "NDKCamera::CanPreconfig failed."); return CAMERA_INVALID_ARGUMENT; } - DRAWING_LOGD("NDKCamera::CanPreconfig isSuccess: %{public}d, preconfigTyep: %{public}d!", *isSuccess, + OH_LOG_INFO(LOG_APP, "NDKCamera::CanPreconfig isSuccess: %{public}d, preconfigTyep: %{public}d!", *isSuccess, preconfigType_); - DRAWING_LOGD("NDKCamera::CanPreconfig return with ret code: %{public}d!", ret_); + OH_LOG_INFO(LOG_APP, "NDKCamera::CanPreconfig return with ret code: %{public}d!", ret_); return ret_; } Camera_ErrorCode NDKCamera::Preconfig(void) { - DRAWING_LOGD("NDKCamera::Preconfig start!"); + OH_LOG_INFO(LOG_APP, "NDKCamera::Preconfig start!"); ret_ = OH_CaptureSession_Preconfig(captureSession_, preconfigType_); if (ret_ != CAMERA_OK) { - DRAWING_LOGD("NDKCamera::Preconfig failed."); + OH_LOG_INFO(LOG_APP, "NDKCamera::Preconfig failed."); return CAMERA_INVALID_ARGUMENT; } - DRAWING_LOGD("NDKCamera::Preconfig return with ret code: %{public}d!", ret_); + OH_LOG_INFO(LOG_APP, "NDKCamera::Preconfig return with ret code: %{public}d!", ret_); return ret_; } Camera_ErrorCode NDKCamera::CanPreconfigWithRatio(bool *isSuccess) { - DRAWING_LOGD("NDKCamera::CanPreconfigWithRatio start!"); + OH_LOG_INFO(LOG_APP, "NDKCamera::CanPreconfigWithRatio start!"); ret_ = OH_CaptureSession_CanPreconfigWithRatio(captureSession_, preconfigType_, preconfigRatio_, isSuccess); if (ret_ != CAMERA_OK) { - DRAWING_LOGD("NDKCamera::CanPreconfigWithRatio failed."); + OH_LOG_INFO(LOG_APP, "NDKCamera::CanPreconfigWithRatio failed."); return CAMERA_INVALID_ARGUMENT; } - DRAWING_LOGD("NDKCamera::CanPreconfigWithRatio isSuccess: %{public}d, type: %{public}d, ratio: %{public}d!", + OH_LOG_INFO(LOG_APP, "NDKCamera::CanPreconfigWithRatio isSuccess: %{public}d, type: %{public}d, ratio: %{public}d!", *isSuccess, preconfigType_, preconfigRatio_); - DRAWING_LOGD("NDKCamera::CanPreconfigWithRatio return with ret code: %{public}d!", ret_); + OH_LOG_INFO(LOG_APP, "NDKCamera::CanPreconfigWithRatio return with ret code: %{public}d!", ret_); return ret_; } Camera_ErrorCode NDKCamera::PreconfigWithRatio(void) { - DRAWING_LOGD("NDKCamera::PreconfigWithRatio start!"); - DRAWING_LOGD("Calling OH_CaptureSession_PreconfigWithRatio with type=%{public}d, ratio=%{public}d", preconfigType_, + OH_LOG_INFO(LOG_APP, "NDKCamera::PreconfigWithRatio start!"); + OH_LOG_INFO(LOG_APP, "Calling OH_CaptureSession_PreconfigWithRatio with type=%{public}d, ratio=%{public}d", preconfigType_, preconfigRatio_); ret_ = OH_CaptureSession_PreconfigWithRatio(captureSession_, preconfigType_, preconfigRatio_); if (ret_ != CAMERA_OK) { - DRAWING_LOGD("NDKCamera::PreconfigWithRatio failed."); + OH_LOG_INFO(LOG_APP, "NDKCamera::PreconfigWithRatio failed."); return CAMERA_INVALID_ARGUMENT; } - DRAWING_LOGD("PreconfigWithRatio SUCCESS! ret=%{public}d", ret_); + OH_LOG_INFO(LOG_APP, "PreconfigWithRatio SUCCESS! ret=%{public}d", ret_); return ret_; } Camera_ErrorCode NDKCamera::GetActivePreviewOutputProfile(void) { - DRAWING_LOGD("NDKCamera::GetActivePreviewOutputProfile start!"); + OH_LOG_INFO(LOG_APP, "NDKCamera::GetActivePreviewOutputProfile start!"); ret_ = OH_PreviewOutput_GetActiveProfile(previewOutput_, &activePreviewProfile_); if (activePreviewProfile_ == nullptr || ret_ != CAMERA_OK) { - DRAWING_LOGD("NDKCamera::GetActivePreviewOutputProfile failed."); + OH_LOG_INFO(LOG_APP, "NDKCamera::GetActivePreviewOutputProfile failed."); return CAMERA_INVALID_ARGUMENT; } - DRAWING_LOGD("Preview Active Profile - format: %{public}d", activePreviewProfile_->format); - DRAWING_LOGD("Preview Active Profile - width: %{public}d", activePreviewProfile_->size.width); - DRAWING_LOGD("Preview Active Profile - height: %{public}d", activePreviewProfile_->size.height); - DRAWING_LOGD("NDKCamera::GetActivePreviewOutputProfile return with ret code: %{public}d!", ret_); + OH_LOG_INFO(LOG_APP, "Preview Active Profile - format: %{public}d", activePreviewProfile_->format); + OH_LOG_INFO(LOG_APP, "Preview Active Profile - width: %{public}d", activePreviewProfile_->size.width); + OH_LOG_INFO(LOG_APP, "Preview Active Profile - height: %{public}d", activePreviewProfile_->size.height); + OH_LOG_INFO(LOG_APP, "NDKCamera::GetActivePreviewOutputProfile return with ret code: %{public}d!", ret_); return ret_; } Camera_ErrorCode NDKCamera::GetActivePhotoOutputProfile(void) { - DRAWING_LOGD("NDKCamera::GetActivePhotoOutputProfile start!"); + OH_LOG_INFO(LOG_APP, "NDKCamera::GetActivePhotoOutputProfile start!"); ret_ = OH_PhotoOutput_GetActiveProfile(photoOutput_, &activePhotoProfile_); if (activePhotoProfile_ == nullptr || ret_ != CAMERA_OK) { - DRAWING_LOGD("NDKCamera::GetActivePhotoOutputProfile failed."); + OH_LOG_INFO(LOG_APP, "NDKCamera::GetActivePhotoOutputProfile failed."); return CAMERA_INVALID_ARGUMENT; } - DRAWING_LOGD("Photo Active Profile - format: %{public}d", activePhotoProfile_->format); - DRAWING_LOGD("Photo Active Profile - width: %{public}d", activePhotoProfile_->size.width); - DRAWING_LOGD("Photo Active Profile - height: %{public}d", activePhotoProfile_->size.height); - DRAWING_LOGD("NDKCamera::GetActivePhotoOutputProfile return with ret code: %{public}d!", ret_); + OH_LOG_INFO(LOG_APP, "Photo Active Profile - format: %{public}d", activePhotoProfile_->format); + OH_LOG_INFO(LOG_APP, "Photo Active Profile - width: %{public}d", activePhotoProfile_->size.width); + OH_LOG_INFO(LOG_APP, "Photo Active Profile - height: %{public}d", activePhotoProfile_->size.height); + OH_LOG_INFO(LOG_APP, "NDKCamera::GetActivePhotoOutputProfile return with ret code: %{public}d!", ret_); return ret_; } void onPhotoAvailable(Camera_PhotoOutput *photoOutput, OH_PhotoNative *photo) { - DRAWING_LOGD("onPhotoAvailable start!"); + OH_LOG_INFO(LOG_APP, "onPhotoAvailable start!"); NDKCamera::PhotoNativeGetMainImage(photo); NDKCamera::PhotoNativeRelease(photo); - DRAWING_LOGD("onPhotoAvailable finish!"); + OH_LOG_INFO(LOG_APP, "onPhotoAvailable finish!"); } Camera_ErrorCode NDKCamera::PhotoOutputRegisterPhotoAvailableCallback(void) { - DRAWING_LOGD("NDKCamera::PhotoOutputRegisterPhotoAvailableCallback start!"); + OH_LOG_INFO(LOG_APP, "NDKCamera::PhotoOutputRegisterPhotoAvailableCallback start!"); ret_ = OH_PhotoOutput_RegisterPhotoAvailableCallback(photoOutput_, onPhotoAvailable); if (ret_ != CAMERA_OK) { - DRAWING_LOGD("NDKCamera::PhotoOutputRegisterPhotoAvailableCallback failed."); + OH_LOG_INFO(LOG_APP, "NDKCamera::PhotoOutputRegisterPhotoAvailableCallback failed."); } - DRAWING_LOGD("NDKCamera::PhotoOutputRegisterPhotoAvailableCallback return with ret code: %{public}d!", ret_); + OH_LOG_INFO(LOG_APP, "NDKCamera::PhotoOutputRegisterPhotoAvailableCallback return with ret code: %{public}d!", ret_); return ret_; } void onPhotoAssetAvailable(Camera_PhotoOutput *photoOutput, OH_MediaAsset *mediaAsset) @@ -1942,7 +1488,7 @@ void onPhotoAssetAvailable(Camera_PhotoOutput *photoOutput, OH_MediaAsset *media DRAWING_LOGI("onPhotoAssetAvailable mediaAsset is nullptr !"); return; } - DRAWING_LOGD("onPhotoAssetAvailable start!"); + OH_LOG_INFO(LOG_APP, "onPhotoAssetAvailable start!"); NDKCamera::MediaAssetRelease(); g_mediaAsset = mediaAsset; NDKCamera::MediaAssetGetUri(mediaAsset); @@ -1954,278 +1500,278 @@ void onPhotoAssetAvailable(Camera_PhotoOutput *photoOutput, OH_MediaAsset *media NDKCamera::MediaAssetGetOrientation(mediaAsset); NDKCamera::MediaAssetManagerCreate(); NDKCamera::MediaAssetChangeRequest(mediaAsset); - DRAWING_LOGD("onPhotoAssetAvailable finish!"); + OH_LOG_INFO(LOG_APP, "onPhotoAssetAvailable finish!"); return; } Camera_ErrorCode NDKCamera::PhotoOutputRegisterPhotoAssetAvailableCallback(void) { - DRAWING_LOGD("NDKCamera::PhotoOutputRegisterPhotoAssetAvailableCallback start!"); + OH_LOG_INFO(LOG_APP, "NDKCamera::PhotoOutputRegisterPhotoAssetAvailableCallback start!"); MediaAssetManagerCreate(); ret_ = OH_PhotoOutput_RegisterPhotoAssetAvailableCallback(photoOutput_, onPhotoAssetAvailable); if (ret_ != CAMERA_OK) { - DRAWING_LOGD("NDKCamera::PhotoOutputRegisterPhotoAssetAvailableCallback failed."); + OH_LOG_INFO(LOG_APP, "NDKCamera::PhotoOutputRegisterPhotoAssetAvailableCallback failed."); } - DRAWING_LOGD("NDKCamera::PhotoOutputRegisterPhotoAssetAvailableCallback return with ret code: %{public}d!", ret_); + OH_LOG_INFO(LOG_APP, "NDKCamera::PhotoOutputRegisterPhotoAssetAvailableCallback return with ret code: %{public}d!", ret_); return ret_; } Camera_ErrorCode NDKCamera::GetActiveVideoOutputProfile(void) { - DRAWING_LOGD("NDKCamera::GetActiveVideoOutputProfile start!"); - DRAWING_LOGD("===== GetActiveVideoOutputProfile ====="); - DRAWING_LOGD("videoOutput_=%{public}p", videoOutput_); + OH_LOG_INFO(LOG_APP, "NDKCamera::GetActiveVideoOutputProfile start!"); + OH_LOG_INFO(LOG_APP, "===== GetActiveVideoOutputProfile ====="); + OH_LOG_INFO(LOG_APP, "videoOutput_=%{public}p", videoOutput_); if (videoOutput_ == nullptr) { - DRAWING_LOGD("ERROR: videoOutput_ is nullptr!"); + OH_LOG_INFO(LOG_APP, "ERROR: videoOutput_ is nullptr!"); return CAMERA_INVALID_ARGUMENT; } ret_ = OH_VideoOutput_GetActiveProfile(videoOutput_, &activeVideoProfile_); if (activeVideoProfile_ == nullptr || ret_ != CAMERA_OK) { - DRAWING_LOGD("NDKCamera::GetActiveVideoOutputProfile failed."); - DRAWING_LOGD("ERROR: GetActiveProfile failed! ret=%{public}d", ret_); + OH_LOG_INFO(LOG_APP, "NDKCamera::GetActiveVideoOutputProfile failed."); + OH_LOG_INFO(LOG_APP, "ERROR: GetActiveProfile failed! ret=%{public}d", ret_); return CAMERA_INVALID_ARGUMENT; } - DRAWING_LOGD("NDKCamera::GetActiveVideoOutputProfile activeVideoProfile_ format: %{public}d!", + OH_LOG_INFO(LOG_APP, "NDKCamera::GetActiveVideoOutputProfile activeVideoProfile_ format: %{public}d!", activeVideoProfile_->format); - DRAWING_LOGD("NDKCamera::GetActiveVideoOutputProfile activeVideoProfile_ width: %{public}d!", + OH_LOG_INFO(LOG_APP, "NDKCamera::GetActiveVideoOutputProfile activeVideoProfile_ width: %{public}d!", activeVideoProfile_->size.width); - DRAWING_LOGD("NDKCamera::GetActiveVideoOutputProfile activeVideoProfile_ height: %{public}d!", + OH_LOG_INFO(LOG_APP, "NDKCamera::GetActiveVideoOutputProfile activeVideoProfile_ height: %{public}d!", activeVideoProfile_->size.height); - DRAWING_LOGD("NDKCamera::GetActiveVideoOutputProfile activeVideoProfile_ range.min: %{public}d!", + OH_LOG_INFO(LOG_APP, "NDKCamera::GetActiveVideoOutputProfile activeVideoProfile_ range.min: %{public}d!", activeVideoProfile_->range.min); - DRAWING_LOGD("NDKCamera::GetActiveVideoOutputProfile activeVideoProfile_ range.max: %{public}d!", + OH_LOG_INFO(LOG_APP, "NDKCamera::GetActiveVideoOutputProfile activeVideoProfile_ range.max: %{public}d!", activeVideoProfile_->range.max); - DRAWING_LOGD("Active Video Profile: %{public}dx%{public}d, format=%{public}d, fps=[%{public}d,%{public}d]", + OH_LOG_INFO(LOG_APP, "Active Video Profile: %{public}dx%{public}d, format=%{public}d, fps=[%{public}d,%{public}d]", activeVideoProfile_->size.width, activeVideoProfile_->size.height, activeVideoProfile_->format, activeVideoProfile_->range.min, activeVideoProfile_->range.max); - DRAWING_LOGD("NDKCamera::GetActiveVideoOutputProfile return with ret code: %{public}d!", ret_); + OH_LOG_INFO(LOG_APP, "NDKCamera::GetActiveVideoOutputProfile return with ret code: %{public}d!", ret_); return ret_; } Camera_ErrorCode NDKCamera::PhotoNativeGetMainImage(OH_PhotoNative *photoNative) { - DRAWING_LOGD("NDKCamera::PhotoNativeGetMainImage start!"); + OH_LOG_INFO(LOG_APP, "NDKCamera::PhotoNativeGetMainImage start!"); Camera_ErrorCode result = CAMERA_OK; OH_ImageNative *imageNative = nullptr; result = OH_PhotoNative_GetMainImage(photoNative, &imageNative); if (imageNative == nullptr || result != CAMERA_OK) { - DRAWING_LOGD("NDKCamera::PhotoNativeGetMainImage failed."); + OH_LOG_INFO(LOG_APP, "NDKCamera::PhotoNativeGetMainImage failed."); } - DRAWING_LOGD("NDKCamera::PhotoNativeGetMainImage return with ret code: %{public}d!", result); + OH_LOG_INFO(LOG_APP, "NDKCamera::PhotoNativeGetMainImage return with ret code: %{public}d!", result); return result; } Camera_ErrorCode NDKCamera::PhotoNativeRelease(OH_PhotoNative *photoNative) { - DRAWING_LOGD("NDKCamera::PhotoNativeRelease start!"); + OH_LOG_INFO(LOG_APP, "NDKCamera::PhotoNativeRelease start!"); Camera_ErrorCode result = CAMERA_OK; result = OH_PhotoNative_Release(photoNative); if (result != CAMERA_OK) { - DRAWING_LOGD("NDKCamera::PhotoNativeRelease failed."); + OH_LOG_INFO(LOG_APP, "NDKCamera::PhotoNativeRelease failed."); } - DRAWING_LOGD("NDKCamera::PhotoNativeRelease return with ret code: %{public}d!", result); + OH_LOG_INFO(LOG_APP, "NDKCamera::PhotoNativeRelease return with ret code: %{public}d!", result); return result; } MediaLibrary_ErrorCode NDKCamera::MediaAssetGetUri(OH_MediaAsset *mediaAsset) { - DRAWING_LOGD("NDKCamera::MediaAssetGetUri start!"); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetGetUri start!"); const char *uri = nullptr; result = OH_MediaAsset_GetUri(mediaAsset, &g_uri); if (g_uri == nullptr || result != MEDIA_LIBRARY_OK) { - DRAWING_LOGD("NDKCamera::MediaAssetGetUri failed."); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetGetUri failed."); } - DRAWING_LOGD("NDKCamera::MediaAssetGetUri uri: %{public}s", g_uri); - DRAWING_LOGD("NDKCamera::MediaAssetGetUri return with ret code: %{public}d!", result); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetGetUri uri: %{public}s", g_uri); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetGetUri return with ret code: %{public}d!", result); return result; } MediaLibrary_ErrorCode NDKCamera::MediaAssetGetDisplayName(OH_MediaAsset *mediaAsset) { - DRAWING_LOGD("NDKCamera::MediaAssetGetDisplayName start!"); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetGetDisplayName start!"); const char *displayName = nullptr; result = OH_MediaAsset_GetDisplayName(mediaAsset, &displayName); if (displayName == nullptr || result != MEDIA_LIBRARY_OK) { - DRAWING_LOGD("NDKCamera::MediaAssetGetDisplayName failed."); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetGetDisplayName failed."); } - DRAWING_LOGD("NDKCamera::MediaAssetGetDisplayName displayName: %{public}s", displayName); - DRAWING_LOGD("NDKCamera::MediaAssetGetDisplayName return with ret code: %{public}d!", result); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetGetDisplayName displayName: %{public}s", displayName); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetGetDisplayName return with ret code: %{public}d!", result); return result; } MediaLibrary_ErrorCode NDKCamera::MediaAssetGetSize(OH_MediaAsset *mediaAsset) { - DRAWING_LOGD("NDKCamera::MediaAssetGetSize start!"); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetGetSize start!"); uint32_t mediaAssetSize; result = OH_MediaAsset_GetSize(mediaAsset, &mediaAssetSize); if (result != MEDIA_LIBRARY_OK) { - DRAWING_LOGD("NDKCamera::MediaAssetGetSize failed."); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetGetSize failed."); } - DRAWING_LOGD("NDKCamera::MediaAssetGetSize mediaAssetSize: %{public}d", mediaAssetSize); - DRAWING_LOGD("NDKCamera::MediaAssetGetSize return with ret code: %{public}d!", result); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetGetSize mediaAssetSize: %{public}d", mediaAssetSize); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetGetSize return with ret code: %{public}d!", result); return result; } MediaLibrary_ErrorCode NDKCamera::MediaAssetGetDateModifiedMs(OH_MediaAsset *mediaAsset) { - DRAWING_LOGD("NDKCamera::MediaAssetGetDateModifiedMs start!"); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetGetDateModifiedMs start!"); uint32_t dateModifiedMs; result = OH_MediaAsset_GetDateModifiedMs(mediaAsset, &dateModifiedMs); if (result != MEDIA_LIBRARY_OK) { - DRAWING_LOGD("NDKCamera::MediaAssetGetDateModifiedMs failed."); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetGetDateModifiedMs failed."); } - DRAWING_LOGD("NDKCamera::MediaAssetGetDateModifiedMs dateModifiedMs: %{public}lu", dateModifiedMs); - DRAWING_LOGD("NDKCamera::MediaAssetGetDateModifiedMs return with ret code: %{public}d!", result); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetGetDateModifiedMs dateModifiedMs: %{public}lu", dateModifiedMs); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetGetDateModifiedMs return with ret code: %{public}d!", result); return result; } MediaLibrary_ErrorCode NDKCamera::MediaAssetGetWidth(OH_MediaAsset *mediaAsset) { - DRAWING_LOGD("NDKCamera::MediaAssetGetWidth start!"); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetGetWidth start!"); uint32_t width; result = OH_MediaAsset_GetWidth(mediaAsset, &width); if (result != MEDIA_LIBRARY_OK) { - DRAWING_LOGD("NDKCamera::MediaAssetGetWidth failed."); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetGetWidth failed."); } - DRAWING_LOGD("NDKCamera::MediaAssetGetWidth width: %{public}d", width); - DRAWING_LOGD("NDKCamera::MediaAssetGetWidth return with ret code: %{public}d!", result); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetGetWidth width: %{public}d", width); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetGetWidth return with ret code: %{public}d!", result); return result; } MediaLibrary_ErrorCode NDKCamera::MediaAssetGetHeight(OH_MediaAsset *mediaAsset) { - DRAWING_LOGD("NDKCamera::MediaAssetGetHeight start!"); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetGetHeight start!"); uint32_t height; result = OH_MediaAsset_GetHeight(mediaAsset, &height); if (result != MEDIA_LIBRARY_OK) { - DRAWING_LOGD("NDKCamera::MediaAssetGetHeight failed."); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetGetHeight failed."); } - DRAWING_LOGD("NDKCamera::MediaAssetGetHeight height: %{public}d", height); - DRAWING_LOGD("NDKCamera::MediaAssetGetHeight return with ret code: %{public}d!", result); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetGetHeight height: %{public}d", height); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetGetHeight return with ret code: %{public}d!", result); return result; } MediaLibrary_ErrorCode NDKCamera::MediaAssetGetOrientation(OH_MediaAsset *mediaAsset) { - DRAWING_LOGD("NDKCamera::MediaAssetGetOrientation start!"); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetGetOrientation start!"); uint32_t orientation; result = OH_MediaAsset_GetOrientation(mediaAsset, &orientation); if (result != MEDIA_LIBRARY_OK) { - DRAWING_LOGD("NDKCamera::MediaAssetGetOrientation failed."); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetGetOrientation failed."); } - DRAWING_LOGD("NDKCamera::MediaAssetGetOrientation orientation: %{public}d", orientation); - DRAWING_LOGD("NDKCamera::MediaAssetGetOrientation return with ret code: %{public}d!", result); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetGetOrientation orientation: %{public}d", orientation); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetGetOrientation return with ret code: %{public}d!", result); return result; } MediaLibrary_ErrorCode NDKCamera::MediaAssetRelease() { - DRAWING_LOGD("NDKCamera::MediaAssetRelease start!"); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetRelease start!"); result = OH_MediaAsset_Release(g_mediaAsset); if (result != MEDIA_LIBRARY_OK) { - DRAWING_LOGD("NDKCamera::MediaAssetRelease failed."); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetRelease failed."); } g_mediaAsset = nullptr; - DRAWING_LOGD("NDKCamera::MediaAssetRelease return with ret code: %{public}d!", result); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetRelease return with ret code: %{public}d!", result); return result; } MediaLibrary_ErrorCode NDKCamera::MediaAssetChangeRequest(OH_MediaAsset *mediaAsset) { - DRAWING_LOGD("NDKCamera::MediaAssetChangeRequest start!"); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetChangeRequest start!"); MediaAssetChangeRequestCreate(mediaAsset); MediaAssetManagerRequestImage(mediaAsset); - DRAWING_LOGD("NDKCamera::MediaAssetChangeRequest finish!"); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetChangeRequest finish!"); return MEDIA_LIBRARY_OK; } MediaLibrary_ErrorCode NDKCamera::MediaAssetChangeRequestCreate(OH_MediaAsset *mediaAsset) { - DRAWING_LOGD("NDKCamera::MediaAssetChangeRequestCreate start!"); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetChangeRequestCreate start!"); g_changeRequest = OH_MediaAssetChangeRequest_Create(mediaAsset); if (g_changeRequest == nullptr) { - DRAWING_LOGD("NDKCamera::MediaAssetChangeRequestCreate failed."); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetChangeRequestCreate failed."); } return MEDIA_LIBRARY_OK; } MediaLibrary_ErrorCode NDKCamera::ChangeRequestAddResourceWithBuffer(OH_ImageSourceNative *imageSourceNative) { - DRAWING_LOGD("[RM003 log] NDKCamera::ChangeRequestAddResourceWithBuffer start!"); + OH_LOG_INFO(LOG_APP, "[RM003 log] NDKCamera::ChangeRequestAddResourceWithBuffer start!"); size_t bufferSize = BUFFER_SIZE; char buffer[BUFFER_SIZE]; int fd = open("/data/storage/el2/base/haps/test.jpg", O_RDONLY); int fr = read(fd, buffer, bufferSize); if (fr == -1) { - DRAWING_LOGD("[RM003 log] NDKCamera::ChangeRequestAddResourceWithBuffer read failed."); + OH_LOG_INFO(LOG_APP, "[RM003 log] NDKCamera::ChangeRequestAddResourceWithBuffer read failed."); return MEDIA_LIBRARY_OK; } if (fr == BUFFER_SIZE) { - DRAWING_LOGD("[RM003 log] NDKCamera::ChangeRequestAddResourceWithBuffer read not complete."); + OH_LOG_INFO(LOG_APP, "[RM003 log] NDKCamera::ChangeRequestAddResourceWithBuffer read not complete."); return MEDIA_LIBRARY_OK; } result = OH_MediaAssetChangeRequest_AddResourceWithBuffer(g_changeRequest, MediaLibrary_ResourceType::MEDIA_LIBRARY_IMAGE_RESOURCE, (uint8_t *)buffer, (uint32_t)bufferSize); if (result != MEDIA_LIBRARY_OK) { - DRAWING_LOGD("[RM003 log] NDKCamera::ChangeRequestAddResourceWithBuffer failed."); - DRAWING_LOGD("[RM003 log] NDKCamera::ChangeRequestAddResourceWithBuffer failed %{public}d.", result); + OH_LOG_INFO(LOG_APP, "[RM003 log] NDKCamera::ChangeRequestAddResourceWithBuffer failed."); + OH_LOG_INFO(LOG_APP, "[RM003 log] NDKCamera::ChangeRequestAddResourceWithBuffer failed %{public}d.", result); return MEDIA_LIBRARY_OK; } result = OH_MediaAccessHelper_ApplyChanges(g_changeRequest); if (result != MEDIA_LIBRARY_OK) { - DRAWING_LOGD( + OH_LOG_INFO(LOG_APP, "[RM003 log] NDKCamera::ChangeRequestAddResourceWithBuffer OH_MediaAccessHelper_ApplyChanges failed."); return MEDIA_LIBRARY_OK; } - DRAWING_LOGD("[RM003 log] NDKCamera::ChangeRequestAddResourceWithBuffer OH_MediaAccessHelper_ApplyChanges return " + OH_LOG_INFO(LOG_APP, "[RM003 log] NDKCamera::ChangeRequestAddResourceWithBuffer OH_MediaAccessHelper_ApplyChanges return " "with ret code: %{public}d!", result); return result; } MediaLibrary_ErrorCode NDKCamera::ChangeRequestSaveCameraPhoto(void) { - DRAWING_LOGD("NDKCamera::ChangeRequestSaveCameraPhoto start!"); + OH_LOG_INFO(LOG_APP, "NDKCamera::ChangeRequestSaveCameraPhoto start!"); result = OH_MediaAssetChangeRequest_SaveCameraPhoto(g_changeRequest, MediaLibrary_ImageFileType::MEDIA_LIBRARY_IMAGE_JPEG); if (result != MEDIA_LIBRARY_OK) { - DRAWING_LOGD("NDKCamera::ChangeRequestSaveCameraPhoto OH_MediaAssetChangeRequest_SaveCameraPhoto failed."); + OH_LOG_INFO(LOG_APP, "NDKCamera::ChangeRequestSaveCameraPhoto OH_MediaAssetChangeRequest_SaveCameraPhoto failed."); } - DRAWING_LOGD("NDKCamera::ChangeRequestSaveCameraPhoto OH_MediaAssetChangeRequest_SaveCameraPhoto return with ret " + OH_LOG_INFO(LOG_APP, "NDKCamera::ChangeRequestSaveCameraPhoto OH_MediaAssetChangeRequest_SaveCameraPhoto return with ret " "code: %{public}d!", result); result = OH_MediaAccessHelper_ApplyChanges(g_changeRequest); if (result != MEDIA_LIBRARY_OK) { - DRAWING_LOGD("NDKCamera::ChangeRequestSaveCameraPhoto OH_MediaAccessHelper_ApplyChanges failed."); + OH_LOG_INFO(LOG_APP, "NDKCamera::ChangeRequestSaveCameraPhoto OH_MediaAccessHelper_ApplyChanges failed."); } - DRAWING_LOGD( + OH_LOG_INFO(LOG_APP, "NDKCamera::ChangeRequestSaveCameraPhoto OH_MediaAccessHelper_ApplyChanges return with ret code: %{public}d!", result); return result; } MediaLibrary_ErrorCode NDKCamera::ChangeRequestDiscardCameraPhoto(void) { - DRAWING_LOGD("NDKCamera::ChangeRequestDiscardCameraPhoto start!"); + OH_LOG_INFO(LOG_APP, "NDKCamera::ChangeRequestDiscardCameraPhoto start!"); result = OH_MediaAssetChangeRequest_DiscardCameraPhoto(g_changeRequest); if (result != MEDIA_LIBRARY_OK) { - DRAWING_LOGD( + OH_LOG_INFO(LOG_APP, "NDKCamera::ChangeRequestDiscardCameraPhoto OH_MediaAssetChangeRequest_DiscardCameraPhoto failed."); } - DRAWING_LOGD("NDKCamera::ChangeRequestDiscardCameraPhoto OH_MediaAssetChangeRequest_DiscardCameraPhoto return with " + OH_LOG_INFO(LOG_APP, "NDKCamera::ChangeRequestDiscardCameraPhoto OH_MediaAssetChangeRequest_DiscardCameraPhoto return with " "ret code: %{public}d!", result); result = OH_MediaAccessHelper_ApplyChanges(g_changeRequest); if (result != MEDIA_LIBRARY_OK) { - DRAWING_LOGD("NDKCamera::ChangeRequestDiscardCameraPhoto OH_MediaAccessHelper_ApplyChanges failed."); + OH_LOG_INFO(LOG_APP, "NDKCamera::ChangeRequestDiscardCameraPhoto OH_MediaAccessHelper_ApplyChanges failed."); } - DRAWING_LOGD("NDKCamera::ChangeRequestDiscardCameraPhoto OH_MediaAccessHelper_ApplyChanges return with ret code: " + OH_LOG_INFO(LOG_APP, "NDKCamera::ChangeRequestDiscardCameraPhoto OH_MediaAccessHelper_ApplyChanges return with ret code: " "%{public}d!", result); return result; } MediaLibrary_ErrorCode NDKCamera::ChangeRequestRelease(void) { - DRAWING_LOGD("NDKCamera::ChangeRequestRelease start!"); + OH_LOG_INFO(LOG_APP, "NDKCamera::ChangeRequestRelease start!"); result = OH_MediaAssetChangeRequest_Release(g_changeRequest); if (result != MEDIA_LIBRARY_OK) { - DRAWING_LOGD("NDKCamera::ChangeRequestRelease failed."); + OH_LOG_INFO(LOG_APP, "NDKCamera::ChangeRequestRelease failed."); } g_changeRequest = nullptr; - DRAWING_LOGD("NDKCamera::ChangeRequestRelease return with ret code: %{public}d!", result); + OH_LOG_INFO(LOG_APP, "NDKCamera::ChangeRequestRelease return with ret code: %{public}d!", result); return result; } MediaLibrary_ErrorCode NDKCamera::MediaAssetManagerCreate(void) { - DRAWING_LOGD("NDKCamera::MediaAssetManagerCreate start!"); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetManagerCreate start!"); mediaAssetManager = OH_MediaAssetManager_Create(); if (mediaAssetManager == nullptr) { - DRAWING_LOGD("NDKCamera::MediaAssetManagerCreate failed."); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetManagerCreate failed."); } return MEDIA_LIBRARY_OK; } @@ -2234,31 +1780,31 @@ void OnRequsetImageDataPreparedWithDetails(MediaLibrary_ErrorCode result, MediaL { auto cb = (void (*)(char *))(g_requestImageCallback); auto qCb = (void (*)(char *))(g_requestImageQualityCallback); - DRAWING_LOGD("OnRequsetImageDataPreparedWithDetails start!"); + OH_LOG_INFO(LOG_APP, "OnRequsetImageDataPreparedWithDetails start!"); if (mediaQuality == MediaLibrary_MediaQuality::MEDIA_LIBRARY_QUALITY_FAST) { - DRAWING_LOGD("OnRequsetImageDataPreparedWithDetails into fast quality mode!"); + OH_LOG_INFO(LOG_APP, "OnRequsetImageDataPreparedWithDetails into fast quality mode!"); g_mediaQualityCb = "fast"; qCb(g_mediaQualityCb); } else { - DRAWING_LOGD("OnRequsetImageDataPreparedWithDetails into high quality mode!"); + OH_LOG_INFO(LOG_APP, "OnRequsetImageDataPreparedWithDetails into high quality mode!"); g_mediaQualityCb = "high"; qCb(g_mediaQualityCb); } - DRAWING_LOGD("OnRequsetImageDataPreparedWithDetails GetUri g_uri = %{public}s", g_uri); + OH_LOG_INFO(LOG_APP, "OnRequsetImageDataPreparedWithDetails GetUri g_uri = %{public}s", g_uri); cb(const_cast(g_uri)); NDKCamera::ChangeRequestAddResourceWithBuffer(imageSourceNative); return; } MediaLibrary_ErrorCode NDKCamera::MediaAssetManagerRequestImage(OH_MediaAsset *mediaAsset) { - DRAWING_LOGD("NDKCamera::MediaAssetManagerRequestImage start! g_deliveryMode = %{public}d", g_deliveryMode); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetManagerRequestImage start! g_deliveryMode = %{public}d", g_deliveryMode); requestOptions.deliveryMode = g_deliveryMode; result = OH_MediaAssetManager_RequestImage(mediaAssetManager, mediaAsset, requestOptions, &g_requestId, OnRequsetImageDataPreparedWithDetails); if (result != MEDIA_LIBRARY_OK) { - DRAWING_LOGD("NDKCamera::MediaAssetManagerRequestImage failed."); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetManagerRequestImage failed."); } - DRAWING_LOGD("NDKCamera::MediaAssetManagerRequestImage return with ret code: %{public}d!", result); + OH_LOG_INFO(LOG_APP, "NDKCamera::MediaAssetManagerRequestImage return with ret code: %{public}d!", result); return result; } } // namespace OHOS_CAMERA_SAMPLE diff --git a/CameraKit/NDKPreconfigSample/entry/src/main/cpp/camera_manager.h b/CameraKit/NDKPreconfigSample/entry/src/main/cpp/camera_manager.h index c1c38efbf..3334c730a 100644 --- a/CameraKit/NDKPreconfigSample/entry/src/main/cpp/camera_manager.h +++ b/CameraKit/NDKPreconfigSample/entry/src/main/cpp/camera_manager.h @@ -56,7 +56,7 @@ class NDKCamera { ~NDKCamera(); NDKCamera(char *str, uint32_t focusMode, uint32_t cameraDeviceIndex, uint32_t sceneMode, uint32_t preconfigMode, uint32_t preconfigType, uint32_t preconfigRatio, - uint32_t photoOutputType, bool isMovingPhoto, bool isSavingPhoto); + uint32_t photoOutputType, char *videoId, char *photoId); static void Destroy() { @@ -222,6 +222,7 @@ class NDKCamera { Camera_Type type_; char *previewSurfaceId_; char *photoSurfaceId_; + char *videoSurfaceId_; Camera_ErrorCode ret_; uint32_t takePictureTimes = 0; Camera_ExposureMode exposureMode_; diff --git a/CameraKit/NDKPreconfigSample/entry/src/main/cpp/main.cpp b/CameraKit/NDKPreconfigSample/entry/src/main/cpp/main.cpp index bce2a01ce..8ce10c78b 100644 --- a/CameraKit/NDKPreconfigSample/entry/src/main/cpp/main.cpp +++ b/CameraKit/NDKPreconfigSample/entry/src/main/cpp/main.cpp @@ -124,12 +124,16 @@ static napi_value InitCamera(napi_env env, napi_callback_info info) bool photoOutputType; napi_get_value_bool(env, args[ARGS_SEVEN], &photoOutputType); - - bool isMovingPhoto; - napi_get_value_bool(env, args[ARGS_EIGHT], &isMovingPhoto); - - bool isSavingPhoto; - napi_get_value_bool(env, args[ARGS_NINE], &isSavingPhoto); + + char* videoId = nullptr; + napi_get_value_string_utf8(env, args[ARGS_EIGHT], nullptr, 0, &typeLen); + videoId = new char[typeLen + 1]; + napi_get_value_string_utf8(env, args[ARGS_EIGHT], videoId, typeLen + 1, &typeLen); + + char* photoId = nullptr; + napi_get_value_string_utf8(env, args[ARGS_NINE], nullptr, 0, &typeLen); + photoId = new char[typeLen + 1]; + napi_get_value_string_utf8(env, args[ARGS_NINE], photoId, typeLen + 1, &typeLen); OH_LOG_ERROR(LOG_APP, "InitCamera focusMode : %{public}d, surfaceId : %{public}s", focusMode, surfaceId); OH_LOG_ERROR(LOG_APP, "InitCamera DeviceIndex: %{public}d, sceneMode: %{public}d", cameraDeviceIndex, sceneMode); @@ -144,7 +148,7 @@ static napi_value InitCamera(napi_env env, napi_callback_info info) } ndkCamera_ = new NDKCamera(surfaceId, focusMode, cameraDeviceIndex, sceneMode, preconfigMode, preconfigType, preconfigRatio, - photoOutputType, isMovingPhoto, isSavingPhoto); + photoOutputType, videoId, photoId); OH_LOG_ERROR(LOG_APP, "InitCamera End"); napi_create_int32(env, argc, &result); return result; @@ -544,7 +548,7 @@ static napi_value VideoOutputStopAndRelease(napi_env env, napi_callback_info inf napi_value result = nullptr; ndkCamera_->VideoOutputStop(); - ndkCamera_->VideoOutputRelease(); +// ndkCamera_->VideoOutputRelease(); OH_LOG_ERROR(LOG_APP, "VideoOutputStopAndRelease End"); napi_create_int32(env, argc, &result); diff --git a/CameraKit/NDKPreconfigSample/entry/src/main/cpp/types/libentry/index.d.ts b/CameraKit/NDKPreconfigSample/entry/src/main/cpp/types/libentry/index.d.ts index 038b31228..9a35f5f28 100644 --- a/CameraKit/NDKPreconfigSample/entry/src/main/cpp/types/libentry/index.d.ts +++ b/CameraKit/NDKPreconfigSample/entry/src/main/cpp/types/libentry/index.d.ts @@ -17,7 +17,7 @@ import { Callback } from '@kit.BasicServicesKit'; export const initCamera:(surfaceId: string, focusMode: number, cameraDeviceIndex: number, sceneMode: number, preconfigMode: number, preconfigType: number, preconfigRatio: number, - photoOutputType: number, isMovingPhoto: boolean, isSavingPhoto: boolean) => number; + photoOutputType: number, videoId: string, photoId: string) => number; export const startPhotoOrVideo: (modeFlag: string, videoId: string, photoId: string) => number; export const videoOutputStart: () => number; export const setZoomRatio: (a: number) => number; diff --git a/CameraKit/NDKPreconfigSample/entry/src/main/ets/pages/Index.ets b/CameraKit/NDKPreconfigSample/entry/src/main/ets/pages/Index.ets index 1890473b3..b1eaccf31 100644 --- a/CameraKit/NDKPreconfigSample/entry/src/main/ets/pages/Index.ets +++ b/CameraKit/NDKPreconfigSample/entry/src/main/ets/pages/Index.ets @@ -28,12 +28,9 @@ import display from '@ohos.display'; import * as Common from '../common/Constants' import { SettingDataObj } from '../common/Constants' import common from '@ohos.app.ability.common' +import { camera } from '@kit.CameraKit'; const TAG: string = 'UI indexPage'; -// scene mode -const NORMAL_PHOTO: number = 1; -const NORMAL_VIDEO: number = 2; -const SECURE_PHOTO: number = 12; // preconfig mode const PRECONFIG_MODE_01: number = 1; const PRECONFIG_MODE_02: number = 2; @@ -120,7 +117,11 @@ struct Index { }; private appContext: common.Context = this.getUIContext().getHostContext()!; // Set Popup Box - @State sceneMode: number = NORMAL_PHOTO; + @State videoId: string = ''; + @State mSurfaceId: string = ''; + @State videoTrigger: number = 0; + @State photoTrigger: number = 0; + @State sceneMode: camera.SceneMode = camera.SceneMode.NORMAL_PHOTO; @State preconfigMode: number = PRECONFIG_MODE_03; @State preconfigType: number = PRECONFIG_1080P; @State preconfigRatio: number = PRECONFIG_RATIO_1_1; @@ -191,9 +192,14 @@ struct Index { Logger.info(TAG, `onConfigTypeChanged 111: ${this.xComponentHeight} this.selectedIndex ${this.selectedIndex}`); this.updateXComponentSize(); Logger.info(TAG, `onConfigTypeChanged 333: ${this.xComponentHeight} this.PreconfigType= ${this.preconfigType}`); - cameraDemo.initCamera(this.surfaceId, this.focusMode, this.cameraDeviceIndex, - this.sceneMode, this.preconfigMode, this.preconfigType, this.preconfigRatio, - this.photoOutputType, this.isMovingPhoto, this.isSavingPhoto); + // cameraDemo.initCamera(this.surfaceId, this.focusMode, this.cameraDeviceIndex, + // this.sceneMode, this.preconfigMode, this.preconfigType, this.preconfigRatio, + // this.photoOutputType, this.videoId, this.mSurfaceId); + if (this.sceneMode == camera.SceneMode.NORMAL_VIDEO) { + this.videoTrigger++; + } else { + this.photoTrigger++; + } } onRatioConfigChanged() { @@ -201,9 +207,14 @@ struct Index { Logger.info(TAG, `onRatioConfigChanged 111: ${this.xComponentHeight} this.ratioIndex ${this.ratioIndex}`); this.updateXComponentSize(); Logger.info(TAG, `onRatioConfigChanged 333: ${this.xComponentHeight} this.mConfigRatio= ${this.preconfigRatio}`); - cameraDemo.initCamera(this.surfaceId, this.focusMode, this.cameraDeviceIndex, - this.sceneMode, this.preconfigMode, this.preconfigType, this.preconfigRatio, - this.photoOutputType, this.isMovingPhoto, this.isSavingPhoto); + // cameraDemo.initCamera(this.surfaceId, this.focusMode, this.cameraDeviceIndex, + // this.sceneMode, this.preconfigMode, this.preconfigType, this.preconfigRatio, + // this.photoOutputType, this.videoId, this.mSurfaceId); + if (this.sceneMode == camera.SceneMode.NORMAL_VIDEO) { + this.videoTrigger++; + } else { + this.photoTrigger++; + } } // Obtain permissions @@ -229,9 +240,12 @@ struct Index { Logger.info(TAG, `onPageShow App1`); if (this.surfaceId && this.onShow) { Logger.error(TAG, `initCamera start1`); - cameraDemo.initCamera(this.surfaceId, this.settingDataObj.focusMode, this.cameraDeviceIndex, - this.sceneMode, this.preconfigMode, this.preconfigType, this.preconfigRatio, - this.photoOutputType, this.isMovingPhoto, this.isSavingPhoto); + if (this.sceneMode == camera.SceneMode.NORMAL_VIDEO) { + this.videoTrigger++; + } else { + this.photoTrigger++; + // cameraDemo.initCamera(this.surfaceId, this.videoId, this.sceneMode, this.settingDataObj.focusMode, this.cameraDeviceIndex); + } Logger.error(TAG, `initCamera end1`); } @@ -256,9 +270,9 @@ struct Index { this.surfaceId = this.mXComponentController.getXComponentSurfaceId(); Logger.info(TAG, `onLoad surfaceId: ${this.surfaceId}`); Logger.error(TAG, `initCamera start`); - cameraDemo.initCamera(this.surfaceId, this.settingDataObj.focusMode, this.cameraDeviceIndex, + cameraDemo.initCamera(this.surfaceId, this.focusMode, this.cameraDeviceIndex, this.sceneMode, this.preconfigMode, this.preconfigType, this.preconfigRatio, - this.photoOutputType, this.isMovingPhoto, this.isSavingPhoto); + this.photoOutputType, this.videoId, this.mSurfaceId); let device = Common.cameraDeviceIndex; device = this.cameraDeviceIndex; @@ -277,6 +291,7 @@ struct Index { } }); Logger.error(TAG, `initCamera end`); + this.photoTrigger++; }) .backgroundColor(Color.Blue) .width(this.xComponentWidth) @@ -306,7 +321,7 @@ struct Index { modeSwitchPage({ surfaceId: this.surfaceId, cameraDeviceIndex: $cameraDeviceIndex, - sceneMode: $sceneMode, + sceneMode: this.sceneMode, preconfigMode: this.preconfigMode, preconfigType: this.preconfigType, preconfigRatio: this.preconfigRatio, @@ -314,7 +329,11 @@ struct Index { isMovingPhoto: this.isMovingPhoto, isSavingPhoto: this.isSavingPhoto, countdownNum: $countdownNum, - isHdr: this.isHdr + isHdr: this.isHdr, + videoId: this.videoId, + videoTrigger: this.videoTrigger, + photoTrigger: this.photoTrigger, + mSurfaceId: this.mSurfaceId }); Row({ space: 24 }) { diff --git a/CameraKit/NDKPreconfigSample/entry/src/main/ets/views/ModeSwitchPage.ets b/CameraKit/NDKPreconfigSample/entry/src/main/ets/views/ModeSwitchPage.ets index 7f788f2a1..9191e624b 100644 --- a/CameraKit/NDKPreconfigSample/entry/src/main/ets/views/ModeSwitchPage.ets +++ b/CameraKit/NDKPreconfigSample/entry/src/main/ets/views/ModeSwitchPage.ets @@ -26,6 +26,9 @@ import { fileIo, ReadOptions, WriteOptions } from '@kit.CoreFileKit'; import { Constants, SettingDataObj } from '../common/Constants' import common from '@ohos.app.ability.common' import { promptAction, router } from '@kit.ArkUI'; +import { Decimal } from '@kit.ArkTS'; +import { sensor } from '@kit.SensorServiceKit'; +import { camera } from '@kit.CameraKit'; import { BusinessError } from '@kit.BasicServicesKit'; @@ -61,8 +64,10 @@ export struct modeSwitchPage { private tag: string = 'sample modeSwitchPage:'; private fileAsset?: photoAccessHelper.PhotoAsset; private fd: number = -1; - @State videoId: string = ''; - @State mSurfaceId: string = ''; + @Link videoId: string; + @Link mSurfaceId: string; + @Prop @Watch('onTriggerChange') videoTrigger: number; + @Prop @Watch('onPhotoChange') photoTrigger: number; private cameraSize: CameraSize = { WIDTH: 1280, HEIGHT: 720 @@ -129,7 +134,7 @@ export struct modeSwitchPage { // Video Thumbnails // private videoThumbnail?: image.PixelMap; @State videoThumbnail: image.PixelMap | undefined | null = undefined; - @Link sceneMode: number; + @Link sceneMode: camera.SceneMode; @Prop preconfigMode: number; @Prop preconfigType: number; @Prop preconfigRatio: number; @@ -177,6 +182,81 @@ export struct modeSwitchPage { onChangeIsModeBol() { } + async onTriggerChange() { + await this.getVideoSurfaceID(); + cameraDemo.initCamera(this.surfaceId, this.settingDataObj.focusMode, this.cameraDeviceIndex, + this.sceneMode, this.preconfigMode, this.preconfigType, this.preconfigRatio, + this.photoOutputType, this.videoId, this.mSurfaceId); + } + + async onPhotoChange() { + await this.getPhotoSurfaceID(); + cameraDemo.initCamera(this.surfaceId, this.settingDataObj.focusMode, this.cameraDeviceIndex, + this.sceneMode, this.preconfigMode, this.preconfigType, this.preconfigRatio, + this.photoOutputType, this.videoId, this.mSurfaceId); + } + + getRealData(data: sensor.GravityResponse): number { + let getDeviceDegree: number = 0; + let x = data.x; + let y = data.y; + let z = data.z; + if ((x * x + y * y) * 3 < z * z) { + return getDeviceDegree; + } else { + try { + let sd: Decimal = Decimal.atan2(y, -x); + let sc: Decimal = Decimal.round(Number(sd) / 3.141592653589 * 180); + getDeviceDegree = 90 - Number(sc); + getDeviceDegree = getDeviceDegree >= 0 ? getDeviceDegree % 360 : getDeviceDegree % 360 + 360; + } catch (error) { + let err = error as BusinessError; + console.error(`decimal failed, error: ${err.code}`); + } + } + return getDeviceDegree; + } + + async getGravity() : Promise { + let isSupported: boolean = false; + let data: sensor.Sensor[]; + try { + data = await sensor.getSensorList(); + } catch (error) { + let err = error as BusinessError; + console.error(`getSensorList failed, error: ${err.code}`); + return -1; // 异常场景下返回默认值 + } + + for (let i = 0; i < data.length; i++) { + if (data[i].sensorId === sensor.SensorId.GRAVITY) { + isSupported = true; + break; + } + } + try { + if (isSupported === true) { + const promise: Promise = new Promise((resolve) => { + sensor.once(sensor.SensorId.GRAVITY, (data: sensor.GravityResponse) => { + resolve(this.getRealData(data)); + }); + }) + return promise; + } else { + const promise: Promise = new Promise((resolve) => { + sensor.once(sensor.SensorId.ACCELEROMETER, (data: sensor.AccelerometerResponse) => { + resolve(this.getRealData(data as sensor.GravityResponse)); + }); + }) + return promise; + } + } catch (error) { + let err = error as BusinessError; + console.error(`gePromise failed, error: ${err.code}`); + return -1; // 异常场景下返回默认值 + } + } + // Countdown capture and video countTakeVideoFn() { if (this.countdownNum) { @@ -256,6 +336,7 @@ export struct modeSwitchPage { } this.videoId = await this.videoRecorder.getInputSurface(); + Logger.info(this.tag, `js videoId = ${this.videoId}`); } getVideoProfile(preConfigType: number, configRatio: number) { @@ -405,7 +486,7 @@ export struct modeSwitchPage { // Determine the video or photo mode async isVideoPhotoFn() { - await this.getPhotoSurfaceID(); + // await this.getPhotoSurfaceID(); if (this.modelBagCol == 'photo') { cameraDemo.startPhotoOrVideo(this.modelBagCol, this.videoId, this.mSurfaceId); @@ -416,7 +497,7 @@ export struct modeSwitchPage { } // Start record - await this.getVideoSurfaceID(); + // await this.getVideoSurfaceID(); cameraDemo.startPhotoOrVideo(this.modelBagCol, this.videoId, this.mSurfaceId); cameraDemo.videoOutputStart(); @@ -444,14 +525,15 @@ export struct modeSwitchPage { .borderRadius(14) .fontSize(15) .fontColor(Color.White) - .onClick(() => { + .onClick(async () => { this.modelBagCol = 'photo'; - this.sceneMode = NORMAL_PHOTO; + this.sceneMode = camera.SceneMode.NORMAL_PHOTO; cameraDemo.releaseSession(); + await this.getPhotoSurfaceID(); // sceneMode : 1 (NORMAL_PHOTO) cameraDemo.initCamera(this.surfaceId, this.settingDataObj.focusMode, this.cameraDeviceIndex, - NORMAL_PHOTO, this.preconfigMode, this.preconfigType, this.preconfigRatio, - this.photoOutputType, this.isMovingPhoto, this.isSavingPhoto); + this.sceneMode, this.preconfigMode, this.preconfigType, this.preconfigRatio, + this.photoOutputType, this.videoId, this.mSurfaceId); }) }.position({ x: '45%', y: '77%' }) @@ -461,14 +543,15 @@ export struct modeSwitchPage { .fontColor(Color.White) .borderRadius(14) .size({ width: 64, height: 28 }) - .onClick(() => { + .onClick(async () => { this.modelBagCol = 'video'; - this.sceneMode = NORMAL_VIDEO; + this.sceneMode = camera.SceneMode.NORMAL_VIDEO; cameraDemo.releaseSession(); + await this.getVideoSurfaceID(); // sceneMode : 2 (NORMAL_VIDEO) cameraDemo.initCamera(this.surfaceId, this.settingDataObj.focusMode, this.cameraDeviceIndex, - NORMAL_VIDEO, this.preconfigMode, this.preconfigType, this.preconfigRatio, - this.photoOutputType, this.isMovingPhoto, this.isSavingPhoto); + this.sceneMode, this.preconfigMode, this.preconfigType, this.preconfigRatio, + this.photoOutputType, this.videoId, this.mSurfaceId); }) }.position({ x: '60%', y: '77%' }) @@ -541,10 +624,15 @@ export struct modeSwitchPage { this.cameraDeviceIndex ? this.cameraDeviceIndex = 0 : this.cameraDeviceIndex = 1; // Clear configuration cameraDemo.releaseSession(); + if (this.sceneMode == camera.SceneMode.NORMAL_VIDEO) { + await this.getVideoSurfaceID(); + } else { + await this.getPhotoSurfaceID(); + } // Start preview cameraDemo.initCamera(this.surfaceId, this.settingDataObj.focusMode, this.cameraDeviceIndex, this.sceneMode, this.preconfigMode, this.preconfigType, this.preconfigRatio, - this.photoOutputType, this.isMovingPhoto, this.isSavingPhoto); + this.photoOutputType, this.videoId, this.mSurfaceId); }) } }.position({ x: '70%', y: '85%' }) @@ -611,7 +699,9 @@ export struct modeSwitchPage { try { if (this.videoRecorder) { await this.videoRecorder.stop(); - await this.videoRecorder.release(); + // await this.videoRecorder.release(); + await this.videoRecorder.prepare(this.videoConfig); + await this.videoRecorder.getInputSurface(); } cameraDemo.videoOutputStopAndRelease(); if (this.fileAsset) { diff --git a/CameraKit/NDKPreviewImageSample/build-profile.json5 b/CameraKit/NDKPreviewImageSample/build-profile.json5 index 65e725f8d..f848455bf 100644 --- a/CameraKit/NDKPreviewImageSample/build-profile.json5 +++ b/CameraKit/NDKPreviewImageSample/build-profile.json5 @@ -1,17 +1,17 @@ - /* - * Copyright (c) 2025 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. - */ +/* +* Copyright (c) 2025 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. +*/ { "app": { @@ -19,15 +19,9 @@ { "name": "default", "signingConfig": "default", - "compatibleSdkVersion": "6.0.0(20)", - "runtimeOS": "HarmonyOS", - "targetSdkVersion": "6.0.0(20)", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } + "compileSdkVersion": 23, + "compatibleSdkVersion": 20, + "runtimeOS": "OpenHarmony" } ], "buildModeSet": [ @@ -37,6 +31,20 @@ { "name": "release" } + ], + "signingConfigs": [ + { + "name": "default", + "material": { + "certpath": "C:/Users/wWX1366912/.ohos/config/openharmony/default_NDKPreviewImageSample_SAdrGgKi7ea-HQN8Fhx0zXBnmqiv2mjWySnePZHpwo8=.cer", + "keyAlias": "debugKey", + "keyPassword": "0000001BE46C067843E2B13743FFB4DC2AD932F1972F237A5191A39FA98DBBD244DE519BBE445C358688FB", + "profile": "C:/Users/wWX1366912/.ohos/config/openharmony/default_NDKPreviewImageSample_SAdrGgKi7ea-HQN8Fhx0zXBnmqiv2mjWySnePZHpwo8=.p7b", + "signAlg": "SHA256withECDSA", + "storeFile": "C:/Users/wWX1366912/.ohos/config/openharmony/default_NDKPreviewImageSample_SAdrGgKi7ea-HQN8Fhx0zXBnmqiv2mjWySnePZHpwo8=.p12", + "storePassword": "0000001BBBB5FB693C1FC8E37065D1BD69DDEAB75BE24AC358D706E9201ADF3DBE6A83E571F9AD4745C7A4" + } + } ] }, "modules": [ diff --git a/CameraKit/NDKPreviewImageSample/entry/build-profile.json5 b/CameraKit/NDKPreviewImageSample/entry/build-profile.json5 index d54a42856..80ea69f3f 100644 --- a/CameraKit/NDKPreviewImageSample/entry/build-profile.json5 +++ b/CameraKit/NDKPreviewImageSample/entry/build-profile.json5 @@ -46,7 +46,7 @@ "targets": [ { "name": "default", - "runtimeOS": "HarmonyOS" + "runtimeOS": "OpenHarmony" }, { "name": "ohosTest", diff --git a/CameraKit/NDKPreviewImageSample/entry/src/main/cpp/camera_manager.cpp b/CameraKit/NDKPreviewImageSample/entry/src/main/cpp/camera_manager.cpp index 0e854e496..9917911f3 100644 --- a/CameraKit/NDKPreviewImageSample/entry/src/main/cpp/camera_manager.cpp +++ b/CameraKit/NDKPreviewImageSample/entry/src/main/cpp/camera_manager.cpp @@ -13,27 +13,7 @@ * limitations under the License. */ -#include "hilog/log.h" #include "camera_manager.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include #define LOG_TAG "NDK_CAMERA_MANAGER" #define LOG_DOMAIN 0x3210 @@ -300,6 +280,14 @@ NDKCamera::NDKCamera(char *previewSurfaceId, char *videoSurfaceId, Camera_SceneM ret = OH_CaptureSession_AddVideoOutput(captureSession_, videoOutput_); } ret = OH_CaptureSession_CommitConfig(captureSession_); + if (sceneMode_ == NORMAL_VIDEO) { + bool isMirrorSupported = false; + ret = OH_VideoOutput_IsMirrorSupported(videoOutput_, &isMirrorSupported); + OH_LOG_INFO(LOG_APP, "VideoOutput IsMirrorSupported: %{public}d", isMirrorSupported); + if (isMirrorSupported) { + OH_VideoOutput_EnableMirror(videoOutput_, isMirrorSupported); + } + } ret = OH_CaptureSession_Start(captureSession_); OH_NativeBuffer_ColorSpace curColorSpace; @@ -751,21 +739,21 @@ Camera_ImageRotation NDKCamera::GetVideoRotation(int32_t deviceDegree) Camera_ErrorCode NDKCamera::VideoOutputStart(char *videoId) { OH_LOG_INFO(LOG_APP, "VideoOutputStart begin."); - Camera_ErrorCode ret = OH_CaptureSession_Stop(captureSession_); - ret = OH_CaptureSession_BeginConfig(captureSession_); - ret = OH_CaptureSession_RemoveVideoOutput(captureSession_, videoOutput_); - ret = OH_CameraManager_CreateVideoOutput(cameraManager_, videoProfile_, videoId, &videoOutput_); - ret = OH_CaptureSession_AddVideoOutput(captureSession_, videoOutput_); - - ret = OH_CaptureSession_CommitConfig(captureSession_); - bool isMirrorSupported = false; - ret = OH_VideoOutput_IsMirrorSupported(videoOutput_, &isMirrorSupported); - OH_LOG_INFO(LOG_APP, "VideoOutput IsMirrorSupported: %{public}d", isMirrorSupported); - if (isMirrorSupported) { - OH_VideoOutput_EnableMirror(videoOutput_, isMirrorSupported); - } - ret = OH_CaptureSession_Start(captureSession_); - ret = OH_VideoOutput_Start(videoOutput_); +// Camera_ErrorCode ret = OH_CaptureSession_Stop(captureSession_); +// ret = OH_CaptureSession_BeginConfig(captureSession_); +// ret = OH_CaptureSession_RemoveVideoOutput(captureSession_, videoOutput_); +// ret = OH_CameraManager_CreateVideoOutput(cameraManager_, videoProfile_, videoId, &videoOutput_); +// ret = OH_CaptureSession_AddVideoOutput(captureSession_, videoOutput_); +// +// ret = OH_CaptureSession_CommitConfig(captureSession_); +// bool isMirrorSupported = false; +// ret = OH_VideoOutput_IsMirrorSupported(videoOutput_, &isMirrorSupported); +// OH_LOG_INFO(LOG_APP, "VideoOutput IsMirrorSupported: %{public}d", isMirrorSupported); +// if (isMirrorSupported) { +// OH_VideoOutput_EnableMirror(videoOutput_, isMirrorSupported); +// } +// ret = OH_CaptureSession_Start(captureSession_); + Camera_ErrorCode ret = OH_VideoOutput_Start(videoOutput_); if (ret == CAMERA_OK) { OH_LOG_INFO(LOG_APP, "OH_VideoOutput_Start success."); } else { diff --git a/CameraKit/NDKPreviewImageSample/entry/src/main/cpp/camera_manager.h b/CameraKit/NDKPreviewImageSample/entry/src/main/cpp/camera_manager.h index 51fcc03ab..b2ad46781 100644 --- a/CameraKit/NDKPreviewImageSample/entry/src/main/cpp/camera_manager.h +++ b/CameraKit/NDKPreviewImageSample/entry/src/main/cpp/camera_manager.h @@ -16,6 +16,13 @@ #ifndef CAMERA_NDK_CAMERA_H #define CAMERA_NDK_CAMERA_H +#include +#include +#include "hilog/log.h" +#include +#include +#include +#include #include "ohcamera/camera.h" #include "ohcamera/camera_input.h" #include "ohcamera/camera_device.h" @@ -25,6 +32,19 @@ #include "ohcamera/video_output.h" #include "ohcamera/camera_manager.h" +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + namespace OHOS_CAMERA_NDK_SAMPLE { class NDKCamera { diff --git a/CameraKit/NDKPreviewImageSample/entry/src/main/ets/pages/Index.ets b/CameraKit/NDKPreviewImageSample/entry/src/main/ets/pages/Index.ets index bb43e3d3d..c8d77611a 100644 --- a/CameraKit/NDKPreviewImageSample/entry/src/main/ets/pages/Index.ets +++ b/CameraKit/NDKPreviewImageSample/entry/src/main/ets/pages/Index.ets @@ -43,6 +43,7 @@ struct Index { @State mRotate: number = display.getDefaultDisplaySync().rotation * camera.ImageRotation.ROTATION_90; @State mXComponentWidth: number = Constants.X_COMPONENT_SURFACE_WIDTH; @State mXComponentHeight: number = Constants.X_COMPONENT_SURFACE_HEIGHT; + @State videoTrigger: number = 0; private mWindowHeight = 0; private mWindowWidth = 0; @State reloadXComponentFlag: boolean = false; @@ -226,19 +227,22 @@ struct Index { if (this.previewSurfaceId != '') { Logger.info(TAG, `onPageShow previewSurfaceId:${this.previewSurfaceId} videoSurfaceId:${this.videoSurfaceId} sceneMode:${this.sceneMode}`); - cameraDemo.initCamera(this.previewSurfaceId, this.previewSurfaceIdSlave, this.videoSurfaceId, this.sceneMode, - this.curCameraPosition); - Logger.info(TAG, `onPageShow torch mode change 111111`); - cameraDemo.setFoldCb((foldStatusInfo: camera.FoldStatusInfo) => { - Logger.info(TAG, `onPageShow fold mode change ${foldStatusInfo.foldStatus}`); - for (let i = 0; i < foldStatusInfo.supportedCameras.length; i++) { - console.info(TAG + - `foldStatusChanged camera[${i}]: ${foldStatusInfo.supportedCameras[i].cameraId},cameraPosition: ${foldStatusInfo.supportedCameras[i].cameraPosition}`); - } - this.foldStatusChanged(foldStatusInfo); - }); - cameraDemo.setBufferCb(this.photoBufferCallback); - AppStorage.setOrCreate('isOpenEditPage', false); + if (this.sceneMode == camera.SceneMode.NORMAL_VIDEO) { + this.videoTrigger++; + } else { + cameraDemo.initCamera(this.previewSurfaceId, this.previewSurfaceIdSlave, this.videoSurfaceId, this.sceneMode, + this.curCameraPosition); + cameraDemo.setFoldCb((foldStatusInfo: camera.FoldStatusInfo) => { + Logger.info(TAG, `onPageShow fold mode change ${foldStatusInfo.foldStatus}`); + for (let i = 0; i < foldStatusInfo.supportedCameras.length; i++) { + console.info(TAG + + `foldStatusChanged camera[${i}]: ${foldStatusInfo.supportedCameras[i].cameraId},cameraPosition: ${foldStatusInfo.supportedCameras[i].cameraPosition}`); + } + this.foldStatusChanged(foldStatusInfo); + }); + cameraDemo.setBufferCb(this.photoBufferCallback); + AppStorage.setOrCreate('isOpenEditPage', false); + } } } @@ -314,7 +318,9 @@ struct Index { .justifyContent(FlexAlign.Center) .height('70%') - ModeComponent() + ModeComponent({ + videoTrigger: this.videoTrigger + }) .height('15%') Row() { @@ -351,8 +357,26 @@ struct ModeComponent { @StorageLink('isOpenEditPage') @Watch('changePageState') isOpenEditPage: boolean = false; @State sceneMode: camera.SceneMode = camera.SceneMode.NORMAL_PHOTO; @StorageLink('isRecording') @Watch('changeRecord') isRecording: boolean = false; + @Prop @Watch('onTriggerChange') videoTrigger: number; private avRecorder: media.AVRecorder | undefined = undefined; + async onTriggerChange() { + await this.prepareAVRecorder(); + let previewSurfaceId = AppStorage.get('previewSurfaceId'); + let previewSurfaceIdSlave = AppStorage.get('previewSurfaceIdSlave'); + let videoSurfaceId = AppStorage.get('videoSurfaceId'); + let curCameraPosition = AppStorage.get('curCameraPosition'); + cameraDemo.initCamera(previewSurfaceId, previewSurfaceIdSlave, videoSurfaceId, this.sceneMode, curCameraPosition); + cameraDemo.setFoldCb((foldStatusInfo: camera.FoldStatusInfo) => { + Logger.info(TAG, `onPageShow fold mode change ${foldStatusInfo.foldStatus}`); + for (let i = 0; i < foldStatusInfo.supportedCameras.length; i++) { + console.info(TAG + + `foldStatusChanged camera[${i}]: ${foldStatusInfo.supportedCameras[i].cameraId},cameraPosition: ${foldStatusInfo.supportedCameras[i].cameraPosition}`); + } + }); + AppStorage.setOrCreate('isOpenEditPage', false); + } + updateProfile() { let profile = AppStorage.get('profile'); let ratio = AppStorage.get('ratio'); @@ -420,6 +444,12 @@ struct ModeComponent { } } + async onPageShow() { + if (this.sceneMode == camera.SceneMode.NORMAL_VIDEO) { + await this.prepareAVRecorder(); + } + } + changePageState() { Logger.info(TAG, 'isOpenEditPage change:' + this.isOpenEditPage); if (this.isOpenEditPage) { @@ -586,12 +616,12 @@ struct ModeComponent { Logger.info(TAG, 'startVideo is called 33333'); - let isFirstRecording = AppStorage.get('isFirstRecording'); - Logger.info(TAG, `startVideo isFirstRecording ${isFirstRecording}`); - if (!isFirstRecording) { - Logger.info(TAG, 'startVideo is called 22222'); - await this.prepareAVRecorder(); - } + // let isFirstRecording = AppStorage.get('isFirstRecording'); + // Logger.info(TAG, `startVideo isFirstRecording ${isFirstRecording}`); + // if (!isFirstRecording) { + // Logger.info(TAG, 'startVideo is called 22222'); + // await this.prepareAVRecorder(); + // } // updateRotation let deviceDegree = await this.getGravity(); @@ -611,8 +641,8 @@ struct ModeComponent { let err = error as BusinessError; Logger.error(TAG, `startVideo err: ${JSON.stringify(err)}`); } - AppStorage.set('isFirstRecording', false); - isFirstRecording = AppStorage.get('isFirstRecording'); + // AppStorage.set('isFirstRecording', false); + // isFirstRecording = AppStorage.get('isFirstRecording'); Logger.info(TAG, 'startVideo End of call'); } @@ -690,6 +720,7 @@ struct ModeComponent { cameraDemo.releaseCamera(); this.sceneMode = camera.SceneMode.NORMAL_VIDEO; AppStorage.set('sceneMode', this.sceneMode); + await this.prepareAVRecorder(); let previewSurfaceId = AppStorage.get('previewSurfaceId'); let previewSurfaceIdSlave = AppStorage.get('previewSurfaceIdSlave'); let curCameraPosition = AppStorage.get('curCameraPosition'); @@ -808,6 +839,9 @@ struct ModeComponent { Logger.info(TAG, `switch previewSurfaceId:${previewSurfaceId} videoSurfaceId:${videoSurfaceId} sceneMode:${this.sceneMode},curCameraPosition:${curCameraPosition}`); await cameraDemo.releaseCamera(); + if (this.sceneMode == camera.SceneMode.NORMAL_VIDEO) { + await this.prepareAVRecorder(); + } await cameraDemo.initCamera(previewSurfaceId, previewSurfaceIdSlave, videoSurfaceId, this.sceneMode, curCameraPosition); cameraDemo.setFoldCb((foldStatusInfo: camera.FoldStatusInfo) => { -- Gitee