wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 15:54:43 | [diff] [blame] | 2 | * Copyright 2013 The WebRTC project authors. All Rights Reserved. |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 15:54:43 | [diff] [blame] | 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. |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 | [diff] [blame] | 9 | */ |
| 10 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 11 | #ifndef PC_TEST_PEER_CONNECTION_TEST_WRAPPER_H_ |
| 12 | #define PC_TEST_PEER_CONNECTION_TEST_WRAPPER_H_ |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 | [diff] [blame] | 13 | |
kwiberg | d1fe281 | 2016-04-27 13:47:29 | [diff] [blame] | 14 | #include <memory> |
Steve Anton | 36b29d1 | 2017-10-30 16:57:42 | [diff] [blame] | 15 | #include <string> |
Steve Anton | 191c39f | 2018-01-25 03:35:55 | [diff] [blame] | 16 | #include <vector> |
kwiberg | d1fe281 | 2016-04-27 13:47:29 | [diff] [blame] | 17 | |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 18 | #include "api/audio_codecs/audio_decoder_factory.h" |
| 19 | #include "api/audio_codecs/audio_encoder_factory.h" |
| 20 | #include "api/audio_options.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 21 | #include "api/data_channel_interface.h" |
Florent Castelli | 64d68c3 | 2024-09-03 09:14:37 | [diff] [blame] | 22 | #include "api/field_trials_view.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 23 | #include "api/jsep.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 24 | #include "api/media_stream_interface.h" |
| 25 | #include "api/peer_connection_interface.h" |
| 26 | #include "api/rtc_error.h" |
Florent Castelli | 43a5dd8 | 2023-04-12 10:45:07 | [diff] [blame] | 27 | #include "api/rtp_parameters.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 28 | #include "api/rtp_receiver_interface.h" |
Mirko Bonadei | d970807 | 2019-01-25 19:26:48 | [diff] [blame] | 29 | #include "api/scoped_refptr.h" |
Artem Titov | d15a575 | 2021-02-10 13:31:24 | [diff] [blame] | 30 | #include "api/sequence_checker.h" |
Henrik Boström | fd4ddd1 | 2023-02-08 10:29:20 | [diff] [blame] | 31 | #include "api/video/resolution.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 32 | #include "pc/test/fake_audio_capture_module.h" |
Henrik Boström | fd4ddd1 | 2023-02-08 10:29:20 | [diff] [blame] | 33 | #include "pc/test/fake_periodic_video_source.h" |
Henrik Boström | 89f095c | 2023-04-03 15:57:47 | [diff] [blame] | 34 | #include "pc/test/fake_periodic_video_track_source.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 35 | #include "pc/test/fake_video_track_renderer.h" |
Artem Titov | e41c433 | 2018-07-25 13:04:28 | [diff] [blame] | 36 | #include "rtc_base/third_party/sigslot/sigslot.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 37 | #include "rtc_base/thread.h" |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 | [diff] [blame] | 38 | |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 | [diff] [blame] | 39 | class PeerConnectionTestWrapper |
| 40 | : public webrtc::PeerConnectionObserver, |
| 41 | public webrtc::CreateSessionDescriptionObserver, |
| 42 | public sigslot::has_slots<> { |
| 43 | public: |
| 44 | static void Connect(PeerConnectionTestWrapper* caller, |
| 45 | PeerConnectionTestWrapper* callee); |
| 46 | |
danilchap | e9021a3 | 2016-05-17 08:52:02 | [diff] [blame] | 47 | PeerConnectionTestWrapper(const std::string& name, |
Byoungchan Lee | d58f526 | 2022-06-27 09:05:22 | [diff] [blame] | 48 | rtc::SocketServer* socket_server, |
danilchap | e9021a3 | 2016-05-17 08:52:02 | [diff] [blame] | 49 | rtc::Thread* network_thread, |
| 50 | rtc::Thread* worker_thread); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 | [diff] [blame] | 51 | virtual ~PeerConnectionTestWrapper(); |
| 52 | |
zhihuang | 9763d56 | 2016-08-05 18:14:50 | [diff] [blame] | 53 | bool CreatePc( |
kwiberg | 9e5b11e | 2017-04-19 10:47:57 | [diff] [blame] | 54 | const webrtc::PeerConnectionInterface::RTCConfiguration& config, |
| 55 | rtc::scoped_refptr<webrtc::AudioEncoderFactory> audio_encoder_factory, |
Danil Chapovalov | acf26ce | 2024-12-16 10:37:36 | [diff] [blame] | 56 | rtc::scoped_refptr<webrtc::AudioDecoderFactory> audio_decoder_factory, |
| 57 | std::unique_ptr<webrtc::FieldTrialsView> field_trials = nullptr); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 | [diff] [blame] | 58 | |
Henrik Boström | 4c1e7cc | 2020-06-11 10:26:53 | [diff] [blame] | 59 | rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory() |
| 60 | const { |
| 61 | return peer_connection_factory_; |
| 62 | } |
hbos | db346a7 | 2016-11-29 09:57:01 | [diff] [blame] | 63 | webrtc::PeerConnectionInterface* pc() { return peer_connection_.get(); } |
| 64 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 65 | rtc::scoped_refptr<webrtc::DataChannelInterface> CreateDataChannel( |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 | [diff] [blame] | 66 | const std::string& label, |
| 67 | const webrtc::DataChannelInit& init); |
| 68 | |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 69 | std::optional<webrtc::RtpCodecCapability> FindFirstSendCodecWithName( |
Florent Castelli | 43a5dd8 | 2023-04-12 10:45:07 | [diff] [blame] | 70 | cricket::MediaType media_type, |
| 71 | const std::string& name) const; |
| 72 | |
Henrik Boström | 4c1e7cc | 2020-06-11 10:26:53 | [diff] [blame] | 73 | void WaitForNegotiation(); |
| 74 | |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 | [diff] [blame] | 75 | // Implements PeerConnectionObserver. |
nisse | 63b14b7 | 2017-01-31 11:34:01 | [diff] [blame] | 76 | void OnSignalingChange( |
Henrik Boström | 4c1e7cc | 2020-06-11 10:26:53 | [diff] [blame] | 77 | webrtc::PeerConnectionInterface::SignalingState new_state) override; |
Steve Anton | 191c39f | 2018-01-25 03:35:55 | [diff] [blame] | 78 | void OnAddTrack( |
| 79 | rtc::scoped_refptr<webrtc::RtpReceiverInterface> receiver, |
| 80 | const std::vector<rtc::scoped_refptr<webrtc::MediaStreamInterface>>& |
| 81 | streams) override; |
nisse | 63b14b7 | 2017-01-31 11:34:01 | [diff] [blame] | 82 | void OnDataChannel( |
Steve Anton | 36b29d1 | 2017-10-30 16:57:42 | [diff] [blame] | 83 | rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) override; |
nisse | 63b14b7 | 2017-01-31 11:34:01 | [diff] [blame] | 84 | void OnRenegotiationNeeded() override {} |
| 85 | void OnIceConnectionChange( |
| 86 | webrtc::PeerConnectionInterface::IceConnectionState new_state) override {} |
| 87 | void OnIceGatheringChange( |
| 88 | webrtc::PeerConnectionInterface::IceGatheringState new_state) override {} |
| 89 | void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 | [diff] [blame] | 90 | |
| 91 | // Implements CreateSessionDescriptionObserver. |
nisse | 63b14b7 | 2017-01-31 11:34:01 | [diff] [blame] | 92 | void OnSuccess(webrtc::SessionDescriptionInterface* desc) override; |
Harald Alvestrand | 5081c0c | 2018-03-09 14:18:03 | [diff] [blame] | 93 | void OnFailure(webrtc::RTCError) override {} |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 | [diff] [blame] | 94 | |
Niels Möller | f06f923 | 2018-08-07 10:32:18 | [diff] [blame] | 95 | void CreateOffer( |
| 96 | const webrtc::PeerConnectionInterface::RTCOfferAnswerOptions& options); |
| 97 | void CreateAnswer( |
| 98 | const webrtc::PeerConnectionInterface::RTCOfferAnswerOptions& options); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 | [diff] [blame] | 99 | void ReceiveOfferSdp(const std::string& sdp); |
| 100 | void ReceiveAnswerSdp(const std::string& sdp); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 101 | void AddIceCandidate(const std::string& sdp_mid, |
| 102 | int sdp_mline_index, |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 | [diff] [blame] | 103 | const std::string& candidate); |
Harald Alvestrand | b3ac753 | 2024-09-30 14:02:58 | [diff] [blame] | 104 | bool WaitForCallEstablished(); |
| 105 | bool WaitForConnection(); |
| 106 | bool WaitForAudio(); |
| 107 | bool WaitForVideo(); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 108 | void GetAndAddUserMedia(bool audio, |
| 109 | const cricket::AudioOptions& audio_options, |
Niels Möller | 5c4ddad | 2019-02-12 11:30:58 | [diff] [blame] | 110 | bool video); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 | [diff] [blame] | 111 | |
| 112 | // sigslots |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 113 | sigslot::signal3<const std::string&, int, const std::string&> |
| 114 | SignalOnIceCandidateReady; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 | [diff] [blame] | 115 | sigslot::signal1<const std::string&> SignalOnSdpReady; |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 | [diff] [blame] | 116 | sigslot::signal1<webrtc::DataChannelInterface*> SignalOnDataChannel; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 | [diff] [blame] | 117 | |
Henrik Boström | fd4ddd1 | 2023-02-08 10:29:20 | [diff] [blame] | 118 | rtc::scoped_refptr<webrtc::MediaStreamInterface> GetUserMedia( |
| 119 | bool audio, |
| 120 | const cricket::AudioOptions& audio_options, |
| 121 | bool video, |
| 122 | webrtc::Resolution resolution = { |
| 123 | .width = webrtc::FakePeriodicVideoSource::kDefaultWidth, |
| 124 | .height = webrtc::FakePeriodicVideoSource::kDefaultHeight}); |
Henrik Boström | 89f095c | 2023-04-03 15:57:47 | [diff] [blame] | 125 | void StopFakeVideoSources(); |
Henrik Boström | fd4ddd1 | 2023-02-08 10:29:20 | [diff] [blame] | 126 | |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 | [diff] [blame] | 127 | private: |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 128 | void SetLocalDescription(webrtc::SdpType type, const std::string& sdp); |
| 129 | void SetRemoteDescription(webrtc::SdpType type, const std::string& sdp); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 | [diff] [blame] | 130 | bool CheckForConnection(); |
| 131 | bool CheckForAudio(); |
| 132 | bool CheckForVideo(); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 | [diff] [blame] | 133 | |
| 134 | std::string name_; |
Byoungchan Lee | d58f526 | 2022-06-27 09:05:22 | [diff] [blame] | 135 | rtc::SocketServer* const socket_server_; |
danilchap | e9021a3 | 2016-05-17 08:52:02 | [diff] [blame] | 136 | rtc::Thread* const network_thread_; |
| 137 | rtc::Thread* const worker_thread_; |
Artem Titov | c8421c4 | 2021-02-02 09:57:19 | [diff] [blame] | 138 | webrtc::SequenceChecker pc_thread_checker_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 139 | rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_; |
| 140 | rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 | [diff] [blame] | 141 | peer_connection_factory_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 142 | rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_; |
kwiberg | d1fe281 | 2016-04-27 13:47:29 | [diff] [blame] | 143 | std::unique_ptr<webrtc::FakeVideoTrackRenderer> renderer_; |
Steve Anton | fc85371 | 2018-03-01 21:48:58 | [diff] [blame] | 144 | int num_get_user_media_calls_ = 0; |
Henrik Boström | 4c1e7cc | 2020-06-11 10:26:53 | [diff] [blame] | 145 | bool pending_negotiation_; |
Henrik Boström | 89f095c | 2023-04-03 15:57:47 | [diff] [blame] | 146 | std::vector<rtc::scoped_refptr<webrtc::FakePeriodicVideoTrackSource>> |
| 147 | fake_video_sources_; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 | [diff] [blame] | 148 | }; |
| 149 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 150 | #endif // PC_TEST_PEER_CONNECTION_TEST_WRAPPER_H_ |