aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/audio.c6
-rw-r--r--src/audioOutputs/audioOutput_alsa.c2
-rw-r--r--src/audioOutputs/audioOutput_oss.c4
-rw-r--r--src/audioOutputs/audioOutput_shout.c2
-rw-r--r--src/audio_format.h6
-rw-r--r--src/charConv.c6
-rw-r--r--src/command.c6
-rw-r--r--src/dbUtils.c4
-rw-r--r--src/decode.c33
-rw-r--r--src/decode.h2
-rw-r--r--src/inputPlugins/_flac_common.c131
-rw-r--r--src/inputPlugins/_flac_common.h13
-rw-r--r--src/inputPlugins/aac_plugin.c4
-rw-r--r--src/inputPlugins/audiofile_plugin.c8
-rw-r--r--src/inputPlugins/flac_plugin.c74
-rw-r--r--src/inputPlugins/mp3_plugin.c10
-rw-r--r--src/inputPlugins/mp4_plugin.c2
-rw-r--r--src/inputPlugins/mpc_plugin.c10
-rw-r--r--src/inputPlugins/oggflac_plugin.c45
-rw-r--r--src/inputPlugins/wavpack_plugin.c6
-rw-r--r--src/locate.c24
-rw-r--r--src/locate.h2
-rw-r--r--src/metadata_pipe.c8
-rw-r--r--src/mpd_types.h51
-rw-r--r--src/os_compat.h9
-rw-r--r--src/outputBuffer.c19
-rw-r--r--src/outputBuffer.h6
-rw-r--r--src/outputBuffer_accessors.h4
-rw-r--r--src/outputBuffer_ob_send.h6
-rw-r--r--src/pcm_utils.c106
-rw-r--r--src/pcm_utils.h6
-rw-r--r--src/player_error.c36
-rw-r--r--src/player_error.h5
-rw-r--r--src/playlist.c163
-rw-r--r--src/playlist.h6
-rw-r--r--src/replayGain.c10
-rw-r--r--src/song.c21
-rw-r--r--src/song.h2
-rw-r--r--src/tag.c2
-rw-r--r--src/tag.h2
40 files changed, 433 insertions, 429 deletions
diff --git a/src/audio.c b/src/audio.c
index a10f5cf42..2f457829b 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -44,7 +44,7 @@ enum ad_state {
and enable in playAudio() routine */
static enum ad_state *audioDeviceStates;
-static mpd_uint8 audioOpened;
+static uint8_t audioOpened;
static size_t audioBufferSize;
static char *audioBuffer;
@@ -195,7 +195,7 @@ int parseAudioConfig(AudioFormat * audioFormat, char *conf)
return -1;
}
- audioFormat->bits = (mpd_sint8)strtol(test + 1, &test, 10);
+ audioFormat->bits = (int8_t)strtol(test + 1, &test, 10);
if (*test != ':') {
ERROR("error parsing audio output format: %s\n", conf);
@@ -211,7 +211,7 @@ int parseAudioConfig(AudioFormat * audioFormat, char *conf)
return -1;
}
- audioFormat->channels = (mpd_sint8)strtol(test + 1, &test, 10);
+ audioFormat->channels = (int8_t)strtol(test + 1, &test, 10);
if (*test != '\0') {
ERROR("error parsing audio output format: %s\n", conf);
diff --git a/src/audioOutputs/audioOutput_alsa.c b/src/audioOutputs/audioOutput_alsa.c
index 06dbeb956..cd93f9159 100644
--- a/src/audioOutputs/audioOutput_alsa.c
+++ b/src/audioOutputs/audioOutput_alsa.c
@@ -217,7 +217,7 @@ configure_hw:
snd_strerror(-err));
goto fail;
}
- audioFormat->channels = (mpd_sint8)channels;
+ audioFormat->channels = (int8_t)channels;
err = snd_pcm_hw_params_set_rate_near(ad->pcmHandle, hwparams,
&sampleRate, NULL);
diff --git a/src/audioOutputs/audioOutput_oss.c b/src/audioOutputs/audioOutput_oss.c
index 2df7d5728..a89eeab46 100644
--- a/src/audioOutputs/audioOutput_oss.c
+++ b/src/audioOutputs/audioOutput_oss.c
@@ -486,9 +486,9 @@ static int oss_openDevice(AudioOutput * audioOutput)
OssData *od = audioOutput->data;
AudioFormat *audioFormat = &audioOutput->outAudioFormat;
- od->channels = (mpd_sint8)audioFormat->channels;
+ od->channels = (int8_t)audioFormat->channels;
od->sampleRate = audioFormat->sampleRate;
- od->bits = (mpd_sint8)audioFormat->bits;
+ od->bits = (int8_t)audioFormat->bits;
if ((ret = oss_open(audioOutput)) < 0)
return ret;
diff --git a/src/audioOutputs/audioOutput_shout.c b/src/audioOutputs/audioOutput_shout.c
index 2ee942809..95db68544 100644
--- a/src/audioOutputs/audioOutput_shout.c
+++ b/src/audioOutputs/audioOutput_shout.c
@@ -636,7 +636,7 @@ static int myShout_play(AudioOutput * audioOutput,
for (i = 0; i < samples; i++) {
for (j = 0; j < sd->audioFormat->channels; j++) {
- vorbbuf[j][i] = (*((const mpd_sint16 *) playChunk))
+ vorbbuf[j][i] = (*((const int16_t *) playChunk))
/ 32768.0;
playChunk += bytes;
}
diff --git a/src/audio_format.h b/src/audio_format.h
index ade9d8810..ce47fb95b 100644
--- a/src/audio_format.h
+++ b/src/audio_format.h
@@ -22,9 +22,9 @@
#include "mpd_types.h"
typedef struct _AudioFormat {
- mpd_sint8 channels;
- mpd_uint32 sampleRate;
- mpd_sint8 bits;
+ int8_t channels;
+ uint32_t sampleRate;
+ int8_t bits;
} AudioFormat;
static inline double audio_format_time_to_size(const AudioFormat * af)
diff --git a/src/charConv.c b/src/charConv.c
index 60bcc655a..9c97be38c 100644
--- a/src/charConv.c
+++ b/src/charConv.c
@@ -32,13 +32,13 @@ static iconv_t char_conv_iconv;
static char *char_conv_to;
static char *char_conv_from;
-static mpd_sint8 char_conv_same;
-static mpd_sint8 char_conv_use_iconv;
+static int8_t char_conv_same;
+static int8_t char_conv_use_iconv;
/* 1 is to use latin1ToUtf8
0 is not to use latin1/utf8 converter
-1 is to use utf8ToLatin1*/
-static mpd_sint8 char_conv_latin1ToUtf8;
+static int8_t char_conv_latin1ToUtf8;
#define BUFFER_SIZE MPD_PATH_MAX
diff --git a/src/command.c b/src/command.c
index 851e4f67d..cc5f615c7 100644
--- a/src/command.c
+++ b/src/command.c
@@ -167,7 +167,7 @@ static void command_error_va(int fd, int error, const char *fmt, va_list args)
}
}
-static int mpd_fprintf__ check_uint32(int fd, mpd_uint32 *dst,
+static int mpd_fprintf__ check_uint32(int fd, uint32_t *dst,
const char *s, const char *fmt, ...)
{
char *test;
@@ -593,7 +593,7 @@ static int handleRename(int fd, mpd_unused int *permission,
static int handlePlaylistChanges(int fd, mpd_unused int *permission,
mpd_unused int argc, char *argv[])
{
- mpd_uint32 version;
+ uint32_t version;
if (check_uint32(fd, &version, argv[1], need_positive) < 0)
return -1;
@@ -603,7 +603,7 @@ static int handlePlaylistChanges(int fd, mpd_unused int *permission,
static int handlePlaylistChangesPosId(int fd, mpd_unused int *permission,
mpd_unused int argc, char *argv[])
{
- mpd_uint32 version;
+ uint32_t version;
if (check_uint32(fd, &version, argv[1], need_positive) < 0)
return -1;
diff --git a/src/dbUtils.c b/src/dbUtils.c
index 1ecb9f608..4cb3edcca 100644
--- a/src/dbUtils.c
+++ b/src/dbUtils.c
@@ -29,7 +29,7 @@
#include "storedPlaylist.h"
typedef struct _ListCommandItem {
- mpd_sint8 tagType;
+ int8_t tagType;
int numConditionals;
LocateTagItem *conditionals;
} ListCommandItem;
@@ -295,8 +295,10 @@ static void visitTag(int fd, struct strset *set,
for (i = 0; i < tag->numOfItems; i++) {
if (tag->items[i]->type == tagType) {
strset_add(set, tag->items[i]->value);
+ return;
}
}
+ strset_add(set, "");
}
struct list_tags_data {
diff --git a/src/decode.c b/src/decode.c
index e0685e0e9..dd1ea9396 100644
--- a/src/decode.c
+++ b/src/decode.c
@@ -173,12 +173,9 @@ static int decode_start(void)
InputStream is;
InputPlugin *plugin = NULL;
char path_max_fs[MPD_PATH_MAX];
- char path_max_utf8[MPD_PATH_MAX];
assert(pthread_equal(pthread_self(), dc.thread));
assert(dc.state == DC_STATE_DECODE);
- assert(dc.current_song);
- get_song_url(path_max_utf8, dc.current_song);
- assert(*path_max_utf8);
+ assert(*dc.utf8url);
switch (dc.action) {
case DC_ACTION_START:
@@ -193,20 +190,20 @@ static int decode_start(void)
default: assert("unknown action!" && 0);
}
- if (isRemoteUrl(path_max_utf8)) {
- pathcpy_trunc(path_max_fs, path_max_utf8);
+ if (isRemoteUrl(dc.utf8url)) {
+ pathcpy_trunc(path_max_fs, dc.utf8url);
} else {
rmp2amp_r(path_max_fs,
- utf8_to_fs_charset(path_max_fs, path_max_utf8));
+ utf8_to_fs_charset(path_max_fs, dc.utf8url));
}
if (openInputStream(&is, path_max_fs) < 0) {
DEBUG("couldn't open song: %s\n", path_max_fs);
- player_seterror(PLAYER_ERROR_FILENOTFOUND, dc.current_song);
+ player_seterror(PLAYER_ERROR_FILENOTFOUND, dc.utf8url);
return err;
}
- if (isRemoteUrl(path_max_utf8)) {
+ if (isRemoteUrl(dc.utf8url)) {
unsigned int next = 0;
/* first we try mime types: */
@@ -224,7 +221,7 @@ static int decode_start(void)
/* if that fails, try suffix matching the URL: */
if (plugin == NULL) {
- const char *s = getSuffix(path_max_utf8);
+ const char *s = getSuffix(dc.utf8url);
next = 0;
while (err && (plugin = getInputPluginFromSuffix(s, next++))) {
if (!plugin->streamDecodeFunc)
@@ -250,7 +247,7 @@ static int decode_start(void)
}
} else {
unsigned int next = 0;
- const char *s = getSuffix(path_max_utf8);
+ const char *s = getSuffix(dc.utf8url);
while (err && (plugin = getInputPluginFromSuffix(s, next++))) {
if (!plugin->streamTypes & INPUT_PLUGIN_STREAM_FILE)
continue;
@@ -273,9 +270,9 @@ static int decode_start(void)
if (err) {
if (plugin)
- player_seterror(PLAYER_ERROR_SYSTEM, dc.current_song);
+ player_seterror(PLAYER_ERROR_SYSTEM, dc.utf8url);
else
- player_seterror(PLAYER_ERROR_UNKTYPE, dc.current_song);
+ player_seterror(PLAYER_ERROR_UNKTYPE, dc.utf8url);
}
if (player_errno)
ERROR("player_error: %s\n", player_strerror());
@@ -299,20 +296,18 @@ static void * decoder_task(mpd_unused void *arg)
case DC_STATE_DECODE:
/* DEBUG(__FILE__": %s %d\n", __func__, __LINE__); */
/* DEBUG("dc.action: %d\n", (int)dc.action); */
- if ((dc.current_song = playlist_queued_song())) {
- char p[MPD_PATH_MAX];
+ if (playlist_queued_url(dc.utf8url)) {
int err;
ob_advance_sequence();
- get_song_url(p, dc.current_song);
- DEBUG("decoding song: %s\n", p);
+ DEBUG("decoding song: %s\n", dc.utf8url);
err = decode_start();
- DEBUG("DONE decoding song: %s\n", p);
+ DEBUG("DONE decoding song: %s\n", dc.utf8url);
if (err)
ob_trigger_action(OB_ACTION_RESET);
else
ob_flush();
- dc.current_song = NULL;
+ dc.utf8url[0] = '\0';
}
finalize_per_track_actions();
playlist_queue_next();
diff --git a/src/decode.h b/src/decode.h
index 61eeee078..71e7a498e 100644
--- a/src/decode.h
+++ b/src/decode.h
@@ -43,7 +43,7 @@ enum dc_state {
};
struct decoder_control {
- Song * current_song; /* only needed for wavpack, remove? */
+ char utf8url[MPD_PATH_MAX]; /* only needed for wavpack, remove? */
enum dc_state state; /* rw=dc.thread, r=main */
enum dc_action action; /* rw protected by action_cond */
float total_time; /* w=dc.thread, r=main */
diff --git a/src/inputPlugins/_flac_common.c b/src/inputPlugins/_flac_common.c
index 9950f75db..546f5c192 100644
--- a/src/inputPlugins/_flac_common.c
+++ b/src/inputPlugins/_flac_common.c
@@ -32,7 +32,6 @@
void init_FlacData(FlacData * data, InputStream * inStream)
{
- data->chunk_length = 0;
data->time = 0;
data->position = 0;
data->bitRate = 0;
@@ -160,9 +159,9 @@ void flac_metadata_common_cb(const FLAC__StreamMetadata * block,
switch (block->type) {
case FLAC__METADATA_TYPE_STREAMINFO:
- dc.audio_format.bits = (mpd_sint8)si->bits_per_sample;
+ dc.audio_format.bits = (int8_t)si->bits_per_sample;
dc.audio_format.sampleRate = si->sample_rate;
- dc.audio_format.channels = (mpd_sint8)si->channels;
+ dc.audio_format.channels = (int8_t)si->channels;
dc.total_time = ((float)si->total_samples) / (si->sample_rate);
break;
case FLAC__METADATA_TYPE_VORBIS_COMMENT:
@@ -194,4 +193,130 @@ void flac_error_common_cb(const char *plugin,
}
}
+static void flac_convert_stereo16(int16_t *dest,
+ const FLAC__int32 * const buf[],
+ unsigned int position, unsigned int end)
+{
+ for (; position < end; ++position) {
+ *dest++ = buf[0][position];
+ *dest++ = buf[1][position];
+ }
+}
+
+static void
+flac_convert_16(int16_t *dest,
+ unsigned int num_channels,
+ const FLAC__int32 * const buf[],
+ unsigned int position, unsigned int end)
+{
+ unsigned int c_chan;
+
+ for (; position < end; ++position)
+ for (c_chan = 0; c_chan < num_channels; c_chan++)
+ *dest++ = buf[c_chan][position];
+}
+
+/**
+ * Note: this function also handles 24 bit files!
+ */
+static void
+flac_convert_32(int32_t *dest,
+ unsigned int num_channels,
+ const FLAC__int32 * const buf[],
+ unsigned int position, unsigned int end)
+{
+ unsigned int c_chan;
+
+ for (; position < end; ++position)
+ for (c_chan = 0; c_chan < num_channels; c_chan++)
+ *dest++ = buf[c_chan][position];
+}
+
+static void
+flac_convert_8(int8_t *dest,
+ unsigned int num_channels,
+ const FLAC__int32 * const buf[],
+ unsigned int position, unsigned int end)
+{
+ unsigned int c_chan;
+
+ for (; position < end; ++position)
+ for (c_chan = 0; c_chan < num_channels; c_chan++)
+ *dest++ = buf[c_chan][position];
+}
+
+static void flac_convert(unsigned char *dest,
+ unsigned int num_channels,
+ unsigned int bytes_per_sample,
+ const FLAC__int32 * const buf[],
+ unsigned int position, unsigned int end)
+{
+ switch (bytes_per_sample) {
+ case 2:
+ if (num_channels == 2)
+ flac_convert_stereo16((int16_t*)dest, buf,
+ position, end);
+ else
+ flac_convert_16((int16_t*)dest, num_channels, buf,
+ position, end);
+ break;
+
+ case 4:
+ flac_convert_32((int32_t*)dest, num_channels, buf,
+ position, end);
+ break;
+
+ case 1:
+ flac_convert_8((int8_t*)dest, num_channels, buf,
+ position, end);
+ break;
+ }
+}
+
+FLAC__StreamDecoderWriteStatus
+flac_common_write(FlacData *data, const FLAC__Frame * frame,
+ const FLAC__int32 *const buf[])
+{
+ unsigned int c_samp;
+ const unsigned int num_channels = frame->header.channels;
+ const unsigned int bytes_per_sample = (dc.audio_format.bits / 8);
+ const unsigned int bytes_per_channel =
+ bytes_per_sample * frame->header.channels;
+ const unsigned int max_samples = FLAC_CHUNK_SIZE / bytes_per_channel;
+ unsigned int num_samples;
+ enum dc_action action;
+
+ assert(dc.audio_format.bits > 0);
+
+ if (bytes_per_sample != 1 && bytes_per_sample != 2 &&
+ bytes_per_sample != 4)
+ /* exotic unsupported bit rate */
+ return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
+
+ for (c_samp = 0; c_samp < frame->header.blocksize;
+ c_samp += num_samples) {
+ num_samples = frame->header.blocksize - c_samp;
+ if (num_samples > max_samples)
+ num_samples = max_samples;
+
+ flac_convert(data->chunk,
+ num_channels, bytes_per_sample, buf,
+ c_samp, c_samp + num_samples);
+
+ action = ob_send(data->chunk,
+ num_samples * bytes_per_channel,
+ data->time, data->bitRate,
+ data->replayGainInfo);
+ switch (action) {
+ case DC_ACTION_STOP:
+ return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
+ case DC_ACTION_SEEK:
+ return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
+ default: break; /* compilers are complainers */
+ }
+ }
+
+ return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
+}
+
#endif /* HAVE_FLAC || HAVE_OGGFLAC */
diff --git a/src/inputPlugins/_flac_common.h b/src/inputPlugins/_flac_common.h
index a1b0cac8f..f88866b08 100644
--- a/src/inputPlugins/_flac_common.h
+++ b/src/inputPlugins/_flac_common.h
@@ -140,7 +140,6 @@ typedef size_t flac_read_status_size_t;
typedef struct {
unsigned char chunk[FLAC_CHUNK_SIZE];
- size_t chunk_length;
float time;
unsigned int bitRate;
FLAC__uint64 position;
@@ -160,15 +159,9 @@ void flac_error_common_cb(const char *plugin,
struct mpd_tag *copyVorbisCommentBlockToMpdTag(const FLAC__StreamMetadata * block,
struct mpd_tag *tag);
-/* keep this inlined, this is just macro but prettier :) */
-static inline enum dc_action flacSendChunk(FlacData * data)
-{
- enum dc_action ret = ob_send(data->chunk, data->chunk_length,
- data->time, data->bitRate,
- data->replayGainInfo);
- data->chunk_length = 0;
- return ret;
-}
+FLAC__StreamDecoderWriteStatus
+flac_common_write(FlacData *data, const FLAC__Frame * frame,
+ const FLAC__int32 *const buf[]);
#endif /* HAVE_FLAC || HAVE_OGGFLAC */
diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c
index dc97c1e08..2e5df8f48 100644
--- a/src/inputPlugins/aac_plugin.c
+++ b/src/inputPlugins/aac_plugin.c
@@ -313,7 +313,7 @@ static int aac_stream_decode(InputStream *inStream)
unsigned int sampleCount;
char *sampleBuffer;
size_t sampleBufferLen;
- mpd_uint16 bitRate = 0;
+ uint16_t bitRate = 0;
AacBuffer b;
initAacBuffer(inStream, &b);
@@ -442,7 +442,7 @@ static int aac_decode(char *path)
/*float * seekTable;
long seekTableEnd = -1;
int seekPositionFound = 0; */
- mpd_uint16 bitRate = 0;
+ uint16_t bitRate = 0;
AacBuffer b;
InputStream inStream;
diff --git a/src/inputPlugins/audiofile_plugin.c b/src/inputPlugins/audiofile_plugin.c
index 6fcc98239..858b71229 100644
--- a/src/inputPlugins/audiofile_plugin.c
+++ b/src/inputPlugins/audiofile_plugin.c
@@ -45,7 +45,7 @@ static int audiofile_decode(char *path)
int fs, frame_count;
AFfilehandle af_fp;
int bits;
- mpd_uint16 bitRate;
+ uint16_t bitRate;
struct stat st;
int ret, current = 0;
char chunk[CHUNK_SIZE];
@@ -64,18 +64,18 @@ static int audiofile_decode(char *path)
afSetVirtualSampleFormat(af_fp, AF_DEFAULT_TRACK,
AF_SAMPFMT_TWOSCOMP, 16);
afGetVirtualSampleFormat(af_fp, AF_DEFAULT_TRACK, &fs, &bits);
- dc.audio_format.bits = (mpd_uint8)bits;
+ dc.audio_format.bits = (uint8_t)bits;
dc.audio_format.sampleRate =
(unsigned int)afGetRate(af_fp, AF_DEFAULT_TRACK);
dc.audio_format.channels =
- (mpd_uint8)afGetVirtualChannels(af_fp, AF_DEFAULT_TRACK);
+ (uint8_t)afGetVirtualChannels(af_fp, AF_DEFAULT_TRACK);
frame_count = afGetFrameCount(af_fp, AF_DEFAULT_TRACK);
dc.total_time = ((float)frame_count /
(float)dc.audio_format.sampleRate);
- bitRate = (mpd_uint16)(st.st_size * 8.0 / dc.total_time / 1000.0 + 0.5);
+ bitRate = (uint16_t)(st.st_size * 8.0 / dc.total_time / 1000.0 + 0.5);
if (dc.audio_format.bits != 8 && dc.audio_format.bits != 16) {
ERROR("Only 8 and 16-bit files are supported. %s is %i-bit\n",
diff --git a/src/inputPlugins/flac_plugin.c b/src/inputPlugins/flac_plugin.c
index 89e988a03..228301291 100644
--- a/src/inputPlugins/flac_plugin.c
+++ b/src/inputPlugins/flac_plugin.c
@@ -199,39 +199,6 @@ static void flacMetadata(mpd_unused const flac_decoder * dec,
flac_metadata_common_cb(block, (FlacData *) vdata);
}
-static void flac_convert_stereo16(unsigned char *dest,
- const FLAC__int32 * const buf[],
- unsigned int position, unsigned int end)
-{
- for (; position < end; ++position) {
- *(uint16_t*)dest = buf[0][position];
- dest += 2;
- *(uint16_t*)dest = buf[1][position];
- dest += 2;
- }
-}
-
-static void flac_convert(unsigned char *dest,
- unsigned int num_channels,
- unsigned int bytes_per_sample,
- const FLAC__int32 * const buf[],
- unsigned int position, unsigned int end)
-{
- unsigned int c_chan, i;
- FLAC__uint16 u16;
- unsigned char *uc;
-
- for (; position < end; ++position) {
- for (c_chan = 0; c_chan < num_channels; c_chan++) {
- u16 = buf[c_chan][position];
- uc = (unsigned char *)&u16;
- for (i = 0; i < bytes_per_sample; i++) {
- *dest++ = *uc++;
- }
- }
- }
-}
-
static FLAC__StreamDecoderWriteStatus flacWrite(const flac_decoder *dec,
const FLAC__Frame * frame,
const FLAC__int32 * const buf[],
@@ -239,18 +206,9 @@ static FLAC__StreamDecoderWriteStatus flacWrite(const flac_decoder *dec,
{
FlacData *data = (FlacData *) vdata;
FLAC__uint32 samples = frame->header.blocksize;
- unsigned int c_samp;
- const unsigned int num_channels = frame->header.channels;
- const unsigned int bytes_per_sample = (dc.audio_format.bits / 8);
- const unsigned int bytes_per_channel =
- bytes_per_sample * frame->header.channels;
- const unsigned int max_samples = FLAC_CHUNK_SIZE / bytes_per_channel;
- unsigned int num_samples;
float timeChange;
FLAC__uint64 newPosition = 0;
- assert(dc.audio_format.bits > 0);
-
timeChange = ((float)samples) / frame->header.sample_rate;
data->time += timeChange;
@@ -264,32 +222,7 @@ static FLAC__StreamDecoderWriteStatus flacWrite(const flac_decoder *dec,
}
data->position = newPosition;
- for (c_samp = 0; c_samp < frame->header.blocksize;
- c_samp += num_samples) {
- num_samples = frame->header.blocksize - c_samp;
- if (num_samples > max_samples)
- num_samples = max_samples;
-
- if (num_channels == 2 && bytes_per_sample == 2)
- flac_convert_stereo16(data->chunk + data->chunk_length,
- buf, c_samp,
- c_samp + num_samples);
- else
- flac_convert(data->chunk + data->chunk_length,
- num_channels, bytes_per_sample, buf,
- c_samp, c_samp + num_samples);
- data->chunk_length = num_samples * bytes_per_channel;
-
- switch (flacSendChunk(data)) {
- case DC_ACTION_STOP:
- return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
- case DC_ACTION_SEEK:
- return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
- default: break; /* compilers are complainers */
- }
- }
-
- return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
+ return flac_common_write(data, frame, buf);
}
static struct mpd_tag *flacMetadataDup(char *file, int *vorbisCommentFound)
@@ -426,7 +359,6 @@ static int flac_decode_internal(InputStream * inStream, int is_ogg)
data.time = ((float)sampleToSeek) /
dc.audio_format.sampleRate;
data.position = 0;
- data.chunk_length = 0;
} else {
dc.seek_where = DC_SEEK_ERROR;
}
@@ -437,10 +369,6 @@ static int flac_decode_internal(InputStream * inStream, int is_ogg)
flacPrintErroredState(flac_get_state(flacDec));
flac_finish(flacDec);
}
- /* send last little bit */
- if (data.chunk_length > 0 && !dc_intr())
- flacSendChunk(&data);
-
fail:
if (data.replayGainInfo)
freeReplayGainInfo(data.replayGainInfo);
diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c
index 1d6333fd6..0d664b020 100644
--- a/src/inputPlugins/mp3_plugin.c
+++ b/src/inputPlugins/mp3_plugin.c
@@ -65,7 +65,7 @@ static unsigned long prng(unsigned long state)
return (state * 0x0019660dL + 0x3c6ef35fL) & 0xffffffffL;
}
-static mpd_sint16 audio_linear_dither(unsigned int bits, mad_fixed_t sample,
+static int16_t audio_linear_dither(unsigned int bits, mad_fixed_t sample,
struct audio_dither *dither)
{
unsigned int scalebits;
@@ -107,15 +107,15 @@ static mpd_sint16 audio_linear_dither(unsigned int bits, mad_fixed_t sample,
dither->error[0] = sample - output;
- return (mpd_sint16)(output >> scalebits);
+ return (int16_t)(output >> scalebits);
}
-static unsigned dither_buffer(mpd_sint16 *dest0, const struct mad_synth *synth,
+static unsigned dither_buffer(int16_t *dest0, const struct mad_synth *synth,
struct audio_dither *dither,
unsigned int start, unsigned int end,
unsigned int num_channels)
{
- mpd_sint16 *dest = dest0;
+ int16_t *dest = dest0;
unsigned int i;
for (i = start; i < end; ++i) {
@@ -153,7 +153,7 @@ typedef struct _mp3DecodeData {
struct mad_synth synth;
mad_timer_t timer;
unsigned char readBuffer[READ_BUFFER_SIZE];
- mpd_sint16 outputBuffer[MP3_DATA_OUTPUT_BUFFER_SIZE];
+ int16_t outputBuffer[MP3_DATA_OUTPUT_BUFFER_SIZE];
float totalTime;
float elapsedTime;
enum muteframe muteFrame;
diff --git a/src/inputPlugins/mp4_plugin.c b/src/inputPlugins/mp4_plugin.c
index 1e65f6667..0763c6c12 100644
--- a/src/inputPlugins/mp4_plugin.c
+++ b/src/inputPlugins/mp4_plugin.c
@@ -103,7 +103,7 @@ static int mp4_decode(InputStream * inStream)
long seekTableEnd = -1;
int seekPositionFound = 0;
long offset;
- mpd_uint16 bitRate = 0;
+ uint16_t bitRate = 0;
int seeking = 0;
mp4cb = xmalloc(sizeof(mp4ff_callback_t));
diff --git a/src/inputPlugins/mpc_plugin.c b/src/inputPlugins/mpc_plugin.c
index e5502a2f0..735916cdc 100644
--- a/src/inputPlugins/mpc_plugin.c
+++ b/src/inputPlugins/mpc_plugin.c
@@ -74,10 +74,10 @@ static mpc_int32_t mpc_getsize_cb(void *vdata)
}
/* this _looks_ performance-critical, don't de-inline -- eric */
-static inline mpd_sint16 convertSample(MPC_SAMPLE_FORMAT sample)
+static inline int16_t convertSample(MPC_SAMPLE_FORMAT sample)
{
/* only doing 16-bit audio for now */
- mpd_sint32 val;
+ int32_t val;
const int clip_min = -1 << (16 - 1);
const int clip_max = (1 << (16 - 1)) - 1;
@@ -121,7 +121,7 @@ static int mpc_decode(InputStream * inStream)
char chunk[MPC_CHUNK_SIZE];
int chunkpos = 0;
long bitRate = 0;
- mpd_sint16 *s16 = (mpd_sint16 *) chunk;
+ int16_t *s16 = (int16_t *) chunk;
unsigned long samplePos = 0;
mpc_uint32_t vbrUpdateAcc;
mpc_uint32_t vbrUpdateBits;
@@ -175,7 +175,7 @@ static int mpc_decode(InputStream * inStream)
dc_action_begin();
samplePos = dc.seek_where * dc.audio_format.sampleRate;
if (mpc_decoder_seek_sample(&decoder, samplePos)) {
- s16 = (mpd_sint16 *) chunk;
+ s16 = (int16_t *) chunk;
chunkpos = 0;
} else
dc.seek_where = DC_SEEK_ERROR;
@@ -214,7 +214,7 @@ static int mpc_decode(InputStream * inStream)
bitRate, replayGainInfo);
chunkpos = 0;
- s16 = (mpd_sint16 *) chunk;
+ s16 = (int16_t *) chunk;
if (dc_intr()) {
eof = 1;
break;
diff --git a/src/inputPlugins/oggflac_plugin.c b/src/inputPlugins/oggflac_plugin.c
index 841030481..36bd9dced 100644
--- a/src/inputPlugins/oggflac_plugin.c
+++ b/src/inputPlugins/oggflac_plugin.c
@@ -162,51 +162,12 @@ static FLAC__StreamDecoderWriteStatus oggflacWrite(mpd_unused const
{
FlacData *data = (FlacData *) vdata;
FLAC__uint32 samples = frame->header.blocksize;
- FLAC__uint16 u16;
- unsigned char *uc;
- unsigned int c_samp, c_chan;
- int i;
float timeChange;
timeChange = ((float)samples) / frame->header.sample_rate;
data->time += timeChange;
- /* ogg123 uses a complicated method of calculating bitrate
- * with averaging which I'm not too fond of.
- * (waste of memory/CPU cycles, especially given this is _lossless_)
- * a get_decode_position() is not available in OggFLAC, either
- *
- * this does not give an accurate bitrate:
- * (bytes_last_read was set in the read callback)
- data->bitRate = ((8.0 * data->bytes_last_read *
- frame->header.sample_rate)
- /((float)samples * 1000)) + 0.5;
- */
-
- for (c_samp = 0; c_samp < frame->header.blocksize; c_samp++) {
- for (c_chan = 0; c_chan < frame->header.channels;
- c_chan++) {
- u16 = buf[c_chan][c_samp];
- uc = (unsigned char *)&u16;
- for (i = 0; i < (dc.audio_format.bits / 8); i++) {
- if (data->chunk_length >= FLAC_CHUNK_SIZE) {
- /* FIXME: line wrapping */
- switch (flacSendChunk(data)) {
- case DC_ACTION_STOP:
- return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
- case DC_ACTION_SEEK:
- return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
- default:
- /* compilers are complainers */
- break;
- }
- }
- data->chunk[data->chunk_length++] = *(uc++);
- }
- }
- }
-
- return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
+ return flac_common_write(data, frame, buf);
}
/* used by TagDup */
@@ -367,7 +328,6 @@ static int oggflac_decode(InputStream * inStream)
data.time = ((float)sampleToSeek) /
dc.audio_format.sampleRate;
data.position = 0;
- data.chunk_length = 0;
} else {
dc.seek_where = DC_SEEK_ERROR;
}
@@ -380,9 +340,6 @@ static int oggflac_decode(InputStream * inStream)
(OggFLAC__seekable_stream_decoder_get_state(decoder));
OggFLAC__seekable_stream_decoder_finish(decoder);
}
- /* send last little bit */
- if (data.chunk_length > 0 && !dc_intr())
- flacSendChunk(&data);
fail:
oggflac_cleanup(&data, decoder);
diff --git a/src/inputPlugins/wavpack_plugin.c b/src/inputPlugins/wavpack_plugin.c
index 8bba8ae2b..b6da51e5e 100644
--- a/src/inputPlugins/wavpack_plugin.c
+++ b/src/inputPlugins/wavpack_plugin.c
@@ -429,10 +429,8 @@ static int wavpack_open_wvc(InputStream *is_wvc)
char wvc_url[MPD_PATH_MAX];
size_t len;
- /* This is the only reader of dc.current_song */
- if (!get_song_url(wvc_url, dc.current_song))
- return 0;
-
+ /* This is the only reader of dc.utf8url (in inputPlugins) */
+ pathcpy_trunc(wvc_url, dc.utf8url);
len = strlen(wvc_url);
if ((len + 2) >= MPD_PATH_MAX)
return 0;
diff --git a/src/locate.c b/src/locate.c
index 76e229f4c..6101dd95b 100644
--- a/src/locate.c
+++ b/src/locate.c
@@ -126,6 +126,7 @@ static int strstrSearchTag(Song * song, enum tag_type type, char *str)
int i;
char *duplicate;
int ret = 0;
+ int8_t visitedTypes[TAG_NUM_OF_ITEM_TYPES] = { 0 };
if (type == LOCATE_TAG_FILE_TYPE || type == LOCATE_TAG_ANY_TYPE) {
char path_max_tmp[MPD_PATH_MAX];
@@ -141,17 +142,27 @@ static int strstrSearchTag(Song * song, enum tag_type type, char *str)
return 0;
for (i = 0; i < song->tag->numOfItems && !ret; i++) {
+ visitedTypes[song->tag->items[i]->type] = 1;
if (type != LOCATE_TAG_ANY_TYPE &&
song->tag->items[i]->type != type) {
continue;
}
duplicate = strDupToUpper(song->tag->items[i]->value);
- if (strstr(duplicate, str))
+ if (*str && strstr(duplicate, str))
ret = 1;
free(duplicate);
}
+ /** If the search critieron was not visited during the sweep
+ * through the song's tag, it means this field is absent from
+ * the tag or empty. Thus, if the searched string is also
+ * empty (first char is a \0), then it's a match as well and
+ * we should return 1.
+ */
+ if (!*str && !visitedTypes[type])
+ return 1;
+
return ret;
}
@@ -172,6 +183,7 @@ int strstrSearchTags(Song * song, int numItems, LocateTagItem * items)
static int tagItemFoundAndMatches(Song * song, enum tag_type type, char *str)
{
int i;
+ int8_t visitedTypes[TAG_NUM_OF_ITEM_TYPES] = { 0 };
if (type == LOCATE_TAG_FILE_TYPE || type == LOCATE_TAG_ANY_TYPE) {
char path_max_tmp[MPD_PATH_MAX];
@@ -185,6 +197,7 @@ static int tagItemFoundAndMatches(Song * song, enum tag_type type, char *str)
return 0;
for (i = 0; i < song->tag->numOfItems; i++) {
+ visitedTypes[song->tag->items[i]->type] = 1;
if (type != LOCATE_TAG_ANY_TYPE &&
song->tag->items[i]->type != type) {
continue;
@@ -194,6 +207,15 @@ static int tagItemFoundAndMatches(Song * song, enum tag_type type, char *str)
return 1;
}
+ /** If the search critieron was not visited during the sweep
+ * through the song's tag, it means this field is absent from
+ * the tag or empty. Thus, if the searched string is also
+ * empty (first char is a \0), then it's a match as well and
+ * we should return 1.
+ */
+ if (!*str && !visitedTypes[type])
+ return 1;
+
return 0;
}
diff --git a/src/locate.h b/src/locate.h
index 325ae384d..7a817828a 100644
--- a/src/locate.h
+++ b/src/locate.h
@@ -26,7 +26,7 @@
/* struct used for search, find, list queries */
typedef struct _LocateTagItem {
- mpd_sint8 tagType;
+ int8_t tagType;
/* what we are looking for */
char *needle;
} LocateTagItem;
diff --git a/src/metadata_pipe.c b/src/metadata_pipe.c
index f4ff16052..83c36ce1b 100644
--- a/src/metadata_pipe.c
+++ b/src/metadata_pipe.c
@@ -29,7 +29,7 @@ static struct ringbuf *mp;
/* Each one of these is a packet inside the metadata pipe */
struct tag_container {
float metadata_time;
- mpd_uint8 seq; /* ob.seq_decoder at time of metadata_pipe_send() */
+ uint8_t seq; /* ob.seq_decoder at time of metadata_pipe_send() */
struct mpd_tag *tag; /* our payload */
};
@@ -79,8 +79,8 @@ struct mpd_tag * metadata_pipe_recv(void)
{
struct tag_container tc;
size_t r;
- static const size_t mpd_uint8_max = 255; /* XXX CLEANUP */
- mpd_uint8 expect_seq = ob_get_player_sequence();
+ static const size_t uint8_t_max = 255; /* XXX CLEANUP */
+ uint8_t expect_seq = ob_get_player_sequence();
unsigned long current_time = ob_get_elapsed_time();
struct mpd_tag *tag = NULL;
@@ -106,7 +106,7 @@ retry:
current_tag = tc.tag;
ringbuf_read_advance(mp, sizeof(struct tag_container));
} else if (expect_seq > tc.seq ||
- (!expect_seq && tc.seq == mpd_uint8_max)) {
+ (!expect_seq && tc.seq == uint8_t_max)) {
DEBUG("metadata_pipe: reader is ahead of writer\n");
tag_free(tc.tag);
ringbuf_read_advance(mp, sizeof(struct tag_container));
diff --git a/src/mpd_types.h b/src/mpd_types.h
index dbdfc6865..b61f007ad 100644
--- a/src/mpd_types.h
+++ b/src/mpd_types.h
@@ -21,23 +21,48 @@
#include "../config.h"
-typedef unsigned char mpd_uint8;
-typedef signed char mpd_sint8;
+#if defined(HAVE_INTTYPES_H)
+ /*
+ * inttypes.h pulls in stdint.h on C99 systems, needed for older systems
+ * that didn't provide stdint.h but still defined equivalent types.
+ */
+# include <inttypes.h>
+#elif defined(HAVE_STDINT_H)
+# include <stdint.h>
+#elif defined(HAVE_SYS_INTTYPES_H)
+# include <sys/inttypes.h> /* some ancient systems had this, untested */
+#endif /* C99-ish type headers */
+
+#include <sys/types.h>
+
+#if (!defined(HAVE_STDINT_H) && !defined(HAVE_INTTYPES_H))
+
+/*
+ * this only includes a partial subset of what is expected in a C99
+ * stdint.h or inttypes.h; but includes enough of what is needed for mpd
+ * to function on older platforms
+ * (especially Linux ones still using gcc 2.95)
+ */
+
+typedef unsigned char uint8_t;
+typedef signed char int8_t;
#if SIZEOF_SHORT == 2
-typedef unsigned short mpd_uint16;
-typedef signed short mpd_sint16;
+typedef unsigned short uint16_t;
+typedef signed short int16_t;
#elif SIZEOF_INT == 2
-typedef unsigned int mpd_uint16;
-typedef signed int mpd_sint16;
-#endif
+typedef unsigned int uint16_t;
+typedef signed int int16_t;
+#endif /* (u)int_16_t */
#if SIZEOF_INT == 4
-typedef unsigned int mpd_uint32;
-typedef signed int mpd_sint32;
+typedef unsigned int uint32_t;
+typedef signed int int32_t;
#elif SIZEOF_LONG == 4
-typedef unsigned long mpd_uint32;
-typedef signed long mpd_sint32;
-#endif
+typedef unsigned long uint32_t;
+typedef signed long int32_t;
+#endif /* (u)int_32 */
+
+#endif /* !HAVE_STDINT_H && !HAVE_INTTYPES_H */
-#endif
+#endif /* MPD_TYPES_H */
diff --git a/src/os_compat.h b/src/os_compat.h
index 7cd47cbf8..c3aede51c 100644
--- a/src/os_compat.h
+++ b/src/os_compat.h
@@ -31,14 +31,7 @@
* 2) optional features in core (libsamplerate, avahi, ...)
*/
-#if defined(HAVE_STDINT_H)
-#include <stdint.h>
-#elif defined(HAVE_INTTYPES_H)
-#include <inttypes.h>
-#elif defined(HAVE_SYS_INTTYPES_H)
-#include <sys/inttypes.h>
-#endif
-#include <sys/types.h>
+#include "mpd_types.h"
#define _XOPEN_SOURCE 600 /* for posix_fadvise, won't hurt if not available */
#include <fcntl.h>
diff --git a/src/outputBuffer.c b/src/outputBuffer.c
index 606877dd0..7216a9c9c 100644
--- a/src/outputBuffer.c
+++ b/src/outputBuffer.c
@@ -22,7 +22,6 @@
#include "normalize.h"
#include "ringbuf.h"
#include "condition.h"
-#include "song.h"
#include "main_notify.h"
#include "player_error.h"
#include "log.h"
@@ -33,10 +32,10 @@
/* typically have 2048-4096 of these structs, so pack tightly */
struct ob_chunk {
- mpd_uint16 len; /* 0: skip this chunk */
- mpd_uint16 bit_rate;
+ uint16_t len; /* 0: skip this chunk */
+ uint16_t bit_rate;
float time;
- mpd_uint8 seq; /* see seq_ok() for explanation */
+ uint8_t seq; /* see seq_ok() for explanation */
char data[CHUNK_SIZE];
};
@@ -73,12 +72,12 @@ struct output_buffer {
size_t conv_buf_len;
pthread_t thread;
ConvState conv_state;
- mpd_uint8 seq_drop;
- mpd_uint8 seq_player; /* only gets changed by ob.thread */
- mpd_uint8 seq_decoder; /* only gets changed by dc.thread */
+ uint8_t seq_drop;
+ uint8_t seq_player; /* only gets changed by ob.thread */
+ uint8_t seq_decoder; /* only gets changed by dc.thread */
struct ringbuf preseek_index;
enum ob_state preseek_state;
- mpd_uint16 *preseek_len;
+ uint16_t *preseek_len;
};
static struct output_buffer ob;
@@ -158,7 +157,7 @@ static enum action_status ob_do_drop(void)
{
struct rbvec vec[2];
long i;
- mpd_uint8 seq_drop;
+ uint8_t seq_drop;
cond_enter(&ob_seq_cond);
seq_drop = ob.seq_drop;
@@ -209,7 +208,7 @@ static void reader_reset_buffer(void)
metadata_pipe_clear();
}
-static void ob_seq_player_set(mpd_uint8 seq_num)
+static void ob_seq_player_set(uint8_t seq_num)
{
cond_enter(&ob_seq_cond);
ob.seq_player = seq_num;
diff --git a/src/outputBuffer.h b/src/outputBuffer.h
index 022f7ecdc..258875868 100644
--- a/src/outputBuffer.h
+++ b/src/outputBuffer.h
@@ -67,7 +67,7 @@ int ob_synced(void);
* vec = ob_getv(); decode_to(&vec, ...); ob_vmsplice(&vec, ...);
*/
enum dc_action ob_send(void *data, size_t len, float time,
- mpd_uint16 bit_rate, ReplayGainInfo *rgi);
+ uint16_t bit_rate, ReplayGainInfo *rgi);
/* synchronous and blocking (the only way it should be) */
void ob_trigger_action(enum ob_action action);
@@ -106,7 +106,7 @@ void ob_flush(void);
void config_output_buffer(void);
void init_output_buffer(void);
-mpd_uint8 ob_get_decoder_sequence(void);
+uint8_t ob_get_decoder_sequence(void);
-mpd_uint8 ob_get_player_sequence(void);
+uint8_t ob_get_player_sequence(void);
#endif
diff --git a/src/outputBuffer_accessors.h b/src/outputBuffer_accessors.h
index 2f4116b94..8d59429dd 100644
--- a/src/outputBuffer_accessors.h
+++ b/src/outputBuffer_accessors.h
@@ -76,12 +76,12 @@ AudioFormat *ob_audio_format(void)
return &ob.audio_format;
}
-mpd_uint8 ob_get_decoder_sequence(void)
+uint8_t ob_get_decoder_sequence(void)
{
return ob.seq_decoder;
}
-mpd_uint8 ob_get_player_sequence(void)
+uint8_t ob_get_player_sequence(void)
{
return ob.seq_player;
}
diff --git a/src/outputBuffer_ob_send.h b/src/outputBuffer_ob_send.h
index 310d5f8fd..f27a5c0dc 100644
--- a/src/outputBuffer_ob_send.h
+++ b/src/outputBuffer_ob_send.h
@@ -37,7 +37,7 @@ static void do_audio_conversion(void **data, size_t *len)
static void ensure_audio_format_sanity(void **data, size_t *len)
{
- static mpd_uint8 seq_last;
+ static uint8_t seq_last;
assert(pthread_equal(pthread_self(), dc.thread));
if (mpd_unlikely(seq_last != ob.seq_decoder)) {
@@ -61,7 +61,7 @@ static void start_playback(void)
enum dc_action
ob_send(void *data, size_t len,
- float decode_time, mpd_uint16 bit_rate, ReplayGainInfo * rgi)
+ float decode_time, uint16_t bit_rate, ReplayGainInfo * rgi)
{
struct rbvec vec[2];
struct ob_chunk *c;
@@ -97,7 +97,7 @@ ob_send(void *data, size_t len,
c->bit_rate = bit_rate;
c_len = len > CHUNK_SIZE ? CHUNK_SIZE
: len;
- c->len = (mpd_uint16)c_len;
+ c->len = (uint16_t)c_len;
memcpy(c->data, data, c_len);
} else { /* partially filled chunk */
size_t max = CHUNK_SIZE - c->len;
diff --git a/src/pcm_utils.c b/src/pcm_utils.c
index 90856fa1d..a798223c7 100644
--- a/src/pcm_utils.c
+++ b/src/pcm_utils.c
@@ -24,12 +24,32 @@
#include "conf.h"
#include "os_compat.h"
+static inline int
+pcm_dither(void)
+{
+ return (rand() & 511) - (rand() & 511);
+}
+
+/**
+ * Check if the value is within the range of the provided bit size,
+ * and caps it if necessary.
+ */
+static int32_t
+pcm_range(int32_t sample, unsigned bits)
+{
+ if (mpd_unlikely(sample < (-1 << (bits - 1))))
+ return -1 << (bits - 1);
+ if (mpd_unlikely(sample >= (1 << (bits - 1))))
+ return (1 << (bits - 1)) - 1;
+ return sample;
+}
+
void pcm_volumeChange(char *buffer, int bufferSize, const AudioFormat * format,
int volume)
{
- mpd_sint32 temp32;
- mpd_sint8 *buffer8 = (mpd_sint8 *) buffer;
- mpd_sint16 *buffer16 = (mpd_sint16 *) buffer;
+ int32_t temp32;
+ int8_t *buffer8 = (int8_t *) buffer;
+ int16_t *buffer16 = (int16_t *) buffer;
if (volume >= 1000)
return;
@@ -44,12 +64,10 @@ void pcm_volumeChange(char *buffer, int bufferSize, const AudioFormat * format,
while (bufferSize > 0) {
temp32 = *buffer16;
temp32 *= volume;
- temp32 += rand() & 511;
- temp32 -= rand() & 511;
+ temp32 += pcm_dither();
temp32 += 500;
temp32 /= 1000;
- *buffer16 = temp32 > 32767 ? 32767 :
- (temp32 < -32768 ? -32768 : temp32);
+ *buffer16 = pcm_range(temp32, 16);
buffer16++;
bufferSize -= 2;
}
@@ -58,12 +76,10 @@ void pcm_volumeChange(char *buffer, int bufferSize, const AudioFormat * format,
while (bufferSize > 0) {
temp32 = *buffer8;
temp32 *= volume;
- temp32 += rand() & 511;
- temp32 -= rand() & 511;
+ temp32 += pcm_dither();
temp32 += 500;
temp32 /= 1000;
- *buffer8 = temp32 > 127 ? 127 :
- (temp32 < -128 ? -128 : temp32);
+ *buffer8 = pcm_range(temp32, 8);
buffer8++;
bufferSize--;
}
@@ -78,11 +94,11 @@ static void pcm_add(char *buffer1, const char *buffer2, size_t bufferSize1,
size_t bufferSize2, int vol1, int vol2,
const AudioFormat * format)
{
- mpd_sint32 temp32;
- mpd_sint8 *buffer8_1 = (mpd_sint8 *) buffer1;
- const mpd_sint8 *buffer8_2 = (const mpd_sint8 *) buffer2;
- mpd_sint16 *buffer16_1 = (mpd_sint16 *) buffer1;
- const mpd_sint16 *buffer16_2 = (const mpd_sint16 *) buffer2;
+ int32_t temp32;
+ int8_t *buffer8_1 = (int8_t *) buffer1;
+ const int8_t *buffer8_2 = (const int8_t *) buffer2;
+ int16_t *buffer16_1 = (int16_t *) buffer1;
+ const int16_t *buffer16_2 = (const int16_t *) buffer2;
switch (format->bits) {
case 16:
@@ -90,13 +106,10 @@ static void pcm_add(char *buffer1, const char *buffer2, size_t bufferSize1,
temp32 =
(vol1 * (*buffer16_1) +
vol2 * (*buffer16_2));
- temp32 += rand() & 511;
- temp32 -= rand() & 511;
+ temp32 += pcm_dither();
temp32 += 500;
temp32 /= 1000;
- *buffer16_1 =
- temp32 > 32767 ? 32767 : (temp32 <
- -32768 ? -32768 : temp32);
+ *buffer16_1 = pcm_range(temp32, 16);
buffer16_1++;
buffer16_2++;
bufferSize1 -= 2;
@@ -109,13 +122,10 @@ static void pcm_add(char *buffer1, const char *buffer2, size_t bufferSize1,
while (bufferSize1 > 0 && bufferSize2 > 0) {
temp32 =
(vol1 * (*buffer8_1) + vol2 * (*buffer8_2));
- temp32 += rand() & 511;
- temp32 -= rand() & 511;
+ temp32 += pcm_dither();
temp32 += 500;
temp32 /= 1000;
- *buffer8_1 =
- temp32 > 127 ? 127 : (temp32 <
- -128 ? -128 : temp32);
+ *buffer8_1 = pcm_range(temp32, 8);
buffer8_1++;
buffer8_2++;
bufferSize1--;
@@ -182,9 +192,9 @@ out:
#endif
#ifdef HAVE_LIBSAMPLERATE
-static size_t pcm_convertSampleRate(mpd_sint8 channels, mpd_uint32 inSampleRate,
+static size_t pcm_convertSampleRate(int8_t channels, uint32_t inSampleRate,
const char *inBuffer, size_t inSize,
- mpd_uint32 outSampleRate, char *outBuffer,
+ uint32_t outSampleRate, char *outBuffer,
size_t outSize, ConvState *convState)
{
static int convalgo = -1;
@@ -258,19 +268,19 @@ 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,
+static size_t pcm_convertSampleRate(int8_t channels, uint32_t inSampleRate,
const char *inBuffer,
mpd_unused size_t inSize,
- mpd_uint32 outSampleRate, char *outBuffer,
+ uint32_t outSampleRate, char *outBuffer,
size_t outSize,
mpd_unused ConvState *convState)
{
- mpd_uint32 rd_dat = 0;
- mpd_uint32 wr_dat = 0;
- mpd_sint16 *in = (mpd_sint16 *)inBuffer;
- mpd_sint16 *out = (mpd_sint16 *)outBuffer;
- mpd_uint32 nlen = outSize / 2;
- mpd_sint16 lsample, rsample;
+ uint32_t rd_dat = 0;
+ uint32_t wr_dat = 0;
+ int16_t *in = (int16_t *)inBuffer;
+ int16_t *out = (int16_t *)outBuffer;
+ uint32_t nlen = outSize / 2;
+ int16_t lsample, rsample;
switch (channels) {
case 1:
@@ -300,14 +310,14 @@ static size_t pcm_convertSampleRate(mpd_sint8 channels, mpd_uint32 inSampleRate,
}
#endif /* !HAVE_LIBSAMPLERATE */
-static char *pcm_convertChannels(mpd_sint8 channels, const char *inBuffer,
+static char *pcm_convertChannels(int8_t channels, const char *inBuffer,
size_t inSize, size_t *outSize)
{
static char *buf;
static size_t len;
char *outBuffer = NULL;
- const mpd_sint16 *in;
- mpd_sint16 *out;
+ const int16_t *in;
+ int16_t *out;
int inSamples, i;
switch (channels) {
@@ -321,8 +331,8 @@ static char *pcm_convertChannels(mpd_sint8 channels, const char *inBuffer,
outBuffer = buf;
inSamples = inSize >> 1;
- in = (const mpd_sint16 *)inBuffer;
- out = (mpd_sint16 *)outBuffer;
+ in = (const int16_t *)inBuffer;
+ out = (int16_t *)outBuffer;
for (i = 0; i < inSamples; i++) {
*out++ = *in;
*out++ = *in++;
@@ -339,8 +349,8 @@ static char *pcm_convertChannels(mpd_sint8 channels, const char *inBuffer,
outBuffer = buf;
inSamples = inSize >> 2;
- in = (const mpd_sint16 *)inBuffer;
- out = (mpd_sint16 *)outBuffer;
+ in = (const int16_t *)inBuffer;
+ out = (int16_t *)outBuffer;
for (i = 0; i < inSamples; i++) {
*out = (*in++) / 2;
*out++ += (*in++) / 2;
@@ -354,14 +364,14 @@ static char *pcm_convertChannels(mpd_sint8 channels, const char *inBuffer,
return outBuffer;
}
-static const char *pcm_convertTo16bit(mpd_sint8 bits, const char *inBuffer,
+static const char *pcm_convertTo16bit(int8_t bits, const char *inBuffer,
size_t inSize, size_t *outSize)
{
static char *buf;
static size_t len;
char *outBuffer = NULL;
- const mpd_sint8 *in;
- mpd_sint16 *out;
+ const int8_t *in;
+ int16_t *out;
size_t i;
switch (bits) {
@@ -373,8 +383,8 @@ static const char *pcm_convertTo16bit(mpd_sint8 bits, const char *inBuffer,
}
outBuffer = buf;
- in = (const mpd_sint8 *)inBuffer;
- out = (mpd_sint16 *)outBuffer;
+ in = (const int8_t *)inBuffer;
+ out = (int16_t *)outBuffer;
for (i = 0; i < inSize; i++)
*out++ = (*in++) << 8;
diff --git a/src/pcm_utils.h b/src/pcm_utils.h
index 2ecb56201..31911af01 100644
--- a/src/pcm_utils.h
+++ b/src/pcm_utils.h
@@ -34,9 +34,9 @@ typedef struct _ConvState {
SRC_DATA data;
size_t dataInSize;
size_t dataOutSize;
- mpd_sint8 lastChannels;
- mpd_uint32 lastInSampleRate;
- mpd_uint32 lastOutSampleRate;
+ int8_t lastChannels;
+ uint32_t lastInSampleRate;
+ uint32_t lastOutSampleRate;
#endif
/* Strict C99 doesn't allow empty structs */
int error;
diff --git a/src/player_error.c b/src/player_error.c
index 4c7f7b9de..38e76e2c4 100644
--- a/src/player_error.c
+++ b/src/player_error.c
@@ -4,50 +4,52 @@
#include "path.h"
enum player_error player_errno;
-Song *player_errsong;
+static char errsong_url[MPD_PATH_MAX];
void player_clearerror(void)
{
player_errno = PLAYER_ERROR_NONE;
- player_errsong = NULL;
+ *errsong_url = '\0';
}
-void player_seterror(enum player_error err, Song *song)
+void player_seterror(enum player_error err, const char *url)
{
if (player_errno)
ERROR("Clobbering existing error: %s\n", player_strerror());
player_errno = err;
- player_errsong = song;
+ pathcpy_trunc(errsong_url, url);
}
const char *player_strerror(void)
{
/* static OK here, only one user in main task */
static char error[MPD_PATH_MAX + 64]; /* still too much */
- char path_max_tmp[MPD_PATH_MAX];
- *error = '\0'; /* likely */
+ const char *ret = NULL;
switch (player_errno) {
- case PLAYER_ERROR_NONE: break;
+ case PLAYER_ERROR_NONE:
+ ret = "";
+ break;
case PLAYER_ERROR_FILE:
- snprintf(error, sizeof(error), "problems decoding \"%s\"",
- get_song_url(path_max_tmp, player_errsong));
+ snprintf(error, sizeof(error),
+ "problems decoding \"%s\"", errsong_url);
break;
case PLAYER_ERROR_AUDIO:
- strcpy(error, "problems opening audio device");
+ ret = "problems opening audio device";
break;
case PLAYER_ERROR_SYSTEM:
- strcpy(error, "system error occured");
+ /* DONTFIX: misspelling "occurred" here is client-visible */
+ ret = "system error occured";
break;
case PLAYER_ERROR_UNKTYPE:
- snprintf(error, sizeof(error), "file type of \"%s\" is unknown",
- get_song_url(path_max_tmp, player_errsong));
- case PLAYER_ERROR_FILENOTFOUND:
snprintf(error, sizeof(error),
- "file \"%s\" does not exist or is inaccessible",
- get_song_url(path_max_tmp, player_errsong));
+ "file type of \"%s\" is unknown", errsong_url);
break;
+ case PLAYER_ERROR_FILENOTFOUND:
+ snprintf(error, sizeof(error),
+ "file \"%s\" does not exist or is inaccessible",
+ errsong_url);
}
- return *error ? error : NULL;
+ return ret ? ret : error;
}
diff --git a/src/player_error.h b/src/player_error.h
index c90c98420..997cb4604 100644
--- a/src/player_error.h
+++ b/src/player_error.h
@@ -19,8 +19,6 @@
#ifndef PLAYER_ERROR_H
#define PLAYER_ERROR_H
-#include "song.h"
-
enum player_error {
PLAYER_ERROR_NONE = 0,
PLAYER_ERROR_FILE,
@@ -31,10 +29,9 @@ enum player_error {
};
extern enum player_error player_errno;
-extern Song *player_errsong;
void player_clearerror(void);
-void player_seterror(enum player_error err, Song *song);
+void player_seterror(enum player_error err, const char *url);
const char *player_strerror(void);
#endif /* PLAYER_ERROR_H */
diff --git a/src/playlist.c b/src/playlist.c
index af0aaccc0..474e11f4b 100644
--- a/src/playlist.c
+++ b/src/playlist.c
@@ -43,7 +43,7 @@ static enum _playlist_state playlist_state;
struct _playlist {
Song **songs;
/* holds version a song was modified on */
- mpd_uint32 *songMod;
+ uint32_t *songMod;
int *order;
int *positionToId;
int *idToPosition;
@@ -52,7 +52,7 @@ struct _playlist {
int queued; /* to be decoded */
int repeat;
int random;
- mpd_uint32 version;
+ uint32_t version;
};
#define PLAYLIST_PREV_UNLESS_ELAPSED 10
@@ -99,15 +99,11 @@ static void randomizeOrder(int start, int end);
static void incrPlaylistVersion(void)
{
- static unsigned long max = ((mpd_uint32) 1 << 31) - 1;
- playlist.version++;
- if (playlist.version >= max) {
- int i;
-
- for (i = 0; i < playlist.length; i++) {
- playlist.songMod[i] = 0;
- }
+ static unsigned long max = ((uint32_t) 1 << 31) - 1;
+ if (++playlist.version >= max) {
+ memset(playlist.songMod, 0,
+ playlist.length * sizeof(*playlist.songMod));
playlist.version = 1;
}
}
@@ -116,9 +112,8 @@ void playlistVersionChange(void)
{
int i;
- for (i = 0; i < playlist.length; i++) {
+ for (i = playlist.length; --i >= 0; )
playlist.songMod[i] = playlist.version;
- }
incrPlaylistVersion();
}
@@ -128,12 +123,9 @@ static void incrPlaylistCurrent(void)
if (playlist.current < 0)
return;
- if (playlist.current >= playlist.length - 1) {
- if (playlist.repeat)
- playlist.current = 0;
- else
- playlist.current = -1;
- } else
+ if (playlist.current >= playlist.length - 1)
+ playlist.current = playlist.repeat ? 0 : -1;
+ else
playlist.current++;
}
@@ -154,10 +146,9 @@ void initPlaylist(void)
if (param) {
playlist_max_length = strtol(param->value, &test, 10);
- if (*test != '\0') {
+ if (*test != '\0')
FATAL("max playlist length \"%s\" is not an integer, "
"line %i\n", param->value, param->line);
- }
}
playlist_saveAbsolutePaths = getBoolConfigParam(
@@ -166,20 +157,17 @@ void initPlaylist(void)
playlist_saveAbsolutePaths =
DEFAULT_PLAYLIST_SAVE_ABSOLUTE_PATHS;
- playlist.songs = xmalloc(sizeof(Song *) * playlist_max_length);
- playlist.songMod = xmalloc(sizeof(mpd_uint32) * playlist_max_length);
+ playlist.songs = xcalloc(playlist_max_length, sizeof(Song *));
+ playlist.songMod = xmalloc(sizeof(uint32_t) * playlist_max_length);
playlist.order = xmalloc(sizeof(int) * playlist_max_length);
playlist.idToPosition = xmalloc(sizeof(int) * playlist_max_length *
PLAYLIST_HASH_MULT);
playlist.positionToId = xmalloc(sizeof(int) * playlist_max_length);
- memset(playlist.songs, 0, sizeof(char *) * playlist_max_length);
-
srandom(time(NULL));
- for (i = 0; i < playlist_max_length * PLAYLIST_HASH_MULT; i++) {
+ for (i = playlist_max_length * PLAYLIST_HASH_MULT; --i >= 0; )
playlist.idToPosition[i] = -1;
- }
}
static int getNextId(void)
@@ -187,10 +175,8 @@ static int getNextId(void)
static int cur = -1;
do {
- cur++;
- if (cur >= playlist_max_length * PLAYLIST_HASH_MULT) {
+ if (++cur >= playlist_max_length * PLAYLIST_HASH_MULT)
cur = 0;
- }
} while (playlist.idToPosition[cur] != -1);
return cur;
@@ -199,10 +185,10 @@ static int getNextId(void)
void finishPlaylist(void)
{
int i;
- for (i = 0; i < playlist.length; i++) {
- if (playlist.songs[i]->type == SONG_TYPE_URL) {
+
+ for (i = playlist.length; --i >= 0; ) {
+ if (playlist.songs[i]->type == SONG_TYPE_URL)
freeJustSong(playlist.songs[i]);
- }
}
playlist.length = 0;
@@ -225,10 +211,9 @@ void clearPlaylist(void)
stopPlaylist();
- for (i = 0; i < playlist.length; i++) {
- if (playlist.songs[i]->type == SONG_TYPE_URL) {
+ for (i = playlist.length; --i >= 0 ; ) {
+ if (playlist.songs[i]->type == SONG_TYPE_URL)
freeJustSong(playlist.songs[i]);
- }
playlist.idToPosition[playlist.positionToId[i]] = -1;
playlist.songs[i] = NULL;
}
@@ -248,10 +233,9 @@ void showPlaylist(int fd)
int i;
char path_max_tmp[MPD_PATH_MAX];
- for (i = 0; i < playlist.length; i++) {
+ for (i = 0; i < playlist.length; i++)
fdprintf(fd, "%i:%s\n", i,
get_song_url(path_max_tmp, playlist.songs[i]));
- }
}
void savePlaylistState(int fd)
@@ -305,10 +289,9 @@ static void loadPlaylistFromStateFile(FILE *fp, char *buffer,
&& current == song) {
if (state == OB_STATE_PAUSE)
ob_trigger_action(OB_ACTION_PAUSE_SET);
- if (state != OB_STATE_STOP) {
+ if (state != OB_STATE_STOP)
seekSongInPlaylist(playlist.length - 1,
seek_time);
- }
}
if (!myFgets(buffer, PLAYLIST_BUFFER_SIZE, fp))
state_file_fatal();
@@ -381,32 +364,30 @@ static void printPlaylistSongInfo(int fd, int song)
fdprintf(fd, "Pos: %i\nId: %i\n", song, playlist.positionToId[song]);
}
-int playlistChanges(int fd, mpd_uint32 version)
+int playlistChanges(int fd, uint32_t version)
{
int i;
for (i = 0; i < playlist.length; i++) {
if (version > playlist.version ||
playlist.songMod[i] >= version ||
- playlist.songMod[i] == 0) {
+ playlist.songMod[i] == 0)
printPlaylistSongInfo(fd, i);
- }
}
return 0;
}
-int playlistChangesPosId(int fd, mpd_uint32 version)
+int playlistChangesPosId(int fd, uint32_t version)
{
int i;
for (i = 0; i < playlist.length; i++) {
if (version > playlist.version ||
playlist.songMod[i] >= version ||
- playlist.songMod[i] == 0) {
+ playlist.songMod[i] == 0)
fdprintf(fd, "cpos: %i\nId: %i\n",
i, playlist.positionToId[i]);
- }
}
return 0;
@@ -522,7 +503,6 @@ static void queueNextSongInPlaylist(void)
playlist.current = -1;
}
} else if (dc.state == DC_STATE_STOP) {
- /* DEBUG("%s:%d (%d)\n", __func__, __LINE__, playlist.queued);*/
dc_trigger_action(DC_ACTION_START, 0);
}
}
@@ -554,11 +534,15 @@ void playlist_queue_next(void)
wakeup_main_task();
}
-Song *playlist_queued_song(void)
+char *playlist_queued_url(char utf8url[MPD_PATH_MAX])
{
+ Song *song;
+
assert(pthread_equal(pthread_self(), dc.thread));
pthread_mutex_lock(&queue_lock);
- return song_at(playlist.queued);
+ song = song_at(playlist.queued);
+
+ return song ? get_song_url(utf8url, song) : NULL;
}
static void queue_song_locked(int order_num)
@@ -605,15 +589,13 @@ int addToStoredPlaylist(const char *url, const char *utf8file)
DEBUG("add to stored playlist: %s\n", url);
- song = getSongFromDB(url);
- if (song)
+ if ((song = getSongFromDB(url)))
return appendSongToStoredPlaylistByPath(utf8file, song);
if (!isValidRemoteUtf8Url(url))
return ACK_ERROR_NO_EXIST;
- song = newSong(url, SONG_TYPE_URL, NULL);
- if (song) {
+ if ((song = newSong(url, SONG_TYPE_URL, NULL))) {
int ret = appendSongToStoredPlaylistByPath(utf8file, song);
freeJustSong(song);
return ret;
@@ -629,11 +611,10 @@ enum playlist_result addSongToPlaylist(Song * song, int *added_id)
if (playlist.length == playlist_max_length)
return PLAYLIST_RESULT_TOO_LARGE;
- if (playlist_state == PLAYLIST_STATE_PLAY) {
- if (playlist.queued >= 0
- && playlist.current == playlist.length - 1)
- clear_queue();
- }
+ if (playlist_state == PLAYLIST_STATE_PLAY &&
+ playlist.queued >= 0 &&
+ playlist.current == playlist.length - 1)
+ clear_queue();
id = getNextId();
@@ -684,9 +665,8 @@ enum playlist_result swapSongsInPlaylist(int song1, int song2)
return PLAYLIST_RESULT_BAD_RANGE;
if (playlist_state == PLAYLIST_STATE_PLAY) {
- if (playlist.queued >= 0) {
+ if (playlist.queued >= 0)
queuedSong = playlist.order[playlist.queued];
- }
assert(playlist.current >= 0 &&
playlist.current < playlist.length);
currentSong = playlist.order[playlist.current];
@@ -755,21 +735,18 @@ enum playlist_result deleteFromPlaylist(int song)
if (prev_queued >= 0
&& (playlist.order[prev_queued] == song
|| playlist.order[playlist.current] == song)) {
- /* DEBUG(__FILE__": %d (clearing)\n", __LINE__); */
clear_queue();
}
}
- if (playlist.songs[song]->type == SONG_TYPE_URL) {
+ if (playlist.songs[song]->type == SONG_TYPE_URL)
freeJustSong(playlist.songs[song]);
- }
playlist.idToPosition[playlist.positionToId[song]] = -1;
/* delete song from songs array */
- for (i = song; i < playlist.length - 1; i++) {
+ for (i = song; i < playlist.length - 1; i++)
moveSongFromTo(i + 1, i);
- }
/* now find it in the order array */
for (i = 0; i < playlist.length - 1; i++) {
if (playlist.order[i] == song)
@@ -790,8 +767,6 @@ enum playlist_result deleteFromPlaylist(int song)
incrPlaylistVersion();
- /* DEBUG("current: %d, songOrder: %d\n", playlist.current, songOrder); */
- /* DEBUG("playlist_state: %d\n", playlist_state); */
if (playlist_state != PLAYLIST_STATE_STOP
&& playlist.current == songOrder)
stop_current = 1;
@@ -804,13 +779,11 @@ enum playlist_result deleteFromPlaylist(int song)
incrPlaylistCurrent();
}
if (stop_current) {
- /* DEBUG(__FILE__": %d\n", __LINE__); */
if (playlist.current >= 0 && songOrder > 0)
play_order_num(playlist.current, 0);
else
stopPlaylist();
} else {
- /* DEBUG(__FILE__": %d\n", __LINE__); */
queueNextSongInPlaylist();
}
@@ -832,10 +805,9 @@ void deleteASongFromPlaylist(const Song * song)
if (NULL == playlist.songs)
return;
- for (i = 0; i < playlist.length; i++) {
- if (song == playlist.songs[i]) {
+ for (i = playlist.length; --i >= 0; ) {
+ if (mpd_unlikely(song == playlist.songs[i]))
deleteFromPlaylist(i);
- }
}
}
@@ -884,8 +856,6 @@ enum playlist_result playPlaylist(int song, int stopOnError)
{
int i = song;
- DEBUG("%s %d song(%d)\n", __func__, __LINE__, song);
-
player_clearerror();
if (song == -1) {
@@ -896,11 +866,10 @@ enum playlist_result playPlaylist(int song, int stopOnError)
ob_trigger_action(OB_ACTION_PAUSE_UNSET);
return PLAYLIST_RESULT_SUCCESS;
}
- if (playlist.current >= 0 && playlist.current < playlist.length) {
+ if (playlist.current >= 0 && playlist.current < playlist.length)
i = playlist.current;
- } else {
+ else
i = 0;
- }
} else if (song < 0 || song >= playlist.length) {
return PLAYLIST_RESULT_BAD_RANGE;
}
@@ -929,9 +898,8 @@ enum playlist_result playPlaylist(int song, int stopOnError)
enum playlist_result playPlaylistById(int id, int stopOnError)
{
- if (id == -1) {
+ if (id == -1)
return playPlaylist(id, stopOnError);
- }
if (!song_id_exists(id))
return PLAYLIST_RESULT_NO_SUCH_SONG;
@@ -957,8 +925,7 @@ static void sync_metadata(void)
if (!(tag = metadata_pipe_current()))
return;
song = song_at(playlist.current);
- if (!song || song->type != SONG_TYPE_URL ||
- tag_equal(song->tag, tag)) {
+ if (!song || song->type != SONG_TYPE_URL || tag_equal(song->tag, tag)) {
tag_free(tag);
return;
}
@@ -981,9 +948,8 @@ void syncPlayerAndPlaylist(void)
playlist.queued != playlist.current &&
ob_synced() &&
dc.state == DC_STATE_STOP &&
- ob_get_state() != OB_STATE_PAUSE) {
+ ob_get_state() != OB_STATE_PAUSE)
dc_trigger_action(DC_ACTION_START, 0);
- }
}
void nextSongInPlaylist(void)
@@ -1015,10 +981,9 @@ int getPlaylistRandomStatus(void)
void setPlaylistRepeatStatus(int status)
{
- if (playlist_state == PLAYLIST_STATE_PLAY) {
- if (playlist.repeat && !status && playlist.queued == 0)
- clear_queue();
- }
+ if (playlist_state == PLAYLIST_STATE_PLAY &&
+ playlist.repeat && !status && playlist.queued == 0)
+ clear_queue();
playlist.repeat = status;
}
@@ -1066,9 +1031,8 @@ enum playlist_result moveSongInPlaylist(int from, int to)
tmpSong = playlist.songs[from];
tmpId = playlist.positionToId[from];
/* move songs to one less in from->to */
- for (i = from; i < to; i++) {
+ for (i = from; i < to; i++)
moveSongFromTo(i + 1, i);
- }
/* move songs to one more in to->from */
for (i = from; i > to; i--) {
moveSongFromTo(i - 1, i);
@@ -1091,13 +1055,12 @@ enum playlist_result moveSongInPlaylist(int from, int to)
}
}
} else {
- if (playlist.current == from) {
+ if (playlist.current == from)
playlist.current = to;
- } else if (playlist.current > from && playlist.current <= to) {
+ else if (playlist.current > from && playlist.current <= to)
playlist.current--;
- } else if (playlist.current >= to && playlist.current < from) {
+ else if (playlist.current >= to && playlist.current < from)
playlist.current++;
- }
if (queued_is_current)
playlist.queued = playlist.current;
}
@@ -1129,7 +1092,7 @@ static void orderPlaylist(void)
if (queued_is_current)
playlist.queued = playlist.current;
}
- for (i = 0; i < playlist.length; i++)
+ for (i = playlist.length; --i >= 0; )
playlist.order[i] = i;
}
@@ -1154,7 +1117,6 @@ static void randomizeOrder(int start, int end)
int queued_is_current = (playlist.queued == playlist.current);
DEBUG("playlist: randomize from %i to %i\n", start, end);
- DEBUG("%s:%d current: %d\n", __func__, __LINE__, playlist.current);
if (!queued_is_current &&
playlist_state == PLAYLIST_STATE_PLAY &&
@@ -1172,7 +1134,6 @@ static void randomizeOrder(int start, int end)
}
if (queued_is_current)
playlist.queued = playlist.current;
- DEBUG("%s:%d current: %d\n", __func__, __LINE__, playlist.current);
}
void setPlaylistRandomStatus(int status)
@@ -1186,11 +1147,8 @@ void setPlaylistRandomStatus(int status)
randomizeOrder(0, playlist.length - 1);
else
orderPlaylist();
- if (playlist_state == PLAYLIST_STATE_PLAY) {
+ if (playlist_state == PLAYLIST_STATE_PLAY)
queueNextSongInPlaylist();
- DEBUG("%s:%d queued: %d\n",
- __func__,__LINE__,playlist.queued);
- }
}
}
@@ -1314,10 +1272,8 @@ enum playlist_result savePlaylist(const char *utf8file)
int getPlaylistCurrentSong(void)
{
- DEBUG("%s:%d current: %d\n", __func__, __LINE__, playlist.current);
- if (playlist.current >= 0 && playlist.current < playlist.length) {
+ if (playlist.current >= 0 && playlist.current < playlist.length)
return playlist.order[playlist.current];
- }
return -1;
}
@@ -1402,9 +1358,8 @@ int PlaylistInfo(int fd, const char *utf8file, int detail)
}
}
- if (!wrote) {
+ if (!wrote)
fdprintf(fd, SONG_FILE "%s\n", temp);
- }
node = node->nextNode;
}
diff --git a/src/playlist.h b/src/playlist.h
index 6b5fe0cd7..df1bd9e7b 100644
--- a/src/playlist.h
+++ b/src/playlist.h
@@ -68,7 +68,7 @@ enum playlist_result playlistInfo(int fd, int song);
enum playlist_result playlistId(int fd, int song);
-Song *playlist_queued_song(void);
+char *playlist_queued_url(char utf8url[MPD_PATH_MAX]);
void playlist_queue_next(void);
@@ -126,9 +126,9 @@ enum playlist_result seekSongInPlaylistById(int id, float seek_time);
void playlistVersionChange(void);
-int playlistChanges(int fd, mpd_uint32 version);
+int playlistChanges(int fd, uint32_t version);
-int playlistChangesPosId(int fd, mpd_uint32 version);
+int playlistChangesPosId(int fd, uint32_t version);
int PlaylistInfo(int fd, const char *utf8file, int detail);
diff --git a/src/replayGain.c b/src/replayGain.c
index 8926138bb..7576fb974 100644
--- a/src/replayGain.c
+++ b/src/replayGain.c
@@ -106,9 +106,9 @@ void freeReplayGainInfo(ReplayGainInfo * info)
void doReplayGain(ReplayGainInfo * info, char *buffer, int bufferSize,
const AudioFormat * format)
{
- mpd_sint16 *buffer16;
- mpd_sint8 *buffer8;
- mpd_sint32 temp32;
+ int16_t *buffer16;
+ int8_t *buffer8;
+ int32_t temp32;
float scale;
if (replayGainState == REPLAYGAIN_OFF || !info)
@@ -134,8 +134,8 @@ void doReplayGain(ReplayGainInfo * info, char *buffer, int bufferSize,
if (info->scale <= 1.01 && info->scale >= 0.99)
return;
- buffer16 = (mpd_sint16 *) buffer;
- buffer8 = (mpd_sint8 *) buffer;
+ buffer16 = (int16_t *) buffer;
+ buffer8 = (int8_t *) buffer;
scale = info->scale;
diff --git a/src/song.c b/src/song.c
index 5c5024391..dc100899a 100644
--- a/src/song.c
+++ b/src/song.c
@@ -207,19 +207,22 @@ int updateSongInfo(Song * song)
unsigned int next = 0;
char path_max_tmp[MPD_PATH_MAX];
char abs_path[MPD_PATH_MAX];
+ struct mpd_tag *old_tag = song->tag;
+ struct mpd_tag *new_tag = NULL;
utf8_to_fs_charset(abs_path, get_song_url(path_max_tmp, song));
rmp2amp_r(abs_path, abs_path);
- if (song->tag)
- tag_free(song->tag);
-
- song->tag = NULL;
-
- while (!song->tag && (plugin = isMusic(abs_path,
- &(song->mtime),
- next++))) {
- song->tag = plugin->tagDupFunc(abs_path);
+ while ((plugin = isMusic(abs_path, &song->mtime, next++))) {
+ if ((new_tag = plugin->tagDupFunc(abs_path)))
+ break;
+ }
+ if (new_tag && tag_equal(new_tag, old_tag)) {
+ tag_free(new_tag);
+ } else {
+ song->tag = new_tag;
+ if (old_tag)
+ tag_free(old_tag);
}
if (!song->tag || song->tag->time < 0)
return -1;
diff --git a/src/song.h b/src/song.h
index 0fbee7b07..9bb96aba0 100644
--- a/src/song.h
+++ b/src/song.h
@@ -37,7 +37,7 @@
typedef struct _Song {
char *url;
- mpd_sint8 type;
+ int8_t type;
struct mpd_tag *tag;
struct _Directory *parentDir;
time_t mtime;
diff --git a/src/tag.c b/src/tag.c
index f1acb7c79..2dcaf4ef8 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -52,7 +52,7 @@ const char *mpdTagItemKeys[TAG_NUM_OF_ITEM_TYPES] = {
"Disc"
};
-static mpd_sint8 ignoreTagItems[TAG_NUM_OF_ITEM_TYPES];
+static int8_t ignoreTagItems[TAG_NUM_OF_ITEM_TYPES];
static size_t items_size(const struct mpd_tag *tag)
{
diff --git a/src/tag.h b/src/tag.h
index a05f7654a..744b82e83 100644
--- a/src/tag.h
+++ b/src/tag.h
@@ -48,7 +48,7 @@ struct tag_item {
struct mpd_tag {
int time;
struct tag_item **items;
- mpd_uint8 numOfItems;
+ uint8_t numOfItems;
};
struct mpd_tag *tag_ape_load(const char *file);