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 #ifndef CONTENT_PUBLIC_COMMON_MEDIA_STREAM_REQUEST_H_
6 #define CONTENT_PUBLIC_COMMON_MEDIA_STREAM_REQUEST_H_
12 #include "base/basictypes.h"
13 #include "base/callback_forward.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "content/common/content_export.h"
20 // Types of media streams.
21 enum MediaStreamType {
24 // A device provided by the operating system (e.g., webcam input).
25 MEDIA_DEVICE_AUDIO_CAPTURE,
26 MEDIA_DEVICE_VIDEO_CAPTURE,
28 // Mirroring of a browser tab.
30 // TODO(serygeu): Remove these values and use MEDIA_DESKTOP_VIDEO_CAPTURE and
31 // MEDIA_DESKTOP_AUDIO_CAPTURE.
32 MEDIA_TAB_AUDIO_CAPTURE,
33 MEDIA_TAB_VIDEO_CAPTURE,
35 // Desktop media sources.
36 MEDIA_DESKTOP_VIDEO_CAPTURE,
38 // Capture system audio (post-mix loopback stream).
40 // TODO(sergeyu): Replace with MEDIA_DESKTOP_AUDIO_CAPTURE.
41 MEDIA_LOOPBACK_AUDIO_CAPTURE,
46 // Types of media stream requests that can be made to the media controller.
47 enum MediaStreamRequestType {
48 MEDIA_DEVICE_ACCESS = 0,
49 MEDIA_GENERATE_STREAM,
50 MEDIA_ENUMERATE_DEVICES,
54 // Facing mode for video capture.
55 enum VideoFacingMode {
56 MEDIA_VIDEO_FACING_NONE = 0,
57 MEDIA_VIDEO_FACING_USER,
58 MEDIA_VIDEO_FACING_ENVIRONMENT,
59 MEDIA_VIDEO_FACING_LEFT,
60 MEDIA_VIDEO_FACING_RIGHT,
62 NUM_MEDIA_VIDEO_FACING_MODE
65 // Convenience predicates to determine whether the given type represents some
66 // audio or some video device.
67 CONTENT_EXPORT bool IsAudioMediaType(MediaStreamType type);
68 CONTENT_EXPORT bool IsVideoMediaType(MediaStreamType type);
70 // TODO(xians): Change the structs to classes.
71 // Represents one device in a request for media stream(s).
72 struct CONTENT_EXPORT MediaStreamDevice {
77 const std::string& id,
78 const std::string& name);
82 const std::string& id,
83 const std::string& name,
86 int frames_per_buffer);
93 // The device's unique ID.
96 // The facing mode for video capture device.
97 VideoFacingMode video_facing;
99 // The device id of a matched output device if any (otherwise empty).
100 // Only applicable to audio devices.
101 std::string matched_output_device_id;
103 // The device's "friendly" name. Not guaranteed to be unique.
106 // Contains properties that match directly with those with the same name
107 // in media::AudioParameters.
108 struct AudioDeviceParameters {
109 AudioDeviceParameters()
110 : sample_rate(), channel_layout(), frames_per_buffer() {
113 AudioDeviceParameters(int sample_rate, int channel_layout,
114 int frames_per_buffer)
115 : sample_rate(sample_rate),
116 channel_layout(channel_layout),
117 frames_per_buffer(frames_per_buffer) {
120 // Preferred sample rate in samples per second for the device.
123 // Preferred channel configuration for the device.
124 // TODO(henrika): ideally, we would like to use media::ChannelLayout here
125 // but including media/base/channel_layout.h violates checkdeps rules.
128 // Preferred number of frames per buffer for the device. This is filled
129 // in on the browser side and can be used by the renderer to match the
130 // expected browser side settings and avoid unnecessary buffering.
131 // See media::AudioParameters for more.
132 int frames_per_buffer;
135 // These below two member variables are valid only when the type of device is
136 // audio (i.e. IsAudioMediaType returns true).
138 // Contains the device properties of the capture device.
139 AudioDeviceParameters input;
141 // If the capture device has an associated output device (e.g. headphones),
142 // this will contain the properties for the output device. If no such device
143 // exists (e.g. webcam w/mic), then the value of this member will be all
145 AudioDeviceParameters matched_output;
148 typedef std::vector<MediaStreamDevice> MediaStreamDevices;
150 typedef std::map<MediaStreamType, MediaStreamDevices> MediaStreamDeviceMap;
152 // Represents a request for media streams (audio/video).
153 // It looks like the last 4 parameters should use StreamOptions instead, but
154 // StreamOption depends on media_stream_request.h because it needs
155 // MediaStreamDevice.
156 // TODO(vrk): Decouple MediaStreamDevice from this header file so that
157 // media_stream_options.h no longer depends on this file.
158 // TODO(vrk,justinlin,wjia): Figure out a way to share this code cleanly between
159 // vanilla WebRTC, Tab Capture, and Pepper Video Capture. Right now there is
160 // Tab-only stuff and Pepper-only stuff being passed around to all clients,
162 struct CONTENT_EXPORT MediaStreamRequest {
164 int render_process_id,
167 const std::string& tab_capture_device_id,
168 const GURL& security_origin,
169 MediaStreamRequestType request_type,
170 const std::string& requested_audio_device_id,
171 const std::string& requested_video_device_id,
172 MediaStreamType audio_type,
173 MediaStreamType video_type);
175 ~MediaStreamRequest();
177 // This is the render process id for the renderer associated with generating
178 // frames for a MediaStream. Any indicators associated with a capture will be
179 // displayed for this renderer.
180 int render_process_id;
182 // This is the render view id for the renderer associated with generating
183 // frames for a MediaStream. Any indicators associated with a capture will be
184 // displayed for this renderer.
187 // The unique id combined with render_process_id and render_view_id for
188 // identifying this request. This is used for cancelling request.
191 // Used by tab capture.
192 std::string tab_capture_device_id;
194 // The WebKit security origin for the current request (e.g. "html5rocks.com").
195 GURL security_origin;
197 // Stores the type of request that was made to the media controller. Right now
198 // this is only used to distinguish between WebRTC and Pepper requests, as the
199 // latter should not be subject to user approval but only to policy check.
200 // Pepper requests are signified by the |MEDIA_OPEN_DEVICE| value.
201 MediaStreamRequestType request_type;
203 // Stores the requested raw device id for physical audio or video devices.
204 std::string requested_audio_device_id;
205 std::string requested_video_device_id;
207 // Flag to indicate if the request contains audio.
208 MediaStreamType audio_type;
210 // Flag to indicate if the request contains video.
211 MediaStreamType video_type;
214 // Interface used by the content layer to notify chrome about changes in the
215 // state of a media stream. Instances of this class are passed to content layer
216 // when MediaStream access is approved using MediaResponseCallback.
217 class MediaStreamUI {
219 virtual ~MediaStreamUI() {}
221 // Called when MediaStream capturing is started. Chrome layer can call |stop|
222 // to stop the stream.
223 virtual void OnStarted(const base::Closure& stop) = 0;
226 // Callback used return results of media access requests.
227 typedef base::Callback<void(
228 const MediaStreamDevices& devices,
229 scoped_ptr<MediaStreamUI> ui)> MediaResponseCallback;
231 } // namespace content
233 #endif // CONTENT_PUBLIC_COMMON_MEDIA_STREAM_REQUEST_H_