OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/video/encoder_state_feedback.h" | 11 #include "webrtc/video/encoder_state_feedback.h" |
12 | 12 |
13 #include "webrtc/base/checks.h" | 13 #include "webrtc/base/checks.h" |
14 #include "webrtc/video/vie_encoder.h" | 14 #include "webrtc/video/vie_encoder.h" |
15 | 15 |
16 static const int kMinKeyFrameRequestIntervalMs = 300; | |
17 | |
16 namespace webrtc { | 18 namespace webrtc { |
17 | 19 |
18 EncoderStateFeedback::EncoderStateFeedback() : vie_encoder_(nullptr) {} | 20 EncoderStateFeedback::EncoderStateFeedback(Clock* clock) |
21 : clock_(clock), vie_encoder_(nullptr) {} | |
19 | 22 |
20 void EncoderStateFeedback::Init(const std::vector<uint32_t>& ssrcs, | 23 void EncoderStateFeedback::Init(const std::vector<uint32_t>& ssrcs, |
21 ViEEncoder* encoder) { | 24 ViEEncoder* encoder) { |
22 RTC_DCHECK(!ssrcs.empty()); | 25 RTC_DCHECK(!ssrcs.empty()); |
23 rtc::CritScope lock(&crit_); | 26 rtc::CritScope lock(&crit_); |
24 ssrcs_ = ssrcs; | 27 ssrcs_ = ssrcs; |
25 vie_encoder_ = encoder; | 28 vie_encoder_ = encoder; |
29 time_last_intra_request_ms_.resize(ssrcs.size(), 0); | |
pbos-webrtc
2016/05/03 18:19:59
I think -1 is the usual no-timestamp timestamp.
perkj_webrtc
2016/05/04 08:31:03
Done.
| |
26 } | 30 } |
27 | 31 |
28 bool EncoderStateFeedback::HasSsrc(uint32_t ssrc) { | 32 bool EncoderStateFeedback::HasSsrc(uint32_t ssrc) { |
29 for (uint32_t registered_ssrc : ssrcs_) { | 33 for (uint32_t registered_ssrc : ssrcs_) { |
30 if (registered_ssrc == ssrc) | 34 if (registered_ssrc == ssrc) |
31 return true; | 35 return true; |
32 } | 36 } |
33 return false; | 37 return false; |
34 } | 38 } |
35 | 39 |
40 size_t EncoderStateFeedback::GetStreamIndex(uint32_t ssrc) { | |
41 for (size_t i = 0; i < ssrcs_.size(); ++i) { | |
42 if (ssrcs_[i] == ssrc) | |
43 return i; | |
44 } | |
45 RTC_NOTREACHED() << "Unknown ssrc " << ssrc; | |
46 return 0; | |
47 } | |
48 | |
36 void EncoderStateFeedback::OnReceivedIntraFrameRequest(uint32_t ssrc) { | 49 void EncoderStateFeedback::OnReceivedIntraFrameRequest(uint32_t ssrc) { |
37 rtc::CritScope lock(&crit_); | 50 rtc::CritScope lock(&crit_); |
38 if (!HasSsrc(ssrc)) | 51 if (!HasSsrc(ssrc)) |
39 return; | 52 return; |
40 RTC_DCHECK(vie_encoder_); | 53 RTC_DCHECK(vie_encoder_); |
41 | 54 |
42 vie_encoder_->OnReceivedIntraFrameRequest(ssrc); | 55 size_t index = GetStreamIndex(ssrc); |
56 int64_t now_ms = clock_->TimeInMilliseconds(); | |
57 if (time_last_intra_request_ms_[index] + kMinKeyFrameRequestIntervalMs > | |
58 now_ms) { | |
59 return; | |
60 } | |
61 time_last_intra_request_ms_[index] = now_ms; | |
62 | |
63 vie_encoder_->OnReceivedIntraFrameRequest(index); | |
pbos-webrtc
2016/05/03 18:19:59
I think you can drop crit_ during this callback.
perkj_webrtc
2016/05/04 08:31:03
Done.
| |
43 } | 64 } |
44 | 65 |
45 void EncoderStateFeedback::OnReceivedSLI(uint32_t ssrc, uint8_t picture_id) { | 66 void EncoderStateFeedback::OnReceivedSLI(uint32_t ssrc, uint8_t picture_id) { |
46 rtc::CritScope lock(&crit_); | 67 rtc::CritScope lock(&crit_); |
47 if (!HasSsrc(ssrc)) | 68 if (!HasSsrc(ssrc)) |
48 return; | 69 return; |
49 RTC_DCHECK(vie_encoder_); | 70 RTC_DCHECK(vie_encoder_); |
50 | 71 |
51 vie_encoder_->OnReceivedSLI(ssrc, picture_id); | 72 vie_encoder_->OnReceivedSLI(picture_id); |
52 } | 73 } |
53 | 74 |
54 void EncoderStateFeedback::OnReceivedRPSI(uint32_t ssrc, uint64_t picture_id) { | 75 void EncoderStateFeedback::OnReceivedRPSI(uint32_t ssrc, uint64_t picture_id) { |
55 rtc::CritScope lock(&crit_); | 76 rtc::CritScope lock(&crit_); |
56 if (!HasSsrc(ssrc)) | 77 if (!HasSsrc(ssrc)) |
57 return; | 78 return; |
58 RTC_DCHECK(vie_encoder_); | 79 RTC_DCHECK(vie_encoder_); |
59 | 80 |
60 vie_encoder_->OnReceivedRPSI(ssrc, picture_id); | 81 vie_encoder_->OnReceivedRPSI(picture_id); |
61 } | 82 } |
62 | 83 |
63 // Sending SSRCs for this encoder should never change since they are configured | 84 // Sending SSRCs for this encoder should never change since they are configured |
64 // once and not reconfigured. | 85 // once and not reconfigured. |
65 void EncoderStateFeedback::OnLocalSsrcChanged(uint32_t old_ssrc, | 86 void EncoderStateFeedback::OnLocalSsrcChanged(uint32_t old_ssrc, |
66 uint32_t new_ssrc) { | 87 uint32_t new_ssrc) { |
67 if (!RTC_DCHECK_IS_ON) | 88 if (!RTC_DCHECK_IS_ON) |
68 return; | 89 return; |
69 rtc::CritScope lock(&crit_); | 90 rtc::CritScope lock(&crit_); |
70 if (ssrcs_.empty()) // Encoder not yet attached (or detached for teardown). | 91 if (ssrcs_.empty()) // Encoder not yet attached (or detached for teardown). |
71 return; | 92 return; |
72 // SSRC shouldn't change to something we haven't already registered with the | 93 // SSRC shouldn't change to something we haven't already registered with the |
73 // encoder. | 94 // encoder. |
74 RTC_DCHECK(HasSsrc(new_ssrc)); | 95 RTC_DCHECK(HasSsrc(new_ssrc)); |
75 } | 96 } |
76 | 97 |
77 } // namespace webrtc | 98 } // namespace webrtc |
OLD | NEW |