Chromium Code Reviews| 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 <assert.h> | |
| 14 | |
| 15 #include "webrtc/base/checks.h" | 13 #include "webrtc/base/checks.h" |
| 16 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 14 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
|
danilchap
2016/02/17 16:14:00
included in webrtc/video/encoder_state_feedback.h
pbos-webrtc
2016/02/18 16:00:29
Done.
| |
| 17 #include "webrtc/video/vie_encoder.h" | 15 #include "webrtc/video/vie_encoder.h" |
| 18 | 16 |
| 19 namespace webrtc { | 17 namespace webrtc { |
| 20 | 18 |
| 21 // Helper class registered at the RTP module relaying callbacks to | 19 EncoderStateFeedback::EncoderStateFeedback() : vie_encoder_(nullptr) {} |
| 22 // EncoderStatFeedback. | |
| 23 class EncoderStateFeedbackObserver : public RtcpIntraFrameObserver { | |
| 24 public: | |
| 25 explicit EncoderStateFeedbackObserver(EncoderStateFeedback* owner) | |
| 26 : owner_(owner) {} | |
| 27 ~EncoderStateFeedbackObserver() {} | |
| 28 | 20 |
| 29 // Implements RtcpIntraFrameObserver. | 21 void EncoderStateFeedback::Init(const std::vector<uint32_t>& ssrcs, |
| 30 virtual void OnReceivedIntraFrameRequest(uint32_t ssrc) { | 22 ViEEncoder* encoder) { |
| 31 owner_->OnReceivedIntraFrameRequest(ssrc); | 23 RTC_DCHECK(!ssrcs.empty()); |
| 32 } | 24 rtc::CritScope lock(&crit_); |
| 33 virtual void OnReceivedSLI(uint32_t ssrc, uint8_t picture_id) { | 25 ssrcs_ = ssrcs; |
| 34 owner_->OnReceivedSLI(ssrc, picture_id); | 26 vie_encoder_ = encoder; |
| 35 } | |
| 36 virtual void OnReceivedRPSI(uint32_t ssrc, uint64_t picture_id) { | |
| 37 owner_->OnReceivedRPSI(ssrc, picture_id); | |
| 38 } | |
| 39 | |
| 40 virtual void OnLocalSsrcChanged(uint32_t old_ssrc, uint32_t new_ssrc) { | |
| 41 owner_->OnLocalSsrcChanged(old_ssrc, new_ssrc); | |
| 42 } | |
| 43 | |
| 44 private: | |
| 45 EncoderStateFeedback* owner_; | |
| 46 }; | |
| 47 | |
| 48 EncoderStateFeedback::EncoderStateFeedback() | |
| 49 : observer_(new EncoderStateFeedbackObserver(this)) {} | |
| 50 | |
| 51 EncoderStateFeedback::~EncoderStateFeedback() { | |
| 52 assert(encoders_.empty()); | |
| 53 } | 27 } |
| 54 | 28 |
| 55 void EncoderStateFeedback::AddEncoder(const std::vector<uint32_t>& ssrcs, | 29 void EncoderStateFeedback::TearDown() { |
| 56 ViEEncoder* encoder) { | |
| 57 RTC_DCHECK(!ssrcs.empty()); | |
| 58 rtc::CritScope lock(&crit_); | 30 rtc::CritScope lock(&crit_); |
| 59 for (uint32_t ssrc : ssrcs) { | 31 RTC_DCHECK(vie_encoder_); |
| 60 RTC_DCHECK(encoders_.find(ssrc) == encoders_.end()); | 32 ssrcs_.clear(); |
| 61 encoders_[ssrc] = encoder; | 33 vie_encoder_ = nullptr; |
| 62 } | |
| 63 } | 34 } |
| 64 | 35 |
| 65 void EncoderStateFeedback::RemoveEncoder(const ViEEncoder* encoder) { | 36 bool EncoderStateFeedback::HasSsrc(uint32_t ssrc) { |
| 66 rtc::CritScope lock(&crit_); | 37 for (uint32_t registered_ssrc : ssrcs_) { |
| 67 SsrcEncoderMap::iterator it = encoders_.begin(); | 38 if (registered_ssrc == ssrc) |
| 68 while (it != encoders_.end()) { | 39 return true; |
| 69 if (it->second == encoder) { | |
| 70 encoders_.erase(it++); | |
| 71 } else { | |
| 72 ++it; | |
| 73 } | |
| 74 } | 40 } |
| 75 } | 41 return false; |
| 76 | |
| 77 RtcpIntraFrameObserver* EncoderStateFeedback::GetRtcpIntraFrameObserver() { | |
| 78 return observer_.get(); | |
| 79 } | 42 } |
| 80 | 43 |
| 81 void EncoderStateFeedback::OnReceivedIntraFrameRequest(uint32_t ssrc) { | 44 void EncoderStateFeedback::OnReceivedIntraFrameRequest(uint32_t ssrc) { |
| 82 rtc::CritScope lock(&crit_); | 45 rtc::CritScope lock(&crit_); |
| 83 SsrcEncoderMap::iterator it = encoders_.find(ssrc); | 46 if (!HasSsrc(ssrc)) |
| 84 if (it == encoders_.end()) | |
| 85 return; | 47 return; |
| 48 RTC_DCHECK(vie_encoder_); | |
| 86 | 49 |
| 87 it->second->OnReceivedIntraFrameRequest(ssrc); | 50 vie_encoder_->OnReceivedIntraFrameRequest(ssrc); |
| 88 } | 51 } |
| 89 | 52 |
| 90 void EncoderStateFeedback::OnReceivedSLI(uint32_t ssrc, uint8_t picture_id) { | 53 void EncoderStateFeedback::OnReceivedSLI(uint32_t ssrc, uint8_t picture_id) { |
| 91 rtc::CritScope lock(&crit_); | 54 rtc::CritScope lock(&crit_); |
| 92 SsrcEncoderMap::iterator it = encoders_.find(ssrc); | 55 if (!HasSsrc(ssrc)) |
| 93 if (it == encoders_.end()) | |
| 94 return; | 56 return; |
| 57 RTC_DCHECK(vie_encoder_); | |
| 95 | 58 |
| 96 it->second->OnReceivedSLI(ssrc, picture_id); | 59 vie_encoder_->OnReceivedSLI(ssrc, picture_id); |
| 97 } | 60 } |
| 98 | 61 |
| 99 void EncoderStateFeedback::OnReceivedRPSI(uint32_t ssrc, uint64_t picture_id) { | 62 void EncoderStateFeedback::OnReceivedRPSI(uint32_t ssrc, uint64_t picture_id) { |
| 100 rtc::CritScope lock(&crit_); | 63 rtc::CritScope lock(&crit_); |
| 101 SsrcEncoderMap::iterator it = encoders_.find(ssrc); | 64 if (!HasSsrc(ssrc)) |
| 102 if (it == encoders_.end()) | |
| 103 return; | 65 return; |
| 66 RTC_DCHECK(vie_encoder_); | |
| 104 | 67 |
| 105 it->second->OnReceivedRPSI(ssrc, picture_id); | 68 vie_encoder_->OnReceivedRPSI(ssrc, picture_id); |
| 106 } | 69 } |
| 107 | 70 |
| 108 void EncoderStateFeedback::OnLocalSsrcChanged(uint32_t old_ssrc, | 71 void EncoderStateFeedback::OnLocalSsrcChanged(uint32_t old_ssrc, |
| 109 uint32_t new_ssrc) { | 72 uint32_t new_ssrc) { |
| 110 rtc::CritScope lock(&crit_); | 73 // Unused since all SSRCs are set in Init and filtered outside. |
|
danilchap
2016/02/17 16:14:00
Can't see how Init is related to ssrc change.
this
| |
| 111 SsrcEncoderMap::iterator it = encoders_.find(old_ssrc); | |
| 112 if (it == encoders_.end() || encoders_.find(new_ssrc) != encoders_.end()) { | |
| 113 return; | |
| 114 } | |
| 115 | |
| 116 ViEEncoder* encoder = it->second; | |
| 117 encoders_.erase(it); | |
| 118 encoders_[new_ssrc] = encoder; | |
| 119 encoder->OnLocalSsrcChanged(old_ssrc, new_ssrc); | |
| 120 } | 74 } |
| 121 | 75 |
| 122 } // namespace webrtc | 76 } // namespace webrtc |
| OLD | NEW |