blob: 6b7fd5e95b7568d20a184cb31394bb79cb92099c [file] [log] [blame]
wu@webrtc.org364f2042013-11-20 21:49:41 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2013 The WebRTC project authors. All Rights Reserved.
wu@webrtc.org364f2042013-11-20 21:49:41 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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.org364f2042013-11-20 21:49:41 +00009 */
10
ossu7bb87ee2017-01-23 04:56:25 -080011#ifndef WEBRTC_PC_TEST_PEERCONNECTIONTESTWRAPPER_H_
12#define WEBRTC_PC_TEST_PEERCONNECTIONTESTWRAPPER_H_
wu@webrtc.org364f2042013-11-20 21:49:41 +000013
kwibergd1fe2812016-04-27 06:47:29 -070014#include <memory>
15
Henrik Kjellander15583c12016-02-10 10:53:12 +010016#include "webrtc/api/peerconnectioninterface.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010017#include "webrtc/api/test/fakeconstraints.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000018#include "webrtc/base/sigslot.h"
ossu7bb87ee2017-01-23 04:56:25 -080019#include "webrtc/pc/test/fakeaudiocapturemodule.h"
20#include "webrtc/pc/test/fakevideotrackrenderer.h"
wu@webrtc.org364f2042013-11-20 21:49:41 +000021
wu@webrtc.org364f2042013-11-20 21:49:41 +000022class 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
danilchape9021a32016-05-17 01:52:02 -070030 PeerConnectionTestWrapper(const std::string& name,
31 rtc::Thread* network_thread,
32 rtc::Thread* worker_thread);
wu@webrtc.org364f2042013-11-20 21:49:41 +000033 virtual ~PeerConnectionTestWrapper();
34
zhihuang9763d562016-08-05 11:14:50 -070035 bool CreatePc(
36 const webrtc::MediaConstraintsInterface* constraints,
37 const webrtc::PeerConnectionInterface::RTCConfiguration& config);
wu@webrtc.org364f2042013-11-20 21:49:41 +000038
hbosdb346a72016-11-29 01:57:01 -080039 webrtc::PeerConnectionInterface* pc() { return peer_connection_.get(); }
40
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000041 rtc::scoped_refptr<webrtc::DataChannelInterface> CreateDataChannel(
jiayl@webrtc.org1a6c6282014-06-12 21:59:29 +000042 const std::string& label,
43 const webrtc::DataChannelInit& init);
44
wu@webrtc.org364f2042013-11-20 21:49:41 +000045 // Implements PeerConnectionObserver.
nisse63b14b72017-01-31 03:34:01 -080046 void OnSignalingChange(
47 webrtc::PeerConnectionInterface::SignalingState new_state) override {}
48 void OnAddStream(
49 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) override;
50 void OnRemoveStream(
51 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) override {}
52 void OnDataChannel(
53 rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) override ;
54 void OnRenegotiationNeeded() override {}
55 void OnIceConnectionChange(
56 webrtc::PeerConnectionInterface::IceConnectionState new_state) override {}
57 void OnIceGatheringChange(
58 webrtc::PeerConnectionInterface::IceGatheringState new_state) override {}
59 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override;
wu@webrtc.org364f2042013-11-20 21:49:41 +000060
61 // Implements CreateSessionDescriptionObserver.
nisse63b14b72017-01-31 03:34:01 -080062 void OnSuccess(webrtc::SessionDescriptionInterface* desc) override;
63 void OnFailure(const std::string& error) override {}
wu@webrtc.org364f2042013-11-20 21:49:41 +000064
65 void CreateOffer(const webrtc::MediaConstraintsInterface* constraints);
66 void CreateAnswer(const webrtc::MediaConstraintsInterface* constraints);
67 void ReceiveOfferSdp(const std::string& sdp);
68 void ReceiveAnswerSdp(const std::string& sdp);
69 void AddIceCandidate(const std::string& sdp_mid, int sdp_mline_index,
70 const std::string& candidate);
71 void WaitForCallEstablished();
72 void WaitForConnection();
73 void WaitForAudio();
74 void WaitForVideo();
75 void GetAndAddUserMedia(
76 bool audio, const webrtc::FakeConstraints& audio_constraints,
77 bool video, const webrtc::FakeConstraints& video_constraints);
78
79 // sigslots
80 sigslot::signal1<std::string*> SignalOnIceCandidateCreated;
81 sigslot::signal3<const std::string&,
82 int,
83 const std::string&> SignalOnIceCandidateReady;
84 sigslot::signal1<std::string*> SignalOnSdpCreated;
85 sigslot::signal1<const std::string&> SignalOnSdpReady;
jiayl@webrtc.org1a6c6282014-06-12 21:59:29 +000086 sigslot::signal1<webrtc::DataChannelInterface*> SignalOnDataChannel;
wu@webrtc.org364f2042013-11-20 21:49:41 +000087
88 private:
89 void SetLocalDescription(const std::string& type, const std::string& sdp);
90 void SetRemoteDescription(const std::string& type, const std::string& sdp);
91 bool CheckForConnection();
92 bool CheckForAudio();
93 bool CheckForVideo();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000094 rtc::scoped_refptr<webrtc::MediaStreamInterface> GetUserMedia(
wu@webrtc.org364f2042013-11-20 21:49:41 +000095 bool audio, const webrtc::FakeConstraints& audio_constraints,
96 bool video, const webrtc::FakeConstraints& video_constraints);
97
98 std::string name_;
danilchape9021a32016-05-17 01:52:02 -070099 rtc::Thread* const network_thread_;
100 rtc::Thread* const worker_thread_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000101 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
102 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>
wu@webrtc.org364f2042013-11-20 21:49:41 +0000103 peer_connection_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000104 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
kwibergd1fe2812016-04-27 06:47:29 -0700105 std::unique_ptr<webrtc::FakeVideoTrackRenderer> renderer_;
wu@webrtc.org364f2042013-11-20 21:49:41 +0000106};
107
ossu7bb87ee2017-01-23 04:56:25 -0800108#endif // WEBRTC_PC_TEST_PEERCONNECTIONTESTWRAPPER_H_