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 27 matching lines...) Expand all Loading... | |
38 return kVideoCodecVP9; | 38 return kVideoCodecVP9; |
39 if (payload_name == "H264") | 39 if (payload_name == "H264") |
40 return kVideoCodecH264; | 40 return kVideoCodecH264; |
41 return kVideoCodecGeneric; | 41 return kVideoCodecGeneric; |
42 } | 42 } |
43 | 43 |
44 VideoCodec VideoEncoderConfigToVideoCodec( | 44 VideoCodec VideoEncoderConfigToVideoCodec( |
45 const VideoEncoderConfig& config, | 45 const VideoEncoderConfig& config, |
46 const std::vector<VideoStream>& streams, | 46 const std::vector<VideoStream>& streams, |
47 const std::string& payload_name, | 47 const std::string& payload_name, |
48 int payload_type) { | 48 int payload_type, |
49 bool nack_enabled) { | |
49 static const int kEncoderMinBitrateKbps = 30; | 50 static const int kEncoderMinBitrateKbps = 30; |
50 RTC_DCHECK(!streams.empty()); | 51 RTC_DCHECK(!streams.empty()); |
51 RTC_DCHECK_GE(config.min_transmit_bitrate_bps, 0); | 52 RTC_DCHECK_GE(config.min_transmit_bitrate_bps, 0); |
52 | 53 |
53 VideoCodec video_codec; | 54 VideoCodec video_codec; |
54 memset(&video_codec, 0, sizeof(video_codec)); | 55 memset(&video_codec, 0, sizeof(video_codec)); |
55 video_codec.codecType = PayloadNameToCodecType(payload_name); | 56 video_codec.codecType = PayloadNameToCodecType(payload_name); |
56 | 57 |
57 switch (config.content_type) { | 58 switch (config.content_type) { |
58 case VideoEncoderConfig::ContentType::kRealtimeVideo: | 59 case VideoEncoderConfig::ContentType::kRealtimeVideo: |
(...skipping 12 matching lines...) Expand all Loading... | |
71 if (config.encoder_specific_settings) | 72 if (config.encoder_specific_settings) |
72 config.encoder_specific_settings->FillEncoderSpecificSettings(&video_codec); | 73 config.encoder_specific_settings->FillEncoderSpecificSettings(&video_codec); |
73 | 74 |
74 switch (video_codec.codecType) { | 75 switch (video_codec.codecType) { |
75 case kVideoCodecVP8: { | 76 case kVideoCodecVP8: { |
76 if (!config.encoder_specific_settings) | 77 if (!config.encoder_specific_settings) |
77 video_codec.codecSpecific.VP8 = VideoEncoder::GetDefaultVp8Settings(); | 78 video_codec.codecSpecific.VP8 = VideoEncoder::GetDefaultVp8Settings(); |
78 video_codec.codecSpecific.VP8.numberOfTemporalLayers = | 79 video_codec.codecSpecific.VP8.numberOfTemporalLayers = |
79 static_cast<unsigned char>( | 80 static_cast<unsigned char>( |
80 streams.back().temporal_layer_thresholds_bps.size() + 1); | 81 streams.back().temporal_layer_thresholds_bps.size() + 1); |
82 // Turn error resilience off for single stream and no temporal layers when | |
83 // nack is enabled. | |
84 if (nack_enabled && streams.size() == 1 && | |
stefan-webrtc
2016/11/15 08:48:47
Why only for single stream?
marpan
2016/11/15 17:38:23
No need for single stream condition, can also be u
åsapersson
2016/11/17 15:30:50
Removed single stream check.
åsapersson
2016/11/17 15:30:50
Done.
| |
85 video_codec.codecSpecific.VP8.numberOfTemporalLayers == 1) { | |
86 video_codec.codecSpecific.VP8.resilience = kResilienceOff; | |
87 } | |
81 break; | 88 break; |
82 } | 89 } |
83 case kVideoCodecVP9: { | 90 case kVideoCodecVP9: { |
marpan
2016/11/15 17:38:23
Same can also be done with VP9 (for #spatial_layer
åsapersson
2016/11/17 15:30:50
Will do the same for VP9 in a separate CL.
| |
84 if (!config.encoder_specific_settings) | 91 if (!config.encoder_specific_settings) |
85 video_codec.codecSpecific.VP9 = VideoEncoder::GetDefaultVp9Settings(); | 92 video_codec.codecSpecific.VP9 = VideoEncoder::GetDefaultVp9Settings(); |
86 if (video_codec.mode == kScreensharing && | 93 if (video_codec.mode == kScreensharing && |
87 config.encoder_specific_settings) { | 94 config.encoder_specific_settings) { |
88 video_codec.codecSpecific.VP9.flexibleMode = true; | 95 video_codec.codecSpecific.VP9.flexibleMode = true; |
89 // For now VP9 screensharing use 1 temporal and 2 spatial layers. | 96 // For now VP9 screensharing use 1 temporal and 2 spatial layers. |
90 RTC_DCHECK_EQ(1, video_codec.codecSpecific.VP9.numberOfTemporalLayers); | 97 RTC_DCHECK_EQ(1, video_codec.codecSpecific.VP9.numberOfTemporalLayers); |
91 RTC_DCHECK_EQ(2, video_codec.codecSpecific.VP9.numberOfSpatialLayers); | 98 RTC_DCHECK_EQ(2, video_codec.codecSpecific.VP9.numberOfSpatialLayers); |
92 } | 99 } |
93 video_codec.codecSpecific.VP9.numberOfTemporalLayers = | 100 video_codec.codecSpecific.VP9.numberOfTemporalLayers = |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 } | 192 } |
186 return options; | 193 return options; |
187 } | 194 } |
188 | 195 |
189 } // namespace | 196 } // namespace |
190 | 197 |
191 class ViEEncoder::ConfigureEncoderTask : public rtc::QueuedTask { | 198 class ViEEncoder::ConfigureEncoderTask : public rtc::QueuedTask { |
192 public: | 199 public: |
193 ConfigureEncoderTask(ViEEncoder* vie_encoder, | 200 ConfigureEncoderTask(ViEEncoder* vie_encoder, |
194 VideoEncoderConfig config, | 201 VideoEncoderConfig config, |
195 size_t max_data_payload_length) | 202 size_t max_data_payload_length, |
203 bool nack_enabled) | |
196 : vie_encoder_(vie_encoder), | 204 : vie_encoder_(vie_encoder), |
197 config_(std::move(config)), | 205 config_(std::move(config)), |
198 max_data_payload_length_(max_data_payload_length) {} | 206 max_data_payload_length_(max_data_payload_length), |
207 nack_enabled_(nack_enabled) {} | |
199 | 208 |
200 private: | 209 private: |
201 bool Run() override { | 210 bool Run() override { |
202 vie_encoder_->ConfigureEncoderOnTaskQueue(std::move(config_), | 211 vie_encoder_->ConfigureEncoderOnTaskQueue( |
203 max_data_payload_length_); | 212 std::move(config_), max_data_payload_length_, nack_enabled_); |
204 return true; | 213 return true; |
205 } | 214 } |
206 | 215 |
207 ViEEncoder* const vie_encoder_; | 216 ViEEncoder* const vie_encoder_; |
208 VideoEncoderConfig config_; | 217 VideoEncoderConfig config_; |
209 size_t max_data_payload_length_; | 218 size_t max_data_payload_length_; |
219 bool nack_enabled_; | |
210 }; | 220 }; |
211 | 221 |
212 class ViEEncoder::EncodeTask : public rtc::QueuedTask { | 222 class ViEEncoder::EncodeTask : public rtc::QueuedTask { |
213 public: | 223 public: |
214 EncodeTask(const VideoFrame& frame, | 224 EncodeTask(const VideoFrame& frame, |
215 ViEEncoder* vie_encoder, | 225 ViEEncoder* vie_encoder, |
216 int64_t time_when_posted_in_ms, | 226 int64_t time_when_posted_in_ms, |
217 bool log_stats) | 227 bool log_stats) |
218 : vie_encoder_(vie_encoder), | 228 : vie_encoder_(vie_encoder), |
219 time_when_posted_ms_(time_when_posted_in_ms), | 229 time_when_posted_ms_(time_when_posted_in_ms), |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
378 GetCpuOveruseOptions(settings.full_overuse_time), | 388 GetCpuOveruseOptions(settings.full_overuse_time), |
379 this, | 389 this, |
380 encoder_timing, | 390 encoder_timing, |
381 stats_proxy), | 391 stats_proxy), |
382 stats_proxy_(stats_proxy), | 392 stats_proxy_(stats_proxy), |
383 pre_encode_callback_(pre_encode_callback), | 393 pre_encode_callback_(pre_encode_callback), |
384 module_process_thread_(nullptr), | 394 module_process_thread_(nullptr), |
385 pending_encoder_reconfiguration_(false), | 395 pending_encoder_reconfiguration_(false), |
386 encoder_start_bitrate_bps_(0), | 396 encoder_start_bitrate_bps_(0), |
387 max_data_payload_length_(0), | 397 max_data_payload_length_(0), |
398 nack_enabled_(false), | |
388 last_observed_bitrate_bps_(0), | 399 last_observed_bitrate_bps_(0), |
389 encoder_paused_and_dropped_frame_(false), | 400 encoder_paused_and_dropped_frame_(false), |
390 has_received_sli_(false), | 401 has_received_sli_(false), |
391 picture_id_sli_(0), | 402 picture_id_sli_(0), |
392 has_received_rpsi_(false), | 403 has_received_rpsi_(false), |
393 picture_id_rpsi_(0), | 404 picture_id_rpsi_(0), |
394 clock_(Clock::GetRealTimeClock()), | 405 clock_(Clock::GetRealTimeClock()), |
395 degradation_preference_( | 406 degradation_preference_( |
396 VideoSendStream::DegradationPreference::kBalanced), | 407 VideoSendStream::DegradationPreference::kBalanced), |
397 cpu_restricted_counter_(0), | 408 cpu_restricted_counter_(0), |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
475 } | 486 } |
476 | 487 |
477 void ViEEncoder::SetStartBitrate(int start_bitrate_bps) { | 488 void ViEEncoder::SetStartBitrate(int start_bitrate_bps) { |
478 encoder_queue_.PostTask([this, start_bitrate_bps] { | 489 encoder_queue_.PostTask([this, start_bitrate_bps] { |
479 RTC_DCHECK_RUN_ON(&encoder_queue_); | 490 RTC_DCHECK_RUN_ON(&encoder_queue_); |
480 encoder_start_bitrate_bps_ = start_bitrate_bps; | 491 encoder_start_bitrate_bps_ = start_bitrate_bps; |
481 }); | 492 }); |
482 } | 493 } |
483 | 494 |
484 void ViEEncoder::ConfigureEncoder(VideoEncoderConfig config, | 495 void ViEEncoder::ConfigureEncoder(VideoEncoderConfig config, |
485 size_t max_data_payload_length) { | 496 size_t max_data_payload_length, |
497 bool nack_enabled) { | |
486 encoder_queue_.PostTask( | 498 encoder_queue_.PostTask( |
487 std::unique_ptr<rtc::QueuedTask>(new ConfigureEncoderTask( | 499 std::unique_ptr<rtc::QueuedTask>(new ConfigureEncoderTask( |
488 this, std::move(config), max_data_payload_length))); | 500 this, std::move(config), max_data_payload_length, nack_enabled))); |
489 } | 501 } |
490 | 502 |
491 void ViEEncoder::ConfigureEncoderOnTaskQueue(VideoEncoderConfig config, | 503 void ViEEncoder::ConfigureEncoderOnTaskQueue(VideoEncoderConfig config, |
492 size_t max_data_payload_length) { | 504 size_t max_data_payload_length, |
505 bool nack_enabled) { | |
493 RTC_DCHECK_RUN_ON(&encoder_queue_); | 506 RTC_DCHECK_RUN_ON(&encoder_queue_); |
494 RTC_DCHECK(sink_); | 507 RTC_DCHECK(sink_); |
495 LOG(LS_INFO) << "ConfigureEncoder requested."; | 508 LOG(LS_INFO) << "ConfigureEncoder requested."; |
496 | 509 |
497 max_data_payload_length_ = max_data_payload_length; | 510 max_data_payload_length_ = max_data_payload_length; |
511 nack_enabled_ = nack_enabled; | |
498 encoder_config_ = std::move(config); | 512 encoder_config_ = std::move(config); |
499 pending_encoder_reconfiguration_ = true; | 513 pending_encoder_reconfiguration_ = true; |
500 | 514 |
501 // Reconfigure the encoder now if the encoder has an internal source or | 515 // Reconfigure the encoder now if the encoder has an internal source or |
502 // if the frame resolution is known. Otherwise, the reconfiguration is | 516 // if the frame resolution is known. Otherwise, the reconfiguration is |
503 // deferred until the next frame to minimize the number of reconfigurations. | 517 // deferred until the next frame to minimize the number of reconfigurations. |
504 // The codec configuration depends on incoming video frame size. | 518 // The codec configuration depends on incoming video frame size. |
505 if (last_frame_info_) { | 519 if (last_frame_info_) { |
506 ReconfigureEncoder(); | 520 ReconfigureEncoder(); |
507 } else if (settings_.internal_source) { | 521 } else if (settings_.internal_source) { |
508 last_frame_info_ = rtc::Optional<VideoFrameInfo>( | 522 last_frame_info_ = rtc::Optional<VideoFrameInfo>( |
509 VideoFrameInfo(176, 144, kVideoRotation_0, false)); | 523 VideoFrameInfo(176, 144, kVideoRotation_0, false)); |
510 ReconfigureEncoder(); | 524 ReconfigureEncoder(); |
511 } | 525 } |
512 } | 526 } |
513 | 527 |
514 void ViEEncoder::ReconfigureEncoder() { | 528 void ViEEncoder::ReconfigureEncoder() { |
515 RTC_DCHECK_RUN_ON(&encoder_queue_); | 529 RTC_DCHECK_RUN_ON(&encoder_queue_); |
516 RTC_DCHECK(pending_encoder_reconfiguration_); | 530 RTC_DCHECK(pending_encoder_reconfiguration_); |
517 std::vector<VideoStream> streams = | 531 std::vector<VideoStream> streams = |
518 encoder_config_.video_stream_factory->CreateEncoderStreams( | 532 encoder_config_.video_stream_factory->CreateEncoderStreams( |
519 last_frame_info_->width, last_frame_info_->height, encoder_config_); | 533 last_frame_info_->width, last_frame_info_->height, encoder_config_); |
520 | 534 |
521 VideoCodec codec = VideoEncoderConfigToVideoCodec( | 535 VideoCodec codec = VideoEncoderConfigToVideoCodec( |
522 encoder_config_, streams, settings_.payload_name, settings_.payload_type); | 536 encoder_config_, streams, settings_.payload_name, settings_.payload_type, |
537 nack_enabled_); | |
523 | 538 |
524 codec.startBitrate = | 539 codec.startBitrate = |
525 std::max(encoder_start_bitrate_bps_ / 1000, codec.minBitrate); | 540 std::max(encoder_start_bitrate_bps_ / 1000, codec.minBitrate); |
526 codec.startBitrate = std::min(codec.startBitrate, codec.maxBitrate); | 541 codec.startBitrate = std::min(codec.startBitrate, codec.maxBitrate); |
527 codec.expect_encode_from_texture = last_frame_info_->is_texture; | 542 codec.expect_encode_from_texture = last_frame_info_->is_texture; |
528 | 543 |
529 bool success = video_sender_.RegisterSendCodec( | 544 bool success = video_sender_.RegisterSendCodec( |
530 &codec, number_of_cores_, | 545 &codec, number_of_cores_, |
531 static_cast<uint32_t>(max_data_payload_length_)) == VCM_OK; | 546 static_cast<uint32_t>(max_data_payload_length_)) == VCM_OK; |
532 if (!success) { | 547 if (!success) { |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
824 current_pixel_count > *max_pixel_count_step_up_) { | 839 current_pixel_count > *max_pixel_count_step_up_) { |
825 max_pixel_count_ = rtc::Optional<int>(); | 840 max_pixel_count_ = rtc::Optional<int>(); |
826 max_pixel_count_step_up_ = rtc::Optional<int>(current_pixel_count); | 841 max_pixel_count_step_up_ = rtc::Optional<int>(current_pixel_count); |
827 --cpu_restricted_counter_; | 842 --cpu_restricted_counter_; |
828 stats_proxy_->OnCpuRestrictedResolutionChanged(cpu_restricted_counter_ > 0); | 843 stats_proxy_->OnCpuRestrictedResolutionChanged(cpu_restricted_counter_ > 0); |
829 source_proxy_->RequestHigherResolutionThan(current_pixel_count); | 844 source_proxy_->RequestHigherResolutionThan(current_pixel_count); |
830 } | 845 } |
831 } | 846 } |
832 | 847 |
833 } // namespace webrtc | 848 } // namespace webrtc |
OLD | NEW |