Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: source/libvpx/vp9/encoder/vp9_encoder.c

Issue 812033011: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_encoder.h ('k') | source/libvpx/vp9/encoder/vp9_ethread.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 17 matching lines...) Expand all
28 #include "vp9/common/vp9_systemdependent.h" 28 #include "vp9/common/vp9_systemdependent.h"
29 #include "vp9/common/vp9_tile_common.h" 29 #include "vp9/common/vp9_tile_common.h"
30 30
31 #include "vp9/encoder/vp9_aq_complexity.h" 31 #include "vp9/encoder/vp9_aq_complexity.h"
32 #include "vp9/encoder/vp9_aq_cyclicrefresh.h" 32 #include "vp9/encoder/vp9_aq_cyclicrefresh.h"
33 #include "vp9/encoder/vp9_aq_variance.h" 33 #include "vp9/encoder/vp9_aq_variance.h"
34 #include "vp9/encoder/vp9_bitstream.h" 34 #include "vp9/encoder/vp9_bitstream.h"
35 #include "vp9/encoder/vp9_context_tree.h" 35 #include "vp9/encoder/vp9_context_tree.h"
36 #include "vp9/encoder/vp9_encodeframe.h" 36 #include "vp9/encoder/vp9_encodeframe.h"
37 #include "vp9/encoder/vp9_encodemv.h" 37 #include "vp9/encoder/vp9_encodemv.h"
38 #include "vp9/encoder/vp9_ethread.h"
38 #include "vp9/encoder/vp9_firstpass.h" 39 #include "vp9/encoder/vp9_firstpass.h"
39 #include "vp9/encoder/vp9_mbgraph.h" 40 #include "vp9/encoder/vp9_mbgraph.h"
40 #include "vp9/encoder/vp9_encoder.h" 41 #include "vp9/encoder/vp9_encoder.h"
41 #include "vp9/encoder/vp9_picklpf.h" 42 #include "vp9/encoder/vp9_picklpf.h"
42 #include "vp9/encoder/vp9_ratectrl.h" 43 #include "vp9/encoder/vp9_ratectrl.h"
43 #include "vp9/encoder/vp9_rd.h" 44 #include "vp9/encoder/vp9_rd.h"
44 #include "vp9/encoder/vp9_segmentation.h" 45 #include "vp9/encoder/vp9_segmentation.h"
45 #include "vp9/encoder/vp9_speed_features.h" 46 #include "vp9/encoder/vp9_speed_features.h"
46 #if CONFIG_INTERNAL_STATS 47 #if CONFIG_INTERNAL_STATS
47 #include "vp9/encoder/vp9_ssim.h" 48 #include "vp9/encoder/vp9_ssim.h"
48 #endif 49 #endif
49 #include "vp9/encoder/vp9_temporal_filter.h" 50 #include "vp9/encoder/vp9_temporal_filter.h"
50 #include "vp9/encoder/vp9_resize.h" 51 #include "vp9/encoder/vp9_resize.h"
51 #include "vp9/encoder/vp9_svc_layercontext.h" 52 #include "vp9/encoder/vp9_svc_layercontext.h"
52 53
53 void vp9_coef_tree_initialize();
54 54
55 #define SHARP_FILTER_QTHRESH 0 /* Q threshold for 8-tap sharp filter */ 55 #define SHARP_FILTER_QTHRESH 0 /* Q threshold for 8-tap sharp filter */
56 56
57 #define ALTREF_HIGH_PRECISION_MV 1 // Whether to use high precision mv 57 #define ALTREF_HIGH_PRECISION_MV 1 // Whether to use high precision mv
58 // for altref computation. 58 // for altref computation.
59 #define HIGH_PRECISION_MV_QTHRESH 200 // Q threshold for high precision 59 #define HIGH_PRECISION_MV_QTHRESH 200 // Q threshold for high precision
60 // mv. Choose a very high value for 60 // mv. Choose a very high value for
61 // now so that HIGH_PRECISION is always 61 // now so that HIGH_PRECISION is always
62 // chosen. 62 // chosen.
63 63
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 // Current mip will be the prev_mip for the next frame. 173 // Current mip will be the prev_mip for the next frame.
174 MODE_INFO *temp = cm->prev_mip; 174 MODE_INFO *temp = cm->prev_mip;
175 cm->prev_mip = cm->mip; 175 cm->prev_mip = cm->mip;
176 cm->mip = temp; 176 cm->mip = temp;
177 177
178 // Update the upper left visible macroblock ptrs. 178 // Update the upper left visible macroblock ptrs.
179 cm->mi = cm->mip + cm->mi_stride + 1; 179 cm->mi = cm->mip + cm->mi_stride + 1;
180 cm->prev_mi = cm->prev_mip + cm->mi_stride + 1; 180 cm->prev_mi = cm->prev_mip + cm->mi_stride + 1;
181 } 181 }
182 182
183 void vp9_initialize_enc() { 183 void vp9_initialize_enc(void) {
184 static int init_done = 0; 184 static volatile int init_done = 0;
185 185
186 if (!init_done) { 186 if (!init_done) {
187 vp9_rtcd(); 187 vp9_rtcd();
188 vp9_init_intra_predictors(); 188 vp9_init_intra_predictors();
189 vp9_coef_tree_initialize();
190 vp9_tokenize_initialize();
191 vp9_init_me_luts(); 189 vp9_init_me_luts();
192 vp9_rc_init_minq_luts(); 190 vp9_rc_init_minq_luts();
193 vp9_entropy_mv_init(); 191 vp9_entropy_mv_init();
194 vp9_entropy_mode_init();
195 vp9_temporal_filter_init(); 192 vp9_temporal_filter_init();
196 init_done = 1; 193 init_done = 1;
197 } 194 }
198 } 195 }
199 196
200 static void dealloc_compressor_data(VP9_COMP *cpi) { 197 static void dealloc_compressor_data(VP9_COMP *cpi) {
201 VP9_COMMON *const cm = &cpi->common; 198 VP9_COMMON *const cm = &cpi->common;
202 int i; 199 int i;
203 200
204 vpx_free(cpi->tile_data); 201 vpx_free(cpi->tile_data);
205 cpi->tile_data = NULL; 202 cpi->tile_data = NULL;
206 203
207 // Delete sementation map 204 // Delete sementation map
208 vpx_free(cpi->segmentation_map); 205 vpx_free(cpi->segmentation_map);
209 cpi->segmentation_map = NULL; 206 cpi->segmentation_map = NULL;
210 vpx_free(cm->last_frame_seg_map); 207 vpx_free(cm->last_frame_seg_map);
211 cm->last_frame_seg_map = NULL; 208 cm->last_frame_seg_map = NULL;
212 vpx_free(cpi->coding_context.last_frame_seg_map_copy); 209 vpx_free(cpi->coding_context.last_frame_seg_map_copy);
213 cpi->coding_context.last_frame_seg_map_copy = NULL; 210 cpi->coding_context.last_frame_seg_map_copy = NULL;
214 211
215 vpx_free(cpi->complexity_map);
216 cpi->complexity_map = NULL;
217
218 vpx_free(cpi->nmvcosts[0]); 212 vpx_free(cpi->nmvcosts[0]);
219 vpx_free(cpi->nmvcosts[1]); 213 vpx_free(cpi->nmvcosts[1]);
220 cpi->nmvcosts[0] = NULL; 214 cpi->nmvcosts[0] = NULL;
221 cpi->nmvcosts[1] = NULL; 215 cpi->nmvcosts[1] = NULL;
222 216
223 vpx_free(cpi->nmvcosts_hp[0]); 217 vpx_free(cpi->nmvcosts_hp[0]);
224 vpx_free(cpi->nmvcosts_hp[1]); 218 vpx_free(cpi->nmvcosts_hp[1]);
225 cpi->nmvcosts_hp[0] = NULL; 219 cpi->nmvcosts_hp[0] = NULL;
226 cpi->nmvcosts_hp[1] = NULL; 220 cpi->nmvcosts_hp[1] = NULL;
227 221
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 if (!cpi->lookahead) 480 if (!cpi->lookahead)
487 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, 481 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
488 "Failed to allocate lag buffers"); 482 "Failed to allocate lag buffers");
489 483
490 if (vp9_realloc_frame_buffer(&cpi->alt_ref_buffer, 484 if (vp9_realloc_frame_buffer(&cpi->alt_ref_buffer,
491 oxcf->width, oxcf->height, 485 oxcf->width, oxcf->height,
492 cm->subsampling_x, cm->subsampling_y, 486 cm->subsampling_x, cm->subsampling_y,
493 #if CONFIG_VP9_HIGHBITDEPTH 487 #if CONFIG_VP9_HIGHBITDEPTH
494 cm->use_highbitdepth, 488 cm->use_highbitdepth,
495 #endif 489 #endif
496 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL)) 490 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
491 NULL, NULL, NULL))
497 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, 492 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
498 "Failed to allocate altref buffer"); 493 "Failed to allocate altref buffer");
499 } 494 }
500 495
501 static void alloc_ref_frame_buffers(VP9_COMP *cpi) { 496 static void alloc_ref_frame_buffers(VP9_COMP *cpi) {
502 VP9_COMMON *const cm = &cpi->common; 497 VP9_COMMON *const cm = &cpi->common;
503 if (vp9_alloc_ref_frame_buffers(cm, cm->width, cm->height)) 498 if (vp9_alloc_ref_frame_buffers(cm, cm->width, cm->height))
504 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, 499 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
505 "Failed to allocate frame buffers"); 500 "Failed to allocate frame buffers");
506 } 501 }
507 502
508 static void alloc_util_frame_buffers(VP9_COMP *cpi) { 503 static void alloc_util_frame_buffers(VP9_COMP *cpi) {
509 VP9_COMMON *const cm = &cpi->common; 504 VP9_COMMON *const cm = &cpi->common;
510 if (vp9_realloc_frame_buffer(&cpi->last_frame_uf, 505 if (vp9_realloc_frame_buffer(&cpi->last_frame_uf,
511 cm->width, cm->height, 506 cm->width, cm->height,
512 cm->subsampling_x, cm->subsampling_y, 507 cm->subsampling_x, cm->subsampling_y,
513 #if CONFIG_VP9_HIGHBITDEPTH 508 #if CONFIG_VP9_HIGHBITDEPTH
514 cm->use_highbitdepth, 509 cm->use_highbitdepth,
515 #endif 510 #endif
516 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL)) 511 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
512 NULL, NULL, NULL))
517 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, 513 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
518 "Failed to allocate last frame buffer"); 514 "Failed to allocate last frame buffer");
519 515
520 if (vp9_realloc_frame_buffer(&cpi->scaled_source, 516 if (vp9_realloc_frame_buffer(&cpi->scaled_source,
521 cm->width, cm->height, 517 cm->width, cm->height,
522 cm->subsampling_x, cm->subsampling_y, 518 cm->subsampling_x, cm->subsampling_y,
523 #if CONFIG_VP9_HIGHBITDEPTH 519 #if CONFIG_VP9_HIGHBITDEPTH
524 cm->use_highbitdepth, 520 cm->use_highbitdepth,
525 #endif 521 #endif
526 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL)) 522 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
523 NULL, NULL, NULL))
527 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, 524 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
528 "Failed to allocate scaled source buffer"); 525 "Failed to allocate scaled source buffer");
529 526
530 if (vp9_realloc_frame_buffer(&cpi->scaled_last_source, 527 if (vp9_realloc_frame_buffer(&cpi->scaled_last_source,
531 cm->width, cm->height, 528 cm->width, cm->height,
532 cm->subsampling_x, cm->subsampling_y, 529 cm->subsampling_x, cm->subsampling_y,
533 #if CONFIG_VP9_HIGHBITDEPTH 530 #if CONFIG_VP9_HIGHBITDEPTH
534 cm->use_highbitdepth, 531 cm->use_highbitdepth,
535 #endif 532 #endif
536 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL)) 533 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
534 NULL, NULL, NULL))
537 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, 535 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
538 "Failed to allocate scaled last source buffer"); 536 "Failed to allocate scaled last source buffer");
539 } 537 }
540 538
541 void vp9_alloc_compressor_data(VP9_COMP *cpi) { 539 void vp9_alloc_compressor_data(VP9_COMP *cpi) {
542 VP9_COMMON *cm = &cpi->common; 540 VP9_COMMON *cm = &cpi->common;
543 541
544 vp9_alloc_context_buffers(cm, cm->width, cm->height); 542 vp9_alloc_context_buffers(cm, cm->width, cm->height);
545 543
546 vpx_free(cpi->tile_tok[0][0]); 544 vpx_free(cpi->tile_tok[0][0]);
(...skipping 15 matching lines...) Expand all
562 vp9_init_context_buffers(cm); 560 vp9_init_context_buffers(cm);
563 init_macroblockd(cm, xd); 561 init_macroblockd(cm, xd);
564 562
565 if (is_two_pass_svc(cpi)) { 563 if (is_two_pass_svc(cpi)) {
566 if (vp9_realloc_frame_buffer(&cpi->alt_ref_buffer, 564 if (vp9_realloc_frame_buffer(&cpi->alt_ref_buffer,
567 cm->width, cm->height, 565 cm->width, cm->height,
568 cm->subsampling_x, cm->subsampling_y, 566 cm->subsampling_x, cm->subsampling_y,
569 #if CONFIG_VP9_HIGHBITDEPTH 567 #if CONFIG_VP9_HIGHBITDEPTH
570 cm->use_highbitdepth, 568 cm->use_highbitdepth,
571 #endif 569 #endif
572 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL)) 570 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
571 NULL, NULL, NULL))
573 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, 572 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
574 "Failed to reallocate alt_ref_buffer"); 573 "Failed to reallocate alt_ref_buffer");
575 } 574 }
576 } 575 }
577 576
578 void vp9_new_framerate(VP9_COMP *cpi, double framerate) { 577 void vp9_new_framerate(VP9_COMP *cpi, double framerate) {
579 cpi->framerate = framerate < 0.1 ? 30 : framerate; 578 cpi->framerate = framerate < 0.1 ? 30 : framerate;
580 vp9_rc_update_framerate(cpi); 579 vp9_rc_update_framerate(cpi);
581 } 580 }
582 581
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after
1341 #endif 1340 #endif
1342 1341
1343 set_tile_limits(cpi); 1342 set_tile_limits(cpi);
1344 1343
1345 cpi->ext_refresh_frame_flags_pending = 0; 1344 cpi->ext_refresh_frame_flags_pending = 0;
1346 cpi->ext_refresh_frame_context_pending = 0; 1345 cpi->ext_refresh_frame_context_pending = 0;
1347 1346
1348 #if CONFIG_VP9_HIGHBITDEPTH 1347 #if CONFIG_VP9_HIGHBITDEPTH
1349 highbd_set_var_fns(cpi); 1348 highbd_set_var_fns(cpi);
1350 #endif 1349 #endif
1351
1352 #if CONFIG_VP9_TEMPORAL_DENOISING
1353 if (cpi->oxcf.noise_sensitivity > 0) {
1354 vp9_denoiser_alloc(&(cpi->denoiser), cm->width, cm->height,
1355 cm->subsampling_x, cm->subsampling_y,
1356 #if CONFIG_VP9_HIGHBITDEPTH
1357 cm->use_highbitdepth,
1358 #endif
1359 VP9_ENC_BORDER_IN_PIXELS);
1360 }
1361 #endif
1362 } 1350 }
1363 1351
1364 #ifndef M_LOG2_E 1352 #ifndef M_LOG2_E
1365 #define M_LOG2_E 0.693147180559945309417 1353 #define M_LOG2_E 0.693147180559945309417
1366 #endif 1354 #endif
1367 #define log2f(x) (log (x) / (float) M_LOG2_E) 1355 #define log2f(x) (log (x) / (float) M_LOG2_E)
1368 1356
1369 static void cal_nmvjointsadcost(int *mvjointsadcost) { 1357 static void cal_nmvjointsadcost(int *mvjointsadcost) {
1370 mvjointsadcost[0] = 600; 1358 mvjointsadcost[0] = 600;
1371 mvjointsadcost[1] = 300; 1359 mvjointsadcost[1] = 300;
(...skipping 27 matching lines...) Expand all
1399 mvsadcost[0][i] = (int)z; 1387 mvsadcost[0][i] = (int)z;
1400 mvsadcost[1][i] = (int)z; 1388 mvsadcost[1][i] = (int)z;
1401 mvsadcost[0][-i] = (int)z; 1389 mvsadcost[0][-i] = (int)z;
1402 mvsadcost[1][-i] = (int)z; 1390 mvsadcost[1][-i] = (int)z;
1403 } while (++i <= MV_MAX); 1391 } while (++i <= MV_MAX);
1404 } 1392 }
1405 1393
1406 1394
1407 VP9_COMP *vp9_create_compressor(VP9EncoderConfig *oxcf) { 1395 VP9_COMP *vp9_create_compressor(VP9EncoderConfig *oxcf) {
1408 unsigned int i; 1396 unsigned int i;
1409 VP9_COMP *const cpi = vpx_memalign(32, sizeof(VP9_COMP)); 1397 VP9_COMP *volatile const cpi = vpx_memalign(32, sizeof(VP9_COMP));
1410 VP9_COMMON *const cm = cpi != NULL ? &cpi->common : NULL; 1398 VP9_COMMON *volatile const cm = cpi != NULL ? &cpi->common : NULL;
1411 1399
1412 if (!cm) 1400 if (!cm)
1413 return NULL; 1401 return NULL;
1414 1402
1415 vp9_zero(*cpi); 1403 vp9_zero(*cpi);
1416 1404
1417 if (setjmp(cm->error.jmp)) { 1405 if (setjmp(cm->error.jmp)) {
1418 cm->error.setjmp = 0; 1406 cm->error.setjmp = 0;
1419 vp9_remove_compressor(cpi); 1407 vp9_remove_compressor(cpi);
1420 return 0; 1408 return 0;
(...skipping 16 matching lines...) Expand all
1437 vp9_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc); 1425 vp9_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc);
1438 1426
1439 cm->current_video_frame = 0; 1427 cm->current_video_frame = 0;
1440 cpi->partition_search_skippable_frame = 0; 1428 cpi->partition_search_skippable_frame = 0;
1441 cpi->tile_data = NULL; 1429 cpi->tile_data = NULL;
1442 1430
1443 // Create the encoder segmentation map and set all entries to 0 1431 // Create the encoder segmentation map and set all entries to 0
1444 CHECK_MEM_ERROR(cm, cpi->segmentation_map, 1432 CHECK_MEM_ERROR(cm, cpi->segmentation_map,
1445 vpx_calloc(cm->mi_rows * cm->mi_cols, 1)); 1433 vpx_calloc(cm->mi_rows * cm->mi_cols, 1));
1446 1434
1447 // Create a complexity map used for rd adjustment
1448 CHECK_MEM_ERROR(cm, cpi->complexity_map,
1449 vpx_calloc(cm->mi_rows * cm->mi_cols, 1));
1450
1451 // Create a map used for cyclic background refresh. 1435 // Create a map used for cyclic background refresh.
1452 CHECK_MEM_ERROR(cm, cpi->cyclic_refresh, 1436 CHECK_MEM_ERROR(cm, cpi->cyclic_refresh,
1453 vp9_cyclic_refresh_alloc(cm->mi_rows, cm->mi_cols)); 1437 vp9_cyclic_refresh_alloc(cm->mi_rows, cm->mi_cols));
1454 1438
1455 // And a place holder structure is the coding context 1439 // And a place holder structure is the coding context
1456 // for use if we want to save and restore it 1440 // for use if we want to save and restore it
1457 CHECK_MEM_ERROR(cm, cpi->coding_context.last_frame_seg_map_copy, 1441 CHECK_MEM_ERROR(cm, cpi->coding_context.last_frame_seg_map_copy,
1458 vpx_calloc(cm->mi_rows * cm->mi_cols, 1)); 1442 vpx_calloc(cm->mi_rows * cm->mi_cols, 1));
1459 1443
1460 CHECK_MEM_ERROR(cm, cpi->nmvcosts[0], 1444 CHECK_MEM_ERROR(cm, cpi->nmvcosts[0],
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
1721 vp9_loop_filter_init(cm); 1705 vp9_loop_filter_init(cm);
1722 1706
1723 cm->error.setjmp = 0; 1707 cm->error.setjmp = 0;
1724 1708
1725 return cpi; 1709 return cpi;
1726 } 1710 }
1727 1711
1728 void vp9_remove_compressor(VP9_COMP *cpi) { 1712 void vp9_remove_compressor(VP9_COMP *cpi) {
1729 VP9_COMMON *const cm = &cpi->common; 1713 VP9_COMMON *const cm = &cpi->common;
1730 unsigned int i; 1714 unsigned int i;
1715 int t;
1731 1716
1732 if (!cpi) 1717 if (!cpi)
1733 return; 1718 return;
1734 1719
1735 if (cpi && (cm->current_video_frame > 0)) { 1720 if (cpi && (cm->current_video_frame > 0)) {
1736 #if CONFIG_INTERNAL_STATS 1721 #if CONFIG_INTERNAL_STATS
1737 1722
1738 vp9_clear_system_state(); 1723 vp9_clear_system_state();
1739 1724
1740 // printf("\n8x8-4x4:%d-%d\n", cpi->t8x8_count, cpi->t4x4_count); 1725 // printf("\n8x8-4x4:%d-%d\n", cpi->t8x8_count, cpi->t4x4_count);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1788 printf("\n_frames recive_data encod_mb_row compress_frame Total\n"); 1773 printf("\n_frames recive_data encod_mb_row compress_frame Total\n");
1789 printf("%6d %10ld %10ld %10ld %10ld\n", cpi->common.current_video_frame, 1774 printf("%6d %10ld %10ld %10ld %10ld\n", cpi->common.current_video_frame,
1790 cpi->time_receive_data / 1000, cpi->time_encode_sb_row / 1000, 1775 cpi->time_receive_data / 1000, cpi->time_encode_sb_row / 1000,
1791 cpi->time_compress_data / 1000, 1776 cpi->time_compress_data / 1000,
1792 (cpi->time_receive_data + cpi->time_compress_data) / 1000); 1777 (cpi->time_receive_data + cpi->time_compress_data) / 1000);
1793 } 1778 }
1794 #endif 1779 #endif
1795 } 1780 }
1796 1781
1797 #if CONFIG_VP9_TEMPORAL_DENOISING 1782 #if CONFIG_VP9_TEMPORAL_DENOISING
1798 if (cpi->oxcf.noise_sensitivity > 0) { 1783 vp9_denoiser_free(&(cpi->denoiser));
1799 vp9_denoiser_free(&(cpi->denoiser)); 1784 #endif
1785
1786 for (t = 0; t < cpi->num_workers; ++t) {
1787 VP9Worker *const worker = &cpi->workers[t];
1788 EncWorkerData *const thread_data = (EncWorkerData*)worker->data1;
1789
1790 // Deallocate allocated threads.
1791 vp9_get_worker_interface()->end(worker);
1792
1793 // Deallocate allocated thread data.
1794 if (t < cpi->num_workers - 1) {
1795 vpx_free(thread_data->td->counts);
1796 vp9_free_pc_tree(thread_data->td);
1797 vpx_free(thread_data->td);
1798 }
1799
1800 vpx_free(worker->data1);
1800 } 1801 }
1801 #endif 1802 vpx_free(cpi->workers);
1802 1803
1803 dealloc_compressor_data(cpi); 1804 dealloc_compressor_data(cpi);
1804 1805
1805 for (i = 0; i < sizeof(cpi->mbgraph_stats) / 1806 for (i = 0; i < sizeof(cpi->mbgraph_stats) /
1806 sizeof(cpi->mbgraph_stats[0]); ++i) { 1807 sizeof(cpi->mbgraph_stats[0]); ++i) {
1807 vpx_free(cpi->mbgraph_stats[i].mb_stats); 1808 vpx_free(cpi->mbgraph_stats[i].mb_stats);
1808 } 1809 }
1809 1810
1810 #if CONFIG_FP_MB_STATS 1811 #if CONFIG_FP_MB_STATS
1811 if (cpi->use_fp_mb_stats) { 1812 if (cpi->use_fp_mb_stats) {
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
2118 void vp9_write_yuv_frame_420(YV12_BUFFER_CONFIG *s, FILE *f) { 2119 void vp9_write_yuv_frame_420(YV12_BUFFER_CONFIG *s, FILE *f) {
2119 uint8_t *src = s->y_buffer; 2120 uint8_t *src = s->y_buffer;
2120 int h = s->y_height; 2121 int h = s->y_height;
2121 2122
2122 do { 2123 do {
2123 fwrite(src, s->y_width, 1, f); 2124 fwrite(src, s->y_width, 1, f);
2124 src += s->y_stride; 2125 src += s->y_stride;
2125 } while (--h); 2126 } while (--h);
2126 2127
2127 src = s->u_buffer; 2128 src = s->u_buffer;
2128 h = s->uv_height / 2; 2129 h = s->uv_height;
2129 2130
2130 do { 2131 do {
2131 fwrite(src, s->uv_width / 2, 1, f); 2132 fwrite(src, s->uv_width, 1, f);
2132 src += s->uv_stride + s->uv_width / 2; 2133 src += s->uv_stride;
2133 } while (--h); 2134 } while (--h);
2134 2135
2135 src = s->v_buffer; 2136 src = s->v_buffer;
2136 h = s->uv_height / 2; 2137 h = s->uv_height;
2137 2138
2138 do { 2139 do {
2139 fwrite(src, s->uv_width / 2, 1, f); 2140 fwrite(src, s->uv_width, 1, f);
2140 src += s->uv_stride + s->uv_width / 2; 2141 src += s->uv_stride;
2141 } while (--h); 2142 } while (--h);
2142 } 2143 }
2143 #endif 2144 #endif
2144 #endif 2145 #endif
2145 2146
2146 #ifdef OUTPUT_YUV_REC 2147 #ifdef OUTPUT_YUV_REC
2147 void vp9_write_yuv_rec_frame(VP9_COMMON *cm) { 2148 void vp9_write_yuv_rec_frame(VP9_COMMON *cm) {
2148 YV12_BUFFER_CONFIG *s = cm->frame_to_show; 2149 YV12_BUFFER_CONFIG *s = cm->frame_to_show;
2149 uint8_t *src = s->y_buffer; 2150 uint8_t *src = s->y_buffer;
2150 int h = cm->height; 2151 int h = cm->height;
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
2453 const YV12_BUFFER_CONFIG *const ref = &cm->frame_bufs[idx].buf; 2454 const YV12_BUFFER_CONFIG *const ref = &cm->frame_bufs[idx].buf;
2454 2455
2455 #if CONFIG_VP9_HIGHBITDEPTH 2456 #if CONFIG_VP9_HIGHBITDEPTH
2456 if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) { 2457 if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) {
2457 const int new_fb = get_free_fb(cm); 2458 const int new_fb = get_free_fb(cm);
2458 cm->cur_frame = &cm->frame_bufs[new_fb]; 2459 cm->cur_frame = &cm->frame_bufs[new_fb];
2459 vp9_realloc_frame_buffer(&cm->frame_bufs[new_fb].buf, 2460 vp9_realloc_frame_buffer(&cm->frame_bufs[new_fb].buf,
2460 cm->width, cm->height, 2461 cm->width, cm->height,
2461 cm->subsampling_x, cm->subsampling_y, 2462 cm->subsampling_x, cm->subsampling_y,
2462 cm->use_highbitdepth, 2463 cm->use_highbitdepth,
2463 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL); 2464 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
2465 NULL, NULL, NULL);
2464 scale_and_extend_frame(ref, &cm->frame_bufs[new_fb].buf, 2466 scale_and_extend_frame(ref, &cm->frame_bufs[new_fb].buf,
2465 (int)cm->bit_depth); 2467 (int)cm->bit_depth);
2466 #else 2468 #else
2467 if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) { 2469 if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) {
2468 const int new_fb = get_free_fb(cm); 2470 const int new_fb = get_free_fb(cm);
2469 vp9_realloc_frame_buffer(&cm->frame_bufs[new_fb].buf, 2471 vp9_realloc_frame_buffer(&cm->frame_bufs[new_fb].buf,
2470 cm->width, cm->height, 2472 cm->width, cm->height,
2471 cm->subsampling_x, cm->subsampling_y, 2473 cm->subsampling_x, cm->subsampling_y,
2472 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL); 2474 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
2475 NULL, NULL, NULL);
2473 scale_and_extend_frame(ref, &cm->frame_bufs[new_fb].buf); 2476 scale_and_extend_frame(ref, &cm->frame_bufs[new_fb].buf);
2474 #endif // CONFIG_VP9_HIGHBITDEPTH 2477 #endif // CONFIG_VP9_HIGHBITDEPTH
2475 cpi->scaled_ref_idx[ref_frame - 1] = new_fb; 2478 cpi->scaled_ref_idx[ref_frame - 1] = new_fb;
2476 if (cm->frame_bufs[new_fb].mvs == NULL || 2479 if (cm->frame_bufs[new_fb].mvs == NULL ||
2477 cm->frame_bufs[new_fb].mi_rows < cm->mi_rows || 2480 cm->frame_bufs[new_fb].mi_rows < cm->mi_rows ||
2478 cm->frame_bufs[new_fb].mi_cols < cm->mi_cols) { 2481 cm->frame_bufs[new_fb].mi_cols < cm->mi_cols) {
2479 vpx_free(cm->frame_bufs[new_fb].mvs); 2482 vpx_free(cm->frame_bufs[new_fb].mvs);
2480 cm->frame_bufs[new_fb].mvs = 2483 cm->frame_bufs[new_fb].mvs =
2481 (MV_REF *)vpx_calloc(cm->mi_rows * cm->mi_cols, 2484 (MV_REF *)vpx_calloc(cm->mi_rows * cm->mi_cols,
2482 sizeof(*cm->frame_bufs[new_fb].mvs)); 2485 sizeof(*cm->frame_bufs[new_fb].mvs));
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2526 for (j = 0; j < REF_TYPES; ++j) 2529 for (j = 0; j < REF_TYPES; ++j)
2527 for (k = 0; k < COEF_BANDS; ++k) 2530 for (k = 0; k < COEF_BANDS; ++k)
2528 for (l = 0; l < BAND_COEFF_CONTEXTS(k); ++l) 2531 for (l = 0; l < BAND_COEFF_CONTEXTS(k); ++l)
2529 full_to_model_count(model_count[i][j][k][l], full_count[i][j][k][l]); 2532 full_to_model_count(model_count[i][j][k][l], full_count[i][j][k][l]);
2530 } 2533 }
2531 2534
2532 #if 0 && CONFIG_INTERNAL_STATS 2535 #if 0 && CONFIG_INTERNAL_STATS
2533 static void output_frame_level_debug_stats(VP9_COMP *cpi) { 2536 static void output_frame_level_debug_stats(VP9_COMP *cpi) {
2534 VP9_COMMON *const cm = &cpi->common; 2537 VP9_COMMON *const cm = &cpi->common;
2535 FILE *const f = fopen("tmp.stt", cm->current_video_frame ? "a" : "w"); 2538 FILE *const f = fopen("tmp.stt", cm->current_video_frame ? "a" : "w");
2536 int recon_err; 2539 int64_t recon_err;
2537 2540
2538 vp9_clear_system_state(); 2541 vp9_clear_system_state();
2539 2542
2540 recon_err = vp9_get_y_sse(cpi->Source, get_frame_new_buffer(cm)); 2543 recon_err = vp9_get_y_sse(cpi->Source, get_frame_new_buffer(cm));
2541 2544
2542 if (cpi->twopass.total_left_stats.coded_error != 0.0) 2545 if (cpi->twopass.total_left_stats.coded_error != 0.0)
2543 fprintf(f, "%10u %10d %10d %10d %10d" 2546 fprintf(f, "%10u %10d %10d %10d %10d"
2544 "%10"PRId64" %10"PRId64" %10"PRId64" %10"PRId64" %10d " 2547 "%10"PRId64" %10"PRId64" %10"PRId64" %10"PRId64" %10d "
2545 "%7.2lf %7.2lf %7.2lf %7.2lf %7.2lf" 2548 "%7.2lf %7.2lf %7.2lf %7.2lf %7.2lf"
2546 "%6d %6d %5d %5d %5d " 2549 "%6d %6d %5d %5d %5d "
2547 "%10"PRId64" %10.3lf" 2550 "%10"PRId64" %10.3lf"
2548 "%10lf %8u %10d %10d %10d\n", 2551 "%10lf %8u %10"PRId64" %10d %10d\n",
2549 cpi->common.current_video_frame, cpi->rc.this_frame_target, 2552 cpi->common.current_video_frame, cpi->rc.this_frame_target,
2550 cpi->rc.projected_frame_size, 2553 cpi->rc.projected_frame_size,
2551 cpi->rc.projected_frame_size / cpi->common.MBs, 2554 cpi->rc.projected_frame_size / cpi->common.MBs,
2552 (cpi->rc.projected_frame_size - cpi->rc.this_frame_target), 2555 (cpi->rc.projected_frame_size - cpi->rc.this_frame_target),
2553 cpi->rc.vbr_bits_off_target, 2556 cpi->rc.vbr_bits_off_target,
2554 cpi->rc.total_target_vs_actual, 2557 cpi->rc.total_target_vs_actual,
2555 (cpi->rc.starting_buffer_level - cpi->rc.bits_off_target), 2558 (cpi->rc.starting_buffer_level - cpi->rc.bits_off_target),
2556 cpi->rc.total_actual_bits, cm->base_qindex, 2559 cpi->rc.total_actual_bits, cm->base_qindex,
2557 vp9_convert_qindex_to_q(cm->base_qindex, cm->bit_depth), 2560 vp9_convert_qindex_to_q(cm->base_qindex, cm->bit_depth),
2558 (double)vp9_dc_quant(cm->base_qindex, 0, cm->bit_depth) / 4.0, 2561 (double)vp9_dc_quant(cm->base_qindex, 0, cm->bit_depth) / 4.0,
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
2701 vp9_set_target_rate(cpi); 2704 vp9_set_target_rate(cpi);
2702 } 2705 }
2703 2706
2704 // Reset the frame pointers to the current frame size. 2707 // Reset the frame pointers to the current frame size.
2705 vp9_realloc_frame_buffer(get_frame_new_buffer(cm), 2708 vp9_realloc_frame_buffer(get_frame_new_buffer(cm),
2706 cm->width, cm->height, 2709 cm->width, cm->height,
2707 cm->subsampling_x, cm->subsampling_y, 2710 cm->subsampling_x, cm->subsampling_y,
2708 #if CONFIG_VP9_HIGHBITDEPTH 2711 #if CONFIG_VP9_HIGHBITDEPTH
2709 cm->use_highbitdepth, 2712 cm->use_highbitdepth,
2710 #endif 2713 #endif
2711 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL); 2714 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
2715 NULL, NULL, NULL);
2712 2716
2713 alloc_util_frame_buffers(cpi); 2717 alloc_util_frame_buffers(cpi);
2714 init_motion_estimation(cpi); 2718 init_motion_estimation(cpi);
2715 2719
2716 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { 2720 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
2717 const int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)]; 2721 const int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)];
2718 YV12_BUFFER_CONFIG *const buf = &cm->frame_bufs[idx].buf; 2722 YV12_BUFFER_CONFIG *const buf = &cm->frame_bufs[idx].buf;
2719 RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - 1]; 2723 RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - 1];
2720 ref_buf->buf = buf; 2724 ref_buf->buf = buf;
2721 ref_buf->idx = idx; 2725 ref_buf->idx = idx;
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
2866 frame_over_shoot_limit = 1; 2870 frame_over_shoot_limit = 1;
2867 } 2871 }
2868 2872
2869 if (cpi->oxcf.rc_mode == VPX_Q) { 2873 if (cpi->oxcf.rc_mode == VPX_Q) {
2870 loop = 0; 2874 loop = 0;
2871 } else { 2875 } else {
2872 if ((cm->frame_type == KEY_FRAME) && 2876 if ((cm->frame_type == KEY_FRAME) &&
2873 rc->this_key_frame_forced && 2877 rc->this_key_frame_forced &&
2874 (rc->projected_frame_size < rc->max_frame_bandwidth)) { 2878 (rc->projected_frame_size < rc->max_frame_bandwidth)) {
2875 int last_q = q; 2879 int last_q = q;
2876 int kf_err; 2880 int64_t kf_err;
2877 2881
2878 int high_err_target = cpi->ambient_err; 2882 int64_t high_err_target = cpi->ambient_err;
2879 int low_err_target = cpi->ambient_err >> 1; 2883 int64_t low_err_target = cpi->ambient_err >> 1;
2880 2884
2881 #if CONFIG_VP9_HIGHBITDEPTH 2885 #if CONFIG_VP9_HIGHBITDEPTH
2882 if (cm->use_highbitdepth) { 2886 if (cm->use_highbitdepth) {
2883 kf_err = vp9_highbd_get_y_sse(cpi->Source, get_frame_new_buffer(cm), 2887 kf_err = vp9_highbd_get_y_sse(cpi->Source, get_frame_new_buffer(cm));
2884 cm->bit_depth);
2885 } else { 2888 } else {
2886 kf_err = vp9_get_y_sse(cpi->Source, get_frame_new_buffer(cm)); 2889 kf_err = vp9_get_y_sse(cpi->Source, get_frame_new_buffer(cm));
2887 } 2890 }
2888 #else 2891 #else
2889 kf_err = vp9_get_y_sse(cpi->Source, get_frame_new_buffer(cm)); 2892 kf_err = vp9_get_y_sse(cpi->Source, get_frame_new_buffer(cm));
2890 #endif // CONFIG_VP9_HIGHBITDEPTH 2893 #endif // CONFIG_VP9_HIGHBITDEPTH
2891 2894
2892 // Prevent possible divide by zero error below for perfect KF 2895 // Prevent possible divide by zero error below for perfect KF
2893 kf_err += !kf_err; 2896 kf_err += !kf_err;
2894 2897
2895 // The key frame is not good enough or we can afford 2898 // The key frame is not good enough or we can afford
2896 // to make it better without undue risk of popping. 2899 // to make it better without undue risk of popping.
2897 if ((kf_err > high_err_target && 2900 if ((kf_err > high_err_target &&
2898 rc->projected_frame_size <= frame_over_shoot_limit) || 2901 rc->projected_frame_size <= frame_over_shoot_limit) ||
2899 (kf_err > low_err_target && 2902 (kf_err > low_err_target &&
2900 rc->projected_frame_size <= frame_under_shoot_limit)) { 2903 rc->projected_frame_size <= frame_under_shoot_limit)) {
2901 // Lower q_high 2904 // Lower q_high
2902 q_high = q > q_low ? q - 1 : q_low; 2905 q_high = q > q_low ? q - 1 : q_low;
2903 2906
2904 // Adjust Q 2907 // Adjust Q
2905 q = (q * high_err_target) / kf_err; 2908 q = (int)((q * high_err_target) / kf_err);
2906 q = MIN(q, (q_high + q_low) >> 1); 2909 q = MIN(q, (q_high + q_low) >> 1);
2907 } else if (kf_err < low_err_target && 2910 } else if (kf_err < low_err_target &&
2908 rc->projected_frame_size >= frame_under_shoot_limit) { 2911 rc->projected_frame_size >= frame_under_shoot_limit) {
2909 // The key frame is much better than the previous frame 2912 // The key frame is much better than the previous frame
2910 // Raise q_low 2913 // Raise q_low
2911 q_low = q < q_high ? q + 1 : q_high; 2914 q_low = q < q_high ? q + 1 : q_high;
2912 2915
2913 // Adjust Q 2916 // Adjust Q
2914 q = (q * low_err_target) / kf_err; 2917 q = (int)((q * low_err_target) / kf_err);
2915 q = MIN(q, (q_high + q_low + 1) >> 1); 2918 q = MIN(q, (q_high + q_low + 1) >> 1);
2916 } 2919 }
2917 2920
2918 // Clamp Q to upper and lower limits: 2921 // Clamp Q to upper and lower limits:
2919 q = clamp(q, q_low, q_high); 2922 q = clamp(q, q_low, q_high);
2920 2923
2921 loop = q != last_q; 2924 loop = q != last_q;
2922 } else if (recode_loop_test( 2925 } else if (recode_loop_test(
2923 cpi, frame_over_shoot_limit, frame_under_shoot_limit, 2926 cpi, frame_over_shoot_limit, frame_under_shoot_limit,
2924 q, MAX(q_high, top_index), bottom_index)) { 2927 q, MAX(q_high, top_index), bottom_index)) {
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
3120 unsigned int *frame_flags) { 3123 unsigned int *frame_flags) {
3121 VP9_COMMON *const cm = &cpi->common; 3124 VP9_COMMON *const cm = &cpi->common;
3122 const VP9EncoderConfig *const oxcf = &cpi->oxcf; 3125 const VP9EncoderConfig *const oxcf = &cpi->oxcf;
3123 struct segmentation *const seg = &cm->seg; 3126 struct segmentation *const seg = &cm->seg;
3124 TX_SIZE t; 3127 TX_SIZE t;
3125 3128
3126 set_ext_overrides(cpi); 3129 set_ext_overrides(cpi);
3127 3130
3128 vp9_clear_system_state(); 3131 vp9_clear_system_state();
3129 3132
3130 // Enable or disable mode based tweaking of the zbin.
3131 // For 2 pass only used where GF/ARF prediction quality
3132 // is above a threshold.
3133 cpi->zbin_mode_boost = 0;
3134 cpi->zbin_mode_boost_enabled = 0;
3135
3136 // Set the arf sign bias for this frame. 3133 // Set the arf sign bias for this frame.
3137 set_arf_sign_bias(cpi); 3134 set_arf_sign_bias(cpi);
3138 3135
3139 // Set default state for segment based loop filter update flags. 3136 // Set default state for segment based loop filter update flags.
3140 cm->lf.mode_ref_delta_update = 0; 3137 cm->lf.mode_ref_delta_update = 0;
3141 3138
3142 if (cpi->oxcf.pass == 2 && 3139 if (cpi->oxcf.pass == 2 &&
3143 cpi->sf.adaptive_interp_filter_search) 3140 cpi->sf.adaptive_interp_filter_search)
3144 cpi->sf.interp_filter_search_mask = 3141 cpi->sf.interp_filter_search_mask =
3145 setup_interp_filter_search_mask(cpi); 3142 setup_interp_filter_search_mask(cpi);
3146 3143
3147 // Set various flags etc to special state if it is a key frame. 3144 // Set various flags etc to special state if it is a key frame.
3148 if (frame_is_intra_only(cm)) { 3145 if (frame_is_intra_only(cm)) {
3149 // Reset the loop filter deltas and segmentation map. 3146 // Reset the loop filter deltas and segmentation map.
3150 vp9_reset_segment_features(&cm->seg); 3147 vp9_reset_segment_features(&cm->seg);
3151 3148
3152 // If segmentation is enabled force a map update for key frames. 3149 // If segmentation is enabled force a map update for key frames.
3153 if (seg->enabled) { 3150 if (seg->enabled) {
3154 seg->update_map = 1; 3151 seg->update_map = 1;
3155 seg->update_data = 1; 3152 seg->update_data = 1;
3156 } 3153 }
3157 3154
3158 // The alternate reference frame cannot be active for a key frame. 3155 // The alternate reference frame cannot be active for a key frame.
3159 cpi->rc.source_alt_ref_active = 0; 3156 cpi->rc.source_alt_ref_active = 0;
3160 3157
3161 cm->error_resilient_mode = oxcf->error_resilient_mode; 3158 cm->error_resilient_mode = oxcf->error_resilient_mode;
3159 cm->frame_parallel_decoding_mode = oxcf->frame_parallel_decoding_mode;
3162 3160
3163 // By default, encoder assumes decoder can use prev_mi. 3161 // By default, encoder assumes decoder can use prev_mi.
3164 if (cm->error_resilient_mode) { 3162 if (cm->error_resilient_mode) {
3165 cm->frame_parallel_decoding_mode = 1; 3163 cm->frame_parallel_decoding_mode = 1;
3166 cm->reset_frame_context = 0; 3164 cm->reset_frame_context = 0;
3167 cm->refresh_frame_context = 0; 3165 cm->refresh_frame_context = 0;
3168 } else if (cm->intra_only) { 3166 } else if (cm->intra_only) {
3169 cm->frame_parallel_decoding_mode = oxcf->frame_parallel_decoding_mode;
3170 // Only reset the current context. 3167 // Only reset the current context.
3171 cm->reset_frame_context = 2; 3168 cm->reset_frame_context = 2;
3172 } 3169 }
3173 } 3170 }
3174 if (is_two_pass_svc(cpi) && cm->error_resilient_mode == 0) { 3171 if (is_two_pass_svc(cpi) && cm->error_resilient_mode == 0) {
3175 // Use the last frame context for the empty frame. 3172 // Use the last frame context for the empty frame.
3176 cm->frame_context_idx = 3173 cm->frame_context_idx =
3177 (cpi->svc.encode_empty_frame_state == ENCODING) ? FRAME_CONTEXTS - 1 : 3174 (cpi->svc.encode_empty_frame_state == ENCODING) ? FRAME_CONTEXTS - 1 :
3178 cpi->svc.spatial_layer_id * cpi->svc.number_temporal_layers + 3175 cpi->svc.spatial_layer_id * cpi->svc.number_temporal_layers +
3179 cpi->svc.temporal_layer_id; 3176 cpi->svc.temporal_layer_id;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
3238 #endif 3235 #endif
3239 3236
3240 3237
3241 // Special case code to reduce pulsing when key frames are forced at a 3238 // Special case code to reduce pulsing when key frames are forced at a
3242 // fixed interval. Note the reconstruction error if it is the frame before 3239 // fixed interval. Note the reconstruction error if it is the frame before
3243 // the force key frame 3240 // the force key frame
3244 if (cpi->rc.next_key_frame_forced && cpi->rc.frames_to_key == 1) { 3241 if (cpi->rc.next_key_frame_forced && cpi->rc.frames_to_key == 1) {
3245 #if CONFIG_VP9_HIGHBITDEPTH 3242 #if CONFIG_VP9_HIGHBITDEPTH
3246 if (cm->use_highbitdepth) { 3243 if (cm->use_highbitdepth) {
3247 cpi->ambient_err = vp9_highbd_get_y_sse(cpi->Source, 3244 cpi->ambient_err = vp9_highbd_get_y_sse(cpi->Source,
3248 get_frame_new_buffer(cm), 3245 get_frame_new_buffer(cm));
3249 cm->bit_depth);
3250 } else { 3246 } else {
3251 cpi->ambient_err = vp9_get_y_sse(cpi->Source, get_frame_new_buffer(cm)); 3247 cpi->ambient_err = vp9_get_y_sse(cpi->Source, get_frame_new_buffer(cm));
3252 } 3248 }
3253 #else 3249 #else
3254 cpi->ambient_err = vp9_get_y_sse(cpi->Source, get_frame_new_buffer(cm)); 3250 cpi->ambient_err = vp9_get_y_sse(cpi->Source, get_frame_new_buffer(cm));
3255 #endif // CONFIG_VP9_HIGHBITDEPTH 3251 #endif // CONFIG_VP9_HIGHBITDEPTH
3256 } 3252 }
3257 3253
3258 // If the encoder forced a KEY_FRAME decision 3254 // If the encoder forced a KEY_FRAME decision
3259 if (cm->frame_type == KEY_FRAME) 3255 if (cm->frame_type == KEY_FRAME)
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
3390 alloc_util_frame_buffers(cpi); 3386 alloc_util_frame_buffers(cpi);
3391 3387
3392 init_motion_estimation(cpi); // TODO(agrange) This can be removed. 3388 init_motion_estimation(cpi); // TODO(agrange) This can be removed.
3393 3389
3394 cpi->initial_width = cm->width; 3390 cpi->initial_width = cm->width;
3395 cpi->initial_height = cm->height; 3391 cpi->initial_height = cm->height;
3396 cpi->initial_mbs = cm->MBs; 3392 cpi->initial_mbs = cm->MBs;
3397 } 3393 }
3398 } 3394 }
3399 3395
3396 #if CONFIG_VP9_TEMPORAL_DENOISING
3397 static void setup_denoiser_buffer(VP9_COMP *cpi) {
3398 VP9_COMMON *const cm = &cpi->common;
3399 if (cpi->oxcf.noise_sensitivity > 0 &&
3400 !cpi->denoiser.frame_buffer_initialized) {
3401 vp9_denoiser_alloc(&(cpi->denoiser), cm->width, cm->height,
3402 cm->subsampling_x, cm->subsampling_y,
3403 #if CONFIG_VP9_HIGHBITDEPTH
3404 cm->use_highbitdepth,
3405 #endif
3406 VP9_ENC_BORDER_IN_PIXELS);
3407 }
3408 }
3409 #endif
3400 3410
3401 int vp9_receive_raw_frame(VP9_COMP *cpi, unsigned int frame_flags, 3411 int vp9_receive_raw_frame(VP9_COMP *cpi, unsigned int frame_flags,
3402 YV12_BUFFER_CONFIG *sd, int64_t time_stamp, 3412 YV12_BUFFER_CONFIG *sd, int64_t time_stamp,
3403 int64_t end_time) { 3413 int64_t end_time) {
3404 VP9_COMMON *cm = &cpi->common; 3414 VP9_COMMON *cm = &cpi->common;
3405 struct vpx_usec_timer timer; 3415 struct vpx_usec_timer timer;
3406 int res = 0; 3416 int res = 0;
3407 const int subsampling_x = sd->subsampling_x; 3417 const int subsampling_x = sd->subsampling_x;
3408 const int subsampling_y = sd->subsampling_y; 3418 const int subsampling_y = sd->subsampling_y;
3409 #if CONFIG_VP9_HIGHBITDEPTH 3419 #if CONFIG_VP9_HIGHBITDEPTH
3410 const int use_highbitdepth = sd->flags & YV12_FLAG_HIGHBITDEPTH; 3420 const int use_highbitdepth = sd->flags & YV12_FLAG_HIGHBITDEPTH;
3411 check_initial_width(cpi, use_highbitdepth, subsampling_x, subsampling_y); 3421 check_initial_width(cpi, use_highbitdepth, subsampling_x, subsampling_y);
3412 #else 3422 #else
3413 check_initial_width(cpi, subsampling_x, subsampling_y); 3423 check_initial_width(cpi, subsampling_x, subsampling_y);
3414 #endif // CONFIG_VP9_HIGHBITDEPTH 3424 #endif // CONFIG_VP9_HIGHBITDEPTH
3415 3425
3426 #if CONFIG_VP9_TEMPORAL_DENOISING
3427 setup_denoiser_buffer(cpi);
3428 #endif
3416 vpx_usec_timer_start(&timer); 3429 vpx_usec_timer_start(&timer);
3417 3430
3418 if (vp9_lookahead_push(cpi->lookahead, sd, time_stamp, end_time, frame_flags)) 3431 if (vp9_lookahead_push(cpi->lookahead, sd, time_stamp, end_time, frame_flags))
3419 res = -1; 3432 res = -1;
3420 vpx_usec_timer_mark(&timer); 3433 vpx_usec_timer_mark(&timer);
3421 cpi->time_receive_data += vpx_usec_timer_elapsed(&timer); 3434 cpi->time_receive_data += vpx_usec_timer_elapsed(&timer);
3422 3435
3423 if ((cm->profile == PROFILE_0 || cm->profile == PROFILE_2) && 3436 if ((cm->profile == PROFILE_0 || cm->profile == PROFILE_2) &&
3424 (subsampling_x != 1 || subsampling_y != 1)) { 3437 (subsampling_x != 1 || subsampling_y != 1)) {
3425 vpx_internal_error(&cm->error, VPX_CODEC_INVALID_PARAM, 3438 vpx_internal_error(&cm->error, VPX_CODEC_INVALID_PARAM,
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
3819 3832
3820 cpi->totalp += psnr2.psnr[0]; 3833 cpi->totalp += psnr2.psnr[0];
3821 cpi->totalp_y += psnr2.psnr[1]; 3834 cpi->totalp_y += psnr2.psnr[1];
3822 cpi->totalp_u += psnr2.psnr[2]; 3835 cpi->totalp_u += psnr2.psnr[2];
3823 cpi->totalp_v += psnr2.psnr[3]; 3836 cpi->totalp_v += psnr2.psnr[3];
3824 cpi->totalp_sq_error += psnr2.sse[0]; 3837 cpi->totalp_sq_error += psnr2.sse[0];
3825 cpi->totalp_samples += psnr2.samples[0]; 3838 cpi->totalp_samples += psnr2.samples[0];
3826 3839
3827 #if CONFIG_VP9_HIGHBITDEPTH 3840 #if CONFIG_VP9_HIGHBITDEPTH
3828 if (cm->use_highbitdepth) { 3841 if (cm->use_highbitdepth) {
3829 frame_ssim2 = vp9_highbd_calc_ssim(orig, recon, &weight, xd->bd); 3842 frame_ssim2 = vp9_highbd_calc_ssim(orig, recon, &weight,
3843 (int)cm->bit_depth);
3830 } else { 3844 } else {
3831 frame_ssim2 = vp9_calc_ssim(orig, recon, &weight); 3845 frame_ssim2 = vp9_calc_ssim(orig, recon, &weight);
3832 } 3846 }
3833 #else 3847 #else
3834 frame_ssim2 = vp9_calc_ssim(orig, recon, &weight); 3848 frame_ssim2 = vp9_calc_ssim(orig, recon, &weight);
3835 #endif // CONFIG_VP9_HIGHBITDEPTH 3849 #endif // CONFIG_VP9_HIGHBITDEPTH
3836 3850
3837 cpi->summed_quality += frame_ssim2 * weight; 3851 cpi->summed_quality += frame_ssim2 * weight;
3838 cpi->summed_weights += weight; 3852 cpi->summed_weights += weight;
3839 3853
3840 #if CONFIG_VP9_HIGHBITDEPTH 3854 #if CONFIG_VP9_HIGHBITDEPTH
3841 if (cm->use_highbitdepth) { 3855 if (cm->use_highbitdepth) {
3842 frame_ssim2 = vp9_highbd_calc_ssim( 3856 frame_ssim2 = vp9_highbd_calc_ssim(
3843 orig, &cm->post_proc_buffer, &weight, xd->bd); 3857 orig, &cm->post_proc_buffer, &weight, (int)cm->bit_depth);
3844 } else { 3858 } else {
3845 frame_ssim2 = vp9_calc_ssim(orig, &cm->post_proc_buffer, &weight); 3859 frame_ssim2 = vp9_calc_ssim(orig, &cm->post_proc_buffer, &weight);
3846 } 3860 }
3847 #else 3861 #else
3848 frame_ssim2 = vp9_calc_ssim(orig, &cm->post_proc_buffer, &weight); 3862 frame_ssim2 = vp9_calc_ssim(orig, &cm->post_proc_buffer, &weight);
3849 #endif // CONFIG_VP9_HIGHBITDEPTH 3863 #endif // CONFIG_VP9_HIGHBITDEPTH
3850 3864
3851 cpi->summedp_quality += frame_ssim2 * weight; 3865 cpi->summedp_quality += frame_ssim2 * weight;
3852 cpi->summedp_weights += weight; 3866 cpi->summedp_weights += weight;
3853 #if 0 3867 #if 0
3854 { 3868 {
3855 FILE *f = fopen("q_used.stt", "a"); 3869 FILE *f = fopen("q_used.stt", "a");
3856 fprintf(f, "%5d : Y%f7.3:U%f7.3:V%f7.3:F%f7.3:S%7.3f\n", 3870 fprintf(f, "%5d : Y%f7.3:U%f7.3:V%f7.3:F%f7.3:S%7.3f\n",
3857 cpi->common.current_video_frame, y2, u2, v2, 3871 cpi->common.current_video_frame, y2, u2, v2,
3858 frame_psnr2, frame_ssim2); 3872 frame_psnr2, frame_ssim2);
3859 fclose(f); 3873 fclose(f);
3860 } 3874 }
3861 #endif 3875 #endif
3862 } 3876 }
3863 } 3877 }
3864 3878
3865 3879
3866 if (cpi->b_calculate_ssimg) { 3880 if (cpi->b_calculate_ssimg) {
3867 double y, u, v, frame_all; 3881 double y, u, v, frame_all;
3868 #if CONFIG_VP9_HIGHBITDEPTH 3882 #if CONFIG_VP9_HIGHBITDEPTH
3869 if (cm->use_highbitdepth) { 3883 if (cm->use_highbitdepth) {
3870 frame_all = vp9_highbd_calc_ssimg(cpi->Source, cm->frame_to_show, &y, 3884 frame_all = vp9_highbd_calc_ssimg(cpi->Source, cm->frame_to_show, &y,
3871 &u, &v, xd->bd); 3885 &u, &v, (int)cm->bit_depth);
3872 } else { 3886 } else {
3873 frame_all = vp9_calc_ssimg(cpi->Source, cm->frame_to_show, &y, &u, 3887 frame_all = vp9_calc_ssimg(cpi->Source, cm->frame_to_show, &y, &u,
3874 &v); 3888 &v);
3875 } 3889 }
3876 #else 3890 #else
3877 frame_all = vp9_calc_ssimg(cpi->Source, cm->frame_to_show, &y, &u, &v); 3891 frame_all = vp9_calc_ssimg(cpi->Source, cm->frame_to_show, &y, &u, &v);
3878 #endif // CONFIG_VP9_HIGHBITDEPTH 3892 #endif // CONFIG_VP9_HIGHBITDEPTH
3879 cpi->total_ssimg_y += y; 3893 cpi->total_ssimg_y += y;
3880 cpi->total_ssimg_u += u; 3894 cpi->total_ssimg_u += u;
3881 cpi->total_ssimg_v += v; 3895 cpi->total_ssimg_v += v;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
3979 3993
3980 int vp9_set_size_literal(VP9_COMP *cpi, unsigned int width, 3994 int vp9_set_size_literal(VP9_COMP *cpi, unsigned int width,
3981 unsigned int height) { 3995 unsigned int height) {
3982 VP9_COMMON *cm = &cpi->common; 3996 VP9_COMMON *cm = &cpi->common;
3983 #if CONFIG_VP9_HIGHBITDEPTH 3997 #if CONFIG_VP9_HIGHBITDEPTH
3984 check_initial_width(cpi, 1, 1, cm->use_highbitdepth); 3998 check_initial_width(cpi, 1, 1, cm->use_highbitdepth);
3985 #else 3999 #else
3986 check_initial_width(cpi, 1, 1); 4000 check_initial_width(cpi, 1, 1);
3987 #endif // CONFIG_VP9_HIGHBITDEPTH 4001 #endif // CONFIG_VP9_HIGHBITDEPTH
3988 4002
4003 #if CONFIG_VP9_TEMPORAL_DENOISING
4004 setup_denoiser_buffer(cpi);
4005 #endif
4006
3989 if (width) { 4007 if (width) {
3990 cm->width = width; 4008 cm->width = width;
3991 if (cm->width > cpi->initial_width) { 4009 if (cm->width > cpi->initial_width) {
3992 cm->width = cpi->initial_width; 4010 cm->width = cpi->initial_width;
3993 printf("Warning: Desired width too large, changed to %d\n", cm->width); 4011 printf("Warning: Desired width too large, changed to %d\n", cm->width);
3994 } 4012 }
3995 } 4013 }
3996 4014
3997 if (height) { 4015 if (height) {
3998 cm->height = height; 4016 cm->height = height;
3999 if (cm->height > cpi->initial_height) { 4017 if (cm->height > cpi->initial_height) {
4000 cm->height = cpi->initial_height; 4018 cm->height = cpi->initial_height;
4001 printf("Warning: Desired height too large, changed to %d\n", cm->height); 4019 printf("Warning: Desired height too large, changed to %d\n", cm->height);
4002 } 4020 }
4003 } 4021 }
4004 assert(cm->width <= cpi->initial_width); 4022 assert(cm->width <= cpi->initial_width);
4005 assert(cm->height <= cpi->initial_height); 4023 assert(cm->height <= cpi->initial_height);
4006 4024
4007 update_frame_size(cpi); 4025 update_frame_size(cpi);
4008 4026
4009 return 0; 4027 return 0;
4010 } 4028 }
4011 4029
4012 void vp9_set_svc(VP9_COMP *cpi, int use_svc) { 4030 void vp9_set_svc(VP9_COMP *cpi, int use_svc) {
4013 cpi->use_svc = use_svc; 4031 cpi->use_svc = use_svc;
4014 return; 4032 return;
4015 } 4033 }
4016 4034
4017 int vp9_get_y_sse(const YV12_BUFFER_CONFIG *a, const YV12_BUFFER_CONFIG *b) { 4035 int64_t vp9_get_y_sse(const YV12_BUFFER_CONFIG *a,
4036 const YV12_BUFFER_CONFIG *b) {
4018 assert(a->y_crop_width == b->y_crop_width); 4037 assert(a->y_crop_width == b->y_crop_width);
4019 assert(a->y_crop_height == b->y_crop_height); 4038 assert(a->y_crop_height == b->y_crop_height);
4020 4039
4021 return (int)get_sse(a->y_buffer, a->y_stride, b->y_buffer, b->y_stride, 4040 return get_sse(a->y_buffer, a->y_stride, b->y_buffer, b->y_stride,
4022 a->y_crop_width, a->y_crop_height); 4041 a->y_crop_width, a->y_crop_height);
4023 } 4042 }
4024 4043
4025 #if CONFIG_VP9_HIGHBITDEPTH 4044 #if CONFIG_VP9_HIGHBITDEPTH
4026 int vp9_highbd_get_y_sse(const YV12_BUFFER_CONFIG *a, 4045 int64_t vp9_highbd_get_y_sse(const YV12_BUFFER_CONFIG *a,
4027 const YV12_BUFFER_CONFIG *b, 4046 const YV12_BUFFER_CONFIG *b) {
4028 vpx_bit_depth_t bit_depth) {
4029 unsigned int sse;
4030 int sum;
4031 assert(a->y_crop_width == b->y_crop_width); 4047 assert(a->y_crop_width == b->y_crop_width);
4032 assert(a->y_crop_height == b->y_crop_height); 4048 assert(a->y_crop_height == b->y_crop_height);
4033 assert((a->flags & YV12_FLAG_HIGHBITDEPTH) != 0); 4049 assert((a->flags & YV12_FLAG_HIGHBITDEPTH) != 0);
4034 assert((b->flags & YV12_FLAG_HIGHBITDEPTH) != 0); 4050 assert((b->flags & YV12_FLAG_HIGHBITDEPTH) != 0);
4035 switch (bit_depth) { 4051
4036 case VPX_BITS_8: 4052 return highbd_get_sse(a->y_buffer, a->y_stride, b->y_buffer, b->y_stride,
4037 highbd_variance(a->y_buffer, a->y_stride, b->y_buffer, b->y_stride, 4053 a->y_crop_width, a->y_crop_height);
4038 a->y_crop_width, a->y_crop_height, &sse, &sum);
4039 return (int) sse;
4040 case VPX_BITS_10:
4041 highbd_10_variance(a->y_buffer, a->y_stride, b->y_buffer, b->y_stride,
4042 a->y_crop_width, a->y_crop_height, &sse, &sum);
4043 return (int) sse;
4044 case VPX_BITS_12:
4045 highbd_12_variance(a->y_buffer, a->y_stride, b->y_buffer, b->y_stride,
4046 a->y_crop_width, a->y_crop_height, &sse, &sum);
4047 return (int) sse;
4048 default:
4049 assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12");
4050 return -1;
4051 }
4052 } 4054 }
4053 #endif // CONFIG_VP9_HIGHBITDEPTH 4055 #endif // CONFIG_VP9_HIGHBITDEPTH
4054 4056
4055 int vp9_get_quantizer(VP9_COMP *cpi) { 4057 int vp9_get_quantizer(VP9_COMP *cpi) {
4056 return cpi->common.base_qindex; 4058 return cpi->common.base_qindex;
4057 } 4059 }
4058 4060
4059 void vp9_apply_encoding_flags(VP9_COMP *cpi, vpx_enc_frame_flags_t flags) { 4061 void vp9_apply_encoding_flags(VP9_COMP *cpi, vpx_enc_frame_flags_t flags) {
4060 if (flags & (VP8_EFLAG_NO_REF_LAST | VP8_EFLAG_NO_REF_GF | 4062 if (flags & (VP8_EFLAG_NO_REF_LAST | VP8_EFLAG_NO_REF_GF |
4061 VP8_EFLAG_NO_REF_ARF)) { 4063 VP8_EFLAG_NO_REF_ARF)) {
(...skipping 25 matching lines...) Expand all
4087 if (flags & VP8_EFLAG_NO_UPD_ARF) 4089 if (flags & VP8_EFLAG_NO_UPD_ARF)
4088 upd ^= VP9_ALT_FLAG; 4090 upd ^= VP9_ALT_FLAG;
4089 4091
4090 vp9_update_reference(cpi, upd); 4092 vp9_update_reference(cpi, upd);
4091 } 4093 }
4092 4094
4093 if (flags & VP8_EFLAG_NO_UPD_ENTROPY) { 4095 if (flags & VP8_EFLAG_NO_UPD_ENTROPY) {
4094 vp9_update_entropy(cpi, 0); 4096 vp9_update_entropy(cpi, 0);
4095 } 4097 }
4096 } 4098 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_encoder.h ('k') | source/libvpx/vp9/encoder/vp9_ethread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698