blob: 021b11f6f6c21afca28b8dd9ff372ee9def333ca [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "video/encoder_rtcp_feedback.h"
mflodman15d83572016-10-06 08:35:11 -070012
Niels Möller213618e2018-07-24 09:29:58 +020013#include "api/video/video_stream_encoder_interface.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#include "rtc_base/checks.h"
mflodman15d83572016-10-06 08:35:11 -070015
16static const int kMinKeyFrameRequestIntervalMs = 300;
17
18namespace webrtc {
19
20EncoderRtcpFeedback::EncoderRtcpFeedback(Clock* clock,
21 const std::vector<uint32_t>& ssrcs,
Sebastian Jansson652dc912018-04-19 17:09:15 +020022 VideoStreamEncoderInterface* encoder)
mflodman15d83572016-10-06 08:35:11 -070023 : clock_(clock),
24 ssrcs_(ssrcs),
mflodmancc3d4422017-08-03 08:27:51 -070025 video_stream_encoder_(encoder),
Magnus Flodman3c62afd2018-09-24 11:44:49 +020026 time_last_intra_request_ms_(-1) {
mflodman15d83572016-10-06 08:35:11 -070027 RTC_DCHECK(!ssrcs.empty());
28}
29
30bool 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
mflodman15d83572016-10-06 08:35:11 -070039void EncoderRtcpFeedback::OnReceivedIntraFrameRequest(uint32_t ssrc) {
40 RTC_DCHECK(HasSsrc(ssrc));
mflodman15d83572016-10-06 08:35:11 -070041 {
mflodman15d83572016-10-06 08:35:11 -070042 int64_t now_ms = clock_->TimeInMilliseconds();
43 rtc::CritScope lock(&crit_);
Magnus Flodman3c62afd2018-09-24 11:44:49 +020044 if (time_last_intra_request_ms_ + kMinKeyFrameRequestIntervalMs > now_ms) {
mflodman15d83572016-10-06 08:35:11 -070045 return;
46 }
Magnus Flodman3c62afd2018-09-24 11:44:49 +020047 time_last_intra_request_ms_ = now_ms;
mflodman15d83572016-10-06 08:35:11 -070048 }
49
Niels Möller1c9aa1e2018-02-16 10:27:23 +010050 // Always produce key frame for all streams.
51 video_stream_encoder_->SendKeyFrame();
mflodman15d83572016-10-06 08:35:11 -070052}
53
mflodman15d83572016-10-06 08:35:11 -070054} // namespace webrtc