+ updated caps for new float caps + added 'Library' to license at top of file since gst-inspect says LGPL

Original commit message from CVS:
+ updated caps for new float caps
+ added 'Library' to license at top of file since gst-inspect says LGPL
This commit is contained in:
Leif Johnson 2003-07-19 23:22:47 +00:00
parent e6f278e065
commit 0894ba5603

View file

@ -5,7 +5,7 @@
* Copyright (C) 2003 Benjamin Otte <in7y118@public.uni-hamburg.de> * Copyright (C) 2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public * modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either * License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version. * version 2 of the License, or (at your option) any later version.
* *
@ -14,7 +14,7 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details. * General Public License for more details.
* *
* You should have received a copy of the GNU General Public * You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free * License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
@ -992,7 +992,7 @@ gst_alsa_adjust_rate (gint rate, gboolean aggressive)
if (aggressive) if (aggressive)
return rate; return rate;
for (i = 0; i < G_N_ELEMENTS (rates); i++) { for (i = 0; i < G_N_ELEMENTS (rates); i++) {
if (rate >= rates[i]) if (rate >= rates[i])
return rates[i]; return rates[i];
@ -1020,7 +1020,7 @@ gst_alsa_src_set_caps (GstAlsaSrc *src, gboolean aggressive)
return FALSE; return FALSE;
} }
} }
/* construct caps */ /* construct caps */
caps = GST_CAPS_NEW ("alsasrc caps", "audio/x-raw-int", caps = GST_CAPS_NEW ("alsasrc caps", "audio/x-raw-int",
"endianness", GST_PROPS_INT (G_BYTE_ORDER), "endianness", GST_PROPS_INT (G_BYTE_ORDER),
@ -1045,12 +1045,12 @@ gst_alsa_src_set_caps (GstAlsaSrc *src, gboolean aggressive)
gst_caps_set (caps, "width", GST_PROPS_INT (width)); gst_caps_set (caps, "width", GST_PROPS_INT (width));
gst_caps_set (caps, "depth", GST_PROPS_INT (depth)); gst_caps_set (caps, "depth", GST_PROPS_INT (depth));
gst_caps_set (caps, "signed", GST_PROPS_BOOLEAN (sign)); gst_caps_set (caps, "signed", GST_PROPS_BOOLEAN (sign));
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), "rate"), &min_rate, &max_rate);
gst_props_entry_get_int_range (gst_props_get_entry (GST_CAPS_PROPERTIES (walk), "channels"), &min_channels, &max_channels); gst_props_entry_get_int_range (gst_props_get_entry (GST_CAPS_PROPERTIES (walk), "channels"), &min_channels, &max_channels);
for (rate = max_rate;; rate--) { for (rate = max_rate;; rate--) {
if ((rate = gst_alsa_adjust_rate (rate, aggressive)) < min_rate) if ((rate = gst_alsa_adjust_rate (rate, aggressive)) < min_rate)
break; break;
gst_caps_set (caps, "rate", GST_PROPS_INT (rate)); gst_caps_set (caps, "rate", GST_PROPS_INT (rate));
for (channels = aggressive ? max_channels : MIN (max_channels, 2); channels >= min_channels; channels--) { for (channels = aggressive ? max_channels : MIN (max_channels, 2); channels >= min_channels; channels--) {
gst_caps_set (caps, "channels", GST_PROPS_INT (channels)); gst_caps_set (caps, "channels", GST_PROPS_INT (channels));
@ -1058,8 +1058,8 @@ gst_alsa_src_set_caps (GstAlsaSrc *src, gboolean aggressive)
sign ? "" : "un", endian, width, depth, channels, rate); sign ? "" : "un", endian, width, depth, channels, rate);
if (gst_pad_try_set_caps (this->pad[0], caps) != GST_PAD_LINK_REFUSED) if (gst_pad_try_set_caps (this->pad[0], caps) != GST_PAD_LINK_REFUSED)
gst_alsa_link (this->pad[0], caps); gst_alsa_link (this->pad[0], caps);
if (this->format) { if (this->format) {
/* try to set caps here */ /* try to set caps here */
return TRUE; return TRUE;
} }
@ -1223,7 +1223,7 @@ found_channel:
gst_pad_set_query_function (this->pad[channel], gst_alsa_pad_query); gst_pad_set_query_function (this->pad[channel], gst_alsa_pad_query);
gst_pad_set_query_type_function (this->pad[channel], gst_alsa_get_query_types); gst_pad_set_query_type_function (this->pad[channel], gst_alsa_get_query_types);
gst_pad_set_formats_function (this->pad[channel], gst_alsa_get_formats); gst_pad_set_formats_function (this->pad[channel], gst_alsa_get_formats);
return this->pad[channel]; return this->pad[channel];
} }
@ -1240,45 +1240,34 @@ gst_alsa_get_format (GstCaps *caps)
/* we have to differentiate between int and float formats */ /* we have to differentiate between int and float formats */
mimetype = gst_caps_get_mime (caps); mimetype = gst_caps_get_mime (caps);
if (strcmp (mimetype, "audio/x-raw-int") == 0) { if (! strncmp (mimetype, "audio/x-raw-int", 15)) {
gboolean sign; gboolean sign;
gint width, depth, endianness; gint width, depth, endianness;
/* extract the needed information from the caps */ /* extract the needed information from the caps */
if (!gst_caps_get (caps, if (!gst_caps_get (caps,
"width", &width, "width", &width, "depth", &depth, "signed", &sign, NULL))
"depth", &depth,
"signed", &sign,
NULL))
goto error; goto error;
/* extract endianness if needed */ /* extract endianness if needed */
if (width > 8) { if (width > 8) {
if (!gst_caps_get (caps, if (!gst_caps_get (caps, "endianness", &endianness, NULL))
"endianness", &endianness,
NULL))
goto error; goto error;
} else { } else {
endianness = G_BYTE_ORDER; endianness = G_BYTE_ORDER;
} }
/* find corresponding alsa format */
ret->format = snd_pcm_build_linear_format (depth, width, sign ? 0 : 1, endianness == G_LITTLE_ENDIAN ? 0 : 1); ret->format = snd_pcm_build_linear_format (depth, width, sign ? 0 : 1, endianness == G_LITTLE_ENDIAN ? 0 : 1);
} else if (strcmp (mimetype, "audio/x-raw-float") == 0) {
gint depth; } else if (! strncmp (mimetype, "audio/x-raw-float", 17)) {
gfloat intercept, slope; gint width;
/* get layout */ /* get layout */
if (!gst_caps_get (caps, "depth", &depth, if (!gst_caps_get (caps, "width", &width, NULL))
"intercept", &intercept,
"slope", &slope,
NULL))
goto error; goto error;
if (intercept != 0.0f || slope != 1.0f) {
goto error;
}
/* match layout to format wrt to endianness */ /* match layout to format wrt to endianness */
if (depth == 32) { if (width == 32) {
if (G_BYTE_ORDER == G_LITTLE_ENDIAN) { if (G_BYTE_ORDER == G_LITTLE_ENDIAN) {
ret->format = SND_PCM_FORMAT_FLOAT_LE; ret->format = SND_PCM_FORMAT_FLOAT_LE;
} else if (G_BYTE_ORDER == G_BIG_ENDIAN) { } else if (G_BYTE_ORDER == G_BIG_ENDIAN) {
@ -1286,7 +1275,7 @@ gst_alsa_get_format (GstCaps *caps)
} else { } else {
ret->format = SND_PCM_FORMAT_FLOAT; ret->format = SND_PCM_FORMAT_FLOAT;
} }
} else if (depth == 64) { } else if (width == 64) {
if (G_BYTE_ORDER == G_LITTLE_ENDIAN) { if (G_BYTE_ORDER == G_LITTLE_ENDIAN) {
ret->format = SND_PCM_FORMAT_FLOAT64_LE; ret->format = SND_PCM_FORMAT_FLOAT64_LE;
} else if (G_BYTE_ORDER == G_BIG_ENDIAN) { } else if (G_BYTE_ORDER == G_BIG_ENDIAN) {
@ -1297,20 +1286,19 @@ gst_alsa_get_format (GstCaps *caps)
} else { } else {
goto error; goto error;
} }
} else if (!strcmp (mimetype, "audio/x-alaw")) { } else if (!strncmp (mimetype, "audio/x-alaw", 12)) {
ret->format = SND_PCM_FORMAT_A_LAW; ret->format = SND_PCM_FORMAT_A_LAW;
} else if (!strcmp (mimetype, "audio/x-mulaw")) { } else if (!strncmp (mimetype, "audio/x-mulaw", 13)) {
ret->format = SND_PCM_FORMAT_MU_LAW; ret->format = SND_PCM_FORMAT_MU_LAW;
} }
/* get rate and channels */ /* get rate and channels */
if (!gst_caps_get (caps, "rate", &ret->rate, if (!gst_caps_get (caps,
"channels", &ret->channels, "rate", &ret->rate, "channels", &ret->channels, NULL))
NULL))
goto error; goto error;
return ret; return ret;
error: error:
g_free (ret); g_free (ret);
return NULL; return NULL;
@ -1321,8 +1309,8 @@ gst_alsa_formats_match (GstAlsaFormat *one, GstAlsaFormat *two)
{ {
if (one == two) return TRUE; if (one == two) return TRUE;
if (one == NULL || two == NULL) return FALSE; if (one == NULL || two == NULL) return FALSE;
return (one->format == two->format) && return (one->format == two->format) &&
(one->rate == two->rate) && (one->rate == two->rate) &&
(one->channels == two->channels); (one->channels == two->channels);
} }
/* get props for a spec */ /* get props for a spec */
@ -1333,7 +1321,6 @@ gst_alsa_get_caps_internal (snd_pcm_format_t format)
if (format == SND_PCM_FORMAT_A_LAW) { if (format == SND_PCM_FORMAT_A_LAW) {
return GST_CAPS_NEW (name, "audio/x-alaw", return GST_CAPS_NEW (name, "audio/x-alaw",
"format", GST_PROPS_STRING ("int"),
"law", GST_PROPS_INT(2), "law", GST_PROPS_INT(2),
"width", GST_PROPS_INT(8), "width", GST_PROPS_INT(8),
"depth", GST_PROPS_INT(8), "depth", GST_PROPS_INT(8),
@ -1341,7 +1328,6 @@ gst_alsa_get_caps_internal (snd_pcm_format_t format)
NULL); NULL);
} else if (format == SND_PCM_FORMAT_MU_LAW) { } else if (format == SND_PCM_FORMAT_MU_LAW) {
return GST_CAPS_NEW (name, "audio/x-mulaw", return GST_CAPS_NEW (name, "audio/x-mulaw",
"format", GST_PROPS_STRING ("int"),
"law", GST_PROPS_INT(1), "law", GST_PROPS_INT(1),
"width", GST_PROPS_INT(8), "width", GST_PROPS_INT(8),
"depth", GST_PROPS_INT(8), "depth", GST_PROPS_INT(8),
@ -1349,12 +1335,12 @@ gst_alsa_get_caps_internal (snd_pcm_format_t format)
NULL); NULL);
} else if (snd_pcm_format_linear (format)) { } else if (snd_pcm_format_linear (format)) {
/* int */ /* int */
GstProps *props = gst_props_new ("format", GST_PROPS_STRING ("int"), GstProps *props =
"width", GST_PROPS_INT(snd_pcm_format_physical_width (format)), gst_props_new ("width", GST_PROPS_INT(snd_pcm_format_physical_width (format)),
"depth", GST_PROPS_INT(snd_pcm_format_width (format)), "depth", GST_PROPS_INT(snd_pcm_format_width (format)),
"law", GST_PROPS_INT(0), "law", GST_PROPS_INT(0),
"signed", GST_PROPS_BOOLEAN (snd_pcm_format_signed (format) == 1 ? TRUE : FALSE), "signed", GST_PROPS_BOOLEAN (snd_pcm_format_signed (format) == 1 ? TRUE : FALSE),
NULL); NULL);
/* endianness */ /* endianness */
if (snd_pcm_format_physical_width (format) > 8) { if (snd_pcm_format_physical_width (format) > 8) {
switch (snd_pcm_format_little_endian (format)) { switch (snd_pcm_format_little_endian (format)) {
@ -1376,12 +1362,10 @@ gst_alsa_get_caps_internal (snd_pcm_format_t format)
if (!snd_pcm_format_cpu_endian (format)) if (!snd_pcm_format_cpu_endian (format))
return NULL; return NULL;
return GST_CAPS_NEW (name, "audio/x-raw-float", return GST_CAPS_NEW (name,
"depth", GST_PROPS_INT (snd_pcm_format_width (format)), "audio/x-raw-float",
"endianness", GST_PROPS_INT (G_BYTE_ORDER), "width", GST_PROPS_INT (snd_pcm_format_width (format)),
"intercept", GST_PROPS_FLOAT (0.), "endianness", GST_PROPS_INT (G_BYTE_ORDER));
"slope", GST_PROPS_FLOAT (1.),
NULL);
} }
return NULL; return NULL;
} }
@ -1490,7 +1474,7 @@ gst_alsa_get_caps (GstPad *pad, GstCaps *caps)
if (snd_pcm_format_mask_test (mask, i)) { if (snd_pcm_format_mask_test (mask, i)) {
GstCaps *caps = gst_alsa_get_caps_internal (i); GstCaps *caps = gst_alsa_get_caps_internal (i);
/* we can never use a format we can't set caps for */ /* we can never use a format we can't set caps for */
if (caps->properties != NULL) { if (caps != NULL && caps->properties != NULL) {
add_channels (caps->properties, min_rate, max_rate, min_channels, max_channels); add_channels (caps->properties, min_rate, max_rate, min_channels, max_channels);
ret = gst_caps_append (ret, caps); ret = gst_caps_append (ret, caps);
} }