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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
276 | 276 |
277 private: | 277 private: |
278 rtc::CriticalSection crit_; | 278 rtc::CriticalSection crit_; |
279 rtc::SequencedTaskChecker main_checker_; | 279 rtc::SequencedTaskChecker main_checker_; |
280 ViEEncoder* vie_encoder_; | 280 ViEEncoder* vie_encoder_; |
281 rtc::VideoSourceInterface<VideoFrame>* source_ GUARDED_BY(&crit_); | 281 rtc::VideoSourceInterface<VideoFrame>* source_ GUARDED_BY(&crit_); |
282 | 282 |
283 RTC_DISALLOW_COPY_AND_ASSIGN(VideoSourceProxy); | 283 RTC_DISALLOW_COPY_AND_ASSIGN(VideoSourceProxy); |
284 }; | 284 }; |
285 | 285 |
286 class ViEEncoder::ConfigureEncoderTask : public rtc::QueuedTask { | |
287 public: | |
288 ConfigureEncoderTask(ViEEncoder* vie_encoder, | |
289 VideoEncoderConfig config, | |
290 size_t max_data_payload_length) | |
291 : vie_encoder_(vie_encoder), | |
292 config_(std::move(config)), | |
293 max_data_payload_length_(max_data_payload_length) {} | |
294 | |
295 private: | |
296 bool Run() override { | |
297 vie_encoder_->ConfigureEncoderOnTaskQueue(std::move(config_), | |
298 max_data_payload_length_); | |
299 return true; | |
300 } | |
301 | |
302 ViEEncoder* const vie_encoder_; | |
303 VideoEncoderConfig config_; | |
304 size_t max_data_payload_length_; | |
305 }; | |
306 | |
286 ViEEncoder::ViEEncoder(uint32_t number_of_cores, | 307 ViEEncoder::ViEEncoder(uint32_t number_of_cores, |
287 SendStatisticsProxy* stats_proxy, | 308 SendStatisticsProxy* stats_proxy, |
288 const VideoSendStream::Config::EncoderSettings& settings, | 309 const VideoSendStream::Config::EncoderSettings& settings, |
289 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, | 310 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, |
290 LoadObserver* overuse_callback, | 311 LoadObserver* overuse_callback, |
291 EncodedFrameObserver* encoder_timing) | 312 EncodedFrameObserver* encoder_timing) |
292 : shutdown_event_(true /* manual_reset */, false), | 313 : shutdown_event_(true /* manual_reset */, false), |
293 number_of_cores_(number_of_cores), | 314 number_of_cores_(number_of_cores), |
294 source_proxy_(new VideoSourceProxy(this)), | 315 source_proxy_(new VideoSourceProxy(this)), |
316 sink_(nullptr), | |
295 settings_(settings), | 317 settings_(settings), |
318 codec_type_(PayloadNameToCodecType(settings.payload_name)), | |
296 vp_(VideoProcessing::Create()), | 319 vp_(VideoProcessing::Create()), |
297 video_sender_(Clock::GetRealTimeClock(), this, this), | 320 video_sender_(Clock::GetRealTimeClock(), this, this), |
298 overuse_detector_(Clock::GetRealTimeClock(), | 321 overuse_detector_(Clock::GetRealTimeClock(), |
299 GetCpuOveruseOptions(settings.full_overuse_time), | 322 GetCpuOveruseOptions(settings.full_overuse_time), |
300 this, | 323 this, |
301 encoder_timing, | 324 encoder_timing, |
302 stats_proxy), | 325 stats_proxy), |
303 load_observer_(overuse_callback), | 326 load_observer_(overuse_callback), |
304 stats_proxy_(stats_proxy), | 327 stats_proxy_(stats_proxy), |
305 pre_encode_callback_(pre_encode_callback), | 328 pre_encode_callback_(pre_encode_callback), |
306 module_process_thread_(nullptr), | 329 module_process_thread_(nullptr), |
307 encoder_config_(), | 330 encoder_config_(), |
308 encoder_start_bitrate_bps_(0), | 331 encoder_start_bitrate_bps_(0), |
332 max_data_payload_length_(0), | |
309 last_observed_bitrate_bps_(0), | 333 last_observed_bitrate_bps_(0), |
310 encoder_paused_and_dropped_frame_(false), | 334 encoder_paused_and_dropped_frame_(false), |
311 has_received_sli_(false), | 335 has_received_sli_(false), |
312 picture_id_sli_(0), | 336 picture_id_sli_(0), |
313 has_received_rpsi_(false), | 337 has_received_rpsi_(false), |
314 picture_id_rpsi_(0), | 338 picture_id_rpsi_(0), |
315 clock_(Clock::GetRealTimeClock()), | 339 clock_(Clock::GetRealTimeClock()), |
316 last_captured_timestamp_(0), | 340 last_captured_timestamp_(0), |
317 delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() - | 341 delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() - |
318 clock_->TimeInMilliseconds()), | 342 clock_->TimeInMilliseconds()), |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
377 | 401 |
378 void ViEEncoder::SetStartBitrate(int start_bitrate_bps) { | 402 void ViEEncoder::SetStartBitrate(int start_bitrate_bps) { |
379 encoder_queue_.PostTask([this, start_bitrate_bps] { | 403 encoder_queue_.PostTask([this, start_bitrate_bps] { |
380 RTC_DCHECK_RUN_ON(&encoder_queue_); | 404 RTC_DCHECK_RUN_ON(&encoder_queue_); |
381 encoder_start_bitrate_bps_ = start_bitrate_bps; | 405 encoder_start_bitrate_bps_ = start_bitrate_bps; |
382 }); | 406 }); |
383 } | 407 } |
384 | 408 |
385 void ViEEncoder::ConfigureEncoder(VideoEncoderConfig config, | 409 void ViEEncoder::ConfigureEncoder(VideoEncoderConfig config, |
386 size_t max_data_payload_length) { | 410 size_t max_data_payload_length) { |
387 VideoCodec video_codec = VideoEncoderConfigToVideoCodec( | 411 encoder_queue_.PostTask( |
388 config, settings_.payload_name, settings_.payload_type); | 412 std::unique_ptr<rtc::QueuedTask>(new ConfigureEncoderTask( |
389 LOG(LS_INFO) << "ConfigureEncoder: " << config.ToString(); | 413 this, std::move(config), max_data_payload_length))); |
390 std::vector<VideoStream> stream = std::move(config.streams); | |
391 int min_transmit_bitrate = config.min_transmit_bitrate_bps; | |
392 encoder_queue_.PostTask([this, video_codec, max_data_payload_length, stream, | |
393 min_transmit_bitrate] { | |
394 ConfigureEncoderInternal(video_codec, max_data_payload_length, stream, | |
395 min_transmit_bitrate); | |
396 }); | |
397 return; | |
398 } | 414 } |
399 | 415 |
400 void ViEEncoder::ConfigureEncoderInternal(const VideoCodec& video_codec, | 416 void ViEEncoder::ConfigureEncoderOnTaskQueue(VideoEncoderConfig config, |
401 size_t max_data_payload_length, | 417 size_t max_data_payload_length) { |
402 std::vector<VideoStream> stream, | |
403 int min_transmit_bitrate) { | |
404 RTC_DCHECK_RUN_ON(&encoder_queue_); | 418 RTC_DCHECK_RUN_ON(&encoder_queue_); |
405 RTC_DCHECK_GE(encoder_start_bitrate_bps_, 0); | |
406 RTC_DCHECK(sink_); | 419 RTC_DCHECK(sink_); |
420 LOG(LS_INFO) << "ConfigureEncoderOnTaskQueue"; | |
421 | |
422 max_data_payload_length_ = max_data_payload_length; | |
423 encoder_config_ = std::move(config); | |
424 | |
425 VideoCodec video_codec = VideoEncoderConfigToVideoCodec( | |
426 encoder_config_, settings_.payload_name, settings_.payload_type); | |
407 | 427 |
408 // Setting target width and height for VPM. | 428 // Setting target width and height for VPM. |
409 RTC_CHECK_EQ(VPM_OK, | 429 RTC_CHECK_EQ(VPM_OK, |
410 vp_->SetTargetResolution(video_codec.width, video_codec.height, | 430 vp_->SetTargetResolution(video_codec.width, video_codec.height, |
411 video_codec.maxFramerate)); | 431 video_codec.maxFramerate)); |
412 | 432 |
413 encoder_config_ = video_codec; | 433 video_codec.startBitrate = |
414 encoder_config_.startBitrate = encoder_start_bitrate_bps_ / 1000; | 434 std::max(encoder_start_bitrate_bps_ / 1000, video_codec.minBitrate); |
415 encoder_config_.startBitrate = | 435 video_codec.startBitrate = |
416 std::max(encoder_config_.startBitrate, video_codec.minBitrate); | 436 std::min(video_codec.startBitrate, video_codec.maxBitrate); |
417 encoder_config_.startBitrate = | |
418 std::min(encoder_config_.startBitrate, video_codec.maxBitrate); | |
419 | 437 |
420 bool success = video_sender_.RegisterSendCodec( | 438 bool success = video_sender_.RegisterSendCodec( |
421 &encoder_config_, number_of_cores_, | 439 &video_codec, number_of_cores_, |
422 static_cast<uint32_t>(max_data_payload_length)) == VCM_OK; | 440 static_cast<uint32_t>(max_data_payload_length)) == VCM_OK; |
sprang_webrtc
2016/09/26 11:50:02
Can we add getter to VideoSender instead, and calc
perkj_webrtc
2016/09/27 10:49:29
I added SimulcastRateAlloctor directly in ViEEncod
| |
423 | 441 |
424 if (!success) { | 442 if (!success) { |
425 LOG(LS_ERROR) << "Failed to configure encoder."; | 443 LOG(LS_ERROR) << "Failed to configure encoder."; |
426 RTC_DCHECK(success); | 444 RTC_DCHECK(success); |
427 } | 445 } |
428 | 446 |
429 if (stats_proxy_) { | 447 if (stats_proxy_) { |
430 VideoEncoderConfig::ContentType content_type = | 448 stats_proxy_->OnEncoderReconfigured(encoder_config_, |
431 VideoEncoderConfig::ContentType::kRealtimeVideo; | 449 encoder_config_.streams); |
432 switch (video_codec.mode) { | |
433 case kRealtimeVideo: | |
434 content_type = VideoEncoderConfig::ContentType::kRealtimeVideo; | |
435 break; | |
436 case kScreensharing: | |
437 content_type = VideoEncoderConfig::ContentType::kScreen; | |
438 break; | |
439 default: | |
440 RTC_NOTREACHED(); | |
441 break; | |
442 } | |
443 stats_proxy_->SetContentType(content_type); | |
444 } | 450 } |
445 | 451 |
446 sink_->OnEncoderConfigurationChanged(stream, min_transmit_bitrate); | 452 sink_->OnEncoderConfigurationChanged( |
453 encoder_config_.streams, encoder_config_.min_transmit_bitrate_bps); | |
447 } | 454 } |
448 | 455 |
449 void ViEEncoder::OnFrame(const VideoFrame& video_frame) { | 456 void ViEEncoder::OnFrame(const VideoFrame& video_frame) { |
450 RTC_DCHECK_RUNS_SERIALIZED(&incoming_frame_race_checker_); | 457 RTC_DCHECK_RUNS_SERIALIZED(&incoming_frame_race_checker_); |
451 stats_proxy_->OnIncomingFrame(video_frame.width(), video_frame.height()); | 458 stats_proxy_->OnIncomingFrame(video_frame.width(), video_frame.height()); |
452 | 459 |
453 VideoFrame incoming_frame = video_frame; | 460 VideoFrame incoming_frame = video_frame; |
454 | 461 |
455 // Local time in webrtc time base. | 462 // Local time in webrtc time base. |
456 int64_t current_time = clock_->TimeInMilliseconds(); | 463 int64_t current_time = clock_->TimeInMilliseconds(); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
540 // Pass frame via preprocessor. | 547 // Pass frame via preprocessor. |
541 frame_to_send = vp_->PreprocessFrame(video_frame); | 548 frame_to_send = vp_->PreprocessFrame(video_frame); |
542 if (!frame_to_send) { | 549 if (!frame_to_send) { |
543 // Drop this frame, or there was an error processing it. | 550 // Drop this frame, or there was an error processing it. |
544 return; | 551 return; |
545 } | 552 } |
546 } | 553 } |
547 | 554 |
548 overuse_detector_.FrameCaptured(video_frame, time_when_posted_in_ms); | 555 overuse_detector_.FrameCaptured(video_frame, time_when_posted_in_ms); |
549 | 556 |
550 if (encoder_config_.codecType == webrtc::kVideoCodecVP8) { | 557 if (codec_type_ == webrtc::kVideoCodecVP8) { |
551 webrtc::CodecSpecificInfo codec_specific_info; | 558 webrtc::CodecSpecificInfo codec_specific_info; |
552 codec_specific_info.codecType = webrtc::kVideoCodecVP8; | 559 codec_specific_info.codecType = webrtc::kVideoCodecVP8; |
553 | 560 |
554 codec_specific_info.codecSpecific.VP8.hasReceivedRPSI = | 561 codec_specific_info.codecSpecific.VP8.hasReceivedRPSI = |
555 has_received_rpsi_; | 562 has_received_rpsi_; |
556 codec_specific_info.codecSpecific.VP8.hasReceivedSLI = | 563 codec_specific_info.codecSpecific.VP8.hasReceivedSLI = |
557 has_received_sli_; | 564 has_received_sli_; |
558 codec_specific_info.codecSpecific.VP8.pictureIdRPSI = | 565 codec_specific_info.codecSpecific.VP8.pictureIdRPSI = |
559 picture_id_rpsi_; | 566 picture_id_rpsi_; |
560 codec_specific_info.codecSpecific.VP8.pictureIdSLI = | 567 codec_specific_info.codecSpecific.VP8.pictureIdSLI = |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
681 load_observer_->OnLoadUpdate(LoadObserver::kOveruse); | 688 load_observer_->OnLoadUpdate(LoadObserver::kOveruse); |
682 } | 689 } |
683 | 690 |
684 void ViEEncoder::NormalUsage() { | 691 void ViEEncoder::NormalUsage() { |
685 RTC_DCHECK_RUN_ON(&encoder_queue_); | 692 RTC_DCHECK_RUN_ON(&encoder_queue_); |
686 if (load_observer_) | 693 if (load_observer_) |
687 load_observer_->OnLoadUpdate(LoadObserver::kUnderuse); | 694 load_observer_->OnLoadUpdate(LoadObserver::kUnderuse); |
688 } | 695 } |
689 | 696 |
690 } // namespace webrtc | 697 } // namespace webrtc |
OLD | NEW |