aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2008-09-01 16:24:41 -0700
committerEric Wong <normalperson@yhbt.net>2008-09-01 16:24:41 -0700
commitc36029fc806cf083de3aaf1344d6bd2be8db316f (patch)
treeda88b1f073b8125d764b94b924492d2b05ea4c69
parentaa0755f53545fcf343f791f04760f6b934e022e4 (diff)
parent6982a829e22d2bc7cf7c829c4430a4ea6f5bc7fa (diff)
downloadmpd-c36029fc806cf083de3aaf1344d6bd2be8db316f.tar.gz
mpd-c36029fc806cf083de3aaf1344d6bd2be8db316f.tar.xz
mpd-c36029fc806cf083de3aaf1344d6bd2be8db316f.zip
Merge branch 'mk/cleanups'
* mk/cleanups: (60 commits) pass constant pointers const pointers unsigned integers and size_t oggflac: fix GCC warnings include cleanup protect locate.h from double inclusion playlist: eliminate unused fd parameters jack: made "sample_size" static const moved jack configuration to the JackData struct jack: removed unused macros jack: don't set audioOutput->data=NULL jack: initialize JackData in jack_initDriver() jack: added freeJackClient() jack: initialize jd->client after !jd check jack: eliminate superfluous freeJackData() calls mp3: converted the MUTEFRAME_ macros to an enum mp3: converted the DECODE_ constants to an enum wavpack: don't use "isp" before initialization wavpack: moved code to wavpack_open_wvc() simplified code in the ogg decoder plugin ...
-rw-r--r--configure.ac3
-rw-r--r--m4/mpd_check_cflag.m42
-rw-r--r--src/audio.c2
-rw-r--r--src/audio.h15
-rw-r--r--src/audioOutput.c3
-rw-r--r--src/audioOutput.h6
-rw-r--r--src/audioOutputs/audioOutput_ao.c2
-rw-r--r--src/audioOutputs/audioOutput_jack.c185
-rw-r--r--src/audioOutputs/audioOutput_null.c5
-rw-r--r--src/audioOutputs/audioOutput_oss.c3
-rw-r--r--src/audioOutputs/audioOutput_shout.c2
-rw-r--r--src/audio_format.h40
-rw-r--r--src/command.c212
-rw-r--r--src/dbUtils.c24
-rw-r--r--src/decode.h2
-rw-r--r--src/directory.c1
-rw-r--r--src/inputPlugin.h1
-rw-r--r--src/inputPlugins/_flac_common.c8
-rw-r--r--src/inputPlugins/_flac_common.h4
-rw-r--r--src/inputPlugins/_ogg_common.c1
-rw-r--r--src/inputPlugins/aac_plugin.c359
-rw-r--r--src/inputPlugins/audiofile_plugin.c57
-rw-r--r--src/inputPlugins/flac_plugin.c20
-rw-r--r--src/inputPlugins/mod_plugin.c3
-rw-r--r--src/inputPlugins/mp3_plugin.c212
-rw-r--r--src/inputPlugins/mp4_plugin.c21
-rw-r--r--src/inputPlugins/mpc_plugin.c6
-rw-r--r--src/inputPlugins/oggflac_plugin.c29
-rw-r--r--src/inputPlugins/oggvorbis_plugin.c63
-rw-r--r--src/inputPlugins/wavpack_plugin.c144
-rw-r--r--src/inputStream_file.c2
-rw-r--r--src/inputStream_http.c11
-rw-r--r--src/interface.c10
-rw-r--r--src/interface.h4
-rw-r--r--src/locate.c4
-rw-r--r--src/locate.h5
-rw-r--r--src/ls.c6
-rw-r--r--src/ls.h4
-rw-r--r--src/main.c5
-rw-r--r--src/normalize.h2
-rw-r--r--src/outputBuffer.c25
-rw-r--r--src/outputBuffer.h1
-rw-r--r--src/outputBuffer_ob_send.h6
-rw-r--r--src/outputBuffer_xfade.h10
-rw-r--r--src/pcm_utils.c6
-rw-r--r--src/pcm_utils.h2
-rw-r--r--src/playlist.c42
-rw-r--r--src/playlist.h10
-rw-r--r--src/replayGain.h2
-rw-r--r--src/ringbuf.c44
-rw-r--r--src/ringbuf.h20
-rw-r--r--src/sig_handlers.c3
-rw-r--r--src/sllist.c8
-rw-r--r--src/sllist.h4
-rw-r--r--src/song.c3
-rw-r--r--src/tag.c11
-rw-r--r--src/tag.h35
-rw-r--r--src/tagTracker.c2
-rw-r--r--src/tagTracker.h2
-rw-r--r--src/timer.h4
-rw-r--r--src/tree.c20
-rw-r--r--src/tree.h3
-rw-r--r--src/utf8.c12
-rw-r--r--src/volume.c2
-rw-r--r--src/zeroconf.c9
65 files changed, 996 insertions, 778 deletions
diff --git a/configure.ac b/configure.ac
index 6067bc480..5630fe650 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,11 +26,12 @@ if test x$GCC = xyes
then
MPD_CHECK_FLAG([-Wall])
MPD_CHECK_FLAG([-Wextra])
- MPD_CHECK_FLAG([-Wno-unused-parameter])
MPD_CHECK_FLAG([-Wno-deprecated-declarations])
MPD_CHECK_FLAG([-Wmissing-prototypes])
MPD_CHECK_FLAG([-Wdeclaration-after-statement])
MPD_CHECK_FLAG([-Wshadow])
+ MPD_CHECK_FLAG([-Wpointer-arith])
+ MPD_CHECK_FLAG([-Wstrict-prototypes])
fi
if test -z "$prefix" || test "x$prefix" = xNONE; then
diff --git a/m4/mpd_check_cflag.m4 b/m4/mpd_check_cflag.m4
index 05682f611..421123355 100644
--- a/m4/mpd_check_cflag.m4
+++ b/m4/mpd_check_cflag.m4
@@ -1,5 +1,5 @@
AC_DEFUN([MPD_CHECK_FLAG],[
- var=`echo "$1" | tr "-" "_"`
+ var=`echo "$1" | tr "=-" "__"`
AC_CACHE_CHECK([whether the C compiler accepts $1],
[mpd_check_cflag_$var],[
save_CFLAGS="$CFLAGS"
diff --git a/src/audio.c b/src/audio.c
index 34b74e6e1..409761177 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -419,7 +419,7 @@ void closeAudioDevice(void)
audioOpened = 0;
}
-void sendMetadataToAudioDevice(MpdTag * tag)
+void sendMetadataToAudioDevice(const MpdTag * tag)
{
unsigned int i;
diff --git a/src/audio.h b/src/audio.h
index eab83916a..0032cff22 100644
--- a/src/audio.h
+++ b/src/audio.h
@@ -19,23 +19,12 @@
#ifndef AUDIO_H
#define AUDIO_H
-#include "mpd_types.h"
#include "tag.h"
#include "os_compat.h"
+#include "audio_format.h"
#define AUDIO_AO_DRIVER_DEFAULT "default"
-typedef struct _AudioFormat {
- volatile mpd_sint8 channels;
- volatile mpd_uint32 sampleRate;
- volatile mpd_sint8 bits;
-} AudioFormat;
-
-static inline double audioFormatSizeToTime(const AudioFormat * af)
-{
- return 8.0 / af->bits / af->channels / af->sampleRate;
-}
-
void copyAudioFormat(AudioFormat * dest, const AudioFormat * src);
int cmpAudioFormat(const AudioFormat * dest, const AudioFormat * src);
@@ -66,7 +55,7 @@ int isAudioDeviceOpen(void);
int isCurrentAudioFormat(const AudioFormat * audioFormat);
-void sendMetadataToAudioDevice(MpdTag * tag);
+void sendMetadataToAudioDevice(const MpdTag * tag);
/* these functions are called in the main parent process while the child
process is busy playing to the audio */
diff --git a/src/audioOutput.c b/src/audioOutput.c
index ff5efabc9..f165979d0 100644
--- a/src/audioOutput.c
+++ b/src/audioOutput.c
@@ -22,6 +22,7 @@
#include "log.h"
#include "pcm_utils.h"
#include "os_compat.h"
+#include "audio.h"
#define AUDIO_OUTPUT_TYPE "type"
#define AUDIO_OUTPUT_NAME "name"
@@ -243,7 +244,7 @@ void finishAudioOutput(AudioOutput * audioOutput)
free(audioOutput->convBuffer);
}
-void sendMetadataToAudioOutput(AudioOutput * audioOutput, MpdTag * tag)
+void sendMetadataToAudioOutput(AudioOutput * audioOutput, const MpdTag * tag)
{
if (!audioOutput->sendMetdataFunc)
return;
diff --git a/src/audioOutput.h b/src/audioOutput.h
index 7574f5ae1..f82eedfba 100644
--- a/src/audioOutput.h
+++ b/src/audioOutput.h
@@ -23,7 +23,7 @@
#include "pcm_utils.h"
#include "mpd_types.h"
-#include "audio.h"
+#include "audio_format.h"
#include "tag.h"
#include "conf.h"
#include "utils.h"
@@ -50,7 +50,7 @@ typedef void (*AudioOutputDropBufferedAudioFunc) (AudioOutput * audioOutput);
typedef void (*AudioOutputCloseDeviceFunc) (AudioOutput * audioOutput);
typedef void (*AudioOutputSendMetadataFunc) (AudioOutput * audioOutput,
- MpdTag * tag);
+ const MpdTag * tag);
struct _AudioOutput {
int open;
@@ -104,7 +104,7 @@ void dropBufferedAudioOutput(AudioOutput * audioOutput);
void closeAudioOutput(AudioOutput * audioOutput);
void finishAudioOutput(AudioOutput * audioOutput);
int keepAudioOutputAlive(AudioOutput * audioOutput, int ms);
-void sendMetadataToAudioOutput(AudioOutput * audioOutput, MpdTag * tag);
+void sendMetadataToAudioOutput(AudioOutput * audioOutput, const MpdTag * tag);
void printAllOutputPluginTypes(FILE * fp);
diff --git a/src/audioOutputs/audioOutput_ao.c b/src/audioOutputs/audioOutput_ao.c
index 65ffa2c27..e7e201add 100644
--- a/src/audioOutputs/audioOutput_ao.c
+++ b/src/audioOutputs/audioOutput_ao.c
@@ -158,7 +158,7 @@ static void audioOutputAo_finishDriver(AudioOutput * audioOutput)
ao_shutdown();
}
-static void audioOutputAo_dropBufferedAudio(AudioOutput * audioOutput)
+static void audioOutputAo_dropBufferedAudio(mpd_unused AudioOutput * audioOutput)
{
/* not supported by libao */
}
diff --git a/src/audioOutputs/audioOutput_jack.c b/src/audioOutputs/audioOutput_jack.c
index ed0bceb46..8818bb739 100644
--- a/src/audioOutputs/audioOutput_jack.c
+++ b/src/audioOutputs/audioOutput_jack.c
@@ -27,25 +27,19 @@
#include <jack/types.h>
#include <jack/ringbuffer.h>
-pthread_mutex_t play_audio_lock = PTHREAD_MUTEX_INITIALIZER;
-pthread_cond_t play_audio = PTHREAD_COND_INITIALIZER;
-
-/*#include "dmalloc.h"*/
-
-#ifdef MIN
-# undef MIN
-# define MIN(a, b) ((a) < (b) ? (a) : (b))
-#endif
-
-/*#define SAMPLE_SIZE sizeof(jack_default_audio_sample_t);*/
+static const size_t sample_size = sizeof(jack_default_audio_sample_t);
+typedef struct _JackData {
+ /* configuration */
+ char *name;
+ char *output_ports[2];
+ int ringbuf_sz;
-static char *name = "mpd";
-static char *output_ports[2];
-static int ringbuf_sz = 32768;
-size_t sample_size = sizeof(jack_default_audio_sample_t);
+ /* locks */
+ pthread_mutex_t play_audio_lock;
+ pthread_cond_t play_audio;
-typedef struct _JackData {
+ /* jack library stuff */
jack_port_t *ports[2];
jack_client_t *client;
jack_ringbuffer_t *ringbuffer[2];
@@ -60,49 +54,67 @@ static JackData *newJackData(void)
JackData *ret;
ret = xcalloc(sizeof(JackData), 1);
+ ret->name = "mpd";
+ ret->ringbuf_sz = 32768;
+
+ pthread_mutex_init(&ret->play_audio_lock, NULL);
+ pthread_cond_init(&ret->play_audio, NULL);
+
return ret;
}
-static void freeJackData(AudioOutput *audioOutput)
+static void freeJackClient(JackData *jd)
{
- JackData *jd = audioOutput->data;
- if (jd) {
- if (jd->ringbuffer[0])
- jack_ringbuffer_free(jd->ringbuffer[0]);
- if (jd->ringbuffer[1])
- jack_ringbuffer_free(jd->ringbuffer[1]);
- free(jd);
- audioOutput->data = NULL;
+ assert(jd != NULL);
+
+ if (jd->client != NULL) {
+ jack_deactivate(jd->client);
+ jack_client_close(jd->client);
+ jd->client = NULL;
+ }
+
+ if (jd->ringbuffer[0] != NULL) {
+ jack_ringbuffer_free(jd->ringbuffer[0]);
+ jd->ringbuffer[0] = NULL;
+ }
+
+ if (jd->ringbuffer[1] != NULL) {
+ jack_ringbuffer_free(jd->ringbuffer[1]);
+ jd->ringbuffer[1] = NULL;
}
+
+ pthread_mutex_destroy(&jd->play_audio_lock);
+ pthread_cond_destroy(&jd->play_audio);
}
-static void jack_finishDriver(AudioOutput *audioOutput)
+static void freeJackData(AudioOutput *audioOutput)
{
JackData *jd = audioOutput->data;
int i;
- if ( jd && jd->client ) {
- jack_deactivate(jd->client);
- jack_client_close(jd->client);
- }
- DEBUG("disconnect_jack (pid=%d)\n", getpid ());
+ assert(jd != NULL);
+
+ freeJackClient(jd);
- if ( strcmp(name, "mpd") ) {
- free(name);
- name = "mpd";
- }
+ if (strcmp(jd->name, "mpd") != 0)
+ free(jd->name);
- for ( i = ARRAY_SIZE(output_ports); --i >= 0; ) {
- if (!output_ports[i])
- continue;
- free(output_ports[i]);
- output_ports[i] = NULL;
- }
+ for ( i = ARRAY_SIZE(jd->output_ports); --i >= 0; ) {
+ if (!jd->output_ports[i])
+ continue;
+ free(jd->output_ports[i]);
+ }
+ free(jd);
+}
+
+static void jack_finishDriver(AudioOutput *audioOutput)
+{
freeJackData(audioOutput);
+ DEBUG("disconnect_jack (pid=%d)\n", getpid ());
}
-static int srate(jack_nframes_t rate, void *data)
+static int srate(mpd_unused jack_nframes_t rate, void *data)
{
JackData *jd = (JackData *) ((AudioOutput*) data)->data;
AudioFormat *audioFormat = &(((AudioOutput*) data)->outAudioFormat);
@@ -150,9 +162,9 @@ static int process(jack_nframes_t nframes, void *arg)
nframes = 0;
}
- if (pthread_mutex_trylock (&play_audio_lock) == 0) {
- pthread_cond_signal (&play_audio);
- pthread_mutex_unlock (&play_audio_lock);
+ if (pthread_mutex_trylock (&jd->play_audio_lock) == 0) {
+ pthread_cond_signal (&jd->play_audio);
+ pthread_mutex_unlock (&jd->play_audio_lock);
}
}
@@ -188,12 +200,14 @@ static void error_callback(const char *msg)
static int jack_initDriver(AudioOutput *audioOutput, ConfigParam *param)
{
+ JackData *jd;
BlockParam *bp;
char *endptr;
int val;
char *cp = NULL;
- audioOutput->data = NULL;
+ audioOutput->data = newJackData();
+ jd = audioOutput->data;
DEBUG("jack_initDriver (pid=%d)\n", getpid());
if ( ! param ) return 0;
@@ -207,18 +221,19 @@ static int jack_initDriver(AudioOutput *audioOutput, ConfigParam *param)
bp->name, bp->line, bp->value);
*cp = '\0';
- output_ports[0] = xstrdup(bp->value);
+ jd->output_ports[0] = xstrdup(bp->value);
*cp++ = ',';
if (!*cp)
FATAL("expected a second value for '%s' at line %d: "
"%s\n", bp->name, bp->line, bp->value);
- output_ports[1] = xstrdup(cp);
+ jd->output_ports[1] = xstrdup(cp);
if (strchr(cp,','))
FATAL("Only %d values are supported for '%s' "
- "at line %d\n", (int)ARRAY_SIZE(output_ports),
+ "at line %d\n",
+ (int)ARRAY_SIZE(jd->output_ports),
bp->name, bp->line);
}
@@ -227,18 +242,18 @@ static int jack_initDriver(AudioOutput *audioOutput, ConfigParam *param)
val = strtol(bp->value, &endptr, 10);
if ( errno == 0 && endptr != bp->value) {
- ringbuf_sz = val < 32768 ? 32768 : val;
- DEBUG("ringbuffer_size=%d\n", ringbuf_sz);
+ jd->ringbuf_sz = val < 32768 ? 32768 : val;
+ DEBUG("ringbuffer_size=%d\n", jd->ringbuf_sz);
} else {
FATAL("%s is not a number; ringbuf_size=%d\n",
- bp->value, ringbuf_sz);
+ bp->value, jd->ringbuf_sz);
}
}
if ( (bp = getBlockParam(param, "name"))
&& (strcmp(bp->value, "mpd") != 0) ) {
- name = xstrdup(bp->value);
- DEBUG("name=%s\n", name);
+ jd->name = xstrdup(bp->value);
+ DEBUG("name=%s\n", jd->name);
}
return 0;
@@ -255,9 +270,8 @@ static int connect_jack(AudioOutput *audioOutput)
char **jports;
char *port_name;
- if ( (jd->client = jack_client_new(name)) == NULL ) {
+ if ( (jd->client = jack_client_new(jd->name)) == NULL ) {
ERROR("jack server not running?\n");
- freeJackData(audioOutput);
return -1;
}
@@ -269,7 +283,6 @@ static int connect_jack(AudioOutput *audioOutput)
if ( jack_activate(jd->client) ) {
ERROR("cannot activate client\n");
- freeJackData(audioOutput);
return -1;
}
@@ -278,7 +291,6 @@ static int connect_jack(AudioOutput *audioOutput)
JackPortIsOutput, 0);
if ( !jd->ports[0] ) {
ERROR("Cannot register left output port.\n");
- freeJackData(audioOutput);
return -1;
}
@@ -287,44 +299,42 @@ static int connect_jack(AudioOutput *audioOutput)
JackPortIsOutput, 0);
if ( !jd->ports[1] ) {
ERROR("Cannot register right output port.\n");
- freeJackData(audioOutput);
return -1;
}
/* hay que buscar que hay */
- if ( !output_ports[1]
+ if ( !jd->output_ports[1]
&& (jports = (char **)jack_get_ports(jd->client, NULL, NULL,
JackPortIsPhysical|
JackPortIsInput)) ) {
- output_ports[0] = jports[0];
- output_ports[1] = jports[1] ? jports[1] : jports[0];
- DEBUG("output_ports: %s %s\n", output_ports[0], output_ports[1]);
+ jd->output_ports[0] = jports[0];
+ jd->output_ports[1] = jports[1] ? jports[1] : jports[0];
+ DEBUG("output_ports: %s %s\n",
+ jd->output_ports[0], jd->output_ports[1]);
free(jports);
}
- if ( output_ports[1] ) {
- jd->ringbuffer[0] = jack_ringbuffer_create(ringbuf_sz);
- jd->ringbuffer[1] = jack_ringbuffer_create(ringbuf_sz);
+ if ( jd->output_ports[1] ) {
+ jd->ringbuffer[0] = jack_ringbuffer_create(jd->ringbuf_sz);
+ jd->ringbuffer[1] = jack_ringbuffer_create(jd->ringbuf_sz);
memset(jd->ringbuffer[0]->buf, 0, jd->ringbuffer[0]->size);
memset(jd->ringbuffer[1]->buf, 0, jd->ringbuffer[1]->size);
- port_name = xmalloc(sizeof(char)*(7+strlen(name)));
+ port_name = xmalloc(sizeof(char)*(7+strlen(jd->name)));
- sprintf(port_name, "%s:left", name);
+ sprintf(port_name, "%s:left", jd->name);
if ( (jack_connect(jd->client, port_name,
- output_ports[0])) != 0 ) {
+ jd->output_ports[0])) != 0 ) {
ERROR("%s is not a valid Jack Client / Port\n",
- output_ports[0]);
- freeJackData(audioOutput);
+ jd->output_ports[0]);
free(port_name);
return -1;
}
- sprintf(port_name, "%s:right", name);
+ sprintf(port_name, "%s:right", jd->name);
if ( (jack_connect(jd->client, port_name,
- output_ports[1])) != 0 ) {
+ jd->output_ports[1])) != 0 ) {
ERROR("%s is not a valid Jack Client / Port\n",
- output_ports[1]);
- freeJackData(audioOutput);
+ jd->output_ports[1]);
free(port_name);
return -1;
}
@@ -339,16 +349,12 @@ static int jack_openDevice(AudioOutput *audioOutput)
{
JackData *jd = audioOutput->data;
- if ( !jd ) {
- DEBUG("connect!\n");
- jd = newJackData();
- audioOutput->data = jd;
+ assert(jd != NULL);
- if (connect_jack(audioOutput) < 0) {
- freeJackData(audioOutput);
- audioOutput->open = 0;
- return -1;
- }
+ if (jd->client == NULL && connect_jack(audioOutput) < 0) {
+ freeJackClient(jd);
+ audioOutput->open = 0;
+ return -1;
}
set_audioformat(audioOutput);
@@ -366,7 +372,7 @@ static void jack_closeDevice(AudioOutput * audioOutput)
DEBUG("jack_closeDevice (pid=%d)\n", getpid());
}
-static void jack_dropBufferedAudio (AudioOutput * audioOutput)
+static void jack_dropBufferedAudio (mpd_unused AudioOutput * audioOutput)
{
}
@@ -384,7 +390,7 @@ static int jack_playAudio(AudioOutput * audioOutput,
if ( jd->shutdown ) {
ERROR("Refusing to play, because there is no client thread.\n");
- freeJackData(audioOutput);
+ freeJackClient(jd);
audioOutput->open = 0;
return 0;
}
@@ -414,9 +420,10 @@ static int jack_playAudio(AudioOutput * audioOutput,
samples=0;
} else {
- pthread_mutex_lock(&play_audio_lock);
- pthread_cond_wait(&play_audio, &play_audio_lock);
- pthread_mutex_unlock(&play_audio_lock);
+ pthread_mutex_lock(&jd->play_audio_lock);
+ pthread_cond_wait(&jd->play_audio,
+ &jd->play_audio_lock);
+ pthread_mutex_unlock(&jd->play_audio_lock);
}
}
diff --git a/src/audioOutputs/audioOutput_null.c b/src/audioOutputs/audioOutput_null.c
index 37ff7194a..d63004645 100644
--- a/src/audioOutputs/audioOutput_null.c
+++ b/src/audioOutputs/audioOutput_null.c
@@ -19,7 +19,8 @@
#include "../audioOutput.h"
#include "../timer.h"
-static int null_initDriver(AudioOutput *audioOutput, ConfigParam *param)
+static int null_initDriver(AudioOutput *audioOutput,
+ mpd_unused ConfigParam *param)
{
audioOutput->data = NULL;
return 0;
@@ -43,7 +44,7 @@ static void null_closeDevice(AudioOutput *audioOutput)
}
static int null_playAudio(AudioOutput *audioOutput,
- const char *playChunk, size_t size)
+ mpd_unused const char *playChunk, size_t size)
{
Timer *timer = audioOutput->data;
diff --git a/src/audioOutputs/audioOutput_oss.c b/src/audioOutputs/audioOutput_oss.c
index 2a6a4876b..2df7d5728 100644
--- a/src/audioOutputs/audioOutput_oss.c
+++ b/src/audioOutputs/audioOutput_oss.c
@@ -334,7 +334,8 @@ static int oss_testDefault(void)
return -1;
}
-static int oss_open_default(AudioOutput *ao, ConfigParam *param, OssData *od)
+static int oss_open_default(mpd_unused AudioOutput *ao, ConfigParam *param,
+ OssData *od)
{
int i;
int err[ARRAY_SIZE(default_devices)];
diff --git a/src/audioOutputs/audioOutput_shout.c b/src/audioOutputs/audioOutput_shout.c
index 9ed5b4e7e..49d69eebd 100644
--- a/src/audioOutputs/audioOutput_shout.c
+++ b/src/audioOutputs/audioOutput_shout.c
@@ -413,6 +413,8 @@ static void copyTagToVorbisComment(ShoutData * sd)
case TAG_ITEM_TITLE:
addTag(sd, "TITLE", sd->tag->items[i].value);
break;
+ default:
+ break;
}
}
}
diff --git a/src/audio_format.h b/src/audio_format.h
new file mode 100644
index 000000000..a6e97e046
--- /dev/null
+++ b/src/audio_format.h
@@ -0,0 +1,40 @@
+/* the Music Player Daemon (MPD)
+ * Copyright (C) 2003-2007 by Warren Dukes (warren.dukes@gmail.com)
+ * This project's homepage is: http://www.musicpd.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef AUDIO_FORMAT_H
+#define AUDIO_FORMAT_H
+
+#include "mpd_types.h"
+
+typedef struct _AudioFormat {
+ volatile mpd_sint8 channels;
+ volatile mpd_uint32 sampleRate;
+ volatile mpd_sint8 bits;
+} AudioFormat;
+
+static inline double audio_format_time_to_size(const AudioFormat * af)
+{
+ return af->sampleRate * af->bits * af->channels / 8.0;
+}
+
+static inline double audioFormatSizeToTime(const AudioFormat * af)
+{
+ return 8.0 / af->bits / af->channels / af->sampleRate;
+}
+
+#endif
diff --git a/src/command.c b/src/command.c
index a8c49e8c9..805addde1 100644
--- a/src/command.c
+++ b/src/command.c
@@ -31,6 +31,8 @@
#include "storedPlaylist.h"
#include "sllist.h"
#include "ack.h"
+#include "audio.h"
+#include "dbUtils.h"
#include "os_compat.h"
#include "player_error.h"
#include "outputBuffer.h"
@@ -234,18 +236,21 @@ static void addCommand(const char *name,
insertInList(commandList, cmd->cmd, cmd);
}
-static int handleUrlHandlers(int fd, int *permission, int argc, char *argv[])
+static int handleUrlHandlers(int fd, mpd_unused int *permission,
+ mpd_unused int argc, mpd_unused char *argv[])
{
return printRemoteUrlHandlers(fd);
}
-static int handleTagTypes(int fd, int *permission, int argc, char *argv[])
+static int handleTagTypes(int fd, mpd_unused int *permission,
+ mpd_unused int argc, mpd_unused char *argv[])
{
printTagTypes(fd);
return 0;
}
-static int handlePlay(int fd, int *permission, int argc, char *argv[])
+static int handlePlay(int fd, mpd_unused int *permission,
+ int argc, char *argv[])
{
int song = -1;
@@ -254,7 +259,8 @@ static int handlePlay(int fd, int *permission, int argc, char *argv[])
return playPlaylist(fd, song, 0);
}
-static int handlePlayId(int fd, int *permission, int argc, char *argv[])
+static int handlePlayId(int fd, mpd_unused int *permission,
+ int argc, char *argv[])
{
int id = -1;
@@ -264,12 +270,15 @@ static int handlePlayId(int fd, int *permission, int argc, char *argv[])
return playPlaylistById(fd, id, 0);
}
-static int handleStop(int fd, int *permission, int argc, char *argv[])
+static int handleStop(mpd_unused int fd, mpd_unused int *permission,
+ mpd_unused int argc, mpd_unused char *argv[])
{
- return stopPlaylist(fd);
+ stopPlaylist();
+ return 0;
}
-static int handleCurrentSong(int fd, int *permission, int argc, char *argv[])
+static int handleCurrentSong(int fd, mpd_unused int *permission,
+ mpd_unused int argc, mpd_unused char *argv[])
{
int song = getPlaylistCurrentSong();
@@ -279,7 +288,8 @@ static int handleCurrentSong(int fd, int *permission, int argc, char *argv[])
return 0;
}
-static int handlePause(int fd, int *permission, int argc, char *argv[])
+static int handlePause(int fd, mpd_unused int *permission,
+ int argc, char *argv[])
{
enum ob_action action = OB_ACTION_PAUSE_FLIP;
if (argc == 2) {
@@ -292,7 +302,8 @@ static int handlePause(int fd, int *permission, int argc, char *argv[])
return 0;
}
-static int commandStatus(int fd, int *permission, int argc, char *argv[])
+static int commandStatus(mpd_unused int fd, mpd_unused int *permission,
+ mpd_unused int argc, mpd_unused char *argv[])
{
const char *state = NULL;
int updateJobId;
@@ -355,17 +366,20 @@ static int commandStatus(int fd, int *permission, int argc, char *argv[])
return 0;
}
-static int handleKill(int fd, int *permission, int argc, char *argv[])
+static int handleKill(mpd_unused int fd, mpd_unused int *permission,
+ mpd_unused int argc, mpd_unused char *argv[])
{
return COMMAND_RETURN_KILL;
}
-static int handleClose(int fd, int *permission, int argc, char *argv[])
+static int handleClose(mpd_unused int fd, mpd_unused int *permission,
+ mpd_unused int argc, mpd_unused char *argv[])
{
return COMMAND_RETURN_CLOSE;
}
-static int handleAdd(int fd, int *permission, int argc, char *argv[])
+static int handleAdd(int fd, mpd_unused int *permission,
+ mpd_unused int argc, char *argv[])
{
char *path = argv[1];
@@ -375,7 +389,8 @@ static int handleAdd(int fd, int *permission, int argc, char *argv[])
return addAllIn(fd, path);
}
-static int handleAddId(int fd, int *permission, int argc, char *argv[])
+static int handleAddId(int fd, mpd_unused int *permission,
+ int argc, char *argv[])
{
int added_id;
int ret = addToPlaylist(fd, argv[1], &added_id);
@@ -397,7 +412,8 @@ static int handleAddId(int fd, int *permission, int argc, char *argv[])
return ret;
}
-static int handleDelete(int fd, int *permission, int argc, char *argv[])
+static int handleDelete(int fd, mpd_unused int *permission,
+ mpd_unused int argc, char *argv[])
{
int song;
@@ -406,7 +422,8 @@ static int handleDelete(int fd, int *permission, int argc, char *argv[])
return deleteFromPlaylist(fd, song);
}
-static int handleDeleteId(int fd, int *permission, int argc, char *argv[])
+static int handleDeleteId(int fd, mpd_unused int *permission,
+ mpd_unused int argc, char *argv[])
{
int id;
@@ -415,43 +432,51 @@ static int handleDeleteId(int fd, int *permission, int argc, char *argv[])
return deleteFromPlaylistById(fd, id);
}
-static int handlePlaylist(int fd, int *permission, int argc, char *argv[])
+static int handlePlaylist(int fd, mpd_unused int *permission,
+ mpd_unused int argc, mpd_unused char *argv[])
{
return showPlaylist(fd);
}
-static int handleShuffle(int fd, int *permission, int argc, char *argv[])
+static int handleShuffle(int fd, mpd_unused int *permission,
+ mpd_unused int argc, mpd_unused char *argv[])
{
return shufflePlaylist(fd);
}
-static int handleClear(int fd, int *permission, int argc, char *argv[])
+static int handleClear(mpd_unused int fd, mpd_unused int *permission,
+ mpd_unused int argc, mpd_unused char *argv[])
{
- return clearPlaylist(fd);
+ clearPlaylist();
+ return 0;
}
-static int handleSave(int fd, int *permission, int argc, char *argv[])
+static int handleSave(int fd, mpd_unused int *permission,
+ mpd_unused int argc, char *argv[])
{
return savePlaylist(fd, argv[1]);
}
-static int handleLoad(int fd, int *permission, int argc, char *argv[])
+static int handleLoad(int fd, mpd_unused int *permission,
+ mpd_unused int argc, char *argv[])
{
return loadPlaylist(fd, argv[1]);
}
-static int handleListPlaylist(int fd, int *permission, int argc, char *argv[])
+static int handleListPlaylist(int fd, mpd_unused int *permission,
+ mpd_unused int argc, char *argv[])
{
return PlaylistInfo(fd, argv[1], 0);
}
-static int handleListPlaylistInfo(int fd, int *permission,
- int argc, char *argv[])
+static int handleListPlaylistInfo(int fd, mpd_unused int *permission,
+ mpd_unused int argc, char *argv[])
{
return PlaylistInfo(fd, argv[1], 1);
}
-static int handleLsInfo(int fd, int *permission, int argc, char *argv[])
+static int handleLsInfo(int fd, mpd_unused int *permission,
+ int argc, char *argv[])
{
const char *path = "";
@@ -467,18 +492,20 @@ static int handleLsInfo(int fd, int *permission, int argc, char *argv[])
return 0;
}
-static int handleRm(int fd, int *permission, int argc, char *argv[])
+static int handleRm(int fd, mpd_unused int *permission,
+ mpd_unused int argc, char *argv[])
{
return deletePlaylist(fd, argv[1]);
}
-static int handleRename(int fd, int *permission, int argc, char *argv[])
+static int handleRename(int fd, mpd_unused int *permission,
+ mpd_unused int argc, char *argv[])
{
return renameStoredPlaylist(fd, argv[1], argv[2]);
}
-static int handlePlaylistChanges(int fd, int *permission,
- int argc, char *argv[])
+static int handlePlaylistChanges(int fd, mpd_unused int *permission,
+ mpd_unused int argc, char *argv[])
{
mpd_uint32 version;
@@ -487,8 +514,8 @@ static int handlePlaylistChanges(int fd, int *permission,
return playlistChanges(fd, version);
}
-static int handlePlaylistChangesPosId(int fd, int *permission,
- int argc, char *argv[])
+static int handlePlaylistChangesPosId(int fd, mpd_unused int *permission,
+ mpd_unused int argc, char *argv[])
{
mpd_uint32 version;
@@ -497,7 +524,8 @@ static int handlePlaylistChangesPosId(int fd, int *permission,
return playlistChangesPosId(fd, version);
}
-static int handlePlaylistInfo(int fd, int *permission, int argc, char *argv[])
+static int handlePlaylistInfo(int fd, mpd_unused int *permission,
+ int argc, char *argv[])
{
int song = -1;
@@ -506,7 +534,8 @@ static int handlePlaylistInfo(int fd, int *permission, int argc, char *argv[])
return playlistInfo(fd, song);
}
-static int handlePlaylistId(int fd, int *permission, int argc, char *argv[])
+static int handlePlaylistId(int fd, mpd_unused int *permission,
+ int argc, char *argv[])
{
int id = -1;
@@ -515,7 +544,8 @@ static int handlePlaylistId(int fd, int *permission, int argc, char *argv[])
return playlistId(fd, id);
}
-static int handleFind(int fd, int *permission, int argc, char *argv[])
+static int handleFind(int fd, mpd_unused int *permission,
+ int argc, char *argv[])
{
int ret;
@@ -536,7 +566,8 @@ static int handleFind(int fd, int *permission, int argc, char *argv[])
return ret;
}
-static int handleSearch(int fd, int *permission, int argc, char *argv[])
+static int handleSearch(int fd, mpd_unused int *permission,
+ int argc, char *argv[])
{
int ret;
@@ -557,7 +588,8 @@ static int handleSearch(int fd, int *permission, int argc, char *argv[])
return ret;
}
-static int handleCount(int fd, int *permission, int argc, char *argv[])
+static int handleCount(int fd, mpd_unused int *permission,
+ int argc, char *argv[])
{
int ret;
@@ -578,7 +610,8 @@ static int handleCount(int fd, int *permission, int argc, char *argv[])
return ret;
}
-static int handlePlaylistFind(int fd, int *permission, int argc, char *argv[])
+static int handlePlaylistFind(int fd, mpd_unused int *permission,
+ int argc, char *argv[])
{
LocateTagItem *items;
int numItems = newLocateTagItemArrayFromArgArray(argv + 1,
@@ -597,7 +630,8 @@ static int handlePlaylistFind(int fd, int *permission, int argc, char *argv[])
return 0;
}
-static int handlePlaylistSearch(int fd, int *permission, int argc, char *argv[])
+static int handlePlaylistSearch(int fd, mpd_unused int *permission,
+ int argc, char *argv[])
{
LocateTagItem *items;
int numItems = newLocateTagItemArrayFromArgArray(argv + 1,
@@ -616,7 +650,8 @@ static int handlePlaylistSearch(int fd, int *permission, int argc, char *argv[])
return 0;
}
-static int handlePlaylistDelete(int fd, int *permission, int argc, char *argv[]) {
+static int handlePlaylistDelete(int fd, mpd_unused int *permission,
+ mpd_unused int argc, char *argv[]) {
char *playlist = argv[1];
int from;
@@ -626,7 +661,8 @@ static int handlePlaylistDelete(int fd, int *permission, int argc, char *argv[])
return removeOneSongFromStoredPlaylistByPath(fd, playlist, from);
}
-static int handlePlaylistMove(int fd, int *permission, int argc, char *argv[])
+static int handlePlaylistMove(int fd, mpd_unused int *permission,
+ mpd_unused mpd_unused int argc, char *argv[])
{
char *playlist = argv[1];
int from, to;
@@ -640,8 +676,8 @@ static int handlePlaylistMove(int fd, int *permission, int argc, char *argv[])
}
static int listHandleUpdate(int fd,
- int *permission,
- int argc,
+ mpd_unused int *permission,
+ mpd_unused int argc,
char *argv[],
struct strnode *cmdnode, CommandEntry * cmd)
{
@@ -670,7 +706,8 @@ static int listHandleUpdate(int fd,
return 0;
}
-static int handleUpdate(int fd, int *permission, int argc, char *argv[])
+static int handleUpdate(int fd, mpd_unused int *permission,
+ mpd_unused int argc, char *argv[])
{
if (argc == 2) {
int ret;
@@ -683,17 +720,22 @@ static int handleUpdate(int fd, int *permission, int argc, char *argv[])
return updateInit(fd, NULL);
}
-static int handleNext(int fd, int *permission, int argc, char *argv[])
+static int handleNext(mpd_unused int fd, mpd_unused int *permission,
+ mpd_unused int argc, mpd_unused char *argv[])
{
- return nextSongInPlaylist(fd);
+ nextSongInPlaylist();
+ return 0;
}
-static int handlePrevious(int fd, int *permission, int argc, char *argv[])
+static int handlePrevious(mpd_unused int fd, mpd_unused int *permission,
+ mpd_unused int argc, mpd_unused char *argv[])
{
- return previousSongInPlaylist(fd);
+ previousSongInPlaylist();
+ return 0;
}
-static int handleListAll(int fd, int *permission, int argc, char *argv[])
+static int handleListAll(int fd, mpd_unused int *permission,
+ mpd_unused int argc, char *argv[])
{
char *directory = NULL;
@@ -702,7 +744,8 @@ static int handleListAll(int fd, int *permission, int argc, char *argv[])
return printAllIn(fd, directory);
}
-static int handleVolume(int fd, int *permission, int argc, char *argv[])
+static int handleVolume(int fd, mpd_unused int *permission,
+ mpd_unused int argc, char *argv[])
{
int change;
@@ -711,7 +754,8 @@ static int handleVolume(int fd, int *permission, int argc, char *argv[])
return changeVolumeLevel(fd, change, 1);
}
-static int handleSetVol(int fd, int *permission, int argc, char *argv[])
+static int handleSetVol(int fd, mpd_unused int *permission,
+ mpd_unused int argc, char *argv[])
{
int level;
@@ -720,7 +764,8 @@ static int handleSetVol(int fd, int *permission, int argc, char *argv[])
return changeVolumeLevel(fd, level, 0);
}
-static int handleRepeat(int fd, int *permission, int argc, char *argv[])
+static int handleRepeat(int fd, mpd_unused int *permission,
+ mpd_unused int argc, char *argv[])
{
int status;
@@ -729,7 +774,8 @@ static int handleRepeat(int fd, int *permission, int argc, char *argv[])
return setPlaylistRepeatStatus(fd, status);
}
-static int handleRandom(int fd, int *permission, int argc, char *argv[])
+static int handleRandom(int fd, mpd_unused int *permission,
+ mpd_unused int argc, char *argv[])
{
int status;
@@ -738,18 +784,21 @@ static int handleRandom(int fd, int *permission, int argc, char *argv[])
return setPlaylistRandomStatus(fd, status);
}
-static int handleStats(int fd, int *permission, int argc, char *argv[])
+static int handleStats(int fd, mpd_unused int *permission,
+ mpd_unused int argc, mpd_unused char *argv[])
{
return printStats(fd);
}
-static int handleClearError(int fd, int *permission, int argc, char *argv[])
+static int handleClearError(mpd_unused int fd, mpd_unused int *permission,
+ mpd_unused int argc, mpd_unused char *argv[])
{
player_clearerror();
return 0;
}
-static int handleList(int fd, int *permission, int argc, char *argv[])
+static int handleList(int fd, mpd_unused int *permission,
+ int argc, char *argv[])
{
int numConditionals;
LocateTagItem *conditionals = NULL;
@@ -798,7 +847,8 @@ static int handleList(int fd, int *permission, int argc, char *argv[])
return ret;
}
-static int handleMove(int fd, int *permission, int argc, char *argv[])
+static int handleMove(int fd, mpd_unused int *permission,
+ mpd_unused int argc, char *argv[])
{
int from, to;
@@ -809,7 +859,8 @@ static int handleMove(int fd, int *permission, int argc, char *argv[])
return moveSongInPlaylist(fd, from, to);
}
-static int handleMoveId(int fd, int *permission, int argc, char *argv[])
+static int handleMoveId(int fd, mpd_unused int *permission,
+ mpd_unused int argc, char *argv[])
{
int id, to;
@@ -820,7 +871,8 @@ static int handleMoveId(int fd, int *permission, int argc, char *argv[])
return moveSongInPlaylistById(fd, id, to);
}
-static int handleSwap(int fd, int *permission, int argc, char *argv[])
+static int handleSwap(int fd, mpd_unused int *permission,
+ mpd_unused int argc, char *argv[])
{
int song1, song2;
@@ -831,7 +883,8 @@ static int handleSwap(int fd, int *permission, int argc, char *argv[])
return swapSongsInPlaylist(fd, song1, song2);
}
-static int handleSwapId(int fd, int *permission, int argc, char *argv[])
+static int handleSwapId(int fd, mpd_unused int *permission,
+ mpd_unused int argc, char *argv[])
{
int id1, id2;
@@ -842,7 +895,8 @@ static int handleSwapId(int fd, int *permission, int argc, char *argv[])
return swapSongsInPlaylistById(fd, id1, id2);
}
-static int handleSeek(int fd, int *permission, int argc, char *argv[])
+static int handleSeek(int fd, mpd_unused int *permission,
+ mpd_unused int argc, char *argv[])
{
int song, seek_time;
@@ -853,7 +907,8 @@ static int handleSeek(int fd, int *permission, int argc, char *argv[])
return seekSongInPlaylist(fd, song, seek_time);
}
-static int handleSeekId(int fd, int *permission, int argc, char *argv[])
+static int handleSeekId(int fd, mpd_unused int *permission,
+ mpd_unused int argc, char *argv[])
{
int id, seek_time;
@@ -864,7 +919,8 @@ static int handleSeekId(int fd, int *permission, int argc, char *argv[])
return seekSongInPlaylistById(fd, id, seek_time);
}
-static int handleListAllInfo(int fd, int *permission, int argc, char *argv[])
+static int handleListAllInfo(int fd, mpd_unused int *permission,
+ mpd_unused int argc, char *argv[])
{
char *directory = NULL;
@@ -873,12 +929,14 @@ static int handleListAllInfo(int fd, int *permission, int argc, char *argv[])
return printInfoForAllIn(fd, directory);
}
-static int handlePing(int fd, int *permission, int argc, char *argv[])
+static int handlePing(mpd_unused int fd, mpd_unused int *permission,
+ mpd_unused int argc, mpd_unused char *argv[])
{
return 0;
}
-static int handlePassword(int fd, int *permission, int argc, char *argv[])
+static int handlePassword(int fd, mpd_unused int *permission,
+ mpd_unused int argc, char *argv[])
{
if (getPermissionFromPassword(argv[1], permission) < 0) {
commandError(fd, ACK_ERROR_PASSWORD, "incorrect password");
@@ -888,7 +946,8 @@ static int handlePassword(int fd, int *permission, int argc, char *argv[])
return 0;
}
-static int handleCrossfade(int fd, int *permission, int argc, char *argv[])
+static int handleCrossfade(int fd, mpd_unused int *permission,
+ mpd_unused int argc, char *argv[])
{
int xfade_time;
@@ -899,7 +958,8 @@ static int handleCrossfade(int fd, int *permission, int argc, char *argv[])
return 0;
}
-static int handleEnableDevice(int fd, int *permission, int argc, char *argv[])
+static int handleEnableDevice(int fd, mpd_unused int *permission,
+ mpd_unused int argc, char *argv[])
{
int device;
@@ -908,7 +968,8 @@ static int handleEnableDevice(int fd, int *permission, int argc, char *argv[])
return enableAudioDevice(fd, device);
}
-static int handleDisableDevice(int fd, int *permission, int argc, char *argv[])
+static int handleDisableDevice(int fd, mpd_unused int *permission,
+ mpd_unused int argc, char *argv[])
{
int device;
@@ -917,7 +978,8 @@ static int handleDisableDevice(int fd, int *permission, int argc, char *argv[])
return disableAudioDevice(fd, device);
}
-static int handleDevices(int fd, int *permission, int argc, char *argv[])
+static int handleDevices(int fd, mpd_unused int *permission,
+ mpd_unused int argc, mpd_unused char *argv[])
{
printAudioDevices(fd);
@@ -925,7 +987,8 @@ static int handleDevices(int fd, int *permission, int argc, char *argv[])
}
/* don't be fooled, this is the command handler for "commands" command */
-static int handleCommands(int fd, int *permission, int argc, char *argv[])
+static int handleCommands(int fd, mpd_unused int *permission,
+ mpd_unused int argc, mpd_unused char *argv[])
{
ListNode *node = commandList->firstNode;
CommandEntry *cmd;
@@ -942,7 +1005,8 @@ static int handleCommands(int fd, int *permission, int argc, char *argv[])
return 0;
}
-static int handleNotcommands(int fd, int *permission, int argc, char *argv[])
+static int handleNotcommands(int fd, mpd_unused int *permission,
+ mpd_unused int argc, mpd_unused char *argv[])
{
ListNode *node = commandList->firstNode;
CommandEntry *cmd;
@@ -960,12 +1024,14 @@ static int handleNotcommands(int fd, int *permission, int argc, char *argv[])
return 0;
}
-static int handlePlaylistClear(int fd, int *permission, int argc, char *argv[])
+static int handlePlaylistClear(int fd, mpd_unused int *permission,
+ mpd_unused int argc, char *argv[])
{
return clearStoredPlaylist(fd, argv[1]);
}
-static int handlePlaylistAdd(int fd, int *permission, int argc, char *argv[])
+static int handlePlaylistAdd(int fd, mpd_unused int *permission,
+ mpd_unused int argc, char *argv[])
{
char *playlist = argv[1];
char *path = argv[2];
@@ -1139,7 +1205,7 @@ static CommandEntry *getCommandEntryFromString(char *string, int *permission)
return cmd;
}
-static int processCommandInternal(int fd, int *permission,
+static int processCommandInternal(int fd, mpd_unused int *permission,
char *commandString, struct strnode *cmdnode)
{
int argc;
diff --git a/src/dbUtils.c b/src/dbUtils.c
index 11f724b21..519c1802d 100644
--- a/src/dbUtils.c
+++ b/src/dbUtils.c
@@ -45,7 +45,8 @@ typedef struct _SearchStats {
unsigned long playTime;
} SearchStats;
-static int countSongsInDirectory(int fd, Directory * directory, void *data)
+static int countSongsInDirectory(mpd_unused int fd, Directory * directory,
+ void *data)
{
int *count = (int *)data;
@@ -55,7 +56,7 @@ static int countSongsInDirectory(int fd, Directory * directory, void *data)
}
static int printDirectoryInDirectory(int fd, Directory * directory,
- void *data)
+ mpd_unused void *data)
{
if (directory->path) {
fdprintf(fd, "directory: %s\n", getDirectoryPath(directory));
@@ -63,7 +64,7 @@ static int printDirectoryInDirectory(int fd, Directory * directory,
return 0;
}
-static int printSongInDirectory(int fd, Song * song, void *data)
+static int printSongInDirectory(int fd, Song * song, mpd_unused void *data)
{
printSongUrl(fd, song);
return 0;
@@ -133,7 +134,7 @@ static void printSearchStats(int fd, SearchStats *stats)
fdprintf(fd, "playtime: %li\n", stats->playTime);
}
-static int searchStatsInDirectory(int fd, Song * song, void *data)
+static int searchStatsInDirectory(mpd_unused int fd, Song * song, void *data)
{
SearchStats *stats = data;
@@ -171,7 +172,8 @@ int printAllIn(int fd, char *name)
printDirectoryInDirectory, NULL);
}
-static int directoryAddSongToPlaylist(int fd, Song * song, void *data)
+static int directoryAddSongToPlaylist(int fd, Song * song,
+ mpd_unused void *data)
{
return addSongToPlaylist(fd, song, NULL);
}
@@ -194,12 +196,12 @@ int addAllInToStoredPlaylist(int fd, char *name, char *utf8file)
(void *)utf8file);
}
-static int directoryPrintSongInfo(int fd, Song * song, void *data)
+static int directoryPrintSongInfo(int fd, Song * song, mpd_unused void *data)
{
return printSongInfo(fd, song);
}
-static int sumSongTime(int fd, Song * song, void *data)
+static int sumSongTime(mpd_unused int fd, Song * song, void *data)
{
unsigned long *sum_time = (unsigned long *)data;
@@ -252,7 +254,7 @@ static void freeListCommandItem(ListCommandItem * item)
free(item);
}
-static void visitTag(int fd, Song * song, int tagType)
+static void visitTag(int fd, Song * song, enum tag_type tagType)
{
int i;
MpdTag *tag = song->tag;
@@ -307,7 +309,8 @@ int listAllUniqueTags(int fd, int type, int numConditionals,
return ret;
}
-static int sumSavedFilenameMemoryInDirectory(int fd, Directory * dir,
+static int sumSavedFilenameMemoryInDirectory(mpd_unused int fd,
+ Directory * dir,
void *data)
{
int *sum = data;
@@ -321,7 +324,8 @@ static int sumSavedFilenameMemoryInDirectory(int fd, Directory * dir,
return 0;
}
-static int sumSavedFilenameMemoryInSong(int fd, Song * song, void *data)
+static int sumSavedFilenameMemoryInSong(mpd_unused int fd, Song * song,
+ void *data)
{
int *sum = data;
diff --git a/src/decode.h b/src/decode.h
index b1ba138e2..61eeee078 100644
--- a/src/decode.h
+++ b/src/decode.h
@@ -21,8 +21,8 @@
#include "song.h"
-#include "audio.h"
#include "condition.h"
+#include "audio_format.h"
#define DECODE_TYPE_FILE 0
#define DECODE_TYPE_URL 1
diff --git a/src/directory.c b/src/directory.c
index 7168dab02..94a55d664 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -32,6 +32,7 @@
#include "volume.h"
#include "ack.h"
#include "myfprintf.h"
+#include "dbUtils.h"
#define DIRECTORY_DIR "directory: "
#define DIRECTORY_MTIME "mtime: "
diff --git a/src/inputPlugin.h b/src/inputPlugin.h
index 2f337acef..161a0db59 100644
--- a/src/inputPlugin.h
+++ b/src/inputPlugin.h
@@ -22,6 +22,7 @@
#include "inputStream.h"
#include "outputBuffer.h"
#include "metadata_pipe.h"
+#include "decode.h"
/* valid values for streamTypes in the InputPlugin struct: */
#define INPUT_PLUGIN_STREAM_FILE 0x01
diff --git a/src/inputPlugins/_flac_common.c b/src/inputPlugins/_flac_common.c
index 3401a8b4f..6890c7c50 100644
--- a/src/inputPlugins/_flac_common.c
+++ b/src/inputPlugins/_flac_common.c
@@ -26,12 +26,6 @@
#include "_flac_common.h"
#include "../log.h"
-#include "../tag.h"
-#include "../inputStream.h"
-#include "../outputBuffer.h"
-#include "../decode.h"
-#include "../replayGain.h"
-#include "../os_compat.h"
#include <FLAC/format.h>
#include <FLAC/metadata.h>
@@ -180,7 +174,7 @@ void flac_metadata_common_cb(const FLAC__StreamMetadata * block,
void flac_error_common_cb(const char *plugin,
const FLAC__StreamDecoderErrorStatus status,
- FlacData * data)
+ mpd_unused FlacData * data)
{
if (dc_intr())
return;
diff --git a/src/inputPlugins/_flac_common.h b/src/inputPlugins/_flac_common.h
index 5c147a064..6fe5bd744 100644
--- a/src/inputPlugins/_flac_common.h
+++ b/src/inputPlugins/_flac_common.h
@@ -26,10 +26,6 @@
#if defined(HAVE_FLAC) || defined(HAVE_OGGFLAC)
-#include "../tag.h"
-#include "../inputStream.h"
-#include "../outputBuffer.h"
-#include "../decode.h"
#include <FLAC/export.h>
#if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT <= 7
# include <FLAC/seekable_stream_decoder.h>
diff --git a/src/inputPlugins/_ogg_common.c b/src/inputPlugins/_ogg_common.c
index d24b2b47b..a7525c2de 100644
--- a/src/inputPlugins/_ogg_common.c
+++ b/src/inputPlugins/_ogg_common.c
@@ -28,7 +28,6 @@
(defined(FLAC_API_VERSION_CURRENT) && FLAC_API_VERSION_CURRENT > 7)
#include "../utils.h"
-#include "../os_compat.h"
ogg_stream_type ogg_stream_type_detect(InputStream * inStream)
{
diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c
index 98329a4b3..512e73e53 100644
--- a/src/inputPlugins/aac_plugin.c
+++ b/src/inputPlugins/aac_plugin.c
@@ -23,66 +23,65 @@
#define AAC_MAX_CHANNELS 6
#include "../utils.h"
-#include "../audio.h"
#include "../log.h"
-#include "../inputStream.h"
-#include "../outputBuffer.h"
-#include "../os_compat.h"
#include <faad.h>
/* all code here is either based on or copied from FAAD2's frontend code */
typedef struct {
InputStream *inStream;
- long bytesIntoBuffer;
- long bytesConsumed;
- long fileOffset;
+ size_t bytesIntoBuffer;
+ size_t bytesConsumed;
+ off_t fileOffset;
unsigned char *buffer;
int atEof;
} AacBuffer;
+static void aac_buffer_shift(AacBuffer * b, size_t length)
+{
+ assert(length >= b->bytesConsumed);
+ assert(length <= b->bytesConsumed + b->bytesIntoBuffer);
+
+ memmove(b->buffer, b->buffer + length,
+ b->bytesConsumed + b->bytesIntoBuffer - length);
+
+ length -= b->bytesConsumed;
+ b->bytesConsumed = 0;
+ b->bytesIntoBuffer -= length;
+}
+
static void fillAacBuffer(AacBuffer * b)
{
- if (b->bytesConsumed > 0) {
- int bread;
+ size_t bread;
- if (b->bytesIntoBuffer) {
- memmove((void *)b->buffer, (void *)(b->buffer +
- b->bytesConsumed),
- b->bytesIntoBuffer);
- }
+ if (b->bytesIntoBuffer >= FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS)
+ /* buffer already full */
+ return;
- if (!b->atEof) {
- bread = readFromInputStream(b->inStream,
- (void *)(b->buffer +
- b->
- bytesIntoBuffer),
- 1, b->bytesConsumed);
- if (bread != b->bytesConsumed)
- b->atEof = 1;
- b->bytesIntoBuffer += bread;
- }
+ aac_buffer_shift(b, b->bytesConsumed);
- b->bytesConsumed = 0;
+ if (!b->atEof) {
+ size_t rest = FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS -
+ b->bytesIntoBuffer;
- if (b->bytesIntoBuffer > 3) {
- if (memcmp(b->buffer, "TAG", 3) == 0)
- b->bytesIntoBuffer = 0;
- }
- if (b->bytesIntoBuffer > 11) {
- if (memcmp(b->buffer, "LYRICSBEGIN", 11) == 0) {
- b->bytesIntoBuffer = 0;
- }
- }
- if (b->bytesIntoBuffer > 8) {
- if (memcmp(b->buffer, "APETAGEX", 8) == 0) {
- b->bytesIntoBuffer = 0;
- }
- }
+ bread = readFromInputStream(b->inStream,
+ (void *)(b->buffer +
+ b->
+ bytesIntoBuffer),
+ 1, rest);
+ if (bread == 0 && inputStreamAtEOF(b->inStream))
+ b->atEof = 1;
+ b->bytesIntoBuffer += bread;
}
+
+ if ((b->bytesIntoBuffer > 3 && memcmp(b->buffer, "TAG", 3) == 0) ||
+ (b->bytesIntoBuffer > 11 &&
+ memcmp(b->buffer, "LYRICSBEGIN", 11) == 0) ||
+ (b->bytesIntoBuffer > 8 && memcmp(b->buffer, "APETAGEX", 8) == 0))
+ b->bytesIntoBuffer = 0;
}
-static void advanceAacBuffer(AacBuffer * b, int bytes)
+static void advanceAacBuffer(AacBuffer * b, size_t bytes)
{
b->fileOffset += bytes;
b->bytesConsumed = bytes;
@@ -94,36 +93,76 @@ static int adtsSampleRates[] =
16000, 12000, 11025, 8000, 7350, 0, 0, 0
};
-static int adtsParse(AacBuffer * b, float *length)
+/**
+ * Check whether the buffer head is an AAC frame, and return the frame
+ * length. Returns 0 if it is not a frame.
+ */
+static size_t adts_check_frame(AacBuffer * b)
+{
+ if (b->bytesIntoBuffer <= 7)
+ return 0;
+
+ /* check syncword */
+ if (!((b->buffer[0] == 0xFF) && ((b->buffer[1] & 0xF6) == 0xF0)))
+ return 0;
+
+ return (((unsigned int)b->buffer[3] & 0x3) << 11) |
+ (((unsigned int)b->buffer[4]) << 3) |
+ (b->buffer[5] >> 5);
+}
+
+/**
+ * Find the next AAC frame in the buffer. Returns 0 if no frame is
+ * found or if not enough data is available.
+ */
+static size_t adts_find_frame(AacBuffer * b)
{
- int frames, frameLength;
- int tFrameLength = 0;
+ const unsigned char *p;
+ size_t frame_length;
+
+ while ((p = memchr(b->buffer, 0xff, b->bytesIntoBuffer)) != NULL) {
+ /* discard data before 0xff */
+ if (p > b->buffer)
+ aac_buffer_shift(b, p - b->buffer);
+
+ if (b->bytesIntoBuffer <= 7)
+ /* not enough data yet */
+ return 0;
+
+ /* is it a frame? */
+ frame_length = adts_check_frame(b);
+ if (frame_length > 0)
+ /* yes, it is */
+ return frame_length;
+
+ /* it's just some random 0xff byte; discard and and
+ continue searching */
+ aac_buffer_shift(b, 1);
+ }
+
+ /* nothing at all; discard the whole buffer */
+ aac_buffer_shift(b, b->bytesIntoBuffer);
+ return 0;
+}
+
+static void adtsParse(AacBuffer * b, float *length)
+{
+ unsigned int frames, frameLength;
int sampleRate = 0;
- float framesPerSec, bytesPerFrame;
+ float framesPerSec;
/* Read all frames to ensure correct time and bitrate */
for (frames = 0;; frames++) {
fillAacBuffer(b);
- if (b->bytesIntoBuffer > 7) {
- /* check syncword */
- if (!((b->buffer[0] == 0xFF) &&
- ((b->buffer[1] & 0xF6) == 0xF0))) {
- break;
- }
-
+ frameLength = adts_find_frame(b);
+ if (frameLength > 0) {
if (frames == 0) {
sampleRate = adtsSampleRates[(b->
buffer[2] & 0x3c)
>> 2];
}
- frameLength = ((((unsigned int)b->buffer[3] & 0x3))
- << 11) | (((unsigned int)b->buffer[4])
- << 3) | (b->buffer[5] >> 5);
-
- tFrameLength += frameLength;
-
if (frameLength > b->bytesIntoBuffer)
break;
@@ -133,46 +172,34 @@ static int adtsParse(AacBuffer * b, float *length)
}
framesPerSec = (float)sampleRate / 1024.0;
- if (frames != 0) {
- bytesPerFrame = (float)tFrameLength / (float)(frames * 1000);
- } else
- bytesPerFrame = 0;
if (framesPerSec != 0)
*length = (float)frames / framesPerSec;
-
- return 1;
}
-static void initAacBuffer(InputStream * inStream, AacBuffer * b, float *length,
- size_t * retFileread, size_t * retTagsize)
+static void initAacBuffer(InputStream * inStream, AacBuffer * b)
{
- size_t fileread;
- size_t bread;
- size_t tagsize;
-
- if (length)
- *length = -1;
-
memset(b, 0, sizeof(AacBuffer));
b->inStream = inStream;
- fileread = inStream->size;
-
b->buffer = xmalloc(FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS);
memset(b->buffer, 0, FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS);
+}
- bread = readFromInputStream(inStream, b->buffer, 1,
- FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS);
- b->bytesIntoBuffer = bread;
- b->bytesConsumed = 0;
- b->fileOffset = 0;
+static void aac_parse_header(AacBuffer * b, float *length)
+{
+ size_t fileread;
+ size_t tagsize;
- if (bread != FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS)
- b->atEof = 1;
+ if (length)
+ *length = -1;
+
+ fileread = b->inStream->size;
+
+ fillAacBuffer(b);
tagsize = 0;
- if (!memcmp(b->buffer, "ID3", 3)) {
+ if (b->bytesIntoBuffer >= 10 && !memcmp(b->buffer, "ID3", 3)) {
tagsize = (b->buffer[6] << 21) | (b->buffer[7] << 14) |
(b->buffer[8] << 7) | (b->buffer[9] << 0);
@@ -181,28 +208,19 @@ static void initAacBuffer(InputStream * inStream, AacBuffer * b, float *length,
fillAacBuffer(b);
}
- if (retFileread)
- *retFileread = fileread;
- if (retTagsize)
- *retTagsize = tagsize;
-
if (length == NULL)
return;
- if ((b->buffer[0] == 0xFF) && ((b->buffer[1] & 0xF6) == 0xF0)) {
+ if (b->bytesIntoBuffer >= 2 &&
+ (b->buffer[0] == 0xFF) && ((b->buffer[1] & 0xF6) == 0xF0)) {
adtsParse(b, length);
seekInputStream(b->inStream, tagsize, SEEK_SET);
- bread = readFromInputStream(b->inStream, b->buffer, 1,
- FAAD_MIN_STREAMSIZE *
- AAC_MAX_CHANNELS);
- if (bread != FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS)
- b->atEof = 1;
- else
- b->atEof = 0;
- b->bytesIntoBuffer = bread;
+ b->bytesIntoBuffer = 0;
b->bytesConsumed = 0;
b->fileOffset = tagsize;
+
+ fillAacBuffer(b);
} else if (memcmp(b->buffer, "ADIF", 4) == 0) {
int bitRate;
int skipSize = (b->buffer[4] & 0x80) ? 9 : 0;
@@ -231,7 +249,6 @@ static float getAacFloatTotalTime(char *file)
{
AacBuffer b;
float length;
- size_t fileread, tagsize;
faacDecHandle decoder;
faacDecConfigurationPtr config;
uint32_t sampleRate;
@@ -242,7 +259,8 @@ static float getAacFloatTotalTime(char *file)
if (openInputStream(&inStream, file) < 0)
return -1;
- initAacBuffer(&inStream, &b, &length, &fileread, &tagsize);
+ initAacBuffer(&inStream, &b);
+ aac_parse_header(&b, &length);
if (length < 0) {
decoder = faacDecOpen();
@@ -282,6 +300,132 @@ static int getAacTotalTime(char *file)
return file_time;
}
+static int aac_stream_decode(InputStream *inStream)
+{
+ float file_time;
+ float totalTime = 0;
+ faacDecHandle decoder;
+ faacDecFrameInfo frameInfo;
+ faacDecConfigurationPtr config;
+ long bread;
+ uint32_t sampleRate;
+ unsigned char channels;
+ unsigned int sampleCount;
+ char *sampleBuffer;
+ size_t sampleBufferLen;
+ mpd_uint16 bitRate = 0;
+ AacBuffer b;
+
+ initAacBuffer(inStream, &b);
+ aac_parse_header(&b, NULL);
+
+ decoder = faacDecOpen();
+
+ config = faacDecGetCurrentConfiguration(decoder);
+ config->outputFormat = FAAD_FMT_16BIT;
+#ifdef HAVE_FAACDECCONFIGURATION_DOWNMATRIX
+ config->downMatrix = 1;
+#endif
+#ifdef HAVE_FAACDECCONFIGURATION_DONTUPSAMPLEIMPLICITSBR
+ config->dontUpSampleImplicitSBR = 0;
+#endif
+ faacDecSetConfiguration(decoder, config);
+
+ while (b.bytesIntoBuffer < FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS &&
+ !b.atEof && !dc_intr()) {
+ fillAacBuffer(&b);
+ adts_find_frame(&b);
+ fillAacBuffer(&b);
+ }
+
+#ifdef HAVE_FAAD_BUFLEN_FUNCS
+ bread = faacDecInit(decoder, b.buffer, b.bytesIntoBuffer,
+ &sampleRate, &channels);
+#else
+ bread = faacDecInit(decoder, b.buffer, &sampleRate, &channels);
+#endif
+ if (bread < 0) {
+ ERROR("Error not a AAC stream.\n");
+ faacDecClose(decoder);
+ if (b.buffer)
+ free(b.buffer);
+ return -1;
+ }
+
+ dc.audio_format.bits = 16;
+ dc.total_time = totalTime;
+
+ file_time = 0.0;
+
+ advanceAacBuffer(&b, bread);
+
+ while (1) {
+ fillAacBuffer(&b);
+ adts_find_frame(&b);
+ fillAacBuffer(&b);
+
+ if (b.bytesIntoBuffer == 0)
+ break;
+
+#ifdef HAVE_FAAD_BUFLEN_FUNCS
+ sampleBuffer = faacDecDecode(decoder, &frameInfo, b.buffer,
+ b.bytesIntoBuffer);
+#else
+ sampleBuffer = faacDecDecode(decoder, &frameInfo, b.buffer);
+#endif
+
+ if (frameInfo.error > 0) {
+ ERROR("error decoding AAC stream\n");
+ ERROR("faad2 error: %s\n",
+ faacDecGetErrorMessage(frameInfo.error));
+ break;
+ }
+#ifdef HAVE_FAACDECFRAMEINFO_SAMPLERATE
+ sampleRate = frameInfo.samplerate;
+#endif
+
+ dc.audio_format.channels = frameInfo.channels;
+ dc.audio_format.sampleRate = sampleRate;
+
+ advanceAacBuffer(&b, frameInfo.bytesconsumed);
+
+ sampleCount = (unsigned long)(frameInfo.samples);
+
+ if (sampleCount > 0) {
+ bitRate = frameInfo.bytesconsumed * 8.0 *
+ frameInfo.channels * sampleRate /
+ frameInfo.samples / 1000 + 0.5;
+ file_time +=
+ (float)(frameInfo.samples) / frameInfo.channels /
+ sampleRate;
+ }
+
+ sampleBufferLen = sampleCount * 2;
+
+ switch (ob_send(sampleBuffer, sampleBufferLen,
+ file_time, bitRate, NULL)) {
+ case DC_ACTION_NONE: break;
+ case DC_ACTION_SEEK:
+ /*
+ * this plugin doesn't support seek because nobody
+ * has bothered, yet...
+ */
+ dc_action_seek_fail(DC_SEEK_ERROR);
+ break;
+ default: goto out;
+ }
+ }
+out:
+
+ faacDecClose(decoder);
+ if (b.buffer)
+ free(b.buffer);
+
+ return 0;
+}
+
+
+
static int aac_decode(char *path)
{
float file_time;
@@ -292,7 +436,6 @@ static int aac_decode(char *path)
long bread;
uint32_t sampleRate;
unsigned char channels;
- int eof = 0;
unsigned int sampleCount;
char *sampleBuffer;
size_t sampleBufferLen;
@@ -309,7 +452,8 @@ static int aac_decode(char *path)
if (openInputStream(&inStream, path) < 0)
return -1;
- initAacBuffer(&inStream, &b, NULL, NULL, NULL);
+ initAacBuffer(&inStream, &b);
+ aac_parse_header(&b, NULL);
decoder = faacDecOpen();
@@ -346,13 +490,12 @@ static int aac_decode(char *path)
advanceAacBuffer(&b, bread);
- while (!eof) {
+ while (1) {
fillAacBuffer(&b);
- if (b.bytesIntoBuffer == 0) {
- eof = 1;
+ if (b.bytesIntoBuffer == 0)
break;
- }
+
#ifdef HAVE_FAAD_BUFLEN_FUNCS
sampleBuffer = faacDecDecode(decoder, &frameInfo, b.buffer,
b.bytesIntoBuffer);
@@ -364,7 +507,6 @@ static int aac_decode(char *path)
ERROR("error decoding AAC file: %s\n", path);
ERROR("faad2 error: %s\n",
faacDecGetErrorMessage(frameInfo.error));
- eof = 1;
break;
}
#ifdef HAVE_FAACDECFRAMEINFO_SAMPLERATE
@@ -399,9 +541,10 @@ static int aac_decode(char *path)
*/
dc_action_seek_fail(DC_SEEK_ERROR);
break;
- default: eof = 1;
+ default: goto out;
}
}
+out:
faacDecClose(decoder);
if (b.buffer)
@@ -435,10 +578,10 @@ InputPlugin aacPlugin = {
NULL,
NULL,
NULL,
- NULL,
+ aac_stream_decode,
aac_decode,
aacTagDup,
- INPUT_PLUGIN_STREAM_FILE,
+ INPUT_PLUGIN_STREAM_FILE | INPUT_PLUGIN_STREAM_URL,
aac_suffixes,
aac_mimeTypes
};
diff --git a/src/inputPlugins/audiofile_plugin.c b/src/inputPlugins/audiofile_plugin.c
index 114a87786..fcebf562b 100644
--- a/src/inputPlugins/audiofile_plugin.c
+++ b/src/inputPlugins/audiofile_plugin.c
@@ -22,11 +22,7 @@
#ifdef HAVE_AUDIOFILE
-#include "../utils.h"
-#include "../audio.h"
#include "../log.h"
-#include "../pcm_utils.h"
-#include "../os_compat.h"
#include <audiofile.h>
@@ -51,6 +47,8 @@ static int audiofile_decode(char *path)
int bits;
mpd_uint16 bitRate;
struct stat st;
+ int ret, current = 0;
+ char chunk[CHUNK_SIZE];
if (stat(path, &st) < 0) {
ERROR("failed to stat: %s\n", path);
@@ -88,34 +86,29 @@ static int audiofile_decode(char *path)
fs = (int)afGetVirtualFrameSize(af_fp, AF_DEFAULT_TRACK, 1);
- {
- int ret, eof = 0, current = 0;
- char chunk[CHUNK_SIZE];
-
- while (!eof) {
- if (dc_seek()) {
- dc_action_begin();
- current = dc.seek_where *
- dc.audio_format.sampleRate;
- afSeekFrame(af_fp, AF_DEFAULT_TRACK, current);
- dc_action_end();
- }
-
- ret =
- afReadFrames(af_fp, AF_DEFAULT_TRACK, chunk,
- CHUNK_SIZE / fs);
- if (ret <= 0)
- eof = 1;
- else {
- current += ret;
- ob_send(chunk, ret * fs,
- (float)current /
- (float)dc.audio_format.sampleRate,
- bitRate,
- NULL);
- if (dc_intr())
- break;
- }
+ while (1) {
+ if (dc_seek()) {
+ dc_action_begin();
+ current = dc.seek_where *
+ dc.audio_format.sampleRate;
+ afSeekFrame(af_fp, AF_DEFAULT_TRACK, current);
+ dc_action_end();
+ }
+
+ ret =
+ afReadFrames(af_fp, AF_DEFAULT_TRACK, chunk,
+ CHUNK_SIZE / fs);
+ if (ret <= 0)
+ break;
+ else {
+ current += ret;
+ ob_send(chunk, ret * fs,
+ (float)current /
+ (float)dc.audio_format.sampleRate,
+ bitRate,
+ NULL);
+ if (dc_intr())
+ break;
}
}
afCloseFile(af_fp);
diff --git a/src/inputPlugins/flac_plugin.c b/src/inputPlugins/flac_plugin.c
index 4a4ac627c..de0648c90 100644
--- a/src/inputPlugins/flac_plugin.c
+++ b/src/inputPlugins/flac_plugin.c
@@ -22,16 +22,10 @@
#include "../utils.h"
#include "../log.h"
-#include "../pcm_utils.h"
-#include "../inputStream.h"
-#include "../outputBuffer.h"
-#include "../replayGain.h"
-#include "../audio.h"
-#include "../os_compat.h"
/* this code was based on flac123, from flac-tools */
-static flac_read_status flacRead(const flac_decoder * flacDec,
+static flac_read_status flacRead(mpd_unused const flac_decoder * flacDec,
FLAC__byte buf[],
flac_read_status_size_t *bytes,
void *fdata)
@@ -57,7 +51,7 @@ static flac_read_status flacRead(const flac_decoder * flacDec,
return flac_read_status_continue;
}
-static flac_seek_status flacSeek(const flac_decoder * flacDec,
+static flac_seek_status flacSeek(mpd_unused const flac_decoder * flacDec,
FLAC__uint64 offset,
void *fdata)
{
@@ -70,7 +64,7 @@ static flac_seek_status flacSeek(const flac_decoder * flacDec,
return flac_seek_status_ok;
}
-static flac_tell_status flacTell(const flac_decoder * flacDec,
+static flac_tell_status flacTell(mpd_unused const flac_decoder * flacDec,
FLAC__uint64 * offset,
void *fdata)
{
@@ -81,7 +75,7 @@ static flac_tell_status flacTell(const flac_decoder * flacDec,
return flac_tell_status_ok;
}
-static flac_length_status flacLength(const flac_decoder * flacDec,
+static flac_length_status flacLength(mpd_unused const flac_decoder * flacDec,
FLAC__uint64 * length,
void *fdata)
{
@@ -92,7 +86,7 @@ static flac_length_status flacLength(const flac_decoder * flacDec,
return flac_length_status_ok;
}
-static FLAC__bool flacEOF(const flac_decoder * flacDec, void *fdata)
+static FLAC__bool flacEOF(mpd_unused const flac_decoder * flacDec, void *fdata)
{
FlacData *data = (FlacData *) fdata;
@@ -101,7 +95,7 @@ static FLAC__bool flacEOF(const flac_decoder * flacDec, void *fdata)
return false;
}
-static void flacError(const flac_decoder *dec,
+static void flacError(mpd_unused const flac_decoder *dec,
FLAC__StreamDecoderErrorStatus status, void *fdata)
{
flac_error_common_cb("flac", status, (FlacData *) fdata);
@@ -199,7 +193,7 @@ static void flacPrintErroredState(FLAC__StreamDecoderState state)
}
#endif /* FLAC_API_VERSION_CURRENT >= 7 */
-static void flacMetadata(const flac_decoder * dec,
+static void flacMetadata(mpd_unused const flac_decoder * dec,
const FLAC__StreamMetadata * block, void *vdata)
{
flac_metadata_common_cb(block, (FlacData *) vdata);
diff --git a/src/inputPlugins/mod_plugin.c b/src/inputPlugins/mod_plugin.c
index 9f9da6273..df938f0ed 100644
--- a/src/inputPlugins/mod_plugin.c
+++ b/src/inputPlugins/mod_plugin.c
@@ -21,10 +21,7 @@
#ifdef HAVE_MIKMOD
#include "../utils.h"
-#include "../audio.h"
#include "../log.h"
-#include "../pcm_utils.h"
-#include "../os_compat.h"
#include <mikmod.h>
diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c
index c36cab6f0..f1304f401 100644
--- a/src/inputPlugins/mp3_plugin.c
+++ b/src/inputPlugins/mp3_plugin.c
@@ -20,7 +20,6 @@
#ifdef HAVE_MAD
-#include "../pcm_utils.h"
#include <mad.h>
#ifdef HAVE_ID3TAG
@@ -29,23 +28,24 @@
#include "../log.h"
#include "../utils.h"
-#include "../replayGain.h"
-#include "../tag.h"
#include "../conf.h"
-#include "../os_compat.h"
-
#define FRAMES_CUSHION 2000
#define READ_BUFFER_SIZE 40960
-#define DECODE_SKIP -3
-#define DECODE_BREAK -2
-#define DECODE_CONT -1
-#define DECODE_OK 0
+enum mp3_action {
+ DECODE_SKIP = -3,
+ DECODE_BREAK = -2,
+ DECODE_CONT = -1,
+ DECODE_OK = 0
+};
-#define MUTEFRAME_SKIP 1
-#define MUTEFRAME_SEEK 2
+enum muteframe {
+ MUTEFRAME_NONE,
+ MUTEFRAME_SKIP,
+ MUTEFRAME_SEEK
+};
/* the number of samples of silence the decoder inserts at start */
#define DECODERDELAY 529
@@ -65,8 +65,8 @@ static unsigned long prng(unsigned long state)
return (state * 0x0019660dL + 0x3c6ef35fL) & 0xffffffffL;
}
-static signed long audio_linear_dither(unsigned int bits, mad_fixed_t sample,
- struct audio_dither *dither)
+static mpd_sint16 audio_linear_dither(unsigned int bits, mad_fixed_t sample,
+ struct audio_dither *dither)
{
unsigned int scalebits;
mad_fixed_t output, mask, rnd;
@@ -107,7 +107,29 @@ static signed long audio_linear_dither(unsigned int bits, mad_fixed_t sample,
dither->error[0] = sample - output;
- return output >> scalebits;
+ return (mpd_sint16)(output >> scalebits);
+}
+
+static unsigned dither_buffer(mpd_sint16 *dest0, const struct mad_synth *synth,
+ struct audio_dither *dither,
+ unsigned int start, unsigned int end,
+ unsigned int num_channels)
+{
+ mpd_sint16 *dest = dest0;
+ unsigned int i;
+
+ for (i = start; i < end; ++i) {
+ *dest++ = audio_linear_dither(16,
+ synth->pcm.samples[0][i],
+ dither);
+
+ if (num_channels == 2)
+ *dest++ = audio_linear_dither(16,
+ synth->pcm.samples[1][i],
+ dither);
+ }
+
+ return dest - dest0;
}
/* end of stolen stuff from mpg321 */
@@ -123,7 +145,7 @@ static int mp3_plugin_init(void)
/* decoder stuff is based on madlld */
-#define MP3_DATA_OUTPUT_BUFFER_SIZE 4096
+#define MP3_DATA_OUTPUT_BUFFER_SIZE 2048
typedef struct _mp3DecodeData {
struct mad_stream stream;
@@ -131,25 +153,22 @@ typedef struct _mp3DecodeData {
struct mad_synth synth;
mad_timer_t timer;
unsigned char readBuffer[READ_BUFFER_SIZE];
- char outputBuffer[MP3_DATA_OUTPUT_BUFFER_SIZE];
- char *outputPtr;
- char *outputBufferEnd;
+ mpd_sint16 outputBuffer[MP3_DATA_OUTPUT_BUFFER_SIZE];
float totalTime;
float elapsedTime;
- int muteFrame;
+ enum muteframe muteFrame;
long *frameOffset;
mad_timer_t *times;
- long highestFrame;
- long maxFrames;
- long currentFrame;
- int dropFramesAtStart;
- int dropFramesAtEnd;
- int dropSamplesAtStart;
- int dropSamplesAtEnd;
+ unsigned long highestFrame;
+ unsigned long maxFrames;
+ unsigned long currentFrame;
+ unsigned int dropFramesAtStart;
+ unsigned int dropFramesAtEnd;
+ unsigned int dropSamplesAtStart;
+ unsigned int dropSamplesAtEnd;
int foundXing;
int foundFirstFrame;
int decodedFirstFrame;
- int flush;
unsigned long bitRate;
InputStream *inStream;
struct audio_dither dither;
@@ -158,10 +177,7 @@ typedef struct _mp3DecodeData {
static void initMp3DecodeData(mp3DecodeData * data, InputStream * inStream)
{
- data->outputPtr = data->outputBuffer;
- data->outputBufferEnd =
- data->outputBuffer + MP3_DATA_OUTPUT_BUFFER_SIZE;
- data->muteFrame = 0;
+ data->muteFrame = MUTEFRAME_NONE;
data->highestFrame = 0;
data->maxFrames = 0;
data->frameOffset = NULL;
@@ -174,7 +190,6 @@ static void initMp3DecodeData(mp3DecodeData * data, InputStream * inStream)
data->foundXing = 0;
data->foundFirstFrame = 0;
data->decodedFirstFrame = 0;
- data->flush = 1;
data->inStream = inStream;
data->layer = 0;
memset(&(data->dither), 0, sizeof(struct audio_dither));
@@ -357,8 +372,9 @@ fail:
}
#endif
-static int decodeNextFrameHeader(mp3DecodeData * data, MpdTag ** tag,
- ReplayGainInfo ** replayGainInfo)
+static enum mp3_action
+decodeNextFrameHeader(mp3DecodeData * data, MpdTag ** tag,
+ ReplayGainInfo ** replayGainInfo)
{
enum mad_layer layer;
@@ -400,7 +416,6 @@ static int decodeNextFrameHeader(mp3DecodeData * data, MpdTag ** tag,
ERROR("unrecoverable frame level error "
"(%s).\n",
mad_stream_errorstr(&data->stream));
- data->flush = 0;
return DECODE_BREAK;
}
}
@@ -421,7 +436,8 @@ static int decodeNextFrameHeader(mp3DecodeData * data, MpdTag ** tag,
return DECODE_OK;
}
-static int decodeNextFrame(mp3DecodeData * data)
+static enum mp3_action
+decodeNextFrame(mp3DecodeData * data)
{
if ((data->stream).buffer == NULL
|| (data->stream).error == MAD_ERROR_BUFLEN) {
@@ -453,7 +469,6 @@ static int decodeNextFrame(mp3DecodeData * data)
ERROR("unrecoverable frame level error "
"(%s).\n",
mad_stream_errorstr(&data->stream));
- data->flush = 0;
return DECODE_BREAK;
}
}
@@ -819,7 +834,7 @@ static float frame_time(mp3DecodeData * data, long j)
static void mp3Read_seek(mp3DecodeData * data)
{
- long j = 0;
+ unsigned long j = 0;
data->muteFrame = MUTEFRAME_SEEK;
assert(pthread_equal(pthread_self(), dc.thread));
@@ -829,22 +844,20 @@ static void mp3Read_seek(mp3DecodeData * data)
j++;
if (j < data->highestFrame) {
dc_action_begin();
- if (seekMp3InputBuffer(data, data->frameOffset[j]) < 0) {
+ if (seekMp3InputBuffer(data, data->frameOffset[j]) < 0)
dc.seek_where = DC_SEEK_ERROR;
- } else {
- data->outputPtr = data->outputBuffer;
+ else
data->currentFrame = j;
- }
- data->muteFrame = 0;
+ data->muteFrame = MUTEFRAME_NONE;
dc_action_end();
}
}
-static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo)
+static enum mp3_action
+mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo)
{
- int samplesPerFrame;
- int samplesLeft;
- int i;
+ unsigned int pcm_length, max_samples;
+ unsigned int i;
int ret;
int skip;
@@ -877,22 +890,21 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo)
switch (data->muteFrame) {
case MUTEFRAME_SKIP:
- data->muteFrame = 0;
+ data->muteFrame = MUTEFRAME_NONE;
break;
case MUTEFRAME_SEEK:
if (dc.seek_where <= data->elapsedTime) {
dc_action_begin();
assert(dc.action == DC_ACTION_SEEK);
- data->outputPtr = data->outputBuffer;
- data->muteFrame = 0;
+ data->muteFrame = MUTEFRAME_NONE;
dc_action_end();
}
break;
- default:
+ case MUTEFRAME_NONE:
mad_synth_frame(&data->synth, &data->frame);
if (!data->foundFirstFrame) {
- samplesPerFrame = (data->synth).pcm.length;
+ unsigned int samplesPerFrame = (data->synth).pcm.length;
data->dropFramesAtStart = data->dropSamplesAtStart / samplesPerFrame;
data->dropFramesAtEnd = data->dropSamplesAtEnd / samplesPerFrame;
data->dropSamplesAtStart = data->dropSamplesAtStart % samplesPerFrame;
@@ -924,60 +936,57 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo)
metadata_pipe_send(tag, data->elapsedTime);
}
- samplesLeft = (data->synth).pcm.length;
+ if (!data->decodedFirstFrame) {
+ i = data->dropSamplesAtStart;
+ data->decodedFirstFrame = 1;
+ } else
+ i = 0;
+
+ pcm_length = data->synth.pcm.length;
+ if (data->dropSamplesAtEnd &&
+ (data->currentFrame == data->maxFrames - data->dropFramesAtEnd)) {
+ if (data->dropSamplesAtEnd >= pcm_length)
+ pcm_length = 0;
+ else
+ pcm_length -= data->dropSamplesAtEnd;
+ }
- for (i = 0; i < (data->synth).pcm.length; i++) {
- mpd_sint16 *sample;
+ max_samples = sizeof(data->outputBuffer) /
+ (2 * MAD_NCHANNELS(&(data->frame).header));
- samplesLeft--;
+ while (i < pcm_length) {
+ enum dc_action action;
+ unsigned int num_samples = pcm_length - i;
- if (!data->decodedFirstFrame &&
- (i < data->dropSamplesAtStart)) {
- continue;
- } else if (data->dropSamplesAtEnd &&
- (data->currentFrame == (data->maxFrames - data->dropFramesAtEnd)) &&
- (samplesLeft < data->dropSamplesAtEnd)) {
- /* stop decoding, effectively dropping
- * all remaining samples */
- return DECODE_BREAK;
- }
+ if (num_samples > max_samples)
+ num_samples = max_samples;
+ i += num_samples;
- sample = (mpd_sint16 *) data->outputPtr;
- *sample = (mpd_sint16) audio_linear_dither(16,
- (data->synth).pcm.samples[0][i],
- &(data->dither));
- data->outputPtr += 2;
-
- if (MAD_NCHANNELS(&(data->frame).header) == 2) {
- sample = (mpd_sint16 *) data->outputPtr;
- *sample = (mpd_sint16) audio_linear_dither(16,
- (data->synth).pcm.samples[1][i],
- &(data->dither));
- data->outputPtr += 2;
- }
+ num_samples = dither_buffer(data->outputBuffer,
+ &data->synth, &data->dither,
+ i - num_samples, i,
+ MAD_NCHANNELS(
+ &(data->frame).header));
- if (data->outputPtr >= data->outputBufferEnd) {
- enum dc_action action = ob_send(
- data->outputBuffer,
- data->outputPtr -
- data->outputBuffer,
- data->elapsedTime,
- data->bitRate / 1000,
- replayGainInfo ? *replayGainInfo
- : NULL);
-
- if (action == DC_ACTION_STOP) {
- data->flush = 0;
- return DECODE_BREAK;
- }
- data->outputPtr = data->outputBuffer;
+ action = ob_send(data->outputBuffer,
+ 2 * num_samples,
+ data->elapsedTime,
+ data->bitRate / 1000,
+ replayGainInfo ? *replayGainInfo : NULL);
- if (action == DC_ACTION_SEEK)
- break;
- }
+ if (action == DC_ACTION_STOP)
+ return DECODE_BREAK;
+
+ if (action == DC_ACTION_SEEK)
+ break;
}
- data->decodedFirstFrame = 1;
+ if (data->dropSamplesAtEnd &&
+ (data->currentFrame ==
+ (data->maxFrames - data->dropFramesAtEnd)))
+ /* stop decoding, effectively dropping
+ * all remaining samples */
+ return DECODE_BREAK;
if (dc_seek()) {
if (data->inStream->seekable)
@@ -997,7 +1006,7 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo)
break;
else if (ret == DECODE_SKIP)
skip = 1;
- if (!data->muteFrame) {
+ if (data->muteFrame == MUTEFRAME_NONE) {
while ((ret = decodeNextFrame(data)) == DECODE_CONT &&
!dc_intr() && dc_seek()) ;
if (ret == DECODE_BREAK || dc_intr() || dc_seek())
@@ -1065,11 +1074,6 @@ static int mp3_decode(InputStream * inStream)
metadata_pipe_send(tag, 0);
while (mp3Read(&data, &replayGainInfo) != DECODE_BREAK) ;
- /* send last little bit if not dc_intr() */
- if (!dc_intr() && data.outputPtr != data.outputBuffer && data.flush) {
- ob_send(data.outputBuffer, data.outputPtr - data.outputBuffer,
- data.elapsedTime, data.bitRate / 1000, replayGainInfo);
- }
if (replayGainInfo)
freeReplayGainInfo(replayGainInfo);
diff --git a/src/inputPlugins/mp4_plugin.c b/src/inputPlugins/mp4_plugin.c
index bf200c534..8e3d02354 100644
--- a/src/inputPlugins/mp4_plugin.c
+++ b/src/inputPlugins/mp4_plugin.c
@@ -21,13 +21,7 @@
#ifdef HAVE_FAAD
#include "../utils.h"
-#include "../audio.h"
#include "../log.h"
-#include "../pcm_utils.h"
-#include "../inputStream.h"
-#include "../outputBuffer.h"
-#include "../decode.h"
-#include "../os_compat.h"
#include "../mp4ff/mp4ff.h"
@@ -100,7 +94,6 @@ static int mp4_decode(InputStream * inStream)
unsigned char channels;
long sampleId;
long numSamples;
- int eof = 0;
long dur;
unsigned int sampleCount;
char *sampleBuffer;
@@ -183,7 +176,7 @@ static int mp4_decode(InputStream * inStream)
seekTable = xmalloc(sizeof(float) * numSamples);
- for (sampleId = 0; sampleId < numSamples && !eof; sampleId++) {
+ for (sampleId = 0; sampleId < numSamples; sampleId++) {
if (!seeking && dc_seek()) {
dc_action_begin();
assert(dc.action == DC_ACTION_SEEK);
@@ -229,10 +222,9 @@ static int mp4_decode(InputStream * inStream)
continue;
if (mp4ff_read_sample(mp4fh, track, sampleId, &mp4Buffer,
- &mp4BufferSize) == 0) {
- eof = 1;
- continue;
- }
+ &mp4BufferSize) == 0)
+ break;
+
#ifdef HAVE_FAAD_BUFLEN_FUNCS
sampleBuffer = faacDecDecode(decoder, &frameInfo, mp4Buffer,
mp4BufferSize);
@@ -245,7 +237,6 @@ static int mp4_decode(InputStream * inStream)
if (frameInfo.error > 0) {
ERROR("faad2 error: %s\n",
faacDecGetErrorMessage(frameInfo.error));
- eof = 1;
break;
}
@@ -276,10 +267,8 @@ static int mp4_decode(InputStream * inStream)
ob_send(sampleBuffer, sampleBufferLen, file_time,
bitRate, NULL);
- if (dc_intr()) {
- eof = 1;
+ if (dc_intr())
break;
- }
}
free(seekTable);
diff --git a/src/inputPlugins/mpc_plugin.c b/src/inputPlugins/mpc_plugin.c
index 116e471ff..ea27d1dbf 100644
--- a/src/inputPlugins/mpc_plugin.c
+++ b/src/inputPlugins/mpc_plugin.c
@@ -21,13 +21,7 @@
#ifdef HAVE_MPCDEC
#include "../utils.h"
-#include "../audio.h"
#include "../log.h"
-#include "../pcm_utils.h"
-#include "../inputStream.h"
-#include "../outputBuffer.h"
-#include "../replayGain.h"
-#include "../os_compat.h"
#include <mpcdec/mpcdec.h>
diff --git a/src/inputPlugins/oggflac_plugin.c b/src/inputPlugins/oggflac_plugin.c
index 6c5998afe..4b3bb0a6b 100644
--- a/src/inputPlugins/oggflac_plugin.c
+++ b/src/inputPlugins/oggflac_plugin.c
@@ -27,12 +27,6 @@
#include "../utils.h"
#include "../log.h"
-#include "../pcm_utils.h"
-#include "../inputStream.h"
-#include "../outputBuffer.h"
-#include "../replayGain.h"
-#include "../audio.h"
-#include "../os_compat.h"
static void oggflac_cleanup(FlacData * data,
OggFLAC__SeekableStreamDecoder * decoder)
@@ -43,7 +37,7 @@ static void oggflac_cleanup(FlacData * data,
OggFLAC__seekable_stream_decoder_delete(decoder);
}
-static OggFLAC__SeekableStreamDecoderReadStatus of_read_cb(const
+static OggFLAC__SeekableStreamDecoderReadStatus of_read_cb(mpd_unused const
OggFLAC__SeekableStreamDecoder
* decoder,
FLAC__byte buf[],
@@ -68,7 +62,7 @@ static OggFLAC__SeekableStreamDecoderReadStatus of_read_cb(const
return OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK;
}
-static OggFLAC__SeekableStreamDecoderSeekStatus of_seek_cb(const
+static OggFLAC__SeekableStreamDecoderSeekStatus of_seek_cb(mpd_unused const
OggFLAC__SeekableStreamDecoder
* decoder,
FLAC__uint64 offset,
@@ -83,7 +77,7 @@ static OggFLAC__SeekableStreamDecoderSeekStatus of_seek_cb(const
return OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK;
}
-static OggFLAC__SeekableStreamDecoderTellStatus of_tell_cb(const
+static OggFLAC__SeekableStreamDecoderTellStatus of_tell_cb(mpd_unused const
OggFLAC__SeekableStreamDecoder
* decoder,
FLAC__uint64 *
@@ -96,7 +90,7 @@ static OggFLAC__SeekableStreamDecoderTellStatus of_tell_cb(const
return OggFLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK;
}
-static OggFLAC__SeekableStreamDecoderLengthStatus of_length_cb(const
+static OggFLAC__SeekableStreamDecoderLengthStatus of_length_cb(mpd_unused const
OggFLAC__SeekableStreamDecoder
* decoder,
FLAC__uint64 *
@@ -110,7 +104,7 @@ static OggFLAC__SeekableStreamDecoderLengthStatus of_length_cb(const
return OggFLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK;
}
-static FLAC__bool of_EOF_cb(const OggFLAC__SeekableStreamDecoder * decoder,
+static FLAC__bool of_EOF_cb(mpd_unused const OggFLAC__SeekableStreamDecoder * decoder,
void *fdata)
{
FlacData *data = (FlacData *) fdata;
@@ -120,7 +114,7 @@ static FLAC__bool of_EOF_cb(const OggFLAC__SeekableStreamDecoder * decoder,
return false;
}
-static void of_error_cb(const OggFLAC__SeekableStreamDecoder * decoder,
+static void of_error_cb(mpd_unused const OggFLAC__SeekableStreamDecoder * decoder,
FLAC__StreamDecoderErrorStatus status, void *fdata)
{
flac_error_common_cb("oggflac", status, (FlacData *) fdata);
@@ -157,7 +151,7 @@ static void oggflacPrintErroredState(OggFLAC__SeekableStreamDecoderState state)
}
}
-static FLAC__StreamDecoderWriteStatus oggflacWrite(const
+static FLAC__StreamDecoderWriteStatus oggflacWrite(mpd_unused const
OggFLAC__SeekableStreamDecoder
* decoder,
const FLAC__Frame * frame,
@@ -214,7 +208,7 @@ static FLAC__StreamDecoderWriteStatus oggflacWrite(const
}
/* used by TagDup */
-static void of_metadata_dup_cb(const OggFLAC__SeekableStreamDecoder * decoder,
+static void of_metadata_dup_cb(mpd_unused const OggFLAC__SeekableStreamDecoder * decoder,
const FLAC__StreamMetadata * block, void *vdata)
{
FlacData *data = (FlacData *) vdata;
@@ -235,7 +229,7 @@ static void of_metadata_dup_cb(const OggFLAC__SeekableStreamDecoder * decoder,
}
/* used by decode */
-static void of_metadata_decode_cb(const OggFLAC__SeekableStreamDecoder * dec,
+static void of_metadata_decode_cb(mpd_unused const OggFLAC__SeekableStreamDecoder * dec,
const FLAC__StreamMetadata * block,
void *vdata)
{
@@ -333,6 +327,11 @@ static MpdTag *oggflac_TagDup(char *file)
static unsigned int oggflac_try_decode(InputStream * inStream)
{
+ if (!inStream->seekable)
+ /* we cannot seek after the detection, so don't bother
+ checking */
+ return 1;
+
return (ogg_stream_type_detect(inStream) == FLAC) ? 1 : 0;
}
diff --git a/src/inputPlugins/oggvorbis_plugin.c b/src/inputPlugins/oggvorbis_plugin.c
index 70a0ce2d3..d14ae2bac 100644
--- a/src/inputPlugins/oggvorbis_plugin.c
+++ b/src/inputPlugins/oggvorbis_plugin.c
@@ -25,13 +25,7 @@
#include "_ogg_common.h"
#include "../utils.h"
-#include "../audio.h"
#include "../log.h"
-#include "../pcm_utils.h"
-#include "../inputStream.h"
-#include "../outputBuffer.h"
-#include "../replayGain.h"
-#include "../os_compat.h"
#ifndef HAVE_TREMOR
#include <vorbis/vorbisfile.h>
@@ -86,7 +80,7 @@ static int ogg_seek_cb(void *vdata, ogg_int64_t offset, int whence)
}
/* TODO: check Ogg libraries API and see if we can just not have this func */
-static int ogg_close_cb(void *vdata)
+static int ogg_close_cb(mpd_unused void *vdata)
{
return 0;
}
@@ -246,32 +240,32 @@ static int oggvorbis_decode(InputStream * inStream)
callbacks.close_func = ogg_close_cb;
callbacks.tell_func = ogg_tell_cb;
if ((ret = ov_open_callbacks(&data, &vf, NULL, 0, callbacks)) < 0) {
- if (!dc_intr()) {
- switch (ret) {
- case OV_EREAD:
- errorStr = "read error";
- break;
- case OV_ENOTVORBIS:
- errorStr = "not vorbis stream";
- break;
- case OV_EVERSION:
- errorStr = "vorbis version mismatch";
- break;
- case OV_EBADHEADER:
- errorStr = "invalid vorbis header";
- break;
- case OV_EFAULT:
- errorStr = "internal logic error";
- break;
- default:
- errorStr = "unknown error";
- break;
- }
- ERROR("Error decoding Ogg Vorbis stream: %s\n",
- errorStr);
- return -1;
+ if (dc_intr())
+ return 0;
+
+ switch (ret) {
+ case OV_EREAD:
+ errorStr = "read error";
+ break;
+ case OV_ENOTVORBIS:
+ errorStr = "not vorbis stream";
+ break;
+ case OV_EVERSION:
+ errorStr = "vorbis version mismatch";
+ break;
+ case OV_EBADHEADER:
+ errorStr = "invalid vorbis header";
+ break;
+ case OV_EFAULT:
+ errorStr = "internal logic error";
+ break;
+ default:
+ errorStr = "unknown error";
+ break;
}
- return 0;
+
+ ERROR("Error decoding Ogg Vorbis stream: %s\n", errorStr);
+ return -1;
}
dc.total_time = ov_time_total(&vf, -1);
if (dc.total_time < 0)
@@ -368,6 +362,11 @@ static MpdTag *oggvorbis_TagDup(char *file)
static unsigned int oggvorbis_try_decode(InputStream * inStream)
{
+ if (!inStream->seekable)
+ /* we cannot seek after the detection, so don't bother
+ checking */
+ return 1;
+
return (ogg_stream_type_detect(inStream) == VORBIS) ? 1 : 0;
}
diff --git a/src/inputPlugins/wavpack_plugin.c b/src/inputPlugins/wavpack_plugin.c
index 2538be326..c7e024a41 100644
--- a/src/inputPlugins/wavpack_plugin.c
+++ b/src/inputPlugins/wavpack_plugin.c
@@ -23,11 +23,7 @@
#ifdef HAVE_WAVPACK
#include "../utils.h"
-#include "../audio.h"
#include "../log.h"
-#include "../pcm_utils.h"
-#include "../outputBuffer.h"
-#include "../os_compat.h"
#include "../path.h"
#include <wavpack/wavpack.h>
@@ -113,7 +109,8 @@ static void format_samples_int(int Bps, void *buffer, uint32_t samcnt)
/*
* This function converts floating point sample data to 16 bit integer.
*/
-static void format_samples_float(int Bps, void *buffer, uint32_t samcnt)
+static void format_samples_float(mpd_unused int Bps, void *buffer,
+ uint32_t samcnt)
{
int16_t *dst = (int16_t *)buffer;
float *src = (float *)buffer;
@@ -427,86 +424,80 @@ static unsigned int wavpack_trydecode(InputStream *is)
return 1;
}
-/*
- * Decodes a stream.
- */
-static int wavpack_streamdecode(InputStream *is)
+/* wvc being the "correction" file to supplement the original .wv */
+static int wavpack_open_wvc(InputStream *is_wvc)
{
- char error[ERRORLEN];
- WavpackContext *wpc;
- InputStream is_wvc;
- int open_flags = OPEN_2CH_MAX | OPEN_NORMALIZE /*| OPEN_STREAMING*/;
- char *wvc_url = NULL;
- int err;
- InputStreamPlus isp, isp_wvc;
- int canseek;
-
- /* Try to find wvc */
- /* wvc being the "correction" file to supplement the original .wv */
- do {
- char tmp[MPD_PATH_MAX];
- const char *utf8url;
- size_t len;
- err = 1;
+ char wvc_url[MPD_PATH_MAX];
+ size_t len;
- /* This is the only reader of dc.current_song */
- if (!(utf8url = get_song_url(tmp, dc.current_song)))
- break;
+ /* This is the only reader of dc.current_song */
+ if (!get_song_url(wvc_url, dc.current_song))
+ return 0;
- if (!(len = strlen(utf8url)))
- break;
+ len = strlen(wvc_url);
+ if ((len + 2) >= MPD_PATH_MAX)
+ return 0;
- wvc_url = (char *)xmalloc(len + sizeof("c"));
- memcpy(wvc_url, utf8url, len);
- wvc_url[len] = 'c';
- wvc_url[len + 1] = '\0';
+ /* convert the original ".wv" path to a ".wvc" path */
+ assert(wvc_url[len - 3] == '.');
+ assert(wvc_url[len - 2] == 'w' || wvc_url[len - 2] == 'w');
+ assert(wvc_url[len - 1] == 'v' || wvc_url[len - 1] == 'V');
+ assert(wvc_url[len] == '\0');
- if (openInputStream(&is_wvc, wvc_url))
- break;
+ wvc_url[len] = 'c';
+ wvc_url[len + 1] = '\0';
- /*
- * And we try to buffer in order to get know
- * about a possible 404 error.
- */
- for (;;) {
- if (inputStreamAtEOF(&is_wvc)) {
- /*
- * EOF is reached even without
- * a single byte is read...
- * So, this is not good :/
- */
- break;
- }
-
- /* FIXME: replace with future "peek" function */
- if (bufferInputStream(&is_wvc) >= 0) {
- err = 0;
- break;
- }
+ if (openInputStream(is_wvc, wvc_url) < 0) {
+ /* lowercase 'c' didn't work, maybe uppercase... */
+ wvc_url[len] = 'C';
+ if (openInputStream(is_wvc, wvc_url) < 0)
+ return 0;
+ }
- if (dc_intr())
- break;
+ /*
+ * And we try to buffer in order to get know
+ * about a possible 404 error.
+ */
+ for (;;) {
+ if (inputStreamAtEOF(is_wvc))
+ /*
+ * EOF is reached even without
+ * a single byte is read...
+ * So, this is not good :/
+ */
+ break;
- /* Save some CPU */
- my_usleep(1000); /* FIXME: remove */
+ /* FIXME: replace with future "peek" function */
+ if (bufferInputStream(is_wvc) >= 0) {
+ DEBUG("wavpack: got wvc file: %s\n", wvc_url);
+ return 1; /* success */
}
- if (err) {
- closeInputStream(&is_wvc);
+
+ if (dc_intr())
break;
- }
+ /* Save some CPU */
+ my_usleep(1000); /* FIXME: remove */
+ }
- open_flags |= OPEN_WVC;
+ closeInputStream(is_wvc);
+ return 0;
+}
- } while (0);
- canseek = can_seek(&isp);
- if (wvc_url != NULL) {
- if (err) {
- free(wvc_url);
- wvc_url = NULL;
- } else {
- initInputStreamPlus(&isp_wvc, &is_wvc);
- }
+/*
+ * Decodes a stream.
+ */
+static int wavpack_streamdecode(InputStream *is)
+{
+ char error[ERRORLEN];
+ WavpackContext *wpc;
+ InputStream is_wvc;
+ int open_flags = OPEN_2CH_MAX | OPEN_NORMALIZE /*| OPEN_STREAMING*/;
+ InputStreamPlus isp, isp_wvc;
+
+ if (wavpack_open_wvc(&is_wvc)) {
+ initInputStreamPlus(&isp_wvc, &is_wvc);
+ open_flags |= OPEN_WVC;
}
initInputStreamPlus(&isp, is);
@@ -515,17 +506,16 @@ static int wavpack_streamdecode(InputStream *is)
if (wpc == NULL) {
ERROR("failed to open WavPack stream: %s\n", error);
+ if (open_flags & OPEN_WVC)
+ closeInputStream(&is_wvc);
return -1;
}
- wavpack_decode(wpc, canseek, NULL);
+ wavpack_decode(wpc, can_seek(&isp), NULL);
WavpackCloseFile(wpc);
- if (wvc_url != NULL) {
+ if (open_flags & OPEN_WVC)
closeInputStream(&is_wvc);
- free(wvc_url);
- }
- closeInputStream(is);
return 0;
}
diff --git a/src/inputStream_file.c b/src/inputStream_file.c
index fb433d380..2e51e3f6c 100644
--- a/src/inputStream_file.c
+++ b/src/inputStream_file.c
@@ -106,7 +106,7 @@ int inputStream_fileAtEOF(InputStream * inStream)
return 0;
}
-int inputStream_fileBuffer(InputStream * inStream)
+int inputStream_fileBuffer(mpd_unused InputStream * inStream)
{
return 0;
}
diff --git a/src/inputStream_http.c b/src/inputStream_http.c
index a6c715459..8802eda2b 100644
--- a/src/inputStream_http.c
+++ b/src/inputStream_http.c
@@ -461,7 +461,7 @@ static ssize_t buffer_data(InputStream *is)
assert(pthread_equal(data->io_thread, pthread_self()));
assert_state2(CONN_STATE_BUFFER, CONN_STATE_PREBUFFER);
- if (!ringbuf_get_write_vector(data->rb, vec)) {
+ if (!ringbuf_get_write_vector(data->rb, (struct rbvec *)vec)) {
data->state = CONN_STATE_BUFFER_FULL;
return 0;
}
@@ -750,7 +750,7 @@ closed:
return NULL;
}
-int inputStream_httpBuffer(InputStream *is)
+int inputStream_httpBuffer(mpd_unused InputStream *is)
{
return 0;
}
@@ -847,7 +847,8 @@ static void parse_icy_metadata(InputStream * is, char *metadata, size_t size)
}
}
-static size_t read_with_metadata(InputStream *is, void *ptr, ssize_t len)
+static size_t read_with_metadata(InputStream *is, unsigned char *ptr,
+ ssize_t len)
{
struct http_data *data = (struct http_data *) is->data;
size_t readed = 0;
@@ -887,13 +888,13 @@ static size_t read_with_metadata(InputStream *is, void *ptr, ssize_t len)
return readed;
}
-size_t inputStream_httpRead(InputStream * is, void *ptr, size_t size,
+size_t inputStream_httpRead(InputStream * is, void *_ptr, size_t size,
size_t nmemb)
{
struct http_data *data = (struct http_data *) is->data;
size_t len = size * nmemb;
size_t r;
- void *ptr0 = ptr;
+ unsigned char *ptr = _ptr, *ptr0 = _ptr;
long tries = len / 128; /* try harder for bigger reads */
retry:
diff --git a/src/interface.c b/src/interface.c
index 45b81a2f7..83e0084b5 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -234,7 +234,7 @@ static void closeInterface(Interface * interface)
SECURE("interface %i: closed\n", interface->num);
}
-void openAInterface(int fd, struct sockaddr *addr)
+void openAInterface(int fd, const struct sockaddr *addr)
{
unsigned int i;
@@ -249,7 +249,7 @@ void openAInterface(int fd, struct sockaddr *addr)
switch (addr->sa_family) {
#ifdef HAVE_TCP
case AF_INET:
- hostname = (const char *)inet_ntoa(((struct sockaddr_in *)
+ hostname = (const char *)inet_ntoa(((const struct sockaddr_in *)
addr)->sin_addr);
if (!hostname)
hostname = "error getting ipv4 address";
@@ -259,8 +259,8 @@ void openAInterface(int fd, struct sockaddr *addr)
{
static char host[INET6_ADDRSTRLEN + 1];
memset(host, 0, INET6_ADDRSTRLEN + 1);
- if (inet_ntop(AF_INET6, (void *)
- &(((struct sockaddr_in6 *)addr)->
+ if (inet_ntop(AF_INET6, (const void *)
+ &(((const struct sockaddr_in6 *)addr)->
sin6_addr), host,
INET6_ADDRSTRLEN)) {
hostname = (const char *)host;
@@ -686,7 +686,7 @@ static void flushInterfaceBuffer(Interface * interface)
}
}
-int interfacePrintWithFD(int fd, char *buffer, size_t buflen)
+int interfacePrintWithFD(int fd, const char *buffer, size_t buflen)
{
static unsigned int i;
size_t copylen;
diff --git a/src/interface.h b/src/interface.h
index a364f7922..c83381319 100644
--- a/src/interface.h
+++ b/src/interface.h
@@ -22,10 +22,10 @@
#include "os_compat.h"
void initInterfaces(void);
-void openAInterface(int fd, struct sockaddr *addr);
+void openAInterface(int fd, const struct sockaddr *addr);
void freeAllInterfaces(void);
void closeOldInterfaces(void);
-int interfacePrintWithFD(int fd, char *buffer, size_t len);
+int interfacePrintWithFD(int fd, const char *buffer, size_t len);
int doIOForInterfaces(void);
diff --git a/src/locate.c b/src/locate.c
index d97097f37..f68afdedb 100644
--- a/src/locate.c
+++ b/src/locate.c
@@ -121,7 +121,7 @@ void freeLocateTagItem(LocateTagItem * item)
free(item);
}
-static int strstrSearchTag(Song * song, int type, char *str)
+static int strstrSearchTag(Song * song, enum tag_type type, char *str)
{
int i;
char *duplicate;
@@ -169,7 +169,7 @@ int strstrSearchTags(Song * song, int numItems, LocateTagItem * items)
return 1;
}
-static int tagItemFoundAndMatches(Song * song, int type, char *str)
+static int tagItemFoundAndMatches(Song * song, enum tag_type type, char *str)
{
int i;
diff --git a/src/locate.h b/src/locate.h
index 28b2782b0..325ae384d 100644
--- a/src/locate.h
+++ b/src/locate.h
@@ -16,6 +16,9 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#ifndef LOCATE_H
+#define LOCATE_H
+
#include "song.h"
#define LOCATE_TAG_FILE_TYPE TAG_NUM_OF_ITEM_TYPES+10
@@ -44,3 +47,5 @@ void freeLocateTagItem(LocateTagItem * item);
int strstrSearchTags(Song * song, int numItems, LocateTagItem * items);
int tagItemsFoundAndMatches(Song * song, int numItems, LocateTagItem * items);
+
+#endif
diff --git a/src/ls.c b/src/ls.c
index 3032935c6..f87e09fdb 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -42,10 +42,10 @@ int printRemoteUrlHandlers(int fd)
return 0;
}
-int isValidRemoteUtf8Url(char *utf8url)
+int isValidRemoteUtf8Url(const char *utf8url)
{
int ret = 0;
- char *temp;
+ const char *temp;
switch (isRemoteUrl(utf8url)) {
case 1:
@@ -82,7 +82,7 @@ int isValidRemoteUtf8Url(char *utf8url)
return ret;
}
-int isRemoteUrl(char *url)
+int isRemoteUrl(const char *url)
{
int count = 0;
const char **urlPrefixes = remoteUrlPrefixes;
diff --git a/src/ls.h b/src/ls.h
index ed49c99d8..ce4f94b56 100644
--- a/src/ls.h
+++ b/src/ls.h
@@ -25,9 +25,9 @@ int lsPlaylists(int fd, const char *utf8path);
const char *getSuffix(const char *utf8file);
-int isValidRemoteUtf8Url(char *utf8url);
+int isValidRemoteUtf8Url(const char *utf8url);
-int isRemoteUrl(char *url);
+int isRemoteUrl(const char *url);
int myStat(const char *utf8file, struct stat *st);
diff --git a/src/main.c b/src/main.c
index e897cacc1..9d75fadc7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -35,7 +35,6 @@
#include "inputStream.h"
#include "state_file.h"
#include "tag.h"
-#include "tagTracker.h"
#include "dbUtils.h"
#include "../config.h"
#include "utils.h"
@@ -352,7 +351,7 @@ static void cleanUpPidFile(void)
unlink(pidFileParam->value);
}
-static void killFromPidFile(char *cmd, int killOption)
+static void killFromPidFile(void)
{
FILE *fp;
ConfigParam *pidFileParam = parseConfigFilePath(CONF_PID_FILE, 0);
@@ -391,7 +390,7 @@ int main(int argc, char *argv[])
parseOptions(argc, argv, &options);
if (options.kill)
- killFromPidFile(argv[0], options.kill);
+ killFromPidFile();
initStats();
initTagConfig();
diff --git a/src/normalize.h b/src/normalize.h
index 8356b2a7c..81c9c81c4 100644
--- a/src/normalize.h
+++ b/src/normalize.h
@@ -19,7 +19,7 @@
#ifndef NORMALIZE_H
#define NORMALIZE_H
-#include "audio.h"
+#include "audio_format.h"
extern int normalizationEnabled;
diff --git a/src/outputBuffer.c b/src/outputBuffer.c
index 0adf570f7..8a41924db 100644
--- a/src/outputBuffer.c
+++ b/src/outputBuffer.c
@@ -27,6 +27,7 @@
#include "player_error.h"
#include "log.h"
#include "action_status.h"
+#include "decode.h"
/* typically have 2048-4096 of these structs, so pack tightly */
struct ob_chunk {
@@ -152,7 +153,7 @@ static enum action_status ob_finalize_action(void)
/* marks all buffered chunks with sequence number matching `seq' as invalid */
static enum action_status ob_do_drop(void)
{
- struct iovec vec[2];
+ struct rbvec vec[2];
long i;
mpd_uint8 seq_drop;
@@ -190,7 +191,7 @@ static enum action_status ob_do_pause(void)
static void reader_reset_buffer(void)
{
- struct iovec vec[2];
+ struct rbvec vec[2];
size_t nr;
long i;
@@ -330,15 +331,15 @@ static enum action_status ob_take_action(void)
* like an infinite, rotating buffer. The first available chunk
* is always indexed as `0', the second one as `1', and so on...
*/
-static struct ob_chunk *get_chunk(struct iovec vec[2], size_t i)
+static struct ob_chunk *get_chunk(struct rbvec vec[2], size_t i)
{
- if (vec[0].iov_len > i)
- return &ob.chunks[vec[0].iov_base + i - ob.index->buf];
- if (i && vec[1].iov_base) {
- assert(vec[0].iov_len > 0);
- i -= vec[0].iov_len;
- if (vec[1].iov_len > i)
- return &ob.chunks[vec[1].iov_base + i - ob.index->buf];
+ if (vec[0].len > i)
+ return &ob.chunks[vec[0].base + i - ob.index->buf];
+ if (i && vec[1].base) {
+ assert(vec[0].len > 0);
+ i -= vec[0].len;
+ if (vec[1].len > i)
+ return &ob.chunks[vec[1].base + i - ob.index->buf];
}
return NULL;
}
@@ -426,7 +427,7 @@ static void send_next_tag(void)
static void play_next_chunk(void)
{
- struct iovec vec[2];
+ struct rbvec vec[2];
struct ob_chunk *a;
size_t nr;
static float last_time;
@@ -551,7 +552,7 @@ void ob_seek_finish(void)
*/
void ob_flush(void)
{
- struct iovec vec[2];
+ struct rbvec vec[2];
assert(pthread_equal(pthread_self(), dc.thread));
/* DEBUG(__FILE__":%s %d\n", __func__, __LINE__); */
diff --git a/src/outputBuffer.h b/src/outputBuffer.h
index 15e46da60..3fc440af3 100644
--- a/src/outputBuffer.h
+++ b/src/outputBuffer.h
@@ -21,7 +21,6 @@
#include "pcm_utils.h"
#include "mpd_types.h"
-#include "decode.h"
#include "inputStream.h"
#include "replayGain.h"
diff --git a/src/outputBuffer_ob_send.h b/src/outputBuffer_ob_send.h
index 2a4a84763..d2c99b3f2 100644
--- a/src/outputBuffer_ob_send.h
+++ b/src/outputBuffer_ob_send.h
@@ -63,7 +63,7 @@ enum dc_action
ob_send(void *data, size_t len,
float decode_time, mpd_uint16 bit_rate, ReplayGainInfo * rgi)
{
- struct iovec vec[2];
+ struct rbvec vec[2];
struct ob_chunk *c;
size_t idx;
size_t i, j;
@@ -86,9 +86,9 @@ ob_send(void *data, size_t len,
}
for (i = 0; i < ARRAY_SIZE(vec); i++) {
- for (j = 0; j < vec[i].iov_len; j++) {
+ for (j = 0; j < vec[i].len; j++) {
size_t c_len;
- idx = vec[i].iov_base - ob.index->buf + j;
+ idx = vec[i].base - ob.index->buf + j;
c = &(ob.chunks[idx]);
if (!c->len) { /* populate empty chunk */
diff --git a/src/outputBuffer_xfade.h b/src/outputBuffer_xfade.h
index 336a7adc2..70e490c65 100644
--- a/src/outputBuffer_xfade.h
+++ b/src/outputBuffer_xfade.h
@@ -5,8 +5,8 @@
#include "audio.h"
#include "pcm_utils.h"
-static struct ob_chunk *get_chunk(struct iovec vec[2], size_t i);
-static size_t calculate_xfade_chunks(struct iovec vec[2])
+static struct ob_chunk *get_chunk(struct rbvec vec[2], size_t i);
+static size_t calculate_xfade_chunks(struct rbvec vec[2])
{
float xfade_time = ob.xfade_time; /* prevent race conditions */
size_t chunks;
@@ -29,7 +29,7 @@ static size_t calculate_xfade_chunks(struct iovec vec[2])
assert(af->channels > 0);
assert(af->sampleRate > 0);
- chunks = af->sampleRate * af->bits * af->channels / 8.0 / CHUNK_SIZE;
+ chunks = audio_format_time_to_size(af) / CHUNK_SIZE;
chunks = chunks * (xfade_time + 0.5);
assert(chunks);
@@ -37,7 +37,7 @@ static size_t calculate_xfade_chunks(struct iovec vec[2])
if (chunks > (ob.index->size - ob.bpp_cur))
chunks = ob.index->size - ob.bpp_cur;
DEBUG("calculated xfade chunks: %d\n", chunks);
- nr = vec[0].iov_len + vec[1].iov_len;
+ nr = vec[0].len + vec[1].len;
if (chunks <= nr) {
c = get_chunk(vec, chunks);
@@ -64,7 +64,7 @@ static size_t calculate_xfade_chunks(struct iovec vec[2])
return chunks;
}
-static size_t xfade_chunks_needed(struct iovec vec[2])
+static size_t xfade_chunks_needed(struct rbvec vec[2])
{
assert(pthread_equal(ob.thread, pthread_self()));
diff --git a/src/pcm_utils.c b/src/pcm_utils.c
index 3cf57def1..f716c279d 100644
--- a/src/pcm_utils.c
+++ b/src/pcm_utils.c
@@ -258,9 +258,11 @@ static size_t pcm_convertSampleRate(mpd_sint8 channels, mpd_uint32 inSampleRate,
#else /* !HAVE_LIBSAMPLERATE */
/* resampling code blatantly ripped from ESD */
static size_t pcm_convertSampleRate(mpd_sint8 channels, mpd_uint32 inSampleRate,
- const char *inBuffer, size_t inSize,
+ const char *inBuffer,
+ mpd_unused size_t inSize,
mpd_uint32 outSampleRate, char *outBuffer,
- size_t outSize, ConvState *convState)
+ size_t outSize,
+ mpd_unused ConvState *convState)
{
mpd_uint32 rd_dat = 0;
mpd_uint32 wr_dat = 0;
diff --git a/src/pcm_utils.h b/src/pcm_utils.h
index 53d268db7..2ecb56201 100644
--- a/src/pcm_utils.h
+++ b/src/pcm_utils.h
@@ -21,7 +21,7 @@
#include "../config.h"
-#include "audio.h"
+#include "audio_format.h"
#include "os_compat.h"
#ifdef HAVE_LIBSAMPLERATE
diff --git a/src/playlist.c b/src/playlist.c
index 9751eda76..0512951fd 100644
--- a/src/playlist.c
+++ b/src/playlist.c
@@ -94,7 +94,7 @@ static pthread_mutex_t queue_lock = PTHREAD_MUTEX_INITIALIZER;
int playlist_saveAbsolutePaths = DEFAULT_PLAYLIST_SAVE_ABSOLUTE_PATHS;
static void swapOrder(int a, int b);
-static int play_order_num(int fd, int order_num, float seek_time);
+static void play_order_num(int order_num, float seek_time);
static void randomizeOrder(int start, int end);
static void incrPlaylistVersion(void)
@@ -219,12 +219,11 @@ void finishPlaylist(void)
playlist.positionToId = NULL;
}
-int clearPlaylist(int fd)
+void clearPlaylist(void)
{
int i;
- if (stopPlaylist(fd) < 0)
- return -1;
+ stopPlaylist();
for (i = 0; i < playlist.length; i++) {
if (playlist.songs[i]->type == SONG_TYPE_URL) {
@@ -237,8 +236,6 @@ int clearPlaylist(int fd)
playlist.current = -1;
incrPlaylistVersion();
-
- return 0;
}
int clearStoredPlaylist(int fd, char *utf8file)
@@ -834,9 +831,9 @@ int deleteFromPlaylist(int fd, int song)
if (stop_current) {
/* DEBUG(__FILE__": %d\n", __LINE__); */
if (playlist.current >= 0 && songOrder > 0)
- play_order_num(fd, playlist.current, 0);
+ play_order_num(playlist.current, 0);
else
- stopPlaylist(fd);
+ stopPlaylist();
} else {
/* DEBUG(__FILE__": %d\n", __LINE__); */
queueNextSongInPlaylist();
@@ -866,7 +863,7 @@ void deleteASongFromPlaylist(Song * song)
}
}
-int stopPlaylist(int fd)
+void stopPlaylist(void)
{
DEBUG("playlist: stop\n");
@@ -883,10 +880,9 @@ int stopPlaylist(int fd)
playlist_state = PLAYLIST_STATE_STOP;
if (playlist.random)
randomizeOrder(0, playlist.length - 1);
- return 0;
}
-static int play_order_num(int fd, int order_num, float seek_time)
+static void play_order_num(int order_num, float seek_time)
{
char path[MPD_PATH_MAX];
enum dc_action action = seek_time ? DC_ACTION_SEEK : DC_ACTION_START;
@@ -906,8 +902,6 @@ static int play_order_num(int fd, int order_num, float seek_time)
dc_trigger_action(action, seek_time);
if (dc.seek_where >= 0)
playlist.current = order_num;
-
- return 0;
}
int playPlaylist(int fd, int song, int stopOnError)
@@ -954,7 +948,8 @@ int playPlaylist(int fd, int song, int stopOnError)
ERROR(__FILE__ ": %d current:%d\n", __LINE__, playlist.current);
ob_trigger_action(OB_ACTION_PAUSE_UNSET);
- return play_order_num(fd, i, 0);
+ play_order_num(i, 0);
+ return 0;
}
int playPlaylistById(int fd, int id, int stopOnError)
@@ -1015,20 +1010,21 @@ void syncPlayerAndPlaylist(void)
}
}
-int nextSongInPlaylist(int fd)
+void nextSongInPlaylist(void)
{
int next;
if (playlist_state != PLAYLIST_STATE_PLAY)
- return 0;
+ return;
playlist_stopOnError = 0;
next = next_order_num();
if (next < 0) {
/* we were already at last song w/o repeat: */
incrPlaylistCurrent();
- return stopPlaylist(fd);
+ stopPlaylist();
+ return;
}
ob_trigger_action(OB_ACTION_PAUSE_UNSET);
- return play_order_num(fd, next, 0);
+ play_order_num(next, 0);
}
int getPlaylistRepeatStatus(void)
@@ -1234,7 +1230,7 @@ int setPlaylistRandomStatus(int fd, int status)
return 0;
}
-int previousSongInPlaylist(int fd)
+void previousSongInPlaylist(void)
{
static time_t lastTime;
time_t diff = time(NULL) - lastTime;
@@ -1243,7 +1239,7 @@ int previousSongInPlaylist(int fd)
lastTime += diff;
if (playlist_state != PLAYLIST_STATE_PLAY)
- return 0;
+ return;
syncPlaylistWithQueue();
@@ -1258,10 +1254,10 @@ int previousSongInPlaylist(int fd)
prev_order_num = playlist.current;
}
ob_trigger_action(OB_ACTION_PAUSE_UNSET);
- return play_order_num(fd, prev_order_num, 0);
+ play_order_num(prev_order_num, 0);
}
-int shufflePlaylist(int fd)
+int shufflePlaylist(mpd_unused int fd)
{
int i;
int ri;
@@ -1419,7 +1415,7 @@ int seekSongInPlaylist(int fd, int song, float seek_time)
}
DEBUG("playlist: seek %i:\"%s\"\n", i, get_song_url(path, song_at(i)));
- play_order_num(fd, i, seek_time);
+ play_order_num(i, seek_time);
return 0;
}
diff --git a/src/playlist.h b/src/playlist.h
index 2ba28f9e4..0bcc9680a 100644
--- a/src/playlist.h
+++ b/src/playlist.h
@@ -19,7 +19,7 @@
#ifndef PLAYLIST_H
#define PLAYLIST_H
-#include "dbUtils.h"
+#include "locate.h"
#define PLAYLIST_FILE_SUFFIX "m3u"
#define PLAYLIST_COMMENT '#'
@@ -36,7 +36,7 @@ void readPlaylistState(FILE *);
void savePlaylistState(FILE *);
-int clearPlaylist(int fd);
+void clearPlaylist(void);
int clearStoredPlaylist(int fd, char *utf8file);
@@ -62,17 +62,17 @@ void playlist_queue_next(void);
int playlist_playing(void);
-int stopPlaylist(int fd);
+void stopPlaylist(void);
int playPlaylist(int fd, int song, int stopOnError);
int playPlaylistById(int fd, int song, int stopOnError);
-int nextSongInPlaylist(int fd);
+void nextSongInPlaylist(void);
void syncPlayerAndPlaylist(void);
-int previousSongInPlaylist(int fd);
+void previousSongInPlaylist(void);
int shufflePlaylist(int fd);
diff --git a/src/replayGain.h b/src/replayGain.h
index 8df6fb0b1..8282da785 100644
--- a/src/replayGain.h
+++ b/src/replayGain.h
@@ -20,7 +20,7 @@
#ifndef REPLAYGAIN_H
#define REPLAYGAIN_H
-#include "audio.h"
+#include "audio_format.h"
#define REPLAYGAIN_OFF 0
#define REPLAYGAIN_TRACK 1
diff --git a/src/ringbuf.c b/src/ringbuf.c
index ed46c3beb..ec388abf3 100644
--- a/src/ringbuf.c
+++ b/src/ringbuf.c
@@ -36,7 +36,7 @@ struct ringbuf *ringbuf_create(size_t sz)
struct ringbuf *rb = xmalloc(sizeof(struct ringbuf));
size_t power_of_two;
- for (power_of_two = 1; 1 << power_of_two < sz; power_of_two++)
+ for (power_of_two = 1; (size_t)(1 << power_of_two) < sz; power_of_two++)
/* next power_of_two... */;
rb->size = 1 << power_of_two;
@@ -137,7 +137,7 @@ size_t ringbuf_read(struct ringbuf * rb, void *dest, size_t cnt)
ringbuf_read_advance(rb, n1);
if (n2) {
- memcpy(dest + n1, rb->buf + rb->read_ptr, n2);
+ memcpy((char*)dest + n1, rb->buf + rb->read_ptr, n2);
ringbuf_read_advance(rb, n2);
}
@@ -175,7 +175,7 @@ size_t ringbuf_peek(struct ringbuf * rb, void *dest, size_t cnt)
advance_ptr(tmp_read_ptr, n1, rb->size_mask);
if (n2) {
- memcpy(dest + n1, rb->buf + tmp_read_ptr, n2);
+ memcpy((char*)dest + n1, rb->buf + tmp_read_ptr, n2);
advance_ptr(tmp_read_ptr, n2, rb->size_mask);
}
@@ -211,7 +211,7 @@ size_t ringbuf_write(struct ringbuf * rb, const void *src, size_t cnt)
ringbuf_write_advance(rb, n1);
if (n2) {
- memcpy(rb->buf + rb->write_ptr, src + n1, n2);
+ memcpy(rb->buf + rb->write_ptr, (const char*)src + n1, n2);
ringbuf_write_advance(rb, n2);
}
@@ -236,7 +236,7 @@ void ringbuf_write_advance(struct ringbuf * rb, size_t cnt)
* the readable data is in one segment the second segment has zero
* length.
*/
-size_t ringbuf_get_read_vector(const struct ringbuf * rb, struct iovec * vec)
+size_t ringbuf_get_read_vector(const struct ringbuf * rb, struct rbvec * vec)
{
size_t free_cnt;
size_t cnt2;
@@ -255,17 +255,17 @@ size_t ringbuf_get_read_vector(const struct ringbuf * rb, struct iovec * vec)
* Two part vector: the rest of the buffer after the current
* write ptr, plus some from the start of the buffer.
*/
- vec[0].iov_base = rb->buf + r;
- vec[0].iov_len = rb->size - r;
- vec[1].iov_base = rb->buf;
- vec[1].iov_len = cnt2 & rb->size_mask;
+ vec[0].base = rb->buf + r;
+ vec[0].len = rb->size - r;
+ vec[1].base = rb->buf;
+ vec[1].len = cnt2 & rb->size_mask;
} else {
/* Single part vector: just the rest of the buffer */
- vec[0].iov_base = rb->buf + r;
- vec[0].iov_len = free_cnt;
- vec[1].iov_len = 0;
+ vec[0].base = rb->buf + r;
+ vec[0].len = free_cnt;
+ vec[1].len = 0;
}
- return vec[0].iov_len + vec[1].iov_len;
+ return vec[0].len + vec[1].len;
}
/*
@@ -274,7 +274,7 @@ size_t ringbuf_get_read_vector(const struct ringbuf * rb, struct iovec * vec)
* the writeable data is in one segment the second segment has zero
* length.
*/
-size_t ringbuf_get_write_vector(const struct ringbuf * rb, struct iovec * vec)
+size_t ringbuf_get_write_vector(const struct ringbuf * rb, struct rbvec * vec)
{
size_t free_cnt;
size_t cnt2;
@@ -295,15 +295,15 @@ size_t ringbuf_get_write_vector(const struct ringbuf * rb, struct iovec * vec)
* Two part vector: the rest of the buffer after the current
* write ptr, plus some from the start of the buffer.
*/
- vec[0].iov_base = rb->buf + w;
- vec[0].iov_len = rb->size - w;
- vec[1].iov_base = rb->buf;
- vec[1].iov_len = cnt2 & rb->size_mask;
+ vec[0].base = rb->buf + w;
+ vec[0].len = rb->size - w;
+ vec[1].base = rb->buf;
+ vec[1].len = cnt2 & rb->size_mask;
} else {
- vec[0].iov_base = rb->buf + w;
- vec[0].iov_len = free_cnt;
- vec[1].iov_len = 0;
+ vec[0].base = rb->buf + w;
+ vec[0].len = free_cnt;
+ vec[1].len = 0;
}
- return vec[0].iov_len + vec[1].iov_len;
+ return vec[0].len + vec[1].len;
}
diff --git a/src/ringbuf.h b/src/ringbuf.h
index 43ba83a7c..6225fcadf 100644
--- a/src/ringbuf.h
+++ b/src/ringbuf.h
@@ -39,13 +39,19 @@
*/
struct ringbuf {
- void *buf;
+ unsigned char *buf;
size_t write_ptr;
size_t read_ptr;
size_t size;
size_t size_mask;
};
+/* remain binary-compatible with struct iovec declared in <sys/uio.h>: */
+struct rbvec {
+ unsigned char *base;
+ size_t len;
+};
+
/**
* Allocates a ringbuffer data structure of a specified size. The
* caller must arrange for a call to ringbuf_free() to release
@@ -69,7 +75,7 @@ void ringbuf_free(struct ringbuf * rb);
/**
* Fill a data structure with a description of the current readable
* data held in the ringbuffer. This description is returned in a two
- * element array of struct iovec. Two elements are needed
+ * element array of struct rbvec. Two elements are needed
* because the data to be read may be split across the end of the
* ringbuffer.
*
@@ -83,16 +89,16 @@ void ringbuf_free(struct ringbuf * rb);
* its corresponding @a buf field.
*
* @param rb a pointer to the ringbuffer structure.
- * @param vec a pointer to a 2 element array of struct iovec.
+ * @param vec a pointer to a 2 element array of struct rbvec.
*
* @return total number of bytes readable into both vec elements
*/
-size_t ringbuf_get_read_vector(const struct ringbuf * rb, struct iovec * vec);
+size_t ringbuf_get_read_vector(const struct ringbuf * rb, struct rbvec * vec);
/**
* Fill a data structure with a description of the current writable
* space in the ringbuffer. The description is returned in a two
- * element array of struct iovec. Two elements are needed
+ * element array of struct rbvec. Two elements are needed
* because the space available for writing may be split across the end
* of the ringbuffer.
*
@@ -106,11 +112,11 @@ size_t ringbuf_get_read_vector(const struct ringbuf * rb, struct iovec * vec);
* the corresponding @a buf field.
*
* @param rb a pointer to the ringbuffer structure.
- * @param vec a pointer to a 2 element array of struct iovec.
+ * @param vec a pointer to a 2 element array of struct rbvec.
*
* @return total number of bytes writable in both vec elements
*/
-size_t ringbuf_get_write_vector(const struct ringbuf * rb, struct iovec * vec);
+size_t ringbuf_get_write_vector(const struct ringbuf * rb, struct rbvec * vec);
/**
* Read data from the ringbuffer.
diff --git a/src/sig_handlers.c b/src/sig_handlers.c
index 0ad35b779..6b28cb675 100644
--- a/src/sig_handlers.c
+++ b/src/sig_handlers.c
@@ -23,7 +23,6 @@
#include "command.h"
#include "signal_check.h"
#include "log.h"
-#include "decode.h"
int handlePendingSignals(void)
{
@@ -46,7 +45,7 @@ int handlePendingSignals(void)
return 0;
}
-static void chldSigHandler(int sig)
+static void chldSigHandler(mpd_unused int sig)
{
int status;
int pid;
diff --git a/src/sllist.c b/src/sllist.c
index cfe392d60..0f4529fd3 100644
--- a/src/sllist.c
+++ b/src/sllist.c
@@ -34,22 +34,22 @@ struct strnode *new_strnode(char *s)
return x;
}
-struct strnode *new_strnode_dup(char *s, const size_t size)
+struct strnode *new_strnode_dup(const char *s, const size_t size)
{
struct strnode *x = xmalloc(sizeof(struct strnode) + size);
x->next = NULL;
x->data = ((char *)x + sizeof(struct strnode));
- memcpy((void *)x->data, (void*)s, size);
+ memcpy((void *)x->data, (const void*)s, size);
return x;
}
-struct sllnode *new_sllnode(void *s, const size_t size)
+struct sllnode *new_sllnode(const void *s, const size_t size)
{
struct sllnode *x = xmalloc(sizeof(struct sllnode) + size);
x->next = NULL;
x->size = size;
x->data = ((char *)x + sizeof(struct sllnode));
- memcpy(x->data, (void *)s, size);
+ memcpy(x->data, (const void *)s, size);
return x;
}
diff --git a/src/sllist.h b/src/sllist.h
index ba7d8ea95..e8cb8805d 100644
--- a/src/sllist.h
+++ b/src/sllist.h
@@ -42,11 +42,11 @@ struct sllnode {
struct strnode *new_strnode(char *s);
-struct strnode *new_strnode_dup(char *s, const size_t size);
+struct strnode *new_strnode_dup(const char *s, const size_t size);
struct strnode *dup_strlist(struct strnode *old);
-struct sllnode *new_sllnode(void *s, const size_t size);
+struct sllnode *new_sllnode(const void *s, const size_t size);
#endif /* SLLIST_H */
diff --git a/src/song.c b/src/song.c
index a8ab4284f..cc1547d10 100644
--- a/src/song.c
+++ b/src/song.c
@@ -315,6 +315,9 @@ char *get_song_url(char *path_max_tmp, Song *song)
{
if (!song)
return NULL;
+
+ assert(song->url != NULL);
+
if (!song->parentDir || !song->parentDir->path)
strcpy(path_max_tmp, song->url);
else
diff --git a/src/tag.c b/src/tag.c
index 5023a58cb..c1ccd0a42 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -25,7 +25,6 @@
#include "charConv.h"
#include "tagTracker.h"
#include "song.h"
-#include "os_compat.h"
#ifdef HAVE_ID3TAG
# define isId3v1(tag) (id3_tag_options(tag, 0, 0) & ID3_TAG_OPTION_ID3V1)
@@ -606,7 +605,7 @@ static void deleteItem(MpdTag * tag, int idx)
}
}
-void clearItemsFromMpdTag(MpdTag * tag, int type)
+void clearItemsFromMpdTag(MpdTag * tag, enum tag_type type)
{
int i;
@@ -697,9 +696,10 @@ int mpdTagsAreEqual(MpdTag * tag1, MpdTag * tag2)
} \
}
-static void appendToTagItems(MpdTag * tag, int type, char *value, int len)
+static void appendToTagItems(MpdTag * tag, enum tag_type type,
+ const char *value, size_t len)
{
- int i = tag->numOfItems;
+ unsigned int i = tag->numOfItems;
char *duplicated = xmalloc(len + 1);
memcpy(duplicated, value, len);
@@ -717,7 +717,8 @@ static void appendToTagItems(MpdTag * tag, int type, char *value, int len)
free(duplicated);
}
-void addItemToMpdTagWithLen(MpdTag * tag, int itemType, char *value, int len)
+void addItemToMpdTagWithLen(MpdTag * tag, enum tag_type itemType,
+ const char *value, size_t len)
{
if (ignoreTagItems[itemType])
{
diff --git a/src/tag.h b/src/tag.h
index 363ad98aa..a9bf19934 100644
--- a/src/tag.h
+++ b/src/tag.h
@@ -22,29 +22,31 @@
#include "../config.h"
#include "mpd_types.h"
+#include "os_compat.h"
#ifdef HAVE_ID3TAG
#include <id3tag.h>
#endif
-#define TAG_ITEM_ARTIST 0
-#define TAG_ITEM_ALBUM 1
-#define TAG_ITEM_TITLE 2
-#define TAG_ITEM_TRACK 3
-#define TAG_ITEM_NAME 4
-#define TAG_ITEM_GENRE 5
-#define TAG_ITEM_DATE 6
-#define TAG_ITEM_COMPOSER 7
-#define TAG_ITEM_PERFORMER 8
-#define TAG_ITEM_COMMENT 9
-#define TAG_ITEM_DISC 10
-
-#define TAG_NUM_OF_ITEM_TYPES 11
+enum tag_type {
+ TAG_ITEM_ARTIST,
+ TAG_ITEM_ALBUM,
+ TAG_ITEM_TITLE,
+ TAG_ITEM_TRACK,
+ TAG_ITEM_NAME,
+ TAG_ITEM_GENRE,
+ TAG_ITEM_DATE,
+ TAG_ITEM_COMPOSER,
+ TAG_ITEM_PERFORMER,
+ TAG_ITEM_COMMENT,
+ TAG_ITEM_DISC,
+ TAG_NUM_OF_ITEM_TYPES
+};
extern const char *mpdTagItemKeys[];
typedef struct _MpdTagItem {
- mpd_sint8 type;
+ enum tag_type type;
char *value;
} MpdTagItem;
@@ -66,11 +68,12 @@ MpdTag *newMpdTag(void);
void initTagConfig(void);
-void clearItemsFromMpdTag(MpdTag * tag, int itemType);
+void clearItemsFromMpdTag(MpdTag * tag, enum tag_type itemType);
void freeMpdTag(MpdTag * tag);
-void addItemToMpdTagWithLen(MpdTag * tag, int itemType, char *value, int len);
+void addItemToMpdTagWithLen(MpdTag * tag, enum tag_type itemType,
+ const char *value, size_t len);
#define addItemToMpdTag(tag, itemType, value) \
addItemToMpdTagWithLen(tag, itemType, value, strlen(value))
diff --git a/src/tagTracker.c b/src/tagTracker.c
index acc8a4d2e..892cc2955 100644
--- a/src/tagTracker.c
+++ b/src/tagTracker.c
@@ -117,7 +117,7 @@ void resetVisitedFlagsInTagTracker(int type)
}
}
-void visitInTagTracker(int type, char *str)
+void visitInTagTracker(int type, const char *str)
{
TreeIterator iter;
diff --git a/src/tagTracker.h b/src/tagTracker.h
index 17958f3af..84506426e 100644
--- a/src/tagTracker.h
+++ b/src/tagTracker.h
@@ -29,7 +29,7 @@ void printMemorySavedByTagTracker(void);
void resetVisitedFlagsInTagTracker(int type);
-void visitInTagTracker(int type, char *str);
+void visitInTagTracker(int type, const char *str);
void printVisitedInTagTracker(int fd, int type);
diff --git a/src/timer.h b/src/timer.h
index c8018e260..6851a1535 100644
--- a/src/timer.h
+++ b/src/timer.h
@@ -19,8 +19,8 @@
#ifndef MPD_TIMER_H
#define MPD_TIMER_H
-#include "audio.h"
-#include "mpd_types.h"
+#include "audio_format.h"
+#include "os_compat.h"
typedef struct _Timer {
uint64_t time;
diff --git a/src/tree.c b/src/tree.c
index 4b212cca6..d583aee7c 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -71,7 +71,7 @@ _ClearKeyData(TreeKeyData * keyData)
static
int
-_FindPosition(Tree * tree, TreeNode * node, void * key, int * pos)
+_FindPosition(Tree * tree, TreeNode * node, const void * key, int * pos)
{
#ifdef USE_BINARY_SEARCH
int low = 0;
@@ -113,7 +113,7 @@ _FindPosition(Tree * tree, TreeNode * node, void * key, int * pos)
static
int
-_Find(TreeIterator * iter, void * key)
+_Find(TreeIterator * iter, const void * key)
{
while (1)
{
@@ -171,8 +171,7 @@ _SplitNode(TreeNode * node)
static
void
-_InsertNodeAndData(Tree * tree,
- TreeNode * node,
+_InsertNodeAndData(TreeNode * node,
int pos,
TreeNode * newNode,
TreeKeyData keyData)
@@ -204,8 +203,7 @@ _InsertNodeAndData(Tree * tree,
static
TreeKeyData
-_AddDataToSplitNodes(Tree * tree,
- TreeNode * lessNode,
+_AddDataToSplitNodes(TreeNode * lessNode,
TreeNode * moreNode,
int pos,
TreeNode * newNode,
@@ -217,7 +215,7 @@ _AddDataToSplitNodes(Tree * tree,
if (pos <= lessNode->count)
{
- _InsertNodeAndData(tree, lessNode, pos, newNode, keyData);
+ _InsertNodeAndData(lessNode, pos, newNode, keyData);
lessNode->count--;
retKeyData = lessNode->keyData[lessNode->count];
_ClearKeyData(&(lessNode->keyData[lessNode->count]));
@@ -277,8 +275,7 @@ _InsertAt(TreeIterator * iter, TreeKeyData keyData)
TreeNode * newNode = _SplitNode(node);
/* insert data in split nodes */
- keyData = _AddDataToSplitNodes(iter->tree,
- node,
+ keyData = _AddDataToSplitNodes(node,
newNode,
pos,
insertNode,
@@ -306,8 +303,7 @@ _InsertAt(TreeIterator * iter, TreeKeyData keyData)
else
{
/* insert the data and newNode */
- _InsertNodeAndData(iter->tree,
- node,
+ _InsertNodeAndData(node,
pos,
insertNode,
keyData);
@@ -684,7 +680,7 @@ RemoveFromTreeByIterator(Tree * tree, TreeIterator * iter)
}
int
-FindInTree(Tree * tree, void * key, TreeIterator * iter)
+FindInTree(Tree * tree, const void * key, TreeIterator * iter)
{
TreeIterator i;
diff --git a/src/tree.h b/src/tree.h
index 4d30e0106..ef397bbd4 100644
--- a/src/tree.h
+++ b/src/tree.h
@@ -57,6 +57,7 @@ int InsertInTree(Tree * tree, void * key, void * data);
int RemoveFromTreeByKey(Tree * tree, void * key);
void RemoveFromTreeByIterator(Tree * tree, TreeIterator * iter);
-int FindInTree(Tree * tree, void * key, TreeIterator * iter /* can be NULL */);
+int FindInTree(Tree * tree, const void * key,
+ TreeIterator * iter /* can be NULL */);
#endif
diff --git a/src/utf8.c b/src/utf8.c
index f0d6b3b11..e8f3dbdde 100644
--- a/src/utf8.c
+++ b/src/utf8.c
@@ -69,7 +69,7 @@ static char utf8_to_latin1_char(const char *inUtf8)
return (char)(c + utf8[1]);
}
-static int validateUtf8Char(const char *inUtf8Char)
+static unsigned int validateUtf8Char(const char *inUtf8Char)
{
const unsigned char *utf8Char = (const unsigned char *)inUtf8Char;
@@ -77,9 +77,9 @@ static int validateUtf8Char(const char *inUtf8Char)
return 1;
if (utf8Char[0] >= 0xC0 && utf8Char[0] <= 0xFD) {
- int count = 1;
+ unsigned int count = 1;
char t = 1 << 5;
- int i;
+ unsigned int i;
while (count < 6 && (t & utf8Char[0])) {
t = (t >> 1);
count++;
@@ -97,7 +97,7 @@ static int validateUtf8Char(const char *inUtf8Char)
int validUtf8String(const char *string)
{
- int ret;
+ unsigned int ret;
while (*string) {
ret = validateUtf8Char(string);
@@ -114,7 +114,7 @@ char *utf8StrToLatin1Dup(const char *utf8)
/* utf8 should have at most two char's per latin1 char */
char *ret = xmalloc(strlen(utf8) + 1);
char *cp = ret;
- int count;
+ unsigned int count;
size_t len = 0;
while (*utf8) {
@@ -136,7 +136,7 @@ char *utf8StrToLatin1Dup(const char *utf8)
char *utf8_to_latin1(char *dest, const char *utf8)
{
char *cp = dest;
- int count;
+ unsigned int count;
size_t len = 0;
while (*utf8) {
diff --git a/src/volume.c b/src/volume.c
index 0da7d0360..791c1ea02 100644
--- a/src/volume.c
+++ b/src/volume.c
@@ -468,7 +468,7 @@ int getVolumeLevel(void)
}
}
-static int changeSoftwareVolume(int fd, int change, int rel)
+static int changeSoftwareVolume(mpd_unused int fd, int change, int rel)
{
int new = change;
diff --git a/src/zeroconf.c b/src/zeroconf.c
index 421a037b8..e6cbb4287 100644
--- a/src/zeroconf.c
+++ b/src/zeroconf.c
@@ -94,7 +94,7 @@ struct AvahiTimeout {
static AvahiWatch *avahiWatchList;
static AvahiTimeout *avahiTimeoutList;
-static AvahiWatch *avahiWatchNew(const AvahiPoll * api, int fd,
+static AvahiWatch *avahiWatchNew(mpd_unused const AvahiPoll * api, int fd,
AvahiWatchEvent event,
AvahiWatchCallback callback, void *userdata)
{
@@ -177,7 +177,7 @@ static void avahiTimeoutFree(AvahiTimeout * t)
free(t);
}
-static AvahiTimeout *avahiTimeoutNew(const AvahiPoll * api,
+static AvahiTimeout *avahiTimeoutNew(mpd_unused const AvahiPoll * api,
const struct timeval *tv,
AvahiTimeoutCallback callback,
void *userdata)
@@ -201,7 +201,8 @@ static AvahiTimeout *avahiTimeoutNew(const AvahiPoll * api,
/* Callback when the EntryGroup changes state */
static void avahiGroupCallback(AvahiEntryGroup * g,
- AvahiEntryGroupState state, void *userdata)
+ AvahiEntryGroupState state,
+ mpd_unused void *userdata)
{
char *n;
assert(g);
@@ -291,7 +292,7 @@ fail:
/* Callback when avahi changes state */
static void avahiClientCallback(AvahiClient * c, AvahiClientState state,
- void *userdata)
+ mpd_unused void *userdata)
{
int reason;
assert(c);