Skip to content

Commit

Permalink
[Decode] Enable AV1 HDR extract from clips (#6206)
Browse files Browse the repository at this point in the history
Co-authored-by: Yuan, Pengxin <[email protected]>
  • Loading branch information
gfxVPLsdm and pengxin99 authored Dec 5, 2023
1 parent a7bc259 commit 0d0ba3c
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 0 deletions.
34 changes: 34 additions & 0 deletions _studio/mfx_lib/decode/av1/src/mfx_av1_dec_decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,40 @@ mfxStatus VideoDECODEAV1::FillOutputSurface(mfxFrameSurface1** surf_out, mfxFram
surface_out->Info.FrameRateExtD = isShouldUpdate ? m_init_par.mfx.FrameInfo.FrameRateExtD : m_first_par.mfx.FrameInfo.FrameRateExtD;
surface_out->Info.FrameRateExtN = isShouldUpdate ? m_init_par.mfx.FrameInfo.FrameRateExtN : m_first_par.mfx.FrameInfo.FrameRateExtN;

const UMC_AV1_DECODER::FrameHeader& fh = pFrame->GetFrameHeader();
// extract HDR MasteringDisplayColourVolume info
mfxExtMasteringDisplayColourVolume* display_colour = (mfxExtMasteringDisplayColourVolume*)GetExtendedBuffer(surface_out->Data.ExtParam, surface_out->Data.NumExtParam, MFX_EXTBUFF_MASTERING_DISPLAY_COLOUR_VOLUME);
if (display_colour && fh.meta_data.hdr_mdcv.existence)
{
for (size_t i = 0; i < 3; i++)
{
display_colour->DisplayPrimariesX[i] = (mfxU16)fh.meta_data.hdr_mdcv.display_primaries[i][0];
display_colour->DisplayPrimariesY[i] = (mfxU16)fh.meta_data.hdr_mdcv.display_primaries[i][1];
}
display_colour->WhitePointX = (mfxU16)fh.meta_data.hdr_mdcv.white_point[0];
display_colour->WhitePointY = (mfxU16)fh.meta_data.hdr_mdcv.white_point[1];
display_colour->MaxDisplayMasteringLuminance = (mfxU32)fh.meta_data.hdr_mdcv.max_luminance;
display_colour->MinDisplayMasteringLuminance = (mfxU32)fh.meta_data.hdr_mdcv.min_luminance;
display_colour->InsertPayloadToggle = MFX_PAYLOAD_IDR;
}
else if(display_colour)
{
display_colour->InsertPayloadToggle = MFX_PAYLOAD_OFF;
}

// extract HDR ContentLightLevel info
mfxExtContentLightLevelInfo* content_light = (mfxExtContentLightLevelInfo*)GetExtendedBuffer(surface_out->Data.ExtParam, surface_out->Data.NumExtParam, MFX_EXTBUFF_CONTENT_LIGHT_LEVEL_INFO);
if (content_light && fh.meta_data.hdr_cll.existence)
{
content_light->MaxContentLightLevel = (mfxU16)fh.meta_data.hdr_cll.max_content_light_level;
content_light->MaxPicAverageLightLevel = (mfxU16)fh.meta_data.hdr_cll.max_pic_average_light_level;
content_light->InsertPayloadToggle = MFX_PAYLOAD_IDR;
}
else if(content_light)
{
content_light->InsertPayloadToggle = MFX_PAYLOAD_OFF;
}

TRACE_BUFFER_EVENT(MFX_TRACE_API_AV1_OUTPUTINFO_TASK, EVENT_TYPE_INFO, TR_KEY_DECODE_BASIC_INFO,
surface_out, AV1DecodeSurfaceOutparam, SURFACEOUT_AV1D);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace UMC_AV1_DECODER
uint64_t GetLE(uint32_t);
void ReadSequenceHeader(SequenceHeader&);
void ReadUncompressedHeader(FrameHeader&, SequenceHeader const&, DPBType const&, OBUHeader const&, uint32_t&);
void ReadMetaData(FrameHeader& fh);

using UMC_VP9_DECODER::VP9Bitstream::VP9Bitstream;

Expand Down
30 changes: 30 additions & 0 deletions _studio/shared/umc/codec/av1_dec/include/umc_av1_dec_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ namespace UMC_AV1_DECODER
OBU_PADDING = 15,
};

/* OBU metadata types. */
enum OBU_METADATA_TYPE
{
OBU_METADATA_TYPE_AOM_RESERVED_0 = 0,
OBU_METADATA_TYPE_HDR_CLL = 1,
OBU_METADATA_TYPE_HDR_MDCV = 2,
OBU_METADATA_TYPE_SCALABILITY = 3,
OBU_METADATA_TYPE_ITUT_T35 = 4,
OBU_METADATA_TYPE_TIMECODE = 5,
};

const uint32_t OBU_TILE_LIST_HEADER_LENGTH = 4;
const uint32_t OBU_TILE_LIST_ENTRY_HEDAER_LENGTH = 5;

Expand Down Expand Up @@ -548,6 +559,24 @@ namespace UMC_AV1_DECODER
uint32_t FrameHeight;
};

struct MetaData
{
struct MasteringDisplayColorVolume
{
bool existence;
uint16_t display_primaries[3][2];
uint16_t white_point[2];
uint32_t max_luminance;
uint32_t min_luminance;
}hdr_mdcv;

struct ContentLightLevelInfo {
bool existence;
uint16_t max_content_light_level;
uint16_t max_pic_average_light_level;
}hdr_cll;
};

struct FrameHeader
{
//Rev 0.85 parameters (AV1 spec version 1.0) in order of appearance/calculation in uncompressed_header()
Expand Down Expand Up @@ -632,6 +661,7 @@ namespace UMC_AV1_DECODER
uint32_t enable_masked_compound;
uint32_t enable_intra_edge_filter;
uint32_t enable_filter_intra;
MetaData meta_data;
};

struct OBUHeader
Expand Down
29 changes: 29 additions & 0 deletions _studio/shared/umc/codec/av1_dec/src/umc_av1_bitstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2026,6 +2026,35 @@ namespace UMC_AV1_DECODER
AV1D_LOG("[-]: %d", (uint32_t)BitsDecoded());
}

void AV1Bitstream::ReadMetaData(FrameHeader& fh)
{
const uint8_t MetaData_byte = (uint8_t)GetBits(8);
switch ((OBU_METADATA_TYPE)MetaData_byte)
{
case OBU_METADATA_TYPE_HDR_CLL:
fh.meta_data.hdr_cll.max_content_light_level = (uint16_t)GetBits(16);
fh.meta_data.hdr_cll.max_pic_average_light_level = (uint16_t)GetBits(16);
fh.meta_data.hdr_cll.existence = true;
break;
case OBU_METADATA_TYPE_HDR_MDCV:
for (size_t i = 0; i < 3; ++i)
{
fh.meta_data.hdr_mdcv.display_primaries[i][0] = (uint16_t)GetBits(16);
fh.meta_data.hdr_mdcv.display_primaries[i][1] = (uint16_t)GetBits(16);
}
// White point(x, y)
fh.meta_data.hdr_mdcv.white_point[0] = (uint16_t)GetBits(16);
fh.meta_data.hdr_mdcv.white_point[1] = (uint16_t)GetBits(16);

// Max and min luminance of mastering display
fh.meta_data.hdr_mdcv.max_luminance = (uint32_t)GetBits(32);
fh.meta_data.hdr_mdcv.min_luminance = (uint32_t)GetBits(32);
fh.meta_data.hdr_mdcv.existence = true;
default:
break;
}
}

} // namespace UMC_AV1_DECODER

#endif // MFX_ENABLE_AV1_VIDEO_DECODE
3 changes: 3 additions & 0 deletions _studio/shared/umc/codec/av1_dec/src/umc_av1_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,9 @@ namespace UMC_AV1_DECODER
break;
}
}
case OBU_METADATA:
bs.ReadMetaData(fh);
break;
default:
break;
}
Expand Down

0 comments on commit 0d0ba3c

Please sign in to comment.