blob: 0a3a689e946f671b6556278daf63607cac77d5e3 [file] [log] [blame]
wu@webrtc.org364f2042013-11-20 21:49:411/*
kjellanderb24317b2016-02-10 15:54:432 * Copyright 2013 The WebRTC project authors. All Rights Reserved.
wu@webrtc.org364f2042013-11-20 21:49:413 *
kjellanderb24317b2016-02-10 15:54:434 * 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:419 */
10
Steve Anton10542f22019-01-11 17:11:0011#ifndef PC_TEST_PEER_CONNECTION_TEST_WRAPPER_H_
12#define PC_TEST_PEER_CONNECTION_TEST_WRAPPER_H_
wu@webrtc.org364f2042013-11-20 21:49:4113
kwibergd1fe2812016-04-27 13:47:2914#include <memory>
Steve Anton36b29d12017-10-30 16:57:4215#include <string>
Steve Anton191c39f2018-01-25 03:35:5516#include <vector>
kwibergd1fe2812016-04-27 13:47:2917
Yves Gerey3e707812018-11-28 15:47:4918#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 17:11:0021#include "api/data_channel_interface.h"
Florent Castelli64d68c32024-09-03 09:14:3722#include "api/field_trials_view.h"
Yves Gerey3e707812018-11-28 15:47:4923#include "api/jsep.h"
Steve Anton10542f22019-01-11 17:11:0024#include "api/media_stream_interface.h"
25#include "api/peer_connection_interface.h"
26#include "api/rtc_error.h"
Florent Castelli43a5dd82023-04-12 10:45:0727#include "api/rtp_parameters.h"
Steve Anton10542f22019-01-11 17:11:0028#include "api/rtp_receiver_interface.h"
Mirko Bonadeid9708072019-01-25 19:26:4829#include "api/scoped_refptr.h"
Artem Titovd15a5752021-02-10 13:31:2430#include "api/sequence_checker.h"
Henrik Boströmfd4ddd12023-02-08 10:29:2031#include "api/video/resolution.h"
Steve Anton10542f22019-01-11 17:11:0032#include "pc/test/fake_audio_capture_module.h"
Henrik Boströmfd4ddd12023-02-08 10:29:2033#include "pc/test/fake_periodic_video_source.h"
Henrik Boström89f095c2023-04-03 15:57:4734#include "pc/test/fake_periodic_video_track_source.h"
Steve Anton10542f22019-01-11 17:11:0035#include "pc/test/fake_video_track_renderer.h"
Artem Titove41c4332018-07-25 13:04:2836#include "rtc_base/third_party/sigslot/sigslot.h"
Yves Gerey3e707812018-11-28 15:47:4937#include "rtc_base/thread.h"
wu@webrtc.org364f2042013-11-20 21:49:4138
wu@webrtc.org364f2042013-11-20 21:49:4139class PeerConnectionTestWrapper
40 : public webrtc::PeerConnectionObserver,
41 public webrtc::CreateSessionDescriptionObserver,
42 public sigslot::has_slots<> {
43 public:
44 static void Connect(PeerConnectionTestWrapper* caller,
45 PeerConnectionTestWrapper* callee);
46
danilchape9021a32016-05-17 08:52:0247 PeerConnectionTestWrapper(const std::string& name,
Byoungchan Leed58f5262022-06-27 09:05:2248 rtc::SocketServer* socket_server,
danilchape9021a32016-05-17 08:52:0249 rtc::Thread* network_thread,
50 rtc::Thread* worker_thread);
wu@webrtc.org364f2042013-11-20 21:49:4151 virtual ~PeerConnectionTestWrapper();
52
zhihuang9763d562016-08-05 18:14:5053 bool CreatePc(
kwiberg9e5b11e2017-04-19 10:47:5754 const webrtc::PeerConnectionInterface::RTCConfiguration& config,
55 rtc::scoped_refptr<webrtc::AudioEncoderFactory> audio_encoder_factory,
Danil Chapovalovacf26ce2024-12-16 10:37:3656 rtc::scoped_refptr<webrtc::AudioDecoderFactory> audio_decoder_factory,
57 std::unique_ptr<webrtc::FieldTrialsView> field_trials = nullptr);
wu@webrtc.org364f2042013-11-20 21:49:4158
Henrik Boström4c1e7cc2020-06-11 10:26:5359 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory()
60 const {
61 return peer_connection_factory_;
62 }
hbosdb346a72016-11-29 09:57:0163 webrtc::PeerConnectionInterface* pc() { return peer_connection_.get(); }
64
buildbot@webrtc.orgd4e598d2014-07-29 17:36:5265 rtc::scoped_refptr<webrtc::DataChannelInterface> CreateDataChannel(
jiayl@webrtc.org1a6c6282014-06-12 21:59:2966 const std::string& label,
67 const webrtc::DataChannelInit& init);
68
Florent Castelli8037fc62024-08-29 13:00:4069 std::optional<webrtc::RtpCodecCapability> FindFirstSendCodecWithName(
Florent Castelli43a5dd82023-04-12 10:45:0770 cricket::MediaType media_type,
71 const std::string& name) const;
72
Henrik Boström4c1e7cc2020-06-11 10:26:5373 void WaitForNegotiation();
74
wu@webrtc.org364f2042013-11-20 21:49:4175 // Implements PeerConnectionObserver.
nisse63b14b72017-01-31 11:34:0176 void OnSignalingChange(
Henrik Boström4c1e7cc2020-06-11 10:26:5377 webrtc::PeerConnectionInterface::SignalingState new_state) override;
Steve Anton191c39f2018-01-25 03:35:5578 void OnAddTrack(
79 rtc::scoped_refptr<webrtc::RtpReceiverInterface> receiver,
80 const std::vector<rtc::scoped_refptr<webrtc::MediaStreamInterface>>&
81 streams) override;
nisse63b14b72017-01-31 11:34:0182 void OnDataChannel(
Steve Anton36b29d12017-10-30 16:57:4283 rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) override;
nisse63b14b72017-01-31 11:34:0184 void OnRenegotiationNeeded() override {}
85 void OnIceConnectionChange(
86 webrtc::PeerConnectionInterface::IceConnectionState new_state) override {}
87 void OnIceGatheringChange(
88 webrtc::PeerConnectionInterface::IceGatheringState new_state) override {}
89 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override;
wu@webrtc.org364f2042013-11-20 21:49:4190
91 // Implements CreateSessionDescriptionObserver.
nisse63b14b72017-01-31 11:34:0192 void OnSuccess(webrtc::SessionDescriptionInterface* desc) override;
Harald Alvestrand5081c0c2018-03-09 14:18:0393 void OnFailure(webrtc::RTCError) override {}
wu@webrtc.org364f2042013-11-20 21:49:4194
Niels Möllerf06f9232018-08-07 10:32:1895 void CreateOffer(
96 const webrtc::PeerConnectionInterface::RTCOfferAnswerOptions& options);
97 void CreateAnswer(
98 const webrtc::PeerConnectionInterface::RTCOfferAnswerOptions& options);
wu@webrtc.org364f2042013-11-20 21:49:4199 void ReceiveOfferSdp(const std::string& sdp);
100 void ReceiveAnswerSdp(const std::string& sdp);
Yves Gerey665174f2018-06-19 13:03:05101 void AddIceCandidate(const std::string& sdp_mid,
102 int sdp_mline_index,
wu@webrtc.org364f2042013-11-20 21:49:41103 const std::string& candidate);
Harald Alvestrandb3ac7532024-09-30 14:02:58104 bool WaitForCallEstablished();
105 bool WaitForConnection();
106 bool WaitForAudio();
107 bool WaitForVideo();
Yves Gerey665174f2018-06-19 13:03:05108 void GetAndAddUserMedia(bool audio,
109 const cricket::AudioOptions& audio_options,
Niels Möller5c4ddad2019-02-12 11:30:58110 bool video);
wu@webrtc.org364f2042013-11-20 21:49:41111
112 // sigslots
Yves Gerey665174f2018-06-19 13:03:05113 sigslot::signal3<const std::string&, int, const std::string&>
114 SignalOnIceCandidateReady;
wu@webrtc.org364f2042013-11-20 21:49:41115 sigslot::signal1<const std::string&> SignalOnSdpReady;
jiayl@webrtc.org1a6c6282014-06-12 21:59:29116 sigslot::signal1<webrtc::DataChannelInterface*> SignalOnDataChannel;
wu@webrtc.org364f2042013-11-20 21:49:41117
Henrik Boströmfd4ddd12023-02-08 10:29:20118 rtc::scoped_refptr<webrtc::MediaStreamInterface> GetUserMedia(
119 bool audio,
120 const cricket::AudioOptions& audio_options,
121 bool video,
122 webrtc::Resolution resolution = {
123 .width = webrtc::FakePeriodicVideoSource::kDefaultWidth,
124 .height = webrtc::FakePeriodicVideoSource::kDefaultHeight});
Henrik Boström89f095c2023-04-03 15:57:47125 void StopFakeVideoSources();
Henrik Boströmfd4ddd12023-02-08 10:29:20126
wu@webrtc.org364f2042013-11-20 21:49:41127 private:
Steve Antona3a92c22017-12-07 18:27:41128 void SetLocalDescription(webrtc::SdpType type, const std::string& sdp);
129 void SetRemoteDescription(webrtc::SdpType type, const std::string& sdp);
wu@webrtc.org364f2042013-11-20 21:49:41130 bool CheckForConnection();
131 bool CheckForAudio();
132 bool CheckForVideo();
wu@webrtc.org364f2042013-11-20 21:49:41133
134 std::string name_;
Byoungchan Leed58f5262022-06-27 09:05:22135 rtc::SocketServer* const socket_server_;
danilchape9021a32016-05-17 08:52:02136 rtc::Thread* const network_thread_;
137 rtc::Thread* const worker_thread_;
Artem Titovc8421c42021-02-02 09:57:19138 webrtc::SequenceChecker pc_thread_checker_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52139 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
140 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>
wu@webrtc.org364f2042013-11-20 21:49:41141 peer_connection_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52142 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
kwibergd1fe2812016-04-27 13:47:29143 std::unique_ptr<webrtc::FakeVideoTrackRenderer> renderer_;
Steve Antonfc853712018-03-01 21:48:58144 int num_get_user_media_calls_ = 0;
Henrik Boström4c1e7cc2020-06-11 10:26:53145 bool pending_negotiation_;
Henrik Boström89f095c2023-04-03 15:57:47146 std::vector<rtc::scoped_refptr<webrtc::FakePeriodicVideoTrackSource>>
147 fake_video_sources_;
wu@webrtc.org364f2042013-11-20 21:49:41148};
149
Steve Anton10542f22019-01-11 17:11:00150#endif // PC_TEST_PEER_CONNECTION_TEST_WRAPPER_H_