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

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

Issue 1751363003: Move all calls after SetEncoder into SetEncoder. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 9 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/vie_encoder.h ('k') | no next file » | 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
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 this, 113 this,
114 qm_callback_.get())), 114 qm_callback_.get())),
115 stats_proxy_(stats_proxy), 115 stats_proxy_(stats_proxy),
116 pre_encode_callback_(pre_encode_callback), 116 pre_encode_callback_(pre_encode_callback),
117 overuse_detector_(overuse_detector), 117 overuse_detector_(overuse_detector),
118 pacer_(pacer), 118 pacer_(pacer),
119 send_payload_router_(payload_router), 119 send_payload_router_(payload_router),
120 bitrate_allocator_(bitrate_allocator), 120 bitrate_allocator_(bitrate_allocator),
121 time_of_last_frame_activity_ms_(0), 121 time_of_last_frame_activity_ms_(0),
122 encoder_config_(), 122 encoder_config_(),
123 min_transmit_bitrate_kbps_(0), 123 min_transmit_bitrate_bps_(0),
124 last_observed_bitrate_bps_(0), 124 last_observed_bitrate_bps_(0),
125 network_is_transmitting_(true), 125 network_is_transmitting_(true),
126 encoder_paused_(false), 126 encoder_paused_(false),
127 encoder_paused_and_dropped_frame_(false), 127 encoder_paused_and_dropped_frame_(false),
128 time_last_intra_request_ms_(ssrcs.size(), -1), 128 time_last_intra_request_ms_(ssrcs.size(), -1),
129 module_process_thread_(module_process_thread), 129 module_process_thread_(module_process_thread),
130 has_received_sli_(false), 130 has_received_sli_(false),
131 picture_id_sli_(0), 131 picture_id_sli_(0),
132 has_received_rpsi_(false), 132 has_received_rpsi_(false),
133 picture_id_rpsi_(0), 133 picture_id_rpsi_(0),
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 } 187 }
188 return 0; 188 return 0;
189 } 189 }
190 190
191 int32_t ViEEncoder::DeRegisterExternalEncoder(uint8_t pl_type) { 191 int32_t ViEEncoder::DeRegisterExternalEncoder(uint8_t pl_type) {
192 if (vcm_->RegisterExternalEncoder(NULL, pl_type) != VCM_OK) { 192 if (vcm_->RegisterExternalEncoder(NULL, pl_type) != VCM_OK) {
193 return -1; 193 return -1;
194 } 194 }
195 return 0; 195 return 0;
196 } 196 }
197 void ViEEncoder::SetEncoder(const webrtc::VideoCodec& video_codec) { 197 void ViEEncoder::SetEncoder(const webrtc::VideoCodec& video_codec,
198 int min_transmit_bitrate_bps) {
198 RTC_DCHECK(send_payload_router_ != NULL); 199 RTC_DCHECK(send_payload_router_ != NULL);
199 // Setting target width and height for VPM. 200 // Setting target width and height for VPM.
200 RTC_CHECK_EQ(VPM_OK, 201 RTC_CHECK_EQ(VPM_OK,
201 vp_->SetTargetResolution(video_codec.width, video_codec.height, 202 vp_->SetTargetResolution(video_codec.width, video_codec.height,
202 video_codec.maxFramerate)); 203 video_codec.maxFramerate));
203 204
204 // Cache codec before calling AddBitrateObserver (which calls OnNetworkChanged 205 // Cache codec before calling AddBitrateObserver (which calls OnNetworkChanged
205 // that makes use of the number of simulcast streams configured). 206 // that makes use of the number of simulcast streams configured).
206 { 207 {
207 rtc::CritScope lock(&data_cs_); 208 rtc::CritScope lock(&data_cs_);
208 encoder_config_ = video_codec; 209 encoder_config_ = video_codec;
209 encoder_paused_ = true; 210 encoder_paused_ = true;
211 min_transmit_bitrate_bps_ = min_transmit_bitrate_bps;
210 } 212 }
211 213
212 // Add a bitrate observer to the allocator and update the start, max and 214 // Add a bitrate observer to the allocator and update the start, max and
213 // min bitrates of the bitrate controller as needed. 215 // min bitrates of the bitrate controller as needed.
214 int allocated_bitrate_bps = bitrate_allocator_->AddBitrateObserver( 216 int allocated_bitrate_bps = bitrate_allocator_->AddBitrateObserver(
215 bitrate_observer_.get(), video_codec.minBitrate * 1000, 217 bitrate_observer_.get(), video_codec.minBitrate * 1000,
216 video_codec.maxBitrate * 1000); 218 video_codec.maxBitrate * 1000);
217 219
218 webrtc::VideoCodec modified_video_codec = video_codec; 220 webrtc::VideoCodec modified_video_codec = video_codec;
219 modified_video_codec.startBitrate = allocated_bitrate_bps / 1000; 221 modified_video_codec.startBitrate = allocated_bitrate_bps / 1000;
220 222
221 size_t max_data_payload_length = send_payload_router_->MaxPayloadLength(); 223 size_t max_data_payload_length = send_payload_router_->MaxPayloadLength();
222 bool success = vcm_->RegisterSendCodec( 224 bool success = vcm_->RegisterSendCodec(
223 &modified_video_codec, number_of_cores_, 225 &modified_video_codec, number_of_cores_,
224 static_cast<uint32_t>(max_data_payload_length)) == VCM_OK; 226 static_cast<uint32_t>(max_data_payload_length)) == VCM_OK;
225 if (!success) { 227 if (!success) {
226 LOG(LS_ERROR) << "Failed to configure encoder."; 228 LOG(LS_ERROR) << "Failed to configure encoder.";
227 RTC_DCHECK(success); 229 RTC_DCHECK(success);
228 } 230 }
229 231
230 send_payload_router_->SetSendingRtpModules( 232 send_payload_router_->SetSendingRtpModules(
231 video_codec.numberOfSimulcastStreams); 233 video_codec.numberOfSimulcastStreams);
232 234
233 // Restart the media flow 235 // Restart the media flow
234 Restart(); 236 Restart();
237 if (stats_proxy_) {
238 // Clear stats for disabled layers.
239 for (size_t i = video_codec.numberOfSimulcastStreams; i < ssrcs_.size();
240 ++i) {
241 stats_proxy_->OnInactiveSsrc(ssrcs_[i]);
242 }
243 VideoEncoderConfig::ContentType content_type;
244 switch (video_codec.mode) {
245 case kRealtimeVideo:
246 content_type = VideoEncoderConfig::ContentType::kRealtimeVideo;
247 break;
248 case kScreensharing:
249 content_type = VideoEncoderConfig::ContentType::kScreen;
250 break;
251 default:
252 RTC_NOTREACHED();
253 break;
254 }
255 stats_proxy_->SetContentType(content_type);
256 }
235 } 257 }
236 258
237 int ViEEncoder::GetPaddingNeededBps() const { 259 int ViEEncoder::GetPaddingNeededBps() const {
238 int64_t time_of_last_frame_activity_ms; 260 int64_t time_of_last_frame_activity_ms;
239 int min_transmit_bitrate_bps; 261 int min_transmit_bitrate_bps;
240 int bitrate_bps; 262 int bitrate_bps;
241 VideoCodec send_codec; 263 VideoCodec send_codec;
242 { 264 {
243 rtc::CritScope lock(&data_cs_); 265 rtc::CritScope lock(&data_cs_);
244 bool send_padding = encoder_config_.numberOfSimulcastStreams > 1 || 266 bool send_padding = encoder_config_.numberOfSimulcastStreams > 1 ||
245 video_suspended_ || min_transmit_bitrate_kbps_ > 0; 267 video_suspended_ || min_transmit_bitrate_bps_ > 0;
246 if (!send_padding) 268 if (!send_padding)
247 return 0; 269 return 0;
248 time_of_last_frame_activity_ms = time_of_last_frame_activity_ms_; 270 time_of_last_frame_activity_ms = time_of_last_frame_activity_ms_;
249 min_transmit_bitrate_bps = 1000 * min_transmit_bitrate_kbps_; 271 min_transmit_bitrate_bps = min_transmit_bitrate_bps_;
250 bitrate_bps = last_observed_bitrate_bps_; 272 bitrate_bps = last_observed_bitrate_bps_;
251 send_codec = encoder_config_; 273 send_codec = encoder_config_;
252 } 274 }
253 275
254 bool video_is_suspended = vcm_->VideoSuspended(); 276 bool video_is_suspended = vcm_->VideoSuspended();
255 277
256 // Find the max amount of padding we can allow ourselves to send at this 278 // Find the max amount of padding we can allow ourselves to send at this
257 // point, based on which streams are currently active and what our current 279 // point, based on which streams are currently active and what our current
258 // available bandwidth is. 280 // available bandwidth is.
259 int pad_up_to_bitrate_bps = 0; 281 int pad_up_to_bitrate_bps = 0;
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 return; 503 return;
482 } 504 }
483 time_last_intra_request_ms_[i] = now_ms; 505 time_last_intra_request_ms_[i] = now_ms;
484 } 506 }
485 vcm_->IntraFrameRequest(static_cast<int>(i)); 507 vcm_->IntraFrameRequest(static_cast<int>(i));
486 return; 508 return;
487 } 509 }
488 RTC_NOTREACHED() << "Should not receive keyframe requests on unknown SSRCs."; 510 RTC_NOTREACHED() << "Should not receive keyframe requests on unknown SSRCs.";
489 } 511 }
490 512
491 void ViEEncoder::SetMinTransmitBitrate(int min_transmit_bitrate_kbps) {
492 assert(min_transmit_bitrate_kbps >= 0);
493 rtc::CritScope lock(&data_cs_);
494 min_transmit_bitrate_kbps_ = min_transmit_bitrate_kbps;
495 }
496
497 // Called from ViEBitrateObserver. 513 // Called from ViEBitrateObserver.
498 void ViEEncoder::OnNetworkChanged(uint32_t bitrate_bps, 514 void ViEEncoder::OnNetworkChanged(uint32_t bitrate_bps,
499 uint8_t fraction_lost, 515 uint8_t fraction_lost,
500 int64_t round_trip_time_ms) { 516 int64_t round_trip_time_ms) {
501 LOG(LS_VERBOSE) << "OnNetworkChanged, bitrate" << bitrate_bps 517 LOG(LS_VERBOSE) << "OnNetworkChanged, bitrate" << bitrate_bps
502 << " packet loss " << static_cast<int>(fraction_lost) 518 << " packet loss " << static_cast<int>(fraction_lost)
503 << " rtt " << round_trip_time_ms; 519 << " rtt " << round_trip_time_ms;
504 RTC_DCHECK(send_payload_router_ != NULL); 520 RTC_DCHECK(send_payload_router_ != NULL);
505 vcm_->SetChannelParameters(bitrate_bps, fraction_lost, round_trip_time_ms); 521 vcm_->SetChannelParameters(bitrate_bps, fraction_lost, round_trip_time_ms);
506 bool video_is_suspended = vcm_->VideoSuspended(); 522 bool video_is_suspended = vcm_->VideoSuspended();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 const uint32_t width, 567 const uint32_t width,
552 const uint32_t height) { 568 const uint32_t height) {
553 return vp_->SetTargetResolution(width, height, frame_rate); 569 return vp_->SetTargetResolution(width, height, frame_rate);
554 } 570 }
555 571
556 void QMVideoSettingsCallback::SetTargetFramerate(int frame_rate) { 572 void QMVideoSettingsCallback::SetTargetFramerate(int frame_rate) {
557 vp_->SetTargetFramerate(frame_rate); 573 vp_->SetTargetFramerate(frame_rate);
558 } 574 }
559 575
560 } // namespace webrtc 576 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/vie_encoder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698