Skip to content

Commit e1771d2

Browse files
zhangyichixsysopenci
authored andcommitted
[c2][encoder] Fixed the gralloc4 not working on Android U
From Android U, the get function of IMapper4 will check whether the buffer handle is reserved. So we need to call importBuffer before getting the buffer's info. https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3433121 Tracked-On: OAM-111738 Signed-off-by: zhangyichix <yichix.zhang@intel.com>
1 parent d5caa91 commit e1771d2

File tree

7 files changed

+45
-5
lines changed

7 files changed

+45
-5
lines changed

c2_components/src/mfx_c2_encoder_component.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "mfx_c2_utils.h"
2828
#include "mfx_defaults.h"
2929
#include "C2PlatformSupport.h"
30+
#include "mfx_gralloc_instance.h"
3031

3132
#include <limits>
3233
#include <thread>
@@ -1244,12 +1245,23 @@ void MfxC2EncoderComponent::DoWork(std::unique_ptr<C2Work>&& work)
12441245
mfxMemId mem_id = nullptr;
12451246
bool decode_target = false;
12461247
native_handle_t *grallocHandle = android::UnwrapNativeCodec2GrallocHandle(c_graph_block->handle());
1248+
// From Android U, the get function of IMapper4 will check whether the buffer handle is reserved.
1249+
// So we need to call importBuffer before getting the buffer's info.
1250+
#if MFX_ANDROID_VERSION >= MFX_U
1251+
buffer_handle_t importedHandle = MfxGrallocInstance::getInstance()->ImportBuffer(grallocHandle);
12471252

1253+
mfxStatus mfx_sts = frame_converter->ConvertGrallocToVa(importedHandle,
1254+
decode_target, &mem_id);
1255+
1256+
native_handle_delete(const_cast<native_handle_t *>(importedHandle));
1257+
importedHandle = nullptr;
1258+
#else
12481259
mfxStatus mfx_sts = frame_converter->ConvertGrallocToVa(grallocHandle,
12491260
decode_target, &mem_id);
12501261

12511262
native_handle_delete(grallocHandle);
12521263
grallocHandle = nullptr;
1264+
#endif
12531265

12541266
if (MFX_ERR_NONE != mfx_sts) {
12551267
res = MfxStatusToC2(mfx_sts);

c2_utils/include/mfx_gralloc1.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class MfxGralloc1Module : public IMfxGrallocModule
3939
virtual c2_status_t Free(const buffer_handle_t handle);
4040
virtual c2_status_t LockFrame(buffer_handle_t handle, uint8_t** data, C2PlanarLayout *layout);
4141
virtual c2_status_t UnlockFrame(buffer_handle_t handle);
42-
virtual c2_status_t ImportBuffer(const buffer_handle_t rawHandle, buffer_handle_t *outBuffer);
42+
virtual buffer_handle_t ImportBuffer(const buffer_handle_t rawHandle) override;
4343

4444
protected:
4545
hw_module_t const* m_hwModule {};

c2_utils/include/mfx_gralloc4.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class MfxGralloc4Module : public IMfxGrallocModule
4949

5050
virtual c2_status_t GetBufferDetails(const buffer_handle_t handle, BufferDetails* details) override;
5151
virtual c2_status_t GetBackingStore(const buffer_handle_t rawHandle, uint64_t *id) override;
52+
virtual buffer_handle_t ImportBuffer(const buffer_handle_t rawHandle) override;
5253

5354
// TODO: not fully tested
5455
virtual c2_status_t LockFrame(buffer_handle_t handle, uint8_t** data, C2PlanarLayout *layout);

c2_utils/include/mfx_gralloc_interface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,5 @@ class IMfxGrallocModule
5656
virtual c2_status_t GetBufferDetails(const buffer_handle_t handle, BufferDetails* details) = 0;
5757
virtual c2_status_t GetBackingStore(const buffer_handle_t rawHandle, uint64_t *id) = 0;
5858

59-
59+
virtual buffer_handle_t ImportBuffer(const buffer_handle_t rawHandle) = 0;
6060
};

c2_utils/src/mfx_gralloc1.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,19 +273,21 @@ c2_status_t MfxGralloc1Module::UnlockFrame(buffer_handle_t handle)
273273
return res;
274274
}
275275

276-
c2_status_t MfxGralloc1Module::ImportBuffer(const buffer_handle_t rawHandle, buffer_handle_t *outBuffer)
276+
buffer_handle_t MfxGralloc1Module::ImportBuffer(const buffer_handle_t rawHandle)
277277
{
278278
MFX_DEBUG_TRACE_FUNC;
279279
c2_status_t res = C2_OK;
280+
buffer_handle_t *outBuffer = nullptr;
280281
int32_t gr1_res = (*m_grImportBufferFunc)(m_gralloc1_dev, rawHandle, outBuffer);
281282

282283
if (GRALLOC1_ERROR_NONE != gr1_res) {
283284
MFX_DEBUG_TRACE_I32(gr1_res);
284285
res = C2_BAD_STATE;
285286
}
287+
buffer_handle_t out = const_cast<buffer_handle_t>(*outBuffer);
286288

287289
MFX_DEBUG_TRACE__android_c2_status_t(res);
288-
return res;
290+
return out;
289291
}
290292

291293
c2_status_t MfxGralloc1Module::GetBackingStore(const buffer_handle_t rawHandle, uint64_t *id)

c2_utils/src/mfx_gralloc4.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ c2_status_t MfxGralloc4Module::GetBufferDetails(const buffer_handle_t handle, Bu
9898
uint64_t height = 0;
9999
gralloc4::decodeHeight(vec, &height);
100100
details->height = details->allocHeight = height;
101-
MFX_DEBUG_TRACE_I32(details->width);
101+
MFX_DEBUG_TRACE_I32(details->height);
102102

103103
hardware::graphics::common::V1_2::PixelFormat pixelFormat;
104104
if (IsFailed(get(handle, gralloc4::MetadataType_PixelFormatRequested, vec)))
@@ -150,6 +150,28 @@ c2_status_t MfxGralloc4Module::GetBackingStore(const buffer_handle_t handle, uin
150150
return res;
151151
}
152152

153+
buffer_handle_t MfxGralloc4Module::ImportBuffer(const buffer_handle_t rawHandle)
154+
{
155+
MFX_DEBUG_TRACE_FUNC;
156+
c2_status_t res = C2_OK;
157+
buffer_handle_t outBuffer = nullptr;
158+
Error4 err;
159+
160+
if (nullptr == m_mapper)
161+
res = C2_CORRUPTED;
162+
if (C2_OK == res)
163+
{
164+
m_mapper->importBuffer(hardware::hidl_handle(rawHandle), [&](const Error4 & tmpError, void * tmpBuffer) {
165+
err = tmpError;
166+
outBuffer = static_cast<buffer_handle_t>(tmpBuffer);
167+
});
168+
if (IsFailed(err))
169+
res = C2_CORRUPTED;
170+
}
171+
MFX_DEBUG_TRACE__android_c2_status_t(res);
172+
return outBuffer;
173+
}
174+
153175
c2_status_t MfxGralloc4Module::LockFrame(buffer_handle_t handle, uint8_t** data, C2PlanarLayout *layout)
154176
{
155177
MFX_DEBUG_TRACE_FUNC;

mfx_c2_defs.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ endif
2424

2525
# Android version preference:
2626
# We start codec2.0 development starting from Android R
27+
ifneq ($(filter 14 14.% U% ,$(PLATFORM_VERSION)),)
28+
MFX_ANDROID_VERSION:= MFX_U
29+
endif
2730
ifneq ($(filter 13 13.% T% ,$(PLATFORM_VERSION)),)
2831
MFX_ANDROID_VERSION:= MFX_T
2932
endif

0 commit comments

Comments
 (0)