GPU workaround to simulate Out of Memory errors with large textures
[chromium-blink-merge.git] / content / common / media / media_stream_options.cc
blobdfba2e821e58fd4227e5584eda12e5083ed6cb91
1 // Copyright (c) 2012 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 "content/common/media/media_stream_options.h"
7 #include "base/logging.h"
9 namespace content {
11 const char kMediaStreamSource[] = "chromeMediaSource";
12 const char kMediaStreamSourceId[] = "chromeMediaSourceId";
13 const char kMediaStreamSourceInfoId[] = "sourceId";
14 const char kMediaStreamSourceTab[] = "tab";
15 const char kMediaStreamSourceScreen[] = "screen";
16 const char kMediaStreamSourceDesktop[] = "desktop";
17 const char kMediaStreamSourceSystem[] = "system";
18 const char kMediaStreamRenderToAssociatedSink[] =
19 "chromeRenderToAssociatedSink";
20 // The prefix of this constant is 'goog' to match with other getUserMedia
21 // constraints for audio.
22 const char kMediaStreamAudioDucking[] = "googDucking";
23 const char kMediaStreamAudioHotword[] = "googHotword";
25 namespace {
27 bool GetFirstConstraintByName(const StreamOptions::Constraints& constraints,
28 const std::string& name,
29 std::string* value) {
30 for (StreamOptions::Constraints::const_iterator it = constraints.begin();
31 it != constraints.end(); ++it ) {
32 if (it->name == name) {
33 *value = it->value;
34 return true;
37 return false;
40 bool GetFirstConstraintByName(const StreamOptions::Constraints& mandatory,
41 const StreamOptions::Constraints& optional,
42 const std::string& name,
43 std::string* value,
44 bool* is_mandatory) {
45 if (GetFirstConstraintByName(mandatory, name, value)) {
46 if (is_mandatory)
47 *is_mandatory = true;
48 return true;
50 if (is_mandatory)
51 *is_mandatory = false;
52 return GetFirstConstraintByName(optional, name, value);
55 } // namespace
57 StreamOptions::StreamOptions()
58 : audio_requested(false),
59 video_requested(false) {}
61 StreamOptions::StreamOptions(bool request_audio, bool request_video)
62 : audio_requested(request_audio), video_requested(request_video) {
65 StreamOptions::~StreamOptions() {}
67 StreamOptions::Constraint::Constraint() {}
69 StreamOptions::Constraint::Constraint(const std::string& name,
70 const std::string& value)
71 : name(name), value(value) {
74 bool StreamOptions::GetFirstAudioConstraintByName(const std::string& name,
75 std::string* value,
76 bool* is_mandatory) const {
77 return GetFirstConstraintByName(mandatory_audio, optional_audio, name, value,
78 is_mandatory);
81 bool StreamOptions::GetFirstVideoConstraintByName(const std::string& name,
82 std::string* value,
83 bool* is_mandatory) const {
84 return GetFirstConstraintByName(mandatory_video, optional_video, name, value,
85 is_mandatory);
88 // static
89 void StreamOptions::GetConstraintsByName(
90 const StreamOptions::Constraints& constraints,
91 const std::string& name,
92 std::vector<std::string>* values) {
93 for (StreamOptions::Constraints::const_iterator it = constraints.begin();
94 it != constraints.end(); ++it ) {
95 if (it->name == name)
96 values->push_back(it->value);
100 // static
101 const int StreamDeviceInfo::kNoId = -1;
103 StreamDeviceInfo::StreamDeviceInfo()
104 : session_id(kNoId) {}
106 StreamDeviceInfo::StreamDeviceInfo(MediaStreamType service_param,
107 const std::string& name_param,
108 const std::string& device_param)
109 : device(service_param, device_param, name_param),
110 session_id(kNoId) {
113 StreamDeviceInfo::StreamDeviceInfo(MediaStreamType service_param,
114 const std::string& name_param,
115 const std::string& device_param,
116 int sample_rate,
117 int channel_layout,
118 int frames_per_buffer)
119 : device(service_param, device_param, name_param, sample_rate,
120 channel_layout, frames_per_buffer),
121 session_id(kNoId) {
124 // static
125 bool StreamDeviceInfo::IsEqual(const StreamDeviceInfo& first,
126 const StreamDeviceInfo& second) {
127 return first.device.IsEqual(second.device) &&
128 first.session_id == second.session_id;
131 } // namespace content