blob: 5a0920f874c8c8e19b6bf2e8a4e32e2582a757d9 [file] [log] [blame]
mflodman15d83572016-10-06 08:35:11 -07001/*
2 * Copyright (c) 2012 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
Elad Alon14d1c9d2019-04-08 14:16:17 +020011#include "video/encoder_rtcp_feedback.h"
mflodman15d83572016-10-06 08:35:11 -070012
Rasmus Brandt3dde4502019-03-21 11:46:17 +010013#include "absl/types/optional.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#include "rtc_base/checks.h"
Rasmus Brandt3dde4502019-03-21 11:46:17 +010015#include "rtc_base/experiments/keyframe_interval_settings.h"
mflodman15d83572016-10-06 08:35:11 -070016
17namespace webrtc {
18
Rasmus Brandt3dde4502019-03-21 11:46:17 +010019namespace {
20constexpr int kMinKeyframeSendIntervalMs = 300;
21} // namespace
22
Elad Alon14d1c9d2019-04-08 14:16:17 +020023EncoderRtcpFeedback::EncoderRtcpFeedback(Clock* clock,
24 const std::vector<uint32_t>& ssrcs,
25 VideoStreamEncoderInterface* encoder)
mflodman15d83572016-10-06 08:35:11 -070026 : clock_(clock),
27 ssrcs_(ssrcs),
mflodmancc3d4422017-08-03 08:27:51 -070028 video_stream_encoder_(encoder),
Rasmus Brandt3dde4502019-03-21 11:46:17 +010029 time_last_intra_request_ms_(-1),
30 min_keyframe_send_interval_ms_(
31 KeyframeIntervalSettings::ParseFromFieldTrials()
32 .MinKeyframeSendIntervalMs()
33 .value_or(kMinKeyframeSendIntervalMs)) {
mflodman15d83572016-10-06 08:35:11 -070034 RTC_DCHECK(!ssrcs.empty());
35}
36
Elad Alon14d1c9d2019-04-08 14:16:17 +020037bool EncoderRtcpFeedback::HasSsrc(uint32_t ssrc) {
mflodman15d83572016-10-06 08:35:11 -070038 for (uint32_t registered_ssrc : ssrcs_) {
39 if (registered_ssrc == ssrc) {
40 return true;
41 }
42 }
43 return false;
44}
45
Elad Alon14d1c9d2019-04-08 14:16:17 +020046void EncoderRtcpFeedback::OnReceivedIntraFrameRequest(uint32_t ssrc) {
mflodman15d83572016-10-06 08:35:11 -070047 RTC_DCHECK(HasSsrc(ssrc));
mflodman15d83572016-10-06 08:35:11 -070048 {
mflodman15d83572016-10-06 08:35:11 -070049 int64_t now_ms = clock_->TimeInMilliseconds();
50 rtc::CritScope lock(&crit_);
Rasmus Brandt3dde4502019-03-21 11:46:17 +010051 if (time_last_intra_request_ms_ + min_keyframe_send_interval_ms_ > now_ms) {
mflodman15d83572016-10-06 08:35:11 -070052 return;
53 }
Magnus Flodman3c62afd2018-09-24 11:44:49 +020054 time_last_intra_request_ms_ = now_ms;
mflodman15d83572016-10-06 08:35:11 -070055 }
56
Niels Möller1c9aa1e2018-02-16 10:27:23 +010057 // Always produce key frame for all streams.
58 video_stream_encoder_->SendKeyFrame();
mflodman15d83572016-10-06 08:35:11 -070059}
60
Elad Alon14d1c9d2019-04-08 14:16:17 +020061void EncoderRtcpFeedback::OnKeyFrameRequested(uint64_t channel_id) {
Niels Möllerfa89d842019-01-30 16:33:45 +010062 if (channel_id != ssrcs_[0]) {
63 RTC_LOG(LS_INFO) << "Key frame request on unknown channel id " << channel_id
64 << " expected " << ssrcs_[0];
65 return;
66 }
67
68 video_stream_encoder_->SendKeyFrame();
69}
70
Elad Alon0a8562e2019-04-09 11:55:13 +020071void EncoderRtcpFeedback::OnReceivedLossNotification(
72 uint32_t ssrc,
73 uint16_t seq_num_of_last_decodable,
74 uint16_t seq_num_of_last_received,
75 bool decodability_flag) {
76 // TODO(eladalon): Handle.
77}
78
mflodman15d83572016-10-06 08:35:11 -070079} // namespace webrtc