pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [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 | */ |
Peter Boström | 7623ce4 | 2015-12-09 12:13:30 +0100 | [diff] [blame] | 10 | #ifndef WEBRTC_TEST_DIRECT_TRANSPORT_H_ |
| 11 | #define WEBRTC_TEST_DIRECT_TRANSPORT_H_ |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 12 | |
pbos@webrtc.org | bbb07e6 | 2013-08-05 12:01:36 +0000 | [diff] [blame] | 13 | #include <assert.h> |
| 14 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 15 | #include <memory> |
pbos@webrtc.org | 9668467 | 2013-08-12 12:59:04 +0000 | [diff] [blame] | 16 | |
aleloi | a8eb756 | 2016-11-28 07:02:13 -0800 | [diff] [blame] | 17 | #include "webrtc/api/call/transport.h" |
nisse | e5ad5ca | 2017-03-29 23:57:43 -0700 | [diff] [blame] | 18 | #include "webrtc/call/call.h" |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 19 | #include "webrtc/rtc_base/sequenced_task_checker.h" |
eladalon | cff98dc | 2017-08-24 05:04:56 -0700 | [diff] [blame^] | 20 | #include "webrtc/rtc_base/thread_annotations.h" |
stefan@webrtc.org | faada6e | 2013-12-18 20:28:25 +0000 | [diff] [blame] | 21 | #include "webrtc/test/fake_network_pipe.h" |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 22 | #include "webrtc/test/single_threaded_task_queue.h" |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
pbos@webrtc.org | 9668467 | 2013-08-12 12:59:04 +0000 | [diff] [blame] | 25 | |
stefan@webrtc.org | b082ade | 2013-11-18 11:45:11 +0000 | [diff] [blame] | 26 | class Clock; |
pbos@webrtc.org | 9668467 | 2013-08-12 12:59:04 +0000 | [diff] [blame] | 27 | class PacketReceiver; |
pbos@webrtc.org | 9668467 | 2013-08-12 12:59:04 +0000 | [diff] [blame] | 28 | |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 29 | namespace test { |
| 30 | |
eladalon | cff98dc | 2017-08-24 05:04:56 -0700 | [diff] [blame^] | 31 | // Objects of this class are expected to be allocated and destroyed on the |
| 32 | // same task-queue - the one that's passed in via the constructor. |
pbos | 2d56668 | 2015-09-28 09:59:31 -0700 | [diff] [blame] | 33 | class DirectTransport : public Transport { |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 34 | public: |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 35 | RTC_DEPRECATED DirectTransport( |
| 36 | Call* send_call, |
| 37 | const std::map<uint8_t, MediaType>& payload_type_map); |
| 38 | RTC_DEPRECATED DirectTransport( |
| 39 | const FakeNetworkPipe::Config& config, |
| 40 | Call* send_call, |
| 41 | const std::map<uint8_t, MediaType>& payload_type_map); |
| 42 | RTC_DEPRECATED DirectTransport( |
| 43 | const FakeNetworkPipe::Config& config, |
| 44 | Call* send_call, |
| 45 | std::unique_ptr<Demuxer> demuxer); |
minyue | 20c84cc | 2017-04-10 16:57:57 -0700 | [diff] [blame] | 46 | |
eladalon | 88df90b | 2017-08-02 06:18:41 -0700 | [diff] [blame] | 47 | // This deprecated variant always uses MediaType::VIDEO. |
nisse | e5ad5ca | 2017-03-29 23:57:43 -0700 | [diff] [blame] | 48 | RTC_DEPRECATED explicit DirectTransport(Call* send_call) |
minyue | 20c84cc | 2017-04-10 16:57:57 -0700 | [diff] [blame] | 49 | : DirectTransport( |
| 50 | FakeNetworkPipe::Config(), |
| 51 | send_call, |
| 52 | std::unique_ptr<Demuxer>(new ForceDemuxer(MediaType::VIDEO))) {} |
nisse | e5ad5ca | 2017-03-29 23:57:43 -0700 | [diff] [blame] | 53 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 54 | DirectTransport(SingleThreadedTaskQueueForTesting* task_queue, |
| 55 | Call* send_call, |
| 56 | const std::map<uint8_t, MediaType>& payload_type_map); |
| 57 | |
| 58 | DirectTransport(SingleThreadedTaskQueueForTesting* task_queue, |
| 59 | const FakeNetworkPipe::Config& config, |
| 60 | Call* send_call, |
| 61 | const std::map<uint8_t, MediaType>& payload_type_map); |
| 62 | |
| 63 | DirectTransport(SingleThreadedTaskQueueForTesting* task_queue, |
| 64 | const FakeNetworkPipe::Config& config, |
| 65 | Call* send_call, |
| 66 | std::unique_ptr<Demuxer> demuxer); |
| 67 | |
eladalon | 8435e55 | 2017-08-03 07:44:08 -0700 | [diff] [blame] | 68 | ~DirectTransport() override; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 69 | |
henrik.lundin@webrtc.org | c0e9aeb | 2014-02-26 13:34:52 +0000 | [diff] [blame] | 70 | void SetConfig(const FakeNetworkPipe::Config& config); |
| 71 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 72 | RTC_DEPRECATED void StopSending(); |
| 73 | |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 74 | // TODO(holmer): Look into moving this to the constructor. |
pbos@webrtc.org | 74fa489 | 2013-08-23 09:19:30 +0000 | [diff] [blame] | 75 | virtual void SetReceiver(PacketReceiver* receiver); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 76 | |
stefan | 1d8a506 | 2015-10-02 03:39:33 -0700 | [diff] [blame] | 77 | bool SendRtp(const uint8_t* data, |
| 78 | size_t length, |
| 79 | const PacketOptions& options) override; |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 80 | bool SendRtcp(const uint8_t* data, size_t length) override; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 81 | |
Stefan Holmer | ff2a635 | 2016-01-14 10:00:21 +0100 | [diff] [blame] | 82 | int GetAverageDelayMs(); |
| 83 | |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 84 | private: |
minyue | 20c84cc | 2017-04-10 16:57:57 -0700 | [diff] [blame] | 85 | // TODO(minyue): remove when the deprecated ctors of DirectTransport that |
| 86 | // create ForceDemuxer are removed. |
| 87 | class ForceDemuxer : public Demuxer { |
| 88 | public: |
| 89 | explicit ForceDemuxer(MediaType media_type); |
| 90 | void SetReceiver(PacketReceiver* receiver) override; |
| 91 | void DeliverPacket(const NetworkPacket* packet, |
| 92 | const PacketTime& packet_time) override; |
| 93 | |
| 94 | private: |
| 95 | const MediaType media_type_; |
| 96 | PacketReceiver* packet_receiver_; |
| 97 | RTC_DISALLOW_COPY_AND_ASSIGN(ForceDemuxer); |
| 98 | }; |
| 99 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 100 | void SendPackets(); |
pbos@webrtc.org | 9668467 | 2013-08-12 12:59:04 +0000 | [diff] [blame] | 101 | |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 102 | Call* const send_call_; |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 103 | Clock* const clock_; |
pbos@webrtc.org | 9668467 | 2013-08-12 12:59:04 +0000 | [diff] [blame] | 104 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 105 | // TODO(eladalon): Make |task_queue_| const. |
| 106 | // https://bugs.chromium.org/p/webrtc/issues/detail?id=8125 |
| 107 | SingleThreadedTaskQueueForTesting* task_queue_; |
eladalon | cff98dc | 2017-08-24 05:04:56 -0700 | [diff] [blame^] | 108 | SingleThreadedTaskQueueForTesting::TaskId next_scheduled_task_ |
| 109 | GUARDED_BY(&sequence_checker_); |
pbos@webrtc.org | 468e19a | 2013-08-12 14:28:00 +0000 | [diff] [blame] | 110 | |
stefan@webrtc.org | faada6e | 2013-12-18 20:28:25 +0000 | [diff] [blame] | 111 | FakeNetworkPipe fake_network_; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 112 | |
| 113 | rtc::SequencedTaskChecker sequence_checker_; |
| 114 | |
| 115 | // TODO(eladalon): https://bugs.chromium.org/p/webrtc/issues/detail?id=8125 |
| 116 | // Deprecated versions of the ctor don't get the task queue passed in from |
| 117 | // outside. We'll create one locally for them. This is deprecated, and will |
| 118 | // be removed as soon as the need for those ctors is removed. |
| 119 | std::unique_ptr<SingleThreadedTaskQueueForTesting> deprecated_task_queue_; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 120 | }; |
pbos@webrtc.org | 9668467 | 2013-08-12 12:59:04 +0000 | [diff] [blame] | 121 | } // namespace test |
| 122 | } // namespace webrtc |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 123 | |
Peter Boström | 7623ce4 | 2015-12-09 12:13:30 +0100 | [diff] [blame] | 124 | #endif // WEBRTC_TEST_DIRECT_TRANSPORT_H_ |