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 // WebKit::WebPeerConnectionHandler implementation | |
| 39 virtual void initialize( | |
| 40 const WebKit::WebString& serverConfiguration, | |
|
tommi (sloooow) - chröme
2011/11/08 12:27:24
fix variable names
Henrik Grunell
2011/11/08 22:06:41
Done.
| |
| 41 const WebKit::WebSecurityOrigin&) OVERRIDE; | |
|
tommi (sloooow) - chröme
2011/11/08 12:27:24
and add variable names where missing
Henrik Grunell
2011/11/08 22:06:41
Done.
| |
| 42 virtual void produceInitialOffer( | |
| 43 const WebKit::WebVector<WebKit::WebMediaStreamDescriptor>& | |
| 44 pendingAddStreams) OVERRIDE; | |
| 45 virtual void handleInitialOffer(const WebKit::WebString& sdp) OVERRIDE; | |
| 46 virtual void processSDP(const WebKit::WebString& sdp) OVERRIDE; | |
| 47 virtual void processPendingStreams( | |
| 48 const WebKit::WebVector<WebKit::WebMediaStreamDescriptor>& | |
| 49 pendingAddStreams, | |
| 50 const WebKit::WebVector<WebKit::WebMediaStreamDescriptor>& | |
| 51 pendingRemoveStreams) OVERRIDE; | |
| 52 virtual void sendDataStreamMessage(const char* data, size_t length) OVERRIDE; | |
| 53 virtual void stop() OVERRIDE; | |
| 54 | |
| 55 // webrtc::PeerConnectionObserver implementation | |
| 56 virtual void OnSignalingMessage(const std::string& msg) OVERRIDE; | |
| 57 virtual void OnAddStream(const std::string& stream_id, bool video) OVERRIDE; | |
| 58 virtual void OnRemoveStream( | |
| 59 const std::string& stream_id, | |
| 60 bool video) OVERRIDE; | |
| 61 | |
| 62 private: | |
| 63 FRIEND_TEST(PeerConnectionHandlerTest, Basic); | |
| 64 | |
| 65 void AddStream(const std::string label); | |
| 66 void OnAddStreamCallback(const std::string& stream_label); | |
| 67 void OnRemoveStreamCallback(const std::string& stream_label); | |
| 68 | |
| 69 // The controller_ is valid for the lifetime of the underlying | |
| 70 // WebCore::WebMediaStreamController. shutdown() is invoked when the | |
| 71 // controller is destroyed. Additionally, MediaStreamImpl has the same | |
| 72 // lifetime as the controller since it is owned by RenderView. | |
| 73 // scoped_ptr<WebKit::WebMediaStreamController> controller_; | |
| 74 | |
| 75 // TODO(grunell): Check corresponding behavior for client_ in new WebKit | |
| 76 // implementation. | |
| 77 WebKit::WebPeerConnectionHandlerClient* client_; | |
| 78 | |
| 79 // TODO(grunell): Better name. | |
|
tommi (sloooow) - chröme
2011/11/08 12:27:24
address before checkin?
Henrik Grunell
2011/11/08 22:06:41
Done.
| |
| 80 MediaStreamImpl* msi_; | |
| 81 | |
| 82 // dependency_factory_ is a weak pointer, and is valid for the lifetime of | |
| 83 // MediaStreamImpl. | |
| 84 MediaStreamDependencyFactory* dependency_factory_; | |
| 85 | |
| 86 // native_peer_connection_ is the native PeerConnection object, | |
| 87 // it handles the ICE processing and media engine. | |
| 88 scoped_ptr<webrtc::PeerConnection> native_peer_connection_; | |
| 89 | |
| 90 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | |
| 91 | |
| 92 talk_base::Thread* signaling_thread_; | |
| 93 | |
| 94 // Currently, a stream in WebKit has audio and/or video and has one label. | |
| 95 // Local and remote streams have different labels. | |
| 96 // In native PeerConnection, a stream has audio or video (not both), and they | |
| 97 // have separate labels. A remote stream has the same label as the | |
| 98 // corresponding local stream. Hence the workarounds in the implementation to | |
| 99 // handle this. It could look like this: | |
| 100 // WebKit: Local, audio and video: label "foo". | |
| 101 // Remote, audio and video: label "foo-remote". | |
| 102 // Libjingle: Local and remote, audio: label "foo-audio". | |
| 103 // Local and remote, video: label "foo". | |
| 104 // TODO(grunell): This shall be removed or changed when native PeerConnection | |
| 105 // has been updated to closer follow the specification. | |
| 106 std::string local_label_; // Label used in WebKit | |
| 107 std::string remote_label_; // Label used in WebKit | |
| 108 | |
| 109 // Call states. Possible transitions: | |
| 110 // NOT_STARTED -> INITIATING -> SENDING_AND_RECEIVING | |
| 111 // NOT_STARTED -> RECEIVING | |
| 112 // RECEIVING -> NOT_STARTED | |
| 113 // RECEIVING -> SENDING_AND_RECEIVING | |
| 114 // SENDING_AND_RECEIVING -> NOT_STARTED | |
| 115 // Note that when in state SENDING_AND_RECEIVING, the other side may or may | |
| 116 // not send media. Thus, this state does not necessarily mean full duplex. | |
| 117 // TODO(grunell): This shall be removed or changed when native PeerConnection | |
| 118 // has been updated to closer follow the specification. | |
| 119 enum CallState { | |
| 120 NOT_STARTED, | |
| 121 INITIATING, | |
| 122 RECEIVING, | |
| 123 SENDING_AND_RECEIVING | |
| 124 }; | |
| 125 CallState call_state_; | |
| 126 | |
| 127 DISALLOW_COPY_AND_ASSIGN(PeerConnectionHandler); | |
| 128 }; | |
| 129 | |
| 130 #endif // CONTENT_RENDERER_MEDIA_PEER_CONNECTION_HANDLER_H_ | |
| OLD | NEW |