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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef PC_TEST_PEERCONNECTIONTESTWRAPPER_H_ |
| 12 | #define PC_TEST_PEERCONNECTIONTESTWRAPPER_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> |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "api/peerconnectioninterface.h" |
| 18 | #include "api/test/fakeconstraints.h" |
| 19 | #include "pc/test/fakeaudiocapturemodule.h" |
| 20 | #include "pc/test/fakevideotrackrenderer.h" |
| 21 | #include "rtc_base/sigslot.h" |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 22 | |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 23 | class PeerConnectionTestWrapper |
| 24 | : public webrtc::PeerConnectionObserver, |
| 25 | public webrtc::CreateSessionDescriptionObserver, |
| 26 | public sigslot::has_slots<> { |
| 27 | public: |
| 28 | static void Connect(PeerConnectionTestWrapper* caller, |
| 29 | PeerConnectionTestWrapper* callee); |
| 30 | |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 31 | PeerConnectionTestWrapper(const std::string& name, |
| 32 | rtc::Thread* network_thread, |
| 33 | rtc::Thread* worker_thread); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 34 | virtual ~PeerConnectionTestWrapper(); |
| 35 | |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 36 | bool CreatePc( |
| 37 | const webrtc::MediaConstraintsInterface* constraints, |
kwiberg | 9e5b11e | 2017-04-19 03:47:57 -0700 | [diff] [blame] | 38 | const webrtc::PeerConnectionInterface::RTCConfiguration& config, |
| 39 | rtc::scoped_refptr<webrtc::AudioEncoderFactory> audio_encoder_factory, |
| 40 | rtc::scoped_refptr<webrtc::AudioDecoderFactory> audio_decoder_factory); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 41 | |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 42 | webrtc::PeerConnectionInterface* pc() { return peer_connection_.get(); } |
| 43 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 44 | rtc::scoped_refptr<webrtc::DataChannelInterface> CreateDataChannel( |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 45 | const std::string& label, |
| 46 | const webrtc::DataChannelInit& init); |
| 47 | |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 48 | // Implements PeerConnectionObserver. |
nisse | 63b14b7 | 2017-01-31 03:34:01 -0800 | [diff] [blame] | 49 | void OnSignalingChange( |
| 50 | webrtc::PeerConnectionInterface::SignalingState new_state) override {} |
| 51 | void OnAddStream( |
| 52 | rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) override; |
| 53 | void OnRemoveStream( |
| 54 | rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) override {} |
| 55 | void OnDataChannel( |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 56 | rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) override; |
nisse | 63b14b7 | 2017-01-31 03:34:01 -0800 | [diff] [blame] | 57 | void OnRenegotiationNeeded() override {} |
| 58 | void OnIceConnectionChange( |
| 59 | webrtc::PeerConnectionInterface::IceConnectionState new_state) override {} |
| 60 | void OnIceGatheringChange( |
| 61 | webrtc::PeerConnectionInterface::IceGatheringState new_state) override {} |
| 62 | void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 63 | |
| 64 | // Implements CreateSessionDescriptionObserver. |
nisse | 63b14b7 | 2017-01-31 03:34:01 -0800 | [diff] [blame] | 65 | void OnSuccess(webrtc::SessionDescriptionInterface* desc) override; |
| 66 | void OnFailure(const std::string& error) override {} |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 67 | |
| 68 | void CreateOffer(const webrtc::MediaConstraintsInterface* constraints); |
| 69 | void CreateAnswer(const webrtc::MediaConstraintsInterface* constraints); |
| 70 | void ReceiveOfferSdp(const std::string& sdp); |
| 71 | void ReceiveAnswerSdp(const std::string& sdp); |
| 72 | void AddIceCandidate(const std::string& sdp_mid, int sdp_mline_index, |
| 73 | const std::string& candidate); |
| 74 | void WaitForCallEstablished(); |
| 75 | void WaitForConnection(); |
| 76 | void WaitForAudio(); |
| 77 | void WaitForVideo(); |
| 78 | void GetAndAddUserMedia( |
| 79 | bool audio, const webrtc::FakeConstraints& audio_constraints, |
| 80 | bool video, const webrtc::FakeConstraints& video_constraints); |
| 81 | |
| 82 | // sigslots |
| 83 | sigslot::signal1<std::string*> SignalOnIceCandidateCreated; |
| 84 | sigslot::signal3<const std::string&, |
| 85 | int, |
| 86 | const std::string&> SignalOnIceCandidateReady; |
| 87 | sigslot::signal1<std::string*> SignalOnSdpCreated; |
| 88 | sigslot::signal1<const std::string&> SignalOnSdpReady; |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 89 | sigslot::signal1<webrtc::DataChannelInterface*> SignalOnDataChannel; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 90 | |
| 91 | private: |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 92 | void SetLocalDescription(webrtc::SdpType type, const std::string& sdp); |
| 93 | void SetRemoteDescription(webrtc::SdpType type, const std::string& sdp); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 94 | bool CheckForConnection(); |
| 95 | bool CheckForAudio(); |
| 96 | bool CheckForVideo(); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 97 | rtc::scoped_refptr<webrtc::MediaStreamInterface> GetUserMedia( |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 98 | bool audio, const webrtc::FakeConstraints& audio_constraints, |
| 99 | bool video, const webrtc::FakeConstraints& video_constraints); |
| 100 | |
| 101 | std::string name_; |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 102 | rtc::Thread* const network_thread_; |
| 103 | rtc::Thread* const worker_thread_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 104 | rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_; |
| 105 | rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 106 | peer_connection_factory_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 107 | rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 108 | std::unique_ptr<webrtc::FakeVideoTrackRenderer> renderer_; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 109 | }; |
| 110 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 111 | #endif // PC_TEST_PEERCONNECTIONTESTWRAPPER_H_ |