diff --git a/services/cameraservice/cameraoperator/client/include/dcamera_client.h b/services/cameraservice/cameraoperator/client/include/dcamera_client.h index 7632baa6e18ebf716c76aa632528a76264116c03..d1a915d2daca117c94a6ba5d1fd32be36361c9de 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 bfa8143e5c9d5e11f157868f47973b863327df9b..fe6710072f460ab12b4b587792e6576d9ef88492 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 f28d0c2aa017e1e81c38d9229d000e4d34d4c553..da6e8d78d1ef4e74760fbd618e29994479f6da28 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 11508f4d1f916edd254fbf723d1c92b1099e4f66..898213792aaa5f45d1100bbc8c780364ca4b3e8a 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 b207380dd7d1994427a4a1b4e4a66acbbdf14947..948f7286783d049c338977ece9a12ea2953dece3 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); } }