| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 if (!cpi->use_svc) | 127 if (!cpi->use_svc) |
| 128 cm->frame_context_idx = cpi->refresh_alt_ref_frame; | 128 cm->frame_context_idx = cpi->refresh_alt_ref_frame; |
| 129 } | 129 } |
| 130 | 130 |
| 131 if (cm->frame_type == KEY_FRAME) { | 131 if (cm->frame_type == KEY_FRAME) { |
| 132 if (!is_two_pass_svc(cpi)) | 132 if (!is_two_pass_svc(cpi)) |
| 133 cpi->refresh_golden_frame = 1; | 133 cpi->refresh_golden_frame = 1; |
| 134 cpi->refresh_alt_ref_frame = 1; | 134 cpi->refresh_alt_ref_frame = 1; |
| 135 vp9_zero(cpi->interp_filter_selected); | 135 vp9_zero(cpi->interp_filter_selected); |
| 136 } else { | 136 } else { |
| 137 cm->fc = cm->frame_contexts[cm->frame_context_idx]; | 137 *cm->fc = cm->frame_contexts[cm->frame_context_idx]; |
| 138 vp9_zero(cpi->interp_filter_selected[0]); | 138 vp9_zero(cpi->interp_filter_selected[0]); |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 | 141 |
| 142 static void vp9_enc_setup_mi(VP9_COMMON *cm) { |
| 143 int i; |
| 144 cm->mi = cm->mip + cm->mi_stride + 1; |
| 145 vpx_memset(cm->mip, 0, cm->mi_stride * (cm->mi_rows + 1) * sizeof(*cm->mip)); |
| 146 cm->prev_mi = cm->prev_mip + cm->mi_stride + 1; |
| 147 // Clear top border row |
| 148 vpx_memset(cm->prev_mip, 0, sizeof(*cm->prev_mip) * cm->mi_stride); |
| 149 // Clear left border column |
| 150 for (i = 1; i < cm->mi_rows + 1; ++i) |
| 151 vpx_memset(&cm->prev_mip[i * cm->mi_stride], 0, sizeof(*cm->prev_mip)); |
| 152 } |
| 153 |
| 154 static int vp9_enc_alloc_mi(VP9_COMMON *cm, int mi_size) { |
| 155 cm->mip = vpx_calloc(mi_size, sizeof(*cm->mip)); |
| 156 if (!cm->mip) |
| 157 return 1; |
| 158 cm->prev_mip = vpx_calloc(mi_size, sizeof(*cm->prev_mip)); |
| 159 if (!cm->prev_mip) |
| 160 return 1; |
| 161 cm->mi_alloc_size = mi_size; |
| 162 return 0; |
| 163 } |
| 164 |
| 165 static void vp9_enc_free_mi(VP9_COMMON *cm) { |
| 166 vpx_free(cm->mip); |
| 167 cm->mip = NULL; |
| 168 vpx_free(cm->prev_mip); |
| 169 cm->prev_mip = NULL; |
| 170 } |
| 171 |
| 172 static void vp9_swap_mi_and_prev_mi(VP9_COMMON *cm) { |
| 173 // Current mip will be the prev_mip for the next frame. |
| 174 MODE_INFO *temp = cm->prev_mip; |
| 175 cm->prev_mip = cm->mip; |
| 176 cm->mip = temp; |
| 177 |
| 178 // Update the upper left visible macroblock ptrs. |
| 179 cm->mi = cm->mip + cm->mi_stride + 1; |
| 180 cm->prev_mi = cm->prev_mip + cm->mi_stride + 1; |
| 181 } |
| 182 |
| 142 void vp9_initialize_enc() { | 183 void vp9_initialize_enc() { |
| 143 static int init_done = 0; | 184 static int init_done = 0; |
| 144 | 185 |
| 145 if (!init_done) { | 186 if (!init_done) { |
| 146 vp9_rtcd(); | 187 vp9_rtcd(); |
| 147 vp9_init_intra_predictors(); | 188 vp9_init_intra_predictors(); |
| 148 vp9_coef_tree_initialize(); | 189 vp9_coef_tree_initialize(); |
| 149 vp9_tokenize_initialize(); | 190 vp9_tokenize_initialize(); |
| 150 vp9_init_me_luts(); | 191 vp9_init_me_luts(); |
| 151 vp9_rc_init_minq_luts(); | 192 vp9_rc_init_minq_luts(); |
| 152 vp9_entropy_mv_init(); | 193 vp9_entropy_mv_init(); |
| 153 vp9_entropy_mode_init(); | 194 vp9_entropy_mode_init(); |
| 154 vp9_temporal_filter_init(); | 195 vp9_temporal_filter_init(); |
| 155 init_done = 1; | 196 init_done = 1; |
| 156 } | 197 } |
| 157 } | 198 } |
| 158 | 199 |
| 159 static void dealloc_compressor_data(VP9_COMP *cpi) { | 200 static void dealloc_compressor_data(VP9_COMP *cpi) { |
| 160 VP9_COMMON *const cm = &cpi->common; | 201 VP9_COMMON *const cm = &cpi->common; |
| 161 int i; | 202 int i; |
| 162 | 203 |
| 204 vpx_free(cpi->tile_data); |
| 205 cpi->tile_data = NULL; |
| 206 |
| 163 // Delete sementation map | 207 // Delete sementation map |
| 164 vpx_free(cpi->segmentation_map); | 208 vpx_free(cpi->segmentation_map); |
| 165 cpi->segmentation_map = NULL; | 209 cpi->segmentation_map = NULL; |
| 166 vpx_free(cm->last_frame_seg_map); | 210 vpx_free(cm->last_frame_seg_map); |
| 167 cm->last_frame_seg_map = NULL; | 211 cm->last_frame_seg_map = NULL; |
| 168 vpx_free(cpi->coding_context.last_frame_seg_map_copy); | 212 vpx_free(cpi->coding_context.last_frame_seg_map_copy); |
| 169 cpi->coding_context.last_frame_seg_map_copy = NULL; | 213 cpi->coding_context.last_frame_seg_map_copy = NULL; |
| 170 | 214 |
| 171 vpx_free(cpi->complexity_map); | 215 vpx_free(cpi->complexity_map); |
| 172 cpi->complexity_map = NULL; | 216 cpi->complexity_map = NULL; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 184 vpx_free(cpi->nmvsadcosts[0]); | 228 vpx_free(cpi->nmvsadcosts[0]); |
| 185 vpx_free(cpi->nmvsadcosts[1]); | 229 vpx_free(cpi->nmvsadcosts[1]); |
| 186 cpi->nmvsadcosts[0] = NULL; | 230 cpi->nmvsadcosts[0] = NULL; |
| 187 cpi->nmvsadcosts[1] = NULL; | 231 cpi->nmvsadcosts[1] = NULL; |
| 188 | 232 |
| 189 vpx_free(cpi->nmvsadcosts_hp[0]); | 233 vpx_free(cpi->nmvsadcosts_hp[0]); |
| 190 vpx_free(cpi->nmvsadcosts_hp[1]); | 234 vpx_free(cpi->nmvsadcosts_hp[1]); |
| 191 cpi->nmvsadcosts_hp[0] = NULL; | 235 cpi->nmvsadcosts_hp[0] = NULL; |
| 192 cpi->nmvsadcosts_hp[1] = NULL; | 236 cpi->nmvsadcosts_hp[1] = NULL; |
| 193 | 237 |
| 238 vpx_free(cpi->frame_counts); |
| 239 cpi->frame_counts = NULL; |
| 240 |
| 194 vp9_cyclic_refresh_free(cpi->cyclic_refresh); | 241 vp9_cyclic_refresh_free(cpi->cyclic_refresh); |
| 195 cpi->cyclic_refresh = NULL; | 242 cpi->cyclic_refresh = NULL; |
| 196 | 243 |
| 197 vp9_free_ref_frame_buffers(cm); | 244 vp9_free_ref_frame_buffers(cm); |
| 198 vp9_free_context_buffers(cm); | 245 vp9_free_context_buffers(cm); |
| 199 | 246 |
| 200 vp9_free_frame_buffer(&cpi->last_frame_uf); | 247 vp9_free_frame_buffer(&cpi->last_frame_uf); |
| 201 vp9_free_frame_buffer(&cpi->scaled_source); | 248 vp9_free_frame_buffer(&cpi->scaled_source); |
| 202 vp9_free_frame_buffer(&cpi->scaled_last_source); | 249 vp9_free_frame_buffer(&cpi->scaled_last_source); |
| 203 vp9_free_frame_buffer(&cpi->alt_ref_buffer); | 250 vp9_free_frame_buffer(&cpi->alt_ref_buffer); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 MV_VALS * sizeof(*cpi->nmvcosts_hp[1])); | 297 MV_VALS * sizeof(*cpi->nmvcosts_hp[1])); |
| 251 | 298 |
| 252 vp9_copy(cc->segment_pred_probs, cm->seg.pred_probs); | 299 vp9_copy(cc->segment_pred_probs, cm->seg.pred_probs); |
| 253 | 300 |
| 254 vpx_memcpy(cpi->coding_context.last_frame_seg_map_copy, | 301 vpx_memcpy(cpi->coding_context.last_frame_seg_map_copy, |
| 255 cm->last_frame_seg_map, (cm->mi_rows * cm->mi_cols)); | 302 cm->last_frame_seg_map, (cm->mi_rows * cm->mi_cols)); |
| 256 | 303 |
| 257 vp9_copy(cc->last_ref_lf_deltas, cm->lf.last_ref_deltas); | 304 vp9_copy(cc->last_ref_lf_deltas, cm->lf.last_ref_deltas); |
| 258 vp9_copy(cc->last_mode_lf_deltas, cm->lf.last_mode_deltas); | 305 vp9_copy(cc->last_mode_lf_deltas, cm->lf.last_mode_deltas); |
| 259 | 306 |
| 260 cc->fc = cm->fc; | 307 cc->fc = *cm->fc; |
| 261 } | 308 } |
| 262 | 309 |
| 263 static void restore_coding_context(VP9_COMP *cpi) { | 310 static void restore_coding_context(VP9_COMP *cpi) { |
| 264 CODING_CONTEXT *const cc = &cpi->coding_context; | 311 CODING_CONTEXT *const cc = &cpi->coding_context; |
| 265 VP9_COMMON *cm = &cpi->common; | 312 VP9_COMMON *cm = &cpi->common; |
| 266 | 313 |
| 267 // Restore key state variables to the snapshot state stored in the | 314 // Restore key state variables to the snapshot state stored in the |
| 268 // previous call to vp9_save_coding_context. | 315 // previous call to vp9_save_coding_context. |
| 269 vp9_copy(cpi->mb.nmvjointcost, cc->nmvjointcost); | 316 vp9_copy(cpi->mb.nmvjointcost, cc->nmvjointcost); |
| 270 | 317 |
| 271 vpx_memcpy(cpi->nmvcosts[0], cc->nmvcosts[0], | 318 vpx_memcpy(cpi->nmvcosts[0], cc->nmvcosts[0], |
| 272 MV_VALS * sizeof(*cc->nmvcosts[0])); | 319 MV_VALS * sizeof(*cc->nmvcosts[0])); |
| 273 vpx_memcpy(cpi->nmvcosts[1], cc->nmvcosts[1], | 320 vpx_memcpy(cpi->nmvcosts[1], cc->nmvcosts[1], |
| 274 MV_VALS * sizeof(*cc->nmvcosts[1])); | 321 MV_VALS * sizeof(*cc->nmvcosts[1])); |
| 275 vpx_memcpy(cpi->nmvcosts_hp[0], cc->nmvcosts_hp[0], | 322 vpx_memcpy(cpi->nmvcosts_hp[0], cc->nmvcosts_hp[0], |
| 276 MV_VALS * sizeof(*cc->nmvcosts_hp[0])); | 323 MV_VALS * sizeof(*cc->nmvcosts_hp[0])); |
| 277 vpx_memcpy(cpi->nmvcosts_hp[1], cc->nmvcosts_hp[1], | 324 vpx_memcpy(cpi->nmvcosts_hp[1], cc->nmvcosts_hp[1], |
| 278 MV_VALS * sizeof(*cc->nmvcosts_hp[1])); | 325 MV_VALS * sizeof(*cc->nmvcosts_hp[1])); |
| 279 | 326 |
| 280 vp9_copy(cm->seg.pred_probs, cc->segment_pred_probs); | 327 vp9_copy(cm->seg.pred_probs, cc->segment_pred_probs); |
| 281 | 328 |
| 282 vpx_memcpy(cm->last_frame_seg_map, | 329 vpx_memcpy(cm->last_frame_seg_map, |
| 283 cpi->coding_context.last_frame_seg_map_copy, | 330 cpi->coding_context.last_frame_seg_map_copy, |
| 284 (cm->mi_rows * cm->mi_cols)); | 331 (cm->mi_rows * cm->mi_cols)); |
| 285 | 332 |
| 286 vp9_copy(cm->lf.last_ref_deltas, cc->last_ref_lf_deltas); | 333 vp9_copy(cm->lf.last_ref_deltas, cc->last_ref_lf_deltas); |
| 287 vp9_copy(cm->lf.last_mode_deltas, cc->last_mode_lf_deltas); | 334 vp9_copy(cm->lf.last_mode_deltas, cc->last_mode_lf_deltas); |
| 288 | 335 |
| 289 cm->fc = cc->fc; | 336 *cm->fc = cc->fc; |
| 290 } | 337 } |
| 291 | 338 |
| 292 static void configure_static_seg_features(VP9_COMP *cpi) { | 339 static void configure_static_seg_features(VP9_COMP *cpi) { |
| 293 VP9_COMMON *const cm = &cpi->common; | 340 VP9_COMMON *const cm = &cpi->common; |
| 294 const RATE_CONTROL *const rc = &cpi->rc; | 341 const RATE_CONTROL *const rc = &cpi->rc; |
| 295 struct segmentation *const seg = &cm->seg; | 342 struct segmentation *const seg = &cm->seg; |
| 296 | 343 |
| 297 int high_q = (int)(rc->avg_q > 48.0); | 344 int high_q = (int)(rc->avg_q > 48.0); |
| 298 int qi_delta; | 345 int qi_delta; |
| 299 | 346 |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 vp9_alloc_compressor_data(cpi); | 617 vp9_alloc_compressor_data(cpi); |
| 571 | 618 |
| 572 // Spatial scalability. | 619 // Spatial scalability. |
| 573 cpi->svc.number_spatial_layers = oxcf->ss_number_layers; | 620 cpi->svc.number_spatial_layers = oxcf->ss_number_layers; |
| 574 // Temporal scalability. | 621 // Temporal scalability. |
| 575 cpi->svc.number_temporal_layers = oxcf->ts_number_layers; | 622 cpi->svc.number_temporal_layers = oxcf->ts_number_layers; |
| 576 | 623 |
| 577 if ((cpi->svc.number_temporal_layers > 1 && cpi->oxcf.rc_mode == VPX_CBR) || | 624 if ((cpi->svc.number_temporal_layers > 1 && cpi->oxcf.rc_mode == VPX_CBR) || |
| 578 ((cpi->svc.number_temporal_layers > 1 || | 625 ((cpi->svc.number_temporal_layers > 1 || |
| 579 cpi->svc.number_spatial_layers > 1) && | 626 cpi->svc.number_spatial_layers > 1) && |
| 580 cpi->oxcf.pass == 2)) { | 627 cpi->oxcf.pass != 1)) { |
| 581 vp9_init_layer_context(cpi); | 628 vp9_init_layer_context(cpi); |
| 582 } | 629 } |
| 583 | 630 |
| 584 // change includes all joint functionality | 631 // change includes all joint functionality |
| 585 vp9_change_config(cpi, oxcf); | 632 vp9_change_config(cpi, oxcf); |
| 586 | 633 |
| 587 cpi->static_mb_pct = 0; | 634 cpi->static_mb_pct = 0; |
| 588 cpi->ref_frame_flags = 0; | 635 cpi->ref_frame_flags = 0; |
| 589 | 636 |
| 590 init_buffer_indices(cpi); | 637 init_buffer_indices(cpi); |
| (...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1271 // TODO(jkoleszar): exit gracefully. | 1318 // TODO(jkoleszar): exit gracefully. |
| 1272 assert(cm->width <= cpi->initial_width); | 1319 assert(cm->width <= cpi->initial_width); |
| 1273 assert(cm->height <= cpi->initial_height); | 1320 assert(cm->height <= cpi->initial_height); |
| 1274 } | 1321 } |
| 1275 update_frame_size(cpi); | 1322 update_frame_size(cpi); |
| 1276 | 1323 |
| 1277 if ((cpi->svc.number_temporal_layers > 1 && | 1324 if ((cpi->svc.number_temporal_layers > 1 && |
| 1278 cpi->oxcf.rc_mode == VPX_CBR) || | 1325 cpi->oxcf.rc_mode == VPX_CBR) || |
| 1279 ((cpi->svc.number_temporal_layers > 1 || | 1326 ((cpi->svc.number_temporal_layers > 1 || |
| 1280 cpi->svc.number_spatial_layers > 1) && | 1327 cpi->svc.number_spatial_layers > 1) && |
| 1281 cpi->oxcf.pass == 2)) { | 1328 cpi->oxcf.pass != 1)) { |
| 1282 vp9_update_layer_context_change_config(cpi, | 1329 vp9_update_layer_context_change_config(cpi, |
| 1283 (int)cpi->oxcf.target_bandwidth); | 1330 (int)cpi->oxcf.target_bandwidth); |
| 1284 } | 1331 } |
| 1285 | 1332 |
| 1286 cpi->alt_ref_source = NULL; | 1333 cpi->alt_ref_source = NULL; |
| 1287 rc->is_src_frame_alt_ref = 0; | 1334 rc->is_src_frame_alt_ref = 0; |
| 1288 | 1335 |
| 1289 #if 0 | 1336 #if 0 |
| 1290 // Experimental RD Code | 1337 // Experimental RD Code |
| 1291 cpi->frame_distortion = 0; | 1338 cpi->frame_distortion = 0; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1350 double z = 256 * (2 * (log2f(8 * i) + .6)); | 1397 double z = 256 * (2 * (log2f(8 * i) + .6)); |
| 1351 mvsadcost[0][i] = (int)z; | 1398 mvsadcost[0][i] = (int)z; |
| 1352 mvsadcost[1][i] = (int)z; | 1399 mvsadcost[1][i] = (int)z; |
| 1353 mvsadcost[0][-i] = (int)z; | 1400 mvsadcost[0][-i] = (int)z; |
| 1354 mvsadcost[1][-i] = (int)z; | 1401 mvsadcost[1][-i] = (int)z; |
| 1355 } while (++i <= MV_MAX); | 1402 } while (++i <= MV_MAX); |
| 1356 } | 1403 } |
| 1357 | 1404 |
| 1358 | 1405 |
| 1359 VP9_COMP *vp9_create_compressor(VP9EncoderConfig *oxcf) { | 1406 VP9_COMP *vp9_create_compressor(VP9EncoderConfig *oxcf) { |
| 1360 unsigned int i, j; | 1407 unsigned int i; |
| 1361 VP9_COMP *const cpi = vpx_memalign(32, sizeof(VP9_COMP)); | 1408 VP9_COMP *const cpi = vpx_memalign(32, sizeof(VP9_COMP)); |
| 1362 VP9_COMMON *const cm = cpi != NULL ? &cpi->common : NULL; | 1409 VP9_COMMON *const cm = cpi != NULL ? &cpi->common : NULL; |
| 1363 | 1410 |
| 1364 if (!cm) | 1411 if (!cm) |
| 1365 return NULL; | 1412 return NULL; |
| 1366 | 1413 |
| 1367 vp9_zero(*cpi); | 1414 vp9_zero(*cpi); |
| 1368 | 1415 |
| 1369 if (setjmp(cm->error.jmp)) { | 1416 if (setjmp(cm->error.jmp)) { |
| 1370 cm->error.setjmp = 0; | 1417 cm->error.setjmp = 0; |
| 1371 vp9_remove_compressor(cpi); | 1418 vp9_remove_compressor(cpi); |
| 1372 return 0; | 1419 return 0; |
| 1373 } | 1420 } |
| 1374 | 1421 |
| 1375 cm->error.setjmp = 1; | 1422 cm->error.setjmp = 1; |
| 1423 cm->alloc_mi = vp9_enc_alloc_mi; |
| 1424 cm->free_mi = vp9_enc_free_mi; |
| 1425 cm->setup_mi = vp9_enc_setup_mi; |
| 1426 |
| 1427 CHECK_MEM_ERROR(cm, cm->fc, |
| 1428 (FRAME_CONTEXT *)vpx_calloc(1, sizeof(*cm->fc))); |
| 1429 CHECK_MEM_ERROR(cm, cm->frame_contexts, |
| 1430 (FRAME_CONTEXT *)vpx_calloc(FRAME_CONTEXTS, |
| 1431 sizeof(*cm->frame_contexts))); |
| 1376 | 1432 |
| 1377 cpi->use_svc = 0; | 1433 cpi->use_svc = 0; |
| 1378 | 1434 |
| 1379 init_config(cpi, oxcf); | 1435 init_config(cpi, oxcf); |
| 1380 vp9_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc); | 1436 vp9_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc); |
| 1381 | 1437 |
| 1382 cm->current_video_frame = 0; | 1438 cm->current_video_frame = 0; |
| 1383 cpi->partition_search_skippable_frame = 0; | 1439 cpi->partition_search_skippable_frame = 0; |
| 1440 cpi->tile_data = NULL; |
| 1384 | 1441 |
| 1385 // Create the encoder segmentation map and set all entries to 0 | 1442 // Create the encoder segmentation map and set all entries to 0 |
| 1386 CHECK_MEM_ERROR(cm, cpi->segmentation_map, | 1443 CHECK_MEM_ERROR(cm, cpi->segmentation_map, |
| 1387 vpx_calloc(cm->mi_rows * cm->mi_cols, 1)); | 1444 vpx_calloc(cm->mi_rows * cm->mi_cols, 1)); |
| 1388 | 1445 |
| 1389 // Create a complexity map used for rd adjustment | 1446 // Create a complexity map used for rd adjustment |
| 1390 CHECK_MEM_ERROR(cm, cpi->complexity_map, | 1447 CHECK_MEM_ERROR(cm, cpi->complexity_map, |
| 1391 vpx_calloc(cm->mi_rows * cm->mi_cols, 1)); | 1448 vpx_calloc(cm->mi_rows * cm->mi_cols, 1)); |
| 1392 | 1449 |
| 1393 // Create a map used for cyclic background refresh. | 1450 // Create a map used for cyclic background refresh. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1409 vpx_calloc(MV_VALS, sizeof(*cpi->nmvcosts_hp[1]))); | 1466 vpx_calloc(MV_VALS, sizeof(*cpi->nmvcosts_hp[1]))); |
| 1410 CHECK_MEM_ERROR(cm, cpi->nmvsadcosts[0], | 1467 CHECK_MEM_ERROR(cm, cpi->nmvsadcosts[0], |
| 1411 vpx_calloc(MV_VALS, sizeof(*cpi->nmvsadcosts[0]))); | 1468 vpx_calloc(MV_VALS, sizeof(*cpi->nmvsadcosts[0]))); |
| 1412 CHECK_MEM_ERROR(cm, cpi->nmvsadcosts[1], | 1469 CHECK_MEM_ERROR(cm, cpi->nmvsadcosts[1], |
| 1413 vpx_calloc(MV_VALS, sizeof(*cpi->nmvsadcosts[1]))); | 1470 vpx_calloc(MV_VALS, sizeof(*cpi->nmvsadcosts[1]))); |
| 1414 CHECK_MEM_ERROR(cm, cpi->nmvsadcosts_hp[0], | 1471 CHECK_MEM_ERROR(cm, cpi->nmvsadcosts_hp[0], |
| 1415 vpx_calloc(MV_VALS, sizeof(*cpi->nmvsadcosts_hp[0]))); | 1472 vpx_calloc(MV_VALS, sizeof(*cpi->nmvsadcosts_hp[0]))); |
| 1416 CHECK_MEM_ERROR(cm, cpi->nmvsadcosts_hp[1], | 1473 CHECK_MEM_ERROR(cm, cpi->nmvsadcosts_hp[1], |
| 1417 vpx_calloc(MV_VALS, sizeof(*cpi->nmvsadcosts_hp[1]))); | 1474 vpx_calloc(MV_VALS, sizeof(*cpi->nmvsadcosts_hp[1]))); |
| 1418 | 1475 |
| 1476 CHECK_MEM_ERROR(cm, cpi->frame_counts, vpx_calloc(1, |
| 1477 sizeof(*cpi->frame_counts))); |
| 1478 |
| 1419 for (i = 0; i < (sizeof(cpi->mbgraph_stats) / | 1479 for (i = 0; i < (sizeof(cpi->mbgraph_stats) / |
| 1420 sizeof(cpi->mbgraph_stats[0])); i++) { | 1480 sizeof(cpi->mbgraph_stats[0])); i++) { |
| 1421 CHECK_MEM_ERROR(cm, cpi->mbgraph_stats[i].mb_stats, | 1481 CHECK_MEM_ERROR(cm, cpi->mbgraph_stats[i].mb_stats, |
| 1422 vpx_calloc(cm->MBs * | 1482 vpx_calloc(cm->MBs * |
| 1423 sizeof(*cpi->mbgraph_stats[i].mb_stats), 1)); | 1483 sizeof(*cpi->mbgraph_stats[i].mb_stats), 1)); |
| 1424 } | 1484 } |
| 1425 | 1485 |
| 1426 #if CONFIG_FP_MB_STATS | 1486 #if CONFIG_FP_MB_STATS |
| 1427 cpi->use_fp_mb_stats = 0; | 1487 cpi->use_fp_mb_stats = 0; |
| 1428 if (cpi->use_fp_mb_stats) { | 1488 if (cpi->use_fp_mb_stats) { |
| 1429 // a place holder used to store the first pass mb stats in the first pass | 1489 // a place holder used to store the first pass mb stats in the first pass |
| 1430 CHECK_MEM_ERROR(cm, cpi->twopass.frame_mb_stats_buf, | 1490 CHECK_MEM_ERROR(cm, cpi->twopass.frame_mb_stats_buf, |
| 1431 vpx_calloc(cm->MBs * sizeof(uint8_t), 1)); | 1491 vpx_calloc(cm->MBs * sizeof(uint8_t), 1)); |
| 1432 } else { | 1492 } else { |
| 1433 cpi->twopass.frame_mb_stats_buf = NULL; | 1493 cpi->twopass.frame_mb_stats_buf = NULL; |
| 1434 } | 1494 } |
| 1435 #endif | 1495 #endif |
| 1436 | 1496 |
| 1437 cpi->refresh_alt_ref_frame = 0; | 1497 cpi->refresh_alt_ref_frame = 0; |
| 1438 | |
| 1439 // Note that at the moment multi_arf will not work with svc. | |
| 1440 // For the current check in all the execution paths are defaulted to 0 | |
| 1441 // pending further tuning and testing. The code is left in place here | |
| 1442 // as a place holder in regard to the required paths. | |
| 1443 cpi->multi_arf_last_grp_enabled = 0; | 1498 cpi->multi_arf_last_grp_enabled = 0; |
| 1444 if (oxcf->pass == 2) { | |
| 1445 if (cpi->use_svc) { | |
| 1446 cpi->multi_arf_allowed = 0; | |
| 1447 cpi->multi_arf_enabled = 0; | |
| 1448 } else { | |
| 1449 // Disable by default for now. | |
| 1450 cpi->multi_arf_allowed = 0; | |
| 1451 cpi->multi_arf_enabled = 0; | |
| 1452 } | |
| 1453 } else { | |
| 1454 cpi->multi_arf_allowed = 0; | |
| 1455 cpi->multi_arf_enabled = 0; | |
| 1456 } | |
| 1457 | 1499 |
| 1458 cpi->b_calculate_psnr = CONFIG_INTERNAL_STATS; | 1500 cpi->b_calculate_psnr = CONFIG_INTERNAL_STATS; |
| 1459 #if CONFIG_INTERNAL_STATS | 1501 #if CONFIG_INTERNAL_STATS |
| 1460 cpi->b_calculate_ssimg = 0; | 1502 cpi->b_calculate_ssimg = 0; |
| 1461 | 1503 |
| 1462 cpi->count = 0; | 1504 cpi->count = 0; |
| 1463 cpi->bytes = 0; | 1505 cpi->bytes = 0; |
| 1464 | 1506 |
| 1465 if (cpi->b_calculate_psnr) { | 1507 if (cpi->b_calculate_psnr) { |
| 1466 cpi->total_y = 0.0; | 1508 cpi->total_y = 0.0; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1582 #endif | 1624 #endif |
| 1583 | 1625 |
| 1584 cpi->twopass.stats_in_start = oxcf->two_pass_stats_in.buf; | 1626 cpi->twopass.stats_in_start = oxcf->two_pass_stats_in.buf; |
| 1585 cpi->twopass.stats_in = cpi->twopass.stats_in_start; | 1627 cpi->twopass.stats_in = cpi->twopass.stats_in_start; |
| 1586 cpi->twopass.stats_in_end = &cpi->twopass.stats_in[packets - 1]; | 1628 cpi->twopass.stats_in_end = &cpi->twopass.stats_in[packets - 1]; |
| 1587 | 1629 |
| 1588 vp9_init_second_pass(cpi); | 1630 vp9_init_second_pass(cpi); |
| 1589 } | 1631 } |
| 1590 } | 1632 } |
| 1591 | 1633 |
| 1592 vp9_set_speed_features(cpi); | 1634 vp9_set_speed_features_framesize_independent(cpi); |
| 1635 vp9_set_speed_features_framesize_dependent(cpi); |
| 1593 | 1636 |
| 1594 // Allocate memory to store variances for a frame. | 1637 // Allocate memory to store variances for a frame. |
| 1595 CHECK_MEM_ERROR(cm, cpi->source_diff_var, | 1638 CHECK_MEM_ERROR(cm, cpi->source_diff_var, |
| 1596 vpx_calloc(cm->MBs, sizeof(diff))); | 1639 vpx_calloc(cm->MBs, sizeof(diff))); |
| 1597 cpi->source_var_thresh = 0; | 1640 cpi->source_var_thresh = 0; |
| 1598 cpi->frames_till_next_var_check = 0; | 1641 cpi->frames_till_next_var_check = 0; |
| 1599 | 1642 |
| 1600 // Default rd threshold factors for mode selection | |
| 1601 for (i = 0; i < BLOCK_SIZES; ++i) { | |
| 1602 for (j = 0; j < MAX_MODES; ++j) { | |
| 1603 cpi->rd.thresh_freq_fact[i][j] = 32; | |
| 1604 cpi->rd.mode_map[i][j] = j; | |
| 1605 } | |
| 1606 } | |
| 1607 | |
| 1608 #define BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF)\ | 1643 #define BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX3F, SDX8F, SDX4DF)\ |
| 1609 cpi->fn_ptr[BT].sdf = SDF; \ | 1644 cpi->fn_ptr[BT].sdf = SDF; \ |
| 1610 cpi->fn_ptr[BT].sdaf = SDAF; \ | 1645 cpi->fn_ptr[BT].sdaf = SDAF; \ |
| 1611 cpi->fn_ptr[BT].vf = VF; \ | 1646 cpi->fn_ptr[BT].vf = VF; \ |
| 1612 cpi->fn_ptr[BT].svf = SVF; \ | 1647 cpi->fn_ptr[BT].svf = SVF; \ |
| 1613 cpi->fn_ptr[BT].svaf = SVAF; \ | 1648 cpi->fn_ptr[BT].svaf = SVAF; \ |
| 1614 cpi->fn_ptr[BT].sdx3f = SDX3F; \ | 1649 cpi->fn_ptr[BT].sdx3f = SDX3F; \ |
| 1615 cpi->fn_ptr[BT].sdx8f = SDX8F; \ | 1650 cpi->fn_ptr[BT].sdx8f = SDX8F; \ |
| 1616 cpi->fn_ptr[BT].sdx4df = SDX4DF; | 1651 cpi->fn_ptr[BT].sdx4df = SDX4DF; |
| 1617 | 1652 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1686 vp9_init_quantizer(cpi); | 1721 vp9_init_quantizer(cpi); |
| 1687 | 1722 |
| 1688 vp9_loop_filter_init(cm); | 1723 vp9_loop_filter_init(cm); |
| 1689 | 1724 |
| 1690 cm->error.setjmp = 0; | 1725 cm->error.setjmp = 0; |
| 1691 | 1726 |
| 1692 return cpi; | 1727 return cpi; |
| 1693 } | 1728 } |
| 1694 | 1729 |
| 1695 void vp9_remove_compressor(VP9_COMP *cpi) { | 1730 void vp9_remove_compressor(VP9_COMP *cpi) { |
| 1731 VP9_COMMON *const cm = &cpi->common; |
| 1696 unsigned int i; | 1732 unsigned int i; |
| 1697 | 1733 |
| 1698 if (!cpi) | 1734 if (!cpi) |
| 1699 return; | 1735 return; |
| 1700 | 1736 |
| 1701 if (cpi && (cpi->common.current_video_frame > 0)) { | 1737 if (cpi && (cm->current_video_frame > 0)) { |
| 1702 #if CONFIG_INTERNAL_STATS | 1738 #if CONFIG_INTERNAL_STATS |
| 1703 | 1739 |
| 1704 vp9_clear_system_state(); | 1740 vp9_clear_system_state(); |
| 1705 | 1741 |
| 1706 // printf("\n8x8-4x4:%d-%d\n", cpi->t8x8_count, cpi->t4x4_count); | 1742 // printf("\n8x8-4x4:%d-%d\n", cpi->t8x8_count, cpi->t4x4_count); |
| 1707 if (cpi->oxcf.pass != 1) { | 1743 if (cpi->oxcf.pass != 1) { |
| 1708 FILE *f = fopen("opsnr.stt", "a"); | 1744 FILE *f = fopen("opsnr.stt", "a"); |
| 1709 double time_encoded = (cpi->last_end_time_stamp_seen | 1745 double time_encoded = (cpi->last_end_time_stamp_seen |
| 1710 - cpi->first_time_stamp_ever) / 10000000.000; | 1746 - cpi->first_time_stamp_ever) / 10000000.000; |
| 1711 double total_encode_time = (cpi->time_receive_data + | 1747 double total_encode_time = (cpi->time_receive_data + |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1774 vpx_free(cpi->mbgraph_stats[i].mb_stats); | 1810 vpx_free(cpi->mbgraph_stats[i].mb_stats); |
| 1775 } | 1811 } |
| 1776 | 1812 |
| 1777 #if CONFIG_FP_MB_STATS | 1813 #if CONFIG_FP_MB_STATS |
| 1778 if (cpi->use_fp_mb_stats) { | 1814 if (cpi->use_fp_mb_stats) { |
| 1779 vpx_free(cpi->twopass.frame_mb_stats_buf); | 1815 vpx_free(cpi->twopass.frame_mb_stats_buf); |
| 1780 cpi->twopass.frame_mb_stats_buf = NULL; | 1816 cpi->twopass.frame_mb_stats_buf = NULL; |
| 1781 } | 1817 } |
| 1782 #endif | 1818 #endif |
| 1783 | 1819 |
| 1784 vp9_remove_common(&cpi->common); | 1820 vp9_remove_common(cm); |
| 1785 vpx_free(cpi); | 1821 vpx_free(cpi); |
| 1786 | 1822 |
| 1787 #if CONFIG_VP9_TEMPORAL_DENOISING | 1823 #if CONFIG_VP9_TEMPORAL_DENOISING |
| 1788 #ifdef OUTPUT_YUV_DENOISED | 1824 #ifdef OUTPUT_YUV_DENOISED |
| 1789 fclose(yuv_denoised_file); | 1825 fclose(yuv_denoised_file); |
| 1790 #endif | 1826 #endif |
| 1791 #endif | 1827 #endif |
| 1792 #ifdef OUTPUT_YUV_REC | 1828 #ifdef OUTPUT_YUV_REC |
| 1793 fclose(yuv_rec_file); | 1829 fclose(yuv_rec_file); |
| 1794 #endif | 1830 #endif |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2265 } | 2301 } |
| 2266 | 2302 |
| 2267 vp9_extend_frame_borders(dst); | 2303 vp9_extend_frame_borders(dst); |
| 2268 } | 2304 } |
| 2269 | 2305 |
| 2270 // Function to test for conditions that indicate we should loop | 2306 // Function to test for conditions that indicate we should loop |
| 2271 // back and recode a frame. | 2307 // back and recode a frame. |
| 2272 static int recode_loop_test(const VP9_COMP *cpi, | 2308 static int recode_loop_test(const VP9_COMP *cpi, |
| 2273 int high_limit, int low_limit, | 2309 int high_limit, int low_limit, |
| 2274 int q, int maxq, int minq) { | 2310 int q, int maxq, int minq) { |
| 2275 const VP9_COMMON *const cm = &cpi->common; | |
| 2276 const RATE_CONTROL *const rc = &cpi->rc; | 2311 const RATE_CONTROL *const rc = &cpi->rc; |
| 2277 const VP9EncoderConfig *const oxcf = &cpi->oxcf; | 2312 const VP9EncoderConfig *const oxcf = &cpi->oxcf; |
| 2278 int force_recode = 0; | 2313 int force_recode = 0; |
| 2279 | 2314 |
| 2280 // Special case trap if maximum allowed frame size exceeded. | 2315 // Special case trap if maximum allowed frame size exceeded. |
| 2281 if (rc->projected_frame_size > rc->max_frame_bandwidth) { | 2316 if (rc->projected_frame_size > rc->max_frame_bandwidth) { |
| 2282 force_recode = 1; | 2317 force_recode = 1; |
| 2283 | 2318 |
| 2284 // Is frame recode allowed. | 2319 // Is frame recode allowed. |
| 2285 // Yes if either recode mode 1 is selected or mode 2 is selected | 2320 // Yes if either recode mode 1 is selected or mode 2 is selected |
| 2286 // and the frame is a key frame, golden frame or alt_ref_frame | 2321 // and the frame is a key frame, golden frame or alt_ref_frame |
| 2287 } else if ((cpi->sf.recode_loop == ALLOW_RECODE) || | 2322 } else if ((cpi->sf.recode_loop == ALLOW_RECODE) || |
| 2288 ((cpi->sf.recode_loop == ALLOW_RECODE_KFARFGF) && | 2323 ((cpi->sf.recode_loop == ALLOW_RECODE_KFARFGF) && |
| 2289 (cm->frame_type == KEY_FRAME || | 2324 frame_is_kf_gf_arf(cpi))) { |
| 2290 cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame))) { | |
| 2291 // General over and under shoot tests | 2325 // General over and under shoot tests |
| 2292 if ((rc->projected_frame_size > high_limit && q < maxq) || | 2326 if ((rc->projected_frame_size > high_limit && q < maxq) || |
| 2293 (rc->projected_frame_size < low_limit && q > minq)) { | 2327 (rc->projected_frame_size < low_limit && q > minq)) { |
| 2294 force_recode = 1; | 2328 force_recode = 1; |
| 2295 } else if (cpi->oxcf.rc_mode == VPX_CQ) { | 2329 } else if (cpi->oxcf.rc_mode == VPX_CQ) { |
| 2296 // Deal with frame undershoot and whether or not we are | 2330 // Deal with frame undershoot and whether or not we are |
| 2297 // below the automatically set cq level. | 2331 // below the automatically set cq level. |
| 2298 if (q > oxcf->cq_level && | 2332 if (q > oxcf->cq_level && |
| 2299 rc->projected_frame_size < ((rc->this_frame_target * 7) >> 3)) { | 2333 rc->projected_frame_size < ((rc->this_frame_target * 7) >> 3)) { |
| 2300 force_recode = 1; | 2334 force_recode = 1; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2409 | 2443 |
| 2410 vp9_extend_frame_inner_borders(cm->frame_to_show); | 2444 vp9_extend_frame_inner_borders(cm->frame_to_show); |
| 2411 } | 2445 } |
| 2412 | 2446 |
| 2413 void vp9_scale_references(VP9_COMP *cpi) { | 2447 void vp9_scale_references(VP9_COMP *cpi) { |
| 2414 VP9_COMMON *cm = &cpi->common; | 2448 VP9_COMMON *cm = &cpi->common; |
| 2415 MV_REFERENCE_FRAME ref_frame; | 2449 MV_REFERENCE_FRAME ref_frame; |
| 2416 const VP9_REFFRAME ref_mask[3] = {VP9_LAST_FLAG, VP9_GOLD_FLAG, VP9_ALT_FLAG}; | 2450 const VP9_REFFRAME ref_mask[3] = {VP9_LAST_FLAG, VP9_GOLD_FLAG, VP9_ALT_FLAG}; |
| 2417 | 2451 |
| 2418 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { | 2452 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 2419 const int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)]; | 2453 // Need to convert from VP9_REFFRAME to index into ref_mask (subtract 1). |
| 2420 const YV12_BUFFER_CONFIG *const ref = &cm->frame_bufs[idx].buf; | 2454 if (cpi->ref_frame_flags & ref_mask[ref_frame - 1]) { |
| 2455 const int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)]; |
| 2456 const YV12_BUFFER_CONFIG *const ref = &cm->frame_bufs[idx].buf; |
| 2421 | 2457 |
| 2422 // Need to convert from VP9_REFFRAME to index into ref_mask (subtract 1). | |
| 2423 if ((cpi->ref_frame_flags & ref_mask[ref_frame - 1]) && | |
| 2424 (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height)) { | |
| 2425 const int new_fb = get_free_fb(cm); | |
| 2426 vp9_realloc_frame_buffer(&cm->frame_bufs[new_fb].buf, | |
| 2427 cm->width, cm->height, | |
| 2428 cm->subsampling_x, cm->subsampling_y, | |
| 2429 #if CONFIG_VP9_HIGHBITDEPTH | 2458 #if CONFIG_VP9_HIGHBITDEPTH |
| 2430 cm->use_highbitdepth, | 2459 if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) { |
| 2460 const int new_fb = get_free_fb(cm); |
| 2461 cm->cur_frame = &cm->frame_bufs[new_fb]; |
| 2462 vp9_realloc_frame_buffer(&cm->frame_bufs[new_fb].buf, |
| 2463 cm->width, cm->height, |
| 2464 cm->subsampling_x, cm->subsampling_y, |
| 2465 cm->use_highbitdepth, |
| 2466 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL); |
| 2467 scale_and_extend_frame(ref, &cm->frame_bufs[new_fb].buf, |
| 2468 (int)cm->bit_depth); |
| 2469 #else |
| 2470 if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) { |
| 2471 const int new_fb = get_free_fb(cm); |
| 2472 vp9_realloc_frame_buffer(&cm->frame_bufs[new_fb].buf, |
| 2473 cm->width, cm->height, |
| 2474 cm->subsampling_x, cm->subsampling_y, |
| 2475 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL); |
| 2476 scale_and_extend_frame(ref, &cm->frame_bufs[new_fb].buf); |
| 2431 #endif // CONFIG_VP9_HIGHBITDEPTH | 2477 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 2432 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL); | 2478 cpi->scaled_ref_idx[ref_frame - 1] = new_fb; |
| 2433 #if CONFIG_VP9_HIGHBITDEPTH | 2479 if (cm->frame_bufs[new_fb].mvs == NULL || |
| 2434 scale_and_extend_frame(ref, &cm->frame_bufs[new_fb].buf, | 2480 cm->frame_bufs[new_fb].mi_rows < cm->mi_rows || |
| 2435 (int)cm->bit_depth); | 2481 cm->frame_bufs[new_fb].mi_cols < cm->mi_cols) { |
| 2436 #else | 2482 cm->frame_bufs[new_fb].mvs = |
| 2437 scale_and_extend_frame(ref, &cm->frame_bufs[new_fb].buf); | 2483 (MV_REF *)vpx_calloc(cm->mi_rows * cm->mi_cols, |
| 2438 #endif // CONFIG_VP9_HIGHBITDEPTH | 2484 sizeof(*cm->frame_bufs[new_fb].mvs)); |
| 2439 cpi->scaled_ref_idx[ref_frame - 1] = new_fb; | 2485 cm->frame_bufs[new_fb].mi_rows = cm->mi_rows; |
| 2486 cm->frame_bufs[new_fb].mi_cols = cm->mi_cols; |
| 2487 } |
| 2488 } else { |
| 2489 cpi->scaled_ref_idx[ref_frame - 1] = idx; |
| 2490 ++cm->frame_bufs[idx].ref_count; |
| 2491 } |
| 2440 } else { | 2492 } else { |
| 2441 cpi->scaled_ref_idx[ref_frame - 1] = idx; | 2493 cpi->scaled_ref_idx[ref_frame - 1] = INVALID_REF_BUFFER_IDX; |
| 2442 cm->frame_bufs[idx].ref_count++; | |
| 2443 } | 2494 } |
| 2444 } | 2495 } |
| 2445 } | 2496 } |
| 2446 | 2497 |
| 2447 static void release_scaled_references(VP9_COMP *cpi) { | 2498 static void release_scaled_references(VP9_COMP *cpi) { |
| 2448 VP9_COMMON *cm = &cpi->common; | 2499 VP9_COMMON *cm = &cpi->common; |
| 2449 int i; | 2500 int i; |
| 2450 | 2501 for (i = 0; i < MAX_REF_FRAMES; ++i) { |
| 2451 for (i = 0; i < 3; i++) | 2502 const int idx = cpi->scaled_ref_idx[i]; |
| 2452 cm->frame_bufs[cpi->scaled_ref_idx[i]].ref_count--; | 2503 RefCntBuffer *const buf = |
| 2504 idx != INVALID_REF_BUFFER_IDX ? &cm->frame_bufs[idx] : NULL; |
| 2505 if (buf != NULL) { |
| 2506 --buf->ref_count; |
| 2507 cpi->scaled_ref_idx[i] = INVALID_REF_BUFFER_IDX; |
| 2508 } |
| 2509 } |
| 2453 } | 2510 } |
| 2454 | 2511 |
| 2455 static void full_to_model_count(unsigned int *model_count, | 2512 static void full_to_model_count(unsigned int *model_count, |
| 2456 unsigned int *full_count) { | 2513 unsigned int *full_count) { |
| 2457 int n; | 2514 int n; |
| 2458 model_count[ZERO_TOKEN] = full_count[ZERO_TOKEN]; | 2515 model_count[ZERO_TOKEN] = full_count[ZERO_TOKEN]; |
| 2459 model_count[ONE_TOKEN] = full_count[ONE_TOKEN]; | 2516 model_count[ONE_TOKEN] = full_count[ONE_TOKEN]; |
| 2460 model_count[TWO_TOKEN] = full_count[TWO_TOKEN]; | 2517 model_count[TWO_TOKEN] = full_count[TWO_TOKEN]; |
| 2461 for (n = THREE_TOKEN; n < EOB_TOKEN; ++n) | 2518 for (n = THREE_TOKEN; n < EOB_TOKEN; ++n) |
| 2462 model_count[TWO_TOKEN] += full_count[n]; | 2519 model_count[TWO_TOKEN] += full_count[n]; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2527 for (i = 0; i < MAX_MODES; ++i) | 2584 for (i = 0; i < MAX_MODES; ++i) |
| 2528 fprintf(fmodes, "%5d ", cpi->mode_chosen_counts[i]); | 2585 fprintf(fmodes, "%5d ", cpi->mode_chosen_counts[i]); |
| 2529 | 2586 |
| 2530 fprintf(fmodes, "\n"); | 2587 fprintf(fmodes, "\n"); |
| 2531 | 2588 |
| 2532 fclose(fmodes); | 2589 fclose(fmodes); |
| 2533 } | 2590 } |
| 2534 } | 2591 } |
| 2535 #endif | 2592 #endif |
| 2536 | 2593 |
| 2537 static void encode_without_recode_loop(VP9_COMP *cpi, | 2594 static void set_mv_search_params(VP9_COMP *cpi) { |
| 2538 int q) { | 2595 const VP9_COMMON *const cm = &cpi->common; |
| 2596 const unsigned int max_mv_def = MIN(cm->width, cm->height); |
| 2597 |
| 2598 // Default based on max resolution. |
| 2599 cpi->mv_step_param = vp9_init_search_range(max_mv_def); |
| 2600 |
| 2601 if (cpi->sf.mv.auto_mv_step_size) { |
| 2602 if (frame_is_intra_only(cm)) { |
| 2603 // Initialize max_mv_magnitude for use in the first INTER frame |
| 2604 // after a key/intra-only frame. |
| 2605 cpi->max_mv_magnitude = max_mv_def; |
| 2606 } else { |
| 2607 if (cm->show_frame) { |
| 2608 // Allow mv_steps to correspond to twice the max mv magnitude found |
| 2609 // in the previous frame, capped by the default max_mv_magnitude based |
| 2610 // on resolution. |
| 2611 cpi->mv_step_param = |
| 2612 vp9_init_search_range(MIN(max_mv_def, 2 * cpi->max_mv_magnitude)); |
| 2613 } |
| 2614 cpi->max_mv_magnitude = 0; |
| 2615 } |
| 2616 } |
| 2617 } |
| 2618 |
| 2619 static void set_size_independent_vars(VP9_COMP *cpi) { |
| 2620 vp9_set_speed_features_framesize_independent(cpi); |
| 2621 vp9_set_rd_speed_thresholds(cpi); |
| 2622 vp9_set_rd_speed_thresholds_sub8x8(cpi); |
| 2623 cpi->common.interp_filter = cpi->sf.default_interp_filter; |
| 2624 } |
| 2625 |
| 2626 static void set_size_dependent_vars(VP9_COMP *cpi, int *q, |
| 2627 int *bottom_index, int *top_index) { |
| 2539 VP9_COMMON *const cm = &cpi->common; | 2628 VP9_COMMON *const cm = &cpi->common; |
| 2629 const VP9EncoderConfig *const oxcf = &cpi->oxcf; |
| 2630 |
| 2631 // Setup variables that depend on the dimensions of the frame. |
| 2632 vp9_set_speed_features_framesize_dependent(cpi); |
| 2633 |
| 2634 // Decide q and q bounds. |
| 2635 *q = vp9_rc_pick_q_and_bounds(cpi, bottom_index, top_index); |
| 2636 |
| 2637 if (!frame_is_intra_only(cm)) { |
| 2638 vp9_set_high_precision_mv(cpi, (*q) < HIGH_PRECISION_MV_QTHRESH); |
| 2639 } |
| 2640 |
| 2641 // Configure experimental use of segmentation for enhanced coding of |
| 2642 // static regions if indicated. |
| 2643 // Only allowed in the second pass of a two pass encode, as it requires |
| 2644 // lagged coding, and if the relevant speed feature flag is set. |
| 2645 if (oxcf->pass == 2 && cpi->sf.static_segmentation) |
| 2646 configure_static_seg_features(cpi); |
| 2647 |
| 2648 #if CONFIG_VP9_POSTPROC |
| 2649 if (oxcf->noise_sensitivity > 0) { |
| 2650 int l = 0; |
| 2651 switch (oxcf->noise_sensitivity) { |
| 2652 case 1: |
| 2653 l = 20; |
| 2654 break; |
| 2655 case 2: |
| 2656 l = 40; |
| 2657 break; |
| 2658 case 3: |
| 2659 l = 60; |
| 2660 break; |
| 2661 case 4: |
| 2662 case 5: |
| 2663 l = 100; |
| 2664 break; |
| 2665 case 6: |
| 2666 l = 150; |
| 2667 break; |
| 2668 } |
| 2669 vp9_denoise(cpi->Source, cpi->Source, l); |
| 2670 } |
| 2671 #endif // CONFIG_VP9_POSTPROC |
| 2672 } |
| 2673 |
| 2674 static void init_motion_estimation(VP9_COMP *cpi) { |
| 2675 int y_stride = cpi->scaled_source.y_stride; |
| 2676 |
| 2677 if (cpi->sf.mv.search_method == NSTEP) { |
| 2678 vp9_init3smotion_compensation(&cpi->ss_cfg, y_stride); |
| 2679 } else if (cpi->sf.mv.search_method == DIAMOND) { |
| 2680 vp9_init_dsmotion_compensation(&cpi->ss_cfg, y_stride); |
| 2681 } |
| 2682 } |
| 2683 |
| 2684 void set_frame_size(VP9_COMP *cpi) { |
| 2685 int ref_frame; |
| 2686 VP9_COMMON *const cm = &cpi->common; |
| 2687 const VP9EncoderConfig *const oxcf = &cpi->oxcf; |
| 2688 MACROBLOCKD *const xd = &cpi->mb.e_mbd; |
| 2689 |
| 2690 if (oxcf->pass == 2 && |
| 2691 cm->current_video_frame == 0 && |
| 2692 oxcf->resize_mode == RESIZE_FIXED && |
| 2693 oxcf->rc_mode == VPX_VBR) { |
| 2694 // Internal scaling is triggered on the first frame. |
| 2695 vp9_set_size_literal(cpi, oxcf->scaled_frame_width, |
| 2696 oxcf->scaled_frame_height); |
| 2697 } |
| 2698 |
| 2699 if ((oxcf->pass == 2) && |
| 2700 (!cpi->use_svc || |
| 2701 (is_two_pass_svc(cpi) && |
| 2702 cpi->svc.encode_empty_frame_state != ENCODING))) { |
| 2703 vp9_set_target_rate(cpi); |
| 2704 } |
| 2705 |
| 2706 // Reset the frame pointers to the current frame size. |
| 2707 vp9_realloc_frame_buffer(get_frame_new_buffer(cm), |
| 2708 cm->width, cm->height, |
| 2709 cm->subsampling_x, cm->subsampling_y, |
| 2710 #if CONFIG_VP9_HIGHBITDEPTH |
| 2711 cm->use_highbitdepth, |
| 2712 #endif |
| 2713 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL); |
| 2714 |
| 2715 alloc_util_frame_buffers(cpi); |
| 2716 init_motion_estimation(cpi); |
| 2717 |
| 2718 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 2719 const int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)]; |
| 2720 YV12_BUFFER_CONFIG *const buf = &cm->frame_bufs[idx].buf; |
| 2721 RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - 1]; |
| 2722 ref_buf->buf = buf; |
| 2723 ref_buf->idx = idx; |
| 2724 #if CONFIG_VP9_HIGHBITDEPTH |
| 2725 vp9_setup_scale_factors_for_frame(&ref_buf->sf, |
| 2726 buf->y_crop_width, buf->y_crop_height, |
| 2727 cm->width, cm->height, |
| 2728 (buf->flags & YV12_FLAG_HIGHBITDEPTH) ? |
| 2729 1 : 0); |
| 2730 #else |
| 2731 vp9_setup_scale_factors_for_frame(&ref_buf->sf, |
| 2732 buf->y_crop_width, buf->y_crop_height, |
| 2733 cm->width, cm->height); |
| 2734 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 2735 if (vp9_is_scaled(&ref_buf->sf)) |
| 2736 vp9_extend_frame_borders(buf); |
| 2737 } |
| 2738 |
| 2739 set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME); |
| 2740 } |
| 2741 |
| 2742 static void encode_without_recode_loop(VP9_COMP *cpi) { |
| 2743 VP9_COMMON *const cm = &cpi->common; |
| 2744 int q, bottom_index, top_index; // Dummy variables. |
| 2745 |
| 2540 vp9_clear_system_state(); | 2746 vp9_clear_system_state(); |
| 2747 |
| 2748 set_frame_size(cpi); |
| 2749 |
| 2750 cpi->Source = vp9_scale_if_required(cm, cpi->un_scaled_source, |
| 2751 &cpi->scaled_source); |
| 2752 |
| 2753 if (cpi->unscaled_last_source != NULL) |
| 2754 cpi->Last_Source = vp9_scale_if_required(cm, cpi->unscaled_last_source, |
| 2755 &cpi->scaled_last_source); |
| 2756 |
| 2757 if (frame_is_intra_only(cm) == 0) { |
| 2758 vp9_scale_references(cpi); |
| 2759 } |
| 2760 |
| 2761 set_size_independent_vars(cpi); |
| 2762 set_size_dependent_vars(cpi, &q, &bottom_index, &top_index); |
| 2763 |
| 2541 vp9_set_quantizer(cm, q); | 2764 vp9_set_quantizer(cm, q); |
| 2542 setup_frame(cpi); | 2765 setup_frame(cpi); |
| 2543 // Variance adaptive and in frame q adjustment experiments are mutually | 2766 // Variance adaptive and in frame q adjustment experiments are mutually |
| 2544 // exclusive. | 2767 // exclusive. |
| 2545 if (cpi->oxcf.aq_mode == VARIANCE_AQ) { | 2768 if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
| 2546 vp9_vaq_frame_setup(cpi); | 2769 vp9_vaq_frame_setup(cpi); |
| 2547 } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { | 2770 } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { |
| 2548 vp9_setup_in_frame_q_adj(cpi); | 2771 vp9_setup_in_frame_q_adj(cpi); |
| 2549 } else if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) { | 2772 } else if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) { |
| 2550 vp9_cyclic_refresh_setup(cpi); | 2773 vp9_cyclic_refresh_setup(cpi); |
| 2551 } | 2774 } |
| 2552 // transform / motion compensation build reconstruction frame | 2775 // transform / motion compensation build reconstruction frame |
| 2553 vp9_encode_frame(cpi); | 2776 vp9_encode_frame(cpi); |
| 2554 | 2777 |
| 2555 // Update the skip mb flag probabilities based on the distribution | 2778 // Update the skip mb flag probabilities based on the distribution |
| 2556 // seen in the last encoder iteration. | 2779 // seen in the last encoder iteration. |
| 2557 // update_base_skip_probs(cpi); | 2780 // update_base_skip_probs(cpi); |
| 2558 vp9_clear_system_state(); | 2781 vp9_clear_system_state(); |
| 2559 } | 2782 } |
| 2560 | 2783 |
| 2561 static void encode_with_recode_loop(VP9_COMP *cpi, | 2784 static void encode_with_recode_loop(VP9_COMP *cpi, |
| 2562 size_t *size, | 2785 size_t *size, |
| 2563 uint8_t *dest, | 2786 uint8_t *dest) { |
| 2564 int q, | |
| 2565 int bottom_index, | |
| 2566 int top_index) { | |
| 2567 VP9_COMMON *const cm = &cpi->common; | 2787 VP9_COMMON *const cm = &cpi->common; |
| 2568 RATE_CONTROL *const rc = &cpi->rc; | 2788 RATE_CONTROL *const rc = &cpi->rc; |
| 2789 int bottom_index, top_index; |
| 2569 int loop_count = 0; | 2790 int loop_count = 0; |
| 2570 int loop = 0; | 2791 int loop = 0; |
| 2571 int overshoot_seen = 0; | 2792 int overshoot_seen = 0; |
| 2572 int undershoot_seen = 0; | 2793 int undershoot_seen = 0; |
| 2573 int q_low = bottom_index, q_high = top_index; | |
| 2574 int frame_over_shoot_limit; | 2794 int frame_over_shoot_limit; |
| 2575 int frame_under_shoot_limit; | 2795 int frame_under_shoot_limit; |
| 2796 int q = 0, q_low = 0, q_high = 0; |
| 2797 int frame_size_changed = 0; |
| 2576 | 2798 |
| 2577 // Decide frame size bounds | 2799 set_size_independent_vars(cpi); |
| 2578 vp9_rc_compute_frame_size_bounds(cpi, rc->this_frame_target, | |
| 2579 &frame_under_shoot_limit, | |
| 2580 &frame_over_shoot_limit); | |
| 2581 | 2800 |
| 2582 do { | 2801 do { |
| 2583 vp9_clear_system_state(); | 2802 vp9_clear_system_state(); |
| 2584 | 2803 |
| 2804 set_frame_size(cpi); |
| 2805 |
| 2806 if (loop_count == 0 || frame_size_changed != 0) { |
| 2807 set_size_dependent_vars(cpi, &q, &bottom_index, &top_index); |
| 2808 q_low = bottom_index; |
| 2809 q_high = top_index; |
| 2810 |
| 2811 // TODO(agrange) Scale cpi->max_mv_magnitude if frame-size has changed. |
| 2812 set_mv_search_params(cpi); |
| 2813 } |
| 2814 |
| 2815 // Decide frame size bounds |
| 2816 vp9_rc_compute_frame_size_bounds(cpi, rc->this_frame_target, |
| 2817 &frame_under_shoot_limit, |
| 2818 &frame_over_shoot_limit); |
| 2819 |
| 2820 cpi->Source = vp9_scale_if_required(cm, cpi->un_scaled_source, |
| 2821 &cpi->scaled_source); |
| 2822 |
| 2823 if (cpi->unscaled_last_source != NULL) |
| 2824 cpi->Last_Source = vp9_scale_if_required(cm, cpi->unscaled_last_source, |
| 2825 &cpi->scaled_last_source); |
| 2826 |
| 2827 if (frame_is_intra_only(cm) == 0) { |
| 2828 if (loop_count > 0) { |
| 2829 release_scaled_references(cpi); |
| 2830 } |
| 2831 vp9_scale_references(cpi); |
| 2832 } |
| 2833 |
| 2585 vp9_set_quantizer(cm, q); | 2834 vp9_set_quantizer(cm, q); |
| 2586 | 2835 |
| 2587 if (loop_count == 0) | 2836 if (loop_count == 0) |
| 2588 setup_frame(cpi); | 2837 setup_frame(cpi); |
| 2589 | 2838 |
| 2590 // Variance adaptive and in frame q adjustment experiments are mutually | 2839 // Variance adaptive and in frame q adjustment experiments are mutually |
| 2591 // exclusive. | 2840 // exclusive. |
| 2592 if (cpi->oxcf.aq_mode == VARIANCE_AQ) { | 2841 if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
| 2593 vp9_vaq_frame_setup(cpi); | 2842 vp9_vaq_frame_setup(cpi); |
| 2594 } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { | 2843 } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2771 static int get_ref_frame_flags(const VP9_COMP *cpi) { | 3020 static int get_ref_frame_flags(const VP9_COMP *cpi) { |
| 2772 const int *const map = cpi->common.ref_frame_map; | 3021 const int *const map = cpi->common.ref_frame_map; |
| 2773 const int gold_is_last = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idx]; | 3022 const int gold_is_last = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idx]; |
| 2774 const int alt_is_last = map[cpi->alt_fb_idx] == map[cpi->lst_fb_idx]; | 3023 const int alt_is_last = map[cpi->alt_fb_idx] == map[cpi->lst_fb_idx]; |
| 2775 const int gold_is_alt = map[cpi->gld_fb_idx] == map[cpi->alt_fb_idx]; | 3024 const int gold_is_alt = map[cpi->gld_fb_idx] == map[cpi->alt_fb_idx]; |
| 2776 int flags = VP9_ALT_FLAG | VP9_GOLD_FLAG | VP9_LAST_FLAG; | 3025 int flags = VP9_ALT_FLAG | VP9_GOLD_FLAG | VP9_LAST_FLAG; |
| 2777 | 3026 |
| 2778 if (gold_is_last) | 3027 if (gold_is_last) |
| 2779 flags &= ~VP9_GOLD_FLAG; | 3028 flags &= ~VP9_GOLD_FLAG; |
| 2780 | 3029 |
| 2781 if (cpi->rc.frames_till_gf_update_due == INT_MAX && !is_two_pass_svc(cpi)) | 3030 if (cpi->rc.frames_till_gf_update_due == INT_MAX && |
| 3031 (cpi->svc.number_temporal_layers == 1 && |
| 3032 cpi->svc.number_spatial_layers == 1)) |
| 2782 flags &= ~VP9_GOLD_FLAG; | 3033 flags &= ~VP9_GOLD_FLAG; |
| 2783 | 3034 |
| 2784 if (alt_is_last) | 3035 if (alt_is_last) |
| 2785 flags &= ~VP9_ALT_FLAG; | 3036 flags &= ~VP9_ALT_FLAG; |
| 2786 | 3037 |
| 2787 if (gold_is_alt) | 3038 if (gold_is_alt) |
| 2788 flags &= ~VP9_ALT_FLAG; | 3039 flags &= ~VP9_ALT_FLAG; |
| 2789 | 3040 |
| 2790 return flags; | 3041 return flags; |
| 2791 } | 3042 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2816 scale_and_extend_frame_nonnormative(unscaled, scaled, (int)cm->bit_depth); | 3067 scale_and_extend_frame_nonnormative(unscaled, scaled, (int)cm->bit_depth); |
| 2817 #else | 3068 #else |
| 2818 scale_and_extend_frame_nonnormative(unscaled, scaled); | 3069 scale_and_extend_frame_nonnormative(unscaled, scaled); |
| 2819 #endif // CONFIG_VP9_HIGHBITDEPTH | 3070 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 2820 return scaled; | 3071 return scaled; |
| 2821 } else { | 3072 } else { |
| 2822 return unscaled; | 3073 return unscaled; |
| 2823 } | 3074 } |
| 2824 } | 3075 } |
| 2825 | 3076 |
| 2826 static int is_skippable_frame(const VP9_COMP *cpi) { | |
| 2827 // If the current frame does not have non-zero motion vector detected in the | |
| 2828 // first pass, and so do its previous and forward frames, then this frame | |
| 2829 // can be skipped for partition check, and the partition size is assigned | |
| 2830 // according to the variance | |
| 2831 const SVC *const svc = &cpi->svc; | |
| 2832 const TWO_PASS *const twopass = is_two_pass_svc(cpi) ? | |
| 2833 &svc->layer_context[svc->spatial_layer_id].twopass : &cpi->twopass; | |
| 2834 | |
| 2835 return (!frame_is_intra_only(&cpi->common) && | |
| 2836 twopass->stats_in - 2 > twopass->stats_in_start && | |
| 2837 twopass->stats_in < twopass->stats_in_end && | |
| 2838 (twopass->stats_in - 1)->pcnt_inter - (twopass->stats_in - 1)->pcnt_motion | |
| 2839 == 1 && | |
| 2840 (twopass->stats_in - 2)->pcnt_inter - (twopass->stats_in - 2)->pcnt_motion | |
| 2841 == 1 && | |
| 2842 twopass->stats_in->pcnt_inter - twopass->stats_in->pcnt_motion == 1); | |
| 2843 } | |
| 2844 | |
| 2845 static void set_arf_sign_bias(VP9_COMP *cpi) { | 3077 static void set_arf_sign_bias(VP9_COMP *cpi) { |
| 2846 VP9_COMMON *const cm = &cpi->common; | 3078 VP9_COMMON *const cm = &cpi->common; |
| 2847 int arf_sign_bias; | 3079 int arf_sign_bias; |
| 2848 | 3080 |
| 2849 if ((cpi->oxcf.pass == 2) && cpi->multi_arf_allowed) { | 3081 if ((cpi->oxcf.pass == 2) && cpi->multi_arf_allowed) { |
| 2850 const GF_GROUP *const gf_group = &cpi->twopass.gf_group; | 3082 const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 2851 arf_sign_bias = cpi->rc.source_alt_ref_active && | 3083 arf_sign_bias = cpi->rc.source_alt_ref_active && |
| 2852 (!cpi->refresh_alt_ref_frame || | 3084 (!cpi->refresh_alt_ref_frame || |
| 2853 (gf_group->rf_level[gf_group->index] == GF_ARF_LOW)); | 3085 (gf_group->rf_level[gf_group->index] == GF_ARF_LOW)); |
| 2854 } else { | 3086 } else { |
| 2855 arf_sign_bias = | 3087 arf_sign_bias = |
| 2856 (cpi->rc.source_alt_ref_active && !cpi->refresh_alt_ref_frame); | 3088 (cpi->rc.source_alt_ref_active && !cpi->refresh_alt_ref_frame); |
| 2857 } | 3089 } |
| 2858 cm->ref_frame_sign_bias[ALTREF_FRAME] = arf_sign_bias; | 3090 cm->ref_frame_sign_bias[ALTREF_FRAME] = arf_sign_bias; |
| 2859 } | 3091 } |
| 2860 | 3092 |
| 2861 static void set_mv_search_params(VP9_COMP *cpi) { | |
| 2862 const VP9_COMMON *const cm = &cpi->common; | |
| 2863 const unsigned int max_mv_def = MIN(cm->width, cm->height); | |
| 2864 | |
| 2865 // Default based on max resolution. | |
| 2866 cpi->mv_step_param = vp9_init_search_range(max_mv_def); | |
| 2867 | |
| 2868 if (cpi->sf.mv.auto_mv_step_size) { | |
| 2869 if (frame_is_intra_only(cm)) { | |
| 2870 // Initialize max_mv_magnitude for use in the first INTER frame | |
| 2871 // after a key/intra-only frame. | |
| 2872 cpi->max_mv_magnitude = max_mv_def; | |
| 2873 } else { | |
| 2874 if (cm->show_frame) | |
| 2875 // Allow mv_steps to correspond to twice the max mv magnitude found | |
| 2876 // in the previous frame, capped by the default max_mv_magnitude based | |
| 2877 // on resolution. | |
| 2878 cpi->mv_step_param = | |
| 2879 vp9_init_search_range(MIN(max_mv_def, 2 * cpi->max_mv_magnitude)); | |
| 2880 cpi->max_mv_magnitude = 0; | |
| 2881 } | |
| 2882 } | |
| 2883 } | |
| 2884 | |
| 2885 | |
| 2886 int setup_interp_filter_search_mask(VP9_COMP *cpi) { | 3093 int setup_interp_filter_search_mask(VP9_COMP *cpi) { |
| 2887 INTERP_FILTER ifilter; | 3094 INTERP_FILTER ifilter; |
| 2888 int ref_total[MAX_REF_FRAMES] = {0}; | 3095 int ref_total[MAX_REF_FRAMES] = {0}; |
| 2889 MV_REFERENCE_FRAME ref; | 3096 MV_REFERENCE_FRAME ref; |
| 2890 int mask = 0; | 3097 int mask = 0; |
| 2891 if (cpi->common.last_frame_type == KEY_FRAME || | 3098 if (cpi->common.last_frame_type == KEY_FRAME || |
| 2892 cpi->refresh_alt_ref_frame) | 3099 cpi->refresh_alt_ref_frame) |
| 2893 return mask; | 3100 return mask; |
| 2894 for (ref = LAST_FRAME; ref <= ALTREF_FRAME; ++ref) | 3101 for (ref = LAST_FRAME; ref <= ALTREF_FRAME; ++ref) |
| 2895 for (ifilter = EIGHTTAP; ifilter <= EIGHTTAP_SHARP; ++ifilter) | 3102 for (ifilter = EIGHTTAP; ifilter <= EIGHTTAP_SHARP; ++ifilter) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2910 } | 3117 } |
| 2911 | 3118 |
| 2912 static void encode_frame_to_data_rate(VP9_COMP *cpi, | 3119 static void encode_frame_to_data_rate(VP9_COMP *cpi, |
| 2913 size_t *size, | 3120 size_t *size, |
| 2914 uint8_t *dest, | 3121 uint8_t *dest, |
| 2915 unsigned int *frame_flags) { | 3122 unsigned int *frame_flags) { |
| 2916 VP9_COMMON *const cm = &cpi->common; | 3123 VP9_COMMON *const cm = &cpi->common; |
| 2917 const VP9EncoderConfig *const oxcf = &cpi->oxcf; | 3124 const VP9EncoderConfig *const oxcf = &cpi->oxcf; |
| 2918 struct segmentation *const seg = &cm->seg; | 3125 struct segmentation *const seg = &cm->seg; |
| 2919 TX_SIZE t; | 3126 TX_SIZE t; |
| 2920 int q; | |
| 2921 int top_index; | |
| 2922 int bottom_index; | |
| 2923 | 3127 |
| 2924 set_ext_overrides(cpi); | 3128 set_ext_overrides(cpi); |
| 2925 | 3129 |
| 2926 cpi->Source = vp9_scale_if_required(cm, cpi->un_scaled_source, | |
| 2927 &cpi->scaled_source); | |
| 2928 | |
| 2929 if (cpi->unscaled_last_source != NULL) | |
| 2930 cpi->Last_Source = vp9_scale_if_required(cm, cpi->unscaled_last_source, | |
| 2931 &cpi->scaled_last_source); | |
| 2932 | |
| 2933 vp9_scale_references(cpi); | |
| 2934 | |
| 2935 vp9_clear_system_state(); | 3130 vp9_clear_system_state(); |
| 2936 | 3131 |
| 2937 // Enable or disable mode based tweaking of the zbin. | 3132 // Enable or disable mode based tweaking of the zbin. |
| 2938 // For 2 pass only used where GF/ARF prediction quality | 3133 // For 2 pass only used where GF/ARF prediction quality |
| 2939 // is above a threshold. | 3134 // is above a threshold. |
| 2940 cpi->zbin_mode_boost = 0; | 3135 cpi->zbin_mode_boost = 0; |
| 2941 cpi->zbin_mode_boost_enabled = 0; | 3136 cpi->zbin_mode_boost_enabled = 0; |
| 2942 | 3137 |
| 2943 // Set the arf sign bias for this frame. | 3138 // Set the arf sign bias for this frame. |
| 2944 set_arf_sign_bias(cpi); | 3139 set_arf_sign_bias(cpi); |
| 2945 | 3140 |
| 2946 // Set default state for segment based loop filter update flags. | 3141 // Set default state for segment based loop filter update flags. |
| 2947 cm->lf.mode_ref_delta_update = 0; | 3142 cm->lf.mode_ref_delta_update = 0; |
| 2948 | 3143 |
| 2949 set_mv_search_params(cpi); | |
| 2950 | |
| 2951 if (cpi->oxcf.pass == 2 && | 3144 if (cpi->oxcf.pass == 2 && |
| 2952 cpi->sf.adaptive_interp_filter_search) | 3145 cpi->sf.adaptive_interp_filter_search) |
| 2953 cpi->sf.interp_filter_search_mask = | 3146 cpi->sf.interp_filter_search_mask = |
| 2954 setup_interp_filter_search_mask(cpi); | 3147 setup_interp_filter_search_mask(cpi); |
| 2955 | 3148 |
| 2956 | |
| 2957 // Set various flags etc to special state if it is a key frame. | 3149 // Set various flags etc to special state if it is a key frame. |
| 2958 if (frame_is_intra_only(cm)) { | 3150 if (frame_is_intra_only(cm)) { |
| 2959 // Reset the loop filter deltas and segmentation map. | 3151 // Reset the loop filter deltas and segmentation map. |
| 2960 vp9_reset_segment_features(&cm->seg); | 3152 vp9_reset_segment_features(&cm->seg); |
| 2961 | 3153 |
| 2962 // If segmentation is enabled force a map update for key frames. | 3154 // If segmentation is enabled force a map update for key frames. |
| 2963 if (seg->enabled) { | 3155 if (seg->enabled) { |
| 2964 seg->update_map = 1; | 3156 seg->update_map = 1; |
| 2965 seg->update_data = 1; | 3157 seg->update_data = 1; |
| 2966 } | 3158 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3006 if (cpi->svc.layer_context[0].frames_from_key_frame == 1 << i) { | 3198 if (cpi->svc.layer_context[0].frames_from_key_frame == 1 << i) { |
| 3007 cm->frame_parallel_decoding_mode = 1; | 3199 cm->frame_parallel_decoding_mode = 1; |
| 3008 break; | 3200 break; |
| 3009 } | 3201 } |
| 3010 } | 3202 } |
| 3011 if (i == cpi->svc.number_temporal_layers) | 3203 if (i == cpi->svc.number_temporal_layers) |
| 3012 cm->frame_parallel_decoding_mode = 0; | 3204 cm->frame_parallel_decoding_mode = 0; |
| 3013 } | 3205 } |
| 3014 } | 3206 } |
| 3015 | 3207 |
| 3016 // Configure experimental use of segmentation for enhanced coding of | |
| 3017 // static regions if indicated. | |
| 3018 // Only allowed in second pass of two pass (as requires lagged coding) | |
| 3019 // and if the relevant speed feature flag is set. | |
| 3020 if (oxcf->pass == 2 && cpi->sf.static_segmentation) | |
| 3021 configure_static_seg_features(cpi); | |
| 3022 | |
| 3023 // Check if the current frame is skippable for the partition search in the | |
| 3024 // second pass according to the first pass stats | |
| 3025 if (cpi->sf.allow_partition_search_skip && oxcf->pass == 2 && | |
| 3026 (!cpi->use_svc || is_two_pass_svc(cpi))) { | |
| 3027 cpi->partition_search_skippable_frame = is_skippable_frame(cpi); | |
| 3028 } | |
| 3029 | |
| 3030 // For 1 pass CBR, check if we are dropping this frame. | 3208 // For 1 pass CBR, check if we are dropping this frame. |
| 3031 // Never drop on key frame. | 3209 // Never drop on key frame. |
| 3032 if (oxcf->pass == 0 && | 3210 if (oxcf->pass == 0 && |
| 3033 oxcf->rc_mode == VPX_CBR && | 3211 oxcf->rc_mode == VPX_CBR && |
| 3034 cm->frame_type != KEY_FRAME) { | 3212 cm->frame_type != KEY_FRAME) { |
| 3035 if (vp9_rc_drop_frame(cpi)) { | 3213 if (vp9_rc_drop_frame(cpi)) { |
| 3036 vp9_rc_postencode_update_drop_frame(cpi); | 3214 vp9_rc_postencode_update_drop_frame(cpi); |
| 3037 ++cm->current_video_frame; | 3215 ++cm->current_video_frame; |
| 3038 return; | 3216 return; |
| 3039 } | 3217 } |
| 3040 } | 3218 } |
| 3041 | 3219 |
| 3042 vp9_clear_system_state(); | 3220 vp9_clear_system_state(); |
| 3043 | 3221 |
| 3044 #if CONFIG_VP9_POSTPROC | |
| 3045 if (oxcf->noise_sensitivity > 0) { | |
| 3046 int l = 0; | |
| 3047 switch (oxcf->noise_sensitivity) { | |
| 3048 case 1: | |
| 3049 l = 20; | |
| 3050 break; | |
| 3051 case 2: | |
| 3052 l = 40; | |
| 3053 break; | |
| 3054 case 3: | |
| 3055 l = 60; | |
| 3056 break; | |
| 3057 case 4: | |
| 3058 case 5: | |
| 3059 l = 100; | |
| 3060 break; | |
| 3061 case 6: | |
| 3062 l = 150; | |
| 3063 break; | |
| 3064 } | |
| 3065 vp9_denoise(cpi->Source, cpi->Source, l); | |
| 3066 } | |
| 3067 #endif | |
| 3068 | |
| 3069 #if CONFIG_INTERNAL_STATS | 3222 #if CONFIG_INTERNAL_STATS |
| 3070 { | 3223 { |
| 3071 int i; | 3224 int i; |
| 3072 for (i = 0; i < MAX_MODES; ++i) | 3225 for (i = 0; i < MAX_MODES; ++i) |
| 3073 cpi->mode_chosen_counts[i] = 0; | 3226 cpi->mode_chosen_counts[i] = 0; |
| 3074 } | 3227 } |
| 3075 #endif | 3228 #endif |
| 3076 | 3229 |
| 3077 vp9_set_speed_features(cpi); | |
| 3078 | |
| 3079 vp9_set_rd_speed_thresholds(cpi); | |
| 3080 vp9_set_rd_speed_thresholds_sub8x8(cpi); | |
| 3081 | |
| 3082 // Decide q and q bounds. | |
| 3083 q = vp9_rc_pick_q_and_bounds(cpi, &bottom_index, &top_index); | |
| 3084 | |
| 3085 if (!frame_is_intra_only(cm)) { | |
| 3086 cm->interp_filter = cpi->sf.default_interp_filter; | |
| 3087 /* TODO: Decide this more intelligently */ | |
| 3088 vp9_set_high_precision_mv(cpi, q < HIGH_PRECISION_MV_QTHRESH); | |
| 3089 } | |
| 3090 | |
| 3091 if (cpi->sf.recode_loop == DISALLOW_RECODE) { | 3230 if (cpi->sf.recode_loop == DISALLOW_RECODE) { |
| 3092 encode_without_recode_loop(cpi, q); | 3231 encode_without_recode_loop(cpi); |
| 3093 } else { | 3232 } else { |
| 3094 encode_with_recode_loop(cpi, size, dest, q, bottom_index, top_index); | 3233 encode_with_recode_loop(cpi, size, dest); |
| 3095 } | 3234 } |
| 3096 | 3235 |
| 3097 #if CONFIG_VP9_TEMPORAL_DENOISING | 3236 #if CONFIG_VP9_TEMPORAL_DENOISING |
| 3098 #ifdef OUTPUT_YUV_DENOISED | 3237 #ifdef OUTPUT_YUV_DENOISED |
| 3099 if (oxcf->noise_sensitivity > 0) { | 3238 if (oxcf->noise_sensitivity > 0) { |
| 3100 vp9_write_yuv_frame_420(&cpi->denoiser.running_avg_y[INTRA_FRAME], | 3239 vp9_write_yuv_frame_420(&cpi->denoiser.running_avg_y[INTRA_FRAME], |
| 3101 yuv_denoised_file); | 3240 yuv_denoised_file); |
| 3102 } | 3241 } |
| 3103 #endif | 3242 #endif |
| 3104 #endif | 3243 #endif |
| (...skipping 24 matching lines...) Expand all Loading... |
| 3129 | 3268 |
| 3130 // Pick the loop filter level for the frame. | 3269 // Pick the loop filter level for the frame. |
| 3131 loopfilter_frame(cpi, cm); | 3270 loopfilter_frame(cpi, cm); |
| 3132 | 3271 |
| 3133 // build the bitstream | 3272 // build the bitstream |
| 3134 vp9_pack_bitstream(cpi, dest, size); | 3273 vp9_pack_bitstream(cpi, dest, size); |
| 3135 | 3274 |
| 3136 if (cm->seg.update_map) | 3275 if (cm->seg.update_map) |
| 3137 update_reference_segmentation_map(cpi); | 3276 update_reference_segmentation_map(cpi); |
| 3138 | 3277 |
| 3139 release_scaled_references(cpi); | 3278 if (frame_is_intra_only(cm) == 0) { |
| 3279 release_scaled_references(cpi); |
| 3280 } |
| 3140 vp9_update_reference_frames(cpi); | 3281 vp9_update_reference_frames(cpi); |
| 3141 | 3282 |
| 3142 for (t = TX_4X4; t <= TX_32X32; t++) | 3283 for (t = TX_4X4; t <= TX_32X32; t++) |
| 3143 full_to_model_counts(cm->counts.coef[t], cpi->coef_counts[t]); | 3284 full_to_model_counts(cm->counts.coef[t], cpi->frame_counts->coef_counts[t]); |
| 3144 | 3285 |
| 3145 if (!cm->error_resilient_mode && !cm->frame_parallel_decoding_mode) | 3286 if (!cm->error_resilient_mode && !cm->frame_parallel_decoding_mode) |
| 3146 vp9_adapt_coef_probs(cm); | 3287 vp9_adapt_coef_probs(cm); |
| 3147 | 3288 |
| 3148 if (!frame_is_intra_only(cm)) { | 3289 if (!frame_is_intra_only(cm)) { |
| 3149 if (!cm->error_resilient_mode && !cm->frame_parallel_decoding_mode) { | 3290 if (!cm->error_resilient_mode && !cm->frame_parallel_decoding_mode) { |
| 3150 vp9_adapt_mode_probs(cm); | 3291 vp9_adapt_mode_probs(cm); |
| 3151 vp9_adapt_mv_probs(cm, cm->allow_high_precision_mv); | 3292 vp9_adapt_mv_probs(cm, cm->allow_high_precision_mv); |
| 3152 } | 3293 } |
| 3153 } | 3294 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3189 // keep track of the last coded dimensions | 3330 // keep track of the last coded dimensions |
| 3190 cm->last_width = cm->width; | 3331 cm->last_width = cm->width; |
| 3191 cm->last_height = cm->height; | 3332 cm->last_height = cm->height; |
| 3192 | 3333 |
| 3193 // reset to normal state now that we are done. | 3334 // reset to normal state now that we are done. |
| 3194 if (!cm->show_existing_frame) | 3335 if (!cm->show_existing_frame) |
| 3195 cm->last_show_frame = cm->show_frame; | 3336 cm->last_show_frame = cm->show_frame; |
| 3196 | 3337 |
| 3197 if (cm->show_frame) { | 3338 if (cm->show_frame) { |
| 3198 vp9_swap_mi_and_prev_mi(cm); | 3339 vp9_swap_mi_and_prev_mi(cm); |
| 3199 | |
| 3200 // Don't increment frame counters if this was an altref buffer | 3340 // Don't increment frame counters if this was an altref buffer |
| 3201 // update not a real frame | 3341 // update not a real frame |
| 3202 ++cm->current_video_frame; | 3342 ++cm->current_video_frame; |
| 3203 if (cpi->use_svc) | 3343 if (cpi->use_svc) |
| 3204 vp9_inc_frame_in_layer(cpi); | 3344 vp9_inc_frame_in_layer(cpi); |
| 3205 } | 3345 } |
| 3346 cm->prev_frame = cm->cur_frame; |
| 3206 | 3347 |
| 3207 if (is_two_pass_svc(cpi)) | 3348 if (is_two_pass_svc(cpi)) |
| 3208 cpi->svc.layer_context[cpi->svc.spatial_layer_id].last_frame_type = | 3349 cpi->svc.layer_context[cpi->svc.spatial_layer_id].last_frame_type = |
| 3209 cm->frame_type; | 3350 cm->frame_type; |
| 3210 } | 3351 } |
| 3211 | 3352 |
| 3212 static void SvcEncode(VP9_COMP *cpi, size_t *size, uint8_t *dest, | 3353 static void SvcEncode(VP9_COMP *cpi, size_t *size, uint8_t *dest, |
| 3213 unsigned int *frame_flags) { | 3354 unsigned int *frame_flags) { |
| 3214 vp9_rc_get_svc_params(cpi); | 3355 vp9_rc_get_svc_params(cpi); |
| 3215 encode_frame_to_data_rate(cpi, size, dest, frame_flags); | 3356 encode_frame_to_data_rate(cpi, size, dest, frame_flags); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3227 | 3368 |
| 3228 static void Pass2Encode(VP9_COMP *cpi, size_t *size, | 3369 static void Pass2Encode(VP9_COMP *cpi, size_t *size, |
| 3229 uint8_t *dest, unsigned int *frame_flags) { | 3370 uint8_t *dest, unsigned int *frame_flags) { |
| 3230 cpi->allow_encode_breakout = ENCODE_BREAKOUT_ENABLED; | 3371 cpi->allow_encode_breakout = ENCODE_BREAKOUT_ENABLED; |
| 3231 encode_frame_to_data_rate(cpi, size, dest, frame_flags); | 3372 encode_frame_to_data_rate(cpi, size, dest, frame_flags); |
| 3232 | 3373 |
| 3233 if (!(is_two_pass_svc(cpi) && cpi->svc.encode_empty_frame_state == ENCODING)) | 3374 if (!(is_two_pass_svc(cpi) && cpi->svc.encode_empty_frame_state == ENCODING)) |
| 3234 vp9_twopass_postencode_update(cpi); | 3375 vp9_twopass_postencode_update(cpi); |
| 3235 } | 3376 } |
| 3236 | 3377 |
| 3237 static void init_motion_estimation(VP9_COMP *cpi) { | |
| 3238 int y_stride = cpi->scaled_source.y_stride; | |
| 3239 | |
| 3240 if (cpi->sf.mv.search_method == NSTEP) { | |
| 3241 vp9_init3smotion_compensation(&cpi->ss_cfg, y_stride); | |
| 3242 } else if (cpi->sf.mv.search_method == DIAMOND) { | |
| 3243 vp9_init_dsmotion_compensation(&cpi->ss_cfg, y_stride); | |
| 3244 } | |
| 3245 } | |
| 3246 | |
| 3247 static void check_initial_width(VP9_COMP *cpi, | 3378 static void check_initial_width(VP9_COMP *cpi, |
| 3248 #if CONFIG_VP9_HIGHBITDEPTH | 3379 #if CONFIG_VP9_HIGHBITDEPTH |
| 3249 int use_highbitdepth, | 3380 int use_highbitdepth, |
| 3250 #endif | 3381 #endif |
| 3251 int subsampling_x, int subsampling_y) { | 3382 int subsampling_x, int subsampling_y) { |
| 3252 VP9_COMMON *const cm = &cpi->common; | 3383 VP9_COMMON *const cm = &cpi->common; |
| 3253 | 3384 |
| 3254 if (!cpi->initial_width) { | 3385 if (!cpi->initial_width) { |
| 3255 cm->subsampling_x = subsampling_x; | 3386 cm->subsampling_x = subsampling_x; |
| 3256 cm->subsampling_y = subsampling_y; | 3387 cm->subsampling_y = subsampling_y; |
| 3257 #if CONFIG_VP9_HIGHBITDEPTH | 3388 #if CONFIG_VP9_HIGHBITDEPTH |
| 3258 cm->use_highbitdepth = use_highbitdepth; | 3389 cm->use_highbitdepth = use_highbitdepth; |
| 3259 #endif | 3390 #endif |
| 3260 | 3391 |
| 3261 alloc_raw_frame_buffers(cpi); | 3392 alloc_raw_frame_buffers(cpi); |
| 3262 alloc_ref_frame_buffers(cpi); | 3393 alloc_ref_frame_buffers(cpi); |
| 3263 alloc_util_frame_buffers(cpi); | 3394 alloc_util_frame_buffers(cpi); |
| 3264 | 3395 |
| 3265 init_motion_estimation(cpi); | 3396 init_motion_estimation(cpi); // TODO(agrange) This can be removed. |
| 3266 | 3397 |
| 3267 cpi->initial_width = cm->width; | 3398 cpi->initial_width = cm->width; |
| 3268 cpi->initial_height = cm->height; | 3399 cpi->initial_height = cm->height; |
| 3400 cpi->initial_mbs = cm->MBs; |
| 3269 } | 3401 } |
| 3270 } | 3402 } |
| 3271 | 3403 |
| 3272 | 3404 |
| 3273 int vp9_receive_raw_frame(VP9_COMP *cpi, unsigned int frame_flags, | 3405 int vp9_receive_raw_frame(VP9_COMP *cpi, unsigned int frame_flags, |
| 3274 YV12_BUFFER_CONFIG *sd, int64_t time_stamp, | 3406 YV12_BUFFER_CONFIG *sd, int64_t time_stamp, |
| 3275 int64_t end_time) { | 3407 int64_t end_time) { |
| 3276 VP9_COMMON *cm = &cpi->common; | 3408 VP9_COMMON *cm = &cpi->common; |
| 3277 struct vpx_usec_timer timer; | 3409 struct vpx_usec_timer timer; |
| 3278 int res = 0; | 3410 int res = 0; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3400 // become the GF so preserve last as an alternative prediction option. | 3532 // become the GF so preserve last as an alternative prediction option. |
| 3401 cpi->refresh_last_frame = 0; | 3533 cpi->refresh_last_frame = 0; |
| 3402 } | 3534 } |
| 3403 } | 3535 } |
| 3404 | 3536 |
| 3405 int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, | 3537 int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, |
| 3406 size_t *size, uint8_t *dest, | 3538 size_t *size, uint8_t *dest, |
| 3407 int64_t *time_stamp, int64_t *time_end, int flush) { | 3539 int64_t *time_stamp, int64_t *time_end, int flush) { |
| 3408 const VP9EncoderConfig *const oxcf = &cpi->oxcf; | 3540 const VP9EncoderConfig *const oxcf = &cpi->oxcf; |
| 3409 VP9_COMMON *const cm = &cpi->common; | 3541 VP9_COMMON *const cm = &cpi->common; |
| 3410 MACROBLOCKD *const xd = &cpi->mb.e_mbd; | |
| 3411 RATE_CONTROL *const rc = &cpi->rc; | 3542 RATE_CONTROL *const rc = &cpi->rc; |
| 3412 struct vpx_usec_timer cmptimer; | 3543 struct vpx_usec_timer cmptimer; |
| 3413 YV12_BUFFER_CONFIG *force_src_buffer = NULL; | 3544 YV12_BUFFER_CONFIG *force_src_buffer = NULL; |
| 3414 struct lookahead_entry *last_source = NULL; | 3545 struct lookahead_entry *last_source = NULL; |
| 3415 struct lookahead_entry *source = NULL; | 3546 struct lookahead_entry *source = NULL; |
| 3416 MV_REFERENCE_FRAME ref_frame; | |
| 3417 int arf_src_index; | 3547 int arf_src_index; |
| 3548 int i; |
| 3418 | 3549 |
| 3419 if (is_two_pass_svc(cpi)) { | 3550 if (is_two_pass_svc(cpi)) { |
| 3420 #if CONFIG_SPATIAL_SVC | 3551 #if CONFIG_SPATIAL_SVC |
| 3421 vp9_svc_start_frame(cpi); | 3552 vp9_svc_start_frame(cpi); |
| 3422 // Use a small empty frame instead of a real frame | 3553 // Use a small empty frame instead of a real frame |
| 3423 if (cpi->svc.encode_empty_frame_state == ENCODING) | 3554 if (cpi->svc.encode_empty_frame_state == ENCODING) |
| 3424 source = &cpi->svc.empty_frame; | 3555 source = &cpi->svc.empty_frame; |
| 3425 #endif | 3556 #endif |
| 3426 if (oxcf->pass == 2) | 3557 if (oxcf->pass == 2) |
| 3427 vp9_restore_layer_context(cpi); | 3558 vp9_restore_layer_context(cpi); |
| 3428 } | 3559 } |
| 3429 | 3560 |
| 3430 vpx_usec_timer_start(&cmptimer); | 3561 vpx_usec_timer_start(&cmptimer); |
| 3431 | 3562 |
| 3432 vp9_set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV); | 3563 vp9_set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV); |
| 3433 | 3564 |
| 3565 // Is multi-arf enabled. |
| 3566 // Note that at the moment multi_arf is only configured for 2 pass VBR and |
| 3567 // will not work properly with svc. |
| 3568 if ((oxcf->pass == 2) && !cpi->use_svc && |
| 3569 (cpi->oxcf.enable_auto_arf > 1)) |
| 3570 cpi->multi_arf_allowed = 1; |
| 3571 else |
| 3572 cpi->multi_arf_allowed = 0; |
| 3573 |
| 3434 // Normal defaults | 3574 // Normal defaults |
| 3435 cm->reset_frame_context = 0; | 3575 cm->reset_frame_context = 0; |
| 3436 cm->refresh_frame_context = 1; | 3576 cm->refresh_frame_context = 1; |
| 3437 cpi->refresh_last_frame = 1; | 3577 cpi->refresh_last_frame = 1; |
| 3438 cpi->refresh_golden_frame = 0; | 3578 cpi->refresh_golden_frame = 0; |
| 3439 cpi->refresh_alt_ref_frame = 0; | 3579 cpi->refresh_alt_ref_frame = 0; |
| 3440 | 3580 |
| 3441 // Should we encode an arf frame. | 3581 // Should we encode an arf frame. |
| 3442 arf_src_index = get_arf_src_index(cpi); | 3582 arf_src_index = get_arf_src_index(cpi); |
| 3443 | 3583 |
| 3444 // Skip alt frame if we encode the empty frame | 3584 // Skip alt frame if we encode the empty frame |
| 3445 if (is_two_pass_svc(cpi) && source != NULL) | 3585 if (is_two_pass_svc(cpi) && source != NULL) |
| 3446 arf_src_index = 0; | 3586 arf_src_index = 0; |
| 3447 | 3587 |
| 3448 if (arf_src_index) { | 3588 if (arf_src_index) { |
| 3449 assert(arf_src_index <= rc->frames_to_key); | 3589 assert(arf_src_index <= rc->frames_to_key); |
| 3450 | 3590 |
| 3451 if ((source = vp9_lookahead_peek(cpi->lookahead, arf_src_index)) != NULL) { | 3591 if ((source = vp9_lookahead_peek(cpi->lookahead, arf_src_index)) != NULL) { |
| 3452 cpi->alt_ref_source = source; | 3592 cpi->alt_ref_source = source; |
| 3453 | 3593 |
| 3454 #if CONFIG_SPATIAL_SVC | 3594 #if CONFIG_SPATIAL_SVC |
| 3455 if (is_two_pass_svc(cpi) && cpi->svc.spatial_layer_id > 0) { | 3595 if (is_two_pass_svc(cpi) && cpi->svc.spatial_layer_id > 0) { |
| 3456 int i; | 3596 int i; |
| 3457 // Reference a hidden frame from a lower layer | 3597 // Reference a hidden frame from a lower layer |
| 3458 for (i = cpi->svc.spatial_layer_id - 1; i >= 0; --i) { | 3598 for (i = cpi->svc.spatial_layer_id - 1; i >= 0; --i) { |
| 3459 if (oxcf->ss_play_alternate[i]) { | 3599 if (oxcf->ss_enable_auto_arf[i]) { |
| 3460 cpi->gld_fb_idx = cpi->svc.layer_context[i].alt_ref_idx; | 3600 cpi->gld_fb_idx = cpi->svc.layer_context[i].alt_ref_idx; |
| 3461 break; | 3601 break; |
| 3462 } | 3602 } |
| 3463 } | 3603 } |
| 3464 } | 3604 } |
| 3465 cpi->svc.layer_context[cpi->svc.spatial_layer_id].has_alt_frame = 1; | 3605 cpi->svc.layer_context[cpi->svc.spatial_layer_id].has_alt_frame = 1; |
| 3466 #endif | 3606 #endif |
| 3467 | 3607 |
| 3468 if (oxcf->arnr_max_frames > 0) { | 3608 if (oxcf->arnr_max_frames > 0) { |
| 3469 // Produce the filtered ARF frame. | 3609 // Produce the filtered ARF frame. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 3493 // Read in the source frame. | 3633 // Read in the source frame. |
| 3494 #if CONFIG_SPATIAL_SVC | 3634 #if CONFIG_SPATIAL_SVC |
| 3495 if (is_two_pass_svc(cpi)) | 3635 if (is_two_pass_svc(cpi)) |
| 3496 source = vp9_svc_lookahead_pop(cpi, cpi->lookahead, flush); | 3636 source = vp9_svc_lookahead_pop(cpi, cpi->lookahead, flush); |
| 3497 else | 3637 else |
| 3498 #endif | 3638 #endif |
| 3499 source = vp9_lookahead_pop(cpi->lookahead, flush); | 3639 source = vp9_lookahead_pop(cpi->lookahead, flush); |
| 3500 if (source != NULL) { | 3640 if (source != NULL) { |
| 3501 cm->show_frame = 1; | 3641 cm->show_frame = 1; |
| 3502 cm->intra_only = 0; | 3642 cm->intra_only = 0; |
| 3643 // if the flags indicate intra frame, but if the current picture is for |
| 3644 // non-zero spatial layer, it should not be an intra picture. |
| 3645 // TODO(Won Kap): this needs to change if per-layer intra frame is |
| 3646 // allowed. |
| 3647 if ((source->flags | VPX_EFLAG_FORCE_KF) && cpi->svc.spatial_layer_id) { |
| 3648 source->flags &= ~(unsigned int)(VPX_EFLAG_FORCE_KF); |
| 3649 } |
| 3503 | 3650 |
| 3504 // Check to see if the frame should be encoded as an arf overlay. | 3651 // Check to see if the frame should be encoded as an arf overlay. |
| 3505 check_src_altref(cpi, source); | 3652 check_src_altref(cpi, source); |
| 3506 } | 3653 } |
| 3507 } | 3654 } |
| 3508 | 3655 |
| 3509 if (source) { | 3656 if (source) { |
| 3510 cpi->un_scaled_source = cpi->Source = force_src_buffer ? force_src_buffer | 3657 cpi->un_scaled_source = cpi->Source = force_src_buffer ? force_src_buffer |
| 3511 : &source->img; | 3658 : &source->img; |
| 3512 | 3659 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 3537 if (cm->show_frame) { | 3684 if (cm->show_frame) { |
| 3538 adjust_frame_rate(cpi, source); | 3685 adjust_frame_rate(cpi, source); |
| 3539 } | 3686 } |
| 3540 | 3687 |
| 3541 if (cpi->svc.number_temporal_layers > 1 && | 3688 if (cpi->svc.number_temporal_layers > 1 && |
| 3542 oxcf->rc_mode == VPX_CBR) { | 3689 oxcf->rc_mode == VPX_CBR) { |
| 3543 vp9_update_temporal_layer_framerate(cpi); | 3690 vp9_update_temporal_layer_framerate(cpi); |
| 3544 vp9_restore_layer_context(cpi); | 3691 vp9_restore_layer_context(cpi); |
| 3545 } | 3692 } |
| 3546 | 3693 |
| 3547 // start with a 0 size frame | 3694 // Find a free buffer for the new frame, releasing the reference previously |
| 3548 *size = 0; | 3695 // held. |
| 3549 | |
| 3550 /* find a free buffer for the new frame, releasing the reference previously | |
| 3551 * held. | |
| 3552 */ | |
| 3553 cm->frame_bufs[cm->new_fb_idx].ref_count--; | 3696 cm->frame_bufs[cm->new_fb_idx].ref_count--; |
| 3554 cm->new_fb_idx = get_free_fb(cm); | 3697 cm->new_fb_idx = get_free_fb(cm); |
| 3555 | 3698 cm->cur_frame = &cm->frame_bufs[cm->new_fb_idx]; |
| 3556 // For two pass encodes analyse the first pass stats and determine | |
| 3557 // the bit allocation and other parameters for this frame / group of frames. | |
| 3558 if ((oxcf->pass == 2) && | |
| 3559 (!cpi->use_svc || | |
| 3560 (is_two_pass_svc(cpi) && | |
| 3561 cpi->svc.encode_empty_frame_state != ENCODING))) { | |
| 3562 vp9_rc_get_second_pass_params(cpi); | |
| 3563 } | |
| 3564 | 3699 |
| 3565 if (!cpi->use_svc && cpi->multi_arf_allowed) { | 3700 if (!cpi->use_svc && cpi->multi_arf_allowed) { |
| 3566 if (cm->frame_type == KEY_FRAME) { | 3701 if (cm->frame_type == KEY_FRAME) { |
| 3567 init_buffer_indices(cpi); | 3702 init_buffer_indices(cpi); |
| 3568 } else if (oxcf->pass == 2) { | 3703 } else if (oxcf->pass == 2) { |
| 3569 const GF_GROUP *const gf_group = &cpi->twopass.gf_group; | 3704 const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 3570 cpi->alt_fb_idx = gf_group->arf_ref_idx[gf_group->index]; | 3705 cpi->alt_fb_idx = gf_group->arf_ref_idx[gf_group->index]; |
| 3571 } | 3706 } |
| 3572 } | 3707 } |
| 3573 | 3708 |
| 3709 // Start with a 0 size frame. |
| 3710 *size = 0; |
| 3711 |
| 3574 cpi->frame_flags = *frame_flags; | 3712 cpi->frame_flags = *frame_flags; |
| 3575 | 3713 |
| 3576 if (oxcf->pass == 2 && | 3714 if ((oxcf->pass == 2) && |
| 3577 cm->current_video_frame == 0 && | 3715 (!cpi->use_svc || |
| 3578 oxcf->allow_spatial_resampling && | 3716 (is_two_pass_svc(cpi) && |
| 3579 oxcf->rc_mode == VPX_VBR) { | 3717 cpi->svc.encode_empty_frame_state != ENCODING))) { |
| 3580 // Internal scaling is triggered on the first frame. | 3718 vp9_rc_get_second_pass_params(cpi); |
| 3581 vp9_set_size_literal(cpi, oxcf->scaled_frame_width, | 3719 } else { |
| 3582 oxcf->scaled_frame_height); | 3720 set_frame_size(cpi); |
| 3583 } | 3721 } |
| 3584 | 3722 |
| 3585 // Reset the frame pointers to the current frame size | 3723 for (i = 0; i < MAX_REF_FRAMES; ++i) |
| 3586 vp9_realloc_frame_buffer(get_frame_new_buffer(cm), | 3724 cpi->scaled_ref_idx[i] = INVALID_REF_BUFFER_IDX; |
| 3587 cm->width, cm->height, | |
| 3588 cm->subsampling_x, cm->subsampling_y, | |
| 3589 #if CONFIG_VP9_HIGHBITDEPTH | |
| 3590 cm->use_highbitdepth, | |
| 3591 #endif | |
| 3592 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL); | |
| 3593 | |
| 3594 alloc_util_frame_buffers(cpi); | |
| 3595 init_motion_estimation(cpi); | |
| 3596 | |
| 3597 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { | |
| 3598 const int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)]; | |
| 3599 YV12_BUFFER_CONFIG *const buf = &cm->frame_bufs[idx].buf; | |
| 3600 RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - 1]; | |
| 3601 ref_buf->buf = buf; | |
| 3602 ref_buf->idx = idx; | |
| 3603 #if CONFIG_VP9_HIGHBITDEPTH | |
| 3604 vp9_setup_scale_factors_for_frame(&ref_buf->sf, | |
| 3605 buf->y_crop_width, buf->y_crop_height, | |
| 3606 cm->width, cm->height, | |
| 3607 (buf->flags & YV12_FLAG_HIGHBITDEPTH) ? | |
| 3608 1 : 0); | |
| 3609 #else | |
| 3610 vp9_setup_scale_factors_for_frame(&ref_buf->sf, | |
| 3611 buf->y_crop_width, buf->y_crop_height, | |
| 3612 cm->width, cm->height); | |
| 3613 #endif // CONFIG_VP9_HIGHBITDEPTH | |
| 3614 if (vp9_is_scaled(&ref_buf->sf)) | |
| 3615 vp9_extend_frame_borders(buf); | |
| 3616 } | |
| 3617 | |
| 3618 set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME); | |
| 3619 | |
| 3620 if (oxcf->aq_mode == VARIANCE_AQ) { | |
| 3621 vp9_vaq_init(); | |
| 3622 } | |
| 3623 | 3725 |
| 3624 if (oxcf->pass == 1 && | 3726 if (oxcf->pass == 1 && |
| 3625 (!cpi->use_svc || is_two_pass_svc(cpi))) { | 3727 (!cpi->use_svc || is_two_pass_svc(cpi))) { |
| 3626 const int lossless = is_lossless_requested(oxcf); | 3728 const int lossless = is_lossless_requested(oxcf); |
| 3627 #if CONFIG_VP9_HIGHBITDEPTH | 3729 #if CONFIG_VP9_HIGHBITDEPTH |
| 3628 if (cpi->oxcf.use_highbitdepth) | 3730 if (cpi->oxcf.use_highbitdepth) |
| 3629 cpi->mb.fwd_txm4x4 = lossless ? vp9_highbd_fwht4x4 : vp9_highbd_fdct4x4; | 3731 cpi->mb.fwd_txm4x4 = lossless ? vp9_highbd_fwht4x4 : vp9_highbd_fdct4x4; |
| 3630 else | 3732 else |
| 3631 cpi->mb.fwd_txm4x4 = lossless ? vp9_fwht4x4 : vp9_fdct4x4; | 3733 cpi->mb.fwd_txm4x4 = lossless ? vp9_fwht4x4 : vp9_fdct4x4; |
| 3632 cpi->mb.highbd_itxm_add = lossless ? vp9_highbd_iwht4x4_add : | 3734 cpi->mb.highbd_itxm_add = lossless ? vp9_highbd_iwht4x4_add : |
| 3633 vp9_highbd_idct4x4_add; | 3735 vp9_highbd_idct4x4_add; |
| 3634 #else | 3736 #else |
| 3635 cpi->mb.fwd_txm4x4 = lossless ? vp9_fwht4x4 : vp9_fdct4x4; | 3737 cpi->mb.fwd_txm4x4 = lossless ? vp9_fwht4x4 : vp9_fdct4x4; |
| 3636 #endif // CONFIG_VP9_HIGHBITDEPTH | 3738 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 3637 cpi->mb.itxm_add = lossless ? vp9_iwht4x4_add : vp9_idct4x4_add; | 3739 cpi->mb.itxm_add = lossless ? vp9_iwht4x4_add : vp9_idct4x4_add; |
| 3638 vp9_first_pass(cpi, source); | 3740 vp9_first_pass(cpi, source); |
| 3639 } else if (oxcf->pass == 2 && | 3741 } else if (oxcf->pass == 2 && |
| 3640 (!cpi->use_svc || is_two_pass_svc(cpi))) { | 3742 (!cpi->use_svc || is_two_pass_svc(cpi))) { |
| 3641 Pass2Encode(cpi, size, dest, frame_flags); | 3743 Pass2Encode(cpi, size, dest, frame_flags); |
| 3642 } else if (cpi->use_svc) { | 3744 } else if (cpi->use_svc) { |
| 3643 SvcEncode(cpi, size, dest, frame_flags); | 3745 SvcEncode(cpi, size, dest, frame_flags); |
| 3644 } else { | 3746 } else { |
| 3645 // One pass encode | 3747 // One pass encode |
| 3646 Pass0Encode(cpi, size, dest, frame_flags); | 3748 Pass0Encode(cpi, size, dest, frame_flags); |
| 3647 } | 3749 } |
| 3648 | 3750 |
| 3649 if (cm->refresh_frame_context) | 3751 if (cm->refresh_frame_context) |
| 3650 cm->frame_contexts[cm->frame_context_idx] = cm->fc; | 3752 cm->frame_contexts[cm->frame_context_idx] = *cm->fc; |
| 3651 | 3753 |
| 3652 // Frame was dropped, release scaled references. | 3754 // No frame encoded, or frame was dropped, release scaled references. |
| 3653 if (*size == 0) { | 3755 if ((*size == 0) && (frame_is_intra_only(cm) == 0)) { |
| 3654 release_scaled_references(cpi); | 3756 release_scaled_references(cpi); |
| 3655 } | 3757 } |
| 3656 | 3758 |
| 3657 if (*size > 0) { | 3759 if (*size > 0) { |
| 3658 cpi->droppable = !frame_is_reference(cpi); | 3760 cpi->droppable = !frame_is_reference(cpi); |
| 3659 } | 3761 } |
| 3660 | 3762 |
| 3661 // Save layer specific state. | 3763 // Save layer specific state. |
| 3662 if ((cpi->svc.number_temporal_layers > 1 && | 3764 if ((cpi->svc.number_temporal_layers > 1 && |
| 3663 oxcf->rc_mode == VPX_CBR) || | 3765 oxcf->rc_mode == VPX_CBR) || |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3988 if (flags & VP8_EFLAG_NO_UPD_ARF) | 4090 if (flags & VP8_EFLAG_NO_UPD_ARF) |
| 3989 upd ^= VP9_ALT_FLAG; | 4091 upd ^= VP9_ALT_FLAG; |
| 3990 | 4092 |
| 3991 vp9_update_reference(cpi, upd); | 4093 vp9_update_reference(cpi, upd); |
| 3992 } | 4094 } |
| 3993 | 4095 |
| 3994 if (flags & VP8_EFLAG_NO_UPD_ENTROPY) { | 4096 if (flags & VP8_EFLAG_NO_UPD_ENTROPY) { |
| 3995 vp9_update_entropy(cpi, 0); | 4097 vp9_update_entropy(cpi, 0); |
| 3996 } | 4098 } |
| 3997 } | 4099 } |
| OLD | NEW |