media/libvpx/vp9/decoder/vp9_dboolhuff.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.

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 #ifndef VP9_DECODER_VP9_DBOOLHUFF_H_
michael@0 12 #define VP9_DECODER_VP9_DBOOLHUFF_H_
michael@0 13
michael@0 14 #include <stddef.h>
michael@0 15 #include <limits.h>
michael@0 16
michael@0 17 #include "./vpx_config.h"
michael@0 18 #include "vpx_ports/mem.h"
michael@0 19 #include "vpx/vpx_integer.h"
michael@0 20
michael@0 21 typedef size_t VP9_BD_VALUE;
michael@0 22
michael@0 23 #define BD_VALUE_SIZE ((int)sizeof(VP9_BD_VALUE)*CHAR_BIT)
michael@0 24
michael@0 25 typedef struct {
michael@0 26 const uint8_t *buffer_end;
michael@0 27 const uint8_t *buffer;
michael@0 28 VP9_BD_VALUE value;
michael@0 29 int count;
michael@0 30 unsigned int range;
michael@0 31 } vp9_reader;
michael@0 32
michael@0 33 DECLARE_ALIGNED(16, extern const uint8_t, vp9_norm[256]);
michael@0 34
michael@0 35 int vp9_reader_init(vp9_reader *r, const uint8_t *buffer, size_t size);
michael@0 36
michael@0 37 void vp9_reader_fill(vp9_reader *r);
michael@0 38
michael@0 39 const uint8_t *vp9_reader_find_end(vp9_reader *r);
michael@0 40
michael@0 41 static int vp9_read(vp9_reader *br, int probability) {
michael@0 42 unsigned int bit = 0;
michael@0 43 VP9_BD_VALUE value;
michael@0 44 VP9_BD_VALUE bigsplit;
michael@0 45 int count;
michael@0 46 unsigned int range;
michael@0 47 unsigned int split = ((br->range * probability) + (256 - probability)) >> 8;
michael@0 48
michael@0 49 if (br->count < 0)
michael@0 50 vp9_reader_fill(br);
michael@0 51
michael@0 52 value = br->value;
michael@0 53 count = br->count;
michael@0 54
michael@0 55 bigsplit = (VP9_BD_VALUE)split << (BD_VALUE_SIZE - 8);
michael@0 56
michael@0 57 range = split;
michael@0 58
michael@0 59 if (value >= bigsplit) {
michael@0 60 range = br->range - split;
michael@0 61 value = value - bigsplit;
michael@0 62 bit = 1;
michael@0 63 }
michael@0 64
michael@0 65 {
michael@0 66 register unsigned int shift = vp9_norm[range];
michael@0 67 range <<= shift;
michael@0 68 value <<= shift;
michael@0 69 count -= shift;
michael@0 70 }
michael@0 71 br->value = value;
michael@0 72 br->count = count;
michael@0 73 br->range = range;
michael@0 74
michael@0 75 return bit;
michael@0 76 }
michael@0 77
michael@0 78 static int vp9_read_bit(vp9_reader *r) {
michael@0 79 return vp9_read(r, 128); // vp9_prob_half
michael@0 80 }
michael@0 81
michael@0 82 static int vp9_read_literal(vp9_reader *br, int bits) {
michael@0 83 int z = 0, bit;
michael@0 84
michael@0 85 for (bit = bits - 1; bit >= 0; bit--)
michael@0 86 z |= vp9_read_bit(br) << bit;
michael@0 87
michael@0 88 return z;
michael@0 89 }
michael@0 90
michael@0 91 int vp9_reader_has_error(vp9_reader *r);
michael@0 92
michael@0 93 #endif // VP9_DECODER_VP9_DBOOLHUFF_H_

mercurial