ifc_aviaudiodecoder.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #pragma once
  2. #include <bfc/dispatch.h>
  3. class NOVTABLE ifc_aviaudiodecoder : public Dispatchable
  4. {
  5. protected:
  6. ifc_aviaudiodecoder() {}
  7. ~ifc_aviaudiodecoder() {}
  8. public:
  9. enum
  10. {
  11. AVI_SUCCESS = 0,
  12. AVI_NEED_MORE_INPUT = -1,
  13. AVI_FAILURE=1,
  14. AVI_RESYNC=2,
  15. };
  16. int OutputFrameSize(uint32_t *frame_size);
  17. int GetOutputProperties(unsigned int *sampleRate, unsigned int *channels, unsigned int *bitsPerSample, bool *isFloat); // can return an error code for "havn't locked to stream yet"
  18. // many AVI files arbitrarily divide the data stream (e.g. an MP3 frame might span two chunks). Others put ALL the audio into ONE chunk. awesome.
  19. // for this reason, you are given double pointers to the data buffer and a pointer to the data size
  20. // and you are expected to update it on return
  21. // if inputBufferBytes != 0, you will be called again with the same data (return AVI_SUCCESS, though)
  22. // if you were unable to decode because of bitstream errors, return AVI_RESYNC so in_avi can try to correct timing
  23. int DecodeChunk(uint16_t type, const void **inputBuffer, uint32_t *inputBufferBytes, void *outputBuffer, uint32_t *outputBufferBytes);
  24. void Flush();
  25. void Close(); // self-destructs
  26. void EndOfStream(); // no more input, output anything you have buffered
  27. DISPATCH_CODES
  28. {
  29. OUTPUT_FRAME_SIZE = 0,
  30. GET_OUTPUT_PROPERTIES = 1,
  31. DECODE_CHUNK = 2,
  32. FLUSH = 3,
  33. CLOSE = 4,
  34. END_OF_STREAM = 5,
  35. };
  36. };
  37. inline int ifc_aviaudiodecoder::OutputFrameSize(uint32_t *frame_size)
  38. {
  39. return _call(OUTPUT_FRAME_SIZE, (int)AVI_FAILURE, frame_size);
  40. }
  41. inline int ifc_aviaudiodecoder::GetOutputProperties(unsigned int *sampleRate, unsigned int *channels, unsigned int *bitsPerSample, bool *isFloat)
  42. {
  43. return _call(GET_OUTPUT_PROPERTIES, (int)AVI_FAILURE, sampleRate, channels, bitsPerSample, isFloat);
  44. }
  45. inline int ifc_aviaudiodecoder::DecodeChunk(uint16_t type, const void **inputBuffer, uint32_t *inputBufferBytes, void *outputBuffer, uint32_t *outputBufferBytes)
  46. {
  47. return _call(DECODE_CHUNK, (int)AVI_FAILURE, type, inputBuffer, inputBufferBytes, outputBuffer, outputBufferBytes);
  48. }
  49. inline void ifc_aviaudiodecoder::Flush()
  50. {
  51. _voidcall(FLUSH);
  52. }
  53. inline void ifc_aviaudiodecoder::Close()
  54. {
  55. _voidcall(CLOSE);
  56. }
  57. inline void ifc_aviaudiodecoder::EndOfStream()
  58. {
  59. _voidcall(END_OF_STREAM);
  60. }