| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 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 "media/capture/video/video_capture_device.h" | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "base/i18n/timezone.h" | |
| 9 #include "base/macros.h" | |
| 10 #include "base/strings/string_util.h" | |
| 11 #include "build/build_config.h" | |
| 12 #include "media/base/media_switches.h" | |
| 13 | |
| 14 namespace media { | |
| 15 | |
| 16 // TODO(msu.koo): http://crbug.com/532272, remove checking the switch in favour | |
| 17 // of deferring GetModel() call to the actual VideoCaptureDevice object. | |
| 18 const std::string VideoCaptureDevice::Name::GetNameAndModel() const { | |
| 19 const std::string model_id = GetModel(); | |
| 20 if (model_id.empty()) | |
| 21 return device_name_; | |
| 22 const std::string suffix = " (" + model_id + ")"; | |
| 23 if (base::EndsWith(device_name_, suffix, base::CompareCase::SENSITIVE) || | |
| 24 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 25 switches::kUseFakeDeviceForMediaStream)) | |
| 26 // Ignore |model_id| if |kUseFakeDeviceForMediaStream| flag is present. | |
| 27 return device_name_; | |
| 28 return device_name_ + suffix; | |
| 29 } | |
| 30 | |
| 31 VideoCaptureDevice::Name::Name() { | |
| 32 } | |
| 33 | |
| 34 VideoCaptureDevice::Name::Name(const std::string& name, const std::string& id) | |
| 35 : device_name_(name), unique_id_(id) { | |
| 36 } | |
| 37 | |
| 38 #if defined(OS_LINUX) | |
| 39 VideoCaptureDevice::Name::Name(const std::string& name, | |
| 40 const std::string& id, | |
| 41 const CaptureApiType api_type) | |
| 42 : device_name_(name), unique_id_(id), capture_api_class_(api_type) { | |
| 43 } | |
| 44 #elif defined(OS_WIN) | |
| 45 VideoCaptureDevice::Name::Name(const std::string& name, | |
| 46 const std::string& id, | |
| 47 const CaptureApiType api_type) | |
| 48 : device_name_(name), | |
| 49 unique_id_(id), | |
| 50 capture_api_class_(api_type), | |
| 51 capabilities_id_(id) { | |
| 52 } | |
| 53 #elif defined(OS_MACOSX) | |
| 54 VideoCaptureDevice::Name::Name(const std::string& name, | |
| 55 const std::string& id, | |
| 56 const CaptureApiType api_type) | |
| 57 : device_name_(name), | |
| 58 unique_id_(id), | |
| 59 capture_api_class_(api_type), | |
| 60 transport_type_(OTHER_TRANSPORT) {} | |
| 61 | |
| 62 VideoCaptureDevice::Name::Name(const std::string& name, | |
| 63 const std::string& id, | |
| 64 const CaptureApiType api_type, | |
| 65 const TransportType transport_type) | |
| 66 : device_name_(name), | |
| 67 unique_id_(id), | |
| 68 capture_api_class_(api_type), | |
| 69 transport_type_(transport_type) {} | |
| 70 #elif defined(ANDROID) | |
| 71 VideoCaptureDevice::Name::Name(const std::string& name, | |
| 72 const std::string& id, | |
| 73 const CaptureApiType api_type) | |
| 74 : device_name_(name), unique_id_(id), capture_api_class_(api_type) { | |
| 75 } | |
| 76 #endif | |
| 77 | |
| 78 VideoCaptureDevice::Name::Name(const Name& other) = default; | |
| 79 | |
| 80 VideoCaptureDevice::Name::~Name() { | |
| 81 } | |
| 82 | |
| 83 #if defined(OS_LINUX) | |
| 84 const char* VideoCaptureDevice::Name::GetCaptureApiTypeString() const { | |
| 85 switch (capture_api_type()) { | |
| 86 case V4L2_SINGLE_PLANE: | |
| 87 return "V4L2 SPLANE"; | |
| 88 default: | |
| 89 NOTREACHED() << "Unknown Video Capture API type!"; | |
| 90 return "Unknown API"; | |
| 91 } | |
| 92 } | |
| 93 #elif defined(OS_WIN) | |
| 94 const char* VideoCaptureDevice::Name::GetCaptureApiTypeString() const { | |
| 95 switch (capture_api_type()) { | |
| 96 case MEDIA_FOUNDATION: | |
| 97 return "Media Foundation"; | |
| 98 case DIRECT_SHOW: | |
| 99 return "Direct Show"; | |
| 100 default: | |
| 101 NOTREACHED() << "Unknown Video Capture API type!"; | |
| 102 return "Unknown API"; | |
| 103 } | |
| 104 } | |
| 105 #elif defined(OS_MACOSX) | |
| 106 const char* VideoCaptureDevice::Name::GetCaptureApiTypeString() const { | |
| 107 switch (capture_api_type()) { | |
| 108 case AVFOUNDATION: | |
| 109 return "AV Foundation"; | |
| 110 case DECKLINK: | |
| 111 return "DeckLink"; | |
| 112 default: | |
| 113 NOTREACHED() << "Unknown Video Capture API type!"; | |
| 114 return "Unknown API"; | |
| 115 } | |
| 116 } | |
| 117 #elif defined(OS_ANDROID) | |
| 118 const char* VideoCaptureDevice::Name::GetCaptureApiTypeString() const { | |
| 119 switch (capture_api_type()) { | |
| 120 case API1: | |
| 121 return "Camera API1"; | |
| 122 case API2_LEGACY: | |
| 123 return "Camera API2 Legacy"; | |
| 124 case API2_FULL: | |
| 125 return "Camera API2 Full"; | |
| 126 case API2_LIMITED: | |
| 127 return "Camera API2 Limited"; | |
| 128 case TANGO: | |
| 129 return "Tango API"; | |
| 130 case API_TYPE_UNKNOWN: | |
| 131 default: | |
| 132 NOTREACHED() << "Unknown Video Capture API type!"; | |
| 133 return "Unknown API"; | |
| 134 } | |
| 135 } | |
| 136 #endif | |
| 137 | |
| 138 VideoCaptureDevice::Client::Buffer::~Buffer() { | |
| 139 } | |
| 140 | |
| 141 VideoCaptureDevice::~VideoCaptureDevice() { | |
| 142 } | |
| 143 | |
| 144 void VideoCaptureDevice::GetPhotoCapabilities( | |
| 145 GetPhotoCapabilitiesCallback callback) {} | |
| 146 | |
| 147 void VideoCaptureDevice::SetPhotoOptions(mojom::PhotoSettingsPtr settings, | |
| 148 SetPhotoOptionsCallback callback) {} | |
| 149 | |
| 150 void VideoCaptureDevice::TakePhoto(TakePhotoCallback callback) {} | |
| 151 | |
| 152 PowerLineFrequency VideoCaptureDevice::GetPowerLineFrequencyForLocation() | |
| 153 const { | |
| 154 const std::string current_country = base::CountryCodeForCurrentTimezone(); | |
| 155 if (current_country.empty()) | |
| 156 return PowerLineFrequency::FREQUENCY_DEFAULT; | |
| 157 // Sorted out list of countries with 60Hz power line frequency, from | |
| 158 // http://en.wikipedia.org/wiki/Mains_electricity_by_country | |
| 159 const char* countries_using_60Hz[] = { | |
| 160 "AI", "AO", "AS", "AW", "AZ", "BM", "BR", "BS", "BZ", "CA", "CO", | |
| 161 "CR", "CU", "DO", "EC", "FM", "GT", "GU", "GY", "HN", "HT", "JP", | |
| 162 "KN", "KR", "KY", "MS", "MX", "NI", "PA", "PE", "PF", "PH", "PR", | |
| 163 "PW", "SA", "SR", "SV", "TT", "TW", "UM", "US", "VG", "VI", "VE"}; | |
| 164 const char** countries_using_60Hz_end = | |
| 165 countries_using_60Hz + arraysize(countries_using_60Hz); | |
| 166 if (std::find(countries_using_60Hz, countries_using_60Hz_end, | |
| 167 current_country) == countries_using_60Hz_end) { | |
| 168 return media::PowerLineFrequency::FREQUENCY_50HZ; | |
| 169 } | |
| 170 return media::PowerLineFrequency::FREQUENCY_60HZ; | |
| 171 } | |
| 172 | |
| 173 PowerLineFrequency VideoCaptureDevice::GetPowerLineFrequency( | |
| 174 const VideoCaptureParams& params) const { | |
| 175 switch (params.power_line_frequency) { | |
| 176 case media::PowerLineFrequency::FREQUENCY_50HZ: // fall through | |
| 177 case media::PowerLineFrequency::FREQUENCY_60HZ: | |
| 178 return params.power_line_frequency; | |
| 179 default: | |
| 180 return GetPowerLineFrequencyForLocation(); | |
| 181 } | |
| 182 } | |
| 183 | |
| 184 } // namespace media | |
| OLD | NEW |