mflodman | 15d8357 | 2016-10-06 08:35:11 -0700 | [diff] [blame] | 1 | /* |
| 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 Alon | 14d1c9d | 2019-04-08 14:16:17 +0200 | [diff] [blame] | 11 | #include "video/encoder_rtcp_feedback.h" |
mflodman | 15d8357 | 2016-10-06 08:35:11 -0700 | [diff] [blame] | 12 | |
Rasmus Brandt | 3dde450 | 2019-03-21 11:46:17 +0100 | [diff] [blame] | 13 | #include "absl/types/optional.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 14 | #include "rtc_base/checks.h" |
Rasmus Brandt | 3dde450 | 2019-03-21 11:46:17 +0100 | [diff] [blame] | 15 | #include "rtc_base/experiments/keyframe_interval_settings.h" |
mflodman | 15d8357 | 2016-10-06 08:35:11 -0700 | [diff] [blame] | 16 | |
| 17 | namespace webrtc { |
| 18 | |
Rasmus Brandt | 3dde450 | 2019-03-21 11:46:17 +0100 | [diff] [blame] | 19 | namespace { |
| 20 | constexpr int kMinKeyframeSendIntervalMs = 300; |
| 21 | } // namespace |
| 22 | |
Elad Alon | 14d1c9d | 2019-04-08 14:16:17 +0200 | [diff] [blame] | 23 | EncoderRtcpFeedback::EncoderRtcpFeedback(Clock* clock, |
| 24 | const std::vector<uint32_t>& ssrcs, |
| 25 | VideoStreamEncoderInterface* encoder) |
mflodman | 15d8357 | 2016-10-06 08:35:11 -0700 | [diff] [blame] | 26 | : clock_(clock), |
| 27 | ssrcs_(ssrcs), |
mflodman | cc3d442 | 2017-08-03 08:27:51 -0700 | [diff] [blame] | 28 | video_stream_encoder_(encoder), |
Rasmus Brandt | 3dde450 | 2019-03-21 11:46:17 +0100 | [diff] [blame] | 29 | time_last_intra_request_ms_(-1), |
| 30 | min_keyframe_send_interval_ms_( |
| 31 | KeyframeIntervalSettings::ParseFromFieldTrials() |
| 32 | .MinKeyframeSendIntervalMs() |
| 33 | .value_or(kMinKeyframeSendIntervalMs)) { |
mflodman | 15d8357 | 2016-10-06 08:35:11 -0700 | [diff] [blame] | 34 | RTC_DCHECK(!ssrcs.empty()); |
| 35 | } |
| 36 | |
Elad Alon | 14d1c9d | 2019-04-08 14:16:17 +0200 | [diff] [blame] | 37 | bool EncoderRtcpFeedback::HasSsrc(uint32_t ssrc) { |
mflodman | 15d8357 | 2016-10-06 08:35:11 -0700 | [diff] [blame] | 38 | for (uint32_t registered_ssrc : ssrcs_) { |
| 39 | if (registered_ssrc == ssrc) { |
| 40 | return true; |
| 41 | } |
| 42 | } |
| 43 | return false; |
| 44 | } |
| 45 | |
Elad Alon | 14d1c9d | 2019-04-08 14:16:17 +0200 | [diff] [blame] | 46 | void EncoderRtcpFeedback::OnReceivedIntraFrameRequest(uint32_t ssrc) { |
mflodman | 15d8357 | 2016-10-06 08:35:11 -0700 | [diff] [blame] | 47 | RTC_DCHECK(HasSsrc(ssrc)); |
mflodman | 15d8357 | 2016-10-06 08:35:11 -0700 | [diff] [blame] | 48 | { |
mflodman | 15d8357 | 2016-10-06 08:35:11 -0700 | [diff] [blame] | 49 | int64_t now_ms = clock_->TimeInMilliseconds(); |
| 50 | rtc::CritScope lock(&crit_); |
Rasmus Brandt | 3dde450 | 2019-03-21 11:46:17 +0100 | [diff] [blame] | 51 | if (time_last_intra_request_ms_ + min_keyframe_send_interval_ms_ > now_ms) { |
mflodman | 15d8357 | 2016-10-06 08:35:11 -0700 | [diff] [blame] | 52 | return; |
| 53 | } |
Magnus Flodman | 3c62afd | 2018-09-24 11:44:49 +0200 | [diff] [blame] | 54 | time_last_intra_request_ms_ = now_ms; |
mflodman | 15d8357 | 2016-10-06 08:35:11 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Niels Möller | 1c9aa1e | 2018-02-16 10:27:23 +0100 | [diff] [blame] | 57 | // Always produce key frame for all streams. |
| 58 | video_stream_encoder_->SendKeyFrame(); |
mflodman | 15d8357 | 2016-10-06 08:35:11 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Elad Alon | 14d1c9d | 2019-04-08 14:16:17 +0200 | [diff] [blame] | 61 | void EncoderRtcpFeedback::OnKeyFrameRequested(uint64_t channel_id) { |
Niels Möller | fa89d84 | 2019-01-30 16:33:45 +0100 | [diff] [blame] | 62 | 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 Alon | 0a8562e | 2019-04-09 11:55:13 +0200 | [diff] [blame^] | 71 | void 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 | |
mflodman | 15d8357 | 2016-10-06 08:35:11 -0700 | [diff] [blame] | 79 | } // namespace webrtc |