FLACFileCallbacks.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "FLACFileCallbacks.h"
  2. FLAC__StreamDecoderReadStatus FLAC_NXFile_Read(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  3. {
  4. nx_file_t file = FLAC_GetFile(client_data);
  5. size_t bytes_to_read = *bytes;
  6. size_t bytes_read=0;
  7. ns_error_t ret = NXFileRead(file, buffer, bytes_to_read, &bytes_read);
  8. *bytes = bytes_read;
  9. if (ret == NErr_EndOfFile)
  10. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  11. if (ret != NErr_Success)
  12. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  13. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  14. }
  15. FLAC__StreamDecoderSeekStatus FLAC_NXFile_Seek(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  16. {
  17. nx_file_t file = FLAC_GetFile(client_data);
  18. if (NXFileSeek(file, absolute_byte_offset) == NErr_Success)
  19. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  20. else
  21. return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
  22. }
  23. FLAC__StreamDecoderTellStatus FLAC_NXFile_Tell(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  24. {
  25. nx_file_t file = FLAC_GetFile(client_data);
  26. if (NXFileTell(file, absolute_byte_offset) == NErr_Success)
  27. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  28. else
  29. return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
  30. }
  31. FLAC__StreamDecoderLengthStatus FLAC_NXFile_Length(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
  32. {
  33. nx_file_t file = FLAC_GetFile(client_data);
  34. if (NXFileLength(file, stream_length) == NErr_Success)
  35. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  36. else
  37. return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
  38. }
  39. FLAC__bool FLAC_NXFile_EOF(const FLAC__StreamDecoder *decoder, void *client_data)
  40. {
  41. nx_file_t file = FLAC_GetFile(client_data);
  42. if (NXFileEndOfFile(file) == NErr_False)
  43. return false;
  44. else
  45. return true;
  46. }