wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2013 The WebRTC project authors. All Rights Reserved. |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [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 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [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 +0000 | [diff] [blame] | 13 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 14 | #include <memory> |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 15 | #include <string> |
Steve Anton | 191c39f | 2018-01-24 19:35:55 -0800 | [diff] [blame] | 16 | #include <vector> |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 17 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [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 09:11:00 -0800 | [diff] [blame] | 21 | #include "api/data_channel_interface.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 22 | #include "api/jsep.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 23 | #include "api/media_stream_interface.h" |
| 24 | #include "api/peer_connection_interface.h" |
| 25 | #include "api/rtc_error.h" |
| 26 | #include "api/rtp_receiver_interface.h" |
| 27 | #include "api/test/fake_constraints.h" |
| 28 | #include "pc/test/fake_audio_capture_module.h" |
| 29 | #include "pc/test/fake_video_track_renderer.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 30 | #include "rtc_base/scoped_ref_ptr.h" |
Artem Titov | e41c433 | 2018-07-25 15:04:28 +0200 | [diff] [blame] | 31 | #include "rtc_base/third_party/sigslot/sigslot.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 32 | #include "rtc_base/thread.h" |
Yves Gerey | 59cfd35 | 2018-11-26 16:22:20 +0100 | [diff] [blame] | 33 | #include "rtc_base/thread_checker.h" |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 34 | |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 35 | class PeerConnectionTestWrapper |
| 36 | : public webrtc::PeerConnectionObserver, |
| 37 | public webrtc::CreateSessionDescriptionObserver, |
| 38 | public sigslot::has_slots<> { |
| 39 | public: |
| 40 | static void Connect(PeerConnectionTestWrapper* caller, |
| 41 | PeerConnectionTestWrapper* callee); |
| 42 | |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 43 | PeerConnectionTestWrapper(const std::string& name, |
| 44 | rtc::Thread* network_thread, |
| 45 | rtc::Thread* worker_thread); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 46 | virtual ~PeerConnectionTestWrapper(); |
| 47 | |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 48 | bool CreatePc( |
kwiberg | 9e5b11e | 2017-04-19 03:47:57 -0700 | [diff] [blame] | 49 | const webrtc::PeerConnectionInterface::RTCConfiguration& config, |
| 50 | rtc::scoped_refptr<webrtc::AudioEncoderFactory> audio_encoder_factory, |
| 51 | rtc::scoped_refptr<webrtc::AudioDecoderFactory> audio_decoder_factory); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 52 | |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 53 | webrtc::PeerConnectionInterface* pc() { return peer_connection_.get(); } |
| 54 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 55 | rtc::scoped_refptr<webrtc::DataChannelInterface> CreateDataChannel( |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 56 | const std::string& label, |
| 57 | const webrtc::DataChannelInit& init); |
| 58 | |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 59 | // Implements PeerConnectionObserver. |
nisse | 63b14b7 | 2017-01-31 03:34:01 -0800 | [diff] [blame] | 60 | void OnSignalingChange( |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 61 | webrtc::PeerConnectionInterface::SignalingState new_state) override {} |
Steve Anton | 191c39f | 2018-01-24 19:35:55 -0800 | [diff] [blame] | 62 | void OnAddTrack( |
| 63 | rtc::scoped_refptr<webrtc::RtpReceiverInterface> receiver, |
| 64 | const std::vector<rtc::scoped_refptr<webrtc::MediaStreamInterface>>& |
| 65 | streams) override; |
nisse | 63b14b7 | 2017-01-31 03:34:01 -0800 | [diff] [blame] | 66 | void OnDataChannel( |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 67 | rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) override; |
nisse | 63b14b7 | 2017-01-31 03:34:01 -0800 | [diff] [blame] | 68 | void OnRenegotiationNeeded() override {} |
| 69 | void OnIceConnectionChange( |
| 70 | webrtc::PeerConnectionInterface::IceConnectionState new_state) override {} |
| 71 | void OnIceGatheringChange( |
| 72 | webrtc::PeerConnectionInterface::IceGatheringState new_state) override {} |
| 73 | void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 74 | |
| 75 | // Implements CreateSessionDescriptionObserver. |
nisse | 63b14b7 | 2017-01-31 03:34:01 -0800 | [diff] [blame] | 76 | void OnSuccess(webrtc::SessionDescriptionInterface* desc) override; |
Harald Alvestrand | 5081c0c | 2018-03-09 15:18:03 +0100 | [diff] [blame] | 77 | void OnFailure(webrtc::RTCError) override {} |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 78 | |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 79 | void CreateOffer( |
| 80 | const webrtc::PeerConnectionInterface::RTCOfferAnswerOptions& options); |
| 81 | void CreateAnswer( |
| 82 | const webrtc::PeerConnectionInterface::RTCOfferAnswerOptions& options); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 83 | void ReceiveOfferSdp(const std::string& sdp); |
| 84 | void ReceiveAnswerSdp(const std::string& sdp); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 85 | void AddIceCandidate(const std::string& sdp_mid, |
| 86 | int sdp_mline_index, |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 87 | const std::string& candidate); |
| 88 | void WaitForCallEstablished(); |
| 89 | void WaitForConnection(); |
| 90 | void WaitForAudio(); |
| 91 | void WaitForVideo(); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 92 | void GetAndAddUserMedia(bool audio, |
| 93 | const cricket::AudioOptions& audio_options, |
| 94 | bool video, |
| 95 | const webrtc::FakeConstraints& video_constraints); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 96 | |
| 97 | // sigslots |
| 98 | sigslot::signal1<std::string*> SignalOnIceCandidateCreated; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 99 | sigslot::signal3<const std::string&, int, const std::string&> |
| 100 | SignalOnIceCandidateReady; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 101 | sigslot::signal1<std::string*> SignalOnSdpCreated; |
| 102 | sigslot::signal1<const std::string&> SignalOnSdpReady; |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 103 | sigslot::signal1<webrtc::DataChannelInterface*> SignalOnDataChannel; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 104 | |
| 105 | private: |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 106 | void SetLocalDescription(webrtc::SdpType type, const std::string& sdp); |
| 107 | void SetRemoteDescription(webrtc::SdpType type, const std::string& sdp); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 108 | bool CheckForConnection(); |
| 109 | bool CheckForAudio(); |
| 110 | bool CheckForVideo(); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 111 | rtc::scoped_refptr<webrtc::MediaStreamInterface> GetUserMedia( |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 112 | bool audio, |
| 113 | const cricket::AudioOptions& audio_options, |
| 114 | bool video, |
| 115 | const webrtc::FakeConstraints& video_constraints); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 116 | |
| 117 | std::string name_; |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 118 | rtc::Thread* const network_thread_; |
| 119 | rtc::Thread* const worker_thread_; |
Yves Gerey | 59cfd35 | 2018-11-26 16:22:20 +0100 | [diff] [blame] | 120 | rtc::ThreadChecker pc_thread_checker_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 121 | rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_; |
| 122 | rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 123 | peer_connection_factory_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 124 | rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 125 | std::unique_ptr<webrtc::FakeVideoTrackRenderer> renderer_; |
Steve Anton | fc85371 | 2018-03-01 13:48:58 -0800 | [diff] [blame] | 126 | int num_get_user_media_calls_ = 0; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 127 | }; |
| 128 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 129 | #endif // PC_TEST_PEER_CONNECTION_TEST_WRAPPER_H_ |