Loading media/libstagefright/codec2/vndk/bufferpool/Accessor.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -43,8 +43,8 @@ Return<void> Accessor::connect(connect_cb _hidl_cb) { return Void(); } Accessor::Accessor(const std::shared_ptr<C2Allocator> &allocator, bool linear) : mImpl(new Impl(allocator, linear)) {} Accessor::Accessor(const std::shared_ptr<BufferPoolAllocator> &allocator) : mImpl(new Impl(allocator)) {} Accessor::~Accessor() { } Loading media/libstagefright/codec2/vndk/bufferpool/Accessor.h +1 −3 Original line number Diff line number Diff line Loading @@ -20,7 +20,6 @@ #include <android/hardware/media/bufferpool/1.0/IAccessor.h> #include <hidl/MQDescriptor.h> #include <hidl/Status.h> #include <C2Buffer.h> #include <BufferPoolTypes.h> #include "BufferStatus.h" Loading Loading @@ -53,9 +52,8 @@ struct Accessor : public IAccessor { * Creates a buffer pool accessor which uses the specified allocator. * * @param allocator buffer allocator. * @param linear whether the allocator is linear or not. */ Accessor(const std::shared_ptr<C2Allocator> &allocator, bool linear); explicit Accessor(const std::shared_ptr<BufferPoolAllocator> &allocator); /** Destructs a buffer pool accessor. */ ~Accessor(); Loading media/libstagefright/codec2/vndk/bufferpool/AccessorImpl.cpp +19 −106 Original line number Diff line number Diff line Loading @@ -22,7 +22,6 @@ #include <time.h> #include <unistd.h> #include <utils/Log.h> #include <C2Buffer.h> #include "AccessorImpl.h" #include "Connection.h" Loading @@ -38,48 +37,18 @@ struct InternalBuffer { BufferId mId; size_t mOwnerCount; size_t mTransactionCount; const bool mLinear; const std::shared_ptr<C2LinearAllocation> mLinearAllocation; const std::shared_ptr<C2GraphicAllocation> mGraphicAllocation; const std::shared_ptr<BufferPoolAllocation> mAllocation; const std::vector<uint8_t> mConfig; InternalBuffer( BufferId id, const std::shared_ptr<C2LinearAllocation> &alloc, const std::shared_ptr<BufferPoolAllocation> &alloc, const std::vector<uint8_t> &allocConfig) : mId(id), mOwnerCount(0), mTransactionCount(0), mLinear(true), mLinearAllocation(alloc), mGraphicAllocation(nullptr), mConfig(allocConfig) {} InternalBuffer( BufferId id, const std::shared_ptr<C2GraphicAllocation> &alloc, const std::vector<uint8_t> &allocConfig) : mId(id), mOwnerCount(0), mTransactionCount(0), mLinear(false), mLinearAllocation(nullptr), mGraphicAllocation(alloc), mConfig(allocConfig) {} mAllocation(alloc), mConfig(allocConfig) {} const native_handle_t *handle() { if (mLinear) { return mLinearAllocation->handle(); } else { return mGraphicAllocation->handle(); } } // TODO : support non exact matching. e.g) capacity bool isRecyclable(const std::vector<uint8_t> &config) { if (mConfig.size() == config.size()) { for (size_t i = 0; i < config.size(); ++i) { if (mConfig[i] != config[i]) { return false; } } return true; } return false; return mAllocation->handle(); } }; Loading Loading @@ -154,8 +123,8 @@ int32_t Accessor::Impl::sPid = getpid(); uint32_t Accessor::Impl::sSeqId = time(NULL); Accessor::Impl::Impl( const std::shared_ptr<C2Allocator> &allocator, bool linear) : mAllocator(allocator), mLinear(linear) {} const std::shared_ptr<BufferPoolAllocator> &allocator) : mAllocator(allocator) {} Accessor::Impl::~Impl() { } Loading Loading @@ -193,14 +162,8 @@ ResultStatus Accessor::Impl::allocate( std::lock_guard<std::mutex> lock(mBufferPool.mMutex); mBufferPool.processStatusMessages(); ResultStatus status = ResultStatus::OK; if (!mBufferPool.getFreeBuffer(params, bufferId, handle)) { if (mLinear) { status = mBufferPool.getNewLinearBuffer( mAllocator, params, bufferId, handle); } else { status = mBufferPool.getNewGraphicBuffer( mAllocator, params, bufferId, handle); } if (!mBufferPool.getFreeBuffer(mAllocator, params, bufferId, handle)) { status = mBufferPool.getNewBuffer(mAllocator, params, bufferId, handle); ALOGV("create a buffer %d : %u %p", status == ResultStatus::OK, *bufferId, *handle); } Loading Loading @@ -437,12 +400,13 @@ bool Accessor::Impl::BufferPool::handleClose(ConnectionId connectionId) { } bool Accessor::Impl::BufferPool::getFreeBuffer( const std::shared_ptr<BufferPoolAllocator> &allocator, const std::vector<uint8_t> ¶ms, BufferId *pId, const native_handle_t** handle) { auto bufferIt = mFreeBuffers.begin(); for (;bufferIt != mFreeBuffers.end(); ++bufferIt) { BufferId bufferId = *bufferIt; if (mBuffers[bufferId]->isRecyclable(params)) { if (allocator->compatible(params, mBuffers[bufferId]->mConfig)) { break; } } Loading @@ -457,81 +421,30 @@ bool Accessor::Impl::BufferPool::getFreeBuffer( return false; } ResultStatus Accessor::Impl::BufferPool::getNewLinearBuffer( const std::shared_ptr<C2Allocator> &allocator, ResultStatus Accessor::Impl::BufferPool::getNewBuffer( const std::shared_ptr<BufferPoolAllocator> &allocator, const std::vector<uint8_t> ¶ms, BufferId *pId, const native_handle_t** handle) { union LinearParam { struct { uint32_t capacity; C2MemoryUsage usage; } data; uint8_t array[0]; LinearParam() : data{0, {0, 0}} {} } linearParam; memcpy(&linearParam, params.data(), std::min(sizeof(linearParam), params.size())); std::shared_ptr<C2LinearAllocation> linearAlloc; c2_status_t status = allocator->newLinearAllocation( linearParam.data.capacity, linearParam.data.usage, &linearAlloc); if (status == C2_OK) { BufferId bufferId = mSeq++; std::unique_ptr<InternalBuffer> buffer = std::make_unique<InternalBuffer>( bufferId, linearAlloc, params); if (buffer) { auto res = mBuffers.insert(std::make_pair( bufferId, std::move(buffer))); if (res.second) { *handle = linearAlloc->handle(); *pId = bufferId; return ResultStatus::OK; } } return ResultStatus::NO_MEMORY; } // TODO: map C2 error code return ResultStatus::CRITICAL_ERROR; } std::shared_ptr<BufferPoolAllocation> alloc; ResultStatus status = allocator->allocate(params, &alloc); ResultStatus Accessor::Impl::BufferPool::getNewGraphicBuffer( const std::shared_ptr<C2Allocator> &allocator, const std::vector<uint8_t> ¶ms, BufferId *pId, const native_handle_t** handle) { union GraphicParam { struct { uint32_t width; uint32_t height; uint32_t format; C2MemoryUsage usage; } data; uint8_t array[0]; GraphicParam() : data{0, 0, 0, {0, 0}} {} } graphicParam; memcpy(&graphicParam, params.data(), std::min(sizeof(graphicParam), params.size())); std::shared_ptr<C2GraphicAllocation> graphicAlloc; c2_status_t status = allocator->newGraphicAllocation( graphicParam.data.width, graphicParam.data.height, graphicParam.data.format, graphicParam.data.usage, &graphicAlloc); if (status == C2_OK) { BufferId bufferId = mSeq; if (status == ResultStatus::OK) { BufferId bufferId = mSeq++; std::unique_ptr<InternalBuffer> buffer = std::make_unique<InternalBuffer>( bufferId, graphicAlloc, params); bufferId, alloc, params); if (buffer) { auto res = mBuffers.insert(std::make_pair( bufferId, std::move(buffer))); if (res.second) { *handle = graphicAlloc->handle(); *handle = alloc->handle(); *pId = bufferId; return ResultStatus::OK; } } return ResultStatus::NO_MEMORY; } // TODO: map C2 error code return ResultStatus::CRITICAL_ERROR; return status; } } // namespace implementation Loading media/libstagefright/codec2/vndk/bufferpool/AccessorImpl.h +12 −27 Original line number Diff line number Diff line Loading @@ -35,7 +35,7 @@ struct TransactionStatus; * An implementation of a buffer pool accessor(or a buffer pool implementation.) */ class Accessor::Impl { public: Impl(const std::shared_ptr<C2Allocator> &allocator, bool linear); Impl(const std::shared_ptr<BufferPoolAllocator> &allocator); ~Impl(); Loading Loading @@ -64,8 +64,7 @@ private: static uint32_t sSeqId; static int32_t sPid; const std::shared_ptr<C2Allocator> mAllocator; bool mLinear; const std::shared_ptr<BufferPoolAllocator> mAllocator; /** * Buffer pool implementation. Loading Loading @@ -172,6 +171,7 @@ private: /** * Recycles a existing free buffer if it is possible. * * @param allocator the buffer allocator * @param params the allocation parameters. * @param pId the id of the recycled buffer. * @param handle the native handle of the recycled buffer. Loading @@ -179,40 +179,25 @@ private: * @return {@code true} when a buffer is recycled, {@code false} * otherwise. */ bool getFreeBuffer(const std::vector<uint8_t> ¶ms, BufferId *pId, const native_handle_t **handle); /** * Creates a new linear buffer. * * @param allocator the linear buffer allocator * @param params the allocator parameters * @param pId the buffer id for the newly allocated buffer. * @param handle the native handle for the newly allocated buffer. * * @return OK when a linear allocation is successfully allocated. * NO_MEMORY when there is no memory. * CRITICAL_ERROR otherwise. */ ResultStatus getNewLinearBuffer( const std::shared_ptr<C2Allocator> &allocator, const std::vector<uint8_t> ¶ms, BufferId *pId, const native_handle_t **handle); bool getFreeBuffer( const std::shared_ptr<BufferPoolAllocator> &allocator, const std::vector<uint8_t> ¶ms, BufferId *pId, const native_handle_t **handle); /** * Creates a new graphic buffer. * Creates a new buffer. * * @param allocator the graphic buffer allocator * @param allocator the buffer allocator * @param params the allocator parameters * @param pId the buffer id for the newly allocated buffer. * @param handle the native handle for the newly allocated buffer. * * @return OK when a graphic allocation is successfully allocated. * @return OK when an allocation is successfully allocated. * NO_MEMORY when there is no memory. * CRITICAL_ERROR otherwise. */ ResultStatus getNewGraphicBuffer( const std::shared_ptr<C2Allocator> &allocator, ResultStatus getNewBuffer( const std::shared_ptr<BufferPoolAllocator> &allocator, const std::vector<uint8_t> ¶ms, BufferId *pId, const native_handle_t **handle); Loading media/libstagefright/codec2/vndk/bufferpool/Android.bp +0 −1 Original line number Diff line number Diff line Loading @@ -24,7 +24,6 @@ cc_library { "libhidlbase", "libhidltransport", "liblog", "libstagefright_codec2", "libutils", "android.hardware.media.bufferpool@1.0", ], Loading Loading
media/libstagefright/codec2/vndk/bufferpool/Accessor.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -43,8 +43,8 @@ Return<void> Accessor::connect(connect_cb _hidl_cb) { return Void(); } Accessor::Accessor(const std::shared_ptr<C2Allocator> &allocator, bool linear) : mImpl(new Impl(allocator, linear)) {} Accessor::Accessor(const std::shared_ptr<BufferPoolAllocator> &allocator) : mImpl(new Impl(allocator)) {} Accessor::~Accessor() { } Loading
media/libstagefright/codec2/vndk/bufferpool/Accessor.h +1 −3 Original line number Diff line number Diff line Loading @@ -20,7 +20,6 @@ #include <android/hardware/media/bufferpool/1.0/IAccessor.h> #include <hidl/MQDescriptor.h> #include <hidl/Status.h> #include <C2Buffer.h> #include <BufferPoolTypes.h> #include "BufferStatus.h" Loading Loading @@ -53,9 +52,8 @@ struct Accessor : public IAccessor { * Creates a buffer pool accessor which uses the specified allocator. * * @param allocator buffer allocator. * @param linear whether the allocator is linear or not. */ Accessor(const std::shared_ptr<C2Allocator> &allocator, bool linear); explicit Accessor(const std::shared_ptr<BufferPoolAllocator> &allocator); /** Destructs a buffer pool accessor. */ ~Accessor(); Loading
media/libstagefright/codec2/vndk/bufferpool/AccessorImpl.cpp +19 −106 Original line number Diff line number Diff line Loading @@ -22,7 +22,6 @@ #include <time.h> #include <unistd.h> #include <utils/Log.h> #include <C2Buffer.h> #include "AccessorImpl.h" #include "Connection.h" Loading @@ -38,48 +37,18 @@ struct InternalBuffer { BufferId mId; size_t mOwnerCount; size_t mTransactionCount; const bool mLinear; const std::shared_ptr<C2LinearAllocation> mLinearAllocation; const std::shared_ptr<C2GraphicAllocation> mGraphicAllocation; const std::shared_ptr<BufferPoolAllocation> mAllocation; const std::vector<uint8_t> mConfig; InternalBuffer( BufferId id, const std::shared_ptr<C2LinearAllocation> &alloc, const std::shared_ptr<BufferPoolAllocation> &alloc, const std::vector<uint8_t> &allocConfig) : mId(id), mOwnerCount(0), mTransactionCount(0), mLinear(true), mLinearAllocation(alloc), mGraphicAllocation(nullptr), mConfig(allocConfig) {} InternalBuffer( BufferId id, const std::shared_ptr<C2GraphicAllocation> &alloc, const std::vector<uint8_t> &allocConfig) : mId(id), mOwnerCount(0), mTransactionCount(0), mLinear(false), mLinearAllocation(nullptr), mGraphicAllocation(alloc), mConfig(allocConfig) {} mAllocation(alloc), mConfig(allocConfig) {} const native_handle_t *handle() { if (mLinear) { return mLinearAllocation->handle(); } else { return mGraphicAllocation->handle(); } } // TODO : support non exact matching. e.g) capacity bool isRecyclable(const std::vector<uint8_t> &config) { if (mConfig.size() == config.size()) { for (size_t i = 0; i < config.size(); ++i) { if (mConfig[i] != config[i]) { return false; } } return true; } return false; return mAllocation->handle(); } }; Loading Loading @@ -154,8 +123,8 @@ int32_t Accessor::Impl::sPid = getpid(); uint32_t Accessor::Impl::sSeqId = time(NULL); Accessor::Impl::Impl( const std::shared_ptr<C2Allocator> &allocator, bool linear) : mAllocator(allocator), mLinear(linear) {} const std::shared_ptr<BufferPoolAllocator> &allocator) : mAllocator(allocator) {} Accessor::Impl::~Impl() { } Loading Loading @@ -193,14 +162,8 @@ ResultStatus Accessor::Impl::allocate( std::lock_guard<std::mutex> lock(mBufferPool.mMutex); mBufferPool.processStatusMessages(); ResultStatus status = ResultStatus::OK; if (!mBufferPool.getFreeBuffer(params, bufferId, handle)) { if (mLinear) { status = mBufferPool.getNewLinearBuffer( mAllocator, params, bufferId, handle); } else { status = mBufferPool.getNewGraphicBuffer( mAllocator, params, bufferId, handle); } if (!mBufferPool.getFreeBuffer(mAllocator, params, bufferId, handle)) { status = mBufferPool.getNewBuffer(mAllocator, params, bufferId, handle); ALOGV("create a buffer %d : %u %p", status == ResultStatus::OK, *bufferId, *handle); } Loading Loading @@ -437,12 +400,13 @@ bool Accessor::Impl::BufferPool::handleClose(ConnectionId connectionId) { } bool Accessor::Impl::BufferPool::getFreeBuffer( const std::shared_ptr<BufferPoolAllocator> &allocator, const std::vector<uint8_t> ¶ms, BufferId *pId, const native_handle_t** handle) { auto bufferIt = mFreeBuffers.begin(); for (;bufferIt != mFreeBuffers.end(); ++bufferIt) { BufferId bufferId = *bufferIt; if (mBuffers[bufferId]->isRecyclable(params)) { if (allocator->compatible(params, mBuffers[bufferId]->mConfig)) { break; } } Loading @@ -457,81 +421,30 @@ bool Accessor::Impl::BufferPool::getFreeBuffer( return false; } ResultStatus Accessor::Impl::BufferPool::getNewLinearBuffer( const std::shared_ptr<C2Allocator> &allocator, ResultStatus Accessor::Impl::BufferPool::getNewBuffer( const std::shared_ptr<BufferPoolAllocator> &allocator, const std::vector<uint8_t> ¶ms, BufferId *pId, const native_handle_t** handle) { union LinearParam { struct { uint32_t capacity; C2MemoryUsage usage; } data; uint8_t array[0]; LinearParam() : data{0, {0, 0}} {} } linearParam; memcpy(&linearParam, params.data(), std::min(sizeof(linearParam), params.size())); std::shared_ptr<C2LinearAllocation> linearAlloc; c2_status_t status = allocator->newLinearAllocation( linearParam.data.capacity, linearParam.data.usage, &linearAlloc); if (status == C2_OK) { BufferId bufferId = mSeq++; std::unique_ptr<InternalBuffer> buffer = std::make_unique<InternalBuffer>( bufferId, linearAlloc, params); if (buffer) { auto res = mBuffers.insert(std::make_pair( bufferId, std::move(buffer))); if (res.second) { *handle = linearAlloc->handle(); *pId = bufferId; return ResultStatus::OK; } } return ResultStatus::NO_MEMORY; } // TODO: map C2 error code return ResultStatus::CRITICAL_ERROR; } std::shared_ptr<BufferPoolAllocation> alloc; ResultStatus status = allocator->allocate(params, &alloc); ResultStatus Accessor::Impl::BufferPool::getNewGraphicBuffer( const std::shared_ptr<C2Allocator> &allocator, const std::vector<uint8_t> ¶ms, BufferId *pId, const native_handle_t** handle) { union GraphicParam { struct { uint32_t width; uint32_t height; uint32_t format; C2MemoryUsage usage; } data; uint8_t array[0]; GraphicParam() : data{0, 0, 0, {0, 0}} {} } graphicParam; memcpy(&graphicParam, params.data(), std::min(sizeof(graphicParam), params.size())); std::shared_ptr<C2GraphicAllocation> graphicAlloc; c2_status_t status = allocator->newGraphicAllocation( graphicParam.data.width, graphicParam.data.height, graphicParam.data.format, graphicParam.data.usage, &graphicAlloc); if (status == C2_OK) { BufferId bufferId = mSeq; if (status == ResultStatus::OK) { BufferId bufferId = mSeq++; std::unique_ptr<InternalBuffer> buffer = std::make_unique<InternalBuffer>( bufferId, graphicAlloc, params); bufferId, alloc, params); if (buffer) { auto res = mBuffers.insert(std::make_pair( bufferId, std::move(buffer))); if (res.second) { *handle = graphicAlloc->handle(); *handle = alloc->handle(); *pId = bufferId; return ResultStatus::OK; } } return ResultStatus::NO_MEMORY; } // TODO: map C2 error code return ResultStatus::CRITICAL_ERROR; return status; } } // namespace implementation Loading
media/libstagefright/codec2/vndk/bufferpool/AccessorImpl.h +12 −27 Original line number Diff line number Diff line Loading @@ -35,7 +35,7 @@ struct TransactionStatus; * An implementation of a buffer pool accessor(or a buffer pool implementation.) */ class Accessor::Impl { public: Impl(const std::shared_ptr<C2Allocator> &allocator, bool linear); Impl(const std::shared_ptr<BufferPoolAllocator> &allocator); ~Impl(); Loading Loading @@ -64,8 +64,7 @@ private: static uint32_t sSeqId; static int32_t sPid; const std::shared_ptr<C2Allocator> mAllocator; bool mLinear; const std::shared_ptr<BufferPoolAllocator> mAllocator; /** * Buffer pool implementation. Loading Loading @@ -172,6 +171,7 @@ private: /** * Recycles a existing free buffer if it is possible. * * @param allocator the buffer allocator * @param params the allocation parameters. * @param pId the id of the recycled buffer. * @param handle the native handle of the recycled buffer. Loading @@ -179,40 +179,25 @@ private: * @return {@code true} when a buffer is recycled, {@code false} * otherwise. */ bool getFreeBuffer(const std::vector<uint8_t> ¶ms, BufferId *pId, const native_handle_t **handle); /** * Creates a new linear buffer. * * @param allocator the linear buffer allocator * @param params the allocator parameters * @param pId the buffer id for the newly allocated buffer. * @param handle the native handle for the newly allocated buffer. * * @return OK when a linear allocation is successfully allocated. * NO_MEMORY when there is no memory. * CRITICAL_ERROR otherwise. */ ResultStatus getNewLinearBuffer( const std::shared_ptr<C2Allocator> &allocator, const std::vector<uint8_t> ¶ms, BufferId *pId, const native_handle_t **handle); bool getFreeBuffer( const std::shared_ptr<BufferPoolAllocator> &allocator, const std::vector<uint8_t> ¶ms, BufferId *pId, const native_handle_t **handle); /** * Creates a new graphic buffer. * Creates a new buffer. * * @param allocator the graphic buffer allocator * @param allocator the buffer allocator * @param params the allocator parameters * @param pId the buffer id for the newly allocated buffer. * @param handle the native handle for the newly allocated buffer. * * @return OK when a graphic allocation is successfully allocated. * @return OK when an allocation is successfully allocated. * NO_MEMORY when there is no memory. * CRITICAL_ERROR otherwise. */ ResultStatus getNewGraphicBuffer( const std::shared_ptr<C2Allocator> &allocator, ResultStatus getNewBuffer( const std::shared_ptr<BufferPoolAllocator> &allocator, const std::vector<uint8_t> ¶ms, BufferId *pId, const native_handle_t **handle); Loading
media/libstagefright/codec2/vndk/bufferpool/Android.bp +0 −1 Original line number Diff line number Diff line Loading @@ -24,7 +24,6 @@ cc_library { "libhidlbase", "libhidltransport", "liblog", "libstagefright_codec2", "libutils", "android.hardware.media.bufferpool@1.0", ], Loading