2016-06-08 00:24:21 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2016 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 "webrtc/modules/rtp_rtcp/source/playout_delay_oracle.h"
|
|
|
|
|
|
|
|
|
|
#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
|
2017-01-23 11:10:20 -08:00
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h"
|
2017-07-06 19:44:34 +02:00
|
|
|
#include "webrtc/rtc_base/checks.h"
|
|
|
|
|
#include "webrtc/rtc_base/logging.h"
|
2016-06-08 00:24:21 -07:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
PlayoutDelayOracle::PlayoutDelayOracle()
|
|
|
|
|
: high_sequence_number_(0),
|
|
|
|
|
send_playout_delay_(false),
|
|
|
|
|
ssrc_(0),
|
2016-09-07 13:29:47 +02:00
|
|
|
playout_delay_{-1, -1} {}
|
2016-06-14 10:55:36 -07:00
|
|
|
|
2016-06-08 00:24:21 -07:00
|
|
|
PlayoutDelayOracle::~PlayoutDelayOracle() {}
|
|
|
|
|
|
|
|
|
|
void PlayoutDelayOracle::UpdateRequest(uint32_t ssrc,
|
|
|
|
|
PlayoutDelay playout_delay,
|
|
|
|
|
uint16_t seq_num) {
|
|
|
|
|
rtc::CritScope lock(&crit_sect_);
|
2017-01-23 11:10:20 -08:00
|
|
|
RTC_DCHECK_LE(playout_delay.min_ms, PlayoutDelayLimits::kMaxMs);
|
|
|
|
|
RTC_DCHECK_LE(playout_delay.max_ms, PlayoutDelayLimits::kMaxMs);
|
2016-06-08 00:24:21 -07:00
|
|
|
RTC_DCHECK_LE(playout_delay.min_ms, playout_delay.max_ms);
|
|
|
|
|
int64_t unwrapped_seq_num = unwrapper_.Unwrap(seq_num);
|
|
|
|
|
if (playout_delay.min_ms >= 0 &&
|
2016-09-07 13:29:47 +02:00
|
|
|
playout_delay.min_ms != playout_delay_.min_ms) {
|
2016-06-08 00:24:21 -07:00
|
|
|
send_playout_delay_ = true;
|
2016-09-07 13:29:47 +02:00
|
|
|
playout_delay_.min_ms = playout_delay.min_ms;
|
2016-06-08 00:24:21 -07:00
|
|
|
high_sequence_number_ = unwrapped_seq_num;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (playout_delay.max_ms >= 0 &&
|
2016-09-07 13:29:47 +02:00
|
|
|
playout_delay.max_ms != playout_delay_.max_ms) {
|
2016-06-08 00:24:21 -07:00
|
|
|
send_playout_delay_ = true;
|
2016-09-07 13:29:47 +02:00
|
|
|
playout_delay_.max_ms = playout_delay.max_ms;
|
2016-06-08 00:24:21 -07:00
|
|
|
high_sequence_number_ = unwrapped_seq_num;
|
|
|
|
|
}
|
|
|
|
|
ssrc_ = ssrc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If an ACK is received on the packet containing the playout delay extension,
|
|
|
|
|
// we stop sending the extension on future packets.
|
|
|
|
|
void PlayoutDelayOracle::OnReceivedRtcpReportBlocks(
|
|
|
|
|
const ReportBlockList& report_blocks) {
|
|
|
|
|
rtc::CritScope lock(&crit_sect_);
|
|
|
|
|
for (const RTCPReportBlock& report_block : report_blocks) {
|
2017-08-09 06:13:45 -07:00
|
|
|
if ((ssrc_ == report_block.source_ssrc) && send_playout_delay_ &&
|
|
|
|
|
(report_block.extended_highest_sequence_number >
|
|
|
|
|
high_sequence_number_)) {
|
2016-06-08 00:24:21 -07:00
|
|
|
send_playout_delay_ = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|