Home | History | Annotate | Download | only in common
      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_PUBLIC_COMMON_MEDIA_STREAM_REQUEST_H_
      6 #define CONTENT_PUBLIC_COMMON_MEDIA_STREAM_REQUEST_H_
      7 
      8 #include <map>
      9 #include <string>
     10 #include <vector>
     11 
     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"
     16 #include "url/gurl.h"
     17 
     18 namespace content {
     19 
     20 // Types of media streams.
     21 enum MediaStreamType {
     22   MEDIA_NO_SERVICE = 0,
     23 
     24   // A device provided by the operating system (e.g., webcam input).
     25   MEDIA_DEVICE_AUDIO_CAPTURE,
     26   MEDIA_DEVICE_VIDEO_CAPTURE,
     27 
     28   // Mirroring of a browser tab.
     29   //
     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,
     34 
     35   // Desktop media sources.
     36   MEDIA_DESKTOP_VIDEO_CAPTURE,
     37 
     38   // Capture system audio (post-mix loopback stream).
     39   //
     40   // TODO(sergeyu): Replace with MEDIA_DESKTOP_AUDIO_CAPTURE.
     41   MEDIA_SYSTEM_AUDIO_CAPTURE,
     42 
     43   NUM_MEDIA_TYPES
     44 };
     45 
     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,
     51   MEDIA_OPEN_DEVICE
     52 };
     53 
     54 // Convenience predicates to determine whether the given type represents some
     55 // audio or some video device.
     56 CONTENT_EXPORT bool IsAudioMediaType(MediaStreamType type);
     57 CONTENT_EXPORT bool IsVideoMediaType(MediaStreamType type);
     58 
     59 // TODO(xians): Change the structs to classes.
     60 // Represents one device in a request for media stream(s).
     61 struct CONTENT_EXPORT MediaStreamDevice {
     62   MediaStreamDevice();
     63 
     64   MediaStreamDevice(
     65       MediaStreamType type,
     66       const std::string& id,
     67       const std::string& name);
     68 
     69   MediaStreamDevice(
     70       MediaStreamType type,
     71       const std::string& id,
     72       const std::string& name,
     73       int sample_rate,
     74       int channel_layout);
     75 
     76   ~MediaStreamDevice();
     77 
     78   // The device's type.
     79   MediaStreamType type;
     80 
     81   // The device's unique ID.
     82   std::string id;
     83 
     84   // The device's "friendly" name. Not guaranteed to be unique.
     85   std::string name;
     86 
     87   // Preferred sample rate in samples per second for the device.
     88   // Only utilized for audio devices. Will be set to 0 if the constructor
     89   // with three parameters (intended for video) is used.
     90   int sample_rate;
     91 
     92   // Preferred channel configuration for the device.
     93   // Only utilized for audio devices. Will be set to 0 if the constructor
     94   // with three parameters (intended for video) is used.
     95   // TODO(henrika): ideally, we would like to use media::ChannelLayout here
     96   // but including media/base/channel_layout.h violates checkdeps rules.
     97   int channel_layout;
     98 };
     99 
    100 typedef std::vector<MediaStreamDevice> MediaStreamDevices;
    101 
    102 typedef std::map<MediaStreamType, MediaStreamDevices> MediaStreamDeviceMap;
    103 
    104 // Represents a request for media streams (audio/video).
    105 // It looks like the last 4 parameters should use StreamOptions instead, but
    106 // StreamOption depends on media_stream_request.h because it needs
    107 // MediaStreamDevice.
    108 // TODO(vrk): Decouple MediaStreamDevice from this header file so that
    109 // media_stream_options.h no longer depends on this file.
    110 // TODO(vrk,justinlin,wjia): Figure out a way to share this code cleanly between
    111 // vanilla WebRTC, Tab Capture, and Pepper Video Capture. Right now there is
    112 // Tab-only stuff and Pepper-only stuff being passed around to all clients,
    113 // which is icky.
    114 struct CONTENT_EXPORT MediaStreamRequest {
    115   MediaStreamRequest(
    116       int render_process_id,
    117       int render_view_id,
    118       int page_request_id,
    119       const std::string& tab_capture_device_id,
    120       const GURL& security_origin,
    121       MediaStreamRequestType request_type,
    122       const std::string& requested_audio_device_id,
    123       const std::string& requested_video_device_id,
    124       MediaStreamType audio_type,
    125       MediaStreamType video_type);
    126 
    127   ~MediaStreamRequest();
    128 
    129   // The render process id generating this request.
    130   int render_process_id;
    131 
    132   // The render view id generating this request.
    133   int render_view_id;
    134 
    135   // The unique id combined with render_process_id and render_view_id for
    136   // identifying this request. This is used for cancelling request.
    137   int page_request_id;
    138 
    139   // Used by tab capture.
    140   std::string tab_capture_device_id;
    141 
    142   // The WebKit security origin for the current request (e.g. "html5rocks.com").
    143   GURL security_origin;
    144 
    145   // Stores the type of request that was made to the media controller. Right now
    146   // this is only used to distinguish between WebRTC and Pepper requests, as the
    147   // latter should not be subject to user approval but only to policy check.
    148   // Pepper requests are signified by the |MEDIA_OPEN_DEVICE| value.
    149   MediaStreamRequestType request_type;
    150 
    151   // Stores the requested raw device id for physical audio or video devices.
    152   std::string requested_audio_device_id;
    153   std::string requested_video_device_id;
    154 
    155   // Flag to indicate if the request contains audio.
    156   MediaStreamType audio_type;
    157 
    158   // Flag to indicate if the request contains video.
    159   MediaStreamType video_type;
    160 };
    161 
    162 // Interface used by the content layer to notify chrome about changes in the
    163 // state of a media stream. Instances of this class are passed to content layer
    164 // when MediaStream access is approved using MediaResponseCallback.
    165 class MediaStreamUI {
    166  public:
    167   virtual ~MediaStreamUI() {}
    168 
    169   // Called when MediaStream capturing is started. Chrome layer can call |stop|
    170   // to stop the stream.
    171   virtual void OnStarted(const base::Closure& stop) = 0;
    172 };
    173 
    174 // Callback used return results of media access requests.
    175 typedef base::Callback<void(
    176     const MediaStreamDevices& devices,
    177     scoped_ptr<MediaStreamUI> ui)> MediaResponseCallback;
    178 
    179 }  // namespace content
    180 
    181 #endif  // CONTENT_PUBLIC_COMMON_MEDIA_STREAM_REQUEST_H_
    182