Skip to content

Commit

Permalink
Add Dolby Vision support
Browse files Browse the repository at this point in the history
  • Loading branch information
peak3d committed Apr 19, 2018
1 parent b3aa34c commit f61409e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/libbento4/Core/Ap4Protection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,11 @@ AP4_EncvSampleEntry::ToTargetSampleDescription(AP4_UI32 format)
m_Depth,
m_CompressorName.GetChars(),
this);

case AP4_SAMPLE_FORMAT_HVC1:
case AP4_SAMPLE_FORMAT_HEV1:
case AP4_SAMPLE_FORMAT_DVHE:
case AP4_SAMPLE_FORMAT_DVH1:
return new AP4_HevcSampleDescription(
format,
m_Width,
Expand Down
2 changes: 2 additions & 0 deletions lib/libbento4/Core/Ap4SampleDescription.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ const AP4_UI32 AP4_SAMPLE_FORMAT_AVC3 = AP4_ATOM_TYPE('a','v','c','3');
const AP4_UI32 AP4_SAMPLE_FORMAT_AVC4 = AP4_ATOM_TYPE('a','v','c','4');
const AP4_UI32 AP4_SAMPLE_FORMAT_HVC1 = AP4_ATOM_TYPE('h','v','c','1');
const AP4_UI32 AP4_SAMPLE_FORMAT_HEV1 = AP4_ATOM_TYPE('h','e','v','1');
const AP4_UI32 AP4_SAMPLE_FORMAT_DVHE = AP4_ATOM_TYPE('d','v','h','e');
const AP4_UI32 AP4_SAMPLE_FORMAT_DVH1 = AP4_ATOM_TYPE('d','v','h','1');
const AP4_UI32 AP4_SAMPLE_FORMAT_ALAC = AP4_ATOM_TYPE('a','l','a','c');
const AP4_UI32 AP4_SAMPLE_FORMAT_OWMA = AP4_ATOM_TYPE('o','w','m','a');
const AP4_UI32 AP4_SAMPLE_FORMAT_OVC1 = AP4_ATOM_TYPE('o','v','c','1');
Expand Down
38 changes: 38 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,41 @@ class HEVCCodecHandler : public CodecHandler
naluLengthSize = hevc->GetNaluLengthSize();
}
}

virtual bool ExtraDataToAnnexB() override
{
if (AP4_HevcSampleDescription *hevc = AP4_DYNAMIC_CAST(AP4_HevcSampleDescription, sample_description))
{
const AP4_Array<AP4_HvccAtom::Sequence>& sequences = hevc->GetSequences();

if (!sequences.ItemCount())
{
kodi::Log(ADDON_LOG_WARNING, "No available sequences for HEVC codec extra data");
return false;
}

//calculate the size for annexb
size_t sz(0);
for (const AP4_HvccAtom::Sequence *b(&sequences[0]), *e(&sequences[sequences.ItemCount()]); b != e; ++b)
for (const AP4_DataBuffer *bn(&b->m_Nalus[0]), *en(&b->m_Nalus[b->m_Nalus.ItemCount()]); bn != en; ++bn)
sz += (4 + bn->GetDataSize());

extra_data.SetDataSize(sz);
uint8_t *cursor(extra_data.UseData());

for (const AP4_HvccAtom::Sequence *b(&sequences[0]), *e(&sequences[sequences.ItemCount()]); b != e; ++b)
for (const AP4_DataBuffer *bn(&b->m_Nalus[0]), *en(&b->m_Nalus[b->m_Nalus.ItemCount()]); bn != en; ++bn)
{
cursor[0] = cursor[1] = cursor[2] = 0; cursor[3] = 1;
memcpy(cursor + 4, bn->GetData(), bn->GetDataSize());
cursor += bn->GetDataSize() + 4;
}
kodi::Log(ADDON_LOG_DEBUG, "Converted %lu bytes HEVC codec extradata", extra_data.GetDataSize());
return true;
}
kodi::Log(ADDON_LOG_WARNING, "No HevcSampleDescription - annexb extradata not available");
return false;
}
};

/*********************** MPEG ************************/
Expand Down Expand Up @@ -1194,6 +1229,7 @@ class FragmentedSampleReader : public SampleReader, public AP4_LinearReader
m_protectedDesc = static_cast<AP4_ProtectedSampleDescription*>(desc);
desc = m_protectedDesc->GetOriginalSampleDescription();
}
kodi::Log(ADDON_LOG_DEBUG, "UpdateSampleDescription: codec %d", desc->GetFormat());
switch (desc->GetFormat())
{
case AP4_SAMPLE_FORMAT_AVC1:
Expand All @@ -1204,6 +1240,8 @@ class FragmentedSampleReader : public SampleReader, public AP4_LinearReader
break;
case AP4_SAMPLE_FORMAT_HEV1:
case AP4_SAMPLE_FORMAT_HVC1:
case AP4_SAMPLE_FORMAT_DVHE:
case AP4_SAMPLE_FORMAT_DVH1:
m_codecHandler = new HEVCCodecHandler(desc);
break;
case AP4_SAMPLE_FORMAT_MP4A:
Expand Down

0 comments on commit f61409e

Please sign in to comment.