From a663bd3baaffb67e6d0fd7bab7794608de5caf61 Mon Sep 17 00:00:00 2001 From: pengyueqing Date: Tue, 21 May 2024 15:24:00 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E7=9B=B8=E6=9C=BA=E6=96=B0=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E7=9B=B8=E5=85=B3=E4=BF=AE=E6=94=B92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/cpp/napi_init.cpp | 2 +- .../main/cpp/webRTC_adapter/ohos_camera.cpp | 48 ++++++++++--------- .../src/main/cpp/webRTC_adapter/ohos_camera.h | 11 ++--- .../webRTC_adapter/ohos_camera_capture.cpp | 13 ++--- .../cpp/webRTC_adapter/ohos_camera_capture.h | 1 + 5 files changed, 39 insertions(+), 36 deletions(-) diff --git a/entry/src/main/cpp/napi_init.cpp b/entry/src/main/cpp/napi_init.cpp index 3353dc55..1f6bfef5 100644 --- a/entry/src/main/cpp/napi_init.cpp +++ b/entry/src/main/cpp/napi_init.cpp @@ -128,7 +128,7 @@ static napi_value PeerClientDisConnectServer(napi_env env, napi_callback_info in static napi_value PeerClientConnectPeer(napi_env env, napi_callback_info info) { OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "mytest", "PeerClientConnectPeer"); - webrtc::ohos::OhosCamera::GetInstance().Init(env, info); + webrtc::ohos::OhosCamera::Init(env, info); if (!GetPeerConnect()) { PeerSamplePostEvent(PEER_EVENT_CONNECT_PEER); diff --git a/entry/src/main/cpp/webRTC_adapter/ohos_camera.cpp b/entry/src/main/cpp/webRTC_adapter/ohos_camera.cpp index fc321f37..9ea500df 100644 --- a/entry/src/main/cpp/webRTC_adapter/ohos_camera.cpp +++ b/entry/src/main/cpp/webRTC_adapter/ohos_camera.cpp @@ -16,6 +16,7 @@ #include #include #include +#include "unordered_map" #include #include @@ -68,6 +69,10 @@ public: ohosCamera_ = ohosCamera; } + void UnsetOhosCamera() { + ohosCamera_ = nullptr; + } + OhosCamera* GetOhosCamera() { return ohosCamera_; } @@ -143,10 +148,14 @@ void ImageReceiverCallback(OH_ImageReceiverNative* receiver) { } } +OhosCamera::OhosCamera() { + InitImageReceiver(); + InitCamera(); + GlobalOHOSCamera::GetInstance().SetOhosCamera(this); +} -OhosCamera& OhosCamera::GetInstance(){ - static OhosCamera ohos_camera; - return ohos_camera; +OhosCamera::~OhosCamera() { + GlobalOHOSCamera::GetInstance().UnsetOhosCamera(); } bool OhosCamera::Init(napi_env env, napi_callback_info info){ @@ -159,14 +168,6 @@ bool OhosCamera::Init(napi_env env, napi_callback_info info){ napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); size_t result; - napi_get_value_string_utf8(env, args[0], nullptr, 0, &result); - if (result == 0) { - return false; - } - img_receive_surfaceId_ = new char[result + 1]; - napi_get_value_string_utf8(env, args[0], img_receive_surfaceId_, result + 1, &result); - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "mytest", "img_receive_surfaceId_ = %{public}s", img_receive_surfaceId_); - napi_get_value_string_utf8(env, args[1], nullptr, 0, &result); if (result > 0) { x_component_surfaceId_ = new char[result + 1]; @@ -175,7 +176,6 @@ bool OhosCamera::Init(napi_env env, napi_callback_info info){ x_component_surfaceId_); } - GlobalOHOSCamera::GetInstance().SetOhosCamera(this); is_init_ = true; return true; } @@ -218,17 +218,6 @@ int32_t OhosCamera::InitCamera() { return return_code; } - ret = OH_CameraManager_GetSupportedCameraOutputCapability(camera_manager_, &cameras_[camera_dev_index_], &camera_output_capability_); - if(camera_output_capability_ == nullptr || ret != CAMERA_OK) { - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "mytest", "OH_CameraManager_GetSupportedCameraOutputCapability failed, ret = %{public}d", ret); - return return_code; - } - - if(camera_output_capability_->metadataProfilesSize <= 0) { - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "mytest", "metadataProfilesSize <= 0"); - return return_code; - } - return_code = 0; return return_code; } @@ -270,6 +259,19 @@ int32_t OhosCamera::CameraInputRelease() { int32_t OhosCamera::PreviewOutputCreate() { Camera_ErrorCode ret; + ret = OH_CameraManager_GetSupportedCameraOutputCapability(camera_manager_, &cameras_[camera_dev_index_], + &camera_output_capability_); + if (camera_output_capability_ == nullptr || ret != CAMERA_OK) { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "mytest", + "OH_CameraManager_GetSupportedCameraOutputCapability failed, ret = %{public}d", ret); + return return_code; + } + + if (camera_output_capability_->metadataProfilesSize <= 0) { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "mytest", "metadataProfilesSize <= 0"); + return return_code; + } + preview_profile_ = camera_output_capability_->previewProfiles[profile_index_]; ret = OH_CameraManager_CreatePreviewOutput(camera_manager_, preview_profile_, img_receive_surfaceId_, &preview_output_); diff --git a/entry/src/main/cpp/webRTC_adapter/ohos_camera.h b/entry/src/main/cpp/webRTC_adapter/ohos_camera.h index c7b4615d..0a6e3433 100644 --- a/entry/src/main/cpp/webRTC_adapter/ohos_camera.h +++ b/entry/src/main/cpp/webRTC_adapter/ohos_camera.h @@ -30,8 +30,8 @@ namespace webrtc{ namespace ohos{ class OhosCamera { public: - static OhosCamera& GetInstance(); - bool Init(napi_env env, napi_callback_info info); + OhosCamera(); + static bool Init(napi_env env, napi_callback_info info); int32_t InitCamera(); int32_t InitImageReceiver(); int32_t StartCamera(); @@ -44,10 +44,9 @@ public: bool ImageReceiverOn(uint8_t *buffer, int32_t width, int32_t height, int32_t stride, size_t bufferSize); void RegisterCaptureDataCallback(rtc::VideoSinkInterface *dataCallback); void UnregisterCaptureDataCallback(); - virtual ~OhosCamera(); + ~OhosCamera(); private: - OhosCamera() {}; int32_t CameraInputCreateAndOpen(); int32_t CameraInputRelease(); @@ -63,10 +62,10 @@ private: rtc::VideoSinkInterface *data_callback_ {nullptr}; webrtc::VideoCaptureCapability configured_capability_; - bool is_init_ {false}; + static bool is_init_ {false}; bool is_camera_started_ {false}; char* img_receive_surfaceId_ {nullptr}; - char* x_component_surfaceId_ {nullptr}; + static char* x_component_surfaceId_ {nullptr}; OH_ImageReceiverNative *imageReceiverNative_ {nullptr}; Camera_Manager* camera_manager_ {nullptr}; Camera_Device* cameras_ {nullptr}; diff --git a/entry/src/main/cpp/webRTC_adapter/ohos_camera_capture.cpp b/entry/src/main/cpp/webRTC_adapter/ohos_camera_capture.cpp index ba9d4a42..23817ffe 100644 --- a/entry/src/main/cpp/webRTC_adapter/ohos_camera_capture.cpp +++ b/entry/src/main/cpp/webRTC_adapter/ohos_camera_capture.cpp @@ -15,10 +15,9 @@ namespace ohos { OhosCameraCapture::OhosCameraCapture() {} bool OhosCameraCapture::Init(){ - OhosCamera::GetInstance().InitImageReceiver(); - OhosCamera::GetInstance().InitCamera(); - OhosCamera::GetInstance().RegisterCaptureDataCallback(this); - OhosCamera::GetInstance().StartCamera(); + ohosCamera_ = new OhosCamera(); + ohosCamera_->RegisterCaptureDataCallback(this); + ohosCamera_->StartCamera(); OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "mytest", "init Finish!!!!"); return true; @@ -35,8 +34,10 @@ OhosCameraCapture* OhosCameraCapture::Create() { } void OhosCameraCapture::Destroy() { - OhosCamera::GetInstance().StopCamera(); - OhosCamera::GetInstance().UnregisterCaptureDataCallback(); + ohosCamera_->StopCamera(); + ohosCamera_->UnregisterCaptureDataCallback(); + delete ohosCamera_; + ohosCamera_ = nullptr; } VideoFrame OhosCameraCapture::MaybePreprocess(const VideoFrame &frame) { diff --git a/entry/src/main/cpp/webRTC_adapter/ohos_camera_capture.h b/entry/src/main/cpp/webRTC_adapter/ohos_camera_capture.h index b314e4d9..85ffa0d0 100644 --- a/entry/src/main/cpp/webRTC_adapter/ohos_camera_capture.h +++ b/entry/src/main/cpp/webRTC_adapter/ohos_camera_capture.h @@ -45,6 +45,7 @@ private: void UpdateVideoAdapter(); VideoFrame MaybePreprocess(const VideoFrame &frame); + OhosCamera* ohosCamera_ {nullptr}; Mutex lock_; rtc::VideoBroadcaster broadcaster_; cricket::VideoAdapter video_adapter_; -- Gitee From 4f1d7c7f61331e6cacd6a17fa31647db8dd31b0a Mon Sep 17 00:00:00 2001 From: pengyueqing Date: Tue, 21 May 2024 16:56:08 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E7=9B=B8=E6=9C=BA=E6=96=B0=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E7=9B=B8=E5=85=B3=E4=BF=AE=E6=94=B92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/cpp/napi_init.cpp | 44 ++----------------- entry/src/main/cpp/types/libentry/index.d.ts | 2 - .../main/cpp/webRTC_adapter/ohos_camera.cpp | 8 +--- .../src/main/cpp/webRTC_adapter/ohos_camera.h | 3 +- 4 files changed, 5 insertions(+), 52 deletions(-) diff --git a/entry/src/main/cpp/napi_init.cpp b/entry/src/main/cpp/napi_init.cpp index 1f6bfef5..6d5b4f35 100644 --- a/entry/src/main/cpp/napi_init.cpp +++ b/entry/src/main/cpp/napi_init.cpp @@ -29,31 +29,9 @@ #include #include "client/ohos/peer_sample.h" -static napi_value CreateFromReceiver(napi_env env, napi_callback_info info) { - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - napi_valuetype value_type; - napi_typeof(env, args[0], &value_type); - napi_ref reference; - napi_create_reference(env, args[0], 1, &reference); - napi_value img_receiver_js; - napi_get_reference_value(env, reference, &img_receiver_js); - - ImageReceiverNative *img_receiver_c = OH_Image_Receiver_InitImageReceiverNative(env, img_receiver_js); - napi_value next_image = webrtc::ohos::OhosCamera::GetInstance().GetImageData(env, img_receiver_c); - - int32_t ret = OH_Image_Receiver_Release(img_receiver_c); - if (ret != 0) { - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "mytest", "OH_Image_Receiver_Release failed"); - return nullptr; - } - return next_image; -} - rtc::scoped_refptr ohos_cts; static napi_value InitCamera(napi_env env, napi_callback_info info){ - webrtc::ohos::OhosCamera::GetInstance().Init(env, info); + webrtc::ohos::OhosCamera::Init(env, info); ohos_cts = webrtc::ohos::CapturerTrackSource::Create(); OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "mytest", "had been try create"); @@ -61,7 +39,6 @@ static napi_value InitCamera(napi_env env, napi_callback_info info){ } static napi_value StopCamera(napi_env env, napi_callback_info info) { - webrtc::ohos::OhosCamera::GetInstance().StopCamera(); ohos_cts = nullptr; return nullptr; } @@ -114,7 +91,7 @@ static napi_value PeerClientDisConnectServer(napi_env env, napi_callback_info in { if (GetPeerConnect()) { PeerSamplePostEvent(PEER_EVENT_DISCONNECT_PEER); - webrtc::ohos::OhosCamera::GetInstance().StopCamera(); +// webrtc::ohos::OhosCamera::GetInstance().StopCamera(); sleep(1); } if (GetServerConnect()) { @@ -143,7 +120,7 @@ static napi_value PeerClientDisConnectPeer(napi_env env, napi_callback_info info { if (GetPeerConnect()) { PeerSamplePostEvent(PEER_EVENT_DISCONNECT_PEER); - webrtc::ohos::OhosCamera::GetInstance().StopCamera(); +// webrtc::ohos::OhosCamera::GetInstance().StopCamera(); sleep(1); } napi_value result; @@ -189,19 +166,6 @@ static napi_value PeerClientPeerIsConnect(napi_env env, napi_callback_info info) return result; } -static napi_value ChangeCamera(napi_env env, napi_callback_info info) { - webrtc::ohos::OhosCamera::GetInstance().StopCamera(); - webrtc::ohos::OhosCamera::GetInstance().CameraRelease(); - uint32_t camera_index = webrtc::ohos::OhosCamera::GetInstance().GetCameraIndex(); - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "mytest", "camera_index = %{public}d", camera_index); - camera_index = camera_index <= 1 ? 1 - camera_index : 0; - webrtc::ohos::OhosCamera::GetInstance().SetCameraIndex(camera_index); - webrtc::ohos::OhosCamera::GetInstance().InitCamera(); - webrtc::ohos::OhosCamera::GetInstance().StartCamera(); - - return nullptr; -} - rtc::scoped_refptr ohos_dts = nullptr; static napi_value StartScreenCapture(napi_env env, napi_callback_info info) { ohos_dts = webrtc::ohos::DesktopTrackSource::Create(); @@ -218,9 +182,7 @@ static napi_value Init(napi_env env, napi_value exports) { napi_property_descriptor desc[] = { {"initCamera", nullptr, InitCamera, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"createFromReceiver", nullptr, CreateFromReceiver, nullptr, nullptr, nullptr, napi_default, nullptr}, {"stopCamera", nullptr, StopCamera, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"changeCamera", nullptr, ChangeCamera, nullptr, nullptr, nullptr, napi_default, nullptr}, {"pcClientInit", nullptr, PeerClientInit, nullptr, nullptr, nullptr, napi_default, nullptr}, {"pcClientConnectServer", nullptr, PeerClientConnectServer, nullptr, nullptr, nullptr, napi_default, nullptr}, {"pcClientConnectPeer", nullptr, PeerClientConnectPeer, nullptr, nullptr, nullptr, napi_default, nullptr}, diff --git a/entry/src/main/cpp/types/libentry/index.d.ts b/entry/src/main/cpp/types/libentry/index.d.ts index 33ebf42a..4e47bdd4 100644 --- a/entry/src/main/cpp/types/libentry/index.d.ts +++ b/entry/src/main/cpp/types/libentry/index.d.ts @@ -1,9 +1,7 @@ import image from '@ohos.multimedia.image' -export const createFromReceiver: (a: image.ImageReceiver) => image.Image; export const initCamera: (a: string, b: String) => void; export const stopCamera: () => void; -export const changeCamera: () => void; export const pcClientInit: (server: string, port: number) => number; export const pcClientConnectServer: () => number; diff --git a/entry/src/main/cpp/webRTC_adapter/ohos_camera.cpp b/entry/src/main/cpp/webRTC_adapter/ohos_camera.cpp index 9ea500df..367bacc9 100644 --- a/entry/src/main/cpp/webRTC_adapter/ohos_camera.cpp +++ b/entry/src/main/cpp/webRTC_adapter/ohos_camera.cpp @@ -154,12 +154,7 @@ OhosCamera::OhosCamera() { GlobalOHOSCamera::GetInstance().SetOhosCamera(this); } -OhosCamera::~OhosCamera() { - GlobalOHOSCamera::GetInstance().UnsetOhosCamera(); -} - bool OhosCamera::Init(napi_env env, napi_callback_info info){ - if(is_init_) return true; size_t argc = 2; // 声明参数数组 napi_value args[2] = {nullptr}; @@ -176,7 +171,6 @@ bool OhosCamera::Init(napi_env env, napi_callback_info info){ x_component_surfaceId_); } - is_init_ = true; return true; } @@ -583,6 +577,7 @@ void OhosCamera::UnregisterCaptureDataCallback() { OhosCamera::~OhosCamera() { OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "mytest", "OhosCamera::~OhosCamera start"); + GlobalOHOSCamera::GetInstance().UnsetOhosCamera(); CameraRelease(); if (img_receive_surfaceId_ != nullptr) { delete[] img_receive_surfaceId_; @@ -596,7 +591,6 @@ OhosCamera::~OhosCamera() { camera_dev_index_ = 0; profile_index_ = 0; - is_init_ = false; } } // namespace ohos } // namespace webrtc diff --git a/entry/src/main/cpp/webRTC_adapter/ohos_camera.h b/entry/src/main/cpp/webRTC_adapter/ohos_camera.h index 0a6e3433..af2dbcfe 100644 --- a/entry/src/main/cpp/webRTC_adapter/ohos_camera.h +++ b/entry/src/main/cpp/webRTC_adapter/ohos_camera.h @@ -62,10 +62,9 @@ private: rtc::VideoSinkInterface *data_callback_ {nullptr}; webrtc::VideoCaptureCapability configured_capability_; - static bool is_init_ {false}; bool is_camera_started_ {false}; char* img_receive_surfaceId_ {nullptr}; - static char* x_component_surfaceId_ {nullptr}; + static char* x_component_surfaceId_; OH_ImageReceiverNative *imageReceiverNative_ {nullptr}; Camera_Manager* camera_manager_ {nullptr}; Camera_Device* cameras_ {nullptr}; -- Gitee From 514d20a3356c3688a9e13ea2102653c70cb14989 Mon Sep 17 00:00:00 2001 From: pengyueqing Date: Tue, 21 May 2024 18:54:23 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E7=9B=B8=E6=9C=BA=E6=96=B0=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E7=9B=B8=E5=85=B3=E4=BF=AE=E6=94=B92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/cpp/webRTC_adapter/ohos_camera.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/entry/src/main/cpp/webRTC_adapter/ohos_camera.cpp b/entry/src/main/cpp/webRTC_adapter/ohos_camera.cpp index 367bacc9..6971b509 100644 --- a/entry/src/main/cpp/webRTC_adapter/ohos_camera.cpp +++ b/entry/src/main/cpp/webRTC_adapter/ohos_camera.cpp @@ -148,6 +148,7 @@ void ImageReceiverCallback(OH_ImageReceiverNative* receiver) { } } +char* OhosCamera::x_component_surfaceId_ = nullptr; OhosCamera::OhosCamera() { InitImageReceiver(); InitCamera(); -- Gitee From 55e2e2d2f6317e233debb9fa4b4e1a93871f858a Mon Sep 17 00:00:00 2001 From: pengyueqing Date: Tue, 21 May 2024 19:30:39 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E7=9B=B8=E6=9C=BA=E6=96=B0=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E7=9B=B8=E5=85=B3=E4=BF=AE=E6=94=B92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/cpp/webRTC_adapter/ohos_camera.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/entry/src/main/cpp/webRTC_adapter/ohos_camera.cpp b/entry/src/main/cpp/webRTC_adapter/ohos_camera.cpp index 6971b509..ba8c8afb 100644 --- a/entry/src/main/cpp/webRTC_adapter/ohos_camera.cpp +++ b/entry/src/main/cpp/webRTC_adapter/ohos_camera.cpp @@ -259,12 +259,12 @@ int32_t OhosCamera::PreviewOutputCreate() { if (camera_output_capability_ == nullptr || ret != CAMERA_OK) { OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "mytest", "OH_CameraManager_GetSupportedCameraOutputCapability failed, ret = %{public}d", ret); - return return_code; + return -1; } if (camera_output_capability_->metadataProfilesSize <= 0) { OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "mytest", "metadataProfilesSize <= 0"); - return return_code; + return -1; } preview_profile_ = camera_output_capability_->previewProfiles[profile_index_]; -- Gitee From 01fbc8bee2a8b23fedb1931b92b15e2ba90df885 Mon Sep 17 00:00:00 2001 From: pengyueqing Date: Wed, 22 May 2024 09:24:51 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E7=9B=B8=E6=9C=BA=E6=96=B0=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E7=9B=B8=E5=85=B3=E4=BF=AE=E6=94=B92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/cpp/webRTC_adapter/ohos_camera.cpp | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/entry/src/main/cpp/webRTC_adapter/ohos_camera.cpp b/entry/src/main/cpp/webRTC_adapter/ohos_camera.cpp index ba8c8afb..2f3a3610 100644 --- a/entry/src/main/cpp/webRTC_adapter/ohos_camera.cpp +++ b/entry/src/main/cpp/webRTC_adapter/ohos_camera.cpp @@ -30,16 +30,22 @@ public: : width_(width), height_(height), capacity_(capacity) { Image_ErrorCode ret = OH_ImageReceiverOptions_Create(&options_); if (ret != IMAGE_SUCCESS) { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "mytest", "OH_ImageReceiverOptions_Create failed with code = %{public}d", + ret); return; } ret = OH_ImageReceiverOptions_SetSize(options_, {width_, height_}); if (ret != IMAGE_SUCCESS) { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "mytest", + "OH_ImageReceiverOptions_SetSize failed with code = %{public}d", ret); return; } ret = OH_ImageReceiverOptions_SetCapacity(options_, capacity_); if (ret != IMAGE_SUCCESS) { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "mytest", + "OH_ImageReceiverOptions_SetCapacity failed with code = %{public}d", ret); return; } }; @@ -90,12 +96,16 @@ void ImageReceiverCallback(OH_ImageReceiverNative* receiver) { OH_ImageNative *image; Image_ErrorCode ret = OH_ImageReceiverNative_ReadLatestImage(receiver, &image); if (ret != IMAGE_SUCCESS) { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "mytest", + "OH_ImageReceiverNative_ReadLatestImage failed with code = %{public}d", ret); return; } Image_Size imageSize; ret = OH_ImageNative_GetImageSize(image, &imageSize); if (ret != IMAGE_SUCCESS) { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "mytest", + "OH_ImageNative_GetImageSize failed with code = %{public}d", ret); return; } @@ -103,12 +113,16 @@ void ImageReceiverCallback(OH_ImageReceiverNative* receiver) { size_t typeSize; ret = OH_ImageNative_GetComponentTypes(image, nullptr, &typeSize); if (ret != IMAGE_SUCCESS || typeSize <= 0) { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "mytest", + "OH_ImageNative_GetComponentTypes failed with code = %{public}d", ret); return; } types = new uint32_t[typeSize]; ret = OH_ImageNative_GetComponentTypes(image, &types, &typeSize); if (ret != IMAGE_SUCCESS) { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "mytest", + "OH_ImageNative_GetComponentTypes failed with code = %{public}d", ret); delete [] types; return; } @@ -116,6 +130,8 @@ void ImageReceiverCallback(OH_ImageReceiverNative* receiver) { int32_t rowStride; ret = OH_ImageNative_GetRowStride(image, types[0], &rowStride); if (ret != IMAGE_SUCCESS) { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "mytest", + "OH_ImageNative_GetRowStride failed with code = %{public}d", ret); delete[] types; return; } @@ -125,11 +141,15 @@ void ImageReceiverCallback(OH_ImageReceiverNative* receiver) { size_t bufferSize; ret = OH_ImageNative_GetByteBuffer(image, types[0], &buffer); if (ret != IMAGE_SUCCESS) { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "mytest", + "OH_ImageNative_GetByteBuffer failed with code = %{public}d", ret); delete[] types; return; } ret = OH_ImageNative_GetBufferSize(image, types[0], &bufferSize); if (ret != IMAGE_SUCCESS) { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "mytest", + "OH_ImageNative_GetBufferSize failed with code = %{public}d", ret); delete[] types; return; } @@ -137,6 +157,8 @@ void ImageReceiverCallback(OH_ImageReceiverNative* receiver) { delete[] types; int32_t retInt = OH_NativeBuffer_Map(buffer, (void**)&addr); if (retInt != 0) { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "mytest", + "OH_NativeBuffer_Map failed with code = %{public}d", retInt); return; } @@ -144,6 +166,8 @@ void ImageReceiverCallback(OH_ImageReceiverNative* receiver) { ret = OH_ImageNative_Release(image); if (ret != IMAGE_SUCCESS) { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "mytest", + "OH_ImageNative_Release failed with code = %{public}d", ret); return; } } @@ -180,11 +204,14 @@ int32_t OhosCamera::InitImageReceiver() { ImageReceiverOption imageReceiverOption(640, 480, 8); Image_ErrorCode ret = OH_ImageReceiverNative_Create(imageReceiverOption.GetImageReceiverOptions(), &imageReceiverNative_); if (ret != IMAGE_SUCCESS) { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "mytest", "OH_ImageReceiverNative_Create failed with code = %{public}d", ret); return returnCode; } ret = OH_ImageReceiverNative_On(imageReceiverNative_, ImageReceiverCallback); if (ret != IMAGE_SUCCESS) { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "mytest", "OH_ImageReceiverNative_On failed with code = %{public}d", + ret); return returnCode; } -- Gitee From 9fca5adc521dded9c8f108cc468cf5979fd6408b Mon Sep 17 00:00:00 2001 From: pengyueqing Date: Wed, 22 May 2024 16:09:27 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E7=9B=B8=E6=9C=BA=E6=96=B0=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E7=9B=B8=E5=85=B3=E4=BF=AE=E6=94=B92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/cpp/webRTC_adapter/ohos_camera.cpp | 19 ++++++++++++++++++- .../src/main/cpp/webRTC_adapter/ohos_camera.h | 2 ++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/entry/src/main/cpp/webRTC_adapter/ohos_camera.cpp b/entry/src/main/cpp/webRTC_adapter/ohos_camera.cpp index 2f3a3610..7cfcd5a4 100644 --- a/entry/src/main/cpp/webRTC_adapter/ohos_camera.cpp +++ b/entry/src/main/cpp/webRTC_adapter/ohos_camera.cpp @@ -16,7 +16,6 @@ #include #include #include -#include "unordered_map" #include #include @@ -459,6 +458,23 @@ int32_t OhosCamera::StopCamera() { return 0; } +int32_t ImageReceiverRelease(){ + if (imageReceiverNative_ == nullptr) { + return 0; + } + Image_ErrorCode ret = OH_ImageReceiverNative_Off(imageReceiverNative_); + if (ret != IMAGE_SUCCESS) { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "mytest", "OH_ImageReceiverNative_Off failed, ret = %{public}d", ret); + } + + ret = OH_ImageReceiverNative_Release(imageReceiverNative_); + if (ret != IMAGE_SUCCESS) { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "mytest", "OH_ImageReceiverNative_Release failed, ret = %{public}d", + ret); + } + + return 0; +} int32_t OhosCamera::DeleteCameraOutputCapability() { if (camera_output_capability_ != nullptr) { // napi暂不支持该操作 @@ -509,6 +525,7 @@ int32_t OhosCamera::CameraRelease() { CaptureSessionUnsetting(); CameraInputRelease(); PreviewOutputRelease(); + ImageReceiverRelease(); DeleteCameraOutputCapability(); DeleteCameras(); diff --git a/entry/src/main/cpp/webRTC_adapter/ohos_camera.h b/entry/src/main/cpp/webRTC_adapter/ohos_camera.h index af2dbcfe..64508f5a 100644 --- a/entry/src/main/cpp/webRTC_adapter/ohos_camera.h +++ b/entry/src/main/cpp/webRTC_adapter/ohos_camera.h @@ -55,6 +55,8 @@ private: int32_t CaptureSessionSetting(); int32_t CaptureSessionUnsetting(); + + int32_t ImageReceiverRelease(); int32_t DeleteCameraOutputCapability(); int32_t DeleteCameras(); -- Gitee From a0fe79a84a70568ae194fc99f484fcd01c874dfa Mon Sep 17 00:00:00 2001 From: pengyueqing Date: Wed, 22 May 2024 16:31:41 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E7=9B=B8=E6=9C=BA=E6=96=B0=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E7=9B=B8=E5=85=B3=E4=BF=AE=E6=94=B92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/cpp/webRTC_adapter/ohos_camera.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entry/src/main/cpp/webRTC_adapter/ohos_camera.cpp b/entry/src/main/cpp/webRTC_adapter/ohos_camera.cpp index 7cfcd5a4..f72774d9 100644 --- a/entry/src/main/cpp/webRTC_adapter/ohos_camera.cpp +++ b/entry/src/main/cpp/webRTC_adapter/ohos_camera.cpp @@ -458,7 +458,7 @@ int32_t OhosCamera::StopCamera() { return 0; } -int32_t ImageReceiverRelease(){ +int32_t OhosCamera::ImageReceiverRelease(){ if (imageReceiverNative_ == nullptr) { return 0; } -- Gitee