Updating XTBs based on .GRDs from branch master
[chromium-blink-merge.git] / media / capture / video / video_capture_device.cc
blob72605890a70f34812dceac25baf8d9524e92d8be
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.
5 #include "media/capture/video/video_capture_device.h"
7 #include "base/i18n/timezone.h"
8 #include "base/strings/string_util.h"
10 namespace media {
12 const std::string VideoCaptureDevice::Name::GetNameAndModel() const {
13 const std::string model_id = GetModel();
14 if (model_id.empty())
15 return device_name_;
16 const std::string suffix = " (" + model_id + ")";
17 if (base::EndsWith(device_name_, suffix, base::CompareCase::SENSITIVE))
18 return device_name_;
19 return device_name_ + suffix;
22 VideoCaptureDevice::Name::Name() {
25 VideoCaptureDevice::Name::Name(const std::string& name, const std::string& id)
26 : device_name_(name), unique_id_(id) {
29 #if defined(OS_LINUX)
30 VideoCaptureDevice::Name::Name(const std::string& name,
31 const std::string& id,
32 const CaptureApiType api_type)
33 : device_name_(name), unique_id_(id), capture_api_class_(api_type) {
35 #elif defined(OS_WIN)
36 VideoCaptureDevice::Name::Name(const std::string& name,
37 const std::string& id,
38 const CaptureApiType api_type)
39 : device_name_(name),
40 unique_id_(id),
41 capture_api_class_(api_type),
42 capabilities_id_(id) {
44 #elif defined(OS_MACOSX)
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 transport_type_(OTHER_TRANSPORT),
52 is_blacklisted_(false) {
55 VideoCaptureDevice::Name::Name(const std::string& name,
56 const std::string& id,
57 const CaptureApiType api_type,
58 const TransportType transport_type)
59 : device_name_(name),
60 unique_id_(id),
61 capture_api_class_(api_type),
62 transport_type_(transport_type),
63 is_blacklisted_(false) {
65 #elif defined(ANDROID)
66 VideoCaptureDevice::Name::Name(const std::string& name,
67 const std::string& id,
68 const CaptureApiType api_type)
69 : device_name_(name), unique_id_(id), capture_api_class_(api_type) {
71 #endif
73 VideoCaptureDevice::Name::~Name() {
76 #if defined(OS_LINUX)
77 const char* VideoCaptureDevice::Name::GetCaptureApiTypeString() const {
78 switch (capture_api_type()) {
79 case V4L2_SINGLE_PLANE:
80 return "V4L2 SPLANE";
81 case V4L2_MULTI_PLANE:
82 return "V4L2 MPLANE";
83 default:
84 NOTREACHED() << "Unknown Video Capture API type!";
85 return "Unknown API";
88 #elif defined(OS_WIN)
89 const char* VideoCaptureDevice::Name::GetCaptureApiTypeString() const {
90 switch (capture_api_type()) {
91 case MEDIA_FOUNDATION:
92 return "Media Foundation";
93 case DIRECT_SHOW:
94 return "Direct Show";
95 default:
96 NOTREACHED() << "Unknown Video Capture API type!";
97 return "Unknown API";
100 #elif defined(OS_MACOSX)
101 const char* VideoCaptureDevice::Name::GetCaptureApiTypeString() const {
102 switch (capture_api_type()) {
103 case AVFOUNDATION:
104 return "AV Foundation";
105 case QTKIT:
106 return "QTKit";
107 case DECKLINK:
108 return "DeckLink";
109 default:
110 NOTREACHED() << "Unknown Video Capture API type!";
111 return "Unknown API";
114 #elif defined(OS_ANDROID)
115 const char* VideoCaptureDevice::Name::GetCaptureApiTypeString() const {
116 switch (capture_api_type()) {
117 case API1:
118 return "Camera API1";
119 case API2_LEGACY:
120 return "Camera API2 Legacy";
121 case API2_FULL:
122 return "Camera API2 Full";
123 case API2_LIMITED:
124 return "Camera API2 Limited";
125 case TANGO:
126 return "Tango API";
127 case API_TYPE_UNKNOWN:
128 default:
129 NOTREACHED() << "Unknown Video Capture API type!";
130 return "Unknown API";
133 #endif
135 VideoCaptureDevice::Client::Buffer::~Buffer() {
138 VideoCaptureDevice::~VideoCaptureDevice() {
141 int VideoCaptureDevice::GetPowerLineFrequencyForLocation() const {
142 std::string current_country = base::CountryCodeForCurrentTimezone();
143 if (current_country.empty())
144 return 0;
145 // Sorted out list of countries with 60Hz power line frequency, from
146 // http://en.wikipedia.org/wiki/Mains_electricity_by_country
147 const char* countries_using_60Hz[] = {
148 "AI", "AO", "AS", "AW", "AZ", "BM", "BR", "BS", "BZ", "CA", "CO",
149 "CR", "CU", "DO", "EC", "FM", "GT", "GU", "GY", "HN", "HT", "JP",
150 "KN", "KR", "KY", "MS", "MX", "NI", "PA", "PE", "PF", "PH", "PR",
151 "PW", "SA", "SR", "SV", "TT", "TW", "UM", "US", "VG", "VI", "VE"};
152 const char** countries_using_60Hz_end =
153 countries_using_60Hz + arraysize(countries_using_60Hz);
154 if (std::find(countries_using_60Hz, countries_using_60Hz_end,
155 current_country) == countries_using_60Hz_end) {
156 return kPowerLine50Hz;
158 return kPowerLine60Hz;
161 } // namespace media