Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
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 | /// |
michael@0 | 3 | /// 'FIFOSamplePipe' : An abstract base class for classes that manipulate sound |
michael@0 | 4 | /// samples by operating like a first-in-first-out pipe: New samples are fed |
michael@0 | 5 | /// into one end of the pipe with the 'putSamples' function, and the processed |
michael@0 | 6 | /// samples are received from the other end with the 'receiveSamples' function. |
michael@0 | 7 | /// |
michael@0 | 8 | /// 'FIFOProcessor' : A base class for classes the do signal processing with |
michael@0 | 9 | /// the samples while operating like a first-in-first-out pipe. When samples |
michael@0 | 10 | /// are input with the 'putSamples' function, the class processes them |
michael@0 | 11 | /// and moves the processed samples to the given 'output' pipe object, which |
michael@0 | 12 | /// may be either another processing stage, or a fifo sample buffer object. |
michael@0 | 13 | /// |
michael@0 | 14 | /// Author : Copyright (c) Olli Parviainen |
michael@0 | 15 | /// Author e-mail : oparviai 'at' iki.fi |
michael@0 | 16 | /// SoundTouch WWW: http://www.surina.net/soundtouch |
michael@0 | 17 | /// |
michael@0 | 18 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 19 | // |
michael@0 | 20 | // Last changed : $Date: 2012-06-13 14:29:53 -0500 (Wed, 13 Jun 2012) $ |
michael@0 | 21 | // File revision : $Revision: 4 $ |
michael@0 | 22 | // |
michael@0 | 23 | // $Id: FIFOSamplePipe.h 143 2012-06-13 19:29:53Z oparviai $ |
michael@0 | 24 | // |
michael@0 | 25 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 26 | // |
michael@0 | 27 | // License : |
michael@0 | 28 | // |
michael@0 | 29 | // SoundTouch audio processing library |
michael@0 | 30 | // Copyright (c) Olli Parviainen |
michael@0 | 31 | // |
michael@0 | 32 | // This library is free software; you can redistribute it and/or |
michael@0 | 33 | // modify it under the terms of the GNU Lesser General Public |
michael@0 | 34 | // License as published by the Free Software Foundation; either |
michael@0 | 35 | // version 2.1 of the License, or (at your option) any later version. |
michael@0 | 36 | // |
michael@0 | 37 | // This library is distributed in the hope that it will be useful, |
michael@0 | 38 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
michael@0 | 39 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
michael@0 | 40 | // Lesser General Public License for more details. |
michael@0 | 41 | // |
michael@0 | 42 | // You should have received a copy of the GNU Lesser General Public |
michael@0 | 43 | // License along with this library; if not, write to the Free Software |
michael@0 | 44 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
michael@0 | 45 | // |
michael@0 | 46 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 47 | |
michael@0 | 48 | #ifndef FIFOSamplePipe_H |
michael@0 | 49 | #define FIFOSamplePipe_H |
michael@0 | 50 | |
michael@0 | 51 | #include <assert.h> |
michael@0 | 52 | #include <stdlib.h> |
michael@0 | 53 | #include "STTypes.h" |
michael@0 | 54 | |
michael@0 | 55 | namespace soundtouch |
michael@0 | 56 | { |
michael@0 | 57 | |
michael@0 | 58 | /// Abstract base class for FIFO (first-in-first-out) sample processing classes. |
michael@0 | 59 | class FIFOSamplePipe |
michael@0 | 60 | { |
michael@0 | 61 | public: |
michael@0 | 62 | // virtual default destructor |
michael@0 | 63 | virtual ~FIFOSamplePipe() {} |
michael@0 | 64 | |
michael@0 | 65 | |
michael@0 | 66 | /// Returns a pointer to the beginning of the output samples. |
michael@0 | 67 | /// This function is provided for accessing the output samples directly. |
michael@0 | 68 | /// Please be careful for not to corrupt the book-keeping! |
michael@0 | 69 | /// |
michael@0 | 70 | /// When using this function to output samples, also remember to 'remove' the |
michael@0 | 71 | /// output samples from the buffer by calling the |
michael@0 | 72 | /// 'receiveSamples(numSamples)' function |
michael@0 | 73 | virtual SAMPLETYPE *ptrBegin() = 0; |
michael@0 | 74 | |
michael@0 | 75 | /// Adds 'numSamples' pcs of samples from the 'samples' memory position to |
michael@0 | 76 | /// the sample buffer. |
michael@0 | 77 | virtual void putSamples(const SAMPLETYPE *samples, ///< Pointer to samples. |
michael@0 | 78 | uint numSamples ///< Number of samples to insert. |
michael@0 | 79 | ) = 0; |
michael@0 | 80 | |
michael@0 | 81 | |
michael@0 | 82 | // Moves samples from the 'other' pipe instance to this instance. |
michael@0 | 83 | void moveSamples(FIFOSamplePipe &other ///< Other pipe instance where from the receive the data. |
michael@0 | 84 | ) |
michael@0 | 85 | { |
michael@0 | 86 | int oNumSamples = other.numSamples(); |
michael@0 | 87 | |
michael@0 | 88 | putSamples(other.ptrBegin(), oNumSamples); |
michael@0 | 89 | other.receiveSamples(oNumSamples); |
michael@0 | 90 | }; |
michael@0 | 91 | |
michael@0 | 92 | /// Output samples from beginning of the sample buffer. Copies requested samples to |
michael@0 | 93 | /// output buffer and removes them from the sample buffer. If there are less than |
michael@0 | 94 | /// 'numsample' samples in the buffer, returns all that available. |
michael@0 | 95 | /// |
michael@0 | 96 | /// \return Number of samples returned. |
michael@0 | 97 | virtual uint receiveSamples(SAMPLETYPE *output, ///< Buffer where to copy output samples. |
michael@0 | 98 | uint maxSamples ///< How many samples to receive at max. |
michael@0 | 99 | ) = 0; |
michael@0 | 100 | |
michael@0 | 101 | /// Adjusts book-keeping so that given number of samples are removed from beginning of the |
michael@0 | 102 | /// sample buffer without copying them anywhere. |
michael@0 | 103 | /// |
michael@0 | 104 | /// Used to reduce the number of samples in the buffer when accessing the sample buffer directly |
michael@0 | 105 | /// with 'ptrBegin' function. |
michael@0 | 106 | virtual uint receiveSamples(uint maxSamples ///< Remove this many samples from the beginning of pipe. |
michael@0 | 107 | ) = 0; |
michael@0 | 108 | |
michael@0 | 109 | /// Returns number of samples currently available. |
michael@0 | 110 | virtual uint numSamples() const = 0; |
michael@0 | 111 | |
michael@0 | 112 | // Returns nonzero if there aren't any samples available for outputting. |
michael@0 | 113 | virtual int isEmpty() const = 0; |
michael@0 | 114 | |
michael@0 | 115 | /// Clears all the samples. |
michael@0 | 116 | virtual void clear() = 0; |
michael@0 | 117 | |
michael@0 | 118 | /// allow trimming (downwards) amount of samples in pipeline. |
michael@0 | 119 | /// Returns adjusted amount of samples |
michael@0 | 120 | virtual uint adjustAmountOfSamples(uint numSamples) = 0; |
michael@0 | 121 | |
michael@0 | 122 | }; |
michael@0 | 123 | |
michael@0 | 124 | |
michael@0 | 125 | |
michael@0 | 126 | /// Base-class for sound processing routines working in FIFO principle. With this base |
michael@0 | 127 | /// class it's easy to implement sound processing stages that can be chained together, |
michael@0 | 128 | /// so that samples that are fed into beginning of the pipe automatically go through |
michael@0 | 129 | /// all the processing stages. |
michael@0 | 130 | /// |
michael@0 | 131 | /// When samples are input to this class, they're first processed and then put to |
michael@0 | 132 | /// the FIFO pipe that's defined as output of this class. This output pipe can be |
michael@0 | 133 | /// either other processing stage or a FIFO sample buffer. |
michael@0 | 134 | class FIFOProcessor :public FIFOSamplePipe |
michael@0 | 135 | { |
michael@0 | 136 | protected: |
michael@0 | 137 | /// Internal pipe where processed samples are put. |
michael@0 | 138 | FIFOSamplePipe *output; |
michael@0 | 139 | |
michael@0 | 140 | /// Sets output pipe. |
michael@0 | 141 | void setOutPipe(FIFOSamplePipe *pOutput) |
michael@0 | 142 | { |
michael@0 | 143 | assert(output == NULL); |
michael@0 | 144 | assert(pOutput != NULL); |
michael@0 | 145 | output = pOutput; |
michael@0 | 146 | } |
michael@0 | 147 | |
michael@0 | 148 | |
michael@0 | 149 | /// Constructor. Doesn't define output pipe; it has to be set be |
michael@0 | 150 | /// 'setOutPipe' function. |
michael@0 | 151 | FIFOProcessor() |
michael@0 | 152 | { |
michael@0 | 153 | output = NULL; |
michael@0 | 154 | } |
michael@0 | 155 | |
michael@0 | 156 | |
michael@0 | 157 | /// Constructor. Configures output pipe. |
michael@0 | 158 | FIFOProcessor(FIFOSamplePipe *pOutput ///< Output pipe. |
michael@0 | 159 | ) |
michael@0 | 160 | { |
michael@0 | 161 | output = pOutput; |
michael@0 | 162 | } |
michael@0 | 163 | |
michael@0 | 164 | |
michael@0 | 165 | /// Destructor. |
michael@0 | 166 | virtual ~FIFOProcessor() |
michael@0 | 167 | { |
michael@0 | 168 | } |
michael@0 | 169 | |
michael@0 | 170 | |
michael@0 | 171 | /// Returns a pointer to the beginning of the output samples. |
michael@0 | 172 | /// This function is provided for accessing the output samples directly. |
michael@0 | 173 | /// Please be careful for not to corrupt the book-keeping! |
michael@0 | 174 | /// |
michael@0 | 175 | /// When using this function to output samples, also remember to 'remove' the |
michael@0 | 176 | /// output samples from the buffer by calling the |
michael@0 | 177 | /// 'receiveSamples(numSamples)' function |
michael@0 | 178 | virtual SAMPLETYPE *ptrBegin() |
michael@0 | 179 | { |
michael@0 | 180 | return output->ptrBegin(); |
michael@0 | 181 | } |
michael@0 | 182 | |
michael@0 | 183 | public: |
michael@0 | 184 | |
michael@0 | 185 | /// Output samples from beginning of the sample buffer. Copies requested samples to |
michael@0 | 186 | /// output buffer and removes them from the sample buffer. If there are less than |
michael@0 | 187 | /// 'numsample' samples in the buffer, returns all that available. |
michael@0 | 188 | /// |
michael@0 | 189 | /// \return Number of samples returned. |
michael@0 | 190 | virtual uint receiveSamples(SAMPLETYPE *outBuffer, ///< Buffer where to copy output samples. |
michael@0 | 191 | uint maxSamples ///< How many samples to receive at max. |
michael@0 | 192 | ) |
michael@0 | 193 | { |
michael@0 | 194 | return output->receiveSamples(outBuffer, maxSamples); |
michael@0 | 195 | } |
michael@0 | 196 | |
michael@0 | 197 | |
michael@0 | 198 | /// Adjusts book-keeping so that given number of samples are removed from beginning of the |
michael@0 | 199 | /// sample buffer without copying them anywhere. |
michael@0 | 200 | /// |
michael@0 | 201 | /// Used to reduce the number of samples in the buffer when accessing the sample buffer directly |
michael@0 | 202 | /// with 'ptrBegin' function. |
michael@0 | 203 | virtual uint receiveSamples(uint maxSamples ///< Remove this many samples from the beginning of pipe. |
michael@0 | 204 | ) |
michael@0 | 205 | { |
michael@0 | 206 | return output->receiveSamples(maxSamples); |
michael@0 | 207 | } |
michael@0 | 208 | |
michael@0 | 209 | |
michael@0 | 210 | /// Returns number of samples currently available. |
michael@0 | 211 | virtual uint numSamples() const |
michael@0 | 212 | { |
michael@0 | 213 | return output->numSamples(); |
michael@0 | 214 | } |
michael@0 | 215 | |
michael@0 | 216 | |
michael@0 | 217 | /// Returns nonzero if there aren't any samples available for outputting. |
michael@0 | 218 | virtual int isEmpty() const |
michael@0 | 219 | { |
michael@0 | 220 | return output->isEmpty(); |
michael@0 | 221 | } |
michael@0 | 222 | |
michael@0 | 223 | /// allow trimming (downwards) amount of samples in pipeline. |
michael@0 | 224 | /// Returns adjusted amount of samples |
michael@0 | 225 | virtual uint adjustAmountOfSamples(uint numSamples) |
michael@0 | 226 | { |
michael@0 | 227 | return output->adjustAmountOfSamples(numSamples); |
michael@0 | 228 | } |
michael@0 | 229 | |
michael@0 | 230 | }; |
michael@0 | 231 | |
michael@0 | 232 | } |
michael@0 | 233 | |
michael@0 | 234 | #endif |