Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(675)

Side by Side Diff: media/capture/video/linux/camera_characteristics.h

Issue 2508803002: Rotate frames correctly for back camera (Closed)
Patch Set: Move parsing back to constructor Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 <string>
11 #include <unordered_map>
12 #include <vector>
kcwu 2016/11/28 10:11:37 unused
shenghao 2016/11/29 10:22:26 Done.
13
14 #include <base/strings/string_piece.h>
15
16 namespace media {
17
18 // DeviceInfo can be found in /etc/camera/camera_characteristics.conf on device.
19 struct CameraDeviceInfo {
20 enum LensFacing { kFacingFront = 0, kFacingBack = 1 };
kcwu 2016/11/28 10:11:37 enum class LensFacing. Then we can skip redundant
kcwu 2016/11/28 10:11:37 Please consider const LensFacing kDefaultLensFacin
shenghao 2016/11/29 10:22:27 Done.
21 // USB vender id and product id in "pid:vid" format.
22 std::string vid_pid;
23 // Direction the camera faces relative to device screen.
24 LensFacing lens_facing;
25 };
26
27 typedef std::vector<CameraDeviceInfo> CameraDeviceInfos;
kcwu 2016/11/28 10:11:37 unused?
shenghao 2016/11/29 10:22:26 Done.
28
29 // CameraCharacteristics reads the file /etc/camera/camera_characteristics.conf
30 // and populates |camera_id_to_facing_|, |usb_id_to_camera_id_| and
31 // |model_id_to_camera_id_|.
32 //
33 // Each line in the config file can be:
34 // 1. Empty line
35 // 2. Line starts with '#': comments
36 // 3. Line follows the format:
37 // camera[camera_id].[root_level_attribute]=[value] OR
38 // camera[camera_id].module[module_id].[module_level_attribute]=[value]
39 //
40 // There are several assumptions of the config file:
41 // 1. One camera ID has exactly one lens_facing attribute, at root level.
42 // 2. usb_path is specified at module level. usb_path may not present at all,
43 // but if it presents, the same usb_path does not appear accross different
44 // camera IDs.
45 // 3. usb_vid_pid is specified at module level. If usb_path does not present,
46 // each module needs to have one unique usb_vid_pid.
47 //
48 // Example of the config file:
49 // camera0.lens_facing=0
50 // camera0.sensor_orientation=0
51 // camera0.module0.usb_vid_pid=0123:4567
52 // camera0.module0.horizontal_view_angle=68.4
53 // camera0.module0.lens_info_available_focal_lengths=1.64
54 // camera0.module0.lens_info_minimum_focus_distance=0.22
55 // camera0.module0.lens_info_optimal_focus_distance=0.5
56 // camera0.module0.vertical_view_angle=41.6
57 // camera0.module1.usb_vid_pid=89ab:cdef
58 // camera0.module1.lens_info_available_focal_lengths=1.69,2
59 // camera1.lens_facing=1
60 // camera1.sensor_orientation=180
61 class CameraCharacteristics {
62 public:
63 CameraCharacteristics();
64 ~CameraCharacteristics();
65
66 // Get camera facing by specifying USB vid and pid and device path. |model_id|
67 // should be formatted as "vid:pid". |device_id| is something like
68 // "/dev/video2". It first tries to match usb path, obtained from |device_id|.
69 // If fails, |model_id| is then used.
70 // Returns CameraDeviceInfo::LensFacing::kFacingFront or
71 // CameraDeviceInfo::LensFacing::kFacingBack.
72 // Default is CameraDeviceInfo::LensFacing::kFacingFront.
73 CameraDeviceInfo::LensFacing GetCameraFacing(
74 const std::string& device_id,
75 const std::string& model_id) const;
76
77 private:
78 std::string GetUsbId(const std::string& device_id) const;
79 bool GetCameraId(const base::StringPiece& sub_key, int* camera_id);
80 // Read file content and populate |camera_id_to_facing_|,
81 // |usb_id_to_camera_id_| and |model_id_to_camera_id_|.
82 void InitializeDeviceInfo();
83
84 std::unordered_map<int, CameraDeviceInfo::LensFacing> camera_id_to_facing_;
85 std::unordered_map<std::string, int> usb_id_to_camera_id_;
86 std::unordered_map<std::string, int> model_id_to_camera_id_;
87 };
88
89 } // namespace arc
90
91 #endif // MEDIA_CAPTURE_VIDEO_LINUX_CAMERA_CHARACTERISTICS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698