Chromium Code Reviews| 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 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/threading/non_thread_safe.h" | 17 #include "base/threading/non_thread_safe.h" |
| 18 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
| 19 #include "content/public/renderer/render_view_observer.h" | 19 #include "content/public/renderer/render_view_observer.h" |
| 20 #include "content/renderer/media/media_stream_client.h" | |
| 21 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" | 20 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" |
| 22 #include "content/renderer/media/media_stream_source.h" | 21 #include "content/renderer/media/media_stream_source.h" |
| 23 #include "third_party/WebKit/public/platform/WebMediaStream.h" | 22 #include "third_party/WebKit/public/platform/WebMediaStream.h" |
| 24 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | 23 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" |
| 25 #include "third_party/WebKit/public/platform/WebVector.h" | 24 #include "third_party/WebKit/public/platform/WebVector.h" |
| 26 #include "third_party/WebKit/public/web/WebUserMediaClient.h" | 25 #include "third_party/WebKit/public/web/WebUserMediaClient.h" |
| 27 #include "third_party/WebKit/public/web/WebUserMediaRequest.h" | 26 #include "third_party/WebKit/public/web/WebUserMediaRequest.h" |
| 28 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" | 27 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" |
| 29 | 28 |
| 30 namespace content { | 29 namespace content { |
| 31 class MediaStreamAudioRenderer; | |
| 32 class PeerConnectionDependencyFactory; | 30 class PeerConnectionDependencyFactory; |
| 33 class MediaStreamDispatcher; | 31 class MediaStreamDispatcher; |
| 34 class MediaStreamVideoSource; | 32 class MediaStreamVideoSource; |
| 35 class VideoCapturerDelegate; | 33 class VideoCapturerDelegate; |
| 36 class WebRtcAudioRenderer; | |
| 37 class WebRtcLocalAudioRenderer; | |
| 38 | 34 |
| 39 // MediaStreamImpl is a delegate for the Media Stream API messages used by | 35 // MediaStreamImpl is a delegate for the Media Stream GetUserMedia API. |
| 40 // WebKit. It ties together WebKit, native PeerConnection in libjingle and | 36 // It ties together WebKit and MediaStreamManager |
| 41 // MediaStreamManager (via MediaStreamDispatcher and MediaStreamDispatcherHost) | 37 // (via MediaStreamDispatcher and MediaStreamDispatcherHost) |
| 42 // in the browser process. It must be created, called and destroyed on the | 38 // in the browser process. It must be created, called and destroyed on the |
| 43 // render thread. | 39 // render thread. |
| 44 // MediaStreamImpl have weak pointers to a MediaStreamDispatcher. | 40 // MediaStreamImpl have weak pointers to a MediaStreamDispatcher. |
| 45 class CONTENT_EXPORT MediaStreamImpl | 41 class CONTENT_EXPORT MediaStreamImpl |
| 46 : public RenderViewObserver, | 42 : public RenderViewObserver, |
| 47 NON_EXPORTED_BASE(public blink::WebUserMediaClient), | 43 NON_EXPORTED_BASE(public blink::WebUserMediaClient), |
| 48 NON_EXPORTED_BASE(public MediaStreamClient), | |
| 49 public MediaStreamDispatcherEventHandler, | 44 public MediaStreamDispatcherEventHandler, |
| 50 public base::SupportsWeakPtr<MediaStreamImpl>, | 45 public base::SupportsWeakPtr<MediaStreamImpl>, |
| 51 NON_EXPORTED_BASE(public base::NonThreadSafe) { | 46 NON_EXPORTED_BASE(public base::NonThreadSafe) { |
| 52 public: | 47 public: |
| 53 MediaStreamImpl( | 48 MediaStreamImpl( |
| 54 RenderView* render_view, | 49 RenderView* render_view, |
| 55 MediaStreamDispatcher* media_stream_dispatcher, | 50 MediaStreamDispatcher* media_stream_dispatcher, |
| 56 PeerConnectionDependencyFactory* dependency_factory); | 51 PeerConnectionDependencyFactory* dependency_factory); |
| 57 virtual ~MediaStreamImpl(); | 52 virtual ~MediaStreamImpl(); |
| 58 | 53 |
| 59 // blink::WebUserMediaClient implementation | 54 // blink::WebUserMediaClient implementation |
| 60 virtual void requestUserMedia( | 55 virtual void requestUserMedia( |
| 61 const blink::WebUserMediaRequest& user_media_request) OVERRIDE; | 56 const blink::WebUserMediaRequest& user_media_request) OVERRIDE; |
|
jochen (gone - plz use gerrit)
2014/05/27 07:26:33
we shouldn't use OVERRIDE on implementations of th
perkj_chrome
2014/05/27 11:04:21
Done.
| |
| 62 virtual void cancelUserMediaRequest( | 57 virtual void cancelUserMediaRequest( |
| 63 const blink::WebUserMediaRequest& user_media_request) OVERRIDE; | 58 const blink::WebUserMediaRequest& user_media_request) OVERRIDE; |
| 64 | 59 |
| 65 // MediaStreamClient implementation. | |
| 66 virtual bool IsMediaStream(const GURL& url) OVERRIDE; | |
| 67 virtual scoped_refptr<VideoFrameProvider> GetVideoFrameProvider( | |
| 68 const GURL& url, | |
| 69 const base::Closure& error_cb, | |
| 70 const VideoFrameProvider::RepaintCB& repaint_cb) OVERRIDE; | |
| 71 virtual scoped_refptr<MediaStreamAudioRenderer> | |
| 72 GetAudioRenderer(const GURL& url, int render_frame_id) OVERRIDE; | |
| 73 | |
| 74 // MediaStreamDispatcherEventHandler implementation. | 60 // MediaStreamDispatcherEventHandler implementation. |
| 75 virtual void OnStreamGenerated( | 61 virtual void OnStreamGenerated( |
| 76 int request_id, | 62 int request_id, |
| 77 const std::string& label, | 63 const std::string& label, |
| 78 const StreamDeviceInfoArray& audio_array, | 64 const StreamDeviceInfoArray& audio_array, |
| 79 const StreamDeviceInfoArray& video_array) OVERRIDE; | 65 const StreamDeviceInfoArray& video_array) OVERRIDE; |
| 80 virtual void OnStreamGenerationFailed( | 66 virtual void OnStreamGenerationFailed( |
| 81 int request_id, | 67 int request_id, |
| 82 content::MediaStreamRequestResult result) OVERRIDE; | 68 content::MediaStreamRequestResult result) OVERRIDE; |
| 83 virtual void OnDeviceStopped(const std::string& label, | 69 virtual void OnDeviceStopped(const std::string& label, |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 102 // These methods are virtual for test purposes. A test can override them to | 88 // These methods are virtual for test purposes. A test can override them to |
| 103 // test requesting local media streams. The function notifies WebKit that the | 89 // test requesting local media streams. The function notifies WebKit that the |
| 104 // |request| have completed. | 90 // |request| have completed. |
| 105 virtual void GetUserMediaRequestSucceeded( | 91 virtual void GetUserMediaRequestSucceeded( |
| 106 const blink::WebMediaStream& stream, | 92 const blink::WebMediaStream& stream, |
| 107 blink::WebUserMediaRequest* request_info); | 93 blink::WebUserMediaRequest* request_info); |
| 108 virtual void GetUserMediaRequestFailed( | 94 virtual void GetUserMediaRequestFailed( |
| 109 blink::WebUserMediaRequest* request_info, | 95 blink::WebUserMediaRequest* request_info, |
| 110 content::MediaStreamRequestResult result); | 96 content::MediaStreamRequestResult result); |
| 111 | 97 |
| 112 | |
| 113 // Returns the WebKit representation of a MediaStream given an URL. | |
| 114 // This is virtual for test purposes. | |
| 115 virtual blink::WebMediaStream GetMediaStream(const GURL& url); | |
| 116 | |
| 117 // Creates a MediaStreamVideoSource object. | 98 // Creates a MediaStreamVideoSource object. |
| 118 // This is virtual for test purposes. | 99 // This is virtual for test purposes. |
| 119 virtual MediaStreamVideoSource* CreateVideoSource( | 100 virtual MediaStreamVideoSource* CreateVideoSource( |
| 120 const StreamDeviceInfo& device, | 101 const StreamDeviceInfo& device, |
| 121 const MediaStreamSource::SourceStoppedCallback& stop_callback); | 102 const MediaStreamSource::SourceStoppedCallback& stop_callback); |
| 122 | 103 |
| 123 private: | 104 private: |
| 124 // Class for storing information about a WebKit request to create a | 105 // Class for storing information about a WebKit request to create a |
| 125 // MediaStream. | 106 // MediaStream. |
| 126 class UserMediaRequestInfo | 107 class UserMediaRequestInfo |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 void DeleteUserMediaRequestInfo(UserMediaRequestInfo* request); | 198 void DeleteUserMediaRequestInfo(UserMediaRequestInfo* request); |
| 218 | 199 |
| 219 // Returns the source that use a device with |device.session_id| | 200 // Returns the source that use a device with |device.session_id| |
| 220 // and |device.device.id|. NULL if such source doesn't exist. | 201 // and |device.device.id|. NULL if such source doesn't exist. |
| 221 const blink::WebMediaStreamSource* FindLocalSource( | 202 const blink::WebMediaStreamSource* FindLocalSource( |
| 222 const StreamDeviceInfo& device) const; | 203 const StreamDeviceInfo& device) const; |
| 223 | 204 |
| 224 void StopLocalSource(const blink::WebMediaStreamSource& source, | 205 void StopLocalSource(const blink::WebMediaStreamSource& source, |
| 225 bool notify_dispatcher); | 206 bool notify_dispatcher); |
| 226 | 207 |
| 227 scoped_refptr<WebRtcAudioRenderer> CreateRemoteAudioRenderer( | |
| 228 webrtc::MediaStreamInterface* stream, int render_frame_id); | |
| 229 scoped_refptr<WebRtcLocalAudioRenderer> CreateLocalAudioRenderer( | |
| 230 const blink::WebMediaStreamTrack& audio_track, | |
| 231 int render_frame_id); | |
| 232 | |
| 233 // Returns a valid session id if a single capture device is currently open | |
| 234 // (and then the matching session_id), otherwise -1. | |
| 235 // This is used to pass on a session id to a webrtc audio renderer (either | |
| 236 // local or remote), so that audio will be rendered to a matching output | |
| 237 // device, should one exist. | |
| 238 // Note that if there are more than one open capture devices the function | |
| 239 // will not be able to pick an appropriate device and return false. | |
| 240 bool GetAuthorizedDeviceInfoForAudioRenderer( | |
| 241 int* session_id, int* output_sample_rate, int* output_buffer_size); | |
| 242 | |
| 243 // Weak ref to a PeerConnectionDependencyFactory, owned by the RenderThread. | 208 // Weak ref to a PeerConnectionDependencyFactory, owned by the RenderThread. |
| 244 // It's valid for the lifetime of RenderThread. | 209 // It's valid for the lifetime of RenderThread. |
| 245 // TODO(xians): Remove this dependency once audio do not need it for local | 210 // TODO(xians): Remove this dependency once audio do not need it for local |
| 246 // audio. | 211 // audio. |
| 247 PeerConnectionDependencyFactory* dependency_factory_; | 212 PeerConnectionDependencyFactory* dependency_factory_; |
| 248 | 213 |
| 249 // media_stream_dispatcher_ is a weak reference, owned by RenderView. It's | 214 // media_stream_dispatcher_ is a weak reference, owned by RenderView. It's |
| 250 // valid for the lifetime of RenderView. | 215 // valid for the lifetime of RenderView. |
| 251 MediaStreamDispatcher* media_stream_dispatcher_; | 216 MediaStreamDispatcher* media_stream_dispatcher_; |
| 252 | 217 |
| 253 LocalStreamSources local_sources_; | 218 LocalStreamSources local_sources_; |
| 254 | 219 |
| 255 UserMediaRequests user_media_requests_; | 220 UserMediaRequests user_media_requests_; |
| 256 | 221 |
| 257 DISALLOW_COPY_AND_ASSIGN(MediaStreamImpl); | 222 DISALLOW_COPY_AND_ASSIGN(MediaStreamImpl); |
| 258 }; | 223 }; |
| 259 | 224 |
| 260 } // namespace content | 225 } // namespace content |
| 261 | 226 |
| 262 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_IMPL_H_ | 227 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_IMPL_H_ |
| OLD | NEW |