From 38858f07809b4f089c4ba710f9b31eddfc83c1f3 Mon Sep 17 00:00:00 2001 From: bohu Date: Tue, 17 May 2022 23:04:08 -0700 Subject: codecs: get decoder output mode using pool id There are two modes of decoding: 1, decoding into bytebuffer 2, decoding into surface (host color buffer for emulator) previous way of getting this mode is not working anymore. now, change it to use the buffer pool id, which is either GRAPHIC(host color buffer) or LINEAR (bytebuffer). Bug: 232881288 Test: atest android.media.decoder.cts.ImageReaderDecoderTest Change-Id: Iff124e74fb95ebb4377a311d1224ef9bb944f195 --- .../codecs/c2/decoders/avcdec/C2GoldfishAvcDec.cpp | 32 ++++----------- .../c2/decoders/hevcdec/C2GoldfishHevcDec.cpp | 32 ++++----------- .../codecs/c2/decoders/vpxdec/C2GoldfishVpxDec.cpp | 45 +++++++--------------- 3 files changed, 27 insertions(+), 82 deletions(-) (limited to 'system/codecs') diff --git a/system/codecs/c2/decoders/avcdec/C2GoldfishAvcDec.cpp b/system/codecs/c2/decoders/avcdec/C2GoldfishAvcDec.cpp index d9e7f3bc..8e871458 100644 --- a/system/codecs/c2/decoders/avcdec/C2GoldfishAvcDec.cpp +++ b/system/codecs/c2/decoders/avcdec/C2GoldfishAvcDec.cpp @@ -670,31 +670,13 @@ C2GoldfishAvcDec::ensureDecoderState(const std::shared_ptr &pool) { void C2GoldfishAvcDec::checkMode(const std::shared_ptr &pool) { mWidth = mIntf->width(); mHeight = mIntf->height(); - { - // now get the block - constexpr uint32_t format = HAL_PIXEL_FORMAT_YCBCR_420_888; - std::shared_ptr block; - C2MemoryUsage usage = {C2MemoryUsage::CPU_READ, - C2MemoryUsage::CPU_WRITE}; - usage.expected = (uint64_t)(BufferUsage::VIDEO_DECODER); - - c2_status_t err = pool->fetchGraphicBlock(align(mWidth, 16), mHeight, - format, usage, &block); - if (err != C2_OK) { - ALOGE("fetchGraphicBlock for Output failed with status %d", err); - return; - } - auto c2Handle = block->handle(); - native_handle_t *grallocHandle = - UnwrapNativeCodec2GrallocHandle(c2Handle); - int hostColorBufferId = getColorBufferHandle(grallocHandle); - if (hostColorBufferId > 0) { - DDD("decoding to host color buffer"); - mEnableAndroidNativeBuffers = true; - } else { - DDD("decoding to guest byte buffer"); - mEnableAndroidNativeBuffers = false; - } + const bool isGraphic = (pool->getAllocatorId() == C2Allocator::GRAPHIC); + if (isGraphic) { + DDD("decoding to host color buffer"); + mEnableAndroidNativeBuffers = false; + } else { + DDD("decoding to guest byte buffer"); + mEnableAndroidNativeBuffers = false; } } diff --git a/system/codecs/c2/decoders/hevcdec/C2GoldfishHevcDec.cpp b/system/codecs/c2/decoders/hevcdec/C2GoldfishHevcDec.cpp index b2f684a6..7aac56f8 100644 --- a/system/codecs/c2/decoders/hevcdec/C2GoldfishHevcDec.cpp +++ b/system/codecs/c2/decoders/hevcdec/C2GoldfishHevcDec.cpp @@ -661,31 +661,13 @@ C2GoldfishHevcDec::ensureDecoderState(const std::shared_ptr &pool) void C2GoldfishHevcDec::checkMode(const std::shared_ptr &pool) { mWidth = mIntf->width(); mHeight = mIntf->height(); - { - // now get the block - constexpr uint32_t format = HAL_PIXEL_FORMAT_YCBCR_420_888; - std::shared_ptr block; - C2MemoryUsage usage = {C2MemoryUsage::CPU_READ, - C2MemoryUsage::CPU_WRITE}; - usage.expected = (uint64_t)(BufferUsage::VIDEO_DECODER); - - c2_status_t err = pool->fetchGraphicBlock(align(mWidth, 16), mHeight, - format, usage, &block); - if (err != C2_OK) { - ALOGE("fetchGraphicBlock for Output failed with status %d", err); - return; - } - auto c2Handle = block->handle(); - native_handle_t *grallocHandle = - UnwrapNativeCodec2GrallocHandle(c2Handle); - int hostColorBufferId = getColorBufferHandle(grallocHandle); - if (hostColorBufferId > 0) { - DDD("decoding to host color buffer"); - mEnableAndroidNativeBuffers = true; - } else { - DDD("decoding to guest byte buffer"); - mEnableAndroidNativeBuffers = false; - } + const bool isGraphic = (pool->getAllocatorId() == C2Allocator::GRAPHIC); + if (isGraphic) { + DDD("decoding to host color buffer"); + mEnableAndroidNativeBuffers = false; + } else { + DDD("decoding to guest byte buffer"); + mEnableAndroidNativeBuffers = false; } } diff --git a/system/codecs/c2/decoders/vpxdec/C2GoldfishVpxDec.cpp b/system/codecs/c2/decoders/vpxdec/C2GoldfishVpxDec.cpp index 99ddcfd2..bb61cf94 100644 --- a/system/codecs/c2/decoders/vpxdec/C2GoldfishVpxDec.cpp +++ b/system/codecs/c2/decoders/vpxdec/C2GoldfishVpxDec.cpp @@ -465,32 +465,13 @@ void C2GoldfishVpxDec::checkContext(const std::shared_ptr &pool) { mCtx = new vpx_codec_ctx_t; mCtx->vpversion = mMode == MODE_VP8 ? 8 : 9; - // check for decoding mode: - { - // now get the block - constexpr uint32_t format = HAL_PIXEL_FORMAT_YCBCR_420_888; - std::shared_ptr block; - C2MemoryUsage usage = {C2MemoryUsage::CPU_READ, - C2MemoryUsage::CPU_WRITE}; - usage.expected = (uint64_t)(BufferUsage::VIDEO_DECODER); - - c2_status_t err = pool->fetchGraphicBlock(align(mWidth, 2), mHeight, - format, usage, &block); - if (err != C2_OK) { - ALOGE("fetchGraphicBlock for Output failed with status %d", err); - return; - } - auto c2Handle = block->handle(); - native_handle_t *grallocHandle = - UnwrapNativeCodec2GrallocHandle(c2Handle); - int hostColorBufferId = getColorBufferHandle(grallocHandle); - if (hostColorBufferId > 0) { - DDD("decoding to host color buffer"); - mEnableAndroidNativeBuffers = true; - } else { - DDD("decoding to guest byte buffer"); - mEnableAndroidNativeBuffers = false; - } + const bool isGraphic = (pool->getAllocatorId() == C2Allocator::GRAPHIC); + if (isGraphic) { + DDD("decoding to host color buffer"); + mEnableAndroidNativeBuffers = false; + } else { + DDD("decoding to guest byte buffer"); + mEnableAndroidNativeBuffers = false; } mCtx->version = mEnableAndroidNativeBuffers ? 200 : 100; @@ -721,24 +702,24 @@ C2GoldfishVpxDec::outputBuffer(const std::shared_ptr &pool, return UNKNOWN_ERROR; } - bool decodingToByteBuffer = false; - { + int hostColorBufferId = -1; + const bool decodingToHostColorBuffer = mEnableAndroidNativeBuffers; + if(decodingToHostColorBuffer){ auto c2Handle = block->handle(); native_handle_t *grallocHandle = UnwrapNativeCodec2GrallocHandle(c2Handle); - int hostColorBufferId = getColorBufferHandle(grallocHandle); + hostColorBufferId = getColorBufferHandle(grallocHandle); if (hostColorBufferId > 0) { DDD("found handle %d", hostColorBufferId); } else { - decodingToByteBuffer = true; DDD("decode to buffer, because handle %d is invalid", hostColorBufferId); // change to -1 so host knows it is definitely invalid // 0 is a bit confusing hostColorBufferId = -1; } - setup_ctx_parameters(mCtx, hostColorBufferId); } + setup_ctx_parameters(mCtx, hostColorBufferId); vpx_image_t *img = vpx_codec_get_frame(mCtx); @@ -798,7 +779,7 @@ C2GoldfishVpxDec::outputBuffer(const std::shared_ptr &pool, } } - if (decodingToByteBuffer) { + if (!decodingToHostColorBuffer) { C2GraphicView wView = block->map().get(); if (wView.error()) { -- cgit v1.2.3