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/libjingle/source/talk/base/socketaddress.h" | |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConne ctionHandler.h" | |
17 | |
18 namespace base { | |
19 class Thread; | |
20 class WaitableEvent; | |
21 } | |
22 | |
23 namespace content { | |
24 class IpcNetworkManager; | |
25 class IpcPacketSocketFactory; | |
26 class P2PSocketDispatcher; | |
27 } | |
28 | |
29 namespace cricket { | |
30 class PortAllocator; | |
31 } | |
32 | |
33 namespace talk_base { | |
34 class Thread; | |
35 } | |
36 | |
37 class MediaStreamDependencyFactory; | |
38 class MediaStreamImpl; | |
39 | |
40 // PeerConnectionHandler is a delegate for the PeerConnection API messages going | |
41 // between WebKit and native PeerConnection in libjingle. It's owned by | |
42 // MediaStreamImpl. | |
43 class PeerConnectionHandler | |
44 : public WebKit::WebPeerConnectionHandler, | |
45 public webrtc::PeerConnectionObserver { | |
46 public: | |
47 PeerConnectionHandler( | |
48 WebKit::WebPeerConnectionHandlerClient* client, | |
49 MediaStreamImpl* msi, | |
50 MediaStreamDependencyFactory* dependency_factory, | |
51 talk_base::Thread* signaling_thread, | |
52 content::P2PSocketDispatcher* socket_dispatcher, | |
53 content::IpcNetworkManager* network_manager, | |
54 content::IpcPacketSocketFactory* socket_factory); | |
55 virtual ~PeerConnectionHandler(); | |
56 | |
57 // Set the video renderer for the specified stream. | |
58 virtual bool SetVideoRenderer(const std::string& stream_label, | |
59 cricket::VideoRenderer* renderer); | |
60 | |
61 // WebKit::WebPeerConnectionHandler implementation | |
62 virtual void initialize( | |
63 const WebKit::WebString& server_configuration, | |
64 const WebKit::WebSecurityOrigin& security_origin) OVERRIDE; | |
65 virtual void produceInitialOffer( | |
66 const WebKit::WebVector<WebKit::WebMediaStreamDescriptor>& | |
67 pending_add_streams) OVERRIDE; | |
68 virtual void handleInitialOffer(const WebKit::WebString& sdp) OVERRIDE; | |
69 virtual void processSDP(const WebKit::WebString& sdp) OVERRIDE; | |
70 virtual void processPendingStreams( | |
71 const WebKit::WebVector<WebKit::WebMediaStreamDescriptor>& | |
72 pending_add_streams, | |
73 const WebKit::WebVector<WebKit::WebMediaStreamDescriptor>& | |
74 pending_remove_streams) OVERRIDE; | |
75 virtual void sendDataStreamMessage(const char* data, size_t length) OVERRIDE; | |
76 virtual void stop() OVERRIDE; | |
77 | |
78 // webrtc::PeerConnectionObserver implementation | |
79 virtual void OnSignalingMessage(const std::string& msg) OVERRIDE; | |
80 virtual void OnAddStream(const std::string& stream_id, bool video) OVERRIDE; | |
81 virtual void OnRemoveStream( | |
82 const std::string& stream_id, | |
83 bool video) OVERRIDE; | |
84 | |
85 private: | |
86 FRIEND_TEST_ALL_PREFIXES(PeerConnectionHandlerTest, Basic); | |
87 | |
88 void AddStream(const std::string label); | |
89 void OnAddStreamCallback(const std::string& stream_label); | |
90 void OnRemoveStreamCallback(const std::string& stream_label); | |
91 | |
92 // client_ is a weak pointer, and is valid until stop() has returned. | |
93 WebKit::WebPeerConnectionHandlerClient* client_; | |
94 | |
95 // media_stream_impl_ is a weak pointer, and is valid for the lifetime of this | |
96 // class. Calls to it must be done on | |
tommi (sloooow) - chröme
2011/12/21 12:41:42
... Mondays? ...sacred ground? what is it? don't
Henrik Grunell
2012/01/05 09:23:49
:-) I wanted to give some tension before Christmas
tommi (sloooow) - chröme
2012/01/05 22:24:20
phew!
| |
97 MediaStreamImpl* media_stream_impl_; | |
98 | |
99 // dependency_factory_ is a weak pointer, and is valid for the lifetime of | |
100 // MediaStreamImpl. | |
101 MediaStreamDependencyFactory* dependency_factory_; | |
102 | |
103 // native_peer_connection_ is the native PeerConnection object, | |
104 // it handles the ICE processing and media engine. | |
105 scoped_ptr<webrtc::PeerConnection> native_peer_connection_; | |
106 | |
107 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | |
108 | |
109 talk_base::Thread* signaling_thread_; | |
110 | |
111 // socket_dispatcher_ is a weak reference, owned by RenderView. It's valid | |
112 // for the lifetime of RenderView. | |
113 content::P2PSocketDispatcher* socket_dispatcher_; | |
114 | |
115 // network_manager_ and socket_factory_ are a weak references, owned by | |
116 // MediaStreamImpl. | |
117 content::IpcNetworkManager* network_manager_; | |
118 content::IpcPacketSocketFactory* socket_factory_; | |
119 | |
120 scoped_ptr<cricket::PortAllocator> port_allocator_; | |
121 | |
122 // Currently, a stream in WebKit has audio and/or video and has one label. | |
123 // Local and remote streams have different labels. | |
124 // In native PeerConnection, a stream has audio or video (not both), and they | |
125 // have separate labels. A remote stream has the same label as the | |
126 // corresponding local stream. Hence the workarounds in the implementation to | |
127 // handle this. It could look like this: | |
128 // WebKit: Local, audio and video: label "foo". | |
129 // Remote, audio and video: label "foo-remote". | |
130 // Native: Local and remote, audio: label "foo-audio". | |
131 // Local and remote, video: label "foo". | |
132 // TODO(grunell): This shall be removed or changed when native PeerConnection | |
133 // has been updated to closer follow the specification. | |
134 std::string local_label_; // Label used in WebKit | |
135 std::string remote_label_; // Label used in WebKit | |
136 | |
137 // Call states. Possible transitions: | |
138 // NOT_STARTED -> INITIATING -> SENDING_AND_RECEIVING | |
139 // NOT_STARTED -> RECEIVING | |
140 // RECEIVING -> NOT_STARTED | |
141 // RECEIVING -> SENDING_AND_RECEIVING | |
142 // SENDING_AND_RECEIVING -> NOT_STARTED | |
143 // Note that when in state SENDING_AND_RECEIVING, the other side may or may | |
144 // not send media. Thus, this state does not necessarily mean full duplex. | |
145 // TODO(grunell): This shall be removed or changed when native PeerConnection | |
146 // has been updated to closer follow the specification. | |
147 enum CallState { | |
148 NOT_STARTED, | |
149 INITIATING, | |
150 RECEIVING, | |
151 SENDING_AND_RECEIVING | |
152 }; | |
153 CallState call_state_; | |
154 | |
155 DISALLOW_COPY_AND_ASSIGN(PeerConnectionHandler); | |
156 }; | |
157 | |
158 #endif // CONTENT_RENDERER_MEDIA_PEER_CONNECTION_HANDLER_H_ | |
OLD | NEW |