Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_RENDERER_MEDIA_PEER_CONNECTION_HANDLER_H_ | |
| 6 #define CONTENT_RENDERER_MEDIA_PEER_CONNECTION_HANDLER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/gtest_prod_util.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/message_loop_proxy.h" | |
| 14 #include "third_party/libjingle/source/talk/app/webrtc/peerconnection.h" | |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPeerConnectionHand ler.h" | |
| 16 | |
| 17 namespace talk_base { | |
| 18 class Thread; | |
| 19 } | |
| 20 | |
| 21 class MediaStreamDependencyFactory; | |
| 22 class MediaStreamImpl; | |
| 23 | |
| 24 // PeerConnectionHandler is a delegate for the PeerConnection API messages going | |
| 25 // between WebKit and native PeerConnection in libjingle. It's owned by | |
| 26 // MediaStreamImpl. | |
| 27 class PeerConnectionHandler | |
| 28 : public WebKit::WebPeerConnectionHandler, | |
| 29 public webrtc::PeerConnectionObserver { | |
| 30 public: | |
| 31 PeerConnectionHandler( | |
| 32 WebKit::WebPeerConnectionHandlerClient* client, | |
| 33 MediaStreamImpl* msi, | |
| 34 MediaStreamDependencyFactory* dependency_factory, | |
| 35 talk_base::Thread* signaling_thread); | |
| 36 virtual ~PeerConnectionHandler(); | |
| 37 | |
| 38 // Set the video renderer for the specified stream. | |
| 39 virtual bool SetVideoRenderer(const std::string& stream_label, | |
| 40 cricket::VideoRenderer* renderer); | |
| 41 | |
| 42 // WebKit::WebPeerConnectionHandler implementation | |
| 43 virtual void initialize( | |
| 44 const WebKit::WebString& server_configuration, | |
| 45 const WebKit::WebSecurityOrigin& security_origin) OVERRIDE; | |
| 46 virtual void produceInitialOffer( | |
| 47 const WebKit::WebVector<WebKit::WebMediaStreamDescriptor>& | |
| 48 pending_add_streams) OVERRIDE; | |
| 49 virtual void handleInitialOffer(const WebKit::WebString& sdp) OVERRIDE; | |
| 50 virtual void processSDP(const WebKit::WebString& sdp) OVERRIDE; | |
| 51 virtual void processPendingStreams( | |
| 52 const WebKit::WebVector<WebKit::WebMediaStreamDescriptor>& | |
| 53 pending_add_streams, | |
| 54 const WebKit::WebVector<WebKit::WebMediaStreamDescriptor>& | |
| 55 pending_remove_streams) OVERRIDE; | |
| 56 virtual void sendDataStreamMessage(const char* data, size_t length) OVERRIDE; | |
| 57 virtual void stop() OVERRIDE; | |
| 58 | |
| 59 // webrtc::PeerConnectionObserver implementation | |
| 60 virtual void OnSignalingMessage(const std::string& msg) OVERRIDE; | |
| 61 virtual void OnAddStream(const std::string& stream_id, bool video) OVERRIDE; | |
| 62 virtual void OnRemoveStream( | |
| 63 const std::string& stream_id, | |
| 64 bool video) OVERRIDE; | |
| 65 | |
| 66 private: | |
| 67 FRIEND_TEST(PeerConnectionHandlerTest, Basic); | |
| 68 | |
| 69 void AddStream(const std::string label); | |
| 70 void OnAddStreamCallback(const std::string& stream_label); | |
| 71 void OnRemoveStreamCallback(const std::string& stream_label); | |
| 72 | |
| 73 // The controller_ is valid for the lifetime of the underlying | |
| 74 // WebCore::WebMediaStreamController. shutdown() is invoked when the | |
| 75 // controller is destroyed. Additionally, MediaStreamImpl has the same | |
| 76 // lifetime as the controller since it is owned by RenderView. | |
| 77 // scoped_ptr<WebKit::WebMediaStreamController> controller_; | |
|
scherkus (not reviewing)
2011/11/09 02:29:10
??
tommi (sloooow) - chröme
2011/11/09 10:45:48
remove?
Henrik Grunell
2011/11/09 20:36:04
Removed controller_. Updated comment on client_ an
| |
| 78 | |
| 79 // TODO(grunell): Check corresponding behavior for client_ in new WebKit | |
| 80 // implementation. | |
| 81 WebKit::WebPeerConnectionHandlerClient* client_; | |
| 82 | |
| 83 // TODO(grunell): Better name. | |
|
tommi (sloooow) - chröme
2011/11/09 10:45:48
remove todo
Henrik Grunell
2011/11/09 20:36:04
Done.
| |
| 84 MediaStreamImpl* media_stream_impl_; | |
| 85 | |
| 86 // dependency_factory_ is a weak pointer, and is valid for the lifetime of | |
| 87 // MediaStreamImpl. | |
| 88 MediaStreamDependencyFactory* dependency_factory_; | |
| 89 | |
| 90 // native_peer_connection_ is the native PeerConnection object, | |
| 91 // it handles the ICE processing and media engine. | |
| 92 scoped_ptr<webrtc::PeerConnection> native_peer_connection_; | |
| 93 | |
| 94 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | |
| 95 | |
| 96 talk_base::Thread* signaling_thread_; | |
| 97 | |
| 98 // Currently, a stream in WebKit has audio and/or video and has one label. | |
| 99 // Local and remote streams have different labels. | |
| 100 // In native PeerConnection, a stream has audio or video (not both), and they | |
| 101 // have separate labels. A remote stream has the same label as the | |
| 102 // corresponding local stream. Hence the workarounds in the implementation to | |
| 103 // handle this. It could look like this: | |
| 104 // WebKit: Local, audio and video: label "foo". | |
| 105 // Remote, audio and video: label "foo-remote". | |
| 106 // Libjingle: Local and remote, audio: label "foo-audio". | |
| 107 // Local and remote, video: label "foo". | |
| 108 // TODO(grunell): This shall be removed or changed when native PeerConnection | |
| 109 // has been updated to closer follow the specification. | |
| 110 std::string local_label_; // Label used in WebKit | |
| 111 std::string remote_label_; // Label used in WebKit | |
| 112 | |
| 113 // Call states. Possible transitions: | |
| 114 // NOT_STARTED -> INITIATING -> SENDING_AND_RECEIVING | |
| 115 // NOT_STARTED -> RECEIVING | |
| 116 // RECEIVING -> NOT_STARTED | |
| 117 // RECEIVING -> SENDING_AND_RECEIVING | |
| 118 // SENDING_AND_RECEIVING -> NOT_STARTED | |
| 119 // Note that when in state SENDING_AND_RECEIVING, the other side may or may | |
| 120 // not send media. Thus, this state does not necessarily mean full duplex. | |
| 121 // TODO(grunell): This shall be removed or changed when native PeerConnection | |
| 122 // has been updated to closer follow the specification. | |
| 123 enum CallState { | |
| 124 NOT_STARTED, | |
| 125 INITIATING, | |
| 126 RECEIVING, | |
| 127 SENDING_AND_RECEIVING | |
| 128 }; | |
| 129 CallState call_state_; | |
| 130 | |
| 131 DISALLOW_COPY_AND_ASSIGN(PeerConnectionHandler); | |
| 132 }; | |
| 133 | |
| 134 #endif // CONTENT_RENDERER_MEDIA_PEER_CONNECTION_HANDLER_H_ | |
| OLD | NEW |