blob: f82bcf235ad1c2f6f08c3481cead97ed7b61e160 [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>
Steve Anton36b29d12017-10-30 09:57:42 -070015#include <string>
Steve Anton191c39f2018-01-24 19:35:55 -080016#include <vector>
kwibergd1fe2812016-04-27 06:47:29 -070017
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "api/peerconnectioninterface.h"
19#include "api/test/fakeconstraints.h"
20#include "pc/test/fakeaudiocapturemodule.h"
21#include "pc/test/fakevideotrackrenderer.h"
Artem Titove41c4332018-07-25 15:04:28 +020022#include "rtc_base/third_party/sigslot/sigslot.h"
wu@webrtc.org364f2042013-11-20 21:49:41 +000023
wu@webrtc.org364f2042013-11-20 21:49:41 +000024class PeerConnectionTestWrapper
25 : public webrtc::PeerConnectionObserver,
26 public webrtc::CreateSessionDescriptionObserver,
27 public sigslot::has_slots<> {
28 public:
29 static void Connect(PeerConnectionTestWrapper* caller,
30 PeerConnectionTestWrapper* callee);
31
danilchape9021a32016-05-17 01:52:02 -070032 PeerConnectionTestWrapper(const std::string& name,
33 rtc::Thread* network_thread,
34 rtc::Thread* worker_thread);
wu@webrtc.org364f2042013-11-20 21:49:41 +000035 virtual ~PeerConnectionTestWrapper();
36
zhihuang9763d562016-08-05 11:14:50 -070037 bool CreatePc(
38 const webrtc::MediaConstraintsInterface* constraints,
kwiberg9e5b11e2017-04-19 03:47:57 -070039 const webrtc::PeerConnectionInterface::RTCConfiguration& config,
40 rtc::scoped_refptr<webrtc::AudioEncoderFactory> audio_encoder_factory,
41 rtc::scoped_refptr<webrtc::AudioDecoderFactory> audio_decoder_factory);
wu@webrtc.org364f2042013-11-20 21:49:41 +000042
hbosdb346a72016-11-29 01:57:01 -080043 webrtc::PeerConnectionInterface* pc() { return peer_connection_.get(); }
44
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000045 rtc::scoped_refptr<webrtc::DataChannelInterface> CreateDataChannel(
jiayl@webrtc.org1a6c6282014-06-12 21:59:29 +000046 const std::string& label,
47 const webrtc::DataChannelInit& init);
48
wu@webrtc.org364f2042013-11-20 21:49:41 +000049 // Implements PeerConnectionObserver.
nisse63b14b72017-01-31 03:34:01 -080050 void OnSignalingChange(
Yves Gerey665174f2018-06-19 15:03:05 +020051 webrtc::PeerConnectionInterface::SignalingState new_state) override {}
Steve Anton191c39f2018-01-24 19:35:55 -080052 void OnAddTrack(
53 rtc::scoped_refptr<webrtc::RtpReceiverInterface> receiver,
54 const std::vector<rtc::scoped_refptr<webrtc::MediaStreamInterface>>&
55 streams) override;
nisse63b14b72017-01-31 03:34:01 -080056 void OnDataChannel(
Steve Anton36b29d12017-10-30 09:57:42 -070057 rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) override;
nisse63b14b72017-01-31 03:34:01 -080058 void OnRenegotiationNeeded() override {}
59 void OnIceConnectionChange(
60 webrtc::PeerConnectionInterface::IceConnectionState new_state) override {}
61 void OnIceGatheringChange(
62 webrtc::PeerConnectionInterface::IceGatheringState new_state) override {}
63 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override;
wu@webrtc.org364f2042013-11-20 21:49:41 +000064
65 // Implements CreateSessionDescriptionObserver.
nisse63b14b72017-01-31 03:34:01 -080066 void OnSuccess(webrtc::SessionDescriptionInterface* desc) override;
Harald Alvestrand5081c0c2018-03-09 15:18:03 +010067 void OnFailure(webrtc::RTCError) override {}
wu@webrtc.org364f2042013-11-20 21:49:41 +000068
69 void CreateOffer(const webrtc::MediaConstraintsInterface* constraints);
70 void CreateAnswer(const webrtc::MediaConstraintsInterface* constraints);
71 void ReceiveOfferSdp(const std::string& sdp);
72 void ReceiveAnswerSdp(const std::string& sdp);
Yves Gerey665174f2018-06-19 15:03:05 +020073 void AddIceCandidate(const std::string& sdp_mid,
74 int sdp_mline_index,
wu@webrtc.org364f2042013-11-20 21:49:41 +000075 const std::string& candidate);
76 void WaitForCallEstablished();
77 void WaitForConnection();
78 void WaitForAudio();
79 void WaitForVideo();
Yves Gerey665174f2018-06-19 15:03:05 +020080 void GetAndAddUserMedia(bool audio,
81 const cricket::AudioOptions& audio_options,
82 bool video,
83 const webrtc::FakeConstraints& video_constraints);
wu@webrtc.org364f2042013-11-20 21:49:41 +000084
85 // sigslots
86 sigslot::signal1<std::string*> SignalOnIceCandidateCreated;
Yves Gerey665174f2018-06-19 15:03:05 +020087 sigslot::signal3<const std::string&, int, const std::string&>
88 SignalOnIceCandidateReady;
wu@webrtc.org364f2042013-11-20 21:49:41 +000089 sigslot::signal1<std::string*> SignalOnSdpCreated;
90 sigslot::signal1<const std::string&> SignalOnSdpReady;
jiayl@webrtc.org1a6c6282014-06-12 21:59:29 +000091 sigslot::signal1<webrtc::DataChannelInterface*> SignalOnDataChannel;
wu@webrtc.org364f2042013-11-20 21:49:41 +000092
93 private:
Steve Antona3a92c22017-12-07 10:27:41 -080094 void SetLocalDescription(webrtc::SdpType type, const std::string& sdp);
95 void SetRemoteDescription(webrtc::SdpType type, const std::string& sdp);
wu@webrtc.org364f2042013-11-20 21:49:41 +000096 bool CheckForConnection();
97 bool CheckForAudio();
98 bool CheckForVideo();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000099 rtc::scoped_refptr<webrtc::MediaStreamInterface> GetUserMedia(
Yves Gerey665174f2018-06-19 15:03:05 +0200100 bool audio,
101 const cricket::AudioOptions& audio_options,
102 bool video,
103 const webrtc::FakeConstraints& video_constraints);
wu@webrtc.org364f2042013-11-20 21:49:41 +0000104
105 std::string name_;
danilchape9021a32016-05-17 01:52:02 -0700106 rtc::Thread* const network_thread_;
107 rtc::Thread* const worker_thread_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000108 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
109 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>
wu@webrtc.org364f2042013-11-20 21:49:41 +0000110 peer_connection_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000111 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
kwibergd1fe2812016-04-27 06:47:29 -0700112 std::unique_ptr<webrtc::FakeVideoTrackRenderer> renderer_;
Steve Antonfc853712018-03-01 13:48:58 -0800113 int num_get_user_media_calls_ = 0;
wu@webrtc.org364f2042013-11-20 21:49:41 +0000114};
115
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200116#endif // PC_TEST_PEERCONNECTIONTESTWRAPPER_H_