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 23 matching lines...) Expand all Loading... |
34 assert(kMaxTemporalStreams >= numberOfTemporalLayers); | 34 assert(kMaxTemporalStreams >= numberOfTemporalLayers); |
35 memset(temporal_ids_, 0, sizeof(temporal_ids_)); | 35 memset(temporal_ids_, 0, sizeof(temporal_ids_)); |
36 memset(temporal_pattern_, 0, sizeof(temporal_pattern_)); | 36 memset(temporal_pattern_, 0, sizeof(temporal_pattern_)); |
37 } | 37 } |
38 | 38 |
39 int DefaultTemporalLayers::CurrentLayerId() const { | 39 int DefaultTemporalLayers::CurrentLayerId() const { |
40 assert(temporal_ids_length_ > 0); | 40 assert(temporal_ids_length_ > 0); |
41 int index = pattern_idx_ % temporal_ids_length_; | 41 int index = pattern_idx_ % temporal_ids_length_; |
42 assert(index >= 0); | 42 assert(index >= 0); |
43 return temporal_ids_[index]; | 43 return temporal_ids_[index]; |
44 } | 44 } |
45 | 45 |
46 bool DefaultTemporalLayers::ConfigureBitrates(int bitrateKbit, | 46 bool DefaultTemporalLayers::ConfigureBitrates(int bitrateKbit, |
47 int max_bitrate_kbit, | 47 int max_bitrate_kbit, |
48 int framerate, | 48 int framerate, |
49 vpx_codec_enc_cfg_t* cfg) { | 49 vpx_codec_enc_cfg_t* cfg) { |
50 switch (number_of_temporal_layers_) { | 50 switch (number_of_temporal_layers_) { |
51 case 0: | 51 case 0: |
52 case 1: | 52 case 1: |
53 temporal_ids_length_ = 1; | 53 temporal_ids_length_ = 1; |
54 temporal_ids_[0] = 0; | 54 temporal_ids_[0] = 0; |
55 cfg->ts_number_layers = number_of_temporal_layers_; | 55 cfg->ts_number_layers = number_of_temporal_layers_; |
56 cfg->ts_periodicity = temporal_ids_length_; | 56 cfg->ts_periodicity = temporal_ids_length_; |
57 cfg->ts_target_bitrate[0] = bitrateKbit; | 57 cfg->ts_target_bitrate[0] = bitrateKbit; |
58 cfg->ts_rate_decimator[0] = 1; | 58 cfg->ts_rate_decimator[0] = 1; |
59 memcpy(cfg->ts_layer_id, | 59 memcpy(cfg->ts_layer_id, temporal_ids_, |
60 temporal_ids_, | |
61 sizeof(unsigned int) * temporal_ids_length_); | 60 sizeof(unsigned int) * temporal_ids_length_); |
62 temporal_pattern_length_ = 1; | 61 temporal_pattern_length_ = 1; |
63 temporal_pattern_[0] = kTemporalUpdateLastRefAll; | 62 temporal_pattern_[0] = kTemporalUpdateLastRefAll; |
64 break; | 63 break; |
65 case 2: | 64 case 2: |
66 temporal_ids_length_ = 2; | 65 temporal_ids_length_ = 2; |
67 temporal_ids_[0] = 0; | 66 temporal_ids_[0] = 0; |
68 temporal_ids_[1] = 1; | 67 temporal_ids_[1] = 1; |
69 cfg->ts_number_layers = number_of_temporal_layers_; | 68 cfg->ts_number_layers = number_of_temporal_layers_; |
70 cfg->ts_periodicity = temporal_ids_length_; | 69 cfg->ts_periodicity = temporal_ids_length_; |
71 // Split stream 60% 40%. | 70 // Split stream 60% 40%. |
72 // Bitrate API for VP8 is the agregated bitrate for all lower layers. | 71 // Bitrate API for VP8 is the agregated bitrate for all lower layers. |
73 cfg->ts_target_bitrate[0] = bitrateKbit * kVp8LayerRateAlloction[1][0]; | 72 cfg->ts_target_bitrate[0] = bitrateKbit * kVp8LayerRateAlloction[1][0]; |
74 cfg->ts_target_bitrate[1] = bitrateKbit; | 73 cfg->ts_target_bitrate[1] = bitrateKbit; |
75 cfg->ts_rate_decimator[0] = 2; | 74 cfg->ts_rate_decimator[0] = 2; |
76 cfg->ts_rate_decimator[1] = 1; | 75 cfg->ts_rate_decimator[1] = 1; |
77 memcpy(cfg->ts_layer_id, | 76 memcpy(cfg->ts_layer_id, temporal_ids_, |
78 temporal_ids_, | |
79 sizeof(unsigned int) * temporal_ids_length_); | 77 sizeof(unsigned int) * temporal_ids_length_); |
80 temporal_pattern_length_ = 8; | 78 temporal_pattern_length_ = 8; |
81 temporal_pattern_[0] = kTemporalUpdateLastAndGoldenRefAltRef; | 79 temporal_pattern_[0] = kTemporalUpdateLastAndGoldenRefAltRef; |
82 temporal_pattern_[1] = kTemporalUpdateGoldenWithoutDependencyRefAltRef; | 80 temporal_pattern_[1] = kTemporalUpdateGoldenWithoutDependencyRefAltRef; |
83 temporal_pattern_[2] = kTemporalUpdateLastRefAltRef; | 81 temporal_pattern_[2] = kTemporalUpdateLastRefAltRef; |
84 temporal_pattern_[3] = kTemporalUpdateGoldenRefAltRef; | 82 temporal_pattern_[3] = kTemporalUpdateGoldenRefAltRef; |
85 temporal_pattern_[4] = kTemporalUpdateLastRefAltRef; | 83 temporal_pattern_[4] = kTemporalUpdateLastRefAltRef; |
86 temporal_pattern_[5] = kTemporalUpdateGoldenRefAltRef; | 84 temporal_pattern_[5] = kTemporalUpdateGoldenRefAltRef; |
87 temporal_pattern_[6] = kTemporalUpdateLastRefAltRef; | 85 temporal_pattern_[6] = kTemporalUpdateLastRefAltRef; |
88 temporal_pattern_[7] = kTemporalUpdateNone; | 86 temporal_pattern_[7] = kTemporalUpdateNone; |
89 break; | 87 break; |
90 case 3: | 88 case 3: |
91 temporal_ids_length_ = 4; | 89 temporal_ids_length_ = 4; |
92 temporal_ids_[0] = 0; | 90 temporal_ids_[0] = 0; |
93 temporal_ids_[1] = 2; | 91 temporal_ids_[1] = 2; |
94 temporal_ids_[2] = 1; | 92 temporal_ids_[2] = 1; |
95 temporal_ids_[3] = 2; | 93 temporal_ids_[3] = 2; |
96 cfg->ts_number_layers = number_of_temporal_layers_; | 94 cfg->ts_number_layers = number_of_temporal_layers_; |
97 cfg->ts_periodicity = temporal_ids_length_; | 95 cfg->ts_periodicity = temporal_ids_length_; |
98 // Split stream 40% 20% 40%. | 96 // Split stream 40% 20% 40%. |
99 // Bitrate API for VP8 is the agregated bitrate for all lower layers. | 97 // Bitrate API for VP8 is the agregated bitrate for all lower layers. |
100 cfg->ts_target_bitrate[0] = bitrateKbit * kVp8LayerRateAlloction[2][0]; | 98 cfg->ts_target_bitrate[0] = bitrateKbit * kVp8LayerRateAlloction[2][0]; |
101 cfg->ts_target_bitrate[1] = bitrateKbit * kVp8LayerRateAlloction[2][1]; | 99 cfg->ts_target_bitrate[1] = bitrateKbit * kVp8LayerRateAlloction[2][1]; |
102 cfg->ts_target_bitrate[2] = bitrateKbit; | 100 cfg->ts_target_bitrate[2] = bitrateKbit; |
103 cfg->ts_rate_decimator[0] = 4; | 101 cfg->ts_rate_decimator[0] = 4; |
104 cfg->ts_rate_decimator[1] = 2; | 102 cfg->ts_rate_decimator[1] = 2; |
105 cfg->ts_rate_decimator[2] = 1; | 103 cfg->ts_rate_decimator[2] = 1; |
106 memcpy(cfg->ts_layer_id, | 104 memcpy(cfg->ts_layer_id, temporal_ids_, |
107 temporal_ids_, | |
108 sizeof(unsigned int) * temporal_ids_length_); | 105 sizeof(unsigned int) * temporal_ids_length_); |
109 temporal_pattern_length_ = 8; | 106 temporal_pattern_length_ = 8; |
110 temporal_pattern_[0] = kTemporalUpdateLastAndGoldenRefAltRef; | 107 temporal_pattern_[0] = kTemporalUpdateLastAndGoldenRefAltRef; |
111 temporal_pattern_[1] = kTemporalUpdateNoneNoRefGoldenRefAltRef; | 108 temporal_pattern_[1] = kTemporalUpdateNoneNoRefGoldenRefAltRef; |
112 temporal_pattern_[2] = kTemporalUpdateGoldenWithoutDependencyRefAltRef; | 109 temporal_pattern_[2] = kTemporalUpdateGoldenWithoutDependencyRefAltRef; |
113 temporal_pattern_[3] = kTemporalUpdateNone; | 110 temporal_pattern_[3] = kTemporalUpdateNone; |
114 temporal_pattern_[4] = kTemporalUpdateLastRefAltRef; | 111 temporal_pattern_[4] = kTemporalUpdateLastRefAltRef; |
115 temporal_pattern_[5] = kTemporalUpdateNone; | 112 temporal_pattern_[5] = kTemporalUpdateNone; |
116 temporal_pattern_[6] = kTemporalUpdateGoldenRefAltRef; | 113 temporal_pattern_[6] = kTemporalUpdateGoldenRefAltRef; |
117 temporal_pattern_[7] = kTemporalUpdateNone; | 114 temporal_pattern_[7] = kTemporalUpdateNone; |
(...skipping 13 matching lines...) Expand all Loading... |
131 cfg->ts_number_layers = 4; | 128 cfg->ts_number_layers = 4; |
132 cfg->ts_periodicity = temporal_ids_length_; | 129 cfg->ts_periodicity = temporal_ids_length_; |
133 cfg->ts_target_bitrate[0] = bitrateKbit * kVp8LayerRateAlloction[3][0]; | 130 cfg->ts_target_bitrate[0] = bitrateKbit * kVp8LayerRateAlloction[3][0]; |
134 cfg->ts_target_bitrate[1] = bitrateKbit * kVp8LayerRateAlloction[3][1]; | 131 cfg->ts_target_bitrate[1] = bitrateKbit * kVp8LayerRateAlloction[3][1]; |
135 cfg->ts_target_bitrate[2] = bitrateKbit * kVp8LayerRateAlloction[3][2]; | 132 cfg->ts_target_bitrate[2] = bitrateKbit * kVp8LayerRateAlloction[3][2]; |
136 cfg->ts_target_bitrate[3] = bitrateKbit; | 133 cfg->ts_target_bitrate[3] = bitrateKbit; |
137 cfg->ts_rate_decimator[0] = 8; | 134 cfg->ts_rate_decimator[0] = 8; |
138 cfg->ts_rate_decimator[1] = 4; | 135 cfg->ts_rate_decimator[1] = 4; |
139 cfg->ts_rate_decimator[2] = 2; | 136 cfg->ts_rate_decimator[2] = 2; |
140 cfg->ts_rate_decimator[3] = 1; | 137 cfg->ts_rate_decimator[3] = 1; |
141 memcpy(cfg->ts_layer_id, | 138 memcpy(cfg->ts_layer_id, temporal_ids_, |
142 temporal_ids_, | |
143 sizeof(unsigned int) * temporal_ids_length_); | 139 sizeof(unsigned int) * temporal_ids_length_); |
144 temporal_pattern_length_ = 16; | 140 temporal_pattern_length_ = 16; |
145 temporal_pattern_[0] = kTemporalUpdateLast; | 141 temporal_pattern_[0] = kTemporalUpdateLast; |
146 temporal_pattern_[1] = kTemporalUpdateNone; | 142 temporal_pattern_[1] = kTemporalUpdateNone; |
147 temporal_pattern_[2] = kTemporalUpdateAltrefWithoutDependency; | 143 temporal_pattern_[2] = kTemporalUpdateAltrefWithoutDependency; |
148 temporal_pattern_[3] = kTemporalUpdateNone; | 144 temporal_pattern_[3] = kTemporalUpdateNone; |
149 temporal_pattern_[4] = kTemporalUpdateGoldenWithoutDependency; | 145 temporal_pattern_[4] = kTemporalUpdateGoldenWithoutDependency; |
150 temporal_pattern_[5] = kTemporalUpdateNone; | 146 temporal_pattern_[5] = kTemporalUpdateNone; |
151 temporal_pattern_[6] = kTemporalUpdateAltref; | 147 temporal_pattern_[6] = kTemporalUpdateAltref; |
152 temporal_pattern_[7] = kTemporalUpdateNone; | 148 temporal_pattern_[7] = kTemporalUpdateNone; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 case kTemporalUpdateLastRefAll: | 232 case kTemporalUpdateLastRefAll: |
237 flags |= VP8_EFLAG_NO_UPD_ARF; | 233 flags |= VP8_EFLAG_NO_UPD_ARF; |
238 flags |= VP8_EFLAG_NO_UPD_GF; | 234 flags |= VP8_EFLAG_NO_UPD_GF; |
239 break; | 235 break; |
240 } | 236 } |
241 return flags; | 237 return flags; |
242 } | 238 } |
243 | 239 |
244 void DefaultTemporalLayers::PopulateCodecSpecific( | 240 void DefaultTemporalLayers::PopulateCodecSpecific( |
245 bool base_layer_sync, | 241 bool base_layer_sync, |
246 CodecSpecificInfoVP8 *vp8_info, | 242 CodecSpecificInfoVP8* vp8_info, |
247 uint32_t timestamp) { | 243 uint32_t timestamp) { |
248 assert(number_of_temporal_layers_ > 0); | 244 assert(number_of_temporal_layers_ > 0); |
249 assert(0 < temporal_ids_length_); | 245 assert(0 < temporal_ids_length_); |
250 | 246 |
251 if (number_of_temporal_layers_ == 1) { | 247 if (number_of_temporal_layers_ == 1) { |
252 vp8_info->temporalIdx = kNoTemporalIdx; | 248 vp8_info->temporalIdx = kNoTemporalIdx; |
253 vp8_info->layerSync = false; | 249 vp8_info->layerSync = false; |
254 vp8_info->tl0PicIdx = kNoTl0PicIdx; | 250 vp8_info->tl0PicIdx = kNoTl0PicIdx; |
255 } else { | 251 } else { |
256 if (base_layer_sync) { | 252 if (base_layer_sync) { |
257 vp8_info->temporalIdx = 0; | 253 vp8_info->temporalIdx = 0; |
258 vp8_info->layerSync = true; | 254 vp8_info->layerSync = true; |
259 } else { | 255 } else { |
260 vp8_info->temporalIdx = CurrentLayerId(); | 256 vp8_info->temporalIdx = CurrentLayerId(); |
261 TemporalReferences temporal_reference = | 257 TemporalReferences temporal_reference = |
262 temporal_pattern_[pattern_idx_ % temporal_pattern_length_]; | 258 temporal_pattern_[pattern_idx_ % temporal_pattern_length_]; |
263 | 259 |
264 if (temporal_reference == kTemporalUpdateAltrefWithoutDependency || | 260 if (temporal_reference == kTemporalUpdateAltrefWithoutDependency || |
265 temporal_reference == kTemporalUpdateGoldenWithoutDependency || | 261 temporal_reference == kTemporalUpdateGoldenWithoutDependency || |
266 temporal_reference == | 262 temporal_reference == |
267 kTemporalUpdateGoldenWithoutDependencyRefAltRef || | 263 kTemporalUpdateGoldenWithoutDependencyRefAltRef || |
268 temporal_reference == kTemporalUpdateNoneNoRefGoldenRefAltRef || | 264 temporal_reference == kTemporalUpdateNoneNoRefGoldenRefAltRef || |
269 (temporal_reference == kTemporalUpdateNone && | 265 (temporal_reference == kTemporalUpdateNone && |
270 number_of_temporal_layers_ == 4)) { | 266 number_of_temporal_layers_ == 4)) { |
271 vp8_info->layerSync = true; | 267 vp8_info->layerSync = true; |
272 } else { | 268 } else { |
273 vp8_info->layerSync = false; | 269 vp8_info->layerSync = false; |
274 } | 270 } |
275 } | 271 } |
276 if (last_base_layer_sync_ && vp8_info->temporalIdx != 0) { | 272 if (last_base_layer_sync_ && vp8_info->temporalIdx != 0) { |
277 // Regardless of pattern the frame after a base layer sync will always | 273 // Regardless of pattern the frame after a base layer sync will always |
278 // be a layer sync. | 274 // be a layer sync. |
279 vp8_info->layerSync = true; | 275 vp8_info->layerSync = true; |
280 } | 276 } |
281 if (vp8_info->temporalIdx == 0 && timestamp != timestamp_) { | 277 if (vp8_info->temporalIdx == 0 && timestamp != timestamp_) { |
282 timestamp_ = timestamp; | 278 timestamp_ = timestamp; |
283 tl0_pic_idx_++; | 279 tl0_pic_idx_++; |
284 } | 280 } |
285 last_base_layer_sync_ = base_layer_sync; | 281 last_base_layer_sync_ = base_layer_sync; |
286 vp8_info->tl0PicIdx = tl0_pic_idx_; | 282 vp8_info->tl0PicIdx = tl0_pic_idx_; |
287 } | 283 } |
288 } | 284 } |
289 | 285 |
290 TemporalLayers* TemporalLayers::Factory::Create( | 286 TemporalLayers* TemporalLayers::Factory::Create( |
291 int temporal_layers, | 287 int temporal_layers, |
292 uint8_t initial_tl0_pic_idx) const { | 288 uint8_t initial_tl0_pic_idx) const { |
293 return new DefaultTemporalLayers(temporal_layers, initial_tl0_pic_idx); | 289 return new DefaultTemporalLayers(temporal_layers, initial_tl0_pic_idx); |
294 } | 290 } |
295 } // namespace webrtc | 291 } // namespace webrtc |
OLD | NEW |