tags 476382 + patch thanks Here is a patch porting cmus to the new libmpcdec API. I couldn't find my way through upstream's non-standard build system, though -- so I don't know whether conditionally supporting the old API is possible at all.
--- cmus-2.2.0.orig/mpc.c +++ cmus-2.2.0/mpc.c @@ -11,12 +11,12 @@ #include "xmalloc.h" #include "read_wrapper.h" -#include <mpcdec/mpcdec.h> +#include <mpc/mpcdec.h> #include <inttypes.h> #include <errno.h> struct mpc_private { - mpc_decoder decoder; + mpc_demux *decoder; mpc_reader reader; mpc_streaminfo info; @@ -40,9 +40,9 @@ }; /* callbacks */ -static mpc_int32_t read_impl(void *data, void *ptr, mpc_int32_t size) +static mpc_int32_t read_impl(mpc_reader *data, void *ptr, mpc_int32_t size) { - struct input_plugin_data *ip_data = data; + struct input_plugin_data *ip_data = data->data; int rc; rc = read_wrapper(ip_data, ptr, size); @@ -55,35 +55,35 @@ return rc; } -static mpc_bool_t seek_impl(void *data, mpc_int32_t offset) +static mpc_bool_t seek_impl(mpc_reader *data, mpc_int32_t offset) { - struct input_plugin_data *ip_data = data; + struct input_plugin_data *ip_data = data->data; int rc; rc = lseek(ip_data->fd, offset, SEEK_SET); if (rc == -1) - return FALSE; - return TRUE; + return MPC_FALSE; + return MPC_TRUE; } -static mpc_int32_t tell_impl(void *data) +static mpc_int32_t tell_impl(mpc_reader *data) { - struct input_plugin_data *ip_data = data; + struct input_plugin_data *ip_data = data->data; return lseek(ip_data->fd, 0, SEEK_CUR); } -static mpc_int32_t get_size_impl(void *data) +static mpc_int32_t get_size_impl(mpc_reader *data) { - struct input_plugin_data *ip_data = data; + struct input_plugin_data *ip_data = data->data; struct mpc_private *priv = ip_data->private; return priv->file_size; } -static mpc_bool_t canseek_impl(void *data) +static mpc_bool_t canseek_impl(mpc_reader *data) { - struct input_plugin_data *ip_data = data; + struct input_plugin_data *ip_data = data->data; return !ip_data->remote; } @@ -108,23 +108,19 @@ priv->reader.canseek = canseek_impl; priv->reader.data = ip_data; - /* must be before mpc_streaminfo_read() */ + /* must be before populating the streaminfo structure */ ip_data->private = priv; - /* read file's streaminfo data */ - mpc_streaminfo_init(&priv->info); - if (mpc_streaminfo_read(&priv->info, &priv->reader) != ERROR_CODE_OK) { - free(priv); - return -IP_ERROR_FILE_FORMAT; - } - /* instantiate a decoder with our file reader */ - mpc_decoder_setup(&priv->decoder, &priv->reader); - if (!mpc_decoder_initialize(&priv->decoder, &priv->info)) { + priv->decoder = mpc_demux_init(&priv->reader); + if (!priv->decoder) { + mpc_demux_exit (priv->decoder); free(priv); return -IP_ERROR_FILE_FORMAT; } + mpc_demux_get_info(priv->decoder, &priv->info); + priv->samples_avail = 0; priv->samples_pos = 0; @@ -137,6 +133,7 @@ { struct mpc_private *priv = ip_data->private; + mpc_demux_exit (priv->decoder); free(priv); ip_data->private = NULL; return 0; @@ -184,23 +181,25 @@ static int mpc_read(struct input_plugin_data *ip_data, char *buffer, int count) { struct mpc_private *priv = ip_data->private; + mpc_status status; + mpc_frame_info frame; + int samples; + + frame.buffer = priv->samples; - if (priv->samples_avail == 0) { - uint32_t status = mpc_decoder_decode(&priv->decoder, priv->samples, NULL, NULL); + while (priv->samples_avail == 0) { + status = mpc_demux_decode(priv->decoder, &frame); - if (status == (uint32_t)(-1)) { - /* right ret val? */ + if (status != MPC_STATUS_OK) { return -IP_ERROR_ERRNO; } - if (status == 0) { + if (frame.bits == -1) { /* EOF */ return 0; } - /* status seems to be number of _frames_ - * the api documentation is wrong - */ - priv->samples_avail = status * priv->info.channels; + samples = frame.samples; + priv->samples_avail = samples * priv->info.channels; } return scale(ip_data, buffer, count); } @@ -212,7 +211,7 @@ priv->samples_pos = 0; priv->samples_avail = 0; - if (mpc_decoder_seek_seconds(&priv->decoder, offset)) + if (mpc_demux_seek_second(priv->decoder, offset) == MPC_STATUS_OK) return 0; return -1; } @@ -281,7 +280,7 @@ /* priv->info.pcm_samples seems to be number of frames * priv->info.frames is _not_ pcm frames */ - return priv->info.pcm_samples / priv->info.sample_freq; + return mpc_streaminfo_get_length(&priv->info); } const struct input_plugin_ops ip_ops = {