Niels Möller | e78fd80 | 2019-09-13 14:45:55 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2019 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 API_TEST_DUMMY_PEER_CONNECTION_H_ |
| 12 | #define API_TEST_DUMMY_PEER_CONNECTION_H_ |
| 13 | |
| 14 | #include <memory> |
| 15 | #include <string> |
| 16 | #include <vector> |
| 17 | |
| 18 | #include "api/peer_connection_interface.h" |
| 19 | #include "api/rtc_error.h" |
| 20 | #include "rtc_base/checks.h" |
| 21 | #include "rtc_base/ref_counted_object.h" |
| 22 | |
| 23 | namespace webrtc { |
| 24 | |
| 25 | // This class includes dummy implementations of all methods on the |
| 26 | // PeerconnectionInterface. Accessor/getter methods return empty or default |
| 27 | // values. State-changing methods with a return value return failure. Remaining |
| 28 | // methods (except Close())) will crash with FATAL if called. |
| 29 | class DummyPeerConnection : public PeerConnectionInterface { |
| 30 | rtc::scoped_refptr<StreamCollectionInterface> local_streams() override { |
| 31 | return nullptr; |
| 32 | } |
| 33 | rtc::scoped_refptr<StreamCollectionInterface> remote_streams() override { |
| 34 | return nullptr; |
| 35 | } |
| 36 | |
| 37 | bool AddStream(MediaStreamInterface* stream) override { return false; } |
| 38 | void RemoveStream(MediaStreamInterface* stream) override { |
| 39 | FATAL() << "Not implemented"; |
| 40 | } |
| 41 | |
| 42 | RTCErrorOr<rtc::scoped_refptr<RtpSenderInterface>> AddTrack( |
| 43 | rtc::scoped_refptr<MediaStreamTrackInterface> track, |
| 44 | const std::vector<std::string>& stream_ids) override { |
| 45 | return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented"); |
| 46 | } |
| 47 | |
| 48 | bool RemoveTrack(RtpSenderInterface* sender) override { return false; } |
| 49 | |
| 50 | RTCError RemoveTrackNew( |
| 51 | rtc::scoped_refptr<RtpSenderInterface> sender) override { |
| 52 | return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented"); |
| 53 | } |
| 54 | |
| 55 | RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver( |
| 56 | rtc::scoped_refptr<MediaStreamTrackInterface> track) override { |
| 57 | return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented"); |
| 58 | } |
| 59 | RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver( |
| 60 | rtc::scoped_refptr<MediaStreamTrackInterface> track, |
| 61 | const RtpTransceiverInit& init) override { |
| 62 | return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented"); |
| 63 | } |
| 64 | |
| 65 | RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver( |
| 66 | cricket::MediaType media_type) override { |
| 67 | return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented"); |
| 68 | } |
| 69 | RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> AddTransceiver( |
| 70 | cricket::MediaType media_type, |
| 71 | const RtpTransceiverInit& init) override { |
| 72 | return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented"); |
| 73 | } |
| 74 | |
| 75 | rtc::scoped_refptr<RtpSenderInterface> CreateSender( |
| 76 | const std::string& kind, |
| 77 | const std::string& stream_id) override { |
| 78 | return nullptr; |
| 79 | } |
| 80 | |
| 81 | std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders() |
| 82 | const override { |
| 83 | return {}; |
| 84 | } |
| 85 | |
| 86 | std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers() |
| 87 | const override { |
| 88 | return {}; |
| 89 | } |
| 90 | |
| 91 | std::vector<rtc::scoped_refptr<RtpTransceiverInterface>> GetTransceivers() |
| 92 | const override { |
| 93 | return {}; |
| 94 | } |
| 95 | |
| 96 | bool GetStats(StatsObserver* observer, |
| 97 | MediaStreamTrackInterface* track, // Optional |
| 98 | StatsOutputLevel level) override { |
| 99 | return false; |
| 100 | } |
| 101 | |
| 102 | void GetStats(RTCStatsCollectorCallback* callback) override { |
| 103 | FATAL() << "Not implemented"; |
| 104 | } |
| 105 | void GetStats( |
| 106 | rtc::scoped_refptr<RtpSenderInterface> selector, |
| 107 | rtc::scoped_refptr<RTCStatsCollectorCallback> callback) override { |
| 108 | FATAL() << "Not implemented"; |
| 109 | } |
| 110 | void GetStats( |
| 111 | rtc::scoped_refptr<RtpReceiverInterface> selector, |
| 112 | rtc::scoped_refptr<RTCStatsCollectorCallback> callback) override { |
| 113 | FATAL() << "Not implemented"; |
| 114 | } |
| 115 | void ClearStatsCache() override {} |
| 116 | |
| 117 | rtc::scoped_refptr<DataChannelInterface> CreateDataChannel( |
| 118 | const std::string& label, |
| 119 | const DataChannelInit* config) override { |
| 120 | return nullptr; |
| 121 | } |
| 122 | |
| 123 | const SessionDescriptionInterface* local_description() const override { |
| 124 | return nullptr; |
| 125 | } |
| 126 | const SessionDescriptionInterface* remote_description() const override { |
| 127 | return nullptr; |
| 128 | } |
| 129 | |
| 130 | const SessionDescriptionInterface* current_local_description() |
| 131 | const override { |
| 132 | return nullptr; |
| 133 | } |
| 134 | const SessionDescriptionInterface* current_remote_description() |
| 135 | const override { |
| 136 | return nullptr; |
| 137 | } |
| 138 | |
| 139 | const SessionDescriptionInterface* pending_local_description() |
| 140 | const override { |
| 141 | return nullptr; |
| 142 | } |
| 143 | const SessionDescriptionInterface* pending_remote_description() |
| 144 | const override { |
| 145 | return nullptr; |
| 146 | } |
| 147 | |
| 148 | void RestartIce() override { FATAL() << "Not implemented"; } |
| 149 | |
| 150 | // Create a new offer. |
| 151 | // The CreateSessionDescriptionObserver callback will be called when done. |
| 152 | void CreateOffer(CreateSessionDescriptionObserver* observer, |
| 153 | const RTCOfferAnswerOptions& options) override { |
| 154 | FATAL() << "Not implemented"; |
| 155 | } |
| 156 | |
| 157 | void CreateAnswer(CreateSessionDescriptionObserver* observer, |
| 158 | const RTCOfferAnswerOptions& options) override { |
| 159 | FATAL() << "Not implemented"; |
| 160 | } |
| 161 | |
| 162 | void SetLocalDescription(SetSessionDescriptionObserver* observer, |
| 163 | SessionDescriptionInterface* desc) override { |
| 164 | FATAL() << "Not implemented"; |
| 165 | } |
| 166 | void SetRemoteDescription(SetSessionDescriptionObserver* observer, |
| 167 | SessionDescriptionInterface* desc) override { |
| 168 | FATAL() << "Not implemented"; |
| 169 | } |
| 170 | void SetRemoteDescription( |
| 171 | std::unique_ptr<SessionDescriptionInterface> desc, |
| 172 | rtc::scoped_refptr<SetRemoteDescriptionObserverInterface> observer) |
| 173 | override { |
| 174 | FATAL() << "Not implemented"; |
| 175 | } |
| 176 | |
| 177 | PeerConnectionInterface::RTCConfiguration GetConfiguration() override { |
| 178 | return RTCConfiguration(); |
| 179 | } |
| 180 | RTCError SetConfiguration( |
| 181 | const PeerConnectionInterface::RTCConfiguration& config) override { |
| 182 | return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented"); |
| 183 | } |
| 184 | |
| 185 | bool AddIceCandidate(const IceCandidateInterface* candidate) override { |
| 186 | return false; |
| 187 | } |
| 188 | bool RemoveIceCandidates( |
| 189 | const std::vector<cricket::Candidate>& candidates) override { |
| 190 | return false; |
| 191 | } |
| 192 | |
| 193 | RTCError SetBitrate(const BitrateSettings& bitrate) override { |
| 194 | return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented"); |
| 195 | } |
| 196 | |
| 197 | RTCError SetBitrate(const BitrateParameters& bitrate_parameters) override { |
| 198 | return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented"); |
| 199 | } |
| 200 | |
| 201 | void SetAudioPlayout(bool playout) override { FATAL() << "Not implemented"; } |
| 202 | void SetAudioRecording(bool recording) override { |
| 203 | FATAL() << "Not implemented"; |
| 204 | } |
| 205 | |
| 206 | rtc::scoped_refptr<DtlsTransportInterface> LookupDtlsTransportByMid( |
| 207 | const std::string& mid) override { |
| 208 | return nullptr; |
| 209 | } |
| 210 | rtc::scoped_refptr<SctpTransportInterface> GetSctpTransport() const override { |
| 211 | return nullptr; |
| 212 | } |
| 213 | |
| 214 | SignalingState signaling_state() override { return SignalingState(); } |
| 215 | |
| 216 | IceConnectionState ice_connection_state() override { |
| 217 | return IceConnectionState(); |
| 218 | } |
| 219 | |
| 220 | IceConnectionState standardized_ice_connection_state() override { |
| 221 | return IceConnectionState(); |
| 222 | } |
| 223 | |
| 224 | PeerConnectionState peer_connection_state() override { |
| 225 | return PeerConnectionState(); |
| 226 | } |
| 227 | |
| 228 | IceGatheringState ice_gathering_state() override { |
| 229 | return IceGatheringState(); |
| 230 | } |
| 231 | |
| 232 | bool StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output, |
| 233 | int64_t output_period_ms) override { |
| 234 | return false; |
| 235 | } |
| 236 | bool StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output) override { |
| 237 | return false; |
| 238 | } |
| 239 | |
| 240 | void StopRtcEventLog() { FATAL() << "Not implemented"; } |
| 241 | |
| 242 | void Close() {} |
| 243 | }; |
| 244 | |
| 245 | static_assert( |
| 246 | !std::is_abstract<rtc::RefCountedObject<DummyPeerConnection>>::value, |
| 247 | ""); |
| 248 | |
| 249 | } // namespace webrtc |
| 250 | |
| 251 | #endif // API_TEST_DUMMY_PEER_CONNECTION_H_ |