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 "vp9/common/vp9_onyxc_int.h" |
michael@0 | 13 | #include "vp9/common/vp9_entropymv.h" |
michael@0 | 14 | |
michael@0 | 15 | #define MV_COUNT_SAT 20 |
michael@0 | 16 | #define MV_MAX_UPDATE_FACTOR 128 |
michael@0 | 17 | |
michael@0 | 18 | /* Integer pel reference mv threshold for use of high-precision 1/8 mv */ |
michael@0 | 19 | #define COMPANDED_MVREF_THRESH 8 |
michael@0 | 20 | |
michael@0 | 21 | const vp9_tree_index vp9_mv_joint_tree[TREE_SIZE(MV_JOINTS)] = { |
michael@0 | 22 | -MV_JOINT_ZERO, 2, |
michael@0 | 23 | -MV_JOINT_HNZVZ, 4, |
michael@0 | 24 | -MV_JOINT_HZVNZ, -MV_JOINT_HNZVNZ |
michael@0 | 25 | }; |
michael@0 | 26 | struct vp9_token vp9_mv_joint_encodings[MV_JOINTS]; |
michael@0 | 27 | |
michael@0 | 28 | const vp9_tree_index vp9_mv_class_tree[TREE_SIZE(MV_CLASSES)] = { |
michael@0 | 29 | -MV_CLASS_0, 2, |
michael@0 | 30 | -MV_CLASS_1, 4, |
michael@0 | 31 | 6, 8, |
michael@0 | 32 | -MV_CLASS_2, -MV_CLASS_3, |
michael@0 | 33 | 10, 12, |
michael@0 | 34 | -MV_CLASS_4, -MV_CLASS_5, |
michael@0 | 35 | -MV_CLASS_6, 14, |
michael@0 | 36 | 16, 18, |
michael@0 | 37 | -MV_CLASS_7, -MV_CLASS_8, |
michael@0 | 38 | -MV_CLASS_9, -MV_CLASS_10, |
michael@0 | 39 | }; |
michael@0 | 40 | struct vp9_token vp9_mv_class_encodings[MV_CLASSES]; |
michael@0 | 41 | |
michael@0 | 42 | const vp9_tree_index vp9_mv_class0_tree[TREE_SIZE(CLASS0_SIZE)] = { |
michael@0 | 43 | -0, -1, |
michael@0 | 44 | }; |
michael@0 | 45 | struct vp9_token vp9_mv_class0_encodings[CLASS0_SIZE]; |
michael@0 | 46 | |
michael@0 | 47 | const vp9_tree_index vp9_mv_fp_tree[TREE_SIZE(4)] = { |
michael@0 | 48 | -0, 2, |
michael@0 | 49 | -1, 4, |
michael@0 | 50 | -2, -3 |
michael@0 | 51 | }; |
michael@0 | 52 | struct vp9_token vp9_mv_fp_encodings[4]; |
michael@0 | 53 | |
michael@0 | 54 | static const nmv_context default_nmv_context = { |
michael@0 | 55 | {32, 64, 96}, |
michael@0 | 56 | { // NOLINT |
michael@0 | 57 | { /* vert component */ // NOLINT |
michael@0 | 58 | 128, /* sign */ |
michael@0 | 59 | {224, 144, 192, 168, 192, 176, 192, 198, 198, 245}, /* class */ |
michael@0 | 60 | {216}, /* class0 */ |
michael@0 | 61 | {136, 140, 148, 160, 176, 192, 224, 234, 234, 240}, /* bits */ |
michael@0 | 62 | {{128, 128, 64}, {96, 112, 64}}, /* class0_fp */ |
michael@0 | 63 | {64, 96, 64}, /* fp */ |
michael@0 | 64 | 160, /* class0_hp bit */ |
michael@0 | 65 | 128, /* hp */ |
michael@0 | 66 | }, |
michael@0 | 67 | { /* hor component */ // NOLINT |
michael@0 | 68 | 128, /* sign */ |
michael@0 | 69 | {216, 128, 176, 160, 176, 176, 192, 198, 198, 208}, /* class */ |
michael@0 | 70 | {208}, /* class0 */ |
michael@0 | 71 | {136, 140, 148, 160, 176, 192, 224, 234, 234, 240}, /* bits */ |
michael@0 | 72 | {{128, 128, 64}, {96, 112, 64}}, /* class0_fp */ |
michael@0 | 73 | {64, 96, 64}, /* fp */ |
michael@0 | 74 | 160, /* class0_hp bit */ |
michael@0 | 75 | 128, /* hp */ |
michael@0 | 76 | } |
michael@0 | 77 | }, |
michael@0 | 78 | }; |
michael@0 | 79 | |
michael@0 | 80 | #define mv_class_base(c) ((c) ? (CLASS0_SIZE << (c + 2)) : 0) |
michael@0 | 81 | |
michael@0 | 82 | static const uint8_t log_in_base_2[] = { |
michael@0 | 83 | 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, |
michael@0 | 84 | 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
michael@0 | 85 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, |
michael@0 | 86 | 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, |
michael@0 | 87 | 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, |
michael@0 | 88 | 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, |
michael@0 | 89 | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, |
michael@0 | 90 | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, |
michael@0 | 91 | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,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8, |
michael@0 | 104 | 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
michael@0 | 105 | 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
michael@0 | 106 | 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
michael@0 | 107 | 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
michael@0 | 108 | 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
michael@0 | 109 | 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
michael@0 | 110 | 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
michael@0 | 111 | 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
michael@0 | 112 | 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
michael@0 | 113 | 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
michael@0 | 114 | 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
michael@0 | 115 | 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
michael@0 | 116 | 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
michael@0 | 117 | 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
michael@0 | 118 | 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
michael@0 | 119 | 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
michael@0 | 120 | 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
michael@0 | 121 | 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
michael@0 | 122 | 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
michael@0 | 123 | 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
michael@0 | 124 | 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
michael@0 | 125 | 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10 |
michael@0 | 126 | }; |
michael@0 | 127 | |
michael@0 | 128 | MV_CLASS_TYPE vp9_get_mv_class(int z, int *offset) { |
michael@0 | 129 | MV_CLASS_TYPE c = MV_CLASS_0; |
michael@0 | 130 | if (z >= CLASS0_SIZE * 4096) |
michael@0 | 131 | c = MV_CLASS_10; |
michael@0 | 132 | else |
michael@0 | 133 | c = log_in_base_2[z >> 3]; |
michael@0 | 134 | |
michael@0 | 135 | if (offset) |
michael@0 | 136 | *offset = z - mv_class_base(c); |
michael@0 | 137 | return c; |
michael@0 | 138 | } |
michael@0 | 139 | |
michael@0 | 140 | int vp9_use_mv_hp(const MV *ref) { |
michael@0 | 141 | return (abs(ref->row) >> 3) < COMPANDED_MVREF_THRESH && |
michael@0 | 142 | (abs(ref->col) >> 3) < COMPANDED_MVREF_THRESH; |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | int vp9_get_mv_mag(MV_CLASS_TYPE c, int offset) { |
michael@0 | 146 | return mv_class_base(c) + offset; |
michael@0 | 147 | } |
michael@0 | 148 | |
michael@0 | 149 | static void inc_mv_component(int v, nmv_component_counts *comp_counts, |
michael@0 | 150 | int incr, int usehp) { |
michael@0 | 151 | int s, z, c, o, d, e, f; |
michael@0 | 152 | assert(v != 0); /* should not be zero */ |
michael@0 | 153 | s = v < 0; |
michael@0 | 154 | comp_counts->sign[s] += incr; |
michael@0 | 155 | z = (s ? -v : v) - 1; /* magnitude - 1 */ |
michael@0 | 156 | |
michael@0 | 157 | c = vp9_get_mv_class(z, &o); |
michael@0 | 158 | comp_counts->classes[c] += incr; |
michael@0 | 159 | |
michael@0 | 160 | d = (o >> 3); /* int mv data */ |
michael@0 | 161 | f = (o >> 1) & 3; /* fractional pel mv data */ |
michael@0 | 162 | e = (o & 1); /* high precision mv data */ |
michael@0 | 163 | |
michael@0 | 164 | if (c == MV_CLASS_0) { |
michael@0 | 165 | comp_counts->class0[d] += incr; |
michael@0 | 166 | comp_counts->class0_fp[d][f] += incr; |
michael@0 | 167 | comp_counts->class0_hp[e] += usehp * incr; |
michael@0 | 168 | } else { |
michael@0 | 169 | int i; |
michael@0 | 170 | int b = c + CLASS0_BITS - 1; // number of bits |
michael@0 | 171 | for (i = 0; i < b; ++i) |
michael@0 | 172 | comp_counts->bits[i][((d >> i) & 1)] += incr; |
michael@0 | 173 | comp_counts->fp[f] += incr; |
michael@0 | 174 | comp_counts->hp[e] += usehp * incr; |
michael@0 | 175 | } |
michael@0 | 176 | } |
michael@0 | 177 | |
michael@0 | 178 | void vp9_inc_mv(const MV *mv, nmv_context_counts *counts) { |
michael@0 | 179 | if (counts != NULL) { |
michael@0 | 180 | const MV_JOINT_TYPE j = vp9_get_mv_joint(mv); |
michael@0 | 181 | ++counts->joints[j]; |
michael@0 | 182 | |
michael@0 | 183 | if (mv_joint_vertical(j)) { |
michael@0 | 184 | inc_mv_component(mv->row, &counts->comps[0], 1, 1); |
michael@0 | 185 | } |
michael@0 | 186 | |
michael@0 | 187 | if (mv_joint_horizontal(j)) { |
michael@0 | 188 | inc_mv_component(mv->col, &counts->comps[1], 1, 1); |
michael@0 | 189 | } |
michael@0 | 190 | } |
michael@0 | 191 | } |
michael@0 | 192 | |
michael@0 | 193 | static vp9_prob adapt_prob(vp9_prob prep, const unsigned int ct[2]) { |
michael@0 | 194 | return merge_probs(prep, ct, MV_COUNT_SAT, MV_MAX_UPDATE_FACTOR); |
michael@0 | 195 | } |
michael@0 | 196 | |
michael@0 | 197 | static void adapt_probs(const vp9_tree_index *tree, const vp9_prob *pre_probs, |
michael@0 | 198 | const unsigned int *counts, vp9_prob *probs) { |
michael@0 | 199 | tree_merge_probs(tree, pre_probs, counts, MV_COUNT_SAT, MV_MAX_UPDATE_FACTOR, |
michael@0 | 200 | probs); |
michael@0 | 201 | } |
michael@0 | 202 | |
michael@0 | 203 | void vp9_adapt_mv_probs(VP9_COMMON *cm, int allow_hp) { |
michael@0 | 204 | int i, j; |
michael@0 | 205 | |
michael@0 | 206 | nmv_context *fc = &cm->fc.nmvc; |
michael@0 | 207 | const nmv_context *pre_fc = &cm->frame_contexts[cm->frame_context_idx].nmvc; |
michael@0 | 208 | const nmv_context_counts *counts = &cm->counts.mv; |
michael@0 | 209 | |
michael@0 | 210 | adapt_probs(vp9_mv_joint_tree, pre_fc->joints, counts->joints, fc->joints); |
michael@0 | 211 | |
michael@0 | 212 | for (i = 0; i < 2; ++i) { |
michael@0 | 213 | nmv_component *comp = &fc->comps[i]; |
michael@0 | 214 | const nmv_component *pre_comp = &pre_fc->comps[i]; |
michael@0 | 215 | const nmv_component_counts *c = &counts->comps[i]; |
michael@0 | 216 | |
michael@0 | 217 | comp->sign = adapt_prob(pre_comp->sign, c->sign); |
michael@0 | 218 | adapt_probs(vp9_mv_class_tree, pre_comp->classes, c->classes, |
michael@0 | 219 | comp->classes); |
michael@0 | 220 | adapt_probs(vp9_mv_class0_tree, pre_comp->class0, c->class0, comp->class0); |
michael@0 | 221 | |
michael@0 | 222 | for (j = 0; j < MV_OFFSET_BITS; ++j) |
michael@0 | 223 | comp->bits[j] = adapt_prob(pre_comp->bits[j], c->bits[j]); |
michael@0 | 224 | |
michael@0 | 225 | for (j = 0; j < CLASS0_SIZE; ++j) |
michael@0 | 226 | adapt_probs(vp9_mv_fp_tree, pre_comp->class0_fp[j], c->class0_fp[j], |
michael@0 | 227 | comp->class0_fp[j]); |
michael@0 | 228 | |
michael@0 | 229 | adapt_probs(vp9_mv_fp_tree, pre_comp->fp, c->fp, comp->fp); |
michael@0 | 230 | |
michael@0 | 231 | if (allow_hp) { |
michael@0 | 232 | comp->class0_hp = adapt_prob(pre_comp->class0_hp, c->class0_hp); |
michael@0 | 233 | comp->hp = adapt_prob(pre_comp->hp, c->hp); |
michael@0 | 234 | } |
michael@0 | 235 | } |
michael@0 | 236 | } |
michael@0 | 237 | |
michael@0 | 238 | void vp9_entropy_mv_init() { |
michael@0 | 239 | vp9_tokens_from_tree(vp9_mv_joint_encodings, vp9_mv_joint_tree); |
michael@0 | 240 | vp9_tokens_from_tree(vp9_mv_class_encodings, vp9_mv_class_tree); |
michael@0 | 241 | vp9_tokens_from_tree(vp9_mv_class0_encodings, vp9_mv_class0_tree); |
michael@0 | 242 | vp9_tokens_from_tree(vp9_mv_fp_encodings, vp9_mv_fp_tree); |
michael@0 | 243 | } |
michael@0 | 244 | |
michael@0 | 245 | void vp9_init_mv_probs(VP9_COMMON *cm) { |
michael@0 | 246 | cm->fc.nmvc = default_nmv_context; |
michael@0 | 247 | } |