test_peer.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 TEST_PC_E2E_TEST_PEER_H_
  11. #define TEST_PC_E2E_TEST_PEER_H_
  12. #include <memory>
  13. #include <vector>
  14. #include "absl/memory/memory.h"
  15. #include "absl/types/variant.h"
  16. #include "api/test/frame_generator_interface.h"
  17. #include "api/test/peerconnection_quality_test_fixture.h"
  18. #include "pc/peer_connection_wrapper.h"
  19. #include "test/pc/e2e/peer_configurer.h"
  20. #include "test/pc/e2e/peer_connection_quality_test_params.h"
  21. namespace webrtc {
  22. namespace webrtc_pc_e2e {
  23. // Describes a single participant in the call.
  24. class TestPeer final {
  25. public:
  26. Params* params() const { return params_.get(); }
  27. PeerConfigurerImpl::VideoSource ReleaseVideoSource(size_t i) {
  28. return std::move(video_sources_[i]);
  29. }
  30. PeerConnectionFactoryInterface* pc_factory() {
  31. return wrapper_->pc_factory();
  32. }
  33. PeerConnectionInterface* pc() { return wrapper_->pc(); }
  34. MockPeerConnectionObserver* observer() { return wrapper_->observer(); }
  35. std::unique_ptr<SessionDescriptionInterface> CreateOffer() {
  36. return wrapper_->CreateOffer();
  37. }
  38. std::unique_ptr<SessionDescriptionInterface> CreateAnswer() {
  39. return wrapper_->CreateAnswer();
  40. }
  41. bool SetLocalDescription(std::unique_ptr<SessionDescriptionInterface> desc,
  42. std::string* error_out = nullptr) {
  43. return wrapper_->SetLocalDescription(std::move(desc), error_out);
  44. }
  45. bool SetRemoteDescription(std::unique_ptr<SessionDescriptionInterface> desc,
  46. std::string* error_out = nullptr) {
  47. return wrapper_->SetRemoteDescription(std::move(desc), error_out);
  48. }
  49. rtc::scoped_refptr<RtpTransceiverInterface> AddTransceiver(
  50. cricket::MediaType media_type,
  51. const RtpTransceiverInit& init) {
  52. return wrapper_->AddTransceiver(media_type, init);
  53. }
  54. rtc::scoped_refptr<RtpSenderInterface> AddTrack(
  55. rtc::scoped_refptr<MediaStreamTrackInterface> track,
  56. const std::vector<std::string>& stream_ids = {}) {
  57. return wrapper_->AddTrack(track, stream_ids);
  58. }
  59. rtc::scoped_refptr<DataChannelInterface> CreateDataChannel(
  60. const std::string& label) {
  61. return wrapper_->CreateDataChannel(label);
  62. }
  63. PeerConnectionInterface::SignalingState signaling_state() {
  64. return wrapper_->signaling_state();
  65. }
  66. bool IsIceGatheringDone() { return wrapper_->IsIceGatheringDone(); }
  67. bool IsIceConnected() { return wrapper_->IsIceConnected(); }
  68. rtc::scoped_refptr<const RTCStatsReport> GetStats() {
  69. return wrapper_->GetStats();
  70. }
  71. void DetachAecDump() {
  72. if (audio_processing_) {
  73. audio_processing_->DetachAecDump();
  74. }
  75. }
  76. // Adds provided |candidates| to the owned peer connection.
  77. bool AddIceCandidates(
  78. std::vector<std::unique_ptr<IceCandidateInterface>> candidates);
  79. protected:
  80. friend class TestPeerFactory;
  81. TestPeer(rtc::scoped_refptr<PeerConnectionFactoryInterface> pc_factory,
  82. rtc::scoped_refptr<PeerConnectionInterface> pc,
  83. std::unique_ptr<MockPeerConnectionObserver> observer,
  84. std::unique_ptr<Params> params,
  85. std::vector<PeerConfigurerImpl::VideoSource> video_sources,
  86. rtc::scoped_refptr<AudioProcessing> audio_processing,
  87. std::unique_ptr<rtc::Thread> worker_thread);
  88. private:
  89. // Keeps ownership of worker thread. It has to be destroyed after |wrapper_|.
  90. std::unique_ptr<rtc::Thread> worker_thread_;
  91. std::unique_ptr<PeerConnectionWrapper> wrapper_;
  92. std::unique_ptr<Params> params_;
  93. std::vector<PeerConfigurerImpl::VideoSource> video_sources_;
  94. rtc::scoped_refptr<AudioProcessing> audio_processing_;
  95. std::vector<std::unique_ptr<IceCandidateInterface>> remote_ice_candidates_;
  96. };
  97. } // namespace webrtc_pc_e2e
  98. } // namespace webrtc
  99. #endif // TEST_PC_E2E_TEST_PEER_H_