tags 476374 + patch
thanks

Attached is an incomplete patch porting xine-lib to the new libmpcdec
API.  Incomplete, because 1) no SV8 support and 2) still no seeking.
However, it is not a regression compared to the current package, and
will allow the libmpcdec transition to complete.

Tested with totem-xine, gxine and amarok-engine-xine.
diff -r dd91981c4d48 configure.ac
--- a/configure.ac      Tue Apr 07 22:34:53 2009 +0100
+++ b/configure.ac      Thu Jun 04 13:29:58 2009 +0300
@@ -1341,8 +1341,10 @@
 if test "x$enable_musepack" = "xno"; then
    AC_MSG_RESULT([musepack support disabled])
 elif test "x$with_external_libmpcdec" = "xyes"; then
-   AC_CHECK_LIB([mpcdec], [mpc_decoder_decode], [have_mpcdec=yes])
-   AC_CHECK_HEADERS([mpcdec/mpcdec.h], , [have_mpcdec=no])
+   AC_CHECK_LIB([mpcdec], [mpc_demux_decode], [have_mpcdec=yes],
+   [AC_CHECK_LIB([mpcdec], [mpc_decoder_decode], [have_mpcdec=yes])])
+   AC_CHECK_HEADERS([mpc/mpcdec.h], [],
+   [AC_CHECK_HEADERS([mpcdec/mpcdec.h], [], [have_mpcdec=no])])
    if test "x$have_mpcdec" != "xyes"; then
       AC_MSG_ERROR([Unable to find mpcdec])
    fi
diff -r dd91981c4d48 src/libmusepack/xine_musepack_decoder.c
--- a/src/libmusepack/xine_musepack_decoder.c   Tue Apr 07 22:34:53 2009 +0100
+++ b/src/libmusepack/xine_musepack_decoder.c   Thu Jun 04 13:29:58 2009 +0300
@@ -47,6 +47,8 @@
 
 #ifdef HAVE_MPCDEC_MPCDEC_H
 # include <mpcdec/mpcdec.h>
+#elif defined(HAVE_MPC_MPCDEC_H)
+# include <mpc/mpcdec.h>
 #else
 # include "musepack/musepack.h"
 #endif
@@ -78,7 +80,11 @@
 
   mpc_reader       reader;
   mpc_streaminfo   streaminfo;
+#ifndef HAVE_MPC_MPCDEC_H
   mpc_decoder      decoder;
+#else
+  mpc_demux       *decoder;
+#endif
   
   int              decoder_ok;
   unsigned int     current_frame;
@@ -93,8 +99,13 @@
  *************************************************************************/
     
 /* Reads size bytes of data into buffer at ptr. */
+#ifndef HAVE_MPC_MPCDEC_H
 static int32_t mpc_reader_read(void *data, void *ptr, int size) {
   mpc_decoder_t *this = (mpc_decoder_t *) data;
+#else
+static int32_t mpc_reader_read(mpc_reader *data, void *ptr, int size) {
+  mpc_decoder_t *this = (mpc_decoder_t *) data->data;
+#endif
   
   lprintf("mpc_reader_read: size=%d\n", size);
   
@@ -112,8 +123,13 @@
 }
  
 /* Seeks to byte position offset. */
+#ifndef HAVE_MPC_MPCDEC_H
 static mpc_bool_t mpc_reader_seek(void *data, int32_t offset) {
   mpc_decoder_t *this = (mpc_decoder_t *) data;
+#else
+static mpc_bool_t mpc_reader_seek(mpc_reader *data, int32_t offset) {
+  mpc_decoder_t *this = (mpc_decoder_t *) data->data;
+#endif
   
   lprintf("mpc_reader_seek: offset=%d\n", offset);
   
@@ -121,11 +137,19 @@
    * that the buffer starts at the start of the file */
   this->read = offset;
   
+#ifndef HAVE_MPC_MPCDEC_H
   return TRUE;
+#else
+  return MPC_TRUE;
+#endif
 }
 
 /* Returns the current byte offset in the stream. */
+#ifndef HAVE_MPC_MPCDEC_H
 static int32_t mpc_reader_tell(void *data) {
+#else
+static int32_t mpc_reader_tell(mpc_reader *data) {
+#endif
   lprintf("mpc_reader_tell\n");
   
   /* Tell isn't used so just return 0 */
@@ -133,8 +157,13 @@
 }
 
 /* Returns the total length of the source stream, in bytes. */
+#ifndef HAVE_MPC_MPCDEC_H
 static int32_t mpc_reader_get_size(void *data) {
   mpc_decoder_t *this = (mpc_decoder_t *) data;
+#else
+static int32_t mpc_reader_get_size(mpc_reader *data) {
+  mpc_decoder_t *this = (mpc_decoder_t *) data->data;
+#endif
   
   lprintf("mpc_reader_get_size\n");
   
@@ -142,10 +171,17 @@
 }
 
 /* True if the stream is a seekable stream. */
+#ifndef HAVE_MPC_MPCDEC_H
 static mpc_bool_t mpc_reader_canseek(void *data) {
   lprintf("mpc_reader_canseek\n");
   
   return TRUE;
+#else
+static mpc_bool_t mpc_reader_canseek(mpc_reader *data) {
+
+  lprintf("mpc_reader_canseek\n");
+  return MPC_TRUE;
+#endif
 }
 
 /* Convert 32bit float samples into 16bit int samples */
@@ -165,10 +201,19 @@
 static int mpc_decode_frame (mpc_decoder_t *this) {
   float buffer[MPC_DECODER_BUFFER_LENGTH];
   uint32_t frames;
+#ifdef HAVE_MPC_MPCDEC_H
+  mpc_frame_info frame;
+#endif
   
   lprintf("mpd_decode_frame\n");
   
+#ifndef HAVE_MPC_MPCDEC_H
   frames = mpc_decoder_decode(&this->decoder, buffer, 0, 0);
+#else
+  frame.buffer = buffer;
+  mpc_demux_decode(this->decoder, &frame);
+  frames = frame.samples;
+#endif
   
   if (frames > 0) {
     audio_buffer_t *audio_buffer;  
@@ -235,6 +280,16 @@
     xine_fast_memcpy(this->buf, buf->content, buf->size);
     this->size = buf->size;
     
+#ifdef HAVE_MPC_MPCDEC_H
+    this->decoder = mpc_demux_init(&this->reader);
+    if (!this->decoder) {
+      xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
+             _("libmusepack: mpc_demux_init failed.\n"));
+      _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0);
+      return;
+    }
+    mpc_demux_get_info(this->decoder, &this->streaminfo);
+#else
     /* Initialise and read stream info */
     mpc_streaminfo_init(&this->streaminfo);
     
@@ -245,6 +300,7 @@
       _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_HANDLED, 0);
       return;
     }
+#endif
     
     this->sample_rate     = this->streaminfo.sample_freq;
     this->channels        = this->streaminfo.channels;
@@ -259,7 +315,9 @@
     this->current_frame = 0;
         
     /* Setup the decoder */
+#ifndef HAVE_MPC_MPCDEC_H
     mpc_decoder_setup(&this->decoder, &this->reader);
+#endif
     this->decoder_ok = 0;
 
     /* Take this opportunity to initialize stream/meta information */
@@ -312,7 +370,11 @@
   /* Time to decode */
   if (buf->decoder_flags & BUF_FLAG_FRAME_END)  {
     /* Increment frame count */
+#ifndef HAVE_MPC_MPCDEC_H
     if (this->current_frame++ == this->streaminfo.frames) {
+#else
+    if (this->current_frame++ == this->streaminfo.samples) {
+#endif
       xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
               _("libmusepack: data after last frame ignored\n"));
       return;
@@ -323,7 +385,11 @@
       if ((this->size - this->read) >= MPC_DECODER_MEMSIZE) {
         lprintf("initialise");
       
+#ifndef HAVE_MPC_MPCDEC_H
         if (!mpc_decoder_initialize(&this->decoder, &this->streaminfo)) {
+#else
+        if (!this->decoder) {
+#endif
           xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
                   _("libmusepack: mpc_decoder_initialise failed\n"));        
           
@@ -354,7 +420,11 @@
     
     /* If we are at the end of the stream we decode the remaining frames as we
      * know we'll have enough data */
+#ifndef HAVE_MPC_MPCDEC_H
     if (this->current_frame == this->streaminfo.frames) {
+#else
+    if (this->current_frame == this->streaminfo.samples) {
+#endif
       lprintf("flushing buffers\n");
       
       do {
@@ -392,6 +462,10 @@
   /* free anything that was allocated during operation */
   if (this->buf)
     free(this->buf);
+#ifdef HAVE_MPC_MPCDEC_H
+  if (this->decoder)
+    mpc_demux_exit(this->decoder);
+#endif
   
   free(this);
 }

Reply via email to