Steve Anton | be5e208 | 2018-01-24 23:29:17 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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. |
| 9 | */ |
| 10 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 11 | #ifndef PC_TEST_FAKE_PEER_CONNECTION_BASE_H_ |
| 12 | #define PC_TEST_FAKE_PEER_CONNECTION_BASE_H_ |
Steve Anton | be5e208 | 2018-01-24 23:29:17 | [diff] [blame] | 13 | |
Steve Anton | 5dfde18 | 2018-02-06 18:34:40 | [diff] [blame] | 14 | #include <map> |
Steve Anton | be5e208 | 2018-01-24 23:29:17 | [diff] [blame] | 15 | #include <memory> |
Steve Anton | 5dfde18 | 2018-02-06 18:34:40 | [diff] [blame] | 16 | #include <set> |
Steve Anton | be5e208 | 2018-01-24 23:29:17 | [diff] [blame] | 17 | #include <string> |
| 18 | #include <vector> |
| 19 | |
Harald Alvestrand | 15845af | 2019-03-05 08:50:57 | [diff] [blame] | 20 | #include "api/sctp_transport_interface.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 21 | #include "pc/peer_connection_internal.h" |
Steve Anton | be5e208 | 2018-01-24 23:29:17 | [diff] [blame] | 22 | |
| 23 | namespace webrtc { |
| 24 | |
| 25 | // Customized PeerConnection fakes can be created by subclassing |
| 26 | // FakePeerConnectionBase then overriding the interesting methods. This class |
| 27 | // takes care of providing default implementations for all the pure virtual |
| 28 | // functions specified in the interfaces. |
Niels Möller | e78fd80 | 2019-09-13 12:45:55 | [diff] [blame] | 29 | // TODO(nisse): Try to replace this with DummyPeerConnection, from |
| 30 | // api/test/ ? |
Steve Anton | be5e208 | 2018-01-24 23:29:17 | [diff] [blame] | 31 | class FakePeerConnectionBase : public PeerConnectionInternal { |
| 32 | public: |
| 33 | // PeerConnectionInterface implementation. |
| 34 | |
| 35 | rtc::scoped_refptr<StreamCollectionInterface> local_streams() override { |
| 36 | return nullptr; |
| 37 | } |
| 38 | |
| 39 | rtc::scoped_refptr<StreamCollectionInterface> remote_streams() override { |
| 40 | return nullptr; |
| 41 | } |
| 42 | |
| 43 | bool AddStream(MediaStreamInterface* stream) override { return false; } |
| 44 | |
| 45 | void RemoveStream(MediaStreamInterface* stream) override {} |
| 46 | |
| 47 | RTCErrorOr<rtc::scoped_refptr<RtpSenderInterface>> AddTrack( |
| 48 | rtc::scoped_refptr<MediaStreamTrackInterface> track, |
Seth Hampson | 845e878 | 2018-03-02 19:34:10 | [diff] [blame] | 49 | const std::vector<std::string>& stream_ids) override { |
Steve Anton | be5e208 | 2018-01-24 23:29:17 | [diff] [blame] | 50 | return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented"); |
| 51 | } |
| 52 | |
Steve Anton | be5e208 | 2018-01-24 23:29:17 | [diff] [blame] | 53 | bool RemoveTrack(RtpSenderInterface* sender) override { return false; } |
| 54 | |
Niels Möller | 7b04a91 | 2019-09-13 13:41:21 | [diff] [blame] | 55 | RTCError RemoveTrackNew( |
| 56 | rtc::scoped_refptr<RtpSenderInterface> sender) override { |
| 57 | return RTCError(RTCErrorType::UNSUPPORTED_OPERATION); |
| 58 | } |
| 59 | |
Steve Anton | be5e208 | 2018-01-24 23:29:17 | [diff] [blame] | 60 | RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver( |
| 61 | rtc::scoped_refptr<MediaStreamTrackInterface> track) override { |
| 62 | return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented"); |
| 63 | } |
| 64 | |
| 65 | RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver( |
| 66 | rtc::scoped_refptr<MediaStreamTrackInterface> track, |
| 67 | const RtpTransceiverInit& init) override { |
| 68 | return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented"); |
| 69 | } |
| 70 | |
| 71 | RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver( |
| 72 | cricket::MediaType media_type) override { |
| 73 | return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented"); |
| 74 | } |
| 75 | |
| 76 | RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver( |
| 77 | cricket::MediaType media_type, |
| 78 | const RtpTransceiverInit& init) override { |
| 79 | return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented"); |
| 80 | } |
| 81 | |
Steve Anton | be5e208 | 2018-01-24 23:29:17 | [diff] [blame] | 82 | rtc::scoped_refptr<RtpSenderInterface> CreateSender( |
| 83 | const std::string& kind, |
| 84 | const std::string& stream_id) override { |
| 85 | return nullptr; |
| 86 | } |
| 87 | |
| 88 | std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders() |
| 89 | const override { |
| 90 | return {}; |
| 91 | } |
| 92 | |
| 93 | std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers() |
| 94 | const override { |
| 95 | return {}; |
| 96 | } |
| 97 | |
| 98 | std::vector<rtc::scoped_refptr<RtpTransceiverInterface>> GetTransceivers() |
| 99 | const override { |
| 100 | return {}; |
| 101 | } |
| 102 | |
| 103 | bool GetStats(StatsObserver* observer, |
| 104 | MediaStreamTrackInterface* track, |
| 105 | StatsOutputLevel level) override { |
| 106 | return false; |
| 107 | } |
| 108 | |
| 109 | void GetStats(RTCStatsCollectorCallback* callback) override {} |
Henrik Boström | 1df1bf8 | 2018-03-20 12:24:20 | [diff] [blame] | 110 | void GetStats( |
| 111 | rtc::scoped_refptr<RtpSenderInterface> selector, |
| 112 | rtc::scoped_refptr<RTCStatsCollectorCallback> callback) override {} |
| 113 | void GetStats( |
| 114 | rtc::scoped_refptr<RtpReceiverInterface> selector, |
| 115 | rtc::scoped_refptr<RTCStatsCollectorCallback> callback) override {} |
Steve Anton | be5e208 | 2018-01-24 23:29:17 | [diff] [blame] | 116 | |
| 117 | void ClearStatsCache() override {} |
| 118 | |
Harald Alvestrand | 15845af | 2019-03-05 08:50:57 | [diff] [blame] | 119 | rtc::scoped_refptr<SctpTransportInterface> GetSctpTransport() const { |
| 120 | return nullptr; |
| 121 | } |
| 122 | |
Harald Alvestrand | a9af50f | 2021-05-21 13:33:51 | [diff] [blame] | 123 | RTCErrorOr<rtc::scoped_refptr<DataChannelInterface>> CreateDataChannelOrError( |
Steve Anton | be5e208 | 2018-01-24 23:29:17 | [diff] [blame] | 124 | const std::string& label, |
| 125 | const DataChannelInit* config) override { |
Harald Alvestrand | a9af50f | 2021-05-21 13:33:51 | [diff] [blame] | 126 | return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, |
| 127 | "Fake function called"); |
Steve Anton | be5e208 | 2018-01-24 23:29:17 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | const SessionDescriptionInterface* local_description() const override { |
| 131 | return nullptr; |
| 132 | } |
| 133 | const SessionDescriptionInterface* remote_description() const override { |
| 134 | return nullptr; |
| 135 | } |
| 136 | |
| 137 | const SessionDescriptionInterface* current_local_description() |
| 138 | const override { |
| 139 | return nullptr; |
| 140 | } |
| 141 | const SessionDescriptionInterface* current_remote_description() |
| 142 | const override { |
| 143 | return nullptr; |
| 144 | } |
| 145 | |
| 146 | const SessionDescriptionInterface* pending_local_description() |
| 147 | const override { |
| 148 | return nullptr; |
| 149 | } |
| 150 | const SessionDescriptionInterface* pending_remote_description() |
| 151 | const override { |
| 152 | return nullptr; |
| 153 | } |
| 154 | |
Henrik Boström | 79b6980 | 2019-07-18 09:16:56 | [diff] [blame] | 155 | void RestartIce() override {} |
| 156 | |
Steve Anton | be5e208 | 2018-01-24 23:29:17 | [diff] [blame] | 157 | void CreateOffer(CreateSessionDescriptionObserver* observer, |
Steve Anton | be5e208 | 2018-01-24 23:29:17 | [diff] [blame] | 158 | const RTCOfferAnswerOptions& options) override {} |
| 159 | |
| 160 | void CreateAnswer(CreateSessionDescriptionObserver* observer, |
| 161 | const RTCOfferAnswerOptions& options) override {} |
| 162 | |
Steve Anton | be5e208 | 2018-01-24 23:29:17 | [diff] [blame] | 163 | void SetLocalDescription(SetSessionDescriptionObserver* observer, |
| 164 | SessionDescriptionInterface* desc) override {} |
| 165 | |
| 166 | void SetRemoteDescription(SetSessionDescriptionObserver* observer, |
| 167 | SessionDescriptionInterface* desc) override {} |
| 168 | |
| 169 | void SetRemoteDescription( |
| 170 | std::unique_ptr<SessionDescriptionInterface> desc, |
| 171 | rtc::scoped_refptr<SetRemoteDescriptionObserverInterface> observer) |
| 172 | override {} |
| 173 | |
Steve Anton | be5e208 | 2018-01-24 23:29:17 | [diff] [blame] | 174 | RTCConfiguration GetConfiguration() override { return RTCConfiguration(); } |
| 175 | |
Niels Möller | 2579f0c | 2019-08-19 07:58:17 | [diff] [blame] | 176 | RTCError SetConfiguration( |
Steve Anton | be5e208 | 2018-01-24 23:29:17 | [diff] [blame] | 177 | const PeerConnectionInterface::RTCConfiguration& config) override { |
Niels Möller | 2579f0c | 2019-08-19 07:58:17 | [diff] [blame] | 178 | return RTCError(); |
Steve Anton | be5e208 | 2018-01-24 23:29:17 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | bool AddIceCandidate(const IceCandidateInterface* candidate) override { |
| 182 | return false; |
| 183 | } |
| 184 | |
| 185 | bool RemoveIceCandidates( |
| 186 | const std::vector<cricket::Candidate>& candidates) override { |
| 187 | return false; |
| 188 | } |
| 189 | |
Niels Möller | 0c4f7be | 2018-05-07 12:01:37 | [diff] [blame] | 190 | RTCError SetBitrate(const BitrateSettings& bitrate) override { |
Steve Anton | be5e208 | 2018-01-24 23:29:17 | [diff] [blame] | 191 | return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented"); |
| 192 | } |
| 193 | |
Steve Anton | be5e208 | 2018-01-24 23:29:17 | [diff] [blame] | 194 | void SetAudioPlayout(bool playout) override {} |
| 195 | |
| 196 | void SetAudioRecording(bool recording) override {} |
| 197 | |
Harald Alvestrand | 4139047 | 2018-12-03 17:45:19 | [diff] [blame] | 198 | rtc::scoped_refptr<DtlsTransportInterface> LookupDtlsTransportByMid( |
| 199 | const std::string& mid) { |
| 200 | return nullptr; |
| 201 | } |
| 202 | |
Steve Anton | be5e208 | 2018-01-24 23:29:17 | [diff] [blame] | 203 | SignalingState signaling_state() override { return SignalingState::kStable; } |
| 204 | |
| 205 | IceConnectionState ice_connection_state() override { |
| 206 | return IceConnectionState::kIceConnectionNew; |
| 207 | } |
| 208 | |
Niels Möller | 7b04a91 | 2019-09-13 13:41:21 | [diff] [blame] | 209 | IceConnectionState standardized_ice_connection_state() override { |
| 210 | return IceConnectionState::kIceConnectionNew; |
| 211 | } |
| 212 | |
| 213 | PeerConnectionState peer_connection_state() override { |
| 214 | return PeerConnectionState::kNew; |
| 215 | } |
| 216 | |
Steve Anton | be5e208 | 2018-01-24 23:29:17 | [diff] [blame] | 217 | IceGatheringState ice_gathering_state() override { |
| 218 | return IceGatheringState::kIceGatheringNew; |
| 219 | } |
| 220 | |
Harald Alvestrand | 61f74d9 | 2020-03-02 10:20:00 | [diff] [blame] | 221 | absl::optional<bool> can_trickle_ice_candidates() { return absl::nullopt; } |
| 222 | |
Steve Anton | be5e208 | 2018-01-24 23:29:17 | [diff] [blame] | 223 | bool StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output, |
| 224 | int64_t output_period_ms) override { |
| 225 | return false; |
| 226 | } |
| 227 | |
Niels Möller | 7b04a91 | 2019-09-13 13:41:21 | [diff] [blame] | 228 | bool StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output) override { |
| 229 | return false; |
| 230 | } |
| 231 | |
Steve Anton | be5e208 | 2018-01-24 23:29:17 | [diff] [blame] | 232 | void StopRtcEventLog() override {} |
| 233 | |
| 234 | void Close() override {} |
| 235 | |
| 236 | // PeerConnectionInternal implementation. |
| 237 | |
| 238 | rtc::Thread* network_thread() const override { return nullptr; } |
| 239 | rtc::Thread* worker_thread() const override { return nullptr; } |
| 240 | rtc::Thread* signaling_thread() const override { return nullptr; } |
| 241 | |
| 242 | std::string session_id() const override { return ""; } |
| 243 | |
| 244 | bool initial_offerer() const override { return false; } |
| 245 | |
Steve Anton | be5e208 | 2018-01-24 23:29:17 | [diff] [blame] | 246 | std::vector< |
| 247 | rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>> |
Steve Anton | b886711 | 2018-02-13 18:07:54 | [diff] [blame] | 248 | GetTransceiversInternal() const override { |
Steve Anton | be5e208 | 2018-01-24 23:29:17 | [diff] [blame] | 249 | return {}; |
| 250 | } |
| 251 | |
Taylor Brandstetter | 3a034e1 | 2020-07-09 22:32:34 | [diff] [blame] | 252 | sigslot::signal1<SctpDataChannel*>& SignalSctpDataChannelCreated() override { |
| 253 | return SignalSctpDataChannelCreated_; |
Steve Anton | be5e208 | 2018-01-24 23:29:17 | [diff] [blame] | 254 | } |
| 255 | |
Danil Chapovalov | 66cadcc | 2018-06-19 14:47:43 | [diff] [blame] | 256 | absl::optional<std::string> sctp_transport_name() const override { |
| 257 | return absl::nullopt; |
Steve Anton | be5e208 | 2018-01-24 23:29:17 | [diff] [blame] | 258 | } |
| 259 | |
Tomas Gunnarsson | bfd9ba8 | 2021-04-18 09:55:57 | [diff] [blame] | 260 | absl::optional<std::string> sctp_mid() const override { |
| 261 | return absl::nullopt; |
Steve Anton | 5dfde18 | 2018-02-06 18:34:40 | [diff] [blame] | 262 | } |
Steve Anton | be5e208 | 2018-01-24 23:29:17 | [diff] [blame] | 263 | |
Steve Anton | 5dfde18 | 2018-02-06 18:34:40 | [diff] [blame] | 264 | std::map<std::string, cricket::TransportStats> GetTransportStatsByNames( |
| 265 | const std::set<std::string>& transport_names) override { |
| 266 | return {}; |
Steve Anton | be5e208 | 2018-01-24 23:29:17 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | Call::Stats GetCallStats() override { return Call::Stats(); } |
| 270 | |
| 271 | bool GetLocalCertificate( |
| 272 | const std::string& transport_name, |
| 273 | rtc::scoped_refptr<rtc::RTCCertificate>* certificate) override { |
| 274 | return false; |
| 275 | } |
| 276 | |
Taylor Brandstetter | c392866 | 2018-02-23 21:04:51 | [diff] [blame] | 277 | std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain( |
Steve Anton | be5e208 | 2018-01-24 23:29:17 | [diff] [blame] | 278 | const std::string& transport_name) override { |
| 279 | return nullptr; |
| 280 | } |
| 281 | |
| 282 | bool IceRestartPending(const std::string& content_name) const override { |
| 283 | return false; |
| 284 | } |
| 285 | |
| 286 | bool NeedsIceRestart(const std::string& content_name) const override { |
| 287 | return false; |
| 288 | } |
| 289 | |
| 290 | bool GetSslRole(const std::string& content_name, |
| 291 | rtc::SSLRole* role) override { |
| 292 | return false; |
| 293 | } |
| 294 | |
| 295 | protected: |
Taylor Brandstetter | 3a034e1 | 2020-07-09 22:32:34 | [diff] [blame] | 296 | sigslot::signal1<SctpDataChannel*> SignalSctpDataChannelCreated_; |
Steve Anton | be5e208 | 2018-01-24 23:29:17 | [diff] [blame] | 297 | }; |
| 298 | |
| 299 | } // namespace webrtc |
| 300 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 301 | #endif // PC_TEST_FAKE_PEER_CONNECTION_BASE_H_ |