Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
CastagnaIT committed Aug 16, 2023
1 parent 59c3274 commit 74afb35
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
85 changes: 85 additions & 0 deletions src/codechandler/AudioCodecHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#include "../utils/Utils.h"

#include <bento4/Ap4Mp4AudioInfo.h>

using namespace UTILS;

AudioCodecHandler::AudioCodecHandler(AP4_SampleDescription* sd) : CodecHandler(sd)
Expand All @@ -30,30 +32,60 @@ bool AudioCodecHandler::GetInformation(kodi::addon::InputstreamInfo& info)
if (m_sampleDescription->GetType() == AP4_SampleDescription::TYPE_MPEG)
{
std::string codecName;
STREAMCODEC_PROFILE codecProfile{CodecProfileUnknown};

switch (static_cast<AP4_MpegSampleDescription*>(m_sampleDescription)->GetObjectTypeId())
{
case AP4_OTI_MPEG4_AUDIO:
codecProfile = static_cast<STREAMCODEC_PROFILE>(GetMpeg4AACProfile());
codecName = CODEC::NAME_AAC;
break;
case AP4_OTI_MPEG2_AAC_AUDIO_MAIN:
codecProfile = AACCodecProfileMAIN;
codecName = CODEC::NAME_AAC;
break;
case AP4_OTI_MPEG2_AAC_AUDIO_LC:
codecProfile = MPEG2AACCodecProfileLOW;
codecName = CODEC::NAME_AAC;
break;
case AP4_OTI_MPEG2_AAC_AUDIO_SSRP:
codecName = CODEC::NAME_AAC;
break;
case AP4_OTI_DTS_AUDIO:
codecProfile = DTSCodecProfile;
codecName = CODEC::NAME_DTS;
break;
case AP4_OTI_DTS_HIRES_AUDIO:
codecProfile = DTSCodecProfileHDHRA;
codecName = CODEC::NAME_DTS;
break;
case AP4_OTI_DTS_MASTER_AUDIO:
codecProfile = DTSCodecProfileHDMA;
codecName = CODEC::NAME_DTS;
break;
case AP4_OTI_DTS_EXPRESS_AUDIO:
codecProfile = DTSCodecProfileHDExpress;
codecName = CODEC::NAME_DTS;
break;
case AP4_OTI_AC3_AUDIO:
codecName = CODEC::NAME_AC3;
break;
case AP4_OTI_EAC3_AUDIO:
// Currently Bento4 cannot read atmos signal flag: flag_ec3_extension_type_a
// https://ott.dolby.com/OnDelKits/DDP/Dolby_Digital_Plus_Online_Delivery_Kit_v1.5/Documentation/Content_Creation/SDM/help_files/topics/ddp_mpeg_dash_c_signal_atmos_in_isobmf_2.html
// so atm we cannot determine the atmos profile
codecName = CODEC::NAME_EAC3;
break;
}

if (!codecName.empty())
isChanged = UpdateInfoCodecName(info, codecName.c_str());

if (codecProfile != CodecProfileUnknown && info.GetCodecProfile() != codecProfile)
{
info.SetCodecProfile(codecProfile);
isChanged = true;
}
}

if (AP4_AudioSampleDescription* audioSd =
Expand All @@ -80,3 +112,56 @@ bool AudioCodecHandler::GetInformation(kodi::addon::InputstreamInfo& info)

return isChanged;
}

int AudioCodecHandler::GetMpeg4AACProfile()
{
AP4_MpegAudioSampleDescription* mpegDesc =
AP4_DYNAMIC_CAST(AP4_MpegAudioSampleDescription, m_sampleDescription);
if (mpegDesc)
{
AP4_MpegAudioSampleDescription::Mpeg4AudioObjectType ot = mpegDesc->GetMpeg4AudioObjectType();
switch (ot)
{
case AP4_MPEG4_AUDIO_OBJECT_TYPE_AAC_MAIN:
return AACCodecProfileMAIN;
break;
case AP4_MPEG4_AUDIO_OBJECT_TYPE_AAC_LC:
{
const AP4_DataBuffer& dsi = mpegDesc->GetDecoderInfo();
if (dsi.GetDataSize() > 0)
{
AP4_Mp4AudioDecoderConfig decConfig;
AP4_Result result = decConfig.Parse(dsi.GetData(), dsi.GetDataSize());
if (AP4_SUCCEEDED(result))
{
if (decConfig.m_Extension.m_PsPresent)
{
return AACCodecProfileHEV2; // HE-AAC v2
}
else if (decConfig.m_Extension.m_SbrPresent)
{
return AACCodecProfileHE; // HE-AAC
}
}
}
return AACCodecProfileLOW;
break;
}
case AP4_MPEG4_AUDIO_OBJECT_TYPE_AAC_SSR:
return AACCodecProfileSSR;
break;
case AP4_MPEG4_AUDIO_OBJECT_TYPE_AAC_LTP:
return AACCodecProfileLTP;
break;
case AP4_MPEG4_AUDIO_OBJECT_TYPE_SBR:
return AACCodecProfileHE; // HE-AAC
break;
case AP4_MPEG4_AUDIO_OBJECT_TYPE_PS:
return AACCodecProfileHEV2; // HE-AAC v2
break;
default:
break;
}
}
return CodecProfileUnknown;
}
3 changes: 3 additions & 0 deletions src/codechandler/AudioCodecHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ class ATTR_DLL_LOCAL AudioCodecHandler : public CodecHandler
AudioCodecHandler(AP4_SampleDescription* sd);

bool GetInformation(kodi::addon::InputstreamInfo& info) override;

protected:
int GetMpeg4AACProfile();
};

0 comments on commit 74afb35

Please sign in to comment.