media/libopus/celt/entcode.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 /* Copyright (c) 2001-2011 Timothy B. Terriberry
michael@0 2 Copyright (c) 2008-2009 Xiph.Org Foundation */
michael@0 3 /*
michael@0 4 Redistribution and use in source and binary forms, with or without
michael@0 5 modification, are permitted provided that the following conditions
michael@0 6 are met:
michael@0 7
michael@0 8 - Redistributions of source code must retain the above copyright
michael@0 9 notice, this list of conditions and the following disclaimer.
michael@0 10
michael@0 11 - Redistributions in binary form must reproduce the above copyright
michael@0 12 notice, this list of conditions and the following disclaimer in the
michael@0 13 documentation and/or other materials provided with the distribution.
michael@0 14
michael@0 15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
michael@0 16 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
michael@0 17 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
michael@0 18 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
michael@0 19 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
michael@0 20 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
michael@0 21 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
michael@0 22 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
michael@0 23 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
michael@0 24 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
michael@0 25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
michael@0 26 */
michael@0 27
michael@0 28 #include "opus_types.h"
michael@0 29 #include "opus_defines.h"
michael@0 30
michael@0 31 #if !defined(_entcode_H)
michael@0 32 # define _entcode_H (1)
michael@0 33 # include <limits.h>
michael@0 34 # include <stddef.h>
michael@0 35 # include "ecintrin.h"
michael@0 36
michael@0 37 /*OPT: ec_window must be at least 32 bits, but if you have fast arithmetic on a
michael@0 38 larger type, you can speed up the decoder by using it here.*/
michael@0 39 typedef opus_uint32 ec_window;
michael@0 40 typedef struct ec_ctx ec_ctx;
michael@0 41 typedef struct ec_ctx ec_enc;
michael@0 42 typedef struct ec_ctx ec_dec;
michael@0 43
michael@0 44 # define EC_WINDOW_SIZE ((int)sizeof(ec_window)*CHAR_BIT)
michael@0 45
michael@0 46 /*The number of bits to use for the range-coded part of unsigned integers.*/
michael@0 47 # define EC_UINT_BITS (8)
michael@0 48
michael@0 49 /*The resolution of fractional-precision bit usage measurements, i.e.,
michael@0 50 3 => 1/8th bits.*/
michael@0 51 # define BITRES 3
michael@0 52
michael@0 53 /*The entropy encoder/decoder context.
michael@0 54 We use the same structure for both, so that common functions like ec_tell()
michael@0 55 can be used on either one.*/
michael@0 56 struct ec_ctx{
michael@0 57 /*Buffered input/output.*/
michael@0 58 unsigned char *buf;
michael@0 59 /*The size of the buffer.*/
michael@0 60 opus_uint32 storage;
michael@0 61 /*The offset at which the last byte containing raw bits was read/written.*/
michael@0 62 opus_uint32 end_offs;
michael@0 63 /*Bits that will be read from/written at the end.*/
michael@0 64 ec_window end_window;
michael@0 65 /*Number of valid bits in end_window.*/
michael@0 66 int nend_bits;
michael@0 67 /*The total number of whole bits read/written.
michael@0 68 This does not include partial bits currently in the range coder.*/
michael@0 69 int nbits_total;
michael@0 70 /*The offset at which the next range coder byte will be read/written.*/
michael@0 71 opus_uint32 offs;
michael@0 72 /*The number of values in the current range.*/
michael@0 73 opus_uint32 rng;
michael@0 74 /*In the decoder: the difference between the top of the current range and
michael@0 75 the input value, minus one.
michael@0 76 In the encoder: the low end of the current range.*/
michael@0 77 opus_uint32 val;
michael@0 78 /*In the decoder: the saved normalization factor from ec_decode().
michael@0 79 In the encoder: the number of oustanding carry propagating symbols.*/
michael@0 80 opus_uint32 ext;
michael@0 81 /*A buffered input/output symbol, awaiting carry propagation.*/
michael@0 82 int rem;
michael@0 83 /*Nonzero if an error occurred.*/
michael@0 84 int error;
michael@0 85 };
michael@0 86
michael@0 87 static OPUS_INLINE opus_uint32 ec_range_bytes(ec_ctx *_this){
michael@0 88 return _this->offs;
michael@0 89 }
michael@0 90
michael@0 91 static OPUS_INLINE unsigned char *ec_get_buffer(ec_ctx *_this){
michael@0 92 return _this->buf;
michael@0 93 }
michael@0 94
michael@0 95 static OPUS_INLINE int ec_get_error(ec_ctx *_this){
michael@0 96 return _this->error;
michael@0 97 }
michael@0 98
michael@0 99 /*Returns the number of bits "used" by the encoded or decoded symbols so far.
michael@0 100 This same number can be computed in either the encoder or the decoder, and is
michael@0 101 suitable for making coding decisions.
michael@0 102 Return: The number of bits.
michael@0 103 This will always be slightly larger than the exact value (e.g., all
michael@0 104 rounding error is in the positive direction).*/
michael@0 105 static OPUS_INLINE int ec_tell(ec_ctx *_this){
michael@0 106 return _this->nbits_total-EC_ILOG(_this->rng);
michael@0 107 }
michael@0 108
michael@0 109 /*Returns the number of bits "used" by the encoded or decoded symbols so far.
michael@0 110 This same number can be computed in either the encoder or the decoder, and is
michael@0 111 suitable for making coding decisions.
michael@0 112 Return: The number of bits scaled by 2**BITRES.
michael@0 113 This will always be slightly larger than the exact value (e.g., all
michael@0 114 rounding error is in the positive direction).*/
michael@0 115 opus_uint32 ec_tell_frac(ec_ctx *_this);
michael@0 116
michael@0 117 #endif

mercurial