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