blob: 33a253e48ffbbb301734ffd4a953863ddff726ee [file] [log] [blame]
Phil Burkfd911c12017-01-03 17:15:39 -08001/*
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#define LOG_TAG "FifoControllerBase"
18//#define LOG_NDEBUG 0
19#include <utils/Log.h>
20
21#include <stdint.h>
22#include "FifoControllerBase.h"
23
24FifoControllerBase::FifoControllerBase(fifo_frames_t capacity, fifo_frames_t threshold)
25 : mCapacity(capacity)
26 , mThreshold(threshold)
27{
28}
29
30FifoControllerBase::~FifoControllerBase() {
31}
32
33fifo_frames_t FifoControllerBase::getFullFramesAvailable() {
34 return (fifo_frames_t) (getWriteCounter() - getReadCounter());
35}
36
37fifo_frames_t FifoControllerBase::getReadIndex() {
38 // % works with non-power of two sizes
39 return (fifo_frames_t) (getReadCounter() % mCapacity);
40}
41
42void FifoControllerBase::advanceReadIndex(fifo_frames_t numFrames) {
43 setReadCounter(getReadCounter() + numFrames);
44}
45
46fifo_frames_t FifoControllerBase::getEmptyFramesAvailable() {
47 return (int32_t)(mThreshold - getFullFramesAvailable());
48}
49
50fifo_frames_t FifoControllerBase::getWriteIndex() {
51 // % works with non-power of two sizes
52 return (fifo_frames_t) (getWriteCounter() % mCapacity);
53}
54
55void FifoControllerBase::advanceWriteIndex(fifo_frames_t numFrames) {
56 setWriteCounter(getWriteCounter() + numFrames);
57}
58
59void FifoControllerBase::setThreshold(fifo_frames_t threshold) {
60 mThreshold = threshold;
61}