1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_RENDERER_MEDIA_PEERCONNECTION_TRACKER_H_
#define CONTENT_RENDERER_MEDIA_PEERCONNECTION_TRACKER_H_
#include <map>
#include "base/compiler_specific.h"
#include "content/public/renderer/render_process_observer.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStream.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebRTCPeerConnectionHandlerClient.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebRTCSessionDescription.h"
#include "third_party/libjingle/source/talk/app/webrtc/peerconnectioninterface.h"
namespace WebKit {
class WebFrame;
class WebRTCICECandidate;
class WebString;
class WebRTCSessionDescription;
} // namespace WebKit
namespace webrtc {
class DataChannelInterface;
} // namespace webrtc
namespace content {
class RTCMediaConstraints;
class RTCPeerConnectionHandler;
// This class collects data about each peer connection,
// sends it to the browser process, and handles messages
// from the browser process.
class CONTENT_EXPORT PeerConnectionTracker : public RenderProcessObserver {
public:
PeerConnectionTracker();
virtual ~PeerConnectionTracker();
enum Source {
SOURCE_LOCAL,
SOURCE_REMOTE
};
enum Action {
ACTION_SET_LOCAL_DESCRIPTION,
ACTION_SET_REMOTE_DESCRIPTION,
ACTION_CREATE_OFFER,
ACTION_CREATE_ANSWER
};
// RenderProcessObserver implementation.
virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE;
//
// The following methods send an update to the browser process when a
// PeerConnection update happens. The caller should call the Track* methods
// after calling RegisterPeerConnection and before calling
// UnregisterPeerConnection, otherwise the Track* call has no effect.
//
// Sends an update when a PeerConnection has been created in Javascript.
// This should be called once and only once for each PeerConnection.
// The |pc_handler| is the handler object associated with the PeerConnection,
// the |servers| are the server configurations used to establish the
// connection, the |constraints| are the media constraints used to initialize
// the PeerConnection, the |frame| is the WebFrame object representing the
// page in which the PeerConnection is created.
void RegisterPeerConnection(
RTCPeerConnectionHandler* pc_handler,
const std::vector<webrtc::PeerConnectionInterface::IceServer>& servers,
const RTCMediaConstraints& constraints,
const WebKit::WebFrame* frame);
// Sends an update when a PeerConnection has been destroyed.
virtual void UnregisterPeerConnection(RTCPeerConnectionHandler* pc_handler);
// Sends an update when createOffer/createAnswer has been called.
// The |pc_handler| is the handler object associated with the PeerConnection,
// the |constraints| is the media constraints used to create the offer/answer.
virtual void TrackCreateOffer(RTCPeerConnectionHandler* pc_handler,
const RTCMediaConstraints& constraints);
virtual void TrackCreateAnswer(RTCPeerConnectionHandler* pc_handler,
const RTCMediaConstraints& constraints);
// Sends an update when setLocalDescription or setRemoteDescription is called.
virtual void TrackSetSessionDescription(
RTCPeerConnectionHandler* pc_handler,
const WebKit::WebRTCSessionDescription& desc, Source source);
// Sends an update when Ice candidates are updated.
virtual void TrackUpdateIce(
RTCPeerConnectionHandler* pc_handler,
const std::vector<webrtc::PeerConnectionInterface::IceServer>& servers,
const RTCMediaConstraints& options);
// Sends an update when an Ice candidate is added.
virtual void TrackAddIceCandidate(
RTCPeerConnectionHandler* pc_handler,
const WebKit::WebRTCICECandidate& candidate, Source source);
// Sends an update when a media stream is added.
virtual void TrackAddStream(
RTCPeerConnectionHandler* pc_handler,
const WebKit::WebMediaStream& stream, Source source);
// Sends an update when a media stream is removed.
virtual void TrackRemoveStream(
RTCPeerConnectionHandler* pc_handler,
const WebKit::WebMediaStream& stream, Source source);
// Sends an update when a DataChannel is created.
virtual void TrackCreateDataChannel(
RTCPeerConnectionHandler* pc_handler,
const webrtc::DataChannelInterface* data_channel, Source source);
// Sends an update when a PeerConnection has been stopped.
virtual void TrackStop(RTCPeerConnectionHandler* pc_handler);
// Sends an update when the signaling state of a PeerConnection has changed.
virtual void TrackSignalingStateChange(
RTCPeerConnectionHandler* pc_handler,
WebKit::WebRTCPeerConnectionHandlerClient::SignalingState state);
// Sends an update when the Ice connection state
// of a PeerConnection has changed.
virtual void TrackIceConnectionStateChange(
RTCPeerConnectionHandler* pc_handler,
WebKit::WebRTCPeerConnectionHandlerClient::ICEConnectionState state);
// Sends an update when the Ice gathering state
// of a PeerConnection has changed.
virtual void TrackIceGatheringStateChange(
RTCPeerConnectionHandler* pc_handler,
WebKit::WebRTCPeerConnectionHandlerClient::ICEGatheringState state);
// Sends an update when the SetSessionDescription or CreateOffer or
// CreateAnswer callbacks are called.
virtual void TrackSessionDescriptionCallback(
RTCPeerConnectionHandler* pc_handler, Action action,
const std::string& type, const std::string& value);
// Sends an update when onRenegotiationNeeded is called.
virtual void TrackOnRenegotiationNeeded(RTCPeerConnectionHandler* pc_handler);
// Sends an update when a DTMFSender is created.
virtual void TrackCreateDTMFSender(
RTCPeerConnectionHandler* pc_handler,
const WebKit::WebMediaStreamTrack& track);
private:
// Assign a local ID to a peer connection so that the browser process can
// uniquely identify a peer connection in the renderer process.
int GetNextLocalID();
// IPC Message handler for getting all stats.
void OnGetAllStats();
void SendPeerConnectionUpdate(RTCPeerConnectionHandler* pc_handler,
const std::string& callback_type,
const std::string& value);
// This map stores the local ID assigned to each RTCPeerConnectionHandler.
typedef std::map<RTCPeerConnectionHandler*, int> PeerConnectionIdMap;
PeerConnectionIdMap peer_connection_id_map_;
// This keeps track of the next available local ID.
int next_lid_;
DISALLOW_COPY_AND_ASSIGN(PeerConnectionTracker);
};
} // namespace content
#endif // CONTENT_RENDERER_MEDIA_PEERCONNECTION_TRACKER_H_
|