2
0

AudioContainers.cpp 899 B

12345678910111213141516171819202122232425262728293031323334
  1. #include "AudioContainers.h"
  2. #include <string.h> // for memcmp
  3. #include <cstddef> // for byte
  4. #include "AACContainer.h" // for AACContainer
  5. #include "CodecType.h" // for bell
  6. #include "MP3Container.h" // for MP3Container
  7. namespace bell {
  8. class AudioContainer;
  9. } // namespace bell
  10. using namespace bell;
  11. std::unique_ptr<bell::AudioContainer> AudioContainers::guessAudioContainer(
  12. std::istream& istr) {
  13. std::byte tmp[14];
  14. istr.read((char*)tmp, sizeof(tmp));
  15. if (memcmp(tmp, "\xFF\xF1", 2) == 0 || memcmp(tmp, "\xFF\xF9", 2) == 0) {
  16. // AAC found
  17. std::cout << "AAC" << std::endl;
  18. return std::make_unique<bell::AACContainer>(istr);
  19. } else if (memcmp(tmp, "\xFF\xFB", 2) == 0 ||
  20. memcmp(tmp, "\x49\x44\x33", 3) == 0) {
  21. // MP3 Found
  22. std::cout << "MP3" << std::endl;
  23. return std::make_unique<bell::MP3Container>(istr);
  24. }
  25. return nullptr;
  26. }