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 #ifndef CONTENT_COMMON_MEDIA_MEDIA_STREAM_OPTIONS_H_ 6 #define CONTENT_COMMON_MEDIA_MEDIA_STREAM_OPTIONS_H_ 7 8 #include <string> 9 #include <vector> 10 11 #include "content/common/content_export.h" 12 #include "content/public/common/media_stream_request.h" 13 14 namespace content { 15 16 // MediaStreamConstraint keys for constraints that are passed to getUserMedia. 17 CONTENT_EXPORT extern const char kMediaStreamSource[]; 18 CONTENT_EXPORT extern const char kMediaStreamSourceId[]; 19 CONTENT_EXPORT extern const char kMediaStreamSourceInfoId[]; 20 CONTENT_EXPORT extern const char kMediaStreamSourceTab[]; 21 CONTENT_EXPORT extern const char kMediaStreamSourceScreen[]; 22 CONTENT_EXPORT extern const char kMediaStreamSourceDesktop[]; 23 CONTENT_EXPORT extern const char kMediaStreamSourceSystem[]; 24 25 // Experimental constraint to do device matching. When this optional constraint 26 // is set, WebRTC audio renderer will render audio from media streams to an 27 // output device that belongs to the same hardware as the requested source 28 // device belongs to. 29 CONTENT_EXPORT extern const char kMediaStreamRenderToAssociatedSink[]; 30 31 // StreamOptions is a Chromium representation of constraints 32 // used in WebUserMediaRequest. 33 // It describes properties requested by JS in a request for a new 34 // media stream. 35 class CONTENT_EXPORT StreamOptions { 36 public: 37 StreamOptions(); 38 StreamOptions(bool request_audio, bool request_video); 39 ~StreamOptions(); 40 41 struct CONTENT_EXPORT Constraint { 42 Constraint(); 43 Constraint(const std::string& name, 44 const std::string& value); 45 46 std::string name; 47 std::string value; 48 }; 49 typedef std::vector<Constraint> Constraints; 50 51 bool audio_requested; 52 Constraints mandatory_audio; 53 Constraints optional_audio; 54 55 bool video_requested; 56 Constraints mandatory_video; 57 Constraints optional_video; 58 59 // Fetches |value| from the first audio constraint with a name that matches 60 // |name| from |mandatory_audio| and |optional_audio|. First mandatory 61 // constraints are searched, then optional. 62 // |is_mandatory| may be NULL but if it is provided, it is set 63 // to true if the found constraint is mandatory. 64 // Returns false if no constraint is found. 65 bool GetFirstAudioConstraintByName(const std::string& name, 66 std::string* value, 67 bool* is_mandatory) const; 68 69 // Fetches |value| from the first video constraint with a name that matches 70 // |name| from |mandatory_video| and |optional_video|. First mandatory 71 // constraints are searched, then optional. 72 // |is_mandatory| may be NULL but if it is provided, it is set 73 // to true if the found constraint is mandatory. 74 // Returns false if no constraint is found. 75 bool GetFirstVideoConstraintByName(const std::string& name, 76 std::string* value, 77 bool* is_mandatory) const; 78 79 // Fetches |values| from all constraint with a name that matches |name| 80 // from |constraints|. 81 static void GetConstraintsByName( 82 const StreamOptions::Constraints& constraints, 83 const std::string& name, 84 std::vector<std::string>* values); 85 }; 86 87 // StreamDeviceInfo describes information about a device. 88 struct CONTENT_EXPORT StreamDeviceInfo { 89 static const int kNoId; 90 91 StreamDeviceInfo(); 92 StreamDeviceInfo(MediaStreamType service_param, 93 const std::string& name_param, 94 const std::string& device_param); 95 StreamDeviceInfo(MediaStreamType service_param, 96 const std::string& name_param, 97 const std::string& device_param, 98 int sample_rate, 99 int channel_layout, 100 int frames_per_buffer); 101 static bool IsEqual(const StreamDeviceInfo& first, 102 const StreamDeviceInfo& second); 103 104 MediaStreamDevice device; 105 106 // Id for this capture session. Unique for all sessions of the same type. 107 int session_id; 108 }; 109 110 typedef std::vector<StreamDeviceInfo> StreamDeviceInfoArray; 111 112 } // namespace content 113 114 #endif // CONTENT_COMMON_MEDIA_MEDIA_STREAM_OPTIONS_H_ 115