Blink roll 25b6bd3a7a131ffe68d809546ad1a20707915cdc:3a503f41ae42e5b79cfcd2ff10e65afde...
[chromium-blink-merge.git] / content / common / media / media_stream_options.cc
blob83add2a42de11266a7732f9d94809f88be23c5cf
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";
24 namespace {
26 bool GetFirstConstraintByName(const StreamOptions::Constraints& constraints,
27 const std::string& name,
28 std::string* value) {
29 for (StreamOptions::Constraints::const_iterator it = constraints.begin();
30 it != constraints.end(); ++it ) {
31 if (it->name == name) {
32 *value = it->value;
33 return true;
36 return false;
39 bool GetFirstConstraintByName(const StreamOptions::Constraints& mandatory,
40 const StreamOptions::Constraints& optional,
41 const std::string& name,
42 std::string* value,
43 bool* is_mandatory) {
44 if (GetFirstConstraintByName(mandatory, name, value)) {
45 if (is_mandatory)
46 *is_mandatory = true;
47 return true;
49 if (is_mandatory)
50 *is_mandatory = false;
51 return GetFirstConstraintByName(optional, name, value);
54 } // namespace
56 StreamOptions::StreamOptions()
57 : audio_requested(false),
58 video_requested(false) {}
60 StreamOptions::StreamOptions(bool request_audio, bool request_video)
61 : audio_requested(request_audio), video_requested(request_video) {
64 StreamOptions::~StreamOptions() {}
66 StreamOptions::Constraint::Constraint() {}
68 StreamOptions::Constraint::Constraint(const std::string& name,
69 const std::string& value)
70 : name(name), value(value) {
73 bool StreamOptions::GetFirstAudioConstraintByName(const std::string& name,
74 std::string* value,
75 bool* is_mandatory) const {
76 return GetFirstConstraintByName(mandatory_audio, optional_audio, name, value,
77 is_mandatory);
80 bool StreamOptions::GetFirstVideoConstraintByName(const std::string& name,
81 std::string* value,
82 bool* is_mandatory) const {
83 return GetFirstConstraintByName(mandatory_video, optional_video, name, value,
84 is_mandatory);
87 // static
88 void StreamOptions::GetConstraintsByName(
89 const StreamOptions::Constraints& constraints,
90 const std::string& name,
91 std::vector<std::string>* values) {
92 for (StreamOptions::Constraints::const_iterator it = constraints.begin();
93 it != constraints.end(); ++it ) {
94 if (it->name == name)
95 values->push_back(it->value);
99 // static
100 const int StreamDeviceInfo::kNoId = -1;
102 StreamDeviceInfo::StreamDeviceInfo()
103 : session_id(kNoId) {}
105 StreamDeviceInfo::StreamDeviceInfo(MediaStreamType service_param,
106 const std::string& name_param,
107 const std::string& device_param)
108 : device(service_param, device_param, name_param),
109 session_id(kNoId) {
112 StreamDeviceInfo::StreamDeviceInfo(MediaStreamType service_param,
113 const std::string& name_param,
114 const std::string& device_param,
115 int sample_rate,
116 int channel_layout,
117 int frames_per_buffer)
118 : device(service_param, device_param, name_param, sample_rate,
119 channel_layout, frames_per_buffer),
120 session_id(kNoId) {
123 // static
124 bool StreamDeviceInfo::IsEqual(const StreamDeviceInfo& first,
125 const StreamDeviceInfo& second) {
126 return first.device.IsEqual(second.device) &&
127 first.session_id == second.session_id;
130 } // namespace content