BaseCodec.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #pragma once
  2. #include "AudioContainer.h"
  3. namespace bell {
  4. class BaseCodec {
  5. private:
  6. uint32_t lastSampleLen, availableBytes;
  7. public:
  8. uint32_t sampleRate = 44100;
  9. uint8_t channelCount = 2;
  10. uint8_t bitDepth = 16;
  11. /**
  12. * Setup the codec (sample rate, channel count, etc) using the specified container.
  13. */
  14. virtual bool setup(AudioContainer* container);
  15. /**
  16. * Setup the codec manually, using the provided values.
  17. */
  18. virtual bool setup(uint32_t sampleRate, uint8_t channelCount,
  19. uint8_t bitDepth) = 0;
  20. /**
  21. * Decode the given sample.
  22. *
  23. * @param [in] inData encoded data. Should allow nullptr, in which case nullptr should be returned.
  24. * @param [in] inLen size of inData, in bytes
  25. * @param [out] outLen size of output PCM data, in bytes
  26. * @return pointer to decoded raw PCM audio data, allocated inside the codec object; nullptr on failure
  27. */
  28. virtual uint8_t* decode(uint8_t* inData, uint32_t& inLen,
  29. uint32_t& outLen) = 0;
  30. /**
  31. * Read a single sample from the container, decode it, and return the result.
  32. *
  33. * @param [in] container media container to read the sample from (the container's codec must match this instance)
  34. * @param [out] outLen size of output PCM data, in bytes
  35. * @return pointer to decoded raw PCM audio data, allocated inside the codec object; nullptr on failure
  36. */
  37. uint8_t* decode(AudioContainer* container, uint32_t& outLen);
  38. /**
  39. * Last error that occurred, this is a codec-specific value.
  40. * This may be set by a codec upon decoding failure.
  41. */
  42. int lastErrno = -1;
  43. };
  44. } // namespace bell