peer_connection_test_wrapper.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright 2013 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 PC_TEST_PEER_CONNECTION_TEST_WRAPPER_H_
  11. #define PC_TEST_PEER_CONNECTION_TEST_WRAPPER_H_
  12. #include <memory>
  13. #include <string>
  14. #include <vector>
  15. #include "api/audio_codecs/audio_decoder_factory.h"
  16. #include "api/audio_codecs/audio_encoder_factory.h"
  17. #include "api/audio_options.h"
  18. #include "api/data_channel_interface.h"
  19. #include "api/jsep.h"
  20. #include "api/media_stream_interface.h"
  21. #include "api/peer_connection_interface.h"
  22. #include "api/rtc_error.h"
  23. #include "api/rtp_receiver_interface.h"
  24. #include "api/scoped_refptr.h"
  25. #include "pc/test/fake_audio_capture_module.h"
  26. #include "pc/test/fake_video_track_renderer.h"
  27. #include "rtc_base/third_party/sigslot/sigslot.h"
  28. #include "rtc_base/thread.h"
  29. #include "rtc_base/thread_checker.h"
  30. class PeerConnectionTestWrapper
  31. : public webrtc::PeerConnectionObserver,
  32. public webrtc::CreateSessionDescriptionObserver,
  33. public sigslot::has_slots<> {
  34. public:
  35. static void Connect(PeerConnectionTestWrapper* caller,
  36. PeerConnectionTestWrapper* callee);
  37. PeerConnectionTestWrapper(const std::string& name,
  38. rtc::Thread* network_thread,
  39. rtc::Thread* worker_thread);
  40. virtual ~PeerConnectionTestWrapper();
  41. bool CreatePc(
  42. const webrtc::PeerConnectionInterface::RTCConfiguration& config,
  43. rtc::scoped_refptr<webrtc::AudioEncoderFactory> audio_encoder_factory,
  44. rtc::scoped_refptr<webrtc::AudioDecoderFactory> audio_decoder_factory);
  45. rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory()
  46. const {
  47. return peer_connection_factory_;
  48. }
  49. webrtc::PeerConnectionInterface* pc() { return peer_connection_.get(); }
  50. rtc::scoped_refptr<webrtc::DataChannelInterface> CreateDataChannel(
  51. const std::string& label,
  52. const webrtc::DataChannelInit& init);
  53. void WaitForNegotiation();
  54. // Implements PeerConnectionObserver.
  55. void OnSignalingChange(
  56. webrtc::PeerConnectionInterface::SignalingState new_state) override;
  57. void OnAddTrack(
  58. rtc::scoped_refptr<webrtc::RtpReceiverInterface> receiver,
  59. const std::vector<rtc::scoped_refptr<webrtc::MediaStreamInterface>>&
  60. streams) override;
  61. void OnDataChannel(
  62. rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) override;
  63. void OnRenegotiationNeeded() override {}
  64. void OnIceConnectionChange(
  65. webrtc::PeerConnectionInterface::IceConnectionState new_state) override {}
  66. void OnIceGatheringChange(
  67. webrtc::PeerConnectionInterface::IceGatheringState new_state) override {}
  68. void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override;
  69. // Implements CreateSessionDescriptionObserver.
  70. void OnSuccess(webrtc::SessionDescriptionInterface* desc) override;
  71. void OnFailure(webrtc::RTCError) override {}
  72. void CreateOffer(
  73. const webrtc::PeerConnectionInterface::RTCOfferAnswerOptions& options);
  74. void CreateAnswer(
  75. const webrtc::PeerConnectionInterface::RTCOfferAnswerOptions& options);
  76. void ReceiveOfferSdp(const std::string& sdp);
  77. void ReceiveAnswerSdp(const std::string& sdp);
  78. void AddIceCandidate(const std::string& sdp_mid,
  79. int sdp_mline_index,
  80. const std::string& candidate);
  81. void WaitForCallEstablished();
  82. void WaitForConnection();
  83. void WaitForAudio();
  84. void WaitForVideo();
  85. void GetAndAddUserMedia(bool audio,
  86. const cricket::AudioOptions& audio_options,
  87. bool video);
  88. // sigslots
  89. sigslot::signal1<std::string*> SignalOnIceCandidateCreated;
  90. sigslot::signal3<const std::string&, int, const std::string&>
  91. SignalOnIceCandidateReady;
  92. sigslot::signal1<std::string*> SignalOnSdpCreated;
  93. sigslot::signal1<const std::string&> SignalOnSdpReady;
  94. sigslot::signal1<webrtc::DataChannelInterface*> SignalOnDataChannel;
  95. private:
  96. void SetLocalDescription(webrtc::SdpType type, const std::string& sdp);
  97. void SetRemoteDescription(webrtc::SdpType type, const std::string& sdp);
  98. bool CheckForConnection();
  99. bool CheckForAudio();
  100. bool CheckForVideo();
  101. rtc::scoped_refptr<webrtc::MediaStreamInterface> GetUserMedia(
  102. bool audio,
  103. const cricket::AudioOptions& audio_options,
  104. bool video);
  105. std::string name_;
  106. rtc::Thread* const network_thread_;
  107. rtc::Thread* const worker_thread_;
  108. rtc::ThreadChecker pc_thread_checker_;
  109. rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
  110. rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>
  111. peer_connection_factory_;
  112. rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
  113. std::unique_ptr<webrtc::FakeVideoTrackRenderer> renderer_;
  114. int num_get_user_media_calls_ = 0;
  115. bool pending_negotiation_;
  116. };
  117. #endif // PC_TEST_PEER_CONNECTION_TEST_WRAPPER_H_