OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_API_PEERCONNECTION_H_ | 11 #ifndef WEBRTC_API_PEERCONNECTION_H_ |
12 #define WEBRTC_API_PEERCONNECTION_H_ | 12 #define WEBRTC_API_PEERCONNECTION_H_ |
13 | 13 |
14 #include <string> | 14 #include <string> |
| 15 #include <map> |
| 16 #include <vector> |
15 | 17 |
16 #include "webrtc/api/dtlsidentitystore.h" | 18 #include "webrtc/api/dtlsidentitystore.h" |
17 #include "webrtc/api/peerconnectionfactory.h" | 19 #include "webrtc/api/peerconnectionfactory.h" |
18 #include "webrtc/api/peerconnectioninterface.h" | 20 #include "webrtc/api/peerconnectioninterface.h" |
19 #include "webrtc/api/rtpreceiverinterface.h" | 21 #include "webrtc/api/rtpreceiverinterface.h" |
20 #include "webrtc/api/rtpsenderinterface.h" | 22 #include "webrtc/api/rtpsenderinterface.h" |
21 #include "webrtc/api/statscollector.h" | 23 #include "webrtc/api/statscollector.h" |
22 #include "webrtc/api/streamcollection.h" | 24 #include "webrtc/api/streamcollection.h" |
23 #include "webrtc/api/webrtcsession.h" | 25 #include "webrtc/api/webrtcsession.h" |
24 #include "webrtc/base/scoped_ptr.h" | 26 #include "webrtc/base/scoped_ptr.h" |
25 | 27 |
26 namespace webrtc { | 28 namespace webrtc { |
27 | 29 |
28 class MediaStreamObserver; | 30 class MediaStreamObserver; |
29 class RemoteMediaStreamFactory; | |
30 class VideoRtpReceiver; | 31 class VideoRtpReceiver; |
31 | 32 |
32 // Populates |session_options| from |rtc_options|, and returns true if options | 33 // Populates |session_options| from |rtc_options|, and returns true if options |
33 // are valid. | 34 // are valid. |
34 // |session_options|->transport_options map entries must exist in order for | 35 // |session_options|->transport_options map entries must exist in order for |
35 // them to be populated from |rtc_options|. | 36 // them to be populated from |rtc_options|. |
36 bool ExtractMediaSessionOptions( | 37 bool ExtractMediaSessionOptions( |
37 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, | 38 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, |
38 bool is_offer, | 39 bool is_offer, |
39 cricket::MediaSessionOptions* session_options); | 40 cricket::MediaSessionOptions* session_options); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 const std::vector<cricket::Candidate>& candidates) override; | 137 const std::vector<cricket::Candidate>& candidates) override; |
137 | 138 |
138 void RegisterUMAObserver(UMAObserver* observer) override; | 139 void RegisterUMAObserver(UMAObserver* observer) override; |
139 | 140 |
140 void Close() override; | 141 void Close() override; |
141 | 142 |
142 // Virtual for unit tests. | 143 // Virtual for unit tests. |
143 virtual const std::vector<rtc::scoped_refptr<DataChannel>>& | 144 virtual const std::vector<rtc::scoped_refptr<DataChannel>>& |
144 sctp_data_channels() const { | 145 sctp_data_channels() const { |
145 return sctp_data_channels_; | 146 return sctp_data_channels_; |
146 }; | 147 } |
147 | 148 |
148 protected: | 149 protected: |
149 ~PeerConnection() override; | 150 ~PeerConnection() override; |
150 | 151 |
151 private: | 152 private: |
152 struct TrackInfo { | 153 struct TrackInfo { |
153 TrackInfo() : ssrc(0) {} | 154 TrackInfo() : ssrc(0) {} |
154 TrackInfo(const std::string& stream_label, | 155 TrackInfo(const std::string& stream_label, |
155 const std::string track_id, | 156 const std::string track_id, |
156 uint32_t ssrc) | 157 uint32_t ssrc) |
157 : stream_label(stream_label), track_id(track_id), ssrc(ssrc) {} | 158 : stream_label(stream_label), track_id(track_id), ssrc(ssrc) {} |
158 bool operator==(const TrackInfo& other) { | 159 bool operator==(const TrackInfo& other) { |
159 return this->stream_label == other.stream_label && | 160 return this->stream_label == other.stream_label && |
160 this->track_id == other.track_id && this->ssrc == other.ssrc; | 161 this->track_id == other.track_id && this->ssrc == other.ssrc; |
161 } | 162 } |
162 std::string stream_label; | 163 std::string stream_label; |
163 std::string track_id; | 164 std::string track_id; |
164 uint32_t ssrc; | 165 uint32_t ssrc; |
165 }; | 166 }; |
166 typedef std::vector<TrackInfo> TrackInfos; | 167 typedef std::vector<TrackInfo> TrackInfos; |
167 | 168 |
168 // Implements MessageHandler. | 169 // Implements MessageHandler. |
169 void OnMessage(rtc::Message* msg) override; | 170 void OnMessage(rtc::Message* msg) override; |
170 | 171 |
171 void CreateAudioReceiver(MediaStreamInterface* stream, | 172 void CreateAudioReceiver(MediaStreamInterface* stream, |
172 AudioTrackInterface* audio_track, | 173 const std::string& track_id, |
173 uint32_t ssrc); | 174 uint32_t ssrc); |
174 | 175 |
175 void CreateVideoReceiver(MediaStreamInterface* stream, | 176 void CreateVideoReceiver(MediaStreamInterface* stream, |
176 const std::string& track_id, | 177 const std::string& track_id, |
177 uint32_t ssrc); | 178 uint32_t ssrc); |
178 void DestroyAudioReceiver(MediaStreamInterface* stream, | 179 void StopReceivers(cricket::MediaType media_type); |
179 AudioTrackInterface* audio_track); | 180 void DestroyReceiver(const std::string& track_id); |
180 void DestroyVideoReceiver(MediaStreamInterface* stream, | |
181 VideoTrackInterface* video_track); | |
182 void DestroyAudioSender(MediaStreamInterface* stream, | 181 void DestroyAudioSender(MediaStreamInterface* stream, |
183 AudioTrackInterface* audio_track, | 182 AudioTrackInterface* audio_track, |
184 uint32_t ssrc); | 183 uint32_t ssrc); |
185 void DestroyVideoSender(MediaStreamInterface* stream, | 184 void DestroyVideoSender(MediaStreamInterface* stream, |
186 VideoTrackInterface* video_track); | 185 VideoTrackInterface* video_track); |
187 | 186 |
188 // Implements IceObserver | 187 // Implements IceObserver |
189 void OnIceConnectionChange(IceConnectionState new_state) override; | 188 void OnIceConnectionChange(IceConnectionState new_state) override; |
190 void OnIceGatheringChange(IceGatheringState new_state) override; | 189 void OnIceGatheringChange(IceGatheringState new_state) override; |
191 void OnIceCandidate(const IceCandidateInterface* candidate) override; | 190 void OnIceCandidate(const IceCandidateInterface* candidate) override; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 // MediaStream and triggers DestroyAudioReceiver or DestroyVideoReceiver. | 270 // MediaStream and triggers DestroyAudioReceiver or DestroyVideoReceiver. |
272 void OnRemoteTrackRemoved(const std::string& stream_label, | 271 void OnRemoteTrackRemoved(const std::string& stream_label, |
273 const std::string& track_id, | 272 const std::string& track_id, |
274 cricket::MediaType media_type); | 273 cricket::MediaType media_type); |
275 | 274 |
276 // Finds remote MediaStreams without any tracks and removes them from | 275 // Finds remote MediaStreams without any tracks and removes them from |
277 // |remote_streams_| and notifies the observer that the MediaStreams no longer | 276 // |remote_streams_| and notifies the observer that the MediaStreams no longer |
278 // exist. | 277 // exist. |
279 void UpdateEndedRemoteMediaStreams(); | 278 void UpdateEndedRemoteMediaStreams(); |
280 | 279 |
281 // Set the MediaStreamTrackInterface::TrackState to |kEnded| on all remote | |
282 // tracks of type |media_type|. | |
283 void EndRemoteTracks(cricket::MediaType media_type); | |
284 | |
285 // Loops through the vector of |streams| and finds added and removed | 280 // Loops through the vector of |streams| and finds added and removed |
286 // StreamParams since last time this method was called. | 281 // StreamParams since last time this method was called. |
287 // For each new or removed StreamParam, OnLocalTrackSeen or | 282 // For each new or removed StreamParam, OnLocalTrackSeen or |
288 // OnLocalTrackRemoved is invoked. | 283 // OnLocalTrackRemoved is invoked. |
289 void UpdateLocalTracks(const std::vector<cricket::StreamParams>& streams, | 284 void UpdateLocalTracks(const std::vector<cricket::StreamParams>& streams, |
290 cricket::MediaType media_type); | 285 cricket::MediaType media_type); |
291 | 286 |
292 // Triggered when a local track has been seen for the first time in a local | 287 // Triggered when a local track has been seen for the first time in a local |
293 // session description. | 288 // session description. |
294 // This method triggers CreateAudioSender or CreateVideoSender if the rtp | 289 // This method triggers CreateAudioSender or CreateVideoSender if the rtp |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 // Called when the cricket::DataChannel receives a message indicating that a | 332 // Called when the cricket::DataChannel receives a message indicating that a |
338 // webrtc::DataChannel should be opened. | 333 // webrtc::DataChannel should be opened. |
339 void OnDataChannelOpenMessage(const std::string& label, | 334 void OnDataChannelOpenMessage(const std::string& label, |
340 const InternalDataChannelInit& config); | 335 const InternalDataChannelInit& config); |
341 | 336 |
342 RtpSenderInterface* FindSenderById(const std::string& id); | 337 RtpSenderInterface* FindSenderById(const std::string& id); |
343 | 338 |
344 std::vector<rtc::scoped_refptr<RtpSenderInterface>>::iterator | 339 std::vector<rtc::scoped_refptr<RtpSenderInterface>>::iterator |
345 FindSenderForTrack(MediaStreamTrackInterface* track); | 340 FindSenderForTrack(MediaStreamTrackInterface* track); |
346 std::vector<rtc::scoped_refptr<RtpReceiverInterface>>::iterator | 341 std::vector<rtc::scoped_refptr<RtpReceiverInterface>>::iterator |
347 FindReceiverForTrack(MediaStreamTrackInterface* track); | 342 FindReceiverForTrack(const std::string& track_id); |
348 | 343 |
349 TrackInfos* GetRemoteTracks(cricket::MediaType media_type); | 344 TrackInfos* GetRemoteTracks(cricket::MediaType media_type); |
350 TrackInfos* GetLocalTracks(cricket::MediaType media_type); | 345 TrackInfos* GetLocalTracks(cricket::MediaType media_type); |
351 const TrackInfo* FindTrackInfo(const TrackInfos& infos, | 346 const TrackInfo* FindTrackInfo(const TrackInfos& infos, |
352 const std::string& stream_label, | 347 const std::string& stream_label, |
353 const std::string track_id) const; | 348 const std::string track_id) const; |
354 | 349 |
355 // Returns the specified SCTP DataChannel in sctp_data_channels_, | 350 // Returns the specified SCTP DataChannel in sctp_data_channels_, |
356 // or nullptr if not found. | 351 // or nullptr if not found. |
357 DataChannel* FindDataChannelBySid(int sid) const; | 352 DataChannel* FindDataChannelBySid(int sid) const; |
(...skipping 29 matching lines...) Expand all Loading... |
387 TrackInfos local_audio_tracks_; | 382 TrackInfos local_audio_tracks_; |
388 TrackInfos local_video_tracks_; | 383 TrackInfos local_video_tracks_; |
389 | 384 |
390 SctpSidAllocator sid_allocator_; | 385 SctpSidAllocator sid_allocator_; |
391 // label -> DataChannel | 386 // label -> DataChannel |
392 std::map<std::string, rtc::scoped_refptr<DataChannel>> rtp_data_channels_; | 387 std::map<std::string, rtc::scoped_refptr<DataChannel>> rtp_data_channels_; |
393 std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_; | 388 std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_; |
394 std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_to_free_; | 389 std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_to_free_; |
395 | 390 |
396 bool remote_peer_supports_msid_ = false; | 391 bool remote_peer_supports_msid_ = false; |
397 rtc::scoped_ptr<RemoteMediaStreamFactory> remote_stream_factory_; | |
398 | 392 |
399 std::vector<rtc::scoped_refptr<RtpSenderInterface>> senders_; | 393 std::vector<rtc::scoped_refptr<RtpSenderInterface>> senders_; |
400 std::vector<rtc::scoped_refptr<RtpReceiverInterface>> receivers_; | 394 std::vector<rtc::scoped_refptr<RtpReceiverInterface>> receivers_; |
401 | 395 |
402 // The session_ scoped_ptr is declared at the bottom of PeerConnection | 396 // The session_ scoped_ptr is declared at the bottom of PeerConnection |
403 // because its destruction fires signals (such as VoiceChannelDestroyed) | 397 // because its destruction fires signals (such as VoiceChannelDestroyed) |
404 // which will trigger some final actions in PeerConnection... | 398 // which will trigger some final actions in PeerConnection... |
405 rtc::scoped_ptr<WebRtcSession> session_; | 399 rtc::scoped_ptr<WebRtcSession> session_; |
406 // ... But stats_ depends on session_ so it should be destroyed even earlier. | 400 // ... But stats_ depends on session_ so it should be destroyed even earlier. |
407 rtc::scoped_ptr<StatsCollector> stats_; | 401 rtc::scoped_ptr<StatsCollector> stats_; |
408 }; | 402 }; |
409 | 403 |
410 } // namespace webrtc | 404 } // namespace webrtc |
411 | 405 |
412 #endif // WEBRTC_API_PEERCONNECTION_H_ | 406 #endif // WEBRTC_API_PEERCONNECTION_H_ |
OLD | NEW |