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

Side by Side Diff: webrtc/modules/video_coding/main/source/generic_encoder.cc

Issue 1426953003: Remove redudant encoder rate calls. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 1 month 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
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
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 } // namespace 87 } // namespace
88 88
89 //#define DEBUG_ENCODER_BIT_STREAM 89 //#define DEBUG_ENCODER_BIT_STREAM
90 90
91 VCMGenericEncoder::VCMGenericEncoder(VideoEncoder* encoder, 91 VCMGenericEncoder::VCMGenericEncoder(VideoEncoder* encoder,
92 VideoEncoderRateObserver* rate_observer, 92 VideoEncoderRateObserver* rate_observer,
93 bool internalSource) 93 bool internalSource)
94 : encoder_(encoder), 94 : encoder_(encoder),
95 rate_observer_(rate_observer), 95 rate_observer_(rate_observer),
96 vcm_encoded_frame_callback_(nullptr), 96 vcm_encoded_frame_callback_(nullptr),
97 bit_rate_(0), 97 encoder_params_({0,0,0,0}),
stefan-webrtc 2015/10/29 14:12:06 spaces between elements.
pbos-webrtc 2015/10/29 14:37:33 cl-format done.
98 frame_rate_(0),
99 internal_source_(internalSource), 98 internal_source_(internalSource),
100 rotation_(kVideoRotation_0), 99 rotation_(kVideoRotation_0),
101 is_screenshare_(false) { 100 is_screenshare_(false) {
102 } 101 }
103 102
104 VCMGenericEncoder::~VCMGenericEncoder() 103 VCMGenericEncoder::~VCMGenericEncoder()
105 { 104 {
106 } 105 }
107 106
108 int32_t VCMGenericEncoder::Release() 107 int32_t VCMGenericEncoder::Release()
109 { 108 {
110 { 109 {
111 rtc::CritScope lock(&rates_lock_); 110 rtc::CritScope lock(&params_lock_);
112 bit_rate_ = 0; 111 encoder_params_ = {0, 0, 0, 0};
113 frame_rate_ = 0;
114 vcm_encoded_frame_callback_ = nullptr; 112 vcm_encoded_frame_callback_ = nullptr;
115 } 113 }
116 114
117 return encoder_->Release(); 115 return encoder_->Release();
118 } 116 }
119 117
120 int32_t 118 int32_t
121 VCMGenericEncoder::InitEncode(const VideoCodec* settings, 119 VCMGenericEncoder::InitEncode(const VideoCodec* settings,
122 int32_t numberOfCores, 120 int32_t numberOfCores,
123 size_t maxPayloadSize) 121 size_t maxPayloadSize)
124 { 122 {
125 { 123 {
126 rtc::CritScope lock(&rates_lock_); 124 rtc::CritScope lock(&params_lock_);
127 bit_rate_ = settings->startBitrate * 1000; 125 encoder_params_.target_bitrate = settings->startBitrate * 1000;
128 frame_rate_ = settings->maxFramerate; 126 encoder_params_.input_frame_rate = settings->maxFramerate;
129 } 127 }
130 128
131 is_screenshare_ = settings->mode == VideoCodecMode::kScreensharing; 129 is_screenshare_ = settings->mode == VideoCodecMode::kScreensharing;
132 if (encoder_->InitEncode(settings, numberOfCores, maxPayloadSize) != 0) { 130 if (encoder_->InitEncode(settings, numberOfCores, maxPayloadSize) != 0) {
133 LOG(LS_ERROR) << "Failed to initialize the encoder associated with " 131 LOG(LS_ERROR) << "Failed to initialize the encoder associated with "
134 "payload name: " << settings->plName; 132 "payload name: " << settings->plName;
135 return -1; 133 return -1;
136 } 134 }
137 return 0; 135 return 0;
138 } 136 }
(...skipping 16 matching lines...) Expand all
155 int32_t result = encoder_->Encode(inputFrame, codecSpecificInfo, &frameTypes); 153 int32_t result = encoder_->Encode(inputFrame, codecSpecificInfo, &frameTypes);
156 if (is_screenshare_ && 154 if (is_screenshare_ &&
157 result == WEBRTC_VIDEO_CODEC_TARGET_BITRATE_OVERSHOOT) { 155 result == WEBRTC_VIDEO_CODEC_TARGET_BITRATE_OVERSHOOT) {
158 // Target bitrate exceeded, encoder state has been reset - try again. 156 // Target bitrate exceeded, encoder state has been reset - try again.
159 return encoder_->Encode(inputFrame, codecSpecificInfo, &frameTypes); 157 return encoder_->Encode(inputFrame, codecSpecificInfo, &frameTypes);
160 } 158 }
161 159
162 return result; 160 return result;
163 } 161 }
164 162
165 int32_t 163 void VCMGenericEncoder::SetEncoderParameters(const EncoderParameters& params) {
166 VCMGenericEncoder::SetChannelParameters(int32_t packetLoss, int64_t rtt) 164 bool channel_parameters_have_changed;
167 { 165 bool rates_have_changed;
168 return encoder_->SetChannelParameters(packetLoss, rtt); 166 {
167 rtc::CritScope lock(&params_lock_);
168 channel_parameters_have_changed =
169 params.loss_rate != encoder_params_.loss_rate ||
170 params.rtt != encoder_params_.rtt;
171 rates_have_changed =
172 params.target_bitrate != encoder_params_.target_bitrate ||
173 params.input_frame_rate != encoder_params_.input_frame_rate;
174 encoder_params_ = params;
175 }
176 if (channel_parameters_have_changed)
177 encoder_->SetChannelParameters(params.loss_rate, params.rtt);
178 if (rates_have_changed) {
179 uint32_t target_bitrate_kbps = (params.target_bitrate + 500) / 1000;
180 encoder_->SetRates(target_bitrate_kbps, params.input_frame_rate);
181 if (rate_observer_ != nullptr) {
182 rate_observer_->OnSetRates(params.target_bitrate,
183 params.input_frame_rate);
184 }
185 }
186 }
187
188 uint32_t VCMGenericEncoder::BitRate() const {
189 rtc::CritScope lock(&params_lock_);
190 return encoder_params_.target_bitrate;
191 }
192
193 uint32_t VCMGenericEncoder::FrameRate() const {
194 rtc::CritScope lock(&params_lock_);
195 return encoder_params_.input_frame_rate;
169 } 196 }
170 197
171 int32_t 198 int32_t
172 VCMGenericEncoder::SetRates(uint32_t newBitRate, uint32_t frameRate)
173 {
174 uint32_t target_bitrate_kbps = (newBitRate + 500) / 1000;
175 int32_t ret = encoder_->SetRates(target_bitrate_kbps, frameRate);
176 if (ret < 0)
177 {
178 return ret;
179 }
180
181 {
182 rtc::CritScope lock(&rates_lock_);
183 bit_rate_ = newBitRate;
184 frame_rate_ = frameRate;
185 }
186
187 if (rate_observer_ != nullptr)
188 rate_observer_->OnSetRates(newBitRate, frameRate);
189 return VCM_OK;
190 }
191
192 int32_t
193 VCMGenericEncoder::CodecConfigParameters(uint8_t* buffer, int32_t size)
194 {
195 int32_t ret = encoder_->CodecConfigParameters(buffer, size);
196 if (ret < 0)
197 {
198 return ret;
199 }
200 return ret;
201 }
202
203 uint32_t VCMGenericEncoder::BitRate() const
204 {
205 rtc::CritScope lock(&rates_lock_);
206 return bit_rate_;
207 }
208
209 uint32_t VCMGenericEncoder::FrameRate() const
210 {
211 rtc::CritScope lock(&rates_lock_);
212 return frame_rate_;
213 }
214
215 int32_t
216 VCMGenericEncoder::SetPeriodicKeyFrames(bool enable) 199 VCMGenericEncoder::SetPeriodicKeyFrames(bool enable)
217 { 200 {
218 return encoder_->SetPeriodicKeyFrames(enable); 201 return encoder_->SetPeriodicKeyFrames(enable);
219 } 202 }
220 203
221 int32_t VCMGenericEncoder::RequestFrame( 204 int32_t VCMGenericEncoder::RequestFrame(
222 const std::vector<FrameType>& frame_types) { 205 const std::vector<FrameType>& frame_types) {
223 VideoFrame image; 206 VideoFrame image;
224 return encoder_->Encode(image, NULL, &frame_types); 207 return encoder_->Encode(image, NULL, &frame_types);
225 } 208 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 } 310 }
328 311
329 void 312 void
330 VCMEncodedFrameCallback::SetMediaOpt( 313 VCMEncodedFrameCallback::SetMediaOpt(
331 media_optimization::MediaOptimization *mediaOpt) 314 media_optimization::MediaOptimization *mediaOpt)
332 { 315 {
333 _mediaOpt = mediaOpt; 316 _mediaOpt = mediaOpt;
334 } 317 }
335 318
336 } // namespace webrtc 319 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698