pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 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 | */ |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 10 | #ifndef TEST_DIRECT_TRANSPORT_H_ |
| 11 | #define TEST_DIRECT_TRANSPORT_H_ |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 12 | |
pbos@webrtc.org | bbb07e6 | 2013-08-05 12:01:36 | [diff] [blame] | 13 | #include <assert.h> |
| 14 | |
eladalon | 413ee9a | 2017-08-22 11:02:52 | [diff] [blame] | 15 | #include <memory> |
pbos@webrtc.org | 9668467 | 2013-08-12 12:59:04 | [diff] [blame] | 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 17 | #include "api/call/transport.h" |
| 18 | #include "call/call.h" |
Erik Språng | 0970851 | 2018-03-14 14:16:50 | [diff] [blame] | 19 | #include "call/fake_network_pipe.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 20 | #include "rtc_base/sequenced_task_checker.h" |
| 21 | #include "rtc_base/thread_annotations.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 22 | #include "test/single_threaded_task_queue.h" |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
pbos@webrtc.org | 9668467 | 2013-08-12 12:59:04 | [diff] [blame] | 25 | |
stefan@webrtc.org | b082ade | 2013-11-18 11:45:11 | [diff] [blame] | 26 | class Clock; |
pbos@webrtc.org | 9668467 | 2013-08-12 12:59:04 | [diff] [blame] | 27 | class PacketReceiver; |
pbos@webrtc.org | 9668467 | 2013-08-12 12:59:04 | [diff] [blame] | 28 | |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 29 | namespace test { |
Sebastian Jansson | 0940811 | 2018-04-24 12:41:22 | [diff] [blame] | 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 | }; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 39 | |
eladalon | cff98dc | 2017-08-24 12:04:56 | [diff] [blame] | 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. |
pbos | 2d56668 | 2015-09-28 16:59:31 | [diff] [blame] | 42 | class DirectTransport : public Transport { |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 43 | public: |
eladalon | 413ee9a | 2017-08-22 11:02:52 | [diff] [blame] | 44 | 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 Jansson | 0940811 | 2018-04-24 12:41:22 | [diff] [blame] | 54 | std::unique_ptr<FakeNetworkPipe> pipe, |
eladalon | 413ee9a | 2017-08-22 11:02:52 | [diff] [blame] | 55 | Call* send_call, |
Sebastian Jansson | 0940811 | 2018-04-24 12:41:22 | [diff] [blame] | 56 | const std::map<uint8_t, MediaType>& payload_type_map); |
Christoffer Rodbro | d2817d8 | 2017-10-24 14:26:49 | [diff] [blame] | 57 | |
eladalon | 8435e55 | 2017-08-03 14:44:08 | [diff] [blame] | 58 | ~DirectTransport() override; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 59 | |
Sebastian Jansson | 7e85d67 | 2018-04-06 07:56:21 | [diff] [blame] | 60 | void SetClockOffset(int64_t offset_ms); |
| 61 | |
henrik.lundin@webrtc.org | c0e9aeb | 2014-02-26 13:34:52 | [diff] [blame] | 62 | void SetConfig(const FakeNetworkPipe::Config& config); |
| 63 | |
eladalon | 413ee9a | 2017-08-22 11:02:52 | [diff] [blame] | 64 | RTC_DEPRECATED void StopSending(); |
| 65 | |
stefan | f116bd0 | 2015-10-27 15:29:42 | [diff] [blame] | 66 | // TODO(holmer): Look into moving this to the constructor. |
pbos@webrtc.org | 74fa489 | 2013-08-23 09:19:30 | [diff] [blame] | 67 | virtual void SetReceiver(PacketReceiver* receiver); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 68 | |
stefan | 1d8a506 | 2015-10-02 10:39:33 | [diff] [blame] | 69 | bool SendRtp(const uint8_t* data, |
| 70 | size_t length, |
| 71 | const PacketOptions& options) override; |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 | [diff] [blame] | 72 | bool SendRtcp(const uint8_t* data, size_t length) override; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 73 | |
Stefan Holmer | ff2a635 | 2016-01-14 09:00:21 | [diff] [blame] | 74 | int GetAverageDelayMs(); |
| 75 | |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 76 | private: |
eladalon | 413ee9a | 2017-08-22 11:02:52 | [diff] [blame] | 77 | void SendPackets(); |
Sebastian Jansson | 0940811 | 2018-04-24 12:41:22 | [diff] [blame] | 78 | void SendPacket(const uint8_t* data, size_t length); |
Christoffer Rodbro | d2817d8 | 2017-10-24 14:26:49 | [diff] [blame] | 79 | void Start(); |
pbos@webrtc.org | 9668467 | 2013-08-12 12:59:04 | [diff] [blame] | 80 | |
stefan | f116bd0 | 2015-10-27 15:29:42 | [diff] [blame] | 81 | Call* const send_call_; |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 | [diff] [blame] | 82 | Clock* const clock_; |
pbos@webrtc.org | 9668467 | 2013-08-12 12:59:04 | [diff] [blame] | 83 | |
eladalon | 8a6241e | 2017-08-29 13:53:21 | [diff] [blame] | 84 | SingleThreadedTaskQueueForTesting* const task_queue_; |
eladalon | cff98dc | 2017-08-24 12:04:56 | [diff] [blame] | 85 | SingleThreadedTaskQueueForTesting::TaskId next_scheduled_task_ |
danilchap | a37de39 | 2017-09-09 11:17:22 | [diff] [blame] | 86 | RTC_GUARDED_BY(&sequence_checker_); |
pbos@webrtc.org | 468e19a | 2013-08-12 14:28:00 | [diff] [blame] | 87 | |
Sebastian Jansson | 0940811 | 2018-04-24 12:41:22 | [diff] [blame] | 88 | const Demuxer demuxer_; |
| 89 | const std::unique_ptr<FakeNetworkPipe> fake_network_; |
eladalon | 413ee9a | 2017-08-22 11:02:52 | [diff] [blame] | 90 | |
| 91 | rtc::SequencedTaskChecker sequence_checker_; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 92 | }; |
pbos@webrtc.org | 9668467 | 2013-08-12 12:59:04 | [diff] [blame] | 93 | } // namespace test |
| 94 | } // namespace webrtc |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 95 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 96 | #endif // TEST_DIRECT_TRANSPORT_H_ |