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/Source/Platform/chromium/public/WebMediaStream.h"
13 #include "third_party/WebKit/Source/Platform/chromium/public/WebRTCPeerConnectionHandlerClient.h"
14 #include "third_party/libjingle/source/talk/app/webrtc/peerconnectioninterface.h"
18 class WebRTCICECandidate
;
23 class DataChannelInterface
;
27 class RTCMediaConstraints
;
28 class RTCPeerConnectionHandler
;
30 // This class collects data about each peer connection,
31 // sends it to the browser process, and handles messages
32 // from the browser process.
33 class CONTENT_EXPORT PeerConnectionTracker
: public RenderProcessObserver
{
35 PeerConnectionTracker();
36 virtual ~PeerConnectionTracker();
44 ACTION_SET_LOCAL_DESCRIPTION
,
45 ACTION_SET_REMOTE_DESCRIPTION
,
50 // RenderProcessObserver implementation.
51 virtual bool OnControlMessageReceived(const IPC::Message
& message
) OVERRIDE
;
54 // The following methods send an update to the browser process when a
55 // PeerConnection update happens. The caller should call the Track* methods
56 // after calling RegisterPeerConnection and before calling
57 // UnregisterPeerConnection, otherwise the Track* call has no effect.
60 // Sends an update when a PeerConnection has been created in Javascript.
61 // This should be called once and only once for each PeerConnection.
62 // The |pc_handler| is the handler object associated with the PeerConnection,
63 // the |servers| are the server configurations used to establish the
64 // connection, the |constraints| are the media constraints used to initialize
65 // the PeerConnection, the |frame| is the WebFrame object representing the
66 // page in which the PeerConnection is created.
67 void RegisterPeerConnection(
68 RTCPeerConnectionHandler
* pc_handler
,
69 const std::vector
<webrtc::PeerConnectionInterface::IceServer
>& servers
,
70 const RTCMediaConstraints
& constraints
,
71 const WebKit::WebFrame
* frame
);
73 // Sends an update when a PeerConnection has been destroyed.
74 virtual void UnregisterPeerConnection(RTCPeerConnectionHandler
* pc_handler
);
76 // Sends an update when createOffer/createAnswer has been called.
77 // The |pc_handler| is the handler object associated with the PeerConnection,
78 // the |constraints| is the media constraints used to create the offer/answer.
79 virtual void TrackCreateOffer(RTCPeerConnectionHandler
* pc_handler
,
80 const RTCMediaConstraints
& constraints
);
81 virtual void TrackCreateAnswer(RTCPeerConnectionHandler
* pc_handler
,
82 const RTCMediaConstraints
& constraints
);
84 // Sends an update when setLocalDescription or setRemoteDescription is called.
85 virtual void TrackSetSessionDescription(
86 RTCPeerConnectionHandler
* pc_handler
,
87 const webrtc::SessionDescriptionInterface
* desc
, Source source
);
89 // Sends an update when Ice candidates are updated.
90 virtual void TrackUpdateIce(
91 RTCPeerConnectionHandler
* pc_handler
,
92 const std::vector
<webrtc::PeerConnectionInterface::IceServer
>& servers
,
93 const RTCMediaConstraints
& options
);
95 // Sends an update when an Ice candidate is added.
96 virtual void TrackAddIceCandidate(
97 RTCPeerConnectionHandler
* pc_handler
,
98 const WebKit::WebRTCICECandidate
& candidate
, Source source
);
100 // Sends an update when a media stream is added.
101 virtual void TrackAddStream(
102 RTCPeerConnectionHandler
* pc_handler
,
103 const WebKit::WebMediaStream
& stream
, Source source
);
105 // Sends an update when a media stream is removed.
106 virtual void TrackRemoveStream(
107 RTCPeerConnectionHandler
* pc_handler
,
108 const WebKit::WebMediaStream
& stream
, Source source
);
110 // Sends an update when a DataChannel is created.
111 virtual void TrackCreateDataChannel(
112 RTCPeerConnectionHandler
* pc_handler
,
113 const webrtc::DataChannelInterface
* data_channel
, Source source
);
115 // Sends an update when a PeerConnection has been stopped.
116 virtual void TrackStop(RTCPeerConnectionHandler
* pc_handler
);
118 // Sends an update when the signaling state of a PeerConnection has changed.
119 virtual void TrackSignalingStateChange(
120 RTCPeerConnectionHandler
* pc_handler
,
121 WebKit::WebRTCPeerConnectionHandlerClient::SignalingState state
);
123 // Sends an update when the Ice connection state
124 // of a PeerConnection has changed.
125 virtual void TrackIceConnectionStateChange(
126 RTCPeerConnectionHandler
* pc_handler
,
127 WebKit::WebRTCPeerConnectionHandlerClient::ICEConnectionState state
);
129 // Sends an update when the Ice gathering state
130 // of a PeerConnection has changed.
131 virtual void TrackIceGatheringStateChange(
132 RTCPeerConnectionHandler
* pc_handler
,
133 WebKit::WebRTCPeerConnectionHandlerClient::ICEGatheringState state
);
135 // Sends an update when the SetSessionDescription or CreateOffer or
136 // CreateAnswer callbacks are called.
137 virtual void TrackSessionDescriptionCallback(
138 RTCPeerConnectionHandler
* pc_handler
, Action action
,
139 const std::string
& type
, const std::string
& value
);
141 // Sends an update when onRenegotiationNeeded is called.
142 virtual void TrackOnRenegotiationNeeded(RTCPeerConnectionHandler
* pc_handler
);
144 // Sends an update when a DTMFSender is created.
145 virtual void TrackCreateDTMFSender(
146 RTCPeerConnectionHandler
* pc_handler
,
147 const WebKit::WebMediaStreamTrack
& track
);
150 // Assign a local ID to a peer connection so that the browser process can
151 // uniquely identify a peer connection in the renderer process.
152 int GetNextLocalID();
154 // IPC Message handler for getting all stats.
155 void OnGetAllStats();
157 void SendPeerConnectionUpdate(RTCPeerConnectionHandler
* pc_handler
,
158 const std::string
& callback_type
,
159 const std::string
& value
);
161 // This map stores the local ID assigned to each RTCPeerConnectionHandler.
162 typedef std::map
<RTCPeerConnectionHandler
*, int> PeerConnectionIdMap
;
163 PeerConnectionIdMap peer_connection_id_map_
;
165 // This keeps track of the next available local ID.
168 DISALLOW_COPY_AND_ASSIGN(PeerConnectionTracker
);
171 } // namespace content
173 #endif // CONTENT_RENDERER_MEDIA_PEERCONNECTION_TRACKER_H_