blob: d9488b45bb369bf6e039901bd2edcd3b0b830297 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef PC_TEST_PEERCONNECTIONTESTWRAPPER_H_
12#define PC_TEST_PEERCONNECTIONTESTWRAPPER_H_
wu@webrtc.org364f2042013-11-20 21:49:41 +000013
kwibergd1fe2812016-04-27 06:47:29 -070014#include <memory>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "api/peerconnectioninterface.h"
17#include "api/test/fakeconstraints.h"
18#include "pc/test/fakeaudiocapturemodule.h"
19#include "pc/test/fakevideotrackrenderer.h"
20#include "rtc_base/sigslot.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,
kwiberg9e5b11e2017-04-19 03:47:57 -070037 const webrtc::PeerConnectionInterface::RTCConfiguration& config,
38 rtc::scoped_refptr<webrtc::AudioEncoderFactory> audio_encoder_factory,
39 rtc::scoped_refptr<webrtc::AudioDecoderFactory> audio_decoder_factory);
wu@webrtc.org364f2042013-11-20 21:49:41 +000040
hbosdb346a72016-11-29 01:57:01 -080041 webrtc::PeerConnectionInterface* pc() { return peer_connection_.get(); }
42
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000043 rtc::scoped_refptr<webrtc::DataChannelInterface> CreateDataChannel(
jiayl@webrtc.org1a6c6282014-06-12 21:59:29 +000044 const std::string& label,
45 const webrtc::DataChannelInit& init);
46
wu@webrtc.org364f2042013-11-20 21:49:41 +000047 // Implements PeerConnectionObserver.
nisse63b14b72017-01-31 03:34:01 -080048 void OnSignalingChange(
49 webrtc::PeerConnectionInterface::SignalingState new_state) override {}
50 void OnAddStream(
51 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) override;
52 void OnRemoveStream(
53 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) override {}
54 void OnDataChannel(
55 rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) override ;
56 void OnRenegotiationNeeded() override {}
57 void OnIceConnectionChange(
58 webrtc::PeerConnectionInterface::IceConnectionState new_state) override {}
59 void OnIceGatheringChange(
60 webrtc::PeerConnectionInterface::IceGatheringState new_state) override {}
61 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override;
wu@webrtc.org364f2042013-11-20 21:49:41 +000062
63 // Implements CreateSessionDescriptionObserver.
nisse63b14b72017-01-31 03:34:01 -080064 void OnSuccess(webrtc::SessionDescriptionInterface* desc) override;
65 void OnFailure(const std::string& error) override {}
wu@webrtc.org364f2042013-11-20 21:49:41 +000066
67 void CreateOffer(const webrtc::MediaConstraintsInterface* constraints);
68 void CreateAnswer(const webrtc::MediaConstraintsInterface* constraints);
69 void ReceiveOfferSdp(const std::string& sdp);
70 void ReceiveAnswerSdp(const std::string& sdp);
71 void AddIceCandidate(const std::string& sdp_mid, int sdp_mline_index,
72 const std::string& candidate);
73 void WaitForCallEstablished();
74 void WaitForConnection();
75 void WaitForAudio();
76 void WaitForVideo();
77 void GetAndAddUserMedia(
78 bool audio, const webrtc::FakeConstraints& audio_constraints,
79 bool video, const webrtc::FakeConstraints& video_constraints);
80
81 // sigslots
82 sigslot::signal1<std::string*> SignalOnIceCandidateCreated;
83 sigslot::signal3<const std::string&,
84 int,
85 const std::string&> SignalOnIceCandidateReady;
86 sigslot::signal1<std::string*> SignalOnSdpCreated;
87 sigslot::signal1<const std::string&> SignalOnSdpReady;
jiayl@webrtc.org1a6c6282014-06-12 21:59:29 +000088 sigslot::signal1<webrtc::DataChannelInterface*> SignalOnDataChannel;
wu@webrtc.org364f2042013-11-20 21:49:41 +000089
90 private:
91 void SetLocalDescription(const std::string& type, const std::string& sdp);
92 void SetRemoteDescription(const std::string& type, const std::string& sdp);
93 bool CheckForConnection();
94 bool CheckForAudio();
95 bool CheckForVideo();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000096 rtc::scoped_refptr<webrtc::MediaStreamInterface> GetUserMedia(
wu@webrtc.org364f2042013-11-20 21:49:41 +000097 bool audio, const webrtc::FakeConstraints& audio_constraints,
98 bool video, const webrtc::FakeConstraints& video_constraints);
99
100 std::string name_;
danilchape9021a32016-05-17 01:52:02 -0700101 rtc::Thread* const network_thread_;
102 rtc::Thread* const worker_thread_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000103 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
104 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>
wu@webrtc.org364f2042013-11-20 21:49:41 +0000105 peer_connection_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000106 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
kwibergd1fe2812016-04-27 06:47:29 -0700107 std::unique_ptr<webrtc::FakeVideoTrackRenderer> renderer_;
wu@webrtc.org364f2042013-11-20 21:49:41 +0000108};
109
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200110#endif // PC_TEST_PEERCONNECTIONTESTWRAPPER_H_