Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Side by Side Diff: content/renderer/media/peer_connection_handler.h

Issue 8060055: Adding support for MediaStream and PeerConnection functionality (Closed) Base URL: http://git.chromium.org/chromium/chromium.git@trunk
Patch Set: Merge Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2012 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/compiler_specific.h"
12 #include "base/gtest_prod_util.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/message_loop_proxy.h"
15 #include "content/common/content_export.h"
16 #include "third_party/libjingle/source/talk/app/webrtc/peerconnection.h"
17 #include "third_party/libjingle/source/talk/base/socketaddress.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConne ctionHandler.h"
19
20 namespace base {
21 class Thread;
22 class WaitableEvent;
23 }
24
25 namespace content {
26 class IpcNetworkManager;
27 class IpcPacketSocketFactory;
28 class P2PSocketDispatcher;
29 }
30
31 namespace cricket {
32 class PortAllocator;
33 }
34
35 namespace talk_base {
36 class Thread;
37 }
38
39 class MediaStreamDependencyFactory;
40 class MediaStreamImpl;
41
42 // PeerConnectionHandler is a delegate for the PeerConnection API messages going
43 // between WebKit and native PeerConnection in libjingle. It's owned by
44 // MediaStreamImpl.
45 class CONTENT_EXPORT PeerConnectionHandler
46 : NON_EXPORTED_BASE(public WebKit::WebPeerConnectionHandler),
47 NON_EXPORTED_BASE(public webrtc::PeerConnectionObserver) {
48 public:
49 PeerConnectionHandler(
50 WebKit::WebPeerConnectionHandlerClient* client,
51 MediaStreamImpl* msi,
52 MediaStreamDependencyFactory* dependency_factory,
53 talk_base::Thread* signaling_thread,
54 content::P2PSocketDispatcher* socket_dispatcher,
55 content::IpcNetworkManager* network_manager,
56 content::IpcPacketSocketFactory* socket_factory);
57 virtual ~PeerConnectionHandler();
58
59 // Set the video renderer for the specified stream.
60 virtual bool SetVideoRenderer(const std::string& stream_label,
61 cricket::VideoRenderer* renderer);
62
63 // WebKit::WebPeerConnectionHandler implementation
64 virtual void initialize(
65 const WebKit::WebString& server_configuration,
66 const WebKit::WebSecurityOrigin& security_origin) OVERRIDE;
67 virtual void produceInitialOffer(
68 const WebKit::WebVector<WebKit::WebMediaStreamDescriptor>&
69 pending_add_streams) OVERRIDE;
70 virtual void handleInitialOffer(const WebKit::WebString& sdp) OVERRIDE;
71 virtual void processSDP(const WebKit::WebString& sdp) OVERRIDE;
72 virtual void processPendingStreams(
73 const WebKit::WebVector<WebKit::WebMediaStreamDescriptor>&
74 pending_add_streams,
75 const WebKit::WebVector<WebKit::WebMediaStreamDescriptor>&
76 pending_remove_streams) OVERRIDE;
77 virtual void sendDataStreamMessage(const char* data, size_t length) OVERRIDE;
78 virtual void stop() OVERRIDE;
79
80 // webrtc::PeerConnectionObserver implementation
81 virtual void OnSignalingMessage(const std::string& msg) OVERRIDE;
82 virtual void OnAddStream(const std::string& stream_id, bool video) OVERRIDE;
83 virtual void OnRemoveStream(
84 const std::string& stream_id,
85 bool video) OVERRIDE;
86
87 private:
88 FRIEND_TEST_ALL_PREFIXES(PeerConnectionHandlerTest, Basic);
89
90 void AddStream(const std::string label);
91 void OnAddStreamCallback(const std::string& stream_label);
92 void OnRemoveStreamCallback(const std::string& stream_label);
93
94 // client_ is a weak pointer, and is valid until stop() has returned.
95 WebKit::WebPeerConnectionHandlerClient* client_;
96
97 // media_stream_impl_ is a weak pointer, and is valid for the lifetime of this
98 // class. Calls to it must be done on the render thread.
99 MediaStreamImpl* media_stream_impl_;
100
101 // dependency_factory_ is a weak pointer, and is valid for the lifetime of
102 // MediaStreamImpl.
103 MediaStreamDependencyFactory* dependency_factory_;
104
105 // native_peer_connection_ is the native PeerConnection object,
106 // it handles the ICE processing and media engine.
107 scoped_ptr<webrtc::PeerConnection> native_peer_connection_;
108
109 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
110
111 talk_base::Thread* signaling_thread_;
112
113 // socket_dispatcher_ is a weak reference, owned by RenderView. It's valid
114 // for the lifetime of RenderView.
115 content::P2PSocketDispatcher* socket_dispatcher_;
116
117 // network_manager_ and socket_factory_ are a weak references, owned by
118 // MediaStreamImpl.
119 content::IpcNetworkManager* network_manager_;
120 content::IpcPacketSocketFactory* socket_factory_;
121
122 scoped_ptr<cricket::PortAllocator> port_allocator_;
123
124 // Currently, a stream in WebKit has audio and/or video and has one label.
125 // Local and remote streams have different labels.
126 // In native PeerConnection, a stream has audio or video (not both), and they
127 // have separate labels. A remote stream has the same label as the
128 // corresponding local stream. Hence the workarounds in the implementation to
129 // handle this. It could look like this:
130 // WebKit: Local, audio and video: label "foo".
131 // Remote, audio and video: label "foo-remote".
132 // Native: Local and remote, audio: label "foo-audio".
133 // Local and remote, video: label "foo".
134 // TODO(grunell): This shall be removed or changed when native PeerConnection
135 // has been updated to closer follow the specification.
136 std::string local_label_; // Label used in WebKit
137 std::string remote_label_; // Label used in WebKit
138
139 // Call states. Possible transitions:
140 // NOT_STARTED -> INITIATING -> SENDING_AND_RECEIVING
141 // NOT_STARTED -> RECEIVING
142 // RECEIVING -> NOT_STARTED
143 // RECEIVING -> SENDING_AND_RECEIVING
144 // SENDING_AND_RECEIVING -> NOT_STARTED
145 // Note that when in state SENDING_AND_RECEIVING, the other side may or may
146 // not send media. Thus, this state does not necessarily mean full duplex.
147 // TODO(grunell): This shall be removed or changed when native PeerConnection
148 // has been updated to closer follow the specification.
149 enum CallState {
150 NOT_STARTED,
151 INITIATING,
152 RECEIVING,
153 SENDING_AND_RECEIVING
154 };
155 CallState call_state_;
156
157 DISALLOW_COPY_AND_ASSIGN(PeerConnectionHandler);
158 };
159
160 #endif // CONTENT_RENDERER_MEDIA_PEER_CONNECTION_HANDLER_H_
OLDNEW
« no previous file with comments | « content/renderer/media/mock_web_peer_connection_handler_client.cc ('k') | content/renderer/media/peer_connection_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698