1/* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15#include "resolution_test.h" 16 17using namespace OHOS; 18using namespace std; 19using namespace testing::ext; 20using namespace OHOS::Camera; 21 22void ResolutionTest::SetUpTestCase(void) {} 23void ResolutionTest::TearDownTestCase(void) {} 24void ResolutionTest::SetUp(void) 25{ 26 Test_ = std::make_shared<OHOS::Camera::Test>(); 27 Test_->Init(); 28 Test_->Open(); 29} 30void ResolutionTest::TearDown(void) 31{ 32 Test_->Close(); 33} 34 35/** 36 * @tc.name: preview and capture 37 * @tc.desc: Preview and still_capture streams, Commit 2 streams together, 38 * which Preview's resolution is 640 * 480 and Capture's resolution is 1280 * 960 39 * @tc.size: MediumTest 40 * @tc.type: Function 41 */ 42HWTEST_F(ResolutionTest, Camera_Resolution_0001, TestSize.Level3) 43{ 44 std::cout << "==========[test log]check Capture: Preview and still_capture streams."; 45 std::cout << "which Preview's resolution is 640 * 480"; 46 std::cout << "and Capture's resolution is 1280 * 960" << std::endl; 47 Test_->CreateStreamOperatorCallback(); 48 Test_->rc = Test_->cameraDevice->GetStreamOperator(Test_->streamOperatorCallback, Test_->streamOperator); 49 EXPECT_EQ(true, Test_->rc == Camera::NO_ERROR); 50 if (Test_->rc == Camera::NO_ERROR) { 51 std::cout << "==========[test log]GetStreamOperator success." << std::endl; 52 } else { 53 std::cout << "==========[test log]GetStreamOperator fail, rc = " << Test_->rc << std::endl; 54 } 55 // Configure preview stream information 56 Test_->streamInfo_pre = std::make_shared<Camera::StreamInfo>(); 57 Test_->streamInfo_pre->streamId_ = Test_->streamId_preview; 58 Test_->streamInfo_pre->width_ = 640; // 640:width of stream 59 Test_->streamInfo_pre->height_ = 480; // 480: height of stream 60#ifdef CAMERA_BUILT_ON_OHOS_LITE 61 Test_->streamInfo_pre->format_ = IMAGE_PIXEL_FORMAT_NV21; 62#else 63 Test_->streamInfo_pre->format_ = PIXEL_FMT_YCRCB_420_SP; 64#endif 65 Test_->streamInfo_pre->dataspace_ = 8; // 8:dataspace of stream 66 Test_->streamInfo_pre->intent_ = Camera::PREVIEW; 67 Test_->streamInfo_pre->tunneledMode_ = 5; // 5:tunneledMode of stream 68 std::shared_ptr<OHOS::Camera::Test::StreamConsumer> preview_consumer = 69 std::make_shared<OHOS::Camera::Test::StreamConsumer>(); 70#ifdef CAMERA_BUILT_ON_OHOS_LITE 71 Test_->streamInfo_pre->bufferQueue_ = preview_consumer->CreateProducer([this](OHOS::SurfaceBuffer* buffer) { 72 Test_->SaveYUV("preview", buffer->GetVirAddr(), buffer->GetSize()); 73 }); 74#else 75 Test_->streamInfo_pre->bufferQueue_ = preview_consumer->CreateProducer([this](void* addr, uint32_t size) { 76 Test_->SaveYUV("preview", addr, size); 77 }); 78#endif 79 Test_->streamInfo_pre->bufferQueue_->SetQueueSize(8); // 8:size of bufferQueue 80 Test_->consumerMap_[Camera::PREVIEW] = preview_consumer; 81 Test_->streamInfos.push_back(Test_->streamInfo_pre); 82 // Configure capture stream information 83 Test_->streamInfo_capture = std::make_shared<Camera::StreamInfo>(); 84 Test_->streamInfo_capture->streamId_ = Test_->streamId_capture; 85 Test_->streamInfo_capture->width_ = 1280; // 1280:width of stream 86 Test_->streamInfo_capture->height_ = 960; // 960: height of stream 87#ifdef CAMERA_BUILT_ON_OHOS_LITE 88 Test_->streamInfo_capture->format_ = IMAGE_PIXEL_FORMAT_NV21; 89#else 90 Test_->streamInfo_capture->format_ = PIXEL_FMT_YCRCB_420_SP; 91#endif 92 Test_->streamInfo_capture->dataspace_ = 8; // 8:dataspace of stream 93 Test_->streamInfo_capture->intent_ = Camera::STILL_CAPTURE; 94 Test_->streamInfo_capture->encodeType_ = ENCODE_TYPE_JPEG; 95 Test_->streamInfo_capture->tunneledMode_ = 5; // 5:tunneledMode of stream 96 std::shared_ptr<OHOS::Camera::Test::StreamConsumer> consumer_capture = 97 std::make_shared<OHOS::Camera::Test::StreamConsumer>(); 98 std::cout << "==========[test log]received a capture buffer ... 1" << std::endl; 99#ifdef CAMERA_BUILT_ON_OHOS_LITE 100 Test_->streamInfo_capture->bufferQueue_ = consumer_capture->CreateProducer([this](OHOS::SurfaceBuffer* buffer) { 101 Test_->SaveYUV("preview", buffer->GetVirAddr(), buffer->GetSize()); 102 }); 103#else 104 Test_->streamInfo_capture->bufferQueue_ = consumer_capture->CreateProducer([this](void* addr, uint32_t size) { 105 Test_->SaveYUV("preview", addr, size); 106 }); 107#endif 108 Test_->streamInfo_capture->bufferQueue_->SetQueueSize(8); // 8:bufferqueue size 109 Test_->consumerMap_[Camera::STILL_CAPTURE] = consumer_capture; 110 Test_->streamInfos.push_back(Test_->streamInfo_capture); 111 // distribution start 112 Test_->rc = Test_->streamOperator->CreateStreams(Test_->streamInfos); 113 EXPECT_EQ(false, Test_->rc != Camera::NO_ERROR); 114 if (Test_->rc == Camera::NO_ERROR) { 115 std::cout << "==========[test log]CreateStreams success." << std::endl; 116 } else { 117 std::cout << "==========[test log]CreateStreams fail, rc = " << Test_->rc << std::endl; 118 } 119 Test_->rc = Test_->streamOperator->CommitStreams(Camera::NORMAL, Test_->ability); 120 EXPECT_EQ(false, Test_->rc != Camera::NO_ERROR); 121 if (Test_->rc == Camera::NO_ERROR) { 122 std::cout << "==========[test log]CommitStreams success." << std::endl; 123 } else { 124 std::cout << "==========[test log]CommitStreams fail, rc = " << Test_->rc << std::endl; 125 } 126 sleep(2); // 2:The program waits two seconds 127 std::vector<std::shared_ptr<Camera::StreamInfo>>().swap(Test_->streamInfos); 128 // Capture preview stream 129 Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true); 130 // Capture the capture stream 131 Test_->StartCapture(Test_->streamId_capture, Test_->captureId_capture, false, true); 132 // post-processing 133 Test_->captureIds = {Test_->captureId_preview, Test_->captureId_capture}; 134 Test_->streamIds = {Test_->streamId_preview, Test_->streamId_capture}; 135 Test_->StopStream(Test_->captureIds, Test_->streamIds); 136 preview_consumer->StopConsumer(); 137 consumer_capture->StopConsumer(); 138} 139 140/** 141 * @tc.name: preview and capture 142 * @tc.desc: Preview and Video streams, Commit 2 streams together, 143 * which Preview's resolving power is 853 * 480 and Video's resolving power is 1280 * 720 144 * @tc.size: MediumTest 145 * @tc.type: Function 146 */ 147HWTEST_F(ResolutionTest, Camera_Resolution_0002, TestSize.Level3) 148{ 149 std::cout << "==========[test log]check Capture: Preview and Video streams."; 150 std::cout << "which Preview's resolution is 853 * 480"; 151 std::cout << "and Video's resolution is 1280 * 720" << std::endl; 152 Test_->CreateStreamOperatorCallback(); 153 Test_->rc = Test_->cameraDevice->GetStreamOperator(Test_->streamOperatorCallback, Test_->streamOperator); 154 EXPECT_EQ(true, Test_->rc == Camera::NO_ERROR); 155 if (Test_->rc == Camera::NO_ERROR) { 156 std::cout << "==========[test log]GetStreamOperator success." << std::endl; 157 } else { 158 std::cout << "==========[test log]GetStreamOperator fail, rc = " << Test_->rc << std::endl; 159 } 160 // Configure preview stream information 161 Test_->streamInfo_pre = std::make_shared<Camera::StreamInfo>(); 162 Test_->streamInfo_pre->streamId_ = Test_->streamId_preview; 163 Test_->streamInfo_pre->width_ = 853; // 853:width of stream 164 Test_->streamInfo_pre->height_ = 480; // 480: height of stream 165#ifdef CAMERA_BUILT_ON_OHOS_LITE 166 Test_->streamInfo_pre->format_ = IMAGE_PIXEL_FORMAT_NV21; 167#else 168 Test_->streamInfo_pre->format_ = PIXEL_FMT_YCRCB_420_SP; 169#endif 170 Test_->streamInfo_pre->dataspace_ = 8; // 8:dataspace of stream 171 Test_->streamInfo_pre->intent_ = Camera::PREVIEW; 172 Test_->streamInfo_pre->tunneledMode_ = 5; // 5:tunneledMode of stream 173 std::shared_ptr<OHOS::Camera::Test::StreamConsumer> preview_consumer = 174 std::make_shared<OHOS::Camera::Test::StreamConsumer>(); 175 std::cout << "==========[test log]received a preview buffer ... 0" << std::endl; 176#ifdef CAMERA_BUILT_ON_OHOS_LITE 177 Test_->streamInfo_pre->bufferQueue_ = preview_consumer->CreateProducer([this](OHOS::SurfaceBuffer* buffer) { 178 Test_->SaveYUV("preview", buffer->GetVirAddr(), buffer->GetSize()); 179 }); 180#else 181 Test_->streamInfo_pre->bufferQueue_ = preview_consumer->CreateProducer([this](void* addr, uint32_t size) { 182 Test_->SaveYUV("preview", addr, size); 183 }); 184#endif 185 Test_->streamInfo_pre->bufferQueue_->SetQueueSize(8); // 8:size of bufferQueue 186 Test_->consumerMap_[Camera::PREVIEW] = preview_consumer; 187 Test_->streamInfos.push_back(Test_->streamInfo_pre); 188 // Configure video stream information 189 Test_->streamInfo_video = std::make_shared<Camera::StreamInfo>(); 190 Test_->streamInfo_video->streamId_ = Test_->streamId_video; 191 Test_->streamInfo_video->width_ = 1280; // 1280:width of stream 192 Test_->streamInfo_video->height_ = 720; // 960: height of stream 193#ifdef CAMERA_BUILT_ON_OHOS_LITE 194 Test_->streamInfo_video->format_ = IMAGE_PIXEL_FORMAT_NV21; 195#else 196 Test_->streamInfo_video->format_ = PIXEL_FMT_YCRCB_420_SP; 197#endif 198 Test_->streamInfo_video->dataspace_ = 8; // 8:dataspace of stream 199 Test_->streamInfo_video->intent_ = Camera::VIDEO; 200 Test_->streamInfo_video->encodeType_ = ENCODE_TYPE_H265; 201 Test_->streamInfo_video->tunneledMode_ = 5; // 5:tunneledMode of stream 202 std::shared_ptr<OHOS::Camera::Test::StreamConsumer> consumer_video = 203 std::make_shared<OHOS::Camera::Test::StreamConsumer>(); 204 std::cout << "==========[test log]received a video buffer ... 1" << std::endl; 205 Test_->SaveVideoFile("video", nullptr, 0, 0); 206#ifdef CAMERA_BUILT_ON_OHOS_LITE 207 Test_->streamInfo_video->bufferQueue_ = consumer_video->CreateProducer([this](OHOS::SurfaceBuffer* buffer) { 208 Test_->SaveYUV("preview", buffer->GetVirAddr(), buffer->GetSize()); 209 }); 210#else 211 Test_->streamInfo_video->bufferQueue_ = consumer_video->CreateProducer([this](void* addr, uint32_t size) { 212 Test_->SaveYUV("preview", addr, size); 213 }); 214#endif 215 Test_->streamInfo_video->bufferQueue_->SetQueueSize(8); // 8:bufferqueue size 216 Test_->consumerMap_[Camera::VIDEO] = consumer_video; 217 Test_->streamInfos.push_back(Test_->streamInfo_video); 218 // distribution start 219 Test_->rc = Test_->streamOperator->CreateStreams(Test_->streamInfos); 220 EXPECT_EQ(false, Test_->rc != Camera::NO_ERROR); 221 if (Test_->rc == Camera::NO_ERROR) { 222 std::cout << "==========[test log]CreateStreams success." << std::endl; 223 } else { 224 std::cout << "==========[test log]CreateStreams fail, rc = " << Test_->rc << std::endl; 225 } 226 Test_->rc = Test_->streamOperator->CommitStreams(Camera::NORMAL, Test_->ability); 227 EXPECT_EQ(false, Test_->rc != Camera::NO_ERROR); 228 if (Test_->rc == Camera::NO_ERROR) { 229 std::cout << "==========[test log]CommitStreams success." << std::endl; 230 } else { 231 std::cout << "==========[test log]CommitStreams fail, rc = " << Test_->rc << std::endl; 232 } 233 sleep(2); // 2:The program waits two seconds 234 std::vector<std::shared_ptr<Camera::StreamInfo>>().swap(Test_->streamInfos); 235 // Capture preview stream 236 Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true); 237 // Capture video stream,Continuous capture 238 Test_->StartCapture(Test_->streamId_video, Test_->captureId_video, false, true); 239 // post-processing 240 Test_->captureIds = {Test_->captureId_preview, Test_->captureId_video}; 241 Test_->streamIds = {Test_->streamId_preview, Test_->streamId_video}; 242 Test_->StopStream(Test_->captureIds, Test_->streamIds); 243 preview_consumer->StopConsumer(); 244 consumer_video->StopConsumer(); 245} 246 247/** 248 * @tc.name: preview and capture 249 * @tc.desc: Preview and Video streams, Commit 2 streams together, 250 * which Preview's resolving power is 640 * 360 and Video's resolving power is 1280 * 720 251 * @tc.size: MediumTest 252 * @tc.type: Function 253 */ 254HWTEST_F(ResolutionTest, Camera_Resolution_0003, TestSize.Level3) 255{ 256 std::cout << "==========[test log]check Capture: Preview and Video streams."; 257 std::cout << "which Preview's resolution is 640 * 360"; 258 std::cout << "and Video's resolution is 1280 * 720" << std::endl; 259 Test_->CreateStreamOperatorCallback(); 260 Test_->rc = Test_->cameraDevice->GetStreamOperator(Test_->streamOperatorCallback, Test_->streamOperator); 261 EXPECT_EQ(true, Test_->rc == Camera::NO_ERROR); 262 if (Test_->rc == Camera::NO_ERROR) { 263 std::cout << "==========[test log]GetStreamOperator success." << std::endl; 264 } else { 265 std::cout << "==========[test log]GetStreamOperator fail, rc = " << Test_->rc << std::endl; 266 } 267 // Configure preview stream information 268 Test_->streamInfo_pre = std::make_shared<Camera::StreamInfo>(); 269 Test_->streamInfo_pre->streamId_ = Test_->streamId_preview; 270 Test_->streamInfo_pre->width_ = 640; // 640:width of stream 271 Test_->streamInfo_pre->height_ = 360; // 360: height of stream 272#ifdef CAMERA_BUILT_ON_OHOS_LITE 273 Test_->streamInfo_pre->format_ = IMAGE_PIXEL_FORMAT_NV21; 274#else 275 Test_->streamInfo_pre->format_ = PIXEL_FMT_YCRCB_420_SP; 276#endif 277 Test_->streamInfo_pre->dataspace_ = 8; // 8:dataspace of stream 278 Test_->streamInfo_pre->intent_ = Camera::PREVIEW; 279 Test_->streamInfo_pre->tunneledMode_ = 5; // 5:tunneledMode of stream 280 std::shared_ptr<OHOS::Camera::Test::StreamConsumer> preview_consumer = 281 std::make_shared<OHOS::Camera::Test::StreamConsumer>(); 282 std::cout << "==========[test log]received a preview buffer ... 0" << std::endl; 283#ifdef CAMERA_BUILT_ON_OHOS_LITE 284 Test_->streamInfo_pre->bufferQueue_ = preview_consumer->CreateProducer([this](OHOS::SurfaceBuffer* buffer) { 285 Test_->SaveYUV("preview", buffer->GetVirAddr(), buffer->GetSize()); 286 }); 287#else 288 Test_->streamInfo_pre->bufferQueue_ = preview_consumer->CreateProducer([this](void* addr, uint32_t size) { 289 Test_->SaveYUV("preview", addr, size); 290 }); 291#endif 292 Test_->streamInfo_pre->bufferQueue_->SetQueueSize(8); // 8:size of bufferQueue 293 Test_->consumerMap_[Camera::PREVIEW] = preview_consumer; 294 Test_->streamInfos.push_back(Test_->streamInfo_pre); 295 // Configure video stream information 296 Test_->streamInfo_video = std::make_shared<Camera::StreamInfo>(); 297 Test_->streamInfo_video->streamId_ = Test_->streamId_video; 298 Test_->streamInfo_video->width_ = 1280; // 1280:width of stream 299 Test_->streamInfo_video->height_ = 720; // 960: height of stream 300#ifdef CAMERA_BUILT_ON_OHOS_LITE 301 Test_->streamInfo_video->format_ = IMAGE_PIXEL_FORMAT_NV21; 302#else 303 Test_->streamInfo_video->format_ = PIXEL_FMT_YCRCB_420_SP; 304#endif 305 Test_->streamInfo_video->dataspace_ = 8; // 8:dataspace of stream 306 Test_->streamInfo_video->intent_ = Camera::VIDEO; 307 Test_->streamInfo_video->encodeType_ = ENCODE_TYPE_H265; 308 Test_->streamInfo_video->tunneledMode_ = 5; // 5:tunneledMode of stream 309 std::shared_ptr<OHOS::Camera::Test::StreamConsumer> consumer_video = 310 std::make_shared<OHOS::Camera::Test::StreamConsumer>(); 311 std::cout << "==========[test log]received a video buffer ... 1" << std::endl; 312 Test_->SaveVideoFile("video", nullptr, 0, 0); 313#ifdef CAMERA_BUILT_ON_OHOS_LITE 314 Test_->streamInfo_video->bufferQueue_ = consumer_video->CreateProducer([this](OHOS::SurfaceBuffer* buffer) { 315 Test_->SaveYUV("preview", buffer->GetVirAddr(), buffer->GetSize()); 316 }); 317#else 318 Test_->streamInfo_video->bufferQueue_ = consumer_video->CreateProducer([this](void* addr, uint32_t size) { 319 Test_->SaveYUV("preview", addr, size); 320 }); 321#endif 322 Test_->streamInfo_video->bufferQueue_->SetQueueSize(8); // 8:bufferqueue size 323 Test_->consumerMap_[Camera::VIDEO] = consumer_video; 324 Test_->streamInfos.push_back(Test_->streamInfo_video); 325 // distribution start 326 Test_->rc = Test_->streamOperator->CreateStreams(Test_->streamInfos); 327 EXPECT_EQ(false, Test_->rc != Camera::NO_ERROR); 328 if (Test_->rc == Camera::NO_ERROR) { 329 std::cout << "==========[test log]CreateStreams success." << std::endl; 330 } else { 331 std::cout << "==========[test log]CreateStreams fail, rc = " << Test_->rc << std::endl; 332 } 333 Test_->rc = Test_->streamOperator->CommitStreams(Camera::NORMAL, Test_->ability); 334 EXPECT_EQ(false, Test_->rc != Camera::NO_ERROR); 335 if (Test_->rc == Camera::NO_ERROR) { 336 std::cout << "==========[test log]CommitStreams success." << std::endl; 337 } else { 338 std::cout << "==========[test log]CommitStreams fail, rc = " << Test_->rc << std::endl; 339 } 340 sleep(2); // 2:The program waits two seconds 341 std::vector<std::shared_ptr<Camera::StreamInfo>>().swap(Test_->streamInfos); 342 // Capture preview stream 343 Test_->StartCapture(Test_->streamId_preview, Test_->captureId_preview, false, true); 344 // Capture video stream,Continuous capture 345 Test_->StartCapture(Test_->streamId_video, Test_->captureId_video, false, true); 346 // post-processing 347 Test_->captureIds = {Test_->captureId_preview, Test_->captureId_video}; 348 Test_->streamIds = {Test_->streamId_preview, Test_->streamId_video}; 349 Test_->StopStream(Test_->captureIds, Test_->streamIds); 350 preview_consumer->StopConsumer(); 351 consumer_video->StopConsumer(); 352}