• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef OHOS_CAMERA_DEVICE_H
17 #define OHOS_CAMERA_DEVICE_H
18 
19 #include <cstdbool>
20 #include <thread>
21 #include <vector>
22 
23 #include "camera_ability.h"
24 #include "camera_config.h"
25 #include "codec_type.h"
26 #include "frame_config.h"
27 #include "surface.h"
28 using namespace std;
29 namespace OHOS {
30 namespace Media {
31 enum LoopState {
32     LOOP_IDLE,
33     LOOP_READY,
34     LOOP_LOOPING,
35     LOOP_STOP,
36     LOOP_ERROR,
37 };
38 const int32_t RECODER_MAX_NUM = 2;
39 class DeviceAssistant {
40 public:
41     std::thread *thrd_ = nullptr;
42     LoopState state_ = LOOP_IDLE;
43     FrameConfig *fc_ = nullptr;
44     uint32_t cameraId_;
45     uint32_t streamId_;
46 
SetFrameConfig(FrameConfig & fc,uint32_t * streamId)47     virtual int32_t SetFrameConfig(FrameConfig &fc, uint32_t *streamId)
48     {
49         return -1;
50     }
Start(uint32_t streamId)51     virtual int32_t Start(uint32_t streamId)
52     {
53         return -1;
54     }
Stop()55     virtual int32_t Stop()
56     {
57         return -1;
58     }
59 };
60 
61 class RecordAssistant : public DeviceAssistant {
62 public:
63     int32_t SetFrameConfig(FrameConfig &fc, uint32_t *streamId) override;
64     int32_t Start(uint32_t streamId) override;
65     int32_t Stop() override;
66 
67     vector<CODEC_HANDLETYPE> vencHdls_;
68     vector<list<Surface *>> vencSurfaces_;
69     static int OnVencBufferAvailble(UINTPTR hComponent, UINTPTR dataIn, OutputInfo *buffer);
70     static CodecCallback recordCodecCb_;
71     int32_t streamIdNum_[RECODER_MAX_NUM] = {-1, -1};
72 };
73 
74 class PreviewAssistant : public DeviceAssistant {
75 public:
76     int32_t SetFrameConfig(FrameConfig &fc, uint32_t *streamId) override;
77     int32_t Start(uint32_t streamId) override;
78     virtual int32_t Stop() override;
79     Surface *capSurface_ = nullptr;
80 private:
81     pthread_t threadId;
82     static void *YuvCopyProcess(void *arg);
83 };
84 
85 class CaptureAssistant : public DeviceAssistant {
86     int32_t SetFrameConfig(FrameConfig &fc, uint32_t *streamId) override;
87     int32_t Start(uint32_t streamId) override;
88     virtual int32_t Stop() override;
89     CODEC_HANDLETYPE vencHdl_ = nullptr;
90     Surface *capSurface_ = nullptr;
91 };
92 
93 class CallbackAssistant : public DeviceAssistant {
94 public:
95     int32_t SetFrameConfig(FrameConfig &fc, uint32_t *streamId) override;
96     int32_t Start(uint32_t streamId) override;
97     virtual int32_t Stop() override;
98     Surface *capSurface_ = nullptr;
99 private:
100     pthread_t threadId;
101     static void *StreamCopyProcess(void *arg);
102 };
103 
104 class CameraDevice {
105 public:
106     CameraDevice();
107     CameraDevice(uint32_t cameraId);
108     virtual ~CameraDevice();
109 
110     int32_t Initialize();
111     int32_t UnInitialize();
112     int32_t SetCameraConfig();
113     int32_t TriggerLoopingCapture(FrameConfig &fc, uint32_t *streamId);
114     void StopLoopingCapture();
115     int32_t TriggerSingleCapture(FrameConfig &fc, uint32_t *streamId);
116     uint32_t GetCameraId();
117 private:
118     uint32_t cameraId;
119     RecordAssistant recordAssistant_;
120     PreviewAssistant previewAssistant_;
121     CaptureAssistant captureAssistant_;
122     CallbackAssistant callbackAssistant_;
123 };
124 } // namespace Media
125 } // namespace OHOS
126 #endif // OHOS_CAMERA_DEVICE_H