blob: 7a9bea46b0d4ef0e2136e841970b87255af036d7 [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:
27 static void Connect(PeerConnectionTestWrapper* caller,
28 PeerConnectionTestWrapper* callee);
29
perkj57db6522016-04-08 08:16:33 -070030 explicit PeerConnectionTestWrapper(const std::string& name,
31 rtc::Thread* worker_thread);
wu@webrtc.org364f2042013-11-20 21:49:41 +000032 virtual ~PeerConnectionTestWrapper();
33
34 bool CreatePc(const webrtc::MediaConstraintsInterface* constraints);
35
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000036 rtc::scoped_refptr<webrtc::DataChannelInterface> CreateDataChannel(
jiayl@webrtc.org1a6c6282014-06-12 21:59:29 +000037 const std::string& label,
38 const webrtc::DataChannelInit& init);
39
wu@webrtc.org364f2042013-11-20 21:49:41 +000040 // Implements PeerConnectionObserver.
wu@webrtc.org364f2042013-11-20 21:49:41 +000041 virtual void OnSignalingChange(
42 webrtc::PeerConnectionInterface::SignalingState new_state) {}
43 virtual void OnStateChange(
44 webrtc::PeerConnectionObserver::StateType state_changed) {}
45 virtual void OnAddStream(webrtc::MediaStreamInterface* stream);
46 virtual void OnRemoveStream(webrtc::MediaStreamInterface* stream) {}
jiayl@webrtc.org1a6c6282014-06-12 21:59:29 +000047 virtual void OnDataChannel(webrtc::DataChannelInterface* data_channel);
wu@webrtc.org364f2042013-11-20 21:49:41 +000048 virtual void OnRenegotiationNeeded() {}
49 virtual void OnIceConnectionChange(
50 webrtc::PeerConnectionInterface::IceConnectionState new_state) {}
51 virtual void OnIceGatheringChange(
52 webrtc::PeerConnectionInterface::IceGatheringState new_state) {}
53 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate);
54 virtual void OnIceComplete() {}
55
56 // Implements CreateSessionDescriptionObserver.
57 virtual void OnSuccess(webrtc::SessionDescriptionInterface* desc);
58 virtual void OnFailure(const std::string& error) {}
59
60 void CreateOffer(const webrtc::MediaConstraintsInterface* constraints);
61 void CreateAnswer(const webrtc::MediaConstraintsInterface* constraints);
62 void ReceiveOfferSdp(const std::string& sdp);
63 void ReceiveAnswerSdp(const std::string& sdp);
64 void AddIceCandidate(const std::string& sdp_mid, int sdp_mline_index,
65 const std::string& candidate);
66 void WaitForCallEstablished();
67 void WaitForConnection();
68 void WaitForAudio();
69 void WaitForVideo();
70 void GetAndAddUserMedia(
71 bool audio, const webrtc::FakeConstraints& audio_constraints,
72 bool video, const webrtc::FakeConstraints& video_constraints);
73
74 // sigslots
75 sigslot::signal1<std::string*> SignalOnIceCandidateCreated;
76 sigslot::signal3<const std::string&,
77 int,
78 const std::string&> SignalOnIceCandidateReady;
79 sigslot::signal1<std::string*> SignalOnSdpCreated;
80 sigslot::signal1<const std::string&> SignalOnSdpReady;
jiayl@webrtc.org1a6c6282014-06-12 21:59:29 +000081 sigslot::signal1<webrtc::DataChannelInterface*> SignalOnDataChannel;
wu@webrtc.org364f2042013-11-20 21:49:41 +000082
83 private:
84 void SetLocalDescription(const std::string& type, const std::string& sdp);
85 void SetRemoteDescription(const std::string& type, const std::string& sdp);
86 bool CheckForConnection();
87 bool CheckForAudio();
88 bool CheckForVideo();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000089 rtc::scoped_refptr<webrtc::MediaStreamInterface> GetUserMedia(
wu@webrtc.org364f2042013-11-20 21:49:41 +000090 bool audio, const webrtc::FakeConstraints& audio_constraints,
91 bool video, const webrtc::FakeConstraints& video_constraints);
92
93 std::string name_;
perkj57db6522016-04-08 08:16:33 -070094 rtc::Thread* worker_thread_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000095 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
96 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>
wu@webrtc.org364f2042013-11-20 21:49:41 +000097 peer_connection_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000098 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
kwibergd1fe2812016-04-27 06:47:29 -070099 std::unique_ptr<webrtc::FakeVideoTrackRenderer> renderer_;
wu@webrtc.org364f2042013-11-20 21:49:41 +0000100};
101
Henrik Kjellander15583c12016-02-10 10:53:12 +0100102#endif // WEBRTC_API_TEST_PEERCONNECTIONTESTWRAPPER_H_