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 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 } | 45 } |
46 return options; | 46 return options; |
47 } | 47 } |
48 | 48 |
49 } // namespace | 49 } // namespace |
50 | 50 |
51 class ViEEncoder::ConfigureEncoderTask : public rtc::QueuedTask { | 51 class ViEEncoder::ConfigureEncoderTask : public rtc::QueuedTask { |
52 public: | 52 public: |
53 ConfigureEncoderTask(ViEEncoder* vie_encoder, | 53 ConfigureEncoderTask(ViEEncoder* vie_encoder, |
54 VideoEncoderConfig config, | 54 VideoEncoderConfig config, |
55 size_t max_data_payload_length) | 55 size_t max_data_payload_length, |
| 56 bool nack_enabled) |
56 : vie_encoder_(vie_encoder), | 57 : vie_encoder_(vie_encoder), |
57 config_(std::move(config)), | 58 config_(std::move(config)), |
58 max_data_payload_length_(max_data_payload_length) {} | 59 max_data_payload_length_(max_data_payload_length), |
| 60 nack_enabled_(nack_enabled) {} |
59 | 61 |
60 private: | 62 private: |
61 bool Run() override { | 63 bool Run() override { |
62 vie_encoder_->ConfigureEncoderOnTaskQueue(std::move(config_), | 64 vie_encoder_->ConfigureEncoderOnTaskQueue( |
63 max_data_payload_length_); | 65 std::move(config_), max_data_payload_length_, nack_enabled_); |
64 return true; | 66 return true; |
65 } | 67 } |
66 | 68 |
67 ViEEncoder* const vie_encoder_; | 69 ViEEncoder* const vie_encoder_; |
68 VideoEncoderConfig config_; | 70 VideoEncoderConfig config_; |
69 size_t max_data_payload_length_; | 71 size_t max_data_payload_length_; |
| 72 bool nack_enabled_; |
70 }; | 73 }; |
71 | 74 |
72 class ViEEncoder::EncodeTask : public rtc::QueuedTask { | 75 class ViEEncoder::EncodeTask : public rtc::QueuedTask { |
73 public: | 76 public: |
74 EncodeTask(const VideoFrame& frame, | 77 EncodeTask(const VideoFrame& frame, |
75 ViEEncoder* vie_encoder, | 78 ViEEncoder* vie_encoder, |
76 int64_t time_when_posted_in_ms, | 79 int64_t time_when_posted_in_ms, |
77 bool log_stats) | 80 bool log_stats) |
78 : vie_encoder_(vie_encoder), | 81 : vie_encoder_(vie_encoder), |
79 time_when_posted_ms_(time_when_posted_in_ms), | 82 time_when_posted_ms_(time_when_posted_in_ms), |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 GetCpuOveruseOptions(settings.full_overuse_time), | 242 GetCpuOveruseOptions(settings.full_overuse_time), |
240 this, | 243 this, |
241 encoder_timing, | 244 encoder_timing, |
242 stats_proxy), | 245 stats_proxy), |
243 stats_proxy_(stats_proxy), | 246 stats_proxy_(stats_proxy), |
244 pre_encode_callback_(pre_encode_callback), | 247 pre_encode_callback_(pre_encode_callback), |
245 module_process_thread_(nullptr), | 248 module_process_thread_(nullptr), |
246 pending_encoder_reconfiguration_(false), | 249 pending_encoder_reconfiguration_(false), |
247 encoder_start_bitrate_bps_(0), | 250 encoder_start_bitrate_bps_(0), |
248 max_data_payload_length_(0), | 251 max_data_payload_length_(0), |
| 252 nack_enabled_(false), |
249 last_observed_bitrate_bps_(0), | 253 last_observed_bitrate_bps_(0), |
250 encoder_paused_and_dropped_frame_(false), | 254 encoder_paused_and_dropped_frame_(false), |
251 has_received_sli_(false), | 255 has_received_sli_(false), |
252 picture_id_sli_(0), | 256 picture_id_sli_(0), |
253 has_received_rpsi_(false), | 257 has_received_rpsi_(false), |
254 picture_id_rpsi_(0), | 258 picture_id_rpsi_(0), |
255 clock_(Clock::GetRealTimeClock()), | 259 clock_(Clock::GetRealTimeClock()), |
256 degradation_preference_( | 260 degradation_preference_( |
257 VideoSendStream::DegradationPreference::kBalanced), | 261 VideoSendStream::DegradationPreference::kBalanced), |
258 cpu_restricted_counter_(0), | 262 cpu_restricted_counter_(0), |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 } | 341 } |
338 | 342 |
339 void ViEEncoder::SetStartBitrate(int start_bitrate_bps) { | 343 void ViEEncoder::SetStartBitrate(int start_bitrate_bps) { |
340 encoder_queue_.PostTask([this, start_bitrate_bps] { | 344 encoder_queue_.PostTask([this, start_bitrate_bps] { |
341 RTC_DCHECK_RUN_ON(&encoder_queue_); | 345 RTC_DCHECK_RUN_ON(&encoder_queue_); |
342 encoder_start_bitrate_bps_ = start_bitrate_bps; | 346 encoder_start_bitrate_bps_ = start_bitrate_bps; |
343 }); | 347 }); |
344 } | 348 } |
345 | 349 |
346 void ViEEncoder::ConfigureEncoder(VideoEncoderConfig config, | 350 void ViEEncoder::ConfigureEncoder(VideoEncoderConfig config, |
347 size_t max_data_payload_length) { | 351 size_t max_data_payload_length, |
| 352 bool nack_enabled) { |
348 encoder_queue_.PostTask( | 353 encoder_queue_.PostTask( |
349 std::unique_ptr<rtc::QueuedTask>(new ConfigureEncoderTask( | 354 std::unique_ptr<rtc::QueuedTask>(new ConfigureEncoderTask( |
350 this, std::move(config), max_data_payload_length))); | 355 this, std::move(config), max_data_payload_length, nack_enabled))); |
351 } | 356 } |
352 | 357 |
353 void ViEEncoder::ConfigureEncoderOnTaskQueue(VideoEncoderConfig config, | 358 void ViEEncoder::ConfigureEncoderOnTaskQueue(VideoEncoderConfig config, |
354 size_t max_data_payload_length) { | 359 size_t max_data_payload_length, |
| 360 bool nack_enabled) { |
355 RTC_DCHECK_RUN_ON(&encoder_queue_); | 361 RTC_DCHECK_RUN_ON(&encoder_queue_); |
356 RTC_DCHECK(sink_); | 362 RTC_DCHECK(sink_); |
357 LOG(LS_INFO) << "ConfigureEncoder requested."; | 363 LOG(LS_INFO) << "ConfigureEncoder requested."; |
358 | 364 |
359 max_data_payload_length_ = max_data_payload_length; | 365 max_data_payload_length_ = max_data_payload_length; |
| 366 nack_enabled_ = nack_enabled; |
360 encoder_config_ = std::move(config); | 367 encoder_config_ = std::move(config); |
361 pending_encoder_reconfiguration_ = true; | 368 pending_encoder_reconfiguration_ = true; |
362 | 369 |
363 // Reconfigure the encoder now if the encoder has an internal source or | 370 // Reconfigure the encoder now if the encoder has an internal source or |
364 // if the frame resolution is known. Otherwise, the reconfiguration is | 371 // if the frame resolution is known. Otherwise, the reconfiguration is |
365 // deferred until the next frame to minimize the number of reconfigurations. | 372 // deferred until the next frame to minimize the number of reconfigurations. |
366 // The codec configuration depends on incoming video frame size. | 373 // The codec configuration depends on incoming video frame size. |
367 if (last_frame_info_) { | 374 if (last_frame_info_) { |
368 ReconfigureEncoder(); | 375 ReconfigureEncoder(); |
369 } else if (settings_.internal_source) { | 376 } else if (settings_.internal_source) { |
370 last_frame_info_ = rtc::Optional<VideoFrameInfo>( | 377 last_frame_info_ = rtc::Optional<VideoFrameInfo>( |
371 VideoFrameInfo(176, 144, kVideoRotation_0, false)); | 378 VideoFrameInfo(176, 144, kVideoRotation_0, false)); |
372 ReconfigureEncoder(); | 379 ReconfigureEncoder(); |
373 } | 380 } |
374 } | 381 } |
375 | 382 |
376 void ViEEncoder::ReconfigureEncoder() { | 383 void ViEEncoder::ReconfigureEncoder() { |
377 RTC_DCHECK_RUN_ON(&encoder_queue_); | 384 RTC_DCHECK_RUN_ON(&encoder_queue_); |
378 RTC_DCHECK(pending_encoder_reconfiguration_); | 385 RTC_DCHECK(pending_encoder_reconfiguration_); |
379 std::vector<VideoStream> streams = | 386 std::vector<VideoStream> streams = |
380 encoder_config_.video_stream_factory->CreateEncoderStreams( | 387 encoder_config_.video_stream_factory->CreateEncoderStreams( |
381 last_frame_info_->width, last_frame_info_->height, encoder_config_); | 388 last_frame_info_->width, last_frame_info_->height, encoder_config_); |
382 | 389 |
383 VideoCodec codec; | 390 VideoCodec codec; |
384 if (!VideoCodecInitializer::SetupCodec(encoder_config_, settings_, streams, | 391 if (!VideoCodecInitializer::SetupCodec(encoder_config_, settings_, streams, |
385 &codec, &rate_allocator_)) { | 392 nack_enabled_, &codec, |
| 393 &rate_allocator_)) { |
386 LOG(LS_ERROR) << "Failed to create encoder configuration."; | 394 LOG(LS_ERROR) << "Failed to create encoder configuration."; |
387 } | 395 } |
388 | 396 |
389 codec.startBitrate = | 397 codec.startBitrate = |
390 std::max(encoder_start_bitrate_bps_ / 1000, codec.minBitrate); | 398 std::max(encoder_start_bitrate_bps_ / 1000, codec.minBitrate); |
391 codec.startBitrate = std::min(codec.startBitrate, codec.maxBitrate); | 399 codec.startBitrate = std::min(codec.startBitrate, codec.maxBitrate); |
392 codec.expect_encode_from_texture = last_frame_info_->is_texture; | 400 codec.expect_encode_from_texture = last_frame_info_->is_texture; |
393 | 401 |
394 bool success = video_sender_.RegisterSendCodec( | 402 bool success = video_sender_.RegisterSendCodec( |
395 &codec, number_of_cores_, | 403 &codec, number_of_cores_, |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 current_pixel_count > *max_pixel_count_step_up_) { | 692 current_pixel_count > *max_pixel_count_step_up_) { |
685 max_pixel_count_ = rtc::Optional<int>(); | 693 max_pixel_count_ = rtc::Optional<int>(); |
686 max_pixel_count_step_up_ = rtc::Optional<int>(current_pixel_count); | 694 max_pixel_count_step_up_ = rtc::Optional<int>(current_pixel_count); |
687 --cpu_restricted_counter_; | 695 --cpu_restricted_counter_; |
688 stats_proxy_->OnCpuRestrictedResolutionChanged(cpu_restricted_counter_ > 0); | 696 stats_proxy_->OnCpuRestrictedResolutionChanged(cpu_restricted_counter_ > 0); |
689 source_proxy_->RequestHigherResolutionThan(current_pixel_count); | 697 source_proxy_->RequestHigherResolutionThan(current_pixel_count); |
690 } | 698 } |
691 } | 699 } |
692 | 700 |
693 } // namespace webrtc | 701 } // namespace webrtc |
OLD | NEW |