media/libvpx/vp9/encoder/vp9_treewriter.h

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.

     1 /*
     2  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
     3  *
     4  *  Use of this source code is governed by a BSD-style license
     5  *  that can be found in the LICENSE file in the root of the source
     6  *  tree. An additional intellectual property rights grant can be found
     7  *  in the file PATENTS.  All contributing project authors may
     8  *  be found in the AUTHORS file in the root of the source tree.
     9  */
    12 #ifndef VP9_ENCODER_VP9_TREEWRITER_H_
    13 #define VP9_ENCODER_VP9_TREEWRITER_H_
    15 /* Trees map alphabets into huffman-like codes suitable for an arithmetic
    16    bit coder.  Timothy S Murphy  11 October 2004 */
    18 #include "vp9/common/vp9_treecoder.h"
    20 #include "vp9/encoder/vp9_boolhuff.h"       /* for now */
    23 #define vp9_write_prob(w, v) vp9_write_literal((w), (v), 8)
    25 /* Approximate length of an encoded bool in 256ths of a bit at given prob */
    27 #define vp9_cost_zero(x) (vp9_prob_cost[x])
    28 #define vp9_cost_one(x) vp9_cost_zero(vp9_complement(x))
    30 #define vp9_cost_bit(x, b) vp9_cost_zero((b) ? vp9_complement(x) : (x))
    32 /* VP8BC version is scaled by 2^20 rather than 2^8; see bool_coder.h */
    35 /* Both of these return bits, not scaled bits. */
    36 static INLINE unsigned int cost_branch256(const unsigned int ct[2],
    37                                           vp9_prob p) {
    38   return ct[0] * vp9_cost_zero(p) + ct[1] * vp9_cost_one(p);
    39 }
    41 static INLINE unsigned int cost_branch(const unsigned int ct[2],
    42                                        vp9_prob p) {
    43   return cost_branch256(ct, p) >> 8;
    44 }
    47 static INLINE void treed_write(vp9_writer *w,
    48                                vp9_tree tree, const vp9_prob *probs,
    49                                int bits, int len) {
    50   vp9_tree_index i = 0;
    52   do {
    53     const int bit = (bits >> --len) & 1;
    54     vp9_write(w, bit, probs[i >> 1]);
    55     i = tree[i + bit];
    56   } while (len);
    57 }
    59 static INLINE void write_token(vp9_writer *w, vp9_tree tree,
    60                                const vp9_prob *probs,
    61                                const struct vp9_token *token) {
    62   treed_write(w, tree, probs, token->value, token->len);
    63 }
    65 static INLINE int treed_cost(vp9_tree tree, const vp9_prob *probs,
    66                              int bits, int len) {
    67   int cost = 0;
    68   vp9_tree_index i = 0;
    70   do {
    71     const int bit = (bits >> --len) & 1;
    72     cost += vp9_cost_bit(probs[i >> 1], bit);
    73     i = tree[i + bit];
    74   } while (len);
    76   return cost;
    77 }
    79 static INLINE int cost_token(vp9_tree tree, const vp9_prob *probs,
    80                              const struct vp9_token *token) {
    81   return treed_cost(tree, probs, token->value, token->len);
    82 }
    84 void vp9_cost_tokens(int *costs, const vp9_prob *probs, vp9_tree tree);
    85 void vp9_cost_tokens_skip(int *costs, const vp9_prob *probs, vp9_tree tree);
    87 #endif  // VP9_ENCODER_VP9_TREEWRITER_H_

mercurial