xref: /aosp_15_r20/external/webrtc/test/direct_transport.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 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 #ifndef TEST_DIRECT_TRANSPORT_H_
11 #define TEST_DIRECT_TRANSPORT_H_
12 
13 #include <memory>
14 
15 #include "api/call/transport.h"
16 #include "api/sequence_checker.h"
17 #include "api/task_queue/task_queue_base.h"
18 #include "api/test/simulated_network.h"
19 #include "call/call.h"
20 #include "call/simulated_packet_receiver.h"
21 #include "rtc_base/synchronization/mutex.h"
22 #include "rtc_base/task_utils/repeating_task.h"
23 #include "rtc_base/thread_annotations.h"
24 
25 namespace webrtc {
26 
27 class PacketReceiver;
28 
29 namespace test {
30 class Demuxer {
31  public:
32   explicit Demuxer(const std::map<uint8_t, MediaType>& payload_type_map);
33   ~Demuxer() = default;
34 
35   Demuxer(const Demuxer&) = delete;
36   Demuxer& operator=(const Demuxer&) = delete;
37 
38   MediaType GetMediaType(const uint8_t* packet_data,
39                          size_t packet_length) const;
40   const std::map<uint8_t, MediaType> payload_type_map_;
41 };
42 
43 // Objects of this class are expected to be allocated and destroyed  on the
44 // same task-queue - the one that's passed in via the constructor.
45 class DirectTransport : public Transport {
46  public:
47   DirectTransport(TaskQueueBase* task_queue,
48                   std::unique_ptr<SimulatedPacketReceiverInterface> pipe,
49                   Call* send_call,
50                   const std::map<uint8_t, MediaType>& payload_type_map);
51 
52   ~DirectTransport() override;
53 
54   // TODO(holmer): Look into moving this to the constructor.
55   virtual void SetReceiver(PacketReceiver* receiver);
56 
57   bool SendRtp(const uint8_t* data,
58                size_t length,
59                const PacketOptions& options) override;
60   bool SendRtcp(const uint8_t* data, size_t length) override;
61 
62   int GetAverageDelayMs();
63 
64  private:
65   void ProcessPackets() RTC_EXCLUSIVE_LOCKS_REQUIRED(&process_lock_);
66   void SendPacket(const uint8_t* data, size_t length);
67   void Start();
68 
69   Call* const send_call_;
70 
71   TaskQueueBase* const task_queue_;
72 
73   Mutex process_lock_;
74   RepeatingTaskHandle next_process_task_ RTC_GUARDED_BY(&process_lock_);
75 
76   const Demuxer demuxer_;
77   const std::unique_ptr<SimulatedPacketReceiverInterface> fake_network_;
78 };
79 }  // namespace test
80 }  // namespace webrtc
81 
82 #endif  // TEST_DIRECT_TRANSPORT_H_
83