| OLD | NEW |
| 1 /* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 1 /* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 2 * | 2 * |
| 3 * Use of this source code is governed by a BSD-style license | 3 * Use of this source code is governed by a BSD-style license |
| 4 * that can be found in the LICENSE file in the root of the source | 4 * that can be found in the LICENSE file in the root of the source |
| 5 * tree. An additional intellectual property rights grant can be found | 5 * tree. An additional intellectual property rights grant can be found |
| 6 * in the file PATENTS. All contributing project authors may | 6 * in the file PATENTS. All contributing project authors may |
| 7 * be found in the AUTHORS file in the root of the source tree. | 7 * be found in the AUTHORS file in the root of the source tree. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 #include "webrtc/modules/video_coding/codecs/vp8/screenshare_layers.h" | 10 #include "webrtc/modules/video_coding/codecs/vp8/screenshare_layers.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 namespace webrtc { | 23 namespace webrtc { |
| 24 | 24 |
| 25 static const int kOneSecond90Khz = 90000; | 25 static const int kOneSecond90Khz = 90000; |
| 26 static const int kMinTimeBetweenSyncs = kOneSecond90Khz * 5; | 26 static const int kMinTimeBetweenSyncs = kOneSecond90Khz * 5; |
| 27 static const int kMaxTimeBetweenSyncs = kOneSecond90Khz * 10; | 27 static const int kMaxTimeBetweenSyncs = kOneSecond90Khz * 10; |
| 28 static const int kQpDeltaThresholdForSync = 8; | 28 static const int kQpDeltaThresholdForSync = 8; |
| 29 | 29 |
| 30 const double ScreenshareLayers::kMaxTL0FpsReduction = 2.5; | 30 const double ScreenshareLayers::kMaxTL0FpsReduction = 2.5; |
| 31 const double ScreenshareLayers::kAcceptableTargetOvershoot = 2.0; | 31 const double ScreenshareLayers::kAcceptableTargetOvershoot = 2.0; |
| 32 | 32 |
| 33 constexpr int ScreenshareLayers::kMaxNumTemporalLayers; |
| 34 |
| 33 // Since this is TL0 we only allow updating and predicting from the LAST | 35 // Since this is TL0 we only allow updating and predicting from the LAST |
| 34 // reference frame. | 36 // reference frame. |
| 35 const int ScreenshareLayers::kTl0Flags = | 37 const int ScreenshareLayers::kTl0Flags = |
| 36 VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_REF_GF | | 38 VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_REF_GF | |
| 37 VP8_EFLAG_NO_REF_ARF; | 39 VP8_EFLAG_NO_REF_ARF; |
| 38 | 40 |
| 39 // Allow predicting from both TL0 and TL1. | 41 // Allow predicting from both TL0 and TL1. |
| 40 const int ScreenshareLayers::kTl1Flags = | 42 const int ScreenshareLayers::kTl1Flags = |
| 41 VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST; | 43 VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST; |
| 42 | 44 |
| 43 // Allow predicting from only TL0 to allow participants to switch to the high | 45 // Allow predicting from only TL0 to allow participants to switch to the high |
| 44 // bitrate stream. This means predicting only from the LAST reference frame, but | 46 // bitrate stream. This means predicting only from the LAST reference frame, but |
| 45 // only updating GF to not corrupt TL0. | 47 // only updating GF to not corrupt TL0. |
| 46 const int ScreenshareLayers::kTl1SyncFlags = | 48 const int ScreenshareLayers::kTl1SyncFlags = |
| 47 VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_UPD_ARF | | 49 VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_UPD_ARF | |
| 48 VP8_EFLAG_NO_UPD_LAST; | 50 VP8_EFLAG_NO_UPD_LAST; |
| 49 | 51 |
| 50 // Always emit a frame with certain interval, even if bitrate targets have | 52 // Always emit a frame with certain interval, even if bitrate targets have |
| 51 // been exceeded. | 53 // been exceeded. |
| 52 const int ScreenshareLayers::kMaxFrameIntervalMs = 2000; | 54 const int ScreenshareLayers::kMaxFrameIntervalMs = 2000; |
| 53 | 55 |
| 54 webrtc::TemporalLayers* ScreenshareTemporalLayersFactory::Create( | 56 webrtc::TemporalLayers* ScreenshareTemporalLayersFactory::Create( |
| 55 int simulcast_id, | 57 int simulcast_id, |
| 56 int num_temporal_layers, | 58 int num_temporal_layers, |
| 57 uint8_t initial_tl0_pic_idx) const { | 59 uint8_t initial_tl0_pic_idx) const { |
| 58 webrtc::TemporalLayers* tl = new webrtc::ScreenshareLayers( | 60 webrtc::TemporalLayers* tl; |
| 59 num_temporal_layers, rand(), webrtc::Clock::GetRealTimeClock()); | 61 if (simulcast_id == 0) { |
| 62 tl = new webrtc::ScreenshareLayers(num_temporal_layers, rand(), |
| 63 webrtc::Clock::GetRealTimeClock()); |
| 64 } else { |
| 65 RealTimeTemporalLayersFactory rt_tl_factory; |
| 66 tl = rt_tl_factory.Create(simulcast_id, num_temporal_layers, rand()); |
| 67 } |
| 60 if (listener_) | 68 if (listener_) |
| 61 listener_->OnTemporalLayersCreated(simulcast_id, tl); | 69 listener_->OnTemporalLayersCreated(simulcast_id, tl); |
| 62 return tl; | 70 return tl; |
| 63 } | 71 } |
| 64 | 72 |
| 65 ScreenshareLayers::ScreenshareLayers(int num_temporal_layers, | 73 ScreenshareLayers::ScreenshareLayers(int num_temporal_layers, |
| 66 uint8_t initial_tl0_pic_idx, | 74 uint8_t initial_tl0_pic_idx, |
| 67 Clock* clock) | 75 Clock* clock) |
| 68 : clock_(clock), | 76 : clock_(clock), |
| 69 number_of_temporal_layers_(num_temporal_layers), | 77 number_of_temporal_layers_( |
| 78 std::min(kMaxNumTemporalLayers, num_temporal_layers)), |
| 70 last_base_layer_sync_(false), | 79 last_base_layer_sync_(false), |
| 71 tl0_pic_idx_(initial_tl0_pic_idx), | 80 tl0_pic_idx_(initial_tl0_pic_idx), |
| 72 active_layer_(-1), | 81 active_layer_(-1), |
| 73 last_timestamp_(-1), | 82 last_timestamp_(-1), |
| 74 last_sync_timestamp_(-1), | 83 last_sync_timestamp_(-1), |
| 75 last_emitted_tl0_timestamp_(-1), | 84 last_emitted_tl0_timestamp_(-1), |
| 76 min_qp_(-1), | 85 min_qp_(-1), |
| 77 max_qp_(-1), | 86 max_qp_(-1), |
| 78 max_debt_bytes_(0), | 87 max_debt_bytes_(0), |
| 79 encode_framerate_(1000.0f, 1000.0f), // 1 second window, second scale. | 88 encode_framerate_(1000.0f, 1000.0f), // 1 second window, second scale. |
| 80 bitrate_updated_(false) { | 89 bitrate_updated_(false) { |
| 81 RTC_CHECK_GT(num_temporal_layers, 0); | 90 RTC_CHECK_GT(number_of_temporal_layers_, 0); |
| 82 RTC_CHECK_LE(num_temporal_layers, 2); | 91 RTC_CHECK_LE(number_of_temporal_layers_, kMaxNumTemporalLayers); |
| 83 } | 92 } |
| 84 | 93 |
| 85 ScreenshareLayers::~ScreenshareLayers() { | 94 ScreenshareLayers::~ScreenshareLayers() { |
| 86 UpdateHistograms(); | 95 UpdateHistograms(); |
| 87 } | 96 } |
| 88 | 97 |
| 89 int ScreenshareLayers::CurrentLayerId() const { | 98 int ScreenshareLayers::CurrentLayerId() const { |
| 90 // Codec does not use temporal layers for screenshare. | 99 // Codec does not use temporal layers for screenshare. |
| 91 return 0; | 100 return 0; |
| 92 } | 101 } |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.Screenshare.Layer1.Qp", | 416 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.Screenshare.Layer1.Qp", |
| 408 stats_.tl1_qp_sum_ / stats_.num_tl1_frames_); | 417 stats_.tl1_qp_sum_ / stats_.num_tl1_frames_); |
| 409 RTC_HISTOGRAM_COUNTS_10000( | 418 RTC_HISTOGRAM_COUNTS_10000( |
| 410 "WebRTC.Video.Screenshare.Layer1.TargetBitrate", | 419 "WebRTC.Video.Screenshare.Layer1.TargetBitrate", |
| 411 stats_.tl1_target_bitrate_sum_ / stats_.num_tl1_frames_); | 420 stats_.tl1_target_bitrate_sum_ / stats_.num_tl1_frames_); |
| 412 } | 421 } |
| 413 } | 422 } |
| 414 } | 423 } |
| 415 | 424 |
| 416 } // namespace webrtc | 425 } // namespace webrtc |
| OLD | NEW |