ext/alsa/gstalsamixer.c: Fix for cases where we fail to attach to a mixer.

Original commit message from CVS:
* ext/alsa/gstalsamixer.c: (gst_alsa_mixer_open),
(gst_alsa_mixer_close), (gst_alsa_mixer_supported),
(gst_alsa_mixer_build_list), (gst_alsa_mixer_free_list),
(gst_alsa_mixer_change_state), (gst_alsa_mixer_list_tracks),
(gst_alsa_mixer_get_volume), (gst_alsa_mixer_set_volume),
(gst_alsa_mixer_set_mute), (gst_alsa_mixer_set_record):
Fix for cases where we fail to attach to a mixer.
This commit is contained in:
Ronald S. Bultje 2004-05-16 20:46:12 +00:00
parent 49c96eeb84
commit 35aff63385
2 changed files with 38 additions and 20 deletions

View file

@ -1,3 +1,13 @@
2004-05-16 Ronald Bultje <rbultje@ronald.bitfreak.net>
* ext/alsa/gstalsamixer.c: (gst_alsa_mixer_open),
(gst_alsa_mixer_close), (gst_alsa_mixer_supported),
(gst_alsa_mixer_build_list), (gst_alsa_mixer_free_list),
(gst_alsa_mixer_change_state), (gst_alsa_mixer_list_tracks),
(gst_alsa_mixer_get_volume), (gst_alsa_mixer_set_volume),
(gst_alsa_mixer_set_mute), (gst_alsa_mixer_set_record):
Fix for cases where we fail to attach to a mixer.
2004-05-16 Ronald Bultje <rbultje@ronald.bitfreak.net> 2004-05-16 Ronald Bultje <rbultje@ronald.bitfreak.net>
* gst-libs/gst/riff/riff-read.c: (gst_riff_read_seek): * gst-libs/gst/riff/riff-read.c: (gst_riff_read_seek):

View file

@ -132,19 +132,25 @@ gst_alsa_mixer_open (GstAlsaMixer * mixer)
{ {
gint err, device; gint err, device;
GstAlsa *alsa = GST_ALSA (mixer); GstAlsa *alsa = GST_ALSA (mixer);
gchar *nocomma; gchar *nocomma = NULL;
mixer->mixer_handle = (snd_mixer_t *) - 1; mixer->mixer_handle = NULL;
/* open and initialize the mixer device */ /* open and initialize the mixer device */
err = snd_mixer_open (&mixer->mixer_handle, 0); err = snd_mixer_open (&mixer->mixer_handle, 0);
if (err < 0 || mixer->mixer_handle == NULL) { if (err < 0 || mixer->mixer_handle == NULL) {
GST_ERROR_OBJECT (GST_OBJECT (mixer), "Cannot open mixer device."); GST_ERROR_OBJECT (GST_OBJECT (mixer), "Cannot open mixer device.");
mixer->mixer_handle = (snd_mixer_t *) - 1; mixer->mixer_handle = NULL;
return FALSE; return FALSE;
} }
if (!strncmp (alsa->device, "hw:", 3))
nocomma = g_strdup (alsa->device); nocomma = g_strdup (alsa->device);
else if (!strncmp (alsa->device, "plughw:", 7))
nocomma = g_strdup (alsa->device + 4);
else
goto error;
if (strchr (nocomma, ',')) if (strchr (nocomma, ','))
strchr (nocomma, ',')[0] = '\0'; strchr (nocomma, ',')[0] = '\0';
@ -179,7 +185,7 @@ gst_alsa_mixer_open (GstAlsaMixer * mixer)
error: error:
snd_mixer_close (mixer->mixer_handle); snd_mixer_close (mixer->mixer_handle);
mixer->mixer_handle = (snd_mixer_t *) - 1; mixer->mixer_handle = NULL;
g_free (nocomma); g_free (nocomma);
return FALSE; return FALSE;
} }
@ -189,7 +195,7 @@ gst_alsa_mixer_close (GstAlsaMixer * mixer)
{ {
GstAlsa *alsa = GST_ALSA (mixer); GstAlsa *alsa = GST_ALSA (mixer);
if (((gint) mixer->mixer_handle) == -1) if (mixer->mixer_handle == NULL)
return; return;
if (alsa->cardname) { if (alsa->cardname) {
@ -197,7 +203,7 @@ gst_alsa_mixer_close (GstAlsaMixer * mixer)
alsa->cardname = NULL; alsa->cardname = NULL;
} }
snd_mixer_close (mixer->mixer_handle); snd_mixer_close (mixer->mixer_handle);
mixer->mixer_handle = (snd_mixer_t *) - 1; mixer->mixer_handle = NULL;
} }
static void static void
@ -224,7 +230,7 @@ gst_alsa_mixer_supported (GstImplementsInterface * iface, GType iface_type)
{ {
g_assert (iface_type == GST_TYPE_MIXER); g_assert (iface_type == GST_TYPE_MIXER);
return (((gint) GST_ALSA_MIXER (iface)->mixer_handle) != -1); return (GST_ALSA_MIXER (iface)->mixer_handle != NULL);
} }
static void static void
@ -236,7 +242,7 @@ gst_alsa_mixer_build_list (GstAlsaMixer * mixer)
const GList *templates; const GList *templates;
GstPadDirection dir = GST_PAD_UNKNOWN; GstPadDirection dir = GST_PAD_UNKNOWN;
g_return_if_fail (((gint) mixer->mixer_handle) != -1); g_return_if_fail (mixer->mixer_handle != NULL);
/* find direction */ /* find direction */
templates = templates =
@ -291,7 +297,7 @@ gst_alsa_mixer_build_list (GstAlsaMixer * mixer)
static void static void
gst_alsa_mixer_free_list (GstAlsaMixer * mixer) gst_alsa_mixer_free_list (GstAlsaMixer * mixer)
{ {
g_return_if_fail (((gint) mixer->mixer_handle) != -1); g_return_if_fail (mixer->mixer_handle != NULL);
g_list_foreach (mixer->tracklist, (GFunc) g_object_unref, NULL); g_list_foreach (mixer->tracklist, (GFunc) g_object_unref, NULL);
g_list_free (mixer->tracklist); g_list_free (mixer->tracklist);
@ -310,13 +316,14 @@ gst_alsa_mixer_change_state (GstElement * element)
switch (GST_STATE_TRANSITION (element)) { switch (GST_STATE_TRANSITION (element)) {
case GST_STATE_NULL_TO_READY: case GST_STATE_NULL_TO_READY:
if (!gst_alsa_mixer_open (this)) if (gst_alsa_mixer_open (this))
return GST_STATE_FAILURE;
gst_alsa_mixer_build_list (this); gst_alsa_mixer_build_list (this);
break; break;
case GST_STATE_READY_TO_NULL: case GST_STATE_READY_TO_NULL:
if (this->mixer_handle != NULL) {
gst_alsa_mixer_free_list (this); gst_alsa_mixer_free_list (this);
gst_alsa_mixer_close (this); gst_alsa_mixer_close (this);
}
break; break;
default: default:
break; break;
@ -335,7 +342,8 @@ gst_alsa_mixer_list_tracks (GstMixer * mixer)
{ {
GstAlsaMixer *alsa_mixer = GST_ALSA_MIXER (mixer); GstAlsaMixer *alsa_mixer = GST_ALSA_MIXER (mixer);
g_return_val_if_fail (((gint) alsa_mixer->mixer_handle) != -1, NULL); if (!alsa_mixer->mixer_handle)
return NULL;
return (const GList *) alsa_mixer->tracklist; return (const GList *) alsa_mixer->tracklist;
} }
@ -348,7 +356,7 @@ gst_alsa_mixer_get_volume (GstMixer * mixer,
GstAlsaMixer *alsa_mixer = GST_ALSA_MIXER (mixer); GstAlsaMixer *alsa_mixer = GST_ALSA_MIXER (mixer);
GstAlsaMixerTrack *alsa_track = (GstAlsaMixerTrack *) track; GstAlsaMixerTrack *alsa_track = (GstAlsaMixerTrack *) track;
g_return_if_fail (((gint) alsa_mixer->mixer_handle) != -1); g_return_if_fail (alsa_mixer->mixer_handle != NULL);
if (track->flags & GST_MIXER_TRACK_MUTE) { if (track->flags & GST_MIXER_TRACK_MUTE) {
for (i = 0; i < track->num_channels; i++) for (i = 0; i < track->num_channels; i++)
@ -376,7 +384,7 @@ gst_alsa_mixer_set_volume (GstMixer * mixer,
GstAlsaMixer *alsa_mixer = GST_ALSA_MIXER (mixer); GstAlsaMixer *alsa_mixer = GST_ALSA_MIXER (mixer);
GstAlsaMixerTrack *alsa_track = (GstAlsaMixerTrack *) track; GstAlsaMixerTrack *alsa_track = (GstAlsaMixerTrack *) track;
g_return_if_fail (((gint) alsa_mixer->mixer_handle) != -1); g_return_if_fail (alsa_mixer->mixer_handle != NULL);
/* only set the volume with ALSA lib if the track isn't muted. */ /* only set the volume with ALSA lib if the track isn't muted. */
if (!(track->flags & GST_MIXER_TRACK_MUTE)) { if (!(track->flags & GST_MIXER_TRACK_MUTE)) {
@ -401,7 +409,7 @@ gst_alsa_mixer_set_mute (GstMixer * mixer, GstMixerTrack * track, gboolean mute)
GstAlsaMixer *alsa_mixer = GST_ALSA_MIXER (mixer); GstAlsaMixer *alsa_mixer = GST_ALSA_MIXER (mixer);
GstAlsaMixerTrack *alsa_track = (GstAlsaMixerTrack *) track; GstAlsaMixerTrack *alsa_track = (GstAlsaMixerTrack *) track;
g_return_if_fail (((gint) alsa_mixer->mixer_handle) != -1); g_return_if_fail (alsa_mixer->mixer_handle != NULL);
if (mute) { if (mute) {
track->flags |= GST_MIXER_TRACK_MUTE; track->flags |= GST_MIXER_TRACK_MUTE;
@ -432,7 +440,7 @@ gst_alsa_mixer_set_record (GstMixer * mixer,
{ {
GstAlsaMixer *alsa_mixer = GST_ALSA_MIXER (mixer); GstAlsaMixer *alsa_mixer = GST_ALSA_MIXER (mixer);
g_return_if_fail (((gint) alsa_mixer->mixer_handle) != -1); g_return_if_fail (alsa_mixer->mixer_handle != NULL);
if (record) { if (record) {
track->flags |= GST_MIXER_TRACK_RECORD; track->flags |= GST_MIXER_TRACK_RECORD;