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

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

Issue 2508803002: Rotate frames correctly for back camera (Closed)
Patch Set: Add comment 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 #include "camera_characteristics.h"
6
7 #include <base/files/file_util.h>
8 #include <base/logging.h>
9 #include <base/strings/string_piece.h>
10 #include <base/strings/string_split.h>
11
12 namespace media {
13
14 // /etc/camera/camera_characteristics.conf contains camera information which
15 // driver cannot provide.
16 static const char kCameraCharacteristicsConfigFile[] =
17 "/etc/camera/camera_characteristics.conf";
18 static const char kLensFacing[] = "lens_facing";
19 static const char kUsbVidPid[] = "usb_vid_pid";
20
21 static const struct DeviceInfo kDefaultCharacteristics = {
wuchengli 2016/11/22 03:47:06 not used?
shenghao 2016/11/24 07:13:03 Done.
22 "", // vid_pid
23 0, // lens_facing
24 };
25
26 CameraCharacteristics::CameraCharacteristics() {}
27
28 CameraCharacteristics::~CameraCharacteristics() {}
29
30 int CameraCharacteristics::GetCameraFacing(const std::string& model_id) {
31 std::unordered_map<std::string, DeviceInfo> model_id_to_info =
32 GetDeviceInfoFromFile();
33 auto iter = model_id_to_info.find(model_id);
34 if (iter != model_id_to_info.end()) {
35 return iter->second.lens_facing;
36 }
37 return DeviceInfo::LENS_FACING_FRONT;
38 }
39
40 std::unordered_map<std::string, DeviceInfo>
41 CameraCharacteristics::GetDeviceInfoFromFile() {
42 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.
43 std::string content;
44 if (!base::ReadFileToString(path, &content)) {
45 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.
46 }
47 std::vector<base::StringPiece> lines = base::SplitStringPiece(
48 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.
49 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
50 base::SplitResult::SPLIT_WANT_NONEMPTY);
51
52 int current_lens_facing = DeviceInfo::LENS_FACING_FRONT;
53 std::unordered_map<std::string, DeviceInfo> device_info;
54 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.
55 if (line.starts_with(base::StringPiece("#"))) {
56 continue;
57 }
58 std::vector<base::StringPiece> key_value = base::SplitStringPiece(
59 line, base::StringPiece("="), base::WhitespaceHandling::TRIM_WHITESPACE,
60 base::SplitResult::SPLIT_WANT_ALL);
61 if (key_value.size() != 2) {
62 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.
63 continue;
64 }
65 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.
66 base::StringPiece value = key_value[1];
67 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
68 key, base::StringPiece("."), base::WhitespaceHandling::TRIM_WHITESPACE,
69 base::SplitResult::SPLIT_WANT_ALL);
70 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
71 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.
72 continue;
73 }
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.
74 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.
75 std::string vid_pid = value.as_string();
76 DeviceInfo info;
77 info.vid_pid = vid_pid;
78 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.
79 device_info[vid_pid] = info;
80 }
81 }
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.
82
83 return device_info;
84 }
85
86 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698