• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "3516_demo.h"
17 
18 namespace OHOS::Camera {
Hos3516Demo()19 Hos3516Demo::Hos3516Demo() {}
~Hos3516Demo()20 Hos3516Demo::~Hos3516Demo() {}
21 
SetStreamInfo(std::shared_ptr<StreamInfo> & streamInfo,const std::shared_ptr<StreamCustomer> & streamCustomer,const int streamId,const StreamIntent intent)22 void Hos3516Demo::SetStreamInfo(std::shared_ptr<StreamInfo>& streamInfo,
23     const std::shared_ptr<StreamCustomer>& streamCustomer,
24     const int streamId, const StreamIntent intent)
25 {
26     constexpr uint32_t datasapce = 8;
27     constexpr uint32_t tunneledMode = 5;
28 
29     if (intent == PREVIEW) {
30         constexpr uint32_t width = 640;
31         constexpr uint32_t height = 480;
32         streamInfo->width_ = width;
33         streamInfo->height_ = height;
34     } else if (intent == STILL_CAPTURE) {
35         constexpr uint32_t width = 1280;
36         constexpr uint32_t height = 960;
37         streamInfo->width_ = width;
38         streamInfo->height_ = height;
39         streamInfo->encodeType_ = ENCODE_TYPE_JPEG;
40     } else {
41         constexpr uint32_t width = 1280;
42         constexpr uint32_t height = 960;
43         streamInfo->width_ = width;
44         streamInfo->height_ = height;
45         streamInfo->encodeType_ = ENCODE_TYPE_H265;
46     }
47 
48     streamInfo->streamId_ = streamId;
49     streamInfo->format_ = PIXEL_FMT_YCRCB_420_SP;
50     streamInfo->datasapce_ = datasapce;
51     streamInfo->intent_ = intent;
52     streamInfo->tunneledMode_ = tunneledMode;
53     streamInfo->bufferQueue_ = streamCustomer->CreateProducer();
54     streamInfo->bufferQueue_->SetQueueSize(8); // 8:set bufferQueue size
55 }
56 
GetStreamOpt()57 void Hos3516Demo::GetStreamOpt()
58 {
59     int rc = 0;
60 
61     if (streamOperator_ == nullptr) {
62         const sptr<IStreamOperatorCallback> streamOperatorCallback = new StreamOperatorCallback();
63         rc = demoCameraDevice_->GetStreamOperator(streamOperatorCallback, streamOperator_);
64         if (rc != Camera::NO_ERROR) {
65             CAMERA_LOGE("demo test: GetStreamOpt GetStreamOperator fail\n");
66             streamOperator_ = nullptr;
67         }
68     }
69 }
70 
CaptureON(const int streamId,const int captureId,CaptureMode mode)71 RetCode Hos3516Demo::CaptureON(const int streamId, const int captureId, CaptureMode mode)
72 {
73     CAMERA_LOGD("demo test: CaptureON enter mode == %{public}d", mode);
74 
75     std::shared_ptr<Camera::CaptureInfo> captureInfo = std::make_shared<Camera::CaptureInfo>();
76     captureInfo->streamIds_ = {streamId};
77     captureInfo->captureSetting_ = ability_;
78     captureInfo->enableShutterCallback_ = false;
79 
80     int rc = streamOperator_->Capture(captureId, captureInfo, true);
81     if (rc != Camera::NO_ERROR) {
82         CAMERA_LOGE("demo test: CaptureStart Capture error\n");
83         streamOperator_->ReleaseStreams(captureInfo->streamIds_);
84         return RC_ERROR;
85     }
86 
87     if (mode == CAPTURE_PREVIEW) {
88         streamCustomerPreview_->ReceiveFrameOn(nullptr);
89     } else if (mode == CAPTURE_SNAPSHOT) {
90         streamCustomerCapture_->ReceiveFrameOn([this](void* addr, const uint32_t size) {
91             StoreImage(addr, size);
92         });
93     } else if (mode == CAPTURE_VIDEO) {
94         OpenVideoFile();
95 
96         streamCustomerVideo_->ReceiveFrameOn([this](void* addr, const uint32_t size) {
97             StoreVideo(addr, size);
98         });
99     }
100     CAMERA_LOGD("demo test: CaptureON exit");
101 
102     return RC_OK;
103 }
104 
CaptureOff(const int captureId,const CaptureMode mode)105 RetCode Hos3516Demo::CaptureOff(const int captureId, const CaptureMode mode)
106 {
107     int rc = 0;
108     CAMERA_LOGD("demo test: CaptureOff enter mode == %{public}d", mode);
109 
110     if (streamOperator_ == nullptr) {
111         CAMERA_LOGE("demo test: CaptureOff streamOperator_ is nullptr\n");
112         return RC_ERROR;
113     }
114 
115     if (mode == CAPTURE_PREVIEW) {
116         streamCustomerPreview_->ReceiveFrameOff();
117         rc = streamOperator_->CancelCapture(captureId);
118     } else if (mode == CAPTURE_SNAPSHOT) {
119         streamCustomerCapture_->ReceiveFrameOff();
120         rc = streamOperator_->CancelCapture(captureId);
121     } else if (mode == CAPTURE_VIDEO) {
122         streamCustomerVideo_->ReceiveFrameOff();
123         rc = streamOperator_->CancelCapture(captureId);
124         close(videoFd_);
125         videoFd_ = -1;
126     }
127 
128     if (rc != Camera::NO_ERROR) {
129         CAMERA_LOGE("demo test: CaptureOff CancelCapture error mode %{public}d rc == %{public}d\n", mode, rc);
130         return RC_ERROR;
131     }
132     CAMERA_LOGD("demo test: CaptureOff exit");
133 
134     return RC_OK;
135 }
136 
CreatStream(const int streamId,std::shared_ptr<StreamCustomer> & streamCustomer,StreamIntent intent)137 RetCode Hos3516Demo::CreatStream(const int streamId, std::shared_ptr<StreamCustomer>& streamCustomer,
138     StreamIntent intent)
139 {
140     int rc = 0;
141     CAMERA_LOGD("demo test: CreatStream enter");
142 
143     GetStreamOpt();
144     if (streamOperator_ == nullptr) {
145         CAMERA_LOGE("demo test: CreatStream GetStreamOpt() is nullptr\n");
146         return RC_ERROR;
147     }
148 
149     std::shared_ptr<StreamInfo> streamInfo = std::make_shared<StreamInfo>();
150     if (streamInfo == nullptr) {
151         CAMERA_LOGE("demo test: std::make_shared<Camera::StreamInfo>() is nullptr\n");
152         return RC_ERROR;
153     }
154 
155     SetStreamInfo(streamInfo, streamCustomer, streamId, intent);
156     if (streamInfo->bufferQueue_ == nullptr) {
157         CAMERA_LOGE("demo test: CreatStream CreateProducer(); is nullptr\n");
158         return RC_ERROR;
159     }
160 
161     std::vector<std::shared_ptr<StreamInfo>> streamInfos;
162     std::vector<std::shared_ptr<StreamInfo>>().swap(streamInfos);
163     streamInfos.push_back(streamInfo);
164 
165     rc = streamOperator_->CreateStreams(streamInfos);
166     if (rc != Camera::NO_ERROR) {
167         CAMERA_LOGE("demo test: CreatStream CreateStreams error\n");
168         return RC_ERROR;
169     }
170 
171     rc = streamOperator_->CommitStreams(Camera::NORMAL, ability_);
172     if (rc != Camera::NO_ERROR) {
173         CAMERA_LOGE("demo test: CreatStream CommitStreams error\n");
174         streamOperator_->ReleaseStreams({streamId});
175         return RC_ERROR;
176     }
177 
178     CAMERA_LOGD("demo test: CreatStream exit");
179 
180     return RC_OK;
181 }
182 
InitCameraDevice()183 RetCode Hos3516Demo::InitCameraDevice()
184 {
185     int rc = 0;
186 
187     CAMERA_LOGD("demo test: InitCameraDevice enter");
188 
189     if (demoCameraHost_ == nullptr) {
190         CAMERA_LOGE("demo test: InitCameraDevice demoCameraHost_ == nullptr");
191         return RC_ERROR;
192     }
193 
194     (void)demoCameraHost_->GetCameraIds(cameraIds_);
195     if (cameraIds_.empty()) {
196         return RC_ERROR;
197     }
198     const std::string cameraId = cameraIds_.front();
199     demoCameraHost_->GetCameraAbility(cameraId, ability_);
200 
201     sptr<CameraDeviceCallback> callback = new CameraDeviceCallback();
202     rc = demoCameraHost_->OpenCamera(cameraIds_.front(), callback, demoCameraDevice_);
203     if (rc != Camera::NO_ERROR || demoCameraDevice_ == nullptr) {
204         CAMERA_LOGE("demo test: InitCameraDevice OpenCamera failed");
205         return RC_ERROR;
206     }
207 
208     CAMERA_LOGD("demo test: InitCameraDevice exit");
209 
210     return RC_OK;
211 }
212 
ReleaseCameraDevice()213 void Hos3516Demo::ReleaseCameraDevice()
214 {
215     if (demoCameraDevice_ != nullptr) {
216         CAMERA_LOGD("demo test: ReleaseCameraDevice close Device");
217         demoCameraDevice_->Close();
218         demoCameraDevice_ = nullptr;
219     }
220 }
221 
222 constexpr const char *DEMO_SERVICE_NAME = "camera_service";
InitSensors()223 RetCode Hos3516Demo::InitSensors()
224 {
225     int rc = 0;
226 
227     CAMERA_LOGD("demo test: InitSensors enter");
228 
229     if (demoCameraHost_ != nullptr) {
230         return RC_OK;
231     }
232 
233     demoCameraHost_ = ICameraHost::Get(DEMO_SERVICE_NAME);
234     if (demoCameraHost_ == nullptr) {
235         CAMERA_LOGE("demo test: ICameraHost::Get error");
236         return RC_ERROR;
237     }
238 
239     hostCallback_ = new CameraHostCallback();
240     rc = demoCameraHost_->SetCallback(hostCallback_);
241     if (rc != Camera::NO_ERROR) {
242         CAMERA_LOGE("demo test: demoCameraHost_->SetCallback(hostCallback_) error");
243         return RC_ERROR;
244     }
245 
246     CAMERA_LOGD("demo test: InitSensors exit");
247 
248     return RC_OK;
249 }
250 
StoreImage(const void * bufStart,const uint32_t size) const251 void Hos3516Demo::StoreImage(const void* bufStart, const uint32_t size) const
252 {
253     constexpr uint32_t pathLen = 30;
254     char path[pathLen] = {0};
255     int imgFD = 0;
256     int ret;
257 
258     struct timeval start;
259     gettimeofday(&start, nullptr);
260     if (sprintf_s(path, sizeof(path), "/data/3516_%ld.jpeg", start.tv_usec) < 0) {
261         CAMERA_LOGE("sprintf_s error .....\n");
262         return;
263     }
264 
265     imgFD = open(path, O_RDWR | O_CREAT, 00766); // 00766:file operate permission
266     if (imgFD == -1) {
267         CAMERA_LOGE("demo test:open image file error %{public}s.....\n", strerror(errno));
268         return;
269     }
270 
271     CAMERA_LOGD("demo test:StoreImage %{public}s buf_start == %{public}p size == %{public}d\n", path, bufStart, size);
272 
273     ret = write(imgFD, bufStart, size);
274     if (ret == -1) {
275         CAMERA_LOGE("demo test:write image file error %{public}s.....\n", strerror(errno));
276     }
277 
278     close(imgFD);
279 }
280 
StoreVideo(const void * bufStart,const uint32_t size) const281 void Hos3516Demo::StoreVideo(const void* bufStart, const uint32_t size) const
282 {
283     int ret = 0;
284 
285     ret = write(videoFd_, bufStart, size);
286     if (ret == -1) {
287         CAMERA_LOGE("demo test:write video file error %{public}s.....\n", strerror(errno));
288     }
289     CAMERA_LOGD("demo test:StoreVideo buf_start == %{public}p size == %{public}d\n", bufStart, size);
290 }
291 
OpenVideoFile()292 void Hos3516Demo::OpenVideoFile()
293 {
294     constexpr uint32_t pathLen = 30;
295     char path[pathLen] = {0};
296 
297     if (sprintf_s(path, sizeof(path), "/data/3516_video%ld.h264", time(nullptr)) < 0) {
298         CAMERA_LOGE("%s: sprintf  failed", __func__);
299         return;
300     }
301     videoFd_ = open(path, O_RDWR | O_CREAT, 00766); // 00766:file operate permission
302     if (videoFd_ < 0) {
303         CAMERA_LOGE("demo test: StartVideo open /data/3516.yuv %{public}s\n", strerror(errno));
304     }
305 }
306 
CreatStreams(const int streamIdSecond,StreamIntent intent)307 RetCode Hos3516Demo::CreatStreams(const int streamIdSecond, StreamIntent intent)
308 {
309     int rc = 0;
310     std::vector<std::shared_ptr<StreamInfo>> streamInfos;
311     std::vector<std::shared_ptr<StreamInfo>>().swap(streamInfos);
312 
313     CAMERA_LOGD("demo test: CreatStreams streamIdSecond = %{public}d", streamIdSecond);
314     GetStreamOpt();
315     if (streamOperator_ == nullptr) {
316         CAMERA_LOGE("demo test: CreatStreams GetStreamOpt() is nullptr\n");
317         return RC_ERROR;
318     }
319 
320     std::shared_ptr<StreamInfo> previewStreamInfo = std::make_shared<StreamInfo>();
321     if (previewStreamInfo == nullptr) {
322         CAMERA_LOGE("demo test: CreatStreams previewStreamInfo is nullptr\n");
323         return RC_ERROR;
324     }
325 
326     SetStreamInfo(previewStreamInfo, streamCustomerPreview_, STREAM_ID_PREVIEW, PREVIEW);
327     if (previewStreamInfo->bufferQueue_ == nullptr) {
328         CAMERA_LOGE("demo test: CreatStream CreateProducer(); is nullptr\n");
329         return RC_ERROR;
330     }
331     streamInfos.push_back(previewStreamInfo);
332 
333     std::shared_ptr<StreamInfo> secondStreamInfo = std::make_shared<StreamInfo>();
334     if (secondStreamInfo == nullptr) {
335         CAMERA_LOGE("demo test: CreatStreams previewStreamInfo is nullptr\n");
336         return RC_ERROR;
337     }
338 
339     if (streamIdSecond == STREAM_ID_CAPTURE) {
340         SetStreamInfo(secondStreamInfo, streamCustomerCapture_, STREAM_ID_CAPTURE, intent);
341     } else {
342         SetStreamInfo(secondStreamInfo, streamCustomerVideo_, STREAM_ID_VIDEO, intent);
343     }
344 
345     if (secondStreamInfo->bufferQueue_ == nullptr) {
346         CAMERA_LOGE("demo test: CreatStreams CreateProducer() secondStreamInfo is nullptr\n");
347         return RC_ERROR;
348     }
349     streamInfos.push_back(secondStreamInfo);
350 
351     rc = streamOperator_->CreateStreams(streamInfos);
352     if (rc != Camera::NO_ERROR) {
353         CAMERA_LOGE("demo test: CreatStream CreateStreams error\n");
354         return RC_ERROR;
355     }
356 
357     rc = streamOperator_->CommitStreams(Camera::NORMAL, ability_);
358     if (rc != Camera::NO_ERROR) {
359         CAMERA_LOGE("demo test: CreatStream CommitStreams error\n");
360         std::vector<int> streamIds = {STREAM_ID_PREVIEW, streamIdSecond};
361         streamOperator_->ReleaseStreams(streamIds);
362         return RC_ERROR;
363     }
364 
365     return RC_OK;
366 }
367 
CaptureOnDualStreams(const int streamIdSecond)368 RetCode Hos3516Demo::CaptureOnDualStreams(const int streamIdSecond)
369 {
370     int rc = 0;
371     CAMERA_LOGD("demo test: CaptuCaptureOnDualStreamsreON enter");
372 
373     std::shared_ptr<Camera::CaptureInfo> previewCaptureInfo = std::make_shared<Camera::CaptureInfo>();
374     previewCaptureInfo->streamIds_ = {STREAM_ID_PREVIEW};
375     previewCaptureInfo->captureSetting_ = ability_;
376     previewCaptureInfo->enableShutterCallback_ = false;
377 
378     rc = streamOperator_->Capture(CAPTURE_ID_PREVIEW, previewCaptureInfo, true);
379     if (rc != Camera::NO_ERROR) {
380         CAMERA_LOGE("demo test: CaptureOnDualStreams preview Capture error\n");
381         streamOperator_->ReleaseStreams(previewCaptureInfo->streamIds_);
382         return RC_ERROR;
383     }
384     streamCustomerPreview_->ReceiveFrameOn(nullptr);
385 
386     std::shared_ptr<Camera::CaptureInfo> secondCaptureInfo = std::make_shared<Camera::CaptureInfo>();
387     secondCaptureInfo->streamIds_ = {streamIdSecond};
388     secondCaptureInfo->captureSetting_ = ability_;
389     previewCaptureInfo->enableShutterCallback_ = false;
390 
391     if (streamIdSecond == STREAM_ID_CAPTURE) {
392         rc = streamOperator_->Capture(CAPTURE_ID_CAPTURE, secondCaptureInfo, true);
393         if (rc != Camera::NO_ERROR) {
394             CAMERA_LOGE("demo test: CaptureOnDualStreams CAPTURE_ID_CAPTURE error\n");
395             streamOperator_->ReleaseStreams(secondCaptureInfo->streamIds_);
396             return RC_ERROR;
397         }
398 
399         streamCustomerCapture_->ReceiveFrameOn([this](void* addr, const uint32_t size) {
400             StoreImage(addr, size);
401         });
402     } else {
403         rc = streamOperator_->Capture(CAPTURE_ID_VIDEO, secondCaptureInfo, true);
404         if (rc != Camera::NO_ERROR) {
405             CAMERA_LOGE("demo test: CaptureOnDualStreams CAPTURE_ID_VIDEO error\n");
406             streamOperator_->ReleaseStreams(secondCaptureInfo->streamIds_);
407             return RC_ERROR;
408         }
409 
410         OpenVideoFile();
411         streamCustomerVideo_->ReceiveFrameOn([this](void* addr, const uint32_t size) {
412             StoreVideo(addr, size);
413         });
414     }
415 
416     CAMERA_LOGD("demo test: CaptuCaptureOnDualStreamsreON exit");
417 
418     return RC_OK;
419 }
420 
StartDualStreams(const int streamIdSecond)421 RetCode Hos3516Demo::StartDualStreams(const int streamIdSecond)
422 {
423     RetCode rc = RC_OK;
424 
425     CAMERA_LOGD("demo test: StartDualStreams enter");
426 
427     if (streamCustomerPreview_ == nullptr) {
428         streamCustomerPreview_ = std::make_shared<StreamCustomer>();
429     }
430 
431     if (isPreviewOn_ == 0) {
432         isPreviewOn_ = 1;
433         if (streamIdSecond == STREAM_ID_CAPTURE) {
434             if (streamCustomerCapture_ == nullptr) {
435                 streamCustomerCapture_ = std::make_shared<StreamCustomer>();
436             }
437 
438             if (isCaptureOn_ == 0) {
439                 isCaptureOn_ = 1;
440                 rc = CreatStreams(streamIdSecond, STILL_CAPTURE);
441                 if (rc != RC_OK) {
442                     CAMERA_LOGE("demo test:StartPreviewStream CreatStreams error");
443                     return RC_ERROR;
444                 }
445             }
446         } else {
447             if (streamCustomerVideo_ == nullptr) {
448                 streamCustomerVideo_ = std::make_shared<StreamCustomer>();
449             }
450 
451             if (isVideoOn_ == 0) {
452                 isVideoOn_ = 1;
453                 rc = CreatStreams(streamIdSecond, VIDEO);
454                 if (rc != RC_OK) {
455                     CAMERA_LOGE("demo test:StartPreviewStream CreatStreams error");
456                     return RC_ERROR;
457                 }
458             }
459         }
460     }
461 
462     CAMERA_LOGD("demo test: StartDualStreams exit");
463 
464     return RC_OK;
465 }
466 
StartCaptureStream()467 RetCode Hos3516Demo::StartCaptureStream()
468 {
469     RetCode rc = RC_OK;
470 
471     CAMERA_LOGD("demo test: StartCaptureStream enter");
472     if (streamCustomerCapture_ == nullptr) {
473         streamCustomerCapture_ = std::make_shared<StreamCustomer>();
474     }
475 
476     if (isCaptureOn_ == 0) {
477         isCaptureOn_ = 1;
478 
479         rc = CreatStream(STREAM_ID_CAPTURE, streamCustomerCapture_, STILL_CAPTURE);
480         if (rc != RC_OK) {
481             CAMERA_LOGE("demo test:StartCaptureStream CreatStream error");
482             return RC_ERROR;
483         }
484     }
485 
486     CAMERA_LOGD("demo test: StartCaptureStream exit");
487 
488     return RC_OK;
489 }
490 
StartVideoStream()491 RetCode Hos3516Demo::StartVideoStream()
492 {
493     RetCode rc = RC_OK;
494 
495     CAMERA_LOGD("demo test: StartVideoStream enter");
496     if (streamCustomerVideo_ == nullptr) {
497         streamCustomerVideo_ = std::make_shared<StreamCustomer>();
498     }
499 
500     if (isVideoOn_ == 0) {
501         isVideoOn_ = 1;
502 
503         rc = CreatStream(STREAM_ID_VIDEO, streamCustomerVideo_, VIDEO);
504         if (rc != RC_OK) {
505             CAMERA_LOGE("demo test:StartVideoStream CreatStream error");
506             return RC_ERROR;
507         }
508     }
509 
510     CAMERA_LOGD("demo test: StartVideoStream exit");
511 
512     return RC_OK;
513 }
514 
StartPreviewStream()515 RetCode Hos3516Demo::StartPreviewStream()
516 {
517     RetCode rc = RC_OK;
518 
519     CAMERA_LOGD("demo test: StartPreviewStream enter");
520 
521     if (streamCustomerPreview_ == nullptr) {
522         streamCustomerPreview_ = std::make_shared<StreamCustomer>();
523     }
524 
525     if (isPreviewOn_ == 0) {
526         isPreviewOn_ = 1;
527 
528         rc = CreatStream(STREAM_ID_PREVIEW, streamCustomerPreview_, PREVIEW);
529         if (rc != RC_OK) {
530             CAMERA_LOGE("demo test:StartPreviewStream CreatStream error");
531             return RC_ERROR;
532         }
533     }
534 
535     CAMERA_LOGD("demo test: StartPreviewStream exit");
536 
537     return RC_OK;
538 }
539 
ReleaseAllStream()540 RetCode Hos3516Demo::ReleaseAllStream()
541 {
542     std::vector<int> streamIds = {};
543 
544     CAMERA_LOGD("demo test: ReleaseAllStream enter");
545 
546     if (isPreviewOn_ != 1) {
547         CAMERA_LOGE("demo test: ReleaseAllStream preview is not running");
548         return RC_ERROR;
549     }
550 
551     if (isCaptureOn_ == 1) {
552         CAMERA_LOGD("demo test: ReleaseAllStream STREAM_ID_PREVIEW STREAM_ID_CAPTURE");
553         streamIds = {STREAM_ID_PREVIEW, STREAM_ID_CAPTURE};
554         streamOperator_->ReleaseStreams(streamIds);
555     } else {
556         CAMERA_LOGD("demo test: ReleaseAllStream STREAM_ID_PREVIEW STREAM_ID_VIDEO");
557         streamIds = {STREAM_ID_PREVIEW, STREAM_ID_VIDEO};
558         streamOperator_->ReleaseStreams(streamIds);
559     }
560 
561     isPreviewOn_ = 0;
562     isCaptureOn_ = 0;
563     isVideoOn_ = 0;
564 
565     CAMERA_LOGD("demo test: ReleaseAllStream exit");
566 
567     return RC_OK;
568 }
569 
QuitDemo()570 void Hos3516Demo::QuitDemo()
571 {
572     ReleaseCameraDevice();
573     CAMERA_LOGD("demo test: QuitDemo done\n");
574 }
575 
SetAwbMode(const int mode) const576 void Hos3516Demo::SetAwbMode(const int mode) const
577 {
578     CAMERA_LOGD("demo test: SetAwbMode enter\n");
579 
580     constexpr size_t entryCapacity = 100;
581     constexpr size_t dataCapacity = 2000;
582 
583     std::shared_ptr<CameraSetting> metaData = std::make_shared<CameraSetting>(entryCapacity, dataCapacity);
584 
585     const uint8_t awbMode = mode;
586     metaData->addEntry(OHOS_CONTROL_AWB_MODE, &awbMode, 1);
587     demoCameraDevice_->UpdateSettings(metaData);
588 
589     CAMERA_LOGD("demo test: SetAwbMode exit\n");
590 }
591 
SetAeExpo()592 void Hos3516Demo::SetAeExpo()
593 {
594     int32_t expo;
595 
596     CAMERA_LOGD("demo test: SetAeExpo enter\n");
597 
598     constexpr size_t entryCapacity = 100;
599     constexpr size_t dataCapacity = 2000;
600 
601     std::shared_ptr<CameraSetting> metaData = std::make_shared<CameraSetting>(entryCapacity, dataCapacity);
602 
603     if (aeStatus_) {
604         expo = 0xa0;
605     } else {
606         expo = 0x30;
607     }
608     aeStatus_ = !aeStatus_;
609     metaData->addEntry(OHOS_CONTROL_AE_EXPOSURE_COMPENSATION, &expo, 1);
610     demoCameraDevice_->UpdateSettings(metaData);
611 
612     CAMERA_LOGD("demo test: SetAeExpo exit\n");
613 }
614 
FlashlightOnOff(bool onOff)615 void Hos3516Demo::FlashlightOnOff(bool onOff)
616 {
617     int rc = 0;
618     CAMERA_LOGD("demo test: FlashlightOnOff enter\n");
619 
620     if (demoCameraHost_ == nullptr) {
621         CAMERA_LOGE("demo test: FlashlightOnOff demoCameraHost_ == nullptr\n");
622         return;
623     }
624 
625     demoCameraHost_->SetFlashlight(cameraIds_.front(), onOff);
626 
627     CAMERA_LOGD("demo test: FlashlightOnOff exit \n");
628 }
629 
StreamOffline(const int streamId)630 RetCode Hos3516Demo::StreamOffline(const int streamId)
631 {
632     int rc = 0;
633     constexpr size_t offlineDelayTime = 4;
634     CAMERA_LOGD("demo test: StreamOffline enter\n");
635 
636     sptr<IStreamOperatorCallback> streamOperatorCallback = new StreamOperatorCallback();
637     sptr<IOfflineStreamOperator> offlineStreamOperator = nullptr;
638 
639     rc = streamOperator_->ChangeToOfflineStream({streamId}, streamOperatorCallback, offlineStreamOperator);
640     if (rc != NO_ERROR) {
641         CAMERA_LOGE("demo test: StreamOffline ChangeToOfflineStream error\n");
642         return RC_ERROR;
643     }
644 
645     CaptureOff(CAPTURE_ID_PREVIEW, CAPTURE_PREVIEW);
646     CaptureOff(CAPTURE_ID_CAPTURE, CAPTURE_SNAPSHOT);
647     sleep(1);
648     ReleaseAllStream();
649     ReleaseCameraDevice();
650     sleep(offlineDelayTime);
651 
652     CAMERA_LOGD("demo test: begin to release offlne stream");
653     rc = offlineStreamOperator->CancelCapture(CAPTURE_ID_CAPTURE);
654     if (rc != NO_ERROR) {
655         CAMERA_LOGE("demo test: StreamOffline offlineStreamOperator->CancelCapture error\n");
656         return RC_ERROR;
657     }
658 
659     rc = offlineStreamOperator->Release();
660     if (rc != OHOS::Camera::NO_ERROR) {
661         CAMERA_LOGE("demo test: StreamOffline offlineStreamOperator->Release() error\n");
662         return RC_ERROR;
663     }
664 
665     streamCustomerCapture_->ReceiveFrameOff();
666 
667     CAMERA_LOGD("demo test: StreamOffline exit\n");
668 
669     return RC_OK;
670 }
671 } // namespace OHOS::Camera
672