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 | /* Copyright (c) 2007-2008 CSIRO |
michael@0 | 2 | Copyright (c) 2007-2010 Xiph.Org Foundation |
michael@0 | 3 | Copyright (c) 2008 Gregory Maxwell |
michael@0 | 4 | Written by Jean-Marc Valin and Gregory Maxwell */ |
michael@0 | 5 | /* |
michael@0 | 6 | Redistribution and use in source and binary forms, with or without |
michael@0 | 7 | modification, are permitted provided that the following conditions |
michael@0 | 8 | are met: |
michael@0 | 9 | |
michael@0 | 10 | - Redistributions of source code must retain the above copyright |
michael@0 | 11 | notice, this list of conditions and the following disclaimer. |
michael@0 | 12 | |
michael@0 | 13 | - Redistributions in binary form must reproduce the above copyright |
michael@0 | 14 | notice, this list of conditions and the following disclaimer in the |
michael@0 | 15 | documentation and/or other materials provided with the distribution. |
michael@0 | 16 | |
michael@0 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
michael@0 | 18 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
michael@0 | 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
michael@0 | 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER |
michael@0 | 21 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
michael@0 | 22 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
michael@0 | 23 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
michael@0 | 24 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
michael@0 | 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
michael@0 | 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
michael@0 | 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
michael@0 | 28 | */ |
michael@0 | 29 | |
michael@0 | 30 | #ifdef HAVE_CONFIG_H |
michael@0 | 31 | #include "config.h" |
michael@0 | 32 | #endif |
michael@0 | 33 | |
michael@0 | 34 | #define CELT_C |
michael@0 | 35 | |
michael@0 | 36 | #include "os_support.h" |
michael@0 | 37 | #include "mdct.h" |
michael@0 | 38 | #include <math.h> |
michael@0 | 39 | #include "celt.h" |
michael@0 | 40 | #include "pitch.h" |
michael@0 | 41 | #include "bands.h" |
michael@0 | 42 | #include "modes.h" |
michael@0 | 43 | #include "entcode.h" |
michael@0 | 44 | #include "quant_bands.h" |
michael@0 | 45 | #include "rate.h" |
michael@0 | 46 | #include "stack_alloc.h" |
michael@0 | 47 | #include "mathops.h" |
michael@0 | 48 | #include "float_cast.h" |
michael@0 | 49 | #include <stdarg.h> |
michael@0 | 50 | #include "celt_lpc.h" |
michael@0 | 51 | #include "vq.h" |
michael@0 | 52 | |
michael@0 | 53 | #ifndef PACKAGE_VERSION |
michael@0 | 54 | #define PACKAGE_VERSION "unknown" |
michael@0 | 55 | #endif |
michael@0 | 56 | |
michael@0 | 57 | |
michael@0 | 58 | int resampling_factor(opus_int32 rate) |
michael@0 | 59 | { |
michael@0 | 60 | int ret; |
michael@0 | 61 | switch (rate) |
michael@0 | 62 | { |
michael@0 | 63 | case 48000: |
michael@0 | 64 | ret = 1; |
michael@0 | 65 | break; |
michael@0 | 66 | case 24000: |
michael@0 | 67 | ret = 2; |
michael@0 | 68 | break; |
michael@0 | 69 | case 16000: |
michael@0 | 70 | ret = 3; |
michael@0 | 71 | break; |
michael@0 | 72 | case 12000: |
michael@0 | 73 | ret = 4; |
michael@0 | 74 | break; |
michael@0 | 75 | case 8000: |
michael@0 | 76 | ret = 6; |
michael@0 | 77 | break; |
michael@0 | 78 | default: |
michael@0 | 79 | #ifndef CUSTOM_MODES |
michael@0 | 80 | celt_assert(0); |
michael@0 | 81 | #endif |
michael@0 | 82 | ret = 0; |
michael@0 | 83 | break; |
michael@0 | 84 | } |
michael@0 | 85 | return ret; |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | #ifndef OVERRIDE_COMB_FILTER_CONST |
michael@0 | 89 | static void comb_filter_const(opus_val32 *y, opus_val32 *x, int T, int N, |
michael@0 | 90 | opus_val16 g10, opus_val16 g11, opus_val16 g12) |
michael@0 | 91 | { |
michael@0 | 92 | opus_val32 x0, x1, x2, x3, x4; |
michael@0 | 93 | int i; |
michael@0 | 94 | x4 = x[-T-2]; |
michael@0 | 95 | x3 = x[-T-1]; |
michael@0 | 96 | x2 = x[-T]; |
michael@0 | 97 | x1 = x[-T+1]; |
michael@0 | 98 | for (i=0;i<N;i++) |
michael@0 | 99 | { |
michael@0 | 100 | x0=x[i-T+2]; |
michael@0 | 101 | y[i] = x[i] |
michael@0 | 102 | + MULT16_32_Q15(g10,x2) |
michael@0 | 103 | + MULT16_32_Q15(g11,ADD32(x1,x3)) |
michael@0 | 104 | + MULT16_32_Q15(g12,ADD32(x0,x4)); |
michael@0 | 105 | x4=x3; |
michael@0 | 106 | x3=x2; |
michael@0 | 107 | x2=x1; |
michael@0 | 108 | x1=x0; |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | } |
michael@0 | 112 | #endif |
michael@0 | 113 | |
michael@0 | 114 | void comb_filter(opus_val32 *y, opus_val32 *x, int T0, int T1, int N, |
michael@0 | 115 | opus_val16 g0, opus_val16 g1, int tapset0, int tapset1, |
michael@0 | 116 | const opus_val16 *window, int overlap) |
michael@0 | 117 | { |
michael@0 | 118 | int i; |
michael@0 | 119 | /* printf ("%d %d %f %f\n", T0, T1, g0, g1); */ |
michael@0 | 120 | opus_val16 g00, g01, g02, g10, g11, g12; |
michael@0 | 121 | opus_val32 x0, x1, x2, x3, x4; |
michael@0 | 122 | static const opus_val16 gains[3][3] = { |
michael@0 | 123 | {QCONST16(0.3066406250f, 15), QCONST16(0.2170410156f, 15), QCONST16(0.1296386719f, 15)}, |
michael@0 | 124 | {QCONST16(0.4638671875f, 15), QCONST16(0.2680664062f, 15), QCONST16(0.f, 15)}, |
michael@0 | 125 | {QCONST16(0.7998046875f, 15), QCONST16(0.1000976562f, 15), QCONST16(0.f, 15)}}; |
michael@0 | 126 | |
michael@0 | 127 | if (g0==0 && g1==0) |
michael@0 | 128 | { |
michael@0 | 129 | /* OPT: Happens to work without the OPUS_MOVE(), but only because the current encoder already copies x to y */ |
michael@0 | 130 | if (x!=y) |
michael@0 | 131 | OPUS_MOVE(y, x, N); |
michael@0 | 132 | return; |
michael@0 | 133 | } |
michael@0 | 134 | g00 = MULT16_16_Q15(g0, gains[tapset0][0]); |
michael@0 | 135 | g01 = MULT16_16_Q15(g0, gains[tapset0][1]); |
michael@0 | 136 | g02 = MULT16_16_Q15(g0, gains[tapset0][2]); |
michael@0 | 137 | g10 = MULT16_16_Q15(g1, gains[tapset1][0]); |
michael@0 | 138 | g11 = MULT16_16_Q15(g1, gains[tapset1][1]); |
michael@0 | 139 | g12 = MULT16_16_Q15(g1, gains[tapset1][2]); |
michael@0 | 140 | x1 = x[-T1+1]; |
michael@0 | 141 | x2 = x[-T1 ]; |
michael@0 | 142 | x3 = x[-T1-1]; |
michael@0 | 143 | x4 = x[-T1-2]; |
michael@0 | 144 | for (i=0;i<overlap;i++) |
michael@0 | 145 | { |
michael@0 | 146 | opus_val16 f; |
michael@0 | 147 | x0=x[i-T1+2]; |
michael@0 | 148 | f = MULT16_16_Q15(window[i],window[i]); |
michael@0 | 149 | y[i] = x[i] |
michael@0 | 150 | + MULT16_32_Q15(MULT16_16_Q15((Q15ONE-f),g00),x[i-T0]) |
michael@0 | 151 | + MULT16_32_Q15(MULT16_16_Q15((Q15ONE-f),g01),ADD32(x[i-T0+1],x[i-T0-1])) |
michael@0 | 152 | + MULT16_32_Q15(MULT16_16_Q15((Q15ONE-f),g02),ADD32(x[i-T0+2],x[i-T0-2])) |
michael@0 | 153 | + MULT16_32_Q15(MULT16_16_Q15(f,g10),x2) |
michael@0 | 154 | + MULT16_32_Q15(MULT16_16_Q15(f,g11),ADD32(x1,x3)) |
michael@0 | 155 | + MULT16_32_Q15(MULT16_16_Q15(f,g12),ADD32(x0,x4)); |
michael@0 | 156 | x4=x3; |
michael@0 | 157 | x3=x2; |
michael@0 | 158 | x2=x1; |
michael@0 | 159 | x1=x0; |
michael@0 | 160 | |
michael@0 | 161 | } |
michael@0 | 162 | if (g1==0) |
michael@0 | 163 | { |
michael@0 | 164 | /* OPT: Happens to work without the OPUS_MOVE(), but only because the current encoder already copies x to y */ |
michael@0 | 165 | if (x!=y) |
michael@0 | 166 | OPUS_MOVE(y+overlap, x+overlap, N-overlap); |
michael@0 | 167 | return; |
michael@0 | 168 | } |
michael@0 | 169 | |
michael@0 | 170 | /* Compute the part with the constant filter. */ |
michael@0 | 171 | comb_filter_const(y+i, x+i, T1, N-i, g10, g11, g12); |
michael@0 | 172 | } |
michael@0 | 173 | |
michael@0 | 174 | const signed char tf_select_table[4][8] = { |
michael@0 | 175 | {0, -1, 0, -1, 0,-1, 0,-1}, |
michael@0 | 176 | {0, -1, 0, -2, 1, 0, 1,-1}, |
michael@0 | 177 | {0, -2, 0, -3, 2, 0, 1,-1}, |
michael@0 | 178 | {0, -2, 0, -3, 3, 0, 1,-1}, |
michael@0 | 179 | }; |
michael@0 | 180 | |
michael@0 | 181 | |
michael@0 | 182 | void init_caps(const CELTMode *m,int *cap,int LM,int C) |
michael@0 | 183 | { |
michael@0 | 184 | int i; |
michael@0 | 185 | for (i=0;i<m->nbEBands;i++) |
michael@0 | 186 | { |
michael@0 | 187 | int N; |
michael@0 | 188 | N=(m->eBands[i+1]-m->eBands[i])<<LM; |
michael@0 | 189 | cap[i] = (m->cache.caps[m->nbEBands*(2*LM+C-1)+i]+64)*C*N>>2; |
michael@0 | 190 | } |
michael@0 | 191 | } |
michael@0 | 192 | |
michael@0 | 193 | |
michael@0 | 194 | |
michael@0 | 195 | const char *opus_strerror(int error) |
michael@0 | 196 | { |
michael@0 | 197 | static const char * const error_strings[8] = { |
michael@0 | 198 | "success", |
michael@0 | 199 | "invalid argument", |
michael@0 | 200 | "buffer too small", |
michael@0 | 201 | "internal error", |
michael@0 | 202 | "corrupted stream", |
michael@0 | 203 | "request not implemented", |
michael@0 | 204 | "invalid state", |
michael@0 | 205 | "memory allocation failed" |
michael@0 | 206 | }; |
michael@0 | 207 | if (error > 0 || error < -7) |
michael@0 | 208 | return "unknown error"; |
michael@0 | 209 | else |
michael@0 | 210 | return error_strings[-error]; |
michael@0 | 211 | } |
michael@0 | 212 | |
michael@0 | 213 | const char *opus_get_version_string(void) |
michael@0 | 214 | { |
michael@0 | 215 | return "libopus " PACKAGE_VERSION |
michael@0 | 216 | #ifdef FIXED_POINT |
michael@0 | 217 | "-fixed" |
michael@0 | 218 | #endif |
michael@0 | 219 | #ifdef FUZZING |
michael@0 | 220 | "-fuzzing" |
michael@0 | 221 | #endif |
michael@0 | 222 | ; |
michael@0 | 223 | } |