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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 DegradationPreference degradation_preference_ GUARDED_BY(&crit_); | 249 DegradationPreference degradation_preference_ GUARDED_BY(&crit_); |
250 rtc::VideoSourceInterface<VideoFrame>* source_ GUARDED_BY(&crit_); | 250 rtc::VideoSourceInterface<VideoFrame>* source_ GUARDED_BY(&crit_); |
251 | 251 |
252 RTC_DISALLOW_COPY_AND_ASSIGN(VideoSourceProxy); | 252 RTC_DISALLOW_COPY_AND_ASSIGN(VideoSourceProxy); |
253 }; | 253 }; |
254 | 254 |
255 ViEEncoder::ViEEncoder(uint32_t number_of_cores, | 255 ViEEncoder::ViEEncoder(uint32_t number_of_cores, |
256 SendStatisticsProxy* stats_proxy, | 256 SendStatisticsProxy* stats_proxy, |
257 const VideoSendStream::Config::EncoderSettings& settings, | 257 const VideoSendStream::Config::EncoderSettings& settings, |
258 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, | 258 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, |
259 EncodedFrameObserver* encoder_timing) | 259 EncodedFrameObserver* encoder_timing, |
| 260 VideoEncoderConfig::ContentType content_type) |
260 : shutdown_event_(true /* manual_reset */, false), | 261 : shutdown_event_(true /* manual_reset */, false), |
261 number_of_cores_(number_of_cores), | 262 number_of_cores_(number_of_cores), |
262 initial_rampup_(0), | 263 initial_rampup_(0), |
263 source_proxy_(new VideoSourceProxy(this)), | 264 source_proxy_(new VideoSourceProxy(this)), |
264 sink_(nullptr), | 265 sink_(nullptr), |
265 settings_(settings), | 266 settings_(settings), |
266 codec_type_(PayloadNameToCodecType(settings.payload_name) | 267 codec_type_(PayloadNameToCodecType(settings.payload_name) |
267 .value_or(VideoCodecType::kVideoCodecUnknown)), | 268 .value_or(VideoCodecType::kVideoCodecUnknown)), |
| 269 content_type_(content_type), |
268 video_sender_(Clock::GetRealTimeClock(), this, this), | 270 video_sender_(Clock::GetRealTimeClock(), this, this), |
269 overuse_detector_(GetCpuOveruseOptions(settings.full_overuse_time), | 271 overuse_detector_(GetCpuOveruseOptions(settings.full_overuse_time), |
270 this, | 272 this, |
271 encoder_timing, | 273 encoder_timing, |
272 stats_proxy), | 274 stats_proxy), |
273 stats_proxy_(stats_proxy), | 275 stats_proxy_(stats_proxy), |
274 pre_encode_callback_(pre_encode_callback), | 276 pre_encode_callback_(pre_encode_callback), |
275 module_process_thread_(nullptr), | 277 module_process_thread_(nullptr), |
276 pending_encoder_reconfiguration_(false), | 278 pending_encoder_reconfiguration_(false), |
277 encoder_start_bitrate_bps_(0), | 279 encoder_start_bitrate_bps_(0), |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 encoder_config_ = std::move(config); | 403 encoder_config_ = std::move(config); |
402 pending_encoder_reconfiguration_ = true; | 404 pending_encoder_reconfiguration_ = true; |
403 | 405 |
404 // Reconfigure the encoder now if the encoder has an internal source or | 406 // Reconfigure the encoder now if the encoder has an internal source or |
405 // if the frame resolution is known. Otherwise, the reconfiguration is | 407 // if the frame resolution is known. Otherwise, the reconfiguration is |
406 // deferred until the next frame to minimize the number of reconfigurations. | 408 // deferred until the next frame to minimize the number of reconfigurations. |
407 // The codec configuration depends on incoming video frame size. | 409 // The codec configuration depends on incoming video frame size. |
408 if (last_frame_info_) { | 410 if (last_frame_info_) { |
409 ReconfigureEncoder(); | 411 ReconfigureEncoder(); |
410 } else if (settings_.internal_source) { | 412 } else if (settings_.internal_source) { |
411 last_frame_info_ = rtc::Optional<VideoFrameInfo>( | 413 last_frame_info_ = rtc::Optional<VideoFrameInfo>(VideoFrameInfo( |
412 VideoFrameInfo(176, 144, kVideoRotation_0, false)); | 414 176, 144, kVideoRotation_0, kVideoContent_Default, false)); |
413 ReconfigureEncoder(); | 415 ReconfigureEncoder(); |
414 } | 416 } |
415 } | 417 } |
416 | 418 |
417 void ViEEncoder::ReconfigureEncoder() { | 419 void ViEEncoder::ReconfigureEncoder() { |
418 RTC_DCHECK_RUN_ON(&encoder_queue_); | 420 RTC_DCHECK_RUN_ON(&encoder_queue_); |
419 RTC_DCHECK(pending_encoder_reconfiguration_); | 421 RTC_DCHECK(pending_encoder_reconfiguration_); |
420 std::vector<VideoStream> streams = | 422 std::vector<VideoStream> streams = |
421 encoder_config_.video_stream_factory->CreateEncoderStreams( | 423 encoder_config_.video_stream_factory->CreateEncoderStreams( |
422 last_frame_info_->width, last_frame_info_->height, encoder_config_); | 424 last_frame_info_->width, last_frame_info_->height, encoder_config_); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 initial_rampup_ = kMaxInitialFramedrop; | 478 initial_rampup_ = kMaxInitialFramedrop; |
477 } | 479 } |
478 stats_proxy_->SetResolutionRestrictionStats( | 480 stats_proxy_->SetResolutionRestrictionStats( |
479 degradation_preference_allows_scaling, scale_counter_[kCpu] > 0, | 481 degradation_preference_allows_scaling, scale_counter_[kCpu] > 0, |
480 scale_counter_[kQuality]); | 482 scale_counter_[kQuality]); |
481 } | 483 } |
482 | 484 |
483 void ViEEncoder::OnFrame(const VideoFrame& video_frame) { | 485 void ViEEncoder::OnFrame(const VideoFrame& video_frame) { |
484 RTC_DCHECK_RUNS_SERIALIZED(&incoming_frame_race_checker_); | 486 RTC_DCHECK_RUNS_SERIALIZED(&incoming_frame_race_checker_); |
485 VideoFrame incoming_frame = video_frame; | 487 VideoFrame incoming_frame = video_frame; |
486 | 488 if (content_type_ == VideoEncoderConfig::ContentType::kScreen) |
| 489 incoming_frame.set_content_type(kVideoContent_Screenshare); |
487 // Local time in webrtc time base. | 490 // Local time in webrtc time base. |
488 int64_t current_time_us = clock_->TimeInMicroseconds(); | 491 int64_t current_time_us = clock_->TimeInMicroseconds(); |
489 int64_t current_time_ms = current_time_us / rtc::kNumMicrosecsPerMillisec; | 492 int64_t current_time_ms = current_time_us / rtc::kNumMicrosecsPerMillisec; |
490 // TODO(nisse): This always overrides the incoming timestamp. Don't | 493 // TODO(nisse): This always overrides the incoming timestamp. Don't |
491 // do that, trust the frame source. | 494 // do that, trust the frame source. |
492 incoming_frame.set_timestamp_us(current_time_us); | 495 incoming_frame.set_timestamp_us(current_time_us); |
493 | 496 |
494 // Capture time may come from clock with an offset and drift from clock_. | 497 // Capture time may come from clock with an offset and drift from clock_. |
495 int64_t capture_ntp_time_ms; | 498 int64_t capture_ntp_time_ms; |
496 if (video_frame.ntp_time_ms() > 0) { | 499 if (video_frame.ntp_time_ms() > 0) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 RTC_DCHECK_RUN_ON(&encoder_queue_); | 563 RTC_DCHECK_RUN_ON(&encoder_queue_); |
561 | 564 |
562 if (pre_encode_callback_) | 565 if (pre_encode_callback_) |
563 pre_encode_callback_->OnFrame(video_frame); | 566 pre_encode_callback_->OnFrame(video_frame); |
564 | 567 |
565 if (!last_frame_info_ || video_frame.width() != last_frame_info_->width || | 568 if (!last_frame_info_ || video_frame.width() != last_frame_info_->width || |
566 video_frame.height() != last_frame_info_->height || | 569 video_frame.height() != last_frame_info_->height || |
567 video_frame.rotation() != last_frame_info_->rotation || | 570 video_frame.rotation() != last_frame_info_->rotation || |
568 video_frame.is_texture() != last_frame_info_->is_texture) { | 571 video_frame.is_texture() != last_frame_info_->is_texture) { |
569 pending_encoder_reconfiguration_ = true; | 572 pending_encoder_reconfiguration_ = true; |
570 last_frame_info_ = rtc::Optional<VideoFrameInfo>( | 573 last_frame_info_ = rtc::Optional<VideoFrameInfo>(VideoFrameInfo( |
571 VideoFrameInfo(video_frame.width(), video_frame.height(), | 574 video_frame.width(), video_frame.height(), video_frame.rotation(), |
572 video_frame.rotation(), video_frame.is_texture())); | 575 video_frame.content_type(), video_frame.is_texture())); |
573 LOG(LS_INFO) << "Video frame parameters changed: dimensions=" | 576 LOG(LS_INFO) << "Video frame parameters changed: dimensions=" |
574 << last_frame_info_->width << "x" << last_frame_info_->height | 577 << last_frame_info_->width << "x" << last_frame_info_->height |
575 << ", rotation=" << last_frame_info_->rotation | 578 << ", rotation=" << last_frame_info_->rotation |
576 << ", texture=" << last_frame_info_->is_texture; | 579 << ", texture=" << last_frame_info_->is_texture; |
577 } | 580 } |
578 | 581 |
579 if (initial_rampup_ < kMaxInitialFramedrop && | 582 if (initial_rampup_ < kMaxInitialFramedrop && |
580 video_frame.size() > | 583 video_frame.size() > |
581 MaximumFrameSizeForBitrate(encoder_start_bitrate_bps_ / 1000)) { | 584 MaximumFrameSizeForBitrate(encoder_start_bitrate_bps_ / 1000)) { |
582 LOG(LS_INFO) << "Dropping frame. Too large for target bitrate."; | 585 LOG(LS_INFO) << "Dropping frame. Too large for target bitrate."; |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 --scale_counter_[reason]; | 812 --scale_counter_[reason]; |
810 source_proxy_->RequestHigherResolutionThan(current_pixel_count); | 813 source_proxy_->RequestHigherResolutionThan(current_pixel_count); |
811 LOG(LS_INFO) << "Scaling up resolution."; | 814 LOG(LS_INFO) << "Scaling up resolution."; |
812 for (size_t i = 0; i < kScaleReasonSize; ++i) { | 815 for (size_t i = 0; i < kScaleReasonSize; ++i) { |
813 LOG(LS_INFO) << "Scaled " << scale_counter_[i] | 816 LOG(LS_INFO) << "Scaled " << scale_counter_[i] |
814 << " times for reason: " << (i ? "cpu" : "quality"); | 817 << " times for reason: " << (i ? "cpu" : "quality"); |
815 } | 818 } |
816 } | 819 } |
817 | 820 |
818 } // namespace webrtc | 821 } // namespace webrtc |
OLD | NEW |