summaryrefslogtreecommitdiffstats
path: root/media/video/capture/video_capture_device.cc
blob: e4744893a261f1dec110548fc34db4fa759ada79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// Copyright 2013 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 "media/video/capture/video_capture_device.h"

#include "base/i18n/timezone.h"
#include "base/strings/string_util.h"

namespace media {

const std::string VideoCaptureDevice::Name::GetNameAndModel() const {
  const std::string model_id = GetModel();
  if (model_id.empty())
    return device_name_;
  const std::string suffix = " (" + model_id + ")";
  if (base::EndsWith(device_name_, suffix, true /* case sensitive */))
    return device_name_;
  return device_name_ + suffix;
}

VideoCaptureDevice::Name::Name() {}

VideoCaptureDevice::Name::Name(const std::string& name, const std::string& id)
    : device_name_(name), unique_id_(id) {}

#if defined(OS_LINUX)
VideoCaptureDevice::Name::Name(const std::string& name,
                               const std::string& id,
                               const CaptureApiType api_type)
    : device_name_(name),
      unique_id_(id),
      capture_api_class_(api_type) {}
#elif defined(OS_WIN)
VideoCaptureDevice::Name::Name(const std::string& name,
                               const std::string& id,
                               const CaptureApiType api_type)
    : device_name_(name),
      unique_id_(id),
      capture_api_class_(api_type),
      capabilities_id_(id) {}
#elif defined(OS_MACOSX)
VideoCaptureDevice::Name::Name(const std::string& name,
                               const std::string& id,
                               const CaptureApiType api_type)
    : device_name_(name),
      unique_id_(id),
      capture_api_class_(api_type),
      transport_type_(OTHER_TRANSPORT),
      is_blacklisted_(false) {}

VideoCaptureDevice::Name::Name(const std::string& name,
                               const std::string& id,
                               const CaptureApiType api_type,
                               const TransportType transport_type)
    : device_name_(name),
      unique_id_(id),
      capture_api_class_(api_type),
      transport_type_(transport_type),
      is_blacklisted_(false) {}
#elif defined(ANDROID)
VideoCaptureDevice::Name::Name(const std::string& name,
                               const std::string& id,
                               const CaptureApiType api_type)
    : device_name_(name),
      unique_id_(id),
      capture_api_class_(api_type) {}
#endif

VideoCaptureDevice::Name::~Name() {}

#if defined(OS_LINUX)
const char* VideoCaptureDevice::Name::GetCaptureApiTypeString() const {
  switch (capture_api_type()) {
    case V4L2_SINGLE_PLANE:
      return "V4L2 SPLANE";
    case V4L2_MULTI_PLANE:
      return "V4L2 MPLANE";
    default:
      NOTREACHED() << "Unknown Video Capture API type!";
      return "Unknown API";
  }
}
#elif defined(OS_WIN)
const char* VideoCaptureDevice::Name::GetCaptureApiTypeString() const {
  switch(capture_api_type()) {
    case MEDIA_FOUNDATION:
      return "Media Foundation";
    case DIRECT_SHOW:
      return "Direct Show";
    default:
      NOTREACHED() << "Unknown Video Capture API type!";
      return "Unknown API";
  }
}
#elif defined(OS_MACOSX)
const char* VideoCaptureDevice::Name::GetCaptureApiTypeString() const {
  switch(capture_api_type()) {
    case AVFOUNDATION:
      return "AV Foundation";
    case QTKIT:
      return "QTKit";
    case DECKLINK:
      return "DeckLink";
    default:
      NOTREACHED() << "Unknown Video Capture API type!";
      return "Unknown API";
  }
}
#elif defined(OS_ANDROID)
const char* VideoCaptureDevice::Name::GetCaptureApiTypeString() const {
  switch(capture_api_type()) {
    case API1:
      return "Camera API1";
    case API2_LEGACY:
      return "Camera API2 Legacy";
    case API2_FULL:
      return "Camera API2 Full";
    case API2_LIMITED:
      return "Camera API2 Limited";
    case TANGO:
      return "Tango API";
    case API_TYPE_UNKNOWN:
    default:
      NOTREACHED() << "Unknown Video Capture API type!";
      return "Unknown API";
  }
}
#endif

VideoCaptureDevice::Client::Buffer::~Buffer() {}

VideoCaptureDevice::~VideoCaptureDevice() {}

int VideoCaptureDevice::GetPowerLineFrequencyForLocation() const {
  std::string current_country = base::CountryCodeForCurrentTimezone();
  if (current_country.empty())
    return 0;
  // Sorted out list of countries with 60Hz power line frequency, from
  // http://en.wikipedia.org/wiki/Mains_electricity_by_country
  const char* countries_using_60Hz[] = {
      "AI", "AO", "AS", "AW", "AZ", "BM", "BR", "BS", "BZ", "CA", "CO",
      "CR", "CU", "DO", "EC", "FM", "GT", "GU", "GY", "HN", "HT", "JP",
      "KN", "KR", "KY", "MS", "MX", "NI", "PA", "PE", "PF", "PH", "PR",
      "PW", "SA", "SR", "SV", "TT", "TW", "UM", "US", "VG", "VI", "VE"};
  const char** countries_using_60Hz_end =
      countries_using_60Hz + arraysize(countries_using_60Hz);
  if (std::find(countries_using_60Hz, countries_using_60Hz_end,
                current_country) == countries_using_60Hz_end) {
    return kPowerLine50Hz;
  }
  return kPowerLine60Hz;
}

}  // namespace media