Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4e942e1b authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Merge "aaudio: use unique_ptr in FixedBlockAdapter" into rvc-dev am:...

Merge "aaudio: use unique_ptr in FixedBlockAdapter" into rvc-dev am: 7f20d08c am: d9d0c1b4 am: d417eb13

Change-Id: I6f08f3ea7917c1a157e39765e473635b9851bed6
parents 588a7d96 d417eb13
Loading
Loading
Loading
Loading
+2 −7
Original line number Original line Diff line number Diff line
@@ -18,22 +18,17 @@


#include "FixedBlockAdapter.h"
#include "FixedBlockAdapter.h"


FixedBlockAdapter::~FixedBlockAdapter() {
    close();
}

int32_t FixedBlockAdapter::open(int32_t bytesPerFixedBlock)
int32_t FixedBlockAdapter::open(int32_t bytesPerFixedBlock)
{
{
    mSize = bytesPerFixedBlock;
    mSize = bytesPerFixedBlock;
    mStorage = new uint8_t[bytesPerFixedBlock];
    mStorage = std::make_unique<uint8_t[]>(bytesPerFixedBlock);
    mPosition = 0;
    mPosition = 0;
    return 0;
    return 0;
}
}


int32_t FixedBlockAdapter::close()
int32_t FixedBlockAdapter::close()
{
{
    delete[] mStorage;
    mStorage.reset();
    mStorage = nullptr;
    mSize = 0;
    mSize = 0;
    mPosition = 0;
    mPosition = 0;
    return 0;
    return 0;
+3 −2
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@
#ifndef AAUDIO_FIXED_BLOCK_ADAPTER_H
#ifndef AAUDIO_FIXED_BLOCK_ADAPTER_H
#define AAUDIO_FIXED_BLOCK_ADAPTER_H
#define AAUDIO_FIXED_BLOCK_ADAPTER_H


#include <memory>
#include <stdio.h>
#include <stdio.h>


/**
/**
@@ -37,7 +38,7 @@ public:
    FixedBlockAdapter(FixedBlockProcessor &fixedBlockProcessor)
    FixedBlockAdapter(FixedBlockProcessor &fixedBlockProcessor)
    : mFixedBlockProcessor(fixedBlockProcessor) {}
    : mFixedBlockProcessor(fixedBlockProcessor) {}


    virtual ~FixedBlockAdapter();
    virtual ~FixedBlockAdapter() = default;


    /**
    /**
     * Allocate internal resources needed for buffering data.
     * Allocate internal resources needed for buffering data.
@@ -63,7 +64,7 @@ public:


protected:
protected:
    FixedBlockProcessor  &mFixedBlockProcessor;
    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               mSize = 0;             // Size in bytes of the fixed size buffer.
    int32_t               mPosition = 0;         // Offset of the last byte read or written.
    int32_t               mPosition = 0;         // Offset of the last byte read or written.
};
};
+2 −2
Original line number Original line Diff line number Diff line
@@ -39,7 +39,7 @@ int32_t FixedBlockReader::readFromStorage(uint8_t *buffer, int32_t numBytes) {
    if (bytesToRead > dataAvailable) {
    if (bytesToRead > dataAvailable) {
        bytesToRead = dataAvailable;
        bytesToRead = dataAvailable;
    }
    }
    memcpy(buffer, mStorage + mPosition, bytesToRead);
    memcpy(buffer, &mStorage[mPosition], bytesToRead);
    mPosition += bytesToRead;
    mPosition += bytesToRead;
    return bytesToRead;
    return bytesToRead;
}
}
@@ -60,7 +60,7 @@ int32_t FixedBlockReader::processVariableBlock(uint8_t *buffer, int32_t numBytes
            bytesLeft -= mSize;
            bytesLeft -= mSize;
        } else {
        } else {
            // Just need a partial block so we have to use storage.
            // Just need a partial block so we have to use storage.
            result = mFixedBlockProcessor.onProcessFixedBlock(mStorage, mSize);
            result = mFixedBlockProcessor.onProcessFixedBlock(mStorage.get(), mSize);
            mPosition = 0;
            mPosition = 0;
        }
        }
    }
    }
+2 −2
Original line number Original line Diff line number Diff line
@@ -30,7 +30,7 @@ int32_t FixedBlockWriter::writeToStorage(uint8_t *buffer, int32_t numBytes) {
    if (bytesToStore > roomAvailable) {
    if (bytesToStore > roomAvailable) {
        bytesToStore = roomAvailable;
        bytesToStore = roomAvailable;
    }
    }
    memcpy(mStorage + mPosition, buffer, bytesToStore);
    memcpy(&mStorage[mPosition], buffer, bytesToStore);
    mPosition += bytesToStore;
    mPosition += bytesToStore;
    return bytesToStore;
    return bytesToStore;
}
}
@@ -46,7 +46,7 @@ int32_t FixedBlockWriter::processVariableBlock(uint8_t *buffer, int32_t numBytes
        bytesLeft -= bytesWritten;
        bytesLeft -= bytesWritten;
        // If storage full then flush it out
        // If storage full then flush it out
        if (mPosition == mSize) {
        if (mPosition == mSize) {
            result = mFixedBlockProcessor.onProcessFixedBlock(mStorage, mSize);
            result = mFixedBlockProcessor.onProcessFixedBlock(mStorage.get(), mSize);
            mPosition = 0;
            mPosition = 0;
        }
        }
    }
    }