blob: e011664c346b66660247cad0417e21690f39c66d [file] [log] [blame]
pbos@webrtc.org29d58392013-05-16 12:08:03 +00001/*
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 */
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020010#ifndef TEST_DIRECT_TRANSPORT_H_
11#define TEST_DIRECT_TRANSPORT_H_
pbos@webrtc.org29d58392013-05-16 12:08:03 +000012
eladalon413ee9a2017-08-22 04:02:52 -070013#include <memory>
pbos@webrtc.org96684672013-08-12 12:59:04 +000014
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "api/call/transport.h"
Danil Chapovalovba2ba592019-09-27 11:10:45 +020016#include "api/task_queue/task_queue_base.h"
Artem Titov46c4e602018-08-17 14:26:54 +020017#include "api/test/simulated_network.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "call/call.h"
Artem Titov46c4e602018-08-17 14:26:54 +020019#include "call/simulated_packet_receiver.h"
Sebastian Janssonb55015e2019-04-09 13:44:04 +020020#include "rtc_base/synchronization/sequence_checker.h"
Danil Chapovalovba2ba592019-09-27 11:10:45 +020021#include "rtc_base/task_utils/repeating_task.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "rtc_base/thread_annotations.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020023#include "test/single_threaded_task_queue.h"
pbos@webrtc.org29d58392013-05-16 12:08:03 +000024
25namespace webrtc {
pbos@webrtc.org96684672013-08-12 12:59:04 +000026
pbos@webrtc.org96684672013-08-12 12:59:04 +000027class PacketReceiver;
pbos@webrtc.org96684672013-08-12 12:59:04 +000028
pbos@webrtc.org29d58392013-05-16 12:08:03 +000029namespace test {
Sebastian Jansson09408112018-04-24 14:41:22 +020030class 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};
pbos@webrtc.org29d58392013-05-16 12:08:03 +000039
eladaloncff98dc2017-08-24 05:04:56 -070040// 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.
pbos2d566682015-09-28 09:59:31 -070042class DirectTransport : public Transport {
pbos@webrtc.org29d58392013-05-16 12:08:03 +000043 public:
Danil Chapovalovba2ba592019-09-27 11:10:45 +020044 DirectTransport(TaskQueueBase* task_queue,
Artem Titov46c4e602018-08-17 14:26:54 +020045 std::unique_ptr<SimulatedPacketReceiverInterface> pipe,
eladalon413ee9a2017-08-22 04:02:52 -070046 Call* send_call,
Sebastian Jansson09408112018-04-24 14:41:22 +020047 const std::map<uint8_t, MediaType>& payload_type_map);
Christoffer Rodbrod2817d82017-10-24 16:26:49 +020048
eladalon8435e552017-08-03 07:44:08 -070049 ~DirectTransport() override;
pbos@webrtc.org29d58392013-05-16 12:08:03 +000050
stefanf116bd02015-10-27 08:29:42 -070051 // TODO(holmer): Look into moving this to the constructor.
pbos@webrtc.org74fa4892013-08-23 09:19:30 +000052 virtual void SetReceiver(PacketReceiver* receiver);
pbos@webrtc.org29d58392013-05-16 12:08:03 +000053
stefan1d8a5062015-10-02 03:39:33 -070054 bool SendRtp(const uint8_t* data,
55 size_t length,
56 const PacketOptions& options) override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000057 bool SendRtcp(const uint8_t* data, size_t length) override;
pbos@webrtc.org29d58392013-05-16 12:08:03 +000058
Stefan Holmerff2a6352016-01-14 10:00:21 +010059 int GetAverageDelayMs();
60
pbos@webrtc.org29d58392013-05-16 12:08:03 +000061 private:
Sebastian Jansson836fee12019-02-08 16:08:10 +010062 void ProcessPackets() RTC_EXCLUSIVE_LOCKS_REQUIRED(&process_lock_);
Sebastian Jansson09408112018-04-24 14:41:22 +020063 void SendPacket(const uint8_t* data, size_t length);
Christoffer Rodbrod2817d82017-10-24 16:26:49 +020064 void Start();
pbos@webrtc.org96684672013-08-12 12:59:04 +000065
stefanf116bd02015-10-27 08:29:42 -070066 Call* const send_call_;
pbos@webrtc.org96684672013-08-12 12:59:04 +000067
Danil Chapovalovba2ba592019-09-27 11:10:45 +020068 TaskQueueBase* const task_queue_;
Sebastian Jansson836fee12019-02-08 16:08:10 +010069
70 rtc::CriticalSection process_lock_;
Danil Chapovalovba2ba592019-09-27 11:10:45 +020071 RepeatingTaskHandle next_process_task_ RTC_GUARDED_BY(&process_lock_);
pbos@webrtc.org468e19a2013-08-12 14:28:00 +000072
Sebastian Jansson09408112018-04-24 14:41:22 +020073 const Demuxer demuxer_;
Artem Titov46c4e602018-08-17 14:26:54 +020074 const std::unique_ptr<SimulatedPacketReceiverInterface> fake_network_;
pbos@webrtc.org29d58392013-05-16 12:08:03 +000075};
pbos@webrtc.org96684672013-08-12 12:59:04 +000076} // namespace test
77} // namespace webrtc
pbos@webrtc.org29d58392013-05-16 12:08:03 +000078
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020079#endif // TEST_DIRECT_TRANSPORT_H_