blob: 3cdac492f1910fd297ee7673191f7282d526eb0a [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
Henrik Kjellander15583c12016-02-10 10:53:12 +010011#ifndef WEBRTC_API_TEST_PEERCONNECTIONTESTWRAPPER_H_
12#define WEBRTC_API_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"
17#include "webrtc/api/test/fakeaudiocapturemodule.h"
18#include "webrtc/api/test/fakeconstraints.h"
19#include "webrtc/api/test/fakevideotrackrenderer.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000020#include "webrtc/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:
kjellander71a1b612016-11-07 01:18:08 -080027 // We need these using declarations because there are two versions of each of
28 // the below methods and we only override one of them.
29 // TODO(deadbeef): Remove once there's only one version of the methods.
30 using PeerConnectionObserver::OnAddStream;
31 using PeerConnectionObserver::OnRemoveStream;
32 using PeerConnectionObserver::OnDataChannel;
33
wu@webrtc.org364f2042013-11-20 21:49:41 +000034 static void Connect(PeerConnectionTestWrapper* caller,
35 PeerConnectionTestWrapper* callee);
36
danilchape9021a32016-05-17 01:52:02 -070037 PeerConnectionTestWrapper(const std::string& name,
38 rtc::Thread* network_thread,
39 rtc::Thread* worker_thread);
wu@webrtc.org364f2042013-11-20 21:49:41 +000040 virtual ~PeerConnectionTestWrapper();
41
zhihuang9763d562016-08-05 11:14:50 -070042 bool CreatePc(
43 const webrtc::MediaConstraintsInterface* constraints,
44 const webrtc::PeerConnectionInterface::RTCConfiguration& config);
wu@webrtc.org364f2042013-11-20 21:49:41 +000045
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000046 rtc::scoped_refptr<webrtc::DataChannelInterface> CreateDataChannel(
jiayl@webrtc.org1a6c6282014-06-12 21:59:29 +000047 const std::string& label,
48 const webrtc::DataChannelInit& init);
49
wu@webrtc.org364f2042013-11-20 21:49:41 +000050 // Implements PeerConnectionObserver.
wu@webrtc.org364f2042013-11-20 21:49:41 +000051 virtual void OnSignalingChange(
52 webrtc::PeerConnectionInterface::SignalingState new_state) {}
53 virtual void OnStateChange(
54 webrtc::PeerConnectionObserver::StateType state_changed) {}
Taylor Brandstetter98cde262016-05-31 13:02:21 -070055 virtual void OnAddStream(
56 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream);
57 virtual void OnRemoveStream(
58 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) {}
59 virtual void OnDataChannel(
60 rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel);
wu@webrtc.org364f2042013-11-20 21:49:41 +000061 virtual void OnRenegotiationNeeded() {}
62 virtual void OnIceConnectionChange(
63 webrtc::PeerConnectionInterface::IceConnectionState new_state) {}
64 virtual void OnIceGatheringChange(
65 webrtc::PeerConnectionInterface::IceGatheringState new_state) {}
66 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate);
67 virtual void OnIceComplete() {}
68
69 // Implements CreateSessionDescriptionObserver.
70 virtual void OnSuccess(webrtc::SessionDescriptionInterface* desc);
71 virtual void OnFailure(const std::string& error) {}
72
73 void CreateOffer(const webrtc::MediaConstraintsInterface* constraints);
74 void CreateAnswer(const webrtc::MediaConstraintsInterface* constraints);
75 void ReceiveOfferSdp(const std::string& sdp);
76 void ReceiveAnswerSdp(const std::string& sdp);
77 void AddIceCandidate(const std::string& sdp_mid, int sdp_mline_index,
78 const std::string& candidate);
79 void WaitForCallEstablished();
80 void WaitForConnection();
81 void WaitForAudio();
82 void WaitForVideo();
83 void GetAndAddUserMedia(
84 bool audio, const webrtc::FakeConstraints& audio_constraints,
85 bool video, const webrtc::FakeConstraints& video_constraints);
86
87 // sigslots
88 sigslot::signal1<std::string*> SignalOnIceCandidateCreated;
89 sigslot::signal3<const std::string&,
90 int,
91 const std::string&> SignalOnIceCandidateReady;
92 sigslot::signal1<std::string*> SignalOnSdpCreated;
93 sigslot::signal1<const std::string&> SignalOnSdpReady;
jiayl@webrtc.org1a6c6282014-06-12 21:59:29 +000094 sigslot::signal1<webrtc::DataChannelInterface*> SignalOnDataChannel;
wu@webrtc.org364f2042013-11-20 21:49:41 +000095
96 private:
97 void SetLocalDescription(const std::string& type, const std::string& sdp);
98 void SetRemoteDescription(const std::string& type, const std::string& sdp);
99 bool CheckForConnection();
100 bool CheckForAudio();
101 bool CheckForVideo();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000102 rtc::scoped_refptr<webrtc::MediaStreamInterface> GetUserMedia(
wu@webrtc.org364f2042013-11-20 21:49:41 +0000103 bool audio, const webrtc::FakeConstraints& audio_constraints,
104 bool video, const webrtc::FakeConstraints& video_constraints);
105
106 std::string name_;
danilchape9021a32016-05-17 01:52:02 -0700107 rtc::Thread* const network_thread_;
108 rtc::Thread* const worker_thread_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000109 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
110 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>
wu@webrtc.org364f2042013-11-20 21:49:41 +0000111 peer_connection_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000112 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
kwibergd1fe2812016-04-27 06:47:29 -0700113 std::unique_ptr<webrtc::FakeVideoTrackRenderer> renderer_;
wu@webrtc.org364f2042013-11-20 21:49:41 +0000114};
115
Henrik Kjellander15583c12016-02-10 10:53:12 +0100116#endif // WEBRTC_API_TEST_PEERCONNECTIONTESTWRAPPER_H_