Thu, 15 Jan 2015 15:59:08 +0100
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 "vp8/common/blockd.h" |
michael@0 | 13 | #include "onyxd_int.h" |
michael@0 | 14 | #include "vpx_mem/vpx_mem.h" |
michael@0 | 15 | #include "vpx_ports/mem.h" |
michael@0 | 16 | #include "detokenize.h" |
michael@0 | 17 | |
michael@0 | 18 | void vp8_reset_mb_tokens_context(MACROBLOCKD *x) |
michael@0 | 19 | { |
michael@0 | 20 | ENTROPY_CONTEXT *a_ctx = ((ENTROPY_CONTEXT *)x->above_context); |
michael@0 | 21 | ENTROPY_CONTEXT *l_ctx = ((ENTROPY_CONTEXT *)x->left_context); |
michael@0 | 22 | |
michael@0 | 23 | vpx_memset(a_ctx, 0, sizeof(ENTROPY_CONTEXT_PLANES)-1); |
michael@0 | 24 | vpx_memset(l_ctx, 0, sizeof(ENTROPY_CONTEXT_PLANES)-1); |
michael@0 | 25 | |
michael@0 | 26 | /* Clear entropy contexts for Y2 blocks */ |
michael@0 | 27 | if (!x->mode_info_context->mbmi.is_4x4) |
michael@0 | 28 | { |
michael@0 | 29 | a_ctx[8] = l_ctx[8] = 0; |
michael@0 | 30 | } |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | /* |
michael@0 | 34 | ------------------------------------------------------------------------------ |
michael@0 | 35 | Residual decoding (Paragraph 13.2 / 13.3) |
michael@0 | 36 | */ |
michael@0 | 37 | static const uint8_t kBands[16 + 1] = { |
michael@0 | 38 | 0, 1, 2, 3, 6, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7, |
michael@0 | 39 | 0 /* extra entry as sentinel */ |
michael@0 | 40 | }; |
michael@0 | 41 | |
michael@0 | 42 | static const uint8_t kCat3[] = { 173, 148, 140, 0 }; |
michael@0 | 43 | static const uint8_t kCat4[] = { 176, 155, 140, 135, 0 }; |
michael@0 | 44 | static const uint8_t kCat5[] = { 180, 157, 141, 134, 130, 0 }; |
michael@0 | 45 | static const uint8_t kCat6[] = |
michael@0 | 46 | { 254, 254, 243, 230, 196, 177, 153, 140, 133, 130, 129, 0 }; |
michael@0 | 47 | static const uint8_t* const kCat3456[] = { kCat3, kCat4, kCat5, kCat6 }; |
michael@0 | 48 | static const uint8_t kZigzag[16] = { |
michael@0 | 49 | 0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 10, 7, 11, 14, 15 |
michael@0 | 50 | }; |
michael@0 | 51 | |
michael@0 | 52 | #define VP8GetBit vp8dx_decode_bool |
michael@0 | 53 | #define NUM_PROBAS 11 |
michael@0 | 54 | #define NUM_CTX 3 |
michael@0 | 55 | |
michael@0 | 56 | /* for const-casting */ |
michael@0 | 57 | typedef const uint8_t (*ProbaArray)[NUM_CTX][NUM_PROBAS]; |
michael@0 | 58 | |
michael@0 | 59 | static int GetSigned(BOOL_DECODER *br, int value_to_sign) |
michael@0 | 60 | { |
michael@0 | 61 | int split = (br->range + 1) >> 1; |
michael@0 | 62 | VP8_BD_VALUE bigsplit = (VP8_BD_VALUE)split << (VP8_BD_VALUE_SIZE - 8); |
michael@0 | 63 | int v; |
michael@0 | 64 | |
michael@0 | 65 | if(br->count < 0) |
michael@0 | 66 | vp8dx_bool_decoder_fill(br); |
michael@0 | 67 | |
michael@0 | 68 | if ( br->value < bigsplit ) |
michael@0 | 69 | { |
michael@0 | 70 | br->range = split; |
michael@0 | 71 | v= value_to_sign; |
michael@0 | 72 | } |
michael@0 | 73 | else |
michael@0 | 74 | { |
michael@0 | 75 | br->range = br->range-split; |
michael@0 | 76 | br->value = br->value-bigsplit; |
michael@0 | 77 | v = -value_to_sign; |
michael@0 | 78 | } |
michael@0 | 79 | br->range +=br->range; |
michael@0 | 80 | br->value +=br->value; |
michael@0 | 81 | br->count--; |
michael@0 | 82 | |
michael@0 | 83 | return v; |
michael@0 | 84 | } |
michael@0 | 85 | /* |
michael@0 | 86 | Returns the position of the last non-zero coeff plus one |
michael@0 | 87 | (and 0 if there's no coeff at all) |
michael@0 | 88 | */ |
michael@0 | 89 | static int GetCoeffs(BOOL_DECODER *br, ProbaArray prob, |
michael@0 | 90 | int ctx, int n, int16_t* out) |
michael@0 | 91 | { |
michael@0 | 92 | const uint8_t* p = prob[n][ctx]; |
michael@0 | 93 | if (!VP8GetBit(br, p[0])) |
michael@0 | 94 | { /* first EOB is more a 'CBP' bit. */ |
michael@0 | 95 | return 0; |
michael@0 | 96 | } |
michael@0 | 97 | while (1) |
michael@0 | 98 | { |
michael@0 | 99 | ++n; |
michael@0 | 100 | if (!VP8GetBit(br, p[1])) |
michael@0 | 101 | { |
michael@0 | 102 | p = prob[kBands[n]][0]; |
michael@0 | 103 | } |
michael@0 | 104 | else |
michael@0 | 105 | { /* non zero coeff */ |
michael@0 | 106 | int v, j; |
michael@0 | 107 | if (!VP8GetBit(br, p[2])) |
michael@0 | 108 | { |
michael@0 | 109 | p = prob[kBands[n]][1]; |
michael@0 | 110 | v = 1; |
michael@0 | 111 | } |
michael@0 | 112 | else |
michael@0 | 113 | { |
michael@0 | 114 | if (!VP8GetBit(br, p[3])) |
michael@0 | 115 | { |
michael@0 | 116 | if (!VP8GetBit(br, p[4])) |
michael@0 | 117 | { |
michael@0 | 118 | v = 2; |
michael@0 | 119 | } |
michael@0 | 120 | else |
michael@0 | 121 | { |
michael@0 | 122 | v = 3 + VP8GetBit(br, p[5]); |
michael@0 | 123 | } |
michael@0 | 124 | } |
michael@0 | 125 | else |
michael@0 | 126 | { |
michael@0 | 127 | if (!VP8GetBit(br, p[6])) |
michael@0 | 128 | { |
michael@0 | 129 | if (!VP8GetBit(br, p[7])) |
michael@0 | 130 | { |
michael@0 | 131 | v = 5 + VP8GetBit(br, 159); |
michael@0 | 132 | } else |
michael@0 | 133 | { |
michael@0 | 134 | v = 7 + 2 * VP8GetBit(br, 165); |
michael@0 | 135 | v += VP8GetBit(br, 145); |
michael@0 | 136 | } |
michael@0 | 137 | } |
michael@0 | 138 | else |
michael@0 | 139 | { |
michael@0 | 140 | const uint8_t* tab; |
michael@0 | 141 | const int bit1 = VP8GetBit(br, p[8]); |
michael@0 | 142 | const int bit0 = VP8GetBit(br, p[9 + bit1]); |
michael@0 | 143 | const int cat = 2 * bit1 + bit0; |
michael@0 | 144 | v = 0; |
michael@0 | 145 | for (tab = kCat3456[cat]; *tab; ++tab) |
michael@0 | 146 | { |
michael@0 | 147 | v += v + VP8GetBit(br, *tab); |
michael@0 | 148 | } |
michael@0 | 149 | v += 3 + (8 << cat); |
michael@0 | 150 | } |
michael@0 | 151 | } |
michael@0 | 152 | p = prob[kBands[n]][2]; |
michael@0 | 153 | } |
michael@0 | 154 | j = kZigzag[n - 1]; |
michael@0 | 155 | |
michael@0 | 156 | out[j] = GetSigned(br, v); |
michael@0 | 157 | |
michael@0 | 158 | if (n == 16 || !VP8GetBit(br, p[0])) |
michael@0 | 159 | { /* EOB */ |
michael@0 | 160 | return n; |
michael@0 | 161 | } |
michael@0 | 162 | } |
michael@0 | 163 | if (n == 16) |
michael@0 | 164 | { |
michael@0 | 165 | return 16; |
michael@0 | 166 | } |
michael@0 | 167 | } |
michael@0 | 168 | } |
michael@0 | 169 | |
michael@0 | 170 | int vp8_decode_mb_tokens(VP8D_COMP *dx, MACROBLOCKD *x) |
michael@0 | 171 | { |
michael@0 | 172 | BOOL_DECODER *bc = x->current_bc; |
michael@0 | 173 | const FRAME_CONTEXT * const fc = &dx->common.fc; |
michael@0 | 174 | char *eobs = x->eobs; |
michael@0 | 175 | |
michael@0 | 176 | int i; |
michael@0 | 177 | int nonzeros; |
michael@0 | 178 | int eobtotal = 0; |
michael@0 | 179 | |
michael@0 | 180 | short *qcoeff_ptr; |
michael@0 | 181 | ProbaArray coef_probs; |
michael@0 | 182 | ENTROPY_CONTEXT *a_ctx = ((ENTROPY_CONTEXT *)x->above_context); |
michael@0 | 183 | ENTROPY_CONTEXT *l_ctx = ((ENTROPY_CONTEXT *)x->left_context); |
michael@0 | 184 | ENTROPY_CONTEXT *a; |
michael@0 | 185 | ENTROPY_CONTEXT *l; |
michael@0 | 186 | int skip_dc = 0; |
michael@0 | 187 | |
michael@0 | 188 | qcoeff_ptr = &x->qcoeff[0]; |
michael@0 | 189 | |
michael@0 | 190 | if (!x->mode_info_context->mbmi.is_4x4) |
michael@0 | 191 | { |
michael@0 | 192 | a = a_ctx + 8; |
michael@0 | 193 | l = l_ctx + 8; |
michael@0 | 194 | |
michael@0 | 195 | coef_probs = fc->coef_probs [1]; |
michael@0 | 196 | |
michael@0 | 197 | nonzeros = GetCoeffs(bc, coef_probs, (*a + *l), 0, qcoeff_ptr + 24 * 16); |
michael@0 | 198 | *a = *l = (nonzeros > 0); |
michael@0 | 199 | |
michael@0 | 200 | eobs[24] = nonzeros; |
michael@0 | 201 | eobtotal += nonzeros - 16; |
michael@0 | 202 | |
michael@0 | 203 | coef_probs = fc->coef_probs [0]; |
michael@0 | 204 | skip_dc = 1; |
michael@0 | 205 | } |
michael@0 | 206 | else |
michael@0 | 207 | { |
michael@0 | 208 | coef_probs = fc->coef_probs [3]; |
michael@0 | 209 | skip_dc = 0; |
michael@0 | 210 | } |
michael@0 | 211 | |
michael@0 | 212 | for (i = 0; i < 16; ++i) |
michael@0 | 213 | { |
michael@0 | 214 | a = a_ctx + (i&3); |
michael@0 | 215 | l = l_ctx + ((i&0xc)>>2); |
michael@0 | 216 | |
michael@0 | 217 | nonzeros = GetCoeffs(bc, coef_probs, (*a + *l), skip_dc, qcoeff_ptr); |
michael@0 | 218 | *a = *l = (nonzeros > 0); |
michael@0 | 219 | |
michael@0 | 220 | nonzeros += skip_dc; |
michael@0 | 221 | eobs[i] = nonzeros; |
michael@0 | 222 | eobtotal += nonzeros; |
michael@0 | 223 | qcoeff_ptr += 16; |
michael@0 | 224 | } |
michael@0 | 225 | |
michael@0 | 226 | coef_probs = fc->coef_probs [2]; |
michael@0 | 227 | |
michael@0 | 228 | a_ctx += 4; |
michael@0 | 229 | l_ctx += 4; |
michael@0 | 230 | for (i = 16; i < 24; ++i) |
michael@0 | 231 | { |
michael@0 | 232 | a = a_ctx + ((i > 19)<<1) + (i&1); |
michael@0 | 233 | l = l_ctx + ((i > 19)<<1) + ((i&3)>1); |
michael@0 | 234 | |
michael@0 | 235 | nonzeros = GetCoeffs(bc, coef_probs, (*a + *l), 0, qcoeff_ptr); |
michael@0 | 236 | *a = *l = (nonzeros > 0); |
michael@0 | 237 | |
michael@0 | 238 | eobs[i] = nonzeros; |
michael@0 | 239 | eobtotal += nonzeros; |
michael@0 | 240 | qcoeff_ptr += 16; |
michael@0 | 241 | } |
michael@0 | 242 | |
michael@0 | 243 | return eobtotal; |
michael@0 | 244 | } |
michael@0 | 245 |