1 #ifndef TAG_PARSER_AACFRAME_H 2 #define TAG_PARSER_AACFRAME_H 6 #include <c++utilities/io/bitreader.h> 16 constexpr
auto aacMaxChannels = 64;
17 constexpr
auto aacMaxSyntaxElements = 48;
18 constexpr
auto aacMaxWindowGroups = 8;
19 constexpr
auto aacMaxSfb = 51;
20 constexpr
auto aacMaxLtpSfb = 40;
21 constexpr
auto aacMaxltpSfbS = 8;
22 constexpr
auto aacInvalidSbrElement = 0xFF;
23 constexpr
auto aacNoTimeSlots960 = 15;
24 constexpr
auto aacNoTimeSlots = 16;
25 constexpr
auto aacSbrRate = 2;
26 constexpr
auto aacSbrM = 49;
27 constexpr
auto aacSbrMaxLe = 5;
28 constexpr
auto aacSbrMaxNtsrhfg = 40;
30 using SbrHuffTab =
const sbyte (*)[2];
32 namespace AacSyntaxElementTypes {
33 enum KnownTypes :
byte {
36 ChannelCouplingElement,
45 namespace AacIcsSequenceTypes {
46 enum KnownTypes :
byte { OnlyLongSequence, LongStartSequence, EightShortSequence, LongStopSequence };
49 namespace AacScaleFactorTypes {
50 enum KnownTypes :
byte { ZeroHcb = 0, FirstPairHcb = 5, EscHcb = 11, QuadLen = 4, PairLen = 2, NoiseHcb = 13, IntensityHcb2 = 14, IntensityHcb = 15 };
53 namespace AacExtensionTypes {
54 enum KnownTypes :
byte { Fill = 0, FillData = 1, DataElement = 2, DynamicRange = 11, SacData = 12, SbrData = 13, SbrDataCrc = 14 };
57 namespace BsFrameClasses {
58 enum BsFrameClass :
byte { FixFix, FixVar, VarFix, VarVar };
61 namespace AacSbrExtensionIds {
62 enum KnownIds :
byte { DrmParametricStereo = 0,
Ps = 2 };
65 struct LIB_EXPORT AacLtpInfo {
72 byte longUsed[aacMaxLtpSfb];
74 byte shortLagPresent[8];
78 struct LIB_EXPORT AacPredictorInfo {
82 byte resetGroupNumber;
83 byte predictionUsed[aacMaxSfb];
86 struct LIB_EXPORT AacPulseInfo {
94 struct LIB_EXPORT AacTnsInfo {
100 byte direction[8][4];
101 byte coefCompress[8][4];
105 struct LIB_EXPORT AacSsrInfo {
108 byte adjustNum[4][8];
109 byte alevcode[4][8][8];
110 byte aloccode[4][8][8];
113 struct LIB_EXPORT AacDrcInfo {
118 byte excludedChannelsPresent;
121 byte dynamicRangeSign[17];
122 byte dynamicRangeControl[17];
123 byte excludeMask[aacMaxChannels];
124 byte additionalExcludedChannels[aacMaxChannels];
127 struct LIB_EXPORT AacPsInfo {
130 byte use34HybridBands;
138 struct LIB_EXPORT AacDrmPsInfo {
141 byte use34HybridBands;
149 struct LIB_EXPORT AacSbrInfo {
150 AacSbrInfo(
byte sbrElementType, uint16 samplingFrequency, uint16 frameLength,
bool isDrm);
153 byte samplingFrequency;
174 byte fTableRes[2][64];
175 byte fTableNoise[64];
176 byte fTableLim[4][64];
180 byte tableMapKToG[64];
183 byte absBordTrail[2];
184 byte relLeadCount[2];
185 byte relTrailCount[2];
191 byte te[2][aacSbrMaxLe + 1];
193 byte f[2][aacSbrMaxLe + 1];
200 int16 e[2][64][aacSbrMaxLe];
212 byte bsInvfMode[2][aacSbrMaxLe];
213 byte bsInvfModePrev[2][aacSbrMaxLe];
218 byte patchNoSubbands[64];
219 byte patchStartSubband[64];
221 byte bsAddHarmonic[2][64];
222 byte bsAddHarmonicPrev[2][64];
224 uint16 indexNoisePrev[2];
227 byte bsStartFreqPrev;
229 byte bsXoverBandPrev;
230 byte bsFreqScalePrev;
231 byte bsAlterScalePrev;
232 byte bsNoiseBandsPrev;
234 sbyte prevEnvIsShort[2];
253 std::shared_ptr<AacDrmPsInfo> drmPs;
255 byte timeSlotsRateCount;
260 std::shared_ptr<AacPsInfo> ps;
267 byte bsProtocolVersion;
278 byte bsSmoothingMode;
279 byte bsSamplerateMode;
280 byte bsAddHarmonicFlag[2];
281 byte bsAddHarmonicFlagPrev[2];
284 byte bsExtensionData;
286 byte bsFrameClass[2];
287 byte bsRelBord[2][9];
288 byte bsRelBord0[2][9];
289 byte bsRelBord1[2][9];
296 byte bsDfNoise[2][3];
299 struct LIB_EXPORT AacProgramConfig {
301 byte elementInstanceTag;
303 byte samplingFrequencyIndex;
304 byte frontChannelElementCount;
305 byte sideChannelElementCount;
306 byte backChannelElementCount;
307 byte lfeChannelElementCount;
308 byte assocDataElementCount;
309 byte validCcElementCount;
310 byte monoMixdownPresent;
311 byte monoMixdownElementNumber;
312 byte stereoMixdownPresent;
313 byte stereoMixdownElementNumber;
314 byte matrixMixdownIdxPresent;
315 byte pseudoSurroundEnable;
316 byte matrixMixdownIdx;
317 byte frontElementIsCpe[16];
318 byte frontElementTagSelect[16];
319 byte sideElementIsCpe[16];
320 byte sideElementTagSelect[16];
321 byte backElementIsCpe[16];
322 byte backElementTagSelect[16];
323 byte lfeElementTagSelect[16];
324 byte assocDataElementTagSelect[16];
325 byte ccElementIsIndSw[16];
326 byte validCcElementTagSelect[16];
328 byte commentFieldBytes;
329 byte commentFieldData[257];
330 byte frontChannelCount;
331 byte sideChannelCount;
332 byte backChannelCount;
333 byte lfeChannelCount;
338 struct LIB_EXPORT AacIcsInfo {
344 byte windowGroupCount;
347 byte windowGroupLengths[8];
349 byte scaleFactorGrouping;
350 uint16 sectionSfbOffset[8][15 * 8];
351 uint16 swbOffset[52];
354 byte sectionCb[8][15 * 8];
355 uint16 sectionStart[8][15 * 8];
356 uint16 sectionEnd[8][15 * 8];
357 byte sfbCb[8][15 * 8];
358 byte sectionsPerGroup[8];
361 uint16 scaleFactors[8][51];
363 byte midSideCodingMaskPresent;
364 byte midSideCodingUsed[aacMaxWindowGroups][aacMaxSfb];
369 byte pulseDataPresent;
371 byte gainControlPresent;
372 byte predictorDataPresent;
376 AacPredictorInfo predictor;
380 std::shared_ptr<AacSbrInfo> sbr;
383 uint16 reorderedSpectralDataLength;
384 byte longestCodewordLength;
389 byte sfEscapesPresent;
390 byte rvlcEscapesLength;
391 uint16 dpcmNoiseLastPos;
394 class LIB_EXPORT AacFrameElementParser {
396 AacFrameElementParser(
397 byte audioObjectId,
byte samplingFrequencyIndex,
byte extensionSamplingFrequencyIndex,
byte channelConfig, uint16 frameLength = 1024);
399 void parse(
const AdtsFrame &adtsFrame, std::unique_ptr<
char[]> &data, std::size_t dataSize);
400 void parse(
const AdtsFrame &adtsFrame, std::istream &stream, std::size_t dataSize);
403 void parseLtpInfo(
const AacIcsInfo &ics, AacLtpInfo <p);
404 void parseIcsInfo(AacIcsInfo &ics);
405 void parseSectionData(AacIcsInfo &ics);
406 void decodeScaleFactorData(AacIcsInfo &ics);
407 void decodeRvlcScaleFactorData(AacIcsInfo &ics);
408 void parseScaleFactorData(AacIcsInfo &ics);
409 void parsePulseData(AacIcsInfo &ics);
410 void parseTnsData(AacIcsInfo &ics);
411 void parseGainControlData(AacIcsInfo &ics);
412 void parseSpectralData(AacIcsInfo &ics, int16 *specData);
413 void parseSideInfo(AacIcsInfo &ics,
bool scaleFlag);
414 byte parseExcludedChannels();
415 byte parseDynamicRange();
416 static sbyte sbrLog2(
const sbyte val);
417 int16 sbrHuffmanDec(SbrHuffTab table);
418 void parseSbrGrid(std::shared_ptr<AacSbrInfo> &sbr,
byte channel);
419 void parseSbrDtdf(std::shared_ptr<AacSbrInfo> &sbr,
byte channel);
420 void parseInvfMode(std::shared_ptr<AacSbrInfo> &sbr,
byte channel);
421 void parseSbrEnvelope(std::shared_ptr<AacSbrInfo> &sbr,
byte channel);
422 void parseSbrNoise(std::shared_ptr<AacSbrInfo> &sbr,
byte channel);
423 void parseSbrSinusoidalCoding(std::shared_ptr<AacSbrInfo> &sbr,
byte channel);
424 uint16 parseSbrExtension(std::shared_ptr<AacSbrInfo> &sbr,
byte extensionId,
byte bitsLeft);
425 uint16 parsePsData(std::shared_ptr<AacPsInfo> &ps,
byte &header);
426 uint16 parseDrmPsData(std::shared_ptr<AacDrmPsInfo> &drmPs);
427 void parseSbrSingleChannelElement(std::shared_ptr<AacSbrInfo> &sbr);
428 void parseSbrChannelPairElement(std::shared_ptr<AacSbrInfo> &sbr);
429 std::shared_ptr<AacSbrInfo> makeSbrInfo(
byte sbrElement,
bool isDrm =
false);
430 void parseSbrExtensionData(
byte sbrElement, uint16 count,
bool crcFlag);
431 byte parseHuffmanScaleFactor();
432 void parseHuffmanSpectralData(
byte cb, int16 *sp);
433 void huffmanSignBits(int16 *sp,
byte len);
434 void huffman2StepQuad(
byte cb, int16 *sp);
435 void huffmanBinaryQuadSign(
byte cb, int16 *sp);
436 void huffmanBinaryPair(
byte cb, int16 *sp);
437 void huffman2StepPair(
byte cb, int16 *sp);
438 void huffmanBinaryPairSign(
byte cb, int16 *sp);
439 void huffman2StepPairSign(
byte cb, int16 *sp);
440 int16 huffmanGetEscape(int16 sp);
441 constexpr
static int16 huffmanCodebook(
byte i);
442 static void vcb11CheckLav(
byte cb, int16 *sp);
443 void calculateWindowGroupingInfo(AacIcsInfo &ics);
444 void parseIndividualChannelStream(AacIcsInfo &ics, int16 *specData,
bool scaleFlag =
false);
445 void parseSingleChannelElement();
446 void parseChannelPairElement();
447 void parseCouplingChannelElement();
448 void parseLowFrequencyElement();
449 void parseDataStreamElement();
450 void parseProgramConfigElement();
451 void parseFillElement(
byte sbrElement = aacInvalidSbrElement);
452 void parseRawDataBlock();
455 IoUtilities::BitReader m_reader;
456 byte m_mpeg4AudioObjectId;
457 byte m_mpeg4SamplingFrequencyIndex;
458 byte m_mpeg4ExtensionSamplingFrequencyIndex;
459 byte m_mpeg4ChannelConfig;
460 uint16 m_frameLength;
461 byte m_aacSectionDataResilienceFlag;
462 byte m_aacScalefactorDataResilienceFlag;
463 byte m_aacSpectralDataResilienceFlag;
465 byte m_elementId[aacMaxChannels];
468 byte m_elementChannelCount[aacMaxSyntaxElements];
471 byte m_elementInstanceTag[aacMaxSyntaxElements];
476 AacProgramConfig m_pce;
477 byte m_sbrPresentFlag;
480 std::shared_ptr<AacSbrInfo> m_sbrElements[aacMaxSyntaxElements];
481 byte m_psUsed[aacMaxSyntaxElements];
489 inline AacFrameElementParser::AacFrameElementParser(
490 byte audioObjectId,
byte samplingFrequencyIndex,
byte extensionSamplingFrequencyIndex,
byte channelConfig, uint16 frameLength)
491 : m_reader(nullptr, nullptr)
492 , m_mpeg4AudioObjectId(audioObjectId)
493 , m_mpeg4SamplingFrequencyIndex(samplingFrequencyIndex)
494 , m_mpeg4ExtensionSamplingFrequencyIndex(extensionSamplingFrequencyIndex)
495 , m_mpeg4ChannelConfig(channelConfig)
496 , m_frameLength(frameLength)
497 , m_aacSpectralDataResilienceFlag(0)
501 , m_elementChannelCount{ 0 }
502 , m_elementInstanceTag{ 0 }
518 inline sbyte AacFrameElementParser::sbrLog2(
const sbyte val)
520 static const int log2tab[] = { 0, 0, 1, 2, 2, 3, 3, 3, 3, 4 };
521 return (val < 10 && val >= 0) ? log2tab[val] : 0;
524 constexpr int16 AacFrameElementParser::huffmanCodebook(
byte i)
526 return static_cast<int16>(i ? (16428320 & 0xFFFF) : ((16428320 >> 16) & 0xFFFF));
533 #endif // TAG_PARSER_AACFRAME_H
Contains all classes and functions of the TagInfo library.