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";
23 bool GetFirstConstraintByName(const StreamOptions::Constraints
& constraints
,
24 const std::string
& name
,
26 for (StreamOptions::Constraints::const_iterator it
= constraints
.begin();
27 it
!= constraints
.end(); ++it
) {
28 if (it
->name
== name
) {
36 bool GetFirstConstraintByName(const StreamOptions::Constraints
& mandatory
,
37 const StreamOptions::Constraints
& optional
,
38 const std::string
& name
,
41 if (GetFirstConstraintByName(mandatory
, name
, value
)) {
47 *is_mandatory
= false;
48 return GetFirstConstraintByName(optional
, name
, value
);
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
,
72 bool* is_mandatory
) const {
73 return GetFirstConstraintByName(mandatory_audio
, optional_audio
, name
, value
,
77 bool StreamOptions::GetFirstVideoConstraintByName(const std::string
& name
,
79 bool* is_mandatory
) const {
80 return GetFirstConstraintByName(mandatory_video
, optional_video
, name
, value
,
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
) {
92 values
->push_back(it
->value
);
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
),
109 StreamDeviceInfo::StreamDeviceInfo(MediaStreamType service_param
,
110 const std::string
& name_param
,
111 const std::string
& device_param
,
114 int frames_per_buffer
)
115 : device(service_param
, device_param
, name_param
, sample_rate
,
116 channel_layout
, frames_per_buffer
),
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