On Wed, Apr 16, 2008 at 01:06:45PM +0200, Sebastian Dröge wrote:
> Package: moc
> Severity: wishlist
> Version: 1:2.5.0~alpha3-1
> 
> Hi,
> please port your application to the new libmpcdec API in experimental.
> You find it as libmpcdec-dev / libmpcdec6 in the libmpc source package.

THanks for the information. I've ported the plugin to the new API. It
compiles and plays MPC files, but seeking and displaying the bitrate
doesn't work. The patch is attached and will be included in the next
alpha release.

-- 
Damian Pietras
Index: configure.in
===================================================================
--- configure.in	(revision 2085)
+++ configure.in	(revision 2086)
@@ -310,9 +310,18 @@
 AC_ARG_WITH(musepack, AS_HELP_STRING(--without-musepack, [Compile without musepack (mpc) support]))
 if test "x$with_musepack" != "xno"
 then
-	AC_CHECK_LIB(mpcdec, mpc_decoder_setup, [
-		AC_CHECK_HEADER([mpcdec/mpcdec.h], [have_musepack="yes"])
-		])
+	dnl taken from gstreamer
+	AC_CHECK_HEADER([mpcdec/mpcdec.h], [
+			 have_musepack="yes"
+			 AC_DEFINE(MPC_IS_OLD_API, 1, [Define if the old MusePack API is used])
+			 MUSEPACK_LIBS="-lmpcdec"
+			 AC_SUBST(MUSEPACK_LIBS)
+			 ], [AC_CHECK_HEADER([mpc/mpcdec.h], [
+			     have_musepack="yes"
+			     MUSEPACK_LIBS="-lmpcdec"
+			     AC_SUBST(MUSEPACK_LIBS)
+			     ], [HAVE_MUSEPACK="no"])
+			 ])
 
 	if test "x$have_musepack" = "xyes"
 	then
Index: decoder_plugins/musepack/musepack.c
===================================================================
--- decoder_plugins/musepack/musepack.c	(revision 2085)
+++ decoder_plugins/musepack/musepack.c	(revision 2086)
@@ -20,7 +20,13 @@
 #include <strings.h>
 #include <stdio.h>
 #include <errno.h>
-#include <mpcdec/mpcdec.h>
+
+#ifdef MPC_IS_OLD_API
+# include <mpcdec/mpcdec.h>
+#else
+# include <mpc/mpcdec.h>
+#endif
+
 #include <tag_c.h>
 
 #define DEBUG
@@ -34,7 +40,11 @@
 struct musepack_data
 {
 	struct io_stream *stream;
+#ifdef MPC_IS_OLD_API
 	mpc_decoder decoder;
+#else
+	mpc_demux *demux;
+#endif
 	mpc_reader reader;
 	mpc_streaminfo info;
 	int avg_bitrate;
@@ -45,9 +55,17 @@
 	size_t remain_buf_len; /* in samples (sizeof(float)) */
 };
 
+#ifdef MPC_IS_OLD_API
 static mpc_int32_t read_callback (void *t, void *buf, mpc_int32_t size)
+#else
+static mpc_int32_t read_callback (mpc_reader *t, void *buf, mpc_int32_t size)
+#endif
 {
+#ifdef MPC_IS_OLD_API
 	struct musepack_data *data = (struct musepack_data *)t;
+#else
+	struct musepack_data *data = t->data;
+#endif
 	ssize_t res;
 
 	res = io_read (data->stream, buf, size);
@@ -59,36 +77,68 @@
 	return res;
 }
 
+#ifdef MPC_IS_OLD_API
 static mpc_bool_t seek_callback (void *t, mpc_int32_t offset)
+#else
+static mpc_bool_t seek_callback (mpc_reader *t, mpc_int32_t offset)
+#endif
 {
+#ifdef MPC_IS_OLD_API
 	struct musepack_data *data = (struct musepack_data *)t;
+#else
+	struct musepack_data *data = t->data;
+#endif
 	
 	debug ("Seek request to %ld", (long)offset);
 
 	return io_seek(data->stream, offset, SEEK_SET) >= 0 ? 1 : 0;
 }
 
+#ifdef MPC_IS_OLD_API
 static mpc_int32_t tell_callback (void *t)
+#else
+static mpc_int32_t tell_callback (mpc_reader *t)
+#endif
 {
+#ifdef MPC_IS_OLD_API
 	struct musepack_data *data = (struct musepack_data *)t;
+#else
+	struct musepack_data *data = t->data;
+#endif
 
 	debug ("tell callback");
 
 	return io_tell (data->stream);
 }
 
+#ifdef MPC_IS_OLD_API
 static mpc_int32_t get_size_callback (void *t)
+#else
+static mpc_int32_t get_size_callback (mpc_reader *t)
+#endif
 {
+#ifdef MPC_IS_OLD_API
 	struct musepack_data *data = (struct musepack_data *)t;
+#else
+	struct musepack_data *data = t->data;
+#endif
 
 	debug ("size callback");
 
 	return io_file_size (data->stream);
 }
 
+#ifdef MPC_IS_OLD_API
 static mpc_bool_t canseek_callback (void *t)
+#else
+static mpc_bool_t canseek_callback (mpc_reader *t)
+#endif
 {
+#ifdef MPC_IS_OLD_API
 	struct musepack_data *data = (struct musepack_data *)t;
+#else
+	struct musepack_data *data = t->data;
+#endif
 
 	return io_seekable (data->stream);
 }
@@ -103,6 +153,7 @@
 	data->reader.canseek = canseek_callback;
 	data->reader.data = data;
 
+#ifdef MPC_IS_OLD_API
 	mpc_streaminfo_init (&data->info);
 
 	if (mpc_streaminfo_read(&data->info, &data->reader) != ERROR_CODE_OK) {
@@ -113,13 +164,25 @@
 	}
 
 	mpc_decoder_setup (&data->decoder, &data->reader);
+
 	if (!mpc_decoder_initialize(&data->decoder, &data->info)) {
 		decoder_error (&data->error, ERROR_FATAL, 0,
-				"Can't initialize moc decoder.");
+				"Can't initialize mpc decoder.");
 		io_close (data->stream);
 		return;
 	}
+#else
+	data->demux = mpc_demux_init (&data->reader);
+	if (!data->demux) {
+		decoder_error (&data->error, ERROR_FATAL, 0,
+				"Not a valid MPC file.");
+		io_close (data->stream);
+		return;
+	}
 
+	mpc_demux_get_info (data->demux, &data->info);
+#endif
+
 	data->avg_bitrate = (int) (data->info.average_bitrate / 1000);
 	debug ("Avg bitrate: %d", data->avg_bitrate);
 
@@ -168,6 +231,10 @@
 {
 	struct musepack_data *data = (struct musepack_data *)prv_data;
 
+#ifndef MPC_IS_OLD_API
+	mpc_demux_exit (data->demux);
+#endif
+
 	if (data->ok) {
 		io_close (data->stream);
 		if (data->remain_buf)
@@ -228,7 +295,16 @@
 	struct musepack_data *data = (struct musepack_data *)prv_data;
 	int res;
 
+#ifdef MPC_IS_OLD_API
 	res = mpc_decoder_seek_seconds (&data->decoder, sec) ? sec : -1;
+#else
+	mpc_status status;
+	status = mpc_demux_seek_second (data->demux, sec);
+	if (status == MPC_STATUS_OK)
+		res = sec;
+	else
+		res = -1;
+#endif
 
 	if (res != -1 && data->remain_buf) {
 		free (data->remain_buf);
@@ -243,18 +319,17 @@
 		struct sound_params *sound_params)
 {
 	struct musepack_data *data = (struct musepack_data *)prv_data;
-	int ret;
-	float decode_buf[MPC_DECODER_BUFFER_LENGTH];
 	int decoded;
 	int bytes_from_decoder;
+#ifndef MPC_IS_OLD_API
+	mpc_frame_info frame;
+	mpc_status err;
+#else
+	int ret;
 	mpc_uint32_t vbrAcc = 0;
 	mpc_uint32_t vbrUpd = 0;
-
-	decoder_error_clear (&data->error);
-	sound_params->channels = data->info.channels;
-	sound_params->rate = data->info.sample_freq;
-	sound_params->fmt = SFMT_FLOAT;
-
+#endif
+	float decode_buf[MPC_DECODER_BUFFER_LENGTH];
 	if (data->remain_buf) {
 		size_t to_copy = MIN((unsigned)buf_len,
 				data->remain_buf_len * sizeof(float));
@@ -278,8 +353,8 @@
 		return to_copy;
 	}
 	
+#ifdef MPC_IS_OLD_API
 	ret = mpc_decoder_decode (&data->decoder, decode_buf, &vbrAcc, &vbrUpd);
-	
 	if (ret == 0) {
 		debug ("EOF");
 		return 0;
@@ -293,7 +368,33 @@
 
 	bytes_from_decoder = ret * sizeof(float) * 2; /* stereo */
 	data->bitrate = vbrUpd * sound_params->rate / 1152 / 1000;
+#else
+	do {
+		frame.buffer = decode_buf;
+		err = mpc_demux_decode (data->demux, &frame);
+		if (err != MPC_STATUS_OK) {
+			if (frame.bits == -1) {
+				decoder_error (&data->error, ERROR_FATAL, 0,
+						"Error in the stream!");
+				return 0;
+			}
 
+			decoder_error (&data->error, ERROR_STREAM, 0,
+					"Broken frame.");
+		}
+
+	} while (err != MPC_STATUS_OK);
+
+	mpc_demux_get_info (data->demux, &data->info);
+	bytes_from_decoder = frame.samples * sizeof(MPC_SAMPLE_FORMAT) * data->info.channels;
+	data->bitrate = data->info.bitrate;
+#endif
+
+	decoder_error_clear (&data->error);
+	sound_params->channels = data->info.channels;
+	sound_params->rate = data->info.sample_freq;
+	sound_params->fmt = SFMT_FLOAT;
+	
 	if (bytes_from_decoder >= buf_len) {
 		size_t to_copy = MIN (buf_len, bytes_from_decoder);
 

Reply via email to