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.
4
5 #include "content/common/media/media_stream_options.h"
6
7 #include "base/logging.h"
8
9 namespace content {
10
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
21 namespace {
22
GetFirstConstraintByName(const StreamOptions::Constraints & constraints,const std::string & name,std::string * value)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;
31 }
32 }
33 return false;
34 }
35
GetFirstConstraintByName(const StreamOptions::Constraints & mandatory,const StreamOptions::Constraints & optional,const std::string & name,std::string * value,bool * is_mandatory)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;
45 }
46 if (is_mandatory)
47 *is_mandatory = false;
48 return GetFirstConstraintByName(optional, name, value);
49 }
50
51 } // namespace
52
StreamOptions()53 StreamOptions::StreamOptions()
54 : audio_requested(false),
55 video_requested(false) {}
56
StreamOptions(bool request_audio,bool request_video)57 StreamOptions::StreamOptions(bool request_audio, bool request_video)
58 : audio_requested(request_audio), video_requested(request_video) {
59 }
60
~StreamOptions()61 StreamOptions::~StreamOptions() {}
62
Constraint()63 StreamOptions::Constraint::Constraint() {}
64
Constraint(const std::string & name,const std::string & value)65 StreamOptions::Constraint::Constraint(const std::string& name,
66 const std::string& value)
67 : name(name), value(value) {
68 }
69
GetFirstAudioConstraintByName(const std::string & name,std::string * value,bool * is_mandatory) const70 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);
75 }
76
GetFirstVideoConstraintByName(const std::string & name,std::string * value,bool * is_mandatory) const77 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);
82 }
83
84 // static
GetConstraintsByName(const StreamOptions::Constraints & constraints,const std::string & name,std::vector<std::string> * values)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);
93 }
94 }
95
96 // static
97 const int StreamDeviceInfo::kNoId = -1;
98
StreamDeviceInfo()99 StreamDeviceInfo::StreamDeviceInfo()
100 : session_id(kNoId) {}
101
StreamDeviceInfo(MediaStreamType service_param,const std::string & name_param,const std::string & device_param)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) {
107 }
108
StreamDeviceInfo(MediaStreamType service_param,const std::string & name_param,const std::string & device_param,int sample_rate,int channel_layout,int frames_per_buffer)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) {
118 }
119
120 // static
IsEqual(const StreamDeviceInfo & first,const StreamDeviceInfo & second)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;
125 }
126
127 } // namespace content
128