blob: 25510b2de079578711f15a59796dd0b91db1ebce [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
Henrik Kjellander15583c12016-02-10 10:53:12 +010014#include "webrtc/api/peerconnectioninterface.h"
15#include "webrtc/api/test/fakeaudiocapturemodule.h"
16#include "webrtc/api/test/fakeconstraints.h"
17#include "webrtc/api/test/fakevideotrackrenderer.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000018#include "webrtc/base/sigslot.h"
wu@webrtc.org364f2042013-11-20 21:49:41 +000019
wu@webrtc.org364f2042013-11-20 21:49:41 +000020class PeerConnectionTestWrapper
21 : public webrtc::PeerConnectionObserver,
22 public webrtc::CreateSessionDescriptionObserver,
23 public sigslot::has_slots<> {
24 public:
25 static void Connect(PeerConnectionTestWrapper* caller,
26 PeerConnectionTestWrapper* callee);
27
28 explicit PeerConnectionTestWrapper(const std::string& name);
29 virtual ~PeerConnectionTestWrapper();
30
31 bool CreatePc(const webrtc::MediaConstraintsInterface* constraints);
32
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000033 rtc::scoped_refptr<webrtc::DataChannelInterface> CreateDataChannel(
jiayl@webrtc.org1a6c6282014-06-12 21:59:29 +000034 const std::string& label,
35 const webrtc::DataChannelInit& init);
36
wu@webrtc.org364f2042013-11-20 21:49:41 +000037 // Implements PeerConnectionObserver.
wu@webrtc.org364f2042013-11-20 21:49:41 +000038 virtual void OnSignalingChange(
39 webrtc::PeerConnectionInterface::SignalingState new_state) {}
40 virtual void OnStateChange(
41 webrtc::PeerConnectionObserver::StateType state_changed) {}
42 virtual void OnAddStream(webrtc::MediaStreamInterface* stream);
43 virtual void OnRemoveStream(webrtc::MediaStreamInterface* stream) {}
jiayl@webrtc.org1a6c6282014-06-12 21:59:29 +000044 virtual void OnDataChannel(webrtc::DataChannelInterface* data_channel);
wu@webrtc.org364f2042013-11-20 21:49:41 +000045 virtual void OnRenegotiationNeeded() {}
46 virtual void OnIceConnectionChange(
47 webrtc::PeerConnectionInterface::IceConnectionState new_state) {}
48 virtual void OnIceGatheringChange(
49 webrtc::PeerConnectionInterface::IceGatheringState new_state) {}
50 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate);
51 virtual void OnIceComplete() {}
52
53 // Implements CreateSessionDescriptionObserver.
54 virtual void OnSuccess(webrtc::SessionDescriptionInterface* desc);
55 virtual void OnFailure(const std::string& error) {}
56
57 void CreateOffer(const webrtc::MediaConstraintsInterface* constraints);
58 void CreateAnswer(const webrtc::MediaConstraintsInterface* constraints);
59 void ReceiveOfferSdp(const std::string& sdp);
60 void ReceiveAnswerSdp(const std::string& sdp);
61 void AddIceCandidate(const std::string& sdp_mid, int sdp_mline_index,
62 const std::string& candidate);
63 void WaitForCallEstablished();
64 void WaitForConnection();
65 void WaitForAudio();
66 void WaitForVideo();
67 void GetAndAddUserMedia(
68 bool audio, const webrtc::FakeConstraints& audio_constraints,
69 bool video, const webrtc::FakeConstraints& video_constraints);
70
71 // sigslots
72 sigslot::signal1<std::string*> SignalOnIceCandidateCreated;
73 sigslot::signal3<const std::string&,
74 int,
75 const std::string&> SignalOnIceCandidateReady;
76 sigslot::signal1<std::string*> SignalOnSdpCreated;
77 sigslot::signal1<const std::string&> SignalOnSdpReady;
jiayl@webrtc.org1a6c6282014-06-12 21:59:29 +000078 sigslot::signal1<webrtc::DataChannelInterface*> SignalOnDataChannel;
wu@webrtc.org364f2042013-11-20 21:49:41 +000079
80 private:
81 void SetLocalDescription(const std::string& type, const std::string& sdp);
82 void SetRemoteDescription(const std::string& type, const std::string& sdp);
83 bool CheckForConnection();
84 bool CheckForAudio();
85 bool CheckForVideo();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000086 rtc::scoped_refptr<webrtc::MediaStreamInterface> GetUserMedia(
wu@webrtc.org364f2042013-11-20 21:49:41 +000087 bool audio, const webrtc::FakeConstraints& audio_constraints,
88 bool video, const webrtc::FakeConstraints& video_constraints);
89
90 std::string name_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000091 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
92 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>
wu@webrtc.org364f2042013-11-20 21:49:41 +000093 peer_connection_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000094 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
95 rtc::scoped_ptr<webrtc::FakeVideoTrackRenderer> renderer_;
wu@webrtc.org364f2042013-11-20 21:49:41 +000096};
97
Henrik Kjellander15583c12016-02-10 10:53:12 +010098#endif // WEBRTC_API_TEST_PEERCONNECTIONTESTWRAPPER_H_