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