Chromium Code Reviews| Index: content/renderer/media/media_stream_impl.h |
| diff --git a/content/renderer/media/media_stream_impl.h b/content/renderer/media/media_stream_impl.h |
| index b338a31a6cdb99914a8de2804d3b9a5450647789..500364b262438ad3e4ae804c5ae5f6b26b6bb6aa 100644 |
| --- a/content/renderer/media/media_stream_impl.h |
| +++ b/content/renderer/media/media_stream_impl.h |
| @@ -2,32 +2,224 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#ifndef CONTENT_RENDERER_MEDIA_STREAM_MEDIA_STREAM_IMPL_H_ |
| -#define CONTENT_RENDERER_MEDIA_STREAM_MEDIA_STREAM_IMPL_H_ |
| +#ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_IMPL_H_ |
| +#define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_IMPL_H_ |
| + |
| +#include <string> |
| #include "base/basictypes.h" |
| +#include "base/gtest_prod_util.h" |
| #include "base/memory/ref_counted.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/message_loop_proxy.h" |
| +#include "base/threading/thread.h" |
| +#include "content/renderer/media/media_stream_dispatcher_eventhandler.h" |
| +#include "third_party/libjingle/source/talk/app/webrtc/peerconnection.h" |
| +#include "third_party/libjingle/source/talk/app/webrtc/peerconnectionfactory.h" |
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamClient.h" |
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebPeerConnection.h" |
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" |
| #include "webkit/glue/media/media_stream_client.h" |
| +namespace base { |
| +class WaitableEvent; |
| +} |
| + |
| +namespace content { |
| +class IpcNetworkManager; |
| +class IpcPacketSocketFactory; |
| +class P2PSocketDispatcher; |
| +} |
| + |
| +namespace cricket { |
| +class HttpPortAllocator; |
| +class WebRtcMediaEngine; |
| +} |
| + |
| +namespace talk_base { |
| +class Thread; |
| +} |
| + |
| +namespace WebKit { |
| +class WebLocalMediaStream; |
| +class WebMediaStreamRecorder; |
| +class WebMediaStreamController; |
| +class WebMediaStreamTrack; |
| +class WebSecurityOrigin; |
| +} |
| + |
| +class MediaStreamDispatcher; |
| +class MediaStreamDependencyFactory; |
| class VideoCaptureImplManager; |
| +class RTCVideoDecoder; |
| -// A implementation of StreamClient to provide supporting functions, such as |
| -// GetVideoDecoder. |
| -class MediaStreamImpl |
| - : public webkit_glue::MediaStreamClient, |
| - public base::RefCountedThreadSafe<MediaStreamImpl> { |
| +// MediaStreamImpl is a delegate for the Media Stream API messages used by |
| +// WebKit. It ties together WebKit, native PeerConnection in libjingle and |
| +// MediaStreamManager (via MediaStreamDispatcher and MediaStreamDispatcherHost) |
| +// in the browser process. |
| +class MediaStreamImpl : public WebKit::WebMediaStreamClient, |
|
scherkus (not reviewing)
2011/10/31 01:59:13
nit: should be initializer-list format
class A
Henrik Grunell
2011/10/31 13:17:53
Done.
|
| + public webkit_glue::MediaStreamClient, |
| + public MediaStreamDispatcherEventHandler, |
| + public webrtc::PeerConnectionObserver, |
| + public base::RefCountedThreadSafe<MediaStreamImpl> { |
| public: |
| - explicit MediaStreamImpl(VideoCaptureImplManager* vc_manager); |
| + MediaStreamImpl( |
| + MediaStreamDispatcher* media_stream_dispatcher, |
| + content::P2PSocketDispatcher* p2p_socket_dispatcher, |
| + VideoCaptureImplManager* vc_manager, |
| + MediaStreamDependencyFactory* dependency_factory); |
| virtual ~MediaStreamImpl(); |
| - // Implement webkit_glue::StreamClient. |
| + // WebKit::WebMediaStreamClient implementation. |
| + virtual void setController( |
| + WebKit::WebMediaStreamController* controller) OVERRIDE; |
| + virtual void shutdown() OVERRIDE; |
| + virtual void generateStream( |
| + int request_id, |
| + WebKit::WebGenerateStreamOptionFlags flags, |
| + const WebKit::WebSecurityOrigin& web_security_origin) OVERRIDE; |
| + virtual void stopGeneratedStream( |
| + const WebKit::WebLocalMediaStream& stream) OVERRIDE; |
| + virtual void recordStream( |
| + const WebKit::WebMediaStreamRecorder& recorder) OVERRIDE; |
| + virtual void getRecordedData( |
| + const WebKit::WebMediaStreamRecorder& recorder, |
| + int request_id) OVERRIDE; |
| + virtual void disposeRecordedData( |
| + const WebKit::WebMediaStreamRecorder& recorder) OVERRIDE; |
| + virtual void setMediaStreamTrackEnabled( |
| + const WebKit::WebMediaStreamTrack& track) OVERRIDE; |
| + virtual void processSignalingMessage( |
| + const WebKit::WebPeerConnection& web_peer_connection, |
| + const WebKit::WebString& message) OVERRIDE; |
| + virtual void message( |
| + const WebKit::WebPeerConnection& web_peer_connection, |
| + const WebKit::WebString& message) OVERRIDE; |
| + virtual void addStream( |
| + const WebKit::WebPeerConnection& web_peer_connection, |
| + const WebKit::WebMediaStream& stream) OVERRIDE; |
| + virtual void newPeerConnection( |
| + const WebKit::WebPeerConnection& web_peer_connection, |
| + const WebKit::WebString& configuration) OVERRIDE; |
| + virtual void closePeerConnection( |
| + const WebKit::WebPeerConnection& web_peer_connection) OVERRIDE; |
| + virtual void startNegotiation( |
| + const WebKit::WebPeerConnection& web_peer_connection) OVERRIDE; |
| + virtual void removeStream( |
| + const WebKit::WebPeerConnection& web_peer_connection, |
| + const WebKit::WebMediaStream& stream) OVERRIDE; |
| + virtual void commitStreamChanges( |
| + const WebKit::WebPeerConnection& web_peer_connection) OVERRIDE; |
| + |
| + // Implement webkit_glue::MediaStreamClient. |
| virtual scoped_refptr<media::VideoDecoder> GetVideoDecoder( |
| - const GURL& url, media::MessageLoopFactory* message_loop_factory); |
| + const GURL& url, |
| + media::MessageLoopFactory* message_loop_factory) OVERRIDE; |
| + |
| + // Implement MediaStreamDispatcherEventHandler. |
| + virtual void OnStreamGenerated( |
| + int request_id, |
| + const std::string& label, |
| + const media_stream::StreamDeviceInfoArray& audio_array, |
| + const media_stream::StreamDeviceInfoArray& video_array) OVERRIDE; |
| + virtual void OnStreamGenerationFailed(int request_id) OVERRIDE; |
| + virtual void OnVideoDeviceFailed( |
| + const std::string& label, |
| + int index) OVERRIDE; |
| + virtual void OnAudioDeviceFailed( |
| + const std::string& label, |
| + int index) OVERRIDE; |
| + |
| + // Implement webrtc::PeerConnectionObserver |
| + virtual void OnSignalingMessage(const std::string& msg) OVERRIDE; |
| + virtual void OnAddStream(const std::string& stream_id, bool video) OVERRIDE; |
| + virtual void OnRemoveStream( |
| + const std::string& stream_id, |
| + bool video) OVERRIDE; |
| private: |
| + FRIEND_TEST(MediaStreamImplTest, Basic); |
| + |
| + void OnAddStreamCallback(const std::string& stream_label); |
| + void OnRemoveStreamCallback(const std::string& stream_label); |
| + |
| + void InitializeWorkerThread( |
| + talk_base::Thread** thread, |
| + base::WaitableEvent* event); |
| + |
| + // The controller_ is valid for the lifetime of the underlying |
| + // WebCore::WebMediaStreamController. shutdown() is invoked when the |
| + // controller is destroyed. Additionally, MediaStreamImpl has the same |
| + // lifetime as the controller since it is owned by RenderView. |
| + scoped_ptr<WebKit::WebMediaStreamController> controller_; |
| + // dependency_factory_ is owned by us. |
|
scherkus (not reviewing)
2011/10/31 01:59:13
nit: could we get some vertical whitespace inserte
Henrik Grunell
2011/10/31 13:17:53
Done.
|
| + scoped_ptr<MediaStreamDependencyFactory> dependency_factory_; |
| + MediaStreamDispatcher* media_stream_dispatcher_; |
| + // The media_engine_ is owned by pc_factory_ and is valid for the lifetime of |
| + // pc_factory_. |
| + cricket::WebRtcMediaEngine* media_engine_; |
| + // p2p_socket_dispatcher_ is a weak reference, owned by RenderView. It's valid |
| + // for the lifetime of RenderView. |
| + content::P2PSocketDispatcher* p2p_socket_dispatcher_; |
|
scherkus (not reviewing)
2011/10/31 01:59:13
who owns this class and what's the lifetime?
for
Henrik Grunell
2011/10/31 13:17:53
RenderView owns it. It's deleted when RenderView i
scherkus (not reviewing)
2011/11/01 00:25:50
I don't have any concrete suggestions, but perhaps
|
| scoped_refptr<VideoCaptureImplManager> vc_manager_; |
| + scoped_ptr<content::IpcNetworkManager> ipc_network_manager_; |
| + scoped_ptr<content::IpcPacketSocketFactory> ipc_socket_factory_; |
| + // TODO(grunell): Support several PeerConnections. |
| + // web_peer_connection_ is WebKit's PeerConnection object |
| + WebKit::WebPeerConnection web_peer_connection_; |
| + // native_peer_connection_ is the native PeerConnection object, |
| + // it handles the ICE processing and media engine. |
| + scoped_ptr<webrtc::PeerConnection> native_peer_connection_; |
| + scoped_refptr<RTCVideoDecoder> rtc_video_decoder_; |
| + scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
| + |
| + // PeerConnection threads. signaling_thread_ is created from the |
| + // "current" chrome thread. |
| + talk_base::Thread* signaling_thread_; |
| + talk_base::Thread* worker_thread_; |
| + base::Thread chrome_worker_thread_; |
| + |
| + // Currently, a stream in WebKit has audio and/or video and has one label. |
| + // Local and remote streams have different labels. |
| + // In native PeerConnection, a stream has audio or video (not both), and they |
| + // have separate labels. A remote stream has the same label as the |
| + // corresponding local stream. Hence the workarounds in the implementation to |
| + // handle this. It could look like this: |
| + // WebKit: Local, audio and video: label "foo". |
| + // Remote, audio and video: label "foo-remote". |
| + // Libjingle: Local and remote, audio: label "foo-audio". |
| + // Local and remote, video: label "foo". |
| + // TODO(grunell): This shall be removed or changed when native PeerConnection |
| + // has been updated to closer follow the specification. |
| + std::string local_label_; // Label used in WebKit |
| + std::string remote_label_; // Label used in WebKit |
| + |
| + // Call states. Possible transitions: |
| + // NOT_STARTED -> INITIATING -> SENDING_AND_RECEIVING |
| + // NOT_STARTED -> RECEIVING |
| + // RECEIVING -> NOT_STARTED |
| + // RECEIVING -> SENDING_AND_RECEIVING |
| + // SENDING_AND_RECEIVING -> NOT_STARTED |
| + // Note that when in state SENDING_AND_RECEIVING, the other side may or may |
| + // not send media. Thus, this state does not necessarily mean full duplex. |
| + // TODO(grunell): This shall be removed or changed when native PeerConnection |
| + // has been updated to closer follow the specification. |
| + enum CallState { |
| + NOT_STARTED, |
| + INITIATING, |
| + RECEIVING, |
| + SENDING_AND_RECEIVING |
| + }; |
| + CallState call_state_; |
| + |
| + // Make sure we only create the video capture module once. This is also |
| + // temporary and will be handled differently when several PeerConnections |
| + // and/or streams is supported. |
| + // TODO(grunell): This shall be removed or changed when native PeerConnection |
| + // has been updated to closer follow the specification. |
| + bool vcm_created_; |
| DISALLOW_COPY_AND_ASSIGN(MediaStreamImpl); |
| }; |
| -#endif // CONTENT_RENDERER_MEDIA_STREAM_MEDIA_STREAM_IMPL_H_ |
| +#endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_IMPL_H_ |