Skip to content

Commit

Permalink
Add a param for setting output usage.
Browse files Browse the repository at this point in the history
Add a parameter to AOSP for setting the buffer useage of output memory
Once it is set as CPU_READ, force to use system memory, instead of
video memory.
Remove the valiable m_consumerUsage which is only set as default.

Tracked-On: OAM-111768
Signed-off-by: Shaofeng Tang <[email protected]>
  • Loading branch information
Shao-Feng committed Oct 16, 2023
1 parent 6459655 commit cc2d2d0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
3 changes: 1 addition & 2 deletions c2_components/include/mfx_c2_decoder_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,6 @@ class MfxC2DecoderComponent : public MfxC2Component

std::vector<std::unique_ptr<C2Param>> m_updatingC2Configures;

uint64_t m_consumerUsage;

uint32_t m_surfaceNum;
std::list<std::shared_ptr<mfxFrameSurface1>> m_surfacePool; // used in case of system memory

Expand Down Expand Up @@ -281,6 +279,7 @@ class MfxC2DecoderComponent : public MfxC2Component
std::shared_ptr<C2StreamColorAspectsTuning::output> m_defaultColorAspects;
std::shared_ptr<C2StreamColorAspectsInfo::input> m_codedColorAspects;
std::shared_ptr<C2StreamColorAspectsInfo::output> m_colorAspects;
std::shared_ptr<C2StreamUsageTuning::output> m_outputUsage;
/* ----------------------------------------Setters------------------------------------------- */
static C2R OutputSurfaceAllocatorSetter(bool mayBlock, C2P<C2PortSurfaceAllocatorTuning::output> &me);
static C2R SizeSetter(bool mayBlock, const C2P<C2StreamPictureSizeInfo::output> &oldMe,
Expand Down
24 changes: 14 additions & 10 deletions c2_components/src/mfx_c2_decoder_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ enum VP8_LEVEL {
LEVEL_VP8_Version0 = C2_PROFILE_LEVEL_VENDOR_START,
};


C2R MfxC2DecoderComponent::OutputSurfaceAllocatorSetter(bool mayBlock, C2P<C2PortSurfaceAllocatorTuning::output> &me) {
(void)mayBlock;
(void)me;
Expand Down Expand Up @@ -222,6 +221,13 @@ MfxC2DecoderComponent::MfxC2DecoderComponent(const C2String name, const CreateCo
.withConstValue(AllocSharedString<C2PortMediaTypeSetting::output>("video/raw"))
.build());

addParameter(
DefineParam(m_outputUsage, C2_PARAMKEY_OUTPUT_STREAM_USAGE)
.withDefault(new C2StreamUsageTuning::output(0u, C2AndroidMemoryUsage::HW_CODEC_WRITE))
.withFields({C2F(m_outputUsage, value).any()})
.withSetter(Setter<decltype(*m_outputUsage)>::StrictValueWithNoDeps)
.build());

switch(m_decoderType) {
case DECODER_H264: {
m_uOutputDelay = /*max_dpb_size*/16 + /*for async depth*/1 + /*for msdk unref in sync part*/1;
Expand Down Expand Up @@ -280,7 +286,6 @@ MfxC2DecoderComponent::MfxC2DecoderComponent(const C2String name, const CreateCo
}
case DECODER_H265: {
m_uOutputDelay = /*max_dpb_size*/16 + /*for async depth*/1 + /*for msdk unref in sync part*/1;

m_uInputDelay = 15;

addParameter(
Expand Down Expand Up @@ -640,9 +645,6 @@ MfxC2DecoderComponent::MfxC2DecoderComponent(const C2String name, const CreateCo
m_hdrStaticInfo->maxCll = 0;
m_hdrStaticInfo->maxFall = 0;

// By default prepare buffer to be displayed on any of the common surfaces
m_consumerUsage = kDefaultConsumerUsage;

MFX_ZERO_MEMORY(m_signalInfo);
//m_paramStorage.DumpParams();
}
Expand Down Expand Up @@ -1124,7 +1126,7 @@ mfxStatus MfxC2DecoderComponent::InitDecoder(std::shared_ptr<C2BlockPool> c2_all

if (MFX_ERR_NONE == mfx_res) {
// set memory type according to consumer usage sent from framework
m_mfxVideoParams.IOPattern = (C2MemoryUsage::CPU_READ == m_consumerUsage) ?
m_mfxVideoParams.IOPattern = (C2MemoryUsage::CPU_READ == m_outputUsage->value) ?
MFX_IOPATTERN_OUT_SYSTEM_MEMORY : MFX_IOPATTERN_OUT_VIDEO_MEMORY;
MFX_DEBUG_TRACE_I32(m_mfxVideoParams.IOPattern);
MFX_DEBUG_TRACE_I32(m_mfxVideoParams.mfx.FrameInfo.Width);
Expand Down Expand Up @@ -1183,9 +1185,11 @@ mfxStatus MfxC2DecoderComponent::InitDecoder(std::shared_ptr<C2BlockPool> c2_all
uint64_t usage, igbp_id;
android::_UnwrapNativeCodec2GrallocMetadata(out_block->handle(), &width, &height, &format, &usage,
&stride, &generation, &igbp_id, &igbp_slot);
if ((!igbp_id && !igbp_slot) || (!igbp_id && igbp_slot == 0xffffffff))
MFX_DEBUG_TRACE_PRINTF("m_outputUsage is C2MemoryUsage::CPU_READ? %s", m_outputUsage->value == C2MemoryUsage::CPU_READ? "Y": "N");
if((!igbp_id && !igbp_slot) || (!igbp_id && igbp_slot == 0xffffffff) || m_outputUsage->value == C2MemoryUsage::CPU_READ)
{
// No surface & BQ
MFX_DEBUG_TRACE_PRINTF("No surface & BQ, Force to use System memory");
m_mfxVideoParams.IOPattern = MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
m_allocator = nullptr;
}
Expand All @@ -1212,7 +1216,7 @@ mfxStatus MfxC2DecoderComponent::InitDecoder(std::shared_ptr<C2BlockPool> c2_all
if (m_allocator) {
m_allocator->SetC2Allocator(c2_allocator);
m_allocator->SetBufferCount(m_uOutputDelay);
m_allocator->SetConsumerUsage(m_consumerUsage);
m_allocator->SetConsumerUsage(m_outputUsage->value);
}

MFX_DEBUG_TRACE_MSG("Decoder initializing...");
Expand Down Expand Up @@ -1748,7 +1752,7 @@ c2_status_t MfxC2DecoderComponent::AllocateC2Block(uint32_t width, uint32_t heig

if (m_mfxVideoParams.IOPattern == MFX_IOPATTERN_OUT_VIDEO_MEMORY) {

C2MemoryUsage mem_usage = {m_consumerUsage, C2AndroidMemoryUsage::HW_CODEC_WRITE};
C2MemoryUsage mem_usage = {m_outputUsage->value, C2AndroidMemoryUsage::HW_CODEC_WRITE};
res = m_c2Allocator->fetchGraphicBlock(width, height,
MfxFourCCToGralloc(fourcc), mem_usage, out_block);
if (res == C2_OK) {
Expand All @@ -1773,7 +1777,7 @@ c2_status_t MfxC2DecoderComponent::AllocateC2Block(uint32_t width, uint32_t heig
}
} else if (m_mfxVideoParams.IOPattern == MFX_IOPATTERN_OUT_SYSTEM_MEMORY) {

C2MemoryUsage mem_usage = {m_consumerUsage, C2MemoryUsage::CPU_WRITE};
C2MemoryUsage mem_usage = {m_outputUsage->value, C2MemoryUsage::CPU_WRITE};
res = m_c2Allocator->fetchGraphicBlock(width, height,
MfxFourCCToGralloc(fourcc, false), mem_usage, out_block);
}
Expand Down

0 comments on commit cc2d2d0

Please sign in to comment.