Skip to content

Commit a4f3a93

Browse files
committed
Remove InCache logic during initialization of decoder
InCache logic will consume all buffers in buffer pool at same time, Sometimes encounters stuck issue. Tracked-On: OAM-132019 Signed-off-by: zhangyichix <yichix.zhang@intel.com>
1 parent 5bff7b0 commit a4f3a93

File tree

1 file changed

+6
-79
lines changed

1 file changed

+6
-79
lines changed

c2_utils/src/mfx_va_frame_pool_allocator.cpp

Lines changed: 6 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -88,87 +88,14 @@ mfxStatus MfxVaFramePoolAllocator::AllocFrames(mfxFrameAllocRequest *request,
8888
}
8989

9090
response->NumFrameActual = 0;
91-
#define RETRY_TIMES 5
92-
for (int i = 0; i < opt_buffers; ++i) {
93-
94-
std::shared_ptr<C2GraphicBlock> new_block;
95-
int retry_time_left = RETRY_TIMES;
96-
do {
97-
res = m_c2Allocator->fetchGraphicBlock(
98-
MFXGetSurfaceWidth(request->Info), MFXGetSurfaceHeight(request->Info),
99-
MfxFourCCToGralloc(request->Info.FourCC),
100-
{ m_consumerUsage, C2AndroidMemoryUsage::HW_CODEC_WRITE },
101-
&new_block);
102-
if (!retry_time_left--) {
103-
if (request->NumFrameMin <= i) {
104-
// Ignore the error here in case system cannot allocate
105-
// the maximum buffers. The minimum buffer is OK.
106-
res = C2_TIMED_OUT;
107-
break;
108-
} else {
109-
// Retry to get minimum request buffers.
110-
retry_time_left = RETRY_TIMES;
111-
}
112-
}
113-
} while(res == C2_BLOCKING);
114-
if (res != C2_OK || !new_block) break;
115-
116-
uint64_t id;
117-
native_handle_t *hndl = android::UnwrapNativeCodec2GrallocHandle(new_block->handle());
118-
if (C2_OK != MfxGrallocInstance::getInstance()->GetBackingStore(hndl, &id)) {
119-
mfx_res = MFX_ERR_INVALID_HANDLE;
120-
break;
121-
}
122-
123-
m_cachedBufferId.emplace(id, i);
124-
// if (C2_OK != res) { //TODO dead code not need.
125-
// native_handle_delete(hndl);
126-
// mfx_res = MFX_ERR_MEMORY_ALLOC;
127-
// break;
128-
// }
129-
130-
// deep copy to have unique_ptr as m_pool required unique_ptr
131-
std::unique_ptr<C2GraphicBlock> unique_block = std::make_unique<C2GraphicBlock>(*new_block);
132-
133-
bool decode_target = true;
134-
mfx_res = ConvertGrallocToVa(hndl, decode_target, &mids[i]);
135-
if (MFX_ERR_NONE != mfx_res) {
136-
native_handle_delete(hndl);
137-
break;
138-
}
139-
140-
MFX_DEBUG_TRACE_STREAM(NAMED(unique_block->handle()) << NAMED(mids[i]));
141-
142-
m_pool->Append(std::move(unique_block));//tmp cache it, in case return it to system and alloc again at once.
143-
144-
native_handle_delete(hndl);
145-
146-
++response->NumFrameActual;
147-
}
148-
MFX_DEBUG_TRACE_I32(response->NumFrameActual);
149-
150-
if (MFX_ERR_NONE != mfx_res) {
151-
MFX_DEBUG_TRACE_MSG("Fatal error occurred while allocating memory");
152-
153-
MFX_DEBUG_TRACE__mfxStatus(mfx_res);
154-
return mfx_res;
155-
}
15691

157-
if (response->NumFrameActual >= request->NumFrameMin) {
158-
response->mids = mids.release();
159-
m_pool = std::make_unique<MfxPool<C2GraphicBlock>>(); //release graphic buffer
160-
mfx_res = MFX_ERR_NONE; // suppress the error if allocated enough
161-
} else {
162-
response->NumFrameActual = 0;
163-
response->mids = nullptr;
164-
// recreate m_pool to clean it
165-
FreeAllMappings();
166-
m_pool = std::make_unique<MfxPool<C2GraphicBlock>>();
167-
mfx_res = MFX_ERR_MEMORY_ALLOC;
168-
}
169-
} while(false);
92+
response->NumFrameActual = opt_buffers;
93+
response->mids = mids.release();
94+
} while (false);
17095
} else {
171-
mfx_res = AllocFrames(request, response);
96+
response->NumFrameActual = 0;
97+
response->mids = nullptr;
98+
mfx_res = MFX_ERR_INCOMPATIBLE_VIDEO_PARAM;
17299
}
173100

174101
MFX_DEBUG_TRACE__mfxStatus(mfx_res);

0 commit comments

Comments
 (0)