#pragma once #include // for size_t #include // for uint8_t #include // for shared_ptr, unique_ptr #include // for basic_string, string #include // for vector #include "aacdec.h" // for AACFrameInfo #include "mp3dec.h" // for MP3FrameInfo namespace bell { class ByteStream; class EncodedAudioStream { public: EncodedAudioStream(); ~EncodedAudioStream(); // Codecs supported by this stream class enum class AudioCodec { AAC, MP3, OGG, NONE }; void openWithStream(std::unique_ptr byteStream); size_t decodeFrame(uint8_t* dst); bool isReadable(); private: std::shared_ptr innerStream; std::vector inputBuffer; std::vector outputBuffer; std::string TAG = "EncryptedAudioStream"; uint8_t* decodePtr = 0; int bytesInBuffer = 0; size_t offset = 0; size_t decodedSampleRate = 44100; AudioCodec codec = AudioCodec::NONE; void guessDataFormat(); void readFully(uint8_t* dst, size_t nbytes); bool vectorStartsWith(std::vector&, std::vector&); std::vector aacMagicBytes = {0xFF, 0xF1}; std::vector aacMagicBytes4 = {0xFF, 0xF9}; std::vector mp3MagicBytesUntagged = {0xFF, 0xFB}; std::vector mp3MagicBytesIdc = {0x49, 0x44, 0x33}; AACFrameInfo aacFrameInfo; MP3FrameInfo mp3FrameInfo; size_t decodeFrameMp3(uint8_t* dst); size_t decodeFrameAAC(uint8_t* dst); }; } // namespace bell