BaseCodec.h 1.4 KB

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