summaryrefslogtreecommitdiffstats
path: root/libmpcodecs
diff options
context:
space:
mode:
authorreimar <reimar@b3059339-0415-0410-9bf9-f77b7e298cf2>2005-07-10 17:14:12 +0000
committerreimar <reimar@b3059339-0415-0410-9bf9-f77b7e298cf2>2005-07-10 17:14:12 +0000
commitc54b5a06bd40fba8a37c7053cd7437785e9a7314 (patch)
tree721cc55674c56e735addc44c4b647f2627f4cb1f /libmpcodecs
parentcd19f28b94690a828a0304961e8b5d5721a77ea2 (diff)
downloadmpv-c54b5a06bd40fba8a37c7053cd7437785e9a7314.tar.bz2
mpv-c54b5a06bd40fba8a37c7053cd7437785e9a7314.tar.xz
musepack demuxing and decoding support (demuxing is v7 bitstream only).
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@15959 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libmpcodecs')
-rw-r--r--libmpcodecs/Makefile4
-rw-r--r--libmpcodecs/ad.c4
-rw-r--r--libmpcodecs/ad_mpc.c178
3 files changed, 186 insertions, 0 deletions
diff --git a/libmpcodecs/Makefile b/libmpcodecs/Makefile
index 52cfbc1e80..e2867f312e 100644
--- a/libmpcodecs/Makefile
+++ b/libmpcodecs/Makefile
@@ -187,6 +187,10 @@ ifeq ($(CONFIG_LIBAVCODEC),yes)
ENCODER_SRCS += ae_lavc.c
endif
+ifeq ($(MUSEPACK),yes)
+AUDIO_SRCS += ad_mpc.c
+endif
+
ifeq ($(FAAC),yes)
ENCODER_SRCS += ae_faac.c
endif
diff --git a/libmpcodecs/ad.c b/libmpcodecs/ad.c
index 770c63fa33..c6d0b3291a 100644
--- a/libmpcodecs/ad.c
+++ b/libmpcodecs/ad.c
@@ -39,6 +39,7 @@ extern ad_functions_t mpcodecs_ad_libdv;
extern ad_functions_t mpcodecs_ad_qtaudio;
extern ad_functions_t mpcodecs_ad_ra1428;
extern ad_functions_t mpcodecs_ad_twin;
+extern ad_functions_t mpcodecs_ad_libmusepack;
ad_functions_t* mpcodecs_ad_drivers[] =
{
@@ -87,5 +88,8 @@ ad_functions_t* mpcodecs_ad_drivers[] =
&mpcodecs_ad_libdv,
#endif
&mpcodecs_ad_ra1428,
+#ifdef HAVE_MUSEPACK
+ &mpcodecs_ad_libmusepack,
+#endif
NULL
};
diff --git a/libmpcodecs/ad_mpc.c b/libmpcodecs/ad_mpc.c
new file mode 100644
index 0000000000..1ca98254f0
--- /dev/null
+++ b/libmpcodecs/ad_mpc.c
@@ -0,0 +1,178 @@
+/**
+ * Musepack audio files decoder for MPlayer
+ * by Reza Jelveh <reza.jelveh@tuhh.de> and
+ * Reimar Döffinger <Reimar.Doeffinger@stud.uni-karlsruhe.de>
+ * License: GPL
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "config.h"
+#include "ad_internal.h"
+#include "../libaf/af_format.h"
+#include "../libvo/fastmemcpy.h"
+
+static ad_info_t info =
+{
+ "MPC/MPEGPlus audio decoder",
+ "libmusepack",
+ "Reza Jelveh and Reimar Döffinger",
+ "",
+ ""
+};
+
+LIBAD_EXTERN(libmusepack)
+
+#include <mpcdec/mpcdec.h>
+
+#define MAX_FRAMESIZE MPC_DECODER_BUFFER_LENGTH
+
+typedef struct context_s {
+ char *header;
+ int header_len;
+ sh_audio_t *sh;
+ uint32_t pos;
+ mpc_decoder decoder;
+} context_t;
+
+/**
+ * \brief mpc_reader callback function for reading the header
+ */
+static mpc_int32_t cb_read(void *data, void *buf, mpc_int32_t size) {
+ context_t *d = (context_t *)data;
+ char *p = (char *)buf;
+ int s = size;
+ if (d->pos < d->header_len) {
+ if (s > d->header_len - d->pos)
+ s = d->header_len - d->pos;
+ memcpy(p, &d->header[d->pos], s);
+ } else
+ s = 0;
+ memset(&p[s], 0, size - s);
+ d->pos += size;
+ return size;
+}
+
+/**
+ * \brief dummy mpc_reader callback function for seeking
+ */
+static mpc_bool_t cb_seek(void *data, mpc_int32_t offset ) {
+ context_t *d = (context_t *)data;
+ d->pos = offset;
+ return 1;
+}
+
+/**
+ * \brief dummy mpc_reader callback function for getting stream position
+ */
+static mpc_int32_t cb_tell(void *data) {
+ context_t *d = (context_t *)data;
+ return d->pos;
+}
+
+/**
+ * \brief dummy mpc_reader callback function for getting stream length
+ */
+static mpc_int32_t cb_get_size(void *data) {
+ return 1 << 30;
+}
+
+/**
+ * \brief mpc_reader callback function, we cannot seek.
+ */
+static mpc_bool_t cb_canseek(void *data) {
+ return 0;
+}
+
+
+mpc_reader header_reader = {
+ .read = cb_read, .seek = cb_seek, .tell = cb_tell,
+ .get_size = cb_get_size, .canseek = cb_canseek
+};
+
+static int preinit(sh_audio_t *sh) {
+// sh->audio_out_minsize = 2 * MPC_DECODER_BUFFER_LENGTH;
+ return 1;
+}
+
+static void uninit(sh_audio_t *sh) {
+ if (sh->context)
+ free(sh->context);
+}
+
+static int init(sh_audio_t *sh) {
+ mpc_streaminfo info;
+ context_t *cd = malloc(sizeof(context_t));
+
+ if (!sh->wf || (sh->wf->cbSize < 6 * 4)) {
+ mp_msg(MSGT_DECAUDIO, MSGL_FATAL, "Missing extradata!\n");
+ return 0;
+ }
+ cd->header = (char *)sh->wf;
+ cd->header = &cd->header[sizeof(WAVEFORMATEX)];
+ cd->header_len = sh->wf->cbSize;
+ cd->sh = sh;
+ cd->pos = 0;
+ sh->context = (char *)cd;
+
+ /* read file's streaminfo data */
+ mpc_streaminfo_init(&info);
+ header_reader.data = cd;
+ if (mpc_streaminfo_read(&info, &header_reader) != ERROR_CODE_OK) {
+ mp_msg(MSGT_DECAUDIO, MSGL_FATAL, "Not a valid musepack file.\n");
+ return 0;
+ }
+ sh->i_bps = info.average_bitrate / 8;
+ sh->channels = info.channels;
+ sh->samplerate = info.sample_freq;
+ sh->samplesize = 4;
+ sh->sample_format =
+#if MPC_SAMPLE_FORMAT == float
+ AF_FORMAT_FLOAT_NE;
+#elif MPC_SAMPLE_FORMAT == mpc_int32_t
+ AF_FORMAT_S32_NE;
+#else
+ #error musepack lib must use either float or mpc_int32_t sample format
+#endif
+
+ mpc_decoder_setup(&cd->decoder, NULL);
+ mpc_decoder_set_streaminfo(&cd->decoder, &info);
+ return 1;
+}
+
+// FIXME: minlen is currently ignored
+static int decode_audio(sh_audio_t *sh, unsigned char *buf,
+ int minlen, int maxlen) {
+ int status, len;
+ MPC_SAMPLE_FORMAT *sample_buffer = (MPC_SAMPLE_FORMAT *)buf;
+ mpc_uint32_t *packet = NULL;
+
+ context_t *cd = (context_t *) sh->context;
+ if (maxlen < MPC_DECODER_BUFFER_LENGTH) {
+ mp_msg(MSGT_DECAUDIO, MSGL_ERR, "maxlen too small in decode_audio\n");
+ return -1;
+ }
+ len = ds_get_packet(sh->ds, (unsigned char **)&packet);
+ if (len <= 0) return -1;
+ status = mpc_decoder_decode_frame(&cd->decoder, packet, len, sample_buffer);
+ if (status == -1) // decode error
+ mp_msg(MSGT_DECAUDIO, MSGL_FATAL, "Error decoding file.\n");
+ if (status <= 0) // error or EOF
+ return -1;
+
+ status = MPC_FRAME_LENGTH * sh->channels; // one sample per channel
+#if MPC_SAMPLE_FORMAT == float || MPC_SAMPLE_FORMAT == mpc_int32_t
+ status *= 4;
+#else
+ // should not happen
+ status *= 2;
+#endif
+ return status;
+}
+
+static int control(sh_audio_t *sh, int cmd, void* arg, ...) {
+ return CONTROL_UNKNOWN;
+}
+