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.
|
|
|
|
|
*/
|
2013-10-28 16:32:01 +00:00
|
|
|
#include "webrtc/test/direct_transport.h"
|
2013-08-12 12:59:04 +00:00
|
|
|
|
2013-10-28 16:32:01 +00:00
|
|
|
#include "webrtc/call.h"
|
2015-10-28 18:17:40 +01:00
|
|
|
#include "webrtc/system_wrappers/include/clock.h"
|
2016-09-30 22:29:43 -07:00
|
|
|
#include "webrtc/test/gtest.h"
|
2013-08-12 12:59:04 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
namespace test {
|
|
|
|
|
|
2015-10-27 08:29:42 -07:00
|
|
|
DirectTransport::DirectTransport(Call* send_call)
|
2015-11-26 17:45:47 +01:00
|
|
|
: DirectTransport(FakeNetworkPipe::Config(), send_call) {}
|
2013-11-18 11:45:11 +00:00
|
|
|
|
2015-10-27 08:29:42 -07:00
|
|
|
DirectTransport::DirectTransport(const FakeNetworkPipe::Config& config,
|
|
|
|
|
Call* send_call)
|
|
|
|
|
: send_call_(send_call),
|
2015-12-10 13:02:50 +01:00
|
|
|
packet_event_(false, false),
|
2015-11-26 17:45:47 +01:00
|
|
|
thread_(NetworkProcess, this, "NetworkProcess"),
|
2013-11-18 11:45:11 +00:00
|
|
|
clock_(Clock::GetRealTimeClock()),
|
|
|
|
|
shutting_down_(false),
|
2015-12-09 11:20:58 +01:00
|
|
|
fake_network_(clock_, config) {
|
2015-11-26 17:45:47 +01:00
|
|
|
thread_.Start();
|
2013-08-12 12:59:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DirectTransport::~DirectTransport() { StopSending(); }
|
|
|
|
|
|
2014-02-26 13:34:52 +00:00
|
|
|
void DirectTransport::SetConfig(const FakeNetworkPipe::Config& config) {
|
|
|
|
|
fake_network_.SetConfig(config);
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-12 14:28:00 +00:00
|
|
|
void DirectTransport::StopSending() {
|
|
|
|
|
{
|
2015-05-01 13:00:41 +02:00
|
|
|
rtc::CritScope crit(&lock_);
|
2013-08-12 14:28:00 +00:00
|
|
|
shutting_down_ = true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-10 13:02:50 +01:00
|
|
|
packet_event_.Set();
|
2015-11-26 17:45:47 +01:00
|
|
|
thread_.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) {
|
2013-12-18 20:28:25 +00: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_) {
|
|
|
|
|
rtc::SentPacket sent_packet(options.packet_id,
|
|
|
|
|
clock_->TimeInMilliseconds());
|
|
|
|
|
send_call_->OnSentPacket(sent_packet);
|
|
|
|
|
}
|
2013-12-18 20:28:25 +00:00
|
|
|
fake_network_.SendPacket(data, length);
|
2015-12-10 13:02:50 +01:00
|
|
|
packet_event_.Set();
|
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) {
|
2013-12-18 20:28:25 +00:00
|
|
|
fake_network_.SendPacket(data, length);
|
2015-12-10 13:02:50 +01:00
|
|
|
packet_event_.Set();
|
2013-12-18 20:28:25 +00:00
|
|
|
return true;
|
2013-08-12 12:59:04 +00:00
|
|
|
}
|
|
|
|
|
|
2016-01-14 10:00:21 +01:00
|
|
|
int DirectTransport::GetAverageDelayMs() {
|
|
|
|
|
return fake_network_.AverageDelay();
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-12 12:59:04 +00:00
|
|
|
bool DirectTransport::NetworkProcess(void* transport) {
|
|
|
|
|
return static_cast<DirectTransport*>(transport)->SendPackets();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DirectTransport::SendPackets() {
|
2013-12-18 20:28:25 +00:00
|
|
|
fake_network_.Process();
|
2014-12-15 22:09:40 +00:00
|
|
|
int64_t wait_time_ms = fake_network_.TimeUntilNextProcess();
|
2013-12-18 20:28:25 +00:00
|
|
|
if (wait_time_ms > 0) {
|
2015-12-10 13:02:50 +01:00
|
|
|
packet_event_.Wait(static_cast<int>(wait_time_ms));
|
2013-11-18 11:45:11 +00:00
|
|
|
}
|
2015-05-01 13:00:41 +02:00
|
|
|
rtc::CritScope crit(&lock_);
|
2013-08-12 14:28:00 +00:00
|
|
|
return shutting_down_ ? false : true;
|
2013-08-12 12:59:04 +00:00
|
|
|
}
|
|
|
|
|
} // namespace test
|
|
|
|
|
} // namespace webrtc
|