1 #ifndef TAG_PARSER_AACFRAME_H 2 #define TAG_PARSER_AACFRAME_H 6 #include <c++utilities/io/bitreader.h> 30 namespace AacSyntaxElementTypes {
43 namespace AacIcsSequenceTypes {
47 namespace AacScaleFactorTypes {
51 namespace AacExtensionTypes {
55 namespace BsFrameClasses {
59 namespace AacSbrExtensionIds {
72 byte shortLagPresent[8];
99 byte coefCompress[8][4];
106 byte adjustNum[4][8];
107 byte alevcode[4][8][8];
108 byte aloccode[4][8][8];
119 byte dynamicRangeSign[17];
120 byte dynamicRangeControl[17];
148 AacSbrInfo(byte sbrElementType, uint16 samplingFrequency, uint16 frameLength,
bool isDrm);
172 byte fTableRes[2][64];
173 byte fTableNoise[64];
174 byte fTableLim[4][64];
178 byte tableMapKToG[64];
181 byte absBordTrail[2];
182 byte relLeadCount[2];
183 byte relTrailCount[2];
216 byte patchNoSubbands[64];
217 byte patchStartSubband[64];
219 byte bsAddHarmonic[2][64];
220 byte bsAddHarmonicPrev[2][64];
222 uint16 indexNoisePrev[2];
232 sbyte prevEnvIsShort[2];
251 std::shared_ptr<AacDrmPsInfo>
drmPs;
258 std::shared_ptr<AacPsInfo>
ps;
278 byte bsAddHarmonicFlag[2];
279 byte bsAddHarmonicFlagPrev[2];
284 byte bsFrameClass[2];
285 byte bsRelBord[2][9];
286 byte bsRelBord0[2][9];
287 byte bsRelBord1[2][9];
294 byte bsDfNoise[2][3];
315 byte frontElementIsCpe[16];
316 byte frontElementTagSelect[16];
317 byte sideElementIsCpe[16];
318 byte sideElementTagSelect[16];
319 byte backElementIsCpe[16];
320 byte backElementTagSelect[16];
321 byte lfeElementTagSelect[16];
322 byte assocDataElementTagSelect[16];
323 byte ccElementIsIndSw[16];
324 byte validCcElementTagSelect[16];
327 byte commentFieldData[257];
345 byte windowGroupLengths[8];
348 uint16 sectionSfbOffset[8][15 * 8];
349 uint16 swbOffset[52];
352 byte sectionCb[8][15 * 8];
353 uint16 sectionStart[8][15 * 8];
354 uint16 sectionEnd[8][15 * 8];
355 byte sfbCb[8][15 * 8];
356 byte sectionsPerGroup[8];
359 uint16 scaleFactors[8][51];
378 std::shared_ptr<AacSbrInfo>
sbr;
395 byte audioObjectId, byte samplingFrequencyIndex, byte extensionSamplingFrequencyIndex, byte channelConfig, uint16 frameLength = 1024);
397 void parse(
const AdtsFrame &adtsFrame, std::unique_ptr<
char[]> &data, std::size_t dataSize);
398 void parse(
const AdtsFrame &adtsFrame, std::istream &stream, std::size_t dataSize);
405 void decodeRvlcScaleFactorData(
AacIcsInfo &ics);
410 void parseSpectralData(
AacIcsInfo &ics, int16 *specData);
411 void parseSideInfo(
AacIcsInfo &ics,
bool scaleFlag);
412 byte parseExcludedChannels();
413 byte parseDynamicRange();
414 static sbyte sbrLog2(
const sbyte val);
416 void parseSbrGrid(std::shared_ptr<AacSbrInfo> &sbr, byte channel);
417 void parseSbrDtdf(std::shared_ptr<AacSbrInfo> &sbr, byte channel);
418 void parseInvfMode(std::shared_ptr<AacSbrInfo> &sbr, byte channel);
419 void parseSbrEnvelope(std::shared_ptr<AacSbrInfo> &sbr, byte channel);
420 void parseSbrNoise(std::shared_ptr<AacSbrInfo> &sbr, byte channel);
421 void parseSbrSinusoidalCoding(std::shared_ptr<AacSbrInfo> &sbr, byte channel);
422 uint16 parseSbrExtension(std::shared_ptr<AacSbrInfo> &sbr, byte extensionId, byte bitsLeft);
423 uint16 parsePsData(std::shared_ptr<AacPsInfo> &ps, byte &header);
424 uint16 parseDrmPsData(std::shared_ptr<AacDrmPsInfo> &drmPs);
425 void parseSbrSingleChannelElement(std::shared_ptr<AacSbrInfo> &sbr);
426 void parseSbrChannelPairElement(std::shared_ptr<AacSbrInfo> &sbr);
427 std::shared_ptr<AacSbrInfo> makeSbrInfo(byte sbrElement,
bool isDrm =
false);
428 void parseSbrExtensionData(byte sbrElement, uint16 count,
bool crcFlag);
429 byte parseHuffmanScaleFactor();
430 void parseHuffmanSpectralData(byte cb, int16 *sp);
431 void huffmanSignBits(int16 *sp, byte len);
432 void huffman2StepQuad(byte cb, int16 *sp);
433 void huffmanBinaryQuadSign(byte cb, int16 *sp);
434 void huffmanBinaryPair(byte cb, int16 *sp);
435 void huffman2StepPair(byte cb, int16 *sp);
436 void huffmanBinaryPairSign(byte cb, int16 *sp);
437 void huffman2StepPairSign(byte cb, int16 *sp);
438 int16 huffmanGetEscape(int16 sp);
439 constexpr
static int16 huffmanCodebook(byte i);
440 static void vcb11CheckLav(byte cb, int16 *sp);
441 void calculateWindowGroupingInfo(
AacIcsInfo &ics);
442 void parseIndividualChannelStream(
AacIcsInfo &ics, int16 *specData,
bool scaleFlag =
false);
443 void parseSingleChannelElement();
444 void parseChannelPairElement();
445 void parseCouplingChannelElement();
446 void parseLowFrequencyElement();
447 void parseDataStreamElement();
448 void parseProgramConfigElement();
450 void parseRawDataBlock();
453 IoUtilities::BitReader m_reader;
454 byte m_mpeg4AudioObjectId;
455 byte m_mpeg4SamplingFrequencyIndex;
456 byte m_mpeg4ExtensionSamplingFrequencyIndex;
457 byte m_mpeg4ChannelConfig;
458 uint16 m_frameLength;
459 byte m_aacSectionDataResilienceFlag;
460 byte m_aacScalefactorDataResilienceFlag;
461 byte m_aacSpectralDataResilienceFlag;
475 byte m_sbrPresentFlag;
488 byte audioObjectId, byte samplingFrequencyIndex, byte extensionSamplingFrequencyIndex, byte channelConfig, uint16 frameLength)
489 : m_reader(nullptr, nullptr)
490 , m_mpeg4AudioObjectId(audioObjectId)
491 , m_mpeg4SamplingFrequencyIndex(samplingFrequencyIndex)
492 , m_mpeg4ExtensionSamplingFrequencyIndex(extensionSamplingFrequencyIndex)
493 , m_mpeg4ChannelConfig(channelConfig)
494 , m_frameLength(frameLength)
495 , m_aacSpectralDataResilienceFlag(0)
499 , m_elementChannelCount{ 0 }
500 , m_elementInstanceTag{ 0 }
516 inline sbyte AacFrameElementParser::sbrLog2(
const sbyte val)
518 static const int log2tab[] = { 0, 0, 1, 2, 2, 3, 3, 3, 3, 4 };
519 return (val < 10 && val >= 0) ? log2tab[val] : 0;
522 constexpr int16 AacFrameElementParser::huffmanCodebook(byte i)
524 return static_cast<int16
>(i ? (16428320 & 0xFFFF) : ((16428320 >> 16) & 0xFFFF));
529 #endif // TAG_PARSER_AACFRAME_H
const sbyte(* SbrHuffTab)[2]
byte backChannelElementCount
byte monoMixdownElementNumber
uint16 reorderedSpectralDataLength
byte stereoMixdownPresent
byte predictorDataPresent
byte stereoMixdownElementNumber
constexpr auto aacMaxltpSfbS
constexpr auto aacSbrRate
constexpr auto aacSbrMaxLe
constexpr auto aacMaxWindowGroups
byte samplingFrequencyIndex
byte pseudoSurroundEnable
std::shared_ptr< AacSbrInfo > sbr
std::shared_ptr< AacPsInfo > ps
constexpr auto aacNoTimeSlots
constexpr auto aacSbrMaxNtsrhfg
byte sideChannelElementCount
std::shared_ptr< AacDrmPsInfo > drmPs
byte matrixMixdownIdxPresent
byte longestCodewordLength
byte assocDataElementCount
constexpr auto aacMaxLtpSfb
byte lfeChannelElementCount
constexpr auto aacInvalidSbrElement
byte excludedChannelsPresent
constexpr auto aacMaxSyntaxElements
AacPredictorInfo predictor
byte midSideCodingMaskPresent
constexpr auto aacMaxChannels
AacFrameElementParser(byte audioObjectId, byte samplingFrequencyIndex, byte extensionSamplingFrequencyIndex, byte channelConfig, uint16 frameLength=1024)
Constructs a new parser with the specified setup information.
constexpr auto aacNoTimeSlots960
byte frontChannelElementCount