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/default_temporal_layers.h" | 10 #include "webrtc/modules/video_coding/codecs/vp8/default_temporal_layers.h" |
(...skipping 27 matching lines...) Expand all Loading... | |
38 golden, | 38 golden, |
39 arf, | 39 arf, |
40 (extra_flags & kLayerSync) != 0, | 40 (extra_flags & kLayerSync) != 0, |
41 (extra_flags & kFreezeEntropy) != 0) {} | 41 (extra_flags & kFreezeEntropy) != 0) {} |
42 | 42 |
43 TemporalReferences::TemporalReferences(TemporalBufferUsage last, | 43 TemporalReferences::TemporalReferences(TemporalBufferUsage last, |
44 TemporalBufferUsage golden, | 44 TemporalBufferUsage golden, |
45 TemporalBufferUsage arf, | 45 TemporalBufferUsage arf, |
46 bool layer_sync, | 46 bool layer_sync, |
47 bool freeze_entropy) | 47 bool freeze_entropy) |
48 : reference_last((last & kReference) != 0), | 48 : drop_frame(last == kNone && golden == kNone && arf == kNone), |
49 reference_last((last & kReference) != 0), | |
49 update_last((last & kUpdate) != 0), | 50 update_last((last & kUpdate) != 0), |
50 reference_golden((golden & kReference) != 0), | 51 reference_golden((golden & kReference) != 0), |
51 update_golden((golden & kUpdate) != 0), | 52 update_golden((golden & kUpdate) != 0), |
52 reference_arf((arf & kReference) != 0), | 53 reference_arf((arf & kReference) != 0), |
53 update_arf((arf & kUpdate) != 0), | 54 update_arf((arf & kUpdate) != 0), |
54 layer_sync(layer_sync), | 55 layer_sync(layer_sync), |
55 freeze_entropy(freeze_entropy) {} | 56 freeze_entropy(freeze_entropy) {} |
56 | 57 |
57 namespace { | 58 namespace { |
58 | 59 |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
239 cfg->ts_number_layers = num_layers_; | 240 cfg->ts_number_layers = num_layers_; |
240 cfg->ts_periodicity = temporal_ids_.size(); | 241 cfg->ts_periodicity = temporal_ids_.size(); |
241 memcpy(cfg->ts_layer_id, &temporal_ids_[0], | 242 memcpy(cfg->ts_layer_id, &temporal_ids_[0], |
242 sizeof(unsigned int) * temporal_ids_.size()); | 243 sizeof(unsigned int) * temporal_ids_.size()); |
243 | 244 |
244 new_bitrates_kbps_ = rtc::Optional<std::vector<uint32_t>>(); | 245 new_bitrates_kbps_ = rtc::Optional<std::vector<uint32_t>>(); |
245 | 246 |
246 return true; | 247 return true; |
247 } | 248 } |
248 | 249 |
249 int DefaultTemporalLayers::EncodeFlags(uint32_t timestamp) { | 250 // TODO(pbos): Name method so that it's obvious that it updates state. |
sprang_webrtc
2017/03/26 12:20:08
Not sure "get" makes it obvious state is changed e
pbos-webrtc
2017/03/27 16:31:07
I like update. Thanks.
| |
251 TemporalReferences DefaultTemporalLayers::GetLayerConfig(uint32_t timestamp) { | |
250 RTC_DCHECK_GT(num_layers_, 0); | 252 RTC_DCHECK_GT(num_layers_, 0); |
251 RTC_DCHECK_LT(0, temporal_pattern_.size()); | 253 RTC_DCHECK_LT(0, temporal_pattern_.size()); |
254 return temporal_pattern_[++pattern_idx_ % temporal_pattern_.size()]; | |
255 } | |
256 | |
257 int TemporalLayers::EncodeFlags(uint32_t timestamp) { | |
258 TemporalReferences references = GetLayerConfig(timestamp); | |
259 if (references.drop_frame) | |
260 return -1; | |
261 | |
252 int flags = 0; | 262 int flags = 0; |
253 // TODO(pbos): Move pattern-update out of EncodeFlags. It's not obvious that | |
254 // EncodeFlags() is non-const. | |
255 const TemporalReferences& references = | |
256 temporal_pattern_[++pattern_idx_ % temporal_pattern_.size()]; | |
257 | 263 |
258 if (!references.reference_last) | 264 if (!references.reference_last) |
259 flags |= VP8_EFLAG_NO_REF_LAST; | 265 flags |= VP8_EFLAG_NO_REF_LAST; |
260 if (!references.update_last) | 266 if (!references.update_last) |
261 flags |= VP8_EFLAG_NO_UPD_LAST; | 267 flags |= VP8_EFLAG_NO_UPD_LAST; |
262 if (!references.reference_golden) | 268 if (!references.reference_golden) |
263 flags |= VP8_EFLAG_NO_REF_GF; | 269 flags |= VP8_EFLAG_NO_REF_GF; |
264 if (!references.update_golden) | 270 if (!references.update_golden) |
265 flags |= VP8_EFLAG_NO_UPD_GF; | 271 flags |= VP8_EFLAG_NO_UPD_GF; |
266 if (!references.reference_arf) | 272 if (!references.reference_arf) |
267 flags |= VP8_EFLAG_NO_REF_ARF; | 273 flags |= VP8_EFLAG_NO_REF_ARF; |
268 if (!references.update_arf) | 274 if (!references.update_arf) |
269 flags |= VP8_EFLAG_NO_UPD_ARF; | 275 flags |= VP8_EFLAG_NO_UPD_ARF; |
270 if (references.freeze_entropy) | 276 if (references.freeze_entropy) |
271 flags |= VP8_EFLAG_NO_UPD_ENTROPY; | 277 flags |= VP8_EFLAG_NO_UPD_ENTROPY; |
272 | 278 |
273 return flags; | 279 return flags; |
274 } | 280 } |
275 | 281 |
276 void DefaultTemporalLayers::PopulateCodecSpecific( | 282 void DefaultTemporalLayers::PopulateCodecSpecific( |
277 bool base_layer_sync, | 283 bool frame_is_keyframe, |
278 CodecSpecificInfoVP8* vp8_info, | 284 CodecSpecificInfoVP8* vp8_info, |
279 uint32_t timestamp) { | 285 uint32_t timestamp) { |
280 RTC_DCHECK_GT(num_layers_, 0); | 286 RTC_DCHECK_GT(num_layers_, 0); |
281 | 287 |
282 if (num_layers_ == 1) { | 288 if (num_layers_ == 1) { |
283 vp8_info->temporalIdx = kNoTemporalIdx; | 289 vp8_info->temporalIdx = kNoTemporalIdx; |
284 vp8_info->layerSync = false; | 290 vp8_info->layerSync = false; |
285 vp8_info->tl0PicIdx = kNoTl0PicIdx; | 291 vp8_info->tl0PicIdx = kNoTl0PicIdx; |
286 } else { | 292 } else { |
287 if (base_layer_sync) { | 293 if (frame_is_keyframe) { |
288 vp8_info->temporalIdx = 0; | 294 vp8_info->temporalIdx = 0; |
289 vp8_info->layerSync = true; | 295 vp8_info->layerSync = true; |
290 } else { | 296 } else { |
291 vp8_info->temporalIdx = CurrentLayerId(); | 297 vp8_info->temporalIdx = CurrentLayerId(); |
292 TemporalReferences temporal_reference = | 298 TemporalReferences temporal_reference = |
293 temporal_pattern_[pattern_idx_ % temporal_pattern_.size()]; | 299 temporal_pattern_[pattern_idx_ % temporal_pattern_.size()]; |
294 | 300 |
295 vp8_info->layerSync = temporal_reference.layer_sync; | 301 vp8_info->layerSync = temporal_reference.layer_sync; |
296 } | 302 } |
297 if (last_base_layer_sync_ && vp8_info->temporalIdx != 0) { | 303 if (last_base_layer_sync_ && vp8_info->temporalIdx != 0) { |
298 // Regardless of pattern the frame after a base layer sync will always | 304 // Regardless of pattern the frame after a base layer sync will always |
299 // be a layer sync. | 305 // be a layer sync. |
300 vp8_info->layerSync = true; | 306 vp8_info->layerSync = true; |
301 } | 307 } |
302 if (vp8_info->temporalIdx == 0 && timestamp != timestamp_) { | 308 if (vp8_info->temporalIdx == 0 && timestamp != timestamp_) { |
303 timestamp_ = timestamp; | 309 timestamp_ = timestamp; |
304 tl0_pic_idx_++; | 310 tl0_pic_idx_++; |
305 } | 311 } |
306 last_base_layer_sync_ = base_layer_sync; | 312 last_base_layer_sync_ = frame_is_keyframe; |
307 vp8_info->tl0PicIdx = tl0_pic_idx_; | 313 vp8_info->tl0PicIdx = tl0_pic_idx_; |
308 } | 314 } |
309 } | 315 } |
310 | 316 |
311 TemporalLayers* TemporalLayersFactory::Create( | 317 TemporalLayers* TemporalLayersFactory::Create( |
312 int simulcast_id, | 318 int simulcast_id, |
313 int temporal_layers, | 319 int temporal_layers, |
314 uint8_t initial_tl0_pic_idx) const { | 320 uint8_t initial_tl0_pic_idx) const { |
315 TemporalLayers* tl = | 321 TemporalLayers* tl = |
316 new DefaultTemporalLayers(temporal_layers, initial_tl0_pic_idx); | 322 new DefaultTemporalLayers(temporal_layers, initial_tl0_pic_idx); |
317 if (listener_) | 323 if (listener_) |
318 listener_->OnTemporalLayersCreated(simulcast_id, tl); | 324 listener_->OnTemporalLayersCreated(simulcast_id, tl); |
319 return tl; | 325 return tl; |
320 } | 326 } |
321 | 327 |
322 void TemporalLayersFactory::SetListener(TemporalLayersListener* listener) { | 328 void TemporalLayersFactory::SetListener(TemporalLayersListener* listener) { |
323 listener_ = listener; | 329 listener_ = listener; |
324 } | 330 } |
325 | 331 |
326 } // namespace webrtc | 332 } // namespace webrtc |
OLD | NEW |