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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "video/encoder_rtcp_feedback.h" |
mflodman | 15d8357 | 2016-10-06 08:35:11 -0700 | [diff] [blame] | 12 | |
Niels Möller | 213618e | 2018-07-24 09:29:58 +0200 | [diff] [blame] | 13 | #include "api/video/video_stream_encoder_interface.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 14 | #include "rtc_base/checks.h" |
mflodman | 15d8357 | 2016-10-06 08:35:11 -0700 | [diff] [blame] | 15 | |
| 16 | static const int kMinKeyFrameRequestIntervalMs = 300; |
| 17 | |
| 18 | namespace webrtc { |
| 19 | |
| 20 | EncoderRtcpFeedback::EncoderRtcpFeedback(Clock* clock, |
| 21 | const std::vector<uint32_t>& ssrcs, |
Sebastian Jansson | 652dc91 | 2018-04-19 17:09:15 +0200 | [diff] [blame] | 22 | VideoStreamEncoderInterface* encoder) |
mflodman | 15d8357 | 2016-10-06 08:35:11 -0700 | [diff] [blame] | 23 | : clock_(clock), |
| 24 | ssrcs_(ssrcs), |
mflodman | cc3d442 | 2017-08-03 08:27:51 -0700 | [diff] [blame] | 25 | video_stream_encoder_(encoder), |
Magnus Flodman | 3c62afd | 2018-09-24 11:44:49 +0200 | [diff] [blame] | 26 | time_last_intra_request_ms_(-1) { |
mflodman | 15d8357 | 2016-10-06 08:35:11 -0700 | [diff] [blame] | 27 | RTC_DCHECK(!ssrcs.empty()); |
| 28 | } |
| 29 | |
| 30 | bool EncoderRtcpFeedback::HasSsrc(uint32_t ssrc) { |
| 31 | for (uint32_t registered_ssrc : ssrcs_) { |
| 32 | if (registered_ssrc == ssrc) { |
| 33 | return true; |
| 34 | } |
| 35 | } |
| 36 | return false; |
| 37 | } |
| 38 | |
mflodman | 15d8357 | 2016-10-06 08:35:11 -0700 | [diff] [blame] | 39 | void EncoderRtcpFeedback::OnReceivedIntraFrameRequest(uint32_t ssrc) { |
| 40 | RTC_DCHECK(HasSsrc(ssrc)); |
mflodman | 15d8357 | 2016-10-06 08:35:11 -0700 | [diff] [blame] | 41 | { |
mflodman | 15d8357 | 2016-10-06 08:35:11 -0700 | [diff] [blame] | 42 | int64_t now_ms = clock_->TimeInMilliseconds(); |
| 43 | rtc::CritScope lock(&crit_); |
Magnus Flodman | 3c62afd | 2018-09-24 11:44:49 +0200 | [diff] [blame] | 44 | if (time_last_intra_request_ms_ + kMinKeyFrameRequestIntervalMs > now_ms) { |
mflodman | 15d8357 | 2016-10-06 08:35:11 -0700 | [diff] [blame] | 45 | return; |
| 46 | } |
Magnus Flodman | 3c62afd | 2018-09-24 11:44:49 +0200 | [diff] [blame] | 47 | time_last_intra_request_ms_ = now_ms; |
mflodman | 15d8357 | 2016-10-06 08:35:11 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Niels Möller | 1c9aa1e | 2018-02-16 10:27:23 +0100 | [diff] [blame] | 50 | // Always produce key frame for all streams. |
| 51 | video_stream_encoder_->SendKeyFrame(); |
mflodman | 15d8357 | 2016-10-06 08:35:11 -0700 | [diff] [blame] | 52 | } |
| 53 | |
mflodman | 15d8357 | 2016-10-06 08:35:11 -0700 | [diff] [blame] | 54 | } // namespace webrtc |