michael@0: /* michael@0: * Copyright (c) 2010 The WebM project authors. All Rights Reserved. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license michael@0: * that can be found in the LICENSE file in the root of the source michael@0: * tree. An additional intellectual property rights grant can be found michael@0: * in the file PATENTS. All contributing project authors may michael@0: * be found in the AUTHORS file in the root of the source tree. michael@0: */ michael@0: michael@0: michael@0: #include "vpx_config.h" michael@0: #include "blockd.h" michael@0: #include "vpx_mem/vpx_mem.h" michael@0: #include "onyxc_int.h" michael@0: #include "findnearmv.h" michael@0: #include "entropymode.h" michael@0: #include "systemdependent.h" michael@0: michael@0: void vp8_de_alloc_frame_buffers(VP8_COMMON *oci) michael@0: { michael@0: int i; michael@0: for (i = 0; i < NUM_YV12_BUFFERS; i++) michael@0: vp8_yv12_de_alloc_frame_buffer(&oci->yv12_fb[i]); michael@0: michael@0: vp8_yv12_de_alloc_frame_buffer(&oci->temp_scale_frame); michael@0: #if CONFIG_POSTPROC michael@0: vp8_yv12_de_alloc_frame_buffer(&oci->post_proc_buffer); michael@0: if (oci->post_proc_buffer_int_used) michael@0: vp8_yv12_de_alloc_frame_buffer(&oci->post_proc_buffer_int); michael@0: michael@0: vpx_free(oci->pp_limits_buffer); michael@0: oci->pp_limits_buffer = NULL; michael@0: #endif michael@0: michael@0: vpx_free(oci->above_context); michael@0: vpx_free(oci->mip); michael@0: #if CONFIG_ERROR_CONCEALMENT michael@0: vpx_free(oci->prev_mip); michael@0: oci->prev_mip = NULL; michael@0: #endif michael@0: michael@0: oci->above_context = NULL; michael@0: oci->mip = NULL; michael@0: } michael@0: michael@0: int vp8_alloc_frame_buffers(VP8_COMMON *oci, int width, int height) michael@0: { michael@0: int i; michael@0: michael@0: vp8_de_alloc_frame_buffers(oci); michael@0: michael@0: /* our internal buffers are always multiples of 16 */ michael@0: if ((width & 0xf) != 0) michael@0: width += 16 - (width & 0xf); michael@0: michael@0: if ((height & 0xf) != 0) michael@0: height += 16 - (height & 0xf); michael@0: michael@0: michael@0: for (i = 0; i < NUM_YV12_BUFFERS; i++) michael@0: { michael@0: oci->fb_idx_ref_cnt[i] = 0; michael@0: oci->yv12_fb[i].flags = 0; michael@0: if (vp8_yv12_alloc_frame_buffer(&oci->yv12_fb[i], width, height, VP8BORDERINPIXELS) < 0) michael@0: goto allocation_fail; michael@0: } michael@0: michael@0: oci->new_fb_idx = 0; michael@0: oci->lst_fb_idx = 1; michael@0: oci->gld_fb_idx = 2; michael@0: oci->alt_fb_idx = 3; michael@0: michael@0: oci->fb_idx_ref_cnt[0] = 1; michael@0: oci->fb_idx_ref_cnt[1] = 1; michael@0: oci->fb_idx_ref_cnt[2] = 1; michael@0: oci->fb_idx_ref_cnt[3] = 1; michael@0: michael@0: if (vp8_yv12_alloc_frame_buffer(&oci->temp_scale_frame, width, 16, VP8BORDERINPIXELS) < 0) michael@0: goto allocation_fail; michael@0: michael@0: oci->mb_rows = height >> 4; michael@0: oci->mb_cols = width >> 4; michael@0: oci->MBs = oci->mb_rows * oci->mb_cols; michael@0: oci->mode_info_stride = oci->mb_cols + 1; michael@0: oci->mip = vpx_calloc((oci->mb_cols + 1) * (oci->mb_rows + 1), sizeof(MODE_INFO)); michael@0: michael@0: if (!oci->mip) michael@0: goto allocation_fail; michael@0: michael@0: oci->mi = oci->mip + oci->mode_info_stride + 1; michael@0: michael@0: /* Allocation of previous mode info will be done in vp8_decode_frame() michael@0: * as it is a decoder only data */ michael@0: michael@0: oci->above_context = vpx_calloc(sizeof(ENTROPY_CONTEXT_PLANES) * oci->mb_cols, 1); michael@0: michael@0: if (!oci->above_context) michael@0: goto allocation_fail; michael@0: michael@0: #if CONFIG_POSTPROC michael@0: if (vp8_yv12_alloc_frame_buffer(&oci->post_proc_buffer, width, height, VP8BORDERINPIXELS) < 0) michael@0: goto allocation_fail; michael@0: michael@0: oci->post_proc_buffer_int_used = 0; michael@0: vpx_memset(&oci->postproc_state, 0, sizeof(oci->postproc_state)); michael@0: vpx_memset(oci->post_proc_buffer.buffer_alloc, 128, michael@0: oci->post_proc_buffer.frame_size); michael@0: michael@0: /* Allocate buffer to store post-processing filter coefficients. michael@0: * michael@0: * Note: Round up mb_cols to support SIMD reads michael@0: */ michael@0: oci->pp_limits_buffer = vpx_memalign(16, 24 * ((oci->mb_cols + 1) & ~1)); michael@0: if (!oci->pp_limits_buffer) michael@0: goto allocation_fail; michael@0: #endif michael@0: michael@0: return 0; michael@0: michael@0: allocation_fail: michael@0: vp8_de_alloc_frame_buffers(oci); michael@0: return 1; michael@0: } michael@0: michael@0: void vp8_setup_version(VP8_COMMON *cm) michael@0: { michael@0: switch (cm->version) michael@0: { michael@0: case 0: michael@0: cm->no_lpf = 0; michael@0: cm->filter_type = NORMAL_LOOPFILTER; michael@0: cm->use_bilinear_mc_filter = 0; michael@0: cm->full_pixel = 0; michael@0: break; michael@0: case 1: michael@0: cm->no_lpf = 0; michael@0: cm->filter_type = SIMPLE_LOOPFILTER; michael@0: cm->use_bilinear_mc_filter = 1; michael@0: cm->full_pixel = 0; michael@0: break; michael@0: case 2: michael@0: cm->no_lpf = 1; michael@0: cm->filter_type = NORMAL_LOOPFILTER; michael@0: cm->use_bilinear_mc_filter = 1; michael@0: cm->full_pixel = 0; michael@0: break; michael@0: case 3: michael@0: cm->no_lpf = 1; michael@0: cm->filter_type = SIMPLE_LOOPFILTER; michael@0: cm->use_bilinear_mc_filter = 1; michael@0: cm->full_pixel = 1; michael@0: break; michael@0: default: michael@0: /*4,5,6,7 are reserved for future use*/ michael@0: cm->no_lpf = 0; michael@0: cm->filter_type = NORMAL_LOOPFILTER; michael@0: cm->use_bilinear_mc_filter = 0; michael@0: cm->full_pixel = 0; michael@0: break; michael@0: } michael@0: } michael@0: void vp8_create_common(VP8_COMMON *oci) michael@0: { michael@0: vp8_machine_specific_config(oci); michael@0: michael@0: vp8_init_mbmode_probs(oci); michael@0: vp8_default_bmode_probs(oci->fc.bmode_prob); michael@0: michael@0: oci->mb_no_coeff_skip = 1; michael@0: oci->no_lpf = 0; michael@0: oci->filter_type = NORMAL_LOOPFILTER; michael@0: oci->use_bilinear_mc_filter = 0; michael@0: oci->full_pixel = 0; michael@0: oci->multi_token_partition = ONE_PARTITION; michael@0: oci->clamp_type = RECON_CLAMP_REQUIRED; michael@0: michael@0: /* Initialize reference frame sign bias structure to defaults */ michael@0: vpx_memset(oci->ref_frame_sign_bias, 0, sizeof(oci->ref_frame_sign_bias)); michael@0: michael@0: /* Default disable buffer to buffer copying */ michael@0: oci->copy_buffer_to_gf = 0; michael@0: oci->copy_buffer_to_arf = 0; michael@0: } michael@0: michael@0: void vp8_remove_common(VP8_COMMON *oci) michael@0: { michael@0: vp8_de_alloc_frame_buffers(oci); michael@0: }