From 4c039c6dc7bd6d9618f95458e170e05cbe01ab75 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Tue, 1 Jun 2004 15:14:09 +0000 Subject: [PATCH] improve _open error messages Original commit message from CVS: improve _open error messages --- ChangeLog | 6 ++++++ ext/alsa/gstalsa.c | 34 +++++++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 354641b86c..94b5ef701c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2004-06-01 Thomas Vander Stichele + + * ext/alsa/gstalsa.c: (gst_alsa_open_audio): + improve error messages on open + + 2004-06-01 Thomas Vander Stichele * sys/v4l/v4l-overlay_calls.c: (gst_v4l_set_overlay): diff --git a/ext/alsa/gstalsa.c b/ext/alsa/gstalsa.c index 129b575527..bc5c114da5 100644 --- a/ext/alsa/gstalsa.c +++ b/ext/alsa/gstalsa.c @@ -1174,6 +1174,7 @@ static gboolean gst_alsa_open_audio (GstAlsa * this) { snd_pcm_info_t *info; + int ret; g_assert (this != NULL); g_assert (this->handle == NULL); @@ -1191,11 +1192,34 @@ gst_alsa_open_audio (GstAlsa * this) "error opening log output: %s"); #endif - if (snd_pcm_open (&this->handle, this->device, - GST_ALSA_GET_CLASS (this)->stream, SND_PCM_NONBLOCK) < 0) { - GST_ELEMENT_ERROR (GST_ELEMENT (this), RESOURCE, BUSY, - (_("Alsa device \"%s\" is already in use by another program."), - this->device), (NULL)); + if ((ret = snd_pcm_open (&this->handle, this->device, + GST_ALSA_GET_CLASS (this)->stream, SND_PCM_NONBLOCK)) < 0) { + /* ALSA inverts standard errno.h error codes */ + switch (-ret) { + case EBUSY: + GST_ELEMENT_ERROR (GST_ELEMENT (this), RESOURCE, BUSY, + (_("ALSA device \"%s\" is already in use by another program."), + this->device), (NULL)); + break; + case EACCES: + case ETXTBSY: + GST_ELEMENT_ERROR (GST_ELEMENT (this), RESOURCE, OPEN_READ_WRITE, + (_("Could not access ALSA device \"%s\", check its permissions."), + this->device), GST_ERROR_SYSTEM); + break; + + case ENXIO: + case ENODEV: + case ENOENT: + GST_ELEMENT_ERROR (GST_ELEMENT (this), RESOURCE, BUSY, + (_("ALSA device \"%s\" does not exist."), this->device), (NULL)); + break; + default: + GST_ELEMENT_ERROR (GST_ELEMENT (this), RESOURCE, BUSY, + (_("ALSA device \"%s\" had an error."), + this->device), ("ALSA error %d: %s", ret, snd_strerror (ret))); + break; + } return FALSE; }