media/libvpx/vp8/common/alloccommon.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/libvpx/vp8/common/alloccommon.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,189 @@
     1.4 +/*
     1.5 + *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
     1.6 + *
     1.7 + *  Use of this source code is governed by a BSD-style license
     1.8 + *  that can be found in the LICENSE file in the root of the source
     1.9 + *  tree. An additional intellectual property rights grant can be found
    1.10 + *  in the file PATENTS.  All contributing project authors may
    1.11 + *  be found in the AUTHORS file in the root of the source tree.
    1.12 + */
    1.13 +
    1.14 +
    1.15 +#include "vpx_config.h"
    1.16 +#include "blockd.h"
    1.17 +#include "vpx_mem/vpx_mem.h"
    1.18 +#include "onyxc_int.h"
    1.19 +#include "findnearmv.h"
    1.20 +#include "entropymode.h"
    1.21 +#include "systemdependent.h"
    1.22 +
    1.23 +void vp8_de_alloc_frame_buffers(VP8_COMMON *oci)
    1.24 +{
    1.25 +    int i;
    1.26 +    for (i = 0; i < NUM_YV12_BUFFERS; i++)
    1.27 +        vp8_yv12_de_alloc_frame_buffer(&oci->yv12_fb[i]);
    1.28 +
    1.29 +    vp8_yv12_de_alloc_frame_buffer(&oci->temp_scale_frame);
    1.30 +#if CONFIG_POSTPROC
    1.31 +    vp8_yv12_de_alloc_frame_buffer(&oci->post_proc_buffer);
    1.32 +    if (oci->post_proc_buffer_int_used)
    1.33 +        vp8_yv12_de_alloc_frame_buffer(&oci->post_proc_buffer_int);
    1.34 +
    1.35 +    vpx_free(oci->pp_limits_buffer);
    1.36 +    oci->pp_limits_buffer = NULL;
    1.37 +#endif
    1.38 +
    1.39 +    vpx_free(oci->above_context);
    1.40 +    vpx_free(oci->mip);
    1.41 +#if CONFIG_ERROR_CONCEALMENT
    1.42 +    vpx_free(oci->prev_mip);
    1.43 +    oci->prev_mip = NULL;
    1.44 +#endif
    1.45 +
    1.46 +    oci->above_context = NULL;
    1.47 +    oci->mip = NULL;
    1.48 +}
    1.49 +
    1.50 +int vp8_alloc_frame_buffers(VP8_COMMON *oci, int width, int height)
    1.51 +{
    1.52 +    int i;
    1.53 +
    1.54 +    vp8_de_alloc_frame_buffers(oci);
    1.55 +
    1.56 +    /* our internal buffers are always multiples of 16 */
    1.57 +    if ((width & 0xf) != 0)
    1.58 +        width += 16 - (width & 0xf);
    1.59 +
    1.60 +    if ((height & 0xf) != 0)
    1.61 +        height += 16 - (height & 0xf);
    1.62 +
    1.63 +
    1.64 +    for (i = 0; i < NUM_YV12_BUFFERS; i++)
    1.65 +    {
    1.66 +        oci->fb_idx_ref_cnt[i] = 0;
    1.67 +        oci->yv12_fb[i].flags = 0;
    1.68 +        if (vp8_yv12_alloc_frame_buffer(&oci->yv12_fb[i], width, height, VP8BORDERINPIXELS) < 0)
    1.69 +            goto allocation_fail;
    1.70 +    }
    1.71 +
    1.72 +    oci->new_fb_idx = 0;
    1.73 +    oci->lst_fb_idx = 1;
    1.74 +    oci->gld_fb_idx = 2;
    1.75 +    oci->alt_fb_idx = 3;
    1.76 +
    1.77 +    oci->fb_idx_ref_cnt[0] = 1;
    1.78 +    oci->fb_idx_ref_cnt[1] = 1;
    1.79 +    oci->fb_idx_ref_cnt[2] = 1;
    1.80 +    oci->fb_idx_ref_cnt[3] = 1;
    1.81 +
    1.82 +    if (vp8_yv12_alloc_frame_buffer(&oci->temp_scale_frame,   width, 16, VP8BORDERINPIXELS) < 0)
    1.83 +        goto allocation_fail;
    1.84 +
    1.85 +    oci->mb_rows = height >> 4;
    1.86 +    oci->mb_cols = width >> 4;
    1.87 +    oci->MBs = oci->mb_rows * oci->mb_cols;
    1.88 +    oci->mode_info_stride = oci->mb_cols + 1;
    1.89 +    oci->mip = vpx_calloc((oci->mb_cols + 1) * (oci->mb_rows + 1), sizeof(MODE_INFO));
    1.90 +
    1.91 +    if (!oci->mip)
    1.92 +        goto allocation_fail;
    1.93 +
    1.94 +    oci->mi = oci->mip + oci->mode_info_stride + 1;
    1.95 +
    1.96 +    /* Allocation of previous mode info will be done in vp8_decode_frame()
    1.97 +     * as it is a decoder only data */
    1.98 +
    1.99 +    oci->above_context = vpx_calloc(sizeof(ENTROPY_CONTEXT_PLANES) * oci->mb_cols, 1);
   1.100 +
   1.101 +    if (!oci->above_context)
   1.102 +        goto allocation_fail;
   1.103 +
   1.104 +#if CONFIG_POSTPROC
   1.105 +    if (vp8_yv12_alloc_frame_buffer(&oci->post_proc_buffer, width, height, VP8BORDERINPIXELS) < 0)
   1.106 +        goto allocation_fail;
   1.107 +
   1.108 +    oci->post_proc_buffer_int_used = 0;
   1.109 +    vpx_memset(&oci->postproc_state, 0, sizeof(oci->postproc_state));
   1.110 +    vpx_memset(oci->post_proc_buffer.buffer_alloc, 128,
   1.111 +               oci->post_proc_buffer.frame_size);
   1.112 +
   1.113 +    /* Allocate buffer to store post-processing filter coefficients.
   1.114 +     *
   1.115 +     * Note: Round up mb_cols to support SIMD reads
   1.116 +     */
   1.117 +    oci->pp_limits_buffer = vpx_memalign(16, 24 * ((oci->mb_cols + 1) & ~1));
   1.118 +    if (!oci->pp_limits_buffer)
   1.119 +        goto allocation_fail;
   1.120 +#endif
   1.121 +
   1.122 +    return 0;
   1.123 +
   1.124 +allocation_fail:
   1.125 +    vp8_de_alloc_frame_buffers(oci);
   1.126 +    return 1;
   1.127 +}
   1.128 +
   1.129 +void vp8_setup_version(VP8_COMMON *cm)
   1.130 +{
   1.131 +    switch (cm->version)
   1.132 +    {
   1.133 +    case 0:
   1.134 +        cm->no_lpf = 0;
   1.135 +        cm->filter_type = NORMAL_LOOPFILTER;
   1.136 +        cm->use_bilinear_mc_filter = 0;
   1.137 +        cm->full_pixel = 0;
   1.138 +        break;
   1.139 +    case 1:
   1.140 +        cm->no_lpf = 0;
   1.141 +        cm->filter_type = SIMPLE_LOOPFILTER;
   1.142 +        cm->use_bilinear_mc_filter = 1;
   1.143 +        cm->full_pixel = 0;
   1.144 +        break;
   1.145 +    case 2:
   1.146 +        cm->no_lpf = 1;
   1.147 +        cm->filter_type = NORMAL_LOOPFILTER;
   1.148 +        cm->use_bilinear_mc_filter = 1;
   1.149 +        cm->full_pixel = 0;
   1.150 +        break;
   1.151 +    case 3:
   1.152 +        cm->no_lpf = 1;
   1.153 +        cm->filter_type = SIMPLE_LOOPFILTER;
   1.154 +        cm->use_bilinear_mc_filter = 1;
   1.155 +        cm->full_pixel = 1;
   1.156 +        break;
   1.157 +    default:
   1.158 +        /*4,5,6,7 are reserved for future use*/
   1.159 +        cm->no_lpf = 0;
   1.160 +        cm->filter_type = NORMAL_LOOPFILTER;
   1.161 +        cm->use_bilinear_mc_filter = 0;
   1.162 +        cm->full_pixel = 0;
   1.163 +        break;
   1.164 +    }
   1.165 +}
   1.166 +void vp8_create_common(VP8_COMMON *oci)
   1.167 +{
   1.168 +    vp8_machine_specific_config(oci);
   1.169 +
   1.170 +    vp8_init_mbmode_probs(oci);
   1.171 +    vp8_default_bmode_probs(oci->fc.bmode_prob);
   1.172 +
   1.173 +    oci->mb_no_coeff_skip = 1;
   1.174 +    oci->no_lpf = 0;
   1.175 +    oci->filter_type = NORMAL_LOOPFILTER;
   1.176 +    oci->use_bilinear_mc_filter = 0;
   1.177 +    oci->full_pixel = 0;
   1.178 +    oci->multi_token_partition = ONE_PARTITION;
   1.179 +    oci->clamp_type = RECON_CLAMP_REQUIRED;
   1.180 +
   1.181 +    /* Initialize reference frame sign bias structure to defaults */
   1.182 +    vpx_memset(oci->ref_frame_sign_bias, 0, sizeof(oci->ref_frame_sign_bias));
   1.183 +
   1.184 +    /* Default disable buffer to buffer copying */
   1.185 +    oci->copy_buffer_to_gf = 0;
   1.186 +    oci->copy_buffer_to_arf = 0;
   1.187 +}
   1.188 +
   1.189 +void vp8_remove_common(VP8_COMMON *oci)
   1.190 +{
   1.191 +    vp8_de_alloc_frame_buffers(oci);
   1.192 +}

mercurial