1c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk/* 2c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk * Copyright (C) 2017 The Android Open Source Project 3c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk * 4c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk * Licensed under the Apache License, Version 2.0 (the "License"); 5c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk * you may not use this file except in compliance with the License. 6c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk * You may obtain a copy of the License at 7c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk * 8c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk * http://www.apache.org/licenses/LICENSE-2.0 9c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk * 10c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk * Unless required by applicable law or agreed to in writing, software 11c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk * distributed under the License is distributed on an "AS IS" BASIS, 12c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk * See the License for the specific language governing permissions and 14c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk * limitations under the License. 15c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk */ 16c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk 17c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk#ifndef AAUDIO_FIXED_BLOCK_ADAPTER_H 18c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk#define AAUDIO_FIXED_BLOCK_ADAPTER_H 19c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk 20c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk#include <stdio.h> 21c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk 22c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk/** 23c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk * Interface for a class that needs fixed-size blocks. 24c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk */ 25c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burkclass FixedBlockProcessor { 26c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burkpublic: 27c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk virtual ~FixedBlockProcessor() = default; 28c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk virtual int32_t onProcessFixedBlock(uint8_t *buffer, int32_t numBytes) = 0; 29c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk}; 30c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk 31c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk/** 32c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk * Base class for a variable-to-fixed-size block adapter. 33c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk */ 34c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burkclass FixedBlockAdapter 35c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk{ 36c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burkpublic: 37c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk FixedBlockAdapter(FixedBlockProcessor &fixedBlockProcessor) 38c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk : mFixedBlockProcessor(fixedBlockProcessor) {} 39c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk 40c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk virtual ~FixedBlockAdapter(); 41c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk 42c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk /** 43c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk * Allocate internal resources needed for buffering data. 44c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk */ 45c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk virtual int32_t open(int32_t bytesPerFixedBlock); 46c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk 47c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk /** 48c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk * Note that if the fixed-sized blocks must be aligned, then the variable-sized blocks 49c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk * must have the same alignment. 50c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk * For example, if the fixed-size blocks must be a multiple of 8, then the variable-sized 51c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk * blocks must also be a multiple of 8. 52c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk * 53c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk * @param buffer 54c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk * @param numBytes 55c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk * @return zero if OK or a non-zero code 56c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk */ 57c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk virtual int32_t processVariableBlock(uint8_t *buffer, int32_t numBytes) = 0; 58c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk 59c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk /** 60c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk * Free internal resources. 61c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk */ 62c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk int32_t close(); 63c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk 64c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burkprotected: 65c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk FixedBlockProcessor &mFixedBlockProcessor; 66c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk uint8_t *mStorage = nullptr; // Store data here while assembling buffers. 67c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk int32_t mSize = 0; // Size in bytes of the fixed size buffer. 68c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk int32_t mPosition = 0; // Offset of the last byte read or written. 69c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk}; 70c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk 71c8f372c22a0e4c667a3ad3c1ec569032574c1d64Phil Burk#endif /* AAUDIO_FIXED_BLOCK_ADAPTER_H */ 72