MP3Container.h 958 B

1234567891011121314151617181920212223242526272829303132333435
  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::MP3
  8. namespace bell {
  9. class MP3Container : public AudioContainer {
  10. public:
  11. ~MP3Container(){};
  12. MP3Container(std::istream& istr, const std::byte* headingBytes = nullptr);
  13. std::byte* readSample(uint32_t& len) override;
  14. void parseSetupData() override;
  15. void consumeBytes(uint32_t len) override;
  16. bell::AudioCodec getCodec() override { return bell::AudioCodec::MP3; }
  17. private:
  18. static constexpr auto MP3_MAX_FRAME_SIZE = 2100;
  19. static constexpr auto BUFFER_SIZE = 1024 * 10;
  20. std::vector<std::byte> buffer = std::vector<std::byte>(BUFFER_SIZE);
  21. size_t bytesInBuffer = 0;
  22. size_t dataOffset = 0;
  23. size_t toConsume = 0;
  24. bool fillBuffer();
  25. };
  26. } // namespace bell