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