ifc_fileplayback.h 4.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #pragma once
  2. #include "audio/ifc_audioout.h"
  3. #include "foundation/error.h"
  4. #include "foundation/dispatch.h"
  5. #include "metadata/ifc_metadata.h"
  6. #include "player/types.h"
  7. #include "nx/nxfile.h"
  8. class ifc_fileplayback_parent : public Wasabi2::Dispatchable
  9. {
  10. protected:
  11. ifc_fileplayback_parent() : Wasabi2::Dispatchable(DISPATCHABLE_VERSION) {}
  12. ~ifc_fileplayback_parent() {}
  13. public:
  14. // only call these functions during DecodeStep!
  15. // if any of these return an error, return it from DecodeStep().
  16. // these return NErr_Aborted if there's a seek pending, and NErr_Interrupted if there is an interrupt pending
  17. ns_error_t OpenOutput(const ifc_audioout::Parameters *parameters) { return FilePlaybackParent_OpenOutput(parameters); }
  18. ns_error_t Output(const void *audio_data, size_t audio_data_length, size_t *frames_consumed, double begin_position_seconds) { return FilePlaybackParent_Output(audio_data, audio_data_length, frames_consumed, begin_position_seconds); }
  19. ns_error_t OutputNonInterleaved(const void *audio_data, size_t audio_data_length, size_t *frames_consumed, double begin_position_seconds) { return FilePlaybackParent_OutputNonInterleaved(audio_data, audio_data_length, frames_consumed, begin_position_seconds); }
  20. // call this if you have mid-stream metadata updates.
  21. ns_error_t OnMetadata(ifc_metadata *new_metadata) { return FilePlaybackParent_OnMetadata(new_metadata); }
  22. enum
  23. {
  24. DISPATCHABLE_VERSION=0,
  25. };
  26. protected:
  27. virtual ns_error_t WASABICALL FilePlaybackParent_OpenOutput(const ifc_audioout::Parameters *parameters)=0;
  28. virtual ns_error_t WASABICALL FilePlaybackParent_Output(const void *audio_data, size_t audio_data_length, size_t *frames_consumed, double begin_position_seconds)=0;
  29. virtual ns_error_t WASABICALL FilePlaybackParent_OutputNonInterleaved(const void *audio_data, size_t audio_data_length, size_t *frames_consumed, double begin_position_seconds)=0;
  30. virtual ns_error_t WASABICALL FilePlaybackParent_OnMetadata(ifc_metadata *new_metadata)=0;
  31. };
  32. class ifc_fileplayback : public Wasabi2::Dispatchable
  33. {
  34. protected:
  35. ifc_fileplayback() : Wasabi2::Dispatchable(DISPATCHABLE_VERSION) {}
  36. ~ifc_fileplayback() {}
  37. public:
  38. void Close() { FilePlayback_Close(); }
  39. ns_error_t Seekable() { return FilePlayback_Seekable(); }
  40. ns_error_t GetMetadata(ifc_metadata **metadata) { return FilePlayback_GetMetadata(metadata); }
  41. ns_error_t GetLength(double *length, ns_error_t *exact) { return FilePlayback_GetLength(length, exact); }
  42. ns_error_t GetBitrate(double *bitrate, ns_error_t *exact) { return FilePlayback_GetBitrate(bitrate, exact); }
  43. ns_error_t Seek(const Agave_Seek *seek, ns_error_t *seek_error, double *new_position) { return FilePlayback_Seek(seek, seek_error, new_position); }
  44. ns_error_t DecodeStep() { return FilePlayback_DecodeStep(); }
  45. ns_error_t Interrupt(Agave_Seek *resume_information) { return FilePlayback_Interrupt(resume_information); }
  46. ns_error_t Resume(Agave_Seek *resume_information, nx_file_t file, ifc_metadata *parent_metadata) { return FilePlayback_Resume(resume_information, file, parent_metadata); }
  47. enum
  48. {
  49. DISPATCHABLE_VERSION=0,
  50. };
  51. protected:
  52. /* you need to handle the possibility that Close gets called more than one time */
  53. virtual void WASABICALL FilePlayback_Close()=0;
  54. virtual ns_error_t WASABICALL FilePlayback_Seekable()=0;
  55. /* implementation note: add a reference (Retain) before assigning the value */
  56. virtual ns_error_t WASABICALL FilePlayback_GetMetadata(ifc_metadata **metadata)=0;
  57. /* if you set *exact=NErr_False, GetLength will get called after the next DecodeStep */
  58. virtual ns_error_t WASABICALL FilePlayback_GetLength(double *length, ns_error_t *exact)=0;
  59. virtual ns_error_t WASABICALL FilePlayback_GetBitrate(double *bitrate, ns_error_t *exact)=0;
  60. /* only return an error if you're in a state you can't recover from.
  61. if you can't seek, then just don't seek and return NErr_Success */
  62. virtual ns_error_t WASABICALL FilePlayback_Seek(const Agave_Seek *seek, ns_error_t *seek_error, double *new_position)=0;
  63. /* return NErr_Success to continue
  64. NErr_EndOfFile to indicate a natural end of file
  65. otherwise return an error
  66. do _not_ return NErr_Stopped, NErr_Aborted, or NErr_Interrupted, unless they were returned from an ifc_fileplayback_parent function, as these have special meaning */
  67. virtual ns_error_t WASABICALL FilePlayback_DecodeStep()=0;
  68. /* Save information and close the OS file handle.
  69. fill resume_information with whatever information you'll need to resume */
  70. virtual ns_error_t WASABICALL FilePlayback_Interrupt(Agave_Seek *resume_information)=0;
  71. /* During resume, be sure to call player->SetMetadata again */
  72. virtual ns_error_t WASABICALL FilePlayback_Resume(Agave_Seek *resume_information, nx_file_t file, ifc_metadata *parent_metadata)=0;
  73. };