1 /* 2 * Copyright 2016 The Chromium OS Authors. All rights reserved. 3 * Use of this source code is governed by a BSD-style license that can be 4 * found in the LICENSE file. 5 */ 6 7 #ifndef CAMERA_CHARACTERISTICS_H_ 8 #define CAMERA_CHARACTERISTICS_H_ 9 10 #include <map> 11 #include <string> 12 #include <utility> 13 14 #include <base/files/file.h> 15 #include <base/macros.h> 16 17 #include "common_types.h" 18 19 // /etc/camera/camera_characteristics.conf contains camera information which 20 // driver cannot provide. 21 static const base::FilePath kCameraCharacteristicsConfigFile( 22 "/etc/camera/camera_characteristics.conf"); 23 24 // CameraCharacteristics reads the file /etc/camera/camera_characteristics.conf. 25 // There are several assumptions of the config file: 26 // 1. camera/module id should be in ascending order (i.e., 0, 1, 2, ...). 27 // 2. All configs of a camera/module should be put together. 28 // 3. Module specific characteristics should come after camera specific ones. 29 // 4. All usb_vid_pid shuold be distinct. 30 // 31 // Example of the config file: 32 // camera0.lens_facing=0 33 // camera0.sensor_orientation=0 34 // camera0.module0.usb_vid_pid=0123:4567 35 // camera0.module0.horizontal_view_angle=68.4 36 // camera0.module0.lens_info_available_focal_lengths=1.64 37 // camera0.module0.lens_info_minimum_focus_distance=0.22 38 // camera0.module0.lens_info_optimal_focus_distance=0.5 39 // camera0.module0.vertical_view_angle=41.6 40 // camera0.module1.usb_vid_pid=89ab:cdef 41 // camera0.module1.lens_info_available_focal_lengths=1.69,2 42 // camera1.lens_facing=1 43 // camera1.sensor_orientation=180 44 // ... 45 class CameraCharacteristics { 46 public: 47 static bool ConfigFileExists(); 48 49 // Initialize camera characteristics from |kCameraCharacteristicsConfigFile|. 50 // If the file does not exist, |camera_module_infos_| would be empty. 51 CameraCharacteristics(); 52 53 // Initialize camera characteristics from |config_file|. 54 explicit CameraCharacteristics(const base::FilePath& config_file); 55 56 // Get the device information by vid and pid. Returns |nullptr| if not found. 57 const DeviceInfo* Find(const std::string& vid, const std::string& pid) const; 58 59 private: 60 void InitFrom(const base::FilePath& config_file); 61 62 // The key is a pair of usb (vid, pid). 63 std::map<std::pair<std::string, std::string>, DeviceInfo> 64 camera_module_infos_; 65 66 DISALLOW_COPY_AND_ASSIGN(CameraCharacteristics); 67 }; 68 69 #endif // CAMERA_CHARACTERISTICS_H_ 70