• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2023 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 
16 #include <unistd.h>
17 #include <iostream>
18 #include <string>
19 #include "input/camera_input.h"
20 #include "input/camera_manager.h"
21 #include "output/camera_output_capability.h"
22 
23 #include "camera_log.h"
24 #include "surface.h"
25 #include "test_common.h"
26 
27 #include "ipc_skeleton.h"
28 #include "access_token.h"
29 #include "hap_token_info.h"
30 #include "accesstoken_kit.h"
31 #include "nativetoken_kit.h"
32 #include "token_setproc.h"
33 #include "camera_utils_stub.h"
34 using namespace std;
35 using namespace OHOS;
36 using namespace OHOS::CameraStandard;
37 
ConfigPhotoCaptureSetting()38 static std::shared_ptr<PhotoCaptureSetting> ConfigPhotoCaptureSetting()
39 {
40     std::shared_ptr<PhotoCaptureSetting> photoCaptureSettings = std::make_shared<PhotoCaptureSetting>();
41     // QualityLevel
42     PhotoCaptureSetting::QualityLevel quality = PhotoCaptureSetting::QualityLevel::QUALITY_LEVEL_HIGH;
43     photoCaptureSettings->SetQuality(quality);
44     return photoCaptureSettings;
45 }
46 
47 std::map<PortraitEffect, camera_portrait_effect_type_t> g_fwToMetaPortraitEffect_ = {
48     {OFF_EFFECT, OHOS_CAMERA_PORTRAIT_EFFECT_OFF},
49     {CIRCLES, OHOS_CAMERA_PORTRAIT_CIRCLES}
50 };
51 
52 std::map<FilterType, camera_filter_type_t> g_fwToMetaFilterType_ = {
53     {NONE, OHOS_CAMERA_FILTER_TYPE_OFF},
54     {CLASSIC, OHOS_CAMERA_FILTER_TYPE_CLASSIC},
55     {DAWN, OHOS_CAMERA_FILTER_TYPE_DAWN},
56     {PURE, OHOS_CAMERA_FILTER_TYPE_PURE},
57     {GREY, OHOS_CAMERA_FILTER_TYPE_GREY},
58     {NATURAL, OHOS_CAMERA_FILTER_TYPE_NATURAL},
59     {MORI, OHOS_CAMERA_FILTER_TYPE_MORI},
60     {FAIR, OHOS_CAMERA_FILTER_TYPE_FAIR},
61     {PINK, OHOS_CAMERA_FILTER_TYPE_PINK}
62 };
63 
64 std::map<camera_beauty_type_t, BeautyType> g_metaToFwBeautyType_ = {
65     {OHOS_CAMERA_BEAUTY_TYPE_AUTO, AUTO_TYPE},
66     {OHOS_CAMERA_BEAUTY_TYPE_SKIN_SMOOTH, SKIN_SMOOTH},
67     {OHOS_CAMERA_BEAUTY_TYPE_FACE_SLENDER, FACE_SLENDER},
68     {OHOS_CAMERA_BEAUTY_TYPE_SKIN_TONE, SKIN_TONE}
69 };
70 
71 std::map<BeautyType, camera_beauty_type_t> g_fwToMetaBeautyType_ = {
72     {AUTO_TYPE, OHOS_CAMERA_BEAUTY_TYPE_AUTO},
73     {SKIN_SMOOTH, OHOS_CAMERA_BEAUTY_TYPE_SKIN_SMOOTH},
74     {FACE_SLENDER, OHOS_CAMERA_BEAUTY_TYPE_FACE_SLENDER},
75     {SKIN_TONE, OHOS_CAMERA_BEAUTY_TYPE_SKIN_TONE}
76 };
77 
78 std::map<BeautyType, camera_device_metadata_tag_t> g_beautyTypeAbility_ = {
79     {SKIN_SMOOTH, OHOS_ABILITY_BEAUTY_SKIN_SMOOTH_VALUES},
80     {FACE_SLENDER, OHOS_ABILITY_BEAUTY_FACE_SLENDER_VALUES},
81     {SKIN_TONE, OHOS_ABILITY_BEAUTY_SKIN_TONE_VALUES}
82 };
83 
84 std::map<BeautyType, std::string> g_beautyTypeStr_ = {
85     {AUTO_TYPE, "OHOS_CAMERA_BEAUTY_TYPE_AUTO"},
86     {SKIN_SMOOTH, "OHOS_CAMERA_BEAUTY_TYPE_SKIN_SMOOTH"},
87     {FACE_SLENDER, "OHOS_CAMERA_BEAUTY_TYPE_FACE_SLENDER"},
88     {SKIN_TONE, "OHOS_CAMERA_BEAUTY_TYPE_SKIN_TONE"}
89 };
90 
91 std::map<BeautyType, std::string> g_beautyAbilityStr_ = {
92     {SKIN_SMOOTH, "OHOS_ABILITY_BEAUTY_SKIN_SMOOTH_VALUES"},
93     {FACE_SLENDER, "OHOS_ABILITY_BEAUTY_FACE_SLENDER_VALUES"},
94     {SKIN_TONE, "OHOS_ABILITY_BEAUTY_SKIN_TONE_VALUES"}
95 };
96 
97 std::map<FilterType, std::string> g_filterTypeStr_ = {
98     {NONE, "OHOS_CAMERA_FILTER_TYPE_OFF"},
99     {CLASSIC, "OHOS_CAMERA_FILTER_TYPE_CLASSIC"},
100     {DAWN, "OHOS_CAMERA_FILTER_TYPE_DAWN"},
101     {PURE, "OHOS_CAMERA_FILTER_TYPE_PURE"},
102     {GREY, "OHOS_CAMERA_FILTER_TYPE_GREY"},
103     {NATURAL, "OHOS_CAMERA_FILTER_TYPE_NATURAL"},
104     {MORI, "OHOS_CAMERA_FILTER_TYPE_MORI"},
105     {FAIR, "OHOS_CAMERA_FILTER_TYPE_FAIR"},
106     {PINK, "OHOS_CAMERA_FILTER_TYPE_PINK"}
107 };
108 
109 std::map<PortraitEffect, std::string> g_portraitEffectStr_ = {
110     {OFF_EFFECT, "OHOS_CAMERA_PORTRAIT_EFFECT_OFF"},
111     {CIRCLES, "OHOS_CAMERA_PORTRAIT_CIRCLES"}
112 };
113 
114 std::map<uint32_t, std::string> g_abilityIdStr_ = {
115     {536870912, "OHOS_ABILITY_SCENE_FILTER_TYPES"},
116     {536870914, "OHOS_ABILITY_SCENE_PORTRAIT_EFFECT_TYPES"},
117     {536870916, "OHOS_ABILITY_SCENE_BEAUTY_TYPES"}
118 };
119 
PrintSupportBeautyTypes(vector<BeautyType> supportedBeautyTypes)120 void PrintSupportBeautyTypes(vector<BeautyType> supportedBeautyTypes)
121 {
122     MEDIA_INFO_LOG("Supported BeautyType size = %{public}zu", supportedBeautyTypes.size());
123     cout << g_abilityIdStr_[OHOS_ABILITY_SCENE_BEAUTY_TYPES] << " : size = " << supportedBeautyTypes.size() <<endl;
124     uint32_t index = 0;
125     for (BeautyType type : supportedBeautyTypes) {
126         for (auto itrType = g_fwToMetaBeautyType_.cbegin(); itrType != g_fwToMetaBeautyType_.cend(); itrType++) {
127             if (type == itrType->first) {
128                 break;
129             }
130         }
131         cout << "[" << index++ << "]" << "type = " << g_beautyTypeStr_[type] << ", ";
132         MEDIA_INFO_LOG("Supported BeautyType type = %{public}s", g_beautyTypeStr_[type].c_str());
133     }
134     cout << endl;
135     cout << "------------------------------------------------------------------------------------------------"<<endl;
136     return;
137 }
138 
PrintSupportFilterTypes(vector<FilterType> supportedFilterTypes)139 void PrintSupportFilterTypes(vector<FilterType> supportedFilterTypes)
140 {
141     MEDIA_INFO_LOG("Supported FilterTypes size = %{public}zu", supportedFilterTypes.size());
142     cout << g_abilityIdStr_[OHOS_ABILITY_SCENE_FILTER_TYPES] <<" : size = " << supportedFilterTypes.size() << endl;
143     uint32_t index = 0;
144     for (FilterType type : supportedFilterTypes) {
145         for (auto itrType = g_fwToMetaFilterType_.cbegin(); itrType != g_fwToMetaFilterType_.cend(); itrType++) {
146             if (type == itrType->first) {
147                 break;
148             }
149         }
150         cout << " [" << index++ << "]" << "type = " << g_filterTypeStr_[type] << ", ";
151         MEDIA_INFO_LOG("Supported FilterType type = %{public}s", g_filterTypeStr_[type].c_str());
152     }
153     cout << endl;
154     cout << "------------------------------------------------------------------------------------------------"<<endl;
155     return;
156 }
157 
PrintSupportPortraitEffects(vector<PortraitEffect> supportedPortraitEffects)158 void PrintSupportPortraitEffects(vector<PortraitEffect> supportedPortraitEffects)
159 {
160     MEDIA_INFO_LOG("Supported PortraitEffects size = %{public}zu", supportedPortraitEffects.size());
161     cout << g_abilityIdStr_[OHOS_ABILITY_SCENE_PORTRAIT_EFFECT_TYPES] <<" : size = "
162          << supportedPortraitEffects.size() <<endl;
163     uint32_t index = 0;
164     for (PortraitEffect type : supportedPortraitEffects) {
165         for (auto itrType = g_fwToMetaPortraitEffect_.cbegin(); itrType != g_fwToMetaPortraitEffect_.cend();
166              itrType++) {
167             if (type == itrType->first) {
168                 break;
169             }
170         }
171         cout << "[" << index++ << "]" << "effect = " << g_portraitEffectStr_[type] << ", ";
172         MEDIA_INFO_LOG("Supported PortraitEffect effect = %{public}s", g_portraitEffectStr_[type].c_str());
173     }
174     cout << endl;
175     cout << "------------------------------------------------------------------------------------------------"<<endl;
176     return;
177 }
178 
PrintSupportBeautyRange(BeautyType beauty,vector<int32_t> range)179 void PrintSupportBeautyRange(BeautyType beauty, vector<int32_t> range)
180 {
181     MEDIA_INFO_LOG("%{public}s size = %{public}zu", g_beautyAbilityStr_[beauty].c_str(), range.size());
182     cout << " " << g_beautyAbilityStr_[beauty] <<" size = " << range.size();
183     for (auto val : range) {
184         cout << " val = " << val << ", ";
185         MEDIA_INFO_LOG("val = %{public}d", val);
186     }
187     cout << endl;
188     return;
189 }
190 
GetSupportedPortraitEffectsStub()191 std::vector<PortraitEffect> GetSupportedPortraitEffectsStub()
192 {
193     cout<<"=================GetSupportedPortraitEffectsStub call================="<<endl;
194     std::vector<PortraitEffect> supportedPortraitEffects = {OFF_EFFECT, CIRCLES};
195     return supportedPortraitEffects;
196 }
197 
GetSupportedBeautyTypesStub()198 std::vector<BeautyType> GetSupportedBeautyTypesStub()
199 {
200     cout<<"=================GetSupportedBeautyTypesStub call================="<<endl;
201     std::vector<BeautyType> supportedBeautyTypes = {AUTO_TYPE, SKIN_SMOOTH, FACE_SLENDER, SKIN_TONE};
202     return supportedBeautyTypes;
203 }
204 
GetSupportedBeautyRangeStub(void * obj,BeautyType beautyType)205 std::vector<int32_t> GetSupportedBeautyRangeStub(void* obj, BeautyType beautyType)
206 {
207     cout<<"=================GetSupportedBeautyRangeStub call================="<<endl;
208     vector<int32_t> beautyRange;
209     switch (beautyType) {
210         case BeautyType::AUTO_TYPE : {
211             std::vector<int32_t> values = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
212             beautyRange = values;
213             break;
214         }
215         case BeautyType::SKIN_TONE : {
216             std::vector<int32_t> values = {0xFFFFFFFF, 0xBF986C, 0xE9BB97, 0xEDCDA3, 0xF7D7B3, 0xFEE6CF};
217             beautyRange = values;
218             break;
219         }
220         case BeautyType::SKIN_SMOOTH : {
221             std::vector<int32_t> values = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
222             beautyRange = values;
223             break;
224         }
225         case BeautyType::FACE_SLENDER : {
226             std::vector<int32_t> values = {0, 1, 2, 3, 4, 5};
227             beautyRange = values;
228             break;
229         }
230         default : {
231             std::vector<int32_t> values = {};
232             beautyRange = values;
233         }
234     }
235     cout<<"BeautyType = " << beautyType << " BeautyType size()" << beautyRange.size() <<endl;
236     return beautyRange;
237 }
238 
GetExposureRangeStub(std::vector<uint32_t> & exposureRange)239 int32_t GetExposureRangeStub(std::vector<uint32_t> &exposureRange)
240 {
241     cout<<"=================GetSupportedBeautyRangeStub call================="<<endl;
242     exposureRange.clear();
243     std::vector<uint32_t> exposureRangeStub = {250, 500, 1000, 2000, 4000, 8000,
244         12000, 16000, 20000, 24000, 28000, 32000};
245     for (size_t i = 0; i < exposureRangeStub.size(); i++) {
246         exposureRange.push_back(exposureRangeStub.at(i));
247     }
248     cout << " exposureRangeStub size()" << exposureRangeStub.size() <<endl;
249     return 0;
250 }
251 
GetSupportedFiltersStub()252 std::vector<FilterType> GetSupportedFiltersStub()
253 {
254     cout<<"=================GetSupportedFiltersStub call================="<<endl;
255     std::vector<FilterType> supportedFilterTypes = { NONE, CLASSIC, DAWN, PURE, GREY, NATURAL, MORI, FAIR, PINK };
256     return supportedFilterTypes;
257 }
258 
main(int argc,char ** argv)259 int main(int argc, char **argv)
260 {
261     cout<<"-----------------version:20230822-----------------"<<endl;
262     Stub stub;
263     stub.set(ADDR(NightSession, GetExposureRange), GetExposureRangeStub);
264     const int32_t previewWidthIndex = 1;
265     const int32_t previewHeightIndex = 2;
266     const int32_t photoWidthIndex = 3;
267     const int32_t photoHeightIndex = 4;
268     const int32_t devicePosionIndex = 5;
269     const int32_t validArgCount = 6;
270     const int32_t gapAfterCapture = 3; // 1 second
271     const int32_t previewCaptureGap = 5; // 5 seconds
272     const char* testName = "camera_capture_mode";
273     int32_t ret = -1;
274     int32_t previewFd = -1;
275     int32_t photoFd = -1;
276     int32_t previewFormat = CAMERA_FORMAT_YUV_420_SP;
277     int32_t previewWidth = 1280;
278     int32_t previewHeight = 960;
279     int32_t photoFormat = CAMERA_FORMAT_JPEG;
280     int32_t photoWidth = 1280;
281     int32_t photoHeight = 960;
282     int32_t photoCaptureCount = 1;
283     int32_t devicePosion = 0;
284     bool isResolutionConfigured = false;
285     Size previewsize;
286     Size photosize;
287 
288     // Update sizes if enough number of valid arguments are passed
289     if (argc == validArgCount) {
290         // Validate arguments
291         for (int counter = 1; counter < argc; counter++) {
292             if (!TestUtils::IsNumber(argv[counter])) {
293                 cout << "Invalid argument: " << argv[counter] << endl;
294                 cout << "Retry by giving proper sizes" << endl;
295                 return 0;
296             }
297         }
298         previewWidth = atoi(argv[previewWidthIndex]);
299         previewHeight = atoi(argv[previewHeightIndex]);
300         photoWidth = atoi(argv[photoWidthIndex]);
301         photoHeight = atoi(argv[photoHeightIndex]);
302         devicePosion = atoi(argv[devicePosionIndex]);
303         isResolutionConfigured = true;
304     } else if (argc != 1) {
305         cout << "Pass " << (validArgCount - 1) << "arguments" << endl;
306         cout << "PreviewHeight, PreviewWidth, PhotoWidth, PhotoHeight"
307             << endl;
308         return 0;
309     }
310 
311     uint64_t tokenId;
312     const char *perms[0];
313     perms[0] = "ohos.permission.CAMERA";
314     NativeTokenInfoParams infoInstance = {
315         .dcapsNum = 0,
316         .permsNum = 1,
317         .aclsNum = 0,
318         .dcaps = NULL,
319         .perms = perms,
320         .acls = NULL,
321         .processName = "camera_capture_mode",
322         .aplStr = "system_basic",
323     };
324     tokenId = GetAccessTokenId(&infoInstance);
325     SetSelfTokenID(tokenId);
326     OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
327 
328     sptr<CameraManager> camManagerObj = CameraManager::GetInstance();
329     MEDIA_INFO_LOG("Setting callback to listen camera status and flash status");
330     camManagerObj->SetCallback(std::make_shared<TestCameraMngerCallback>(testName));
331     std::vector<sptr<CameraDevice>> cameraObjList = camManagerObj->GetSupportedCameras();
332     if (cameraObjList.size() == 0) {
333         return 0;
334     }
335     sptr<CameraDevice> device = cameraObjList[0];
336     MEDIA_INFO_LOG("Camera ID count: %{public}zu", cameraObjList.size());
337     for (auto& it : cameraObjList) {
338         MEDIA_INFO_LOG("Camera ID: %{public}s", it->GetID().c_str());
339         MEDIA_INFO_LOG("Camera Posion: %{public}d", it->GetPosition());
340         if (devicePosion == 0 && it->GetPosition() == CameraPosition::CAMERA_POSITION_BACK) {
341             device = it;
342             break;
343         }
344         if (devicePosion == 1 && it->GetPosition() == CameraPosition::CAMERA_POSITION_FRONT) {
345             device = it;
346             break;
347         }
348     }
349     cout<<"Camera ID ="<<device->GetID()<<",camera Position = "<<device->GetPosition()<<endl;
350     sptr<CameraManager> modeManagerObj = CameraManager::GetInstance();
351     std::vector<SceneMode> supportedModes = modeManagerObj->GetSupportedModes(device);
352     std::string modes = "";
353     for (auto mode : supportedModes) {
354         modes += std::to_string(static_cast<uint32_t>(mode)) + " , ";
355     }
356     MEDIA_INFO_LOG("supportedModes : %{public}s", modes.c_str());
357     sptr<CaptureSession> captureSession = modeManagerObj->CreateCaptureSession(SceneMode::PORTRAIT);
358     sptr<PortraitSession> portraitSession = nullptr;
359     portraitSession = static_cast<PortraitSession *> (captureSession.GetRefPtr());
360     if (portraitSession == nullptr) {
361         return 0;
362     }
363     portraitSession->BeginConfig();
364     sptr<CaptureInput> captureInput = camManagerObj->CreateCameraInput(device);
365     if (captureInput == nullptr) {
366         return 0;
367     }
368 
369     sptr<CameraInput> cameraInput = (sptr<CameraInput> &)captureInput;
370     cameraInput->Open();
371     std::vector<Profile> photoProfiles = {};
372     std::vector<Profile> previewProfiles = {};
373     std::string abilityIds = "";
374     if (isResolutionConfigured) {
375         std::vector<CameraFormat> previewFormats;
376         std::vector<CameraFormat> photoFormats;
377         std::vector<Size> previewSizes;
378         std::vector<Size> photoSizes;
379         sptr<CameraOutputCapability> outputcapability =
380             modeManagerObj->GetSupportedOutputCapability(device, SceneMode::PORTRAIT);
381         previewProfiles = outputcapability->GetPreviewProfiles();
382         uint32_t profileIndex = 0;
383         for (auto i : previewProfiles) {
384             previewFormats.push_back(i.GetCameraFormat());
385             previewSizes.push_back(i.GetSize());
386 
387             abilityIds = "";
388             for (auto id : i.GetAbilityId()) {
389                 abilityIds += g_abilityIdStr_[id] + "("+std::to_string(id) + ") , ";
390             }
391             MEDIA_INFO_LOG("index(%{public}d), preview profile f(%{public}d), w(%{public}d), h(%{public}d) "
392                            "support ability: %{public}s", profileIndex++,
393                            i.GetCameraFormat(), i.GetSize().width, i.GetSize().height, abilityIds.c_str());
394         }
395 
396         photoProfiles =  outputcapability->GetPhotoProfiles();
397         profileIndex = 0;
398         for (auto i : photoProfiles) {
399             photoFormats.push_back(i.GetCameraFormat());
400             photoSizes.push_back(i.GetSize());
401             abilityIds = "";
402             for (auto id : i.GetAbilityId()) {
403                 abilityIds += g_abilityIdStr_[id] + "("+std::to_string(id) + ") , ";
404             }
405             MEDIA_INFO_LOG("index %{public}d, photo support format : %{public}d, width: %{public}d, height: %{public}d"
406                            "support ability: %{public}s", profileIndex++,
407                            i.GetCameraFormat(), i.GetSize().width, i.GetSize().height, abilityIds.c_str());
408         }
409     }
410 
411     MEDIA_INFO_LOG("photoCaptureCount: %{public}d", photoCaptureCount);
412 
413     cameraInput->SetErrorCallback(std::make_shared<TestDeviceCallback>(testName));
414     ret = portraitSession->AddInput(captureInput);
415     if (ret != 0) {
416         return 0;
417     }
418 
419     sptr<IConsumerSurface> photoSurface = IConsumerSurface::Create();
420     if (photoSurface == nullptr) {
421         return 0;
422     }
423     photosize.width = photoWidth;
424     photosize.height = photoHeight;
425     Profile photoprofile;
426     for (auto it : photoProfiles) {
427         if (it.GetSize().width == photosize.width && it.GetSize().height == photosize.height
428             && it.GetCameraFormat() == static_cast<CameraFormat>(photoFormat)) {
429                 photoprofile = it;
430         }
431     }
432     abilityIds = "";
433     for (auto id : photoprofile.GetAbilityId()) {
434         abilityIds += g_abilityIdStr_[id] + "("+std::to_string(id) + ") , ";
435     }
436     MEDIA_INFO_LOG("photo support format : %{public}d, width: %{public}d, height: %{public}d"
437                    "support ability: %{public}s",
438                    photoFormat, photoWidth, photoHeight, abilityIds.c_str());
439     cout<< "photoFormat: " << photoFormat << " photoWidth: "<< photoWidth
440         << " photoHeight: " << photoHeight << " support ability: " << abilityIds.c_str() << endl;
441 
442     sptr<SurfaceListener> captureListener = new(std::nothrow) SurfaceListener("Photo", SurfaceType::PHOTO,
443                                                                               photoFd, photoSurface);
444     photoSurface->RegisterConsumerListener((sptr<IBufferConsumerListener> &)captureListener);
445     sptr<IBufferProducer> bp = photoSurface->GetProducer();
446     sptr<CaptureOutput> photoOutput = camManagerObj->CreatePhotoOutput(photoprofile, bp);
447     if (photoOutput == nullptr) {
448         return 0;
449     }
450 
451     MEDIA_INFO_LOG("Setting photo callback");
452     ((sptr<PhotoOutput> &)photoOutput)->SetCallback(std::make_shared<TestPhotoOutputCallback>(testName));
453     ret = portraitSession->AddOutput(photoOutput);
454     if (ret != 0) {
455         return 0;
456     }
457 
458     sptr<CaptureOutput> metaOutput = camManagerObj->CreateMetadataOutput();
459     MEDIA_INFO_LOG("Setting Meta callback");
460     ((sptr<MetadataOutput> &)metaOutput)->SetCallback(std::make_shared<TestMetadataOutputObjectCallback>(testName));
461 
462     ret = portraitSession->AddOutput(metaOutput);
463     if (ret != 0) {
464         return 0;
465     }
466 
467     sptr<IConsumerSurface> previewSurface = IConsumerSurface::Create();
468     if (previewSurface == nullptr) {
469         return 0;
470     }
471     previewsize.width = previewWidth;
472     previewsize.height = previewHeight;
473     Profile previewprofile;
474     for (auto it : previewProfiles) {
475         if (it.GetSize().width == previewsize.width && it.GetSize().height == previewsize.height
476             && it.GetCameraFormat() == static_cast<CameraFormat>(previewFormat)) {
477                 previewprofile = it;
478             }
479     }
480     abilityIds = "";
481     for (auto id : previewprofile.GetAbilityId()) {
482         abilityIds += g_abilityIdStr_[id] + "("+std::to_string(id) + ") , ";
483     }
484     MEDIA_INFO_LOG("previewFormat: %{public}d, previewWidth: %{public}d, previewHeight: %{public}d"
485                    "support ability: %{public}s",
486                    previewFormat, previewWidth, previewHeight, abilityIds.c_str());
487 
488     cout<< "previewFormat: " << previewFormat << " previewWidth: "<< previewWidth
489         << " previewHeight: " << previewHeight << " support ability: " << abilityIds.c_str() <<endl;
490 
491     cout << "------------------------------------------------------------------------------------------------"<<endl;
492     sptr<SurfaceListener> listener = new(std::nothrow) SurfaceListener("Preview", SurfaceType::PREVIEW,
493                                                                        previewFd, previewSurface);
494     previewSurface->RegisterConsumerListener((sptr<IBufferConsumerListener> &)listener);
495     sptr<IBufferProducer> previewProducer = previewSurface->GetProducer();
496     sptr<Surface> previewProducerSurface = Surface::CreateSurfaceAsProducer(previewProducer);
497     sptr<CaptureOutput> previewOutput = camManagerObj->CreatePreviewOutput(previewprofile, previewProducerSurface);
498     if (previewOutput == nullptr) {
499         return 0;
500     }
501 
502     MEDIA_INFO_LOG("Setting preview callback");
503     ((sptr<PreviewOutput> &)previewOutput)->SetCallback(std::make_shared<TestPreviewOutputCallback>(testName));
504     ret = portraitSession->AddOutput(previewOutput);
505     if (ret != 0) {
506         return 0;
507     }
508 
509     ret = portraitSession->CommitConfig();
510     if (ret != 0) {
511         return 0;
512     }
513 
514     MEDIA_INFO_LOG("Preview started");
515     ret = portraitSession->Start();
516     if (ret != 0) {
517         return 0;
518     }
519 
520     std::vector<float> vecZoomRatioList;
521     portraitSession->GetZoomRatioRange(vecZoomRatioList);
522     cout<< "getMode:" << portraitSession->GetFeaturesMode() << ",minZoom:" << vecZoomRatioList[0]
523         << ", maxZoom:" << vecZoomRatioList[1]<<endl;
524     std::vector<BeautyType> supportedBeautyType = portraitSession->GetSupportedBeautyTypes();
525     PrintSupportBeautyTypes(supportedBeautyType);
526 
527     std::vector<int32_t> faceSlenderRange = portraitSession->GetSupportedBeautyRange(BeautyType::FACE_SLENDER);
528     PrintSupportBeautyRange(BeautyType::FACE_SLENDER, faceSlenderRange);
529 
530     std::vector<int32_t> skinSmoothRange = portraitSession->GetSupportedBeautyRange(BeautyType::SKIN_SMOOTH);
531     PrintSupportBeautyRange(BeautyType::SKIN_SMOOTH, skinSmoothRange);
532 
533     std::vector<int32_t> skinToneRange = portraitSession->GetSupportedBeautyRange(BeautyType::SKIN_TONE);
534     PrintSupportBeautyRange(BeautyType::SKIN_TONE, skinToneRange);
535 
536     vector<FilterType> supportedFilterTypes = portraitSession->GetSupportedFilters();
537     PrintSupportFilterTypes(supportedFilterTypes);
538 
539     vector<PortraitEffect> supportedPortraitEffects = portraitSession->GetSupportedPortraitEffects();
540     PrintSupportPortraitEffects(supportedPortraitEffects);
541 
542     sleep(previewCaptureGap);
543 
544     uint32_t photoCnt = 1;
545 
546     MEDIA_INFO_LOG("Normal Capture started");
547     for (int i = 1; i <= photoCaptureCount; i++) {
548         MEDIA_INFO_LOG("Photo capture %{public}d started", i);
549         ret = ((sptr<PhotoOutput> &)photoOutput)->Capture(ConfigPhotoCaptureSetting());
550         if (ret != 0) {
551             MEDIA_INFO_LOG("Photo capture err ret=%{public}d", ret);
552             return 0;
553         }
554         sleep(gapAfterCapture);
555     }
556 
557     cout<< "Filter Capture started" <<endl;
558     for (auto filter : supportedFilterTypes) {
559         MEDIA_INFO_LOG("Set Filter: %{public}s", g_filterTypeStr_[filter].c_str());
560         portraitSession->LockForControl();
561         portraitSession->SetFilter(filter);
562         portraitSession->UnlockForControl();
563         sleep(gapAfterCapture);
564         ret = ((sptr<PhotoOutput> &)photoOutput)->Capture(ConfigPhotoCaptureSetting());
565         if (ret != 0) {
566             return 0;
567         }
568         MEDIA_INFO_LOG("Photo capture cnt [%{public}d] filter : %{public}s",
569                        photoCnt++, g_filterTypeStr_[filter].c_str());
570         sleep(gapAfterCapture);
571     }
572     cout<< "Filter Capture started" <<endl;
573 
574     cout<< "BeautyType::SKIN_TONE Capture started" <<endl;
575     for (auto beautyVal : skinToneRange) {
576         MEDIA_INFO_LOG("Set Beauty: %{public}s beautyVal= %{public}d",
577                        g_beautyTypeStr_[BeautyType::SKIN_TONE].c_str(), beautyVal);
578         portraitSession->LockForControl();
579         portraitSession->SetBeauty(BeautyType::SKIN_TONE, beautyVal);
580         portraitSession->UnlockForControl();
581         ret = ((sptr<PhotoOutput> &)photoOutput)->Capture(ConfigPhotoCaptureSetting());
582         if (ret != 0) {
583             return 0;
584         }
585         sleep(gapAfterCapture);
586     }
587     cout<< "BeautyType::SKIN_TONE Capture end" <<endl;
588 
589     cout<< "BeautyType::FACE_SLENDER Capture started" <<endl;
590     for (auto beautyVal : skinToneRange) {
591         MEDIA_INFO_LOG("Set Beauty: %{public}s beautyVal= %{public}d",
592                        g_beautyTypeStr_[BeautyType::FACE_SLENDER].c_str(), beautyVal);
593         portraitSession->LockForControl();
594         portraitSession->SetBeauty(BeautyType::FACE_SLENDER, beautyVal);
595         portraitSession->UnlockForControl();
596         ret = ((sptr<PhotoOutput> &)photoOutput)->Capture(ConfigPhotoCaptureSetting());
597         if (ret != 0) {
598             return 0;
599         }
600         sleep(gapAfterCapture);
601     }
602     cout<< "BeautyType::FACE_SLENDER Capture end" <<endl;
603 
604     cout<< "BeautyType::SKIN_SMOOTH Capture started" <<endl;
605     for (auto beautyVal : skinToneRange) {
606         MEDIA_INFO_LOG("Set Beauty: %{public}s beautyVal= %{public}d",
607                        g_beautyTypeStr_[BeautyType::SKIN_SMOOTH].c_str(), beautyVal);
608         portraitSession->LockForControl();
609         portraitSession->SetBeauty(BeautyType::SKIN_SMOOTH, beautyVal);
610         portraitSession->UnlockForControl();
611         ret = ((sptr<PhotoOutput> &)photoOutput)->Capture(ConfigPhotoCaptureSetting());
612         if (ret != 0) {
613             return 0;
614         }
615         sleep(gapAfterCapture);
616     }
617     cout<< "BeautyType::SKIN_SMOOTH Capture end" <<endl;
618 
619     cout<< "PortraitEffect Capture started" <<endl;
620     for (auto effect : supportedPortraitEffects) {
621         MEDIA_INFO_LOG("Set PortraitEffect: %{public}s", g_portraitEffectStr_[effect].c_str());
622         portraitSession->LockForControl();
623         portraitSession->SetPortraitEffect(effect);
624         portraitSession->UnlockForControl();
625         ret = ((sptr<PhotoOutput> &)photoOutput)->Capture(ConfigPhotoCaptureSetting());
626         if (ret != 0) {
627             return 0;
628         }
629         MEDIA_INFO_LOG("Photo capture [%{public}d] filter : %{public}s",
630                        photoCnt++, g_portraitEffectStr_[effect].c_str());
631         sleep(gapAfterCapture);
632     }
633     cout<< "PortraitEffect Capture end" <<endl;
634     MEDIA_INFO_LOG("Closing the session");
635     ((sptr<PreviewOutput> &)previewOutput)->Stop();
636     portraitSession->Stop();
637     portraitSession->Release();
638     cameraInput->Release();
639     camManagerObj->SetCallback(nullptr);
640 
641     MEDIA_INFO_LOG("Camera new sample end.");
642     return 0;
643 }
644