1*05767d91SRobert Wu /* 2*05767d91SRobert Wu * Copyright (C) 2017 The Android Open Source Project 3*05767d91SRobert Wu * 4*05767d91SRobert Wu * Licensed under the Apache License, Version 2.0 (the "License"); 5*05767d91SRobert Wu * you may not use this file except in compliance with the License. 6*05767d91SRobert Wu * You may obtain a copy of the License at 7*05767d91SRobert Wu * 8*05767d91SRobert Wu * http://www.apache.org/licenses/LICENSE-2.0 9*05767d91SRobert Wu * 10*05767d91SRobert Wu * Unless required by applicable law or agreed to in writing, software 11*05767d91SRobert Wu * distributed under the License is distributed on an "AS IS" BASIS, 12*05767d91SRobert Wu * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*05767d91SRobert Wu * See the License for the specific language governing permissions and 14*05767d91SRobert Wu * limitations under the License. 15*05767d91SRobert Wu */ 16*05767d91SRobert Wu 17*05767d91SRobert Wu #ifndef AAUDIO_FIXED_BLOCK_WRITER_H 18*05767d91SRobert Wu #define AAUDIO_FIXED_BLOCK_WRITER_H 19*05767d91SRobert Wu 20*05767d91SRobert Wu #include <stdint.h> 21*05767d91SRobert Wu 22*05767d91SRobert Wu #include "FixedBlockAdapter.h" 23*05767d91SRobert Wu 24*05767d91SRobert Wu /** 25*05767d91SRobert Wu * This can be used to convert a push data flow from variable sized buffers to fixed sized buffers. 26*05767d91SRobert Wu * An example would be an audio input callback. 27*05767d91SRobert Wu */ 28*05767d91SRobert Wu class FixedBlockWriter : public FixedBlockAdapter 29*05767d91SRobert Wu { 30*05767d91SRobert Wu public: 31*05767d91SRobert Wu FixedBlockWriter(FixedBlockProcessor &fixedBlockProcessor); 32*05767d91SRobert Wu 33*05767d91SRobert Wu virtual ~FixedBlockWriter() = default; 34*05767d91SRobert Wu 35*05767d91SRobert Wu /** 36*05767d91SRobert Wu * Write from a variable sized block. 37*05767d91SRobert Wu * 38*05767d91SRobert Wu * Note that if the fixed-sized blocks must be aligned, then the variable-sized blocks 39*05767d91SRobert Wu * must have the same alignment. 40*05767d91SRobert Wu * For example, if the fixed-size blocks must be a multiple of 8, then the variable-sized 41*05767d91SRobert Wu * blocks must also be a multiple of 8. 42*05767d91SRobert Wu * 43*05767d91SRobert Wu * @param buffer 44*05767d91SRobert Wu * @param numBytes 45*05767d91SRobert Wu * @return Number of bytes written or a negative error code. 46*05767d91SRobert Wu */ 47*05767d91SRobert Wu int32_t write(uint8_t *buffer, int32_t numBytes); 48*05767d91SRobert Wu 49*05767d91SRobert Wu private: 50*05767d91SRobert Wu 51*05767d91SRobert Wu int32_t writeToStorage(uint8_t *buffer, int32_t numBytes); 52*05767d91SRobert Wu }; 53*05767d91SRobert Wu 54*05767d91SRobert Wu #endif /* AAUDIO_FIXED_BLOCK_WRITER_H */ 55