ext/alsa/gstalsa.*: refactor big chunks of the core caps negotiation code to make it a lot faster, because people cla...

Original commit message from CVS:
* ext/alsa/gstalsa.c: (gst_alsa_get_caps), (gst_alsa_close_audio):
* ext/alsa/gstalsa.h:
refactor big chunks of the core caps negotiation code to make it
a lot faster, because people claim it's really slow
(actually, just cache the getcaps when the device is opened)
This commit is contained in:
Benjamin Otte 2004-12-06 16:10:06 +00:00
parent cc32e6ddff
commit cffb318704
3 changed files with 23 additions and 10 deletions

View file

@ -1,3 +1,11 @@
2004-12-06 Benjamin Otte <in7y118@public.uni-hamburg.de>
* ext/alsa/gstalsa.c: (gst_alsa_get_caps), (gst_alsa_close_audio):
* ext/alsa/gstalsa.h:
refactor big chunks of the core caps negotiation code to make it
a lot faster, because people claim it's really slow
(actually, just cache the getcaps when the device is opened)
2004-12-06 Ronald S. Bultje <rbultje@ronald.bitfreak.net>
* ext/a52dec/gsta52dec.c: (gst_a52dec_init),

View file

@ -821,6 +821,8 @@ gst_alsa_get_caps (GstPad * pad)
if (!GST_FLAG_IS_SET (this, GST_ALSA_OPEN))
return gst_caps_copy (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad)));
if (this->cached_caps)
return gst_caps_copy (this->cached_caps);
snd_pcm_hw_params_alloca (&hw_params);
ERROR_CHECK (snd_pcm_hw_params_any (this->handle, hw_params),
@ -861,7 +863,8 @@ gst_alsa_get_caps (GstPad * pad)
min_channels, max_channels);
/* channel configuration */
for (n = min_channels; n <= max_channels; n++) {
/* MIN used to spped up because we don't support more than 8 channels */
for (n = min_channels; n <= MIN (8, max_channels); n++) {
if (snd_pcm_hw_params_test_channels (this->handle, hw_params, n) == 0) {
GstStructure *str;
GstAudioChannelPosition pos[8] = {
@ -911,16 +914,13 @@ gst_alsa_get_caps (GstPad * pad)
if (ret == NULL) {
GST_WARNING_OBJECT (this, "no supported caps found, returning empty caps");
return gst_caps_new_empty ();
} else {
G_GNUC_UNUSED gchar *str;
gst_caps_do_simplify (ret);
str = gst_caps_to_string (ret);
GST_LOG_OBJECT (this, "get_caps returns %s", str);
g_free (str);
return ret;
ret = gst_caps_new_empty ();
}
gst_caps_do_simplify (ret);
GST_LOG_OBJECT (this, "get_caps returns %P", ret);
this->cached_caps = gst_caps_copy (ret);
return ret;
}
static GstCaps *
@ -1717,6 +1717,10 @@ gst_alsa_close_audio (GstAlsa * this)
GST_ALSA_CAPS_SET (this, GST_ALSA_CAPS_RESUME, 0);
GST_ALSA_CAPS_SET (this, GST_ALSA_CAPS_SYNC_START, 0);
GST_FLAG_UNSET (this, GST_ALSA_OPEN);
if (this->cached_caps) {
gst_caps_free (this->cached_caps);
this->cached_caps = NULL;
}
return TRUE;
}

View file

@ -147,6 +147,7 @@ struct _GstAlsa {
GstAlsaFormat * format; /* NULL if undefined */
gboolean mmap; /* use mmap transmit (fast) or read/write (sloooow) */
GstAlsaTransmitFunction transmit;
GstCaps * cached_caps; /* we cache caps to speed up get_caps */
/* latency / performance parameters */
snd_pcm_uframes_t period_size;