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

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

Issue 996503002: libvpx: Pull from upstream (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libvpx.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_encoder.h ('k') | source/libvpx/vp9/encoder/vp9_ethread.c » ('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 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 cpi->lookahead = vp9_lookahead_init(oxcf->width, oxcf->height, 476 cpi->lookahead = vp9_lookahead_init(oxcf->width, oxcf->height,
477 cm->subsampling_x, cm->subsampling_y, 477 cm->subsampling_x, cm->subsampling_y,
478 #if CONFIG_VP9_HIGHBITDEPTH 478 #if CONFIG_VP9_HIGHBITDEPTH
479 cm->use_highbitdepth, 479 cm->use_highbitdepth,
480 #endif 480 #endif
481 oxcf->lag_in_frames); 481 oxcf->lag_in_frames);
482 if (!cpi->lookahead) 482 if (!cpi->lookahead)
483 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, 483 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
484 "Failed to allocate lag buffers"); 484 "Failed to allocate lag buffers");
485 485
486 // TODO(agrange) Check if ARF is enabled and skip allocation if not.
486 if (vp9_realloc_frame_buffer(&cpi->alt_ref_buffer, 487 if (vp9_realloc_frame_buffer(&cpi->alt_ref_buffer,
487 oxcf->width, oxcf->height, 488 oxcf->width, oxcf->height,
488 cm->subsampling_x, cm->subsampling_y, 489 cm->subsampling_x, cm->subsampling_y,
489 #if CONFIG_VP9_HIGHBITDEPTH 490 #if CONFIG_VP9_HIGHBITDEPTH
490 cm->use_highbitdepth, 491 cm->use_highbitdepth,
491 #endif 492 #endif
492 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment, 493 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
493 NULL, NULL, NULL)) 494 NULL, NULL, NULL))
494 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, 495 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
495 "Failed to allocate altref buffer"); 496 "Failed to allocate altref buffer");
496 } 497 }
497 498
498 static void alloc_ref_frame_buffers(VP9_COMP *cpi) {
499 VP9_COMMON *const cm = &cpi->common;
500 if (vp9_alloc_ref_frame_buffers(cm, cm->width, cm->height))
501 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
502 "Failed to allocate frame buffers");
503 }
504
505 static void alloc_util_frame_buffers(VP9_COMP *cpi) { 499 static void alloc_util_frame_buffers(VP9_COMP *cpi) {
506 VP9_COMMON *const cm = &cpi->common; 500 VP9_COMMON *const cm = &cpi->common;
507 if (vp9_realloc_frame_buffer(&cpi->last_frame_uf, 501 if (vp9_realloc_frame_buffer(&cpi->last_frame_uf,
508 cm->width, cm->height, 502 cm->width, cm->height,
509 cm->subsampling_x, cm->subsampling_y, 503 cm->subsampling_x, cm->subsampling_y,
510 #if CONFIG_VP9_HIGHBITDEPTH 504 #if CONFIG_VP9_HIGHBITDEPTH
511 cm->use_highbitdepth, 505 cm->use_highbitdepth,
512 #endif 506 #endif
513 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment, 507 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
514 NULL, NULL, NULL)) 508 NULL, NULL, NULL))
(...skipping 1441 matching lines...) Expand 10 before | Expand all | Expand 10 after
1956 1950
1957 typedef struct { 1951 typedef struct {
1958 double psnr[4]; // total/y/u/v 1952 double psnr[4]; // total/y/u/v
1959 uint64_t sse[4]; // total/y/u/v 1953 uint64_t sse[4]; // total/y/u/v
1960 uint32_t samples[4]; // total/y/u/v 1954 uint32_t samples[4]; // total/y/u/v
1961 } PSNR_STATS; 1955 } PSNR_STATS;
1962 1956
1963 static void calc_psnr(const YV12_BUFFER_CONFIG *a, const YV12_BUFFER_CONFIG *b, 1957 static void calc_psnr(const YV12_BUFFER_CONFIG *a, const YV12_BUFFER_CONFIG *b,
1964 PSNR_STATS *psnr) { 1958 PSNR_STATS *psnr) {
1965 static const double peak = 255.0; 1959 static const double peak = 255.0;
1966 const int widths[3] = {a->y_width, a->uv_width, a->uv_width }; 1960 const int widths[3] = {
1967 const int heights[3] = {a->y_height, a->uv_height, a->uv_height}; 1961 a->y_crop_width, a->uv_crop_width, a->uv_crop_width};
1968 const uint8_t *a_planes[3] = {a->y_buffer, a->u_buffer, a->v_buffer }; 1962 const int heights[3] = {
1963 a->y_crop_height, a->uv_crop_height, a->uv_crop_height};
1964 const uint8_t *a_planes[3] = {a->y_buffer, a->u_buffer, a->v_buffer};
1969 const int a_strides[3] = {a->y_stride, a->uv_stride, a->uv_stride}; 1965 const int a_strides[3] = {a->y_stride, a->uv_stride, a->uv_stride};
1970 const uint8_t *b_planes[3] = {b->y_buffer, b->u_buffer, b->v_buffer }; 1966 const uint8_t *b_planes[3] = {b->y_buffer, b->u_buffer, b->v_buffer};
1971 const int b_strides[3] = {b->y_stride, b->uv_stride, b->uv_stride}; 1967 const int b_strides[3] = {b->y_stride, b->uv_stride, b->uv_stride};
1972 int i; 1968 int i;
1973 uint64_t total_sse = 0; 1969 uint64_t total_sse = 0;
1974 uint32_t total_samples = 0; 1970 uint32_t total_samples = 0;
1975 1971
1976 for (i = 0; i < 3; ++i) { 1972 for (i = 0; i < 3; ++i) {
1977 const int w = widths[i]; 1973 const int w = widths[i];
1978 const int h = heights[i]; 1974 const int h = heights[i];
1979 const uint32_t samples = w * h; 1975 const uint32_t samples = w * h;
1980 const uint64_t sse = get_sse(a_planes[i], a_strides[i], 1976 const uint64_t sse = get_sse(a_planes[i], a_strides[i],
(...skipping 12 matching lines...) Expand all
1993 psnr->psnr[0] = vpx_sse_to_psnr((double)total_samples, peak, 1989 psnr->psnr[0] = vpx_sse_to_psnr((double)total_samples, peak,
1994 (double)total_sse); 1990 (double)total_sse);
1995 } 1991 }
1996 1992
1997 #if CONFIG_VP9_HIGHBITDEPTH 1993 #if CONFIG_VP9_HIGHBITDEPTH
1998 static void calc_highbd_psnr(const YV12_BUFFER_CONFIG *a, 1994 static void calc_highbd_psnr(const YV12_BUFFER_CONFIG *a,
1999 const YV12_BUFFER_CONFIG *b, 1995 const YV12_BUFFER_CONFIG *b,
2000 PSNR_STATS *psnr, 1996 PSNR_STATS *psnr,
2001 unsigned int bit_depth, 1997 unsigned int bit_depth,
2002 unsigned int in_bit_depth) { 1998 unsigned int in_bit_depth) {
2003 const int widths[3] = {a->y_width, a->uv_width, a->uv_width }; 1999 const int widths[3] =
2004 const int heights[3] = {a->y_height, a->uv_height, a->uv_height}; 2000 {a->y_crop_width, a->uv_crop_width, a->uv_crop_width };
2001 const int heights[3] =
2002 {a->y_crop_height, a->uv_crop_height, a->uv_crop_height};
2005 const uint8_t *a_planes[3] = {a->y_buffer, a->u_buffer, a->v_buffer }; 2003 const uint8_t *a_planes[3] = {a->y_buffer, a->u_buffer, a->v_buffer };
2006 const int a_strides[3] = {a->y_stride, a->uv_stride, a->uv_stride}; 2004 const int a_strides[3] = {a->y_stride, a->uv_stride, a->uv_stride};
2007 const uint8_t *b_planes[3] = {b->y_buffer, b->u_buffer, b->v_buffer }; 2005 const uint8_t *b_planes[3] = {b->y_buffer, b->u_buffer, b->v_buffer };
2008 const int b_strides[3] = {b->y_stride, b->uv_stride, b->uv_stride}; 2006 const int b_strides[3] = {b->y_stride, b->uv_stride, b->uv_stride};
2009 int i; 2007 int i;
2010 uint64_t total_sse = 0; 2008 uint64_t total_sse = 0;
2011 uint32_t total_samples = 0; 2009 uint32_t total_samples = 0;
2012 const double peak = (double)((1 << in_bit_depth) - 1); 2010 const double peak = (double)((1 << in_bit_depth) - 1);
2013 const unsigned int input_shift = bit_depth - in_bit_depth; 2011 const unsigned int input_shift = bit_depth - in_bit_depth;
2014 2012
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
2472 lf->filter_level, 0, 0, 2470 lf->filter_level, 0, 0,
2473 cpi->workers, cpi->num_workers, 2471 cpi->workers, cpi->num_workers,
2474 &cpi->lf_row_sync); 2472 &cpi->lf_row_sync);
2475 else 2473 else
2476 vp9_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level, 0, 0); 2474 vp9_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level, 0, 0);
2477 } 2475 }
2478 2476
2479 vp9_extend_frame_inner_borders(cm->frame_to_show); 2477 vp9_extend_frame_inner_borders(cm->frame_to_show);
2480 } 2478 }
2481 2479
2480 static INLINE void alloc_frame_mvs(const VP9_COMMON *cm,
2481 int buffer_idx) {
2482 RefCntBuffer *const new_fb_ptr = &cm->buffer_pool->frame_bufs[buffer_idx];
2483 if (new_fb_ptr->mvs == NULL ||
2484 new_fb_ptr->mi_rows < cm->mi_rows ||
2485 new_fb_ptr->mi_cols < cm->mi_cols) {
2486 vpx_free(new_fb_ptr->mvs);
2487 new_fb_ptr->mvs =
2488 (MV_REF *)vpx_calloc(cm->mi_rows * cm->mi_cols,
2489 sizeof(*new_fb_ptr->mvs));
2490 new_fb_ptr->mi_rows = cm->mi_rows;
2491 new_fb_ptr->mi_cols = cm->mi_cols;
2492 }
2493 }
2494
2482 void vp9_scale_references(VP9_COMP *cpi) { 2495 void vp9_scale_references(VP9_COMP *cpi) {
2483 VP9_COMMON *cm = &cpi->common; 2496 VP9_COMMON *cm = &cpi->common;
2484 MV_REFERENCE_FRAME ref_frame; 2497 MV_REFERENCE_FRAME ref_frame;
2485 const VP9_REFFRAME ref_mask[3] = {VP9_LAST_FLAG, VP9_GOLD_FLAG, VP9_ALT_FLAG}; 2498 const VP9_REFFRAME ref_mask[3] = {VP9_LAST_FLAG, VP9_GOLD_FLAG, VP9_ALT_FLAG};
2486 2499
2487 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { 2500 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
2488 // Need to convert from VP9_REFFRAME to index into ref_mask (subtract 1). 2501 // Need to convert from VP9_REFFRAME to index into ref_mask (subtract 1).
2489 if (cpi->ref_frame_flags & ref_mask[ref_frame - 1]) { 2502 if (cpi->ref_frame_flags & ref_mask[ref_frame - 1]) {
2490 const int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)]; 2503 BufferPool *const pool = cm->buffer_pool;
2491 BufferPool *const pool = cm->buffer_pool; 2504 const YV12_BUFFER_CONFIG *const ref = get_ref_frame_buffer(cpi,
2492 const YV12_BUFFER_CONFIG *const ref = &pool->frame_bufs[idx].buf; 2505 ref_frame);
2506
2507 if (ref == NULL) {
2508 cpi->scaled_ref_idx[ref_frame - 1] = INVALID_IDX;
2509 continue;
2510 }
2493 2511
2494 #if CONFIG_VP9_HIGHBITDEPTH 2512 #if CONFIG_VP9_HIGHBITDEPTH
2495 if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) { 2513 if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) {
2496 const int new_fb = get_free_fb(cm); 2514 const int new_fb = get_free_fb(cm);
2515 RefCntBuffer *const new_fb_ptr = &pool->frame_bufs[new_fb];
2497 cm->cur_frame = &pool->frame_bufs[new_fb]; 2516 cm->cur_frame = &pool->frame_bufs[new_fb];
2498 vp9_realloc_frame_buffer(&pool->frame_bufs[new_fb].buf, 2517 vp9_realloc_frame_buffer(&pool->frame_bufs[new_fb].buf,
2499 cm->width, cm->height, 2518 cm->width, cm->height,
2500 cm->subsampling_x, cm->subsampling_y, 2519 cm->subsampling_x, cm->subsampling_y,
2501 cm->use_highbitdepth, 2520 cm->use_highbitdepth,
2502 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment, 2521 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
2503 NULL, NULL, NULL); 2522 NULL, NULL, NULL);
2504 scale_and_extend_frame(ref, &pool->frame_bufs[new_fb].buf, 2523 scale_and_extend_frame(ref, &new_fb_ptr->buf, (int)cm->bit_depth);
2505 (int)cm->bit_depth);
2506 #else 2524 #else
2507 if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) { 2525 if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) {
2508 const int new_fb = get_free_fb(cm); 2526 const int new_fb = get_free_fb(cm);
2509 vp9_realloc_frame_buffer(&pool->frame_bufs[new_fb].buf, 2527 RefCntBuffer *const new_fb_ptr = &pool->frame_bufs[new_fb];
2528 vp9_realloc_frame_buffer(&new_fb_ptr->buf,
2510 cm->width, cm->height, 2529 cm->width, cm->height,
2511 cm->subsampling_x, cm->subsampling_y, 2530 cm->subsampling_x, cm->subsampling_y,
2512 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment, 2531 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
2513 NULL, NULL, NULL); 2532 NULL, NULL, NULL);
2514 scale_and_extend_frame(ref, &pool->frame_bufs[new_fb].buf); 2533 scale_and_extend_frame(ref, &new_fb_ptr->buf);
2515 #endif // CONFIG_VP9_HIGHBITDEPTH 2534 #endif // CONFIG_VP9_HIGHBITDEPTH
2516 cpi->scaled_ref_idx[ref_frame - 1] = new_fb; 2535 cpi->scaled_ref_idx[ref_frame - 1] = new_fb;
2517 if (pool->frame_bufs[new_fb].mvs == NULL || 2536
2518 pool->frame_bufs[new_fb].mi_rows < cm->mi_rows || 2537 alloc_frame_mvs(cm, new_fb);
2519 pool->frame_bufs[new_fb].mi_cols < cm->mi_cols) {
2520 vpx_free(pool->frame_bufs[new_fb].mvs);
2521 pool->frame_bufs[new_fb].mvs =
2522 (MV_REF *)vpx_calloc(cm->mi_rows * cm->mi_cols,
2523 sizeof(*pool->frame_bufs[new_fb].mvs));
2524 pool->frame_bufs[new_fb].mi_rows = cm->mi_rows;
2525 pool->frame_bufs[new_fb].mi_cols = cm->mi_cols;
2526 }
2527 } else { 2538 } else {
2528 cpi->scaled_ref_idx[ref_frame - 1] = idx; 2539 const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame);
2529 ++pool->frame_bufs[idx].ref_count; 2540 cpi->scaled_ref_idx[ref_frame - 1] = buf_idx;
2541 ++pool->frame_bufs[buf_idx].ref_count;
2530 } 2542 }
2531 } else { 2543 } else {
2532 cpi->scaled_ref_idx[ref_frame - 1] = INVALID_REF_BUFFER_IDX; 2544 cpi->scaled_ref_idx[ref_frame - 1] = INVALID_IDX;
2533 } 2545 }
2534 } 2546 }
2535 } 2547 }
2536 2548
2537 static void release_scaled_references(VP9_COMP *cpi) { 2549 static void release_scaled_references(VP9_COMP *cpi) {
2538 VP9_COMMON *cm = &cpi->common; 2550 VP9_COMMON *cm = &cpi->common;
2539 int i; 2551 int i;
2540 for (i = 0; i < MAX_REF_FRAMES; ++i) { 2552 for (i = 0; i < MAX_REF_FRAMES; ++i) {
2541 const int idx = cpi->scaled_ref_idx[i]; 2553 const int idx = cpi->scaled_ref_idx[i];
2542 RefCntBuffer *const buf = idx != INVALID_REF_BUFFER_IDX ? 2554 RefCntBuffer *const buf = idx != INVALID_IDX ?
2543 &cm->buffer_pool->frame_bufs[idx] : NULL; 2555 &cm->buffer_pool->frame_bufs[idx] : NULL;
2544 if (buf != NULL) { 2556 if (buf != NULL) {
2545 --buf->ref_count; 2557 --buf->ref_count;
2546 cpi->scaled_ref_idx[i] = INVALID_REF_BUFFER_IDX; 2558 cpi->scaled_ref_idx[i] = INVALID_IDX;
2547 } 2559 }
2548 } 2560 }
2549 } 2561 }
2550 2562
2551 static void full_to_model_count(unsigned int *model_count, 2563 static void full_to_model_count(unsigned int *model_count,
2552 unsigned int *full_count) { 2564 unsigned int *full_count) {
2553 int n; 2565 int n;
2554 model_count[ZERO_TOKEN] = full_count[ZERO_TOKEN]; 2566 model_count[ZERO_TOKEN] = full_count[ZERO_TOKEN];
2555 model_count[ONE_TOKEN] = full_count[ONE_TOKEN]; 2567 model_count[ONE_TOKEN] = full_count[ONE_TOKEN];
2556 model_count[TWO_TOKEN] = full_count[TWO_TOKEN]; 2568 model_count[TWO_TOKEN] = full_count[TWO_TOKEN];
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
2740 oxcf->scaled_frame_height); 2752 oxcf->scaled_frame_height);
2741 } 2753 }
2742 2754
2743 if ((oxcf->pass == 2) && 2755 if ((oxcf->pass == 2) &&
2744 (!cpi->use_svc || 2756 (!cpi->use_svc ||
2745 (is_two_pass_svc(cpi) && 2757 (is_two_pass_svc(cpi) &&
2746 cpi->svc.encode_empty_frame_state != ENCODING))) { 2758 cpi->svc.encode_empty_frame_state != ENCODING))) {
2747 vp9_set_target_rate(cpi); 2759 vp9_set_target_rate(cpi);
2748 } 2760 }
2749 2761
2762 alloc_frame_mvs(cm, cm->new_fb_idx);
2763
2750 // Reset the frame pointers to the current frame size. 2764 // Reset the frame pointers to the current frame size.
2751 vp9_realloc_frame_buffer(get_frame_new_buffer(cm), 2765 vp9_realloc_frame_buffer(get_frame_new_buffer(cm),
2752 cm->width, cm->height, 2766 cm->width, cm->height,
2753 cm->subsampling_x, cm->subsampling_y, 2767 cm->subsampling_x, cm->subsampling_y,
2754 #if CONFIG_VP9_HIGHBITDEPTH 2768 #if CONFIG_VP9_HIGHBITDEPTH
2755 cm->use_highbitdepth, 2769 cm->use_highbitdepth,
2756 #endif 2770 #endif
2757 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment, 2771 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment,
2758 NULL, NULL, NULL); 2772 NULL, NULL, NULL);
2759 2773
2760 alloc_util_frame_buffers(cpi); 2774 alloc_util_frame_buffers(cpi);
2761 init_motion_estimation(cpi); 2775 init_motion_estimation(cpi);
2762 2776
2763 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { 2777 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
2764 const int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)];
2765 YV12_BUFFER_CONFIG *const buf = &cm->buffer_pool->frame_bufs[idx].buf;
2766 RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - 1]; 2778 RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - 1];
2767 ref_buf->buf = buf; 2779 const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame);
2768 ref_buf->idx = idx; 2780
2781 ref_buf->idx = buf_idx;
2782
2783 if (buf_idx != INVALID_IDX) {
2784 YV12_BUFFER_CONFIG *const buf = &cm->buffer_pool->frame_bufs[buf_idx].buf;
2785 ref_buf->buf = buf;
2769 #if CONFIG_VP9_HIGHBITDEPTH 2786 #if CONFIG_VP9_HIGHBITDEPTH
2770 vp9_setup_scale_factors_for_frame(&ref_buf->sf, 2787 vp9_setup_scale_factors_for_frame(&ref_buf->sf,
2771 buf->y_crop_width, buf->y_crop_height, 2788 buf->y_crop_width, buf->y_crop_height,
2772 cm->width, cm->height, 2789 cm->width, cm->height,
2773 (buf->flags & YV12_FLAG_HIGHBITDEPTH) ? 2790 (buf->flags & YV12_FLAG_HIGHBITDEPTH) ?
2774 1 : 0); 2791 1 : 0);
2775 #else 2792 #else
2776 vp9_setup_scale_factors_for_frame(&ref_buf->sf, 2793 vp9_setup_scale_factors_for_frame(&ref_buf->sf,
2777 buf->y_crop_width, buf->y_crop_height, 2794 buf->y_crop_width, buf->y_crop_height,
2778 cm->width, cm->height); 2795 cm->width, cm->height);
2779 #endif // CONFIG_VP9_HIGHBITDEPTH 2796 #endif // CONFIG_VP9_HIGHBITDEPTH
2780 if (vp9_is_scaled(&ref_buf->sf)) 2797 if (vp9_is_scaled(&ref_buf->sf))
2781 vp9_extend_frame_borders(buf); 2798 vp9_extend_frame_borders(buf);
2799 } else {
2800 ref_buf->buf = NULL;
2801 }
2782 } 2802 }
2783 2803
2784 set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME); 2804 set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME);
2785 } 2805 }
2786 2806
2787 static void encode_without_recode_loop(VP9_COMP *cpi) { 2807 static void encode_without_recode_loop(VP9_COMP *cpi) {
2788 VP9_COMMON *const cm = &cpi->common; 2808 VP9_COMMON *const cm = &cpi->common;
2789 int q = 0, bottom_index = 0, top_index = 0; // Dummy variables. 2809 int q = 0, bottom_index = 0, top_index = 0; // Dummy variables.
2790 2810
2791 vp9_clear_system_state(); 2811 vp9_clear_system_state();
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
3437 3457
3438 static void Pass2Encode(VP9_COMP *cpi, size_t *size, 3458 static void Pass2Encode(VP9_COMP *cpi, size_t *size,
3439 uint8_t *dest, unsigned int *frame_flags) { 3459 uint8_t *dest, unsigned int *frame_flags) {
3440 cpi->allow_encode_breakout = ENCODE_BREAKOUT_ENABLED; 3460 cpi->allow_encode_breakout = ENCODE_BREAKOUT_ENABLED;
3441 encode_frame_to_data_rate(cpi, size, dest, frame_flags); 3461 encode_frame_to_data_rate(cpi, size, dest, frame_flags);
3442 3462
3443 if (!(is_two_pass_svc(cpi) && cpi->svc.encode_empty_frame_state == ENCODING)) 3463 if (!(is_two_pass_svc(cpi) && cpi->svc.encode_empty_frame_state == ENCODING))
3444 vp9_twopass_postencode_update(cpi); 3464 vp9_twopass_postencode_update(cpi);
3445 } 3465 }
3446 3466
3467 static void init_ref_frame_bufs(VP9_COMMON *cm) {
3468 int i;
3469 BufferPool *const pool = cm->buffer_pool;
3470 cm->new_fb_idx = INVALID_IDX;
3471 for (i = 0; i < REF_FRAMES; ++i) {
3472 cm->ref_frame_map[i] = INVALID_IDX;
3473 pool->frame_bufs[i].ref_count = 0;
3474 }
3475 }
3476
3447 static void check_initial_width(VP9_COMP *cpi, 3477 static void check_initial_width(VP9_COMP *cpi,
3448 #if CONFIG_VP9_HIGHBITDEPTH 3478 #if CONFIG_VP9_HIGHBITDEPTH
3449 int use_highbitdepth, 3479 int use_highbitdepth,
3450 #endif 3480 #endif
3451 int subsampling_x, int subsampling_y) { 3481 int subsampling_x, int subsampling_y) {
3452 VP9_COMMON *const cm = &cpi->common; 3482 VP9_COMMON *const cm = &cpi->common;
3453 3483
3454 if (!cpi->initial_width) { 3484 if (!cpi->initial_width ||
3485 #if CONFIG_VP9_HIGHBITDEPTH
3486 cm->use_highbitdepth != use_highbitdepth ||
3487 #endif
3488 cm->subsampling_x != subsampling_x ||
3489 cm->subsampling_y != subsampling_y) {
3455 cm->subsampling_x = subsampling_x; 3490 cm->subsampling_x = subsampling_x;
3456 cm->subsampling_y = subsampling_y; 3491 cm->subsampling_y = subsampling_y;
3457 #if CONFIG_VP9_HIGHBITDEPTH 3492 #if CONFIG_VP9_HIGHBITDEPTH
3458 cm->use_highbitdepth = use_highbitdepth; 3493 cm->use_highbitdepth = use_highbitdepth;
3459 #endif 3494 #endif
3460 3495
3461 alloc_raw_frame_buffers(cpi); 3496 alloc_raw_frame_buffers(cpi);
3462 alloc_ref_frame_buffers(cpi); 3497 init_ref_frame_bufs(cm);
3463 alloc_util_frame_buffers(cpi); 3498 alloc_util_frame_buffers(cpi);
3464 3499
3465 init_motion_estimation(cpi); // TODO(agrange) This can be removed. 3500 init_motion_estimation(cpi); // TODO(agrange) This can be removed.
3466 3501
3467 cpi->initial_width = cm->width; 3502 cpi->initial_width = cm->width;
3468 cpi->initial_height = cm->height; 3503 cpi->initial_height = cm->height;
3469 cpi->initial_mbs = cm->MBs; 3504 cpi->initial_mbs = cm->MBs;
3470 } 3505 }
3471 } 3506 }
3472 3507
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
3777 } 3812 }
3778 3813
3779 if (cpi->svc.number_temporal_layers > 1 && 3814 if (cpi->svc.number_temporal_layers > 1 &&
3780 oxcf->rc_mode == VPX_CBR) { 3815 oxcf->rc_mode == VPX_CBR) {
3781 vp9_update_temporal_layer_framerate(cpi); 3816 vp9_update_temporal_layer_framerate(cpi);
3782 vp9_restore_layer_context(cpi); 3817 vp9_restore_layer_context(cpi);
3783 } 3818 }
3784 3819
3785 // Find a free buffer for the new frame, releasing the reference previously 3820 // Find a free buffer for the new frame, releasing the reference previously
3786 // held. 3821 // held.
3787 pool->frame_bufs[cm->new_fb_idx].ref_count--; 3822 if (cm->new_fb_idx != INVALID_IDX) {
3823 --pool->frame_bufs[cm->new_fb_idx].ref_count;
3824 }
3788 cm->new_fb_idx = get_free_fb(cm); 3825 cm->new_fb_idx = get_free_fb(cm);
3826
3827 if (cm->new_fb_idx == INVALID_IDX)
3828 return -1;
3829
3789 cm->cur_frame = &pool->frame_bufs[cm->new_fb_idx]; 3830 cm->cur_frame = &pool->frame_bufs[cm->new_fb_idx];
3790 3831
3791 if (!cpi->use_svc && cpi->multi_arf_allowed) { 3832 if (!cpi->use_svc && cpi->multi_arf_allowed) {
3792 if (cm->frame_type == KEY_FRAME) { 3833 if (cm->frame_type == KEY_FRAME) {
3793 init_buffer_indices(cpi); 3834 init_buffer_indices(cpi);
3794 } else if (oxcf->pass == 2) { 3835 } else if (oxcf->pass == 2) {
3795 const GF_GROUP *const gf_group = &cpi->twopass.gf_group; 3836 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
3796 cpi->alt_fb_idx = gf_group->arf_ref_idx[gf_group->index]; 3837 cpi->alt_fb_idx = gf_group->arf_ref_idx[gf_group->index];
3797 } 3838 }
3798 } 3839 }
3799 3840
3800 // Start with a 0 size frame. 3841 // Start with a 0 size frame.
3801 *size = 0; 3842 *size = 0;
3802 3843
3803 cpi->frame_flags = *frame_flags; 3844 cpi->frame_flags = *frame_flags;
3804 3845
3805 if ((oxcf->pass == 2) && 3846 if ((oxcf->pass == 2) &&
3806 (!cpi->use_svc || 3847 (!cpi->use_svc ||
3807 (is_two_pass_svc(cpi) && 3848 (is_two_pass_svc(cpi) &&
3808 cpi->svc.encode_empty_frame_state != ENCODING))) { 3849 cpi->svc.encode_empty_frame_state != ENCODING))) {
3809 vp9_rc_get_second_pass_params(cpi); 3850 vp9_rc_get_second_pass_params(cpi);
3810 } else { 3851 } else {
3811 set_frame_size(cpi); 3852 set_frame_size(cpi);
3812 } 3853 }
3813 3854
3814 for (i = 0; i < MAX_REF_FRAMES; ++i) 3855 for (i = 0; i < MAX_REF_FRAMES; ++i)
3815 cpi->scaled_ref_idx[i] = INVALID_REF_BUFFER_IDX; 3856 cpi->scaled_ref_idx[i] = INVALID_IDX;
3816 3857
3817 if (oxcf->pass == 1 && 3858 if (oxcf->pass == 1 &&
3818 (!cpi->use_svc || is_two_pass_svc(cpi))) { 3859 (!cpi->use_svc || is_two_pass_svc(cpi))) {
3819 const int lossless = is_lossless_requested(oxcf); 3860 const int lossless = is_lossless_requested(oxcf);
3820 #if CONFIG_VP9_HIGHBITDEPTH 3861 #if CONFIG_VP9_HIGHBITDEPTH
3821 if (cpi->oxcf.use_highbitdepth) 3862 if (cpi->oxcf.use_highbitdepth)
3822 cpi->td.mb.fwd_txm4x4 = lossless ? 3863 cpi->td.mb.fwd_txm4x4 = lossless ?
3823 vp9_highbd_fwht4x4 : vp9_highbd_fdct4x4; 3864 vp9_highbd_fwht4x4 : vp9_highbd_fdct4x4;
3824 else 3865 else
3825 cpi->td.mb.fwd_txm4x4 = lossless ? vp9_fwht4x4 : vp9_fdct4x4; 3866 cpi->td.mb.fwd_txm4x4 = lossless ? vp9_fwht4x4 : vp9_fdct4x4;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
3891 cpi->total_y += psnr.psnr[1]; 3932 cpi->total_y += psnr.psnr[1];
3892 cpi->total_u += psnr.psnr[2]; 3933 cpi->total_u += psnr.psnr[2];
3893 cpi->total_v += psnr.psnr[3]; 3934 cpi->total_v += psnr.psnr[3];
3894 cpi->total_sq_error += psnr.sse[0]; 3935 cpi->total_sq_error += psnr.sse[0];
3895 cpi->total_samples += psnr.samples[0]; 3936 cpi->total_samples += psnr.samples[0];
3896 3937
3897 { 3938 {
3898 PSNR_STATS psnr2; 3939 PSNR_STATS psnr2;
3899 double frame_ssim2 = 0, weight = 0; 3940 double frame_ssim2 = 0, weight = 0;
3900 #if CONFIG_VP9_POSTPROC 3941 #if CONFIG_VP9_POSTPROC
3901 // TODO(agrange) Add resizing of post-proc buffer in here when the 3942 if (vp9_alloc_frame_buffer(&cm->post_proc_buffer,
3902 // encoder is changed to use on-demand buffer allocation. 3943 recon->y_crop_width, recon->y_crop_height,
3944 cm->subsampling_x, cm->subsampling_y,
3945 #if CONFIG_VP9_HIGHBITDEPTH
3946 cm->use_highbitdepth,
3947 #endif
3948 VP9_ENC_BORDER_IN_PIXELS,
3949 cm->byte_alignment) < 0) {
3950 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
3951 "Failed to allocate post processing buffer");
3952 }
3953
3903 vp9_deblock(cm->frame_to_show, &cm->post_proc_buffer, 3954 vp9_deblock(cm->frame_to_show, &cm->post_proc_buffer,
3904 cm->lf.filter_level * 10 / 6); 3955 cm->lf.filter_level * 10 / 6);
3905 #endif 3956 #endif
3906 vp9_clear_system_state(); 3957 vp9_clear_system_state();
3907 3958
3908 #if CONFIG_VP9_HIGHBITDEPTH 3959 #if CONFIG_VP9_HIGHBITDEPTH
3909 calc_highbd_psnr(orig, pp, &psnr, cpi->td.mb.e_mbd.bd, 3960 calc_highbd_psnr(orig, pp, &psnr, cpi->td.mb.e_mbd.bd,
3910 cpi->oxcf.input_bit_depth); 3961 cpi->oxcf.input_bit_depth);
3911 #else 3962 #else
3912 calc_psnr(orig, pp, &psnr2); 3963 calc_psnr(orig, pp, &psnr2);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
4070 4121
4071 update_frame_size(cpi); 4122 update_frame_size(cpi);
4072 4123
4073 return 0; 4124 return 0;
4074 } 4125 }
4075 4126
4076 int vp9_set_size_literal(VP9_COMP *cpi, unsigned int width, 4127 int vp9_set_size_literal(VP9_COMP *cpi, unsigned int width,
4077 unsigned int height) { 4128 unsigned int height) {
4078 VP9_COMMON *cm = &cpi->common; 4129 VP9_COMMON *cm = &cpi->common;
4079 #if CONFIG_VP9_HIGHBITDEPTH 4130 #if CONFIG_VP9_HIGHBITDEPTH
4080 check_initial_width(cpi, 1, 1, cm->use_highbitdepth); 4131 check_initial_width(cpi, cm->use_highbitdepth, 1, 1);
4081 #else 4132 #else
4082 check_initial_width(cpi, 1, 1); 4133 check_initial_width(cpi, 1, 1);
4083 #endif // CONFIG_VP9_HIGHBITDEPTH 4134 #endif // CONFIG_VP9_HIGHBITDEPTH
4084 4135
4085 #if CONFIG_VP9_TEMPORAL_DENOISING 4136 #if CONFIG_VP9_TEMPORAL_DENOISING
4086 setup_denoiser_buffer(cpi); 4137 setup_denoiser_buffer(cpi);
4087 #endif 4138 #endif
4088 4139
4089 if (width) { 4140 if (width) {
4090 cm->width = width; 4141 cm->width = width;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
4171 if (flags & VP8_EFLAG_NO_UPD_ARF) 4222 if (flags & VP8_EFLAG_NO_UPD_ARF)
4172 upd ^= VP9_ALT_FLAG; 4223 upd ^= VP9_ALT_FLAG;
4173 4224
4174 vp9_update_reference(cpi, upd); 4225 vp9_update_reference(cpi, upd);
4175 } 4226 }
4176 4227
4177 if (flags & VP8_EFLAG_NO_UPD_ENTROPY) { 4228 if (flags & VP8_EFLAG_NO_UPD_ENTROPY) {
4178 vp9_update_entropy(cpi, 0); 4229 vp9_update_entropy(cpi, 0);
4179 } 4230 }
4180 } 4231 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_encoder.h ('k') | source/libvpx/vp9/encoder/vp9_ethread.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698