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 | |
35 // Since this is TL0 we only allow updating and predicting from the LAST | 33 // Since this is TL0 we only allow updating and predicting from the LAST |
36 // reference frame. | 34 // reference frame. |
37 const int ScreenshareLayers::kTl0Flags = | 35 const int ScreenshareLayers::kTl0Flags = |
38 VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_REF_GF | | 36 VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_REF_GF | |
39 VP8_EFLAG_NO_REF_ARF; | 37 VP8_EFLAG_NO_REF_ARF; |
40 | 38 |
41 // Allow predicting from both TL0 and TL1. | 39 // Allow predicting from both TL0 and TL1. |
42 const int ScreenshareLayers::kTl1Flags = | 40 const int ScreenshareLayers::kTl1Flags = |
43 VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST; | 41 VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST; |
44 | 42 |
45 // Allow predicting from only TL0 to allow participants to switch to the high | 43 // Allow predicting from only TL0 to allow participants to switch to the high |
46 // bitrate stream. This means predicting only from the LAST reference frame, but | 44 // bitrate stream. This means predicting only from the LAST reference frame, but |
47 // only updating GF to not corrupt TL0. | 45 // only updating GF to not corrupt TL0. |
48 const int ScreenshareLayers::kTl1SyncFlags = | 46 const int ScreenshareLayers::kTl1SyncFlags = |
49 VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_UPD_ARF | | 47 VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_UPD_ARF | |
50 VP8_EFLAG_NO_UPD_LAST; | 48 VP8_EFLAG_NO_UPD_LAST; |
51 | 49 |
52 // Always emit a frame with certain interval, even if bitrate targets have | 50 // Always emit a frame with certain interval, even if bitrate targets have |
53 // been exceeded. | 51 // been exceeded. |
54 const int ScreenshareLayers::kMaxFrameIntervalMs = 2000; | 52 const int ScreenshareLayers::kMaxFrameIntervalMs = 2000; |
55 | 53 |
56 webrtc::TemporalLayers* ScreenshareTemporalLayersFactory::Create( | 54 webrtc::TemporalLayers* ScreenshareTemporalLayersFactory::Create( |
57 int simulcast_id, | 55 int simulcast_id, |
58 int num_temporal_layers, | 56 int num_temporal_layers, |
59 uint8_t initial_tl0_pic_idx) const { | 57 uint8_t initial_tl0_pic_idx) const { |
60 webrtc::TemporalLayers* tl; | 58 webrtc::TemporalLayers* tl = new webrtc::ScreenshareLayers( |
61 if (simulcast_id == 0) { | 59 num_temporal_layers, rand(), webrtc::Clock::GetRealTimeClock()); |
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 } | |
68 if (listener_) | 60 if (listener_) |
69 listener_->OnTemporalLayersCreated(simulcast_id, tl); | 61 listener_->OnTemporalLayersCreated(simulcast_id, tl); |
70 return tl; | 62 return tl; |
71 } | 63 } |
72 | 64 |
73 ScreenshareLayers::ScreenshareLayers(int num_temporal_layers, | 65 ScreenshareLayers::ScreenshareLayers(int num_temporal_layers, |
74 uint8_t initial_tl0_pic_idx, | 66 uint8_t initial_tl0_pic_idx, |
75 Clock* clock) | 67 Clock* clock) |
76 : clock_(clock), | 68 : clock_(clock), |
77 number_of_temporal_layers_( | 69 number_of_temporal_layers_(num_temporal_layers), |
78 std::min(kMaxNumTemporalLayers, num_temporal_layers)), | |
79 last_base_layer_sync_(false), | 70 last_base_layer_sync_(false), |
80 tl0_pic_idx_(initial_tl0_pic_idx), | 71 tl0_pic_idx_(initial_tl0_pic_idx), |
81 active_layer_(-1), | 72 active_layer_(-1), |
82 last_timestamp_(-1), | 73 last_timestamp_(-1), |
83 last_sync_timestamp_(-1), | 74 last_sync_timestamp_(-1), |
84 last_emitted_tl0_timestamp_(-1), | 75 last_emitted_tl0_timestamp_(-1), |
85 min_qp_(-1), | 76 min_qp_(-1), |
86 max_qp_(-1), | 77 max_qp_(-1), |
87 max_debt_bytes_(0), | 78 max_debt_bytes_(0), |
88 encode_framerate_(1000.0f, 1000.0f), // 1 second window, second scale. | 79 encode_framerate_(1000.0f, 1000.0f), // 1 second window, second scale. |
89 bitrate_updated_(false) { | 80 bitrate_updated_(false) { |
90 RTC_CHECK_GT(number_of_temporal_layers_, 0); | 81 RTC_CHECK_GT(num_temporal_layers, 0); |
91 RTC_CHECK_LE(number_of_temporal_layers_, kMaxNumTemporalLayers); | 82 RTC_CHECK_LE(num_temporal_layers, 2); |
92 } | 83 } |
93 | 84 |
94 ScreenshareLayers::~ScreenshareLayers() { | 85 ScreenshareLayers::~ScreenshareLayers() { |
95 UpdateHistograms(); | 86 UpdateHistograms(); |
96 } | 87 } |
97 | 88 |
98 int ScreenshareLayers::CurrentLayerId() const { | 89 int ScreenshareLayers::CurrentLayerId() const { |
99 // Codec does not use temporal layers for screenshare. | 90 // Codec does not use temporal layers for screenshare. |
100 return 0; | 91 return 0; |
101 } | 92 } |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.Screenshare.Layer1.Qp", | 407 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.Screenshare.Layer1.Qp", |
417 stats_.tl1_qp_sum_ / stats_.num_tl1_frames_); | 408 stats_.tl1_qp_sum_ / stats_.num_tl1_frames_); |
418 RTC_HISTOGRAM_COUNTS_10000( | 409 RTC_HISTOGRAM_COUNTS_10000( |
419 "WebRTC.Video.Screenshare.Layer1.TargetBitrate", | 410 "WebRTC.Video.Screenshare.Layer1.TargetBitrate", |
420 stats_.tl1_target_bitrate_sum_ / stats_.num_tl1_frames_); | 411 stats_.tl1_target_bitrate_sum_ / stats_.num_tl1_frames_); |
421 } | 412 } |
422 } | 413 } |
423 } | 414 } |
424 | 415 |
425 } // namespace webrtc | 416 } // namespace webrtc |
OLD | NEW |