Chromium Code Reviews| Index: media/capture/video/linux/camera_characteristics.h |
| diff --git a/media/capture/video/linux/camera_characteristics.h b/media/capture/video/linux/camera_characteristics.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3bf330506ea9c807f4b3c9f8a4f04de0f6ffbdf6 |
| --- /dev/null |
| +++ b/media/capture/video/linux/camera_characteristics.h |
| @@ -0,0 +1,89 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef MEDIA_CAPTURE_VIDEO_LINUX_CAMERA_CHARACTERISTICS_H_ |
| +#define MEDIA_CAPTURE_VIDEO_LINUX_CAMERA_CHARACTERISTICS_H_ |
| + |
| +#include <stddef.h> |
| + |
| +#include <string> |
| +#include <unordered_map> |
| + |
| +#include <base/strings/string_piece.h> |
| + |
| +namespace media { |
| + |
| +// DeviceInfo can be found in /etc/camera/camera_characteristics.conf on device. |
| +struct CameraDeviceInfo { |
|
mcasas
2016/11/29 19:12:56
Make this struct public inside CameraCharacteristi
shenghao
2016/12/01 07:34:21
Done.
|
| + enum class LensFacing { kFront = 0, kBack = 1 }; |
|
mcasas
2016/11/29 19:12:56
Enum members should be uppercase see, e.g. [1]
and
kcwu
2016/11/30 03:04:53
FYI, chromium's style guide explicitly override th
shenghao
2016/12/01 07:34:21
Done.
|
| + static const LensFacing kLensFacingDefault = LensFacing::kFront; |
| + // USB vender id and product id in "pid:vid" format. |
| + std::string vid_pid; |
|
mcasas
2016/11/29 19:12:56
This member is unused.
shenghao
2016/12/01 07:34:21
Done.
|
| + // Direction the camera faces relative to device screen. |
| + LensFacing lens_facing; |
|
mcasas
2016/11/29 19:12:56
This member is unused.
shenghao
2016/12/01 07:34:21
Done.
|
| +}; |
| + |
| +// CameraCharacteristics reads the file /etc/camera/camera_characteristics.conf |
|
mcasas
2016/11/29 19:12:56
I wonder if this file format is public or is speci
shenghao
2016/12/01 07:34:21
Done.
|
| +// and populates |camera_id_to_facing_|, |usb_id_to_camera_id_| and |
| +// |model_id_to_camera_id_|. |
| +// |
| +// Each line in the config file can be: |
| +// 1. Empty line |
| +// 2. Line starts with '#': comments |
| +// 3. Line follows the format: |
| +// camera[camera_id].[root_level_attribute]=[value] OR |
| +// camera[camera_id].module[module_id].[module_level_attribute]=[value] |
| +// |
| +// There are several assumptions of the config file: |
| +// 1. One camera ID has exactly one lens_facing attribute, at root level. |
| +// 2. usb_path is specified at module level. usb_path may not present at all, |
| +// but if it presents, the same usb_path does not appear accross different |
| +// camera IDs. |
| +// 3. usb_vid_pid is specified at module level. If usb_path does not present, |
| +// each module needs to have one unique usb_vid_pid. |
| +// |
| +// Example of the config file: |
| +// camera0.lens_facing=0 |
| +// camera0.sensor_orientation=0 |
| +// camera0.module0.usb_vid_pid=0123:4567 |
| +// camera0.module0.horizontal_view_angle=68.4 |
| +// camera0.module0.lens_info_available_focal_lengths=1.64 |
| +// camera0.module0.lens_info_minimum_focus_distance=0.22 |
| +// camera0.module0.lens_info_optimal_focus_distance=0.5 |
| +// camera0.module0.vertical_view_angle=41.6 |
| +// camera0.module1.usb_vid_pid=89ab:cdef |
| +// camera0.module1.lens_info_available_focal_lengths=1.69,2 |
| +// camera1.lens_facing=1 |
| +// camera1.sensor_orientation=180 |
| +class CameraCharacteristics { |
|
mcasas
2016/11/29 19:12:56
This class is now only used for parsing a file to
shenghao
2016/12/01 07:34:21
Done.
|
| + public: |
| + CameraCharacteristics(); |
| + ~CameraCharacteristics(); |
| + |
| + // Get camera facing by specifying USB vid and pid and device path. |model_id| |
| + // should be formatted as "vid:pid". |device_id| is something like |
| + // "/dev/video2". It first tries to match usb path, obtained from |device_id|. |
| + // If fails, |model_id| is then used. |
| + // Returns CameraDeviceInfo::LensFacing::kFacingFront or |
| + // CameraDeviceInfo::LensFacing::kFacingBack. |
| + // Default is CameraDeviceInfo::LensFacing::kFacingFront. |
| + CameraDeviceInfo::LensFacing GetCameraFacing( |
| + const std::string& device_id, |
| + const std::string& model_id) const; |
| + |
| + private: |
| + std::string GetUsbId(const std::string& device_id) const; |
| + bool GetCameraId(const base::StringPiece& sub_key, int* camera_id); |
| + // Read file content and populate |camera_id_to_facing_|, |
| + // |usb_id_to_camera_id_| and |model_id_to_camera_id_|. |
| + void InitializeDeviceInfo(); |
| + |
| + std::unordered_map<int, CameraDeviceInfo::LensFacing> camera_id_to_facing_; |
| + std::unordered_map<std::string, int> usb_id_to_camera_id_; |
| + std::unordered_map<std::string, int> model_id_to_camera_id_; |
| +}; |
| + |
| +} // namespace arc |
| + |
| +#endif // MEDIA_CAPTURE_VIDEO_LINUX_CAMERA_CHARACTERISTICS_H_ |