1
0

test_adts_mpg123.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #include "catch.hpp"
  2. #include "adts_mpg123.h"
  3. class MemoryStreamer : public ifc_mpeg_stream_reader
  4. {
  5. public:
  6. MemoryStreamer(){}
  7. int Peek(void *buffer, size_t to_read, size_t *bytes_read)
  8. {
  9. if (to_read > this->bufferBytes) {
  10. to_read = this->bufferBytes;
  11. }
  12. memcpy(buffer, this->buffer, to_read);
  13. *bytes_read = to_read;
  14. return adts::SUCCESS;
  15. }
  16. int Read(void *buffer, size_t to_read, size_t *bytes_read)
  17. {
  18. if (to_read > this->bufferBytes) {
  19. to_read = this->bufferBytes;
  20. }
  21. memcpy(buffer, this->buffer, to_read);
  22. this->buffer = (unsigned char *)this->buffer + *bytes_read;
  23. *bytes_read = to_read;
  24. bufferBytes -= to_read;
  25. return adts::SUCCESS;
  26. }
  27. int EndOf()
  28. {
  29. if (bufferBytes == 0) {
  30. return 1;
  31. } else {
  32. return 0;
  33. }
  34. }
  35. float GetGain()
  36. {
  37. return 1.0;
  38. }
  39. unsigned char *buffer;
  40. size_t bufferBytes;
  41. RECVS_DISPATCH;
  42. };
  43. #define CBCLASS MemoryStreamer
  44. START_DISPATCH;
  45. CB(MPEGSTREAM_PEEK, Peek)
  46. CB(MPEGSTREAM_READ, Read)
  47. CB(MPEGSTREAM_EOF, EndOf)
  48. CB(MPEGSTREAM_GAIN, GetGain)
  49. END_DISPATCH;
  50. #undef CBCLASS
  51. static const unsigned char mp3_frame1[] = {
  52. 0xFF, 0xF3, 0x70, 0x54, 0x00, 0x10, 0x2D, 0xFA, 0x96, 0x0F, 0xA0, 0x20,
  53. 0x00, 0x81, 0xE8, 0x05, 0x2C, 0x1F, 0x40, 0x00, 0x00, 0x03, 0x51, 0xB6,
  54. 0x1B, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF3,
  55. 0x0B, 0x05, 0x86, 0x07, 0x60, 0x2E, 0x11, 0x94, 0x0A, 0x01, 0x61, 0xA0,
  56. 0xD0, 0xC2, 0xC5, 0xCF, 0x81, 0x41, 0x43, 0x2F, 0x44, 0x4E, 0x6E, 0x1F,
  57. 0xFF, 0xFF, 0xFF, 0xFF, 0xF2, 0x01, 0xA0, 0xA2, 0x8B, 0x87, 0xF6, 0x2E,
  58. 0x7A, 0x0A, 0x19, 0x25, 0x9F, 0x02, 0xF6, 0x40, 0xA1, 0x92, 0x2E, 0x2E,
  59. 0x7F, 0xEE, 0xFF, 0x96, 0x1E, 0x0E, 0x2C, 0x1B, 0x87, 0xEC, 0x1C, 0x07,
  60. 0x8A, 0x1C, 0x18, 0x58, 0x76, 0x7C, 0x0A, 0x07, 0x86, 0x5E, 0x88, 0x94,
  61. 0xEF, 0x02, 0xF6, 0x82, 0x86, 0x49, 0x67, 0xC0, 0xBD, 0x90, 0x28, 0x64,
  62. 0x8B, 0x8B, 0xDF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xBC,
  63. 0x3D, 0xA0, 0xA2, 0x4B, 0x8B, 0x8B, 0x8A, 0x51, 0x60, 0xDC, 0x5D, 0x85,
  64. 0x03, 0xC3, 0x2C, 0x00, 0x03, 0x31, 0xE0, 0x00, 0x7F};
  65. TEST_CASE("", "[adts_mpg123]") {
  66. mpg123_init();
  67. ADTS_MPG123 mp3;
  68. MemoryStreamer memoryStreamer;
  69. REQUIRE(mp3.Initialize(false, false, false, 16, true, true, true) == adts::SUCCESS);
  70. REQUIRE(mp3.Open(&memoryStreamer) == true);
  71. size_t numBits;
  72. size_t numChannels;
  73. int sampleRate;
  74. memoryStreamer.buffer = (unsigned char *)mp3_frame1;
  75. memoryStreamer.bufferBytes = sizeof(mp3_frame1);
  76. size_t outputWritten=777;
  77. size_t bitrate=777;
  78. REQUIRE(mp3.Sync(&memoryStreamer, 0, 0, &outputWritten, &bitrate) == adts::SUCCESS);
  79. REQUIRE(bitrate == 64);
  80. REQUIRE(outputWritten == 0);
  81. }