Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_STREAM_MEDIA_STREAM_IMPL_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_IMPL_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_STREAM_MEDIA_STREAM_IMPL_H_ | 6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_IMPL_H_ |
| 7 | |
| 8 #include <string> | |
| 7 | 9 |
| 8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/gtest_prod_util.h" | |
| 9 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/message_loop_proxy.h" | |
| 15 #include "base/threading/thread.h" | |
| 16 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" | |
| 10 #include "webkit/glue/media/media_stream_client.h" | 17 #include "webkit/glue/media/media_stream_client.h" |
| 11 | 18 |
| 19 namespace base { | |
| 20 class WaitableEvent; | |
| 21 } | |
| 22 | |
| 23 namespace content { | |
| 24 class IpcNetworkManager; | |
| 25 class IpcPacketSocketFactory; | |
| 26 class P2PSocketDispatcher; | |
| 27 } | |
| 28 | |
| 29 namespace cricket { | |
| 30 class HttpPortAllocator; | |
| 31 class WebRtcMediaEngine; | |
| 32 } | |
| 33 | |
| 34 namespace talk_base { | |
| 35 class Thread; | |
| 36 } | |
| 37 | |
| 38 namespace WebKit { | |
| 39 class WebPeerConnectionHandler; | |
| 40 class WebPeerConnectionHandlerClient; | |
| 41 } | |
| 42 | |
| 43 class MediaStreamDispatcher; | |
| 44 class MediaStreamDependencyFactory; | |
| 45 class PeerConnectionHandler; | |
| 12 class VideoCaptureImplManager; | 46 class VideoCaptureImplManager; |
| 47 class RTCVideoDecoder; | |
| 13 | 48 |
| 14 // A implementation of StreamClient to provide supporting functions, such as | 49 // MediaStreamImpl is a delegate for the Media Stream API messages used by |
| 15 // GetVideoDecoder. | 50 // WebKit. It ties together WebKit, native PeerConnection in libjingle and |
| 51 // MediaStreamManager (via MediaStreamDispatcher and MediaStreamDispatcherHost) | |
| 52 // in the browser process. | |
| 16 class MediaStreamImpl | 53 class MediaStreamImpl |
| 17 : public webkit_glue::MediaStreamClient, | 54 : public webkit_glue::MediaStreamClient, |
| 55 public MediaStreamDispatcherEventHandler, | |
| 18 public base::RefCountedThreadSafe<MediaStreamImpl> { | 56 public base::RefCountedThreadSafe<MediaStreamImpl> { |
| 19 public: | 57 public: |
| 20 explicit MediaStreamImpl(VideoCaptureImplManager* vc_manager); | 58 MediaStreamImpl( |
| 59 MediaStreamDispatcher* media_stream_dispatcher, | |
| 60 content::P2PSocketDispatcher* p2p_socket_dispatcher, | |
| 61 VideoCaptureImplManager* vc_manager, | |
| 62 MediaStreamDependencyFactory* dependency_factory); | |
| 21 virtual ~MediaStreamImpl(); | 63 virtual ~MediaStreamImpl(); |
| 22 | 64 |
| 23 // Implement webkit_glue::StreamClient. | 65 virtual WebKit::WebPeerConnectionHandler* CreatePeerConnectionHandler( |
| 66 WebKit::WebPeerConnectionHandlerClient* client); | |
| 67 virtual void ClosePeerConnection(); | |
| 68 // Returns true if created successfully or already exists, false otherwise. | |
| 69 virtual bool SetVideoCaptureModule(const std::string label); | |
|
tommi (sloooow) - chröme
2011/11/08 12:27:24
const&
Henrik Grunell
2011/11/08 22:06:41
Done.
| |
| 70 | |
| 71 // Implement webkit_glue::MediaStreamClient. | |
| 24 virtual scoped_refptr<media::VideoDecoder> GetVideoDecoder( | 72 virtual scoped_refptr<media::VideoDecoder> GetVideoDecoder( |
| 25 const GURL& url, media::MessageLoopFactory* message_loop_factory); | 73 const GURL& url, |
| 74 media::MessageLoopFactory* message_loop_factory) OVERRIDE; | |
| 75 | |
| 76 // Implement MediaStreamDispatcherEventHandler. | |
| 77 virtual void OnStreamGenerated( | |
| 78 int request_id, | |
| 79 const std::string& label, | |
| 80 const media_stream::StreamDeviceInfoArray& audio_array, | |
| 81 const media_stream::StreamDeviceInfoArray& video_array) OVERRIDE; | |
| 82 virtual void OnStreamGenerationFailed(int request_id) OVERRIDE; | |
| 83 virtual void OnVideoDeviceFailed( | |
| 84 const std::string& label, | |
| 85 int index) OVERRIDE; | |
| 86 virtual void OnAudioDeviceFailed( | |
| 87 const std::string& label, | |
| 88 int index) OVERRIDE; | |
| 26 | 89 |
| 27 private: | 90 private: |
| 91 FRIEND_TEST(MediaStreamImplTest, Basic); | |
| 92 | |
| 93 void InitializeWorkerThread( | |
| 94 talk_base::Thread** thread, | |
| 95 base::WaitableEvent* event); | |
| 96 | |
| 97 // dependency_factory_ is owned by us. | |
| 98 scoped_ptr<MediaStreamDependencyFactory> dependency_factory_; | |
| 99 | |
| 100 // media_stream_dispatcher_ is a weak reference, owned by RenderView. It's | |
| 101 // valid for the lifetime of RenderView. | |
| 102 MediaStreamDispatcher* media_stream_dispatcher_; | |
| 103 | |
| 104 // The media_engine_ is owned by pc_factory_ and is valid for the lifetime of | |
| 105 // pc_factory_. | |
| 106 cricket::WebRtcMediaEngine* media_engine_; | |
| 107 | |
| 108 // p2p_socket_dispatcher_ is a weak reference, owned by RenderView. It's valid | |
| 109 // for the lifetime of RenderView. | |
| 110 content::P2PSocketDispatcher* p2p_socket_dispatcher_; | |
| 111 | |
| 28 scoped_refptr<VideoCaptureImplManager> vc_manager_; | 112 scoped_refptr<VideoCaptureImplManager> vc_manager_; |
| 113 scoped_ptr<content::IpcNetworkManager> ipc_network_manager_; | |
| 114 scoped_ptr<content::IpcPacketSocketFactory> ipc_socket_factory_; | |
| 115 | |
| 116 // TODO(grunell): Support several PeerConnections. | |
| 117 // TODO(grunell): Comment on this. | |
|
tommi (sloooow) - chröme
2011/11/08 12:27:24
I guess you want to address this comment before ch
Henrik Grunell
2011/11/08 22:06:41
Done.
| |
| 118 scoped_ptr<PeerConnectionHandler> peer_connection_handler_; | |
| 119 | |
| 120 scoped_refptr<RTCVideoDecoder> rtc_video_decoder_; | |
| 121 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | |
| 122 | |
| 123 // PeerConnection threads. signaling_thread_ is created from the | |
| 124 // "current" chrome thread. | |
| 125 talk_base::Thread* signaling_thread_; | |
| 126 talk_base::Thread* worker_thread_; | |
| 127 base::Thread chrome_worker_thread_; | |
| 128 | |
| 129 // Make sure we only create the video capture module once. This is also | |
| 130 // temporary and will be handled differently when several PeerConnections | |
| 131 // and/or streams is supported. | |
| 132 // TODO(grunell): This shall be removed or changed when native PeerConnection | |
| 133 // has been updated to closer follow the specification. | |
| 134 bool vcm_created_; | |
| 29 | 135 |
| 30 DISALLOW_COPY_AND_ASSIGN(MediaStreamImpl); | 136 DISALLOW_COPY_AND_ASSIGN(MediaStreamImpl); |
| 31 }; | 137 }; |
| 32 | 138 |
| 33 #endif // CONTENT_RENDERER_MEDIA_STREAM_MEDIA_STREAM_IMPL_H_ | 139 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_IMPL_H_ |
| OLD | NEW |