2
0

AudioContainers.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include "AudioContainers.h"
  2. #include <string.h> // for memcmp
  3. #include <cstddef> // for byte
  4. #include "BellLogger.h" // for BellLogger
  5. #include "ADTSContainer.h" // for AACContainer
  6. #include "CodecType.h" // for bell
  7. #include "MP3Container.h" // for MP3Container
  8. namespace bell {
  9. class AudioContainer;
  10. } // namespace bell
  11. using namespace bell;
  12. std::unique_ptr<bell::AudioContainer> AudioContainers::guessAudioContainer(
  13. std::istream& istr) {
  14. std::byte tmp[14];
  15. istr.read((char*)tmp, sizeof(tmp));
  16. if (memcmp(tmp, "\xFF\xF1", 2) == 0 || memcmp(tmp, "\xFF\xF9", 2) == 0) {
  17. // AAC found
  18. BELL_LOG(info, "AudioContainers",
  19. "Mime guesser found AAC in ADTS format, creating ADTSContainer");
  20. return std::make_unique<bell::ADTSContainer>(istr, tmp);
  21. } else if (memcmp(tmp, "\xFF\xFB", 2) == 0 ||
  22. memcmp(tmp, "\x49\x44\x33", 3) == 0) {
  23. // MP3 Found
  24. BELL_LOG(info, "AudioContainers",
  25. "Mime guesser found MP3 format, creating MP3Container");
  26. return std::make_unique<bell::MP3Container>(istr, tmp);
  27. }
  28. BELL_LOG(error, "AudioContainers",
  29. "Mime guesser found no supported format [%X, %X]", tmp[0], tmp[1]);
  30. return nullptr;
  31. }