OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2017 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2017 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_P2P_BASE_FAKEPACKETTRANSPORT_H_ | 11 #ifndef WEBRTC_P2P_BASE_FAKEPACKETTRANSPORT_H_ |
12 #define WEBRTC_P2P_BASE_FAKEPACKETTRANSPORT_H_ | 12 #define WEBRTC_P2P_BASE_FAKEPACKETTRANSPORT_H_ |
13 | 13 |
14 #include <string> | 14 #include <string> |
15 | 15 |
16 #include "webrtc/api/ortc/packettransportinterface.h" | 16 #include "webrtc/api/ortc/packettransportinterface.h" |
17 #include "webrtc/base/asyncinvoker.h" | 17 #include "webrtc/base/asyncinvoker.h" |
18 #include "webrtc/base/copyonwritebuffer.h" | 18 #include "webrtc/base/copyonwritebuffer.h" |
19 #include "webrtc/media/base/rtputils.h" | |
joachim
2017/02/28 00:11:45
Same here.
| |
19 #include "webrtc/p2p/base/packettransportinternal.h" | 20 #include "webrtc/p2p/base/packettransportinternal.h" |
20 | 21 |
21 namespace rtc { | 22 namespace rtc { |
22 | 23 |
23 // Used to simulate a packet-based transport. | 24 // Used to simulate a packet-based transport. |
24 class FakePacketTransport : public PacketTransportInternal, | 25 class FakePacketTransport : public PacketTransportInternal, |
25 public webrtc::PacketTransportInterface { | 26 public webrtc::PacketTransportInterface { |
26 public: | 27 public: |
27 explicit FakePacketTransport(const std::string& debug_name) | 28 explicit FakePacketTransport(const std::string& debug_name) |
28 : debug_name_(debug_name) {} | 29 : debug_name_(debug_name) {} |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 size_t len, | 68 size_t len, |
68 const PacketOptions& options, | 69 const PacketOptions& options, |
69 int flags) override { | 70 int flags) override { |
70 if (!dest_) { | 71 if (!dest_) { |
71 return -1; | 72 return -1; |
72 } | 73 } |
73 CopyOnWriteBuffer packet(data, len); | 74 CopyOnWriteBuffer packet(data, len); |
74 if (async_) { | 75 if (async_) { |
75 invoker_.AsyncInvokeDelayed<void>( | 76 invoker_.AsyncInvokeDelayed<void>( |
76 RTC_FROM_HERE, Thread::Current(), | 77 RTC_FROM_HERE, Thread::Current(), |
77 Bind(&FakePacketTransport::SendPacketInternal, this, packet), | 78 Bind(&FakePacketTransport::SendPacketInternal, this, packet, |
79 options), | |
78 async_delay_ms_); | 80 async_delay_ms_); |
79 } else { | 81 } else { |
80 SendPacketInternal(packet); | 82 SendPacketInternal(packet, options); |
81 } | 83 } |
82 SentPacket sent_packet(options.packet_id, TimeMillis()); | 84 SentPacket sent_packet(options.packet_id, TimeMillis()); |
83 SignalSentPacket(this, sent_packet); | 85 SignalSentPacket(this, sent_packet); |
84 return static_cast<int>(len); | 86 return static_cast<int>(len); |
85 } | 87 } |
86 int SetOption(Socket::Option opt, int value) override { return true; } | 88 int SetOption(Socket::Option opt, int value) override { return true; } |
87 bool GetOption(Socket::Option opt, int* value) override { return true; } | 89 bool GetOption(Socket::Option opt, int* value) override { return true; } |
88 int GetError() override { return 0; } | 90 int GetError() override { return 0; } |
89 | 91 |
90 protected: | 92 protected: |
(...skipping 12 matching lines...) Expand all Loading... | |
103 } | 105 } |
104 | 106 |
105 void set_receiving(bool receiving) { | 107 void set_receiving(bool receiving) { |
106 if (receiving_ == receiving) { | 108 if (receiving_ == receiving) { |
107 return; | 109 return; |
108 } | 110 } |
109 receiving_ = receiving; | 111 receiving_ = receiving; |
110 SignalReceivingState(this); | 112 SignalReceivingState(this); |
111 } | 113 } |
112 | 114 |
113 void SendPacketInternal(const CopyOnWriteBuffer& packet) { | 115 void SendPacketInternal(const CopyOnWriteBuffer& packet, |
116 const PacketOptions& options) { | |
114 if (dest_) { | 117 if (dest_) { |
115 dest_->SignalReadPacket(dest_, packet.data<char>(), packet.size(), | 118 rtc::CopyOnWriteBuffer data(packet); |
119 cricket::ApplyPacketOptions( | |
120 reinterpret_cast<uint8_t*>(data.data<char>()), data.size(), | |
121 options.packet_time_params, 0); | |
122 dest_->SignalReadPacket(dest_, data.data<char>(), data.size(), | |
116 CreatePacketTime(0), 0); | 123 CreatePacketTime(0), 0); |
117 } | 124 } |
118 } | 125 } |
119 | 126 |
120 AsyncInvoker invoker_; | 127 AsyncInvoker invoker_; |
121 std::string debug_name_; | 128 std::string debug_name_; |
122 FakePacketTransport* dest_ = nullptr; | 129 FakePacketTransport* dest_ = nullptr; |
123 bool async_ = false; | 130 bool async_ = false; |
124 int async_delay_ms_ = 0; | 131 int async_delay_ms_ = 0; |
125 bool writable_ = false; | 132 bool writable_ = false; |
126 bool receiving_ = false; | 133 bool receiving_ = false; |
127 }; | 134 }; |
128 | 135 |
129 } // namespace rtc | 136 } // namespace rtc |
130 | 137 |
131 #endif // WEBRTC_P2P_BASE_FAKEPACKETTRANSPORT_H_ | 138 #endif // WEBRTC_P2P_BASE_FAKEPACKETTRANSPORT_H_ |
OLD | NEW |