From 0b9b1efd4c78ea5ee7eaa8d5a8f7b5bceb47c189 Mon Sep 17 00:00:00 2001 From: Bobie Date: Wed, 31 Jul 2024 15:09:02 +0800 Subject: [PATCH] fix client, source and sink issue. Signed-off-by: Bobie --- .../client/src/dcamera_client.cpp | 49 +++++++++++++-- .../dcamera_photo_surface_listener.cpp | 6 +- .../client/test/sample/dcamera_client_demo.h | 6 +- .../client/test/sample/main.cpp | 61 ++++++++++++++++--- .../cameraoperator/dcamera_client_test.cpp | 28 ++++++++- .../handler/src/dcamera_handler.cpp | 18 ++++++ .../distributed_camera_sink_service.cpp | 27 +++++--- .../dcamera_sink_controller.cpp | 45 +++++++++++--- .../dcamera_sink_data_process.cpp | 5 ++ .../dcamera_sink_output.cpp | 48 +++++++++------ .../dcamera_sink_service_ipc.cpp | 6 +- .../dcamera_sink_access_control_test.cpp | 6 +- .../dcamera_sink_controller_test.cpp | 36 ++++++++++- .../dcamera_sink_data_process_test.cpp | 8 +++ .../dcamera_sink_dev_test.cpp | 16 ++++- .../dcamera_sink_output_test.cpp | 10 ++- .../dcamera_frame_trigger_event_test.cpp | 3 +- .../dcamera_photo_output_event_test.cpp | 3 +- .../dcamera_source_service_ipc.cpp | 16 +++-- .../dcamera_source_controller.cpp | 9 ++- .../dcamera_source_data_process.cpp | 26 +++++++- .../dcameradata/dcamera_source_input.cpp | 27 +++++++- .../dcamera_stream_data_process.cpp | 30 ++++++++- .../dcamera_stream_data_process_producer.cpp | 7 ++- .../base/ifeeding_smoother.cpp | 6 +- .../base/time_statistician.cpp | 6 +- .../derived/dcamera_feeding_smoother.cpp | 3 +- .../derived/dcamera_time_statistician.cpp | 6 +- .../dcamera_source_capture_state.cpp | 10 ++- .../dcamera_source_config_stream_state.cpp | 9 ++- .../dcamera_source_init_state.cpp | 3 +- .../dcamera_source_opened_state.cpp | 7 ++- .../dcamera_source_regist_state.cpp | 6 +- .../dcamera_source_state_machine.cpp | 8 ++- 34 files changed, 473 insertions(+), 87 deletions(-) diff --git a/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp b/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp index 5a13933f..6169f2a9 100644 --- a/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp +++ b/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 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 @@ -64,7 +64,7 @@ int32_t DCameraClient::Init() uint64_t listSize = static_cast(cameraList.size()); DHLOGI("Init camera size: %{public}" PRIu64, listSize); for (auto& info : cameraList) { - if (info->GetID() == cameraId_) { + if (info != nullptr && info->GetID() == cameraId_) { DHLOGI("Init cameraInfo get id: %{public}s", GetAnonyString(info->GetID()).c_str()); cameraInfo_ = info; break; @@ -99,6 +99,9 @@ int32_t DCameraClient::UpdateSettings(std::vectortype_) { case UPDATE_METADATA: { DHLOGI("UpdateSettings %{public}s update metadata settings", GetAnonyString(cameraId_).c_str()); @@ -144,6 +147,10 @@ void DCameraClient::FindCameraMetadata(const std::string& metadataStr) { std::shared_ptr cameraMetadata = Camera::MetadataUtils::DecodeFromString(metadataStr); camera_metadata_item_t focusItem; + if (cameraMetadata == nullptr) { + DHLOGE("Camera etadata is null."); + return; + } int32_t ret = Camera::FindCameraMetadataItem(cameraMetadata->get(), OHOS_CONTROL_FOCUS_MODE, &focusItem); if (ret == CAM_META_SUCCESS) { DHLOGI("FindCameraMetadata focus mode: %{public}d", focusItem.data.u8[0]); @@ -191,7 +198,7 @@ int32_t DCameraClient::StartCapture(std::vectorstreamType_ == CONTINUOUS_FRAME) || (!info->isCapture_)) { + if (info == nullptr || (info->streamType_ == CONTINUOUS_FRAME) || (!info->isCapture_)) { continue; } int32_t ret = StartCaptureInner(info); @@ -336,6 +343,7 @@ int32_t DCameraClient::ConfigCaptureSession(std::vector &)cameraInput_)->Open(); if (rc != DCAMERA_OK) { DHLOGE("ConfigCaptureSession cameraInput_ Open failed, cameraId: %{public}s, ret: %{public}d", @@ -365,6 +373,7 @@ int32_t DCameraClient::ConfigCaptureSession(std::vector sessionCallback = std::make_shared(stateCallback_); + CHECK_AND_RETURN_RET_LOG((captureSession_ == nullptr), DCAMERA_BAD_VALUE, "Capture session is null."); captureSession_->SetFocusCallback(sessionCallback); captureSession_->SetCallback(sessionCallback); @@ -380,6 +389,7 @@ int32_t DCameraClient::ConfigCaptureSession(std::vectorBeginConfig(); if (ret != DCAMERA_OK) { DHLOGE("ConfigCaptureSession %{public}s config captureSession failed, ret: %{public}d", @@ -437,6 +447,9 @@ int32_t DCameraClient::CreateCaptureOutput(std::vectorstreamType_ == SNAPSHOT_FRAME) { int32_t ret = CreatePhotoOutput(info); if (ret != DCAMERA_OK) { @@ -461,17 +474,20 @@ int32_t DCameraClient::CreateCaptureOutput(std::vector& info) { + CHECK_AND_RETURN_RET_LOG(info == nullptr, DCAMERA_BAD_VALUE, "Camera info is null"); DHLOGI("CreatePhotoOutput dhId: %{public}s, width: %{public}d, height: %{public}d, format: %{public}d, stream: " "%{public}d, isCapture: %{public}d", GetAnonyString(cameraId_).c_str(), info->width_, info->height_, info->format_, info->streamType_, info->isCapture_); photoSurface_ = IConsumerSurface::Create(); - photoListener_ = sptr( + CHECK_AND_RETURN_RET_LOG((photoSurface_ == nullptr), DCAMERA_BAD_VALUE, "Photo suface is null."); + sptr( new DCameraPhotoSurfaceListener(photoSurface_, resultCallback_)); photoSurface_->RegisterConsumerListener((sptr &)photoListener_); CameraStandard::CameraFormat photoFormat = ConvertToCameraFormat(info->format_); CameraStandard::Size photoSize = {info->width_, info->height_}; CameraStandard::Profile photoProfile(photoFormat, photoSize); sptr bp = photoSurface_->GetProducer(); + CHECK_AND_RETURN_RET_LOG((cameraManager_ == nullptr), DCAMERA_BAD_VALUE, "Camera manager is null."); int32_t rv = cameraManager_->CreatePhotoOutput( photoProfile, bp, &((sptr &)photoOutput_)); if (rv != DCAMERA_OK) { @@ -479,6 +495,7 @@ int32_t DCameraClient::CreatePhotoOutput(std::shared_ptr& in return DCAMERA_BAD_VALUE; } std::shared_ptr photoCallback = std::make_shared(stateCallback_); + CHECK_AND_RETURN_RET_LOG((photoOutput_ == nullptr), DCAMERA_BAD_VALUE, "Photo output is null."); ((sptr &)photoOutput_)->SetCallback(photoCallback); DHLOGI("CreatePhotoOutput %{public}s success", GetAnonyString(cameraId_).c_str()); return DCAMERA_OK; @@ -486,12 +503,14 @@ int32_t DCameraClient::CreatePhotoOutput(std::shared_ptr& in int32_t DCameraClient::CreatePreviewOutput(std::shared_ptr& info) { + CHECK_AND_RETURN_RET_LOG(info == nullptr, DCAMERA_BAD_VALUE, "Camera info is null"); DHLOGI("CreatePreviewOutput dhId: %{public}s, width: %{public}d, height: %{public}d, format: %{public}d, stream:" " %{public}d, isCapture: %{public}d", GetAnonyString(cameraId_).c_str(), info->width_, info->height_, info->format_, info->streamType_, info->isCapture_); CameraStandard::CameraFormat previewFormat = ConvertToCameraFormat(info->format_); CameraStandard::Size previewSize = {info->width_, info->height_}; CameraStandard::Profile previewProfile(previewFormat, previewSize); + CHECK_AND_RETURN_RET_LOG((cameraManager_ == nullptr), DCAMERA_BAD_VALUE, "Camera manager is null."); int32_t rv = cameraManager_->CreatePreviewOutput( previewProfile, previewSurface_, &((sptr &)previewOutput_)); if (rv != DCAMERA_OK) { @@ -499,6 +518,7 @@ int32_t DCameraClient::CreatePreviewOutput(std::shared_ptr& return DCAMERA_BAD_VALUE; } auto previewCallback = std::make_shared(stateCallback_); + CHECK_AND_RETURN_RET_LOG((previewOutput_ == nullptr), DCAMERA_BAD_VALUE, "Preview output is null."); ((sptr &)previewOutput_)->SetCallback(previewCallback); DHLOGI("CreatePreviewOutput %{public}s success", GetAnonyString(cameraId_).c_str()); return DCAMERA_OK; @@ -529,6 +549,7 @@ CameraStandard::CameraFormat DCameraClient::ConvertToCameraFormat(int32_t format int32_t DCameraClient::StartCaptureInner(std::shared_ptr& info) { + CHECK_AND_RETURN_RET_LOG(info == nullptr, DCAMERA_BAD_VALUE, "Camera info is null"); if (info->streamType_ != SNAPSHOT_FRAME) { DHLOGE("StartCaptureInner unknown stream type"); return DCAMERA_BAD_VALUE; @@ -547,12 +568,14 @@ int32_t DCameraClient::StartPhotoOutput(std::shared_ptr& inf std::vector> captureSettings = info->captureSettings_; std::string metadataSetting; for (const auto& setting : captureSettings) { + if (setting == nullptr) { + continue; + } if (setting->type_ == UPDATE_METADATA) { DHLOGI("StartPhotoOutput %{public}s update metadata settings", GetAnonyString(cameraId_).c_str()); metadataSetting = setting->value_; } } - if (metadataSetting.empty()) { DHLOGE("StartPhotoOutput no metadata settings to update"); int32_t ret = ((sptr &)photoOutput_)->Capture(); @@ -585,6 +608,10 @@ void DCameraClient::SetPhotoCaptureRotation(const std::shared_ptrget(), OHOS_JPEG_ORIENTATION, &item); if ((ret == CAM_META_SUCCESS) && (rotationCount == item.count)) { CameraStandard::PhotoCaptureSetting::RotationConfig rotation = @@ -600,6 +627,10 @@ void DCameraClient::SetPhotoCaptureQuality(const std::shared_ptrget(), OHOS_JPEG_QUALITY, &item); if ((ret == CAM_META_SUCCESS) && (qualityCount == item.count)) { CameraStandard::PhotoCaptureSetting::QualityLevel quality = @@ -615,6 +646,10 @@ void DCameraClient::SetPhotoCaptureLocation(const std::shared_ptrget(), OHOS_JPEG_GPS_COORDINATES, &item); if ((ret == CAM_META_SUCCESS) && (locationCount == item.count)) { int32_t latitudeIndex = 0; @@ -624,6 +659,10 @@ void DCameraClient::SetPhotoCaptureLocation(const std::shared_ptrlatitude = item.data.d[latitudeIndex]; location->longitude = item.data.d[longitudeIndex]; location->altitude = item.data.d[altitudeIndex]; + if (photoCaptureSetting == nullptr) { + DHLOGE("photoCaptureSetting is null."); + return; + } photoCaptureSetting->SetLocation(location); DHLOGI("SetPhotoCaptureLocation %{public}s photo capture settings set %{public}d location: " "latitude=%{public}s, longitude=%{public}s, altitude=%{public}s", GetAnonyString(cameraId_).c_str(), diff --git a/services/cameraservice/cameraoperator/client/src/listener/dcamera_photo_surface_listener.cpp b/services/cameraservice/cameraoperator/client/src/listener/dcamera_photo_surface_listener.cpp index 15456867..6232730a 100644 --- a/services/cameraservice/cameraoperator/client/src/listener/dcamera_photo_surface_listener.cpp +++ b/services/cameraservice/cameraoperator/client/src/listener/dcamera_photo_surface_listener.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 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 @@ -52,6 +52,10 @@ void DCameraPhotoSurfaceListener::OnBufferAvailable() do { char *address = static_cast(buffer->GetVirAddr()); int32_t size = -1; + if (buffer->GetExtraData() == nullptr) { + DHLOGE("Data buffer exists null data"); + break; + } buffer->GetExtraData()->ExtraGet("dataSize", size); if (size <= 0) { size = static_cast(buffer->GetSize()); diff --git a/services/cameraservice/cameraoperator/client/test/sample/dcamera_client_demo.h b/services/cameraservice/cameraoperator/client/test/sample/dcamera_client_demo.h index 3890667b..b8b3ec1d 100644 --- a/services/cameraservice/cameraoperator/client/test/sample/dcamera_client_demo.h +++ b/services/cameraservice/cameraoperator/client/test/sample/dcamera_client_demo.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -68,7 +68,9 @@ public: height_ = buffer->GetHeight(); size_ = buffer->GetSize(); address_ = static_cast(buffer->GetVirAddr()); - buffer->GetExtraData()->ExtraGet("dataSize", dataSize_); + if (buffer->GetExtraData() != nullptr) { + buffer->GetExtraData()->ExtraGet("dataSize", dataSize_); + } #ifdef DCAMERA_YUV actualSize_ = width_ * height_ * YUV_BYTES_PER_PIXEL / Y2UV_RATIO; diff --git a/services/cameraservice/cameraoperator/client/test/sample/main.cpp b/services/cameraservice/cameraoperator/client/test/sample/main.cpp index cc24fdfb..89b38dd1 100644 --- a/services/cameraservice/cameraoperator/client/test/sample/main.cpp +++ b/services/cameraservice/cameraoperator/client/test/sample/main.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -66,7 +66,7 @@ static int32_t InitCameraStandard() g_cameraManager->SetCallback(std::make_shared()); int rv = g_cameraManager->CreateCaptureSession(&g_captureSession); - if (rv != DCAMERA_OK) { + if (rv != DCAMERA_OK || g_captureSession == nullptr) { DHLOGE("InitCameraStandard create captureSession failed, rv: %{public}d", rv); return rv; } @@ -76,6 +76,9 @@ static int32_t InitCameraStandard() std::vector> cameraObjList = g_cameraManager->GetSupportedCameras(); for (auto info : cameraObjList) { + if (info == nullptr) { + continue; + } DHLOGI("Camera: %{public}s, position: %{public}d, camera type: %{public}d, connection type: %{public}d", GetAnonyString(info->GetID()).c_str(), info->GetPosition(), info->GetCameraType(), info->GetConnectionType()); @@ -150,17 +153,29 @@ static CameraFormat ConvertToCameraFormat(int32_t format) static void InitPhotoOutput() { + if (g_photoInfo == nullptr) { + DHLOGE("g_photoInfo is null"); + return; + } DHLOGI("Distributed Camera Demo: Create PhotoOutput, width = %{public}d, height = %{public}d, format = %{public}d", g_photoInfo->width_, g_photoInfo->height_, g_photoInfo->format_); sptr photoSurface = IConsumerSurface::Create(); + if (photoSurface == nullptr) { + DHLOGE("photoSurface is null"); + return; + } sptr photoListener(new DemoDCameraPhotoSurfaceListener(photoSurface)); photoSurface->RegisterConsumerListener(photoListener); CameraFormat photoFormat = ConvertToCameraFormat(g_photoInfo->format_); Size photoSize = {g_photoInfo->width_, g_photoInfo->height_}; Profile photoProfile(photoFormat, photoSize); sptr photoProducer = photoSurface->GetProducer(); + if (g_cameraManager == nullptr) { + DHLOGE("cameraManager is null"); + return; + } int rv = g_cameraManager->CreatePhotoOutput(photoProfile, photoProducer, &((sptr &)g_photoOutput)); - if (rv != DCAMERA_OK) { + if (rv != DCAMERA_OK || g_photoOutput == nullptr) { DHLOGE("InitPhotoOutput create photoOutput failed, rv: %{public}d", rv); return; } @@ -169,9 +184,17 @@ static void InitPhotoOutput() static void InitPreviewOutput() { + if (g_previewInfo == nullptr) { + DHLOGE("g_previewInfo is null"); + return; + } DHLOGI("Distributed Camera Demo: Create PreviewOutput, width = %{public}d, height = %{public}d, format = " "%{public}d", g_previewInfo->width_, g_previewInfo->height_, g_previewInfo->format_); sptr previewSurface = IConsumerSurface::Create(); + if (previewSurface == nullptr) { + DHLOGE("previewSurface is null"); + return; + } sptr previewListener(new DemoDCameraPreviewSurfaceListener(previewSurface)); previewSurface->RegisterConsumerListener(previewListener); CameraFormat previewFormat = ConvertToCameraFormat(g_previewInfo->format_); @@ -179,9 +202,13 @@ static void InitPreviewOutput() Profile previewProfile(previewFormat, previewSize); sptr previewProducer = previewSurface->GetProducer(); sptr previewProducerSurface = Surface::CreateSurfaceAsProducer(previewProducer); + if (previewProducerSurface == nullptr) { + DHLOGE("previewProducerSurface is null"); + return; + } int rv = g_cameraManager->CreatePreviewOutput( previewProfile, previewProducerSurface, &((sptr &)g_previewOutput)); - if (rv != DCAMERA_OK) { + if (rv != DCAMERA_OK || g_previewOutput == nullptr) { DHLOGE("InitPhotoOutput create previewOutput failed, rv: %{public}d", rv); return; } @@ -190,9 +217,17 @@ static void InitPreviewOutput() static void InitVideoOutput() { + if (g_videoInfo == nullptr) { + DHLOGE("g_videoInfo is null"); + return; + } DHLOGI("Distributed Camera Demo: Create VideoOutput, width = %{public}d, height = %{public}d, format = %{public}d", g_videoInfo->width_, g_videoInfo->height_, g_videoInfo->format_); sptr videoSurface = IConsumerSurface::Create(); + if (videoSurface == nullptr) { + DHLOGE("videoSurface is null"); + return; + } sptr videoListener(new DemoDCameraVideoSurfaceListener(videoSurface)); videoSurface->RegisterConsumerListener(videoListener); CameraFormat videoFormat = ConvertToCameraFormat(g_videoInfo->format_); @@ -201,8 +236,12 @@ static void InitVideoOutput() VideoProfile videoSettings(videoFormat, videoSize, framerates); sptr videoProducer = videoSurface->GetProducer(); sptr pSurface = Surface::CreateSurfaceAsProducer(videoProducer); + if (g_cameraManager == nullptr) { + DHLOGE("g_cameraManager is null"); + return; + } int rv = g_cameraManager->CreateVideoOutput(videoSettings, pSurface, &((sptr &)g_videoOutput)); - if (rv != DCAMERA_OK) { + if (rv != DCAMERA_OK || g_videoOutput == nullptr) { DHLOGE("InitPhotoOutput create videoOutput failed, rv: %{public}d", rv); return; } @@ -211,6 +250,10 @@ static void InitVideoOutput() static void ConfigCaptureSession() { + if (g_captureSession == nullptr) { + DHLOGE("Sapture session is null."); + return; + } g_captureSession->BeginConfig(); g_captureSession->AddInput(g_cameraInput); g_captureSession->AddOutput(g_previewOutput); @@ -234,6 +277,10 @@ static void ConfigCaptureSession() static void ConfigFocusAndExposure() { + if (g_captureSession == nullptr) { + DHLOGE("Sapture session is null."); + return; + } g_captureSession->LockForControl(); FocusMode focusMode = FOCUS_MODE_CONTINUOUS_AUTO; ExposureMode exposureMode = EXPOSURE_MODE_AUTO; @@ -308,10 +355,10 @@ int main() InitPreviewOutput(); InitVideoOutput(); ConfigCaptureSession(); - + CHECK_AND_RETURN_RET_LOG((g_captureSession == nullptr), DCAMERA_BAD_VALUE, "Sapture session is null."); g_captureSession->Start(); sleep(SLEEP_FIVE_SECOND); - + CHECK_AND_RETURN_RET_LOG((g_videoOutput == nullptr), DCAMERA_BAD_VALUE, "video output is null."); if (((sptr &)g_videoOutput)->Start() != DCAMERA_OK) { DHLOGE("main g_videoOutput Start failed"); } diff --git a/services/cameraservice/cameraoperator/client/test/unittest/common/cameraoperator/dcamera_client_test.cpp b/services/cameraservice/cameraoperator/client/test/unittest/common/cameraoperator/dcamera_client_test.cpp index fe8ddc19..8336c5a0 100644 --- a/services/cameraservice/cameraoperator/client/test/unittest/common/cameraoperator/dcamera_client_test.cpp +++ b/services/cameraservice/cameraoperator/client/test/unittest/common/cameraoperator/dcamera_client_test.cpp @@ -47,6 +47,10 @@ class DCameraClientTestStateCallback : public StateCallback { public: void OnStateChanged(std::shared_ptr& event) override { + if (event == nullptr) { + DHLOGE("event is null."); + return; + } DHLOGI("DCameraClientTestStateCallback::OnStateChanged type: %{public}d, result: %{public}d", event->eventType_, event->eventResult_); } @@ -196,6 +200,10 @@ void DCameraClientTest::SetTokenID() void DCameraClientTest::SetCaptureInfo(std::shared_ptr& info) { + if (info == nullptr) { + DHLOGE("Camera info is null."); + return; + } auto metaData = std::make_shared(ENTRY_CAPACITY, DATA_CAPACITY); int32_t orientation = OHOS_CAMERA_JPEG_ROTATION_180; metaData->addEntry(OHOS_JPEG_ORIENTATION, &orientation, sizeof(orientation)); @@ -279,7 +287,7 @@ HWTEST_F(DCameraClientTest, dcamera_client_test_001, TestSize.Level1) videoCallback = std::make_shared(stateCallback); videoCallback->OnError(0); - + EXPECT_NE(nullptr, client_); int32_t ret = client_->SetStateCallback(stateCallback); EXPECT_EQ(DCAMERA_OK, ret); @@ -304,6 +312,7 @@ HWTEST_F(DCameraClientTest, dcamera_client_test_002, TestSize.Level1) photoSurfaceListener = std::make_shared(nullptr, resultCallback); photoSurfaceListener->OnBufferAvailable(); + EXPECT_NE(nullptr, client_); int32_t ret = client_->SetResultCallback(resultCallback); EXPECT_EQ(DCAMERA_OK, ret); @@ -322,6 +331,7 @@ HWTEST_F(DCameraClientTest, dcamera_client_test_003, TestSize.Level1) { DHLOGI("DCameraClientTest dcamera_client_test_003: test init and release client"); std::shared_ptr stateCallback = std::make_shared(); + EXPECT_NE(nullptr, client_); int32_t ret = client_->SetStateCallback(stateCallback); EXPECT_EQ(DCAMERA_OK, ret); @@ -346,6 +356,7 @@ HWTEST_F(DCameraClientTest, dcamera_client_test_004, TestSize.Level1) { DHLOGI("DCameraClientTest dcamera_client_test_004: test startCapture and stopCapture"); std::shared_ptr stateCallback = std::make_shared(); + EXPECT_NE(nullptr, client_); int32_t ret = client_->SetStateCallback(stateCallback); EXPECT_EQ(DCAMERA_OK, ret); @@ -354,12 +365,14 @@ HWTEST_F(DCameraClientTest, dcamera_client_test_004, TestSize.Level1) EXPECT_EQ(DCAMERA_OK, ret); sptr videoSurface = IConsumerSurface::Create(); + EXPECT_NE(nullptr, videoSurface); sptr videoListener(new DCameraClientTestVideoSurfaceListener()); videoSurface->RegisterConsumerListener(videoListener); ret = client_->Init(); EXPECT_EQ(DCAMERA_OK, ret); SetTokenID(); + EXPECT_NE(nullptr, videoInfo_true_); DHLOGI("DCameraClientTest dcamera_client_test_004: video width: %{public}d, height: %{public}d, format: %{public}d," " isCapture: %{public}d", videoInfo_true_->width_, videoInfo_true_->height_, videoInfo_true_->format_, videoInfo_true_->isCapture_); @@ -406,6 +419,7 @@ HWTEST_F(DCameraClientTest, dcamera_client_test_005, TestSize.Level1) { DHLOGI("DCameraClientTest dcamera_client_test_005: test startCapture and stopCapture"); std::shared_ptr stateCallback = std::make_shared(); + EXPECT_NE(nullptr, client_); int32_t ret = client_->SetStateCallback(stateCallback); EXPECT_EQ(DCAMERA_OK, ret); @@ -414,6 +428,7 @@ HWTEST_F(DCameraClientTest, dcamera_client_test_005, TestSize.Level1) EXPECT_EQ(DCAMERA_OK, ret); sptr videoSurface = IConsumerSurface::Create(); + EXPECT_NE(nullptr, videoSurface); sptr videoListener(new DCameraClientTestVideoSurfaceListener()); videoSurface->RegisterConsumerListener(videoListener); ret = client_->Init(); @@ -470,6 +485,7 @@ HWTEST_F(DCameraClientTest, dcamera_client_test_006, TestSize.Level1) setting->type_ = ENABLE_METADATA; setting->value_ = ""; settings.push_back(setting); + EXPECT_NE(nullptr, client_); int32_t ret = client_->UpdateSettings(settings); EXPECT_EQ(DCAMERA_OK, ret); } @@ -500,6 +516,7 @@ HWTEST_F(DCameraClientTest, dcamera_client_test_007, TestSize.Level1) setting->value_ = Base64Encode(reinterpret_cast(abilityString.c_str()), abilityString.length()); settings.push_back(setting); + EXPECT_NE(nullptr, client_); int32_t ret = client_->UpdateSettings(settings); EXPECT_EQ(DCAMERA_OK, ret); } @@ -521,6 +538,7 @@ HWTEST_F(DCameraClientTest, dcamera_client_test_008, TestSize.Level1) setting->value_ = Base64Encode(reinterpret_cast(abilityString.c_str()), abilityString.length()); settings.push_back(setting); + EXPECT_NE(nullptr, client_); int32_t ret = client_->UpdateSettings(settings); EXPECT_EQ(DCAMERA_OK, ret); } @@ -534,6 +552,7 @@ HWTEST_F(DCameraClientTest, dcamera_client_test_008, TestSize.Level1) HWTEST_F(DCameraClientTest, dcamera_client_test_009, TestSize.Level1) { DHLOGI("DCameraClientTest dcamera_client_test_009: test cameraServiceErrorType"); + EXPECT_NE(nullptr, client_); int32_t ret = client_->CameraServiceErrorType(CameraStandard::CamServiceError::CAMERA_OK); EXPECT_EQ(DCAMERA_OK, ret); @@ -553,6 +572,7 @@ HWTEST_F(DCameraClientTest, dcamera_client_test_009, TestSize.Level1) HWTEST_F(DCameraClientTest, dcamera_client_test_010, TestSize.Level1) { DHLOGI("DCameraClientTest dcamera_client_test_010: test createCaptureOutput"); + EXPECT_NE(nullptr, client_); std::vector> captureInfos; int32_t ret = client_->CreateCaptureOutput(captureInfos); EXPECT_EQ(DCAMERA_BAD_VALUE, ret); @@ -574,6 +594,7 @@ HWTEST_F(DCameraClientTest, dcamera_client_test_010, TestSize.Level1) HWTEST_F(DCameraClientTest, dcamera_client_test_011, TestSize.Level1) { DHLOGI("DCameraClientTest dcamera_client_test_011: test convertToCameraFormat"); + EXPECT_NE(nullptr, client_); CameraStandard::CameraFormat ret = client_->ConvertToCameraFormat(OHOS_CAMERA_FORMAT_INVALID); EXPECT_EQ(CameraStandard::CameraFormat::CAMERA_FORMAT_INVALID, ret); @@ -599,6 +620,7 @@ HWTEST_F(DCameraClientTest, dcamera_client_test_011, TestSize.Level1) HWTEST_F(DCameraClientTest, dcamera_client_test_013, TestSize.Level1) { DHLOGI("DCameraClientTest dcamera_client_test_013: test startPhotoOutput"); + EXPECT_NE(nullptr, client_); std::shared_ptr stateCallback = std::make_shared(); int32_t ret = client_->SetStateCallback(stateCallback); EXPECT_EQ(DCAMERA_OK, ret); @@ -608,6 +630,7 @@ HWTEST_F(DCameraClientTest, dcamera_client_test_013, TestSize.Level1) EXPECT_EQ(DCAMERA_OK, ret); sptr videoSurface = IConsumerSurface::Create(); + EXPECT_NE(nullptr, videoSurface); sptr videoListener(new DCameraClientTestVideoSurfaceListener()); videoSurface->RegisterConsumerListener(videoListener); ret = client_->Init(); @@ -654,6 +677,7 @@ HWTEST_F(DCameraClientTest, dcamera_client_test_014, TestSize.Level1) DHLOGI("DCameraClientTest dcamera_client_test_014: test startCapture"); std::vector> captureInfos; sptr surface = nullptr; + EXPECT_NE(nullptr, client_); int32_t ret = client_->StartCapture(captureInfos, surface); EXPECT_EQ(DCAMERA_BAD_VALUE, ret); } @@ -670,6 +694,7 @@ HWTEST_F(DCameraClientTest, dcamera_client_test_015, TestSize.Level1) int32_t invalidParam = 2; auto info = std::make_shared(); info->streamType_ = static_cast(invalidParam); + EXPECT_NE(nullptr, client_); int32_t ret = client_->StartCaptureInner(info); EXPECT_EQ(DCAMERA_BAD_VALUE, ret); } @@ -683,6 +708,7 @@ HWTEST_F(DCameraClientTest, dcamera_client_test_015, TestSize.Level1) HWTEST_F(DCameraClientTest, dcamera_client_test_016, TestSize.Level1) { DHLOGI("DCameraClientTest dcamera_client_test_016: test PauseCapture"); + EXPECT_NE(nullptr, client_); int32_t ret = client_->PauseCapture(); EXPECT_EQ(DCAMERA_BAD_VALUE, ret); diff --git a/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp b/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp index 5ab748d3..791af073 100644 --- a/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp +++ b/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp @@ -64,6 +64,9 @@ std::vector DCameraHandler::QueryMeta() return itemList; } for (auto& info : cameraList) { + if (info == nullptr) { + continue; + } if (info->GetConnectionType() != CameraStandard::ConnectionType::CAMERA_CONNECTION_BUILT_IN) { DHLOGI("connection type: %{public}d", info->GetConnectionType()); continue; @@ -92,6 +95,9 @@ std::vector DCameraHandler::Query() return itemList; } for (auto& info : cameraList) { + if (info == nullptr) { + continue; + } if ((info->GetConnectionType() != CameraStandard::ConnectionType::CAMERA_CONNECTION_BUILT_IN)) { DHLOGI("connection type: %{public}d", info->GetConnectionType()); continue; @@ -138,6 +144,10 @@ void DCameraHandler::UnRegisterPluginListener() std::vector DCameraHandler::GetCameras() { + if (cameraManager_ == nullptr) { + DHLOGE("cameraManager is null."); + return {}; + } std::vector cameras; std::vector> cameraList = cameraManager_->GetSupportedCameras(); uint64_t listSize = static_cast(cameraList.size()); @@ -147,6 +157,9 @@ std::vector DCameraHandler::GetCameras() return cameras; } for (auto& info : cameraList) { + if (info == nullptr) { + continue; + } sptr capability = cameraManager_->GetSupportedOutputCapability(info); if (capability == nullptr) { DHLOGI("get supported capability is null"); @@ -198,6 +211,7 @@ int32_t DCameraHandler::CreateAVCodecList(cJSON *root) int32_t DCameraHandler::CreateMetaDHItem(sptr& info, DHItem& item) { + CHECK_AND_RETURN_RET_LOG(info == nullptr, DCAMERA_BAD_VALUE, "Camera info is null"); std::string id = info->GetID(); item.dhId = CAMERA_ID_PREFIX + id; item.subtype = "camera"; @@ -219,6 +233,10 @@ int32_t DCameraHandler::CreateMetaDHItem(sptr& inf int32_t DCameraHandler::CreateDHItem(sptr& info, DHItem& item) { + if (info == nullptr || cameraManager_ == nullptr) { + DHLOGE("Camera info or camera manager is nullptr."); + return DCAMERA_BAD_VALUE; + } std::string id = info->GetID(); item.dhId = CAMERA_ID_PREFIX + id; item.subtype = "camera"; diff --git a/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_service.cpp b/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_service.cpp index 8f97f2ac..a538b79f 100644 --- a/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_service.cpp +++ b/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_service.cpp @@ -109,8 +109,10 @@ int32_t DistributedCameraSinkService::ReleaseSink() std::lock_guard lock(mapMutex_); for (auto iter = camerasMap_.begin(); iter != camerasMap_.end(); iter++) { std::shared_ptr sinkDevice = iter->second; - int32_t ret = sinkDevice->UnInit(); - CHECK_AND_LOG(ret != DCAMERA_OK, "release sink device failed, ret: %{public}d", ret); + if (sinkDevice != nullptr) { + int32_t ret = sinkDevice->UnInit(); + CHECK_AND_LOG(ret != DCAMERA_OK, "release sink device failed, ret: %{public}d", ret); + } } camerasMap_.clear(); } @@ -137,7 +139,7 @@ int32_t DistributedCameraSinkService::SubscribeLocalHardware(const std::string& } sinkDevice = iter->second; } - + CHECK_AND_RETURN_RET_LOG(sinkDevice== nullptr, DCAMERA_BAD_VALUE, "Sink device is null"); int32_t ret = sinkDevice->SubscribeLocalHardware(parameters); CHECK_AND_RETURN_RET_LOG(ret != DCAMERA_OK, ret, "SubscribeLocalHardware failed, ret: %{public}d", ret); DHLOGI("SubscribeLocalHardware success"); @@ -157,7 +159,7 @@ int32_t DistributedCameraSinkService::UnsubscribeLocalHardware(const std::string } sinkDevice = iter->second; } - + CHECK_AND_RETURN_RET_LOG(sinkDevice== nullptr, DCAMERA_BAD_VALUE, "Sink device is null"); int32_t ret = sinkDevice->UnsubscribeLocalHardware(); CHECK_AND_RETURN_RET_LOG(ret != DCAMERA_OK, ret, "UnsubscribeLocalHardware failed, ret: %{public}d", ret); DHLOGI("UnsubscribeLocalHardware success"); @@ -177,7 +179,7 @@ int32_t DistributedCameraSinkService::StopCapture(const std::string& dhId) } sinkDevice = iter->second; } - + CHECK_AND_RETURN_RET_LOG(sinkDevice== nullptr, DCAMERA_BAD_VALUE, "Sink device is null"); int32_t ret = sinkDevice->StopCapture(); CHECK_AND_RETURN_RET_LOG(ret != DCAMERA_OK, ret, "StopCapture failed, ret: %{public}d", ret); DHLOGI("StopCapture success"); @@ -197,7 +199,7 @@ int32_t DistributedCameraSinkService::ChannelNeg(const std::string& dhId, std::s } sinkDevice = iter->second; } - + CHECK_AND_RETURN_RET_LOG(sinkDevice== nullptr, DCAMERA_BAD_VALUE, "Sink device is null"); int32_t ret = sinkDevice->ChannelNeg(channelInfo); CHECK_AND_RETURN_RET_LOG(ret != DCAMERA_OK, ret, "ChannelNeg failed, ret: %{public}d", ret); DHLOGI("ChannelNeg success"); @@ -217,7 +219,7 @@ int32_t DistributedCameraSinkService::GetCameraInfo(const std::string& dhId, std } sinkDevice = iter->second; } - + CHECK_AND_RETURN_RET_LOG(sinkDevice== nullptr, DCAMERA_BAD_VALUE, "Sink device is null"); int32_t ret = sinkDevice->GetCameraInfo(cameraInfo); CHECK_AND_RETURN_RET_LOG(ret != DCAMERA_OK, ret, "GetCameraInfo failed, ret: %{public}d", ret); DHLOGI("GetCameraInfo success"); @@ -237,7 +239,7 @@ int32_t DistributedCameraSinkService::OpenChannel(const std::string& dhId, std:: } sinkDevice = iter->second; } - + CHECK_AND_RETURN_RET_LOG(sinkDevice== nullptr, DCAMERA_BAD_VALUE, "Sink device is null"); int32_t ret = sinkDevice->OpenChannel(openInfo); if (ret != DCAMERA_OK) { DHLOGE("OpenChannel failed, ret: %{public}d", ret); @@ -262,7 +264,7 @@ int32_t DistributedCameraSinkService::CloseChannel(const std::string& dhId) } sinkDevice = iter->second; } - + CHECK_AND_RETURN_RET_LOG(sinkDevice== nullptr, DCAMERA_BAD_VALUE, "Sink device is null"); int32_t ret = sinkDevice->CloseChannel(); CHECK_AND_RETURN_RET_LOG(ret != DCAMERA_OK, ret, "CloseChannel failed, ret: %{public}d", ret); DHLOGI("CloseChannel success"); @@ -299,6 +301,9 @@ void DistributedCameraSinkService::GetCamIds() { std::lock_guard lock(mapMutex_); for (auto it = camerasMap_.begin(); it != camerasMap_.end(); it++) { + if (it->second == nullptr) { + continue; + } camIds.push_back(it->second->GetDhid()); } } @@ -307,6 +312,9 @@ void DistributedCameraSinkService::GetCamIds() void DistributedCameraSinkService::GetCamDumpInfo(CameraDumpInfo& camDump) { + if (dcSinkService == nullptr) { + return; + } dcSinkService->GetCamIds(); camDump = g_camDump; } @@ -321,6 +329,7 @@ bool DistributedCameraSinkService::IsCurSinkDev(std::shared_ptr ret = cmd.Unmarshal(camInfoJson); CHECK_AND_RETURN_RET_LOG(ret != DCAMERA_OK, false, "DCameraInfoCmd Unmarshal failed: %{public}d", ret); std::shared_ptr camInfo = cmd.value_; + CHECK_AND_RETURN_RET_LOG(camInfo == nullptr, false, "Camera info is null"); if (camInfo->state_ == DCAMERA_CHANNEL_STATE_CONNECTED) { return true; } diff --git a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_controller.cpp b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_controller.cpp index c94d88ea..baa92f16 100644 --- a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_controller.cpp +++ b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_controller.cpp @@ -195,6 +195,7 @@ int32_t DCameraSinkController::UpdateSettings(std::vector& camInfo) { DHLOGI("GetCameraInfo dhId: %{public}s, session state: %{public}d", GetAnonyString(dhId_).c_str(), sessionState_); + CHECK_AND_RETURN_RET_LOG(camInfo == nullptr, DCAMERA_BAD_VALUE, "Camera info is null"); camInfo->state_ = sessionState_; return DCAMERA_OK; } @@ -206,6 +207,7 @@ int32_t DCameraSinkController::OpenChannel(std::shared_ptr& ope DHLOGE("DCameraSinkController OpenChannel fail, CheckPermission fail"); return DCAMERA_WRONG_STATE; } + CHECK_AND_RETURN_RET_LOG(openInfo == nullptr, DCAMERA_BAD_VALUE, "Open info is null"); if (sessionState_ != DCAMERA_CHANNEL_STATE_DISCONNECTED) { DHLOGE("wrong state, dhId: %{public}s, sessionState: %{public}d", GetAnonyString(dhId_).c_str(), sessionState_); return DCAMERA_WRONG_STATE; @@ -235,6 +237,7 @@ int32_t DCameraSinkController::OpenChannel(std::shared_ptr& ope auto controller = std::shared_ptr(shared_from_this()); std::shared_ptr listener = std::make_shared(controller); + CHECK_AND_RETURN_RET_LOG(channel_ == nullptr, DCAMERA_BAD_VALUE, "Camera channel is null"); ret = channel_->CreateSession(indexs, SESSION_FLAG, DCAMERA_SESSION_MODE_CTRL, listener); if (ret != DCAMERA_OK) { DHLOGE("channel create session failed, dhId: %{public}s, ret: %{public}d", GetAnonyString(dhId_).c_str(), ret); @@ -251,6 +254,7 @@ int32_t DCameraSinkController::PullUpPage() if (isSensitive_) { bool isSensitive = false; bool isSameAccout = false; + CHECK_AND_RETURN_RET_LOG(sinkCallback_ == nullptr, DCAMERA_BAD_VALUE, "Sink callback is null"); int32_t ret = sinkCallback_->OnNotifyResourceInfo(ResourceEventType::EVENT_TYPE_PULL_UP_PAGE, PAGE_SUBTYPE, srcDevId_, isSensitive, isSameAccout); if (ret != DCAMERA_OK) { @@ -277,20 +281,23 @@ int32_t DCameraSinkController::CloseChannel() DHLOGE("DCameraSinkController release channel failed, dhId: %{public}s, ret: %{public}d", GetAnonyString(dhId_).c_str(), ret); } - - ret = output_->CloseChannel(); - if (ret != DCAMERA_OK) { - DHLOGE("DCameraSinkController CloseChannel failed, dhId: %{public}s, ret: %{public}d", - GetAnonyString(dhId_).c_str(), ret); + if (output_ != nullptr) { + ret = output_->CloseChannel(); + if (ret != DCAMERA_OK) { + DHLOGE("DCameraSinkController CloseChannel failed, dhId: %{public}s, ret: %{public}d", + GetAnonyString(dhId_).c_str(), ret); + } } sessionState_ = DCAMERA_CHANNEL_STATE_DISCONNECTED; if (isPageStatus_.load()) { bool isSensitive = false; bool isSameAccout = false; - ret = sinkCallback_->OnNotifyResourceInfo(ResourceEventType::EVENT_TYPE_CLOSE_PAGE, PAGE_SUBTYPE, srcDevId_, - isSensitive, isSameAccout); - if (ret != DCAMERA_OK) { - DHLOGE("close page failed, ret: %{public}d", ret); + if (sinkCallback_ != nullptr) { + ret = sinkCallback_->OnNotifyResourceInfo(ResourceEventType::EVENT_TYPE_CLOSE_PAGE, PAGE_SUBTYPE, + srcDevId_, isSensitive, isSameAccout); + if (ret != DCAMERA_OK) { + DHLOGE("close page failed, ret: %{public}d", ret); + } } } isPageStatus_.store(false); @@ -398,6 +405,10 @@ void DCameraSinkController::DCameraSinkContrEventHandler::ProcessEvent(const App void DCameraSinkController::ProcessFrameTrigger(const AppExecFwk::InnerEvent::Pointer &event) { DHLOGD("Receive frame trigger event then start process data in sink controller."); + if (accessControl_ == nullptr) { + DHLOGD("access controller is null."); + return; + } std::shared_ptr param = event->GetSharedObject(); accessControl_->TriggerFrame(*param); } @@ -412,6 +423,10 @@ void DCameraSinkController::ProcessPostAuthorization(const AppExecFwk::InnerEven void DCameraSinkController::OnStateChanged(std::shared_ptr& event) { + if (event == nullptr) { + DHLOGE("event is null."); + return; + } DHLOGI("DCameraSinkController::OnStateChanged dhId: %{public}s, result: %{public}d", GetAnonyString(dhId_).c_str(), event->eventResult_); if (event->eventResult_ == DCAMERA_EVENT_DEVICE_PREEMPT) { @@ -447,6 +462,10 @@ void DCameraSinkController::OnMetadataResult(std::vectorSendData(buffer); if (ret != DCAMERA_OK) { DHLOGE("channel send data failed, dhId: %{public}s ret: %{public}d", GetAnonyString(dhId_).c_str(), ret); @@ -502,6 +521,9 @@ void DCameraSinkController::OnDataReceived(std::vectorSize() <= 0 || buffer->Size() > DATABUFF_MAX_SIZE) { DHLOGI("buffer is invalid"); return; @@ -514,7 +536,7 @@ void DCameraSinkController::PostAuthorization(std::vectorNotifySensitiveSrc(SRC_TYPE); } } @@ -523,6 +545,7 @@ int32_t DCameraSinkController::StartCaptureInner(std::vector autoLock(captureLock_); + CHECK_AND_RETURN_RET_LOG(output_ == nullptr, DCAMERA_BAD_VALUE, "output is null"); int32_t ret = output_->StartCapture(captureInfos); if (ret != DCAMERA_OK) { DHLOGE("output start capture failed, dhId: %{public}s, ret: %{public}d", GetAnonyString(dhId_).c_str(), ret); @@ -535,6 +558,7 @@ int32_t DCameraSinkController::StartCaptureInner(std::vectorStartCapture(captureInfos, carrier.surface_); if (ret != DCAMERA_OK) { DHLOGE("camera client start capture failed, dhId: %{public}s, ret: %{public}d", @@ -566,6 +590,7 @@ int32_t DCameraSinkController::DCameraNotifyInner(int32_t type, int32_t result, int32_t DCameraSinkController::HandleReceivedData(std::shared_ptr& dataBuffer) { DHLOGI("DCameraSinkController::HandleReceivedData dhId: %{public}s", GetAnonyString(dhId_).c_str()); + CHECK_AND_RETURN_RET_LOG(dataBuffer == nullptr, DCAMERA_BAD_VALUE, "Data buffer is null"); uint8_t *data = dataBuffer->Data(); std::string jsonStr(reinterpret_cast(data), dataBuffer->Capacity()); cJSON *rootValue = cJSON_Parse(jsonStr.c_str()); diff --git a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_data_process.cpp b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_data_process.cpp index 5e588116..636052f9 100644 --- a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_data_process.cpp +++ b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_data_process.cpp @@ -70,6 +70,7 @@ void DCameraSinkDataProcess::StartEventHandler() int32_t DCameraSinkDataProcess::StartCapture(std::shared_ptr& captureInfo) { + CHECK_AND_RETURN_RET_LOG(captureInfo == nullptr, DCAMERA_BAD_VALUE, "Capture info is null"); DHLOGI("StartCapture dhId: %{public}s, width: %{public}d, height: %{public}d, format: %{public}d, stream: " "%{public}d, encode: %{public}d", GetAnonyString(dhId_).c_str(), captureInfo->width_, captureInfo->height_, captureInfo->format_, captureInfo->streamType_, captureInfo->encodeType_); @@ -150,6 +151,10 @@ void DCameraSinkDataProcess::SendDataAsync(const std::shared_ptr& bu { auto sendFunc = [this, buffer]() mutable { std::shared_ptr sendBuffer = buffer; + if (buffer == nullptr || channel_ == nullptr || captureInfo_ == nullptr) { + DHLOGE("Existing null pointer."); + return; + } int32_t ret = channel_->SendData(sendBuffer); uint64_t buffersSize = static_cast(buffer->Size()); DHLOGD("SendData type: %{public}d output data ret: %{public}d, dhId: %{public}s, bufferSize: %{public}" PRIu64, diff --git a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_output.cpp b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_output.cpp index e3efaca1..ee915772 100644 --- a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_output.cpp +++ b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_output.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 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 @@ -46,6 +46,7 @@ int32_t DCameraSinkOutput::Init() DHLOGI("Init dhId: %{public}s", GetAnonyString(dhId_).c_str()); auto output = std::shared_ptr(shared_from_this()); std::shared_ptr resultCallback = std::make_shared(output); + CHECK_AND_RETURN_RET_LOG(operator_ == nullptr, DCAMERA_BAD_VALUE, "Operator is null"); operator_->SetResultCallback(resultCallback); InitInner(CONTINUOUS_FRAME); @@ -78,6 +79,7 @@ int32_t DCameraSinkOutput::UnInit() int32_t DCameraSinkOutput::OpenChannel(std::shared_ptr& info) { + CHECK_AND_RETURN_RET_LOG(info == nullptr, DCAMERA_BAD_VALUE, "Camera info is null"); DHLOGI("OpenChannel dhId: %{public}s", GetAnonyString(dhId_).c_str()); std::map modeMaps; modeMaps.emplace(CONTINUOUS_FRAME, DCAMERA_SESSION_MODE_VIDEO); @@ -113,23 +115,27 @@ int32_t DCameraSinkOutput::CloseChannel() auto iterCon = channels_.find(CONTINUOUS_FRAME); if (iterCon != channels_.end()) { int32_t ret = DCAMERA_OK; - ret = iterCon->second->ReleaseSession(); - if (ret != DCAMERA_OK) { - DHLOGI("DCameraSinkOutput UnInit release continue session failed, dhId: %{public}s, ret: %{public}d", - GetAnonyString(dhId_).c_str(), ret); + if (iterCon->second != nullptr) { + ret = iterCon->second->ReleaseSession(); + if (ret != DCAMERA_OK) { + DHLOGE("Release continue session failed, dhId: %{public}s, ret: %{public}d", + GetAnonyString(dhId_).c_str(), ret); + } + sessionState_[CONTINUOUS_FRAME] = DCAMERA_CHANNEL_STATE_DISCONNECTED; } - sessionState_[CONTINUOUS_FRAME] = DCAMERA_CHANNEL_STATE_DISCONNECTED; } auto iterSnap = channels_.find(SNAPSHOT_FRAME); if (iterSnap != channels_.end()) { int32_t ret = DCAMERA_OK; - ret = iterSnap->second->ReleaseSession(); - if (ret != DCAMERA_OK) { - DHLOGI("DCameraSinkOutput UnInit release snapshot session failed, dhId: %{public}s, ret: %{public}d", - GetAnonyString(dhId_).c_str(), ret); + if (iterSnap->second != nullptr) { + ret = iterSnap->second->ReleaseSession(); + if (ret != DCAMERA_OK) { + DHLOGI("Release snapshot session failed, dhId: %{public}s, ret: %{public}d", + GetAnonyString(dhId_).c_str(), ret); + } + sessionState_[SNAPSHOT_FRAME] = DCAMERA_CHANNEL_STATE_DISCONNECTED; } - sessionState_[SNAPSHOT_FRAME] = DCAMERA_CHANNEL_STATE_DISCONNECTED; } return DCAMERA_OK; } @@ -157,20 +163,24 @@ int32_t DCameraSinkOutput::StopCapture() auto iterCon = dataProcesses_.find(CONTINUOUS_FRAME); if (iterCon != dataProcesses_.end()) { DHLOGI("StopCapture %{public}s continuous frame stop capture", GetAnonyString(dhId_).c_str()); - int32_t ret = iterCon->second->StopCapture(); - if (ret != DCAMERA_OK) { - DHLOGE("continuous data process stop capture failed, dhId: %{public}s, ret: %{public}d", - GetAnonyString(dhId_).c_str(), ret); + if (iterCon->second != nullptr) { + int32_t ret = iterCon->second->StopCapture(); + if (ret != DCAMERA_OK) { + DHLOGE("continuous data process stop capture failed, dhId: %{public}s, ret: %{public}d", + GetAnonyString(dhId_).c_str(), ret); + } } } auto iterSnap = dataProcesses_.find(SNAPSHOT_FRAME); if (iterSnap != dataProcesses_.end()) { DHLOGI("StopCapture %{public}s snapshot frame stop capture", GetAnonyString(dhId_).c_str()); - int32_t ret = iterSnap->second->StopCapture(); - if (ret != DCAMERA_OK) { - DHLOGE("snapshot data process stop capture failed, dhId: %{public}s, ret: %{public}d", - GetAnonyString(dhId_).c_str(), ret); + if (iterSnap->second != nullptr) { + int32_t ret = iterSnap->second->StopCapture(); + if (ret != DCAMERA_OK) { + DHLOGE("snapshot data process stop capture failed, dhId: %{public}s, ret: %{public}d", + GetAnonyString(dhId_).c_str(), ret); + } } } DHLOGI("StopCapture %{public}s success", GetAnonyString(dhId_).c_str()); diff --git a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_service_ipc.cpp b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_service_ipc.cpp index 25a286f9..1a703c33 100644 --- a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_service_ipc.cpp +++ b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_service_ipc.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 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 @@ -106,7 +106,9 @@ sptr DCameraSinkServiceIpc::GetSourceRemoteCamSrv(cons std::lock_guard autoLock(sourceRemoteCamSrvLock_); auto iter = remoteSources_.find(deviceId); if (iter != remoteSources_.end()) { - iter->second->AsObject()->RemoveDeathRecipient(sourceRemoteRecipient_); + if (iter->second != nullptr && iter->second->AsObject() != nullptr) { + iter->second->AsObject()->RemoveDeathRecipient(sourceRemoteRecipient_); + } } remoteSources_[deviceId] = remoteCamSrvObj; } diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_access_control_test.cpp b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_access_control_test.cpp index 0458e230..3ec5d0d4 100644 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_access_control_test.cpp +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_access_control_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 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 @@ -65,6 +65,7 @@ void DCameraSinkAccessControlTest::TearDown(void) */ HWTEST_F(DCameraSinkAccessControlTest, dcamera_sink_access_control_test_001, TestSize.Level1) { + EXPECT_EQ(accessControl_ == nullptr, false); bool ret = accessControl_->IsSensitiveSrcAccess(TEST_SRC_TYPE); EXPECT_EQ(true, ret); } @@ -77,6 +78,7 @@ HWTEST_F(DCameraSinkAccessControlTest, dcamera_sink_access_control_test_001, Tes */ HWTEST_F(DCameraSinkAccessControlTest, dcamera_sink_access_control_test_002, TestSize.Level1) { + EXPECT_EQ(accessControl_ == nullptr, false); bool ret = accessControl_->NotifySensitiveSrc(TEST_SRC_TYPE); EXPECT_EQ(true, ret); } @@ -89,6 +91,7 @@ HWTEST_F(DCameraSinkAccessControlTest, dcamera_sink_access_control_test_002, Tes */ HWTEST_F(DCameraSinkAccessControlTest, dcamera_sink_access_control_test_003, TestSize.Level1) { + EXPECT_EQ(accessControl_ == nullptr, false); int32_t ret = accessControl_->GetAccessControlType(TEST_ACCESS_TYPE); EXPECT_EQ(DCAMERA_SAME_ACCOUNT, ret); } @@ -101,6 +104,7 @@ HWTEST_F(DCameraSinkAccessControlTest, dcamera_sink_access_control_test_003, Tes */ HWTEST_F(DCameraSinkAccessControlTest, dcamera_sink_access_control_test_004, TestSize.Level1) { + EXPECT_EQ(accessControl_ == nullptr, false); int32_t ret = accessControl_->TriggerFrame(TEST_DEVICE_NAME); EXPECT_EQ(DCAMERA_OK, ret); } diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_controller_test.cpp b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_controller_test.cpp index a7b0d8e6..1273cf5b 100644 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_controller_test.cpp +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_controller_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 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 @@ -176,6 +176,7 @@ void DCameraSinkControllerTest::SetTokenID() */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_001, TestSize.Level1) { + EXPECT_EQ(controller_ == nullptr, false); int32_t ret = controller_->Init(g_testCamIndex); EXPECT_EQ(DCAMERA_OK, ret); EXPECT_EQ(true, controller_->isInit_); @@ -193,6 +194,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_001, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_002, TestSize.Level1) { + EXPECT_EQ(controller_ == nullptr, false); DCameraInfoCmd cmd; cmd.value_ = std::make_shared(); int32_t ret = controller_->GetCameraInfo(cmd.value_); @@ -208,6 +210,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_002, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_003, TestSize.Level1) { + EXPECT_EQ(controller_ == nullptr, false); DCameraChannelInfoCmd cmd; cmd.Unmarshal(TEST_CHANNEL_INFO_CMD_CONTINUE_JSON); int32_t ret = controller_->ChannelNeg(cmd.value_); @@ -222,6 +225,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_003, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_004, TestSize.Level1) { + EXPECT_EQ(controller_ == nullptr, false); DCameraCaptureInfoCmd cmd; cmd.Unmarshal(TEST_CAPTURE_INFO_CMD_JSON); int32_t ret = controller_->StartCapture(cmd.value_); @@ -236,6 +240,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_004, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_005, TestSize.Level1) { + EXPECT_EQ(controller_ == nullptr, false); SetTokenID(); DCameraCaptureInfoCmd cmd; cmd.Unmarshal(TEST_CAPTURE_INFO_CMD_JSON); @@ -261,6 +266,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_005, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_006, TestSize.Level1) { + EXPECT_EQ(controller_ == nullptr, false); DCameraCaptureInfoCmd cmd; cmd.Unmarshal(TEST_CAPTURE_INFO_CMD_JSON); int32_t ret = controller_->StartCapture(cmd.value_); @@ -278,6 +284,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_006, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_007, TestSize.Level1) { + EXPECT_EQ(controller_ == nullptr, false); controller_->srcDevId_ = TEST_DEVICE_ID_EMPTY; DCameraEventCmd cmd; @@ -294,6 +301,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_007, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_008, TestSize.Level1) { + EXPECT_EQ(controller_ == nullptr, false); DCameraEventCmd cmd; cmd.Unmarshal(TEST_EVENT_CMD_JSON); int32_t ret = controller_->DCameraNotify(cmd.value_); @@ -308,6 +316,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_008, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_009, TestSize.Level1) { + EXPECT_EQ(controller_ == nullptr, false); controller_->OnSessionState(DCAMERA_CHANNEL_STATE_CONNECTING); DCameraInfoCmd cmd; @@ -332,6 +341,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_009, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_010, TestSize.Level1) { + EXPECT_EQ(controller_ == nullptr, false); controller_->OnSessionState(DCAMERA_CHANNEL_STATE_CONNECTED); DCameraInfoCmd cmd; @@ -360,6 +370,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_010, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_011, TestSize.Level1) { + EXPECT_EQ(controller_ == nullptr, false); controller_->OnSessionState(DCAMERA_CHANNEL_STATE_DISCONNECTED); std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS)); @@ -378,6 +389,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_011, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_012, TestSize.Level1) { + EXPECT_EQ(controller_ == nullptr, false); SetTokenID(); DCameraOpenInfoCmd cmd; cmd.Unmarshal(TEST_OPEN_INFO_CMD_JSON); @@ -393,6 +405,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_012, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_013, TestSize.Level1) { + EXPECT_EQ(controller_ == nullptr, false); controller_->OnSessionState(DCAMERA_CHANNEL_STATE_CONNECTED); DCameraInfoCmd cmd; @@ -415,6 +428,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_013, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_014, TestSize.Level1) { + EXPECT_EQ(controller_ == nullptr, false); int32_t ret = controller_->CloseChannel(); EXPECT_EQ(DCAMERA_OK, ret); controller_->isPageStatus_.store(true); @@ -433,6 +447,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_014, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_015, TestSize.Level1) { + EXPECT_EQ(controller_ == nullptr, false); SetTokenID(); DCameraCaptureInfoCmd cmd; cmd.Unmarshal(TEST_CAPTURE_INFO_CMD_JSON); @@ -454,6 +469,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_015, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_016, TestSize.Level1) { + EXPECT_EQ(controller_ == nullptr, false); SetTokenID(); DCameraOpenInfoCmd cmd; cmd.Unmarshal(TEST_OPEN_INFO_CMD_JSON); @@ -470,6 +486,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_016, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_017, TestSize.Level1) { + EXPECT_EQ(controller_ == nullptr, false); g_channelStr = "test017"; int32_t ret = controller_->CloseChannel(); EXPECT_EQ(DCAMERA_OK, ret); @@ -483,6 +500,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_017, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_018, TestSize.Level1) { + EXPECT_EQ(controller_ == nullptr, false); g_outputStr = "test018"; int32_t ret = controller_->CloseChannel(); EXPECT_EQ(DCAMERA_OK, ret); @@ -496,6 +514,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_018, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_019, TestSize.Level1) { + EXPECT_EQ(controller_ == nullptr, false); g_outputStr = "test019"; int32_t ret = controller_->UnInit(); EXPECT_EQ(DCAMERA_OK, ret); @@ -509,6 +528,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_019, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_020, TestSize.Level1) { + EXPECT_EQ(controller_ == nullptr, false); g_operatorStr = "test020"; int32_t ret = controller_->UnInit(); EXPECT_EQ(DCAMERA_OK, ret); @@ -522,6 +542,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_020, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_021, TestSize.Level1) { + EXPECT_EQ(controller_ == nullptr, false); DCameraCaptureInfoCmd cmd; cmd.Unmarshal(TEST_CAPTURE_INFO_CMD_JSON); g_outputStr = "test021"; @@ -537,6 +558,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_021, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_022, TestSize.Level1) { + EXPECT_EQ(controller_ == nullptr, false); DCameraCaptureInfoCmd cmd; cmd.Unmarshal(TEST_CAPTURE_INFO_CMD_JSON); g_outputStr = ""; @@ -553,6 +575,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_022, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_023, TestSize.Level1) { + EXPECT_EQ(controller_ == nullptr, false); DCameraCaptureInfoCmd cmd; cmd.Unmarshal(TEST_CAPTURE_INFO_CMD_JSON); g_operatorStr = "test023"; @@ -568,6 +591,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_023, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_024, TestSize.Level1) { + EXPECT_EQ(controller_ == nullptr, false); g_operatorStr = "test024"; controller_->isSensitive_ = false; int32_t ret = controller_->PullUpPage(); @@ -582,6 +606,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_024, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_025, TestSize.Level1) { + EXPECT_EQ(controller_ == nullptr, false); sptr sinkCallback(new DCameraSinkCallback()); EXPECT_NE(nullptr, sinkCallback); controller_->isSensitive_ = true; @@ -617,6 +642,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_025, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_026, TestSize.Level1) { + EXPECT_EQ(controller_ == nullptr, false); g_outputStr = "test026"; auto outputMock = std::make_shared("camera_1", nullptr); EXPECT_NE(DCAMERA_OK, outputMock->Init()); @@ -633,6 +659,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_026, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_027, TestSize.Level1) { + EXPECT_EQ(controller_ == nullptr, false); g_operatorStr ="test027"; EXPECT_EQ(DCAMERA_OK, controller_->UnInit()); } @@ -645,6 +672,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_027, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_028, TestSize.Level1) { + EXPECT_EQ(controller_ == nullptr, false); size_t capacity = 1; std::shared_ptr dataBuffer = std::make_shared(capacity); EXPECT_EQ(DCAMERA_BAD_VALUE, controller_->HandleReceivedData(dataBuffer)); @@ -658,6 +686,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_028, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_029, TestSize.Level1) { + EXPECT_EQ(controller_ == nullptr, false); std::string netId = ""; EXPECT_EQ(DCAMERA_BAD_VALUE, controller_->PauseDistributedHardware(netId)); netId = "netId"; @@ -677,6 +706,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_029, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_030, TestSize.Level1) { + EXPECT_EQ(controller_ == nullptr, false); std::string netId = ""; EXPECT_EQ(DCAMERA_BAD_VALUE, controller_->ResumeDistributedHardware(netId)); netId = "netId"; @@ -696,6 +726,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_030, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_031, TestSize.Level1) { + EXPECT_EQ(controller_ == nullptr, false); std::string netId = ""; EXPECT_EQ(DCAMERA_BAD_VALUE, controller_->StopDistributedHardware(netId)); netId = "netId"; @@ -710,6 +741,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_031, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_032, TestSize.Level1) { + EXPECT_EQ(controller_ == nullptr, false); std::string srcNetId = ""; std::string dstNetId = ""; EXPECT_NE(true, controller_->CheckDeviceSecurityLevel(srcNetId, dstNetId)); @@ -723,6 +755,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_032, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_033, TestSize.Level1) { + EXPECT_EQ(controller_ == nullptr, false); std::string udId = ""; EXPECT_NE(DCAMERA_OK, controller_->GetDeviceSecurityLevel(udId)); } @@ -735,6 +768,7 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_033, TestSize.L */ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_034, TestSize.Level1) { + EXPECT_EQ(controller_ == nullptr, false); std::string netId = ""; EXPECT_EQ("", controller_->GetUdidByNetworkId(netId)); netId = "netId"; diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_data_process_test.cpp b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_data_process_test.cpp index 8a765334..e270bc9b 100644 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_data_process_test.cpp +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_data_process_test.cpp @@ -126,6 +126,7 @@ void DCameraSinkDataProcessTest::TearDown(void) */ HWTEST_F(DCameraSinkDataProcessTest, dcamera_sink_data_process_test_001, TestSize.Level1) { + EXPECT_EQ(dataProcess_ == nullptr, false); int32_t ret = dataProcess_->StartCapture(g_testCaptureInfoContinuousNotEncode); EXPECT_EQ(DCAMERA_OK, ret); } @@ -138,6 +139,7 @@ HWTEST_F(DCameraSinkDataProcessTest, dcamera_sink_data_process_test_001, TestSiz */ HWTEST_F(DCameraSinkDataProcessTest, dcamera_sink_data_process_test_002, TestSize.Level1) { + EXPECT_EQ(dataProcess_ == nullptr, false); int32_t ret = dataProcess_->StartCapture(g_testCaptureInfoContinuousNeedEncode); EXPECT_EQ(DCAMERA_OK, ret); } @@ -150,6 +152,7 @@ HWTEST_F(DCameraSinkDataProcessTest, dcamera_sink_data_process_test_002, TestSiz */ HWTEST_F(DCameraSinkDataProcessTest, dcamera_sink_data_process_test_003, TestSize.Level1) { + EXPECT_EQ(dataProcess_ == nullptr, false); int32_t ret = dataProcess_->StartCapture(g_testCaptureInfoSnapshot); EXPECT_EQ(DCAMERA_OK, ret); } @@ -162,6 +165,7 @@ HWTEST_F(DCameraSinkDataProcessTest, dcamera_sink_data_process_test_003, TestSiz */ HWTEST_F(DCameraSinkDataProcessTest, dcamera_sink_data_process_test_004, TestSize.Level1) { + EXPECT_EQ(dataProcess_ == nullptr, false); int32_t ret = dataProcess_->StopCapture(); EXPECT_EQ(DCAMERA_OK, ret); } @@ -174,6 +178,7 @@ HWTEST_F(DCameraSinkDataProcessTest, dcamera_sink_data_process_test_004, TestSiz */ HWTEST_F(DCameraSinkDataProcessTest, dcamera_sink_data_process_test_005, TestSize.Level1) { + EXPECT_EQ(dataProcess_ == nullptr, false); dataProcess_->captureInfo_ = g_testCaptureInfoContinuousNotEncode; int32_t ret = dataProcess_->FeedStream(g_testDataBuffer); std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS)); @@ -188,6 +193,7 @@ HWTEST_F(DCameraSinkDataProcessTest, dcamera_sink_data_process_test_005, TestSiz */ HWTEST_F(DCameraSinkDataProcessTest, dcamera_sink_data_process_test_006, TestSize.Level1) { + EXPECT_EQ(dataProcess_ == nullptr, false); dataProcess_->captureInfo_ = g_testCaptureInfoContinuousNeedEncode; int32_t ret = dataProcess_->FeedStream(g_testDataBuffer); std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS)); @@ -202,6 +208,7 @@ HWTEST_F(DCameraSinkDataProcessTest, dcamera_sink_data_process_test_006, TestSiz */ HWTEST_F(DCameraSinkDataProcessTest, dcamera_sink_data_process_test_007, TestSize.Level1) { + EXPECT_EQ(dataProcess_ == nullptr, false); dataProcess_->captureInfo_ = g_testCaptureInfoSnapshot; int32_t ret = dataProcess_->FeedStream(g_testDataBuffer); std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS)); @@ -216,6 +223,7 @@ HWTEST_F(DCameraSinkDataProcessTest, dcamera_sink_data_process_test_007, TestSiz */ HWTEST_F(DCameraSinkDataProcessTest, dcamera_sink_data_process_test_008, TestSize.Level1) { + EXPECT_EQ(dataProcess_ == nullptr, false); EXPECT_EQ(VideoCodecType::CODEC_H264, dataProcess_->GetPipelineCodecType(DCEncodeType::ENCODE_TYPE_H264)); EXPECT_EQ(VideoCodecType::CODEC_H265, dataProcess_->GetPipelineCodecType(DCEncodeType::ENCODE_TYPE_H265)); EXPECT_EQ(VideoCodecType::CODEC_MPEG4_ES, dataProcess_->GetPipelineCodecType(DCEncodeType::ENCODE_TYPE_MPEG4_ES)); diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_dev_test.cpp b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_dev_test.cpp index 9f77c44c..0056957d 100644 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_dev_test.cpp +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_dev_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 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 @@ -102,6 +102,7 @@ void DCameraSinkDevTest::TearDown(void) */ HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_001, TestSize.Level1) { + EXPECT_EQ(dev_ == nullptr, false); int32_t ret = dev_->Init(); EXPECT_EQ(DCAMERA_OK, ret); EXPECT_EQ(true, dev_->isInit_); @@ -129,6 +130,7 @@ HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_001, TestSize.Level1) */ HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_002, TestSize.Level1) { + EXPECT_EQ(dev_ == nullptr, false); int32_t ret = dev_->SubscribeLocalHardware(TEST_PARAMETER); EXPECT_EQ(DCAMERA_OK, ret); } @@ -141,6 +143,7 @@ HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_002, TestSize.Level1) */ HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_003, TestSize.Level1) { + EXPECT_EQ(dev_ == nullptr, false); int32_t ret = dev_->UnsubscribeLocalHardware(); EXPECT_EQ(DCAMERA_OK, ret); } @@ -153,6 +156,7 @@ HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_003, TestSize.Level1) */ HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_004, TestSize.Level1) { + EXPECT_EQ(dev_ == nullptr, false); int32_t ret = dev_->GetCameraInfo(g_testCameraInfo); EXPECT_EQ(DCAMERA_OK, ret); DHLOGI("DCameraSinkDevTest::GetCameraInfo cameraInfo is %{public}s", GetAnonyString(g_testCameraInfo).c_str()); @@ -170,6 +174,7 @@ HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_004, TestSize.Level1) */ HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_005, TestSize.Level1) { + EXPECT_EQ(dev_ == nullptr, false); int32_t ret = dev_->ChannelNeg(g_testChannelInfoDevEmpty); EXPECT_EQ(DCAMERA_BAD_VALUE, ret); } @@ -182,6 +187,7 @@ HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_005, TestSize.Level1) */ HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_006, TestSize.Level1) { + EXPECT_EQ(dev_ == nullptr, false); int32_t ret = dev_->ChannelNeg(g_testChannelInfoDevContinue); EXPECT_EQ(DCAMERA_OK, ret); g_sinkCtrlStr = "test_006"; @@ -198,6 +204,7 @@ HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_006, TestSize.Level1) */ HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_007, TestSize.Level1) { + EXPECT_EQ(dev_ == nullptr, false); int32_t ret = dev_->StopCapture(); EXPECT_EQ(DCAMERA_OK, ret); } @@ -210,6 +217,7 @@ HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_007, TestSize.Level1) */ HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_008, TestSize.Level1) { + EXPECT_EQ(dev_ == nullptr, false); int32_t ret = dev_->OpenChannel(g_testOpenInfoDevEmpty); EXPECT_EQ(DCAMERA_BAD_VALUE, ret); } @@ -222,6 +230,7 @@ HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_008, TestSize.Level1) */ HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_009, TestSize.Level1) { + EXPECT_EQ(dev_ == nullptr, false); int32_t ret = dev_->OpenChannel(g_testOpenInfoDev); EXPECT_EQ(DCAMERA_OK, ret); } @@ -234,6 +243,7 @@ HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_009, TestSize.Level1) */ HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_010, TestSize.Level1) { + EXPECT_EQ(dev_ == nullptr, false); int32_t ret = dev_->CloseChannel(); EXPECT_EQ(DCAMERA_OK, ret); } @@ -246,6 +256,7 @@ HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_010, TestSize.Level1) */ HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_011, TestSize.Level1) { + EXPECT_EQ(dev_ == nullptr, false); dev_->dhId_ = "1"; std::string ret = dev_->GetDhid(); EXPECT_NE("", ret); @@ -259,6 +270,7 @@ HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_011, TestSize.Level1) */ HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_012, TestSize.Level1) { + EXPECT_EQ(dev_ == nullptr, false); std::string devId = ""; int32_t ret = dev_->PauseDistributedHardware(devId); EXPECT_EQ(DCAMERA_BAD_VALUE, ret); @@ -280,6 +292,7 @@ HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_012, TestSize.Level1) */ HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_013, TestSize.Level1) { + EXPECT_EQ(dev_ == nullptr, false); std::string devId = ""; int32_t ret = dev_->ResumeDistributedHardware(devId); EXPECT_EQ(DCAMERA_BAD_VALUE, ret); @@ -301,6 +314,7 @@ HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_013, TestSize.Level1) */ HWTEST_F(DCameraSinkDevTest, dcamera_sink_dev_test_014, TestSize.Level1) { + EXPECT_EQ(dev_ == nullptr, false); std::string devId = ""; int32_t ret = dev_->StopDistributedHardware(devId); EXPECT_EQ(DCAMERA_BAD_VALUE, ret); diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_output_test.cpp b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_output_test.cpp index 0a5fe02f..ff69109d 100644 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_output_test.cpp +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_output_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 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 @@ -140,6 +140,7 @@ void DCameraSinkOutputTest::TearDown(void) */ HWTEST_F(DCameraSinkOutputTest, dcamera_sink_output_test_001, TestSize.Level1) { + EXPECT_EQ(output_ == nullptr, false); int32_t ret = output_->Init(); EXPECT_EQ(DCAMERA_OK, ret); std::shared_ptr output = nullptr; @@ -162,6 +163,7 @@ HWTEST_F(DCameraSinkOutputTest, dcamera_sink_output_test_001, TestSize.Level1) */ HWTEST_F(DCameraSinkOutputTest, dcamera_sink_output_test_002, TestSize.Level1) { + EXPECT_EQ(output_ == nullptr, false); channel_ = std::make_shared(); dataProcess_ = std::make_shared(channel_); output_->channels_.emplace(SNAPSHOT_FRAME, channel_); @@ -183,6 +185,7 @@ HWTEST_F(DCameraSinkOutputTest, dcamera_sink_output_test_002, TestSize.Level1) */ HWTEST_F(DCameraSinkOutputTest, dcamera_sink_output_test_003, TestSize.Level1) { + EXPECT_EQ(output_ == nullptr, false); channel_ = std::make_shared(); dataProcess_ = std::make_shared(channel_); output_->channels_.emplace(SNAPSHOT_FRAME, channel_); @@ -204,6 +207,7 @@ HWTEST_F(DCameraSinkOutputTest, dcamera_sink_output_test_003, TestSize.Level1) */ HWTEST_F(DCameraSinkOutputTest, dcamera_sink_output_test_004, TestSize.Level1) { + EXPECT_EQ(output_ == nullptr, false); channel_ = std::make_shared(); dataProcess_ = std::make_shared(channel_); output_->channels_.emplace(SNAPSHOT_FRAME, channel_); @@ -225,6 +229,7 @@ HWTEST_F(DCameraSinkOutputTest, dcamera_sink_output_test_004, TestSize.Level1) */ HWTEST_F(DCameraSinkOutputTest, dcamera_sink_output_test_005, TestSize.Level1) { + EXPECT_EQ(output_ == nullptr, false); channel_ = std::make_shared(); dataProcess_ = std::make_shared(channel_); output_->channels_.emplace(SNAPSHOT_FRAME, channel_); @@ -249,6 +254,7 @@ HWTEST_F(DCameraSinkOutputTest, dcamera_sink_output_test_005, TestSize.Level1) */ HWTEST_F(DCameraSinkOutputTest, dcamera_sink_output_test_006, TestSize.Level1) { + EXPECT_EQ(output_ == nullptr, false); channel_ = std::make_shared(); output_->channels_.emplace(SNAPSHOT_FRAME, channel_); output_->channels_.emplace(CONTINUOUS_FRAME, channel_); @@ -264,6 +270,7 @@ HWTEST_F(DCameraSinkOutputTest, dcamera_sink_output_test_006, TestSize.Level1) */ HWTEST_F(DCameraSinkOutputTest, dcamera_sink_output_test_007, TestSize.Level1) { + EXPECT_EQ(output_ == nullptr, false); channel_ = std::make_shared(); output_->channels_.emplace(SNAPSHOT_FRAME, channel_); output_->channels_.emplace(CONTINUOUS_FRAME, channel_); @@ -279,6 +286,7 @@ HWTEST_F(DCameraSinkOutputTest, dcamera_sink_output_test_007, TestSize.Level1) */ HWTEST_F(DCameraSinkOutputTest, dcamera_sink_output_test_008, TestSize.Level1) { + EXPECT_EQ(output_ == nullptr, false); std::string name = "name"; PropertyCarrier propertyCarrier; int32_t ret = output_->GetProperty(name, propertyCarrier); diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/eventbus/dcamera_frame_trigger_event_test.cpp b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/eventbus/dcamera_frame_trigger_event_test.cpp index 4e0453ba..e6609eeb 100644 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/eventbus/dcamera_frame_trigger_event_test.cpp +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/eventbus/dcamera_frame_trigger_event_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 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 @@ -66,6 +66,7 @@ void DCameraFrameTriggerEventTest::TearDown(void) */ HWTEST_F(DCameraFrameTriggerEventTest, dcamera_frame_trigger_event_test_001, TestSize.Level1) { + EXPECT_EQ(testDCameraFrameTriggerEvent_ == nullptr, false); std::string param = testDCameraFrameTriggerEvent_->GetParam(); EXPECT_EQ(param, TEST_PARAM); } diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/eventbus/dcamera_photo_output_event_test.cpp b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/eventbus/dcamera_photo_output_event_test.cpp index 4777134f..d546bbe2 100644 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/eventbus/dcamera_photo_output_event_test.cpp +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/eventbus/dcamera_photo_output_event_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 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 @@ -72,6 +72,7 @@ void DCameraPhotoOutputEventTest::TearDown(void) */ HWTEST_F(DCameraPhotoOutputEventTest, dcamera_photo_output_event_test_001, TestSize.Level1) { + EXPECT_EQ(testDCameraPhotoOutputEvent_ == nullptr, false); std::shared_ptr buffer = testDCameraPhotoOutputEvent_->GetParam(); EXPECT_EQ(buffer->Capacity(), TEST_CAPACITY); } diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_service_ipc.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_service_ipc.cpp index ad2aec06..e6192585 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_service_ipc.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_service_ipc.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 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 @@ -106,7 +106,9 @@ sptr DCameraSourceServiceIpc::GetSinkRemoteCamSrv(const std::lock_guard autoLock(sinkRemoteCamSrvLock_); auto iter = remoteSinks_.find(deviceId); if (iter != remoteSinks_.end()) { - iter->second->AsObject()->RemoveDeathRecipient(sinkRemoteRecipient_); + if (iter->second != nullptr && iter->second->AsObject() != nullptr) { + iter->second->AsObject()->RemoveDeathRecipient(sinkRemoteRecipient_); + } } remoteSinks_[deviceId] = remoteCamSrvObj; } @@ -124,7 +126,7 @@ void DCameraSourceServiceIpc::DeleteSinkRemoteCamSrv(const std::string& deviceId return; } - if (item->second != nullptr) { + if (item->second != nullptr && item->second->AsObject() != nullptr) { item->second->AsObject()->RemoveDeathRecipient(sinkRemoteRecipient_); } remoteSinks_.erase(item); @@ -136,7 +138,9 @@ void DCameraSourceServiceIpc::ClearSinkRemoteCamSrv() std::lock_guard autoLock(sinkRemoteCamSrvLock_); for (auto iter = remoteSinks_.begin(); iter != remoteSinks_.end(); iter++) { if (iter->second != nullptr) { - iter->second->AsObject()->RemoveDeathRecipient(sinkRemoteRecipient_); + if (iter->second != nullptr && iter->second->AsObject() != nullptr) { + iter->second->AsObject()->RemoveDeathRecipient(sinkRemoteRecipient_); + } } } remoteSinks_.clear(); @@ -169,7 +173,9 @@ void DCameraSourceServiceIpc::OnSinkRemoteCamSrvDied(const wptr& DHLOGI("OnSinkRemoteCamSrvDied remote.devId: %{public}s", GetAnonyString(iter->first).c_str()); if (iter->second != nullptr) { - iter->second->AsObject()->RemoveDeathRecipient(sinkRemoteRecipient_); + if (iter->second != nullptr && iter->second->AsObject() != nullptr) { + iter->second->AsObject()->RemoveDeathRecipient(sinkRemoteRecipient_); + } } remoteSinks_.erase(iter); } diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameracontrol/dcamera_source_controller.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameracontrol/dcamera_source_controller.cpp index 3c5ed9aa..c5064034 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameracontrol/dcamera_source_controller.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameracontrol/dcamera_source_controller.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 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 @@ -63,11 +63,10 @@ DCameraSourceController::~DCameraSourceController() int32_t DCameraSourceController::StartCapture(std::vector>& captureInfos) { - if (indexs_.size() > DCAMERA_MAX_NUM) { + if (indexs_.empty() || indexs_.size() > DCAMERA_MAX_NUM) { DHLOGE("StartCapture not support operate %{public}zu camera", indexs_.size()); return DCAMERA_BAD_OPERATE; } - std::string dhId = indexs_.begin()->dhId_; std::string devId = indexs_.begin()->devId_; DHLOGI("StartCapture devId: %{public}s, dhId: %{public}s", GetAnonyString(devId).c_str(), @@ -176,6 +175,7 @@ int32_t DCameraSourceController::ChannelNeg(std::shared_ptr& int32_t DCameraSourceController::DCameraNotify(std::shared_ptr& events) { + CHECK_AND_RETURN_RET_LOG(events == nullptr, DCAMERA_BAD_VALUE, "Event is null"); if (events->eventResult_ == DCAMERA_EVENT_CAMERA_ERROR) { DcameraFinishAsyncTrace(DCAMERA_CONTINUE_FIRST_FRAME, DCAMERA_CONTINUE_FIRST_FRAME_TASKID); DcameraFinishAsyncTrace(DCAMERA_SNAPSHOT_FIRST_FRAME, DCAMERA_SNAPSHOT_FIRST_FRAME_TASKID); @@ -487,6 +487,9 @@ void DCameraSourceController::HandleMetaDataResult(std::string& jsonStr) dhBase.dhId_ = dhId_; for (auto iter = cmd.value_.begin(); iter != cmd.value_.end(); iter++) { DCameraSettings setting; + if ((*iter) == nullptr) { + continue; + } setting.type_ = (*iter)->type_; setting.value_ = (*iter)->value_; int32_t retHdi = camHdiProvider_->OnSettingsResult(dhBase, setting); diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_source_data_process.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_source_data_process.cpp index f264135d..b383796e 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_source_data_process.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_source_data_process.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 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 @@ -54,12 +54,15 @@ int32_t DCameraSourceDataProcess::FeedStream(std::vector(buffer->Size()); DHLOGD("DCameraSourceDataProcess FeedStream devId %{public}s dhId %{public}s streamType %{public}d streamSize: " "%{public}" PRIu64, GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamType_, buffersSize); std::lock_guard autoLock(streamMutex_); for (auto iter = streamProcess_.begin(); iter != streamProcess_.end(); iter++) { - (*iter)->FeedStream(buffer); + if ((*iter) != nullptr) { + (*iter)->FeedStream(buffer); + } } return DCAMERA_OK; } @@ -76,6 +79,9 @@ int32_t DCameraSourceDataProcess::ConfigStreams(std::vector> streamConfigs; for (auto iter = streamInfos.begin(); iter != streamInfos.end(); iter++) { std::shared_ptr streamInfo = *iter; + if (streamInfo == nullptr) { + continue; + } DCameraStreamConfig streamConfig(streamInfo->width_, streamInfo->height_, streamInfo->format_, streamInfo->dataspace_, streamInfo->encodeType_, streamInfo->type_); DHLOGI("DCameraSourceDataProcess ConfigStreams devId %{public}s dhId %{public}s, streamId: %{public}d info: " @@ -119,6 +125,9 @@ int32_t DCameraSourceDataProcess::ReleaseStreams(std::vector& streamIds std::set streamIdSet(streamIds.begin(), streamIds.end()); auto iter = streamProcess_.begin(); while (iter != streamProcess_.end()) { + if ((*iter) == nullptr) { + continue; + } (*iter)->ReleaseStreams(streamIdSet); std::set processStreamIds; (*iter)->GetAllStreamIds(processStreamIds); @@ -143,6 +152,7 @@ int32_t DCameraSourceDataProcess::ReleaseStreams(std::vector& streamIds int32_t DCameraSourceDataProcess::StartCapture(std::shared_ptr& captureInfo) { + CHECK_AND_RETURN_RET_LOG((captureInfo == nullptr), DCAMERA_BAD_VALUE, "CaptureInfo is null."); DHLOGI("DCameraSourceDataProcess StartCapture devId %{public}s dhId %{public}s width: %{public}d, height: " "%{public}d, format: %{public}d, isCapture: %{public}d, dataspace: %{public}d, encodeType: %{public}d, " "streamType: %{public}d", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), @@ -161,6 +171,9 @@ int32_t DCameraSourceDataProcess::StartCapture(std::shared_ptr& c GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), *iterSet); } for (auto iter = streamProcess_.begin(); iter != streamProcess_.end(); iter++) { + if ((*iter) == nullptr) { + continue; + } (*iter)->StartCapture(streamConfig, streamIds); } return DCAMERA_OK; @@ -176,6 +189,9 @@ int32_t DCameraSourceDataProcess::StopCapture(std::vector& streamIds) GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), *iterSet); } for (auto iter = streamProcess_.begin(); iter != streamProcess_.end(); iter++) { + if ((*iter) == nullptr) { + continue; + } (*iter)->StopCapture(streamIdSet); } if ((streamType_ == CONTINUOUS_FRAME) && (GetProducerSize() == 0)) { @@ -189,6 +205,9 @@ void DCameraSourceDataProcess::DestroyPipeline() DHLOGI("DCameraSourceDataProcess DestroyPipeline devId %{public}s dhId %{public}s streamType: %{public}d", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamType_); for (auto iter = streamProcess_.begin(); iter != streamProcess_.end(); iter++) { + if ((*iter) == nullptr) { + continue; + } (*iter)->DestroyPipeline(); } } @@ -198,6 +217,9 @@ int32_t DCameraSourceDataProcess::GetProducerSize() int32_t ret = 0; for (auto iter = streamProcess_.begin(); iter != streamProcess_.end(); iter++) { std::shared_ptr streamDataProcess = *iter; + if (streamDataProcess == nullptr) { + continue; + } int32_t size = streamDataProcess->GetProducerSize(); ret += size; } diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_source_input.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_source_input.cpp index 857415d7..2898e016 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_source_input.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_source_input.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 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 @@ -64,6 +64,9 @@ int32_t DCameraSourceInput::ConfigStreams(std::vector> continueStreams; for (auto iter = streamInfos.begin(); iter != streamInfos.end(); iter++) { std::shared_ptr streamInfo = *iter; + if (streamInfo == nullptr) { + continue; + } DHLOGI("DCameraSourceInput ConfigStreams devId: %{public}s, dhId: %{public}s, streamId: %{public}d, width: " "%{public}d, height: %{public}d, format: %{public}d, dataspace: %{public}d, encodeType:%{public}d " "streamType: %{public}d", GetAnonyString(devId_).c_str(), @@ -102,12 +105,14 @@ int32_t DCameraSourceInput::ReleaseStreams(std::vector& streamIds, bool& is { DHLOGI("DCameraSourceInput ReleaseStreams devId %{public}s dhId %{public}s", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); + CHECK_AND_RETURN_RET_LOG((dataProcess_[CONTINUOUS_FRAME] == nullptr), DCAMERA_BAD_VALUE, "dataProcess is null."); int32_t ret = dataProcess_[CONTINUOUS_FRAME]->ReleaseStreams(streamIds); if (ret != DCAMERA_OK) { DHLOGE("DCameraSourceInput ReleaseStreams continue stream ReleaseStreams ret: %{public}d, devId: %{public}s," " dhId: %{public}s", ret, GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); return ret; } + CHECK_AND_RETURN_RET_LOG((dataProcess_[SNAPSHOT_FRAME] == nullptr), DCAMERA_BAD_VALUE, "dataProcess is null."); ret = dataProcess_[SNAPSHOT_FRAME]->ReleaseStreams(streamIds); if (ret != DCAMERA_OK) { DHLOGE("DCameraSourceInput ReleaseStreams snapshot stream ReleaseStreams ret: %{public}d, devId: %{public}s, " @@ -130,6 +135,9 @@ int32_t DCameraSourceInput::StartCapture(std::vectorstreamIds_.begin(); iterSet != (*iter)->streamIds_.end(); iterSet++) { DHLOGI("DCameraSourceInput StartCapture devId %{public}s dhId %{public}s StartCapture id: %{public}d", @@ -153,6 +161,10 @@ int32_t DCameraSourceInput::StopCapture(std::vector& streamIds, bool& isAll { DHLOGI("DCameraSourceInput StopCapture devId %{public}s dhId %{public}s", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); + if (dataProcess_[CONTINUOUS_FRAME] == nullptr || dataProcess_[SNAPSHOT_FRAME] == nullptr) { + DHLOGE("dataProcess of continuous or snapshot is null"); + return DCAMERA_BAD_VALUE; + } int32_t ret = dataProcess_[CONTINUOUS_FRAME]->StopCapture(streamIds); if (ret != DCAMERA_OK) { DHLOGE("DCameraSourceInput StopCapture continue ret: %{public}d, devId: %{public}s, dhId: %{public}s", ret, @@ -202,6 +214,8 @@ int32_t DCameraSourceInput::OpenChannel(std::vector& indexs) int32_t DCameraSourceInput::CloseChannel() { + CHECK_AND_RETURN_RET_LOG((channels_[CONTINUOUS_FRAME] == nullptr), DCAMERA_BAD_VALUE, "Channel is null."); + CHECK_AND_RETURN_RET_LOG((channels_[SNAPSHOT_FRAME] == nullptr), DCAMERA_BAD_VALUE, "Channel of snapshot is null."); DHLOGI("DCameraSourceInput CloseChannel devId %{public}s dhId %{public}s continue state: %{public}d, " "snapshot state: %{public}d", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), channelState_[CONTINUOUS_FRAME], channelState_[SNAPSHOT_FRAME]); @@ -335,6 +349,10 @@ void DCameraSourceInput::OnSessionError(DCStreamType streamType, int32_t eventTy void DCameraSourceInput::OnDataReceived(DCStreamType streamType, std::vector>& buffers) { + if (buffers.empty() || buffers[0] == nullptr) { + DHLOGE("buffer is null."); + return; + } buffers[0]->frameInfo_.offset = DCameraSoftbusLatency::GetInstance().GetTimeSyncInfo(devId_); int32_t ret = dataProcess_[streamType]->FeedStream(buffers); if (ret != DCAMERA_OK) { @@ -348,6 +366,7 @@ int32_t DCameraSourceInput::ReleaseAllStreams() DHLOGI("ReleaseAllStreams devId %{public}s dhId %{public}s", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); std::vector continueStreamIds; + CHECK_AND_RETURN_RET_LOG((dataProcess_[CONTINUOUS_FRAME] == nullptr), DCAMERA_BAD_VALUE, "dataProcess is null."); dataProcess_[CONTINUOUS_FRAME]->GetAllStreamIds(continueStreamIds); int32_t ret = dataProcess_[CONTINUOUS_FRAME]->ReleaseStreams(continueStreamIds); if (ret != DCAMERA_OK) { @@ -372,6 +391,10 @@ int32_t DCameraSourceInput::StopAllCapture() DHLOGI("StopAllCapture devId %{public}s dhId %{public}s", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); std::vector continueStreamIds; + CHECK_AND_RETURN_RET_LOG((dataProcess_[CONTINUOUS_FRAME] == nullptr), DCAMERA_BAD_VALUE, + "dataProcess of continous frame is null."); + CHECK_AND_RETURN_RET_LOG((dataProcess_[SNAPSHOT_FRAME] == nullptr), DCAMERA_BAD_VALUE, + "dataProcess of snapshot frame is null."); dataProcess_[CONTINUOUS_FRAME]->GetAllStreamIds(continueStreamIds); int32_t ret = dataProcess_[CONTINUOUS_FRAME]->StopCapture(continueStreamIds); if (ret != DCAMERA_OK) { @@ -404,6 +427,7 @@ void DCameraSourceInput::PostChannelDisconnectedEvent() int32_t DCameraSourceInput::EstablishContinuousFrameSession(std::vector& indexs) { DcameraStartAsyncTrace(DCAMERA_OPEN_DATA_CONTINUE, DCAMERA_OPEN_DATA_CONTINUE_TASKID); + CHECK_AND_RETURN_RET_LOG((channels_[CONTINUOUS_FRAME] == nullptr), DCAMERA_BAD_VALUE, "Channel is null."); int32_t ret = channels_[CONTINUOUS_FRAME]->CreateSession(indexs, CONTINUE_SESSION_FLAG, DCAMERA_SESSION_MODE_VIDEO, listeners_[CONTINUOUS_FRAME]); if (ret != DCAMERA_OK) { @@ -421,6 +445,7 @@ int32_t DCameraSourceInput::EstablishContinuousFrameSession(std::vector& indexs) { DcameraStartAsyncTrace(DCAMERA_OPEN_DATA_SNAPSHOT, DCAMERA_OPEN_DATA_SNAPSHOT_TASKID); + CHECK_AND_RETURN_RET_LOG((channels_[CONTINUOUS_FRAME] == nullptr), DCAMERA_BAD_VALUE, "Channel is null."); int32_t ret = channels_[SNAPSHOT_FRAME]->CreateSession(indexs, SNAP_SHOT_SESSION_FLAG, DCAMERA_SESSION_MODE_JPEG, listeners_[SNAPSHOT_FRAME]); if (ret != DCAMERA_OK) { diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_stream_data_process.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_stream_data_process.cpp index 93daa0f1..e000572c 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_stream_data_process.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_stream_data_process.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 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 @@ -47,6 +47,10 @@ DCameraStreamDataProcess::~DCameraStreamDataProcess() void DCameraStreamDataProcess::FeedStream(std::shared_ptr& buffer) { + if (buffer == nullptr) { + DHLOGE("Data buffer is null."); + return; + } for (auto streamId : streamIds_) { uint64_t buffersSize = static_cast(buffer->Size()); DHLOGD("FeedStream devId %{public}s dhId %{public}s streamId %{public}d streamType %{public}d streamSize: " @@ -70,6 +74,10 @@ void DCameraStreamDataProcess::FeedStream(std::shared_ptr& buffer) void DCameraStreamDataProcess::ConfigStreams(std::shared_ptr& dstConfig, std::set& streamIds) { + if (dstConfig == nullptr) { + DHLOGE("Stream Config is null."); + return; + } for (auto streamId : streamIds) { DHLOGI("ConfigStreams devId %{public}s dhId %{public}s streamId %{public}d, width: %{public}d, height: " "%{public}d, format: %{public}d, dataspace: %{public}d, encodeType: %{public}d, streamType: %{public}d", @@ -96,6 +104,10 @@ void DCameraStreamDataProcess::ReleaseStreams(std::set& streamIds) if (producerIter == producers_.end()) { continue; } + if (producerIter->second == nullptr) { + DHLOGE("Preducer is null."); + continue; + } producerIter->second->Stop(); producers_.erase(streamId); } @@ -104,6 +116,10 @@ void DCameraStreamDataProcess::ReleaseStreams(std::set& streamIds) void DCameraStreamDataProcess::StartCapture(std::shared_ptr& srcConfig, std::set& streamIds) { + if (srcConfig == nullptr) { + DHLOGE("Stream Config of source is null."); + return; + } for (auto iter = streamIds.begin(); iter != streamIds.end(); iter++) { DHLOGI("StartCapture devId %{public}s dhId %{public}s streamType: %{public}d streamId: %{public}d, " "srcConfig: width: %{public}d, height: %{public}d, format: %{public}d, dataspace: %{public}d, " @@ -165,6 +181,10 @@ void DCameraStreamDataProcess::StopCapture(std::set& streamIds) } DHLOGI("StopCapture stop producer, devId %{public}s dhId %{public}s streamType: %{public}d streamId: " "%{public}d", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamType_, streamId); + if (producerIter->second == nullptr) { + DHLOGE("Preducer is null."); + continue; + } producerIter->second->Stop(); producerIter = producers_.erase(producerIter); } @@ -192,6 +212,10 @@ void DCameraStreamDataProcess::FeedStreamToSnapShot(const std::shared_ptr autoLock(producerMutex_); for (auto iter = producers_.begin(); iter != producers_.end(); iter++) { + if (iter->second == nullptr) { + DHLOGE("Preducer is null."); + continue; + } iter->second->FeedStream(buffer); } } @@ -225,6 +249,10 @@ void DCameraStreamDataProcess::OnProcessedVideoBuffer(const std::shared_ptr autoLock(producerMutex_); for (auto iter = producers_.begin(); iter != producers_.end(); iter++) { + if (iter->second == nullptr) { + DHLOGE("Preducer is null."); + continue; + } iter->second->FeedStream(videoResult); } } diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_stream_data_process_producer.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_stream_data_process_producer.cpp index d220992d..2470edb9 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_stream_data_process_producer.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_stream_data_process_producer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 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 @@ -108,6 +108,10 @@ void DCameraStreamDataProcessProducer::Stop() void DCameraStreamDataProcessProducer::FeedStream(const std::shared_ptr& buffer) { + if (buffer == nullptr) { + DHLOGE("Data buffer is null."); + return; + } buffer->frameInfo_.timePonit.startSmooth = GetNowTimeStampUs(); { std::lock_guard lock(bufferMutex_); @@ -211,6 +215,7 @@ int32_t DCameraStreamDataProcessProducer::FeedStreamToDriver(const DHBase& dhBas return DCAMERA_BAD_OPERATE; } do { + CHECK_AND_RETURN_RET_LOG(buffer == nullptr, DCAMERA_BAD_VALUE, "Data buffer is null"); ret = CheckSharedMemory(sharedMemory, buffer); if (ret != DCAMERA_OK) { DHLOGE("CheckSharedMemory failed devId: %{public}s dhId: %{public}s", GetAnonyString(devId_).c_str(), diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/feedingsmoother/base/ifeeding_smoother.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/feedingsmoother/base/ifeeding_smoother.cpp index 1aeff239..a5161bb2 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/feedingsmoother/base/ifeeding_smoother.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/feedingsmoother/base/ifeeding_smoother.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 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 @@ -95,6 +95,10 @@ void IFeedingSmoother::LooperSmooth() void IFeedingSmoother::SmoothFeeding(const std::shared_ptr& data) { + if (data == nullptr) { + DHLOGE("Feed data is null."); + return; + } int64_t enterTime = GetNowTimeStampUs(); SetClockTime(enterTime); int64_t timeStamp = data->GetTimeStamp(); diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/feedingsmoother/base/time_statistician.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/feedingsmoother/base/time_statistician.cpp index 31c8c440..fdea5ede 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/feedingsmoother/base/time_statistician.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/feedingsmoother/base/time_statistician.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 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 @@ -20,6 +20,10 @@ namespace OHOS { namespace DistributedHardware { void TimeStatistician::CalProcessTime(const std::shared_ptr& data) { + if (data == nullptr) { + DHLOGE("Feed data is null."); + return; + } int64_t feedTime = GetNowTimeStampUs(); int64_t timeStamp = data->GetTimeStamp(); CalAverFeedInterval(feedTime); diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/feedingsmoother/derived/dcamera_feeding_smoother.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/feedingsmoother/derived/dcamera_feeding_smoother.cpp index 635ccfd8..07e88803 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/feedingsmoother/derived/dcamera_feeding_smoother.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/feedingsmoother/derived/dcamera_feeding_smoother.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 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 @@ -51,6 +51,7 @@ void DCameraFeedingSmoother::InitTimeStatistician() int32_t DCameraFeedingSmoother::NotifySmoothFinished(const std::shared_ptr& data) { int64_t finishSmoothT = GetNowTimeStampUs(); + CHECK_AND_RETURN_RET_LOG((data == nullptr), NOTIFY_FAILED, "Feed data is null."); std::shared_ptr buffer = std::reinterpret_pointer_cast(data); buffer->frameInfo_.timePonit.finishSmooth = finishSmoothT; CHECK_AND_RETURN_RET_LOG(dCameraStatistician_ == nullptr, NOTIFY_FAILED, "dCameraStatistician_ is null."); diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/feedingsmoother/derived/dcamera_time_statistician.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/feedingsmoother/derived/dcamera_time_statistician.cpp index 389bffd1..f46b54e2 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/feedingsmoother/derived/dcamera_time_statistician.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/feedingsmoother/derived/dcamera_time_statistician.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 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 @@ -21,6 +21,10 @@ namespace OHOS { namespace DistributedHardware { void DCameraTimeStatistician::CalProcessTime(const std::shared_ptr& data) { + if (data == nullptr) { + DHLOGE("Feed data is null."); + return; + } TimeStatistician::CalProcessTime(data); std::shared_ptr dataBuffer = std::reinterpret_pointer_cast(data); DCameraFrameInfo frameInfo = dataBuffer->frameInfo_; diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerastate/dcamera_source_capture_state.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerastate/dcamera_source_capture_state.cpp index cb79c556..917dd98c 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerastate/dcamera_source_capture_state.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerastate/dcamera_source_capture_state.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 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 @@ -89,6 +89,7 @@ int32_t DCameraSourceCaptureState::DoRegisterTask(std::shared_ptr& camDev, DCameraSourceEvent& event) { + CHECK_AND_RETURN_RET_LOG(camDev == nullptr, DCAMERA_BAD_VALUE, "Camera device is null"); std::shared_ptr camEvent = std::make_shared(); camEvent->eventType_ = DCAMERA_MESSAGE; camEvent->eventResult_ = DCAMERA_EVENT_CHANNEL_DISCONNECTED; @@ -143,6 +144,7 @@ int32_t DCameraSourceCaptureState::DoOpenTask(std::shared_ptr& int32_t DCameraSourceCaptureState::DoCloseTask(std::shared_ptr& camDev, DCameraSourceEvent& event) { + CHECK_AND_RETURN_RET_LOG(camDev == nullptr, DCAMERA_BAD_VALUE, "Camera device is null"); int32_t ret = camDev->StopAllCapture(); if (ret != DCAMERA_OK) { DHLOGE("StopAllCapture failed, ret: %{public}d", ret); @@ -172,6 +174,7 @@ int32_t DCameraSourceCaptureState::DoCloseTask(std::shared_ptr int32_t DCameraSourceCaptureState::DoStartCaptureTask(std::shared_ptr& camDev, DCameraSourceEvent& event) { + CHECK_AND_RETURN_RET_LOG(camDev == nullptr, DCAMERA_BAD_VALUE, "Camera device is null"); std::vector> captureInfos; int32_t ret = event.GetCaptureInfos(captureInfos); if (ret != DCAMERA_OK) { @@ -196,6 +199,7 @@ int32_t DCameraSourceCaptureState::DoStopCaptureTask(std::shared_ptrStopCapture(streamIds, isAllStop); if (ret != DCAMERA_OK) { DHLOGE("StopCapture failed, ret: %{public}d", ret); @@ -221,7 +225,7 @@ int32_t DCameraSourceCaptureState::DoUpdateSettingsTask(std::shared_ptrUpdateSettings(settings); if (ret != DCAMERA_OK) { DHLOGE("UpdateSettings failed, ret: %{public}d", ret); @@ -238,7 +242,7 @@ int32_t DCameraSourceCaptureState::DoEventNofityTask(std::shared_ptrCameraEventNotify(camEvent); if (ret != DCAMERA_OK) { DHLOGE("CameraEventNotify failed, ret: %{public}d", ret); diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerastate/dcamera_source_config_stream_state.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerastate/dcamera_source_config_stream_state.cpp index c76804ef..ce29ef43 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerastate/dcamera_source_config_stream_state.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerastate/dcamera_source_config_stream_state.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 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 @@ -98,6 +98,7 @@ int32_t DCameraSourceConfigStreamState::DoRegisterTask(std::shared_ptr& camDev, DCameraSourceEvent& event) { + CHECK_AND_RETURN_RET_LOG(camDev == nullptr, DCAMERA_BAD_VALUE, "Camera device is null"); std::shared_ptr camEvent = std::make_shared(); camEvent->eventType_ = DCAMERA_MESSAGE; camEvent->eventResult_ = DCAMERA_EVENT_CHANNEL_DISCONNECTED; @@ -147,6 +148,7 @@ int32_t DCameraSourceConfigStreamState::DoOpenTask(std::shared_ptr& camDev, DCameraSourceEvent& event) { + CHECK_AND_RETURN_RET_LOG(camDev == nullptr, DCAMERA_BAD_VALUE, "Camera device is null"); int32_t ret = camDev->CloseCamera(); if (ret != DCAMERA_OK) { DHLOGE("CloseCamera failed, ret: %{public}d", ret); @@ -170,6 +172,7 @@ int32_t DCameraSourceConfigStreamState::DoCloseTask(std::shared_ptr& camDev, DCameraSourceEvent& event) { + CHECK_AND_RETURN_RET_LOG(camDev == nullptr, DCAMERA_BAD_VALUE, "Camera device is null"); std::vector> streamInfos; int32_t ret = event.GetStreamInfos(streamInfos); if (ret != DCAMERA_OK) { @@ -196,6 +199,7 @@ int32_t DCameraSourceConfigStreamState::DoConfigStreamsTask(std::shared_ptr& camDev, DCameraSourceEvent& event) { + CHECK_AND_RETURN_RET_LOG(camDev == nullptr, DCAMERA_BAD_VALUE, "Camera device is null"); std::vector streamIds; int32_t ret = event.GetStreamIds(streamIds); if (ret != DCAMERA_OK) { @@ -223,6 +227,7 @@ int32_t DCameraSourceConfigStreamState::DoReleaseStreamsTask(std::shared_ptr& camDev, DCameraSourceEvent& event) { + CHECK_AND_RETURN_RET_LOG(camDev == nullptr, DCAMERA_BAD_VALUE, "Camera device is null"); std::vector> captureInfos; int32_t ret = event.GetCaptureInfos(captureInfos); if (ret != DCAMERA_OK) { @@ -253,6 +258,7 @@ int32_t DCameraSourceConfigStreamState::DoStopCaptureTask(std::shared_ptr& camDev, DCameraSourceEvent& event) { + CHECK_AND_RETURN_RET_LOG(camDev == nullptr, DCAMERA_BAD_VALUE, "Camera device is null"); std::vector> settings; int32_t ret = event.GetCameraSettings(settings); if (ret != DCAMERA_OK) { @@ -270,6 +276,7 @@ int32_t DCameraSourceConfigStreamState::DoUpdateSettingsTask(std::shared_ptr& camDev, DCameraSourceEvent& event) { + CHECK_AND_RETURN_RET_LOG(camDev == nullptr, DCAMERA_BAD_VALUE, "Camera device is null"); std::shared_ptr camEvent; int32_t ret = event.GetCameraEvent(camEvent); if (ret != DCAMERA_OK) { diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerastate/dcamera_source_init_state.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerastate/dcamera_source_init_state.cpp index ca546074..ad5e337e 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerastate/dcamera_source_init_state.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerastate/dcamera_source_init_state.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 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 @@ -58,6 +58,7 @@ DCameraStateType DCameraSourceInitState::GetStateType() int32_t DCameraSourceInitState::DoRegisterTask(std::shared_ptr& camDev, DCameraSourceEvent& event) { + CHECK_AND_RETURN_RET_LOG(camDev == nullptr, DCAMERA_BAD_VALUE, "Camera device is null"); std::shared_ptr param; int32_t ret = event.GetDCameraRegistParam(param); if (ret != DCAMERA_OK) { diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerastate/dcamera_source_opened_state.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerastate/dcamera_source_opened_state.cpp index 1703c3ed..69736b05 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerastate/dcamera_source_opened_state.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerastate/dcamera_source_opened_state.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 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 @@ -90,6 +90,7 @@ int32_t DCameraSourceOpenedState::DoRegisterTask(std::shared_ptr& camDev, DCameraSourceEvent& event) { + CHECK_AND_RETURN_RET_LOG(camDev == nullptr, DCAMERA_BAD_VALUE, "Camera device is null"); std::shared_ptr camEvent = std::make_shared(); camEvent->eventType_ = DCAMERA_MESSAGE; camEvent->eventResult_ = DCAMERA_EVENT_CHANNEL_DISCONNECTED; @@ -127,6 +128,7 @@ int32_t DCameraSourceOpenedState::DoUnregisterTask(std::shared_ptr& camDev, DCameraSourceEvent& event) { + CHECK_AND_RETURN_RET_LOG(camDev == nullptr, DCAMERA_BAD_VALUE, "Camera device is null"); std::vector> streamInfos; int32_t ret = event.GetStreamInfos(streamInfos); if (ret != DCAMERA_OK) { @@ -159,6 +161,7 @@ int32_t DCameraSourceOpenedState::DoReleaseStreamsTask(std::shared_ptr& camDev, DCameraSourceEvent& event) { + CHECK_AND_RETURN_RET_LOG(camDev == nullptr, DCAMERA_BAD_VALUE, "Camera device is null"); std::vector> settings; int32_t ret = event.GetCameraSettings(settings); if (ret != DCAMERA_OK) { @@ -183,6 +186,7 @@ int32_t DCameraSourceOpenedState::DoOpenTask(std::shared_ptr& int32_t DCameraSourceOpenedState::DoCloseTask(std::shared_ptr& camDev, DCameraSourceEvent& event) { + CHECK_AND_RETURN_RET_LOG(camDev == nullptr, DCAMERA_BAD_VALUE, "Camera device is null"); int32_t ret = camDev->CloseCamera(); if (ret != DCAMERA_OK) { DHLOGE("CloseCamera failed, ret: %{public}d", ret); @@ -200,6 +204,7 @@ int32_t DCameraSourceOpenedState::DoCloseTask(std::shared_ptr& int32_t DCameraSourceOpenedState::DoEventNofityTask(std::shared_ptr& camDev, DCameraSourceEvent& event) { + CHECK_AND_RETURN_RET_LOG(camDev == nullptr, DCAMERA_BAD_VALUE, "Camera device is null"); std::shared_ptr camEvent; int32_t ret = event.GetCameraEvent(camEvent); if (ret != DCAMERA_OK) { diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerastate/dcamera_source_regist_state.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerastate/dcamera_source_regist_state.cpp index 79d3d7ab..912c8ecd 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerastate/dcamera_source_regist_state.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerastate/dcamera_source_regist_state.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 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 @@ -74,6 +74,7 @@ DCameraStateType DCameraSourceRegistState::GetStateType() int32_t DCameraSourceRegistState::DoRegisterTask(std::shared_ptr& camDev, DCameraSourceEvent& event) { + CHECK_AND_RETURN_RET_LOG(camDev == nullptr, DCAMERA_BAD_VALUE, "Camera device is null"); DHLOGI("DCameraSourceRegistState DoRegisterTask"); std::shared_ptr param; int32_t ret = event.GetDCameraRegistParam(param); @@ -92,6 +93,7 @@ int32_t DCameraSourceRegistState::DoRegisterTask(std::shared_ptr& camDev, DCameraSourceEvent& event) { + CHECK_AND_RETURN_RET_LOG(camDev == nullptr, DCAMERA_BAD_VALUE, "Camera device is null"); std::shared_ptr param; int32_t ret = event.GetDCameraRegistParam(param); if (ret != DCAMERA_OK) { @@ -112,6 +114,7 @@ int32_t DCameraSourceRegistState::DoUnregisterTask(std::shared_ptr& camDev, DCameraSourceEvent& event) { + CHECK_AND_RETURN_RET_LOG(camDev == nullptr, DCAMERA_BAD_VALUE, "Camera device is null"); int32_t ret = camDev->OpenCamera(); if (ret != DCAMERA_OK) { DHLOGE("DCameraSourceRegistState OpenCamera failed, ret: %{public}d", ret); @@ -129,6 +132,7 @@ int32_t DCameraSourceRegistState::DoCloseTask(std::shared_ptr& int32_t DCameraSourceRegistState::DoEventNofityTask(std::shared_ptr& camDev, DCameraSourceEvent& event) { + CHECK_AND_RETURN_RET_LOG(camDev == nullptr, DCAMERA_BAD_VALUE, "Camera device is null"); std::shared_ptr camEvent; int32_t ret = event.GetCameraEvent(camEvent); if (ret != DCAMERA_OK) { diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerastate/dcamera_source_state_machine.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerastate/dcamera_source_state_machine.cpp index 00e6bfc3..aca03afd 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerastate/dcamera_source_state_machine.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerastate/dcamera_source_state_machine.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 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 @@ -35,6 +35,7 @@ DCameraSourceStateMachine::~DCameraSourceStateMachine() int32_t DCameraSourceStateMachine::Execute(DCAMERA_EVENT eventType, DCameraSourceEvent& event) { + CHECK_AND_RETURN_RET_LOG((currentState_ == nullptr), DCAMERA_BAD_VALUE, "State is null."); DHLOGI("In state %{public}d execute event %{public}d", currentState_->GetStateType(), eventType); std::shared_ptr camDev = camDev_.lock(); if (camDev == nullptr) { @@ -51,6 +52,10 @@ int32_t DCameraSourceStateMachine::Execute(DCAMERA_EVENT eventType, DCameraSourc void DCameraSourceStateMachine::UpdateState(DCameraStateType stateType) { + if (currentState_ == nullptr) { + DHLOGE("State is null."); + return; + } if (stateType != DCAMERA_STATE_INIT) { DHLOGI("DCameraSourceStateMachine update state from %{public}d to %{public}d", currentState_->GetStateType(), stateType); @@ -63,6 +68,7 @@ void DCameraSourceStateMachine::UpdateState(DCameraStateType stateType) int32_t DCameraSourceStateMachine::GetCameraState() { + CHECK_AND_RETURN_RET_LOG((currentState_ == nullptr), DCAMERA_BAD_VALUE, "State is null."); DHLOGI("GetCameraState In state %{public}d", currentState_->GetStateType()); return currentState_->GetStateType(); } -- Gitee