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

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: Code review fixes plus implementation of WebKit::WebUserMediaClient. Created 9 years, 1 month 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) 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 // client_ is a weak pointer, and is valid until stop() has returned.
74 WebKit::WebPeerConnectionHandlerClient* client_;
75
76 // media_stream_impl_ is a weak pointer, and is valid for the lifetime of this
77 // class.
78 MediaStreamImpl* media_stream_impl_;
79
80 // dependency_factory_ is a weak pointer, and is valid for the lifetime of
81 // MediaStreamImpl.
82 MediaStreamDependencyFactory* dependency_factory_;
83
84 // native_peer_connection_ is the native PeerConnection object,
85 // it handles the ICE processing and media engine.
86 scoped_ptr<webrtc::PeerConnection> native_peer_connection_;
87
88 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
89
90 talk_base::Thread* signaling_thread_;
91
92 // Currently, a stream in WebKit has audio and/or video and has one label.
93 // Local and remote streams have different labels.
94 // In native PeerConnection, a stream has audio or video (not both), and they
95 // have separate labels. A remote stream has the same label as the
96 // corresponding local stream. Hence the workarounds in the implementation to
97 // handle this. It could look like this:
98 // WebKit: Local, audio and video: label "foo".
99 // Remote, audio and video: label "foo-remote".
100 // Libjingle: Local and remote, audio: label "foo-audio".
101 // Local and remote, video: label "foo".
102 // TODO(grunell): This shall be removed or changed when native PeerConnection
103 // has been updated to closer follow the specification.
104 std::string local_label_; // Label used in WebKit
105 std::string remote_label_; // Label used in WebKit
106
107 // Call states. Possible transitions:
108 // NOT_STARTED -> INITIATING -> SENDING_AND_RECEIVING
109 // NOT_STARTED -> RECEIVING
110 // RECEIVING -> NOT_STARTED
111 // RECEIVING -> SENDING_AND_RECEIVING
112 // SENDING_AND_RECEIVING -> NOT_STARTED
113 // Note that when in state SENDING_AND_RECEIVING, the other side may or may
114 // not send media. Thus, this state does not necessarily mean full duplex.
115 // TODO(grunell): This shall be removed or changed when native PeerConnection
116 // has been updated to closer follow the specification.
117 enum CallState {
118 NOT_STARTED,
119 INITIATING,
120 RECEIVING,
121 SENDING_AND_RECEIVING
122 };
123 CallState call_state_;
124
125 DISALLOW_COPY_AND_ASSIGN(PeerConnectionHandler);
126 };
127
128 #endif // CONTENT_RENDERER_MEDIA_PEER_CONNECTION_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698