blob: f744b57c223744415f8b1faa9c76c93da5bec935 [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
perkj57db6522016-04-08 08:16:33 -070028 explicit PeerConnectionTestWrapper(const std::string& name,
29 rtc::Thread* worker_thread);
wu@webrtc.org364f2042013-11-20 21:49:41 +000030 virtual ~PeerConnectionTestWrapper();
31
32 bool CreatePc(const webrtc::MediaConstraintsInterface* constraints);
33
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000034 rtc::scoped_refptr<webrtc::DataChannelInterface> CreateDataChannel(
jiayl@webrtc.org1a6c6282014-06-12 21:59:29 +000035 const std::string& label,
36 const webrtc::DataChannelInit& init);
37
wu@webrtc.org364f2042013-11-20 21:49:41 +000038 // Implements PeerConnectionObserver.
wu@webrtc.org364f2042013-11-20 21:49:41 +000039 virtual void OnSignalingChange(
40 webrtc::PeerConnectionInterface::SignalingState new_state) {}
41 virtual void OnStateChange(
42 webrtc::PeerConnectionObserver::StateType state_changed) {}
43 virtual void OnAddStream(webrtc::MediaStreamInterface* stream);
44 virtual void OnRemoveStream(webrtc::MediaStreamInterface* stream) {}
jiayl@webrtc.org1a6c6282014-06-12 21:59:29 +000045 virtual void OnDataChannel(webrtc::DataChannelInterface* data_channel);
wu@webrtc.org364f2042013-11-20 21:49:41 +000046 virtual void OnRenegotiationNeeded() {}
47 virtual void OnIceConnectionChange(
48 webrtc::PeerConnectionInterface::IceConnectionState new_state) {}
49 virtual void OnIceGatheringChange(
50 webrtc::PeerConnectionInterface::IceGatheringState new_state) {}
51 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate);
52 virtual void OnIceComplete() {}
53
54 // Implements CreateSessionDescriptionObserver.
55 virtual void OnSuccess(webrtc::SessionDescriptionInterface* desc);
56 virtual void OnFailure(const std::string& error) {}
57
58 void CreateOffer(const webrtc::MediaConstraintsInterface* constraints);
59 void CreateAnswer(const webrtc::MediaConstraintsInterface* constraints);
60 void ReceiveOfferSdp(const std::string& sdp);
61 void ReceiveAnswerSdp(const std::string& sdp);
62 void AddIceCandidate(const std::string& sdp_mid, int sdp_mline_index,
63 const std::string& candidate);
64 void WaitForCallEstablished();
65 void WaitForConnection();
66 void WaitForAudio();
67 void WaitForVideo();
68 void GetAndAddUserMedia(
69 bool audio, const webrtc::FakeConstraints& audio_constraints,
70 bool video, const webrtc::FakeConstraints& video_constraints);
71
72 // sigslots
73 sigslot::signal1<std::string*> SignalOnIceCandidateCreated;
74 sigslot::signal3<const std::string&,
75 int,
76 const std::string&> SignalOnIceCandidateReady;
77 sigslot::signal1<std::string*> SignalOnSdpCreated;
78 sigslot::signal1<const std::string&> SignalOnSdpReady;
jiayl@webrtc.org1a6c6282014-06-12 21:59:29 +000079 sigslot::signal1<webrtc::DataChannelInterface*> SignalOnDataChannel;
wu@webrtc.org364f2042013-11-20 21:49:41 +000080
81 private:
82 void SetLocalDescription(const std::string& type, const std::string& sdp);
83 void SetRemoteDescription(const std::string& type, const std::string& sdp);
84 bool CheckForConnection();
85 bool CheckForAudio();
86 bool CheckForVideo();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000087 rtc::scoped_refptr<webrtc::MediaStreamInterface> GetUserMedia(
wu@webrtc.org364f2042013-11-20 21:49:41 +000088 bool audio, const webrtc::FakeConstraints& audio_constraints,
89 bool video, const webrtc::FakeConstraints& video_constraints);
90
91 std::string name_;
perkj57db6522016-04-08 08:16:33 -070092 rtc::Thread* worker_thread_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000093 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
94 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>
wu@webrtc.org364f2042013-11-20 21:49:41 +000095 peer_connection_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000096 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
97 rtc::scoped_ptr<webrtc::FakeVideoTrackRenderer> renderer_;
wu@webrtc.org364f2042013-11-20 21:49:41 +000098};
99
Henrik Kjellander15583c12016-02-10 10:53:12 +0100100#endif // WEBRTC_API_TEST_PEERCONNECTIONTESTWRAPPER_H_