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 | |
pbos@webrtc.org | 9668467 | 2013-08-12 12:59:04 +0000 | [diff] [blame] | 15 | #include <deque> |
| 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" |
Edward Lemur | c20978e | 2017-07-06 19:44:34 +0200 | [diff] [blame^] | 19 | #include "webrtc/rtc_base/criticalsection.h" |
| 20 | #include "webrtc/rtc_base/event.h" |
| 21 | #include "webrtc/rtc_base/platform_thread.h" |
stefan@webrtc.org | faada6e | 2013-12-18 20:28:25 +0000 | [diff] [blame] | 22 | #include "webrtc/test/fake_network_pipe.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 | |
pbos | 2d56668 | 2015-09-28 09:59:31 -0700 | [diff] [blame] | 31 | class DirectTransport : public Transport { |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 32 | public: |
minyue | 20c84cc | 2017-04-10 16:57:57 -0700 | [diff] [blame] | 33 | DirectTransport(Call* send_call, |
| 34 | const std::map<uint8_t, MediaType>& payload_type_map); |
| 35 | DirectTransport(const FakeNetworkPipe::Config& config, |
| 36 | Call* send_call, |
| 37 | const std::map<uint8_t, MediaType>& payload_type_map); |
| 38 | DirectTransport(const FakeNetworkPipe::Config& config, |
| 39 | Call* send_call, |
| 40 | std::unique_ptr<Demuxer> demuxer); |
| 41 | |
| 42 | // These deprecated variants always use ForceDemuxer. |
| 43 | RTC_DEPRECATED DirectTransport(Call* send_call, MediaType media_type) |
| 44 | : DirectTransport( |
| 45 | FakeNetworkPipe::Config(), |
| 46 | send_call, |
| 47 | std::unique_ptr<Demuxer>(new ForceDemuxer(media_type))) {} |
| 48 | RTC_DEPRECATED DirectTransport(const FakeNetworkPipe::Config& config, |
| 49 | Call* send_call, |
| 50 | MediaType media_type) |
| 51 | : DirectTransport( |
| 52 | config, |
| 53 | send_call, |
| 54 | std::unique_ptr<Demuxer>(new ForceDemuxer(media_type))) {} |
| 55 | |
nisse | e5ad5ca | 2017-03-29 23:57:43 -0700 | [diff] [blame] | 56 | // These deprecated variants always use MediaType::VIDEO. |
| 57 | RTC_DEPRECATED explicit DirectTransport(Call* send_call) |
minyue | 20c84cc | 2017-04-10 16:57:57 -0700 | [diff] [blame] | 58 | : DirectTransport( |
| 59 | FakeNetworkPipe::Config(), |
| 60 | send_call, |
| 61 | std::unique_ptr<Demuxer>(new ForceDemuxer(MediaType::VIDEO))) {} |
nisse | e5ad5ca | 2017-03-29 23:57:43 -0700 | [diff] [blame] | 62 | |
| 63 | RTC_DEPRECATED DirectTransport(const FakeNetworkPipe::Config& config, |
| 64 | Call* send_call) |
minyue | 20c84cc | 2017-04-10 16:57:57 -0700 | [diff] [blame] | 65 | : DirectTransport( |
| 66 | config, |
| 67 | send_call, |
| 68 | std::unique_ptr<Demuxer>(new ForceDemuxer(MediaType::VIDEO))) {} |
nisse | e5ad5ca | 2017-03-29 23:57:43 -0700 | [diff] [blame] | 69 | |
pbos@webrtc.org | 9668467 | 2013-08-12 12:59:04 +0000 | [diff] [blame] | 70 | ~DirectTransport(); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 71 | |
henrik.lundin@webrtc.org | c0e9aeb | 2014-02-26 13:34:52 +0000 | [diff] [blame] | 72 | void SetConfig(const FakeNetworkPipe::Config& config); |
| 73 | |
pbos@webrtc.org | 9668467 | 2013-08-12 12:59:04 +0000 | [diff] [blame] | 74 | virtual void StopSending(); |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 75 | // TODO(holmer): Look into moving this to the constructor. |
pbos@webrtc.org | 74fa489 | 2013-08-23 09:19:30 +0000 | [diff] [blame] | 76 | virtual void SetReceiver(PacketReceiver* receiver); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 77 | |
stefan | 1d8a506 | 2015-10-02 03:39:33 -0700 | [diff] [blame] | 78 | bool SendRtp(const uint8_t* data, |
| 79 | size_t length, |
| 80 | const PacketOptions& options) override; |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 81 | bool SendRtcp(const uint8_t* data, size_t length) override; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 82 | |
Stefan Holmer | ff2a635 | 2016-01-14 10:00:21 +0100 | [diff] [blame] | 83 | int GetAverageDelayMs(); |
| 84 | |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 85 | private: |
minyue | 20c84cc | 2017-04-10 16:57:57 -0700 | [diff] [blame] | 86 | // TODO(minyue): remove when the deprecated ctors of DirectTransport that |
| 87 | // create ForceDemuxer are removed. |
| 88 | class ForceDemuxer : public Demuxer { |
| 89 | public: |
| 90 | explicit ForceDemuxer(MediaType media_type); |
| 91 | void SetReceiver(PacketReceiver* receiver) override; |
| 92 | void DeliverPacket(const NetworkPacket* packet, |
| 93 | const PacketTime& packet_time) override; |
| 94 | |
| 95 | private: |
| 96 | const MediaType media_type_; |
| 97 | PacketReceiver* packet_receiver_; |
| 98 | RTC_DISALLOW_COPY_AND_ASSIGN(ForceDemuxer); |
| 99 | }; |
| 100 | |
pbos@webrtc.org | 9668467 | 2013-08-12 12:59:04 +0000 | [diff] [blame] | 101 | static bool NetworkProcess(void* transport); |
| 102 | bool SendPackets(); |
| 103 | |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 104 | rtc::CriticalSection lock_; |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 105 | Call* const send_call_; |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 106 | rtc::Event packet_event_; |
Peter Boström | 8c38e8b | 2015-11-26 17:45:47 +0100 | [diff] [blame] | 107 | rtc::PlatformThread thread_; |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 108 | Clock* const clock_; |
pbos@webrtc.org | 9668467 | 2013-08-12 12:59:04 +0000 | [diff] [blame] | 109 | |
pbos@webrtc.org | 468e19a | 2013-08-12 14:28:00 +0000 | [diff] [blame] | 110 | bool shutting_down_; |
| 111 | |
stefan@webrtc.org | faada6e | 2013-12-18 20:28:25 +0000 | [diff] [blame] | 112 | FakeNetworkPipe fake_network_; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 113 | }; |
pbos@webrtc.org | 9668467 | 2013-08-12 12:59:04 +0000 | [diff] [blame] | 114 | } // namespace test |
| 115 | } // namespace webrtc |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 116 | |
Peter Boström | 7623ce4 | 2015-12-09 12:13:30 +0100 | [diff] [blame] | 117 | #endif // WEBRTC_TEST_DIRECT_TRANSPORT_H_ |