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

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

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

Powered by Google App Engine
This is Rietveld 408576698