blob: 9e15a713174b493af7d89f7ad3971c6a1fb43029 [file] [log] [blame]
Stefan Holmere5904162015-03-26 11:11:06 +01001/*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "webrtc/modules/pacing/include/packet_router.h"
12
13#include "webrtc/base/checks.h"
14#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h"
15#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h"
16#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
17
18namespace webrtc {
19
20PacketRouter::PacketRouter()
21 : crit_(CriticalSectionWrapper::CreateCriticalSection()) {
22}
23
24PacketRouter::~PacketRouter() {
25}
26
27void PacketRouter::AddRtpModule(RtpRtcp* rtp_module) {
28 CriticalSectionScoped cs(crit_.get());
29 DCHECK(std::find(rtp_modules_.begin(), rtp_modules_.end(), rtp_module) ==
30 rtp_modules_.end());
31 rtp_modules_.push_back(rtp_module);
32}
33
34void PacketRouter::RemoveRtpModule(RtpRtcp* rtp_module) {
35 CriticalSectionScoped cs(crit_.get());
36 rtp_modules_.remove(rtp_module);
37}
38
39bool PacketRouter::TimeToSendPacket(uint32_t ssrc,
40 uint16_t sequence_number,
41 int64_t capture_timestamp,
42 bool retransmission) {
43 CriticalSectionScoped cs(crit_.get());
44 for (auto* rtp_module : rtp_modules_) {
45 if (rtp_module->SendingMedia() && ssrc == rtp_module->SSRC()) {
46 return rtp_module->TimeToSendPacket(ssrc, sequence_number,
47 capture_timestamp, retransmission);
48 }
49 }
50 return true;
51}
52
53size_t PacketRouter::TimeToSendPadding(size_t bytes) {
54 CriticalSectionScoped cs(crit_.get());
55 for (auto* rtp_module : rtp_modules_) {
56 if (rtp_module->SendingMedia())
57 return rtp_module->TimeToSendPadding(bytes);
58 }
59 return 0;
60}
61} // namespace webrtc