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 <list> | 8 #include <list> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/message_loop_proxy.h" | 17 #include "base/message_loop_proxy.h" |
| 18 #include "base/threading/non_thread_safe.h" | 18 #include "base/threading/non_thread_safe.h" |
| 19 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
| 20 #include "content/common/content_export.h" | 20 #include "content/common/content_export.h" |
| 21 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" | 21 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" |
| 22 #include "third_party/libjingle/source/talk/app/webrtc/mediastream.h" | |
| 23 #include "third_party/libjingle/source/talk/base/scoped_ref_ptr.h" | |
| 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaClient.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaClient.h" |
| 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaRequest.h " | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaRequest.h " |
| 24 #include "webkit/media/media_stream_client.h" | 26 #include "webkit/media/media_stream_client.h" |
| 25 | 27 |
| 26 namespace base { | 28 namespace base { |
| 27 class WaitableEvent; | 29 class WaitableEvent; |
| 28 } | 30 } |
| 29 | 31 |
| 30 namespace content { | 32 namespace content { |
| 31 class IpcNetworkManager; | 33 class IpcNetworkManager; |
| 32 class IpcPacketSocketFactory; | 34 class IpcPacketSocketFactory; |
| 33 class P2PSocketDispatcher; | 35 class P2PSocketDispatcher; |
| 34 } | 36 } |
| 35 | 37 |
| 36 namespace cricket { | |
| 37 class WebRtcMediaEngine; | |
| 38 } | |
| 39 | |
| 40 namespace talk_base { | 38 namespace talk_base { |
| 41 class Thread; | 39 class Thread; |
| 42 } | 40 } |
| 43 | 41 |
| 44 namespace WebKit { | 42 namespace WebKit { |
| 45 class WebPeerConnectionHandler; | 43 class WebPeerConnectionHandler; |
| 46 class WebPeerConnectionHandlerClient; | 44 class WebPeerConnectionHandlerClient; |
| 47 } | 45 } |
| 48 | 46 |
| 49 class MediaStreamDispatcher; | 47 class MediaStreamDispatcher; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 67 MediaStreamImpl( | 65 MediaStreamImpl( |
| 68 MediaStreamDispatcher* media_stream_dispatcher, | 66 MediaStreamDispatcher* media_stream_dispatcher, |
| 69 content::P2PSocketDispatcher* p2p_socket_dispatcher, | 67 content::P2PSocketDispatcher* p2p_socket_dispatcher, |
| 70 VideoCaptureImplManager* vc_manager, | 68 VideoCaptureImplManager* vc_manager, |
| 71 MediaStreamDependencyFactory* dependency_factory); | 69 MediaStreamDependencyFactory* dependency_factory); |
| 72 virtual ~MediaStreamImpl(); | 70 virtual ~MediaStreamImpl(); |
| 73 | 71 |
| 74 virtual WebKit::WebPeerConnectionHandler* CreatePeerConnectionHandler( | 72 virtual WebKit::WebPeerConnectionHandler* CreatePeerConnectionHandler( |
| 75 WebKit::WebPeerConnectionHandlerClient* client); | 73 WebKit::WebPeerConnectionHandlerClient* client); |
| 76 virtual void ClosePeerConnection(); | 74 virtual void ClosePeerConnection(); |
| 77 | 75 virtual webrtc::MediaStreamTrackInterface* GetLocalMediaStreamTrack( |
| 78 // Returns true if created successfully or already exists, false otherwise. | 76 std::string label); |
|
tommi (sloooow) - chröme
2012/01/24 15:18:56
is this supposed to be by value and not by referen
Henrik Grunell
2012/01/26 13:03:16
No it's a miss. Changed to const ref.
| |
| 79 virtual bool SetVideoCaptureModule(const std::string& label); | |
| 80 | 77 |
| 81 // WebKit::WebUserMediaClient implementation | 78 // WebKit::WebUserMediaClient implementation |
| 82 virtual void requestUserMedia( | 79 virtual void requestUserMedia( |
| 83 const WebKit::WebUserMediaRequest& user_media_request, | 80 const WebKit::WebUserMediaRequest& user_media_request, |
| 84 const WebKit::WebVector<WebKit::WebMediaStreamSource>& | 81 const WebKit::WebVector<WebKit::WebMediaStreamSource>& |
| 85 media_stream_source_vector) OVERRIDE; | 82 media_stream_source_vector) OVERRIDE; |
| 86 virtual void cancelUserMediaRequest( | 83 virtual void cancelUserMediaRequest( |
| 87 const WebKit::WebUserMediaRequest& user_media_request) OVERRIDE; | 84 const WebKit::WebUserMediaRequest& user_media_request) OVERRIDE; |
| 88 | 85 |
| 89 // webkit_media::MediaStreamClient implementation. | 86 // webkit_media::MediaStreamClient implementation. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 101 virtual void OnVideoDeviceFailed( | 98 virtual void OnVideoDeviceFailed( |
| 102 const std::string& label, | 99 const std::string& label, |
| 103 int index) OVERRIDE; | 100 int index) OVERRIDE; |
| 104 virtual void OnAudioDeviceFailed( | 101 virtual void OnAudioDeviceFailed( |
| 105 const std::string& label, | 102 const std::string& label, |
| 106 int index) OVERRIDE; | 103 int index) OVERRIDE; |
| 107 | 104 |
| 108 private: | 105 private: |
| 109 FRIEND_TEST_ALL_PREFIXES(MediaStreamImplTest, Basic); | 106 FRIEND_TEST_ALL_PREFIXES(MediaStreamImplTest, Basic); |
| 110 | 107 |
| 108 class VideoRendererWrapper : public webrtc::VideoRendererWrapperInterface { | |
| 109 public: | |
| 110 VideoRendererWrapper(); | |
| 111 virtual cricket::VideoRenderer* renderer() OVERRIDE; | |
| 112 void SetVideoDecoder(RTCVideoDecoder* decoder); | |
| 113 | |
| 114 protected: | |
| 115 virtual ~VideoRendererWrapper(); | |
| 116 | |
| 117 private: | |
| 118 scoped_refptr<RTCVideoDecoder> rtc_video_decoder_; | |
| 119 }; | |
| 120 | |
| 111 void InitializeWorkerThread( | 121 void InitializeWorkerThread( |
| 112 talk_base::Thread** thread, | 122 talk_base::Thread** thread, |
| 113 base::WaitableEvent* event); | 123 base::WaitableEvent* event); |
| 114 void DeleteIpcNetworkManager(); | 124 void DeleteIpcNetworkManager(); |
| 125 bool EnsurePeerConnectionFactory(); | |
| 115 | 126 |
| 116 scoped_ptr<MediaStreamDependencyFactory> dependency_factory_; | 127 scoped_ptr<MediaStreamDependencyFactory> dependency_factory_; |
| 117 | 128 |
| 118 // media_stream_dispatcher_ is a weak reference, owned by RenderView. It's | 129 // media_stream_dispatcher_ is a weak reference, owned by RenderView. It's |
| 119 // valid for the lifetime of RenderView. | 130 // valid for the lifetime of RenderView. |
| 120 MediaStreamDispatcher* media_stream_dispatcher_; | 131 MediaStreamDispatcher* media_stream_dispatcher_; |
| 121 | 132 |
| 122 // media_engine_ is owned by PeerConnectionFactory (which is owned by | |
| 123 // dependency_factory_) and is valid for the lifetime of | |
| 124 // PeerConnectionFactory. | |
| 125 cricket::WebRtcMediaEngine* media_engine_; | |
| 126 | |
| 127 // p2p_socket_dispatcher_ is a weak reference, owned by RenderView. It's valid | 133 // p2p_socket_dispatcher_ is a weak reference, owned by RenderView. It's valid |
| 128 // for the lifetime of RenderView. | 134 // for the lifetime of RenderView. |
| 129 content::P2PSocketDispatcher* p2p_socket_dispatcher_; | 135 content::P2PSocketDispatcher* p2p_socket_dispatcher_; |
| 130 | 136 |
| 131 // We own network_manager_, must be deleted on the worker thread. | 137 // We own network_manager_, must be deleted on the worker thread. |
| 132 content::IpcNetworkManager* network_manager_; | 138 content::IpcNetworkManager* network_manager_; |
| 133 | 139 |
| 134 scoped_ptr<content::IpcPacketSocketFactory> socket_factory_; | 140 scoped_ptr<content::IpcPacketSocketFactory> socket_factory_; |
| 135 | 141 |
| 136 scoped_refptr<VideoCaptureImplManager> vc_manager_; | 142 scoped_refptr<VideoCaptureImplManager> vc_manager_; |
| 137 | 143 |
| 138 // peer_connection_handler_ is a weak reference, owned by WebKit. It's valid | 144 // peer_connection_handler_ is a weak reference, owned by WebKit. It's valid |
| 139 // until stop is called on it (which will call ClosePeerConnection on us). | 145 // until stop is called on it (which will call ClosePeerConnection on us). |
| 140 // TODO(grunell): Support several PeerConnectionsHandlers. | 146 // TODO(grunell): Support several PeerConnectionsHandlers. |
| 141 PeerConnectionHandler* peer_connection_handler_; | 147 PeerConnectionHandler* peer_connection_handler_; |
| 142 | 148 |
| 143 scoped_refptr<RTCVideoDecoder> rtc_video_decoder_; | 149 // We keep a list of the generated local tracks, so that we can add capture |
| 150 // devices when generated and also use them for recording. | |
| 151 typedef talk_base::scoped_refptr<webrtc::MediaStreamTrackInterface> | |
| 152 MediaStreamTrackPtr; | |
| 153 typedef std::map<std::string, MediaStreamTrackPtr> MediaStreamTrackPtrMap; | |
| 154 MediaStreamTrackPtrMap local_tracks_; | |
| 155 | |
| 156 talk_base::scoped_refptr<VideoRendererWrapper> video_renderer_; | |
| 144 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | 157 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
| 145 | 158 |
| 146 // PeerConnection threads. signaling_thread_ is created from the | 159 // PeerConnection threads. signaling_thread_ is created from the |
| 147 // "current" chrome thread. | 160 // "current" chrome thread. |
| 148 talk_base::Thread* signaling_thread_; | 161 talk_base::Thread* signaling_thread_; |
| 149 talk_base::Thread* worker_thread_; | 162 talk_base::Thread* worker_thread_; |
| 150 base::Thread chrome_worker_thread_; | 163 base::Thread chrome_worker_thread_; |
| 151 | 164 |
| 152 static int next_request_id_; | 165 static int next_request_id_; |
| 153 typedef std::map<int, WebKit::WebUserMediaRequest> MediaRequestMap; | 166 typedef std::map<int, WebKit::WebUserMediaRequest> MediaRequestMap; |
| 154 MediaRequestMap user_media_requests_; | 167 MediaRequestMap user_media_requests_; |
| 155 | 168 |
| 156 std::list<std::string> stream_labels_; | |
| 157 | |
| 158 // Make sure we only create the video capture module once. This is also | |
| 159 // temporary and will be handled differently when several PeerConnections | |
| 160 // and/or streams is supported. | |
| 161 // TODO(grunell): This shall be removed or changed when native PeerConnection | |
| 162 // has been updated to closer follow the specification. | |
| 163 bool vcm_created_; | |
| 164 | |
| 165 DISALLOW_COPY_AND_ASSIGN(MediaStreamImpl); | 169 DISALLOW_COPY_AND_ASSIGN(MediaStreamImpl); |
| 166 }; | 170 }; |
| 167 | 171 |
| 168 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_IMPL_H_ | 172 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_IMPL_H_ |
| OLD | NEW |