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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 static void dealloc_compressor_data(VP9_COMP *cpi) { | 197 static void dealloc_compressor_data(VP9_COMP *cpi) { |
198 VP9_COMMON *const cm = &cpi->common; | 198 VP9_COMMON *const cm = &cpi->common; |
199 int i; | 199 int i; |
200 | 200 |
201 vpx_free(cpi->tile_data); | 201 vpx_free(cpi->tile_data); |
202 cpi->tile_data = NULL; | 202 cpi->tile_data = NULL; |
203 | 203 |
204 // Delete sementation map | 204 // Delete sementation map |
205 vpx_free(cpi->segmentation_map); | 205 vpx_free(cpi->segmentation_map); |
206 cpi->segmentation_map = NULL; | 206 cpi->segmentation_map = NULL; |
207 vpx_free(cm->last_frame_seg_map); | |
208 cm->last_frame_seg_map = NULL; | |
209 vpx_free(cpi->coding_context.last_frame_seg_map_copy); | 207 vpx_free(cpi->coding_context.last_frame_seg_map_copy); |
210 cpi->coding_context.last_frame_seg_map_copy = NULL; | 208 cpi->coding_context.last_frame_seg_map_copy = NULL; |
211 | 209 |
212 vpx_free(cpi->nmvcosts[0]); | 210 vpx_free(cpi->nmvcosts[0]); |
213 vpx_free(cpi->nmvcosts[1]); | 211 vpx_free(cpi->nmvcosts[1]); |
214 cpi->nmvcosts[0] = NULL; | 212 cpi->nmvcosts[0] = NULL; |
215 cpi->nmvcosts[1] = NULL; | 213 cpi->nmvcosts[1] = NULL; |
216 | 214 |
217 vpx_free(cpi->nmvcosts_hp[0]); | 215 vpx_free(cpi->nmvcosts_hp[0]); |
218 vpx_free(cpi->nmvcosts_hp[1]); | 216 vpx_free(cpi->nmvcosts_hp[1]); |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 cache[0] = mi_8x8[0].src_mi->mbmi.segment_id; | 462 cache[0] = mi_8x8[0].src_mi->mbmi.segment_id; |
465 mi_8x8_ptr += cm->mi_stride; | 463 mi_8x8_ptr += cm->mi_stride; |
466 cache_ptr += cm->mi_cols; | 464 cache_ptr += cm->mi_cols; |
467 } | 465 } |
468 } | 466 } |
469 | 467 |
470 static void alloc_raw_frame_buffers(VP9_COMP *cpi) { | 468 static void alloc_raw_frame_buffers(VP9_COMP *cpi) { |
471 VP9_COMMON *cm = &cpi->common; | 469 VP9_COMMON *cm = &cpi->common; |
472 const VP9EncoderConfig *oxcf = &cpi->oxcf; | 470 const VP9EncoderConfig *oxcf = &cpi->oxcf; |
473 | 471 |
474 cpi->lookahead = vp9_lookahead_init(oxcf->width, oxcf->height, | 472 if (!cpi->lookahead) |
475 cm->subsampling_x, cm->subsampling_y, | 473 cpi->lookahead = vp9_lookahead_init(oxcf->width, oxcf->height, |
| 474 cm->subsampling_x, cm->subsampling_y, |
476 #if CONFIG_VP9_HIGHBITDEPTH | 475 #if CONFIG_VP9_HIGHBITDEPTH |
477 cm->use_highbitdepth, | 476 cm->use_highbitdepth, |
478 #endif | 477 #endif |
479 oxcf->lag_in_frames); | 478 oxcf->lag_in_frames); |
480 if (!cpi->lookahead) | 479 if (!cpi->lookahead) |
481 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, | 480 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, |
482 "Failed to allocate lag buffers"); | 481 "Failed to allocate lag buffers"); |
483 | 482 |
484 if (vp9_realloc_frame_buffer(&cpi->alt_ref_buffer, | 483 if (vp9_realloc_frame_buffer(&cpi->alt_ref_buffer, |
485 oxcf->width, oxcf->height, | 484 oxcf->width, oxcf->height, |
(...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1305 vp9_new_framerate(cpi, cpi->framerate); | 1304 vp9_new_framerate(cpi, cpi->framerate); |
1306 | 1305 |
1307 // Set absolute upper and lower quality limits | 1306 // Set absolute upper and lower quality limits |
1308 rc->worst_quality = cpi->oxcf.worst_allowed_q; | 1307 rc->worst_quality = cpi->oxcf.worst_allowed_q; |
1309 rc->best_quality = cpi->oxcf.best_allowed_q; | 1308 rc->best_quality = cpi->oxcf.best_allowed_q; |
1310 | 1309 |
1311 cm->interp_filter = cpi->sf.default_interp_filter; | 1310 cm->interp_filter = cpi->sf.default_interp_filter; |
1312 | 1311 |
1313 cm->display_width = cpi->oxcf.width; | 1312 cm->display_width = cpi->oxcf.width; |
1314 cm->display_height = cpi->oxcf.height; | 1313 cm->display_height = cpi->oxcf.height; |
| 1314 cm->width = cpi->oxcf.width; |
| 1315 cm->height = cpi->oxcf.height; |
1315 | 1316 |
1316 if (cpi->initial_width) { | 1317 if (cpi->initial_width) { |
1317 // Increasing the size of the frame beyond the first seen frame, or some | 1318 if (cm->width > cpi->initial_width || cm->height > cpi->initial_height) { |
1318 // otherwise signaled maximum size, is not supported. | 1319 vp9_free_context_buffers(cm); |
1319 // TODO(jkoleszar): exit gracefully. | 1320 vp9_alloc_context_buffers(cm, cm->width, cm->height); |
1320 assert(cm->width <= cpi->initial_width); | 1321 cpi->initial_width = cpi->initial_height = 0; |
1321 assert(cm->height <= cpi->initial_height); | 1322 } |
1322 } | 1323 } |
1323 update_frame_size(cpi); | 1324 update_frame_size(cpi); |
1324 | 1325 |
1325 if ((cpi->svc.number_temporal_layers > 1 && | 1326 if ((cpi->svc.number_temporal_layers > 1 && |
1326 cpi->oxcf.rc_mode == VPX_CBR) || | 1327 cpi->oxcf.rc_mode == VPX_CBR) || |
1327 ((cpi->svc.number_temporal_layers > 1 || | 1328 ((cpi->svc.number_temporal_layers > 1 || |
1328 cpi->svc.number_spatial_layers > 1) && | 1329 cpi->svc.number_spatial_layers > 1) && |
1329 cpi->oxcf.pass != 1)) { | 1330 cpi->oxcf.pass != 1)) { |
1330 vp9_update_layer_context_change_config(cpi, | 1331 vp9_update_layer_context_change_config(cpi, |
1331 (int)cpi->oxcf.target_bandwidth); | 1332 (int)cpi->oxcf.target_bandwidth); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1386 do { | 1387 do { |
1387 double z = 256 * (2 * (log2f(8 * i) + .6)); | 1388 double z = 256 * (2 * (log2f(8 * i) + .6)); |
1388 mvsadcost[0][i] = (int)z; | 1389 mvsadcost[0][i] = (int)z; |
1389 mvsadcost[1][i] = (int)z; | 1390 mvsadcost[1][i] = (int)z; |
1390 mvsadcost[0][-i] = (int)z; | 1391 mvsadcost[0][-i] = (int)z; |
1391 mvsadcost[1][-i] = (int)z; | 1392 mvsadcost[1][-i] = (int)z; |
1392 } while (++i <= MV_MAX); | 1393 } while (++i <= MV_MAX); |
1393 } | 1394 } |
1394 | 1395 |
1395 | 1396 |
1396 VP9_COMP *vp9_create_compressor(VP9EncoderConfig *oxcf) { | 1397 VP9_COMP *vp9_create_compressor(VP9EncoderConfig *oxcf, |
| 1398 BufferPool *const pool) { |
1397 unsigned int i; | 1399 unsigned int i; |
1398 VP9_COMP *volatile const cpi = vpx_memalign(32, sizeof(VP9_COMP)); | 1400 VP9_COMP *volatile const cpi = vpx_memalign(32, sizeof(VP9_COMP)); |
1399 VP9_COMMON *volatile const cm = cpi != NULL ? &cpi->common : NULL; | 1401 VP9_COMMON *volatile const cm = cpi != NULL ? &cpi->common : NULL; |
1400 | 1402 |
1401 if (!cm) | 1403 if (!cm) |
1402 return NULL; | 1404 return NULL; |
1403 | 1405 |
1404 vp9_zero(*cpi); | 1406 vp9_zero(*cpi); |
1405 | 1407 |
1406 if (setjmp(cm->error.jmp)) { | 1408 if (setjmp(cm->error.jmp)) { |
1407 cm->error.setjmp = 0; | 1409 cm->error.setjmp = 0; |
1408 vp9_remove_compressor(cpi); | 1410 vp9_remove_compressor(cpi); |
1409 return 0; | 1411 return 0; |
1410 } | 1412 } |
1411 | 1413 |
1412 cm->error.setjmp = 1; | 1414 cm->error.setjmp = 1; |
1413 cm->alloc_mi = vp9_enc_alloc_mi; | 1415 cm->alloc_mi = vp9_enc_alloc_mi; |
1414 cm->free_mi = vp9_enc_free_mi; | 1416 cm->free_mi = vp9_enc_free_mi; |
1415 cm->setup_mi = vp9_enc_setup_mi; | 1417 cm->setup_mi = vp9_enc_setup_mi; |
1416 | 1418 |
1417 CHECK_MEM_ERROR(cm, cm->fc, | 1419 CHECK_MEM_ERROR(cm, cm->fc, |
1418 (FRAME_CONTEXT *)vpx_calloc(1, sizeof(*cm->fc))); | 1420 (FRAME_CONTEXT *)vpx_calloc(1, sizeof(*cm->fc))); |
1419 CHECK_MEM_ERROR(cm, cm->frame_contexts, | 1421 CHECK_MEM_ERROR(cm, cm->frame_contexts, |
1420 (FRAME_CONTEXT *)vpx_calloc(FRAME_CONTEXTS, | 1422 (FRAME_CONTEXT *)vpx_calloc(FRAME_CONTEXTS, |
1421 sizeof(*cm->frame_contexts))); | 1423 sizeof(*cm->frame_contexts))); |
1422 | 1424 |
1423 cpi->use_svc = 0; | 1425 cpi->use_svc = 0; |
| 1426 cpi->common.buffer_pool = pool; |
1424 | 1427 |
1425 init_config(cpi, oxcf); | 1428 init_config(cpi, oxcf); |
1426 vp9_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc); | 1429 vp9_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc); |
1427 | 1430 |
1428 cm->current_video_frame = 0; | 1431 cm->current_video_frame = 0; |
1429 cpi->partition_search_skippable_frame = 0; | 1432 cpi->partition_search_skippable_frame = 0; |
1430 cpi->tile_data = NULL; | 1433 cpi->tile_data = NULL; |
1431 | 1434 |
1432 // Create the encoder segmentation map and set all entries to 0 | 1435 // Create the encoder segmentation map and set all entries to 0 |
1433 CHECK_MEM_ERROR(cm, cpi->segmentation_map, | 1436 CHECK_MEM_ERROR(cm, cpi->segmentation_map, |
(...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2334 rc->projected_frame_size < ((rc->this_frame_target * 7) >> 3)) { | 2337 rc->projected_frame_size < ((rc->this_frame_target * 7) >> 3)) { |
2335 force_recode = 1; | 2338 force_recode = 1; |
2336 } | 2339 } |
2337 } | 2340 } |
2338 } | 2341 } |
2339 return force_recode; | 2342 return force_recode; |
2340 } | 2343 } |
2341 | 2344 |
2342 void vp9_update_reference_frames(VP9_COMP *cpi) { | 2345 void vp9_update_reference_frames(VP9_COMP *cpi) { |
2343 VP9_COMMON * const cm = &cpi->common; | 2346 VP9_COMMON * const cm = &cpi->common; |
| 2347 BufferPool *const pool = cm->buffer_pool; |
2344 | 2348 |
2345 // At this point the new frame has been encoded. | 2349 // At this point the new frame has been encoded. |
2346 // If any buffer copy / swapping is signaled it should be done here. | 2350 // If any buffer copy / swapping is signaled it should be done here. |
2347 if (cm->frame_type == KEY_FRAME) { | 2351 if (cm->frame_type == KEY_FRAME) { |
2348 ref_cnt_fb(cm->frame_bufs, | 2352 ref_cnt_fb(pool->frame_bufs, |
2349 &cm->ref_frame_map[cpi->gld_fb_idx], cm->new_fb_idx); | 2353 &cm->ref_frame_map[cpi->gld_fb_idx], cm->new_fb_idx); |
2350 ref_cnt_fb(cm->frame_bufs, | 2354 ref_cnt_fb(pool->frame_bufs, |
2351 &cm->ref_frame_map[cpi->alt_fb_idx], cm->new_fb_idx); | 2355 &cm->ref_frame_map[cpi->alt_fb_idx], cm->new_fb_idx); |
2352 } else if (vp9_preserve_existing_gf(cpi)) { | 2356 } else if (vp9_preserve_existing_gf(cpi)) { |
2353 // We have decided to preserve the previously existing golden frame as our | 2357 // We have decided to preserve the previously existing golden frame as our |
2354 // new ARF frame. However, in the short term in function | 2358 // new ARF frame. However, in the short term in function |
2355 // vp9_bitstream.c::get_refresh_mask() we left it in the GF slot and, if | 2359 // vp9_bitstream.c::get_refresh_mask() we left it in the GF slot and, if |
2356 // we're updating the GF with the current decoded frame, we save it to the | 2360 // we're updating the GF with the current decoded frame, we save it to the |
2357 // ARF slot instead. | 2361 // ARF slot instead. |
2358 // We now have to update the ARF with the current frame and swap gld_fb_idx | 2362 // We now have to update the ARF with the current frame and swap gld_fb_idx |
2359 // and alt_fb_idx so that, overall, we've stored the old GF in the new ARF | 2363 // and alt_fb_idx so that, overall, we've stored the old GF in the new ARF |
2360 // slot and, if we're updating the GF, the current frame becomes the new GF. | 2364 // slot and, if we're updating the GF, the current frame becomes the new GF. |
2361 int tmp; | 2365 int tmp; |
2362 | 2366 |
2363 ref_cnt_fb(cm->frame_bufs, | 2367 ref_cnt_fb(pool->frame_bufs, |
2364 &cm->ref_frame_map[cpi->alt_fb_idx], cm->new_fb_idx); | 2368 &cm->ref_frame_map[cpi->alt_fb_idx], cm->new_fb_idx); |
2365 | 2369 |
2366 tmp = cpi->alt_fb_idx; | 2370 tmp = cpi->alt_fb_idx; |
2367 cpi->alt_fb_idx = cpi->gld_fb_idx; | 2371 cpi->alt_fb_idx = cpi->gld_fb_idx; |
2368 cpi->gld_fb_idx = tmp; | 2372 cpi->gld_fb_idx = tmp; |
2369 | 2373 |
2370 if (is_two_pass_svc(cpi)) { | 2374 if (is_two_pass_svc(cpi)) { |
2371 cpi->svc.layer_context[0].gold_ref_idx = cpi->gld_fb_idx; | 2375 cpi->svc.layer_context[0].gold_ref_idx = cpi->gld_fb_idx; |
2372 cpi->svc.layer_context[0].alt_ref_idx = cpi->alt_fb_idx; | 2376 cpi->svc.layer_context[0].alt_ref_idx = cpi->alt_fb_idx; |
2373 } | 2377 } |
2374 } else { /* For non key/golden frames */ | 2378 } else { /* For non key/golden frames */ |
2375 if (cpi->refresh_alt_ref_frame) { | 2379 if (cpi->refresh_alt_ref_frame) { |
2376 int arf_idx = cpi->alt_fb_idx; | 2380 int arf_idx = cpi->alt_fb_idx; |
2377 if ((cpi->oxcf.pass == 2) && cpi->multi_arf_allowed) { | 2381 if ((cpi->oxcf.pass == 2) && cpi->multi_arf_allowed) { |
2378 const GF_GROUP *const gf_group = &cpi->twopass.gf_group; | 2382 const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
2379 arf_idx = gf_group->arf_update_idx[gf_group->index]; | 2383 arf_idx = gf_group->arf_update_idx[gf_group->index]; |
2380 } | 2384 } |
2381 | 2385 |
2382 ref_cnt_fb(cm->frame_bufs, | 2386 ref_cnt_fb(pool->frame_bufs, |
2383 &cm->ref_frame_map[arf_idx], cm->new_fb_idx); | 2387 &cm->ref_frame_map[arf_idx], cm->new_fb_idx); |
2384 vpx_memcpy(cpi->interp_filter_selected[ALTREF_FRAME], | 2388 vpx_memcpy(cpi->interp_filter_selected[ALTREF_FRAME], |
2385 cpi->interp_filter_selected[0], | 2389 cpi->interp_filter_selected[0], |
2386 sizeof(cpi->interp_filter_selected[0])); | 2390 sizeof(cpi->interp_filter_selected[0])); |
2387 } | 2391 } |
2388 | 2392 |
2389 if (cpi->refresh_golden_frame) { | 2393 if (cpi->refresh_golden_frame) { |
2390 ref_cnt_fb(cm->frame_bufs, | 2394 ref_cnt_fb(pool->frame_bufs, |
2391 &cm->ref_frame_map[cpi->gld_fb_idx], cm->new_fb_idx); | 2395 &cm->ref_frame_map[cpi->gld_fb_idx], cm->new_fb_idx); |
2392 if (!cpi->rc.is_src_frame_alt_ref) | 2396 if (!cpi->rc.is_src_frame_alt_ref) |
2393 vpx_memcpy(cpi->interp_filter_selected[GOLDEN_FRAME], | 2397 vpx_memcpy(cpi->interp_filter_selected[GOLDEN_FRAME], |
2394 cpi->interp_filter_selected[0], | 2398 cpi->interp_filter_selected[0], |
2395 sizeof(cpi->interp_filter_selected[0])); | 2399 sizeof(cpi->interp_filter_selected[0])); |
2396 else | 2400 else |
2397 vpx_memcpy(cpi->interp_filter_selected[GOLDEN_FRAME], | 2401 vpx_memcpy(cpi->interp_filter_selected[GOLDEN_FRAME], |
2398 cpi->interp_filter_selected[ALTREF_FRAME], | 2402 cpi->interp_filter_selected[ALTREF_FRAME], |
2399 sizeof(cpi->interp_filter_selected[ALTREF_FRAME])); | 2403 sizeof(cpi->interp_filter_selected[ALTREF_FRAME])); |
2400 } | 2404 } |
2401 } | 2405 } |
2402 | 2406 |
2403 if (cpi->refresh_last_frame) { | 2407 if (cpi->refresh_last_frame) { |
2404 ref_cnt_fb(cm->frame_bufs, | 2408 ref_cnt_fb(pool->frame_bufs, |
2405 &cm->ref_frame_map[cpi->lst_fb_idx], cm->new_fb_idx); | 2409 &cm->ref_frame_map[cpi->lst_fb_idx], cm->new_fb_idx); |
2406 if (!cpi->rc.is_src_frame_alt_ref) | 2410 if (!cpi->rc.is_src_frame_alt_ref) |
2407 vpx_memcpy(cpi->interp_filter_selected[LAST_FRAME], | 2411 vpx_memcpy(cpi->interp_filter_selected[LAST_FRAME], |
2408 cpi->interp_filter_selected[0], | 2412 cpi->interp_filter_selected[0], |
2409 sizeof(cpi->interp_filter_selected[0])); | 2413 sizeof(cpi->interp_filter_selected[0])); |
2410 } | 2414 } |
2411 #if CONFIG_VP9_TEMPORAL_DENOISING | 2415 #if CONFIG_VP9_TEMPORAL_DENOISING |
2412 if (cpi->oxcf.noise_sensitivity > 0) { | 2416 if (cpi->oxcf.noise_sensitivity > 0) { |
2413 vp9_denoiser_update_frame_info(&cpi->denoiser, | 2417 vp9_denoiser_update_frame_info(&cpi->denoiser, |
2414 *cpi->Source, | 2418 *cpi->Source, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2453 | 2457 |
2454 void vp9_scale_references(VP9_COMP *cpi) { | 2458 void vp9_scale_references(VP9_COMP *cpi) { |
2455 VP9_COMMON *cm = &cpi->common; | 2459 VP9_COMMON *cm = &cpi->common; |
2456 MV_REFERENCE_FRAME ref_frame; | 2460 MV_REFERENCE_FRAME ref_frame; |
2457 const VP9_REFFRAME ref_mask[3] = {VP9_LAST_FLAG, VP9_GOLD_FLAG, VP9_ALT_FLAG}; | 2461 const VP9_REFFRAME ref_mask[3] = {VP9_LAST_FLAG, VP9_GOLD_FLAG, VP9_ALT_FLAG}; |
2458 | 2462 |
2459 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { | 2463 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
2460 // Need to convert from VP9_REFFRAME to index into ref_mask (subtract 1). | 2464 // Need to convert from VP9_REFFRAME to index into ref_mask (subtract 1). |
2461 if (cpi->ref_frame_flags & ref_mask[ref_frame - 1]) { | 2465 if (cpi->ref_frame_flags & ref_mask[ref_frame - 1]) { |
2462 const int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)]; | 2466 const int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)]; |
2463 const YV12_BUFFER_CONFIG *const ref = &cm->frame_bufs[idx].buf; | 2467 BufferPool *const pool = cm->buffer_pool; |
| 2468 const YV12_BUFFER_CONFIG *const ref = &pool->frame_bufs[idx].buf; |
2464 | 2469 |
2465 #if CONFIG_VP9_HIGHBITDEPTH | 2470 #if CONFIG_VP9_HIGHBITDEPTH |
2466 if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) { | 2471 if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) { |
2467 const int new_fb = get_free_fb(cm); | 2472 const int new_fb = get_free_fb(cm); |
2468 cm->cur_frame = &cm->frame_bufs[new_fb]; | 2473 cm->cur_frame = &pool->frame_bufs[new_fb]; |
2469 vp9_realloc_frame_buffer(&cm->frame_bufs[new_fb].buf, | 2474 vp9_realloc_frame_buffer(&pool->frame_bufs[new_fb].buf, |
2470 cm->width, cm->height, | 2475 cm->width, cm->height, |
2471 cm->subsampling_x, cm->subsampling_y, | 2476 cm->subsampling_x, cm->subsampling_y, |
2472 cm->use_highbitdepth, | 2477 cm->use_highbitdepth, |
2473 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment, | 2478 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment, |
2474 NULL, NULL, NULL); | 2479 NULL, NULL, NULL); |
2475 scale_and_extend_frame(ref, &cm->frame_bufs[new_fb].buf, | 2480 scale_and_extend_frame(ref, &pool->frame_bufs[new_fb].buf, |
2476 (int)cm->bit_depth); | 2481 (int)cm->bit_depth); |
2477 #else | 2482 #else |
2478 if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) { | 2483 if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) { |
2479 const int new_fb = get_free_fb(cm); | 2484 const int new_fb = get_free_fb(cm); |
2480 vp9_realloc_frame_buffer(&cm->frame_bufs[new_fb].buf, | 2485 vp9_realloc_frame_buffer(&pool->frame_bufs[new_fb].buf, |
2481 cm->width, cm->height, | 2486 cm->width, cm->height, |
2482 cm->subsampling_x, cm->subsampling_y, | 2487 cm->subsampling_x, cm->subsampling_y, |
2483 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment, | 2488 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment, |
2484 NULL, NULL, NULL); | 2489 NULL, NULL, NULL); |
2485 scale_and_extend_frame(ref, &cm->frame_bufs[new_fb].buf); | 2490 scale_and_extend_frame(ref, &pool->frame_bufs[new_fb].buf); |
2486 #endif // CONFIG_VP9_HIGHBITDEPTH | 2491 #endif // CONFIG_VP9_HIGHBITDEPTH |
2487 cpi->scaled_ref_idx[ref_frame - 1] = new_fb; | 2492 cpi->scaled_ref_idx[ref_frame - 1] = new_fb; |
2488 if (cm->frame_bufs[new_fb].mvs == NULL || | 2493 if (pool->frame_bufs[new_fb].mvs == NULL || |
2489 cm->frame_bufs[new_fb].mi_rows < cm->mi_rows || | 2494 pool->frame_bufs[new_fb].mi_rows < cm->mi_rows || |
2490 cm->frame_bufs[new_fb].mi_cols < cm->mi_cols) { | 2495 pool->frame_bufs[new_fb].mi_cols < cm->mi_cols) { |
2491 vpx_free(cm->frame_bufs[new_fb].mvs); | 2496 vpx_free(pool->frame_bufs[new_fb].mvs); |
2492 cm->frame_bufs[new_fb].mvs = | 2497 pool->frame_bufs[new_fb].mvs = |
2493 (MV_REF *)vpx_calloc(cm->mi_rows * cm->mi_cols, | 2498 (MV_REF *)vpx_calloc(cm->mi_rows * cm->mi_cols, |
2494 sizeof(*cm->frame_bufs[new_fb].mvs)); | 2499 sizeof(*pool->frame_bufs[new_fb].mvs)); |
2495 cm->frame_bufs[new_fb].mi_rows = cm->mi_rows; | 2500 pool->frame_bufs[new_fb].mi_rows = cm->mi_rows; |
2496 cm->frame_bufs[new_fb].mi_cols = cm->mi_cols; | 2501 pool->frame_bufs[new_fb].mi_cols = cm->mi_cols; |
2497 } | 2502 } |
2498 } else { | 2503 } else { |
2499 cpi->scaled_ref_idx[ref_frame - 1] = idx; | 2504 cpi->scaled_ref_idx[ref_frame - 1] = idx; |
2500 ++cm->frame_bufs[idx].ref_count; | 2505 ++pool->frame_bufs[idx].ref_count; |
2501 } | 2506 } |
2502 } else { | 2507 } else { |
2503 cpi->scaled_ref_idx[ref_frame - 1] = INVALID_REF_BUFFER_IDX; | 2508 cpi->scaled_ref_idx[ref_frame - 1] = INVALID_REF_BUFFER_IDX; |
2504 } | 2509 } |
2505 } | 2510 } |
2506 } | 2511 } |
2507 | 2512 |
2508 static void release_scaled_references(VP9_COMP *cpi) { | 2513 static void release_scaled_references(VP9_COMP *cpi) { |
2509 VP9_COMMON *cm = &cpi->common; | 2514 VP9_COMMON *cm = &cpi->common; |
2510 int i; | 2515 int i; |
2511 for (i = 0; i < MAX_REF_FRAMES; ++i) { | 2516 for (i = 0; i < MAX_REF_FRAMES; ++i) { |
2512 const int idx = cpi->scaled_ref_idx[i]; | 2517 const int idx = cpi->scaled_ref_idx[i]; |
2513 RefCntBuffer *const buf = | 2518 RefCntBuffer *const buf = idx != INVALID_REF_BUFFER_IDX ? |
2514 idx != INVALID_REF_BUFFER_IDX ? &cm->frame_bufs[idx] : NULL; | 2519 &cm->buffer_pool->frame_bufs[idx] : NULL; |
2515 if (buf != NULL) { | 2520 if (buf != NULL) { |
2516 --buf->ref_count; | 2521 --buf->ref_count; |
2517 cpi->scaled_ref_idx[i] = INVALID_REF_BUFFER_IDX; | 2522 cpi->scaled_ref_idx[i] = INVALID_REF_BUFFER_IDX; |
2518 } | 2523 } |
2519 } | 2524 } |
2520 } | 2525 } |
2521 | 2526 |
2522 static void full_to_model_count(unsigned int *model_count, | 2527 static void full_to_model_count(unsigned int *model_count, |
2523 unsigned int *full_count) { | 2528 unsigned int *full_count) { |
2524 int n; | 2529 int n; |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2721 cm->use_highbitdepth, | 2726 cm->use_highbitdepth, |
2722 #endif | 2727 #endif |
2723 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment, | 2728 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment, |
2724 NULL, NULL, NULL); | 2729 NULL, NULL, NULL); |
2725 | 2730 |
2726 alloc_util_frame_buffers(cpi); | 2731 alloc_util_frame_buffers(cpi); |
2727 init_motion_estimation(cpi); | 2732 init_motion_estimation(cpi); |
2728 | 2733 |
2729 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { | 2734 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
2730 const int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)]; | 2735 const int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)]; |
2731 YV12_BUFFER_CONFIG *const buf = &cm->frame_bufs[idx].buf; | 2736 YV12_BUFFER_CONFIG *const buf = &cm->buffer_pool->frame_bufs[idx].buf; |
2732 RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - 1]; | 2737 RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - 1]; |
2733 ref_buf->buf = buf; | 2738 ref_buf->buf = buf; |
2734 ref_buf->idx = idx; | 2739 ref_buf->idx = idx; |
2735 #if CONFIG_VP9_HIGHBITDEPTH | 2740 #if CONFIG_VP9_HIGHBITDEPTH |
2736 vp9_setup_scale_factors_for_frame(&ref_buf->sf, | 2741 vp9_setup_scale_factors_for_frame(&ref_buf->sf, |
2737 buf->y_crop_width, buf->y_crop_height, | 2742 buf->y_crop_width, buf->y_crop_height, |
2738 cm->width, cm->height, | 2743 cm->width, cm->height, |
2739 (buf->flags & YV12_FLAG_HIGHBITDEPTH) ? | 2744 (buf->flags & YV12_FLAG_HIGHBITDEPTH) ? |
2740 1 : 0); | 2745 1 : 0); |
2741 #else | 2746 #else |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2946 if (rc->projected_frame_size > rc->this_frame_target) { | 2951 if (rc->projected_frame_size > rc->this_frame_target) { |
2947 // Special case if the projected size is > the max allowed. | 2952 // Special case if the projected size is > the max allowed. |
2948 if (rc->projected_frame_size >= rc->max_frame_bandwidth) | 2953 if (rc->projected_frame_size >= rc->max_frame_bandwidth) |
2949 q_high = rc->worst_quality; | 2954 q_high = rc->worst_quality; |
2950 | 2955 |
2951 // Raise Qlow as to at least the current value | 2956 // Raise Qlow as to at least the current value |
2952 q_low = q < q_high ? q + 1 : q_high; | 2957 q_low = q < q_high ? q + 1 : q_high; |
2953 | 2958 |
2954 if (undershoot_seen || loop_count > 1) { | 2959 if (undershoot_seen || loop_count > 1) { |
2955 // Update rate_correction_factor unless | 2960 // Update rate_correction_factor unless |
2956 vp9_rc_update_rate_correction_factors(cpi, 1); | 2961 vp9_rc_update_rate_correction_factors(cpi); |
2957 | 2962 |
2958 q = (q_high + q_low + 1) / 2; | 2963 q = (q_high + q_low + 1) / 2; |
2959 } else { | 2964 } else { |
2960 // Update rate_correction_factor unless | 2965 // Update rate_correction_factor unless |
2961 vp9_rc_update_rate_correction_factors(cpi, 0); | 2966 vp9_rc_update_rate_correction_factors(cpi); |
2962 | 2967 |
2963 q = vp9_rc_regulate_q(cpi, rc->this_frame_target, | 2968 q = vp9_rc_regulate_q(cpi, rc->this_frame_target, |
2964 bottom_index, MAX(q_high, top_index)); | 2969 bottom_index, MAX(q_high, top_index)); |
2965 | 2970 |
2966 while (q < q_low && retries < 10) { | 2971 while (q < q_low && retries < 10) { |
2967 vp9_rc_update_rate_correction_factors(cpi, 0); | 2972 vp9_rc_update_rate_correction_factors(cpi); |
2968 q = vp9_rc_regulate_q(cpi, rc->this_frame_target, | 2973 q = vp9_rc_regulate_q(cpi, rc->this_frame_target, |
2969 bottom_index, MAX(q_high, top_index)); | 2974 bottom_index, MAX(q_high, top_index)); |
2970 retries++; | 2975 retries++; |
2971 } | 2976 } |
2972 } | 2977 } |
2973 | 2978 |
2974 overshoot_seen = 1; | 2979 overshoot_seen = 1; |
2975 } else { | 2980 } else { |
2976 // Frame is too small | 2981 // Frame is too small |
2977 q_high = q > q_low ? q - 1 : q_low; | 2982 q_high = q > q_low ? q - 1 : q_low; |
2978 | 2983 |
2979 if (overshoot_seen || loop_count > 1) { | 2984 if (overshoot_seen || loop_count > 1) { |
2980 vp9_rc_update_rate_correction_factors(cpi, 1); | 2985 vp9_rc_update_rate_correction_factors(cpi); |
2981 q = (q_high + q_low) / 2; | 2986 q = (q_high + q_low) / 2; |
2982 } else { | 2987 } else { |
2983 vp9_rc_update_rate_correction_factors(cpi, 0); | 2988 vp9_rc_update_rate_correction_factors(cpi); |
2984 q = vp9_rc_regulate_q(cpi, rc->this_frame_target, | 2989 q = vp9_rc_regulate_q(cpi, rc->this_frame_target, |
2985 bottom_index, top_index); | 2990 bottom_index, top_index); |
2986 // Special case reset for qlow for constrained quality. | 2991 // Special case reset for qlow for constrained quality. |
2987 // This should only trigger where there is very substantial | 2992 // This should only trigger where there is very substantial |
2988 // undershoot on a frame and the auto cq level is above | 2993 // undershoot on a frame and the auto cq level is above |
2989 // the user passsed in value. | 2994 // the user passsed in value. |
2990 if (cpi->oxcf.rc_mode == VPX_CQ && | 2995 if (cpi->oxcf.rc_mode == VPX_CQ && |
2991 q < q_low) { | 2996 q < q_low) { |
2992 q_low = q; | 2997 q_low = q; |
2993 } | 2998 } |
2994 | 2999 |
2995 while (q > q_high && retries < 10) { | 3000 while (q > q_high && retries < 10) { |
2996 vp9_rc_update_rate_correction_factors(cpi, 0); | 3001 vp9_rc_update_rate_correction_factors(cpi); |
2997 q = vp9_rc_regulate_q(cpi, rc->this_frame_target, | 3002 q = vp9_rc_regulate_q(cpi, rc->this_frame_target, |
2998 bottom_index, top_index); | 3003 bottom_index, top_index); |
2999 retries++; | 3004 retries++; |
3000 } | 3005 } |
3001 } | 3006 } |
3002 | 3007 |
3003 undershoot_seen = 1; | 3008 undershoot_seen = 1; |
3004 } | 3009 } |
3005 | 3010 |
3006 // Clamp Q to upper and lower limits: | 3011 // Clamp Q to upper and lower limits: |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3430 check_initial_width(cpi, use_highbitdepth, subsampling_x, subsampling_y); | 3435 check_initial_width(cpi, use_highbitdepth, subsampling_x, subsampling_y); |
3431 #else | 3436 #else |
3432 check_initial_width(cpi, subsampling_x, subsampling_y); | 3437 check_initial_width(cpi, subsampling_x, subsampling_y); |
3433 #endif // CONFIG_VP9_HIGHBITDEPTH | 3438 #endif // CONFIG_VP9_HIGHBITDEPTH |
3434 | 3439 |
3435 #if CONFIG_VP9_TEMPORAL_DENOISING | 3440 #if CONFIG_VP9_TEMPORAL_DENOISING |
3436 setup_denoiser_buffer(cpi); | 3441 setup_denoiser_buffer(cpi); |
3437 #endif | 3442 #endif |
3438 vpx_usec_timer_start(&timer); | 3443 vpx_usec_timer_start(&timer); |
3439 | 3444 |
3440 if (vp9_lookahead_push(cpi->lookahead, sd, time_stamp, end_time, frame_flags)) | 3445 if (vp9_lookahead_push(cpi->lookahead, sd, time_stamp, end_time, |
| 3446 #if CONFIG_VP9_HIGHBITDEPTH |
| 3447 use_highbitdepth, |
| 3448 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 3449 frame_flags)) |
3441 res = -1; | 3450 res = -1; |
3442 vpx_usec_timer_mark(&timer); | 3451 vpx_usec_timer_mark(&timer); |
3443 cpi->time_receive_data += vpx_usec_timer_elapsed(&timer); | 3452 cpi->time_receive_data += vpx_usec_timer_elapsed(&timer); |
3444 | 3453 |
3445 if ((cm->profile == PROFILE_0 || cm->profile == PROFILE_2) && | 3454 if ((cm->profile == PROFILE_0 || cm->profile == PROFILE_2) && |
3446 (subsampling_x != 1 || subsampling_y != 1)) { | 3455 (subsampling_x != 1 || subsampling_y != 1)) { |
3447 vpx_internal_error(&cm->error, VPX_CODEC_INVALID_PARAM, | 3456 vpx_internal_error(&cm->error, VPX_CODEC_INVALID_PARAM, |
3448 "Non-4:2:0 color format requires profile 1 or 3"); | 3457 "Non-4:2:0 color format requires profile 1 or 3"); |
3449 res = -1; | 3458 res = -1; |
3450 } | 3459 } |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3550 // become the GF so preserve last as an alternative prediction option. | 3559 // become the GF so preserve last as an alternative prediction option. |
3551 cpi->refresh_last_frame = 0; | 3560 cpi->refresh_last_frame = 0; |
3552 } | 3561 } |
3553 } | 3562 } |
3554 | 3563 |
3555 int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, | 3564 int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, |
3556 size_t *size, uint8_t *dest, | 3565 size_t *size, uint8_t *dest, |
3557 int64_t *time_stamp, int64_t *time_end, int flush) { | 3566 int64_t *time_stamp, int64_t *time_end, int flush) { |
3558 const VP9EncoderConfig *const oxcf = &cpi->oxcf; | 3567 const VP9EncoderConfig *const oxcf = &cpi->oxcf; |
3559 VP9_COMMON *const cm = &cpi->common; | 3568 VP9_COMMON *const cm = &cpi->common; |
| 3569 BufferPool *const pool = cm->buffer_pool; |
3560 RATE_CONTROL *const rc = &cpi->rc; | 3570 RATE_CONTROL *const rc = &cpi->rc; |
3561 struct vpx_usec_timer cmptimer; | 3571 struct vpx_usec_timer cmptimer; |
3562 YV12_BUFFER_CONFIG *force_src_buffer = NULL; | 3572 YV12_BUFFER_CONFIG *force_src_buffer = NULL; |
3563 struct lookahead_entry *last_source = NULL; | 3573 struct lookahead_entry *last_source = NULL; |
3564 struct lookahead_entry *source = NULL; | 3574 struct lookahead_entry *source = NULL; |
3565 int arf_src_index; | 3575 int arf_src_index; |
3566 int i; | 3576 int i; |
3567 | 3577 |
3568 if (is_two_pass_svc(cpi)) { | 3578 if (is_two_pass_svc(cpi)) { |
3569 #if CONFIG_SPATIAL_SVC | 3579 #if CONFIG_SPATIAL_SVC |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3704 } | 3714 } |
3705 | 3715 |
3706 if (cpi->svc.number_temporal_layers > 1 && | 3716 if (cpi->svc.number_temporal_layers > 1 && |
3707 oxcf->rc_mode == VPX_CBR) { | 3717 oxcf->rc_mode == VPX_CBR) { |
3708 vp9_update_temporal_layer_framerate(cpi); | 3718 vp9_update_temporal_layer_framerate(cpi); |
3709 vp9_restore_layer_context(cpi); | 3719 vp9_restore_layer_context(cpi); |
3710 } | 3720 } |
3711 | 3721 |
3712 // Find a free buffer for the new frame, releasing the reference previously | 3722 // Find a free buffer for the new frame, releasing the reference previously |
3713 // held. | 3723 // held. |
3714 cm->frame_bufs[cm->new_fb_idx].ref_count--; | 3724 pool->frame_bufs[cm->new_fb_idx].ref_count--; |
3715 cm->new_fb_idx = get_free_fb(cm); | 3725 cm->new_fb_idx = get_free_fb(cm); |
3716 cm->cur_frame = &cm->frame_bufs[cm->new_fb_idx]; | 3726 cm->cur_frame = &pool->frame_bufs[cm->new_fb_idx]; |
3717 | 3727 |
3718 if (!cpi->use_svc && cpi->multi_arf_allowed) { | 3728 if (!cpi->use_svc && cpi->multi_arf_allowed) { |
3719 if (cm->frame_type == KEY_FRAME) { | 3729 if (cm->frame_type == KEY_FRAME) { |
3720 init_buffer_indices(cpi); | 3730 init_buffer_indices(cpi); |
3721 } else if (oxcf->pass == 2) { | 3731 } else if (oxcf->pass == 2) { |
3722 const GF_GROUP *const gf_group = &cpi->twopass.gf_group; | 3732 const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
3723 cpi->alt_fb_idx = gf_group->arf_ref_idx[gf_group->index]; | 3733 cpi->alt_fb_idx = gf_group->arf_ref_idx[gf_group->index]; |
3724 } | 3734 } |
3725 } | 3735 } |
3726 | 3736 |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4098 if (flags & VP8_EFLAG_NO_UPD_ARF) | 4108 if (flags & VP8_EFLAG_NO_UPD_ARF) |
4099 upd ^= VP9_ALT_FLAG; | 4109 upd ^= VP9_ALT_FLAG; |
4100 | 4110 |
4101 vp9_update_reference(cpi, upd); | 4111 vp9_update_reference(cpi, upd); |
4102 } | 4112 } |
4103 | 4113 |
4104 if (flags & VP8_EFLAG_NO_UPD_ENTROPY) { | 4114 if (flags & VP8_EFLAG_NO_UPD_ENTROPY) { |
4105 vp9_update_entropy(cpi, 0); | 4115 vp9_update_entropy(cpi, 0); |
4106 } | 4116 } |
4107 } | 4117 } |
OLD | NEW |