1
0

ifc_audio_decoder_callback.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #pragma once
  2. #include "foundation/dispatch.h"
  3. #include "nx/nxuri.h"
  4. #include "metadata/ifc_metadata.h"
  5. /* this is the class you actually use */
  6. class ifc_audio_decoder_callback : public Wasabi2::Dispatchable
  7. {
  8. protected:
  9. ifc_audio_decoder_callback() : Dispatchable(DISPATCHABLE_VERSION) {}
  10. ~ifc_audio_decoder_callback() {}
  11. public:
  12. /* you must implement this class to use the decoder */
  13. class callback : public Wasabi2::Dispatchable
  14. {
  15. protected:
  16. callback() : Dispatchable(DISPATCHABLE_VERSION) {}
  17. ~callback() {}
  18. public:
  19. /* frames is defined as all channels, e.g. 16bit stereo is 4 bytes per frame (2 bytes per sample)
  20. return NErr_Success to continue receiving callbacks
  21. */
  22. int OnAudio(const void *buffer, size_t buffer_frames) { return AudioDecoderCallback_OnAudio(buffer, buffer_frames); }
  23. enum
  24. {
  25. DISPATCHABLE_VERSION=0,
  26. };
  27. private:
  28. virtual int WASABICALL AudioDecoderCallback_OnAudio(const void *buffer, size_t buffer_frames)=0;
  29. };
  30. /* if possible, returns an upper bound on the number of frames used internally. this would be the maximum buffer_frames value you receive in a callback */
  31. int GetFrameSize(size_t *frame_size) { return AudioDecoderCallback_GetFrameSize(frame_size); }
  32. int GetMetadata(ifc_metadata **metadata) { return AudioDecoderCallback_GetMetadata(metadata); }
  33. /* returns
  34. * NErr_Success on a successfully completed decode
  35. * NErr_Interrupted if the callback function aborted decoding
  36. * anything else indicates a decoding error
  37. */
  38. int Decode(ifc_audio_decoder_callback::callback *callback) { return AudioDecoderCallback_Decode(callback); }
  39. /* Like decode, but only processes one frame.
  40. returns NErr_EndOfFile on the last frame */
  41. int DecodeStep(ifc_audio_decoder_callback::callback *callback) { return AudioDecoderCallback_DecodeStep(callback); }
  42. enum
  43. {
  44. DISPATCHABLE_VERSION=0,
  45. };
  46. private:
  47. virtual int WASABICALL AudioDecoderCallback_Decode(ifc_audio_decoder_callback::callback *callback)=0;
  48. virtual int WASABICALL AudioDecoderCallback_DecodeStep(ifc_audio_decoder_callback::callback *callback)=0;
  49. virtual int WASABICALL AudioDecoderCallback_GetFrameSize(size_t *frame_size)=0;
  50. virtual int WASABICALL AudioDecoderCallback_GetMetadata(ifc_metadata **metadata)=0;
  51. };