1094332d3Sopenharmony_ci/* 2094332d3Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License. 5094332d3Sopenharmony_ci * You may obtain a copy of the License at 6094332d3Sopenharmony_ci * 7094332d3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8094332d3Sopenharmony_ci * 9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and 13094332d3Sopenharmony_ci * limitations under the License. 14094332d3Sopenharmony_ci */ 15094332d3Sopenharmony_ci#include "resolution_test.h" 16094332d3Sopenharmony_ci 17094332d3Sopenharmony_ciusing namespace OHOS; 18094332d3Sopenharmony_ciusing namespace std; 19094332d3Sopenharmony_ciusing namespace testing::ext; 20094332d3Sopenharmony_ciusing namespace OHOS::Camera; 21094332d3Sopenharmony_ci 22094332d3Sopenharmony_civoid ResolutionTest::SetUpTestCase(void) {} 23094332d3Sopenharmony_civoid ResolutionTest::TearDownTestCase(void) {} 24094332d3Sopenharmony_civoid ResolutionTest::SetUp(void) 25094332d3Sopenharmony_ci{ 26094332d3Sopenharmony_ci Test_ = std::make_shared<OHOS::Camera::Test>(); 27094332d3Sopenharmony_ci Test_->Init(); 28094332d3Sopenharmony_ci Test_->Open(); 29094332d3Sopenharmony_ci} 30094332d3Sopenharmony_civoid ResolutionTest::TearDown(void) 31094332d3Sopenharmony_ci{ 32094332d3Sopenharmony_ci Test_->Close(); 33094332d3Sopenharmony_ci} 34094332d3Sopenharmony_ci 35094332d3Sopenharmony_ci/** 36094332d3Sopenharmony_ci * @tc.name: preview and capture 37094332d3Sopenharmony_ci * @tc.desc: Preview and still_capture streams, Commit 2 streams together, 38094332d3Sopenharmony_ci * which Preview's resolution is 640 * 480 and Capture's resolution is 1280 * 960 39094332d3Sopenharmony_ci * @tc.size: MediumTest 40094332d3Sopenharmony_ci * @tc.type: Function 41094332d3Sopenharmony_ci */ 42094332d3Sopenharmony_ciHWTEST_F(ResolutionTest, Camera_Resolution_0001, TestSize.Level3) 43094332d3Sopenharmony_ci{ 44094332d3Sopenharmony_ci std::cout << "==========[test log]check Capture: Preview and still_capture streams."; 45094332d3Sopenharmony_ci std::cout << "which Preview's resolution is 640 * 480"; 46094332d3Sopenharmony_ci std::cout << "and Capture's resolution is 1280 * 960" << std::endl; 47094332d3Sopenharmony_ci Test_->CreateStreamOperatorCallback(); 48094332d3Sopenharmony_ci Test_->rc = Test_->cameraDevice->GetStreamOperator(Test_->streamOperatorCallback, Test_->streamOperator); 49094332d3Sopenharmony_ci EXPECT_EQ(true, Test_->rc == Camera::NO_ERROR); 50094332d3Sopenharmony_ci if (Test_->rc == Camera::NO_ERROR) { 51094332d3Sopenharmony_ci std::cout << "==========[test log]GetStreamOperator success." << std::endl; 52094332d3Sopenharmony_ci } else { 53094332d3Sopenharmony_ci std::cout << "==========[test log]GetStreamOperator fail, rc = " << Test_->rc << std::endl; 54094332d3Sopenharmony_ci } 55094332d3Sopenharmony_ci // Configure preview stream information 56094332d3Sopenharmony_ci Test_->streamInfo_pre = std::make_shared<Camera::StreamInfo>(); 57094332d3Sopenharmony_ci Test_->streamInfo_pre->streamId_ = Test_->streamId_preview; 58094332d3Sopenharmony_ci Test_->streamInfo_pre->width_ = 640; // 640:width of stream 59094332d3Sopenharmony_ci Test_->streamInfo_pre->height_ = 480; // 480: height of stream 60094332d3Sopenharmony_ci#ifdef CAMERA_BUILT_ON_OHOS_LITE 61094332d3Sopenharmony_ci Test_->streamInfo_pre->format_ = IMAGE_PIXEL_FORMAT_NV21; 62094332d3Sopenharmony_ci#else 63094332d3Sopenharmony_ci Test_->streamInfo_pre->format_ = PIXEL_FMT_YCRCB_420_SP; 64094332d3Sopenharmony_ci#endif 65094332d3Sopenharmony_ci Test_->streamInfo_pre->dataspace_ = 8; // 8:dataspace of stream 66094332d3Sopenharmony_ci Test_->streamInfo_pre->intent_ = Camera::PREVIEW; 67094332d3Sopenharmony_ci Test_->streamInfo_pre->tunneledMode_ = 5; // 5:tunneledMode of stream 68094332d3Sopenharmony_ci std::shared_ptr<OHOS::Camera::Test::StreamConsumer> preview_consumer = 69094332d3Sopenharmony_ci std::make_shared<OHOS::Camera::Test::StreamConsumer>(); 70094332d3Sopenharmony_ci#ifdef CAMERA_BUILT_ON_OHOS_LITE 71094332d3Sopenharmony_ci Test_->streamInfo_pre->bufferQueue_ = preview_consumer->CreateProducer([this](OHOS::SurfaceBuffer* buffer) { 72094332d3Sopenharmony_ci Test_->SaveYUV("preview", buffer->GetVirAddr(), buffer->GetSize()); 73094332d3Sopenharmony_ci }); 74094332d3Sopenharmony_ci#else 75094332d3Sopenharmony_ci Test_->streamInfo_pre->bufferQueue_ = preview_consumer->CreateProducer([this](void* addr, uint32_t size) { 76094332d3Sopenharmony_ci Test_->SaveYUV("preview", addr, size); 77094332d3Sopenharmony_ci }); 78094332d3Sopenharmony_ci#endif 79094332d3Sopenharmony_ci Test_->streamInfo_pre->bufferQueue_->SetQueueSize(8); // 8:size of bufferQueue 80094332d3Sopenharmony_ci Test_->consumerMap_[Camera::PREVIEW] = preview_consumer; 81094332d3Sopenharmony_ci Test_->streamInfos.push_back(Test_->streamInfo_pre); 82094332d3Sopenharmony_ci // Configure capture stream information 83094332d3Sopenharmony_ci Test_->streamInfo_capture = std::make_shared<Camera::StreamInfo>(); 84094332d3Sopenharmony_ci Test_->streamInfo_capture->streamId_ = Test_->streamId_capture; 85094332d3Sopenharmony_ci Test_->streamInfo_capture->width_ = 1280; // 1280:width of stream 86094332d3Sopenharmony_ci Test_->streamInfo_capture->height_ = 960; // 960: height of stream 87094332d3Sopenharmony_ci#ifdef CAMERA_BUILT_ON_OHOS_LITE 88094332d3Sopenharmony_ci Test_->streamInfo_capture->format_ = IMAGE_PIXEL_FORMAT_NV21; 89094332d3Sopenharmony_ci#else 90094332d3Sopenharmony_ci Test_->streamInfo_capture->format_ = PIXEL_FMT_YCRCB_420_SP; 91094332d3Sopenharmony_ci#endif 92094332d3Sopenharmony_ci Test_->streamInfo_capture->dataspace_ = 8; // 8:dataspace of stream 93094332d3Sopenharmony_ci Test_->streamInfo_capture->intent_ = Camera::STILL_CAPTURE; 94094332d3Sopenharmony_ci Test_->streamInfo_capture->encodeType_ = ENCODE_TYPE_JPEG; 95094332d3Sopenharmony_ci Test_->streamInfo_capture->tunneledMode_ = 5; // 5:tunneledMode of stream 96094332d3Sopenharmony_ci std::shared_ptr<OHOS::Camera::Test::StreamConsumer> consumer_capture = 97094332d3Sopenharmony_ci std::make_shared<OHOS::Camera::Test::StreamConsumer>(); 98094332d3Sopenharmony_ci std::cout << "==========[test log]received a capture buffer ... 1" << std::endl; 99094332d3Sopenharmony_ci#ifdef CAMERA_BUILT_ON_OHOS_LITE 100094332d3Sopenharmony_ci Test_->streamInfo_capture->bufferQueue_ = consumer_capture->CreateProducer([this](OHOS::SurfaceBuffer* buffer) { 101094332d3Sopenharmony_ci Test_->SaveYUV("preview", buffer->GetVirAddr(), buffer->GetSize()); 102094332d3Sopenharmony_ci }); 103094332d3Sopenharmony_ci#else 104094332d3Sopenharmony_ci Test_->streamInfo_capture->bufferQueue_ = consumer_capture->CreateProducer([this](void* addr, uint32_t size) { 105094332d3Sopenharmony_ci Test_->SaveYUV("preview", addr, size); 106094332d3Sopenharmony_ci }); 107094332d3Sopenharmony_ci#endif 108094332d3Sopenharmony_ci Test_->streamInfo_capture->bufferQueue_->SetQueueSize(8); // 8:bufferqueue size 109094332d3Sopenharmony_ci Test_->consumerMap_[Camera::STILL_CAPTURE] = consumer_capture; 110094332d3Sopenharmony_ci Test_->streamInfos.push_back(Test_->streamInfo_capture); 111094332d3Sopenharmony_ci // distribution start 112094332d3Sopenharmony_ci Test_->rc = Test_->streamOperator->CreateStreams(Test_->streamInfos); 113094332d3Sopenharmony_ci EXPECT_EQ(false, Test_->rc != Camera::NO_ERROR); 114094332d3Sopenharmony_ci if (Test_->rc == Camera::NO_ERROR) { 115094332d3Sopenharmony_ci std::cout << "==========[test log]CreateStreams success." << std::endl; 116094332d3Sopenharmony_ci } else { 117094332d3Sopenharmony_ci std::cout << "==========[test log]CreateStreams fail, rc = " << Test_->rc << std::endl; 118094332d3Sopenharmony_ci } 119094332d3Sopenharmony_ci Test_->rc = Test_->streamOperator->CommitStreams(Camera::NORMAL, Test_->ability); 120094332d3Sopenharmony_ci EXPECT_EQ(false, Test_->rc != Camera::NO_ERROR); 121094332d3Sopenharmony_ci if (Test_->rc == Camera::NO_ERROR) { 122094332d3Sopenharmony_ci std::cout << "==========[test log]CommitStreams success." << std::endl; 123094332d3Sopenharmony_ci } else { 124094332d3Sopenharmony_ci std::cout << "==========[test log]CommitStreams fail, rc = " << Test_->rc << std::endl; 125094332d3Sopenharmony_ci } 126094332d3Sopenharmony_ci sleep(2); // 2:The program waits two seconds 127094332d3Sopenharmony_ci std::vector<std::shared_ptr<Camera::StreamInfo>>().swap(Test_->streamInfos); 128094332d3Sopenharmony_ci // Capture preview stream 129094332d3Sopenharmony_ci Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true); 130094332d3Sopenharmony_ci // Capture the capture stream 131094332d3Sopenharmony_ci Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, true); 132094332d3Sopenharmony_ci // post-processing 133094332d3Sopenharmony_ci Test_->captureIds = {Test_->captureId_preview, Test_->captureId_capture}; 134094332d3Sopenharmony_ci Test_->streamIds = {Test_->streamId_preview, Test_->streamId_capture}; 135094332d3Sopenharmony_ci Test_->StopStream(Test_->captureIds, Test_->streamIds); 136094332d3Sopenharmony_ci preview_consumer->StopConsumer(); 137094332d3Sopenharmony_ci consumer_capture->StopConsumer(); 138094332d3Sopenharmony_ci} 139094332d3Sopenharmony_ci 140094332d3Sopenharmony_ci/** 141094332d3Sopenharmony_ci * @tc.name: preview and capture 142094332d3Sopenharmony_ci * @tc.desc: Preview and Video streams, Commit 2 streams together, 143094332d3Sopenharmony_ci * which Preview's resolving power is 853 * 480 and Video's resolving power is 1280 * 720 144094332d3Sopenharmony_ci * @tc.size: MediumTest 145094332d3Sopenharmony_ci * @tc.type: Function 146094332d3Sopenharmony_ci */ 147094332d3Sopenharmony_ciHWTEST_F(ResolutionTest, Camera_Resolution_0002, TestSize.Level3) 148094332d3Sopenharmony_ci{ 149094332d3Sopenharmony_ci std::cout << "==========[test log]check Capture: Preview and Video streams."; 150094332d3Sopenharmony_ci std::cout << "which Preview's resolution is 853 * 480"; 151094332d3Sopenharmony_ci std::cout << "and Video's resolution is 1280 * 720" << std::endl; 152094332d3Sopenharmony_ci Test_->CreateStreamOperatorCallback(); 153094332d3Sopenharmony_ci Test_->rc = Test_->cameraDevice->GetStreamOperator(Test_->streamOperatorCallback, Test_->streamOperator); 154094332d3Sopenharmony_ci EXPECT_EQ(true, Test_->rc == Camera::NO_ERROR); 155094332d3Sopenharmony_ci if (Test_->rc == Camera::NO_ERROR) { 156094332d3Sopenharmony_ci std::cout << "==========[test log]GetStreamOperator success." << std::endl; 157094332d3Sopenharmony_ci } else { 158094332d3Sopenharmony_ci std::cout << "==========[test log]GetStreamOperator fail, rc = " << Test_->rc << std::endl; 159094332d3Sopenharmony_ci } 160094332d3Sopenharmony_ci // Configure preview stream information 161094332d3Sopenharmony_ci Test_->streamInfo_pre = std::make_shared<Camera::StreamInfo>(); 162094332d3Sopenharmony_ci Test_->streamInfo_pre->streamId_ = Test_->streamId_preview; 163094332d3Sopenharmony_ci Test_->streamInfo_pre->width_ = 853; // 853:width of stream 164094332d3Sopenharmony_ci Test_->streamInfo_pre->height_ = 480; // 480: height of stream 165094332d3Sopenharmony_ci#ifdef CAMERA_BUILT_ON_OHOS_LITE 166094332d3Sopenharmony_ci Test_->streamInfo_pre->format_ = IMAGE_PIXEL_FORMAT_NV21; 167094332d3Sopenharmony_ci#else 168094332d3Sopenharmony_ci Test_->streamInfo_pre->format_ = PIXEL_FMT_YCRCB_420_SP; 169094332d3Sopenharmony_ci#endif 170094332d3Sopenharmony_ci Test_->streamInfo_pre->dataspace_ = 8; // 8:dataspace of stream 171094332d3Sopenharmony_ci Test_->streamInfo_pre->intent_ = Camera::PREVIEW; 172094332d3Sopenharmony_ci Test_->streamInfo_pre->tunneledMode_ = 5; // 5:tunneledMode of stream 173094332d3Sopenharmony_ci std::shared_ptr<OHOS::Camera::Test::StreamConsumer> preview_consumer = 174094332d3Sopenharmony_ci std::make_shared<OHOS::Camera::Test::StreamConsumer>(); 175094332d3Sopenharmony_ci std::cout << "==========[test log]received a preview buffer ... 0" << std::endl; 176094332d3Sopenharmony_ci#ifdef CAMERA_BUILT_ON_OHOS_LITE 177094332d3Sopenharmony_ci Test_->streamInfo_pre->bufferQueue_ = preview_consumer->CreateProducer([this](OHOS::SurfaceBuffer* buffer) { 178094332d3Sopenharmony_ci Test_->SaveYUV("preview", buffer->GetVirAddr(), buffer->GetSize()); 179094332d3Sopenharmony_ci }); 180094332d3Sopenharmony_ci#else 181094332d3Sopenharmony_ci Test_->streamInfo_pre->bufferQueue_ = preview_consumer->CreateProducer([this](void* addr, uint32_t size) { 182094332d3Sopenharmony_ci Test_->SaveYUV("preview", addr, size); 183094332d3Sopenharmony_ci }); 184094332d3Sopenharmony_ci#endif 185094332d3Sopenharmony_ci Test_->streamInfo_pre->bufferQueue_->SetQueueSize(8); // 8:size of bufferQueue 186094332d3Sopenharmony_ci Test_->consumerMap_[Camera::PREVIEW] = preview_consumer; 187094332d3Sopenharmony_ci Test_->streamInfos.push_back(Test_->streamInfo_pre); 188094332d3Sopenharmony_ci // Configure video stream information 189094332d3Sopenharmony_ci Test_->streamInfo_video = std::make_shared<Camera::StreamInfo>(); 190094332d3Sopenharmony_ci Test_->streamInfo_video->streamId_ = Test_->streamId_video; 191094332d3Sopenharmony_ci Test_->streamInfo_video->width_ = 1280; // 1280:width of stream 192094332d3Sopenharmony_ci Test_->streamInfo_video->height_ = 720; // 960: height of stream 193094332d3Sopenharmony_ci#ifdef CAMERA_BUILT_ON_OHOS_LITE 194094332d3Sopenharmony_ci Test_->streamInfo_video->format_ = IMAGE_PIXEL_FORMAT_NV21; 195094332d3Sopenharmony_ci#else 196094332d3Sopenharmony_ci Test_->streamInfo_video->format_ = PIXEL_FMT_YCRCB_420_SP; 197094332d3Sopenharmony_ci#endif 198094332d3Sopenharmony_ci Test_->streamInfo_video->dataspace_ = 8; // 8:dataspace of stream 199094332d3Sopenharmony_ci Test_->streamInfo_video->intent_ = Camera::VIDEO; 200094332d3Sopenharmony_ci Test_->streamInfo_video->encodeType_ = ENCODE_TYPE_H265; 201094332d3Sopenharmony_ci Test_->streamInfo_video->tunneledMode_ = 5; // 5:tunneledMode of stream 202094332d3Sopenharmony_ci std::shared_ptr<OHOS::Camera::Test::StreamConsumer> consumer_video = 203094332d3Sopenharmony_ci std::make_shared<OHOS::Camera::Test::StreamConsumer>(); 204094332d3Sopenharmony_ci std::cout << "==========[test log]received a video buffer ... 1" << std::endl; 205094332d3Sopenharmony_ci Test_->SaveVideoFile("video", nullptr, 0, 0); 206094332d3Sopenharmony_ci#ifdef CAMERA_BUILT_ON_OHOS_LITE 207094332d3Sopenharmony_ci Test_->streamInfo_video->bufferQueue_ = consumer_video->CreateProducer([this](OHOS::SurfaceBuffer* buffer) { 208094332d3Sopenharmony_ci Test_->SaveYUV("preview", buffer->GetVirAddr(), buffer->GetSize()); 209094332d3Sopenharmony_ci }); 210094332d3Sopenharmony_ci#else 211094332d3Sopenharmony_ci Test_->streamInfo_video->bufferQueue_ = consumer_video->CreateProducer([this](void* addr, uint32_t size) { 212094332d3Sopenharmony_ci Test_->SaveYUV("preview", addr, size); 213094332d3Sopenharmony_ci }); 214094332d3Sopenharmony_ci#endif 215094332d3Sopenharmony_ci Test_->streamInfo_video->bufferQueue_->SetQueueSize(8); // 8:bufferqueue size 216094332d3Sopenharmony_ci Test_->consumerMap_[Camera::VIDEO] = consumer_video; 217094332d3Sopenharmony_ci Test_->streamInfos.push_back(Test_->streamInfo_video); 218094332d3Sopenharmony_ci // distribution start 219094332d3Sopenharmony_ci Test_->rc = Test_->streamOperator->CreateStreams(Test_->streamInfos); 220094332d3Sopenharmony_ci EXPECT_EQ(false, Test_->rc != Camera::NO_ERROR); 221094332d3Sopenharmony_ci if (Test_->rc == Camera::NO_ERROR) { 222094332d3Sopenharmony_ci std::cout << "==========[test log]CreateStreams success." << std::endl; 223094332d3Sopenharmony_ci } else { 224094332d3Sopenharmony_ci std::cout << "==========[test log]CreateStreams fail, rc = " << Test_->rc << std::endl; 225094332d3Sopenharmony_ci } 226094332d3Sopenharmony_ci Test_->rc = Test_->streamOperator->CommitStreams(Camera::NORMAL, Test_->ability); 227094332d3Sopenharmony_ci EXPECT_EQ(false, Test_->rc != Camera::NO_ERROR); 228094332d3Sopenharmony_ci if (Test_->rc == Camera::NO_ERROR) { 229094332d3Sopenharmony_ci std::cout << "==========[test log]CommitStreams success." << std::endl; 230094332d3Sopenharmony_ci } else { 231094332d3Sopenharmony_ci std::cout << "==========[test log]CommitStreams fail, rc = " << Test_->rc << std::endl; 232094332d3Sopenharmony_ci } 233094332d3Sopenharmony_ci sleep(2); // 2:The program waits two seconds 234094332d3Sopenharmony_ci std::vector<std::shared_ptr<Camera::StreamInfo>>().swap(Test_->streamInfos); 235094332d3Sopenharmony_ci // Capture preview stream 236094332d3Sopenharmony_ci Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true); 237094332d3Sopenharmony_ci // Capture video stream,Continuous capture 238094332d3Sopenharmony_ci Test_->StartCapture(Test_->streamId_video, Test_->captureId_video, false, true); 239094332d3Sopenharmony_ci // post-processing 240094332d3Sopenharmony_ci Test_->captureIds = {Test_->captureId_preview, Test_->captureId_video}; 241094332d3Sopenharmony_ci Test_->streamIds = {Test_->streamId_preview, Test_->streamId_video}; 242094332d3Sopenharmony_ci Test_->StopStream(Test_->captureIds, Test_->streamIds); 243094332d3Sopenharmony_ci preview_consumer->StopConsumer(); 244094332d3Sopenharmony_ci consumer_video->StopConsumer(); 245094332d3Sopenharmony_ci} 246094332d3Sopenharmony_ci 247094332d3Sopenharmony_ci/** 248094332d3Sopenharmony_ci * @tc.name: preview and capture 249094332d3Sopenharmony_ci * @tc.desc: Preview and Video streams, Commit 2 streams together, 250094332d3Sopenharmony_ci * which Preview's resolving power is 640 * 360 and Video's resolving power is 1280 * 720 251094332d3Sopenharmony_ci * @tc.size: MediumTest 252094332d3Sopenharmony_ci * @tc.type: Function 253094332d3Sopenharmony_ci */ 254094332d3Sopenharmony_ciHWTEST_F(ResolutionTest, Camera_Resolution_0003, TestSize.Level3) 255094332d3Sopenharmony_ci{ 256094332d3Sopenharmony_ci std::cout << "==========[test log]check Capture: Preview and Video streams."; 257094332d3Sopenharmony_ci std::cout << "which Preview's resolution is 640 * 360"; 258094332d3Sopenharmony_ci std::cout << "and Video's resolution is 1280 * 720" << std::endl; 259094332d3Sopenharmony_ci Test_->CreateStreamOperatorCallback(); 260094332d3Sopenharmony_ci Test_->rc = Test_->cameraDevice->GetStreamOperator(Test_->streamOperatorCallback, Test_->streamOperator); 261094332d3Sopenharmony_ci EXPECT_EQ(true, Test_->rc == Camera::NO_ERROR); 262094332d3Sopenharmony_ci if (Test_->rc == Camera::NO_ERROR) { 263094332d3Sopenharmony_ci std::cout << "==========[test log]GetStreamOperator success." << std::endl; 264094332d3Sopenharmony_ci } else { 265094332d3Sopenharmony_ci std::cout << "==========[test log]GetStreamOperator fail, rc = " << Test_->rc << std::endl; 266094332d3Sopenharmony_ci } 267094332d3Sopenharmony_ci // Configure preview stream information 268094332d3Sopenharmony_ci Test_->streamInfo_pre = std::make_shared<Camera::StreamInfo>(); 269094332d3Sopenharmony_ci Test_->streamInfo_pre->streamId_ = Test_->streamId_preview; 270094332d3Sopenharmony_ci Test_->streamInfo_pre->width_ = 640; // 640:width of stream 271094332d3Sopenharmony_ci Test_->streamInfo_pre->height_ = 360; // 360: height of stream 272094332d3Sopenharmony_ci#ifdef CAMERA_BUILT_ON_OHOS_LITE 273094332d3Sopenharmony_ci Test_->streamInfo_pre->format_ = IMAGE_PIXEL_FORMAT_NV21; 274094332d3Sopenharmony_ci#else 275094332d3Sopenharmony_ci Test_->streamInfo_pre->format_ = PIXEL_FMT_YCRCB_420_SP; 276094332d3Sopenharmony_ci#endif 277094332d3Sopenharmony_ci Test_->streamInfo_pre->dataspace_ = 8; // 8:dataspace of stream 278094332d3Sopenharmony_ci Test_->streamInfo_pre->intent_ = Camera::PREVIEW; 279094332d3Sopenharmony_ci Test_->streamInfo_pre->tunneledMode_ = 5; // 5:tunneledMode of stream 280094332d3Sopenharmony_ci std::shared_ptr<OHOS::Camera::Test::StreamConsumer> preview_consumer = 281094332d3Sopenharmony_ci std::make_shared<OHOS::Camera::Test::StreamConsumer>(); 282094332d3Sopenharmony_ci std::cout << "==========[test log]received a preview buffer ... 0" << std::endl; 283094332d3Sopenharmony_ci#ifdef CAMERA_BUILT_ON_OHOS_LITE 284094332d3Sopenharmony_ci Test_->streamInfo_pre->bufferQueue_ = preview_consumer->CreateProducer([this](OHOS::SurfaceBuffer* buffer) { 285094332d3Sopenharmony_ci Test_->SaveYUV("preview", buffer->GetVirAddr(), buffer->GetSize()); 286094332d3Sopenharmony_ci }); 287094332d3Sopenharmony_ci#else 288094332d3Sopenharmony_ci Test_->streamInfo_pre->bufferQueue_ = preview_consumer->CreateProducer([this](void* addr, uint32_t size) { 289094332d3Sopenharmony_ci Test_->SaveYUV("preview", addr, size); 290094332d3Sopenharmony_ci }); 291094332d3Sopenharmony_ci#endif 292094332d3Sopenharmony_ci Test_->streamInfo_pre->bufferQueue_->SetQueueSize(8); // 8:size of bufferQueue 293094332d3Sopenharmony_ci Test_->consumerMap_[Camera::PREVIEW] = preview_consumer; 294094332d3Sopenharmony_ci Test_->streamInfos.push_back(Test_->streamInfo_pre); 295094332d3Sopenharmony_ci // Configure video stream information 296094332d3Sopenharmony_ci Test_->streamInfo_video = std::make_shared<Camera::StreamInfo>(); 297094332d3Sopenharmony_ci Test_->streamInfo_video->streamId_ = Test_->streamId_video; 298094332d3Sopenharmony_ci Test_->streamInfo_video->width_ = 1280; // 1280:width of stream 299094332d3Sopenharmony_ci Test_->streamInfo_video->height_ = 720; // 960: height of stream 300094332d3Sopenharmony_ci#ifdef CAMERA_BUILT_ON_OHOS_LITE 301094332d3Sopenharmony_ci Test_->streamInfo_video->format_ = IMAGE_PIXEL_FORMAT_NV21; 302094332d3Sopenharmony_ci#else 303094332d3Sopenharmony_ci Test_->streamInfo_video->format_ = PIXEL_FMT_YCRCB_420_SP; 304094332d3Sopenharmony_ci#endif 305094332d3Sopenharmony_ci Test_->streamInfo_video->dataspace_ = 8; // 8:dataspace of stream 306094332d3Sopenharmony_ci Test_->streamInfo_video->intent_ = Camera::VIDEO; 307094332d3Sopenharmony_ci Test_->streamInfo_video->encodeType_ = ENCODE_TYPE_H265; 308094332d3Sopenharmony_ci Test_->streamInfo_video->tunneledMode_ = 5; // 5:tunneledMode of stream 309094332d3Sopenharmony_ci std::shared_ptr<OHOS::Camera::Test::StreamConsumer> consumer_video = 310094332d3Sopenharmony_ci std::make_shared<OHOS::Camera::Test::StreamConsumer>(); 311094332d3Sopenharmony_ci std::cout << "==========[test log]received a video buffer ... 1" << std::endl; 312094332d3Sopenharmony_ci Test_->SaveVideoFile("video", nullptr, 0, 0); 313094332d3Sopenharmony_ci#ifdef CAMERA_BUILT_ON_OHOS_LITE 314094332d3Sopenharmony_ci Test_->streamInfo_video->bufferQueue_ = consumer_video->CreateProducer([this](OHOS::SurfaceBuffer* buffer) { 315094332d3Sopenharmony_ci Test_->SaveYUV("preview", buffer->GetVirAddr(), buffer->GetSize()); 316094332d3Sopenharmony_ci }); 317094332d3Sopenharmony_ci#else 318094332d3Sopenharmony_ci Test_->streamInfo_video->bufferQueue_ = consumer_video->CreateProducer([this](void* addr, uint32_t size) { 319094332d3Sopenharmony_ci Test_->SaveYUV("preview", addr, size); 320094332d3Sopenharmony_ci }); 321094332d3Sopenharmony_ci#endif 322094332d3Sopenharmony_ci Test_->streamInfo_video->bufferQueue_->SetQueueSize(8); // 8:bufferqueue size 323094332d3Sopenharmony_ci Test_->consumerMap_[Camera::VIDEO] = consumer_video; 324094332d3Sopenharmony_ci Test_->streamInfos.push_back(Test_->streamInfo_video); 325094332d3Sopenharmony_ci // distribution start 326094332d3Sopenharmony_ci Test_->rc = Test_->streamOperator->CreateStreams(Test_->streamInfos); 327094332d3Sopenharmony_ci EXPECT_EQ(false, Test_->rc != Camera::NO_ERROR); 328094332d3Sopenharmony_ci if (Test_->rc == Camera::NO_ERROR) { 329094332d3Sopenharmony_ci std::cout << "==========[test log]CreateStreams success." << std::endl; 330094332d3Sopenharmony_ci } else { 331094332d3Sopenharmony_ci std::cout << "==========[test log]CreateStreams fail, rc = " << Test_->rc << std::endl; 332094332d3Sopenharmony_ci } 333094332d3Sopenharmony_ci Test_->rc = Test_->streamOperator->CommitStreams(Camera::NORMAL, Test_->ability); 334094332d3Sopenharmony_ci EXPECT_EQ(false, Test_->rc != Camera::NO_ERROR); 335094332d3Sopenharmony_ci if (Test_->rc == Camera::NO_ERROR) { 336094332d3Sopenharmony_ci std::cout << "==========[test log]CommitStreams success." << std::endl; 337094332d3Sopenharmony_ci } else { 338094332d3Sopenharmony_ci std::cout << "==========[test log]CommitStreams fail, rc = " << Test_->rc << std::endl; 339094332d3Sopenharmony_ci } 340094332d3Sopenharmony_ci sleep(2); // 2:The program waits two seconds 341094332d3Sopenharmony_ci std::vector<std::shared_ptr<Camera::StreamInfo>>().swap(Test_->streamInfos); 342094332d3Sopenharmony_ci // Capture preview stream 343094332d3Sopenharmony_ci Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true); 344094332d3Sopenharmony_ci // Capture video stream,Continuous capture 345094332d3Sopenharmony_ci Test_->StartCapture(Test_->streamId_video, Test_->captureId_video, false, true); 346094332d3Sopenharmony_ci // post-processing 347094332d3Sopenharmony_ci Test_->captureIds = {Test_->captureId_preview, Test_->captureId_video}; 348094332d3Sopenharmony_ci Test_->streamIds = {Test_->streamId_preview, Test_->streamId_video}; 349094332d3Sopenharmony_ci Test_->StopStream(Test_->captureIds, Test_->streamIds); 350094332d3Sopenharmony_ci preview_consumer->StopConsumer(); 351094332d3Sopenharmony_ci consumer_video->StopConsumer(); 352094332d3Sopenharmony_ci}