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 | #ifndef VP9_ENCODER_VP9_TREEWRITER_H_ |
michael@0 | 13 | #define VP9_ENCODER_VP9_TREEWRITER_H_ |
michael@0 | 14 | |
michael@0 | 15 | /* Trees map alphabets into huffman-like codes suitable for an arithmetic |
michael@0 | 16 | bit coder. Timothy S Murphy 11 October 2004 */ |
michael@0 | 17 | |
michael@0 | 18 | #include "vp9/common/vp9_treecoder.h" |
michael@0 | 19 | |
michael@0 | 20 | #include "vp9/encoder/vp9_boolhuff.h" /* for now */ |
michael@0 | 21 | |
michael@0 | 22 | |
michael@0 | 23 | #define vp9_write_prob(w, v) vp9_write_literal((w), (v), 8) |
michael@0 | 24 | |
michael@0 | 25 | /* Approximate length of an encoded bool in 256ths of a bit at given prob */ |
michael@0 | 26 | |
michael@0 | 27 | #define vp9_cost_zero(x) (vp9_prob_cost[x]) |
michael@0 | 28 | #define vp9_cost_one(x) vp9_cost_zero(vp9_complement(x)) |
michael@0 | 29 | |
michael@0 | 30 | #define vp9_cost_bit(x, b) vp9_cost_zero((b) ? vp9_complement(x) : (x)) |
michael@0 | 31 | |
michael@0 | 32 | /* VP8BC version is scaled by 2^20 rather than 2^8; see bool_coder.h */ |
michael@0 | 33 | |
michael@0 | 34 | |
michael@0 | 35 | /* Both of these return bits, not scaled bits. */ |
michael@0 | 36 | static INLINE unsigned int cost_branch256(const unsigned int ct[2], |
michael@0 | 37 | vp9_prob p) { |
michael@0 | 38 | return ct[0] * vp9_cost_zero(p) + ct[1] * vp9_cost_one(p); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | static INLINE unsigned int cost_branch(const unsigned int ct[2], |
michael@0 | 42 | vp9_prob p) { |
michael@0 | 43 | return cost_branch256(ct, p) >> 8; |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | |
michael@0 | 47 | static INLINE void treed_write(vp9_writer *w, |
michael@0 | 48 | vp9_tree tree, const vp9_prob *probs, |
michael@0 | 49 | int bits, int len) { |
michael@0 | 50 | vp9_tree_index i = 0; |
michael@0 | 51 | |
michael@0 | 52 | do { |
michael@0 | 53 | const int bit = (bits >> --len) & 1; |
michael@0 | 54 | vp9_write(w, bit, probs[i >> 1]); |
michael@0 | 55 | i = tree[i + bit]; |
michael@0 | 56 | } while (len); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | static INLINE void write_token(vp9_writer *w, vp9_tree tree, |
michael@0 | 60 | const vp9_prob *probs, |
michael@0 | 61 | const struct vp9_token *token) { |
michael@0 | 62 | treed_write(w, tree, probs, token->value, token->len); |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | static INLINE int treed_cost(vp9_tree tree, const vp9_prob *probs, |
michael@0 | 66 | int bits, int len) { |
michael@0 | 67 | int cost = 0; |
michael@0 | 68 | vp9_tree_index i = 0; |
michael@0 | 69 | |
michael@0 | 70 | do { |
michael@0 | 71 | const int bit = (bits >> --len) & 1; |
michael@0 | 72 | cost += vp9_cost_bit(probs[i >> 1], bit); |
michael@0 | 73 | i = tree[i + bit]; |
michael@0 | 74 | } while (len); |
michael@0 | 75 | |
michael@0 | 76 | return cost; |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | static INLINE int cost_token(vp9_tree tree, const vp9_prob *probs, |
michael@0 | 80 | const struct vp9_token *token) { |
michael@0 | 81 | return treed_cost(tree, probs, token->value, token->len); |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | void vp9_cost_tokens(int *costs, const vp9_prob *probs, vp9_tree tree); |
michael@0 | 85 | void vp9_cost_tokens_skip(int *costs, const vp9_prob *probs, vp9_tree tree); |
michael@0 | 86 | |
michael@0 | 87 | #endif // VP9_ENCODER_VP9_TREEWRITER_H_ |