1 /*
2 * Copyright (c) 2020 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 <sys/stat.h>
18 #include <sys/types.h>
19 #include <fcntl.h>
20
21 #include "camera_manager.h"
22 #include "securec.h"
23 #include "ui_config.h"
24
25 using namespace std;
26 using namespace OHOS;
27 using namespace OHOS::Media;
28
29 static constexpr int TEMP_BUF_LEN = 8;
30 static constexpr int MAX_THM_SIZE = (64 * PAGE_SIZE);
31 static constexpr int FILE_NAME_LEN = 128;
32 static constexpr int MILLI_SECONDS = 1000;
33 static constexpr int PIC_WIDTH = 1920;
34 static constexpr int PIC_HEIGHT = 1080;
35
36 char* g_dstBuf = nullptr;
37
SampleDealThumb(char * psrc,uint32_t srcSize,uint32_t * dstSize,uint16_t u16THMLen)38 static int32_t SampleDealThumb(char* psrc, uint32_t srcSize, uint32_t* dstSize, uint16_t u16THMLen)
39 {
40 int32_t endpos = 0;
41 uint32_t s32I = 0;
42 int32_t startpos = 0;
43 char tempbuf[TEMP_BUF_LEN] = { 0 };
44 int32_t bufpos = 0;
45 char startflag[2] = { 0xff, 0xd8 };
46 char endflag[2] = { 0xff, 0xd9 };
47
48 while (s32I < srcSize) {
49 if (bufpos >= TEMP_BUF_LEN) {
50 break;
51 }
52 tempbuf[bufpos] = psrc[s32I++];
53 if (bufpos > 0) {
54 if (0 == memcmp(tempbuf + bufpos - 1, startflag, sizeof(startflag))) {
55 startpos = s32I - 2; /* 2 thumb head offset */
56 if (startpos < 0) {
57 startpos = 0;
58 }
59 }
60 if (0 == memcmp(tempbuf + bufpos - 1, endflag, sizeof(endflag))) {
61 endpos = s32I;
62 break;
63 }
64 }
65 if (++bufpos == (TEMP_BUF_LEN - 1)) {
66 if (tempbuf[bufpos - 1] != 0xFF) {
67 bufpos = 0;
68 }
69 } else if (bufpos > (TEMP_BUF_LEN - 1)) {
70 bufpos = 0;
71 }
72 }
73
74 if ((endpos - startpos <= 0) || (static_cast<uint32_t>(endpos - startpos) >= srcSize)) {
75 return -1;
76 }
77
78 char* temp = psrc + startpos;
79 if (MAX_THM_SIZE < (endpos - startpos)) {
80 return -1;
81 }
82 char* cDstBuf = (char*)malloc(endpos - startpos);
83 if (cDstBuf == nullptr) {
84 return -1;
85 }
86
87 (void)memcpy_s(cDstBuf, endpos - startpos, temp, endpos - startpos);
88
89 g_dstBuf = cDstBuf;
90 *dstSize = endpos - startpos;
91
92 return 0;
93 }
94
SampleGetThmFromJpg(const char * jpegPath,uint32_t * dstSize)95 static int32_t SampleGetThmFromJpg(const char* jpegPath, uint32_t* dstSize)
96 {
97 FILE* fpJpg = nullptr;
98 fpJpg = fopen(jpegPath, "rb");
99 char* pszFile = nullptr;
100 int32_t fd = 0;
101 struct stat stStat;
102 (void)memset_s(&stStat, sizeof(struct stat), 0, sizeof(struct stat));
103 if (fpJpg == nullptr) {
104 printf("file %s not exist!\n", jpegPath);
105 return -1;
106 }
107 fd = fileno(fpJpg);
108 fstat(fd, &stStat);
109 pszFile = (char*)malloc(stStat.st_size);
110 if ((pszFile == nullptr) || (stStat.st_size < 6)) { /* 6 min size of thumb head */
111 fflush(fpJpg);
112 fsync(fileno(fpJpg));
113 fclose(fpJpg);
114 if (pszFile) {
115 free(pszFile);
116 pszFile = nullptr;
117 }
118 printf("memory malloc fail!\n");
119 return -1;
120 }
121
122 if (fread(pszFile, stStat.st_size, 1, fpJpg) <= 0) {
123 fflush(fpJpg);
124 fsync(fileno(fpJpg));
125 fclose(fpJpg);
126 free(pszFile);
127 printf("fread jpeg src fail!\n");
128 return -1;
129 }
130 fclose(fpJpg);
131
132 // The fourth byte is shifted to the left by eight bits then the fifth byte is added.
133 // the 4 byte is the length high 8 bit, and byte 5 is low 8bit;
134 uint16_t u16THMLen = (static_cast<uint16_t>(pszFile[4]) << 8) + pszFile[5];
135 if (SampleDealThumb(pszFile, stStat.st_size, dstSize, u16THMLen) < 0) {
136 printf("get jpg thumb failed! \n");
137 free(pszFile);
138 return -1;
139 }
140 free(pszFile);
141 return 0;
142 }
143
SampleGetdcfinfo(const char * srcJpgPath,const char * dstThmPath)144 int32_t SampleGetdcfinfo(const char* srcJpgPath, const char* dstThmPath)
145 {
146 int32_t s32RtnVal = 0;
147 char jpegSrcPath[FILE_NAME_LEN] = { 0 };
148 char jpegDesPath[FILE_NAME_LEN] = { 0 };
149 uint32_t dstSize = 0;
150 if (sprintf_s(jpegSrcPath, sizeof(jpegSrcPath), "%s", srcJpgPath) < 0) {
151 return -1;
152 }
153 if (sprintf_s(jpegDesPath, sizeof(jpegDesPath), "%s", dstThmPath) < 0) {
154 return -1;
155 }
156 s32RtnVal = SampleGetThmFromJpg(static_cast<const char *>(jpegSrcPath), &dstSize);
157 if ((s32RtnVal != 0) || (dstSize == 0)) {
158 printf("fail to get thm\n");
159 return -1;
160 }
161 FILE* fpTHM = fopen(jpegDesPath, "w");
162 if (fpTHM == 0) {
163 printf("file to create file %s\n", jpegDesPath);
164 return -1;
165 }
166 uint32_t u32WritenSize = 0;
167 while (u32WritenSize < dstSize) {
168 s32RtnVal = fwrite(g_dstBuf + u32WritenSize, 1, dstSize, fpTHM);
169 if (s32RtnVal <= 0) {
170 printf("fail to wirte file, rtn=%d\n", s32RtnVal);
171 break;
172 }
173 u32WritenSize += s32RtnVal;
174 }
175 if (fpTHM != nullptr) {
176 fflush(fpTHM);
177 fsync(fileno(fpTHM));
178 fclose(fpTHM);
179 fpTHM = 0;
180 }
181 if (g_dstBuf != nullptr) {
182 free(g_dstBuf);
183 g_dstBuf = nullptr;
184 }
185 return 0;
186 }
187
SampleSaveCapture(const char * p,uint32_t size,int type,const char * timeStamp,int length)188 static void SampleSaveCapture(const char* p, uint32_t size, int type, const char *timeStamp, int length)
189 {
190 char acFileDcf[FILE_NAME_LEN] = {0};
191 FILE *fp = nullptr;
192 char acFile[FILE_NAME_LEN] = { 0 };
193
194 if (type == 0) {
195 char tmpFile[FILE_NAME_LEN] = {0};
196 if (sprintf_s(tmpFile, sizeof(tmpFile), "%s/photo%s.jpg", PHOTO_PATH, timeStamp) < 0) {
197 return;
198 }
199 fp = fopen(tmpFile, "w+");
200 if (fp) {
201 fwrite(p, 1, size, fp);
202 fflush(fp);
203 fsync(fileno(fp));
204 fclose(fp);
205 }
206 }
207
208 if (sprintf_s(acFile, sizeof(acFile), "%s/tmp.jpg", PHOTO_PATH) < 0) {
209 return;
210 }
211 remove(acFile);
212
213 fp = fopen(acFile, "w+");
214 if (fp == NULL) {
215 return;
216 }
217 fwrite(p, 1, size, fp);
218 fflush(fp);
219 fsync(fileno(fp));
220 fclose(fp);
221
222 if (type == 0) {
223 if (sprintf_s(acFileDcf, sizeof(acFileDcf), "%s/photo%s.jpg", THUMB_PATH, timeStamp) < 0) {
224 return;
225 }
226 } else if (type == 1) {
227 if (sprintf_s(acFileDcf, sizeof(acFileDcf), "%s/video%s.jpg", THUMB_PATH, timeStamp) < 0) {
228 return;
229 }
230 } else {
231 return;
232 }
233
234 SampleGetdcfinfo(static_cast<char *>(acFile), static_cast<char *>(acFileDcf));
235 }
236
CameraGetRecordFd(const char * p)237 static int CameraGetRecordFd(const char* p)
238 {
239 int fd = -1;
240 char pname[128] = {0};
241 char *ptr = const_cast<char *>(p);
242 char *pe = strrchr(ptr, '.');
243 char *ps = strrchr(ptr, '/');
244 if (pe == nullptr || ps == nullptr) {
245 return -1;
246 }
247
248 if (strcpy_s(static_cast<char *>(pname), sizeof(pname), VIDEO_PATH) != 0) {
249 return -1;
250 }
251
252 if (strncat_s(pname, sizeof(pname), ps, pe - ps) != 0) {
253 return -1;
254 }
255
256 if (strcat_s(pname, sizeof(pname), ".mp4") < 0) {
257 return -1;
258 }
259 fd = open(pname, O_RDWR | O_CREAT | O_CLOEXEC | O_TRUNC, S_IROTH | S_IRUSR | S_IWUSR);
260 if (fd < 0) {
261 return -1;
262 }
263
264 return fd;
265 }
266
SampleCreateRecorder(int w,int h)267 Recorder *SampleCreateRecorder(int w, int h)
268 {
269 int ret = 0;
270 AudioCodecFormat audioFormat = AAC_LC;
271 AudioSourceType inputSource = AUDIO_MIC;
272 VideoSourceType source = VIDEO_SOURCE_SURFACE_ES;
273 int32_t sourceId = 0;
274 int32_t audioSourceId = 0;
275
276 VideoCodecFormat encoder = HEVC;
277
278 Recorder *recorder = new Recorder();
279 if ((ret = recorder->SetVideoSource(source, sourceId)) != SUCCESS) {
280 goto EXIT_;
281 }
282 if ((ret = recorder->SetVideoEncoder(sourceId, encoder)) != SUCCESS) {
283 goto EXIT_;
284 }
285 if ((ret = recorder->SetVideoSize(sourceId, w, h)) != SUCCESS) {
286 goto EXIT_;
287 }
288 if ((ret = recorder->SetVideoFrameRate(sourceId, FRAME_RATE)) != SUCCESS) {
289 goto EXIT_;
290 }
291 if ((ret = recorder->SetVideoEncodingBitRate(sourceId, BIT_RATE)) != SUCCESS) {
292 goto EXIT_;
293 }
294 if ((ret = recorder->SetCaptureRate(sourceId, FRAME_RATE)) != SUCCESS) {
295 goto EXIT_;
296 }
297 if ((ret = recorder->SetAudioSource(inputSource, audioSourceId)) != SUCCESS) {
298 goto EXIT_;
299 }
300 if ((ret = recorder->SetAudioEncoder(audioSourceId, audioFormat)) != SUCCESS) {
301 goto EXIT_;
302 }
303 if ((ret = recorder->SetAudioSampleRate(audioSourceId, SAMPLE_RATE)) != SUCCESS) {
304 goto EXIT_;
305 }
306 if ((ret = recorder->SetAudioChannels(audioSourceId, CHANNEL_COUNT)) != SUCCESS) {
307 goto EXIT_;
308 }
309 if ((ret = recorder->SetAudioEncodingBitRate(audioSourceId, AUDIO_ENCODING_BITRATE)) != SUCCESS) {
310 goto EXIT_;
311 }
312
313 if ((ret = recorder->SetMaxDuration(36000)) != SUCCESS) { // 36000=10h
314 goto EXIT_;
315 }
316 EXIT_:
317 if (ret != SUCCESS) {
318 delete recorder;
319 recorder = nullptr;
320 }
321 return recorder;
322 }
323
324 // TestFrameStateCallback
OnFrameFinished(Camera & camera,FrameConfig & fc,FrameResult & result)325 void TestFrameStateCallback::OnFrameFinished(Camera &camera, FrameConfig &fc, FrameResult &result)
326 {
327 if (fc.GetFrameConfigType() == FRAME_CONFIG_CAPTURE) {
328 cout << "Capture frame received." << endl;
329 list<Surface *> surfaceList = fc.GetSurfaces();
330
331 for (Surface *surface : surfaceList) {
332 SurfaceBuffer *buffer = surface->AcquireBuffer();
333 if (buffer != nullptr) {
334 char *virtAddr = static_cast<char *>(buffer->GetVirAddr());
335 if (virtAddr != nullptr) {
336 SampleSaveCapture(virtAddr, buffer->GetSize(),
337 gPhotoType_, static_cast<const char *>(timeStamp_), sizeof(timeStamp_));
338 }
339 surface->ReleaseBuffer(buffer);
340 } else {
341 printf("ERROR:surface buffer is NULL!! \n");
342 }
343 delete surface;
344
345 gIsFinished_ = true;
346 }
347 delete &fc;
348 } else if (fc.GetFrameConfigType() == FRAME_CONFIG_RECORD || fc.GetFrameConfigType() == FRAME_CONFIG_PREVIEW) {
349 delete &fc;
350 }
351 }
352
SetPhotoType(int type)353 void TestFrameStateCallback::SetPhotoType(int type)
354 {
355 gPhotoType_ = type;
356 gIsFinished_ = false;
357 }
358
IsFinish(void)359 bool TestFrameStateCallback::IsFinish(void)
360 {
361 return gIsFinished_;
362 }
363
GetVideoName(char * pName,size_t length) const364 void TestFrameStateCallback::GetVideoName(char *pName, size_t length) const
365 {
366 if (strlen(videoName_) <= 0)
367 return;
368 if (pName == nullptr || length < strlen(videoName_))
369 return;
370 if (strcpy_s(pName, length, videoName_) != 0) {
371 return;
372 }
373 }
374
InitTimeStamp()375 void TestFrameStateCallback::InitTimeStamp()
376 {
377 struct timeval tv;
378 struct tm *ltm = nullptr;
379 gettimeofday(&tv, nullptr);
380 ltm = localtime(&tv.tv_sec);
381 if (ltm != nullptr) {
382 if (sprintf_s(timeStamp_, sizeof(timeStamp_), "%02d-%02d-%02d-%lld",
383 ltm->tm_hour, ltm->tm_min, ltm->tm_sec, tv.tv_usec / MILLI_SECONDS) < 0) {
384 return;
385 }
386 }
387 }
388
InitVideoName()389 void TestFrameStateCallback::InitVideoName()
390 {
391 if (sprintf_s(videoName_, sizeof(videoName_), "%s/video%s.jpg", THUMB_PATH, timeStamp_) < 0) {
392 return;
393 }
394 }
395
396 // SampleCameraStateMng class
~SampleCameraStateMng()397 SampleCameraStateMng::~SampleCameraStateMng()
398 {
399 if (recorder_ != nullptr) {
400 if (gRecordSta_ != MEDIA_STATE_IDLE) {
401 recorder_->Stop(false);
402 }
403 recorder_->Release();
404 delete recorder_;
405 }
406 if (gRecFd_ > 0) {
407 FILE *fp = fdopen(gRecFd_, "w+");
408 if (fp) {
409 fflush(fp);
410 fsync(gRecFd_);
411 fclose(fp);
412 close(gRecFd_);
413 }
414 }
415 if (fc_) {
416 delete fc_;
417 fc_ = nullptr;
418 }
419 }
420
OnCreated(Camera & c)421 void SampleCameraStateMng::OnCreated(Camera &c)
422 {
423 cout << "Sample recv OnCreate camera." << endl;
424 auto config = CameraConfig::CreateCameraConfig();
425 if (config == nullptr) {
426 cout << "New object failed." << endl;
427 return;
428 }
429 config->SetFrameStateCallback(&fsCb_, &eventHdlr_);
430 c.Configure(*config);
431 cam_ = &c;
432 }
433
StartRecord(Surface * mSurface)434 void SampleCameraStateMng::StartRecord(Surface *mSurface)
435 {
436 int ret = 0;
437 if (gRecordSta_ == MEDIA_STATE_START) {
438 return;
439 }
440 if (recorder_ == nullptr) {
441 recorder_ = SampleCreateRecorder(IMAGE_WIDTH, IMAGE_HEIGHT);
442 }
443 if (recorder_ == nullptr) {
444 return;
445 }
446 if (gRecFd_ > 0) {
447 FILE *fp = fdopen(gRecFd_, "w+");
448 if (fp) {
449 fflush(fp);
450 fsync(gRecFd_);
451 fclose(fp);
452 close(gRecFd_);
453 }
454 gRecFd_ = -1;
455 }
456
457 char vName[MAX_NAME_LEN] = {0};
458 fsCb_.GetVideoName(vName, sizeof(vName));
459 gRecFd_ = CameraGetRecordFd(static_cast<char *>(vName));
460 if (gRecFd_ < 0) {
461 return;
462 }
463
464 if (gRecordSta_ == MEDIA_STATE_PAUSE) {
465 recorder_->SetNextOutputFile(gRecFd_);
466 recorder_->Resume();
467 } else {
468 ret = recorder_->SetOutputFile(gRecFd_);
469 if (ret != SUCCESS || recorder_->Prepare() != SUCCESS || recorder_->Start() != SUCCESS) {
470 return;
471 }
472 }
473
474 auto surface = recorder_->GetSurface(0);
475 if (surface == nullptr) {
476 return;
477 }
478
479 surface->SetWidthAndHeight(IMAGE_WIDTH, IMAGE_HEIGHT);
480 surface->SetQueueSize(3); /* queueSize is 3 */
481 surface->SetSize(PAGE_SIZE * PAGE_SIZE);
482
483 FrameConfig *fc = new FrameConfig(FRAME_CONFIG_RECORD);
484 fc->AddSurface(*surface);
485 if (cam_->TriggerLoopingCapture(*fc) != 0) {
486 delete fc;
487 return;
488 }
489 gRecordSta_ = MEDIA_STATE_START;
490 }
491
StartPreview(Surface * surface)492 void SampleCameraStateMng::StartPreview(Surface *surface)
493 {
494 printf("enter StartPreview ##################################### \n");
495 if (cam_ == nullptr) {
496 cout << "Camera is not ready." << endl;
497 return;
498 }
499 if (gPreviewSta_ == MEDIA_STATE_START) {
500 cout << "Camera is already previewing." << endl;
501 return;
502 }
503 if (surface == nullptr) {
504 cout << "surface is NULL." << endl;
505 return;
506 }
507
508 FrameConfig *fc = new FrameConfig(FRAME_CONFIG_PREVIEW);
509 fc->AddSurface(*surface);
510 int32_t ret = cam_->TriggerLoopingCapture(*fc);
511 if (ret != 0) {
512 delete fc;
513 cout << "camera start preview failed. ret=" << ret << endl;
514 return;
515 }
516
517 gPreviewSta_ = MEDIA_STATE_START;
518 cout << "camera start preview succeed." << endl;
519 }
520
Capture(int type)521 void SampleCameraStateMng::Capture(int type)
522 {
523 printf("camera start Capture ##################################### \n");
524 if (cam_ == nullptr) {
525 cout << "Camera is not ready." << endl;
526 return;
527 }
528
529 fsCb_.SetPhotoType(type);
530 fsCb_.InitTimeStamp();
531 fsCb_.InitVideoName();
532
533 FrameConfig *fc = new FrameConfig(FRAME_CONFIG_CAPTURE);
534 Surface *surface = Surface::CreateSurface();
535 if (surface == nullptr) {
536 delete fc;
537 return;
538 }
539
540 surface->SetWidthAndHeight(IMAGE_WIDTH, IMAGE_HEIGHT);
541 fc->AddSurface(*surface);
542 printf("Capture before TriggerSingleCapture. ##################################### \n");
543 cam_->TriggerSingleCapture(*fc);
544 printf("camera start Capture over. ##################################### \n");
545 }
546
IsCaptureOver(void)547 bool SampleCameraStateMng::IsCaptureOver(void)
548 {
549 return fsCb_.IsFinish();
550 }
551
SetPause()552 void SampleCameraStateMng::SetPause() { }
553
SetResume(Surface * mSurface)554 void SampleCameraStateMng::SetResume(Surface *mSurface) { }
555
SetStop(int s)556 void SampleCameraStateMng::SetStop(int s)
557 {
558 if (cam_ == nullptr) {
559 cout << "Camera is not ready." << endl;
560 return;
561 }
562
563 if (s == 0) { /* only stop recorder */
564 cam_->StopLoopingCapture(FRAME_CONFIG_RECORD);
565 } else {
566 cam_->StopLoopingCapture(-1);
567 }
568
569 if (gRecordSta_ == MEDIA_STATE_START) {
570 if (s) {
571 recorder_->Stop(false);
572 gRecordSta_ = MEDIA_STATE_IDLE;
573 } else {
574 recorder_->Pause();
575 gRecordSta_ = MEDIA_STATE_PAUSE;
576 }
577 }
578
579 gPreviewSta_ = MEDIA_STATE_IDLE;
580 }
581
RecordState()582 bool SampleCameraStateMng::RecordState()
583 {
584 return (gRecordSta_ == MEDIA_STATE_START);
585 }
586
CameraIsReady()587 bool SampleCameraStateMng::CameraIsReady()
588 {
589 return (cam_ == nullptr) ? false : true;
590 }
591
592 // SampleCameraManager class
~SampleCameraManager()593 SampleCameraManager::~SampleCameraManager()
594 {
595 if (CamStateMng) {
596 CamStateMng->SetStop(1);
597 delete CamStateMng;
598 CamStateMng = nullptr;
599 }
600 }
601
SampleCameraCreate()602 int SampleCameraManager::SampleCameraCreate()
603 {
604 int retval = 0;
605 printf("camera start init!!! \n");
606 camKit = CameraKit::GetInstance();
607 if (camKit == nullptr) {
608 cout << "Can not get CameraKit instance" << endl;
609 return -1;
610 }
611
612 list<string> camList = camKit->GetCameraIds();
613 if (camList.size() == 0) {
614 cout << "SampleCameraCreate camList.size() = 0" << endl;
615 return -1;
616 }
617 camId = camList.front();
618
619 if (camId.empty()) {
620 cout << "No available camera.(1080p wanted)" << endl;
621 printf("No available camera.(1080p wanted)####################### \n");
622 return -1;
623 }
624
625 CamStateMng = new SampleCameraStateMng(eventHdlr_);
626 if (CamStateMng == nullptr) {
627 printf("create SampleCameraStateMng failed! \n");
628 return -1;
629 }
630
631 printf("before CreateCamera \n");
632 camKit->CreateCamera(camId, *CamStateMng, eventHdlr_);
633 printf("after CreateCamera \n");
634 if (!access("/userdata/", F_OK | R_OK | W_OK)) {
635 if (access(PHOTO_PATH, F_OK) != 0) {
636 mkdir(PHOTO_PATH, FILE_MODE);
637 }
638 if (access(THUMB_PATH, F_OK) != 0) {
639 mkdir(THUMB_PATH, FILE_MODE);
640 }
641 if (access(VIDEO_PATH, F_OK) != 0) {
642 mkdir(VIDEO_PATH, FILE_MODE);
643 }
644 }
645 printf("camera init ok! \n");
646 return retval;
647 }
648
SampleCameraExist(void)649 bool SampleCameraManager::SampleCameraExist(void)
650 {
651 return camId.empty() ? false : true;
652 }
653
SampleCameraStart(Surface * surface)654 int SampleCameraManager::SampleCameraStart(Surface *surface)
655 {
656 if (CamStateMng == nullptr) {
657 return -1;
658 }
659 CamStateMng->StartPreview(surface);
660 return 0;
661 }
662
SampleCameraStop(void)663 int SampleCameraManager::SampleCameraStop(void)
664 {
665 if (CamStateMng == nullptr) {
666 return -1;
667 }
668 CamStateMng->SetStop(1);
669 return 0;
670 }
671
SampleCameraCaptrue(int type)672 int SampleCameraManager::SampleCameraCaptrue(int type)
673 {
674 if (CamStateMng == nullptr) {
675 return -1;
676 }
677 CamStateMng->Capture(type);
678 return 0;
679 }
680
SampleCameraStartRecord(Surface * surface)681 int SampleCameraManager::SampleCameraStartRecord(Surface *surface)
682 {
683 if (CamStateMng == nullptr) {
684 return -1;
685 }
686 CamStateMng->StartRecord(surface);
687 return 0;
688 }
689
SampleCameraPauseRecord(void)690 int SampleCameraManager::SampleCameraPauseRecord(void)
691 {
692 if (CamStateMng == nullptr) {
693 return -1;
694 }
695 CamStateMng->SetPause();
696 return 0;
697 }
698
SampleCameraResumeRecord(Surface * mSurface)699 int SampleCameraManager::SampleCameraResumeRecord(Surface *mSurface)
700 {
701 if (CamStateMng == nullptr) {
702 return -1;
703 }
704 CamStateMng->SetResume(mSurface);
705 return 0;
706 }
707
SampleCameraStopRecord(void)708 int SampleCameraManager::SampleCameraStopRecord(void)
709 {
710 if (CamStateMng == nullptr) {
711 return -1;
712 }
713 CamStateMng->SetStop(0);
714 return 0;
715 }
SampleCameraGetRecord(void)716 bool SampleCameraManager::SampleCameraGetRecord(void)
717 {
718 if (CamStateMng == nullptr) {
719 return false;
720 }
721 return CamStateMng->RecordState();
722 }
723
SampleCameraCaptrueIsFinish(void)724 bool SampleCameraManager::SampleCameraCaptrueIsFinish(void)
725 {
726 return CamStateMng->IsCaptureOver();
727 }
728
SampleCameraIsReady(void)729 bool SampleCameraManager::SampleCameraIsReady(void)
730 {
731 return CamStateMng->CameraIsReady();
732 }
733