ronnie
2022-10-14 1504bb53e29d3d46222c0b3ea994fc494b48e153
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
/*
 * Copyright (c) 2021 by Allwinnertech Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
#ifndef __CAMERA_CONFIG_H_
#define __CAMERA_CONFIG_H_
 
#include "common.h"
#ifdef LOG_NDEBUG
#undef LOG_NDEBUG
#endif
 
#if DBG_CAMERA_CONFIG
#undef NDEBUG
#define LOG_NDEBUG 0
#else
#define LOG_NDEBUG 1
#endif
 
#include <stdlib.h>
#include <stdio.h>
 
#include <string>
 
#define CAMERA_KEY_CONFIG_PATH    "/vendor/etc/camera.cfg"
 
#define KEY_LENGTH    256
 
#define kCAMERA_EXIF_MAKE                 "key_camera_exif_make"
#define kCAMERA_EXIF_MODEL                "key_camera_exif_model"
 
#define kNUMBER_OF_CAMERA                 "number_of_camera"
#define kCAMERA_MULTIPLEXING              "use_camera_multiplexing"
#define kCAMERA_FACING                    "camera_facing"
#define kCAMERA_ORIENTATION               "camera_orientation"
#define kCAMERA_DEVICE                    "camera_device"
#define kDEVICE_ID                        "device_id"
#define kFAST_PICTURE_MODE                "fast_picture_mode"
#define kUSE_BUILTIN_ISP                  "use_builtin_isp"
 
#define kUSED_PREVIEW_SIZE                "used_preview_size"
#define kSUPPORT_PREVIEW_SIZE             "key_support_preview_size"
#define kDEFAULT_PREVIEW_SIZE             "key_default_preview_size"
 
#define kUSED_PICTURE_SIZE                "used_picture_size"
#define kSUPPORT_PICTURE_SIZE             "key_support_picture_size"
#define kDEFAULT_PICTURE_SIZE             "key_default_picture_size"
 
#define kUSED_INTERPOLATION_SIZE          "used_interpolation_size"
#define kSUPPORT_INTERPOLATION_SIZE       "key_support_src_interpolation_size"
#define kDEFAULT_INTERPOLATION_SIZE       "key_default_dst_interpolation_size"
 
#define kUSED_FLASH_MODE                  "used_flash_mode"
#define kSUPPORT_FLASH_MODE               "key_support_flash_mode"
#define kDEFAULT_FLASH_MODE               "key_default_flash_mode"
 
#define kUSED_COLOR_EFFECT                "used_color_effect"
#define kSUPPORT_COLOR_EFFECT             "key_support_color_effect"
#define kDEFAULT_COLOR_EFFECT             "key_default_color_effect"
 
#define kUSED_FRAME_RATE                  "used_frame_rate"
#define kSUPPORT_FRAME_RATE               "key_support_frame_rate"
#define kDEFAULT_FRAME_RATE               "key_default_frame_rate"
 
#define kUSED_FOCUS_MODE                  "used_focus_mode"
#define kSUPPORT_FOCUS_MODE               "key_support_focus_mode"
#define kDEFAULT_FOCUS_MODE               "key_default_focus_mode"
 
#define kUSED_SCENE_MODE                  "used_scene_mode"
#define kSUPPORT_SCENE_MODE               "key_support_scene_mode"
#define kDEFAULT_SCENE_MODE               "key_default_scene_mode"
 
#define kUSED_WHITE_BALANCE               "used_white_balance"
#define kSUPPORT_WHITE_BALANCE            "key_support_white_balance"
#define kDEFAULT_WHITE_BALANCE            "key_default_white_balance"
 
#define kUSED_EXPOSURE_COMPENSATION       "used_exposure_compensation"
#define kMIN_EXPOSURE_COMPENSATION        "key_min_exposure_compensation"
#define kMAX_EXPOSURE_COMPENSATION        "key_max_exposure_compensation"
#define kSTEP_EXPOSURE_COMPENSATION        "key_step_exposure_compensation"
#define kDEFAULT_EXPOSURE_COMPENSATION    "key_default_exposure_compensation"
 
#define kUSED_ZOOM                        "used_zoom"
#define kZOOM_SUPPORTED                   "key_zoom_supported"
#define kSMOOTH_ZOOM_SUPPORTED            "key_smooth_zoom_supported"
#define kZOOM_RATIOS                      "key_zoom_ratios"
#define kMAX_ZOOM                         "key_max_zoom"
#define kDEFAULT_ZOOM                     "key_default_zoom"
#define KHORIZONTAL_VIEW_ANGLE            "key_horizonal_view_angle"
#define KVERTICAL_VIEW_ANGLE              "key_vertical_view_angle"
 
#define MEMBER_DEF(mem)             \
    char mUsed##mem[2];             \
    char * mSupport##mem##Value;    \
    char * mDefault##mem##Value;
 
class CCameraConfig {
 public:
  explicit CCameraConfig(int id);
  ~CCameraConfig();
 
  void initParameters();
  void dumpParameters();
 
  static int numberOfCamera() {
    if (mhKeyFile == NULL) {
      mhKeyFile = ::fopen(CAMERA_KEY_CONFIG_PATH, "rb");
    }
    if (mNumberOfCamera == 0) {
      char numberOfCamera[2];
      bool retNumOfCamera = readCommonKey(kNUMBER_OF_CAMERA, numberOfCamera);
      if (retNumOfCamera < 0) {
        return -1;
      }
      std::string numberOfCameraStr = std::string(numberOfCamera);
      mNumberOfCamera = std::stoi(numberOfCameraStr);
    }
    return mNumberOfCamera;
  }
 
  static int supportCameraMulplex() {
    char cameraMultiplexing[2];
    if (readCommonKey(kCAMERA_MULTIPLEXING, cameraMultiplexing)) {
      mCameraMultiplexing = atoi(cameraMultiplexing);
    }
    return mCameraMultiplexing;
  }
 
  inline int cameraFacing() {
    return mCameraFacing;
  }
 
  inline int getCameraOrientation() {
    return mOrientation;
  }
 
  inline int getSupportFrameRate() {
    return mSupportFrameRate;
  }
 
  inline const char* cameraDevice() {
    return mCameraDevice;
  }
 
  inline int getDeviceID() {
    return mDeviceID;
  }
 
  // support fast picture mode or not
  inline bool supportFastPictureMode() {
    return mFastPictureMode;
  }
 
  // exif
  static char * getExifMake() {
    if (mhKeyFile == NULL) {
      mhKeyFile = ::fopen(CAMERA_KEY_CONFIG_PATH, "rb");
    }
    readCommonKey(kCAMERA_EXIF_MAKE,  mCameraMake);
    return mCameraMake;
  }
 
  static char * getExifModel() {
    if (mhKeyFile == NULL) {
      mhKeyFile = ::fopen(CAMERA_KEY_CONFIG_PATH, "rb");
    }
    readCommonKey(kCAMERA_EXIF_MODEL, mCameraModel);
    return mCameraModel;
  }
 
  float getHorizonalViewAngle() {
    return mHorizonalViewAngle;
  }
 
  float getVerticalViewAngle() {
    return mVerticalViewAngle;
  }
 
  bool supportPreviewSize();
  char* supportPreviewSizeValue();
  char* defaultPreviewSizeValue();
 
  bool supportPictureSize();
  char* supportPictureSizeValue();
  char* defaultPictureSizeValue();
 
  bool supportInterpolationSize();
  char* supportInterpolationSizeValue();
  char* defaultInterpolationSizeValue();
 
  bool supportFlashMode();
  char* supportFlashModeValue();
  char* defaultFlashModeValue();
 
  bool supportColorEffect();
  char* supportColorEffectValue();
  char* defaultColorEffectValue();
 
  bool supportFrameRate();
  char* supportFrameRateValue();
  char* defaultFrameRateValue();
 
  bool supportFocusMode();
  char* supportFocusModeValue();
  char* defaultFocusModeValue();
 
  bool supportSceneMode();
  char* supportSceneModeValue();
  char* defaultSceneModeValue();
 
  bool supportWhiteBalance();
  char* supportWhiteBalanceValue();
  char* defaultWhiteBalanceValue();
 
  // exposure compensation
  bool supportExposureCompensation() {
    return usedKey(mUsedExposureCompensation);
  }
 
  inline char* minExposureCompensationValue() {
    return mMinExposureCompensation;
  }
 
  inline char* maxExposureCompensationValue() {
    return mMaxExposureCompensation;
  }
 
  inline char* stepExposureCompensationValue() {
    return mStepExposureCompensation;
  }
 
  char* defaultExposureCompensationValue() {
    return mDefaultExposureCompensation;
  }
 
  // zoom
  bool supportZoom() {
    return usedKey(mUsedZoom);
  }
 
  inline char* zoomSupportedValue() {
    return mZoomSupported;
  }
 
  inline char * smoothZoomSupportedValue() {
    return mSmoothZoomSupported;
  }
 
  inline char * zoomRatiosValue() {
    return mZoomRatios;
  }
 
  inline char * maxZoomValue() {
    return mMaxZoom;
  }
 
  inline char * defaultZoomValue() {
    return mDefaultZoom;
  }
 
  static FILE * mhKeyFile;
  static int mNumberOfCamera;
  static char mCameraMake[64];
  static char mCameraModel[64];
  static int mCameraMultiplexing;
  static bool readCommonKey(const char *key, char* value, int cameraId = -1);
 
 private:
  bool readKey(const char *key, char *value);
  bool usedKey(char *value);
 
  static void getValue(char *line, char *value);
 
  bool mConstructOk;
 
  int mCurCameraId;
  int mCameraFacing;
  int mOrientation;
  int mSupportFrameRate;
  char mCameraDevice[64];
  int mDeviceID;
  bool mFastPictureMode;
 
  MEMBER_DEF(PreviewSize)
  MEMBER_DEF(PictureSize)
  MEMBER_DEF(InterpolationSize)
  MEMBER_DEF(FlashMode)
  MEMBER_DEF(ColorEffect)
  MEMBER_DEF(FrameRate)
  MEMBER_DEF(FocusMode)
  MEMBER_DEF(SceneMode)
  MEMBER_DEF(WhiteBalance)
 
  char mUsedExposureCompensation[2];
  char mMinExposureCompensation[4];
  char mMaxExposureCompensation[4];
  char mStepExposureCompensation[4];
  char mDefaultExposureCompensation[4];
 
  char mUsedZoom[2];
  char mZoomSupported[8];
  char mSmoothZoomSupported[8];
  char mZoomRatios[KEY_LENGTH];
  char mMaxZoom[4];
  char mDefaultZoom[4];
  float mHorizonalViewAngle;
  float mVerticalViewAngle;
};
 
#endif  // __CAMERA_CONFIG_H_