From 3f261582701fb374575b78f99735f23c06be72b8 Mon Sep 17 00:00:00 2001 From: lengye Date: Fri, 27 Oct 2023 14:00:20 +0000 Subject: [PATCH 1/4] add delete method code for ndk/demo Signed-off-by: lengye --- .../entry/src/main/cpp/camera_manager.cpp | 26 ++- .../entry/src/main/cpp/main.cpp | 6 +- .../entry/src/main/ets/pages/tableIndex.ets | 4 +- frameworks/native/ndk/camera_input.cpp | 4 +- frameworks/native/ndk/camera_manager.cpp | 30 +++ frameworks/native/ndk/capture_session.cpp | 6 +- .../native/ndk/impl/camera_manager_impl.cpp | 192 ++++++++++++++---- .../native/ndk/impl/camera_manager_impl.h | 16 ++ frameworks/native/ndk/metadata_output.cpp | 6 +- frameworks/native/ndk/photo_output.cpp | 6 +- frameworks/native/ndk/preview_output.cpp | 6 +- frameworks/native/ndk/video_output.cpp | 6 +- .../kits/native/include/camera/camera.h | 7 + .../native/include/camera/camera_manager.h | 16 ++ 14 files changed, 279 insertions(+), 52 deletions(-) diff --git a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/camera_manager.cpp b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/camera_manager.cpp index f546f72f8..a71cb2d5c 100644 --- a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/camera_manager.cpp +++ b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/camera_manager.cpp @@ -54,15 +54,37 @@ NDKCamera::NDKCamera(char* str, uint32_t focusMode, uint32_t cameraDeviceIndex) NDKCamera::~NDKCamera() { valid_ = false; - + OH_LOG_ERROR(LOG_APP, "zss ~NDKCamera"); Camera_ErrorCode ret = OH_CaptureSession_Release(captureSession_); if (ret != CAMERA_OK) { OH_LOG_ERROR(LOG_APP, "Release failed."); } - if (cameraManager_) { + if (cameraManager_) { + OH_LOG_ERROR(LOG_APP, "zss Release OH_CameraManager_DeleteSupportedCameras. enter"); + ret = OH_CameraManager_DeleteSupportedCameras(cameraManager_, cameras_, size_); + if (ret != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "Delete Cameras failed."); + } else { + OH_LOG_ERROR(LOG_APP, "zss Release OH_CameraManager_DeleteSupportedCameras. ok"); + } + + ret = OH_CameraManager_DeleteSupportedCameraOutputCapability(cameraManager_, cameraOutputCapability_); + if (ret != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "Delete CameraOutputCapability failed."); + } else { + OH_LOG_ERROR(LOG_APP, "zss Release OH_CameraManager_DeleteSupportedCameraOutputCapability. ok"); + } + + ret = OH_Camera_DeleteCameraMananger(cameraManager_); + if (ret != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "Delete CameraManager failed."); + } else { + OH_LOG_ERROR(LOG_APP, "zss Release OH_Camera_DeleteCameraMananger. ok"); + } cameraManager_ = nullptr; } + OH_LOG_ERROR(LOG_APP, "zss ~NDKCamera exit"); } Camera_ErrorCode NDKCamera::ReleaseCamera() diff --git a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/main.cpp b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/main.cpp index 72a6d2179..461c180c6 100644 --- a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/main.cpp +++ b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/main.cpp @@ -151,7 +151,11 @@ static napi_value ReleaseCamera(napi_env env, napi_callback_info info) napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); ndkCamera_->ReleaseCamera(); - + if(ndkCamera_){ + OH_LOG_ERROR(LOG_APP, "ndkCamera_ 22is not null"); + delete ndkCamera_; + ndkCamera_ = nullptr; + } OH_LOG_ERROR(LOG_APP, "ReleaseCamera End"); napi_create_int32(env, argc, &result); diff --git a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/ets/pages/tableIndex.ets b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/ets/pages/tableIndex.ets index 65586e947..5333157a8 100644 --- a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/ets/pages/tableIndex.ets +++ b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/ets/pages/tableIndex.ets @@ -150,9 +150,9 @@ struct Index { } } - async onPageHide() { + onPageHide() { Logger.info(TAG, `onPageHide App`) - await cameraDemo.releaseCamera(); + cameraDemo.releaseCamera(); // CameraService.releaseCamera() } diff --git a/frameworks/native/ndk/camera_input.cpp b/frameworks/native/ndk/camera_input.cpp index 66320f941..6b63d12b1 100644 --- a/frameworks/native/ndk/camera_input.cpp +++ b/frameworks/native/ndk/camera_input.cpp @@ -68,7 +68,9 @@ Camera_ErrorCode OH_CameraInput_Release(Camera_Input* cameraInput) "invaild argument! cameraInput is null!"); Camera_ErrorCode retCode = cameraInput->Release(); - delete cameraInput; + if (cameraInput != nullptr) { + delete cameraInput; + } return retCode; } diff --git a/frameworks/native/ndk/camera_manager.cpp b/frameworks/native/ndk/camera_manager.cpp index 7a8b4bd4f..760f82bf4 100644 --- a/frameworks/native/ndk/camera_manager.cpp +++ b/frameworks/native/ndk/camera_manager.cpp @@ -28,6 +28,14 @@ Camera_ErrorCode OH_Camera_GetCameraMananger(Camera_Manager** cameraManager) return CAMERA_OK; } +Camera_ErrorCode OH_Camera_DeleteCameraMananger(Camera_Manager* cameraManager) +{ + CHECK_AND_RETURN_RET_LOG(cameraManager != nullptr, CAMERA_INVALID_ARGUMENT, + "invaild argument! cameraManager is null!"); + delete cameraManager; + return CAMERA_OK; +} + Camera_ErrorCode OH_CameraManager_RegisterCallback(Camera_Manager* cameraManager, CameraManager_Callbacks* callback) { CHECK_AND_RETURN_RET_LOG(cameraManager != nullptr, CAMERA_INVALID_ARGUMENT, @@ -66,6 +74,17 @@ Camera_ErrorCode OH_CameraManager_GetSupportedCameras(Camera_Manager* cameraMana return cameraManager->GetSupportedCameras(cameras, size); } +Camera_ErrorCode OH_CameraManager_DeleteSupportedCameras(Camera_Manager* cameraManager, + Camera_Device* cameras, uint32_t size) +{ + CHECK_AND_RETURN_RET_LOG(cameraManager != nullptr, CAMERA_INVALID_ARGUMENT, + "invaild argument! cameraManager is null!"); + CHECK_AND_RETURN_RET_LOG(cameras != nullptr, CAMERA_INVALID_ARGUMENT, + "invaild argument! cameras is null!"); + + return cameraManager->DeleteSupportedCameras(cameras, size); +} + Camera_ErrorCode OH_CameraManager_GetSupportedCameraOutputCapability(Camera_Manager* cameraManager, const Camera_Device* camera, Camera_OutputCapability** cameraOutputCapability) { @@ -77,6 +96,17 @@ Camera_ErrorCode OH_CameraManager_GetSupportedCameraOutputCapability(Camera_Mana return cameraManager->GetSupportedCameraOutputCapability(camera, cameraOutputCapability); } +Camera_ErrorCode OH_CameraManager_DeleteSupportedCameraOutputCapability(Camera_Manager* cameraManager, + Camera_OutputCapability* cameraOutputCapability) +{ + CHECK_AND_RETURN_RET_LOG(cameraManager != nullptr, CAMERA_INVALID_ARGUMENT, + "invaild argument! cameraManager is null!"); + CHECK_AND_RETURN_RET_LOG(cameraOutputCapability != nullptr, CAMERA_INVALID_ARGUMENT, + "invaild argument! cameraOutputCapability is null!"); + + return cameraManager->DeleteSupportedCameraOutputCapability(cameraOutputCapability); +} + Camera_ErrorCode OH_CameraManager_IsCameraMuted(Camera_Manager* cameraManager, bool* isCameraMuted) { MEDIA_DEBUG_LOG("OH_CameraManager_IsCameraMuted is called"); diff --git a/frameworks/native/ndk/capture_session.cpp b/frameworks/native/ndk/capture_session.cpp index 09bd97855..dd319d864 100644 --- a/frameworks/native/ndk/capture_session.cpp +++ b/frameworks/native/ndk/capture_session.cpp @@ -281,7 +281,11 @@ Camera_ErrorCode OH_CaptureSession_Release(Camera_CaptureSession* session) { CHECK_AND_RETURN_RET_LOG(session != nullptr, CAMERA_INVALID_ARGUMENT, "invaild argument! session is null!"); - return session->Release(); + Camera_ErrorCode retCode = session->Release(); + if (session != nullptr) { + delete session; + } + return retCode; } Camera_ErrorCode OH_CaptureSession_HasFlash(Camera_CaptureSession* session, bool* hasFlash) diff --git a/frameworks/native/ndk/impl/camera_manager_impl.cpp b/frameworks/native/ndk/impl/camera_manager_impl.cpp index c65e6f970..82061b01b 100644 --- a/frameworks/native/ndk/impl/camera_manager_impl.cpp +++ b/frameworks/native/ndk/impl/camera_manager_impl.cpp @@ -112,11 +112,26 @@ Camera_ErrorCode Camera_Manager::GetSupportedCameras(Camera_Device** cameras, ui return CAMERA_OK; } +Camera_ErrorCode Camera_Manager::DeleteSupportedCameras(Camera_Device* cameras, uint32_t size) +{ + if (cameras != nullptr) { + for (int i = 0; i < size; i++) { + if (&cameras[i] != nullptr) { + delete[] cameras[i].cameraId; + } + } + delete[] cameras; + } + return CAMERA_OK; +} + Camera_ErrorCode Camera_Manager::GetSupportedCameraOutputCapability(const Camera_Device* camera, Camera_OutputCapability** cameraOutputCapability) { Camera_OutputCapability* outCapability = new Camera_OutputCapability; - + if (!outCapability) { + MEDIA_ERR_LOG("Failed to allocate memory for Camera_OutputCapability!"); + } sptr cameraDevice = nullptr; std::vector> cameraObjList = CameraManager::GetInstance()->GetSupportedCameras(); MEDIA_ERR_LOG("GetSupportedCameraOutputCapability cameraInfo is null, the cameraObjList size is %{public}zu", @@ -147,53 +162,148 @@ Camera_ErrorCode Camera_Manager::GetSupportedCameraOutputCapability(const Camera std::vector previewProfiles = innerCameraOutputCapability->GetPreviewProfiles(); std::vector photoProfiles = innerCameraOutputCapability->GetPhotoProfiles(); std::vector videoProfiles = innerCameraOutputCapability->GetVideoProfiles(); - int previewOutputNum = previewProfiles.size(); - int photoOutputNum = previewProfiles.size(); - int videoOutputNum = videoProfiles.size(); - if (previewOutputNum <= 0 || photoOutputNum <= 0 || videoOutputNum <= 0) { + + std::vector metadataTypeList = innerCameraOutputCapability->GetSupportedMetadataObjectType(); + + GetSupportedPreviewProfiles(outCapability, previewProfiles); + GetSupportedPhotoProfiles(outCapability, photoProfiles); + GetSupportedVideoProfiles(outCapability, videoProfiles); + GetSupportedMetadataTypeList(outCapability, metadataTypeList); + + *cameraOutputCapability = outCapability; + MEDIA_ERR_LOG("GetSupportedCameraOutputCapability previewOutputSize return"); + return CAMERA_OK; +} +Camera_ErrorCode Camera_Manager::GetSupportedPreviewProfiles(Camera_OutputCapability* outCapability, + std::vector &previewProfiles) +{ + int previewOutputSize = previewProfiles.size(); + if (previewOutputSize <= 0) { MEDIA_ERR_LOG("alloc size <= 0"); return CAMERA_INVALID_ARGUMENT; } - Camera_Profile **previewProfilesWarp = new Camera_Profile *; - Camera_Profile **photoProfilesWarp = new Camera_Profile *; - Camera_VideoProfile **videoProfilesWarp = new Camera_VideoProfile *; - Camera_Profile *outPreviewProfiles = new Camera_Profile[previewOutputNum]; - Camera_Profile *outPhotoProfiles = new Camera_Profile[photoOutputNum]; - Camera_VideoProfile *outVideoProfiles = new Camera_VideoProfile[videoOutputNum]; - *previewProfilesWarp = outPreviewProfiles; - *photoProfilesWarp = outPhotoProfiles; - *videoProfilesWarp = outVideoProfiles; - for (int i = 0; i < previewOutputNum; i++) { - outPreviewProfiles[i].format = static_cast(previewProfiles[i].GetCameraFormat()); - outPreviewProfiles[i].size.width = previewProfiles[i].GetSize().width; - outPreviewProfiles[i].size.height = previewProfiles[i].GetSize().height; - MEDIA_ERR_LOG("GetSupportedCameraOutputCapability previewOutputNum enter"); - } - MEDIA_ERR_LOG("GetSupportedCameraOutputCapability previewOutputNum exit"); - - outCapability->previewProfiles = previewProfilesWarp; - - for (int i = 0; i < photoOutputNum; i++) { - outPhotoProfiles[i].format = static_cast(photoProfiles[i].GetCameraFormat()); - outPhotoProfiles[i].size.width = photoProfiles[i].GetSize().width; - outPhotoProfiles[i].size.height = photoProfiles[i].GetSize().height; - } - outCapability->photoProfiles = photoProfilesWarp; - - for (int i = 0; i < videoOutputNum; i++) { - outVideoProfiles[i].format = static_cast(videoProfiles[i].GetCameraFormat()); - outVideoProfiles[i].size.width = videoProfiles[i].GetSize().width; - outVideoProfiles[i].size.height = videoProfiles[i].GetSize().height; - outVideoProfiles[i].range.min = videoProfiles[i].framerates_[0]; - outVideoProfiles[i].range.max = videoProfiles[i].framerates_[1]; - } - outCapability->videoProfiles = videoProfilesWarp; + outCapability->previewProfiles = new Camera_Profile*[previewOutputSize]; + if (!outCapability->previewProfiles) { + MEDIA_ERR_LOG("Failed to allocate memory for previewProfiles"); + } + for (int i = 0; i < previewOutputSize; i++) { + Camera_Profile* outPreviewProfile = new Camera_Profile; + if (!outPreviewProfile) { + MEDIA_ERR_LOG("Failed to allocate memory for outPreviewProfile"); + } + outPreviewProfile->format = static_cast(previewProfiles[i].GetCameraFormat()); + outPreviewProfile->size.width = previewProfiles[i].GetSize().width; + outPreviewProfile->size.height = previewProfiles[i].GetSize().height; + outCapability->previewProfiles[i] = outPreviewProfile; + MEDIA_ERR_LOG("GetSupportedCameraOutputCapability previewOutputSize enter"); + } + outCapability->previewProfilesSize = previewOutputSize; + MEDIA_ERR_LOG("GetSupportedCameraOutputCapability previewOutputSize exit"); + return CAMERA_OK; +} - *cameraOutputCapability = outCapability; - MEDIA_ERR_LOG("GetSupportedCameraOutputCapability previewOutputNum return"); +Camera_ErrorCode Camera_Manager::GetSupportedPhotoProfiles(Camera_OutputCapability* outCapability, + std::vector &photoProfiles) +{ + int photoOutputSize = photoProfiles.size(); + if (photoOutputSize <= 0) { + MEDIA_ERR_LOG("alloc size <= 0"); + return CAMERA_INVALID_ARGUMENT; + } + outCapability->photoProfiles = new Camera_Profile*[photoOutputSize]; + if (!outCapability->photoProfiles) { + MEDIA_ERR_LOG("Failed to allocate memory for photoProfiles"); + } + for (int i = 0; i < photoOutputSize; i++) { + Camera_Profile* outPhotoProfile = new Camera_Profile; + if (!outPhotoProfile) { + MEDIA_ERR_LOG("Failed to allocate memory for outPhotoProfile"); + } + outPhotoProfile->format = static_cast(photoProfiles[i].GetCameraFormat()); + outPhotoProfile->size.width = photoProfiles[i].GetSize().width; + outPhotoProfile->size.height = photoProfiles[i].GetSize().height; + outCapability->photoProfiles[i] = outPhotoProfile; + } + outCapability->photoProfilesSize = photoOutputSize; return CAMERA_OK; } +Camera_ErrorCode Camera_Manager::GetSupportedVideoProfiles(Camera_OutputCapability* outCapability, + std::vector &videoProfiles) +{ + int videoOutputSize = videoProfiles.size(); + if (videoOutputSize <= 0) { + MEDIA_ERR_LOG("alloc size <= 0"); + return CAMERA_INVALID_ARGUMENT; + } + outCapability->videoProfiles = new Camera_VideoProfile*[videoOutputSize]; + if (!outCapability->videoProfiles) { + MEDIA_ERR_LOG("Failed to allocate memory for videoProfiles"); + } + for (int i = 0; i < videoOutputSize; i++) { + Camera_VideoProfile* outVideoProfile = new Camera_VideoProfile; + if (!outVideoProfile) { + MEDIA_ERR_LOG("Failed to allocate memory for outVideoProfile"); + } + outVideoProfile->format = static_cast(videoProfiles[i].GetCameraFormat()); + outVideoProfile->size.width = videoProfiles[i].GetSize().width; + outVideoProfile->size.height = videoProfiles[i].GetSize().height; + outVideoProfile->range.min = videoProfiles[i].framerates_[0]; + outVideoProfile->range.max = videoProfiles[i].framerates_[1]; + outCapability->videoProfiles[i] = outVideoProfile; + } + outCapability->videoProfilesSize = videoOutputSize; + return CAMERA_OK; +} + +Camera_ErrorCode Camera_Manager::GetSupportedMetadataTypeList(Camera_OutputCapability* outCapability, + std::vector &metadataTypeList) +{ + int metadataOutputSize = metadataTypeList.size(); + if (metadataOutputSize <= 0) { + MEDIA_ERR_LOG("alloc size <= 0"); + return CAMERA_INVALID_ARGUMENT; + } + outCapability->supportedMetadataObjectTypes = new Camera_MetadataObjectType*[metadataOutputSize]; + if (!outCapability->supportedMetadataObjectTypes) { + MEDIA_ERR_LOG("Failed to allocate memory for supportedMetadataObjectTypes"); + } + for (int i = 0; i < metadataOutputSize; i++) { + Camera_MetadataObjectType outmetadataObject = static_cast(metadataTypeList[i]); + outCapability->supportedMetadataObjectTypes[i] = &outmetadataObject; + } + outCapability->metadataProfilesSize = metadataOutputSize; + return CAMERA_OK; +} + +Camera_ErrorCode Camera_Manager::DeleteSupportedCameraOutputCapability(Camera_OutputCapability* cameraOutputCapability) +{ + if (cameraOutputCapability != nullptr) { + for (int i = 0; i < cameraOutputCapability->previewProfilesSize; i++) { + if (cameraOutputCapability->previewProfiles[i] != nullptr) { + delete cameraOutputCapability->previewProfiles[i]; + } + } + + for (int i = 0; i < cameraOutputCapability->photoProfilesSize; i++) { + if (cameraOutputCapability->photoProfiles[i] != nullptr) { + delete cameraOutputCapability->photoProfiles[i]; + } + } + for (int i = 0; i < cameraOutputCapability->videoProfilesSize; i++) { + if (cameraOutputCapability->videoProfiles[i] != nullptr) { + delete cameraOutputCapability->videoProfiles[i]; + } + } + for (int i = 0; i < cameraOutputCapability->metadataProfilesSize; i++) { + if (cameraOutputCapability->supportedMetadataObjectTypes[i] != nullptr) { + delete cameraOutputCapability->supportedMetadataObjectTypes[i]; + } + } + delete cameraOutputCapability; + } + return CAMERA_OK; +} Camera_ErrorCode Camera_Manager::IsCameraMuted(bool* isCameraMuted) { MEDIA_ERR_LOG("Camera_Manager IsCameraMuted is called"); diff --git a/frameworks/native/ndk/impl/camera_manager_impl.h b/frameworks/native/ndk/impl/camera_manager_impl.h index 773d66790..6f43cc484 100644 --- a/frameworks/native/ndk/impl/camera_manager_impl.h +++ b/frameworks/native/ndk/impl/camera_manager_impl.h @@ -37,9 +37,13 @@ public: Camera_ErrorCode GetSupportedCameras(Camera_Device** cameras, uint32_t* size); + Camera_ErrorCode DeleteSupportedCameras(Camera_Device* cameras, uint32_t size); + Camera_ErrorCode GetSupportedCameraOutputCapability(const Camera_Device* camera, Camera_OutputCapability** cameraOutputCapability); + Camera_ErrorCode DeleteSupportedCameraOutputCapability(Camera_OutputCapability* cameraOutputCapability); + Camera_ErrorCode IsCameraMuted(bool* isCameraMuted); Camera_ErrorCode CreateCaptureSession(Camera_CaptureSession** captureSession); @@ -62,6 +66,18 @@ public: Camera_MetadataOutput** metadataOutput); private: + Camera_ErrorCode GetSupportedPreviewProfiles(Camera_OutputCapability* outCapability, + std::vector &previewProfiles); + + Camera_ErrorCode GetSupportedPhotoProfiles(Camera_OutputCapability* outCapability, + std::vector &photoProfiles); + + Camera_ErrorCode GetSupportedVideoProfiles(Camera_OutputCapability* outCapability, + std::vector &videoProfiles); + + Camera_ErrorCode GetSupportedMetadataTypeList(Camera_OutputCapability* outCapability, + std::vector &metadataTypeList); + OHOS::sptr cameraManager_; }; #endif // OHOS_CAMERA_CAPTURE_INPUT_H \ No newline at end of file diff --git a/frameworks/native/ndk/metadata_output.cpp b/frameworks/native/ndk/metadata_output.cpp index 7c90f080f..122a2a2ec 100644 --- a/frameworks/native/ndk/metadata_output.cpp +++ b/frameworks/native/ndk/metadata_output.cpp @@ -95,7 +95,11 @@ Camera_ErrorCode OH_MetadataOutput_Release(Camera_MetadataOutput* metadataOutput CHECK_AND_RETURN_RET_LOG(metadataOutput != nullptr, CAMERA_INVALID_ARGUMENT, "invaild argument! metadataOutput is null!"); - return metadataOutput->Release(); + Camera_ErrorCode retCode = metadataOutput->Release(); + if (metadataOutput != nullptr) { + delete metadataOutput; + } + return retCode; } #ifdef __cplusplus } diff --git a/frameworks/native/ndk/photo_output.cpp b/frameworks/native/ndk/photo_output.cpp index 9382ee08b..200a6a137 100644 --- a/frameworks/native/ndk/photo_output.cpp +++ b/frameworks/native/ndk/photo_output.cpp @@ -100,7 +100,11 @@ Camera_ErrorCode OH_PhotoOutput_Release(Camera_PhotoOutput* photoOutput) CHECK_AND_RETURN_RET_LOG(photoOutput != nullptr, CAMERA_INVALID_ARGUMENT, "invaild argument! photoOutput is null!"); - return photoOutput->Release(); + Camera_ErrorCode retCode = photoOutput->Release(); + if (photoOutput != nullptr) { + delete photoOutput; + } + return retCode; } /** diff --git a/frameworks/native/ndk/preview_output.cpp b/frameworks/native/ndk/preview_output.cpp index ad1462294..9db84f9e1 100644 --- a/frameworks/native/ndk/preview_output.cpp +++ b/frameworks/native/ndk/preview_output.cpp @@ -99,7 +99,11 @@ Camera_ErrorCode OH_PreviewOutput_Release(Camera_PreviewOutput* previewOutput) CHECK_AND_RETURN_RET_LOG(previewOutput != nullptr, CAMERA_INVALID_ARGUMENT, "invaild argument! previewOutput is null!"); - return previewOutput->Release(); + Camera_ErrorCode retCode = previewOutput->Release(); + if (previewOutput != nullptr) { + delete previewOutput; + } + return retCode; } #ifdef __cplusplus } diff --git a/frameworks/native/ndk/video_output.cpp b/frameworks/native/ndk/video_output.cpp index 5329afbf4..d5f51575a 100644 --- a/frameworks/native/ndk/video_output.cpp +++ b/frameworks/native/ndk/video_output.cpp @@ -97,7 +97,11 @@ Camera_ErrorCode OH_VideoOutput_Release(Camera_VideoOutput* videoOutput) CHECK_AND_RETURN_RET_LOG(videoOutput != nullptr, CAMERA_INVALID_ARGUMENT, "invaild argument! videoOutput is null!"); - return videoOutput->Release(); + Camera_ErrorCode retCode = videoOutput->Release(); + if (videoOutput != nullptr) { + delete videoOutput; + } + return retCode; } #ifdef __cplusplus diff --git a/interfaces/kits/native/include/camera/camera.h b/interfaces/kits/native/include/camera/camera.h index b8d8724e2..0c7f36f9f 100644 --- a/interfaces/kits/native/include/camera/camera.h +++ b/interfaces/kits/native/include/camera/camera.h @@ -511,6 +511,13 @@ typedef struct Camera_MetadataObject { */ Camera_ErrorCode OH_Camera_GetCameraMananger(Camera_Manager** cameraManager); +/** + * @since 11 + * @version 1.0 + */ +Camera_ErrorCode OH_Camera_DeleteCameraMananger(Camera_Manager* cameraManager); + + #ifdef __cplusplus } #endif diff --git a/interfaces/kits/native/include/camera/camera_manager.h b/interfaces/kits/native/include/camera/camera_manager.h index 833a6e776..5a386f7ec 100644 --- a/interfaces/kits/native/include/camera/camera_manager.h +++ b/interfaces/kits/native/include/camera/camera_manager.h @@ -55,6 +55,15 @@ Camera_ErrorCode OH_CameraManager_UnregisterCallback(Camera_Manager* cameraManag Camera_ErrorCode OH_CameraManager_GetSupportedCameras(Camera_Manager* cameraManager, Camera_Device** cameras, uint32_t* size); + +/** + * @since 11 + * @version 1.0 + */ +Camera_ErrorCode OH_CameraManager_DeleteSupportedCameras(Camera_Manager* cameraManager, + Camera_Device* cameras, uint32_t size); + + /** * @since 11 * @version 1.0 @@ -62,6 +71,13 @@ Camera_ErrorCode OH_CameraManager_GetSupportedCameras(Camera_Manager* cameraMana Camera_ErrorCode OH_CameraManager_GetSupportedCameraOutputCapability(Camera_Manager* cameraManager, const Camera_Device* camera, Camera_OutputCapability** cameraOutputCapability); +/** + * @since 11 + * @version 1.0 + */ +Camera_ErrorCode OH_CameraManager_DeleteSupportedCameraOutputCapability(Camera_Manager* cameraManager, + Camera_OutputCapability* cameraOutputCapability); + /** * @since 11 * @version 1.0 -- Gitee From a37434bb2fb9e83b92931dd634054323465317ef Mon Sep 17 00:00:00 2001 From: lengye Date: Sat, 28 Oct 2023 11:37:03 +0800 Subject: [PATCH 2/4] add ndkdemo callback Signed-off-by: lengye --- .../entry/src/main/cpp/camera_manager.cpp | 232 +++++++++++++++++- .../entry/src/main/cpp/camera_manager.h | 28 ++- 2 files changed, 248 insertions(+), 12 deletions(-) diff --git a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/camera_manager.cpp b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/camera_manager.cpp index a71cb2d5c..430d13617 100644 --- a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/camera_manager.cpp +++ b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/camera_manager.cpp @@ -42,11 +42,13 @@ NDKCamera::NDKCamera(char* str, uint32_t focusMode, uint32_t cameraDeviceIndex) if (captureSession_ == nullptr || ret != CAMERA_OK) { OH_LOG_ERROR(LOG_APP, "Create captureSession failed."); } + CaptureSessionRegisterCallback(); GetSupportedCameras(); GetSupportedOutputCapability(); CreatePreviewOutput(); CreateCameraInput(); CameraInputOpen(); + CameraManagerRegisterCallback(); SessionFlowFn(); valid_ = true; } @@ -87,7 +89,7 @@ NDKCamera::~NDKCamera() OH_LOG_ERROR(LOG_APP, "zss ~NDKCamera exit"); } -Camera_ErrorCode NDKCamera::ReleaseCamera() +Camera_ErrorCode NDKCamera::ReleaseCamera(void) { OH_LOG_ERROR(LOG_APP, " enter ReleaseCamera"); if (previewOutput_) { @@ -110,7 +112,7 @@ Camera_ErrorCode NDKCamera::ReleaseCamera() OH_LOG_ERROR(LOG_APP, " exit ReleaseCamera"); return ret_; } -Camera_ErrorCode NDKCamera::ReleaseSession() +Camera_ErrorCode NDKCamera::ReleaseSession(void) { OH_LOG_ERROR(LOG_APP, " enter ReleaseSession"); PreviewOutputStop(); @@ -119,7 +121,7 @@ Camera_ErrorCode NDKCamera::ReleaseSession() OH_LOG_ERROR(LOG_APP, " exit ReleaseSession"); return ret_; } -Camera_ErrorCode NDKCamera::SessionRealese() +Camera_ErrorCode NDKCamera::SessionRealese(void) { OH_LOG_ERROR(LOG_APP, " enter SessionRealese"); Camera_ErrorCode ret = OH_CaptureSession_Release(captureSession_); @@ -325,6 +327,7 @@ Camera_ErrorCode NDKCamera::CreateCameraInput(void) return CAMERA_INVALID_ARGUMENT; } OH_LOG_ERROR(LOG_APP, "exit CreateCameraInput."); + CameraInputRegisterCallback(); return ret_; } @@ -398,6 +401,7 @@ Camera_ErrorCode NDKCamera::CreatePreviewOutput(void) return CAMERA_INVALID_ARGUMENT; } return ret_; + PreviewOutputRegisterCallback(); } Camera_ErrorCode NDKCamera::CreatePhotoOutput(char* photoSurfaceId) @@ -414,7 +418,7 @@ Camera_ErrorCode NDKCamera::CreatePhotoOutput(char* photoSurfaceId) } ret_ = OH_CameraManager_CreatePhotoOutput(cameraManager_, profile_, photoSurfaceId, &photoOutput_); - + PhotoOutputRegisterCallback(); return ret_; } @@ -469,6 +473,7 @@ Camera_ErrorCode NDKCamera::CreateMetadataOutput(void) OH_LOG_ERROR(LOG_APP, "CreateMetadataOutput failed."); return CAMERA_INVALID_ARGUMENT; } + MetadataOutputRegisterCallback(); return ret_; } @@ -536,6 +541,7 @@ Camera_ErrorCode NDKCamera::StartVideo(char* videoId, char* photoId) AddVideoOutput(); SessionCommitConfig(); SessionStart(); + VideoOutputRegisterCallback(); return ret; } @@ -768,7 +774,7 @@ Camera_ErrorCode NDKCamera::VideoOutputRelease(void) return ret_; } -Camera_ErrorCode NDKCamera::TakePicture() +Camera_ErrorCode NDKCamera::TakePicture(void) { Camera_ErrorCode ret = CAMERA_OK; ret = OH_PhotoOutput_Capture(photoOutput_); @@ -797,3 +803,219 @@ Camera_ErrorCode NDKCamera::TakePictureWithPhotoSettings(Camera_PhotoCaptureSett } return ret; } + +// CameraManager Callback +void CameraManagerStatusCallback(Camera_Manager* cameraManager, Camera_StatusInfo* status) +{ + OH_LOG_INFO(LOG_APP, "CameraManagerStatusCallback"); +} + +CameraManager_Callbacks* NDKCamera::GetCameraManagerListener(void) +{ + static CameraManager_Callbacks cameraManagerListener = { + .onCameraStatus = CameraManagerStatusCallback + }; + return &cameraManagerListener; +} + +Camera_ErrorCode NDKCamera::CameraManagerRegisterCallback(void) +{ + ret_ = OH_CameraManager_RegisterCallback(cameraManager_, GetCameraManagerListener()); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "OH_CameraManager_RegisterCallback failed."); + } + return ret_; +} + +// CameraInput Callback +void OnCameraInputError(const Camera_Input* cameraInput, Camera_ErrorCode errorCode) +{ + OH_LOG_INFO(LOG_APP, "OnCameraInput errorCode = %{public}d", errorCode); +} + +CameraInput_Callbacks* NDKCamera::GetCameraInputListener(void) +{ + static CameraInput_Callbacks cameraInputCallbacks = { + .onError = OnCameraInputError + }; + return &cameraInputCallbacks; +} + +Camera_ErrorCode NDKCamera::CameraInputRegisterCallback(void) +{ + ret_ = OH_CameraInput_RegisterCallback(cameraInput_, GetCameraInputListener()); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "OH_CameraInput_RegisterCallback failed."); + } + return ret_; +} + +// PreviewOutput Callback +void PreviewOutputOnFrameStart(Camera_PreviewOutput* previewOutput) +{ + OH_LOG_INFO(LOG_APP, "PreviewOutputOnFrameStart"); +} + +void PreviewOutputOnFrameEnd(Camera_PreviewOutput* previewOutput, int32_t frameCount) +{ + OH_LOG_INFO(LOG_APP, "PreviewOutput frameCount = %{public}d", frameCount); +} + +void PreviewOutputOnError(Camera_PreviewOutput* previewOutput, Camera_ErrorCode errorCode) +{ + OH_LOG_INFO(LOG_APP, "PreviewOutput errorCode = %{public}d", errorCode); +} + +PreviewOutput_Callbacks* NDKCamera::GetPreviewOutputListener(void) +{ + static PreviewOutput_Callbacks previewOutputListener = { + .onFrameStart = PreviewOutputOnFrameStart, + .onFrameEnd = PreviewOutputOnFrameEnd, + .onError = PreviewOutputOnError + }; + return &previewOutputListener; +} + +Camera_ErrorCode NDKCamera::PreviewOutputRegisterCallback(void) +{ + ret_ = OH_PreviewOutput_RegisterCallback(previewOutput_, GetPreviewOutputListener()); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "OH_PreviewOutput_RegisterCallback failed."); + } + return ret_; +} + +// PhotoOutput Callback +void PhotoOutputOnFrameStart(Camera_PhotoOutput* photoOutput) +{ + OH_LOG_INFO(LOG_APP, "PhotoOutputOnFrameStart"); +} + +void PhotoOutputOnFrameShutter(Camera_PhotoOutput* photoOutput, Camera_FrameShutterInfo* info) +{ + OH_LOG_INFO(LOG_APP, "PhotoOutputOnFrameShutter"); +} + +void PhotoOutputOnFrameEnd(Camera_PhotoOutput* photoOutput, int32_t frameCount) +{ + OH_LOG_INFO(LOG_APP, "PhotoOutput frameCount = %{public}d", frameCount); +} + +void PhotoOutputOnError(Camera_PhotoOutput* photoOutput, Camera_ErrorCode errorCode) +{ + OH_LOG_INFO(LOG_APP, "PhotoOutput errorCode = %{public}d", errorCode); +} + +PhotoOutput_Callbacks* NDKCamera::GetPhotoOutputListener(void) +{ + static PhotoOutput_Callbacks photoOutputListener = { + .onFrameStart = PhotoOutputOnFrameStart, + .onFrameShutter = PhotoOutputOnFrameShutter, + .onFrameEnd = PhotoOutputOnFrameEnd, + .onError = PhotoOutputOnError + }; + return &photoOutputListener; +} + +Camera_ErrorCode NDKCamera::PhotoOutputRegisterCallback(void) +{ + ret_ = OH_PhotoOutput_RegisterCallback(photoOutput_, GetPhotoOutputListener()); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "OH_PhotoOutput_RegisterCallback failed."); + } + return ret_; +} + +// VideoOutput Callback +void VideoOutputOnFrameStart(Camera_VideoOutput* videoOutput) +{ + OH_LOG_INFO(LOG_APP, "VideoOutputOnFrameStart"); +} + +void VideoOutputOnFrameEnd(Camera_VideoOutput* videoOutput, int32_t frameCount) +{ + OH_LOG_INFO(LOG_APP, "VideoOutput frameCount = %{public}d", frameCount); +} + +void VideoOutputOnError(Camera_VideoOutput* videoOutput, Camera_ErrorCode errorCode) +{ + OH_LOG_INFO(LOG_APP, "VideoOutput errorCode = %{public}d", errorCode); +} + +VideoOutput_Callbacks* NDKCamera::GetVideoOutputListener(void) +{ + static VideoOutput_Callbacks videoOutputListener = { + .onFrameStart = VideoOutputOnFrameStart, + .onFrameEnd = VideoOutputOnFrameEnd, + .onError = VideoOutputOnError + }; + return &videoOutputListener; +} + +Camera_ErrorCode NDKCamera::VideoOutputRegisterCallback(void) +{ + ret_ = OH_VideoOutput_RegisterCallback(videoOutput_, GetVideoOutputListener()); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "OH_VideoOutput_RegisterCallback failed."); + } + return ret_; +} + +// Metadata Callback +void OnMetadataObjectAvailable(Camera_MetadataOutput* metadataOutput, + Camera_MetadataObject* metadataObject, uint32_t size) +{ + OH_LOG_INFO(LOG_APP, "size = %{public}d", size); +} + +void OnMetadataOutputError(Camera_MetadataOutput* metadataOutput, Camera_ErrorCode errorCode) +{ + OH_LOG_INFO(LOG_APP, "OnMetadataOutput errorCode = %{public}d", errorCode); +} + +MetadataOutput_Callbacks* NDKCamera::GetMetadataOutputListener(void) +{ + static MetadataOutput_Callbacks metadataOutputListener = { + .onMetadataObjectAvailable = OnMetadataObjectAvailable, + .onError = OnMetadataOutputError + }; + return &metadataOutputListener; +} + +Camera_ErrorCode NDKCamera::MetadataOutputRegisterCallback(void) +{ + ret_ = OH_MetadataOutput_RegisterCallback(metadataOutput_, GetMetadataOutputListener()); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "OH_MetadataOutput_RegisterCallback failed."); + } + return ret_; +} + +// Session Callback +void CaptureSessionOnFocusStateChange(Camera_CaptureSession* session, Camera_FocusState focusState) +{ + OH_LOG_INFO(LOG_APP, "CaptureSessionOnFocusStateChange"); +} + +void CaptureSessionOnError(Camera_CaptureSession* session, Camera_ErrorCode errorCode) +{ + OH_LOG_INFO(LOG_APP, "CaptureSession errorCode = %{public}d", errorCode); +} + +CaptureSession_Callbacks* NDKCamera::GetCaptureSessionRegister(void) +{ + static CaptureSession_Callbacks captureSessionCallbacks = { + .onFocusStateChange = CaptureSessionOnFocusStateChange, + .onError = CaptureSessionOnError + }; + return &captureSessionCallbacks; +} + +Camera_ErrorCode NDKCamera::CaptureSessionRegisterCallback(void) +{ + ret_ = OH_CaptureSession_RegisterCallback(captureSession_, GetCaptureSessionRegister()); + if (ret_ != CAMERA_OK) { + OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_RegisterCallback failed."); + } + return ret_; +} \ No newline at end of file diff --git a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/camera_manager.h b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/camera_manager.h index a82b6f836..ccfd4b2d6 100644 --- a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/camera_manager.h +++ b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/camera_manager.h @@ -85,16 +85,33 @@ public: Camera_ErrorCode IsFocusMode(uint32_t mode); Camera_ErrorCode IsFocusPoint(int x, int y); Camera_ErrorCode IsFocusModeSupported(uint32_t mode); - Camera_ErrorCode ReleaseCamera(); - Camera_ErrorCode SessionRealese(); - Camera_ErrorCode ReleaseSession(); + Camera_ErrorCode ReleaseCamera(void); + Camera_ErrorCode SessionRealese(void); + Camera_ErrorCode ReleaseSession(void); int32_t GetVideoFrameWidth(void); int32_t GetVideoFrameHeight(void); int32_t GetVideoFrameRate(void); Camera_ErrorCode VideoOutputStop(void); Camera_ErrorCode VideoOutputRelease(void); - Camera_ErrorCode TakePicture(); + Camera_ErrorCode TakePicture(void); Camera_ErrorCode TakePictureWithPhotoSettings(Camera_PhotoCaptureSetting photoSetting); + // callback + Camera_ErrorCode CameraManagerRegisterCallback(void); + Camera_ErrorCode CameraInputRegisterCallback(void); + Camera_ErrorCode PreviewOutputRegisterCallback(void); + Camera_ErrorCode PhotoOutputRegisterCallback(void); + Camera_ErrorCode VideoOutputRegisterCallback(void); + Camera_ErrorCode MetadataOutputRegisterCallback(void); + Camera_ErrorCode CaptureSessionRegisterCallback(void); + + // Get callback + CameraManager_Callbacks* GetCameraManagerListener(void); + CameraInput_Callbacks* GetCameraInputListener(void); + PreviewOutput_Callbacks* GetPreviewOutputListener(void); + PhotoOutput_Callbacks* GetPhotoOutputListener(void); + VideoOutput_Callbacks* GetVideoOutputListener(void); + MetadataOutput_Callbacks* GetMetadataOutputListener(void); + CaptureSession_Callbacks* GetCaptureSessionRegister(void); private: NDKCamera(const NDKCamera&) = delete; @@ -128,9 +145,6 @@ private: float step_; uint32_t focusMode_; - // callback - CameraManager_Callbacks* callback_; - static NDKCamera* ndkCamera_; static std::mutex mtx_; volatile bool valid_; -- Gitee From 2b473d72a34def783ddafabc90e883cc029413b3 Mon Sep 17 00:00:00 2001 From: lengye Date: Sat, 28 Oct 2023 19:46:16 +0800 Subject: [PATCH 3/4] fix crash and callback info Signed-off-by: lengye --- .../entry/src/main/cpp/camera_manager.cpp | 18 +++++----- .../entry/src/main/cpp/camera_manager.h | 2 +- .../entry/src/main/cpp/main.cpp | 17 +++++---- .../native/ndk/impl/camera_manager_impl.cpp | 36 ++++++++++++------- .../native/ndk/impl/capture_session_impl.cpp | 2 ++ .../kits/native/include/camera/camera.h | 12 +++---- 6 files changed, 51 insertions(+), 36 deletions(-) diff --git a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/camera_manager.cpp b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/camera_manager.cpp index 430d13617..a0c962ca8 100644 --- a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/camera_manager.cpp +++ b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/camera_manager.cpp @@ -56,37 +56,37 @@ NDKCamera::NDKCamera(char* str, uint32_t focusMode, uint32_t cameraDeviceIndex) NDKCamera::~NDKCamera() { valid_ = false; - OH_LOG_ERROR(LOG_APP, "zss ~NDKCamera"); + OH_LOG_ERROR(LOG_APP, "~NDKCamera"); Camera_ErrorCode ret = OH_CaptureSession_Release(captureSession_); if (ret != CAMERA_OK) { OH_LOG_ERROR(LOG_APP, "Release failed."); } if (cameraManager_) { - OH_LOG_ERROR(LOG_APP, "zss Release OH_CameraManager_DeleteSupportedCameras. enter"); + OH_LOG_ERROR(LOG_APP, "Release OH_CameraManager_DeleteSupportedCameras. enter"); ret = OH_CameraManager_DeleteSupportedCameras(cameraManager_, cameras_, size_); if (ret != CAMERA_OK) { OH_LOG_ERROR(LOG_APP, "Delete Cameras failed."); } else { - OH_LOG_ERROR(LOG_APP, "zss Release OH_CameraManager_DeleteSupportedCameras. ok"); + OH_LOG_ERROR(LOG_APP, "Release OH_CameraManager_DeleteSupportedCameras. ok"); } ret = OH_CameraManager_DeleteSupportedCameraOutputCapability(cameraManager_, cameraOutputCapability_); if (ret != CAMERA_OK) { OH_LOG_ERROR(LOG_APP, "Delete CameraOutputCapability failed."); } else { - OH_LOG_ERROR(LOG_APP, "zss Release OH_CameraManager_DeleteSupportedCameraOutputCapability. ok"); - } + OH_LOG_ERROR(LOG_APP, "Release OH_CameraManager_DeleteSupportedCameraOutputCapability. ok"); + } ret = OH_Camera_DeleteCameraMananger(cameraManager_); if (ret != CAMERA_OK) { OH_LOG_ERROR(LOG_APP, "Delete CameraManager failed."); } else { - OH_LOG_ERROR(LOG_APP, "zss Release OH_Camera_DeleteCameraMananger. ok"); - } + OH_LOG_ERROR(LOG_APP, "Release OH_Camera_DeleteCameraMananger. ok"); + } cameraManager_ = nullptr; } - OH_LOG_ERROR(LOG_APP, "zss ~NDKCamera exit"); + OH_LOG_ERROR(LOG_APP, "~NDKCamera exit"); } Camera_ErrorCode NDKCamera::ReleaseCamera(void) @@ -703,7 +703,7 @@ Camera_ErrorCode NDKCamera::IsFocusMode(uint32_t mode) return ret_; } -Camera_ErrorCode NDKCamera::IsFocusPoint(int x, int y) +Camera_ErrorCode NDKCamera::IsFocusPoint(float x, float y) { OH_LOG_INFO(LOG_APP, "IsFocusPoint start."); Camera_Point focusPoint; diff --git a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/camera_manager.h b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/camera_manager.h index ccfd4b2d6..7edf130bd 100644 --- a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/camera_manager.h +++ b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/camera_manager.h @@ -83,7 +83,7 @@ public: Camera_ErrorCode IsMeteringPoint(int x, int y); Camera_ErrorCode IsExposureBiasRange(int exposureBias); Camera_ErrorCode IsFocusMode(uint32_t mode); - Camera_ErrorCode IsFocusPoint(int x, int y); + Camera_ErrorCode IsFocusPoint(float x, float y); Camera_ErrorCode IsFocusModeSupported(uint32_t mode); Camera_ErrorCode ReleaseCamera(void); Camera_ErrorCode SessionRealese(void); diff --git a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/main.cpp b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/main.cpp index 461c180c6..07b0489d9 100644 --- a/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/main.cpp +++ b/frameworks/native/camera/test/ndktest/camera_ndk_demo/entry/src/main/cpp/main.cpp @@ -152,7 +152,7 @@ static napi_value ReleaseCamera(napi_env env, napi_callback_info info) ndkCamera_->ReleaseCamera(); if(ndkCamera_){ - OH_LOG_ERROR(LOG_APP, "ndkCamera_ 22is not null"); + OH_LOG_ERROR(LOG_APP, "ndkCamera_ is not null"); delete ndkCamera_; ndkCamera_ = nullptr; } @@ -328,14 +328,17 @@ static napi_value IsFocusPoint(napi_env env, napi_callback_info info) napi_valuetype valuetype0; napi_typeof(env, args[0], &valuetype0); - int x; - napi_get_value_int32(env, args[0], &x); + double x; + napi_get_value_double(env, args[0], &x); napi_valuetype valuetype1; - napi_typeof(env, args[0], &valuetype0); - int y; - napi_get_value_int32(env, args[1], &y); - ndkCamera_->IsFocusPoint(x, y); + napi_typeof(env, args[1], &valuetype1); + double y; + napi_get_value_double(env, args[1], &y); + + float focusPointX = (float)x; + float focusPointY = (float)y; + ndkCamera_->IsFocusPoint(focusPointX, focusPointY); return result; } diff --git a/frameworks/native/ndk/impl/camera_manager_impl.cpp b/frameworks/native/ndk/impl/camera_manager_impl.cpp index 82061b01b..2aff0ce31 100644 --- a/frameworks/native/ndk/impl/camera_manager_impl.cpp +++ b/frameworks/native/ndk/impl/camera_manager_impl.cpp @@ -279,27 +279,37 @@ Camera_ErrorCode Camera_Manager::GetSupportedMetadataTypeList(Camera_OutputCapab Camera_ErrorCode Camera_Manager::DeleteSupportedCameraOutputCapability(Camera_OutputCapability* cameraOutputCapability) { if (cameraOutputCapability != nullptr) { - for (int i = 0; i < cameraOutputCapability->previewProfilesSize; i++) { - if (cameraOutputCapability->previewProfiles[i] != nullptr) { - delete cameraOutputCapability->previewProfiles[i]; + if (cameraOutputCapability->previewProfiles != nullptr) { + for (int i = 0; i < cameraOutputCapability->previewProfilesSize; i++) { + if (cameraOutputCapability->previewProfiles[i] != nullptr) { + delete cameraOutputCapability->previewProfiles[i]; + } } + delete[] cameraOutputCapability->previewProfiles; } - for (int i = 0; i < cameraOutputCapability->photoProfilesSize; i++) { - if (cameraOutputCapability->photoProfiles[i] != nullptr) { - delete cameraOutputCapability->photoProfiles[i]; + if (cameraOutputCapability->photoProfiles != nullptr) { + for (int i = 0; i < cameraOutputCapability->photoProfilesSize; i++) { + if (cameraOutputCapability->photoProfiles[i] != nullptr) { + delete cameraOutputCapability->photoProfiles[i]; + } } + delete[] cameraOutputCapability->photoProfiles; } - for (int i = 0; i < cameraOutputCapability->videoProfilesSize; i++) { - if (cameraOutputCapability->videoProfiles[i] != nullptr) { - delete cameraOutputCapability->videoProfiles[i]; + + if (cameraOutputCapability->videoProfiles != nullptr) { + for (int i = 0; i < cameraOutputCapability->videoProfilesSize; i++) { + if (cameraOutputCapability->videoProfiles[i] != nullptr) { + delete cameraOutputCapability->videoProfiles[i]; + } } + delete[] cameraOutputCapability->videoProfiles; } - for (int i = 0; i < cameraOutputCapability->metadataProfilesSize; i++) { - if (cameraOutputCapability->supportedMetadataObjectTypes[i] != nullptr) { - delete cameraOutputCapability->supportedMetadataObjectTypes[i]; - } + + if (cameraOutputCapability->supportedMetadataObjectTypes != nullptr) { + delete[] cameraOutputCapability->supportedMetadataObjectTypes; } + delete cameraOutputCapability; } return CAMERA_OK; diff --git a/frameworks/native/ndk/impl/capture_session_impl.cpp b/frameworks/native/ndk/impl/capture_session_impl.cpp index 5d47aab00..8b6363ac4 100644 --- a/frameworks/native/ndk/impl/capture_session_impl.cpp +++ b/frameworks/native/ndk/impl/capture_session_impl.cpp @@ -67,12 +67,14 @@ Camera_ErrorCode Camera_CaptureSession::RegisterCallback(CaptureSession_Callback shared_ptr innerCallback = make_shared(this, callback); innerCaptureSession_->SetCallback(innerCallback); + innerCaptureSession_->SetFocusCallback(innerCallback); return CAMERA_OK; } Camera_ErrorCode Camera_CaptureSession::UnregisterCallback(CaptureSession_Callbacks* callback) { innerCaptureSession_->SetCallback(nullptr); + innerCaptureSession_->SetFocusCallback(nullptr); return CAMERA_OK; } diff --git a/interfaces/kits/native/include/camera/camera.h b/interfaces/kits/native/include/camera/camera.h index 0c7f36f9f..4437d53c1 100644 --- a/interfaces/kits/native/include/camera/camera.h +++ b/interfaces/kits/native/include/camera/camera.h @@ -447,17 +447,17 @@ typedef struct Camera_StatusInfo { * Enumerates the return values that may be used by the interface. */ typedef struct Camera_Point { - int32_t x; - int32_t y; + double x; + double y; } Camera_Point; /** * Enumerates the return values that may be used by the interface. */ typedef struct Camera_Location { - int32_t latitude; - int32_t longitude; - int32_t altitude; + double latitude; + double longitude; + double altitude; } Camera_Location; /** @@ -475,7 +475,7 @@ typedef struct Camera_PhotoCaptureSetting { */ typedef struct Camera_FrameShutterInfo { int32_t captureId; - int64_t timestamp; + uint64_t timestamp; } Camera_FrameShutterInfo; /** -- Gitee From 39ded3d08c1521358caed20cec6a4867cd523261 Mon Sep 17 00:00:00 2001 From: lengye Date: Sat, 28 Oct 2023 20:29:48 +0800 Subject: [PATCH 4/4] fix zoom bug Signed-off-by: lengye --- frameworks/native/ndk/impl/capture_session_impl.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/frameworks/native/ndk/impl/capture_session_impl.cpp b/frameworks/native/ndk/impl/capture_session_impl.cpp index 8b6363ac4..6e241e3c0 100644 --- a/frameworks/native/ndk/impl/capture_session_impl.cpp +++ b/frameworks/native/ndk/impl/capture_session_impl.cpp @@ -178,11 +178,13 @@ Camera_ErrorCode Camera_CaptureSession::SetVideoStabilizationMode(Camera_VideoSt Camera_ErrorCode Camera_CaptureSession::GetZoomRatioRange(float* minZoom, float* maxZoom) { - MEDIA_DEBUG_LOG("Camera_CaptureSession::GetZoomRatioRange is called"); std::vector vecZoomRatioList = innerCaptureSession_->GetZoomRatioRange(); - *minZoom = vecZoomRatioList[0]; - *maxZoom = vecZoomRatioList[1]; - + if (vecZoomRatioList.empty()) { + MEDIA_ERR_LOG("Camera_CaptureSession::GetZoomRatioRange vecZoomRatioList size is null "); + } else { + *minZoom = vecZoomRatioList[0]; + *maxZoom = vecZoomRatioList[1]; + } return CAMERA_OK; } -- Gitee