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;
25 class DataChannelInterface;
29 class RTCMediaConstraints;
30 class RTCPeerConnectionHandler;
32 // This class collects data about each peer connection,
33 // sends it to the browser process, and handles messages
34 // from the browser process.
35 class CONTENT_EXPORT PeerConnectionTracker : public RenderProcessObserver {
37 PeerConnectionTracker();
38 virtual ~PeerConnectionTracker();
46 ACTION_SET_LOCAL_DESCRIPTION,
47 ACTION_SET_REMOTE_DESCRIPTION,
52 // RenderProcessObserver implementation.
53 virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE;
56 // The following methods send an update to the browser process when a
57 // PeerConnection update happens. The caller should call the Track* methods
58 // after calling RegisterPeerConnection and before calling
59 // UnregisterPeerConnection, otherwise the Track* call has no effect.
62 // Sends an update when a PeerConnection has been created in Javascript.
63 // This should be called once and only once for each PeerConnection.
64 // The |pc_handler| is the handler object associated with the PeerConnection,
65 // the |servers| are the server configurations used to establish the
66 // connection, the |constraints| are the media constraints used to initialize
67 // the PeerConnection, the |frame| is the WebFrame object representing the
68 // page in which the PeerConnection is created.
69 void RegisterPeerConnection(
70 RTCPeerConnectionHandler* pc_handler,
71 const std::vector<webrtc::PeerConnectionInterface::IceServer>& servers,
72 const RTCMediaConstraints& constraints,
73 const WebKit::WebFrame* frame);
75 // Sends an update when a PeerConnection has been destroyed.
76 virtual void UnregisterPeerConnection(RTCPeerConnectionHandler* pc_handler);
78 // Sends an update when createOffer/createAnswer has been called.
79 // The |pc_handler| is the handler object associated with the PeerConnection,
80 // the |constraints| is the media constraints used to create the offer/answer.
81 virtual void TrackCreateOffer(RTCPeerConnectionHandler* pc_handler,
82 const RTCMediaConstraints& constraints);
83 virtual void TrackCreateAnswer(RTCPeerConnectionHandler* pc_handler,
84 const RTCMediaConstraints& constraints);
86 // Sends an update when setLocalDescription or setRemoteDescription is called.
87 virtual void TrackSetSessionDescription(
88 RTCPeerConnectionHandler* pc_handler,
89 const WebKit::WebRTCSessionDescription& desc, Source source);
91 // Sends an update when Ice candidates are updated.
92 virtual void TrackUpdateIce(
93 RTCPeerConnectionHandler* pc_handler,
94 const std::vector<webrtc::PeerConnectionInterface::IceServer>& servers,
95 const RTCMediaConstraints& options);
97 // Sends an update when an Ice candidate is added.
98 virtual void TrackAddIceCandidate(
99 RTCPeerConnectionHandler* pc_handler,
100 const WebKit::WebRTCICECandidate& candidate, Source source);
102 // Sends an update when a media stream is added.
103 virtual void TrackAddStream(
104 RTCPeerConnectionHandler* pc_handler,
105 const WebKit::WebMediaStream& stream, Source source);
107 // Sends an update when a media stream is removed.
108 virtual void TrackRemoveStream(
109 RTCPeerConnectionHandler* pc_handler,
110 const WebKit::WebMediaStream& stream, Source source);
112 // Sends an update when a DataChannel is created.
113 virtual void TrackCreateDataChannel(
114 RTCPeerConnectionHandler* pc_handler,
115 const webrtc::DataChannelInterface* data_channel, Source source);
117 // Sends an update when a PeerConnection has been stopped.
118 virtual void TrackStop(RTCPeerConnectionHandler* pc_handler);
120 // Sends an update when the signaling state of a PeerConnection has changed.
121 virtual void TrackSignalingStateChange(
122 RTCPeerConnectionHandler* pc_handler,
123 WebKit::WebRTCPeerConnectionHandlerClient::SignalingState state);
125 // Sends an update when the Ice connection state
126 // of a PeerConnection has changed.
127 virtual void TrackIceConnectionStateChange(
128 RTCPeerConnectionHandler* pc_handler,
129 WebKit::WebRTCPeerConnectionHandlerClient::ICEConnectionState state);
131 // Sends an update when the Ice gathering state
132 // of a PeerConnection has changed.
133 virtual void TrackIceGatheringStateChange(
134 RTCPeerConnectionHandler* pc_handler,
135 WebKit::WebRTCPeerConnectionHandlerClient::ICEGatheringState state);
137 // Sends an update when the SetSessionDescription or CreateOffer or
138 // CreateAnswer callbacks are called.
139 virtual void TrackSessionDescriptionCallback(
140 RTCPeerConnectionHandler* pc_handler, Action action,
141 const std::string& type, const std::string& value);
143 // Sends an update when onRenegotiationNeeded is called.
144 virtual void TrackOnRenegotiationNeeded(RTCPeerConnectionHandler* pc_handler);
146 // Sends an update when a DTMFSender is created.
147 virtual void TrackCreateDTMFSender(
148 RTCPeerConnectionHandler* pc_handler,
149 const WebKit::WebMediaStreamTrack& track);
152 // Assign a local ID to a peer connection so that the browser process can
153 // uniquely identify a peer connection in the renderer process.
154 int GetNextLocalID();
156 // IPC Message handler for getting all stats.
157 void OnGetAllStats();
159 void SendPeerConnectionUpdate(RTCPeerConnectionHandler* pc_handler,
160 const std::string& callback_type,
161 const std::string& value);
163 // This map stores the local ID assigned to each RTCPeerConnectionHandler.
164 typedef std::map<RTCPeerConnectionHandler*, int> PeerConnectionIdMap;
165 PeerConnectionIdMap peer_connection_id_map_;
167 // This keeps track of the next available local ID.
170 DISALLOW_COPY_AND_ASSIGN(PeerConnectionTracker);
173 } // namespace content
175 #endif // CONTENT_RENDERER_MEDIA_PEERCONNECTION_TRACKER_H_