cuecue-0.2.2-flac113.diff 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. --- a/src/libcuecue/flac.c
  2. +++ b/src/libcuecue/flac.c
  3. @@ -27,6 +27,12 @@
  4. #include "cuecue.h"
  5. #include "cuecue_internal.h"
  6. +#if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT <= 7
  7. +#define LEGACY_FLAC
  8. +#else
  9. +#undef LEGACY_FLAC
  10. +#endif
  11. +
  12. typedef struct Internal
  13. {
  14. FILE *dst;
  15. @@ -38,7 +44,11 @@
  16. } Internal;
  17. +#ifdef LEGACY_FLAC
  18. void error(const FLAC__FileDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
  19. +#else
  20. +void error(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
  21. +#endif
  22. {
  23. Internal *internal = client_data;
  24. switch (status) {
  25. @@ -52,11 +62,21 @@
  26. strcpy(cuecue_error,"CRC Mismatch: FLAC file corrupted");
  27. internal->error=1;
  28. break;
  29. +#ifndef LEGACY_FLAC
  30. + case FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM:
  31. + strcpy(cuecue_error,"Unparseable stream");
  32. + internal->error=1;
  33. + break;
  34. +#endif
  35. }
  36. }
  37. +#ifdef LEGACY_FLAC
  38. void metadata(const FLAC__FileDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
  39. +#else
  40. +void metadata(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
  41. +#endif
  42. {
  43. if(metadata->type == FLAC__METADATA_TYPE_STREAMINFO) {
  44. /* get size of the file, for progress callback */
  45. @@ -66,7 +86,11 @@
  46. }
  47. +#ifdef LEGACY_FLAC
  48. FLAC__StreamDecoderWriteStatus write(const FLAC__FileDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
  49. +#else
  50. +FLAC__StreamDecoderWriteStatus write(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
  51. +#endif
  52. {
  53. Internal *internal = client_data;
  54. unsigned int samples = frame->header.blocksize;
  55. @@ -126,7 +150,11 @@
  56. {
  57. FILE *dst;
  58. Internal internal;
  59. +#ifdef LEGACY_FLAC
  60. FLAC__FileDecoder *decoder;
  61. +#else
  62. + FLAC__StreamDecoder *decoder;
  63. +#endif
  64. dst = fopen(file_destination, "wb");
  65. @@ -141,7 +169,11 @@
  66. internal.error=0;
  67. internal.dst=dst;
  68. +#ifdef LEGACY_FLAC
  69. decoder = FLAC__file_decoder_new();
  70. +#else
  71. + decoder = FLAC__stream_decoder_new();
  72. +#endif
  73. if (decoder==NULL) {
  74. snprintf(cuecue_error,CUECUE_ERROR_LENGTH,"Cannot create FLAC decoder! memory error ?");
  75. @@ -150,6 +182,7 @@
  76. internal.buffer = malloc(BUFFER_SIZE);
  77. +#ifdef LEGACY_FLAC
  78. FLAC__file_decoder_set_md5_checking(decoder, true);
  79. FLAC__file_decoder_set_filename(decoder, file_source);
  80. @@ -162,8 +195,20 @@
  81. snprintf(cuecue_error,1024,"Cannot open '%s'",file_source);
  82. internal.error=1;
  83. }
  84. +#else
  85. + FLAC__stream_decoder_set_md5_checking(decoder, true);
  86. + if(FLAC__stream_decoder_init_file(decoder, file_source, write, metadata, error, &internal) != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
  87. + snprintf(cuecue_error,1024,"Cannot open '%s'",file_source);
  88. + internal.error=1;
  89. + }
  90. +#endif
  91. - if(!FLAC__file_decoder_process_until_end_of_file(decoder)) {
  92. +#ifdef LEGACY_FLAC
  93. + if(!FLAC__file_decoder_process_until_end_of_file(decoder))
  94. +#else
  95. + if(!FLAC__stream_decoder_process_until_end_of_stream(decoder))
  96. +#endif
  97. + {
  98. if (!internal.error) {
  99. /* early error, not even the time to decode metadata :) */
  100. snprintf(cuecue_error,CUECUE_ERROR_LENGTH,"Cannot open '%s'",file_source);
  101. @@ -171,8 +216,13 @@
  102. internal.error=1;
  103. }
  104. +#ifdef LEGACY_FLAC
  105. FLAC__file_decoder_finish(decoder);
  106. FLAC__file_decoder_delete(decoder);
  107. +#else
  108. + FLAC__stream_decoder_finish(decoder);
  109. + FLAC__stream_decoder_delete(decoder);
  110. +#endif
  111. fclose(dst);
  112. free(internal.buffer);