1 // Copyright (c) 2013 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_PEERCONNECTION_TRACKER_H_
6 #define CONTENT_RENDERER_MEDIA_PEERCONNECTION_TRACKER_H_
10 #include "base/compiler_specific.h"
11 #include "content/public/renderer/render_process_observer.h"
12 #include "third_party/WebKit/public/platform/WebMediaStream.h"
13 #include "third_party/WebKit/public/platform/WebRTCPeerConnectionHandlerClient.h"
14 #include "third_party/WebKit/public/platform/WebRTCSessionDescription.h"
15 #include "third_party/libjingle/source/talk/app/webrtc/peerconnectioninterface.h"
19 class WebRTCICECandidate
;
21 class WebRTCSessionDescription
;
22 class WebUserMediaRequest
;
26 class DataChannelInterface
;
30 class RTCMediaConstraints
;
31 class RTCPeerConnectionHandler
;
33 // This class collects data about each peer connection,
34 // sends it to the browser process, and handles messages
35 // from the browser process.
36 class CONTENT_EXPORT PeerConnectionTracker
: public RenderProcessObserver
{
38 PeerConnectionTracker();
39 virtual ~PeerConnectionTracker();
47 ACTION_SET_LOCAL_DESCRIPTION
,
48 ACTION_SET_REMOTE_DESCRIPTION
,
53 // RenderProcessObserver implementation.
54 virtual bool OnControlMessageReceived(const IPC::Message
& message
) OVERRIDE
;
57 // The following methods send an update to the browser process when a
58 // PeerConnection update happens. The caller should call the Track* methods
59 // after calling RegisterPeerConnection and before calling
60 // UnregisterPeerConnection, otherwise the Track* call has no effect.
63 // Sends an update when a PeerConnection has been created in Javascript.
64 // This should be called once and only once for each PeerConnection.
65 // The |pc_handler| is the handler object associated with the PeerConnection,
66 // the |servers| are the server configurations used to establish the
67 // connection, the |constraints| are the media constraints used to initialize
68 // the PeerConnection, the |frame| is the WebFrame object representing the
69 // page in which the PeerConnection is created.
70 void RegisterPeerConnection(
71 RTCPeerConnectionHandler
* pc_handler
,
72 const webrtc::PeerConnectionInterface::RTCConfiguration
& config
,
73 const RTCMediaConstraints
& constraints
,
74 const blink::WebFrame
* frame
);
76 // Sends an update when a PeerConnection has been destroyed.
77 virtual void UnregisterPeerConnection(RTCPeerConnectionHandler
* pc_handler
);
79 // Sends an update when createOffer/createAnswer has been called.
80 // The |pc_handler| is the handler object associated with the PeerConnection,
81 // the |constraints| is the media constraints used to create the offer/answer.
82 virtual void TrackCreateOffer(RTCPeerConnectionHandler
* pc_handler
,
83 const RTCMediaConstraints
& constraints
);
84 virtual void TrackCreateAnswer(RTCPeerConnectionHandler
* pc_handler
,
85 const RTCMediaConstraints
& constraints
);
87 // Sends an update when setLocalDescription or setRemoteDescription is called.
88 virtual void TrackSetSessionDescription(
89 RTCPeerConnectionHandler
* pc_handler
,
90 const blink::WebRTCSessionDescription
& desc
, Source source
);
92 // Sends an update when Ice candidates are updated.
93 virtual void TrackUpdateIce(
94 RTCPeerConnectionHandler
* pc_handler
,
95 const webrtc::PeerConnectionInterface::RTCConfiguration
& config
,
96 const RTCMediaConstraints
& options
);
98 // Sends an update when an Ice candidate is added.
99 virtual void TrackAddIceCandidate(
100 RTCPeerConnectionHandler
* pc_handler
,
101 const blink::WebRTCICECandidate
& candidate
, Source source
);
103 // Sends an update when a media stream is added.
104 virtual void TrackAddStream(
105 RTCPeerConnectionHandler
* pc_handler
,
106 const blink::WebMediaStream
& stream
, Source source
);
108 // Sends an update when a media stream is removed.
109 virtual void TrackRemoveStream(
110 RTCPeerConnectionHandler
* pc_handler
,
111 const blink::WebMediaStream
& stream
, Source source
);
113 // Sends an update when a DataChannel is created.
114 virtual void TrackCreateDataChannel(
115 RTCPeerConnectionHandler
* pc_handler
,
116 const webrtc::DataChannelInterface
* data_channel
, Source source
);
118 // Sends an update when a PeerConnection has been stopped.
119 virtual void TrackStop(RTCPeerConnectionHandler
* pc_handler
);
121 // Sends an update when the signaling state of a PeerConnection has changed.
122 virtual void TrackSignalingStateChange(
123 RTCPeerConnectionHandler
* pc_handler
,
124 blink::WebRTCPeerConnectionHandlerClient::SignalingState state
);
126 // Sends an update when the Ice connection state
127 // of a PeerConnection has changed.
128 virtual void TrackIceConnectionStateChange(
129 RTCPeerConnectionHandler
* pc_handler
,
130 blink::WebRTCPeerConnectionHandlerClient::ICEConnectionState state
);
132 // Sends an update when the Ice gathering state
133 // of a PeerConnection has changed.
134 virtual void TrackIceGatheringStateChange(
135 RTCPeerConnectionHandler
* pc_handler
,
136 blink::WebRTCPeerConnectionHandlerClient::ICEGatheringState state
);
138 // Sends an update when the SetSessionDescription or CreateOffer or
139 // CreateAnswer callbacks are called.
140 virtual void TrackSessionDescriptionCallback(
141 RTCPeerConnectionHandler
* pc_handler
, Action action
,
142 const std::string
& type
, const std::string
& value
);
144 // Sends an update when onRenegotiationNeeded is called.
145 virtual void TrackOnRenegotiationNeeded(RTCPeerConnectionHandler
* pc_handler
);
147 // Sends an update when a DTMFSender is created.
148 virtual void TrackCreateDTMFSender(
149 RTCPeerConnectionHandler
* pc_handler
,
150 const blink::WebMediaStreamTrack
& track
);
152 // Sends an update when getUserMedia is called.
153 virtual void TrackGetUserMedia(
154 const blink::WebUserMediaRequest
& user_media_request
);
157 // Assign a local ID to a peer connection so that the browser process can
158 // uniquely identify a peer connection in the renderer process.
159 int GetNextLocalID();
161 // IPC Message handler for getting all stats.
162 void OnGetAllStats();
164 void SendPeerConnectionUpdate(RTCPeerConnectionHandler
* pc_handler
,
165 const std::string
& callback_type
,
166 const std::string
& value
);
168 // This map stores the local ID assigned to each RTCPeerConnectionHandler.
169 typedef std::map
<RTCPeerConnectionHandler
*, int> PeerConnectionIdMap
;
170 PeerConnectionIdMap peer_connection_id_map_
;
172 // This keeps track of the next available local ID.
175 DISALLOW_COPY_AND_ASSIGN(PeerConnectionTracker
);
178 } // namespace content
180 #endif // CONTENT_RENDERER_MEDIA_PEERCONNECTION_TRACKER_H_