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