RawReader.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include "main.h"
  2. #include "RawReader.h"
  3. #include <shlwapi.h>
  4. /*
  5. bool IsMyExtension(const wchar_t *filename)
  6. {
  7. const wchar_t *ext = PathFindExtension(filename);
  8. if (ext && *ext)
  9. {
  10. ext++;
  11. return fileTypes.GetAVType(ext) != -1;
  12. }
  13. return false;
  14. }*/
  15. int RawMediaReaderService::CreateRawMediaReader(const wchar_t *filename, ifc_raw_media_reader **out_reader)
  16. {
  17. // TODO:if (IsMyExtension(filename))
  18. if (!_wcsicmp(L".WAV", PathFindExtensionW(filename)))
  19. {
  20. RawMediaReader *raw_reader = new RawMediaReader();
  21. if (!raw_reader)
  22. {
  23. return NErr_OutOfMemory;
  24. }
  25. int ret = raw_reader->Initialize(filename);
  26. if (ret != NErr_Success)
  27. {
  28. delete raw_reader;
  29. return ret;
  30. }
  31. *out_reader = raw_reader;
  32. return NErr_Success;
  33. }
  34. else
  35. {
  36. return NErr_False;
  37. }
  38. }
  39. #define CBCLASS RawMediaReaderService
  40. START_DISPATCH;
  41. CB( CREATERAWMEDIAREADER, CreateRawMediaReader )
  42. END_DISPATCH;
  43. #undef CBCLASS
  44. RawMediaReader::~RawMediaReader()
  45. {
  46. if (soundFile)
  47. sf_close(soundFile);
  48. }
  49. int RawMediaReader::Initialize(const wchar_t *filename)
  50. {
  51. info.format = 0;
  52. soundFile = sf_wchar_open(filename, SFM_READ, &info);
  53. if (!soundFile)
  54. return NErr_FileNotFound;
  55. return NErr_Success;
  56. }
  57. int RawMediaReader::Read(void *out_buffer, size_t buffer_size, size_t *bytes_read)
  58. {
  59. sf_count_t sf_read = sf_read_raw(soundFile, out_buffer, buffer_size);
  60. if (sf_read == 0)
  61. return NErr_EndOfFile;
  62. *bytes_read = (size_t)sf_read;
  63. return NErr_Success;
  64. }
  65. size_t RawMediaReader::Release()
  66. {
  67. delete this;
  68. return 0;
  69. }
  70. #define CBCLASS RawMediaReader
  71. START_DISPATCH;
  72. CB(RELEASE, Release);
  73. CB(RAW_READ, Read);
  74. END_DISPATCH;
  75. #undef CBCLASS