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 | /**************************************************************************** |
michael@0 | 13 | * |
michael@0 | 14 | * Module Title : vp9_boolhuff.h |
michael@0 | 15 | * |
michael@0 | 16 | * Description : Bool Coder header file. |
michael@0 | 17 | * |
michael@0 | 18 | ****************************************************************************/ |
michael@0 | 19 | #ifndef VP9_ENCODER_VP9_BOOLHUFF_H_ |
michael@0 | 20 | #define VP9_ENCODER_VP9_BOOLHUFF_H_ |
michael@0 | 21 | |
michael@0 | 22 | #include "vpx_ports/mem.h" |
michael@0 | 23 | |
michael@0 | 24 | typedef struct { |
michael@0 | 25 | unsigned int lowvalue; |
michael@0 | 26 | unsigned int range; |
michael@0 | 27 | unsigned int value; |
michael@0 | 28 | int count; |
michael@0 | 29 | unsigned int pos; |
michael@0 | 30 | uint8_t *buffer; |
michael@0 | 31 | |
michael@0 | 32 | // Variables used to track bit costs without outputing to the bitstream |
michael@0 | 33 | unsigned int measure_cost; |
michael@0 | 34 | unsigned long bit_counter; |
michael@0 | 35 | } vp9_writer; |
michael@0 | 36 | |
michael@0 | 37 | extern const unsigned int vp9_prob_cost[256]; |
michael@0 | 38 | |
michael@0 | 39 | void vp9_start_encode(vp9_writer *bc, uint8_t *buffer); |
michael@0 | 40 | void vp9_stop_encode(vp9_writer *bc); |
michael@0 | 41 | |
michael@0 | 42 | DECLARE_ALIGNED(16, extern const unsigned char, vp9_norm[256]); |
michael@0 | 43 | |
michael@0 | 44 | static void vp9_write(vp9_writer *br, int bit, int probability) { |
michael@0 | 45 | unsigned int split; |
michael@0 | 46 | int count = br->count; |
michael@0 | 47 | unsigned int range = br->range; |
michael@0 | 48 | unsigned int lowvalue = br->lowvalue; |
michael@0 | 49 | register unsigned int shift; |
michael@0 | 50 | |
michael@0 | 51 | #ifdef ENTROPY_STATS |
michael@0 | 52 | #if defined(SECTIONBITS_OUTPUT) |
michael@0 | 53 | |
michael@0 | 54 | if (bit) |
michael@0 | 55 | Sectionbits[active_section] += vp9_prob_cost[255 - probability]; |
michael@0 | 56 | else |
michael@0 | 57 | Sectionbits[active_section] += vp9_prob_cost[probability]; |
michael@0 | 58 | |
michael@0 | 59 | #endif |
michael@0 | 60 | #endif |
michael@0 | 61 | |
michael@0 | 62 | split = 1 + (((range - 1) * probability) >> 8); |
michael@0 | 63 | |
michael@0 | 64 | range = split; |
michael@0 | 65 | |
michael@0 | 66 | if (bit) { |
michael@0 | 67 | lowvalue += split; |
michael@0 | 68 | range = br->range - split; |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | shift = vp9_norm[range]; |
michael@0 | 72 | |
michael@0 | 73 | range <<= shift; |
michael@0 | 74 | count += shift; |
michael@0 | 75 | |
michael@0 | 76 | if (count >= 0) { |
michael@0 | 77 | int offset = shift - count; |
michael@0 | 78 | |
michael@0 | 79 | if ((lowvalue << (offset - 1)) & 0x80000000) { |
michael@0 | 80 | int x = br->pos - 1; |
michael@0 | 81 | |
michael@0 | 82 | while (x >= 0 && br->buffer[x] == 0xff) { |
michael@0 | 83 | br->buffer[x] = 0; |
michael@0 | 84 | x--; |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | br->buffer[x] += 1; |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | br->buffer[br->pos++] = (lowvalue >> (24 - offset)); |
michael@0 | 91 | lowvalue <<= offset; |
michael@0 | 92 | shift = count; |
michael@0 | 93 | lowvalue &= 0xffffff; |
michael@0 | 94 | count -= 8; |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | lowvalue <<= shift; |
michael@0 | 98 | br->count = count; |
michael@0 | 99 | br->lowvalue = lowvalue; |
michael@0 | 100 | br->range = range; |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | static void vp9_write_bit(vp9_writer *w, int bit) { |
michael@0 | 104 | vp9_write(w, bit, 128); // vp9_prob_half |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | static void vp9_write_literal(vp9_writer *w, int data, int bits) { |
michael@0 | 108 | int bit; |
michael@0 | 109 | |
michael@0 | 110 | for (bit = bits - 1; bit >= 0; bit--) |
michael@0 | 111 | vp9_write_bit(w, 1 & (data >> bit)); |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | |
michael@0 | 115 | #endif // VP9_ENCODER_VP9_BOOLHUFF_H_ |