OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "camera_facing_chromeos.h" | 5 #include "camera_facing_chromeos.h" |
6 | 6 |
7 #include <base/files/file_util.h> | 7 #include <base/files/file_util.h> |
8 #include <base/logging.h> | 8 #include <base/logging.h> |
9 #include <base/strings/stringprintf.h> | 9 #include <base/strings/stringprintf.h> |
10 #include <base/strings/string_number_conversions.h> | 10 #include <base/strings/string_number_conversions.h> |
11 #include <base/strings/string_piece.h> | 11 #include <base/strings/string_piece.h> |
12 #include <base/strings/string_split.h> | 12 #include <base/strings/string_split.h> |
13 #include <base/strings/string_util.h> | 13 #include <base/strings/string_util.h> |
14 | 14 |
15 namespace media { | 15 namespace media { |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
| 19 // The value for each field in the enum matches the value in |
| 20 // /etc/camera/camera_characteristics.conf. |
| 21 enum LensFacing { FRONT = 0, BACK = 1 }; |
| 22 |
19 bool GetCameraId(const base::StringPiece& sub_key, int* camera_id) { | 23 bool GetCameraId(const base::StringPiece& sub_key, int* camera_id) { |
20 const base::StringPiece camera_id_prefix = "camera"; | 24 const base::StringPiece camera_id_prefix = "camera"; |
21 if (!sub_key.starts_with(camera_id_prefix)) | 25 if (!sub_key.starts_with(camera_id_prefix)) |
22 return false; | 26 return false; |
23 return base::StringToInt(sub_key.substr(camera_id_prefix.size()), camera_id); | 27 return base::StringToInt(sub_key.substr(camera_id_prefix.size()), camera_id); |
24 } | 28 } |
25 } | 29 } |
26 | 30 |
27 // /etc/camera/camera_characteristics.conf contains camera information which | 31 // /etc/camera/camera_characteristics.conf contains camera information which |
28 // driver cannot provide. | 32 // driver cannot provide. |
29 static const char kCameraCharacteristicsConfigFile[] = | 33 static const char kCameraCharacteristicsConfigFile[] = |
30 "/etc/camera/camera_characteristics.conf"; | 34 "/etc/camera/camera_characteristics.conf"; |
31 static const char kLensFacing[] = "lens_facing"; | 35 static const char kLensFacing[] = "lens_facing"; |
32 static const char kUsbVidPid[] = "usb_vid_pid"; | 36 static const char kUsbVidPid[] = "usb_vid_pid"; |
33 static const char kUsbPath[] = "usb_path"; | 37 static const char kUsbPath[] = "usb_path"; |
34 | 38 |
35 CameraFacingChromeOS::CameraFacingChromeOS() { | 39 CameraFacingChromeOS::CameraFacingChromeOS() { |
36 InitializeDeviceInfo(std::string(kCameraCharacteristicsConfigFile)); | 40 InitializeDeviceInfo(std::string(kCameraCharacteristicsConfigFile)); |
37 } | 41 } |
38 | 42 |
39 CameraFacingChromeOS::CameraFacingChromeOS( | 43 CameraFacingChromeOS::CameraFacingChromeOS( |
40 const std::string& config_file_path) { | 44 const std::string& config_file_path) { |
41 InitializeDeviceInfo(config_file_path); | 45 InitializeDeviceInfo(config_file_path); |
42 } | 46 } |
43 | 47 |
44 CameraFacingChromeOS::~CameraFacingChromeOS() {} | 48 CameraFacingChromeOS::~CameraFacingChromeOS() {} |
45 | 49 |
46 CameraFacingChromeOS::LensFacing CameraFacingChromeOS::GetCameraFacing( | 50 VideoFacingMode CameraFacingChromeOS::GetCameraFacing( |
47 const std::string& device_id, | 51 const std::string& device_id, |
48 const std::string& model_id) const { | 52 const std::string& model_id) const { |
49 std::string usb_id = GetUsbId(device_id); | 53 std::string usb_id = GetUsbId(device_id); |
50 const auto& usb_id_to_camera_id_const = usb_id_to_camera_id_; | 54 const auto& usb_id_to_camera_id_const = usb_id_to_camera_id_; |
51 const auto& model_id_to_camera_id_const = model_id_to_camera_id_; | 55 const auto& model_id_to_camera_id_const = model_id_to_camera_id_; |
52 const auto& camera_id_to_facing_const = camera_id_to_facing_; | 56 const auto& camera_id_to_facing_const = camera_id_to_facing_; |
53 auto usb_id_iter = usb_id_to_camera_id_const.find(usb_id); | 57 auto usb_id_iter = usb_id_to_camera_id_const.find(usb_id); |
54 int camera_id; | 58 int camera_id; |
55 if (usb_id_iter == usb_id_to_camera_id_const.end()) { | 59 if (usb_id_iter == usb_id_to_camera_id_const.end()) { |
56 // Can't find Usb ID. Fall back to use model_id. | 60 // Can't find Usb ID. Fall back to use model_id. |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 } | 153 } |
150 | 154 |
151 if (sub_keys.size() == 2 && sub_keys[1] == kLensFacing) { | 155 if (sub_keys.size() == 2 && sub_keys[1] == kLensFacing) { |
152 int lens_facing = -1; | 156 int lens_facing = -1; |
153 if (!base::StringToInt(value, &lens_facing)) { | 157 if (!base::StringToInt(value, &lens_facing)) { |
154 DLOG(ERROR) << "Invalid value for lens_facing: " << value; | 158 DLOG(ERROR) << "Invalid value for lens_facing: " << value; |
155 continue; | 159 continue; |
156 } | 160 } |
157 switch (lens_facing) { | 161 switch (lens_facing) { |
158 case LensFacing::FRONT: | 162 case LensFacing::FRONT: |
159 camera_id_to_facing_[camera_id] = LensFacing::FRONT; | 163 camera_id_to_facing_[camera_id] = |
| 164 VideoFacingMode::MEDIA_VIDEO_FACING_USER; |
160 break; | 165 break; |
161 case LensFacing::BACK: | 166 case LensFacing::BACK: |
162 camera_id_to_facing_[camera_id] = LensFacing::BACK; | 167 camera_id_to_facing_[camera_id] = |
| 168 VideoFacingMode::MEDIA_VIDEO_FACING_ENVIRONMENT; |
163 break; | 169 break; |
164 default: | 170 default: |
165 DLOG(ERROR) << "Invalid value for lens_facing: " << lens_facing; | 171 DLOG(ERROR) << "Invalid value for lens_facing: " << lens_facing; |
166 continue; | 172 continue; |
167 } | 173 } |
168 } else if (sub_keys.size() == 3 && sub_keys[2] == kUsbVidPid) { | 174 } else if (sub_keys.size() == 3 && sub_keys[2] == kUsbVidPid) { |
169 if (value.empty()) { | 175 if (value.empty()) { |
170 DLOG(ERROR) << "model_id is empty"; | 176 DLOG(ERROR) << "model_id is empty"; |
171 continue; | 177 continue; |
172 } | 178 } |
173 std::string model_id = value.as_string(); | 179 std::string model_id = value.as_string(); |
174 std::transform(model_id.begin(), model_id.end(), model_id.begin(), | 180 std::transform(model_id.begin(), model_id.end(), model_id.begin(), |
175 ::tolower); | 181 ::tolower); |
176 model_id_to_camera_id_[model_id] = camera_id; | 182 model_id_to_camera_id_[model_id] = camera_id; |
177 } else if (sub_keys.size() == 3 && sub_keys[2] == kUsbPath) { | 183 } else if (sub_keys.size() == 3 && sub_keys[2] == kUsbPath) { |
178 if (value.empty()) { | 184 if (value.empty()) { |
179 DLOG(ERROR) << "usb_path is empty"; | 185 DLOG(ERROR) << "usb_path is empty"; |
180 continue; | 186 continue; |
181 } | 187 } |
182 usb_id_to_camera_id_[value.as_string()] = camera_id; | 188 usb_id_to_camera_id_[value.as_string()] = camera_id; |
183 } | 189 } |
184 // Ignore unknown or unutilized attributes. | 190 // Ignore unknown or unutilized attributes. |
185 } | 191 } |
186 } | 192 } |
187 | 193 |
188 } // namespace media | 194 } // namespace media |
OLD | NEW |