• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef FRAMEWORKS_EX_VARIABLESPEED_JNI_DECODE_BUFFER_H_
18 #define FRAMEWORKS_EX_VARIABLESPEED_JNI_DECODE_BUFFER_H_
19 
20 #include <integral_types.h>
21 #include <macros.h>
22 #include <stdlib.h>
23 #include <vector>
24 
25 // DecodeBuffer is used to store arrays of int16 values for audio.
26 //
27 // This class is not thread-safe.  You should provide your own
28 // synchronization if you wish to use it from multiple threads.
29 class DecodeBuffer {
30  public:
31   DecodeBuffer(size_t sizeOfOneBuffer, size_t maxSize);
32   virtual ~DecodeBuffer();
33   size_t GetSizeInBytes() const;
34   void AddData(int8_t* pointer, size_t lengthInBytes);
35   void Clear();
36   void AdvanceHeadPointerShorts(size_t numberOfShorts);
37   int16 GetAtIndex(size_t index);
38   bool IsTooLarge() const;
39   size_t GetTotalAdvancedCount() const;
40 
41  private:
42   void PushValue(int16 value);
43 
44   size_t sizeOfOneBuffer_;
45   size_t maxSize_;
46   size_t start_;
47   size_t end_;
48   size_t advancedCount_;
49   // This vector isn't ideal because we perform a number of queue-like
50   // operations: namely removing from the front and appending at the back.
51   // However we also need constant-time access to the elements of this
52   // vector, and therefore it's not good enough to use a std::queue.
53   // In practice this data structure choice doesn't seem to be a bottleneck.
54   std::vector<int16*> data_;
55 
56   DISALLOW_COPY_AND_ASSIGN(DecodeBuffer);
57 };
58 
59 #endif  // FRAMEWORKS_EX_VARIABLESPEED_JNI_DECODE_BUFFER_H_
60