Loading media/libaaudio/src/utility/FixedBlockAdapter.cpp +2 −7 Original line number Diff line number Diff line Loading @@ -18,22 +18,17 @@ #include "FixedBlockAdapter.h" FixedBlockAdapter::~FixedBlockAdapter() { close(); } int32_t FixedBlockAdapter::open(int32_t bytesPerFixedBlock) { mSize = bytesPerFixedBlock; mStorage = new uint8_t[bytesPerFixedBlock]; mStorage = std::make_unique<uint8_t[]>(bytesPerFixedBlock); mPosition = 0; return 0; } int32_t FixedBlockAdapter::close() { delete[] mStorage; mStorage = nullptr; mStorage.reset(); mSize = 0; mPosition = 0; return 0; Loading media/libaaudio/src/utility/FixedBlockAdapter.h +3 −2 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ #ifndef AAUDIO_FIXED_BLOCK_ADAPTER_H #define AAUDIO_FIXED_BLOCK_ADAPTER_H #include <memory> #include <stdio.h> /** Loading @@ -37,7 +38,7 @@ public: FixedBlockAdapter(FixedBlockProcessor &fixedBlockProcessor) : mFixedBlockProcessor(fixedBlockProcessor) {} virtual ~FixedBlockAdapter(); virtual ~FixedBlockAdapter() = default; /** * Allocate internal resources needed for buffering data. Loading @@ -63,7 +64,7 @@ public: protected: FixedBlockProcessor &mFixedBlockProcessor; uint8_t *mStorage = nullptr; // Store data here while assembling buffers. std::unique_ptr<uint8_t[]> mStorage; // Store data here while assembling buffers. int32_t mSize = 0; // Size in bytes of the fixed size buffer. int32_t mPosition = 0; // Offset of the last byte read or written. }; Loading media/libaaudio/src/utility/FixedBlockReader.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -39,7 +39,7 @@ int32_t FixedBlockReader::readFromStorage(uint8_t *buffer, int32_t numBytes) { if (bytesToRead > dataAvailable) { bytesToRead = dataAvailable; } memcpy(buffer, mStorage + mPosition, bytesToRead); memcpy(buffer, &mStorage[mPosition], bytesToRead); mPosition += bytesToRead; return bytesToRead; } Loading @@ -60,7 +60,7 @@ int32_t FixedBlockReader::processVariableBlock(uint8_t *buffer, int32_t numBytes bytesLeft -= mSize; } else { // Just need a partial block so we have to use storage. result = mFixedBlockProcessor.onProcessFixedBlock(mStorage, mSize); result = mFixedBlockProcessor.onProcessFixedBlock(mStorage.get(), mSize); mPosition = 0; } } Loading media/libaaudio/src/utility/FixedBlockWriter.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -30,7 +30,7 @@ int32_t FixedBlockWriter::writeToStorage(uint8_t *buffer, int32_t numBytes) { if (bytesToStore > roomAvailable) { bytesToStore = roomAvailable; } memcpy(mStorage + mPosition, buffer, bytesToStore); memcpy(&mStorage[mPosition], buffer, bytesToStore); mPosition += bytesToStore; return bytesToStore; } Loading @@ -46,7 +46,7 @@ int32_t FixedBlockWriter::processVariableBlock(uint8_t *buffer, int32_t numBytes bytesLeft -= bytesWritten; // If storage full then flush it out if (mPosition == mSize) { result = mFixedBlockProcessor.onProcessFixedBlock(mStorage, mSize); result = mFixedBlockProcessor.onProcessFixedBlock(mStorage.get(), mSize); mPosition = 0; } } Loading Loading
media/libaaudio/src/utility/FixedBlockAdapter.cpp +2 −7 Original line number Diff line number Diff line Loading @@ -18,22 +18,17 @@ #include "FixedBlockAdapter.h" FixedBlockAdapter::~FixedBlockAdapter() { close(); } int32_t FixedBlockAdapter::open(int32_t bytesPerFixedBlock) { mSize = bytesPerFixedBlock; mStorage = new uint8_t[bytesPerFixedBlock]; mStorage = std::make_unique<uint8_t[]>(bytesPerFixedBlock); mPosition = 0; return 0; } int32_t FixedBlockAdapter::close() { delete[] mStorage; mStorage = nullptr; mStorage.reset(); mSize = 0; mPosition = 0; return 0; Loading
media/libaaudio/src/utility/FixedBlockAdapter.h +3 −2 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ #ifndef AAUDIO_FIXED_BLOCK_ADAPTER_H #define AAUDIO_FIXED_BLOCK_ADAPTER_H #include <memory> #include <stdio.h> /** Loading @@ -37,7 +38,7 @@ public: FixedBlockAdapter(FixedBlockProcessor &fixedBlockProcessor) : mFixedBlockProcessor(fixedBlockProcessor) {} virtual ~FixedBlockAdapter(); virtual ~FixedBlockAdapter() = default; /** * Allocate internal resources needed for buffering data. Loading @@ -63,7 +64,7 @@ public: protected: FixedBlockProcessor &mFixedBlockProcessor; uint8_t *mStorage = nullptr; // Store data here while assembling buffers. std::unique_ptr<uint8_t[]> mStorage; // Store data here while assembling buffers. int32_t mSize = 0; // Size in bytes of the fixed size buffer. int32_t mPosition = 0; // Offset of the last byte read or written. }; Loading
media/libaaudio/src/utility/FixedBlockReader.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -39,7 +39,7 @@ int32_t FixedBlockReader::readFromStorage(uint8_t *buffer, int32_t numBytes) { if (bytesToRead > dataAvailable) { bytesToRead = dataAvailable; } memcpy(buffer, mStorage + mPosition, bytesToRead); memcpy(buffer, &mStorage[mPosition], bytesToRead); mPosition += bytesToRead; return bytesToRead; } Loading @@ -60,7 +60,7 @@ int32_t FixedBlockReader::processVariableBlock(uint8_t *buffer, int32_t numBytes bytesLeft -= mSize; } else { // Just need a partial block so we have to use storage. result = mFixedBlockProcessor.onProcessFixedBlock(mStorage, mSize); result = mFixedBlockProcessor.onProcessFixedBlock(mStorage.get(), mSize); mPosition = 0; } } Loading
media/libaaudio/src/utility/FixedBlockWriter.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -30,7 +30,7 @@ int32_t FixedBlockWriter::writeToStorage(uint8_t *buffer, int32_t numBytes) { if (bytesToStore > roomAvailable) { bytesToStore = roomAvailable; } memcpy(mStorage + mPosition, buffer, bytesToStore); memcpy(&mStorage[mPosition], buffer, bytesToStore); mPosition += bytesToStore; return bytesToStore; } Loading @@ -46,7 +46,7 @@ int32_t FixedBlockWriter::processVariableBlock(uint8_t *buffer, int32_t numBytes bytesLeft -= bytesWritten; // If storage full then flush it out if (mPosition == mSize) { result = mFixedBlockProcessor.onProcessFixedBlock(mStorage, mSize); result = mFixedBlockProcessor.onProcessFixedBlock(mStorage.get(), mSize); mPosition = 0; } } Loading