From b7bfa24f22a3a5a7709ce425ffc84bd4bb64be08 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 2 Mar 2009 09:42:16 +0100 Subject: pcm_volume: return bool Don't abort MPD when a sample format is not supported by pcm_volume(). --- src/pcm_volume.c | 15 +++++++-------- src/pcm_volume.h | 4 +++- src/player_thread.c | 13 +++++++++++-- test/read_tags.c | 3 ++- test/run_decoder.c | 3 ++- 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/pcm_volume.c b/src/pcm_volume.c index 383caecc..49b0f9fb 100644 --- a/src/pcm_volume.c +++ b/src/pcm_volume.c @@ -112,36 +112,35 @@ pcm_volume_change_24(int32_t *buffer, unsigned num_samples, int volume) } } -void +bool pcm_volume(void *buffer, int length, const struct audio_format *format, int volume) { if (volume == PCM_VOLUME_1) - return; + return true; if (volume <= 0) { memset(buffer, 0, length); - return; + return true; } switch (format->bits) { case 8: pcm_volume_change_8((int8_t *)buffer, length, volume); - break; + return true; case 16: pcm_volume_change_16((int16_t *)buffer, length / 2, volume); - break; + return true; case 24: pcm_volume_change_24((int32_t*)buffer, length / 4, volume); - break; + return true; default: - g_error("%u bits not supported by pcm_volume!\n", - format->bits); + return false; } } diff --git a/src/pcm_volume.h b/src/pcm_volume.h index 1b5e7fb0..e21ea6f5 100644 --- a/src/pcm_volume.h +++ b/src/pcm_volume.h @@ -22,6 +22,7 @@ #include "pcm_prng.h" #include +#include enum { /** this value means "100% volume" */ @@ -62,8 +63,9 @@ pcm_volume_dither(void) * @param length the length of the PCM buffer * @param format the audio format of the PCM buffer * @param volume the volume between 0 and #PCM_VOLUME_1 + * @return true on success, false if the audio format is not supported */ -void +bool pcm_volume(void *buffer, int length, const struct audio_format *format, int volume); diff --git a/src/player_thread.c b/src/player_thread.c index 24942fbf..fb3e9bf6 100644 --- a/src/player_thread.c +++ b/src/player_thread.c @@ -238,6 +238,8 @@ static bool play_chunk(struct song *song, struct music_chunk *chunk, const struct audio_format *format, double sizeToTime) { + bool success; + pc.elapsed_time = chunk->times; pc.bit_rate = chunk->bit_rate; @@ -266,8 +268,15 @@ play_chunk(struct song *song, struct music_chunk *chunk, if (chunk->length == 0) return true; - pcm_volume(chunk->data, chunk->length, - format, pc.software_volume); + success = pcm_volume(chunk->data, chunk->length, + format, pc.software_volume); + if (!success) { + g_warning("pcm_volume() failed on %u:%u:%u", + format->sample_rate, format->bits, format->channels); + pc.errored_song = dc.current_song; + pc.error = PLAYER_ERROR_AUDIO; + return false; + } if (!audio_output_all_play(chunk->data, chunk->length)) { pc.errored_song = dc.current_song; diff --git a/test/read_tags.c b/test/read_tags.c index cdee3722..1b223f07 100644 --- a/test/read_tags.c +++ b/test/read_tags.c @@ -32,11 +32,12 @@ /** * No-op dummy. */ -void +bool pcm_volume(G_GNUC_UNUSED void *buffer, G_GNUC_UNUSED int length, G_GNUC_UNUSED const struct audio_format *format, G_GNUC_UNUSED int volume) { + return true; } void diff --git a/test/run_decoder.c b/test/run_decoder.c index 8d11494c..6bd331b0 100644 --- a/test/run_decoder.c +++ b/test/run_decoder.c @@ -30,11 +30,12 @@ /** * No-op dummy. */ -void +bool pcm_volume(G_GNUC_UNUSED void *buffer, G_GNUC_UNUSED int length, G_GNUC_UNUSED const struct audio_format *format, G_GNUC_UNUSED int volume) { + return true; } struct decoder { -- cgit v1.2.3