OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 #include "webrtc/test/direct_transport.h" | 10 #include "webrtc/test/direct_transport.h" |
11 | 11 |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 #include "webrtc/call.h" | 14 #include "webrtc/call.h" |
15 #include "webrtc/system_wrappers/include/clock.h" | 15 #include "webrtc/system_wrappers/include/clock.h" |
16 | 16 |
17 namespace webrtc { | 17 namespace webrtc { |
18 namespace test { | 18 namespace test { |
19 | 19 |
20 DirectTransport::DirectTransport(Call* send_call) | 20 DirectTransport::DirectTransport(Call* send_call) |
21 : DirectTransport(FakeNetworkPipe::Config(), send_call) {} | 21 : DirectTransport(FakeNetworkPipe::Config(), send_call) {} |
22 | 22 |
23 DirectTransport::DirectTransport(const FakeNetworkPipe::Config& config, | 23 DirectTransport::DirectTransport(const FakeNetworkPipe::Config& config, |
24 Call* send_call) | 24 Call* send_call) |
25 : send_call_(send_call), | 25 : send_call_(send_call), |
26 packet_event_(EventWrapper::Create()), | 26 packet_event_(false, false), |
27 thread_(NetworkProcess, this, "NetworkProcess"), | 27 thread_(NetworkProcess, this, "NetworkProcess"), |
28 clock_(Clock::GetRealTimeClock()), | 28 clock_(Clock::GetRealTimeClock()), |
29 shutting_down_(false), | 29 shutting_down_(false), |
30 fake_network_(clock_, config) { | 30 fake_network_(clock_, config) { |
31 thread_.Start(); | 31 thread_.Start(); |
32 } | 32 } |
33 | 33 |
34 DirectTransport::~DirectTransport() { StopSending(); } | 34 DirectTransport::~DirectTransport() { StopSending(); } |
35 | 35 |
36 void DirectTransport::SetConfig(const FakeNetworkPipe::Config& config) { | 36 void DirectTransport::SetConfig(const FakeNetworkPipe::Config& config) { |
37 fake_network_.SetConfig(config); | 37 fake_network_.SetConfig(config); |
38 } | 38 } |
39 | 39 |
40 void DirectTransport::StopSending() { | 40 void DirectTransport::StopSending() { |
41 { | 41 { |
42 rtc::CritScope crit(&lock_); | 42 rtc::CritScope crit(&lock_); |
43 shutting_down_ = true; | 43 shutting_down_ = true; |
44 } | 44 } |
45 | 45 |
46 packet_event_->Set(); | 46 packet_event_.Set(); |
47 thread_.Stop(); | 47 thread_.Stop(); |
48 } | 48 } |
49 | 49 |
50 void DirectTransport::SetReceiver(PacketReceiver* receiver) { | 50 void DirectTransport::SetReceiver(PacketReceiver* receiver) { |
51 fake_network_.SetReceiver(receiver); | 51 fake_network_.SetReceiver(receiver); |
52 } | 52 } |
53 | 53 |
54 bool DirectTransport::SendRtp(const uint8_t* data, | 54 bool DirectTransport::SendRtp(const uint8_t* data, |
55 size_t length, | 55 size_t length, |
56 const PacketOptions& options) { | 56 const PacketOptions& options) { |
57 if (send_call_) { | 57 if (send_call_) { |
58 rtc::SentPacket sent_packet(options.packet_id, | 58 rtc::SentPacket sent_packet(options.packet_id, |
59 clock_->TimeInMilliseconds()); | 59 clock_->TimeInMilliseconds()); |
60 send_call_->OnSentPacket(sent_packet); | 60 send_call_->OnSentPacket(sent_packet); |
61 } | 61 } |
62 fake_network_.SendPacket(data, length); | 62 fake_network_.SendPacket(data, length); |
63 packet_event_->Set(); | 63 packet_event_.Set(); |
64 return true; | 64 return true; |
65 } | 65 } |
66 | 66 |
67 bool DirectTransport::SendRtcp(const uint8_t* data, size_t length) { | 67 bool DirectTransport::SendRtcp(const uint8_t* data, size_t length) { |
68 fake_network_.SendPacket(data, length); | 68 fake_network_.SendPacket(data, length); |
69 packet_event_->Set(); | 69 packet_event_.Set(); |
70 return true; | 70 return true; |
71 } | 71 } |
72 | 72 |
73 bool DirectTransport::NetworkProcess(void* transport) { | 73 bool DirectTransport::NetworkProcess(void* transport) { |
74 return static_cast<DirectTransport*>(transport)->SendPackets(); | 74 return static_cast<DirectTransport*>(transport)->SendPackets(); |
75 } | 75 } |
76 | 76 |
77 bool DirectTransport::SendPackets() { | 77 bool DirectTransport::SendPackets() { |
78 fake_network_.Process(); | 78 fake_network_.Process(); |
79 int64_t wait_time_ms = fake_network_.TimeUntilNextProcess(); | 79 int64_t wait_time_ms = fake_network_.TimeUntilNextProcess(); |
80 if (wait_time_ms > 0) { | 80 if (wait_time_ms > 0) { |
81 switch (packet_event_->Wait(static_cast<unsigned long>(wait_time_ms))) { | 81 packet_event_.Wait(static_cast<int>(wait_time_ms)); |
82 case kEventSignaled: | |
83 break; | |
84 case kEventTimeout: | |
85 break; | |
86 case kEventError: | |
87 // TODO(pbos): Log a warning here? | |
88 return true; | |
89 } | |
90 } | 82 } |
91 rtc::CritScope crit(&lock_); | 83 rtc::CritScope crit(&lock_); |
92 return shutting_down_ ? false : true; | 84 return shutting_down_ ? false : true; |
93 } | 85 } |
94 } // namespace test | 86 } // namespace test |
95 } // namespace webrtc | 87 } // namespace webrtc |
OLD | NEW |