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