From 70f587949910b5c07009281f3b60bd83b723f9b1 Mon Sep 17 00:00:00 2001 From: wangchaole Date: Wed, 16 Aug 2023 16:56:11 +0800 Subject: [PATCH] fix: modify codecheck Signed-off-by: wangchaole --- .../client/include/dcamera_client.h | 1 + .../client/src/dcamera_client.cpp | 55 ++++++++++--------- .../client/test/sample/main.cpp | 6 +- .../cameraoperator/dcamera_client_test.cpp | 53 ++++++++++-------- .../dcameradata/dcamera_source_input.cpp | 16 ++---- 5 files changed, 70 insertions(+), 61 deletions(-) diff --git a/services/cameraservice/cameraoperator/client/include/dcamera_client.h b/services/cameraservice/cameraoperator/client/include/dcamera_client.h index 7632baa6..d1a915d2 100644 --- a/services/cameraservice/cameraoperator/client/include/dcamera_client.h +++ b/services/cameraservice/cameraoperator/client/include/dcamera_client.h @@ -63,6 +63,7 @@ private: std::shared_ptr& photoCaptureSetting); void SetPhotoCaptureLocation(const std::shared_ptr& cameraMetadata, std::shared_ptr& photoCaptureSetting); + void StopOutputCapture(); void ReleaseCaptureSession(); int32_t CameraServiceErrorType(const int32_t errorType); CameraStandard::CameraFormat ConvertToCameraFormat(int32_t format); diff --git a/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp b/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp index bfa8143e..fe671007 100644 --- a/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp +++ b/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp @@ -217,31 +217,7 @@ int32_t DCameraClient::CameraServiceErrorType(const int32_t errorType) int32_t DCameraClient::StopCapture() { DHLOGI("StopCapture cameraId: %s", GetAnonyString(cameraId_).c_str()); - if (previewOutput_ != nullptr) { - DHLOGI("StopCapture %s stop previewOutput", GetAnonyString(cameraId_).c_str()); - int32_t ret = ((sptr &)previewOutput_)->Stop(); - if (ret != DCAMERA_OK) { - DHLOGE("StopCapture videoOutput stop failed, cameraId: %s, ret: %d", - GetAnonyString(cameraId_).c_str(), ret); - } - DHLOGI("StopCapture %s release previewOutput", GetAnonyString(cameraId_).c_str()); - ret = previewOutput_->Release(); - if (ret != DCAMERA_OK) { - DHLOGE("StopCapture previewOutput Release failed, cameraId: %s, ret: %d", - GetAnonyString(cameraId_).c_str(), ret); - } - previewOutput_ = nullptr; - } - - if (photoOutput_ != nullptr) { - DHLOGI("StopCapture %s release photoOutput", GetAnonyString(cameraId_).c_str()); - int32_t ret = photoOutput_->Release(); - if (ret != DCAMERA_OK) { - DHLOGE("StopCapture photoOutput Release failed, cameraId: %s, ret: %d", - GetAnonyString(cameraId_).c_str(), ret); - } - photoOutput_ = nullptr; - } + StopOutputCapture(); if (cameraInput_ != nullptr) { DHLOGI("StopCapture %s release cameraInput", GetAnonyString(cameraId_).c_str()); @@ -281,6 +257,35 @@ int32_t DCameraClient::StopCapture() return DCAMERA_OK; } +void DCameraClient::StopOutputCapture() +{ + if (previewOutput_ != nullptr) { + DHLOGI("StopCapture %s stop previewOutput", GetAnonyString(cameraId_).c_str()); + int32_t ret = ((sptr &)previewOutput_)->Stop(); + if (ret != DCAMERA_OK) { + DHLOGE("StopCapture videoOutput stop failed, cameraId: %s, ret: %d", + GetAnonyString(cameraId_).c_str(), ret); + } + DHLOGI("StopCapture %s release previewOutput", GetAnonyString(cameraId_).c_str()); + ret = previewOutput_->Release(); + if (ret != DCAMERA_OK) { + DHLOGE("StopCapture previewOutput Release failed, cameraId: %s, ret: %d", + GetAnonyString(cameraId_).c_str(), ret); + } + previewOutput_ = nullptr; + } + + if (photoOutput_ != nullptr) { + DHLOGI("StopCapture %s release photoOutput", GetAnonyString(cameraId_).c_str()); + int32_t ret = photoOutput_->Release(); + if (ret != DCAMERA_OK) { + DHLOGE("StopCapture photoOutput Release failed, cameraId: %s, ret: %d", + GetAnonyString(cameraId_).c_str(), ret); + } + photoOutput_ = nullptr; + } +} + void DCameraClient::ReleaseCaptureSession() { if (captureSession_ == nullptr) { diff --git a/services/cameraservice/cameraoperator/client/test/sample/main.cpp b/services/cameraservice/cameraoperator/client/test/sample/main.cpp index f28d0c2a..da6e8d78 100644 --- a/services/cameraservice/cameraoperator/client/test/sample/main.cpp +++ b/services/cameraservice/cameraoperator/client/test/sample/main.cpp @@ -271,7 +271,7 @@ static std::shared_ptr ConfigPhotoCaptureSetting() return photoCaptureSettings; } -int main() +static void SetPermissions() { uint64_t tokenId; const char *perms[2]; @@ -290,8 +290,12 @@ int main() tokenId = GetAccessTokenId(&infoInstance); SetSelfTokenID(tokenId); OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); +} +int main() +{ DHLOGI("========== Distributed Camera Demo Start =========="); + SetPermissions(); int32_t ret = InitCameraStandard(); if (ret != DCAMERA_OK) { std::cout << "have no remote camera" << std::endl; 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 11508f4d..89821379 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 @@ -104,6 +104,7 @@ public: void SetUp(); void TearDown(); void SetTokenID(); + void SetCaptureInfo(std::shared_ptr& info); std::shared_ptr client_; std::shared_ptr photoInfo_false_; @@ -189,6 +190,33 @@ void DCameraClientTest::SetTokenID() OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); } +void DCameraClientTest::SetCaptureInfo(std::shared_ptr& info) +{ + 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)); + uint8_t quality = OHOS_CAMERA_JPEG_LEVEL_HIGH; + metaData->addEntry(OHOS_JPEG_QUALITY, &quality, sizeof(quality)); + std::vector gps; + gps.push_back(LATITUDE); + gps.push_back(LONGITUDE); + gps.push_back(ALTITUDE); + metaData->addEntry(OHOS_JPEG_GPS_COORDINATES, gps.data(), gps.size()); + std::string abilityString = Camera::MetadataUtils::EncodeToString(metaData); + std::vector> settings; + auto setting = std::make_shared(); + setting->type_ = UPDATE_METADATA; + setting->value_ = Base64Encode(reinterpret_cast(abilityString.c_str()), + abilityString.length()); + settings.push_back(setting); + info->width_ = TEST_WIDTH; + info->height_ = TEST_HEIGHT; + info->format_ = TEST_FORMAT_PHOTO; + info->isCapture_ = true; + info->streamType_ = SNAPSHOT_FRAME; + info->captureSettings_ = settings; +} + /** * @tc.name: dcamera_client_test_001 * @tc.desc: Verify SetStateCallback @@ -583,31 +611,8 @@ HWTEST_F(DCameraClientTest, dcamera_client_test_013, TestSize.Level1) sleep(TEST_SLEEP_SEC); - 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)); - uint8_t quality = OHOS_CAMERA_JPEG_LEVEL_HIGH; - metaData->addEntry(OHOS_JPEG_QUALITY, &quality, sizeof(quality)); - std::vector gps; - gps.push_back(LATITUDE); - gps.push_back(LONGITUDE); - gps.push_back(ALTITUDE); - metaData->addEntry(OHOS_JPEG_GPS_COORDINATES, gps.data(), gps.size()); - std::string abilityString = Camera::MetadataUtils::EncodeToString(metaData); - std::vector> settings; - auto setting = std::make_shared(); - setting->type_ = UPDATE_METADATA; - setting->value_ = Base64Encode(reinterpret_cast(abilityString.c_str()), - abilityString.length()); - settings.push_back(setting); - auto info = std::make_shared(); - info->width_ = TEST_WIDTH; - info->height_ = TEST_HEIGHT; - info->format_ = TEST_FORMAT_PHOTO; - info->isCapture_ = true; - info->streamType_ = SNAPSHOT_FRAME; - info->captureSettings_ = settings; + SetCaptureInfo(info); ret = client_->StartPhotoOutput(info); EXPECT_EQ(DCAMERA_OK, ret); 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 b207380d..948f7286 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_source_input.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_source_input.cpp @@ -67,17 +67,11 @@ int32_t DCameraSourceInput::ConfigStreams(std::vectorstreamId_, streamInfo->width_, streamInfo->height_, streamInfo->format_, streamInfo->dataspace_, streamInfo->encodeType_, streamInfo->type_); - switch (streamInfo->type_) { - case CONTINUOUS_FRAME: { - continueStreams.push_back(streamInfo); - break; - } - case SNAPSHOT_FRAME: { - snapStreams.push_back(streamInfo); - break; - } - default: - break; + if (streamInfo->type_ == CONTINUOUS_FRAME) { + continueStreams.push_back(streamInfo); + } + if (streamInfo->type_ == SNAPSHOT_FRAME) { + snapStreams.push_back(streamInfo); } } -- Gitee