NSVAACDecoder.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #include "NSVAACDecoder.h"
  2. #include <assert.h>
  3. #include "api.h"
  4. #include "../nsv/nsvlib.h"
  5. #include "api.h"
  6. #include "../nsv/nsvlib.h"
  7. #include "../nsv/dec_if.h"
  8. #include <string.h>
  9. #include <bfc/platform/export.h>
  10. #include "NSVAACDecoder.h"
  11. #include <bfc/error.h>
  12. #ifndef MIN
  13. #define MIN(a,b) (((a) < (b)) ? (a) : (b))
  14. #endif
  15. NSVAACDecoder *NSVAACDecoder::CreateDecoder()
  16. {
  17. NSVAACDecoder *decoder=0;
  18. WASABI_API_MEMMGR->New(&decoder);
  19. if (!decoder)
  20. {
  21. return 0;
  22. }
  23. decoder->Initialize();
  24. return decoder;
  25. }
  26. NSVAACDecoder::NSVAACDecoder()
  27. {
  28. source_position=0;
  29. out_left=0;
  30. in_position=0;
  31. }
  32. NSVAACDecoder::~NSVAACDecoder()
  33. {
  34. }
  35. void NSVAACDecoder::Initialize()
  36. {
  37. decoder.Open();
  38. }
  39. void NSVAACDecoder::flush()
  40. {
  41. decoder.Flush();
  42. }
  43. // returns -1 on error, 0 on success (done with data in 'in'), 1 on success
  44. // but to pass 'in' again next time around.
  45. int NSVAACDecoder::decode(void *in, int in_len, void *out, int *out_len, unsigned int out_fmt[8])
  46. {
  47. HRESULT hr;
  48. size_t local_out_len = *out_len;
  49. if (SUCCEEDED(decoder.Decode(out, &local_out_len, 16, false, 1.0))) {
  50. *out_len = (int)local_out_len;
  51. if (local_out_len) {
  52. uint32_t local_sample_rate, local_channels;
  53. if (SUCCEEDED(decoder.GetOutputProperties(&local_sample_rate, &local_channels))) {
  54. out_fmt[0] = NSV_MAKETYPE('P', 'C', 'M', ' ');
  55. out_fmt[1] = local_sample_rate;
  56. out_fmt[2] = local_channels;
  57. out_fmt[3] = 16;
  58. }
  59. return 1;
  60. }
  61. }
  62. hr = decoder.Feed(in, in_len);
  63. if (FAILED(hr)) {
  64. hr=hr;
  65. }
  66. local_out_len = *out_len;
  67. if (SUCCEEDED(decoder.Decode(out, &local_out_len, 16, false, 1.0))) {
  68. *out_len = (int)local_out_len;
  69. if (local_out_len) {
  70. uint32_t local_sample_rate, local_channels;
  71. if (SUCCEEDED(decoder.GetOutputProperties(&local_sample_rate, &local_channels))) {
  72. out_fmt[0] = NSV_MAKETYPE('P', 'C', 'M', ' ');
  73. out_fmt[1] = local_sample_rate;
  74. out_fmt[2] = local_channels;
  75. out_fmt[3] = 16;
  76. }
  77. }
  78. } else {
  79. *out_len = 0;
  80. }
  81. return 0;
  82. }
  83. IAudioDecoder *NSVDecoder::CreateAudioDecoder(FOURCC format, IAudioOutput **output)
  84. {
  85. switch (format)
  86. {
  87. case NSV_MAKETYPE('A', 'A', 'C', ' ') :
  88. case NSV_MAKETYPE('A', 'A', 'C', 'P'):
  89. case NSV_MAKETYPE('A', 'P', 'L', ' '):
  90. {
  91. NSVAACDecoder *dec = NSVAACDecoder::CreateDecoder();
  92. return dec;
  93. }
  94. default:
  95. return 0;
  96. }
  97. }
  98. #define CBCLASS NSVDecoder
  99. START_DISPATCH;
  100. CB(SVC_NSVFACTORY_CREATEAUDIODECODER, CreateAudioDecoder)
  101. END_DISPATCH;
  102. #undef CBCLASS