diff options
author | Max Kellermann <max@duempel.org> | 2008-10-29 20:40:27 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-10-29 20:40:27 +0100 |
commit | 58c5bee9f0bcb46da7d113b66a4e1e2d7add9837 (patch) | |
tree | 4517d2156aa3643247e7f2fc886af86d3dfd8791 /src/output | |
parent | 03390d8be1cb8983778faf6eedb9bcfd26a6dbce (diff) | |
download | mpd-58c5bee9f0bcb46da7d113b66a4e1e2d7add9837.tar.gz mpd-58c5bee9f0bcb46da7d113b66a4e1e2d7add9837.tar.xz mpd-58c5bee9f0bcb46da7d113b66a4e1e2d7add9837.zip |
output: use bool for return values and flags
Don't return 0/-1 on success/error, but true/false. Instead of int,
use bool for storing flags.
Diffstat (limited to 'src/output')
-rw-r--r-- | src/output/alsa_plugin.c | 19 | ||||
-rw-r--r-- | src/output/ao_plugin.c | 17 | ||||
-rw-r--r-- | src/output/fifo_plugin.c | 24 | ||||
-rw-r--r-- | src/output/jack_plugin.c | 16 | ||||
-rw-r--r-- | src/output/mvp_plugin.c | 28 | ||||
-rw-r--r-- | src/output/null_plugin.c | 12 | ||||
-rw-r--r-- | src/output/oss_plugin.c | 33 | ||||
-rw-r--r-- | src/output/osx_plugin.c | 29 | ||||
-rw-r--r-- | src/output/pulse_plugin.c | 22 | ||||
-rw-r--r-- | src/output/shout_plugin.c | 24 | ||||
-rw-r--r-- | src/output/shout_plugin.h | 2 |
11 files changed, 116 insertions, 110 deletions
diff --git a/src/output/alsa_plugin.c b/src/output/alsa_plugin.c index e812e49fc..2d4f9c239 100644 --- a/src/output/alsa_plugin.c +++ b/src/output/alsa_plugin.c @@ -125,7 +125,7 @@ static void alsa_finishDriver(void *data) freeAlsaData(ad); } -static int alsa_testDefault(void) +static bool alsa_testDefault(void) { snd_pcm_t *handle; @@ -134,11 +134,11 @@ static int alsa_testDefault(void) if (ret) { WARNING("Error opening default ALSA device: %s\n", snd_strerror(-ret)); - return -1; + return false; } else snd_pcm_close(handle); - return 0; + return true; } static snd_pcm_format_t get_bitformat(const struct audio_format *af) @@ -152,7 +152,7 @@ static snd_pcm_format_t get_bitformat(const struct audio_format *af) return SND_PCM_FORMAT_UNKNOWN; } -static int alsa_openDevice(void *data, struct audio_format *audioFormat) +static bool alsa_openDevice(void *data, struct audio_format *audioFormat) { AlsaData *ad = data; snd_pcm_format_t bitformat; @@ -318,7 +318,7 @@ configure_hw: "%u Hz\n", ad->device, audioFormat->bits, channels, sample_rate); - return 0; + return true; error: if (cmd) { @@ -332,7 +332,7 @@ fail: if (ad->pcmHandle) snd_pcm_close(ad->pcmHandle); ad->pcmHandle = NULL; - return -1; + return false; } static int alsa_errorRecovery(AlsaData * ad, int err) @@ -393,7 +393,8 @@ static void alsa_closeDevice(void *data) } } -static int alsa_playAudio(void *data, const char *playChunk, size_t size) +static bool +alsa_playAudio(void *data, const char *playChunk, size_t size) { AlsaData *ad = data; int ret; @@ -412,7 +413,7 @@ static int alsa_playAudio(void *data, const char *playChunk, size_t size) "error: %s\n", ad->device, snd_strerror(-errno)); alsa_closeDevice(ad); - return -1; + return false; } continue; } @@ -421,7 +422,7 @@ static int alsa_playAudio(void *data, const char *playChunk, size_t size) size -= ret; } - return 0; + return true; } const struct audio_output_plugin alsaPlugin = { diff --git a/src/output/ao_plugin.c b/src/output/ao_plugin.c index b5cebc93b..d2c7dab6e 100644 --- a/src/output/ao_plugin.c +++ b/src/output/ao_plugin.c @@ -168,8 +168,8 @@ static void audioOutputAo_closeDevice(void *data) } } -static int audioOutputAo_openDevice(void *data, - struct audio_format *audio_format) +static bool +audioOutputAo_openDevice(void *data, struct audio_format *audio_format) { ao_sample_format format; AoData *ad = (AoData *)data; @@ -186,9 +186,9 @@ static int audioOutputAo_openDevice(void *data, ad->device = ao_open_live(ad->driverId, &format, ad->options); if (ad->device == NULL) - return -1; + return false; - return 0; + return true; } /** @@ -208,13 +208,14 @@ static int ao_play_deconst(ao_device *device, const void *output_samples, return ao_play(device, u.out, num_bytes); } -static int audioOutputAo_play(void *data, const char *playChunk, size_t size) +static bool +audioOutputAo_play(void *data, const char *playChunk, size_t size) { AoData *ad = (AoData *)data; size_t chunk_size; if (ad->device == NULL) - return -1; + return false; while (size > 0) { chunk_size = (size_t)ad->writeSize > size @@ -224,14 +225,14 @@ static int audioOutputAo_play(void *data, const char *playChunk, size_t size) audioOutputAo_error(); ERROR("closing audio device due to write error\n"); audioOutputAo_closeDevice(ad); - return -1; + return false; } playChunk += chunk_size; size -= chunk_size; } - return 0; + return true; } const struct audio_output_plugin aoPlugin = { diff --git a/src/output/fifo_plugin.c b/src/output/fifo_plugin.c index cd83177f8..fe85d6644 100644 --- a/src/output/fifo_plugin.c +++ b/src/output/fifo_plugin.c @@ -128,17 +128,17 @@ static int checkFifo(FifoData *fd) return 0; } -static int openFifo(FifoData *fd) +static bool openFifo(FifoData *fd) { if (checkFifo(fd) < 0) - return -1; + return false; fd->input = open(fd->path, O_RDONLY|O_NONBLOCK); if (fd->input < 0) { ERROR("Could not open FIFO \"%s\" for reading: %s\n", fd->path, strerror(errno)); closeFifo(fd); - return -1; + return false; } fd->output = open(fd->path, O_WRONLY|O_NONBLOCK); @@ -146,10 +146,10 @@ static int openFifo(FifoData *fd) ERROR("Could not open FIFO \"%s\" for writing: %s\n", fd->path, strerror(errno)); closeFifo(fd); - return -1; + return false; } - return 0; + return true; } static void *fifo_initDriver(mpd_unused struct audio_output *ao, @@ -175,7 +175,7 @@ static void *fifo_initDriver(mpd_unused struct audio_output *ao, fd = newFifoData(); fd->path = path; - if (openFifo(fd) < 0) { + if (!openFifo(fd)) { freeFifoData(fd); return NULL; } @@ -191,7 +191,7 @@ static void fifo_finishDriver(void *data) freeFifoData(fd); } -static int fifo_openDevice(void *data, +static bool fifo_openDevice(void *data, struct audio_format *audio_format) { FifoData *fd = (FifoData *)data; @@ -201,7 +201,7 @@ static int fifo_openDevice(void *data, fd->timer = timer_new(audio_format); - return 0; + return true; } static void fifo_closeDevice(void *data) @@ -231,8 +231,8 @@ static void fifo_dropBufferedAudio(void *data) } } -static int fifo_playAudio(void *data, - const char *playChunk, size_t size) +static bool +fifo_playAudio(void *data, const char *playChunk, size_t size) { FifoData *fd = (FifoData *)data; size_t offset = 0; @@ -260,14 +260,14 @@ static int fifo_playAudio(void *data, ERROR("Closing FIFO output \"%s\" due to write error: " "%s\n", fd->path, strerror(errno)); fifo_closeDevice(fd); - return -1; + return false; } size -= bytes; offset += bytes; } - return 0; + return true; } const struct audio_output_plugin fifoPlugin = { diff --git a/src/output/jack_plugin.c b/src/output/jack_plugin.c index 7f10db976..1e6c81b75 100644 --- a/src/output/jack_plugin.c +++ b/src/output/jack_plugin.c @@ -242,10 +242,10 @@ mpd_jack_init(struct audio_output *ao, return jd; } -static int +static bool mpd_jack_test_default_device(void) { - return 0; + return true; } static int @@ -328,7 +328,7 @@ mpd_jack_connect(struct jack_data *jd, struct audio_format *audio_format) return 1; } -static int +static bool mpd_jack_open(void *data, struct audio_format *audio_format) { struct jack_data *jd = data; @@ -337,12 +337,12 @@ mpd_jack_open(void *data, struct audio_format *audio_format) if (jd->client == NULL && mpd_jack_connect(jd, audio_format) < 0) { mpd_jack_client_free(jd); - return -1; + return false; } set_audioformat(jd, audio_format); - return 0; + return true; } static void @@ -422,7 +422,7 @@ mpd_jack_write_samples(struct jack_data *jd, const void *src, } } -static int +static bool mpd_jack_play(void *data, const char *buff, size_t size) { struct jack_data *jd = data; @@ -433,7 +433,7 @@ mpd_jack_play(void *data, const char *buff, size_t size) ERROR("Refusing to play, because there is no client thread.\n"); mpd_jack_client_free(jd); audio_output_closed(jd->ao); - return 0; + return true; } assert(size % frame_size == 0); @@ -462,7 +462,7 @@ mpd_jack_play(void *data, const char *buff, size_t size) } - return 0; + return true; } const struct audio_output_plugin jackPlugin = { diff --git a/src/output/mvp_plugin.c b/src/output/mvp_plugin.c index 94f4f0ea7..9a56e7943 100644 --- a/src/output/mvp_plugin.c +++ b/src/output/mvp_plugin.c @@ -81,7 +81,7 @@ static unsigned pcmfrequencies[][3] = { static const unsigned numfrequencies = sizeof(pcmfrequencies) / sizeof(pcmfrequencies[0]); -static int mvp_testDefault(void) +static bool mvp_testDefault(void) { int fd; @@ -89,13 +89,13 @@ static int mvp_testDefault(void) if (fd) { close(fd); - return 0; + return true; } WARNING("Error opening PCM device \"/dev/adec_pcm\": %s\n", strerror(errno)); - return -1; + return false; } static void *mvp_initDriver(mpd_unused struct audio_output *audio_output, @@ -178,7 +178,8 @@ static int mvp_setPcmParams(MvpData * md, unsigned long rate, int channels, return 0; } -static int mvp_openDevice(void *data, struct audio_format *audioFormat) +static bool +mvp_openDevice(void *data, struct audio_format *audioFormat) { MvpData *md = data; long long int stc = 0; @@ -186,24 +187,24 @@ static int mvp_openDevice(void *data, struct audio_format *audioFormat) if ((md->fd = open("/dev/adec_pcm", O_RDWR | O_NONBLOCK)) < 0) { ERROR("Error opening /dev/adec_pcm: %s\n", strerror(errno)); - return -1; + return false; } if (ioctl(md->fd, MVP_SET_AUD_SRC, 1) < 0) { ERROR("Error setting audio source: %s\n", strerror(errno)); - return -1; + return false; } if (ioctl(md->fd, MVP_SET_AUD_STREAMTYPE, 0) < 0) { ERROR("Error setting audio streamtype: %s\n", strerror(errno)); - return -1; + return false; } if (ioctl(md->fd, MVP_SET_AUD_FORMAT, &mix) < 0) { ERROR("Error setting audio format: %s\n", strerror(errno)); - return -1; + return false; } ioctl(md->fd, MVP_SET_AUD_STC, &stc); if (ioctl(md->fd, MVP_SET_AUD_BYPASS, 1) < 0) { ERROR("Error setting audio streamtype: %s\n", strerror(errno)); - return -1; + return false; } #ifdef WORDS_BIGENDIAN mvp_setPcmParams(md, audioFormat->sample_rate, audioFormat->channels, @@ -213,7 +214,7 @@ static int mvp_openDevice(void *data, struct audio_format *audioFormat) 1, audioFormat->bits); #endif md->audio_format = *audioFormat; - return 0; + return true; } static void mvp_closeDevice(void *data) @@ -235,7 +236,8 @@ static void mvp_dropBufferedAudio(void *data) } } -static int mvp_playAudio(void *data, const char *playChunk, size_t size) +static bool +mvp_playAudio(void *data, const char *playChunk, size_t size) { MvpData *md = data; ssize_t ret; @@ -252,12 +254,12 @@ static int mvp_playAudio(void *data, const char *playChunk, size_t size) ERROR("closing mvp PCM device due to write error: " "%s\n", strerror(errno)); mvp_closeDevice(md); - return -1; + return false; } playChunk += ret; size -= ret; } - return 0; + return true; } const struct audio_output_plugin mvpPlugin = { diff --git a/src/output/null_plugin.c b/src/output/null_plugin.c index ff3a9833c..bef2ff924 100644 --- a/src/output/null_plugin.c +++ b/src/output/null_plugin.c @@ -33,13 +33,13 @@ static void *null_initDriver(mpd_unused struct audio_output *audioOutput, return nd; } -static int null_openDevice(void *data, - struct audio_format *audio_format) +static bool +null_openDevice(void *data, struct audio_format *audio_format) { struct null_data *nd = data; nd->timer = timer_new(audio_format); - return 0; + return true; } static void null_closeDevice(void *data) @@ -52,8 +52,8 @@ static void null_closeDevice(void *data) } } -static int null_playAudio(void *data, - mpd_unused const char *playChunk, size_t size) +static bool +null_playAudio(void *data, mpd_unused const char *playChunk, size_t size) { struct null_data *nd = data; Timer *timer = nd->timer; @@ -65,7 +65,7 @@ static int null_playAudio(void *data, timer_add(timer, size); - return 0; + return true; } static void null_dropBufferedAudio(void *data) diff --git a/src/output/oss_plugin.c b/src/output/oss_plugin.c index 2992368d9..26bc1b3aa 100644 --- a/src/output/oss_plugin.c +++ b/src/output/oss_plugin.c @@ -322,20 +322,20 @@ static int oss_statDevice(const char *device, int *stErrno) static const char *default_devices[] = { "/dev/sound/dsp", "/dev/dsp" }; -static int oss_testDefault(void) +static bool oss_testDefault(void) { int fd, i; for (i = ARRAY_SIZE(default_devices); --i >= 0; ) { if ((fd = open(default_devices[i], O_WRONLY)) >= 0) { xclose(fd); - return 0; + return true; } WARNING("Error opening OSS device \"%s\": %s\n", default_devices[i], strerror(errno)); } - return -1; + return false; } static void *oss_open_default(ConfigParam *param) @@ -438,7 +438,7 @@ static void oss_close(OssData * od) od->fd = -1; } -static int oss_open(OssData *od) +static bool oss_open(OssData *od) { int tmp; @@ -486,23 +486,24 @@ static int oss_open(OssData *od) goto fail; } - return 0; + return true; fail: oss_close(od); - return -1; + return false; } -static int oss_openDevice(void *data, - struct audio_format *audioFormat) +static bool +oss_openDevice(void *data, struct audio_format *audioFormat) { - int ret; + bool ret; OssData *od = data; od->audio_format = *audioFormat; - if ((ret = oss_open(od)) < 0) - return ret; + ret = oss_open(od); + if (!ret) + return false; *audioFormat = od->audio_format; @@ -531,15 +532,15 @@ static void oss_dropBufferedAudio(void *data) } } -static int oss_playAudio(void *data, - const char *playChunk, size_t size) +static bool +oss_playAudio(void *data, const char *playChunk, size_t size) { OssData *od = data; ssize_t ret; /* reopen the device since it was closed by dropBufferedAudio */ if (od->fd < 0 && oss_open(od) < 0) - return -1; + return false; while (size > 0) { ret = write(od->fd, playChunk, size); @@ -549,13 +550,13 @@ static int oss_playAudio(void *data, ERROR("closing oss device \"%s\" due to write error: " "%s\n", od->device, strerror(errno)); oss_closeDevice(od); - return -1; + return false; } playChunk += ret; size -= ret; } - return 0; + return true; } const struct audio_output_plugin ossPlugin = { diff --git a/src/output/osx_plugin.c b/src/output/osx_plugin.c index a3f67fa68..a31a6e736 100644 --- a/src/output/osx_plugin.c +++ b/src/output/osx_plugin.c @@ -49,7 +49,7 @@ static OsxData *newOsxData() return ret; } -static int osx_testDefault() +static bool osx_testDefault() { /*AudioUnit au; ComponentDescription desc; @@ -74,7 +74,7 @@ static int osx_testDefault() CloseComponent(au); */ - return 0; + return true; } static int osx_initDriver(struct audio_output *audioOutput, @@ -212,8 +212,9 @@ static OSStatus osx_render(void *vdata, return 0; } -static int osx_openDevice(struct audio_output *audioOutput, - struct audio_format *audioFormat) +static bool +osx_openDevice(struct audio_output *audioOutput, + struct audio_format *audioFormat) { OsxData *od = (OsxData *) audioOutput->data; ComponentDescription desc; @@ -230,18 +231,18 @@ static int osx_openDevice(struct audio_output *audioOutput, comp = FindNextComponent(NULL, &desc); if (comp == 0) { ERROR("Error finding OS X component\n"); - return -1; + return false; } if (OpenAComponent(comp, &od->au) != noErr) { ERROR("Unable to open OS X component\n"); - return -1; + return false; } if (AudioUnitInitialize(od->au) != 0) { CloseComponent(od->au); ERROR("Unable to initialize OS X audio unit\n"); - return -1; + return false; } callback.inputProc = osx_render; @@ -253,7 +254,7 @@ static int osx_openDevice(struct audio_output *audioOutput, AudioUnitUninitialize(od->au); CloseComponent(od->au); ERROR("unable to set callback for OS X audio unit\n"); - return -1; + return false; } streamDesc.mSampleRate = audioFormat->sample_rate; @@ -275,7 +276,7 @@ static int osx_openDevice(struct audio_output *audioOutput, AudioUnitUninitialize(od->au); CloseComponent(od->au); ERROR("Unable to set format on OS X device\n"); - return -1; + return false; } /* create a buffer of 1s */ @@ -286,11 +287,11 @@ static int osx_openDevice(struct audio_output *audioOutput, od->pos = 0; od->len = 0; - return 0; + return true; } -static int osx_play(struct audio_output *audioOutput, - const char *playChunk, size_t size) +static bool +osx_play(struct audio_output *audioOutput, const char *playChunk, size_t size) { OsxData *od = (OsxData *) audioOutput->data; size_t bytesToCopy; @@ -304,7 +305,7 @@ static int osx_play(struct audio_output *audioOutput, err = AudioOutputUnitStart(od->au); if (err) { ERROR("unable to start audio output: %i\n", err); - return -1; + return false; } } @@ -345,7 +346,7 @@ static int osx_play(struct audio_output *audioOutput, pthread_mutex_unlock(&od->mutex); /* DEBUG("osx_play: leave\n"); */ - return 0; + return true; } const struct audio_output_plugin osxPlugin = { diff --git a/src/output/pulse_plugin.c b/src/output/pulse_plugin.c index 2104fe81e..c6849dbc6 100644 --- a/src/output/pulse_plugin.c +++ b/src/output/pulse_plugin.c @@ -86,7 +86,7 @@ static void pulse_finish(void *data) pulse_free_data(pd); } -static int pulse_test_default_device(void) +static bool pulse_test_default_device(void) { pa_simple *s; pa_sample_spec ss; @@ -101,15 +101,15 @@ static int pulse_test_default_device(void) if (!s) { g_message("Cannot connect to default PulseAudio server: %s\n", pa_strerror(error)); - return -1; + return false; } pa_simple_free(s); - return 0; + return true; } -static int +static bool pulse_open(void *data, struct audio_format *audio_format) { struct pulse_data *pd = data; @@ -121,7 +121,7 @@ pulse_open(void *data, struct audio_format *audio_format) if (pd->num_connect_attempts != 0 && (t - pd->last_connect_attempt) < CONN_ATTEMPT_INTERVAL) - return -1; + return false; pd->num_connect_attempts++; pd->last_connect_attempt = t; @@ -143,7 +143,7 @@ pulse_open(void *data, struct audio_format *audio_format) "\"%s\" (attempt %i): %s\n", audio_output_get_name(pd->ao), pd->num_connect_attempts, pa_strerror(error)); - return -1; + return false; } pd->num_connect_attempts = 0; @@ -154,7 +154,7 @@ pulse_open(void *data, struct audio_format *audio_format) audio_format->bits, audio_format->channels, audio_format->sample_rate); - return 0; + return true; } static void pulse_cancel(void *data) @@ -179,8 +179,8 @@ static void pulse_close(void *data) } } -static int pulse_play(void *data, - const char *playChunk, size_t size) +static bool +pulse_play(void *data, const char *playChunk, size_t size) { struct pulse_data *pd = data; int error; @@ -191,10 +191,10 @@ static int pulse_play(void *data, audio_output_get_name(pd->ao), pa_strerror(error)); pulse_close(pd); - return -1; + return false; } - return 0; + return true; } const struct audio_output_plugin pulse_plugin = { diff --git a/src/output/shout_plugin.c b/src/output/shout_plugin.c index dd909bdae..7bd806d36 100644 --- a/src/output/shout_plugin.c +++ b/src/output/shout_plugin.c @@ -354,7 +354,7 @@ static void close_shout_conn(struct shout_data * sd) shout_get_error(sd->shout_conn)); } - sd->opened = 0; + sd->opened = false; } static void my_shout_finish_driver(void *data) @@ -465,27 +465,27 @@ static int open_shout_conn(void *data) write_page(sd); sd->shout_error = 0; - sd->opened = 1; + sd->opened = true; sd->tag_to_send = 1; sd->conn_attempts = 0; return 0; } -static int my_shout_open_device(void *data, +static bool my_shout_open_device(void *data, struct audio_format *audio_format) { struct shout_data *sd = (struct shout_data *)data; if (!sd->opened && open_shout_conn(sd) < 0) - return -1; + return false; if (sd->timer) timer_free(sd->timer); sd->timer = timer_new(audio_format); - return 0; + return true; } static void send_metadata(struct shout_data * sd) @@ -508,8 +508,8 @@ static void send_metadata(struct shout_data * sd) sd->tag_to_send = 0; } -static int my_shout_play(void *data, - const char *chunk, size_t size) +static bool +my_shout_play(void *data, const char *chunk, size_t size) { struct shout_data *sd = (struct shout_data *)data; int status; @@ -526,24 +526,24 @@ static int my_shout_play(void *data, status = open_shout_conn(sd); if (status < 0) { my_shout_close_device(sd); - return -1; + return false; } else if (status > 0) { timer_sync(sd->timer); - return 0; + return true; } } if (sd->encoder->encode_func(sd, chunk, size)) { my_shout_close_device(sd); - return -1; + return false; } if (write_page(sd) < 0) { my_shout_close_device(sd); - return -1; + return false; } - return 0; + return true; } static void my_shout_pause(void *data) diff --git a/src/output/shout_plugin.h b/src/output/shout_plugin.h index ae7d23b03..2ddde22ae 100644 --- a/src/output/shout_plugin.h +++ b/src/output/shout_plugin.h @@ -65,7 +65,7 @@ struct shout_data { float quality; int bitrate; - int opened; + bool opened; struct tag *tag; int tag_to_send; |