1
0

api_decodefile.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #ifndef NULLSOFT_AGAVE_API_DECODEFILE_H
  2. #define NULLSOFT_AGAVE_API_DECODEFILE_H
  3. #include <bfc/dispatch.h>
  4. #include <bfc/platform/types.h>
  5. #include "ifc_audiostream.h"
  6. enum
  7. {
  8. API_DECODEFILE_SUCCESS = 0,
  9. API_DECODEFILE_FAILURE = 1,
  10. API_DECODEFILE_UNSUPPORTED = 2, // type is unsupported
  11. API_DECODEFILE_NO_INTERFACE = 3, // type is supported, but plugin does provide any interfaces for direct decoding
  12. API_DECODEFILE_WINAMP_PRO = 4, // user has to pay $$$ to do this
  13. API_DECODEFILE_NO_RIGHTS = 5, // user is not allowed to decode this file (e.g. DRM)
  14. API_DECODEFILE_BAD_RESAMPLE = 6, // Winamp is unable to resample this file to CDDA format (stereo 16bit 44.1kHz)
  15. API_DECODEFILE_FAIL_NO_WARN = 7, // we have already informed the user of an issue so do not show again e.g. CD playing so cannot also do a rip
  16. };
  17. enum
  18. {
  19. AUDIOPARAMETERS_FLOAT = 1,
  20. AUDIOPARAMETERS_MAXCHANNELS = 2, // set this if channels is meant to define an upper limit
  21. // (e.g. setting channels=2 and flags |= AUDIOPARAMETERS_MAXCHANNELS means 1 or 2 channels is OK, but not more)
  22. AUDIOPARAMETERS_MAXSAMPLERATE = 4, // like AUDIOPARAMETERS_MAXCHANNELS but for sample rate
  23. AUDIOPARAMETERS_NON_INTERLEAVED = 8, // audio data is stored as separate buffers per channel. not currently implemented
  24. };
  25. struct AudioParameters
  26. {
  27. public:
  28. AudioParameters() : bitsPerSample(0), channels(0), sampleRate(0), sampleRateReal(0.f), flags(0), sizeBytes((size_t) - 1), errorCode(API_DECODEFILE_SUCCESS)
  29. {}
  30. uint32_t bitsPerSample;
  31. uint32_t channels;
  32. uint32_t sampleRate;
  33. float sampleRateReal; // yes this is duplicate.
  34. int flags;
  35. size_t sizeBytes; // total size of decoded file, (size_t)-1 means don't know
  36. int errorCode;
  37. };
  38. class api_decodefile : public Dispatchable
  39. {
  40. public:
  41. /* OpenAudioBackground gives you back an ifc_audiostream that you can use to get decompressed bits
  42. * if it returns 0, check parameters->errorCode for the failure reason
  43. * fill parameters with desired values (0 if you don't care)
  44. * the decoder will _do its best_ to satisfy your passed-in audio parameters
  45. * but this API does not guarantee them, so be sure to check the parameters struct after the function returns
  46. * it's **UP TO YOU** to do any necessary conversion (sample rate, channels, bits-per-sample) if the decoder can't do it
  47. */
  48. ifc_audiostream *OpenAudioBackground(const wchar_t *filename, AudioParameters *parameters);
  49. /* OpenAudio is the same as OpenAudioBackground
  50. * but, it will use the input plugin system to decode if necessary
  51. * so it's best to use this in a separate winamp.exe
  52. * to be honest, it was designed for internal use in the CD burner
  53. * so it's best not to use this one at all
  54. */
  55. ifc_audiostream *OpenAudio(const wchar_t *filename, AudioParameters *parameters);
  56. void CloseAudio(ifc_audiostream *audioStream);
  57. /* verifies that a decoder exists to decompress this filename.
  58. this is not a guarantee that the file is openable, just that it can be matched to a decoder */
  59. bool DecoderExists(const wchar_t *filename);
  60. public:
  61. DISPATCH_CODES
  62. {
  63. API_DECODEFILE_OPENAUDIO = 10,
  64. API_DECODEFILE_OPENAUDIO2 = 11,
  65. API_DECODEFILE_CLOSEAUDIO = 20,
  66. API_DECODEFILE_DECODEREXISTS = 30,
  67. };
  68. };
  69. inline ifc_audiostream *api_decodefile::OpenAudio(const wchar_t *filename, AudioParameters *parameters)
  70. {
  71. return _call(API_DECODEFILE_OPENAUDIO, (ifc_audiostream *)0, filename, parameters);
  72. }
  73. inline ifc_audiostream *api_decodefile::OpenAudioBackground(const wchar_t *filename, AudioParameters *parameters)
  74. {
  75. return _call(API_DECODEFILE_OPENAUDIO2, (ifc_audiostream *)0, filename, parameters);
  76. }
  77. inline void api_decodefile::CloseAudio(ifc_audiostream *audioStream)
  78. {
  79. _voidcall(API_DECODEFILE_CLOSEAUDIO, audioStream);
  80. }
  81. inline bool api_decodefile::DecoderExists(const wchar_t *filename)
  82. {
  83. return _call(API_DECODEFILE_DECODEREXISTS, (bool)true, filename); // we default to true so that an old implementation doesn't break completely
  84. }
  85. // {9B4188F5-4295-48ab-B50C-F2B0BB56D242}
  86. static const GUID decodeFileGUID =
  87. {
  88. 0x9b4188f5, 0x4295, 0x48ab, { 0xb5, 0xc, 0xf2, 0xb0, 0xbb, 0x56, 0xd2, 0x42 }
  89. };
  90. #endif