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..f9b032f78abdc6047ab4fbd39e1f8c8eea7b68cb 100644 |
--- a/content/renderer/media/media_stream_impl.h |
+++ b/content/renderer/media/media_stream_impl.h |
@@ -2,32 +2,199 @@ |
// 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/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 WebMediaStreamController; |
+class WebSecurityOrigin; |
+} |
+ |
+class MediaStreamDispatcher; |
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. |
+class MediaStreamImpl : public WebKit::WebMediaStreamClient, |
+ public webkit_glue::MediaStreamClient, |
+ public MediaStreamDispatcherEventHandler, |
+ public webrtc::PeerConnectionObserver, |
+ public base::RefCountedThreadSafe<MediaStreamImpl> { |
public: |
- explicit MediaStreamImpl(VideoCaptureImplManager* vc_manager); |
- virtual ~MediaStreamImpl(); |
+ MediaStreamImpl(MediaStreamDispatcher* media_stream_dispatcher, |
+ content::P2PSocketDispatcher* p2p_socket_dispatcher, |
+ VideoCaptureImplManager* vc_manager); |
+ ~MediaStreamImpl(); |
+ |
+ // WebKit::WebMediaStreamClient implementation. |
+ virtual void setController(WebKit::WebMediaStreamController*); |
tommi (sloooow) - chröme
2011/09/23 13:02:42
Missing parameter names in a few methods. Also, I
grunell (dont use)
2011/09/29 13:38:17
Both done.
|
+ virtual void mediaStreamDestroyed(); |
- // Implement webkit_glue::StreamClient. |
+ virtual void generateStream(int requestId, |
+ WebKit::WebGenerateStreamOptionFlags, |
+ const WebKit::WebSecurityOrigin&); |
+ virtual void recordStream(const WebKit::WebString& streamLabel, |
+ int recorderId); |
+ virtual void getRecordedData(const WebKit::WebString& streamLabel, |
+ int recorderId, int requestId); |
+ virtual void disposeRecordedData(const WebKit::WebString& streamLabel, |
+ int recorderId); |
+ virtual void stopGeneratedStream(const WebKit::WebString& streamLabel); |
+ virtual void setMediaStreamTrackEnabled(const WebKit::WebString& trackId, |
+ bool enabled); |
+ virtual void processSignalingMessage(int peerConnectionId, |
+ const WebKit::WebString& message); |
+ virtual void message(int peerConnectionId, |
+ const WebKit::WebString& message); |
+ virtual void addStream(int peerConnectionId, |
+ const WebKit::WebString& streamLabel); |
+ virtual void newPeerConnection(int peerConnectionId, |
+ const WebKit::WebString& configuration); |
+ virtual void closePeerConnection(int peerConnectionId); |
+ virtual void startNegotiation(int peerConnectionId); |
+ virtual void removeStream(int peerConnectionId, |
+ const WebKit::WebString& streamLabel); |
+ virtual void commitStreamChanges(int peerConnectionId); |
+ |
+ // Implement media_stream::MediaStreamClient. |
virtual scoped_refptr<media::VideoDecoder> GetVideoDecoder( |
const GURL& url, media::MessageLoopFactory* message_loop_factory); |
+ // Implement MediaStreamDispatcherEventHandler. |
+ virtual void OnStreamGenerated( |
+ int requestId, |
+ const std::string& label, |
+ const media_stream::StreamDeviceInfoArray& audio_array, |
+ const media_stream::StreamDeviceInfoArray& video_array); |
+ virtual void OnStreamGenerationFailed(int requestId); |
+ virtual void OnVideoDeviceFailed(const std::string& label, int index); |
+ virtual void OnAudioDeviceFailed(const std::string& label, int index); |
+ |
+ // Implement webrtc::PeerConnectionObserver |
+ virtual void OnError(); |
+ virtual void OnSignalingMessage(const std::string& msg); |
+ virtual void OnAddStream(const std::string& stream_id, bool video); |
+ virtual void OnRemoveStream(const std::string& stream_id, bool video); |
+ |
private: |
+ FRIEND_TEST_ALL_PREFIXES(MediaStreamImplTest, Basic); |
+ FRIEND_TEST_ALL_PREFIXES(MediaStreamImplTest, TestFailure); |
+ |
+ // TODO(grunell): These shall be removed or changed when libjingle's |
+ // PeerConnection has been updated to closer follow the specification. |
+ void OnAddStreamCallback(std::string streamLabel); |
tommi (sloooow) - chröme
2011/09/23 13:02:42
const &
grunell (dont use)
2011/09/29 13:38:17
Done.
|
+ void OnRemoveStreamCallback(std::string streamLabel); |
tommi (sloooow) - chröme
2011/09/23 13:02:42
const &
grunell (dont use)
2011/09/29 13:38:17
Done.
|
+ void DeletePeerConnection(); |
+ |
+ void initializeWorkerThread(talk_base::Thread** thread, |
tommi (sloooow) - chröme
2011/09/23 13:02:42
InitializeWorkerThread
grunell (dont use)
2011/09/29 13:38:17
Done.
|
+ base::WaitableEvent* event); |
+ |
+ // The controller_ is valid for the lifetime of the underlying |
+ // WebCore::WebMediaStreamController. mediaStreamDestroyed() is |
+ // invoked when the underlying object is destroyed. Additionally, |
+ // the dispatcher has the same life time as the controller since |
+ // it is owned by RenderView. |
+ scoped_ptr<WebKit::WebMediaStreamController> controller_; |
+ |
+ MediaStreamDispatcher* media_stream_dispatcher_; |
+ cricket::WebRtcMediaEngine* media_engine_; |
+ |
+ content::P2PSocketDispatcher* p2p_socket_dispatcher_; |
scoped_refptr<VideoCaptureImplManager> vc_manager_; |
+ scoped_ptr<webrtc::PeerConnectionFactory> pc_factory_; |
+ scoped_ptr<content::IpcNetworkManager> ipc_network_manager_; |
+ scoped_ptr<content::IpcPacketSocketFactory> ipc_socket_factory_; |
+ // PeerConnectionFactory owns port_allocator_; |
+ cricket::HttpPortAllocator* port_allocator_; |
tommi (sloooow) - chröme
2011/09/23 13:02:42
do you need to hang on to all these in the MediaSt
grunell (dont use)
2011/09/29 13:38:17
Not port_allocator_, removed this. The other, yes.
|
+ // TODO(grunell): Support several PeerConnections. |
+ int peer_connection_id_; |
tommi (sloooow) - chröme
2011/09/23 13:02:42
document the purpose of peer_connection_id_ and pe
grunell (dont use)
2011/09/29 13:38:17
Done.
|
+ scoped_ptr<webrtc::PeerConnection> 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. |
+ // threads will be deleted when MessageLoop are destroyed. |
+ talk_base::Thread* signaling_thread_; |
+ talk_base::Thread* worker_thread_; |
+ base::Thread chrome_worker_thread_; |
+ |
+ // TODO(grunell): All of this shall be removed or changed when libjingle's |
+ // PeerConnection has been updated to closer follow the specification. |
+ // Currently, a stream in WebKit has audio and/or video and has one label. |
+ // Local and remote streams have different labels. |
+ // In libjingle, 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 stream audio and video, label "foo". |
+ // Remote stream audio and video, label "foo-remote". |
+ // Libjingle: Local stream audio, label "foo-audio". |
+ // Local stream video, label "foo". |
+ // Remote stream audio, label "foo-audio". |
+ // Remote stream video, label "foo". |
+ std::string local_label_; // Label used in WebKit |
+ std::string remote_label_; // Label used in WebKit |
+ // Call states. Possible transitions: |
tommi (sloooow) - chröme
2011/09/23 13:02:42
empty line before this one as above
grunell (dont use)
2011/09/29 13:38:17
Done.
|
+ // NOT_STARTED -> INITIATING -> SENDING_AND_RECEIVING |
+ // NOT_STARTED -> RECEIVING |
+ // RECEIVING -> NOT_STARTED |
+ // RECEIVING -> SENDING_AND_RECEIVING |
+ // RECEIVING -> TERMINATING -> NOT_STARTED |
+ // SENDING_AND_RECEIVING -> TERMINATING -> NOT_STARTED |
+ // 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. |
+ enum CallState { |
+ NOT_STARTED, |
+ INITIATING, |
+ RECEIVING, |
+ SENDING_AND_RECEIVING, |
+ TERMINATING |
+ }; |
+ 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. |
+ bool vcm_is_created_; |
+ |
DISALLOW_COPY_AND_ASSIGN(MediaStreamImpl); |
}; |
-#endif // CONTENT_RENDERER_MEDIA_STREAM_MEDIA_STREAM_IMPL_H_ |
+#endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_IMPL_H_ |