blob: 2d473073e91d44b50792a1bf421774c5f5a3abd4 [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
pbos@webrtc.orgbbb07e62013-08-05 12:01:3613#include <assert.h>
14
eladalon413ee9a2017-08-22 11:02:5215#include <memory>
pbos@webrtc.org96684672013-08-12 12:59:0416
Mirko Bonadei92ea95e2017-09-15 04:47:3117#include "api/call/transport.h"
18#include "call/call.h"
Erik Språng09708512018-03-14 14:16:5019#include "call/fake_network_pipe.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3120#include "rtc_base/sequenced_task_checker.h"
21#include "rtc_base/thread_annotations.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3122#include "test/single_threaded_task_queue.h"
pbos@webrtc.org29d58392013-05-16 12:08:0323
24namespace webrtc {
pbos@webrtc.org96684672013-08-12 12:59:0425
stefan@webrtc.orgb082ade2013-11-18 11:45:1126class Clock;
pbos@webrtc.org96684672013-08-12 12:59:0427class PacketReceiver;
pbos@webrtc.org96684672013-08-12 12:59:0428
pbos@webrtc.org29d58392013-05-16 12:08:0329namespace test {
Sebastian Jansson09408112018-04-24 12:41:2230class 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:0339
eladaloncff98dc2017-08-24 12:04:5640// 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 16:59:3142class DirectTransport : public Transport {
pbos@webrtc.org29d58392013-05-16 12:08:0343 public:
eladalon413ee9a2017-08-22 11:02:5244 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 12:41:2254 std::unique_ptr<FakeNetworkPipe> pipe,
eladalon413ee9a2017-08-22 11:02:5255 Call* send_call,
Sebastian Jansson09408112018-04-24 12:41:2256 const std::map<uint8_t, MediaType>& payload_type_map);
Christoffer Rodbrod2817d82017-10-24 14:26:4957
eladalon8435e552017-08-03 14:44:0858 ~DirectTransport() override;
pbos@webrtc.org29d58392013-05-16 12:08:0359
Sebastian Jansson7e85d672018-04-06 07:56:2160 void SetClockOffset(int64_t offset_ms);
61
henrik.lundin@webrtc.orgc0e9aeb2014-02-26 13:34:5262 void SetConfig(const FakeNetworkPipe::Config& config);
63
eladalon413ee9a2017-08-22 11:02:5264 RTC_DEPRECATED void StopSending();
65
stefanf116bd02015-10-27 15:29:4266 // TODO(holmer): Look into moving this to the constructor.
pbos@webrtc.org74fa4892013-08-23 09:19:3067 virtual void SetReceiver(PacketReceiver* receiver);
pbos@webrtc.org29d58392013-05-16 12:08:0368
stefan1d8a5062015-10-02 10:39:3369 bool SendRtp(const uint8_t* data,
70 size_t length,
71 const PacketOptions& options) override;
kjellander@webrtc.org14665ff2015-03-04 12:58:3572 bool SendRtcp(const uint8_t* data, size_t length) override;
pbos@webrtc.org29d58392013-05-16 12:08:0373
Stefan Holmerff2a6352016-01-14 09:00:2174 int GetAverageDelayMs();
75
pbos@webrtc.org29d58392013-05-16 12:08:0376 private:
eladalon413ee9a2017-08-22 11:02:5277 void SendPackets();
Sebastian Jansson09408112018-04-24 12:41:2278 void SendPacket(const uint8_t* data, size_t length);
Christoffer Rodbrod2817d82017-10-24 14:26:4979 void Start();
pbos@webrtc.org96684672013-08-12 12:59:0480
stefanf116bd02015-10-27 15:29:4281 Call* const send_call_;
pbos@webrtc.orgde1429e2014-04-28 13:00:2182 Clock* const clock_;
pbos@webrtc.org96684672013-08-12 12:59:0483
eladalon8a6241e2017-08-29 13:53:2184 SingleThreadedTaskQueueForTesting* const task_queue_;
eladaloncff98dc2017-08-24 12:04:5685 SingleThreadedTaskQueueForTesting::TaskId next_scheduled_task_
danilchapa37de392017-09-09 11:17:2286 RTC_GUARDED_BY(&sequence_checker_);
pbos@webrtc.org468e19a2013-08-12 14:28:0087
Sebastian Jansson09408112018-04-24 12:41:2288 const Demuxer demuxer_;
89 const std::unique_ptr<FakeNetworkPipe> fake_network_;
eladalon413ee9a2017-08-22 11:02:5290
91 rtc::SequencedTaskChecker sequence_checker_;
pbos@webrtc.org29d58392013-05-16 12:08:0392};
pbos@webrtc.org96684672013-08-12 12:59:0493} // namespace test
94} // namespace webrtc
pbos@webrtc.org29d58392013-05-16 12:08:0395
Mirko Bonadei92ea95e2017-09-15 04:47:3196#endif // TEST_DIRECT_TRANSPORT_H_