| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_IMPL_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_IMPL_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_IMPL_H_ | 6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_IMPL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 class WebRtcLocalAudioRenderer; | 35 class WebRtcLocalAudioRenderer; |
| 36 | 36 |
| 37 // MediaStreamImpl is a delegate for the Media Stream API messages used by | 37 // MediaStreamImpl is a delegate for the Media Stream API messages used by |
| 38 // WebKit. It ties together WebKit, native PeerConnection in libjingle and | 38 // WebKit. It ties together WebKit, native PeerConnection in libjingle and |
| 39 // MediaStreamManager (via MediaStreamDispatcher and MediaStreamDispatcherHost) | 39 // MediaStreamManager (via MediaStreamDispatcher and MediaStreamDispatcherHost) |
| 40 // in the browser process. It must be created, called and destroyed on the | 40 // in the browser process. It must be created, called and destroyed on the |
| 41 // render thread. | 41 // render thread. |
| 42 // MediaStreamImpl have weak pointers to a MediaStreamDispatcher. | 42 // MediaStreamImpl have weak pointers to a MediaStreamDispatcher. |
| 43 class CONTENT_EXPORT MediaStreamImpl | 43 class CONTENT_EXPORT MediaStreamImpl |
| 44 : public RenderViewObserver, | 44 : public RenderViewObserver, |
| 45 NON_EXPORTED_BASE(public WebKit::WebUserMediaClient), | 45 NON_EXPORTED_BASE(public blink::WebUserMediaClient), |
| 46 NON_EXPORTED_BASE(public MediaStreamClient), | 46 NON_EXPORTED_BASE(public MediaStreamClient), |
| 47 public MediaStreamDispatcherEventHandler, | 47 public MediaStreamDispatcherEventHandler, |
| 48 public base::SupportsWeakPtr<MediaStreamImpl>, | 48 public base::SupportsWeakPtr<MediaStreamImpl>, |
| 49 NON_EXPORTED_BASE(public base::NonThreadSafe) { | 49 NON_EXPORTED_BASE(public base::NonThreadSafe) { |
| 50 public: | 50 public: |
| 51 MediaStreamImpl( | 51 MediaStreamImpl( |
| 52 RenderView* render_view, | 52 RenderView* render_view, |
| 53 MediaStreamDispatcher* media_stream_dispatcher, | 53 MediaStreamDispatcher* media_stream_dispatcher, |
| 54 MediaStreamDependencyFactory* dependency_factory); | 54 MediaStreamDependencyFactory* dependency_factory); |
| 55 virtual ~MediaStreamImpl(); | 55 virtual ~MediaStreamImpl(); |
| 56 | 56 |
| 57 // WebKit::WebUserMediaClient implementation | 57 // blink::WebUserMediaClient implementation |
| 58 virtual void requestUserMedia( | 58 virtual void requestUserMedia( |
| 59 const WebKit::WebUserMediaRequest& user_media_request) OVERRIDE; | 59 const blink::WebUserMediaRequest& user_media_request) OVERRIDE; |
| 60 virtual void cancelUserMediaRequest( | 60 virtual void cancelUserMediaRequest( |
| 61 const WebKit::WebUserMediaRequest& user_media_request) OVERRIDE; | 61 const blink::WebUserMediaRequest& user_media_request) OVERRIDE; |
| 62 | 62 |
| 63 // MediaStreamClient implementation. | 63 // MediaStreamClient implementation. |
| 64 virtual bool IsMediaStream(const GURL& url) OVERRIDE; | 64 virtual bool IsMediaStream(const GURL& url) OVERRIDE; |
| 65 virtual scoped_refptr<VideoFrameProvider> GetVideoFrameProvider( | 65 virtual scoped_refptr<VideoFrameProvider> GetVideoFrameProvider( |
| 66 const GURL& url, | 66 const GURL& url, |
| 67 const base::Closure& error_cb, | 67 const base::Closure& error_cb, |
| 68 const VideoFrameProvider::RepaintCB& repaint_cb) OVERRIDE; | 68 const VideoFrameProvider::RepaintCB& repaint_cb) OVERRIDE; |
| 69 virtual scoped_refptr<MediaStreamAudioRenderer> | 69 virtual scoped_refptr<MediaStreamAudioRenderer> |
| 70 GetAudioRenderer(const GURL& url) OVERRIDE; | 70 GetAudioRenderer(const GURL& url) OVERRIDE; |
| 71 | 71 |
| 72 // MediaStreamDispatcherEventHandler implementation. | 72 // MediaStreamDispatcherEventHandler implementation. |
| 73 virtual void OnStreamGenerated( | 73 virtual void OnStreamGenerated( |
| 74 int request_id, | 74 int request_id, |
| 75 const std::string& label, | 75 const std::string& label, |
| 76 const StreamDeviceInfoArray& audio_array, | 76 const StreamDeviceInfoArray& audio_array, |
| 77 const StreamDeviceInfoArray& video_array) OVERRIDE; | 77 const StreamDeviceInfoArray& video_array) OVERRIDE; |
| 78 virtual void OnStreamGenerationFailed(int request_id) OVERRIDE; | 78 virtual void OnStreamGenerationFailed(int request_id) OVERRIDE; |
| 79 virtual void OnStopGeneratedStream(const std::string& label) OVERRIDE; | 79 virtual void OnStopGeneratedStream(const std::string& label) OVERRIDE; |
| 80 virtual void OnDevicesEnumerated( | 80 virtual void OnDevicesEnumerated( |
| 81 int request_id, | 81 int request_id, |
| 82 const StreamDeviceInfoArray& device_array) OVERRIDE; | 82 const StreamDeviceInfoArray& device_array) OVERRIDE; |
| 83 virtual void OnDevicesEnumerationFailed(int request_id) OVERRIDE; | 83 virtual void OnDevicesEnumerationFailed(int request_id) OVERRIDE; |
| 84 virtual void OnDeviceOpened( | 84 virtual void OnDeviceOpened( |
| 85 int request_id, | 85 int request_id, |
| 86 const std::string& label, | 86 const std::string& label, |
| 87 const StreamDeviceInfo& device_info) OVERRIDE; | 87 const StreamDeviceInfo& device_info) OVERRIDE; |
| 88 virtual void OnDeviceOpenFailed(int request_id) OVERRIDE; | 88 virtual void OnDeviceOpenFailed(int request_id) OVERRIDE; |
| 89 | 89 |
| 90 // RenderViewObserver OVERRIDE | 90 // RenderViewObserver OVERRIDE |
| 91 virtual void FrameDetached(WebKit::WebFrame* frame) OVERRIDE; | 91 virtual void FrameDetached(blink::WebFrame* frame) OVERRIDE; |
| 92 virtual void FrameWillClose(WebKit::WebFrame* frame) OVERRIDE; | 92 virtual void FrameWillClose(blink::WebFrame* frame) OVERRIDE; |
| 93 | 93 |
| 94 protected: | 94 protected: |
| 95 void OnLocalSourceStop(const WebKit::WebMediaStreamSource& source); | 95 void OnLocalSourceStop(const blink::WebMediaStreamSource& source); |
| 96 | 96 |
| 97 void OnLocalMediaStreamStop(const std::string& label); | 97 void OnLocalMediaStreamStop(const std::string& label); |
| 98 | 98 |
| 99 // Callback function triggered when all native (libjingle) versions of the | 99 // Callback function triggered when all native (libjingle) versions of the |
| 100 // underlying media sources have been created and started. | 100 // underlying media sources have been created and started. |
| 101 // |web_stream| is a raw pointer to the web_stream in | 101 // |web_stream| is a raw pointer to the web_stream in |
| 102 // UserMediaRequests::web_stream for which the underlying sources have been | 102 // UserMediaRequests::web_stream for which the underlying sources have been |
| 103 // created. | 103 // created. |
| 104 void OnCreateNativeSourcesComplete( | 104 void OnCreateNativeSourcesComplete( |
| 105 WebKit::WebMediaStream* web_stream, | 105 blink::WebMediaStream* web_stream, |
| 106 bool request_succeeded); | 106 bool request_succeeded); |
| 107 | 107 |
| 108 // This function is virtual for test purposes. A test can override this to | 108 // This function is virtual for test purposes. A test can override this to |
| 109 // test requesting local media streams. The function notifies WebKit that the | 109 // test requesting local media streams. The function notifies WebKit that the |
| 110 // |request| have completed and generated the MediaStream |stream|. | 110 // |request| have completed and generated the MediaStream |stream|. |
| 111 virtual void CompleteGetUserMediaRequest( | 111 virtual void CompleteGetUserMediaRequest( |
| 112 const WebKit::WebMediaStream& stream, | 112 const blink::WebMediaStream& stream, |
| 113 WebKit::WebUserMediaRequest* request_info, | 113 blink::WebUserMediaRequest* request_info, |
| 114 bool request_succeeded); | 114 bool request_succeeded); |
| 115 | 115 |
| 116 // Returns the WebKit representation of a MediaStream given an URL. | 116 // Returns the WebKit representation of a MediaStream given an URL. |
| 117 // This is virtual for test purposes. | 117 // This is virtual for test purposes. |
| 118 virtual WebKit::WebMediaStream GetMediaStream(const GURL& url); | 118 virtual blink::WebMediaStream GetMediaStream(const GURL& url); |
| 119 | 119 |
| 120 private: | 120 private: |
| 121 // Structure for storing information about a WebKit request to create a | 121 // Structure for storing information about a WebKit request to create a |
| 122 // MediaStream. | 122 // MediaStream. |
| 123 struct UserMediaRequestInfo { | 123 struct UserMediaRequestInfo { |
| 124 UserMediaRequestInfo(int request_id, | 124 UserMediaRequestInfo(int request_id, |
| 125 WebKit::WebFrame* frame, | 125 blink::WebFrame* frame, |
| 126 const WebKit::WebUserMediaRequest& request, | 126 const blink::WebUserMediaRequest& request, |
| 127 bool enable_automatic_output_device_selection); | 127 bool enable_automatic_output_device_selection); |
| 128 ~UserMediaRequestInfo(); | 128 ~UserMediaRequestInfo(); |
| 129 int request_id; | 129 int request_id; |
| 130 // True if MediaStreamDispatcher has generated the stream, see | 130 // True if MediaStreamDispatcher has generated the stream, see |
| 131 // OnStreamGenerated. | 131 // OnStreamGenerated. |
| 132 bool generated; | 132 bool generated; |
| 133 const bool enable_automatic_output_device_selection; | 133 const bool enable_automatic_output_device_selection; |
| 134 WebKit::WebFrame* frame; // WebFrame that requested the MediaStream. | 134 blink::WebFrame* frame; // WebFrame that requested the MediaStream. |
| 135 WebKit::WebMediaStream web_stream; | 135 blink::WebMediaStream web_stream; |
| 136 WebKit::WebUserMediaRequest request; | 136 blink::WebUserMediaRequest request; |
| 137 std::vector<WebKit::WebMediaStreamSource> sources; | 137 std::vector<blink::WebMediaStreamSource> sources; |
| 138 }; | 138 }; |
| 139 typedef ScopedVector<UserMediaRequestInfo> UserMediaRequests; | 139 typedef ScopedVector<UserMediaRequestInfo> UserMediaRequests; |
| 140 | 140 |
| 141 struct LocalStreamSource { | 141 struct LocalStreamSource { |
| 142 LocalStreamSource(WebKit::WebFrame* frame, | 142 LocalStreamSource(blink::WebFrame* frame, |
| 143 const WebKit::WebMediaStreamSource& source) | 143 const blink::WebMediaStreamSource& source) |
| 144 : frame(frame), source(source) { | 144 : frame(frame), source(source) { |
| 145 } | 145 } |
| 146 // |frame| is the WebFrame that requested |source|. NULL in unit tests. | 146 // |frame| is the WebFrame that requested |source|. NULL in unit tests. |
| 147 // TODO(perkj): Change so that |frame| is not NULL in unit tests. | 147 // TODO(perkj): Change so that |frame| is not NULL in unit tests. |
| 148 WebKit::WebFrame* frame; | 148 blink::WebFrame* frame; |
| 149 WebKit::WebMediaStreamSource source; | 149 blink::WebMediaStreamSource source; |
| 150 }; | 150 }; |
| 151 typedef std::vector<LocalStreamSource> LocalStreamSources; | 151 typedef std::vector<LocalStreamSource> LocalStreamSources; |
| 152 | 152 |
| 153 // Creates a WebKit representation of stream sources based on | 153 // Creates a WebKit representation of stream sources based on |
| 154 // |devices| from the MediaStreamDispatcher. | 154 // |devices| from the MediaStreamDispatcher. |
| 155 void CreateWebKitSourceVector( | 155 void CreateWebKitSourceVector( |
| 156 const std::string& label, | 156 const std::string& label, |
| 157 const StreamDeviceInfoArray& devices, | 157 const StreamDeviceInfoArray& devices, |
| 158 WebKit::WebMediaStreamSource::Type type, | 158 blink::WebMediaStreamSource::Type type, |
| 159 WebKit::WebFrame* frame, | 159 blink::WebFrame* frame, |
| 160 WebKit::WebVector<WebKit::WebMediaStreamSource>& webkit_sources); | 160 blink::WebVector<blink::WebMediaStreamSource>& webkit_sources); |
| 161 | 161 |
| 162 UserMediaRequestInfo* FindUserMediaRequestInfo(int request_id); | 162 UserMediaRequestInfo* FindUserMediaRequestInfo(int request_id); |
| 163 UserMediaRequestInfo* FindUserMediaRequestInfo( | 163 UserMediaRequestInfo* FindUserMediaRequestInfo( |
| 164 WebKit::WebMediaStream* web_stream); | 164 blink::WebMediaStream* web_stream); |
| 165 UserMediaRequestInfo* FindUserMediaRequestInfo( | 165 UserMediaRequestInfo* FindUserMediaRequestInfo( |
| 166 const WebKit::WebUserMediaRequest& request); | 166 const blink::WebUserMediaRequest& request); |
| 167 UserMediaRequestInfo* FindUserMediaRequestInfo(const std::string& label); | 167 UserMediaRequestInfo* FindUserMediaRequestInfo(const std::string& label); |
| 168 void DeleteUserMediaRequestInfo(UserMediaRequestInfo* request); | 168 void DeleteUserMediaRequestInfo(UserMediaRequestInfo* request); |
| 169 | 169 |
| 170 // Returns the source that use a device with |device.session_id| | 170 // Returns the source that use a device with |device.session_id| |
| 171 // and |device.device.id|. NULL if such source doesn't exist. | 171 // and |device.device.id|. NULL if such source doesn't exist. |
| 172 const WebKit::WebMediaStreamSource* FindLocalSource( | 172 const blink::WebMediaStreamSource* FindLocalSource( |
| 173 const StreamDeviceInfo& device) const; | 173 const StreamDeviceInfo& device) const; |
| 174 | 174 |
| 175 // Returns true if |source| exists in |user_media_requests_| | 175 // Returns true if |source| exists in |user_media_requests_| |
| 176 bool FindSourceInRequests(const WebKit::WebMediaStreamSource& source) const; | 176 bool FindSourceInRequests(const blink::WebMediaStreamSource& source) const; |
| 177 | 177 |
| 178 void StopLocalSource(const WebKit::WebMediaStreamSource& source, | 178 void StopLocalSource(const blink::WebMediaStreamSource& source, |
| 179 bool notify_dispatcher); | 179 bool notify_dispatcher); |
| 180 // Stops all local sources that don't exist in exist in | 180 // Stops all local sources that don't exist in exist in |
| 181 // |user_media_requests_|. | 181 // |user_media_requests_|. |
| 182 void StopUnreferencedSources(bool notify_dispatcher); | 182 void StopUnreferencedSources(bool notify_dispatcher); |
| 183 | 183 |
| 184 scoped_refptr<VideoFrameProvider> | 184 scoped_refptr<VideoFrameProvider> |
| 185 CreateVideoFrameProvider( | 185 CreateVideoFrameProvider( |
| 186 webrtc::MediaStreamInterface* stream, | 186 webrtc::MediaStreamInterface* stream, |
| 187 const base::Closure& error_cb, | 187 const base::Closure& error_cb, |
| 188 const VideoFrameProvider::RepaintCB& repaint_cb); | 188 const VideoFrameProvider::RepaintCB& repaint_cb); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 212 UserMediaRequests user_media_requests_; | 212 UserMediaRequests user_media_requests_; |
| 213 | 213 |
| 214 LocalStreamSources local_sources_; | 214 LocalStreamSources local_sources_; |
| 215 | 215 |
| 216 DISALLOW_COPY_AND_ASSIGN(MediaStreamImpl); | 216 DISALLOW_COPY_AND_ASSIGN(MediaStreamImpl); |
| 217 }; | 217 }; |
| 218 | 218 |
| 219 } // namespace content | 219 } // namespace content |
| 220 | 220 |
| 221 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_IMPL_H_ | 221 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_IMPL_H_ |
| OLD | NEW |