2013-08-12 12:59:04 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "test/direct_transport.h"
|
2013-08-12 12:59:04 +00:00
|
|
|
|
Use absl::make_unique and absl::WrapUnique directly
Instead of going through our wrappers in ptr_util.h.
This CL was generated by the following script:
git grep -l ptr_util | xargs perl -pi -e 's,#include "rtc_base/ptr_util.h",#include "absl/memory/memory.h",'
git grep -l MakeUnique | xargs perl -pi -e 's,\b(rtc::)?MakeUnique\b,absl::make_unique,g'
git grep -l WrapUnique | xargs perl -pi -e 's,\b(rtc::)?WrapUnique\b,absl::WrapUnique,g'
git checkout -- rtc_base/ptr_util{.h,_unittest.cc}
git cl format
Followed by manually adding dependencies on
//third_party/abseil-cpp/absl/memory until `gn check` stopped
complaining.
Bug: webrtc:9473
Change-Id: I89ccd363f070479b8c431eb2c3d404a46eaacc1c
Reviewed-on: https://webrtc-review.googlesource.com/86600
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23850}
2018-07-05 11:40:33 +02:00
|
|
|
#include "absl/memory/memory.h"
|
2019-09-27 11:10:45 +02:00
|
|
|
#include "api/task_queue/task_queue_base.h"
|
|
|
|
|
#include "api/units/time_delta.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "call/call.h"
|
2018-08-17 14:26:54 +02:00
|
|
|
#include "call/fake_network_pipe.h"
|
2019-09-27 11:10:45 +02:00
|
|
|
#include "rtc_base/task_utils/repeating_task.h"
|
2019-03-29 14:17:26 +01:00
|
|
|
#include "rtc_base/time_utils.h"
|
2019-08-29 16:39:05 +02:00
|
|
|
#include "test/rtp_header_parser.h"
|
2013-08-12 12:59:04 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
namespace test {
|
|
|
|
|
|
2018-04-24 14:41:22 +02:00
|
|
|
Demuxer::Demuxer(const std::map<uint8_t, MediaType>& payload_type_map)
|
|
|
|
|
: payload_type_map_(payload_type_map) {}
|
|
|
|
|
|
|
|
|
|
MediaType Demuxer::GetMediaType(const uint8_t* packet_data,
|
|
|
|
|
const size_t packet_length) const {
|
|
|
|
|
if (!RtpHeaderParser::IsRtcp(packet_data, packet_length)) {
|
|
|
|
|
RTC_CHECK_GE(packet_length, 2);
|
|
|
|
|
const uint8_t payload_type = packet_data[1] & 0x7f;
|
|
|
|
|
std::map<uint8_t, MediaType>::const_iterator it =
|
|
|
|
|
payload_type_map_.find(payload_type);
|
|
|
|
|
RTC_CHECK(it != payload_type_map_.end())
|
|
|
|
|
<< "payload type " << static_cast<int>(payload_type) << " unknown.";
|
|
|
|
|
return it->second;
|
|
|
|
|
}
|
|
|
|
|
return MediaType::ANY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DirectTransport::DirectTransport(
|
2019-09-27 11:10:45 +02:00
|
|
|
TaskQueueBase* task_queue,
|
2018-08-17 14:26:54 +02:00
|
|
|
std::unique_ptr<SimulatedPacketReceiverInterface> pipe,
|
2018-04-24 14:41:22 +02:00
|
|
|
Call* send_call,
|
|
|
|
|
const std::map<uint8_t, MediaType>& payload_type_map)
|
2017-10-24 16:26:49 +02:00
|
|
|
: send_call_(send_call),
|
|
|
|
|
task_queue_(task_queue),
|
2018-04-24 14:41:22 +02:00
|
|
|
demuxer_(payload_type_map),
|
2017-10-24 16:26:49 +02:00
|
|
|
fake_network_(std::move(pipe)) {
|
|
|
|
|
Start();
|
2013-08-12 12:59:04 +00:00
|
|
|
}
|
|
|
|
|
|
2017-08-22 04:02:52 -07:00
|
|
|
DirectTransport::~DirectTransport() {
|
2019-09-27 11:10:45 +02:00
|
|
|
next_process_task_.Stop();
|
2013-08-12 14:28:00 +00:00
|
|
|
}
|
2013-08-12 12:59:04 +00:00
|
|
|
|
2013-08-23 09:19:30 +00:00
|
|
|
void DirectTransport::SetReceiver(PacketReceiver* receiver) {
|
2017-10-24 16:26:49 +02:00
|
|
|
fake_network_->SetReceiver(receiver);
|
2013-08-12 12:59:04 +00:00
|
|
|
}
|
|
|
|
|
|
2015-10-02 03:39:33 -07:00
|
|
|
bool DirectTransport::SendRtp(const uint8_t* data,
|
|
|
|
|
size_t length,
|
|
|
|
|
const PacketOptions& options) {
|
2015-10-27 08:29:42 -07:00
|
|
|
if (send_call_) {
|
2019-03-29 14:17:26 +01:00
|
|
|
rtc::SentPacket sent_packet(options.packet_id, rtc::TimeMillis());
|
2018-10-09 18:27:57 +02:00
|
|
|
sent_packet.info.included_in_feedback = options.included_in_feedback;
|
|
|
|
|
sent_packet.info.included_in_allocation = options.included_in_allocation;
|
2018-09-28 17:21:34 +02:00
|
|
|
sent_packet.info.packet_size_bytes = length;
|
|
|
|
|
sent_packet.info.packet_type = rtc::PacketType::kData;
|
2015-10-27 08:29:42 -07:00
|
|
|
send_call_->OnSentPacket(sent_packet);
|
|
|
|
|
}
|
2018-04-24 14:41:22 +02:00
|
|
|
SendPacket(data, length);
|
2013-08-12 12:59:04 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-20 12:17:04 +00:00
|
|
|
bool DirectTransport::SendRtcp(const uint8_t* data, size_t length) {
|
2018-04-24 14:41:22 +02:00
|
|
|
SendPacket(data, length);
|
2013-12-18 20:28:25 +00:00
|
|
|
return true;
|
2013-08-12 12:59:04 +00:00
|
|
|
}
|
|
|
|
|
|
2018-04-24 14:41:22 +02:00
|
|
|
void DirectTransport::SendPacket(const uint8_t* data, size_t length) {
|
|
|
|
|
MediaType media_type = demuxer_.GetMediaType(data, length);
|
2019-03-29 14:17:26 +01:00
|
|
|
int64_t send_time_us = rtc::TimeMicros();
|
2018-04-24 14:41:22 +02:00
|
|
|
fake_network_->DeliverPacket(media_type, rtc::CopyOnWriteBuffer(data, length),
|
2019-03-29 14:17:26 +01:00
|
|
|
send_time_us);
|
2020-07-08 16:09:21 +02:00
|
|
|
MutexLock lock(&process_lock_);
|
2019-09-27 11:10:45 +02:00
|
|
|
if (!next_process_task_.Running())
|
2019-02-08 16:08:10 +01:00
|
|
|
ProcessPackets();
|
2018-04-24 14:41:22 +02:00
|
|
|
}
|
|
|
|
|
|
2016-01-14 10:00:21 +01:00
|
|
|
int DirectTransport::GetAverageDelayMs() {
|
2017-10-24 16:26:49 +02:00
|
|
|
return fake_network_->AverageDelay();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DirectTransport::Start() {
|
|
|
|
|
RTC_DCHECK(task_queue_);
|
|
|
|
|
if (send_call_) {
|
|
|
|
|
send_call_->SignalChannelNetworkState(MediaType::AUDIO, kNetworkUp);
|
|
|
|
|
send_call_->SignalChannelNetworkState(MediaType::VIDEO, kNetworkUp);
|
|
|
|
|
}
|
2016-01-14 10:00:21 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-08 16:08:10 +01:00
|
|
|
void DirectTransport::ProcessPackets() {
|
2019-09-27 11:10:45 +02:00
|
|
|
absl::optional<int64_t> initial_delay_ms =
|
|
|
|
|
fake_network_->TimeUntilNextProcess();
|
|
|
|
|
if (initial_delay_ms == absl::nullopt)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
next_process_task_ = RepeatingTaskHandle::DelayedStart(
|
2020-02-10 11:16:00 +01:00
|
|
|
task_queue_, TimeDelta::Millis(*initial_delay_ms), [this] {
|
2019-09-27 11:10:45 +02:00
|
|
|
fake_network_->Process();
|
|
|
|
|
if (auto delay_ms = fake_network_->TimeUntilNextProcess())
|
2020-02-10 11:16:00 +01:00
|
|
|
return TimeDelta::Millis(*delay_ms);
|
2019-09-27 11:10:45 +02:00
|
|
|
// Otherwise stop the task.
|
2020-07-08 16:09:21 +02:00
|
|
|
MutexLock lock(&process_lock_);
|
2019-09-27 11:10:45 +02:00
|
|
|
next_process_task_.Stop();
|
|
|
|
|
// Since this task is stopped, return value doesn't matter.
|
|
|
|
|
return TimeDelta::Zero();
|
|
|
|
|
});
|
2013-08-12 12:59:04 +00:00
|
|
|
}
|
|
|
|
|
} // namespace test
|
|
|
|
|
} // namespace webrtc
|