ADTSContainer.h 991 B

123456789101112131415161718192021222324252627282930313233343536
  1. #pragma once
  2. #include <stdint.h> // for uint32_t
  3. #include <cstddef> // for byte, size_t
  4. #include <istream> // for istream
  5. #include <vector> // for vector
  6. #include "AudioContainer.h" // for AudioContainer
  7. #include "CodecType.h" // for AudioCodec, AudioCodec::AAC
  8. namespace bell {
  9. class ADTSContainer : public AudioContainer {
  10. public:
  11. ~ADTSContainer(){};
  12. ADTSContainer(std::istream& istr, const std::byte* headingBytes = nullptr);
  13. std::byte* readSample(uint32_t& len) override;
  14. bool resyncADTS();
  15. void parseSetupData() override;
  16. void consumeBytes(uint32_t len) override;
  17. bell::AudioCodec getCodec() override { return bell::AudioCodec::AAC; }
  18. private:
  19. static constexpr auto AAC_MAX_FRAME_SIZE = 2100;
  20. static constexpr auto BUFFER_SIZE = 1024 * 10;
  21. std::vector<std::byte> buffer = std::vector<std::byte>(BUFFER_SIZE);
  22. size_t bytesInBuffer = 0;
  23. size_t dataOffset = 0;
  24. bool protectionAbsent = false;
  25. bool fillBuffer();
  26. };
  27. } // namespace bell