forked from JumpingYang001/webrtc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
direct_transport.cc
111 lines (96 loc) · 3.47 KB
/
direct_transport.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
* 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.
*/
#include "test/direct_transport.h"
#include "call/call.h"
#include "rtc_base/ptr_util.h"
#include "system_wrappers/include/clock.h"
#include "test/single_threaded_task_queue.h"
namespace webrtc {
namespace test {
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),
clock_(Clock::GetRealTimeClock()),
task_queue_(task_queue),
fake_network_(clock_, config, std::move(demuxer)) {
RTC_DCHECK(task_queue);
if (send_call_) {
send_call_->SignalChannelNetworkState(MediaType::AUDIO, kNetworkUp);
send_call_->SignalChannelNetworkState(MediaType::VIDEO, kNetworkUp);
}
SendPackets();
}
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_DCHECK_CALLED_SEQUENTIALLY(&sequence_checker_);
task_queue_->CancelTask(next_scheduled_task_);
}
void DirectTransport::SetReceiver(PacketReceiver* receiver) {
RTC_DCHECK_CALLED_SEQUENTIALLY(&sequence_checker_);
fake_network_.SetReceiver(receiver);
}
bool DirectTransport::SendRtp(const uint8_t* data,
size_t length,
const PacketOptions& options) {
if (send_call_) {
rtc::SentPacket sent_packet(options.packet_id,
clock_->TimeInMilliseconds());
send_call_->OnSentPacket(sent_packet);
}
fake_network_.SendPacket(data, length);
return true;
}
bool DirectTransport::SendRtcp(const uint8_t* data, size_t length) {
fake_network_.SendPacket(data, length);
return true;
}
int DirectTransport::GetAverageDelayMs() {
return fake_network_.AverageDelay();
}
void DirectTransport::SendPackets() {
RTC_DCHECK_CALLED_SEQUENTIALLY(&sequence_checker_);
fake_network_.Process();
int64_t delay_ms = fake_network_.TimeUntilNextProcess();
next_scheduled_task_ = task_queue_->PostDelayedTask([this]() {
SendPackets();
}, delay_ms);
}
} // namespace test
} // namespace webrtc