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 9namespace content { 10 11const char kMediaStreamSource[] = "chromeMediaSource"; 12const char kMediaStreamSourceId[] = "chromeMediaSourceId"; 13const char kMediaStreamSourceInfoId[] = "sourceId"; 14const char kMediaStreamSourceTab[] = "tab"; 15const char kMediaStreamSourceScreen[] = "screen"; 16const char kMediaStreamSourceDesktop[] = "desktop"; 17const char kMediaStreamSourceSystem[] = "system"; 18const char kMediaStreamRenderToAssociatedSink[] = 19 "chromeRenderToAssociatedSink"; 20// The prefix of this constant is 'goog' to match with other getUserMedia 21// constraints for audio. 22const char kMediaStreamAudioDucking[] = "googDucking"; 23 24namespace { 25 26bool GetFirstConstraintByName(const StreamOptions::Constraints& constraints, 27 const std::string& name, 28 std::string* value) { 29 for (StreamOptions::Constraints::const_iterator it = constraints.begin(); 30 it != constraints.end(); ++it ) { 31 if (it->name == name) { 32 *value = it->value; 33 return true; 34 } 35 } 36 return false; 37} 38 39bool GetFirstConstraintByName(const StreamOptions::Constraints& mandatory, 40 const StreamOptions::Constraints& optional, 41 const std::string& name, 42 std::string* value, 43 bool* is_mandatory) { 44 if (GetFirstConstraintByName(mandatory, name, value)) { 45 if (is_mandatory) 46 *is_mandatory = true; 47 return true; 48 } 49 if (is_mandatory) 50 *is_mandatory = false; 51 return GetFirstConstraintByName(optional, name, value); 52} 53 54} // namespace 55 56StreamOptions::StreamOptions() 57 : audio_requested(false), 58 video_requested(false) {} 59 60StreamOptions::StreamOptions(bool request_audio, bool request_video) 61 : audio_requested(request_audio), video_requested(request_video) { 62} 63 64StreamOptions::~StreamOptions() {} 65 66StreamOptions::Constraint::Constraint() {} 67 68StreamOptions::Constraint::Constraint(const std::string& name, 69 const std::string& value) 70 : name(name), value(value) { 71} 72 73bool StreamOptions::GetFirstAudioConstraintByName(const std::string& name, 74 std::string* value, 75 bool* is_mandatory) const { 76 return GetFirstConstraintByName(mandatory_audio, optional_audio, name, value, 77 is_mandatory); 78} 79 80bool StreamOptions::GetFirstVideoConstraintByName(const std::string& name, 81 std::string* value, 82 bool* is_mandatory) const { 83 return GetFirstConstraintByName(mandatory_video, optional_video, name, value, 84 is_mandatory); 85} 86 87// static 88void 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 ) { 94 if (it->name == name) 95 values->push_back(it->value); 96 } 97} 98 99// static 100const int StreamDeviceInfo::kNoId = -1; 101 102StreamDeviceInfo::StreamDeviceInfo() 103 : session_id(kNoId) {} 104 105StreamDeviceInfo::StreamDeviceInfo(MediaStreamType service_param, 106 const std::string& name_param, 107 const std::string& device_param) 108 : device(service_param, device_param, name_param), 109 session_id(kNoId) { 110} 111 112StreamDeviceInfo::StreamDeviceInfo(MediaStreamType service_param, 113 const std::string& name_param, 114 const std::string& device_param, 115 int sample_rate, 116 int channel_layout, 117 int frames_per_buffer) 118 : device(service_param, device_param, name_param, sample_rate, 119 channel_layout, frames_per_buffer), 120 session_id(kNoId) { 121} 122 123// static 124bool StreamDeviceInfo::IsEqual(const StreamDeviceInfo& first, 125 const StreamDeviceInfo& second) { 126 return first.device.IsEqual(second.device) && 127 first.session_id == second.session_id; 128} 129 130} // namespace content 131