blob: 2dc88e930950fc81e3c99395f173800b6ba5c6ff [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
Steve Anton10542f22019-01-11 09:11:00 -080011#ifndef PC_TEST_PEER_CONNECTION_TEST_WRAPPER_H_
12#define PC_TEST_PEER_CONNECTION_TEST_WRAPPER_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
Yves Gerey3e707812018-11-28 16:47:49 +010018#include "api/audio_codecs/audio_decoder_factory.h"
19#include "api/audio_codecs/audio_encoder_factory.h"
20#include "api/audio_options.h"
Steve Anton10542f22019-01-11 09:11:00 -080021#include "api/data_channel_interface.h"
Yves Gerey3e707812018-11-28 16:47:49 +010022#include "api/jsep.h"
Steve Anton10542f22019-01-11 09:11:00 -080023#include "api/media_stream_interface.h"
24#include "api/peer_connection_interface.h"
25#include "api/rtc_error.h"
26#include "api/rtp_receiver_interface.h"
Mirko Bonadeid9708072019-01-25 20:26:48 +010027#include "api/scoped_refptr.h"
Steve Anton10542f22019-01-11 09:11:00 -080028#include "pc/test/fake_audio_capture_module.h"
29#include "pc/test/fake_video_track_renderer.h"
Artem Titove41c4332018-07-25 15:04:28 +020030#include "rtc_base/third_party/sigslot/sigslot.h"
Yves Gerey3e707812018-11-28 16:47:49 +010031#include "rtc_base/thread.h"
Yves Gerey59cfd352018-11-26 16:22:20 +010032#include "rtc_base/thread_checker.h"
wu@webrtc.org364f2042013-11-20 21:49:41 +000033
wu@webrtc.org364f2042013-11-20 21:49:41 +000034class PeerConnectionTestWrapper
35 : public webrtc::PeerConnectionObserver,
36 public webrtc::CreateSessionDescriptionObserver,
37 public sigslot::has_slots<> {
38 public:
39 static void Connect(PeerConnectionTestWrapper* caller,
40 PeerConnectionTestWrapper* callee);
41
danilchape9021a32016-05-17 01:52:02 -070042 PeerConnectionTestWrapper(const std::string& name,
43 rtc::Thread* network_thread,
44 rtc::Thread* worker_thread);
wu@webrtc.org364f2042013-11-20 21:49:41 +000045 virtual ~PeerConnectionTestWrapper();
46
zhihuang9763d562016-08-05 11:14:50 -070047 bool CreatePc(
kwiberg9e5b11e2017-04-19 03:47:57 -070048 const webrtc::PeerConnectionInterface::RTCConfiguration& config,
49 rtc::scoped_refptr<webrtc::AudioEncoderFactory> audio_encoder_factory,
50 rtc::scoped_refptr<webrtc::AudioDecoderFactory> audio_decoder_factory);
wu@webrtc.org364f2042013-11-20 21:49:41 +000051
hbosdb346a72016-11-29 01:57:01 -080052 webrtc::PeerConnectionInterface* pc() { return peer_connection_.get(); }
53
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000054 rtc::scoped_refptr<webrtc::DataChannelInterface> CreateDataChannel(
jiayl@webrtc.org1a6c6282014-06-12 21:59:29 +000055 const std::string& label,
56 const webrtc::DataChannelInit& init);
57
wu@webrtc.org364f2042013-11-20 21:49:41 +000058 // Implements PeerConnectionObserver.
nisse63b14b72017-01-31 03:34:01 -080059 void OnSignalingChange(
Yves Gerey665174f2018-06-19 15:03:05 +020060 webrtc::PeerConnectionInterface::SignalingState new_state) override {}
Steve Anton191c39f2018-01-24 19:35:55 -080061 void OnAddTrack(
62 rtc::scoped_refptr<webrtc::RtpReceiverInterface> receiver,
63 const std::vector<rtc::scoped_refptr<webrtc::MediaStreamInterface>>&
64 streams) override;
nisse63b14b72017-01-31 03:34:01 -080065 void OnDataChannel(
Steve Anton36b29d12017-10-30 09:57:42 -070066 rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) override;
nisse63b14b72017-01-31 03:34:01 -080067 void OnRenegotiationNeeded() override {}
68 void OnIceConnectionChange(
69 webrtc::PeerConnectionInterface::IceConnectionState new_state) override {}
70 void OnIceGatheringChange(
71 webrtc::PeerConnectionInterface::IceGatheringState new_state) override {}
72 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override;
wu@webrtc.org364f2042013-11-20 21:49:41 +000073
74 // Implements CreateSessionDescriptionObserver.
nisse63b14b72017-01-31 03:34:01 -080075 void OnSuccess(webrtc::SessionDescriptionInterface* desc) override;
Harald Alvestrand5081c0c2018-03-09 15:18:03 +010076 void OnFailure(webrtc::RTCError) override {}
wu@webrtc.org364f2042013-11-20 21:49:41 +000077
Niels Möllerf06f9232018-08-07 12:32:18 +020078 void CreateOffer(
79 const webrtc::PeerConnectionInterface::RTCOfferAnswerOptions& options);
80 void CreateAnswer(
81 const webrtc::PeerConnectionInterface::RTCOfferAnswerOptions& options);
wu@webrtc.org364f2042013-11-20 21:49:41 +000082 void ReceiveOfferSdp(const std::string& sdp);
83 void ReceiveAnswerSdp(const std::string& sdp);
Yves Gerey665174f2018-06-19 15:03:05 +020084 void AddIceCandidate(const std::string& sdp_mid,
85 int sdp_mline_index,
wu@webrtc.org364f2042013-11-20 21:49:41 +000086 const std::string& candidate);
87 void WaitForCallEstablished();
88 void WaitForConnection();
89 void WaitForAudio();
90 void WaitForVideo();
Yves Gerey665174f2018-06-19 15:03:05 +020091 void GetAndAddUserMedia(bool audio,
92 const cricket::AudioOptions& audio_options,
Niels Möller5c4ddad2019-02-12 12:30:58 +010093 bool video);
wu@webrtc.org364f2042013-11-20 21:49:41 +000094
95 // sigslots
96 sigslot::signal1<std::string*> SignalOnIceCandidateCreated;
Yves Gerey665174f2018-06-19 15:03:05 +020097 sigslot::signal3<const std::string&, int, const std::string&>
98 SignalOnIceCandidateReady;
wu@webrtc.org364f2042013-11-20 21:49:41 +000099 sigslot::signal1<std::string*> SignalOnSdpCreated;
100 sigslot::signal1<const std::string&> SignalOnSdpReady;
jiayl@webrtc.org1a6c6282014-06-12 21:59:29 +0000101 sigslot::signal1<webrtc::DataChannelInterface*> SignalOnDataChannel;
wu@webrtc.org364f2042013-11-20 21:49:41 +0000102
103 private:
Steve Antona3a92c22017-12-07 10:27:41 -0800104 void SetLocalDescription(webrtc::SdpType type, const std::string& sdp);
105 void SetRemoteDescription(webrtc::SdpType type, const std::string& sdp);
wu@webrtc.org364f2042013-11-20 21:49:41 +0000106 bool CheckForConnection();
107 bool CheckForAudio();
108 bool CheckForVideo();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000109 rtc::scoped_refptr<webrtc::MediaStreamInterface> GetUserMedia(
Yves Gerey665174f2018-06-19 15:03:05 +0200110 bool audio,
111 const cricket::AudioOptions& audio_options,
Niels Möller5c4ddad2019-02-12 12:30:58 +0100112 bool video);
wu@webrtc.org364f2042013-11-20 21:49:41 +0000113
114 std::string name_;
danilchape9021a32016-05-17 01:52:02 -0700115 rtc::Thread* const network_thread_;
116 rtc::Thread* const worker_thread_;
Yves Gerey59cfd352018-11-26 16:22:20 +0100117 rtc::ThreadChecker pc_thread_checker_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000118 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
119 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>
wu@webrtc.org364f2042013-11-20 21:49:41 +0000120 peer_connection_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000121 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
kwibergd1fe2812016-04-27 06:47:29 -0700122 std::unique_ptr<webrtc::FakeVideoTrackRenderer> renderer_;
Steve Antonfc853712018-03-01 13:48:58 -0800123 int num_get_user_media_calls_ = 0;
wu@webrtc.org364f2042013-11-20 21:49:41 +0000124};
125
Steve Anton10542f22019-01-11 09:11:00 -0800126#endif // PC_TEST_PEER_CONNECTION_TEST_WRAPPER_H_