FifoBuffer.h revision f53e613b3dedab3ecada2c93d8846233c442d129
1/* 2 * Copyright 2015 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 FIFO_FIFO_BUFFER_H 18#define FIFO_FIFO_BUFFER_H 19 20#include <stdint.h> 21 22#include "FifoControllerBase.h" 23 24class FifoBuffer { 25public: 26 FifoBuffer(int32_t bytesPerFrame, fifo_frames_t capacityInFrames); 27 28 FifoBuffer(int32_t bytesPerFrame, 29 fifo_frames_t capacityInFrames, 30 fifo_counter_t * readCounterAddress, 31 fifo_counter_t * writeCounterAddress, 32 void * dataStorageAddress); 33 34 ~FifoBuffer(); 35 36 int32_t convertFramesToBytes(fifo_frames_t frames); 37 38 fifo_frames_t read(void *destination, fifo_frames_t framesToRead); 39 40 fifo_frames_t write(const void *source, fifo_frames_t framesToWrite); 41 42 fifo_frames_t getThreshold(); 43 void setThreshold(fifo_frames_t threshold); 44 45 fifo_frames_t getBufferCapacityInFrames(); 46 47 fifo_frames_t readNow(void *buffer, fifo_frames_t numFrames); 48 49 int64_t getNextReadTime(int32_t frameRate); 50 51 int32_t getUnderrunCount() const { return mUnderrunCount; } 52 53 FifoControllerBase *getFifoControllerBase() { return mFifo; } 54 55 int32_t getBytesPerFrame() { 56 return mBytesPerFrame; 57 } 58 59 fifo_counter_t getReadCounter() { 60 return mFifo->getReadCounter(); 61 } 62 63 void setReadCounter(fifo_counter_t n) { 64 mFifo->setReadCounter(n); 65 } 66 67 fifo_counter_t getWriteCounter() { 68 return mFifo->getWriteCounter(); 69 } 70 71 void setWriteCounter(fifo_counter_t n) { 72 mFifo->setWriteCounter(n); 73 } 74 75private: 76 const fifo_frames_t mFrameCapacity; 77 const int32_t mBytesPerFrame; 78 uint8_t * mStorage; 79 bool mStorageOwned; // did this object allocate the storage? 80 FifoControllerBase *mFifo; 81 fifo_counter_t mFramesReadCount; 82 fifo_counter_t mFramesUnderrunCount; 83 int32_t mUnderrunCount; // need? just use frames 84 int32_t mLastReadSize; 85}; 86 87#endif //FIFO_FIFO_BUFFER_H 88