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 11 #ifndef PC_TEST_FAKE_PEER_CONNECTION_BASE_H_ 12 #define PC_TEST_FAKE_PEER_CONNECTION_BASE_H_ 13 14 #include <map> 15 #include <memory> 16 #include <set> 17 #include <string> 18 #include <vector> 19 20 #include "api/field_trials_view.h" 21 #include "api/sctp_transport_interface.h" 22 #include "pc/peer_connection_internal.h" 23 #include "test/scoped_key_value_config.h" 24 25 namespace webrtc { 26 27 // Customized PeerConnection fakes can be created by subclassing 28 // FakePeerConnectionBase then overriding the interesting methods. This class 29 // takes care of providing default implementations for all the pure virtual 30 // functions specified in the interfaces. 31 class FakePeerConnectionBase : public PeerConnectionInternal { 32 public: 33 // PeerConnectionInterface implementation. 34 local_streams()35 rtc::scoped_refptr<StreamCollectionInterface> local_streams() override { 36 return nullptr; 37 } 38 remote_streams()39 rtc::scoped_refptr<StreamCollectionInterface> remote_streams() override { 40 return nullptr; 41 } 42 AddStream(MediaStreamInterface * stream)43 bool AddStream(MediaStreamInterface* stream) override { return false; } 44 RemoveStream(MediaStreamInterface * stream)45 void RemoveStream(MediaStreamInterface* stream) override {} 46 AddTrack(rtc::scoped_refptr<MediaStreamTrackInterface> track,const std::vector<std::string> & stream_ids)47 RTCErrorOr<rtc::scoped_refptr<RtpSenderInterface>> AddTrack( 48 rtc::scoped_refptr<MediaStreamTrackInterface> track, 49 const std::vector<std::string>& stream_ids) override { 50 return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented"); 51 } 52 AddTrack(rtc::scoped_refptr<MediaStreamTrackInterface> track,const std::vector<std::string> & stream_ids,const std::vector<RtpEncodingParameters> & init_send_encodings)53 RTCErrorOr<rtc::scoped_refptr<RtpSenderInterface>> AddTrack( 54 rtc::scoped_refptr<MediaStreamTrackInterface> track, 55 const std::vector<std::string>& stream_ids, 56 const std::vector<RtpEncodingParameters>& init_send_encodings) override { 57 return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented"); 58 } 59 RemoveTrackOrError(rtc::scoped_refptr<RtpSenderInterface> sender)60 RTCError RemoveTrackOrError( 61 rtc::scoped_refptr<RtpSenderInterface> sender) override { 62 return RTCError(RTCErrorType::UNSUPPORTED_OPERATION); 63 } 64 AddTransceiver(rtc::scoped_refptr<MediaStreamTrackInterface> track)65 RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver( 66 rtc::scoped_refptr<MediaStreamTrackInterface> track) override { 67 return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented"); 68 } 69 AddTransceiver(rtc::scoped_refptr<MediaStreamTrackInterface> track,const RtpTransceiverInit & init)70 RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver( 71 rtc::scoped_refptr<MediaStreamTrackInterface> track, 72 const RtpTransceiverInit& init) override { 73 return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented"); 74 } 75 AddTransceiver(cricket::MediaType media_type)76 RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver( 77 cricket::MediaType media_type) override { 78 return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented"); 79 } 80 AddTransceiver(cricket::MediaType media_type,const RtpTransceiverInit & init)81 RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver( 82 cricket::MediaType media_type, 83 const RtpTransceiverInit& init) override { 84 return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented"); 85 } 86 CreateSender(const std::string & kind,const std::string & stream_id)87 rtc::scoped_refptr<RtpSenderInterface> CreateSender( 88 const std::string& kind, 89 const std::string& stream_id) override { 90 return nullptr; 91 } 92 GetSenders()93 std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders() 94 const override { 95 return {}; 96 } 97 GetReceivers()98 std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers() 99 const override { 100 return {}; 101 } 102 GetTransceivers()103 std::vector<rtc::scoped_refptr<RtpTransceiverInterface>> GetTransceivers() 104 const override { 105 return {}; 106 } 107 GetStats(StatsObserver * observer,MediaStreamTrackInterface * track,StatsOutputLevel level)108 bool GetStats(StatsObserver* observer, 109 MediaStreamTrackInterface* track, 110 StatsOutputLevel level) override { 111 return false; 112 } 113 GetStats(RTCStatsCollectorCallback * callback)114 void GetStats(RTCStatsCollectorCallback* callback) override {} GetStats(rtc::scoped_refptr<RtpSenderInterface> selector,rtc::scoped_refptr<RTCStatsCollectorCallback> callback)115 void GetStats( 116 rtc::scoped_refptr<RtpSenderInterface> selector, 117 rtc::scoped_refptr<RTCStatsCollectorCallback> callback) override {} GetStats(rtc::scoped_refptr<RtpReceiverInterface> selector,rtc::scoped_refptr<RTCStatsCollectorCallback> callback)118 void GetStats( 119 rtc::scoped_refptr<RtpReceiverInterface> selector, 120 rtc::scoped_refptr<RTCStatsCollectorCallback> callback) override {} 121 ClearStatsCache()122 void ClearStatsCache() override {} 123 GetSctpTransport()124 rtc::scoped_refptr<SctpTransportInterface> GetSctpTransport() const { 125 return nullptr; 126 } 127 CreateDataChannelOrError(const std::string & label,const DataChannelInit * config)128 RTCErrorOr<rtc::scoped_refptr<DataChannelInterface>> CreateDataChannelOrError( 129 const std::string& label, 130 const DataChannelInit* config) override { 131 return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, 132 "Fake function called"); 133 } 134 local_description()135 const SessionDescriptionInterface* local_description() const override { 136 return nullptr; 137 } remote_description()138 const SessionDescriptionInterface* remote_description() const override { 139 return nullptr; 140 } 141 current_local_description()142 const SessionDescriptionInterface* current_local_description() 143 const override { 144 return nullptr; 145 } current_remote_description()146 const SessionDescriptionInterface* current_remote_description() 147 const override { 148 return nullptr; 149 } 150 pending_local_description()151 const SessionDescriptionInterface* pending_local_description() 152 const override { 153 return nullptr; 154 } pending_remote_description()155 const SessionDescriptionInterface* pending_remote_description() 156 const override { 157 return nullptr; 158 } 159 RestartIce()160 void RestartIce() override {} 161 CreateOffer(CreateSessionDescriptionObserver * observer,const RTCOfferAnswerOptions & options)162 void CreateOffer(CreateSessionDescriptionObserver* observer, 163 const RTCOfferAnswerOptions& options) override {} 164 CreateAnswer(CreateSessionDescriptionObserver * observer,const RTCOfferAnswerOptions & options)165 void CreateAnswer(CreateSessionDescriptionObserver* observer, 166 const RTCOfferAnswerOptions& options) override {} 167 SetLocalDescription(SetSessionDescriptionObserver * observer,SessionDescriptionInterface * desc)168 void SetLocalDescription(SetSessionDescriptionObserver* observer, 169 SessionDescriptionInterface* desc) override {} 170 SetRemoteDescription(SetSessionDescriptionObserver * observer,SessionDescriptionInterface * desc)171 void SetRemoteDescription(SetSessionDescriptionObserver* observer, 172 SessionDescriptionInterface* desc) override {} 173 SetRemoteDescription(std::unique_ptr<SessionDescriptionInterface> desc,rtc::scoped_refptr<SetRemoteDescriptionObserverInterface> observer)174 void SetRemoteDescription( 175 std::unique_ptr<SessionDescriptionInterface> desc, 176 rtc::scoped_refptr<SetRemoteDescriptionObserverInterface> observer) 177 override {} 178 GetConfiguration()179 RTCConfiguration GetConfiguration() override { return RTCConfiguration(); } 180 SetConfiguration(const PeerConnectionInterface::RTCConfiguration & config)181 RTCError SetConfiguration( 182 const PeerConnectionInterface::RTCConfiguration& config) override { 183 return RTCError(); 184 } 185 AddIceCandidate(const IceCandidateInterface * candidate)186 bool AddIceCandidate(const IceCandidateInterface* candidate) override { 187 return false; 188 } 189 RemoveIceCandidates(const std::vector<cricket::Candidate> & candidates)190 bool RemoveIceCandidates( 191 const std::vector<cricket::Candidate>& candidates) override { 192 return false; 193 } 194 SetBitrate(const BitrateSettings & bitrate)195 RTCError SetBitrate(const BitrateSettings& bitrate) override { 196 return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented"); 197 } 198 SetAudioPlayout(bool playout)199 void SetAudioPlayout(bool playout) override {} 200 SetAudioRecording(bool recording)201 void SetAudioRecording(bool recording) override {} 202 LookupDtlsTransportByMid(const std::string & mid)203 rtc::scoped_refptr<DtlsTransportInterface> LookupDtlsTransportByMid( 204 const std::string& mid) { 205 return nullptr; 206 } 207 signaling_state()208 SignalingState signaling_state() override { return SignalingState::kStable; } 209 ice_connection_state()210 IceConnectionState ice_connection_state() override { 211 return IceConnectionState::kIceConnectionNew; 212 } 213 standardized_ice_connection_state()214 IceConnectionState standardized_ice_connection_state() override { 215 return IceConnectionState::kIceConnectionNew; 216 } 217 peer_connection_state()218 PeerConnectionState peer_connection_state() override { 219 return PeerConnectionState::kNew; 220 } 221 ice_gathering_state()222 IceGatheringState ice_gathering_state() override { 223 return IceGatheringState::kIceGatheringNew; 224 } 225 can_trickle_ice_candidates()226 absl::optional<bool> can_trickle_ice_candidates() { return absl::nullopt; } 227 StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output,int64_t output_period_ms)228 bool StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output, 229 int64_t output_period_ms) override { 230 return false; 231 } 232 StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output)233 bool StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output) override { 234 return false; 235 } 236 StopRtcEventLog()237 void StopRtcEventLog() override {} 238 Close()239 void Close() override {} 240 241 // PeerConnectionInternal implementation. 242 network_thread()243 rtc::Thread* network_thread() const override { return nullptr; } worker_thread()244 rtc::Thread* worker_thread() const override { return nullptr; } signaling_thread()245 rtc::Thread* signaling_thread() const override { return nullptr; } 246 session_id()247 std::string session_id() const override { return ""; } 248 initial_offerer()249 bool initial_offerer() const override { return false; } 250 251 std::vector< 252 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>> GetTransceiversInternal()253 GetTransceiversInternal() const override { 254 return {}; 255 } 256 SignalSctpDataChannelCreated()257 sigslot::signal1<SctpDataChannel*>& SignalSctpDataChannelCreated() override { 258 return SignalSctpDataChannelCreated_; 259 } 260 sctp_transport_name()261 absl::optional<std::string> sctp_transport_name() const override { 262 return absl::nullopt; 263 } 264 sctp_mid()265 absl::optional<std::string> sctp_mid() const override { 266 return absl::nullopt; 267 } 268 GetTransportStatsByNames(const std::set<std::string> & transport_names)269 std::map<std::string, cricket::TransportStats> GetTransportStatsByNames( 270 const std::set<std::string>& transport_names) override { 271 return {}; 272 } 273 GetCallStats()274 Call::Stats GetCallStats() override { return Call::Stats(); } 275 GetLocalCertificate(const std::string & transport_name,rtc::scoped_refptr<rtc::RTCCertificate> * certificate)276 bool GetLocalCertificate( 277 const std::string& transport_name, 278 rtc::scoped_refptr<rtc::RTCCertificate>* certificate) override { 279 return false; 280 } 281 GetRemoteSSLCertChain(const std::string & transport_name)282 std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain( 283 const std::string& transport_name) override { 284 return nullptr; 285 } 286 IceRestartPending(const std::string & content_name)287 bool IceRestartPending(const std::string& content_name) const override { 288 return false; 289 } 290 NeedsIceRestart(const std::string & content_name)291 bool NeedsIceRestart(const std::string& content_name) const override { 292 return false; 293 } 294 GetSslRole(const std::string & content_name,rtc::SSLRole * role)295 bool GetSslRole(const std::string& content_name, 296 rtc::SSLRole* role) override { 297 return false; 298 } configuration()299 const PeerConnectionInterface::RTCConfiguration* configuration() 300 const override { 301 return nullptr; 302 } 303 ReportSdpBundleUsage(const SessionDescriptionInterface & remote_description)304 void ReportSdpBundleUsage( 305 const SessionDescriptionInterface& remote_description) override {} 306 message_handler()307 PeerConnectionMessageHandler* message_handler() override { return nullptr; } rtp_manager()308 RtpTransmissionManager* rtp_manager() override { return nullptr; } rtp_manager()309 const RtpTransmissionManager* rtp_manager() const override { return nullptr; } dtls_enabled()310 bool dtls_enabled() const override { return false; } options()311 const PeerConnectionFactoryInterface::Options* options() const override { 312 return nullptr; 313 } 314 GetCryptoOptions()315 CryptoOptions GetCryptoOptions() override { return CryptoOptions(); } transport_controller_s()316 JsepTransportController* transport_controller_s() override { return nullptr; } transport_controller_n()317 JsepTransportController* transport_controller_n() override { return nullptr; } data_channel_controller()318 DataChannelController* data_channel_controller() override { return nullptr; } port_allocator()319 cricket::PortAllocator* port_allocator() override { return nullptr; } legacy_stats()320 LegacyStatsCollector* legacy_stats() override { return nullptr; } Observer()321 PeerConnectionObserver* Observer() const override { return nullptr; } GetSctpSslRole(rtc::SSLRole * role)322 bool GetSctpSslRole(rtc::SSLRole* role) override { return false; } ice_connection_state_internal()323 PeerConnectionInterface::IceConnectionState ice_connection_state_internal() 324 override { 325 return PeerConnectionInterface::IceConnectionState::kIceConnectionNew; 326 } SetIceConnectionState(PeerConnectionInterface::IceConnectionState new_state)327 void SetIceConnectionState( 328 PeerConnectionInterface::IceConnectionState new_state) override {} NoteUsageEvent(UsageEvent event)329 void NoteUsageEvent(UsageEvent event) override {} IsClosed()330 bool IsClosed() const override { return false; } IsUnifiedPlan()331 bool IsUnifiedPlan() const override { return true; } ValidateBundleSettings(const cricket::SessionDescription * desc,const std::map<std::string,const cricket::ContentGroup * > & bundle_groups_by_mid)332 bool ValidateBundleSettings( 333 const cricket::SessionDescription* desc, 334 const std::map<std::string, const cricket::ContentGroup*>& 335 bundle_groups_by_mid) override { 336 return false; 337 } 338 GetDataMid()339 absl::optional<std::string> GetDataMid() const override { 340 return absl::nullopt; 341 } 342 RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver( 343 cricket::MediaType media_type, 344 rtc::scoped_refptr<MediaStreamTrackInterface> track, 345 const RtpTransceiverInit& init, 346 bool fire_callback = true) override { 347 return RTCError(RTCErrorType::INTERNAL_ERROR, ""); 348 } StartSctpTransport(int local_port,int remote_port,int max_message_size)349 void StartSctpTransport(int local_port, 350 int remote_port, 351 int max_message_size) override {} 352 AddRemoteCandidate(const std::string & mid,const cricket::Candidate & candidate)353 void AddRemoteCandidate(const std::string& mid, 354 const cricket::Candidate& candidate) override {} 355 call_ptr()356 Call* call_ptr() override { return nullptr; } SrtpRequired()357 bool SrtpRequired() const override { return false; } SetupDataChannelTransport_n(const std::string & mid)358 bool SetupDataChannelTransport_n(const std::string& mid) override { 359 return false; 360 } TeardownDataChannelTransport_n()361 void TeardownDataChannelTransport_n() override {} SetSctpDataMid(const std::string & mid)362 void SetSctpDataMid(const std::string& mid) override {} ResetSctpDataMid()363 void ResetSctpDataMid() override {} 364 trials()365 const FieldTrialsView& trials() const override { return field_trials_; } 366 367 protected: 368 webrtc::test::ScopedKeyValueConfig field_trials_; 369 sigslot::signal1<SctpDataChannel*> SignalSctpDataChannelCreated_; 370 }; 371 372 } // namespace webrtc 373 374 #endif // PC_TEST_FAKE_PEER_CONNECTION_BASE_H_ 375