Line data Source code
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 :
11 : #include "webrtc/video/encoder_rtcp_feedback.h"
12 :
13 : #include "webrtc/base/checks.h"
14 : #include "webrtc/video/vie_encoder.h"
15 :
16 : static const int kMinKeyFrameRequestIntervalMs = 300;
17 :
18 : namespace webrtc {
19 :
20 0 : EncoderRtcpFeedback::EncoderRtcpFeedback(Clock* clock,
21 : const std::vector<uint32_t>& ssrcs,
22 0 : ViEEncoder* encoder)
23 : : clock_(clock),
24 : ssrcs_(ssrcs),
25 : vie_encoder_(encoder),
26 0 : time_last_intra_request_ms_(ssrcs.size(), -1) {
27 0 : RTC_DCHECK(!ssrcs.empty());
28 0 : }
29 :
30 0 : bool EncoderRtcpFeedback::HasSsrc(uint32_t ssrc) {
31 0 : for (uint32_t registered_ssrc : ssrcs_) {
32 0 : if (registered_ssrc == ssrc) {
33 0 : return true;
34 : }
35 : }
36 0 : return false;
37 : }
38 :
39 0 : size_t EncoderRtcpFeedback::GetStreamIndex(uint32_t ssrc) {
40 0 : for (size_t i = 0; i < ssrcs_.size(); ++i) {
41 0 : if (ssrcs_[i] == ssrc)
42 0 : return i;
43 : }
44 0 : RTC_NOTREACHED() << "Unknown ssrc " << ssrc;
45 0 : return 0;
46 : }
47 :
48 0 : void EncoderRtcpFeedback::OnReceivedIntraFrameRequest(uint32_t ssrc) {
49 0 : RTC_DCHECK(HasSsrc(ssrc));
50 0 : size_t index = GetStreamIndex(ssrc);
51 : {
52 : // TODO(mflodman): Move to ViEEncoder after some more changes making it
53 : // easier to test there.
54 0 : int64_t now_ms = clock_->TimeInMilliseconds();
55 0 : rtc::CritScope lock(&crit_);
56 0 : if (time_last_intra_request_ms_[index] + kMinKeyFrameRequestIntervalMs >
57 : now_ms) {
58 0 : return;
59 : }
60 0 : time_last_intra_request_ms_[index] = now_ms;
61 : }
62 :
63 0 : vie_encoder_->OnReceivedIntraFrameRequest(index);
64 : }
65 :
66 0 : void EncoderRtcpFeedback::OnReceivedSLI(uint32_t ssrc, uint8_t picture_id) {
67 0 : RTC_DCHECK(HasSsrc(ssrc));
68 :
69 0 : vie_encoder_->OnReceivedSLI(picture_id);
70 0 : }
71 :
72 0 : void EncoderRtcpFeedback::OnReceivedRPSI(uint32_t ssrc, uint64_t picture_id) {
73 0 : RTC_DCHECK(HasSsrc(ssrc));
74 :
75 0 : vie_encoder_->OnReceivedRPSI(picture_id);
76 0 : }
77 : } // namespace webrtc
|