Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(515)

Side by Side Diff: webrtc/modules/video_coding/codecs/vp8/screenshare_layers.cc

Issue 2924993002: Move temporal-layer properties to FrameConfig. (Closed)
Patch Set: improve unittests Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 encode_framerate_(1000.0f, 1000.0f), // 1 second window, second scale. 72 encode_framerate_(1000.0f, 1000.0f), // 1 second window, second scale.
73 bitrate_updated_(false) { 73 bitrate_updated_(false) {
74 RTC_CHECK_GT(number_of_temporal_layers_, 0); 74 RTC_CHECK_GT(number_of_temporal_layers_, 0);
75 RTC_CHECK_LE(number_of_temporal_layers_, kMaxNumTemporalLayers); 75 RTC_CHECK_LE(number_of_temporal_layers_, kMaxNumTemporalLayers);
76 } 76 }
77 77
78 ScreenshareLayers::~ScreenshareLayers() { 78 ScreenshareLayers::~ScreenshareLayers() {
79 UpdateHistograms(); 79 UpdateHistograms();
80 } 80 }
81 81
82 int ScreenshareLayers::GetTemporalLayerId(
83 const TemporalLayers::FrameConfig& tl_config) const {
84 // Codec does not use temporal layers for screenshare.
85 return 0;
86 }
87
88 uint8_t ScreenshareLayers::Tl0PicIdx() const { 82 uint8_t ScreenshareLayers::Tl0PicIdx() const {
89 return tl0_pic_idx_; 83 return tl0_pic_idx_;
90 } 84 }
91 85
92 TemporalLayers::FrameConfig ScreenshareLayers::UpdateLayerConfig( 86 TemporalLayers::FrameConfig ScreenshareLayers::UpdateLayerConfig(
93 uint32_t timestamp) { 87 uint32_t timestamp) {
94 if (number_of_temporal_layers_ <= 1) { 88 if (number_of_temporal_layers_ <= 1) {
95 // No flags needed for 1 layer screenshare. 89 // No flags needed for 1 layer screenshare.
96 // TODO(pbos): Consider updating only last, and not all buffers. 90 // TODO(pbos): Consider updating only last, and not all buffers.
97 TemporalLayers::FrameConfig tl_config( 91 TemporalLayers::FrameConfig tl_config(
98 kReferenceAndUpdate, kReferenceAndUpdate, kReferenceAndUpdate); 92 kReferenceAndUpdate, kReferenceAndUpdate, kReferenceAndUpdate);
99 tl_config.pattern_idx = static_cast<int>(TemporalLayerState::kTl1);
100 return tl_config; 93 return tl_config;
101 } 94 }
102 95
103 const int64_t now_ms = clock_->TimeInMilliseconds(); 96 const int64_t now_ms = clock_->TimeInMilliseconds();
104 if (target_framerate_.value_or(0) > 0 && 97 if (target_framerate_.value_or(0) > 0 &&
105 encode_framerate_.Rate(now_ms).value_or(0) > *target_framerate_) { 98 encode_framerate_.Rate(now_ms).value_or(0) > *target_framerate_) {
106 // Max framerate exceeded, drop frame. 99 // Max framerate exceeded, drop frame.
107 return TemporalLayers::FrameConfig(kNone, kNone, kNone); 100 return TemporalLayers::FrameConfig(kNone, kNone, kNone);
108 } 101 }
109 102
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 // TODO(pbos): Consider referencing but not updating the 'alt' buffer for all 170 // TODO(pbos): Consider referencing but not updating the 'alt' buffer for all
178 // layers. 171 // layers.
179 switch (layer_state) { 172 switch (layer_state) {
180 case TemporalLayerState::kDrop: 173 case TemporalLayerState::kDrop:
181 tl_config = TemporalLayers::FrameConfig(kNone, kNone, kNone); 174 tl_config = TemporalLayers::FrameConfig(kNone, kNone, kNone);
182 break; 175 break;
183 case TemporalLayerState::kTl0: 176 case TemporalLayerState::kTl0:
184 // TL0 only references and updates 'last'. 177 // TL0 only references and updates 'last'.
185 tl_config = 178 tl_config =
186 TemporalLayers::FrameConfig(kReferenceAndUpdate, kNone, kNone); 179 TemporalLayers::FrameConfig(kReferenceAndUpdate, kNone, kNone);
180 tl_config.packetizer_temporal_idx = 0;
187 break; 181 break;
188 case TemporalLayerState::kTl1: 182 case TemporalLayerState::kTl1:
189 // TL1 references both 'last' and 'golden' but only updates 'golden'. 183 // TL1 references both 'last' and 'golden' but only updates 'golden'.
190 tl_config = 184 tl_config =
191 TemporalLayers::FrameConfig(kReference, kReferenceAndUpdate, kNone); 185 TemporalLayers::FrameConfig(kReference, kReferenceAndUpdate, kNone);
186 tl_config.packetizer_temporal_idx = 1;
192 break; 187 break;
193 case TemporalLayerState::kTl1Sync: 188 case TemporalLayerState::kTl1Sync:
194 // Predict from only TL0 to allow participants to switch to the high 189 // Predict from only TL0 to allow participants to switch to the high
195 // bitrate stream. Updates 'golden' so that TL1 can continue to refer to 190 // bitrate stream. Updates 'golden' so that TL1 can continue to refer to
196 // and update 'golden' from this point on. 191 // and update 'golden' from this point on.
197 tl_config = TemporalLayers::FrameConfig(kReference, kUpdate, kNone); 192 tl_config = TemporalLayers::FrameConfig(kReference, kUpdate, kNone);
193 tl_config.packetizer_temporal_idx = 1;
198 break; 194 break;
199 } 195 }
200 196
201 tl_config.pattern_idx = static_cast<int>(layer_state); 197 tl_config.layer_sync = layer_state == TemporalLayerState::kTl1Sync;
202 return tl_config; 198 return tl_config;
203 } 199 }
204 200
205 std::vector<uint32_t> ScreenshareLayers::OnRatesUpdated(int bitrate_kbps, 201 std::vector<uint32_t> ScreenshareLayers::OnRatesUpdated(int bitrate_kbps,
206 int max_bitrate_kbps, 202 int max_bitrate_kbps,
207 int framerate) { 203 int framerate) {
208 RTC_DCHECK_GT(framerate, 0); 204 RTC_DCHECK_GT(framerate, 0);
209 if (!target_framerate_) { 205 if (!target_framerate_) {
210 // First OnRatesUpdated() is called during construction, with the configured 206 // First OnRatesUpdated() is called during construction, with the configured
211 // targets as parameters. 207 // targets as parameters.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 stats_.tl1_target_bitrate_sum_ += layers_[1].target_rate_kbps_; 264 stats_.tl1_target_bitrate_sum_ += layers_[1].target_rate_kbps_;
269 stats_.tl1_qp_sum_ += qp; 265 stats_.tl1_qp_sum_ += qp;
270 } 266 }
271 } 267 }
272 268
273 void ScreenshareLayers::PopulateCodecSpecific( 269 void ScreenshareLayers::PopulateCodecSpecific(
274 bool frame_is_keyframe, 270 bool frame_is_keyframe,
275 const TemporalLayers::FrameConfig& tl_config, 271 const TemporalLayers::FrameConfig& tl_config,
276 CodecSpecificInfoVP8* vp8_info, 272 CodecSpecificInfoVP8* vp8_info,
277 uint32_t timestamp) { 273 uint32_t timestamp) {
278 int64_t unwrapped_timestamp = time_wrap_handler_.Unwrap(timestamp);
279 if (number_of_temporal_layers_ == 1) { 274 if (number_of_temporal_layers_ == 1) {
280 vp8_info->temporalIdx = kNoTemporalIdx; 275 vp8_info->temporalIdx = kNoTemporalIdx;
281 vp8_info->layerSync = false; 276 vp8_info->layerSync = false;
282 vp8_info->tl0PicIdx = kNoTl0PicIdx; 277 vp8_info->tl0PicIdx = kNoTl0PicIdx;
283 } else { 278 } else {
284 TemporalLayerState layer_state = 279 int64_t unwrapped_timestamp = time_wrap_handler_.Unwrap(timestamp);
285 static_cast<TemporalLayerState>(tl_config.pattern_idx); 280 vp8_info->temporalIdx = tl_config.packetizer_temporal_idx;
286 switch (layer_state) { 281 vp8_info->layerSync = tl_config.layer_sync;
287 case TemporalLayerState::kDrop:
288 RTC_NOTREACHED();
289 break;
290 case TemporalLayerState::kTl0:
291 vp8_info->temporalIdx = 0;
292 break;
293 case TemporalLayerState::kTl1:
294 case TemporalLayerState::kTl1Sync:
295 vp8_info->temporalIdx = 1;
296 break;
297 }
298 if (frame_is_keyframe) { 282 if (frame_is_keyframe) {
299 vp8_info->temporalIdx = 0; 283 vp8_info->temporalIdx = 0;
300 last_sync_timestamp_ = unwrapped_timestamp; 284 last_sync_timestamp_ = unwrapped_timestamp;
285 vp8_info->layerSync = true;
301 } else if (last_base_layer_sync_ && vp8_info->temporalIdx != 0) { 286 } else if (last_base_layer_sync_ && vp8_info->temporalIdx != 0) {
302 // Regardless of pattern the frame after a base layer sync will always 287 // Regardless of pattern the frame after a base layer sync will always
303 // be a layer sync. 288 // be a layer sync.
304 last_sync_timestamp_ = unwrapped_timestamp; 289 last_sync_timestamp_ = unwrapped_timestamp;
290 vp8_info->layerSync = true;
305 } 291 }
306 vp8_info->layerSync = last_sync_timestamp_ != -1 &&
307 last_sync_timestamp_ == unwrapped_timestamp;
308 if (vp8_info->temporalIdx == 0) { 292 if (vp8_info->temporalIdx == 0) {
309 tl0_pic_idx_++; 293 tl0_pic_idx_++;
310 } 294 }
311 last_base_layer_sync_ = frame_is_keyframe; 295 last_base_layer_sync_ = frame_is_keyframe;
312 vp8_info->tl0PicIdx = tl0_pic_idx_; 296 vp8_info->tl0PicIdx = tl0_pic_idx_;
313 } 297 }
314 } 298 }
315 299
316 bool ScreenshareLayers::TimeToSync(int64_t timestamp) const { 300 bool ScreenshareLayers::TimeToSync(int64_t timestamp) const {
317 RTC_DCHECK_EQ(1, active_layer_); 301 RTC_DCHECK_EQ(1, active_layer_);
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.Screenshare.Layer1.Qp", 450 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.Screenshare.Layer1.Qp",
467 stats_.tl1_qp_sum_ / stats_.num_tl1_frames_); 451 stats_.tl1_qp_sum_ / stats_.num_tl1_frames_);
468 RTC_HISTOGRAM_COUNTS_10000( 452 RTC_HISTOGRAM_COUNTS_10000(
469 "WebRTC.Video.Screenshare.Layer1.TargetBitrate", 453 "WebRTC.Video.Screenshare.Layer1.TargetBitrate",
470 stats_.tl1_target_bitrate_sum_ / stats_.num_tl1_frames_); 454 stats_.tl1_target_bitrate_sum_ / stats_.num_tl1_frames_);
471 } 455 }
472 } 456 }
473 } 457 }
474 458
475 } // namespace webrtc 459 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698