Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MEDIA_CAPTURE_VIDEO_LINUX_CAMERA_CHARACTERISTICS_H_ | |
| 6 #define MEDIA_CAPTURE_VIDEO_LINUX_CAMERA_CHARACTERISTICS_H_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 | |
| 10 #include <map> | |
| 11 #include <string> | |
| 12 #include <unordered_map> | |
| 13 #include <vector> | |
| 14 | |
| 15 #include <base/strings/string_piece.h> | |
| 16 | |
| 17 namespace media { | |
| 18 | |
| 19 // DeviceInfo can be found in /etc/camera/camera_characteristics.conf on device. | |
| 20 struct CameraDeviceInfo { | |
| 21 static const int LENS_FACING_FRONT = 0; | |
| 22 static const int LENS_FACING_BACK = 1; | |
| 23 // USB vender id and product id in "pid:vid" format. | |
| 24 std::string vid_pid; | |
| 25 // Direction the camera faces relative to device screen. | |
| 26 uint32_t lens_facing; | |
| 27 }; | |
| 28 | |
| 29 typedef std::vector<CameraDeviceInfo> CameraDeviceInfos; | |
| 30 | |
| 31 // CameraCharacteristics reads the file /etc/camera/camera_characteristics.conf | |
| 32 // and populates |camera_id_to_facing_|, |usb_id_to_camera_id_| and | |
| 33 // |model_id_to_camera_id_|. | |
| 34 // | |
| 35 // Each line in the config file can be: | |
| 36 // 1. Empty line | |
| 37 // 2. Line starts with '#': comments | |
| 38 // 3. Line follows the format: | |
| 39 // camera[camera_id].[root_level_attribute]=[value] OR | |
| 40 // camera[camera_id].module[module_id].[module_level_attribute]=[value] | |
| 41 // | |
| 42 // There are several assumptions of the config file: | |
| 43 // 1. One camera ID has exactly one lens_facing attribute, at root level. | |
| 44 // 2. usb_path is specified at module level. usb_path may not present at all, | |
| 45 // but if it presents, the same usb_path does not appear accross different | |
| 46 // camera IDs. | |
| 47 // 3. usb_vid_pid is specified at module level. If usb_path does not present, | |
| 48 // each module needs to have one unique usb_vid_pid. | |
| 49 // | |
| 50 // Example of the config file: | |
| 51 // camera0.lens_facing=0 | |
| 52 // camera0.sensor_orientation=0 | |
| 53 // camera0.module0.usb_vid_pid=0123:4567 | |
| 54 // camera0.module0.horizontal_view_angle=68.4 | |
| 55 // camera0.module0.lens_info_available_focal_lengths=1.64 | |
| 56 // camera0.module0.lens_info_minimum_focus_distance=0.22 | |
| 57 // camera0.module0.lens_info_optimal_focus_distance=0.5 | |
| 58 // camera0.module0.vertical_view_angle=41.6 | |
| 59 // camera0.module1.usb_vid_pid=89ab:cdef | |
| 60 // camera0.module1.lens_info_available_focal_lengths=1.69,2 | |
| 61 // camera1.lens_facing=1 | |
| 62 // camera1.sensor_orientation=180 | |
| 63 class CameraCharacteristics { | |
| 64 public: | |
| 65 CameraCharacteristics(); | |
| 66 ~CameraCharacteristics(); | |
| 67 | |
| 68 // Get camera facing by specifying USB vid and pid and device path. |model_id| | |
| 69 // should be formatted as "vid:pid". |device_id| is something like | |
| 70 // "/dev/video2". It first tries to match usb path, obtained from |device_id|. | |
| 71 // If fails, |model_id| is then used. | |
| 72 // Returns CameraDeviceInfo::LENS_FACING_FRONT or | |
| 73 // CameraDeviceInfo::LENS_FACING_BACK. | |
| 74 // Default is CameraDeviceInfo::LENS_FACING_FRONT. | |
| 75 int GetCameraFacing(const std::string& model_id, | |
|
kcwu
2016/11/24 10:16:08
If device_id is matched first, please put it as th
shenghao
2016/11/24 14:13:25
Done.
| |
| 76 const std::string& device_id); | |
| 77 | |
| 78 private: | |
| 79 std::string content_; | |
| 80 std::unordered_map<int, int> camera_id_to_facing_; | |
| 81 std::map<base::StringPiece, int> usb_id_to_camera_id_; | |
|
kcwu
2016/11/24 10:16:08
use std::string instead.
Then we don't need to kee
shenghao
2016/11/24 14:13:25
Done.
| |
| 82 std::unordered_map<std::string, int> model_id_to_camera_id_; | |
| 83 | |
| 84 std::string GetUsbId(const std::string& device_id); | |
|
kcwu
2016/11/24 10:16:08
Methods should put before member variables.
shenghao
2016/11/24 14:13:25
Done.
| |
| 85 bool GetCameraId(const base::StringPiece& sub_key, int* camera_id); | |
| 86 | |
| 87 // Read file content and populate |camera_id_to_facing_|, | |
| 88 // |usb_id_to_camera_id_| and |model_id_to_camera_id_|. | |
| 89 void InitializeDeviceInfo(); | |
| 90 }; | |
| 91 | |
| 92 } // namespace arc | |
| 93 | |
| 94 #endif // MEDIA_CAPTURE_VIDEO_LINUX_CAMERA_CHARACTERISTICS_H_ | |
| OLD | NEW |