BaseCodec.h 1.6 KB

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