Skip to content

Commit

Permalink
Merge pull request #23079 from thexai/dovi-compatibility
Browse files Browse the repository at this point in the history
[Android] improve Dolby Vision compatibility
  • Loading branch information
thexai committed Mar 31, 2023
2 parents 154a807 + 8769b1f commit 847a347
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,13 @@ bool CDVDVideoCodecAndroidMediaCodec::Open(CDVDStreamInfo &hints, CDVDCodecOptio
"Display: {}, MediaCodec: {}",
displaySupportsDovi, mediaCodecSupportsDovi);

if (mediaCodecSupportsDovi)
// For Dolby Vision profiles that don't have HDR10 fallback, always use
// the dvhe decoder even if the display not supports Dolby Vision.
// For profiles that has HDR10 fallback (7, 8) is better use HEVC decoder to
// ensure HDR10 output if display is not DV capable.
bool notHasHDR10fallback = (m_hints.dovi.dv_profile == 4 || m_hints.dovi.dv_profile == 5);

if (mediaCodecSupportsDovi && (displaySupportsDovi || notHasHDR10fallback))
{
m_mime = "video/dolby-vision";
m_formatname = isDvhe ? "amc-dvhe" : "amc-dvh1";
Expand Down
2 changes: 2 additions & 0 deletions xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemux.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class IAddonProvider;
extern "C"
{
#include <libavcodec/avcodec.h>
#include <libavutil/dovi_meta.h>
#include <libavutil/mastering_display_metadata.h>
}

Expand Down Expand Up @@ -150,6 +151,7 @@ class CDemuxStreamVideo : public CDemuxStream

std::string stereo_mode; // expected stereo mode
StreamHdrType hdr_type = StreamHdrType::HDR_TYPE_NONE; // type of HDR for this stream (hdr10, etc)
AVDOVIDecoderConfigurationRecord dovi{};
};

class CDemuxStreamAudio : public CDemuxStream
Expand Down
13 changes: 12 additions & 1 deletion xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ extern "C"
#include <stdint.h>
#endif

extern "C" {
extern "C"
{
#include <libavutil/dict.h>
#include <libavutil/dovi_meta.h>
#include <libavutil/opt.h>
}

Expand Down Expand Up @@ -1689,6 +1691,15 @@ CDemuxStream* CDVDDemuxFFmpeg::AddStream(int streamIdx)
size_t size = 0;
uint8_t* side_data = nullptr;

if (st->hdr_type == StreamHdrType::HDR_TYPE_DOLBYVISION)
{
side_data = av_stream_get_side_data(pStream, AV_PKT_DATA_DOVI_CONF, &size);
if (side_data && size)
{
st->dovi = *reinterpret_cast<AVDOVIDecoderConfigurationRecord*>(side_data);
}
}

side_data = av_stream_get_side_data(pStream, AV_PKT_DATA_MASTERING_DISPLAY_METADATA, &size);
if (side_data && size)
{
Expand Down
8 changes: 8 additions & 0 deletions xbmc/cores/VideoPlayer/DVDStreamInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "DVDDemuxers/DVDDemux.h"
#include "cores/VideoPlayer/Interface/DemuxCrypto.h"

#include <cstring>

CDVDStreamInfo::CDVDStreamInfo() { extradata = NULL; Clear(); }
CDVDStreamInfo::CDVDStreamInfo(const CDVDStreamInfo &right, bool withextradata ) { extradata = NULL; Clear(); Assign(right, withextradata); }
CDVDStreamInfo::CDVDStreamInfo(const CDemuxStream &right, bool withextradata ) { extradata = NULL; Clear(); Assign(right, withextradata); }
Expand Down Expand Up @@ -64,6 +66,7 @@ void CDVDStreamInfo::Clear()
masteringMetadata = nullptr;
contentLightMetadata = nullptr;
stereo_mode.clear();
dovi = {};

channels = 0;
samplerate = 0;
Expand Down Expand Up @@ -152,6 +155,9 @@ bool CDVDStreamInfo::Equal(const CDVDStreamInfo& right, int compare)
else if (contentLightMetadata || right.contentLightMetadata)
return false;

if (0 != std::memcmp(&dovi, &right.dovi, sizeof(AVDOVIDecoderConfigurationRecord)))
return false;

// AUDIO
if( channels != right.channels
|| samplerate != right.samplerate
Expand Down Expand Up @@ -237,6 +243,7 @@ void CDVDStreamInfo::Assign(const CDVDStreamInfo& right, bool withextradata)
masteringMetadata = right.masteringMetadata;
contentLightMetadata = right.contentLightMetadata;
stereo_mode = right.stereo_mode;
dovi = right.dovi;

// AUDIO
channels = right.channels;
Expand Down Expand Up @@ -307,6 +314,7 @@ void CDVDStreamInfo::Assign(const CDemuxStream& right, bool withextradata)
masteringMetadata = stream->masteringMetaData;
contentLightMetadata = stream->contentLightMetaData;
stereo_mode = stream->stereo_mode;
dovi = stream->dovi;
}
else if (right.type == STREAM_SUBTITLE)
{
Expand Down
5 changes: 4 additions & 1 deletion xbmc/cores/VideoPlayer/DVDStreamInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@

#include "DVDDemuxers/DVDDemux.h"

extern "C" {
extern "C"
{
#include <libavcodec/avcodec.h>
#include <libavutil/dovi_meta.h>
}

#define CODEC_FORCE_SOFTWARE 0x01
Expand Down Expand Up @@ -76,6 +78,7 @@ class CDVDStreamInfo
std::shared_ptr<AVMasteringDisplayMetadata> masteringMetadata;
std::shared_ptr<AVContentLightMetadata> contentLightMetadata;
std::string stereo_mode; // stereoscopic 3d mode
AVDOVIDecoderConfigurationRecord dovi{};

// AUDIO
int channels;
Expand Down

0 comments on commit 847a347

Please sign in to comment.