IndexedDBFactory now ForceCloses databases.
[chromium-blink-merge.git] / content / common / media / media_stream_options.cc
blob4ddef015334c3b42b75f5d88121b3b6d5056f2a6
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";
21 namespace {
23 bool GetFirstConstraintByName(const StreamOptions::Constraints& constraints,
24 const std::string& name,
25 std::string* value) {
26 for (StreamOptions::Constraints::const_iterator it = constraints.begin();
27 it != constraints.end(); ++it ) {
28 if (it->name == name) {
29 *value = it->value;
30 return true;
33 return false;
36 bool GetFirstConstraintByName(const StreamOptions::Constraints& mandatory,
37 const StreamOptions::Constraints& optional,
38 const std::string& name,
39 std::string* value,
40 bool* is_mandatory) {
41 if (GetFirstConstraintByName(mandatory, name, value)) {
42 if (is_mandatory)
43 *is_mandatory = true;
44 return true;
46 if (is_mandatory)
47 *is_mandatory = false;
48 return GetFirstConstraintByName(optional, name, value);
51 } // namespace
53 StreamOptions::StreamOptions()
54 : audio_requested(false),
55 video_requested(false) {}
57 StreamOptions::StreamOptions(bool request_audio, bool request_video)
58 : audio_requested(request_audio), video_requested(request_video) {
61 StreamOptions::~StreamOptions() {}
63 StreamOptions::Constraint::Constraint() {}
65 StreamOptions::Constraint::Constraint(const std::string& name,
66 const std::string& value)
67 : name(name), value(value) {
70 bool StreamOptions::GetFirstAudioConstraintByName(const std::string& name,
71 std::string* value,
72 bool* is_mandatory) const {
73 return GetFirstConstraintByName(mandatory_audio, optional_audio, name, value,
74 is_mandatory);
77 bool StreamOptions::GetFirstVideoConstraintByName(const std::string& name,
78 std::string* value,
79 bool* is_mandatory) const {
80 return GetFirstConstraintByName(mandatory_video, optional_video, name, value,
81 is_mandatory);
84 // static
85 void StreamOptions::GetConstraintsByName(
86 const StreamOptions::Constraints& constraints,
87 const std::string& name,
88 std::vector<std::string>* values) {
89 for (StreamOptions::Constraints::const_iterator it = constraints.begin();
90 it != constraints.end(); ++it ) {
91 if (it->name == name)
92 values->push_back(it->value);
96 // static
97 const int StreamDeviceInfo::kNoId = -1;
99 StreamDeviceInfo::StreamDeviceInfo()
100 : session_id(kNoId) {}
102 StreamDeviceInfo::StreamDeviceInfo(MediaStreamType service_param,
103 const std::string& name_param,
104 const std::string& device_param)
105 : device(service_param, device_param, name_param),
106 session_id(kNoId) {
109 StreamDeviceInfo::StreamDeviceInfo(MediaStreamType service_param,
110 const std::string& name_param,
111 const std::string& device_param,
112 int sample_rate,
113 int channel_layout,
114 int frames_per_buffer)
115 : device(service_param, device_param, name_param, sample_rate,
116 channel_layout, frames_per_buffer),
117 session_id(kNoId) {
120 // static
121 bool StreamDeviceInfo::IsEqual(const StreamDeviceInfo& first,
122 const StreamDeviceInfo& second) {
123 return first.device.IsEqual(second.device) &&
124 first.session_id == second.session_id;
127 } // namespace content