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"
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";
26 bool GetFirstConstraintByName(const StreamOptions::Constraints
& constraints
,
27 const std::string
& name
,
29 for (StreamOptions::Constraints::const_iterator it
= constraints
.begin();
30 it
!= constraints
.end(); ++it
) {
31 if (it
->name
== name
) {
39 bool GetFirstConstraintByName(const StreamOptions::Constraints
& mandatory
,
40 const StreamOptions::Constraints
& optional
,
41 const std::string
& name
,
44 if (GetFirstConstraintByName(mandatory
, name
, value
)) {
50 *is_mandatory
= false;
51 return GetFirstConstraintByName(optional
, name
, value
);
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
,
75 bool* is_mandatory
) const {
76 return GetFirstConstraintByName(mandatory_audio
, optional_audio
, name
, value
,
80 bool StreamOptions::GetFirstVideoConstraintByName(const std::string
& name
,
82 bool* is_mandatory
) const {
83 return GetFirstConstraintByName(mandatory_video
, optional_video
, name
, value
,
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
) {
95 values
->push_back(it
->value
);
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
),
112 StreamDeviceInfo::StreamDeviceInfo(MediaStreamType service_param
,
113 const std::string
& name_param
,
114 const std::string
& device_param
,
117 int frames_per_buffer
)
118 : device(service_param
, device_param
, name_param
, sample_rate
,
119 channel_layout
, frames_per_buffer
),
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