Replacing local closure classes with C++14 moving capture lambdas.
Bug: webrtc:10945 Change-Id: I569b9495cae98f204065911e13c37c31f35da372 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/153241 Commit-Queue: Sebastian Jansson <srte@webrtc.org> Reviewed-by: Oskar Sundbom <ossu@webrtc.org> Reviewed-by: Erik Språng <sprang@webrtc.org> Cr-Commit-Position: refs/heads/master@{#29214}
This commit is contained in:

committed by
Commit Bot

parent
4d461ba298
commit
ee5ec9a93a
@ -213,11 +213,6 @@ class ChannelSend : public ChannelSendInterface,
|
||||
return media_transport_config_.media_transport;
|
||||
}
|
||||
|
||||
// Called on the encoder task queue when a new input audio frame is ready
|
||||
// for encoding.
|
||||
void ProcessAndEncodeAudioOnTaskQueue(AudioFrame* audio_input)
|
||||
RTC_RUN_ON(encoder_queue_);
|
||||
|
||||
void OnReceivedRtt(int64_t rtt_ms);
|
||||
|
||||
void OnTargetTransferRate(TargetTransferRate) override;
|
||||
@ -1048,62 +1043,56 @@ CallSendStatistics ChannelSend::GetRTCPStatistics() const {
|
||||
void ChannelSend::ProcessAndEncodeAudio(
|
||||
std::unique_ptr<AudioFrame> audio_frame) {
|
||||
RTC_DCHECK_RUNS_SERIALIZED(&audio_thread_race_checker_);
|
||||
struct ProcessAndEncodeAudio {
|
||||
void operator()() {
|
||||
RTC_DCHECK_RUN_ON(&channel->encoder_queue_);
|
||||
if (!channel->encoder_queue_is_active_) {
|
||||
return;
|
||||
}
|
||||
channel->ProcessAndEncodeAudioOnTaskQueue(audio_frame.get());
|
||||
}
|
||||
std::unique_ptr<AudioFrame> audio_frame;
|
||||
ChannelSend* const channel;
|
||||
};
|
||||
RTC_DCHECK_GT(audio_frame->samples_per_channel_, 0);
|
||||
RTC_DCHECK_LE(audio_frame->num_channels_, 8);
|
||||
|
||||
// Profile time between when the audio frame is added to the task queue and
|
||||
// when the task is actually executed.
|
||||
audio_frame->UpdateProfileTimeStamp();
|
||||
encoder_queue_.PostTask(ProcessAndEncodeAudio{std::move(audio_frame), this});
|
||||
}
|
||||
encoder_queue_.PostTask(
|
||||
[this, audio_frame = std::move(audio_frame)]() mutable {
|
||||
RTC_DCHECK_RUN_ON(&encoder_queue_);
|
||||
if (!encoder_queue_is_active_) {
|
||||
return;
|
||||
}
|
||||
// Measure time between when the audio frame is added to the task queue
|
||||
// and when the task is actually executed. Goal is to keep track of
|
||||
// unwanted extra latency added by the task queue.
|
||||
RTC_HISTOGRAM_COUNTS_10000("WebRTC.Audio.EncodingTaskQueueLatencyMs",
|
||||
audio_frame->ElapsedProfileTimeMs());
|
||||
|
||||
void ChannelSend::ProcessAndEncodeAudioOnTaskQueue(AudioFrame* audio_input) {
|
||||
RTC_DCHECK_GT(audio_input->samples_per_channel_, 0);
|
||||
RTC_DCHECK_LE(audio_input->num_channels_, 8);
|
||||
bool is_muted = InputMute();
|
||||
AudioFrameOperations::Mute(audio_frame.get(), previous_frame_muted_,
|
||||
is_muted);
|
||||
|
||||
// Measure time between when the audio frame is added to the task queue and
|
||||
// when the task is actually executed. Goal is to keep track of unwanted
|
||||
// extra latency added by the task queue.
|
||||
RTC_HISTOGRAM_COUNTS_10000("WebRTC.Audio.EncodingTaskQueueLatencyMs",
|
||||
audio_input->ElapsedProfileTimeMs());
|
||||
if (_includeAudioLevelIndication) {
|
||||
size_t length =
|
||||
audio_frame->samples_per_channel_ * audio_frame->num_channels_;
|
||||
RTC_CHECK_LE(length, AudioFrame::kMaxDataSizeBytes);
|
||||
if (is_muted && previous_frame_muted_) {
|
||||
rms_level_.AnalyzeMuted(length);
|
||||
} else {
|
||||
rms_level_.Analyze(
|
||||
rtc::ArrayView<const int16_t>(audio_frame->data(), length));
|
||||
}
|
||||
}
|
||||
previous_frame_muted_ = is_muted;
|
||||
|
||||
bool is_muted = InputMute();
|
||||
AudioFrameOperations::Mute(audio_input, previous_frame_muted_, is_muted);
|
||||
// Add 10ms of raw (PCM) audio data to the encoder @ 32kHz.
|
||||
|
||||
if (_includeAudioLevelIndication) {
|
||||
size_t length =
|
||||
audio_input->samples_per_channel_ * audio_input->num_channels_;
|
||||
RTC_CHECK_LE(length, AudioFrame::kMaxDataSizeBytes);
|
||||
if (is_muted && previous_frame_muted_) {
|
||||
rms_level_.AnalyzeMuted(length);
|
||||
} else {
|
||||
rms_level_.Analyze(
|
||||
rtc::ArrayView<const int16_t>(audio_input->data(), length));
|
||||
}
|
||||
}
|
||||
previous_frame_muted_ = is_muted;
|
||||
// The ACM resamples internally.
|
||||
audio_frame->timestamp_ = _timeStamp;
|
||||
// This call will trigger AudioPacketizationCallback::SendData if
|
||||
// encoding is done and payload is ready for packetization and
|
||||
// transmission. Otherwise, it will return without invoking the
|
||||
// callback.
|
||||
if (audio_coding_->Add10MsData(*audio_frame) < 0) {
|
||||
RTC_DLOG(LS_ERROR) << "ACM::Add10MsData() failed.";
|
||||
return;
|
||||
}
|
||||
|
||||
// Add 10ms of raw (PCM) audio data to the encoder @ 32kHz.
|
||||
|
||||
// The ACM resamples internally.
|
||||
audio_input->timestamp_ = _timeStamp;
|
||||
// This call will trigger AudioPacketizationCallback::SendData if encoding
|
||||
// is done and payload is ready for packetization and transmission.
|
||||
// Otherwise, it will return without invoking the callback.
|
||||
if (audio_coding_->Add10MsData(*audio_input) < 0) {
|
||||
RTC_DLOG(LS_ERROR) << "ACM::Add10MsData() failed.";
|
||||
return;
|
||||
}
|
||||
|
||||
_timeStamp += static_cast<uint32_t>(audio_input->samples_per_channel_);
|
||||
_timeStamp += static_cast<uint32_t>(audio_frame->samples_per_channel_);
|
||||
});
|
||||
}
|
||||
|
||||
ANAStats ChannelSend::GetANAStatistics() const {
|
||||
|
@ -27,47 +27,40 @@ EmulatedIpPacket::EmulatedIpPacket(const rtc::SocketAddress& from,
|
||||
: from(from), to(to), data(data), arrival_time(arrival_time) {}
|
||||
|
||||
void LinkEmulation::OnPacketReceived(EmulatedIpPacket packet) {
|
||||
struct Closure {
|
||||
void operator()() {
|
||||
RTC_DCHECK_RUN_ON(link->task_queue_);
|
||||
link->HandlePacketReceived(std::move(packet));
|
||||
}
|
||||
LinkEmulation* link;
|
||||
EmulatedIpPacket packet;
|
||||
};
|
||||
task_queue_->PostTask(Closure{this, std::move(packet)});
|
||||
}
|
||||
task_queue_->PostTask([this, packet = std::move(packet)]() mutable {
|
||||
RTC_DCHECK_RUN_ON(task_queue_);
|
||||
|
||||
void LinkEmulation::HandlePacketReceived(EmulatedIpPacket packet) {
|
||||
uint64_t packet_id = next_packet_id_++;
|
||||
bool sent = network_behavior_->EnqueuePacket(
|
||||
PacketInFlightInfo(packet.size(), packet.arrival_time.us(), packet_id));
|
||||
if (sent) {
|
||||
packets_.emplace_back(StoredPacket{packet_id, std::move(packet), false});
|
||||
}
|
||||
if (process_task_.Running())
|
||||
return;
|
||||
absl::optional<int64_t> next_time_us =
|
||||
network_behavior_->NextDeliveryTimeUs();
|
||||
if (!next_time_us)
|
||||
return;
|
||||
Timestamp current_time = clock_->CurrentTime();
|
||||
process_task_ = RepeatingTaskHandle::DelayedStart(
|
||||
task_queue_->Get(),
|
||||
std::max(TimeDelta::Zero(), Timestamp::us(*next_time_us) - current_time),
|
||||
[this]() {
|
||||
RTC_DCHECK_RUN_ON(task_queue_);
|
||||
Timestamp current_time = clock_->CurrentTime();
|
||||
Process(current_time);
|
||||
absl::optional<int64_t> next_time_us =
|
||||
network_behavior_->NextDeliveryTimeUs();
|
||||
if (!next_time_us) {
|
||||
process_task_.Stop();
|
||||
return TimeDelta::Zero(); // This is ignored.
|
||||
}
|
||||
RTC_DCHECK_GE(*next_time_us, current_time.us());
|
||||
return Timestamp::us(*next_time_us) - current_time;
|
||||
});
|
||||
uint64_t packet_id = next_packet_id_++;
|
||||
bool sent = network_behavior_->EnqueuePacket(
|
||||
PacketInFlightInfo(packet.size(), packet.arrival_time.us(), packet_id));
|
||||
if (sent) {
|
||||
packets_.emplace_back(StoredPacket{packet_id, std::move(packet), false});
|
||||
}
|
||||
if (process_task_.Running())
|
||||
return;
|
||||
absl::optional<int64_t> next_time_us =
|
||||
network_behavior_->NextDeliveryTimeUs();
|
||||
if (!next_time_us)
|
||||
return;
|
||||
Timestamp current_time = clock_->CurrentTime();
|
||||
process_task_ = RepeatingTaskHandle::DelayedStart(
|
||||
task_queue_->Get(),
|
||||
std::max(TimeDelta::Zero(),
|
||||
Timestamp::us(*next_time_us) - current_time),
|
||||
[this]() {
|
||||
RTC_DCHECK_RUN_ON(task_queue_);
|
||||
Timestamp current_time = clock_->CurrentTime();
|
||||
Process(current_time);
|
||||
absl::optional<int64_t> next_time_us =
|
||||
network_behavior_->NextDeliveryTimeUs();
|
||||
if (!next_time_us) {
|
||||
process_task_.Stop();
|
||||
return TimeDelta::Zero(); // This is ignored.
|
||||
}
|
||||
RTC_DCHECK_GE(*next_time_us, current_time.us());
|
||||
return Timestamp::us(*next_time_us) - current_time;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void LinkEmulation::Process(Timestamp at_time) {
|
||||
@ -204,19 +197,23 @@ uint64_t EmulatedEndpoint::GetId() const {
|
||||
|
||||
void EmulatedEndpoint::SendPacket(const rtc::SocketAddress& from,
|
||||
const rtc::SocketAddress& to,
|
||||
rtc::CopyOnWriteBuffer packet) {
|
||||
rtc::CopyOnWriteBuffer packet_data) {
|
||||
RTC_CHECK(from.ipaddr() == peer_local_addr_);
|
||||
struct Closure {
|
||||
void operator()() {
|
||||
endpoint->UpdateSendStats(packet);
|
||||
endpoint->router_.OnPacketReceived(std::move(packet));
|
||||
EmulatedIpPacket packet(from, to, std::move(packet_data),
|
||||
clock_->CurrentTime());
|
||||
task_queue_->PostTask([this, packet = std::move(packet)]() mutable {
|
||||
RTC_DCHECK_RUN_ON(task_queue_);
|
||||
Timestamp current_time = clock_->CurrentTime();
|
||||
if (stats_.first_packet_sent_time.IsInfinite()) {
|
||||
stats_.first_packet_sent_time = current_time;
|
||||
stats_.first_sent_packet_size = DataSize::bytes(packet.size());
|
||||
}
|
||||
EmulatedEndpoint* endpoint;
|
||||
EmulatedIpPacket packet;
|
||||
};
|
||||
task_queue_->PostTask(Closure{
|
||||
this,
|
||||
EmulatedIpPacket(from, to, std::move(packet), clock_->CurrentTime())});
|
||||
stats_.last_packet_sent_time = current_time;
|
||||
stats_.packets_sent++;
|
||||
stats_.bytes_sent += DataSize::bytes(packet.size());
|
||||
|
||||
router_.OnPacketReceived(std::move(packet));
|
||||
});
|
||||
}
|
||||
|
||||
absl::optional<uint16_t> EmulatedEndpoint::BindReceiver(
|
||||
@ -316,18 +313,6 @@ EmulatedNetworkStats EmulatedEndpoint::stats() {
|
||||
return stats_;
|
||||
}
|
||||
|
||||
void EmulatedEndpoint::UpdateSendStats(const EmulatedIpPacket& packet) {
|
||||
RTC_DCHECK_RUN_ON(task_queue_);
|
||||
Timestamp current_time = clock_->CurrentTime();
|
||||
if (stats_.first_packet_sent_time.IsInfinite()) {
|
||||
stats_.first_packet_sent_time = current_time;
|
||||
stats_.first_sent_packet_size = DataSize::bytes(packet.size());
|
||||
}
|
||||
stats_.last_packet_sent_time = current_time;
|
||||
stats_.packets_sent++;
|
||||
stats_.bytes_sent += DataSize::bytes(packet.size());
|
||||
}
|
||||
|
||||
void EmulatedEndpoint::UpdateReceiveStats(const EmulatedIpPacket& packet) {
|
||||
RTC_DCHECK_RUN_ON(task_queue_);
|
||||
Timestamp current_time = clock_->CurrentTime();
|
||||
|
@ -82,7 +82,6 @@ class LinkEmulation : public EmulatedNetworkReceiverInterface {
|
||||
bool removed;
|
||||
};
|
||||
void Process(Timestamp at_time) RTC_RUN_ON(task_queue_);
|
||||
void HandlePacketReceived(EmulatedIpPacket packet) RTC_RUN_ON(task_queue_);
|
||||
|
||||
Clock* const clock_;
|
||||
rtc::TaskQueue* const task_queue_;
|
||||
@ -171,7 +170,7 @@ class EmulatedEndpoint : public EmulatedNetworkReceiverInterface {
|
||||
// on destination endpoint.
|
||||
void SendPacket(const rtc::SocketAddress& from,
|
||||
const rtc::SocketAddress& to,
|
||||
rtc::CopyOnWriteBuffer packet);
|
||||
rtc::CopyOnWriteBuffer packet_data);
|
||||
|
||||
// Binds receiver to this endpoint to send and receive data.
|
||||
// |desired_port| is a port that should be used. If it is equal to 0,
|
||||
@ -203,7 +202,6 @@ class EmulatedEndpoint : public EmulatedNetworkReceiverInterface {
|
||||
private:
|
||||
static constexpr uint16_t kFirstEphemeralPort = 49152;
|
||||
uint16_t NextPort() RTC_EXCLUSIVE_LOCKS_REQUIRED(receiver_lock_);
|
||||
void UpdateSendStats(const EmulatedIpPacket& packet);
|
||||
void UpdateReceiveStats(const EmulatedIpPacket& packet);
|
||||
|
||||
rtc::CriticalSection receiver_lock_;
|
||||
|
@ -278,16 +278,11 @@ void CallClient::OnPacketReceived(EmulatedIpPacket packet) {
|
||||
RTC_CHECK(ssrc.has_value());
|
||||
media_type = ssrc_media_types_[*ssrc];
|
||||
}
|
||||
struct Closure {
|
||||
void operator()() {
|
||||
call->Receiver()->DeliverPacket(media_type, packet.data,
|
||||
packet.arrival_time.us());
|
||||
}
|
||||
Call* call;
|
||||
MediaType media_type;
|
||||
EmulatedIpPacket packet;
|
||||
};
|
||||
task_queue_.PostTask(Closure{call_.get(), media_type, std::move(packet)});
|
||||
task_queue_.PostTask(
|
||||
[call = call_.get(), media_type, packet = std::move(packet)]() mutable {
|
||||
call->Receiver()->DeliverPacket(media_type, packet.data,
|
||||
packet.arrival_time.us());
|
||||
});
|
||||
}
|
||||
|
||||
std::unique_ptr<RtcEventLogOutput> CallClient::GetLogWriter(std::string name) {
|
||||
|
@ -622,29 +622,23 @@ int64_t VideoReceiveStream::GetWaitMs() const {
|
||||
|
||||
void VideoReceiveStream::StartNextDecode() {
|
||||
TRACE_EVENT0("webrtc", "VideoReceiveStream::StartNextDecode");
|
||||
|
||||
struct DecodeTask {
|
||||
void operator()() {
|
||||
RTC_DCHECK_RUN_ON(&stream->decode_queue_);
|
||||
if (stream->decoder_stopped_)
|
||||
return;
|
||||
if (frame) {
|
||||
stream->HandleEncodedFrame(std::move(frame));
|
||||
} else {
|
||||
stream->HandleFrameBufferTimeout();
|
||||
}
|
||||
stream->StartNextDecode();
|
||||
}
|
||||
VideoReceiveStream* stream;
|
||||
std::unique_ptr<EncodedFrame> frame;
|
||||
};
|
||||
|
||||
frame_buffer_->NextFrame(
|
||||
GetWaitMs(), keyframe_required_, &decode_queue_,
|
||||
/* encoded frame handler */
|
||||
[this](std::unique_ptr<EncodedFrame> frame, ReturnReason res) {
|
||||
RTC_DCHECK_EQ(frame == nullptr, res == ReturnReason::kTimeout);
|
||||
RTC_DCHECK_EQ(frame != nullptr, res == ReturnReason::kFrameFound);
|
||||
decode_queue_.PostTask(DecodeTask{this, std::move(frame)});
|
||||
decode_queue_.PostTask([this, frame = std::move(frame)]() mutable {
|
||||
RTC_DCHECK_RUN_ON(&decode_queue_);
|
||||
if (decoder_stopped_)
|
||||
return;
|
||||
if (frame) {
|
||||
HandleEncodedFrame(std::move(frame));
|
||||
} else {
|
||||
HandleFrameBufferTimeout();
|
||||
}
|
||||
StartNextDecode();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user