• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright 2013 The WebRTC project authors. All Rights Reserved.
3  *
4  *  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.
9  */
10 
11 #ifndef PC_TEST_PEER_CONNECTION_TEST_WRAPPER_H_
12 #define PC_TEST_PEER_CONNECTION_TEST_WRAPPER_H_
13 
14 #include <memory>
15 #include <string>
16 #include <vector>
17 
18 #include "api/audio_codecs/audio_decoder_factory.h"
19 #include "api/audio_codecs/audio_encoder_factory.h"
20 #include "api/audio_options.h"
21 #include "api/data_channel_interface.h"
22 #include "api/jsep.h"
23 #include "api/media_stream_interface.h"
24 #include "api/peer_connection_interface.h"
25 #include "api/rtc_error.h"
26 #include "api/rtp_receiver_interface.h"
27 #include "api/scoped_refptr.h"
28 #include "pc/test/fake_audio_capture_module.h"
29 #include "pc/test/fake_video_track_renderer.h"
30 #include "rtc_base/third_party/sigslot/sigslot.h"
31 #include "rtc_base/thread.h"
32 #include "rtc_base/thread_checker.h"
33 
34 class PeerConnectionTestWrapper
35     : public webrtc::PeerConnectionObserver,
36       public webrtc::CreateSessionDescriptionObserver,
37       public sigslot::has_slots<> {
38  public:
39   static void Connect(PeerConnectionTestWrapper* caller,
40                       PeerConnectionTestWrapper* callee);
41 
42   PeerConnectionTestWrapper(const std::string& name,
43                             rtc::Thread* network_thread,
44                             rtc::Thread* worker_thread);
45   virtual ~PeerConnectionTestWrapper();
46 
47   bool CreatePc(
48       const webrtc::PeerConnectionInterface::RTCConfiguration& config,
49       rtc::scoped_refptr<webrtc::AudioEncoderFactory> audio_encoder_factory,
50       rtc::scoped_refptr<webrtc::AudioDecoderFactory> audio_decoder_factory);
51 
pc_factory()52   rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory()
53       const {
54     return peer_connection_factory_;
55   }
pc()56   webrtc::PeerConnectionInterface* pc() { return peer_connection_.get(); }
57 
58   rtc::scoped_refptr<webrtc::DataChannelInterface> CreateDataChannel(
59       const std::string& label,
60       const webrtc::DataChannelInit& init);
61 
62   void WaitForNegotiation();
63 
64   // Implements PeerConnectionObserver.
65   void OnSignalingChange(
66       webrtc::PeerConnectionInterface::SignalingState new_state) override;
67   void OnAddTrack(
68       rtc::scoped_refptr<webrtc::RtpReceiverInterface> receiver,
69       const std::vector<rtc::scoped_refptr<webrtc::MediaStreamInterface>>&
70           streams) override;
71   void OnDataChannel(
72       rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) override;
OnRenegotiationNeeded()73   void OnRenegotiationNeeded() override {}
OnIceConnectionChange(webrtc::PeerConnectionInterface::IceConnectionState new_state)74   void OnIceConnectionChange(
75       webrtc::PeerConnectionInterface::IceConnectionState new_state) override {}
OnIceGatheringChange(webrtc::PeerConnectionInterface::IceGatheringState new_state)76   void OnIceGatheringChange(
77       webrtc::PeerConnectionInterface::IceGatheringState new_state) override {}
78   void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override;
79 
80   // Implements CreateSessionDescriptionObserver.
81   void OnSuccess(webrtc::SessionDescriptionInterface* desc) override;
OnFailure(webrtc::RTCError)82   void OnFailure(webrtc::RTCError) override {}
83 
84   void CreateOffer(
85       const webrtc::PeerConnectionInterface::RTCOfferAnswerOptions& options);
86   void CreateAnswer(
87       const webrtc::PeerConnectionInterface::RTCOfferAnswerOptions& options);
88   void ReceiveOfferSdp(const std::string& sdp);
89   void ReceiveAnswerSdp(const std::string& sdp);
90   void AddIceCandidate(const std::string& sdp_mid,
91                        int sdp_mline_index,
92                        const std::string& candidate);
93   void WaitForCallEstablished();
94   void WaitForConnection();
95   void WaitForAudio();
96   void WaitForVideo();
97   void GetAndAddUserMedia(bool audio,
98                           const cricket::AudioOptions& audio_options,
99                           bool video);
100 
101   // sigslots
102   sigslot::signal1<std::string*> SignalOnIceCandidateCreated;
103   sigslot::signal3<const std::string&, int, const std::string&>
104       SignalOnIceCandidateReady;
105   sigslot::signal1<std::string*> SignalOnSdpCreated;
106   sigslot::signal1<const std::string&> SignalOnSdpReady;
107   sigslot::signal1<webrtc::DataChannelInterface*> SignalOnDataChannel;
108 
109  private:
110   void SetLocalDescription(webrtc::SdpType type, const std::string& sdp);
111   void SetRemoteDescription(webrtc::SdpType type, const std::string& sdp);
112   bool CheckForConnection();
113   bool CheckForAudio();
114   bool CheckForVideo();
115   rtc::scoped_refptr<webrtc::MediaStreamInterface> GetUserMedia(
116       bool audio,
117       const cricket::AudioOptions& audio_options,
118       bool video);
119 
120   std::string name_;
121   rtc::Thread* const network_thread_;
122   rtc::Thread* const worker_thread_;
123   rtc::ThreadChecker pc_thread_checker_;
124   rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
125   rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>
126       peer_connection_factory_;
127   rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
128   std::unique_ptr<webrtc::FakeVideoTrackRenderer> renderer_;
129   int num_get_user_media_calls_ = 0;
130   bool pending_negotiation_;
131 };
132 
133 #endif  // PC_TEST_PEER_CONNECTION_TEST_WRAPPER_H_
134