xref: /aosp_15_r20/external/webrtc/test/peer_scenario/scenario_connection.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2019 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 #ifndef TEST_PEER_SCENARIO_SCENARIO_CONNECTION_H_
11 #define TEST_PEER_SCENARIO_SCENARIO_CONNECTION_H_
12 
13 #include <functional>
14 #include <memory>
15 #include <string>
16 #include <vector>
17 
18 #include "api/candidate.h"
19 #include "api/jsep.h"
20 #include "p2p/base/transport_description.h"
21 #include "test/network/network_emulation_manager.h"
22 #include "test/scoped_key_value_config.h"
23 
24 namespace webrtc {
25 
26 // ScenarioIceConnection provides the transport level functionality of a
27 // PeerConnection for use in peer connection scenario tests. This allows
28 // implementing custom server side behavior in tests.
29 class ScenarioIceConnection {
30  public:
31   class IceConnectionObserver {
32    public:
33     // Called on network thread.
34     virtual void OnPacketReceived(rtc::CopyOnWriteBuffer packet) = 0;
35     // Called on signaling thread.
36     virtual void OnIceCandidates(
37         const std::string& mid,
38         const std::vector<cricket::Candidate>& candidates) = 0;
39 
40    protected:
41     ~IceConnectionObserver() = default;
42   };
43   static std::unique_ptr<ScenarioIceConnection> Create(
44       test::NetworkEmulationManagerImpl* net,
45       IceConnectionObserver* observer);
46 
47   virtual ~ScenarioIceConnection() = default;
48 
49   // Posts tasks to send packets to network thread.
50   virtual void SendRtpPacket(rtc::ArrayView<const uint8_t> packet_view) = 0;
51   virtual void SendRtcpPacket(rtc::ArrayView<const uint8_t> packet_view) = 0;
52 
53   // Used for ICE configuration, called on signaling thread.
54   virtual void SetRemoteSdp(SdpType type, const std::string& remote_sdp) = 0;
55   virtual void SetLocalSdp(SdpType type, const std::string& local_sdp) = 0;
56 
57   virtual EmulatedEndpoint* endpoint() = 0;
58   virtual const cricket::TransportDescription& transport_description()
59       const = 0;
60 
61   webrtc::test::ScopedKeyValueConfig field_trials;
62 };
63 
64 }  // namespace webrtc
65 
66 #endif  // TEST_PEER_SCENARIO_SCENARIO_CONNECTION_H_
67