mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-11 18:05:37 +00:00
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:
parent
49c96eeb84
commit
35aff63385
2 changed files with 38 additions and 20 deletions
10
ChangeLog
10
ChangeLog
|
@ -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>
|
||||
|
||||
* gst-libs/gst/riff/riff-read.c: (gst_riff_read_seek):
|
||||
|
|
|
@ -132,19 +132,25 @@ gst_alsa_mixer_open (GstAlsaMixer * mixer)
|
|||
{
|
||||
gint err, device;
|
||||
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 */
|
||||
err = snd_mixer_open (&mixer->mixer_handle, 0);
|
||||
if (err < 0 || mixer->mixer_handle == NULL) {
|
||||
GST_ERROR_OBJECT (GST_OBJECT (mixer), "Cannot open mixer device.");
|
||||
mixer->mixer_handle = (snd_mixer_t *) - 1;
|
||||
mixer->mixer_handle = NULL;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
nocomma = g_strdup (alsa->device);
|
||||
if (!strncmp (alsa->device, "hw:", 3))
|
||||
nocomma = g_strdup (alsa->device);
|
||||
else if (!strncmp (alsa->device, "plughw:", 7))
|
||||
nocomma = g_strdup (alsa->device + 4);
|
||||
else
|
||||
goto error;
|
||||
|
||||
if (strchr (nocomma, ','))
|
||||
strchr (nocomma, ',')[0] = '\0';
|
||||
|
||||
|
@ -179,7 +185,7 @@ gst_alsa_mixer_open (GstAlsaMixer * mixer)
|
|||
|
||||
error:
|
||||
snd_mixer_close (mixer->mixer_handle);
|
||||
mixer->mixer_handle = (snd_mixer_t *) - 1;
|
||||
mixer->mixer_handle = NULL;
|
||||
g_free (nocomma);
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -189,7 +195,7 @@ gst_alsa_mixer_close (GstAlsaMixer * mixer)
|
|||
{
|
||||
GstAlsa *alsa = GST_ALSA (mixer);
|
||||
|
||||
if (((gint) mixer->mixer_handle) == -1)
|
||||
if (mixer->mixer_handle == NULL)
|
||||
return;
|
||||
|
||||
if (alsa->cardname) {
|
||||
|
@ -197,7 +203,7 @@ gst_alsa_mixer_close (GstAlsaMixer * mixer)
|
|||
alsa->cardname = NULL;
|
||||
}
|
||||
snd_mixer_close (mixer->mixer_handle);
|
||||
mixer->mixer_handle = (snd_mixer_t *) - 1;
|
||||
mixer->mixer_handle = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -224,7 +230,7 @@ gst_alsa_mixer_supported (GstImplementsInterface * iface, GType iface_type)
|
|||
{
|
||||
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
|
||||
|
@ -236,7 +242,7 @@ gst_alsa_mixer_build_list (GstAlsaMixer * mixer)
|
|||
const GList *templates;
|
||||
GstPadDirection dir = GST_PAD_UNKNOWN;
|
||||
|
||||
g_return_if_fail (((gint) mixer->mixer_handle) != -1);
|
||||
g_return_if_fail (mixer->mixer_handle != NULL);
|
||||
|
||||
/* find direction */
|
||||
templates =
|
||||
|
@ -291,7 +297,7 @@ gst_alsa_mixer_build_list (GstAlsaMixer * mixer)
|
|||
static void
|
||||
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_free (mixer->tracklist);
|
||||
|
@ -310,13 +316,14 @@ gst_alsa_mixer_change_state (GstElement * element)
|
|||
|
||||
switch (GST_STATE_TRANSITION (element)) {
|
||||
case GST_STATE_NULL_TO_READY:
|
||||
if (!gst_alsa_mixer_open (this))
|
||||
return GST_STATE_FAILURE;
|
||||
gst_alsa_mixer_build_list (this);
|
||||
if (gst_alsa_mixer_open (this))
|
||||
gst_alsa_mixer_build_list (this);
|
||||
break;
|
||||
case GST_STATE_READY_TO_NULL:
|
||||
gst_alsa_mixer_free_list (this);
|
||||
gst_alsa_mixer_close (this);
|
||||
if (this->mixer_handle != NULL) {
|
||||
gst_alsa_mixer_free_list (this);
|
||||
gst_alsa_mixer_close (this);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -335,7 +342,8 @@ gst_alsa_mixer_list_tracks (GstMixer * 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;
|
||||
}
|
||||
|
@ -348,7 +356,7 @@ gst_alsa_mixer_get_volume (GstMixer * mixer,
|
|||
GstAlsaMixer *alsa_mixer = GST_ALSA_MIXER (mixer);
|
||||
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) {
|
||||
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);
|
||||
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. */
|
||||
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);
|
||||
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) {
|
||||
track->flags |= GST_MIXER_TRACK_MUTE;
|
||||
|
@ -432,7 +440,7 @@ gst_alsa_mixer_set_record (GstMixer * 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) {
|
||||
track->flags |= GST_MIXER_TRACK_RECORD;
|
||||
|
|
Loading…
Reference in a new issue