Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
getroot committed Oct 10, 2024
2 parents 2815415 + 68416ae commit 061d02d
Show file tree
Hide file tree
Showing 6 changed files with 195 additions and 115 deletions.
2 changes: 1 addition & 1 deletion src/projects/mediarouter/mediarouter_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ bool MediaRouteStream::ProcessAACAdtsStream(std::shared_ptr<MediaTrack> &media_t
}

auto audio_config = std::make_shared<AudioSpecificConfig>();
audio_config->SetOjbectType(adts.Profile());
audio_config->SetObjectType(adts.ObjectType());
audio_config->SetSamplingFrequency(adts.Samplerate());
audio_config->SetChannel(adts.ChannelConfiguration());

Expand Down
129 changes: 87 additions & 42 deletions src/projects/modules/bitstream/aac/aac_adts.cpp
Original file line number Diff line number Diff line change
@@ -1,44 +1,45 @@
#include "aac_adts.h"

#include <memory>
#include <base/ovlibrary/ovlibrary.h>
#include <base/ovlibrary/log.h>
#include <base/ovlibrary/bit_reader.h>
#include <base/ovlibrary/log.h>
#include <base/ovlibrary/ovlibrary.h>

#include <memory>

#define OV_LOG_TAG "AACAdts"

bool AACAdts::IsValid(const uint8_t *data, size_t data_length)
{
if(data == nullptr)
{
return false;
}
if (data == nullptr)
{
return false;
}

if(data_length < ADTS_MIN_SIZE)
if (data_length < ADTS_MIN_SIZE)
{
return false;
}
// check syncword
if( data[0] == 0xff && (data[1] & 0xf0) == 0xf0)
{
return true;
}

return false;

// check syncword
if (data[0] == 0xff && (data[1] & 0xf0) == 0xf0)
{
return true;
}

return false;
}

bool AACAdts::Parse(const uint8_t *data, size_t data_length, AACAdts &adts)
{
if(data_length < ADTS_MIN_SIZE)
if (data_length < ADTS_MIN_SIZE)
{
return false;
}

BitReader parser(data, data_length);

adts._syncword = parser.ReadBits<uint16_t>(12);
if(adts._syncword != 0xFFF)
if (adts._syncword != 0xFFF)
{
return false;
}
Expand All @@ -59,7 +60,7 @@ bool AACAdts::Parse(const uint8_t *data, size_t data_length, AACAdts &adts)
adts._adts_buffer_fullness = parser.ReadBits<uint16_t>(11);
adts._number_of_raw_data_blocks_in_frame = parser.ReadBits<uint8_t>(2);

if(adts._protection_absent == false)
if (adts._protection_absent == false)
{
adts._crc = parser.ReadBits<uint16_t>(16);
}
Expand All @@ -68,7 +69,7 @@ bool AACAdts::Parse(const uint8_t *data, size_t data_length, AACAdts &adts)
}

uint8_t AACAdts::Id()
{
{
return _id;
}

Expand All @@ -82,29 +83,73 @@ bool AACAdts::ProtectionAbsent()
return _protection_absent;
}

AacObjectType AACAdts::Profile()
AudioObjectType AACAdts::ObjectType()
{
return static_cast<AacObjectType>(_profile + 1);
switch (_profile)
{
case 0:
return AudioObjectType::AacMain;
case 1:
return AudioObjectType::AacLc;
case 2:
return AudioObjectType::AacSsr;
case 3:
return AudioObjectType::AacLtp;
}

return AudioObjectType::Null;
}

ov::String AACAdts::ProfileString()
#define OBJECT_TYPE_DESC_CASE(value, description) \
case AudioObjectType::value: \
return description

ov::String AACAdts::ObjectTypeString()
{
switch(Profile())
switch (ObjectType())
{
case AacObjectTypeAacMain:
return "AAC Main";
case AacObjectTypeAacLC:
return "AAC LC";
case AacObjectTypeAacSSR:
return "AAC SSR";
case AacObjecttypeAacLTP:
return "AAC LTP";
case AacObjectTypeAacHE:
return "AAC HE";
case AacObjectTypeAacHEV2:
return "AAC HEv2";
case AacObjectTypeNull:
break;
OBJECT_TYPE_DESC_CASE(Null, "Null");
OBJECT_TYPE_DESC_CASE(AacMain, "AAC main");
OBJECT_TYPE_DESC_CASE(AacLc, "AAC LC");
OBJECT_TYPE_DESC_CASE(AacSsr, "AAC SSR");
OBJECT_TYPE_DESC_CASE(AacLtp, "AAC LTP");
OBJECT_TYPE_DESC_CASE(Sbr, "SBR");
OBJECT_TYPE_DESC_CASE(AacScalable, "AAC Scalable");
OBJECT_TYPE_DESC_CASE(Twinvq, "TwinVQ");
OBJECT_TYPE_DESC_CASE(Celp, "CELP");
OBJECT_TYPE_DESC_CASE(Hvxc, "HVXC");
OBJECT_TYPE_DESC_CASE(Reserved10, "(reserved-10)");
OBJECT_TYPE_DESC_CASE(Reserved11, "(reserved-11)");
OBJECT_TYPE_DESC_CASE(Ttsi, "TTSI");
OBJECT_TYPE_DESC_CASE(MainSynthetic, "Main synthetic");
OBJECT_TYPE_DESC_CASE(WavetableSynthesis, "Wavetable synthesis");
OBJECT_TYPE_DESC_CASE(GeneralMidi, "General MIDI");
OBJECT_TYPE_DESC_CASE(AlgorithmicSynthesisAndAudioFx, "Algorithmic Synthesis and Audio FX");
OBJECT_TYPE_DESC_CASE(ErAacLc, "ER AAC LC");
OBJECT_TYPE_DESC_CASE(Reserved18, "(reserved-18)");
OBJECT_TYPE_DESC_CASE(ErAacLtp, "ER AAC LTP");
OBJECT_TYPE_DESC_CASE(ErAacScalable, "ER AAC Scalable");
OBJECT_TYPE_DESC_CASE(ErTwinvq, "ER TwinVQ");
OBJECT_TYPE_DESC_CASE(ErBsac, "ER BSAC");
OBJECT_TYPE_DESC_CASE(ErAacLd, "ER AAC LD");
OBJECT_TYPE_DESC_CASE(ErCelp, "ER CELP");
OBJECT_TYPE_DESC_CASE(ErHvxc, "ER HVXC");
OBJECT_TYPE_DESC_CASE(ErHiln, "ER HILN");
OBJECT_TYPE_DESC_CASE(ErParametric, "ER Parametric");
OBJECT_TYPE_DESC_CASE(Ssc, "SSC");
OBJECT_TYPE_DESC_CASE(Ps, "PS");
OBJECT_TYPE_DESC_CASE(MpegSurround, "MPEG Surround");
OBJECT_TYPE_DESC_CASE(Escape, "(escape)");
OBJECT_TYPE_DESC_CASE(Layer1, "Layer-1");
OBJECT_TYPE_DESC_CASE(Layer2, "Layer-2");
OBJECT_TYPE_DESC_CASE(Layer3, "Layer-3");
OBJECT_TYPE_DESC_CASE(Dst, "DST");
OBJECT_TYPE_DESC_CASE(Als, "ALS");
OBJECT_TYPE_DESC_CASE(Sls, "SLS");
OBJECT_TYPE_DESC_CASE(SlsNonCore, "SLS non-core");
OBJECT_TYPE_DESC_CASE(ErAacEld, "ER AAC ELD");
OBJECT_TYPE_DESC_CASE(SmrSimple, "SMR Simple");
OBJECT_TYPE_DESC_CASE(SmrMain, "SMR Main");
}

return "Unknown";
Expand All @@ -117,7 +162,7 @@ AacSamplingFrequencies AACAdts::Samplerate()

uint32_t AACAdts::SamplerateNum()
{
switch(Samplerate())
switch (Samplerate())
{
case RATES_96000HZ:
return 96000;
Expand Down Expand Up @@ -179,11 +224,11 @@ ov::String AACAdts::GetInfoString()

out_str.AppendFormat("\tId(%d)\n", Id());
out_str.AppendFormat("\tLayer(%d)\n", Layer());
out_str.AppendFormat("\tProtectionAbsent(%s)\n", ProtectionAbsent()?"true":"false");
out_str.AppendFormat("\tProfile(%d/%s)\n", Profile(), ProfileString().CStr());
out_str.AppendFormat("\tProtectionAbsent(%s)\n", ProtectionAbsent() ? "true" : "false");
out_str.AppendFormat("\tObjectType(%d/%s)\n", ObjectType(), ObjectTypeString().CStr());
out_str.AppendFormat("\tSamplerate(%d/%d)\n", Samplerate(), SamplerateNum());
out_str.AppendFormat("\tChannelConfiguration(%d)\n", ChannelConfiguration());
out_str.AppendFormat("\tHome(%s)\n", Home()?"true":"false");
out_str.AppendFormat("\tHome(%s)\n", Home() ? "true" : "false");
out_str.AppendFormat("\tAacFrameLength(%d)\n", AacFrameLength());

return out_str;
Expand Down
6 changes: 2 additions & 4 deletions src/projects/modules/bitstream/aac/aac_adts.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

#include <stdint.h>



#define ADTS_MIN_SIZE 7

class AACAdts
Expand All @@ -20,8 +18,8 @@ class AACAdts
uint8_t Id();
uint8_t Layer();
bool ProtectionAbsent();
AacObjectType Profile();
ov::String ProfileString();
AudioObjectType ObjectType();
ov::String ObjectTypeString();
AacSamplingFrequencies Samplerate();
uint32_t SamplerateNum();
uint8_t ChannelConfiguration();
Expand Down
39 changes: 21 additions & 18 deletions src/projects/modules/bitstream/aac/audio_specific_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

bool AudioSpecificConfig::IsValid() const
{
if (_object_type == AacObjectType::AacObjectTypeNull ||
if (_object_type == AudioObjectType::Null ||
_sampling_frequency_index == AacSamplingFrequencies::RATES_RESERVED ||
_channel == 15)
{
Expand Down Expand Up @@ -43,14 +43,14 @@ bool AudioSpecificConfig::Parse(const std::shared_ptr<ov::Data> &data)

BitReader parser(data->GetDataAs<uint8_t>(), data->GetLength());

_object_type = static_cast<AacObjectType>(parser.ReadBits<uint8_t>(5));
_object_type = static_cast<AudioObjectType>(parser.ReadBits<uint8_t>(5));
_sampling_frequency_index = static_cast<AacSamplingFrequencies>(parser.ReadBits<uint8_t>(4));
_channel = parser.ReadBits<uint8_t>(4);

return true;
}

bool AudioSpecificConfig::Equals(const std::shared_ptr<DecoderConfigurationRecord> &other)
bool AudioSpecificConfig::Equals(const std::shared_ptr<DecoderConfigurationRecord> &other)
{
if (other == nullptr)
{
Expand All @@ -63,17 +63,17 @@ bool AudioSpecificConfig::Equals(const std::shared_ptr<DecoderConfigurationRecor
return false;
}

if(ObjectType() != other_config->ObjectType())
if (ObjectType() != other_config->ObjectType())
{
return false;
}

if(SamplingFrequency() != other_config->SamplingFrequency())
if (SamplingFrequency() != other_config->SamplingFrequency())
{
return false;
}

if(Channel() != other_config->Channel())
if (Channel() != other_config->Channel())
{
return false;
}
Expand All @@ -85,19 +85,19 @@ std::shared_ptr<ov::Data> AudioSpecificConfig::Serialize()
{
ov::BitWriter bits(2);

bits.WriteBits(5, _object_type);
bits.WriteBits(5, ov::ToUnderlyingType(_object_type));
bits.WriteBits(4, _sampling_frequency_index);
bits.WriteBits(4, _channel);

return std::make_shared<ov::Data>(bits.GetData(), bits.GetDataSize());
}

AacObjectType AudioSpecificConfig::ObjectType() const
AudioObjectType AudioSpecificConfig::ObjectType() const
{
return _object_type;
}

void AudioSpecificConfig::SetOjbectType(AacObjectType object_type)
void AudioSpecificConfig::SetObjectType(AudioObjectType object_type)
{
_object_type = object_type;
}
Expand Down Expand Up @@ -164,16 +164,19 @@ AacProfile AudioSpecificConfig::GetAacProfile() const
{
switch (_object_type)
{
case AacObjectTypeAacMain:
return AacProfileMain;
case AacObjectTypeAacHE:
case AacObjectTypeAacHEV2:
case AacObjectTypeAacLC:
return AacProfileLC;
case AacObjectTypeAacSSR:
return AacProfileSSR;
case AudioObjectType::AacMain:
return AacProfile::Main;

case AudioObjectType::AacLc:
case AudioObjectType::Sbr:
case AudioObjectType::Ps:
return AacProfile::LC;

case AudioObjectType::AacSsr:
return AacProfile::SSR;

default:
return AacProfileReserved;
return AacProfile::Reserved;
}
}

Expand Down
Loading

0 comments on commit 061d02d

Please sign in to comment.