std::vector<camera_pixel_format_e> _validCapturePixelFormat;
std::vector<cv::Size> _validPreviewResolution;
std::vector<cv::Size> _validCaptureResolution;
+ std::vector<camera_attr_fps_e> _validFps;
std::unordered_set<unsigned int> _camera_ids;
camera_device_e _active_camera_id {};
static bool _registered;
{ CAMERA_PIXEL_FORMAT_H264, "H264" }, { CAMERA_PIXEL_FORMAT_INVZ, "INVZ" }
};
+ std::map<unsigned int, camera_attr_fps_e> _fpsTypeTable = {
+ { 7, CAMERA_ATTR_FPS_7 }, { 8, CAMERA_ATTR_FPS_8 }, { 15, CAMERA_ATTR_FPS_15 }, { 20, CAMERA_ATTR_FPS_20 },
+ { 24, CAMERA_ATTR_FPS_24 }, { 25, CAMERA_ATTR_FPS_25 }, { 30, CAMERA_ATTR_FPS_30 }, { 60, CAMERA_ATTR_FPS_60 },
+ { 90, CAMERA_ATTR_FPS_90 }, { 120, CAMERA_ATTR_FPS_120 }
+ };
+
void updateAvailableCameraDevices();
void setActiveCameraDevice(unsigned int id);
void threadLoop();
static bool previewResolutionCb(int width, int height, void *user_data);
static bool captureResolutionCb(int width, int height, void *user_data);
static void captureCompletedCb(void *user_data);
+ static bool previewFpsCb(camera_attr_fps_e fps, void *user_data);
static bool compareSizesDescending(const cv::Size &a, const cv::Size &b);
public:
return true;
}
+bool CameraApiBackend::previewFpsCb(camera_attr_fps_e fps, void *user_data)
+{
+ auto context = static_cast<CameraApiBackend *>(user_data);
+
+ SINGLEO_LOGD("supported fps: %d", fps);
+
+ context->_validFps.push_back(fps);
+
+ return true;
+}
+
void CameraApiBackend::configure(const CameraConfig &config)
{
setActiveCameraDevice(config.device_id);
SINGLEO_LOGE("CameraApiBackend: camera_set_capture_format failed. ret: %d", ret);
throw InvalidOperation("CameraApiBackend: camera_set_capture_format failed.");
}
+
+ ret = camera_attr_foreach_supported_fps(_camera, previewFpsCb, this);
+ if (ret != CAMERA_ERROR_NONE) {
+ SINGLEO_LOGE("CameraApiBackend: camera_attr_foreach_supported_fps failed. ret: %d", ret);
+ throw InvalidOperation("CameraApiBackend: camera_attr_foreach_supported_fps failed.");
+ }
+
+ camera_attr_fps_e givenFps = CAMERA_ATTR_FPS_AUTO;
+
+ try {
+ givenFps = _fpsTypeTable.at(config.fps);
+ } catch (const std::out_of_range &e) {
+ SINGLEO_LOGE("CameraApiBackend: a given fps(%d) is out_of_range.", config.fps);
+ throw InvalidOperation("CameraApiBackend: a given fps is out_of_range.");
+ }
+
+ auto fps_it = find(_validFps.begin(), _validFps.end(), givenFps);
+ if (fps_it == _validFps.end()) {
+ SINGLEO_LOGE("CameraApiBackend: fps(%d) is not supported.", config.fps);
+ throw InvalidOperation("CameraApiBackend: fps is not supported.");
+ }
+
+ ret = camera_attr_set_preview_fps(_camera, givenFps);
+ if (ret != CAMERA_ERROR_NONE) {
+ SINGLEO_LOGE("CameraApiBackend: camera_attr_set_preview_fps failed. ret: %d", ret);
+ throw InvalidOperation("CameraApiBackend: camera_attr_set_preview_fps failed.");
+ }
+
+ camera_attr_fps_e previewFps;
+
+ ret = camera_attr_get_preview_fps(_camera, &previewFps);
+ if (ret != CAMERA_ERROR_NONE) {
+ SINGLEO_LOGE("CameraApiBackend: camera_attr_get_preview_fps failed. ret: %d", ret);
+ throw InvalidOperation("CameraApiBackend: camera_attr_get_preview_fps failed.");
+ }
+
+ SINGLEO_LOGD("CameraApiBackend: previewFps: %d", previewFps);
}
void CameraApiBackend::captureCb(camera_image_data_s *image, camera_image_data_s *postview,