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

Unified Diff: media/capture/video/linux/camera_characteristics.cc

Issue 2508803002: Rotate frames correctly for back camera (Closed)
Patch Set: Add comment Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: media/capture/video/linux/camera_characteristics.cc
diff --git a/media/capture/video/linux/camera_characteristics.cc b/media/capture/video/linux/camera_characteristics.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5994ead529ed780c4e26901872a318a10432b0f6
--- /dev/null
+++ b/media/capture/video/linux/camera_characteristics.cc
@@ -0,0 +1,86 @@
+// 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.
+
+#include "camera_characteristics.h"
+
+#include <base/files/file_util.h>
+#include <base/logging.h>
+#include <base/strings/string_piece.h>
+#include <base/strings/string_split.h>
+
+namespace media {
+
+// /etc/camera/camera_characteristics.conf contains camera information which
+// driver cannot provide.
+static const char kCameraCharacteristicsConfigFile[] =
+ "/etc/camera/camera_characteristics.conf";
+static const char kLensFacing[] = "lens_facing";
+static const char kUsbVidPid[] = "usb_vid_pid";
+
+static const struct DeviceInfo kDefaultCharacteristics = {
wuchengli 2016/11/22 03:47:06 not used?
shenghao 2016/11/24 07:13:03 Done.
+ "", // vid_pid
+ 0, // lens_facing
+};
+
+CameraCharacteristics::CameraCharacteristics() {}
+
+CameraCharacteristics::~CameraCharacteristics() {}
+
+int CameraCharacteristics::GetCameraFacing(const std::string& model_id) {
+ std::unordered_map<std::string, DeviceInfo> model_id_to_info =
+ GetDeviceInfoFromFile();
+ auto iter = model_id_to_info.find(model_id);
+ if (iter != model_id_to_info.end()) {
+ return iter->second.lens_facing;
+ }
+ return DeviceInfo::LENS_FACING_FRONT;
+}
+
+std::unordered_map<std::string, DeviceInfo>
+CameraCharacteristics::GetDeviceInfoFromFile() {
+ const base::FilePath path(kCameraCharacteristicsConfigFile);
wuchengli 2016/11/22 03:47:06 We should not read the file every time a camera is
shenghao 2016/11/24 07:13:04 Done.
+ std::string content;
+ if (!base::ReadFileToString(path, &content)) {
+ DLOG(ERROR) << "Config file bigger than buffer size.";
wuchengli 2016/11/22 07:59:33 If the file doesn't exist, ReadFileToString also r
shenghao 2016/11/24 07:13:03 Done.
+ }
+ std::vector<base::StringPiece> lines = base::SplitStringPiece(
+ base::StringPiece(content), base::StringPiece("\n"),
kcwu 2016/11/21 07:59:24 IIRC, StringPiece will do casting implicitly, so y
shenghao 2016/11/24 07:13:03 Done.
+ base::WhitespaceHandling::TRIM_WHITESPACE,
wuchengli 2016/11/22 07:59:34 Check if TRIM_WHITESPACE will remove "\r" if the c
shenghao 2016/11/24 07:13:03 Yes. https://cs.chromium.org/chromium/src/base/str
+ base::SplitResult::SPLIT_WANT_NONEMPTY);
+
+ int current_lens_facing = DeviceInfo::LENS_FACING_FRONT;
+ std::unordered_map<std::string, DeviceInfo> device_info;
+ for (base::StringPiece line : lines) {
wuchengli 2016/11/22 07:59:34 // Ignore the comment that starts with "#".
shenghao 2016/11/24 07:13:04 Done.
+ if (line.starts_with(base::StringPiece("#"))) {
+ continue;
+ }
+ std::vector<base::StringPiece> key_value = base::SplitStringPiece(
+ line, base::StringPiece("="), base::WhitespaceHandling::TRIM_WHITESPACE,
+ base::SplitResult::SPLIT_WANT_ALL);
+ if (key_value.size() != 2) {
+ DLOG(ERROR) << "Invalid line in config file: " << line;
wuchengli 2016/11/22 07:59:33 LOG(ERROR) because this is an actual error. We nee
shenghao 2016/11/24 07:13:03 Done.
+ continue;
+ }
+ base::StringPiece key = key_value[0];
kcwu 2016/11/21 07:59:24 const auto& key = key_value[0]; const auto& value
shenghao 2016/11/24 07:13:03 Done.
+ base::StringPiece value = key_value[1];
+ std::vector<base::StringPiece> sub_keys = base::SplitStringPiece(
kcwu 2016/11/21 07:59:24 the value of sub_keys[0] is ignored?
shenghao 2016/11/24 07:13:04 deleted
+ key, base::StringPiece("."), base::WhitespaceHandling::TRIM_WHITESPACE,
+ base::SplitResult::SPLIT_WANT_ALL);
+ if (sub_keys.size() >= 2 && sub_keys[1].compare(kLensFacing) == 0) {
kcwu 2016/11/21 07:59:24 1. why ">=" instead of "==" ? Do you intent to ign
+ current_lens_facing = strtol(value.data(), NULL, 10);
kcwu 2016/11/21 07:59:24 base::StringToUint or the like?
shenghao 2016/11/24 07:13:03 Done.
+ continue;
+ }
wuchengli 2016/11/22 07:59:33 else if (sub_keys.size() >= 3 && sub_keys[2].compa
shenghao 2016/11/24 07:13:03 Done.
+ if (sub_keys.size() >= 3 && sub_keys[2].compare(kUsbVidPid) == 0) {
kcwu 2016/11/21 07:59:24 ditto
shenghao 2016/11/24 07:13:03 Done.
+ std::string vid_pid = value.as_string();
+ DeviceInfo info;
+ info.vid_pid = vid_pid;
+ info.lens_facing = current_lens_facing;
kcwu 2016/11/21 07:59:24 You need to reset current_lens_facing when parsing
shenghao 2016/11/24 07:13:03 Done.
+ device_info[vid_pid] = info;
+ }
+ }
kcwu 2016/11/21 07:59:24 what about else? DLOG(ERROR) ?
wuchengli 2016/11/22 07:59:33 No need to log. We ignore keys like lens_info_avai
shenghao 2016/11/24 07:13:04 Acknowledged.
+
+ return device_info;
+}
+
+} // namespace media

Powered by Google App Engine
This is Rietveld 408576698