OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebM project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... |
28 layer_end = svc->number_temporal_layers; | 28 layer_end = svc->number_temporal_layers; |
29 } else { | 29 } else { |
30 layer_end = svc->number_spatial_layers; | 30 layer_end = svc->number_spatial_layers; |
31 } | 31 } |
32 | 32 |
33 for (layer = 0; layer < layer_end; ++layer) { | 33 for (layer = 0; layer < layer_end; ++layer) { |
34 LAYER_CONTEXT *const lc = &svc->layer_context[layer]; | 34 LAYER_CONTEXT *const lc = &svc->layer_context[layer]; |
35 RATE_CONTROL *const lrc = &lc->rc; | 35 RATE_CONTROL *const lrc = &lc->rc; |
36 int i; | 36 int i; |
37 lc->current_video_frame_in_layer = 0; | 37 lc->current_video_frame_in_layer = 0; |
| 38 lc->layer_size = 0; |
38 lrc->ni_av_qi = oxcf->worst_allowed_q; | 39 lrc->ni_av_qi = oxcf->worst_allowed_q; |
39 lrc->total_actual_bits = 0; | 40 lrc->total_actual_bits = 0; |
40 lrc->total_target_vs_actual = 0; | 41 lrc->total_target_vs_actual = 0; |
41 lrc->ni_tot_qi = 0; | 42 lrc->ni_tot_qi = 0; |
42 lrc->tot_q = 0.0; | 43 lrc->tot_q = 0.0; |
43 lrc->avg_q = 0.0; | 44 lrc->avg_q = 0.0; |
44 lrc->ni_frames = 0; | 45 lrc->ni_frames = 0; |
45 lrc->decimation_count = 0; | 46 lrc->decimation_count = 0; |
46 lrc->decimation_factor = 0; | 47 lrc->decimation_factor = 0; |
47 | 48 |
48 for (i = 0; i < RATE_FACTOR_LEVELS; ++i) { | 49 for (i = 0; i < RATE_FACTOR_LEVELS; ++i) { |
49 lrc->rate_correction_factors[i] = 1.0; | 50 lrc->rate_correction_factors[i] = 1.0; |
50 } | 51 } |
51 lc->layer_size = 0; | |
52 | 52 |
53 if (svc->number_temporal_layers > 1) { | 53 if (svc->number_temporal_layers > 1) { |
54 lc->target_bandwidth = oxcf->ts_target_bitrate[layer]; | 54 lc->target_bandwidth = oxcf->ts_target_bitrate[layer]; |
55 lrc->last_q[INTER_FRAME] = oxcf->worst_allowed_q; | 55 lrc->last_q[INTER_FRAME] = oxcf->worst_allowed_q; |
56 lrc->avg_frame_qindex[INTER_FRAME] = oxcf->worst_allowed_q; | 56 lrc->avg_frame_qindex[INTER_FRAME] = oxcf->worst_allowed_q; |
57 } else { | 57 } else { |
58 lc->target_bandwidth = oxcf->ss_target_bitrate[layer]; | 58 lc->target_bandwidth = oxcf->ss_target_bitrate[layer]; |
59 lrc->last_q[KEY_FRAME] = oxcf->best_allowed_q; | 59 lrc->last_q[KEY_FRAME] = oxcf->best_allowed_q; |
60 lrc->last_q[INTER_FRAME] = oxcf->best_allowed_q; | 60 lrc->last_q[INTER_FRAME] = oxcf->best_allowed_q; |
61 lrc->avg_frame_qindex[KEY_FRAME] = (oxcf->worst_allowed_q + | 61 lrc->avg_frame_qindex[KEY_FRAME] = (oxcf->worst_allowed_q + |
62 oxcf->best_allowed_q) / 2; | 62 oxcf->best_allowed_q) / 2; |
63 lrc->avg_frame_qindex[INTER_FRAME] = (oxcf->worst_allowed_q + | 63 lrc->avg_frame_qindex[INTER_FRAME] = (oxcf->worst_allowed_q + |
64 oxcf->best_allowed_q) / 2; | 64 oxcf->best_allowed_q) / 2; |
65 if (oxcf->ss_play_alternate[layer]) | 65 if (oxcf->ss_play_alternate[layer]) |
66 lc->alt_ref_idx = alt_ref_idx++; | 66 lc->alt_ref_idx = alt_ref_idx++; |
67 else | 67 else |
68 lc->alt_ref_idx = -1; | 68 lc->alt_ref_idx = -1; |
| 69 lc->gold_ref_idx = -1; |
69 } | 70 } |
70 | 71 |
71 lrc->buffer_level = vp9_rescale((int)(oxcf->starting_buffer_level_ms), | 72 lrc->buffer_level = vp9_rescale((int)(oxcf->starting_buffer_level_ms), |
72 lc->target_bandwidth, 1000); | 73 lc->target_bandwidth, 1000); |
73 lrc->bits_off_target = lrc->buffer_level; | 74 lrc->bits_off_target = lrc->buffer_level; |
74 } | 75 } |
| 76 |
| 77 // Still have extra buffer for base layer golden frame |
| 78 if (svc->number_spatial_layers > 1 && alt_ref_idx < REF_FRAMES) |
| 79 svc->layer_context[0].gold_ref_idx = alt_ref_idx; |
75 } | 80 } |
76 | 81 |
77 // Update the layer context from a change_config() call. | 82 // Update the layer context from a change_config() call. |
78 void vp9_update_layer_context_change_config(VP9_COMP *const cpi, | 83 void vp9_update_layer_context_change_config(VP9_COMP *const cpi, |
79 const int target_bandwidth) { | 84 const int target_bandwidth) { |
80 SVC *const svc = &cpi->svc; | 85 SVC *const svc = &cpi->svc; |
81 const VP9EncoderConfig *const oxcf = &cpi->oxcf; | 86 const VP9EncoderConfig *const oxcf = &cpi->oxcf; |
82 const RATE_CONTROL *const rc = &cpi->rc; | 87 const RATE_CONTROL *const rc = &cpi->rc; |
83 int layer; | 88 int layer; |
84 int layer_end; | 89 int layer_end; |
(...skipping 19 matching lines...) Expand all Loading... |
104 lrc->starting_buffer_level = | 109 lrc->starting_buffer_level = |
105 (int64_t)(rc->starting_buffer_level * bitrate_alloc); | 110 (int64_t)(rc->starting_buffer_level * bitrate_alloc); |
106 lrc->optimal_buffer_level = | 111 lrc->optimal_buffer_level = |
107 (int64_t)(rc->optimal_buffer_level * bitrate_alloc); | 112 (int64_t)(rc->optimal_buffer_level * bitrate_alloc); |
108 lrc->maximum_buffer_size = | 113 lrc->maximum_buffer_size = |
109 (int64_t)(rc->maximum_buffer_size * bitrate_alloc); | 114 (int64_t)(rc->maximum_buffer_size * bitrate_alloc); |
110 lrc->bits_off_target = MIN(lrc->bits_off_target, lrc->maximum_buffer_size); | 115 lrc->bits_off_target = MIN(lrc->bits_off_target, lrc->maximum_buffer_size); |
111 lrc->buffer_level = MIN(lrc->buffer_level, lrc->maximum_buffer_size); | 116 lrc->buffer_level = MIN(lrc->buffer_level, lrc->maximum_buffer_size); |
112 // Update framerate-related quantities. | 117 // Update framerate-related quantities. |
113 if (svc->number_temporal_layers > 1) { | 118 if (svc->number_temporal_layers > 1) { |
114 lc->framerate = oxcf->framerate / oxcf->ts_rate_decimator[layer]; | 119 lc->framerate = cpi->framerate / oxcf->ts_rate_decimator[layer]; |
115 } else { | 120 } else { |
116 lc->framerate = oxcf->framerate; | 121 lc->framerate = cpi->framerate; |
117 } | 122 } |
118 lrc->avg_frame_bandwidth = (int)(lc->target_bandwidth / lc->framerate); | 123 lrc->avg_frame_bandwidth = (int)(lc->target_bandwidth / lc->framerate); |
119 lrc->max_frame_bandwidth = rc->max_frame_bandwidth; | 124 lrc->max_frame_bandwidth = rc->max_frame_bandwidth; |
120 // Update qp-related quantities. | 125 // Update qp-related quantities. |
121 lrc->worst_quality = rc->worst_quality; | 126 lrc->worst_quality = rc->worst_quality; |
122 lrc->best_quality = rc->best_quality; | 127 lrc->best_quality = rc->best_quality; |
123 } | 128 } |
124 } | 129 } |
125 | 130 |
126 static LAYER_CONTEXT *get_layer_context(SVC *svc) { | 131 static LAYER_CONTEXT *get_layer_context(SVC *svc) { |
127 return svc->number_temporal_layers > 1 ? | 132 return svc->number_temporal_layers > 1 ? |
128 &svc->layer_context[svc->temporal_layer_id] : | 133 &svc->layer_context[svc->temporal_layer_id] : |
129 &svc->layer_context[svc->spatial_layer_id]; | 134 &svc->layer_context[svc->spatial_layer_id]; |
130 } | 135 } |
131 | 136 |
132 void vp9_update_temporal_layer_framerate(VP9_COMP *const cpi) { | 137 void vp9_update_temporal_layer_framerate(VP9_COMP *const cpi) { |
133 SVC *const svc = &cpi->svc; | 138 SVC *const svc = &cpi->svc; |
134 const VP9EncoderConfig *const oxcf = &cpi->oxcf; | 139 const VP9EncoderConfig *const oxcf = &cpi->oxcf; |
135 LAYER_CONTEXT *const lc = get_layer_context(svc); | 140 LAYER_CONTEXT *const lc = get_layer_context(svc); |
136 RATE_CONTROL *const lrc = &lc->rc; | 141 RATE_CONTROL *const lrc = &lc->rc; |
137 const int layer = svc->temporal_layer_id; | 142 const int layer = svc->temporal_layer_id; |
138 | 143 |
139 lc->framerate = oxcf->framerate / oxcf->ts_rate_decimator[layer]; | 144 lc->framerate = cpi->framerate / oxcf->ts_rate_decimator[layer]; |
140 lrc->avg_frame_bandwidth = (int)(lc->target_bandwidth / lc->framerate); | 145 lrc->avg_frame_bandwidth = (int)(lc->target_bandwidth / lc->framerate); |
141 lrc->max_frame_bandwidth = cpi->rc.max_frame_bandwidth; | 146 lrc->max_frame_bandwidth = cpi->rc.max_frame_bandwidth; |
142 // Update the average layer frame size (non-cumulative per-frame-bw). | 147 // Update the average layer frame size (non-cumulative per-frame-bw). |
143 if (layer == 0) { | 148 if (layer == 0) { |
144 lc->avg_frame_size = lrc->avg_frame_bandwidth; | 149 lc->avg_frame_size = lrc->avg_frame_bandwidth; |
145 } else { | 150 } else { |
146 const double prev_layer_framerate = | 151 const double prev_layer_framerate = |
147 oxcf->framerate / oxcf->ts_rate_decimator[layer - 1]; | 152 cpi->framerate / oxcf->ts_rate_decimator[layer - 1]; |
148 const int prev_layer_target_bandwidth = oxcf->ts_target_bitrate[layer - 1]; | 153 const int prev_layer_target_bandwidth = oxcf->ts_target_bitrate[layer - 1]; |
149 lc->avg_frame_size = | 154 lc->avg_frame_size = |
150 (int)((lc->target_bandwidth - prev_layer_target_bandwidth) / | 155 (int)((lc->target_bandwidth - prev_layer_target_bandwidth) / |
151 (lc->framerate - prev_layer_framerate)); | 156 (lc->framerate - prev_layer_framerate)); |
152 } | 157 } |
153 } | 158 } |
154 | 159 |
155 void vp9_update_spatial_layer_framerate(VP9_COMP *const cpi, double framerate) { | 160 void vp9_update_spatial_layer_framerate(VP9_COMP *const cpi, double framerate) { |
156 const VP9EncoderConfig *const oxcf = &cpi->oxcf; | 161 const VP9EncoderConfig *const oxcf = &cpi->oxcf; |
157 LAYER_CONTEXT *const lc = get_layer_context(&cpi->svc); | 162 LAYER_CONTEXT *const lc = get_layer_context(&cpi->svc); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 } | 215 } |
211 | 216 |
212 void vp9_inc_frame_in_layer(SVC *svc) { | 217 void vp9_inc_frame_in_layer(SVC *svc) { |
213 LAYER_CONTEXT *const lc = (svc->number_temporal_layers > 1) | 218 LAYER_CONTEXT *const lc = (svc->number_temporal_layers > 1) |
214 ? &svc->layer_context[svc->temporal_layer_id] | 219 ? &svc->layer_context[svc->temporal_layer_id] |
215 : &svc->layer_context[svc->spatial_layer_id]; | 220 : &svc->layer_context[svc->spatial_layer_id]; |
216 ++lc->current_video_frame_in_layer; | 221 ++lc->current_video_frame_in_layer; |
217 } | 222 } |
218 | 223 |
219 int vp9_is_upper_layer_key_frame(const VP9_COMP *const cpi) { | 224 int vp9_is_upper_layer_key_frame(const VP9_COMP *const cpi) { |
220 return cpi->use_svc && | 225 return is_spatial_svc(cpi) && |
221 cpi->svc.number_temporal_layers == 1 && | |
222 cpi->svc.spatial_layer_id > 0 && | 226 cpi->svc.spatial_layer_id > 0 && |
223 cpi->svc.layer_context[cpi->svc.spatial_layer_id].is_key_frame; | 227 cpi->svc.layer_context[cpi->svc.spatial_layer_id].is_key_frame; |
224 } | 228 } |
225 | 229 |
226 #if CONFIG_SPATIAL_SVC | 230 #if CONFIG_SPATIAL_SVC |
227 int vp9_svc_lookahead_push(const VP9_COMP *const cpi, struct lookahead_ctx *ctx, | 231 int vp9_svc_lookahead_push(const VP9_COMP *const cpi, struct lookahead_ctx *ctx, |
228 YV12_BUFFER_CONFIG *src, int64_t ts_start, | 232 YV12_BUFFER_CONFIG *src, int64_t ts_start, |
229 int64_t ts_end, unsigned int flags) { | 233 int64_t ts_end, unsigned int flags) { |
230 struct lookahead_entry *buf; | 234 struct lookahead_entry *buf; |
231 int i, index; | 235 int i, index; |
(...skipping 27 matching lines...) Expand all Loading... |
259 if (buf->svc_params[layer_id].spatial_layer >=0) | 263 if (buf->svc_params[layer_id].spatial_layer >=0) |
260 break; | 264 break; |
261 } | 265 } |
262 | 266 |
263 if (layer_id == cpi->svc.number_spatial_layers) | 267 if (layer_id == cpi->svc.number_spatial_layers) |
264 return 1; | 268 return 1; |
265 | 269 |
266 layer_param = &buf->svc_params[layer_id]; | 270 layer_param = &buf->svc_params[layer_id]; |
267 cpi->svc.spatial_layer_id = layer_param->spatial_layer; | 271 cpi->svc.spatial_layer_id = layer_param->spatial_layer; |
268 cpi->svc.temporal_layer_id = layer_param->temporal_layer; | 272 cpi->svc.temporal_layer_id = layer_param->temporal_layer; |
| 273 cpi->ref_frame_flags = VP9_ALT_FLAG | VP9_GOLD_FLAG | VP9_LAST_FLAG; |
| 274 |
| 275 lc = &cpi->svc.layer_context[cpi->svc.spatial_layer_id]; |
269 | 276 |
270 cpi->lst_fb_idx = cpi->svc.spatial_layer_id; | 277 cpi->lst_fb_idx = cpi->svc.spatial_layer_id; |
271 | 278 |
272 if (cpi->svc.spatial_layer_id < 1) | 279 if (cpi->svc.spatial_layer_id < 1) |
273 cpi->gld_fb_idx = cpi->lst_fb_idx; | 280 cpi->gld_fb_idx = lc->gold_ref_idx >= 0 ? |
| 281 lc->gold_ref_idx : cpi->lst_fb_idx; |
274 else | 282 else |
275 cpi->gld_fb_idx = cpi->svc.spatial_layer_id - 1; | 283 cpi->gld_fb_idx = cpi->svc.spatial_layer_id - 1; |
276 | 284 |
277 lc = &cpi->svc.layer_context[cpi->svc.spatial_layer_id]; | |
278 | |
279 if (lc->current_video_frame_in_layer == 0) { | 285 if (lc->current_video_frame_in_layer == 0) { |
280 if (cpi->svc.spatial_layer_id >= 2) | 286 if (cpi->svc.spatial_layer_id >= 2) { |
281 cpi->alt_fb_idx = cpi->svc.spatial_layer_id - 2; | 287 cpi->alt_fb_idx = cpi->svc.spatial_layer_id - 2; |
282 else | 288 } else { |
283 cpi->alt_fb_idx = cpi->lst_fb_idx; | 289 cpi->alt_fb_idx = cpi->lst_fb_idx; |
| 290 cpi->ref_frame_flags &= (~VP9_LAST_FLAG & ~VP9_ALT_FLAG); |
| 291 } |
284 } else { | 292 } else { |
285 if (cpi->oxcf.ss_play_alternate[cpi->svc.spatial_layer_id]) { | 293 if (cpi->oxcf.ss_play_alternate[cpi->svc.spatial_layer_id]) { |
286 cpi->alt_fb_idx = lc->alt_ref_idx; | 294 cpi->alt_fb_idx = lc->alt_ref_idx; |
287 if (!lc->has_alt_frame) | 295 if (!lc->has_alt_frame) |
288 cpi->ref_frame_flags &= (~VP9_ALT_FLAG); | 296 cpi->ref_frame_flags &= (~VP9_ALT_FLAG); |
289 } else { | 297 } else { |
290 // Find a proper alt_fb_idx for layers that don't have alt ref frame | 298 // Find a proper alt_fb_idx for layers that don't have alt ref frame |
291 if (cpi->svc.spatial_layer_id == 0) { | 299 if (cpi->svc.spatial_layer_id == 0) { |
292 cpi->alt_fb_idx = cpi->lst_fb_idx; | 300 cpi->alt_fb_idx = cpi->lst_fb_idx; |
293 } else { | 301 } else { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 buf->svc_params[cpi->svc.spatial_layer_id].spatial_layer = -1; | 355 buf->svc_params[cpi->svc.spatial_layer_id].spatial_layer = -1; |
348 if (cpi->svc.spatial_layer_id == cpi->svc.number_spatial_layers - 1) { | 356 if (cpi->svc.spatial_layer_id == cpi->svc.number_spatial_layers - 1) { |
349 vp9_lookahead_pop(ctx, drain); | 357 vp9_lookahead_pop(ctx, drain); |
350 } | 358 } |
351 } | 359 } |
352 } | 360 } |
353 | 361 |
354 return buf; | 362 return buf; |
355 } | 363 } |
356 #endif | 364 #endif |
OLD | NEW |