blob: 2d473073e91d44b50792a1bf421774c5f5a3abd4 [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
pbos@webrtc.orgbbb07e62013-08-05 12:01:36 +000013#include <assert.h>
14
eladalon413ee9a2017-08-22 04:02:52 -070015#include <memory>
pbos@webrtc.org96684672013-08-12 12:59:04 +000016
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "api/call/transport.h"
18#include "call/call.h"
Erik Språng09708512018-03-14 15:16:50 +010019#include "call/fake_network_pipe.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "rtc_base/sequenced_task_checker.h"
21#include "rtc_base/thread_annotations.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "test/single_threaded_task_queue.h"
pbos@webrtc.org29d58392013-05-16 12:08:03 +000023
24namespace webrtc {
pbos@webrtc.org96684672013-08-12 12:59:04 +000025
stefan@webrtc.orgb082ade2013-11-18 11:45:11 +000026class Clock;
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:
eladalon413ee9a2017-08-22 04:02:52 -070044 DirectTransport(SingleThreadedTaskQueueForTesting* task_queue,
45 Call* send_call,
46 const std::map<uint8_t, MediaType>& payload_type_map);
47
48 DirectTransport(SingleThreadedTaskQueueForTesting* task_queue,
49 const FakeNetworkPipe::Config& config,
50 Call* send_call,
51 const std::map<uint8_t, MediaType>& payload_type_map);
52
53 DirectTransport(SingleThreadedTaskQueueForTesting* task_queue,
Sebastian Jansson09408112018-04-24 14:41:22 +020054 std::unique_ptr<FakeNetworkPipe> pipe,
eladalon413ee9a2017-08-22 04:02:52 -070055 Call* send_call,
Sebastian Jansson09408112018-04-24 14:41:22 +020056 const std::map<uint8_t, MediaType>& payload_type_map);
Christoffer Rodbrod2817d82017-10-24 16:26:49 +020057
eladalon8435e552017-08-03 07:44:08 -070058 ~DirectTransport() override;
pbos@webrtc.org29d58392013-05-16 12:08:03 +000059
Sebastian Jansson7e85d672018-04-06 09:56:21 +020060 void SetClockOffset(int64_t offset_ms);
61
henrik.lundin@webrtc.orgc0e9aeb2014-02-26 13:34:52 +000062 void SetConfig(const FakeNetworkPipe::Config& config);
63
eladalon413ee9a2017-08-22 04:02:52 -070064 RTC_DEPRECATED void StopSending();
65
stefanf116bd02015-10-27 08:29:42 -070066 // TODO(holmer): Look into moving this to the constructor.
pbos@webrtc.org74fa4892013-08-23 09:19:30 +000067 virtual void SetReceiver(PacketReceiver* receiver);
pbos@webrtc.org29d58392013-05-16 12:08:03 +000068
stefan1d8a5062015-10-02 03:39:33 -070069 bool SendRtp(const uint8_t* data,
70 size_t length,
71 const PacketOptions& options) override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000072 bool SendRtcp(const uint8_t* data, size_t length) override;
pbos@webrtc.org29d58392013-05-16 12:08:03 +000073
Stefan Holmerff2a6352016-01-14 10:00:21 +010074 int GetAverageDelayMs();
75
pbos@webrtc.org29d58392013-05-16 12:08:03 +000076 private:
eladalon413ee9a2017-08-22 04:02:52 -070077 void SendPackets();
Sebastian Jansson09408112018-04-24 14:41:22 +020078 void SendPacket(const uint8_t* data, size_t length);
Christoffer Rodbrod2817d82017-10-24 16:26:49 +020079 void Start();
pbos@webrtc.org96684672013-08-12 12:59:04 +000080
stefanf116bd02015-10-27 08:29:42 -070081 Call* const send_call_;
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +000082 Clock* const clock_;
pbos@webrtc.org96684672013-08-12 12:59:04 +000083
eladalon8a6241e2017-08-29 06:53:21 -070084 SingleThreadedTaskQueueForTesting* const task_queue_;
eladaloncff98dc2017-08-24 05:04:56 -070085 SingleThreadedTaskQueueForTesting::TaskId next_scheduled_task_
danilchapa37de392017-09-09 04:17:22 -070086 RTC_GUARDED_BY(&sequence_checker_);
pbos@webrtc.org468e19a2013-08-12 14:28:00 +000087
Sebastian Jansson09408112018-04-24 14:41:22 +020088 const Demuxer demuxer_;
89 const std::unique_ptr<FakeNetworkPipe> fake_network_;
eladalon413ee9a2017-08-22 04:02:52 -070090
91 rtc::SequencedTaskChecker sequence_checker_;
pbos@webrtc.org29d58392013-05-16 12:08:03 +000092};
pbos@webrtc.org96684672013-08-12 12:59:04 +000093} // namespace test
94} // namespace webrtc
pbos@webrtc.org29d58392013-05-16 12:08:03 +000095
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020096#endif // TEST_DIRECT_TRANSPORT_H_