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
16 #include <iostream>
17 #include "common.h"
18 #include "dcamera_source_handler.h"
19
20 using namespace std;
21 using namespace OHOS::DistributedHardware;
22
23 const std::string TEST_DEV_ID = "11111111111111111111111111111111";
24 const std::string TEST_CAM_ID = "camera_0";
25 const std::string TEST_ATTR = R"({"CodecType":["avenc_mpeg4"],
26 "OutputFormat":{"Photo":[4],"Preview":[2,3],"Video":[2,3]},
27 "Position":"BACK",
28 "ProtocolVer":"1.0",
29 "MetaData":"",
30 "Resolution":{
31 "2":["1920*1080","1504*720","1440*1080","1280*960","1280*720","1232*768","1152*720","960*720","960*544",
32 "880*720","720*720","720*480","640*480","352*288","320*240"],
33 "3":["1920*1080","1504*720","1440*1080","1280*960","1280*720","1232*768","1152*720","960*720","960*544",
34 "880*720","720*720","720*480","640*480","352*288","320*240"],
35 "4":["3840*2160","3264*2448","3264*1840","2304*1728","2048*1536","1920*1440","1920*1080","1744*1088",
36 "1280*720","1232*768","1152*720","640*480","320*240"]}})";
37
main()38 int main()
39 {
40 cout << "distributed camera hdf start" << endl;
41
42 IDistributedHardwareSource *sourceSA = GetSourceHardwareHandler();
43 EnableParam param;
44 param.version = "1.0";
45 param.attrs = TEST_ATTR;
46 std::shared_ptr<OHOS::DistributedHardware::RegisterCallback> regCb =
47 std::make_shared<OHOS::DistributedHardware::DCameraMockRegisterCallback>();
48 int32_t ret = sourceSA->InitSource("1.0");
49 cout << "Init Source " << ret << endl;
50 ret = sourceSA->RegisterDistributedHardware(TEST_DEV_ID, TEST_CAM_ID, param, regCb);
51 unsigned int sleepSeconds = 2;
52 sleep(sleepSeconds);
53 cout << "sleep" << sleepSeconds << "second wait register end: " << ret << endl;
54
55 std::shared_ptr<OHOS::DistributedHardware::Test> test = std::make_shared<OHOS::DistributedHardware::Test>();
56 test->Init();
57 test->Open();
58 sleepSeconds = 1;
59 sleep(sleepSeconds);
60 cout << "sleep" << sleepSeconds << "second wait open camera end." << endl;
61
62 std::cout << "==========[test log]Preview stream, 640*480, expected success." << std::endl;
63 // 启动流
64 test->intents = {OHOS::Camera::PREVIEW};
65 test->StartStream(test->intents);
66 sleepSeconds = 1;
67 sleep(sleepSeconds);
68 cout << "sleep" << sleepSeconds << "second wait start stream end." << endl;
69
70 // 获取预览图
71 test->StartCapture(test->streamId_preview, test->captureId_preview, false, true);
72 // 释放流
73 test->captureIds = {test->captureId_preview};
74 test->streamIds = {test->streamId_preview};
75 sleepSeconds = 1;
76 sleep(sleepSeconds);
77 cout << "sleep" << sleepSeconds << "second wait start capture end." << endl;
78
79 test->StopStream(test->captureIds, test->streamIds);
80 sleepSeconds = 1;
81 sleep(sleepSeconds);
82 cout << "sleep" << sleepSeconds << "second wait stop stream end." << endl;
83
84 test->Close();
85 sleepSeconds = 1;
86 sleep(sleepSeconds);
87 cout << "sleep" << sleepSeconds << "second wait close end." << endl;
88
89 std::shared_ptr<OHOS::DistributedHardware::UnregisterCallback> unRegCb =
90 std::make_shared<OHOS::DistributedHardware::DCameraMockUnRegisterCallback>();
91 ret = sourceSA->UnregisterDistributedHardware(TEST_DEV_ID, TEST_CAM_ID, unRegCb);
92 cout << "distributed camera hdf end ret: " << ret << endl;
93
94 return 0;
95 }