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,
105 // Sends an update when a media stream is added.
106 virtual void TrackAddStream(
107 RTCPeerConnectionHandler* pc_handler,
108 const blink::WebMediaStream& stream, Source source);
110 // Sends an update when a media stream is removed.
111 virtual void TrackRemoveStream(
112 RTCPeerConnectionHandler* pc_handler,
113 const blink::WebMediaStream& stream, Source source);
115 // Sends an update when a DataChannel is created.
116 virtual void TrackCreateDataChannel(
117 RTCPeerConnectionHandler* pc_handler,
118 const webrtc::DataChannelInterface* data_channel, Source source);
120 // Sends an update when a PeerConnection has been stopped.
121 virtual void TrackStop(RTCPeerConnectionHandler* pc_handler);
123 // Sends an update when the signaling state of a PeerConnection has changed.
124 virtual void TrackSignalingStateChange(
125 RTCPeerConnectionHandler* pc_handler,
126 blink::WebRTCPeerConnectionHandlerClient::SignalingState state);
128 // Sends an update when the Ice connection state
129 // of a PeerConnection has changed.
130 virtual void TrackIceConnectionStateChange(
131 RTCPeerConnectionHandler* pc_handler,
132 blink::WebRTCPeerConnectionHandlerClient::ICEConnectionState state);
134 // Sends an update when the Ice gathering state
135 // of a PeerConnection has changed.
136 virtual void TrackIceGatheringStateChange(
137 RTCPeerConnectionHandler* pc_handler,
138 blink::WebRTCPeerConnectionHandlerClient::ICEGatheringState state);
140 // Sends an update when the SetSessionDescription or CreateOffer or
141 // CreateAnswer callbacks are called.
142 virtual void TrackSessionDescriptionCallback(
143 RTCPeerConnectionHandler* pc_handler, Action action,
144 const std::string& type, const std::string& value);
146 // Sends an update when onRenegotiationNeeded is called.
147 virtual void TrackOnRenegotiationNeeded(RTCPeerConnectionHandler* pc_handler);
149 // Sends an update when a DTMFSender is created.
150 virtual void TrackCreateDTMFSender(
151 RTCPeerConnectionHandler* pc_handler,
152 const blink::WebMediaStreamTrack& track);
154 // Sends an update when getUserMedia is called.
155 virtual void TrackGetUserMedia(
156 const blink::WebUserMediaRequest& user_media_request);
159 // Assign a local ID to a peer connection so that the browser process can
160 // uniquely identify a peer connection in the renderer process.
161 int GetNextLocalID();
163 // IPC Message handler for getting all stats.
164 void OnGetAllStats();
166 // Called when the browser process reports a suspend event from the OS.
169 void SendPeerConnectionUpdate(RTCPeerConnectionHandler* pc_handler,
170 const std::string& callback_type,
171 const std::string& value);
173 // This map stores the local ID assigned to each RTCPeerConnectionHandler.
174 typedef std::map<RTCPeerConnectionHandler*, int> PeerConnectionIdMap;
175 PeerConnectionIdMap peer_connection_id_map_;
177 // This keeps track of the next available local ID.
180 DISALLOW_COPY_AND_ASSIGN(PeerConnectionTracker);
183 } // namespace content
185 #endif // CONTENT_RENDERER_MEDIA_PEERCONNECTION_TRACKER_H_