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, |
19 | 21 const std::vector<uint32_t>& ssrcs, |
20 void EncoderStateFeedback::Init(const std::vector<uint32_t>& ssrcs, | 22 ViEEncoder* encoder) |
21 ViEEncoder* encoder) { | 23 : clock_(clock), |
24 ssrcs_(ssrcs), | |
25 vie_encoder_(encoder), | |
26 time_last_intra_request_ms_(ssrcs.size(), -1) { | |
22 RTC_DCHECK(!ssrcs.empty()); | 27 RTC_DCHECK(!ssrcs.empty()); |
23 rtc::CritScope lock(&crit_); | |
24 ssrcs_ = ssrcs; | |
25 vie_encoder_ = encoder; | |
26 } | 28 } |
27 | 29 |
28 bool EncoderStateFeedback::HasSsrc(uint32_t ssrc) { | 30 bool EncoderStateFeedback::HasSsrc(uint32_t ssrc) { |
29 for (uint32_t registered_ssrc : ssrcs_) { | 31 for (uint32_t registered_ssrc : ssrcs_) { |
30 if (registered_ssrc == ssrc) | 32 if (registered_ssrc == ssrc) |
31 return true; | 33 return true; |
32 } | 34 } |
33 return false; | 35 return false; |
34 } | 36 } |
35 | 37 |
38 size_t EncoderStateFeedback::GetStreamIndex(uint32_t ssrc) { | |
39 for (size_t i = 0; i < ssrcs_.size(); ++i) { | |
40 if (ssrcs_[i] == ssrc) | |
41 return i; | |
42 } | |
43 RTC_NOTREACHED() << "Unknown ssrc " << ssrc; | |
44 return 0; | |
45 } | |
46 | |
36 void EncoderStateFeedback::OnReceivedIntraFrameRequest(uint32_t ssrc) { | 47 void EncoderStateFeedback::OnReceivedIntraFrameRequest(uint32_t ssrc) { |
37 rtc::CritScope lock(&crit_); | 48 if (!HasSsrc(ssrc)) |
49 return; | |
50 | |
51 size_t index = GetStreamIndex(ssrc); | |
52 { | |
53 int64_t now_ms = clock_->TimeInMilliseconds(); | |
54 rtc::CritScope lock(&crit_); | |
55 if (time_last_intra_request_ms_[index] + kMinKeyFrameRequestIntervalMs > | |
56 now_ms) { | |
57 return; | |
58 } | |
59 time_last_intra_request_ms_[index] = now_ms; | |
60 } | |
61 | |
62 vie_encoder_->OnReceivedIntraFrameRequest(index); | |
63 } | |
64 | |
65 void EncoderStateFeedback::OnReceivedSLI(uint32_t ssrc, uint8_t picture_id) { | |
38 if (!HasSsrc(ssrc)) | 66 if (!HasSsrc(ssrc)) |
39 return; | 67 return; |
40 RTC_DCHECK(vie_encoder_); | 68 RTC_DCHECK(vie_encoder_); |
pbos-webrtc
2016/05/04 14:10:36
Remove all of these DCHECKs, if you want them keep
perkj_webrtc
2016/05/04 15:25:38
Done.
| |
41 | 69 |
42 vie_encoder_->OnReceivedIntraFrameRequest(ssrc); | 70 vie_encoder_->OnReceivedSLI(picture_id); |
43 } | 71 } |
44 | 72 |
45 void EncoderStateFeedback::OnReceivedSLI(uint32_t ssrc, uint8_t picture_id) { | 73 void EncoderStateFeedback::OnReceivedRPSI(uint32_t ssrc, uint64_t picture_id) { |
46 rtc::CritScope lock(&crit_); | |
47 if (!HasSsrc(ssrc)) | 74 if (!HasSsrc(ssrc)) |
48 return; | 75 return; |
49 RTC_DCHECK(vie_encoder_); | 76 RTC_DCHECK(vie_encoder_); |
50 | 77 |
51 vie_encoder_->OnReceivedSLI(ssrc, picture_id); | 78 vie_encoder_->OnReceivedRPSI(picture_id); |
52 } | |
53 | |
54 void EncoderStateFeedback::OnReceivedRPSI(uint32_t ssrc, uint64_t picture_id) { | |
55 rtc::CritScope lock(&crit_); | |
56 if (!HasSsrc(ssrc)) | |
57 return; | |
58 RTC_DCHECK(vie_encoder_); | |
59 | |
60 vie_encoder_->OnReceivedRPSI(ssrc, picture_id); | |
61 } | 79 } |
62 | 80 |
63 // Sending SSRCs for this encoder should never change since they are configured | 81 // Sending SSRCs for this encoder should never change since they are configured |
64 // once and not reconfigured. | 82 // once and not reconfigured, however, OnLocalSsrcChanged is called when the |
83 // RtpModules are created with a different SSRC than what will be used in the | |
84 // end. | |
85 // TODO(perkj): Can we make sure the RTP module is created with the right SSRC | |
86 // from the beginning so this method is not triggered during creation ? | |
65 void EncoderStateFeedback::OnLocalSsrcChanged(uint32_t old_ssrc, | 87 void EncoderStateFeedback::OnLocalSsrcChanged(uint32_t old_ssrc, |
66 uint32_t new_ssrc) { | 88 uint32_t new_ssrc) { |
67 if (!RTC_DCHECK_IS_ON) | 89 if (!RTC_DCHECK_IS_ON) |
68 return; | 90 return; |
69 rtc::CritScope lock(&crit_); | 91 |
70 if (ssrcs_.empty()) // Encoder not yet attached (or detached for teardown). | 92 if (old_ssrc == 0) // old_ssrc == 0 during creation. |
71 return; | 93 return; |
72 // SSRC shouldn't change to something we haven't already registered with the | 94 // SSRC shouldn't change to something we haven't already registered with the |
73 // encoder. | 95 // encoder. |
74 RTC_DCHECK(HasSsrc(new_ssrc)); | 96 RTC_DCHECK(HasSsrc(new_ssrc)); |
75 } | 97 } |
76 | 98 |
77 } // namespace webrtc | 99 } // namespace webrtc |
OLD | NEW |