1902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com// Use of this source code is governed by a BSD-style license that can be
3902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com// found in the LICENSE file.
4902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com
5902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com#ifndef CONTENT_COMMON_MEDIA_MEDIA_STREAM_OPTIONS_H_
6902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com#define CONTENT_COMMON_MEDIA_MEDIA_STREAM_OPTIONS_H_
7902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com
8902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com#include <string>
9902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com#include <vector>
10902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com
11902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com#include "content/common/content_export.h"
12902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com#include "content/public/common/media_stream_request.h"
13902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com
14902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.comnamespace content {
15902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com
168a1cdaece7e1d009befb84f21bb82370025bf4d6robertphillips@google.com// MediaStreamConstraint keys for constraints that are passed to getUserMedia.
1797cee9735350cb472249ce1a827ba1aa6b2a5f59chudy@google.comCONTENT_EXPORT extern const char kMediaStreamSource[];
18902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.comCONTENT_EXPORT extern const char kMediaStreamSourceId[];
1932bbcf828d66ad244fa25b468bc3a229e531491frobertphillips@google.comCONTENT_EXPORT extern const char kMediaStreamSourceInfoId[];
2032bbcf828d66ad244fa25b468bc3a229e531491frobertphillips@google.comCONTENT_EXPORT extern const char kMediaStreamSourceTab[];
2186681b37bd20204e47a492119b345c01d00bc939fmalita@google.comCONTENT_EXPORT extern const char kMediaStreamSourceScreen[];
22902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.comCONTENT_EXPORT extern const char kMediaStreamSourceDesktop[];
2380a4a60f96c33ccd850f9b0eb4b69ab08c198196chudy@google.comCONTENT_EXPORT extern const char kMediaStreamSourceSystem[];
24f4741c1322944e194ca34a8f5cf8188fe2c0efe2robertphillips@google.com
25902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com// Experimental constraint to do device matching.  When this optional constraint
26768ac85655017d4106444bf3ad044680a575ccaacommit-bot@chromium.org// is set, WebRTC audio renderer will render audio from media streams to an
27768ac85655017d4106444bf3ad044680a575ccaacommit-bot@chromium.org// output device that belongs to the same hardware as the requested source
28768ac85655017d4106444bf3ad044680a575ccaacommit-bot@chromium.org// device belongs to.
29902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.comCONTENT_EXPORT extern const char kMediaStreamRenderToAssociatedSink[];
30902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com
31f4741c1322944e194ca34a8f5cf8188fe2c0efe2robertphillips@google.com// Controls whether ducking of audio is enabled on platforms that support it.
32f4741c1322944e194ca34a8f5cf8188fe2c0efe2robertphillips@google.comCONTENT_EXPORT extern const char kMediaStreamAudioDucking[];
33f4741c1322944e194ca34a8f5cf8188fe2c0efe2robertphillips@google.com
34f4741c1322944e194ca34a8f5cf8188fe2c0efe2robertphillips@google.com// StreamOptions is a Chromium representation of constraints
35f4741c1322944e194ca34a8f5cf8188fe2c0efe2robertphillips@google.com// used in WebUserMediaRequest.
3632bbcf828d66ad244fa25b468bc3a229e531491frobertphillips@google.com// It describes properties requested by JS in a request for a new
3732bbcf828d66ad244fa25b468bc3a229e531491frobertphillips@google.com// media stream.
38f84ad8f7fc0194389a8099da2c5e8fff9f092890skia.committer@gmail.comclass CONTENT_EXPORT StreamOptions {
3932bbcf828d66ad244fa25b468bc3a229e531491frobertphillips@google.com public:
4032bbcf828d66ad244fa25b468bc3a229e531491frobertphillips@google.com  StreamOptions();
41902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com  StreamOptions(bool request_audio, bool request_video);
42902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com  ~StreamOptions();
43902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com
44902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com  struct CONTENT_EXPORT Constraint {
45902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com    Constraint();
46902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com    Constraint(const std::string& name,
47902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com               const std::string& value);
48902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com
49902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com    std::string name;
50902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com    std::string value;
510b5bbb0f82e022c8acfbcb6312f0ed18e1ab90cechudy@google.com  };
520b5bbb0f82e022c8acfbcb6312f0ed18e1ab90cechudy@google.com  typedef std::vector<Constraint> Constraints;
530b5bbb0f82e022c8acfbcb6312f0ed18e1ab90cechudy@google.com
54a9e937c7b712b024de108fa963f92d0e70e4a296chudy@google.com  bool audio_requested;
55a9e937c7b712b024de108fa963f92d0e70e4a296chudy@google.com  Constraints mandatory_audio;
56a9e937c7b712b024de108fa963f92d0e70e4a296chudy@google.com  Constraints optional_audio;
57a9e937c7b712b024de108fa963f92d0e70e4a296chudy@google.com
58a9e937c7b712b024de108fa963f92d0e70e4a296chudy@google.com  bool video_requested;
59a9e937c7b712b024de108fa963f92d0e70e4a296chudy@google.com  Constraints mandatory_video;
60a9e937c7b712b024de108fa963f92d0e70e4a296chudy@google.com  Constraints optional_video;
61a9e937c7b712b024de108fa963f92d0e70e4a296chudy@google.com
62a9e937c7b712b024de108fa963f92d0e70e4a296chudy@google.com  // Fetches |value| from the first audio constraint with a name that matches
63a9e937c7b712b024de108fa963f92d0e70e4a296chudy@google.com  // |name| from |mandatory_audio| and |optional_audio|. First mandatory
64a9e937c7b712b024de108fa963f92d0e70e4a296chudy@google.com  // constraints are searched, then optional.
65a9e937c7b712b024de108fa963f92d0e70e4a296chudy@google.com  // |is_mandatory| may be NULL but if it is provided, it is set
66a9e937c7b712b024de108fa963f92d0e70e4a296chudy@google.com  // to true if the found constraint is mandatory.
67a9e937c7b712b024de108fa963f92d0e70e4a296chudy@google.com  // Returns false if no constraint is found.
680b5bbb0f82e022c8acfbcb6312f0ed18e1ab90cechudy@google.com  bool GetFirstAudioConstraintByName(const std::string& name,
690b5bbb0f82e022c8acfbcb6312f0ed18e1ab90cechudy@google.com                                     std::string* value,
70830b8793bb1646bb76817bdc228dd8e2a92bef7dchudy@google.com                                     bool* is_mandatory) const;
71902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com
72902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com  // Fetches |value| from the first video constraint with a name that matches
7350c84da68b17647371a81593402e897d639989e4robertphillips@google.com  // |name| from |mandatory_video| and |optional_video|. First mandatory
7450c84da68b17647371a81593402e897d639989e4robertphillips@google.com  // constraints are searched, then optional.
7550c84da68b17647371a81593402e897d639989e4robertphillips@google.com  // |is_mandatory| may be NULL but if it is provided, it is set
7650c84da68b17647371a81593402e897d639989e4robertphillips@google.com  // to true if the found constraint is mandatory.
7750c84da68b17647371a81593402e897d639989e4robertphillips@google.com  // Returns false if no constraint is found.
7850c84da68b17647371a81593402e897d639989e4robertphillips@google.com  bool GetFirstVideoConstraintByName(const std::string& name,
79902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com                                     std::string* value,
80902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com                                     bool* is_mandatory) const;
81902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com
82902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com  // Fetches |values| from all constraint with a name that matches |name|
83902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com  // from |constraints|.
84902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com  static void GetConstraintsByName(
8550c84da68b17647371a81593402e897d639989e4robertphillips@google.com      const StreamOptions::Constraints& constraints,
8650c84da68b17647371a81593402e897d639989e4robertphillips@google.com      const std::string& name,
8750c84da68b17647371a81593402e897d639989e4robertphillips@google.com      std::vector<std::string>* values);
8850c84da68b17647371a81593402e897d639989e4robertphillips@google.com};
8950c84da68b17647371a81593402e897d639989e4robertphillips@google.com
9050c84da68b17647371a81593402e897d639989e4robertphillips@google.com// StreamDeviceInfo describes information about a device.
9150c84da68b17647371a81593402e897d639989e4robertphillips@google.comstruct CONTENT_EXPORT StreamDeviceInfo {
92902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com  static const int kNoId;
93902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com
94902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com  StreamDeviceInfo();
9597cee9735350cb472249ce1a827ba1aa6b2a5f59chudy@google.com  StreamDeviceInfo(MediaStreamType service_param,
96902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com                   const std::string& name_param,
97902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com                   const std::string& device_param);
987e4cfbf144af7d530d552946cee2a21d30b9b50fchudy@google.com  StreamDeviceInfo(MediaStreamType service_param,
997e4cfbf144af7d530d552946cee2a21d30b9b50fchudy@google.com                   const std::string& name_param,
1007e4cfbf144af7d530d552946cee2a21d30b9b50fchudy@google.com                   const std::string& device_param,
1017e4cfbf144af7d530d552946cee2a21d30b9b50fchudy@google.com                   int sample_rate,
1027e4cfbf144af7d530d552946cee2a21d30b9b50fchudy@google.com                   int channel_layout,
1037e4cfbf144af7d530d552946cee2a21d30b9b50fchudy@google.com                   int frames_per_buffer);
104902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com  static bool IsEqual(const StreamDeviceInfo& first,
105902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com                      const StreamDeviceInfo& second);
1064469938e92d779dff05e745559e67907bbf21e78reed@google.com
1078a1cdaece7e1d009befb84f21bb82370025bf4d6robertphillips@google.com  MediaStreamDevice device;
1082e71f1619d9a2c51c1292e618f42a56ad2da1de8skia.committer@gmail.com
109febc0ec41b4cff6ea69f2b89d72c0d330d198283robertphillips@google.com  // Id for this capture session. Unique for all sessions of the same type.
110febc0ec41b4cff6ea69f2b89d72c0d330d198283robertphillips@google.com  int session_id;
111febc0ec41b4cff6ea69f2b89d72c0d330d198283robertphillips@google.com};
112febc0ec41b4cff6ea69f2b89d72c0d330d198283robertphillips@google.com
113febc0ec41b4cff6ea69f2b89d72c0d330d198283robertphillips@google.comtypedef std::vector<StreamDeviceInfo> StreamDeviceInfoArray;
114902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com
115902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com}  // namespace content
116902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com
117902ebe5eb41a350b766238b3b103c22fe9fc0fb5chudy@google.com#endif  // CONTENT_COMMON_MEDIA_MEDIA_STREAM_OPTIONS_H_
1188a1cdaece7e1d009befb84f21bb82370025bf4d6robertphillips@google.com