CVS Root: /cvsroot/gstreamer
Module: gst-plugins
Changes by: company
Date: Fri Dec 12 2003 14:53:09 PST
Branch: CAPS
Log message:
convert alsa to new caps. compiles, but untested
Modified files:
ext/alsa : gstalsa.c gstalsa.h gstalsasink.c gstalsasrc.c
Links:
http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins/ext/alsa/gstalsa.c.diff?r1=1.77&r2=1.77.4.1
http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins/ext/alsa/gstalsa.h.diff?r1=1.22&r2=1.22.4.1
http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins/ext/alsa/gstalsasink.c.diff?r1=1.3&r2=1.3.4.1
http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins/ext/alsa/gstalsasrc.c.diff?r1=1.2&r2=1.2.4.1
====Begin Diffs====
Index: gstalsa.c
===================================================================
RCS file: /cvsroot/gstreamer/gst-plugins/ext/alsa/gstalsa.c,v
retrieving revision 1.77
retrieving revision 1.77.4.1
diff -u -d -r1.77 -r1.77.4.1
--- gstalsa.c 18 Nov 2003 15:32:52 -0000 1.77
+++ gstalsa.c 12 Dec 2003 22:52:57 -0000 1.77.4.1
@@ -331,29 +331,29 @@
/* gets the matching alsa format or NULL if none matches */
static GstAlsaFormat *
-gst_alsa_get_format (GstCaps *caps)
+gst_alsa_get_format (const GstStructure *structure)
{
const gchar *mimetype;
GstAlsaFormat *ret;
- if (!(ret = g_new (GstAlsaFormat, 1)))
- return NULL;
+ ret = g_new (GstAlsaFormat, 1);
/* we have to differentiate between int and float formats */
- mimetype = gst_caps_get_mime (caps);
+ mimetype = gst_structure_get_name (structure);
if (! strncmp (mimetype, "audio/x-raw-int", 15)) {
gboolean sign;
gint width, depth, endianness;
- /* extract the needed information from the caps */
- if (!gst_caps_get (caps,
- "width", &width, "depth", &depth, "signed", &sign, NULL))
+ /* extract the needed information from the cap */
+ if (!(gst_structure_get_int (structure, "width", &width) &&
+ gst_structure_get_int (structure, "depth", &depth) &&
+ gst_structure_get_boolean (structure, "signed", &sign)))
goto error;
/* extract endianness if needed */
if (width > 8) {
- if (!gst_caps_get (caps, "endianness", &endianness, NULL))
+ if (!gst_structure_get_int (structure, "endianness", &endianness))
goto error;
} else {
endianness = G_BYTE_ORDER;
@@ -365,7 +365,7 @@
gint width;
/* get layout */
- if (!gst_caps_get (caps, "width", &width, NULL))
+ if (!gst_structure_get_int (structure, "width", &width))
goto error;
/* match layout to format wrt to endianness */
@@ -395,8 +395,8 @@
}
/* get rate and channels */
- if (!gst_caps_get (caps,
- "rate", &ret->rate, "channels", &ret->channels, NULL))
+ if (!(gst_structure_get_int (structure, "rate", &ret->rate) &&
+ gst_structure_get_int (structure, "channels", &ret->channels)))
goto error;
return ret;
@@ -416,77 +416,67 @@
(one->channels == two->channels);
}
/* get props for a spec */
-static GstCaps *
+static GstCaps2 *
gst_alsa_get_caps_internal (snd_pcm_format_t format)
{
- const gchar *name = snd_pcm_format_name (format);
-
if (format == SND_PCM_FORMAT_A_LAW) {
- return GST_CAPS_NEW (name, "audio/x-alaw",
- "law", GST_PROPS_INT(2),
- "width", GST_PROPS_INT(8),
- "depth", GST_PROPS_INT(8),
- "signed", GST_PROPS_BOOLEAN (FALSE),
- NULL);
+ return gst_caps2_new_simple ("audio/x-alaw", NULL);
} else if (format == SND_PCM_FORMAT_MU_LAW) {
- return GST_CAPS_NEW (name, "audio/x-mulaw",
- "law", GST_PROPS_INT(1),
- "width", GST_PROPS_INT(8),
- "depth", GST_PROPS_INT(8),
- "signed", GST_PROPS_BOOLEAN (FALSE),
- NULL);
+ return gst_caps2_new_simple ("audio/x-mulaw", NULL);
} else if (snd_pcm_format_linear (format)) {
/* int */
- GstProps *props =
- gst_props_new ("width", GST_PROPS_INT(snd_pcm_format_physical_width (format)),
- "depth", GST_PROPS_INT(snd_pcm_format_width (format)),
- "law", GST_PROPS_INT(0),
- "signed", GST_PROPS_BOOLEAN (snd_pcm_format_signed (format) == 1 ? TRUE : FALSE),
- NULL);
+ GstStructure *structure = gst_structure_new ("audio/x-raw-int",
+ "width", G_TYPE_INT, (gint) snd_pcm_format_physical_width (format),
+ "depth", G_TYPE_INT, (gint) snd_pcm_format_width (format),
+ "signed", G_TYPE_BOOLEAN, snd_pcm_format_signed (format) == 1 ? TRUE : FALSE,
+ NULL);
/* endianness */
if (snd_pcm_format_physical_width (format) > 8) {
switch (snd_pcm_format_little_endian (format)) {
case 0:
- gst_props_add_entry (props, gst_props_entry_new ("endianness", GST_PROPS_INT (G_BIG_ENDIAN)));
+ gst_structure_set (structure, "endianness", G_TYPE_INT, G_BIG_ENDIAN, NULL);
break;
case 1:
- gst_props_add_entry (props, gst_props_entry_new ("endianness", GST_PROPS_INT (G_LITTLE_ENDIAN)));
+ gst_structure_set (structure, "endianness", G_TYPE_INT, G_LITTLE_ENDIAN, NULL);
break;
default:
GST_WARNING ("Unknown byte order in sound driver. Continuing by assuming system byte order.");
- gst_props_add_entry (props, gst_props_entry_new ("endianness", GST_PROPS_INT (G_BYTE_ORDER)));
+ gst_structure_set (structure, "endianness", G_TYPE_INT, G_BYTE_ORDER, NULL);
break;
}
}
- return gst_caps_new (name, "audio/x-raw-int", props);
+ return gst_caps2_new_full (structure, NULL);
} else if (snd_pcm_format_float (format)) {
/* no float with non-platform endianness */
if (!snd_pcm_format_cpu_endian (format))
return NULL;
- return GST_CAPS_NEW (name,
- "audio/x-raw-float",
- "width", GST_PROPS_INT (snd_pcm_format_width (format)),
- "endianness", GST_PROPS_INT (G_BYTE_ORDER));
+ return gst_caps2_new_simple ("audio/x-raw-float",
+ "width", G_TYPE_INT, (gint) snd_pcm_format_width (format),
+ "endianness", G_TYPE_INT, G_BYTE_ORDER);
}
return NULL;
}
static inline void
-add_channels (GstProps *props, gint min_rate, gint max_rate, gint min_channels, gint max_channels) {
+add_channels (GstStructure *structure, gint min_rate, gint max_rate, gint min_channels, gint max_channels) {
if (min_rate < 0) {
- gst_props_add_entry (props, gst_props_entry_new ("rate", GST_PROPS_INT_RANGE (GST_ALSA_MIN_RATE, GST_ALSA_MAX_RATE)));
- } else if (max_rate < 0) {
- gst_props_add_entry (props, gst_props_entry_new ("rate", GST_PROPS_INT (min_rate)));
+ min_rate = GST_ALSA_MIN_RATE;
+ max_rate = GST_ALSA_MAX_RATE;
+ }
+ if (max_rate < 0) {
+ gst_structure_set (structure, "rate", G_TYPE_INT, min_rate, NULL);
} else {
- gst_props_add_entry (props, gst_props_entry_new ("rate", GST_PROPS_INT_RANGE (min_rate, max_rate)));
+ gst_structure_set (structure, "rate", GST_TYPE_INT_RANGE, min_rate, max_rate);
}
if (min_channels < 0) {
- gst_props_add_entry (props, gst_props_entry_new ("channels", GST_PROPS_INT_RANGE (1, GST_ALSA_MAX_CHANNELS)));
- } else if (max_channels < 0) {
- gst_props_add_entry (props, gst_props_entry_new ("channels", GST_PROPS_INT (min_channels)));
+ min_channels = 1;
+ max_channels = GST_ALSA_MAX_CHANNELS;
+ }
+ if (max_channels < 0) {
+ gst_structure_set (structure, "channels", G_TYPE_INT, min_channels, NULL);
} else {
- gst_props_add_entry (props, gst_props_entry_new ("channels", GST_PROPS_INT_RANGE (min_channels, max_channels)));
+ gst_structure_set (structure, "channels", GST_TYPE_INT_RANGE, min_channels, max_channels);
}
}
@@ -496,10 +486,10 @@
* @rate: allowed rates if < 0, else desired rate
* @channels: all allowed values for channels if < 0, else desired channels
*/
-GstCaps *
+GstCaps2 *
gst_alsa_caps (snd_pcm_format_t format, gint rate, gint channels)
{
- GstCaps *ret_caps = NULL;
+ GstCaps2 *ret_caps = NULL;
if (format != SND_PCM_FORMAT_UNKNOWN) {
/* there are some caps set already */
@@ -507,20 +497,21 @@
/* we can never use a format we can't set caps for */
g_assert (ret_caps != NULL);
- g_assert (ret_caps->properties != NULL);
+ g_assert (gst_caps2_get_n_structures (ret_caps) == 1);
- add_channels (ret_caps->properties, rate, -1, channels, -1);
+ add_channels (gst_caps2_get_nth_cap (ret_caps, 0), rate, -1, channels, -1);
} else {
int i;
- GstCaps *temp;
+ GstCaps2 *temp;
for (i = 0; i <= SND_PCM_FORMAT_LAST; i++) {
temp = gst_alsa_get_caps_internal (i);
/* can be NULL, because not all alsa formats can be specified as caps */
- if (temp != NULL && temp->properties != NULL) {
- add_channels (temp->properties, rate, -1, channels, -1);
- ret_caps = gst_caps_append (ret_caps, temp);
+ if (temp != NULL) {
+ g_assert (gst_caps2_get_n_structures (temp) == 1);
+ add_channels (gst_caps2_get_nth_cap (temp, 0), rate, -1, channels, -1);
+ gst_caps2_append (ret_caps, temp);
}
}
}
@@ -529,8 +520,8 @@
}
/* Return better caps when device is open */
-GstCaps *
-gst_alsa_get_caps (GstPad *pad, GstCaps *caps)
+GstCaps2 *
+gst_alsa_get_caps (GstPad *pad)
{
GstAlsa *this;
snd_pcm_hw_params_t *hw_params;
@@ -538,14 +529,14 @@
int i;
unsigned int min_rate, max_rate;
gint min_channels, max_channels;
- GstCaps *ret = NULL;
+ GstCaps2 *ret = NULL;
g_return_val_if_fail (pad != NULL, NULL);
this = GST_ALSA (gst_pad_get_parent (pad));
if (!GST_FLAG_IS_SET (this, GST_ALSA_OPEN))
- return gst_pad_get_pad_template_caps (pad);
+ return gst_caps2_copy (gst_pad_get_pad_template_caps (pad));
snd_pcm_hw_params_alloca (&hw_params);
ERROR_CHECK (snd_pcm_hw_params_any (this->handle, hw_params),
@@ -574,11 +565,12 @@
snd_pcm_hw_params_get_format_mask (hw_params, mask);
for (i = 0; i <= SND_PCM_FORMAT_LAST; i++) {
if (snd_pcm_format_mask_test (mask, i)) {
- GstCaps *caps = gst_alsa_get_caps_internal (i);
+ GstCaps2 *caps = gst_alsa_get_caps_internal (i);
/* we can never use a format we can't set caps for */
- if (caps != NULL && caps->properties != NULL) {
- add_channels (caps->properties, min_rate, max_rate, min_channels, max_channels);
- ret = gst_caps_append (ret, caps);
+ if (caps != NULL) {
+ g_assert (gst_caps2_get_n_structures (caps) == 1);
+ add_channels (gst_caps2_get_nth_cap (caps, 0), min_rate, max_rate, min_channels, max_channels);
+ gst_caps2_append (ret, caps);
}
}
}
@@ -587,7 +579,7 @@
}
/* Negotiates the caps */
GstPadLinkReturn
-gst_alsa_link (GstPad *pad, GstCaps *caps)
+gst_alsa_link (GstPad *pad, const GstCaps2 *caps)
{
GstAlsa *this;
GstAlsaFormat *format;
@@ -598,50 +590,48 @@
this = GST_ALSA (gst_pad_get_parent (pad));
- if (GST_CAPS_IS_FIXED (caps)) {
- if (this->handle == NULL)
- if (!gst_alsa_open_audio (this))
- return GST_PAD_LINK_REFUSED;
+ if (this->handle == NULL)
+ if (!gst_alsa_open_audio (this))
+ return GST_PAD_LINK_REFUSED;
- format = gst_alsa_get_format (caps);
- if (format == NULL)
- return GST_PAD_LINK_DELAYED;
+ format = gst_alsa_get_format (gst_caps2_get_nth_cap (caps, 0));
+ if (format == NULL)
+ return GST_PAD_LINK_REFUSED;
- GST_DEBUG ("found format %s", snd_pcm_format_name (format->format));
+ GST_DEBUG ("found format %s", snd_pcm_format_name (format->format));
- if (!GST_FLAG_IS_SET (this, GST_ALSA_CAPS_NEGO)) {
- gint i;
+ if (!GST_FLAG_IS_SET (this, GST_ALSA_CAPS_NEGO)) {
+ gint i;
- GST_FLAG_SET (this, GST_ALSA_CAPS_NEGO);
+ GST_FLAG_SET (this, GST_ALSA_CAPS_NEGO);
- if (gst_alsa_formats_match (this->format, format)) {
- ret = GST_PAD_LINK_OK;
- goto out;
- }
+ if (gst_alsa_formats_match (this->format, format)) {
+ ret = GST_PAD_LINK_OK;
+ goto out;
+ }
- if (!gst_alsa_probe_hw_params (this, format)) {
- ret = GST_PAD_LINK_REFUSED;
- goto out;
- }
+ if (!gst_alsa_probe_hw_params (this, format)) {
+ ret = GST_PAD_LINK_REFUSED;
+ goto out;
+ }
- for (i = 0; i < ((GstElement *) this)->numpads; i++) {
- g_assert (this->pad[i] != NULL);
- if (this->pad[i] == pad)
- continue;
- if (gst_pad_try_set_caps (this->pad[i], gst_caps_ref (caps)) == GST_PAD_LINK_REFUSED) {
- if (this->format) {
- GstCaps *old = gst_alsa_caps (this->format->format, this->format->rate, this->format->channels);
- for (--i; i >= 0; i--) {
- if (gst_pad_try_set_caps (this->pad[i], gst_caps_ref (old)) == GST_PAD_LINK_REFUSED) {
- gst_element_error (GST_ELEMENT (this), "error resetting caps to sane value");
- gst_caps_unref (old);
- break;
- }
+ for (i = 0; i < ((GstElement *) this)->numpads; i++) {
+ g_assert (this->pad[i] != NULL);
+ if (this->pad[i] == pad)
+ continue;
+ if (gst_pad_try_set_caps (this->pad[i], caps) == GST_PAD_LINK_REFUSED) {
+ if (this->format) {
+ GstCaps2 *old = gst_alsa_caps (this->format->format, this->format->rate, this->format->channels);
+ for (--i; i >= 0; i--) {
+ if (gst_pad_try_set_caps (this->pad[i], old) == GST_PAD_LINK_REFUSED) {
+ gst_element_error (GST_ELEMENT (this), "error resetting caps to sane value");
+ gst_caps2_free (old);
+ break;
+ } else {
+ /* FIXME: unset caps on pads somehow */
}
- gst_caps_unref (old);
- } else {
- /* FIXME: unset caps on pads somehow */
}
+ gst_caps2_free (old);
ret = GST_PAD_LINK_REFUSED;
goto out;
}
Index: gstalsa.h
===================================================================
RCS file: /cvsroot/gstreamer/gst-plugins/ext/alsa/gstalsa.h,v
retrieving revision 1.22
retrieving revision 1.22.4.1
diff -u -d -r1.22 -r1.22.4.1
--- gstalsa.h 18 Nov 2003 15:32:52 -0000 1.22
+++ gstalsa.h 12 Dec 2003 22:52:57 -0000 1.22.4.1
@@ -174,10 +174,9 @@
void gst_alsa_set_eos (GstAlsa * this);
GstPadLinkReturn gst_alsa_link (GstPad * pad,
- GstCaps * caps);
-GstCaps * gst_alsa_get_caps (GstPad * pad,
- GstCaps *caps);
-GstCaps * gst_alsa_caps (snd_pcm_format_t format,
+ const GstCaps2 * caps);
+GstCaps2 * gst_alsa_get_caps (GstPad * pad);
+GstCaps2 * gst_alsa_caps (snd_pcm_format_t format,
gint rate,
gint channels);
Index: gstalsasink.c
===================================================================
RCS file: /cvsroot/gstreamer/gst-plugins/ext/alsa/gstalsasink.c,v
retrieving revision 1.3
retrieving revision 1.3.4.1
diff -u -d -r1.3 -r1.3.4.1
--- gstalsasink.c 22 Nov 2003 16:15:24 -0000 1.3
+++ gstalsasink.c 12 Dec 2003 22:52:57 -0000 1.3.4.1
@@ -65,8 +65,7 @@
if (!template)
template = gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
- gst_alsa_caps (SND_PCM_FORMAT_UNKNOWN, -1, -1),
- NULL);
+ gst_alsa_caps (SND_PCM_FORMAT_UNKNOWN, -1, -1));
return template;
}
@@ -78,8 +77,7 @@
if (!template)
template =
gst_pad_template_new ("sink%d", GST_PAD_SINK, GST_PAD_REQUEST,
- gst_alsa_caps (SND_PCM_FORMAT_UNKNOWN, -1, 1),
- NULL);
+ gst_alsa_caps (SND_PCM_FORMAT_UNKNOWN, -1, 1));
return template;
}
Index: gstalsasrc.c
===================================================================
RCS file: /cvsroot/gstreamer/gst-plugins/ext/alsa/gstalsasrc.c,v
retrieving revision 1.2
retrieving revision 1.2.4.1
diff -u -d -r1.2 -r1.2.4.1
--- gstalsasrc.c 18 Nov 2003 15:32:52 -0000 1.2
+++ gstalsasrc.c 12 Dec 2003 22:52:57 -0000 1.2.4.1
@@ -61,8 +61,7 @@
if (!template)
template = gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
- gst_alsa_caps (SND_PCM_FORMAT_UNKNOWN, -1, -1),
- NULL);
+ gst_alsa_caps (SND_PCM_FORMAT_UNKNOWN, -1, -1));
return template;
}
@@ -73,8 +72,7 @@
if (!template)
template = gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
- gst_alsa_caps (SND_PCM_FORMAT_UNKNOWN, -1, 1),
- NULL);
+ gst_alsa_caps (SND_PCM_FORMAT_UNKNOWN, -1, 1));
return template;
}
@@ -241,18 +239,19 @@
static gboolean
gst_alsa_src_set_caps (GstAlsaSrc *src, gboolean aggressive)
{
- GstCaps *all_caps, *caps, *walk;
+ GstCaps2 *all_caps, *caps;
+ GstStructure *structure, *walk;
gint channels, min_channels, max_channels;
gint rate, min_rate, max_rate;
gint i, endian, width, depth;
gboolean sign;
GstAlsa *this = GST_ALSA (src);
- all_caps = gst_alsa_get_caps (this->pad[0], NULL);
+ all_caps = gst_alsa_get_caps (this->pad[0]);
if (all_caps == NULL) return FALSE;
/* now intersect this with all caps of the peers... */
for (i = 0; i < GST_ELEMENT (src)->numpads; i++) {
- all_caps = gst_caps_intersect (all_caps, gst_pad_get_caps (this->pad[i]));
+ all_caps = gst_caps2_intersect (all_caps, gst_pad_get_caps (this->pad[i]));
if (all_caps == NULL) {
GST_DEBUG ("No compatible caps found in alsasrc (%s)", GST_ELEMENT_NAME (this));
return FALSE;
@@ -260,38 +259,40 @@
}
/* construct caps */
- caps = GST_CAPS_NEW ("alsasrc caps", "audio/x-raw-int",
- "endianness", GST_PROPS_INT (G_BYTE_ORDER),
- "signed", GST_PROPS_BOOLEAN (TRUE),
- "width", GST_PROPS_INT (16),
- "depth", GST_PROPS_INT (16),
- "rate", GST_PROPS_INT (44100),
- "channels", GST_PROPS_INT (1));
- gst_caps_ref (caps);
- gst_caps_sink (caps);
+ caps = gst_caps2_new_simple ("audio/x-raw-int",
+ NULL);
+ g_assert (gst_caps2_get_n_structures (caps) == 1);
+ structure = gst_caps2_get_nth_cap (caps, 0);
/* now try to find the best match */
- walk = all_caps;
- while (walk) {
- gst_caps_get (walk, "signed", &sign, "width", &width, "depth", &depth, NULL);
- if (gst_caps_has_property (walk, "endianness")) {
- gst_caps_get_int (walk, "endianness", &endian);
- } else {
+ for (i = 0; i < gst_caps2_get_n_structures (all_caps); i++) {
+ walk = gst_caps2_get_nth_cap (all_caps, i);
+ if (!(gst_structure_get_int (walk, "signed", &sign) &&
+ gst_structure_get_int (walk, "width", &sign) &&
+ gst_structure_get_int (walk, "depth", &sign))) {
+ GST_ERROR_OBJECT (src, "couldn't parse my own format. Huh?");
+ continue;
+ }
+ if (!gst_structure_get_int (walk, "endianness", &endian)) {
endian = G_BYTE_ORDER;
}
- gst_caps_set (caps, "endianness", GST_PROPS_INT (endian));
- gst_caps_set (caps, "width", GST_PROPS_INT (width));
- gst_caps_set (caps, "depth", GST_PROPS_INT (depth));
- gst_caps_set (caps, "signed", GST_PROPS_BOOLEAN (sign));
+ gst_structure_set (structure,
+ "endianness", G_TYPE_INT, endian,
+ "width", G_TYPE_INT, width,
+ "depth", G_TYPE_INT, depth,
+ "signed", G_TYPE_BOOLEAN, sign,
+ NULL);
- gst_props_entry_get_int_range (gst_props_get_entry (GST_CAPS_PROPERTIES (walk), "rate"), &min_rate, &max_rate);
- gst_props_entry_get_int_range (gst_props_get_entry (GST_CAPS_PROPERTIES (walk), "channels"), &min_channels, &max_channels);
+ min_rate = gst_value_get_int_range_min (gst_structure_get_value (walk, "rate"));
+ max_rate = gst_value_get_int_range_max (gst_structure_get_value (walk, "rate"));
+ min_channels = gst_value_get_int_range_min (gst_structure_get_value (walk, "channels"));
+ max_channels = gst_value_get_int_range_max (gst_structure_get_value (walk, "channels"));
for (rate = max_rate;; rate--) {
if ((rate = gst_alsa_src_adjust_rate (rate, aggressive)) < min_rate)
break;
- gst_caps_set (caps, "rate", GST_PROPS_INT (rate));
+ gst_structure_set (structure, "rate", G_TYPE_INT, rate, NULL);
for (channels = aggressive ? max_channels : MIN (max_channels, 2); channels >= min_channels; channels--) {
- gst_caps_set (caps, "channels", GST_PROPS_INT (channels));
+ gst_structure_set (structure, "channels", G_TYPE_INT, channels, NULL);
GST_DEBUG ("trying new caps: %ssigned, endianness: %d, width %d, depth %d, channels %d, rate %d",
sign ? "" : "un", endian, width, depth, channels, rate);
if (gst_pad_try_set_caps (this->pad[0], caps) != GST_PAD_LINK_REFUSED)
@@ -303,7 +304,6 @@
}
}
}
- walk = GST_CAPS_NEXT (walk);
}
if (!aggressive)
|