• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/task_queue/task_queue_base.h"
17 #include "api/test/simulated_network.h"
18 #include "call/call.h"
19 #include "call/simulated_packet_receiver.h"
20 #include "rtc_base/synchronization/mutex.h"
21 #include "rtc_base/synchronization/sequence_checker.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   MediaType GetMediaType(const uint8_t* packet_data,
35                          const size_t packet_length) const;
36   const std::map<uint8_t, MediaType> payload_type_map_;
37   RTC_DISALLOW_COPY_AND_ASSIGN(Demuxer);
38 };
39 
40 // Objects of this class are expected to be allocated and destroyed  on the
41 // same task-queue - the one that's passed in via the constructor.
42 class DirectTransport : public Transport {
43  public:
44   DirectTransport(TaskQueueBase* task_queue,
45                   std::unique_ptr<SimulatedPacketReceiverInterface> pipe,
46                   Call* send_call,
47                   const std::map<uint8_t, MediaType>& payload_type_map);
48 
49   ~DirectTransport() override;
50 
51   // TODO(holmer): Look into moving this to the constructor.
52   virtual void SetReceiver(PacketReceiver* receiver);
53 
54   bool SendRtp(const uint8_t* data,
55                size_t length,
56                const PacketOptions& options) override;
57   bool SendRtcp(const uint8_t* data, size_t length) override;
58 
59   int GetAverageDelayMs();
60 
61  private:
62   void ProcessPackets() RTC_EXCLUSIVE_LOCKS_REQUIRED(&process_lock_);
63   void SendPacket(const uint8_t* data, size_t length);
64   void Start();
65 
66   Call* const send_call_;
67 
68   TaskQueueBase* const task_queue_;
69 
70   Mutex process_lock_;
71   RepeatingTaskHandle next_process_task_ RTC_GUARDED_BY(&process_lock_);
72 
73   const Demuxer demuxer_;
74   const std::unique_ptr<SimulatedPacketReceiverInterface> fake_network_;
75 };
76 }  // namespace test
77 }  // namespace webrtc
78 
79 #endif  // TEST_DIRECT_TRANSPORT_H_
80