blob: e0b2251eea017430b5dfa36a412e9741e9c472f5 [file] [log] [blame]
pbos@webrtc.org29d58392013-05-16 12:08:031/*
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 04:47:3110#ifndef TEST_DIRECT_TRANSPORT_H_
11#define TEST_DIRECT_TRANSPORT_H_
pbos@webrtc.org29d58392013-05-16 12:08:0312
eladalon413ee9a2017-08-22 11:02:5213#include <memory>
pbos@webrtc.org96684672013-08-12 12:59:0414
Mirko Bonadei92ea95e2017-09-15 04:47:3115#include "api/call/transport.h"
Danil Chapovalovba2ba592019-09-27 09:10:4516#include "api/task_queue/task_queue_base.h"
Artem Titov46c4e602018-08-17 12:26:5417#include "api/test/simulated_network.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3118#include "call/call.h"
Artem Titov46c4e602018-08-17 12:26:5419#include "call/simulated_packet_receiver.h"
Sebastian Janssonb55015e2019-04-09 11:44:0420#include "rtc_base/synchronization/sequence_checker.h"
Danil Chapovalovba2ba592019-09-27 09:10:4521#include "rtc_base/task_utils/repeating_task.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3122#include "rtc_base/thread_annotations.h"
pbos@webrtc.org29d58392013-05-16 12:08:0323
24namespace webrtc {
pbos@webrtc.org96684672013-08-12 12:59:0425
pbos@webrtc.org96684672013-08-12 12:59:0426class PacketReceiver;
pbos@webrtc.org96684672013-08-12 12:59:0427
pbos@webrtc.org29d58392013-05-16 12:08:0328namespace test {
Sebastian Jansson09408112018-04-24 12:41:2229class Demuxer {
30 public:
31 explicit Demuxer(const std::map<uint8_t, MediaType>& payload_type_map);
32 ~Demuxer() = default;
33 MediaType GetMediaType(const uint8_t* packet_data,
34 const size_t packet_length) const;
35 const std::map<uint8_t, MediaType> payload_type_map_;
36 RTC_DISALLOW_COPY_AND_ASSIGN(Demuxer);
37};
pbos@webrtc.org29d58392013-05-16 12:08:0338
eladaloncff98dc2017-08-24 12:04:5639// Objects of this class are expected to be allocated and destroyed on the
40// same task-queue - the one that's passed in via the constructor.
pbos2d566682015-09-28 16:59:3141class DirectTransport : public Transport {
pbos@webrtc.org29d58392013-05-16 12:08:0342 public:
Danil Chapovalovba2ba592019-09-27 09:10:4543 DirectTransport(TaskQueueBase* task_queue,
Artem Titov46c4e602018-08-17 12:26:5444 std::unique_ptr<SimulatedPacketReceiverInterface> pipe,
eladalon413ee9a2017-08-22 11:02:5245 Call* send_call,
Sebastian Jansson09408112018-04-24 12:41:2246 const std::map<uint8_t, MediaType>& payload_type_map);
Christoffer Rodbrod2817d82017-10-24 14:26:4947
eladalon8435e552017-08-03 14:44:0848 ~DirectTransport() override;
pbos@webrtc.org29d58392013-05-16 12:08:0349
stefanf116bd02015-10-27 15:29:4250 // TODO(holmer): Look into moving this to the constructor.
pbos@webrtc.org74fa4892013-08-23 09:19:3051 virtual void SetReceiver(PacketReceiver* receiver);
pbos@webrtc.org29d58392013-05-16 12:08:0352
stefan1d8a5062015-10-02 10:39:3353 bool SendRtp(const uint8_t* data,
54 size_t length,
55 const PacketOptions& options) override;
kjellander@webrtc.org14665ff2015-03-04 12:58:3556 bool SendRtcp(const uint8_t* data, size_t length) override;
pbos@webrtc.org29d58392013-05-16 12:08:0357
Stefan Holmerff2a6352016-01-14 09:00:2158 int GetAverageDelayMs();
59
pbos@webrtc.org29d58392013-05-16 12:08:0360 private:
Sebastian Jansson836fee12019-02-08 15:08:1061 void ProcessPackets() RTC_EXCLUSIVE_LOCKS_REQUIRED(&process_lock_);
Sebastian Jansson09408112018-04-24 12:41:2262 void SendPacket(const uint8_t* data, size_t length);
Christoffer Rodbrod2817d82017-10-24 14:26:4963 void Start();
pbos@webrtc.org96684672013-08-12 12:59:0464
stefanf116bd02015-10-27 15:29:4265 Call* const send_call_;
pbos@webrtc.org96684672013-08-12 12:59:0466
Danil Chapovalovba2ba592019-09-27 09:10:4567 TaskQueueBase* const task_queue_;
Sebastian Jansson836fee12019-02-08 15:08:1068
69 rtc::CriticalSection process_lock_;
Danil Chapovalovba2ba592019-09-27 09:10:4570 RepeatingTaskHandle next_process_task_ RTC_GUARDED_BY(&process_lock_);
pbos@webrtc.org468e19a2013-08-12 14:28:0071
Sebastian Jansson09408112018-04-24 12:41:2272 const Demuxer demuxer_;
Artem Titov46c4e602018-08-17 12:26:5473 const std::unique_ptr<SimulatedPacketReceiverInterface> fake_network_;
pbos@webrtc.org29d58392013-05-16 12:08:0374};
pbos@webrtc.org96684672013-08-12 12:59:0475} // namespace test
76} // namespace webrtc
pbos@webrtc.org29d58392013-05-16 12:08:0377
Mirko Bonadei92ea95e2017-09-15 04:47:3178#endif // TEST_DIRECT_TRANSPORT_H_