Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove memory blocking for decoder #200

Draft
wants to merge 2 commits into
base: celadon/u/mr0/master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 3 additions & 21 deletions c2_components/src/mfx_c2_decoder_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1814,27 +1814,9 @@ c2_status_t MfxC2DecoderComponent::AllocateC2Block(uint32_t width, uint32_t heig
C2MemoryUsage mem_usage = {m_consumerUsage, C2AndroidMemoryUsage::HW_CODEC_WRITE};
res = m_c2Allocator->fetchGraphicBlock(width, height,
MfxFourCCToGralloc(fourcc), mem_usage, out_block);
if (res == C2_OK) {
auto hndl_deleter = [](native_handle_t *hndl) {
native_handle_delete(hndl);
hndl = nullptr;
};

std::unique_ptr<native_handle_t, decltype(hndl_deleter)> hndl(
android::UnwrapNativeCodec2GrallocHandle((*out_block)->handle()), hndl_deleter);

uint64_t id;
if (C2_OK != MfxGrallocInstance::getInstance()->GetBackingStore(hndl.get(), &id))
return C2_CORRUPTED;
if(!m_vppConversion) {
if (m_allocator && !m_allocator->InCache(id)) {
res = C2_BLOCKING;
std::this_thread::sleep_for(std::chrono::milliseconds(1));
// If always fetch a nocached block, check if width or height have changed
// compare to when it was initialized.
MFX_DEBUG_TRACE_STREAM("fetchGraphicBlock a nocached block, please retune output blocks. id = " << id);
}
}
if (res == C2_BLOCKING) {
std::this_thread::sleep_for(std::chrono::milliseconds(1));
MFX_DEBUG_TRACE_MSG("fetchGraphicBlock blocking, wait and try again");
}
} else if (m_mfxVideoParams.IOPattern == MFX_IOPATTERN_OUT_SYSTEM_MEMORY) {
C2MemoryUsage mem_usage = {m_consumerUsage, C2MemoryUsage::CPU_WRITE};
Expand Down
1 change: 0 additions & 1 deletion c2_utils/include/mfx_frame_pool_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class MfxFramePoolAllocator
virtual void SetC2Allocator(std::shared_ptr<C2BlockPool> c2_allocator) = 0;
virtual std::shared_ptr<C2GraphicBlock> Alloc() = 0;
virtual void Reset() = 0;
virtual bool InCache(uint64_t id) = 0;
virtual void SetBufferCount(unsigned int cnt) = 0;
virtual void SetConsumerUsage(uint64_t usage) = 0;

Expand Down
12 changes: 1 addition & 11 deletions c2_utils/include/mfx_va_frame_pool_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class MfxVaFramePoolAllocator : public MfxVaFrameAllocator, public MfxFramePoolA
{
MFX_DEBUG_TRACE_FUNC;
m_pool = std::make_unique<MfxPool<C2GraphicBlock>>();
m_cachedBufferId.clear();
}

virtual void SetBufferCount(unsigned int cnt) override
{
MFX_DEBUG_TRACE_FUNC;
Expand All @@ -76,14 +76,6 @@ class MfxVaFramePoolAllocator : public MfxVaFrameAllocator, public MfxFramePoolA
m_consumerUsage = usage;
}

bool InCache(uint64_t id) {
auto it = m_cachedBufferId.find(id);
if (it == m_cachedBufferId.end()){
return false;
}

return true;
}
private:
virtual mfxStatus AllocFrames(mfxFrameAllocRequest *request, mfxFrameAllocResponse *response) override;

Expand All @@ -96,8 +88,6 @@ class MfxVaFramePoolAllocator : public MfxVaFrameAllocator, public MfxFramePoolA

std::unique_ptr<MfxPool<C2GraphicBlock>> m_pool;

std::map<uint64_t, int> m_cachedBufferId;

unsigned int m_uSuggestBufferCnt = 0;

uint64_t m_consumerUsage = 0;
Expand Down
13 changes: 1 addition & 12 deletions c2_utils/src/mfx_va_frame_pool_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ mfxStatus MfxVaFramePoolAllocator::AllocFrames(mfxFrameAllocRequest *request,
// buffers_count = output_delay_ + kSmoothnessFactor(4) + kRenderingDepth(3)
int max_buffers = m_uSuggestBufferCnt + kSmoothnessFactor + kRenderingDepth;
int min_buffers = MFX_MAX(request->NumFrameSuggested, MFX_MAX(request->NumFrameMin, 1));
// int opt_buffers = min_buffers;
int opt_buffers = max_buffers; // optimal buffer count for better performance
if (max_buffers < request->NumFrameMin) return MFX_ERR_MEMORY_ALLOC;

Expand Down Expand Up @@ -113,19 +114,7 @@ mfxStatus MfxVaFramePoolAllocator::AllocFrames(mfxFrameAllocRequest *request,
} while(res == C2_BLOCKING);
if (res != C2_OK || !new_block) break;

uint64_t id;
native_handle_t *hndl = android::UnwrapNativeCodec2GrallocHandle(new_block->handle());
if (C2_OK != MfxGrallocInstance::getInstance()->GetBackingStore(hndl, &id)) {
mfx_res = MFX_ERR_INVALID_HANDLE;
break;
}

m_cachedBufferId.emplace(id, i);
// if (C2_OK != res) { //TODO dead code not need.
// native_handle_delete(hndl);
// mfx_res = MFX_ERR_MEMORY_ALLOC;
// break;
// }

// deep copy to have unique_ptr as m_pool required unique_ptr
std::unique_ptr<C2GraphicBlock> unique_block = std::make_unique<C2GraphicBlock>(*new_block);
Expand Down