| OLD | NEW |
| (Empty) |
| 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_state_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 EncoderStateFeedback::EncoderStateFeedback(Clock* clock, | |
| 21 const std::vector<uint32_t>& ssrcs, | |
| 22 ViEEncoder* encoder) | |
| 23 : clock_(clock), | |
| 24 ssrcs_(ssrcs), | |
| 25 vie_encoder_(encoder), | |
| 26 time_last_intra_request_ms_(ssrcs.size(), -1) { | |
| 27 RTC_DCHECK(!ssrcs.empty()); | |
| 28 } | |
| 29 | |
| 30 bool EncoderStateFeedback::HasSsrc(uint32_t ssrc) { | |
| 31 for (uint32_t registered_ssrc : ssrcs_) { | |
| 32 if (registered_ssrc == ssrc) | |
| 33 return true; | |
| 34 } | |
| 35 return false; | |
| 36 } | |
| 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 | |
| 47 void EncoderStateFeedback::OnReceivedIntraFrameRequest(uint32_t ssrc) { | |
| 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) { | |
| 66 if (!HasSsrc(ssrc)) | |
| 67 return; | |
| 68 | |
| 69 vie_encoder_->OnReceivedSLI(picture_id); | |
| 70 } | |
| 71 | |
| 72 void EncoderStateFeedback::OnReceivedRPSI(uint32_t ssrc, uint64_t picture_id) { | |
| 73 if (!HasSsrc(ssrc)) | |
| 74 return; | |
| 75 | |
| 76 vie_encoder_->OnReceivedRPSI(picture_id); | |
| 77 } | |
| 78 | |
| 79 // Sending SSRCs for this encoder should never change since they are configured | |
| 80 // once and not reconfigured, however, OnLocalSsrcChanged is called when the | |
| 81 // RtpModules are created with a different SSRC than what will be used in the | |
| 82 // end. | |
| 83 // TODO(perkj): Can we make sure the RTP module is created with the right SSRC | |
| 84 // from the beginning so this method is not triggered during creation ? | |
| 85 void EncoderStateFeedback::OnLocalSsrcChanged(uint32_t old_ssrc, | |
| 86 uint32_t new_ssrc) { | |
| 87 if (!RTC_DCHECK_IS_ON) | |
| 88 return; | |
| 89 | |
| 90 if (old_ssrc == 0) // old_ssrc == 0 during creation. | |
| 91 return; | |
| 92 // SSRC shouldn't change to something we haven't already registered with the | |
| 93 // encoder. | |
| 94 RTC_DCHECK(HasSsrc(new_ssrc)); | |
| 95 } | |
| 96 | |
| 97 } // namespace webrtc | |
| OLD | NEW |