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/sctp_transport_interface.h" 21 #include "pc/peer_connection_internal.h" 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. 29 // TODO(nisse): Try to replace this with DummyPeerConnection, from 30 // api/test/ ? 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 RemoveTrack(RtpSenderInterface * sender)53 bool RemoveTrack(RtpSenderInterface* sender) override { return false; } 54 RemoveTrackNew(rtc::scoped_refptr<RtpSenderInterface> sender)55 RTCError RemoveTrackNew( 56 rtc::scoped_refptr<RtpSenderInterface> sender) override { 57 return RTCError(RTCErrorType::UNSUPPORTED_OPERATION); 58 } 59 AddTransceiver(rtc::scoped_refptr<MediaStreamTrackInterface> track)60 RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver( 61 rtc::scoped_refptr<MediaStreamTrackInterface> track) override { 62 return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented"); 63 } 64 AddTransceiver(rtc::scoped_refptr<MediaStreamTrackInterface> track,const RtpTransceiverInit & init)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 AddTransceiver(cricket::MediaType media_type)71 RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver( 72 cricket::MediaType media_type) override { 73 return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented"); 74 } 75 AddTransceiver(cricket::MediaType media_type,const RtpTransceiverInit & init)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 CreateSender(const std::string & kind,const std::string & stream_id)82 rtc::scoped_refptr<RtpSenderInterface> CreateSender( 83 const std::string& kind, 84 const std::string& stream_id) override { 85 return nullptr; 86 } 87 GetSenders()88 std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders() 89 const override { 90 return {}; 91 } 92 GetReceivers()93 std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers() 94 const override { 95 return {}; 96 } 97 GetTransceivers()98 std::vector<rtc::scoped_refptr<RtpTransceiverInterface>> GetTransceivers() 99 const override { 100 return {}; 101 } 102 GetStats(StatsObserver * observer,MediaStreamTrackInterface * track,StatsOutputLevel level)103 bool GetStats(StatsObserver* observer, 104 MediaStreamTrackInterface* track, 105 StatsOutputLevel level) override { 106 return false; 107 } 108 GetStats(RTCStatsCollectorCallback * callback)109 void GetStats(RTCStatsCollectorCallback* callback) override {} GetStats(rtc::scoped_refptr<RtpSenderInterface> selector,rtc::scoped_refptr<RTCStatsCollectorCallback> callback)110 void GetStats( 111 rtc::scoped_refptr<RtpSenderInterface> selector, 112 rtc::scoped_refptr<RTCStatsCollectorCallback> callback) override {} GetStats(rtc::scoped_refptr<RtpReceiverInterface> selector,rtc::scoped_refptr<RTCStatsCollectorCallback> callback)113 void GetStats( 114 rtc::scoped_refptr<RtpReceiverInterface> selector, 115 rtc::scoped_refptr<RTCStatsCollectorCallback> callback) override {} 116 ClearStatsCache()117 void ClearStatsCache() override {} 118 GetSctpTransport()119 rtc::scoped_refptr<SctpTransportInterface> GetSctpTransport() const { 120 return nullptr; 121 } 122 CreateDataChannel(const std::string & label,const DataChannelInit * config)123 rtc::scoped_refptr<DataChannelInterface> CreateDataChannel( 124 const std::string& label, 125 const DataChannelInit* config) override { 126 return nullptr; 127 } 128 local_description()129 const SessionDescriptionInterface* local_description() const override { 130 return nullptr; 131 } remote_description()132 const SessionDescriptionInterface* remote_description() const override { 133 return nullptr; 134 } 135 current_local_description()136 const SessionDescriptionInterface* current_local_description() 137 const override { 138 return nullptr; 139 } current_remote_description()140 const SessionDescriptionInterface* current_remote_description() 141 const override { 142 return nullptr; 143 } 144 pending_local_description()145 const SessionDescriptionInterface* pending_local_description() 146 const override { 147 return nullptr; 148 } pending_remote_description()149 const SessionDescriptionInterface* pending_remote_description() 150 const override { 151 return nullptr; 152 } 153 RestartIce()154 void RestartIce() override {} 155 CreateOffer(CreateSessionDescriptionObserver * observer,const RTCOfferAnswerOptions & options)156 void CreateOffer(CreateSessionDescriptionObserver* observer, 157 const RTCOfferAnswerOptions& options) override {} 158 CreateAnswer(CreateSessionDescriptionObserver * observer,const RTCOfferAnswerOptions & options)159 void CreateAnswer(CreateSessionDescriptionObserver* observer, 160 const RTCOfferAnswerOptions& options) override {} 161 SetLocalDescription(SetSessionDescriptionObserver * observer,SessionDescriptionInterface * desc)162 void SetLocalDescription(SetSessionDescriptionObserver* observer, 163 SessionDescriptionInterface* desc) override {} 164 SetRemoteDescription(SetSessionDescriptionObserver * observer,SessionDescriptionInterface * desc)165 void SetRemoteDescription(SetSessionDescriptionObserver* observer, 166 SessionDescriptionInterface* desc) override {} 167 SetRemoteDescription(std::unique_ptr<SessionDescriptionInterface> desc,rtc::scoped_refptr<SetRemoteDescriptionObserverInterface> observer)168 void SetRemoteDescription( 169 std::unique_ptr<SessionDescriptionInterface> desc, 170 rtc::scoped_refptr<SetRemoteDescriptionObserverInterface> observer) 171 override {} 172 GetConfiguration()173 RTCConfiguration GetConfiguration() override { return RTCConfiguration(); } 174 SetConfiguration(const PeerConnectionInterface::RTCConfiguration & config)175 RTCError SetConfiguration( 176 const PeerConnectionInterface::RTCConfiguration& config) override { 177 return RTCError(); 178 } 179 AddIceCandidate(const IceCandidateInterface * candidate)180 bool AddIceCandidate(const IceCandidateInterface* candidate) override { 181 return false; 182 } 183 RemoveIceCandidates(const std::vector<cricket::Candidate> & candidates)184 bool RemoveIceCandidates( 185 const std::vector<cricket::Candidate>& candidates) override { 186 return false; 187 } 188 SetBitrate(const BitrateSettings & bitrate)189 RTCError SetBitrate(const BitrateSettings& bitrate) override { 190 return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented"); 191 } 192 SetAudioPlayout(bool playout)193 void SetAudioPlayout(bool playout) override {} 194 SetAudioRecording(bool recording)195 void SetAudioRecording(bool recording) override {} 196 LookupDtlsTransportByMid(const std::string & mid)197 rtc::scoped_refptr<DtlsTransportInterface> LookupDtlsTransportByMid( 198 const std::string& mid) { 199 return nullptr; 200 } 201 signaling_state()202 SignalingState signaling_state() override { return SignalingState::kStable; } 203 ice_connection_state()204 IceConnectionState ice_connection_state() override { 205 return IceConnectionState::kIceConnectionNew; 206 } 207 standardized_ice_connection_state()208 IceConnectionState standardized_ice_connection_state() override { 209 return IceConnectionState::kIceConnectionNew; 210 } 211 peer_connection_state()212 PeerConnectionState peer_connection_state() override { 213 return PeerConnectionState::kNew; 214 } 215 ice_gathering_state()216 IceGatheringState ice_gathering_state() override { 217 return IceGatheringState::kIceGatheringNew; 218 } 219 can_trickle_ice_candidates()220 absl::optional<bool> can_trickle_ice_candidates() { return absl::nullopt; } 221 StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output,int64_t output_period_ms)222 bool StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output, 223 int64_t output_period_ms) override { 224 return false; 225 } 226 StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output)227 bool StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output) override { 228 return false; 229 } 230 StopRtcEventLog()231 void StopRtcEventLog() override {} 232 Close()233 void Close() override {} 234 235 // PeerConnectionInternal implementation. 236 network_thread()237 rtc::Thread* network_thread() const override { return nullptr; } worker_thread()238 rtc::Thread* worker_thread() const override { return nullptr; } signaling_thread()239 rtc::Thread* signaling_thread() const override { return nullptr; } 240 session_id()241 std::string session_id() const override { return ""; } 242 initial_offerer()243 bool initial_offerer() const override { return false; } 244 245 std::vector< 246 rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>> GetTransceiversInternal()247 GetTransceiversInternal() const override { 248 return {}; 249 } 250 SignalRtpDataChannelCreated()251 sigslot::signal1<RtpDataChannel*>& SignalRtpDataChannelCreated() override { 252 return SignalRtpDataChannelCreated_; 253 } 254 SignalSctpDataChannelCreated()255 sigslot::signal1<SctpDataChannel*>& SignalSctpDataChannelCreated() override { 256 return SignalSctpDataChannelCreated_; 257 } 258 rtp_data_channel()259 cricket::RtpDataChannel* rtp_data_channel() const override { return nullptr; } 260 sctp_transport_name()261 absl::optional<std::string> sctp_transport_name() const override { 262 return absl::nullopt; 263 } 264 GetTransportNamesByMid()265 std::map<std::string, std::string> GetTransportNamesByMid() const override { 266 return {}; 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 } 299 300 protected: 301 sigslot::signal1<RtpDataChannel*> SignalRtpDataChannelCreated_; 302 sigslot::signal1<SctpDataChannel*> SignalSctpDataChannelCreated_; 303 }; 304 305 } // namespace webrtc 306 307 #endif // PC_TEST_FAKE_PEER_CONNECTION_BASE_H_ 308