1 /* 2 * Copyright 2024 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 __WAVCAPTUREOUTPUTSTREAM_H__ 18 #define __WAVCAPTUREOUTPUTSTREAM_H__ 19 20 #include "WaveFileWriter.h" 21 22 #include <vector> 23 24 class WavCaptureOutputStream : public WaveFileOutputStream { 25 public: WavCaptureOutputStream()26 WavCaptureOutputStream() { 27 } 28 init()29 void init() { 30 mData.clear(); 31 } 32 write(uint8_t b)33 void write(uint8_t b) override { 34 mData.push_back(b); 35 } 36 write(uint8_t * bytes,size_t numBytes)37 void write(uint8_t* bytes, size_t numBytes) { 38 while (numBytes-- > 0) { 39 mData.push_back(*bytes++); 40 } 41 } 42 length()43 int32_t length() { 44 return (int32_t) mData.size(); 45 } 46 getData()47 uint8_t *getData() { 48 return mData.data(); 49 } 50 abandonData()51 void abandonData() { 52 mData.clear(); 53 } 54 private: 55 std::vector<uint8_t> mData; 56 }; 57 58 #endif 59