Delete AsyncInvoker usage from SimulatedPacketTransport
Bug: webrtc:12339 Change-Id: Ic293f9c8791ec24025f9eac39cbc4fcf2583d3ea Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/212867 Commit-Queue: Niels Moller <nisse@webrtc.org> Reviewed-by: Taylor <deadbeef@webrtc.org> Cr-Commit-Position: refs/heads/master@{#33741}
This commit is contained in:
@ -647,6 +647,7 @@ if (rtc_include_tests) {
|
|||||||
"sctp/usrsctp_transport_unittest.cc",
|
"sctp/usrsctp_transport_unittest.cc",
|
||||||
]
|
]
|
||||||
deps += [
|
deps += [
|
||||||
|
"../rtc_base:rtc_event",
|
||||||
"../rtc_base/task_utils:pending_task_safety_flag",
|
"../rtc_base/task_utils:pending_task_safety_flag",
|
||||||
"../rtc_base/task_utils:to_queued_task",
|
"../rtc_base/task_utils:to_queued_task",
|
||||||
]
|
]
|
||||||
|
@ -13,8 +13,8 @@
|
|||||||
|
|
||||||
#include "media/sctp/sctp_transport_internal.h"
|
#include "media/sctp/sctp_transport_internal.h"
|
||||||
#include "media/sctp/usrsctp_transport.h"
|
#include "media/sctp/usrsctp_transport.h"
|
||||||
#include "rtc_base/async_invoker.h"
|
|
||||||
#include "rtc_base/copy_on_write_buffer.h"
|
#include "rtc_base/copy_on_write_buffer.h"
|
||||||
|
#include "rtc_base/event.h"
|
||||||
#include "rtc_base/gunit.h"
|
#include "rtc_base/gunit.h"
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
#include "rtc_base/random.h"
|
#include "rtc_base/random.h"
|
||||||
@ -54,11 +54,6 @@ class SimulatedPacketTransport final : public rtc::PacketTransportInternal {
|
|||||||
|
|
||||||
~SimulatedPacketTransport() override {
|
~SimulatedPacketTransport() override {
|
||||||
RTC_DCHECK_RUN_ON(transport_thread_);
|
RTC_DCHECK_RUN_ON(transport_thread_);
|
||||||
auto destination = destination_.load();
|
|
||||||
if (destination != nullptr) {
|
|
||||||
invoker_.Flush(destination->transport_thread_);
|
|
||||||
}
|
|
||||||
invoker_.Flush(transport_thread_);
|
|
||||||
destination_ = nullptr;
|
destination_ = nullptr;
|
||||||
SignalWritableState(this);
|
SignalWritableState(this);
|
||||||
}
|
}
|
||||||
@ -83,15 +78,13 @@ class SimulatedPacketTransport final : public rtc::PacketTransportInternal {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
rtc::CopyOnWriteBuffer buffer(data, len);
|
rtc::CopyOnWriteBuffer buffer(data, len);
|
||||||
auto send_job = [this, flags, buffer = std::move(buffer)] {
|
auto send_task = ToQueuedTask(
|
||||||
auto destination = destination_.load();
|
destination->task_safety_.flag(),
|
||||||
if (destination == nullptr) {
|
[destination, flags, buffer = std::move(buffer)] {
|
||||||
return;
|
destination->SignalReadPacket(
|
||||||
}
|
destination, reinterpret_cast<const char*>(buffer.data()),
|
||||||
destination->SignalReadPacket(
|
buffer.size(), rtc::Time(), flags);
|
||||||
destination, reinterpret_cast<const char*>(buffer.data()),
|
});
|
||||||
buffer.size(), rtc::Time(), flags);
|
|
||||||
};
|
|
||||||
// Introduce random send delay in range [0 .. 2 * avg_send_delay_millis_]
|
// Introduce random send delay in range [0 .. 2 * avg_send_delay_millis_]
|
||||||
// millis, which will also work as random packet reordering mechanism.
|
// millis, which will also work as random packet reordering mechanism.
|
||||||
uint16_t actual_send_delay = avg_send_delay_millis_;
|
uint16_t actual_send_delay = avg_send_delay_millis_;
|
||||||
@ -101,12 +94,10 @@ class SimulatedPacketTransport final : public rtc::PacketTransportInternal {
|
|||||||
actual_send_delay += reorder_delay;
|
actual_send_delay += reorder_delay;
|
||||||
|
|
||||||
if (actual_send_delay > 0) {
|
if (actual_send_delay > 0) {
|
||||||
invoker_.AsyncInvokeDelayed<void>(RTC_FROM_HERE,
|
destination->transport_thread_->PostDelayedTask(std::move(send_task),
|
||||||
destination->transport_thread_,
|
actual_send_delay);
|
||||||
std::move(send_job), actual_send_delay);
|
|
||||||
} else {
|
} else {
|
||||||
invoker_.AsyncInvoke<void>(RTC_FROM_HERE, destination->transport_thread_,
|
destination->transport_thread_->PostTask(std::move(send_task));
|
||||||
std::move(send_job));
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -136,8 +127,8 @@ class SimulatedPacketTransport final : public rtc::PacketTransportInternal {
|
|||||||
const uint8_t packet_loss_percents_;
|
const uint8_t packet_loss_percents_;
|
||||||
const uint16_t avg_send_delay_millis_;
|
const uint16_t avg_send_delay_millis_;
|
||||||
std::atomic<SimulatedPacketTransport*> destination_ ATOMIC_VAR_INIT(nullptr);
|
std::atomic<SimulatedPacketTransport*> destination_ ATOMIC_VAR_INIT(nullptr);
|
||||||
rtc::AsyncInvoker invoker_;
|
|
||||||
webrtc::Random random_;
|
webrtc::Random random_;
|
||||||
|
webrtc::ScopedTaskSafety task_safety_;
|
||||||
RTC_DISALLOW_COPY_AND_ASSIGN(SimulatedPacketTransport);
|
RTC_DISALLOW_COPY_AND_ASSIGN(SimulatedPacketTransport);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user