chiark / gitweb /
work around FLAC API change braindamage
authorRichard Kettlewell <richard@deodand>
Sat, 10 Nov 2007 18:44:20 +0000 (18:44 +0000)
committerRichard Kettlewell <richard@deodand>
Sat, 10 Nov 2007 18:44:20 +0000 (18:44 +0000)
configure.ac
plugins/tracklength.c
server/decode.c

index 68dbae042ddb6405de7ea57054e2a75dca751c40..f372639a9b7b6240479fb34da22b8218c9ac275f 100644 (file)
@@ -255,6 +255,7 @@ if test $want_server = yes; then
   AC_CHECK_HEADERS([db.h],[:],[
     missing_headers="$missing_headers $ac_header"
   ])
+  AC_CHECK_HEADERS([FLAC/file_decoder.h])
 fi
 AC_CHECK_HEADERS([dlfcn.h gcrypt.h \
                 getopt.h iconv.h langinfo.h \
index c1b9cb93d0dc9bf7a335c2dcc5e5bf2d32f7ef37..cac700868ba6a7e66dd68b05e7f5a8d023dbe5f1 100644 (file)
 
 #include <vorbis/vorbisfile.h>
 #include <mad.h>
-#include <FLAC/file_decoder.h>
+/* libFLAC has had an API change and stupidly taken away the old API */
+#if HAVE_FLAC_FILE_DECODER_H
+# include <FLAC/file_decoder.h>
+#else
+# include <FLAC/stream_decoder.h>
+#define FLAC__FileDecoder FLAC__StreamDecoder
+#define FLAC__FileDecoderState FLAC__StreamDecoderState
+#endif
+
 
 #include <disorder.h>
 
@@ -159,33 +167,58 @@ static FLAC__StreamDecoderWriteStatus flac_write
 }
 
 static long tl_flac(const char *path) {
-  FLAC__FileDecoder *fd = 0;
-  FLAC__FileDecoderState fs;
   struct flac_state state[1];
 
   state->duration = -1;                        /* error */
   state->path = path;
-  if(!(fd = FLAC__file_decoder_new())) {
-    disorder_error(0, "FLAC__file_decoder_new failed");
-    goto fail;
-  }
-  if(!(FLAC__file_decoder_set_filename(fd, path))) {
-    disorder_error(0, "FLAC__file_set_filename failed");
-    goto fail;
-  }
-  FLAC__file_decoder_set_metadata_callback(fd, flac_metadata);
-  FLAC__file_decoder_set_error_callback(fd, flac_error);
-  FLAC__file_decoder_set_write_callback(fd, flac_write);
-  FLAC__file_decoder_set_client_data(fd, state);
-  if((fs = FLAC__file_decoder_init(fd))) {
-    disorder_error(0, "FLAC__file_decoder_init: %s",
-                  FLAC__FileDecoderStateString[fs]);
-    goto fail;
-  }
-  FLAC__file_decoder_process_until_end_of_metadata(fd);
+#if HAVE_FLAC_FILE_DECODER_H 
+  {
+    FLAC__FileDecoder *fd = 0;
+    FLAC__FileDecoderState fs;
+    
+    if(!(fd = FLAC__file_decoder_new())) {
+      disorder_error(0, "FLAC__file_decoder_new failed");
+      goto fail;
+    }
+    if(!(FLAC__file_decoder_set_filename(fd, path))) {
+      disorder_error(0, "FLAC__file_set_filename failed");
+      goto fail;
+    }
+    FLAC__file_decoder_set_metadata_callback(fd, flac_metadata);
+    FLAC__file_decoder_set_error_callback(fd, flac_error);
+    FLAC__file_decoder_set_write_callback(fd, flac_write);
+    FLAC__file_decoder_set_client_data(fd, state);
+    if((fs = FLAC__file_decoder_init(fd))) {
+      disorder_error(0, "FLAC__file_decoder_init: %s",
+                    FLAC__FileDecoderStateString[fs]);
+      goto fail;
+    }
+    FLAC__file_decoder_process_until_end_of_metadata(fd);
+fail:
+    if(fd)
+      FLAC__file_decoder_delete(fd);
+  }#
+#else
+  {
+    FLAC__StreamDecoder *sd = 0;
+    FLAC__StreamDecoderInitStatus is;
+    
+    if(!(sd = FLAC__stream_decoder_new())) {
+      disorder_error(0, "FLAC__stream_decoder_new failed");
+      goto fail;
+    }
+    if((is = FLAC__stream_decoder_init_file(sd, path, flac_write, flac_metadata,
+                                           flac_error, state))) {
+      disorder_error(0, "FLAC__stream_decoder_init_file %s: %s",
+                    path, FLAC__StreamDecoderInitStatusString[is]);
+      goto fail;
+    }
+    FLAC__stream_decoder_process_until_end_of_metadata(sd);
 fail:
-  if(fd)
-    FLAC__file_decoder_delete(fd);
+    if(sd)
+      FLAC__stream_decoder_delete(sd);
+  }
+#endif
   return state->duration;
 }
 
index 8161dbaf126b40c81b4cd46f78bd425d74a4db86..47227a29ecb55ef375f3611395cb0f5b1fb053aa 100644 (file)
 #include <fnmatch.h>
 #include <mad.h>
 #include <vorbis/vorbisfile.h>
-#include <FLAC/file_decoder.h>
+
+/* libFLAC has had an API change and stupidly taken away the old API */
+#if HAVE_FLAC_FILE_DECODER_H
+# include <FLAC/file_decoder.h>
+#else
+# include <FLAC/stream_decoder.h>
+#define FLAC__FileDecoder FLAC__StreamDecoder
+#define FLAC__FileDecoderState FLAC__StreamDecoderState
+#endif
 
 #include "log.h"
 #include "syscalls.h"
@@ -372,6 +380,7 @@ static FLAC__StreamDecoderWriteStatus flac_write
 
 /** @brief FLAC file decoder */
 static void decode_flac(void) {
+#if HAVE_FLAC_FILE_DECODER_H
   FLAC__FileDecoder *fd = 0;
   FLAC__FileDecoderState fs;
 
@@ -385,6 +394,15 @@ static void decode_flac(void) {
   if((fs = FLAC__file_decoder_init(fd)))
     fatal(0, "FLAC__file_decoder_init: %s", FLAC__FileDecoderStateString[fs]);
   FLAC__file_decoder_process_until_end_of_file(fd);
+#else
+  FLAC__StreamDecoder *sd = 0;
+  FLAC__StreamDecoderInitStatus is;
+
+  if((is = FLAC__stream_decoder_init_file(sd, path, flac_write, flac_metadata,
+                                          flac_error, 0)))
+    fatal(0, "FLAC__stream_decoder_init_file %s: %s",
+          path, FLAC__StreamDecoderInitStatusString[is]);
+#endif
 }
 
 /** @brief Lookup table of decoders */