api_decodefile.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #ifndef NULLSOFT_API_DECODEFILE_H
  2. #define NULLSOFT_API_DECODEFILE_H
  3. #include <bfc/dispatch.h>
  4. #include <bfc/platform/types.h>
  5. #include "api_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. };
  16. enum
  17. {
  18. AUDIOPARAMETERS_FLOAT = 1,
  19. };
  20. struct AudioParameters
  21. {
  22. public:
  23. AudioParameters() : bitsPerSample(0), channels(0), sampleRate(0), sampleRateReal(0.f), sizeBytes((size_t) - 1), errorCode(API_DECODEFILE_SUCCESS), flags(0)
  24. {}
  25. size_t bitsPerSample;
  26. size_t channels;
  27. size_t sampleRate;
  28. float sampleRateReal; // yes this is duplicate.
  29. int flags;
  30. size_t sizeBytes; // total size of decoded file, (size_t)-1 means don't know
  31. int errorCode;
  32. };
  33. class api_decodefile : public Dispatchable
  34. {
  35. public:
  36. /* OpenAudioBackground gives you back an api_audiostream that you can use to get decompressed bits
  37. * if it returns 0, check parameters->errorCode for the failure reason
  38. * fill parameters with desired values (0 if you don't care)
  39. * the decoder will _do its best_ to satisfy your passed-in audio parameters
  40. * but this API does not guarantee them, so be sure to check the parameters struct after the function returns
  41. * it's **UP TO YOU** to do any necessary conversion (sample rate, channels, bits-per-sample) if the decoder can't do it
  42. */
  43. api_audiostream *OpenAudioBackground(const wchar_t *filename, AudioParameters *parameters);
  44. /* OpenAudio is the same as OpenAudioBackground
  45. * but, it will use the input plugin system to decode if necessary
  46. * so it's best to use this in a separate winamp.exe
  47. * to be honest, it was designed for internal use in the CD burner
  48. * so it's best not to use this one at all
  49. */
  50. api_audiostream *OpenAudio(const wchar_t *filename, AudioParameters *parameters);
  51. void CloseAudio(api_audiostream *audioStream);
  52. /* verifies that a decoder exists to decompress this filename.
  53. this is not a guarantee tgat the file is openable, just that it can be matched to a decoder */
  54. bool DecoderExists(const wchar_t *filename);
  55. public:
  56. DISPATCH_CODES
  57. {
  58. API_DECODEFILE_OPENAUDIO = 10,
  59. API_DECODEFILE_OPENAUDIO2 = 11,
  60. API_DECODEFILE_CLOSEAUDIO = 20,
  61. API_DECODEFILE_DECODEREXISTS = 30,
  62. };
  63. };
  64. inline api_audiostream *api_decodefile::OpenAudio(const wchar_t *filename, AudioParameters *parameters)
  65. {
  66. return _call(API_DECODEFILE_OPENAUDIO, (api_audiostream *)0, filename, parameters);
  67. }
  68. inline api_audiostream *api_decodefile::OpenAudioBackground(const wchar_t *filename, AudioParameters *parameters)
  69. {
  70. return _call(API_DECODEFILE_OPENAUDIO2, (api_audiostream *)0, filename, parameters);
  71. }
  72. inline void api_decodefile::CloseAudio(api_audiostream *audioStream)
  73. {
  74. _voidcall(API_DECODEFILE_CLOSEAUDIO, audioStream);
  75. }
  76. inline bool api_decodefile::DecoderExists(const wchar_t *filename)
  77. {
  78. return _call(API_DECODEFILE_DECODEREXISTS, (bool)true, filename); // we default to true so that an old implementation doesn't break completely
  79. }
  80. // {9B4188F5-4295-48ab-B50C-F2B0BB56D242}
  81. static const GUID decodeFileGUID =
  82. {
  83. 0x9b4188f5, 0x4295, 0x48ab, { 0xb5, 0xc, 0xf2, 0xb0, 0xbb, 0x56, 0xd2, 0x42 }
  84. };
  85. #endif