Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(634)

Side by Side Diff: webrtc/video/encoder_state_feedback.cc

Issue 1613053003: Swap use of CriticalSectionWrapper for rtc::CriticalSection in webrtc/video. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase? Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/video/encoder_state_feedback.h ('k') | webrtc/video/end_to_end_tests.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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> 13 #include <assert.h>
14 14
15 #include "webrtc/base/checks.h" 15 #include "webrtc/base/checks.h"
16 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" 16 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
17 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
18 #include "webrtc/video/vie_encoder.h" 17 #include "webrtc/video/vie_encoder.h"
19 18
20 namespace webrtc { 19 namespace webrtc {
21 20
22 // Helper class registered at the RTP module relaying callbacks to 21 // Helper class registered at the RTP module relaying callbacks to
23 // EncoderStatFeedback. 22 // EncoderStatFeedback.
24 class EncoderStateFeedbackObserver : public RtcpIntraFrameObserver { 23 class EncoderStateFeedbackObserver : public RtcpIntraFrameObserver {
25 public: 24 public:
26 explicit EncoderStateFeedbackObserver(EncoderStateFeedback* owner) 25 explicit EncoderStateFeedbackObserver(EncoderStateFeedback* owner)
27 : owner_(owner) {} 26 : owner_(owner) {}
(...skipping 12 matching lines...) Expand all
40 39
41 virtual void OnLocalSsrcChanged(uint32_t old_ssrc, uint32_t new_ssrc) { 40 virtual void OnLocalSsrcChanged(uint32_t old_ssrc, uint32_t new_ssrc) {
42 owner_->OnLocalSsrcChanged(old_ssrc, new_ssrc); 41 owner_->OnLocalSsrcChanged(old_ssrc, new_ssrc);
43 } 42 }
44 43
45 private: 44 private:
46 EncoderStateFeedback* owner_; 45 EncoderStateFeedback* owner_;
47 }; 46 };
48 47
49 EncoderStateFeedback::EncoderStateFeedback() 48 EncoderStateFeedback::EncoderStateFeedback()
50 : crit_(CriticalSectionWrapper::CreateCriticalSection()), 49 : observer_(new EncoderStateFeedbackObserver(this)) {}
51 observer_(new EncoderStateFeedbackObserver(this)) {}
52 50
53 EncoderStateFeedback::~EncoderStateFeedback() { 51 EncoderStateFeedback::~EncoderStateFeedback() {
54 assert(encoders_.empty()); 52 assert(encoders_.empty());
55 } 53 }
56 54
57 void EncoderStateFeedback::AddEncoder(const std::vector<uint32_t>& ssrcs, 55 void EncoderStateFeedback::AddEncoder(const std::vector<uint32_t>& ssrcs,
58 ViEEncoder* encoder) { 56 ViEEncoder* encoder) {
59 RTC_DCHECK(!ssrcs.empty()); 57 RTC_DCHECK(!ssrcs.empty());
60 CriticalSectionScoped lock(crit_.get()); 58 rtc::CritScope lock(&crit_);
61 for (uint32_t ssrc : ssrcs) { 59 for (uint32_t ssrc : ssrcs) {
62 RTC_DCHECK(encoders_.find(ssrc) == encoders_.end()); 60 RTC_DCHECK(encoders_.find(ssrc) == encoders_.end());
63 encoders_[ssrc] = encoder; 61 encoders_[ssrc] = encoder;
64 } 62 }
65 } 63 }
66 64
67 void EncoderStateFeedback::RemoveEncoder(const ViEEncoder* encoder) { 65 void EncoderStateFeedback::RemoveEncoder(const ViEEncoder* encoder) {
68 CriticalSectionScoped lock(crit_.get()); 66 rtc::CritScope lock(&crit_);
69 SsrcEncoderMap::iterator it = encoders_.begin(); 67 SsrcEncoderMap::iterator it = encoders_.begin();
70 while (it != encoders_.end()) { 68 while (it != encoders_.end()) {
71 if (it->second == encoder) { 69 if (it->second == encoder) {
72 encoders_.erase(it++); 70 encoders_.erase(it++);
73 } else { 71 } else {
74 ++it; 72 ++it;
75 } 73 }
76 } 74 }
77 } 75 }
78 76
79 RtcpIntraFrameObserver* EncoderStateFeedback::GetRtcpIntraFrameObserver() { 77 RtcpIntraFrameObserver* EncoderStateFeedback::GetRtcpIntraFrameObserver() {
80 return observer_.get(); 78 return observer_.get();
81 } 79 }
82 80
83 void EncoderStateFeedback::OnReceivedIntraFrameRequest(uint32_t ssrc) { 81 void EncoderStateFeedback::OnReceivedIntraFrameRequest(uint32_t ssrc) {
84 CriticalSectionScoped lock(crit_.get()); 82 rtc::CritScope lock(&crit_);
85 SsrcEncoderMap::iterator it = encoders_.find(ssrc); 83 SsrcEncoderMap::iterator it = encoders_.find(ssrc);
86 if (it == encoders_.end()) 84 if (it == encoders_.end())
87 return; 85 return;
88 86
89 it->second->OnReceivedIntraFrameRequest(ssrc); 87 it->second->OnReceivedIntraFrameRequest(ssrc);
90 } 88 }
91 89
92 void EncoderStateFeedback::OnReceivedSLI(uint32_t ssrc, uint8_t picture_id) { 90 void EncoderStateFeedback::OnReceivedSLI(uint32_t ssrc, uint8_t picture_id) {
93 CriticalSectionScoped lock(crit_.get()); 91 rtc::CritScope lock(&crit_);
94 SsrcEncoderMap::iterator it = encoders_.find(ssrc); 92 SsrcEncoderMap::iterator it = encoders_.find(ssrc);
95 if (it == encoders_.end()) 93 if (it == encoders_.end())
96 return; 94 return;
97 95
98 it->second->OnReceivedSLI(ssrc, picture_id); 96 it->second->OnReceivedSLI(ssrc, picture_id);
99 } 97 }
100 98
101 void EncoderStateFeedback::OnReceivedRPSI(uint32_t ssrc, uint64_t picture_id) { 99 void EncoderStateFeedback::OnReceivedRPSI(uint32_t ssrc, uint64_t picture_id) {
102 CriticalSectionScoped lock(crit_.get()); 100 rtc::CritScope lock(&crit_);
103 SsrcEncoderMap::iterator it = encoders_.find(ssrc); 101 SsrcEncoderMap::iterator it = encoders_.find(ssrc);
104 if (it == encoders_.end()) 102 if (it == encoders_.end())
105 return; 103 return;
106 104
107 it->second->OnReceivedRPSI(ssrc, picture_id); 105 it->second->OnReceivedRPSI(ssrc, picture_id);
108 } 106 }
109 107
110 void EncoderStateFeedback::OnLocalSsrcChanged(uint32_t old_ssrc, 108 void EncoderStateFeedback::OnLocalSsrcChanged(uint32_t old_ssrc,
111 uint32_t new_ssrc) { 109 uint32_t new_ssrc) {
112 CriticalSectionScoped lock(crit_.get()); 110 rtc::CritScope lock(&crit_);
113 SsrcEncoderMap::iterator it = encoders_.find(old_ssrc); 111 SsrcEncoderMap::iterator it = encoders_.find(old_ssrc);
114 if (it == encoders_.end() || encoders_.find(new_ssrc) != encoders_.end()) { 112 if (it == encoders_.end() || encoders_.find(new_ssrc) != encoders_.end()) {
115 return; 113 return;
116 } 114 }
117 115
118 ViEEncoder* encoder = it->second; 116 ViEEncoder* encoder = it->second;
119 encoders_.erase(it); 117 encoders_.erase(it);
120 encoders_[new_ssrc] = encoder; 118 encoders_[new_ssrc] = encoder;
121 encoder->OnLocalSsrcChanged(old_ssrc, new_ssrc); 119 encoder->OnLocalSsrcChanged(old_ssrc, new_ssrc);
122 } 120 }
123 121
124 } // namespace webrtc 122 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/encoder_state_feedback.h ('k') | webrtc/video/end_to_end_tests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698