dummy_peer_connection.h 8.0 KB

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