Skip to content

Commit

Permalink
AMLCodec: write HDR static metadata to config for VP9
Browse files Browse the repository at this point in the history
  • Loading branch information
arthur-liberman committed Jun 5, 2021
1 parent 8d30f66 commit fb3ff50
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
40 changes: 40 additions & 0 deletions xbmc/cores/VideoPlayer/DVDCodecs/Video/AMLCodec.cpp
Expand Up @@ -1751,6 +1751,15 @@ bool CAMLCodec::OpenDecoder(CDVDStreamInfo &hints)
// translate from generic to firmware version dependent
m_dll->codec_init_para(&am_private->gcodec, &am_private->vcodec);

std::string config_data = GetHDRStaticMetadata();
if (!config_data.empty())
{
am_private->vcodec.config_len = static_cast<int>(config_data.size());
am_private->vcodec.config = (char*)malloc(config_data.size() + 1);
config_data.copy(am_private->vcodec.config, config_data.size());
am_private->vcodec.config[am_private->vcodec.config_len] = '\0';
}

if (!am_private->vcodec.multi_vdec)
SetVfmMap("default", "decoder ppmgr amlvideo deinterlace amvideo");

Expand Down Expand Up @@ -1860,6 +1869,8 @@ void CAMLCodec::CloseDecoder()
am_packet_release(&am_private->am_pkt);
free(am_private->extradata);
am_private->extradata = NULL;
if (am_private->vcodec.config)
free(am_private->vcodec.config);
// return tsync to default so external apps work
SysfsUtils::SetInt("/sys/class/tsync/enable", 1);

Expand Down Expand Up @@ -2497,3 +2508,32 @@ unsigned int CAMLCodec::GetDecoderVideoRate()
else
return 0;
}

std::string CAMLCodec::GetHDRStaticMetadata()
{
// add static HDR metadata for VP9 content
if (am_private->video_format == VFORMAT_VP9 && m_hints.masteringMetadata && m_hints.contentLightMetadata)
{
static const double MAX_CHROMATICITY = 5000;
std::stringstream stream;
stream << "HDRStaticInfo:1";
stream << ";mR.x:" << static_cast<int>(av_q2d(m_hints.masteringMetadata->display_primaries[0][0]) * MAX_CHROMATICITY + 0.5);
stream << ";mR.y:" << static_cast<int>(av_q2d(m_hints.masteringMetadata->display_primaries[0][1]) * MAX_CHROMATICITY + 0.5);
stream << ";mG.x:" << static_cast<int>(av_q2d(m_hints.masteringMetadata->display_primaries[1][0]) * MAX_CHROMATICITY + 0.5);
stream << ";mG.y:" << static_cast<int>(av_q2d(m_hints.masteringMetadata->display_primaries[1][1]) * MAX_CHROMATICITY + 0.5);
stream << ";mB.x:" << static_cast<int>(av_q2d(m_hints.masteringMetadata->display_primaries[2][0]) * MAX_CHROMATICITY + 0.5);
stream << ";mB.y:" << static_cast<int>(av_q2d(m_hints.masteringMetadata->display_primaries[2][1]) * MAX_CHROMATICITY + 0.5);
stream << ";mW.x:" << static_cast<int>(av_q2d(m_hints.masteringMetadata->white_point[0]) * MAX_CHROMATICITY + 0.5);
stream << ";mW.y:" << static_cast<int>(av_q2d(m_hints.masteringMetadata->white_point[1]) * MAX_CHROMATICITY + 0.5);
stream << ";mMaxDL:" << static_cast<int>(av_q2d(m_hints.masteringMetadata->max_luminance) + 0.5);
stream << ";mMinDL:" << static_cast<int>(av_q2d(m_hints.masteringMetadata->min_luminance) + 0.5);
stream << ";mMaxCLL:" << m_hints.contentLightMetadata->MaxCLL;
stream << ";mMaxFALL:" << m_hints.contentLightMetadata->MaxFALL;
if (m_hints.colorTransferCharacteristic != AVCOL_TRC_UNSPECIFIED)
stream << ";mTransfer:" << static_cast<int>(m_hints.colorTransferCharacteristic);
std::string config_data = stream.str();
CLog::Log(LOGDEBUG, "CAMLCodec::GetHDRStaticMetadata - Created the following config: %s", config_data.c_str());
return config_data;
}
return std::string();
}
1 change: 1 addition & 0 deletions xbmc/cores/VideoPlayer/DVDCodecs/Video/AMLCodec.h
Expand Up @@ -67,6 +67,7 @@ class CAMLCodec
int DequeueBuffer();
float GetTimeSize();
unsigned int GetDecoderVideoRate();
std::string GetHDRStaticMetadata();

DllLibAmCodec *m_dll;
bool m_opened;
Expand Down

5 comments on commit fb3ff50

@kszaq
Copy link
Contributor

@kszaq kszaq commented on fb3ff50 Jun 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arthur-liberman on https://kodi.wiki/view/Samples#4K_.28UltraHD.29 there are 2 VP9 profile 2 samples that do not contain contentLightMetadata: "The Redwoods" and "The World in HDR".

Can you please take a look at caec255 - I can see that with this patch HDR info is passed to kernel but cannot verify due to no HDR display.

@arthur-liberman
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I actually checked these two videos. And when I didn't get HDR, I thought it was because these were in MKV container.
I'll make a new build later to see if this issue can be worked around, because right now the kernel expects to also get the content light metadata.

@kszaq
Copy link
Contributor

@kszaq kszaq commented on fb3ff50 Jun 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the linked patch these videos play correctly on SDR TV, no complaints from the kernel and in dmesg I could see that the metadata was passed and interpreted by the kernel.

@arthur-liberman
Copy link
Member Author

@arthur-liberman arthur-liberman commented on fb3ff50 Jun 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this. I added your fix and also fixed the luminance and chromaticity metadata which was not passed correctly to the kernel in the original commit.
511afed

@kszaq
Copy link
Contributor

@kszaq kszaq commented on fb3ff50 Jun 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thank you!

Please sign in to comment.