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";
23 const char kMediaStreamAudioHotword
[] = "googHotword";
27 bool GetFirstConstraintByName(const StreamOptions::Constraints
& constraints
,
28 const std::string
& name
,
30 for (StreamOptions::Constraints::const_iterator it
= constraints
.begin();
31 it
!= constraints
.end(); ++it
) {
32 if (it
->name
== name
) {
40 bool GetFirstConstraintByName(const StreamOptions::Constraints
& mandatory
,
41 const StreamOptions::Constraints
& optional
,
42 const std::string
& name
,
45 if (GetFirstConstraintByName(mandatory
, name
, value
)) {
51 *is_mandatory
= false;
52 return GetFirstConstraintByName(optional
, name
, value
);
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
,
76 bool* is_mandatory
) const {
77 return GetFirstConstraintByName(mandatory_audio
, optional_audio
, name
, value
,
81 bool StreamOptions::GetFirstVideoConstraintByName(const std::string
& name
,
83 bool* is_mandatory
) const {
84 return GetFirstConstraintByName(mandatory_video
, optional_video
, name
, value
,
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
) {
96 values
->push_back(it
->value
);
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
),
113 StreamDeviceInfo::StreamDeviceInfo(MediaStreamType service_param
,
114 const std::string
& name_param
,
115 const std::string
& device_param
,
118 int frames_per_buffer
)
119 : device(service_param
, device_param
, name_param
, sample_rate
,
120 channel_layout
, frames_per_buffer
),
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