Index: webrtc/test/direct_transport.cc |
diff --git a/webrtc/test/direct_transport.cc b/webrtc/test/direct_transport.cc |
index 370425c5374930f7562e3f23f71277444a43d2e5..81f3b697102bd3201bd7a6316ff4277f627cde85 100644 |
--- a/webrtc/test/direct_transport.cc |
+++ b/webrtc/test/direct_transport.cc |
@@ -10,7 +10,9 @@ |
#include "webrtc/test/direct_transport.h" |
#include "webrtc/call/call.h" |
+#include "webrtc/rtc_base/ptr_util.h" |
#include "webrtc/system_wrappers/include/clock.h" |
+#include "webrtc/test/single_threaded_task_queue.h" |
namespace webrtc { |
namespace test { |
@@ -32,36 +34,71 @@ DirectTransport::DirectTransport( |
DirectTransport::DirectTransport(const FakeNetworkPipe::Config& config, |
Call* send_call, |
std::unique_ptr<Demuxer> demuxer) |
+ : DirectTransport(nullptr, config, send_call, std::move(demuxer)) {} |
+ |
+DirectTransport::DirectTransport( |
+ SingleThreadedTaskQueueForTesting* task_queue, |
+ Call* send_call, |
+ const std::map<uint8_t, MediaType>& payload_type_map) |
+ : DirectTransport(task_queue, |
+ FakeNetworkPipe::Config(), |
+ send_call, |
+ payload_type_map) { |
+} |
+ |
+DirectTransport::DirectTransport( |
+ SingleThreadedTaskQueueForTesting* task_queue, |
+ const FakeNetworkPipe::Config& config, |
+ Call* send_call, |
+ const std::map<uint8_t, MediaType>& payload_type_map) |
+ : DirectTransport( |
+ task_queue, |
+ config, |
+ send_call, |
+ std::unique_ptr<Demuxer>(new DemuxerImpl(payload_type_map))) { |
+} |
+ |
+DirectTransport::DirectTransport(SingleThreadedTaskQueueForTesting* task_queue, |
+ const FakeNetworkPipe::Config& config, |
+ Call* send_call, |
+ std::unique_ptr<Demuxer> demuxer) |
: send_call_(send_call), |
- packet_event_(false, false), |
- thread_(NetworkProcess, this, "NetworkProcess"), |
clock_(Clock::GetRealTimeClock()), |
- shutting_down_(false), |
+ task_queue_(task_queue), |
fake_network_(clock_, config, std::move(demuxer)) { |
- thread_.Start(); |
+ // TODO(eladalon): When the deprecated ctors are removed, this check |
+ // can be restored. https://bugs.chromium.org/p/webrtc/issues/detail?id=8125 |
+ // RTC_DCHECK(task_queue); |
+ if (!task_queue) { |
+ deprecated_task_queue_ = |
+ rtc::MakeUnique<SingleThreadedTaskQueueForTesting>("deprecated_queue"); |
+ task_queue_ = deprecated_task_queue_.get(); |
+ } |
+ |
if (send_call_) { |
send_call_->SignalChannelNetworkState(MediaType::AUDIO, kNetworkUp); |
send_call_->SignalChannelNetworkState(MediaType::VIDEO, kNetworkUp); |
} |
+ SendPackets(); |
} |
-DirectTransport::~DirectTransport() { StopSending(); } |
+DirectTransport::~DirectTransport() { |
+ RTC_DCHECK_CALLED_SEQUENTIALLY(&sequence_checker_); |
+ // Constructor updates |next_scheduled_task_|, so it's guaranteed to |
+ // be initialized. |
+ task_queue_->CancelTask(next_scheduled_task_); |
+} |
void DirectTransport::SetConfig(const FakeNetworkPipe::Config& config) { |
fake_network_.SetConfig(config); |
} |
void DirectTransport::StopSending() { |
- { |
- rtc::CritScope crit(&lock_); |
- shutting_down_ = true; |
- } |
- |
- packet_event_.Set(); |
- thread_.Stop(); |
+ task_queue_->CancelTask(next_scheduled_task_); |
} |
void DirectTransport::SetReceiver(PacketReceiver* receiver) { |
+ RTC_DCHECK_CALLED_SEQUENTIALLY(&sequence_checker_); |
fake_network_.SetReceiver(receiver); |
} |
@@ -74,13 +111,11 @@ bool DirectTransport::SendRtp(const uint8_t* data, |
send_call_->OnSentPacket(sent_packet); |
} |
fake_network_.SendPacket(data, length); |
- packet_event_.Set(); |
return true; |
} |
bool DirectTransport::SendRtcp(const uint8_t* data, size_t length) { |
fake_network_.SendPacket(data, length); |
- packet_event_.Set(); |
return true; |
} |
@@ -104,18 +139,15 @@ void DirectTransport::ForceDemuxer::DeliverPacket( |
packet->data_length(), packet_time); |
} |
-bool DirectTransport::NetworkProcess(void* transport) { |
- return static_cast<DirectTransport*>(transport)->SendPackets(); |
-} |
+void DirectTransport::SendPackets() { |
+ RTC_DCHECK_CALLED_SEQUENTIALLY(&sequence_checker_); |
-bool DirectTransport::SendPackets() { |
fake_network_.Process(); |
- int64_t wait_time_ms = fake_network_.TimeUntilNextProcess(); |
- if (wait_time_ms > 0) { |
- packet_event_.Wait(static_cast<int>(wait_time_ms)); |
- } |
- rtc::CritScope crit(&lock_); |
- return shutting_down_ ? false : true; |
+ |
+ int64_t delay_ms = fake_network_.TimeUntilNextProcess(); |
+ next_scheduled_task_ = task_queue_->PostDelayedTask([this]() { |
+ SendPackets(); |
+ }, delay_ms); |
} |
} // namespace test |
} // namespace webrtc |