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.
5 #ifndef CONTENT_RENDERER_MEDIA_RTC_PEER_CONNECTION_HANDLER_H_
6 #define CONTENT_RENDERER_MEDIA_RTC_PEER_CONNECTION_HANDLER_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "content/common/content_export.h"
11 #include "content/renderer/media/peer_connection_handler_base.h"
12 #include "third_party/WebKit/Source/Platform/chromium/public/WebRTCPeerConnectionHandler.h"
13 #include "third_party/WebKit/Source/Platform/chromium/public/WebRTCStatsRequest.h"
14 #include "third_party/WebKit/Source/Platform/chromium/public/WebRTCStatsResponse.h"
18 class WebRTCDataChannelHandler
;
23 class PeerConnectionTracker
;
25 // Mockable wrapper for WebKit::WebRTCStatsResponse
26 class CONTENT_EXPORT LocalRTCStatsResponse
27 : public NON_EXPORTED_BASE(talk_base::RefCountInterface
) {
29 explicit LocalRTCStatsResponse(const WebKit::WebRTCStatsResponse
& impl
)
33 virtual WebKit::WebRTCStatsResponse
webKitStatsResponse() const;
34 virtual size_t addReport(WebKit::WebString type
, WebKit::WebString id
,
36 virtual void addStatistic(size_t report
,
37 WebKit::WebString name
, WebKit::WebString value
);
40 virtual ~LocalRTCStatsResponse() {}
41 // Constructor for creating mocks.
42 LocalRTCStatsResponse() {}
45 WebKit::WebRTCStatsResponse impl_
;
48 // Mockable wrapper for WebKit::WebRTCStatsRequest
49 class CONTENT_EXPORT LocalRTCStatsRequest
50 : public NON_EXPORTED_BASE(talk_base::RefCountInterface
) {
52 explicit LocalRTCStatsRequest(WebKit::WebRTCStatsRequest impl
);
53 // Constructor for testing.
54 LocalRTCStatsRequest();
56 virtual bool hasSelector() const;
57 virtual WebKit::WebMediaStream
stream() const;
58 virtual WebKit::WebMediaStreamTrack
component() const;
59 virtual void requestSucceeded(const LocalRTCStatsResponse
* response
);
60 virtual scoped_refptr
<LocalRTCStatsResponse
> createResponse();
63 virtual ~LocalRTCStatsRequest();
66 WebKit::WebRTCStatsRequest impl_
;
67 talk_base::scoped_refptr
<LocalRTCStatsResponse
> response_
;
70 // RTCPeerConnectionHandler is a delegate for the RTC PeerConnection API
71 // messages going between WebKit and native PeerConnection in libjingle. It's
73 // WebKit calls all of these methods on the main render thread.
74 // Callbacks to the webrtc::PeerConnectionObserver implementation also occur on
75 // the main render thread.
76 class CONTENT_EXPORT RTCPeerConnectionHandler
77 : public PeerConnectionHandlerBase
,
78 NON_EXPORTED_BASE(public WebKit::WebRTCPeerConnectionHandler
) {
80 RTCPeerConnectionHandler(
81 WebKit::WebRTCPeerConnectionHandlerClient
* client
,
82 MediaStreamDependencyFactory
* dependency_factory
);
83 virtual ~RTCPeerConnectionHandler();
85 void associateWithFrame(WebKit::WebFrame
* frame
);
87 // Initialize method only used for unit test.
88 bool InitializeForTest(
89 const WebKit::WebRTCConfiguration
& server_configuration
,
90 const WebKit::WebMediaConstraints
& options
,
91 PeerConnectionTracker
* peer_connection_tracker
);
93 // WebKit::WebRTCPeerConnectionHandler implementation
94 virtual bool initialize(
95 const WebKit::WebRTCConfiguration
& server_configuration
,
96 const WebKit::WebMediaConstraints
& options
) OVERRIDE
;
98 virtual void createOffer(
99 const WebKit::WebRTCSessionDescriptionRequest
& request
,
100 const WebKit::WebMediaConstraints
& options
) OVERRIDE
;
101 virtual void createAnswer(
102 const WebKit::WebRTCSessionDescriptionRequest
& request
,
103 const WebKit::WebMediaConstraints
& options
) OVERRIDE
;
105 virtual void setLocalDescription(
106 const WebKit::WebRTCVoidRequest
& request
,
107 const WebKit::WebRTCSessionDescription
& description
) OVERRIDE
;
108 virtual void setRemoteDescription(
109 const WebKit::WebRTCVoidRequest
& request
,
110 const WebKit::WebRTCSessionDescription
& description
) OVERRIDE
;
112 virtual WebKit::WebRTCSessionDescription
localDescription()
114 virtual WebKit::WebRTCSessionDescription
remoteDescription()
116 virtual bool updateICE(
117 const WebKit::WebRTCConfiguration
& server_configuration
,
118 const WebKit::WebMediaConstraints
& options
) OVERRIDE
;
119 virtual bool addICECandidate(
120 const WebKit::WebRTCICECandidate
& candidate
) OVERRIDE
;
122 virtual bool addStream(
123 const WebKit::WebMediaStream
& stream
,
124 const WebKit::WebMediaConstraints
& options
) OVERRIDE
;
125 virtual void removeStream(
126 const WebKit::WebMediaStream
& stream
) OVERRIDE
;
127 virtual void getStats(
128 const WebKit::WebRTCStatsRequest
& request
) OVERRIDE
;
129 virtual WebKit::WebRTCDataChannelHandler
* createDataChannel(
130 const WebKit::WebString
& label
, bool reliable
) OVERRIDE
;
131 virtual WebKit::WebRTCDTMFSenderHandler
* createDTMFSender(
132 const WebKit::WebMediaStreamTrack
& track
) OVERRIDE
;
133 virtual void stop() OVERRIDE
;
135 // webrtc::PeerConnectionObserver implementation
136 virtual void OnError() OVERRIDE
;
137 // Triggered when the SignalingState changed.
138 virtual void OnSignalingChange(
139 webrtc::PeerConnectionInterface::SignalingState new_state
) OVERRIDE
;
140 virtual void OnAddStream(webrtc::MediaStreamInterface
* stream
) OVERRIDE
;
141 virtual void OnRemoveStream(webrtc::MediaStreamInterface
* stream
) OVERRIDE
;
142 virtual void OnIceCandidate(
143 const webrtc::IceCandidateInterface
* candidate
) OVERRIDE
;
144 virtual void OnIceConnectionChange(
145 webrtc::PeerConnectionInterface::IceConnectionState new_state
) OVERRIDE
;
146 virtual void OnIceGatheringChange(
147 webrtc::PeerConnectionInterface::IceGatheringState new_state
) OVERRIDE
;
149 virtual void OnDataChannel(
150 webrtc::DataChannelInterface
* data_channel
) OVERRIDE
;
151 virtual void OnRenegotiationNeeded() OVERRIDE
;
153 // Delegate functions to allow for mocking of WebKit interfaces.
154 // getStats takes ownership of request parameter.
155 virtual void getStats(LocalRTCStatsRequest
* request
);
157 // Calls GetStats on |native_peer_connection_|.
158 void GetStats(webrtc::StatsObserver
* observer
,
159 webrtc::MediaStreamTrackInterface
* track
);
161 PeerConnectionTracker
* peer_connection_tracker();
164 webrtc::SessionDescriptionInterface
* CreateNativeSessionDescription(
165 const WebKit::WebRTCSessionDescription
& description
,
166 webrtc::SdpParseError
* error
);
168 // |client_| is a weak pointer, and is valid until stop() has returned.
169 WebKit::WebRTCPeerConnectionHandlerClient
* client_
;
171 WebKit::WebFrame
* frame_
;
173 PeerConnectionTracker
* peer_connection_tracker_
;
175 DISALLOW_COPY_AND_ASSIGN(RTCPeerConnectionHandler
);
178 } // namespace content
180 #endif // CONTENT_RENDERER_MEDIA_RTC_PEER_CONNECTION_HANDLER_H_