Phil Burk | bd76d6a | 2019-06-01 08:48:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 AAUDIO_FIXED_BLOCK_READER_H |
| 18 | #define AAUDIO_FIXED_BLOCK_READER_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | |
| 22 | #include "FixedBlockAdapter.h" |
| 23 | |
| 24 | /** |
| 25 | * Read from a fixed-size block to a variable sized block. |
| 26 | * |
| 27 | * This can be used to convert a pull data flow from fixed sized buffers to variable sized buffers. |
| 28 | * An example would be an audio output callback that reads from the app. |
| 29 | */ |
| 30 | class FixedBlockReader : public FixedBlockAdapter |
| 31 | { |
| 32 | public: |
| 33 | FixedBlockReader(FixedBlockProcessor &fixedBlockProcessor); |
| 34 | |
| 35 | virtual ~FixedBlockReader() = default; |
| 36 | |
| 37 | int32_t open(int32_t bytesPerFixedBlock) override; |
| 38 | |
Phil Burk | bd76d6a | 2019-06-01 08:48:03 -0700 | [diff] [blame] | 39 | /** |
| 40 | * Read into a variable sized block. |
Phil Burk | 2da4a84 | 2019-08-16 12:15:23 -0700 | [diff] [blame] | 41 | * |
| 42 | * Note that if the fixed-sized blocks must be aligned, then the variable-sized blocks |
| 43 | * must have the same alignment. |
| 44 | * For example, if the fixed-size blocks must be a multiple of 8, then the variable-sized |
| 45 | * blocks must also be a multiple of 8. |
| 46 | * |
| 47 | * @param buffer |
| 48 | * @param numBytes |
| 49 | * @return Number of bytes read or a negative error code. |
Phil Burk | bd76d6a | 2019-06-01 08:48:03 -0700 | [diff] [blame] | 50 | */ |
Phil Burk | 2da4a84 | 2019-08-16 12:15:23 -0700 | [diff] [blame] | 51 | int32_t read(uint8_t *buffer, int32_t numBytes); |
Phil Burk | 561cda3 | 2019-07-11 12:40:52 -0700 | [diff] [blame] | 52 | |
| 53 | private: |
Phil Burk | 2da4a84 | 2019-08-16 12:15:23 -0700 | [diff] [blame] | 54 | int32_t readFromStorage(uint8_t *buffer, int32_t numBytes); |
| 55 | |
Phil Burk | 561cda3 | 2019-07-11 12:40:52 -0700 | [diff] [blame] | 56 | int32_t mValid = 0; // Number of valid bytes in mStorage. |
Phil Burk | bd76d6a | 2019-06-01 08:48:03 -0700 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | |
| 60 | #endif /* AAUDIO_FIXED_BLOCK_READER_H */ |