henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 11 | #ifndef WEBRTC_API_PEERCONNECTION_H_ |
| 12 | #define WEBRTC_API_PEERCONNECTION_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 13 | |
| 14 | #include <string> |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 15 | #include <map> |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 16 | #include <memory> |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 17 | #include <vector> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 18 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 19 | #include "webrtc/api/peerconnectionfactory.h" |
| 20 | #include "webrtc/api/peerconnectioninterface.h" |
hbos | 74e1a4f | 2016-09-15 23:33:01 -0700 | [diff] [blame] | 21 | #include "webrtc/api/rtcstatscollector.h" |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 22 | #include "webrtc/api/rtpreceiver.h" |
| 23 | #include "webrtc/api/rtpsender.h" |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 24 | #include "webrtc/api/statscollector.h" |
| 25 | #include "webrtc/api/streamcollection.h" |
| 26 | #include "webrtc/api/webrtcsession.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 27 | |
| 28 | namespace webrtc { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 29 | |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 30 | class MediaStreamObserver; |
perkj | f0dcfe2 | 2016-03-10 18:32:00 +0100 | [diff] [blame] | 31 | class VideoRtpReceiver; |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 32 | class RtcEventLog; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 33 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 34 | // Populates |session_options| from |rtc_options|, and returns true if options |
| 35 | // are valid. |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 36 | // |session_options|->transport_options map entries must exist in order for |
| 37 | // them to be populated from |rtc_options|. |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 38 | bool ExtractMediaSessionOptions( |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 39 | const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, |
hta | aac2dea | 2016-03-10 13:35:55 -0800 | [diff] [blame] | 40 | bool is_offer, |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 41 | cricket::MediaSessionOptions* session_options); |
| 42 | |
| 43 | // Populates |session_options| from |constraints|, and returns true if all |
| 44 | // mandatory constraints are satisfied. |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 45 | // Assumes that |session_options|->transport_options map entries exist. |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 46 | // Will also set defaults if corresponding constraints are not present: |
| 47 | // recv_audio=true, recv_video=true, bundle_enabled=true. |
| 48 | // Other fields will be left with existing values. |
| 49 | // |
| 50 | // Deprecated. Will be removed once callers that use constraints are gone. |
| 51 | // TODO(hta): Remove when callers are gone. |
| 52 | // https://bugs.chromium.org/p/webrtc/issues/detail?id=5617 |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 53 | bool ParseConstraintsForAnswer(const MediaConstraintsInterface* constraints, |
| 54 | cricket::MediaSessionOptions* session_options); |
| 55 | |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 56 | // Parses the URLs for each server in |servers| to build |stun_servers| and |
| 57 | // |turn_servers|. |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 58 | bool ParseIceServers(const PeerConnectionInterface::IceServers& servers, |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 59 | cricket::ServerAddresses* stun_servers, |
| 60 | std::vector<cricket::RelayServerConfig>* turn_servers); |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 61 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 62 | // PeerConnection implements the PeerConnectionInterface interface. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 63 | // It uses WebRtcSession to implement the PeerConnection functionality. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 64 | class PeerConnection : public PeerConnectionInterface, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 65 | public IceObserver, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 66 | public rtc::MessageHandler, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 67 | public sigslot::has_slots<> { |
| 68 | public: |
| 69 | explicit PeerConnection(PeerConnectionFactory* factory); |
| 70 | |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 71 | bool Initialize( |
| 72 | const PeerConnectionInterface::RTCConfiguration& configuration, |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 73 | std::unique_ptr<cricket::PortAllocator> allocator, |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame] | 74 | std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 75 | PeerConnectionObserver* observer); |
| 76 | |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 77 | rtc::scoped_refptr<StreamCollectionInterface> local_streams() override; |
| 78 | rtc::scoped_refptr<StreamCollectionInterface> remote_streams() override; |
| 79 | bool AddStream(MediaStreamInterface* local_stream) override; |
| 80 | void RemoveStream(MediaStreamInterface* local_stream) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 81 | |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 82 | rtc::scoped_refptr<RtpSenderInterface> AddTrack( |
| 83 | MediaStreamTrackInterface* track, |
| 84 | std::vector<MediaStreamInterface*> streams) override; |
| 85 | bool RemoveTrack(RtpSenderInterface* sender) override; |
| 86 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 87 | virtual WebRtcSession* session() { return session_.get(); } |
| 88 | |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 89 | rtc::scoped_refptr<DtmfSenderInterface> CreateDtmfSender( |
| 90 | AudioTrackInterface* track) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 91 | |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 92 | rtc::scoped_refptr<RtpSenderInterface> CreateSender( |
deadbeef | bd7d8f7 | 2015-12-18 16:58:44 -0800 | [diff] [blame] | 93 | const std::string& kind, |
| 94 | const std::string& stream_id) override; |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 95 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 96 | std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders() |
| 97 | const override; |
| 98 | std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers() |
| 99 | const override; |
| 100 | |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 101 | rtc::scoped_refptr<DataChannelInterface> CreateDataChannel( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 102 | const std::string& label, |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 103 | const DataChannelInit* config) override; |
| 104 | bool GetStats(StatsObserver* observer, |
| 105 | webrtc::MediaStreamTrackInterface* track, |
| 106 | StatsOutputLevel level) override; |
hbos | 74e1a4f | 2016-09-15 23:33:01 -0700 | [diff] [blame] | 107 | void GetStats(RTCStatsCollectorCallback* callback) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 108 | |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 109 | SignalingState signaling_state() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 110 | |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 111 | IceConnectionState ice_connection_state() override; |
| 112 | IceGatheringState ice_gathering_state() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 113 | |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 114 | const SessionDescriptionInterface* local_description() const override; |
| 115 | const SessionDescriptionInterface* remote_description() const override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 116 | |
| 117 | // JSEP01 |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 118 | // Deprecated, use version without constraints. |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 119 | void CreateOffer(CreateSessionDescriptionObserver* observer, |
| 120 | const MediaConstraintsInterface* constraints) override; |
| 121 | void CreateOffer(CreateSessionDescriptionObserver* observer, |
| 122 | const RTCOfferAnswerOptions& options) override; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 123 | // Deprecated, use version without constraints. |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 124 | void CreateAnswer(CreateSessionDescriptionObserver* observer, |
| 125 | const MediaConstraintsInterface* constraints) override; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 126 | void CreateAnswer(CreateSessionDescriptionObserver* observer, |
| 127 | const RTCOfferAnswerOptions& options) override; |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 128 | void SetLocalDescription(SetSessionDescriptionObserver* observer, |
| 129 | SessionDescriptionInterface* desc) override; |
| 130 | void SetRemoteDescription(SetSessionDescriptionObserver* observer, |
| 131 | SessionDescriptionInterface* desc) override; |
deadbeef | 46c7389 | 2016-11-16 19:42:04 -0800 | [diff] [blame^] | 132 | PeerConnectionInterface::RTCConfiguration GetConfiguration() override; |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 133 | bool SetConfiguration( |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 134 | const PeerConnectionInterface::RTCConfiguration& configuration) override; |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 135 | bool AddIceCandidate(const IceCandidateInterface* candidate) override; |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 136 | bool RemoveIceCandidates( |
| 137 | const std::vector<cricket::Candidate>& candidates) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 138 | |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 139 | void RegisterUMAObserver(UMAObserver* observer) override; |
buildbot@webrtc.org | 1567b8c | 2014-05-08 19:54:16 +0000 | [diff] [blame] | 140 | |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 141 | bool StartRtcEventLog(rtc::PlatformFile file, |
| 142 | int64_t max_size_bytes) override; |
| 143 | void StopRtcEventLog() override; |
| 144 | |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 145 | void Close() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 146 | |
hbos | 82ebe02 | 2016-11-14 01:41:09 -0800 | [diff] [blame] | 147 | sigslot::signal1<DataChannel*> SignalDataChannelCreated; |
| 148 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 149 | // Virtual for unit tests. |
| 150 | virtual const std::vector<rtc::scoped_refptr<DataChannel>>& |
| 151 | sctp_data_channels() const { |
| 152 | return sctp_data_channels_; |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 153 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 154 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 155 | protected: |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 156 | ~PeerConnection() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 157 | |
| 158 | private: |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 159 | struct TrackInfo { |
| 160 | TrackInfo() : ssrc(0) {} |
| 161 | TrackInfo(const std::string& stream_label, |
| 162 | const std::string track_id, |
| 163 | uint32_t ssrc) |
| 164 | : stream_label(stream_label), track_id(track_id), ssrc(ssrc) {} |
deadbeef | bda7e0b | 2015-12-08 17:13:40 -0800 | [diff] [blame] | 165 | bool operator==(const TrackInfo& other) { |
| 166 | return this->stream_label == other.stream_label && |
| 167 | this->track_id == other.track_id && this->ssrc == other.ssrc; |
| 168 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 169 | std::string stream_label; |
| 170 | std::string track_id; |
| 171 | uint32_t ssrc; |
| 172 | }; |
| 173 | typedef std::vector<TrackInfo> TrackInfos; |
| 174 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 175 | // Implements MessageHandler. |
deadbeef | a67696b | 2015-09-29 11:56:26 -0700 | [diff] [blame] | 176 | void OnMessage(rtc::Message* msg) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 177 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 178 | void CreateAudioReceiver(MediaStreamInterface* stream, |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 179 | const std::string& track_id, |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 180 | uint32_t ssrc); |
perkj | f0dcfe2 | 2016-03-10 18:32:00 +0100 | [diff] [blame] | 181 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 182 | void CreateVideoReceiver(MediaStreamInterface* stream, |
perkj | f0dcfe2 | 2016-03-10 18:32:00 +0100 | [diff] [blame] | 183 | const std::string& track_id, |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 184 | uint32_t ssrc); |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 185 | void DestroyReceiver(const std::string& track_id); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 186 | void DestroyAudioSender(MediaStreamInterface* stream, |
| 187 | AudioTrackInterface* audio_track, |
| 188 | uint32_t ssrc); |
| 189 | void DestroyVideoSender(MediaStreamInterface* stream, |
| 190 | VideoTrackInterface* video_track); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 191 | |
| 192 | // Implements IceObserver |
Peter Thatcher | 5436051 | 2015-07-08 11:08:35 -0700 | [diff] [blame] | 193 | void OnIceConnectionChange(IceConnectionState new_state) override; |
| 194 | void OnIceGatheringChange(IceGatheringState new_state) override; |
| 195 | void OnIceCandidate(const IceCandidateInterface* candidate) override; |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 196 | void OnIceCandidatesRemoved( |
| 197 | const std::vector<cricket::Candidate>& candidates) override; |
Peter Thatcher | 5436051 | 2015-07-08 11:08:35 -0700 | [diff] [blame] | 198 | void OnIceConnectionReceivingChange(bool receiving) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 199 | |
| 200 | // Signals from WebRtcSession. |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 201 | void OnSessionStateChange(WebRtcSession* session, WebRtcSession::State state); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 202 | void ChangeSignalingState(SignalingState signaling_state); |
| 203 | |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 204 | // Signals from MediaStreamObserver. |
| 205 | void OnAudioTrackAdded(AudioTrackInterface* track, |
| 206 | MediaStreamInterface* stream); |
| 207 | void OnAudioTrackRemoved(AudioTrackInterface* track, |
| 208 | MediaStreamInterface* stream); |
| 209 | void OnVideoTrackAdded(VideoTrackInterface* track, |
| 210 | MediaStreamInterface* stream); |
| 211 | void OnVideoTrackRemoved(VideoTrackInterface* track, |
| 212 | MediaStreamInterface* stream); |
| 213 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 214 | rtc::Thread* signaling_thread() const { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 215 | return factory_->signaling_thread(); |
| 216 | } |
| 217 | |
deadbeef | 91dd567 | 2016-05-18 16:55:30 -0700 | [diff] [blame] | 218 | rtc::Thread* network_thread() const { return factory_->network_thread(); } |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 219 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 220 | void PostSetSessionDescriptionFailure(SetSessionDescriptionObserver* observer, |
| 221 | const std::string& error); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 222 | void PostCreateSessionDescriptionFailure( |
| 223 | CreateSessionDescriptionObserver* observer, |
| 224 | const std::string& error); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 225 | |
| 226 | bool IsClosed() const { |
| 227 | return signaling_state_ == PeerConnectionInterface::kClosed; |
| 228 | } |
| 229 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 230 | // Returns a MediaSessionOptions struct with options decided by |options|, |
| 231 | // the local MediaStreams and DataChannels. |
| 232 | virtual bool GetOptionsForOffer( |
| 233 | const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, |
| 234 | cricket::MediaSessionOptions* session_options); |
| 235 | |
| 236 | // Returns a MediaSessionOptions struct with options decided by |
| 237 | // |constraints|, the local MediaStreams and DataChannels. |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 238 | // Deprecated, use version without constraints. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 239 | virtual bool GetOptionsForAnswer( |
| 240 | const MediaConstraintsInterface* constraints, |
| 241 | cricket::MediaSessionOptions* session_options); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 242 | virtual bool GetOptionsForAnswer( |
| 243 | const RTCOfferAnswerOptions& options, |
| 244 | cricket::MediaSessionOptions* session_options); |
| 245 | |
Honghai Zhang | 4cedf2b | 2016-08-31 08:18:11 -0700 | [diff] [blame] | 246 | void InitializeOptionsForAnswer( |
| 247 | cricket::MediaSessionOptions* session_options); |
| 248 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 249 | // Helper function for options processing. |
| 250 | // Deprecated. |
| 251 | virtual void FinishOptionsForAnswer( |
| 252 | cricket::MediaSessionOptions* session_options); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 253 | |
deadbeef | faac497 | 2015-11-12 15:33:07 -0800 | [diff] [blame] | 254 | // Remove all local and remote tracks of type |media_type|. |
| 255 | // Called when a media type is rejected (m-line set to port 0). |
| 256 | void RemoveTracks(cricket::MediaType media_type); |
| 257 | |
deadbeef | bda7e0b | 2015-12-08 17:13:40 -0800 | [diff] [blame] | 258 | // Makes sure a MediaStreamTrack is created for each StreamParam in |streams|, |
| 259 | // and existing MediaStreamTracks are removed if there is no corresponding |
| 260 | // StreamParam. If |default_track_needed| is true, a default MediaStreamTrack |
| 261 | // is created if it doesn't exist; if false, it's removed if it exists. |
| 262 | // |media_type| is the type of the |streams| and can be either audio or video. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 263 | // If a new MediaStream is created it is added to |new_streams|. |
| 264 | void UpdateRemoteStreamsList( |
| 265 | const std::vector<cricket::StreamParams>& streams, |
deadbeef | bda7e0b | 2015-12-08 17:13:40 -0800 | [diff] [blame] | 266 | bool default_track_needed, |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 267 | cricket::MediaType media_type, |
| 268 | StreamCollection* new_streams); |
| 269 | |
| 270 | // Triggered when a remote track has been seen for the first time in a remote |
| 271 | // session description. It creates a remote MediaStreamTrackInterface |
| 272 | // implementation and triggers CreateAudioReceiver or CreateVideoReceiver. |
| 273 | void OnRemoteTrackSeen(const std::string& stream_label, |
| 274 | const std::string& track_id, |
| 275 | uint32_t ssrc, |
| 276 | cricket::MediaType media_type); |
| 277 | |
| 278 | // Triggered when a remote track has been removed from a remote session |
| 279 | // description. It removes the remote track with id |track_id| from a remote |
| 280 | // MediaStream and triggers DestroyAudioReceiver or DestroyVideoReceiver. |
| 281 | void OnRemoteTrackRemoved(const std::string& stream_label, |
| 282 | const std::string& track_id, |
| 283 | cricket::MediaType media_type); |
| 284 | |
| 285 | // Finds remote MediaStreams without any tracks and removes them from |
| 286 | // |remote_streams_| and notifies the observer that the MediaStreams no longer |
| 287 | // exist. |
| 288 | void UpdateEndedRemoteMediaStreams(); |
| 289 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 290 | // Loops through the vector of |streams| and finds added and removed |
| 291 | // StreamParams since last time this method was called. |
| 292 | // For each new or removed StreamParam, OnLocalTrackSeen or |
| 293 | // OnLocalTrackRemoved is invoked. |
| 294 | void UpdateLocalTracks(const std::vector<cricket::StreamParams>& streams, |
| 295 | cricket::MediaType media_type); |
| 296 | |
| 297 | // Triggered when a local track has been seen for the first time in a local |
| 298 | // session description. |
| 299 | // This method triggers CreateAudioSender or CreateVideoSender if the rtp |
| 300 | // streams in the local SessionDescription can be mapped to a MediaStreamTrack |
| 301 | // in a MediaStream in |local_streams_| |
| 302 | void OnLocalTrackSeen(const std::string& stream_label, |
| 303 | const std::string& track_id, |
| 304 | uint32_t ssrc, |
| 305 | cricket::MediaType media_type); |
| 306 | |
| 307 | // Triggered when a local track has been removed from a local session |
| 308 | // description. |
| 309 | // This method triggers DestroyAudioSender or DestroyVideoSender if a stream |
| 310 | // has been removed from the local SessionDescription and the stream can be |
| 311 | // mapped to a MediaStreamTrack in a MediaStream in |local_streams_|. |
| 312 | void OnLocalTrackRemoved(const std::string& stream_label, |
| 313 | const std::string& track_id, |
| 314 | uint32_t ssrc, |
| 315 | cricket::MediaType media_type); |
| 316 | |
| 317 | void UpdateLocalRtpDataChannels(const cricket::StreamParamsVec& streams); |
| 318 | void UpdateRemoteRtpDataChannels(const cricket::StreamParamsVec& streams); |
| 319 | void UpdateClosingRtpDataChannels( |
| 320 | const std::vector<std::string>& active_channels, |
| 321 | bool is_local_update); |
| 322 | void CreateRemoteRtpDataChannel(const std::string& label, |
| 323 | uint32_t remote_ssrc); |
| 324 | |
| 325 | // Creates channel and adds it to the collection of DataChannels that will |
| 326 | // be offered in a SessionDescription. |
| 327 | rtc::scoped_refptr<DataChannel> InternalCreateDataChannel( |
| 328 | const std::string& label, |
| 329 | const InternalDataChannelInit* config); |
| 330 | |
| 331 | // Checks if any data channel has been added. |
| 332 | bool HasDataChannels() const; |
| 333 | |
| 334 | void AllocateSctpSids(rtc::SSLRole role); |
| 335 | void OnSctpDataChannelClosed(DataChannel* channel); |
| 336 | |
| 337 | // Notifications from WebRtcSession relating to BaseChannels. |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 338 | void OnVoiceChannelCreated(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 339 | void OnVoiceChannelDestroyed(); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 340 | void OnVideoChannelCreated(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 341 | void OnVideoChannelDestroyed(); |
| 342 | void OnDataChannelCreated(); |
| 343 | void OnDataChannelDestroyed(); |
| 344 | // Called when the cricket::DataChannel receives a message indicating that a |
| 345 | // webrtc::DataChannel should be opened. |
| 346 | void OnDataChannelOpenMessage(const std::string& label, |
| 347 | const InternalDataChannelInit& config); |
| 348 | |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 349 | RtpSenderInternal* FindSenderById(const std::string& id); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 350 | |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 351 | std::vector<rtc::scoped_refptr< |
| 352 | RtpSenderProxyWithInternal<RtpSenderInternal>>>::iterator |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 353 | FindSenderForTrack(MediaStreamTrackInterface* track); |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 354 | std::vector<rtc::scoped_refptr< |
| 355 | RtpReceiverProxyWithInternal<RtpReceiverInternal>>>::iterator |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 356 | FindReceiverForTrack(const std::string& track_id); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 357 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 358 | TrackInfos* GetRemoteTracks(cricket::MediaType media_type); |
| 359 | TrackInfos* GetLocalTracks(cricket::MediaType media_type); |
| 360 | const TrackInfo* FindTrackInfo(const TrackInfos& infos, |
| 361 | const std::string& stream_label, |
| 362 | const std::string track_id) const; |
| 363 | |
| 364 | // Returns the specified SCTP DataChannel in sctp_data_channels_, |
| 365 | // or nullptr if not found. |
| 366 | DataChannel* FindDataChannelBySid(int sid) const; |
| 367 | |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 368 | // Called when first configuring the port allocator. |
deadbeef | 91dd567 | 2016-05-18 16:55:30 -0700 | [diff] [blame] | 369 | bool InitializePortAllocator_n(const RTCConfiguration& configuration); |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 370 | // Called when SetConfiguration is called. Only a subset of the configuration |
| 371 | // is applied. |
deadbeef | 91dd567 | 2016-05-18 16:55:30 -0700 | [diff] [blame] | 372 | bool ReconfigurePortAllocator_n(const RTCConfiguration& configuration); |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 373 | |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 374 | // Starts recording an Rtc EventLog using the supplied platform file. |
| 375 | // This function should only be called from the worker thread. |
| 376 | bool StartRtcEventLog_w(rtc::PlatformFile file, int64_t max_size_bytes); |
| 377 | // Starts recording an Rtc EventLog using the supplied platform file. |
| 378 | // This function should only be called from the worker thread. |
| 379 | void StopRtcEventLog_w(); |
| 380 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 381 | // Storing the factory as a scoped reference pointer ensures that the memory |
| 382 | // in the PeerConnectionFactoryImpl remains available as long as the |
| 383 | // PeerConnection is running. It is passed to PeerConnection as a raw pointer. |
| 384 | // However, since the reference counting is done in the |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 385 | // PeerConnectionFactoryInterface all instances created using the raw pointer |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 386 | // will refer to the same reference count. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 387 | rtc::scoped_refptr<PeerConnectionFactory> factory_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 388 | PeerConnectionObserver* observer_; |
buildbot@webrtc.org | 1567b8c | 2014-05-08 19:54:16 +0000 | [diff] [blame] | 389 | UMAObserver* uma_observer_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 390 | SignalingState signaling_state_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 391 | IceConnectionState ice_connection_state_; |
| 392 | IceGatheringState ice_gathering_state_; |
deadbeef | 46c7389 | 2016-11-16 19:42:04 -0800 | [diff] [blame^] | 393 | PeerConnectionInterface::RTCConfiguration configuration_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 394 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 395 | std::unique_ptr<cricket::PortAllocator> port_allocator_; |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 396 | // The EventLog needs to outlive the media controller. |
| 397 | std::unique_ptr<RtcEventLog> event_log_; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 398 | std::unique_ptr<MediaControllerInterface> media_controller_; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 399 | |
zhihuang | 8f65cdf | 2016-05-06 18:40:30 -0700 | [diff] [blame] | 400 | // One PeerConnection has only one RTCP CNAME. |
| 401 | // https://tools.ietf.org/html/draft-ietf-rtcweb-rtp-usage-26#section-4.9 |
| 402 | std::string rtcp_cname_; |
| 403 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 404 | // Streams added via AddStream. |
| 405 | rtc::scoped_refptr<StreamCollection> local_streams_; |
| 406 | // Streams created as a result of SetRemoteDescription. |
| 407 | rtc::scoped_refptr<StreamCollection> remote_streams_; |
| 408 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 409 | std::vector<std::unique_ptr<MediaStreamObserver>> stream_observers_; |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 410 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 411 | // These lists store track info seen in local/remote descriptions. |
| 412 | TrackInfos remote_audio_tracks_; |
| 413 | TrackInfos remote_video_tracks_; |
| 414 | TrackInfos local_audio_tracks_; |
| 415 | TrackInfos local_video_tracks_; |
| 416 | |
| 417 | SctpSidAllocator sid_allocator_; |
| 418 | // label -> DataChannel |
| 419 | std::map<std::string, rtc::scoped_refptr<DataChannel>> rtp_data_channels_; |
| 420 | std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_; |
deadbeef | bd29246 | 2015-12-14 18:15:29 -0800 | [diff] [blame] | 421 | std::vector<rtc::scoped_refptr<DataChannel>> sctp_data_channels_to_free_; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 422 | |
deadbeef | bda7e0b | 2015-12-08 17:13:40 -0800 | [diff] [blame] | 423 | bool remote_peer_supports_msid_ = false; |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 424 | |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 425 | std::vector<rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>>> |
| 426 | senders_; |
| 427 | std::vector< |
| 428 | rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>>> |
| 429 | receivers_; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 430 | std::unique_ptr<WebRtcSession> session_; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 431 | std::unique_ptr<StatsCollector> stats_; |
hbos | 74e1a4f | 2016-09-15 23:33:01 -0700 | [diff] [blame] | 432 | rtc::scoped_refptr<RTCStatsCollector> stats_collector_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 433 | }; |
| 434 | |
| 435 | } // namespace webrtc |
| 436 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 437 | #endif // WEBRTC_API_PEERCONNECTION_H_ |