media/libvpx/vp8/common/alloccommon.c

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /*
michael@0 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license
michael@0 5 * that can be found in the LICENSE file in the root of the source
michael@0 6 * tree. An additional intellectual property rights grant can be found
michael@0 7 * in the file PATENTS. All contributing project authors may
michael@0 8 * be found in the AUTHORS file in the root of the source tree.
michael@0 9 */
michael@0 10
michael@0 11
michael@0 12 #include "vpx_config.h"
michael@0 13 #include "blockd.h"
michael@0 14 #include "vpx_mem/vpx_mem.h"
michael@0 15 #include "onyxc_int.h"
michael@0 16 #include "findnearmv.h"
michael@0 17 #include "entropymode.h"
michael@0 18 #include "systemdependent.h"
michael@0 19
michael@0 20 void vp8_de_alloc_frame_buffers(VP8_COMMON *oci)
michael@0 21 {
michael@0 22 int i;
michael@0 23 for (i = 0; i < NUM_YV12_BUFFERS; i++)
michael@0 24 vp8_yv12_de_alloc_frame_buffer(&oci->yv12_fb[i]);
michael@0 25
michael@0 26 vp8_yv12_de_alloc_frame_buffer(&oci->temp_scale_frame);
michael@0 27 #if CONFIG_POSTPROC
michael@0 28 vp8_yv12_de_alloc_frame_buffer(&oci->post_proc_buffer);
michael@0 29 if (oci->post_proc_buffer_int_used)
michael@0 30 vp8_yv12_de_alloc_frame_buffer(&oci->post_proc_buffer_int);
michael@0 31
michael@0 32 vpx_free(oci->pp_limits_buffer);
michael@0 33 oci->pp_limits_buffer = NULL;
michael@0 34 #endif
michael@0 35
michael@0 36 vpx_free(oci->above_context);
michael@0 37 vpx_free(oci->mip);
michael@0 38 #if CONFIG_ERROR_CONCEALMENT
michael@0 39 vpx_free(oci->prev_mip);
michael@0 40 oci->prev_mip = NULL;
michael@0 41 #endif
michael@0 42
michael@0 43 oci->above_context = NULL;
michael@0 44 oci->mip = NULL;
michael@0 45 }
michael@0 46
michael@0 47 int vp8_alloc_frame_buffers(VP8_COMMON *oci, int width, int height)
michael@0 48 {
michael@0 49 int i;
michael@0 50
michael@0 51 vp8_de_alloc_frame_buffers(oci);
michael@0 52
michael@0 53 /* our internal buffers are always multiples of 16 */
michael@0 54 if ((width & 0xf) != 0)
michael@0 55 width += 16 - (width & 0xf);
michael@0 56
michael@0 57 if ((height & 0xf) != 0)
michael@0 58 height += 16 - (height & 0xf);
michael@0 59
michael@0 60
michael@0 61 for (i = 0; i < NUM_YV12_BUFFERS; i++)
michael@0 62 {
michael@0 63 oci->fb_idx_ref_cnt[i] = 0;
michael@0 64 oci->yv12_fb[i].flags = 0;
michael@0 65 if (vp8_yv12_alloc_frame_buffer(&oci->yv12_fb[i], width, height, VP8BORDERINPIXELS) < 0)
michael@0 66 goto allocation_fail;
michael@0 67 }
michael@0 68
michael@0 69 oci->new_fb_idx = 0;
michael@0 70 oci->lst_fb_idx = 1;
michael@0 71 oci->gld_fb_idx = 2;
michael@0 72 oci->alt_fb_idx = 3;
michael@0 73
michael@0 74 oci->fb_idx_ref_cnt[0] = 1;
michael@0 75 oci->fb_idx_ref_cnt[1] = 1;
michael@0 76 oci->fb_idx_ref_cnt[2] = 1;
michael@0 77 oci->fb_idx_ref_cnt[3] = 1;
michael@0 78
michael@0 79 if (vp8_yv12_alloc_frame_buffer(&oci->temp_scale_frame, width, 16, VP8BORDERINPIXELS) < 0)
michael@0 80 goto allocation_fail;
michael@0 81
michael@0 82 oci->mb_rows = height >> 4;
michael@0 83 oci->mb_cols = width >> 4;
michael@0 84 oci->MBs = oci->mb_rows * oci->mb_cols;
michael@0 85 oci->mode_info_stride = oci->mb_cols + 1;
michael@0 86 oci->mip = vpx_calloc((oci->mb_cols + 1) * (oci->mb_rows + 1), sizeof(MODE_INFO));
michael@0 87
michael@0 88 if (!oci->mip)
michael@0 89 goto allocation_fail;
michael@0 90
michael@0 91 oci->mi = oci->mip + oci->mode_info_stride + 1;
michael@0 92
michael@0 93 /* Allocation of previous mode info will be done in vp8_decode_frame()
michael@0 94 * as it is a decoder only data */
michael@0 95
michael@0 96 oci->above_context = vpx_calloc(sizeof(ENTROPY_CONTEXT_PLANES) * oci->mb_cols, 1);
michael@0 97
michael@0 98 if (!oci->above_context)
michael@0 99 goto allocation_fail;
michael@0 100
michael@0 101 #if CONFIG_POSTPROC
michael@0 102 if (vp8_yv12_alloc_frame_buffer(&oci->post_proc_buffer, width, height, VP8BORDERINPIXELS) < 0)
michael@0 103 goto allocation_fail;
michael@0 104
michael@0 105 oci->post_proc_buffer_int_used = 0;
michael@0 106 vpx_memset(&oci->postproc_state, 0, sizeof(oci->postproc_state));
michael@0 107 vpx_memset(oci->post_proc_buffer.buffer_alloc, 128,
michael@0 108 oci->post_proc_buffer.frame_size);
michael@0 109
michael@0 110 /* Allocate buffer to store post-processing filter coefficients.
michael@0 111 *
michael@0 112 * Note: Round up mb_cols to support SIMD reads
michael@0 113 */
michael@0 114 oci->pp_limits_buffer = vpx_memalign(16, 24 * ((oci->mb_cols + 1) & ~1));
michael@0 115 if (!oci->pp_limits_buffer)
michael@0 116 goto allocation_fail;
michael@0 117 #endif
michael@0 118
michael@0 119 return 0;
michael@0 120
michael@0 121 allocation_fail:
michael@0 122 vp8_de_alloc_frame_buffers(oci);
michael@0 123 return 1;
michael@0 124 }
michael@0 125
michael@0 126 void vp8_setup_version(VP8_COMMON *cm)
michael@0 127 {
michael@0 128 switch (cm->version)
michael@0 129 {
michael@0 130 case 0:
michael@0 131 cm->no_lpf = 0;
michael@0 132 cm->filter_type = NORMAL_LOOPFILTER;
michael@0 133 cm->use_bilinear_mc_filter = 0;
michael@0 134 cm->full_pixel = 0;
michael@0 135 break;
michael@0 136 case 1:
michael@0 137 cm->no_lpf = 0;
michael@0 138 cm->filter_type = SIMPLE_LOOPFILTER;
michael@0 139 cm->use_bilinear_mc_filter = 1;
michael@0 140 cm->full_pixel = 0;
michael@0 141 break;
michael@0 142 case 2:
michael@0 143 cm->no_lpf = 1;
michael@0 144 cm->filter_type = NORMAL_LOOPFILTER;
michael@0 145 cm->use_bilinear_mc_filter = 1;
michael@0 146 cm->full_pixel = 0;
michael@0 147 break;
michael@0 148 case 3:
michael@0 149 cm->no_lpf = 1;
michael@0 150 cm->filter_type = SIMPLE_LOOPFILTER;
michael@0 151 cm->use_bilinear_mc_filter = 1;
michael@0 152 cm->full_pixel = 1;
michael@0 153 break;
michael@0 154 default:
michael@0 155 /*4,5,6,7 are reserved for future use*/
michael@0 156 cm->no_lpf = 0;
michael@0 157 cm->filter_type = NORMAL_LOOPFILTER;
michael@0 158 cm->use_bilinear_mc_filter = 0;
michael@0 159 cm->full_pixel = 0;
michael@0 160 break;
michael@0 161 }
michael@0 162 }
michael@0 163 void vp8_create_common(VP8_COMMON *oci)
michael@0 164 {
michael@0 165 vp8_machine_specific_config(oci);
michael@0 166
michael@0 167 vp8_init_mbmode_probs(oci);
michael@0 168 vp8_default_bmode_probs(oci->fc.bmode_prob);
michael@0 169
michael@0 170 oci->mb_no_coeff_skip = 1;
michael@0 171 oci->no_lpf = 0;
michael@0 172 oci->filter_type = NORMAL_LOOPFILTER;
michael@0 173 oci->use_bilinear_mc_filter = 0;
michael@0 174 oci->full_pixel = 0;
michael@0 175 oci->multi_token_partition = ONE_PARTITION;
michael@0 176 oci->clamp_type = RECON_CLAMP_REQUIRED;
michael@0 177
michael@0 178 /* Initialize reference frame sign bias structure to defaults */
michael@0 179 vpx_memset(oci->ref_frame_sign_bias, 0, sizeof(oci->ref_frame_sign_bias));
michael@0 180
michael@0 181 /* Default disable buffer to buffer copying */
michael@0 182 oci->copy_buffer_to_gf = 0;
michael@0 183 oci->copy_buffer_to_arf = 0;
michael@0 184 }
michael@0 185
michael@0 186 void vp8_remove_common(VP8_COMMON *oci)
michael@0 187 {
michael@0 188 vp8_de_alloc_frame_buffers(oci);
michael@0 189 }

mercurial