ifc_player.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #pragma once
  2. #include "foundation/dispatch.h"
  3. #include "foundation/error.h"
  4. #include "foundation/types.h"
  5. #include "metadata/ifc_metadata.h"
  6. #include "audio/ifc_equalizer.h"
  7. #include "nx/nxuri.h"
  8. /* implemented by Winamp (or whatever application)
  9. your ifc_playback implementation should call this with events
  10. TODO: benski> should we require the ifc_playback object to get passed in to each function?
  11. */
  12. class NOVTABLE ifc_player : public Wasabi2::Dispatchable
  13. {
  14. protected:
  15. ifc_player() : Dispatchable(DISPATCHABLE_VERSION) {}
  16. ~ifc_player() {}
  17. public:
  18. /* When your playback object has read enough of the file to provide metadata
  19. it should call this method.
  20. It will be called for both song metadata (artist, album, etc) and codec metadata (bitrate, samplerate, etc).
  21. so make sure you can provide both - this might mean you have to wait until the first frame is decoded.
  22. The player object will add a reference in the function, and release whenever it is no longer needed (usually on start of next track)
  23. */
  24. void SetMetadata(ifc_metadata *metadata) { Player_SetMetadata(metadata); }
  25. /* Call this just once (with timestamp=0) for CBR files or update continuously for VBR
  26. bitrate should be in bits per second, e.g. 128000 (not 128!)
  27. */
  28. void SetBitrate(uint64_t bitrate, double timestamp) { Player_SetBitrate(bitrate, timestamp); }
  29. /* Playback plugin should call this when it knows the length
  30. can be updated if necessary (e.g. for VBR files w/o header)
  31. If this is not called, it assumed to be a stream (radio)
  32. */
  33. void SetLength(double length) { Player_SetLength(length); }
  34. /* Output plugin should call this every once in a while,
  35. if your input plugin does its own audio output (e.g. analog CD) you should call this yourself
  36. */
  37. void SetPosition(double timestamp) { Player_SetPosition(timestamp); }
  38. void OnLoaded(nx_uri_t filename) { Player_OnLoaded(filename); }
  39. /* Input plugin should call this when playback ends at the end of the file
  40. Do not call if playback stopped because of an error */
  41. void OnEndOfFile() { Player_OnEndOfFile(); }
  42. void OnError(NError code) { Player_OnError(code); }
  43. void OnStopped() { Player_OnStopped(); }
  44. void SetEqualizer(ifc_equalizer *equalizer) { return Player_SetEqualizer(equalizer); }
  45. /* percent is 0-100. setting to 100 implies that buffering has finished */
  46. void SetBufferStatus(int percent) { return Player_SetBufferStatus(percent); }
  47. void OnSeekComplete(int error_code, double new_position) { return Player_OnSeekComplete(error_code, new_position); }
  48. /* seekable is 0 (false) or 1 (true) */
  49. void SetSeekable(int seekable) { return Player_SetSeekable(seekable); }
  50. void AsynchronousFunctionCall(void (*function)(void *, void *, double), void *param1, void *param2, double real_param) { Player_AsynchronousFunctionCall(function, param1, param2, real_param); }
  51. /* Call this after you've successfully opened and parsed the playback file, and are attempting to start playback */
  52. void OnReady() { Player_OnReady(); };
  53. /* Call this after EndOfFile() when either 1) You process an ifc_playback::Close() call or 2) ifc_audioout::IsPlaying() returns NErr_False while waiting for a Close() call */
  54. void OnClosed() { Player_OnClosed(); };
  55. enum
  56. {
  57. DISPATCHABLE_VERSION,
  58. };
  59. protected:
  60. virtual void WASABICALL Player_SetMetadata(ifc_metadata *metadata) = 0;
  61. virtual void WASABICALL Player_SetBitrate(uint64_t bitrate, double timestamp) = 0;
  62. virtual void WASABICALL Player_SetLength(double length) = 0;
  63. virtual void WASABICALL Player_SetPosition(double timestamp) = 0;
  64. virtual void WASABICALL Player_OnLoaded(nx_uri_t filename) = 0;
  65. virtual void WASABICALL Player_OnEndOfFile() = 0;
  66. virtual void WASABICALL Player_OnError(NError code) = 0;
  67. virtual void WASABICALL Player_OnStopped()=0;
  68. virtual void WASABICALL Player_SetEqualizer(ifc_equalizer *equalizer)=0;
  69. virtual void WASABICALL Player_SetBufferStatus(int percent)=0;
  70. virtual void WASABICALL Player_OnSeekComplete(int error_code, double new_position)=0;
  71. virtual void WASABICALL Player_SetSeekable(int seekable)=0;
  72. virtual void WASABICALL Player_AsynchronousFunctionCall(void (*function)(void *, void *, double), void *param1, void *param2, double real_param)=0;
  73. virtual void WASABICALL Player_OnReady()=0;
  74. virtual void WASABICALL Player_OnClosed()=0;
  75. };