summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Schleef <ds@schleef.org>2003-12-07 22:23:46 +0000
committerDavid Schleef <ds@schleef.org>2003-12-07 22:23:46 +0000
commit6281451b4179365b4d17699894ef77bccdcda9ef (patch)
tree00ed167418f6137d4871d8dc9609235049f6fdd2
parent0856bd775bcac8abfec9febff65ae0d81df84a28 (diff)
downloadgstreamer-plugins-base-6281451b4179365b4d17699894ef77bccdcda9ef.tar.gz
Convert to new caps
Original commit message from CVS: Convert to new caps
-rw-r--r--gst/audioconvert/gstaudioconvert.c126
-rw-r--r--gst/audioscale/gstaudioscale.c148
2 files changed, 114 insertions, 160 deletions
diff --git a/gst/audioconvert/gstaudioconvert.c b/gst/audioconvert/gstaudioconvert.c
index 8901ff797..073f79e91 100644
--- a/gst/audioconvert/gstaudioconvert.c
+++ b/gst/audioconvert/gstaudioconvert.c
@@ -29,7 +29,7 @@
#if 0
static void
-print_caps (GstCaps *caps)
+print_caps (GstCaps2 *caps)
{
GValue v = { 0, };
GValue s = { 0, };
@@ -121,7 +121,7 @@ static void gst_audio_convert_get_property (GObject *object, guint prop_id, GVa
/* gstreamer functions */
static void gst_audio_convert_chain (GstPad *pad, GstData *_data);
-static GstPadLinkReturn gst_audio_convert_link (GstPad *pad, GstCaps *caps);
+static GstPadLinkReturn gst_audio_convert_link (GstPad *pad, const GstCaps2 *caps);
static GstElementStateReturn gst_audio_convert_change_state (GstElement *element);
/* actual work */
@@ -151,37 +151,27 @@ static GstElementClass *parent_class = NULL;
/*** GSTREAMER PROTOTYPES *****************************************************/
-GST_PAD_TEMPLATE_FACTORY (audio_convert_src_template_factory,
+static GstStaticPadTemplate gst_audio_convert_src_template =
+GST_STATIC_PAD_TEMPLATE (
"src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
- gst_caps_append (
- gst_caps_new (
- "audio_convert_src_int",
- "audio/x-raw-int",
- GST_AUDIO_INT_PAD_TEMPLATE_PROPS),
- gst_caps_new (
- "audio_convert_src_float",
- "audio/x-raw-float",
- GST_AUDIO_FLOAT_PAD_TEMPLATE_PROPS)
+ GST_STATIC_CAPS (
+ GST_AUDIO_INT_PAD_TEMPLATE_CAPS "; "
+ GST_AUDIO_FLOAT_PAD_TEMPLATE_CAPS
)
-)
+);
-GST_PAD_TEMPLATE_FACTORY (audio_convert_sink_template_factory,
+static GstStaticPadTemplate gst_audio_convert_sink_template =
+GST_STATIC_PAD_TEMPLATE (
"sink",
- GST_PAD_SINK,
+ GST_PAD_SRC,
GST_PAD_ALWAYS,
- gst_caps_append (
- gst_caps_new (
- "audio_convert_sink_int",
- "audio/x-raw-int",
- GST_AUDIO_INT_PAD_TEMPLATE_PROPS),
- gst_caps_new (
- "audio_convert_sink_float",
- "audio/x-raw-float",
- GST_AUDIO_FLOAT_PAD_TEMPLATE_PROPS)
+ GST_STATIC_CAPS (
+ GST_AUDIO_INT_PAD_TEMPLATE_CAPS "; "
+ GST_AUDIO_FLOAT_PAD_TEMPLATE_CAPS
)
-)
+);
/*** TYPE FUNCTIONS ***********************************************************/
@@ -214,9 +204,9 @@ gst_audio_convert_base_init (gpointer g_class)
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
gst_element_class_add_pad_template (element_class,
- GST_PAD_TEMPLATE_GET (audio_convert_src_template_factory));
+ gst_static_pad_template_get (&gst_audio_convert_src_template));
gst_element_class_add_pad_template (element_class,
- GST_PAD_TEMPLATE_GET (audio_convert_sink_template_factory));
+ gst_static_pad_template_get (&gst_audio_convert_sink_template));
gst_element_class_set_details (element_class, &audio_convert_details);
}
@@ -261,14 +251,14 @@ static void
gst_audio_convert_init (GstAudioConvert *this)
{
/* sinkpad */
- this->sink = gst_pad_new_from_template (GST_PAD_TEMPLATE_GET (
- audio_convert_sink_template_factory), "sink");
+ this->sink = gst_pad_new_from_template (
+ gst_static_pad_template_get (&gst_audio_convert_sink_template), "sink");
gst_pad_set_link_function (this->sink, gst_audio_convert_link);
gst_element_add_pad (GST_ELEMENT(this), this->sink);
/* srcpad */
- this->src = gst_pad_new_from_template (GST_PAD_TEMPLATE_GET (
- audio_convert_src_template_factory), "src");
+ this->src = gst_pad_new_from_template (
+ gst_static_pad_template_get (&gst_audio_convert_src_template), "src");
gst_pad_set_link_function (this->src, gst_audio_convert_link);
gst_element_add_pad (GST_ELEMENT(this), this->src);
@@ -383,38 +373,36 @@ gst_audio_convert_chain (GstPad *pad, GstData *_data)
}
static GstPadLinkReturn
-gst_audio_convert_link (GstPad *pad, GstCaps *caps)
+gst_audio_convert_link (GstPad *pad, const GstCaps2 *caps)
{
GstAudioConvert *this;
gint nr = 0;
gint rate, endianness, depth, width, channels;
gboolean sign;
+ GstStructure *structure;
+ gboolean ret;
g_return_val_if_fail(GST_IS_PAD(pad), GST_PAD_LINK_REFUSED);
g_return_val_if_fail(GST_IS_AUDIO_CONVERT(GST_OBJECT_PARENT (pad)), GST_PAD_LINK_REFUSED);
this = GST_AUDIO_CONVERT(GST_OBJECT_PARENT (pad));
- /* could we do better? */
- if (!GST_CAPS_IS_FIXED (caps)) return GST_PAD_LINK_DELAYED;
-
nr = (pad == this->sink) ? 0 : (pad == this->src) ? 1 : -1;
g_assert (nr > -1);
- if (! gst_caps_get (caps,
- "channels", &channels,
- "signed", &sign,
- "depth", &depth,
- "width", &width,
- "rate", &rate, NULL))
- return GST_PAD_LINK_DELAYED;
-
- if (!gst_caps_get_int (caps, "endianness", &endianness)) {
- if (width == 1) {
- endianness = G_BYTE_ORDER;
- } else {
- return GST_PAD_LINK_DELAYED;
- }
+ structure = gst_caps2_get_nth_cap (caps, 0);
+
+ ret = gst_structure_get_int (structure, "channels", &channels);
+ ret &= gst_structure_get_boolean (structure, "signed", &sign);
+ ret &= gst_structure_get_int (structure, "depth", &depth);
+ ret &= gst_structure_get_int (structure, "width", &width);
+ ret &= gst_structure_get_int (structure, "rate", &rate);
+ endianness = G_BYTE_ORDER;
+ if (width != 8) {
+ ret &= gst_structure_get_int (structure, "endianness", &endianness);
}
+
+ if (!ret) return GST_PAD_LINK_REFUSED;
+
/* we can't convert rate changes yet */
if ((this->caps_set[1 - nr]) &&
(rate != this->rate[1 - nr]))
@@ -454,36 +442,30 @@ gst_audio_convert_change_state (GstElement *element)
/*** ACTUAL WORK **************************************************************/
-static GstCaps*
+static GstCaps2 *
make_caps (gint endianness, gboolean sign, gint depth, gint width, gint rate, gint channels)
{
- if (width == 1) {
- return GST_CAPS_NEW (
- "audio_convert_caps",
- "audio/x-raw-int",
- "signed", GST_PROPS_BOOLEAN (sign),
- "depth", GST_PROPS_INT (depth),
- "width", GST_PROPS_INT (width * 8),
- "rate", GST_PROPS_INT (rate),
- "channels", GST_PROPS_INT (channels)
- );
- } else {
- return GST_CAPS_NEW (
- "audio_convert_caps",
- "audio/x-raw-int",
- "endianness", GST_PROPS_INT (endianness),
- "signed", GST_PROPS_BOOLEAN (sign),
- "depth", GST_PROPS_INT (depth),
- "width", GST_PROPS_INT (width * 8),
- "rate", GST_PROPS_INT (rate),
- "channels", GST_PROPS_INT (channels)
- );
+ GstCaps2 *caps;
+
+ caps = gst_caps2_new_simple ("audio/x-raw-int",
+ "signed", G_TYPE_BOOLEAN, sign,
+ "depth", G_TYPE_INT, depth,
+ "width", G_TYPE_INT, width * 8,
+ "rate", G_TYPE_INT, rate,
+ "channels", G_TYPE_INT, channels, NULL);
+
+ if (width != 1) {
+ gst_caps2_set_simple (caps,
+ "endianness", G_TYPE_INT, endianness, NULL);
}
+
+ return caps;
}
+
static gboolean
gst_audio_convert_set_caps (GstPad *pad)
{
- GstCaps *caps;
+ GstCaps2 *caps;
gint nr;
GstPadLinkReturn ret;
GstAudioConvert *this;
diff --git a/gst/audioscale/gstaudioscale.c b/gst/audioscale/gstaudioscale.c
index a4e1acdab..69a5b633d 100644
--- a/gst/audioscale/gstaudioscale.c
+++ b/gst/audioscale/gstaudioscale.c
@@ -50,22 +50,20 @@ enum {
/* FILL ME */
};
-GST_PAD_TEMPLATE_FACTORY (sink_factory,
+static GstStaticPadTemplate gst_audioscale_sink_template =
+GST_STATIC_PAD_TEMPLATE (
"sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
- gst_caps_new ("audioscale_sink",
- "audio/x-raw-int",
- GST_AUDIO_INT_PAD_TEMPLATE_PROPS)
+ GST_STATIC_CAPS ( GST_AUDIO_INT_PAD_TEMPLATE_CAPS)
);
-GST_PAD_TEMPLATE_FACTORY (src_factory,
+static GstStaticPadTemplate gst_audioscale_src_template =
+GST_STATIC_PAD_TEMPLATE (
"src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
- gst_caps_new ("audioscale_src",
- "audio/x-raw-int",
- GST_AUDIO_INT_PAD_TEMPLATE_PROPS)
+ GST_STATIC_CAPS ( GST_AUDIO_INT_PAD_TEMPLATE_CAPS)
);
#define GST_TYPE_AUDIOSCALE_METHOD (gst_audioscale_method_get_type())
@@ -129,9 +127,9 @@ gst_audioscale_base_init (gpointer g_class)
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
gst_element_class_add_pad_template (gstelement_class,
- GST_PAD_TEMPLATE_GET (src_factory));
+ gst_static_pad_template_get (&gst_audioscale_src_template));
gst_element_class_add_pad_template (gstelement_class,
- GST_PAD_TEMPLATE_GET (sink_factory));
+ gst_static_pad_template_get (&gst_audioscale_sink_template));
gst_element_class_set_details (gstelement_class, &gst_audioscale_details);
}
@@ -159,11 +157,14 @@ gst_audioscale_class_init (AudioscaleClass *klass)
parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
}
-static GstCaps *
-gst_audioscale_getcaps (GstPad *pad, GstCaps *caps)
+static GstCaps2 *
+gst_audioscale_getcaps (GstPad *pad)
{
Audioscale *audioscale;
- GstCaps *peercaps;
+ GstCaps2 *peercaps;
+ GstCaps2 *caps;
+ int i;
+ int n;
audioscale = GST_AUDIOSCALE (gst_pad_get_parent (pad));
@@ -173,105 +174,75 @@ gst_audioscale_getcaps (GstPad *pad, GstCaps *caps)
peercaps = gst_pad_get_allowed_caps (audioscale->srcpad);
}
- if(peercaps == GST_CAPS_NONE){
- return GST_CAPS_NONE;
- }
+ caps = gst_caps2_intersect (peercaps, gst_static_caps2_get (
+ &gst_audioscale_sink_template.static_caps));
+ if (gst_caps2_is_empty(caps)) return caps;
- caps = gst_caps_copy (peercaps);
-#if 1
/* we do this hack, because the audioscale lib doesn't handle
* rate conversions larger than a factor of 2 */
- if(gst_caps_has_property_typed(caps, "rate", GST_PROPS_INT_RANGE_TYPE)){
+ n = gst_caps2_get_n_structures (caps);
+ for (i=0;i<n;i++){
int rate_min, rate_max;
-
- gst_props_entry_get_int_range (gst_props_get_entry(caps->properties, "rate"),
- &rate_min, &rate_max);
- gst_caps_set (caps, "rate", GST_PROPS_INT_RANGE((rate_min+1)/2,
- rate_max*2));
- }else{
- int rate;
-
- gst_caps_get_int (caps, "rate", &rate);
- gst_caps_set (caps, "rate", GST_PROPS_INT_RANGE((rate+1)/2,rate*2));
+ GstStructure *structure = gst_caps2_get_nth_cap (caps, i);
+ const GValue *value;
+
+ value = gst_structure_get_value (structure, "rate");
+ if (value == NULL) return NULL;
+
+ if (G_VALUE_TYPE (value) == G_TYPE_INT) {
+ rate_min = g_value_get_int (value);
+ rate_max = rate_min;
+ } else if (G_VALUE_TYPE (value) == GST_TYPE_INT_RANGE) {
+ rate_min = gst_value_get_int_range_min (value);
+ rate_max = gst_value_get_int_range_max (value);
+ } else {
+ return NULL;
+ }
+
+ gst_structure_set (structure, "rate", GST_TYPE_INT_RANGE, rate_min/2,
+ rate_max*2, NULL);
}
-#else
- gst_caps_set (caps, "rate", GST_PROPS_INT_RANGE(4000,96000));
-#endif
return caps;
}
static GstPadLinkReturn
-gst_audioscale_sink_link (GstPad * pad, GstCaps * caps)
+gst_audioscale_link (GstPad * pad, const GstCaps2 * caps)
{
Audioscale *audioscale;
resample_t *r;
- GstCaps *caps1;
- GstCaps *caps2;
- GstCaps *peercaps;
- gint rate;
+ GstStructure *structure;
+ int rate;
+ int channels;
int ret;
+ GstPadLinkReturn link_ret;
audioscale = GST_AUDIOSCALE (gst_pad_get_parent (pad));
r = audioscale->resample;
- if (!GST_CAPS_IS_FIXED (caps)){
- return GST_PAD_LINK_DELAYED;
- }
-
- ret = gst_pad_try_set_caps (audioscale->srcpad, caps);
-
- if(ret == GST_PAD_LINK_OK || ret == GST_PAD_LINK_DONE){
+ link_ret = gst_pad_try_set_caps ((pad == audioscale->srcpad)
+ ? audioscale->sinkpad : audioscale->srcpad, caps);
+ if(link_ret == GST_PAD_LINK_OK){
audioscale->passthru = TRUE;
- return ret;
+ return link_ret;
}
audioscale->passthru = FALSE;
- gst_caps_get_int (caps, "rate", &rate);
- gst_caps_get_int (caps, "channels", &r->channels);
-
- r->i_rate = rate;
- resample_reinit(r);
-
- peercaps = gst_pad_get_allowed_caps (audioscale->srcpad);
+ structure = gst_caps2_get_nth_cap (caps, 0);
- caps1 = gst_caps_copy (caps);
-#if 1
- /* we do this hack, because the audioscale lib doesn't handle
- * rate conversions larger than a factor of 2 */
- if(gst_caps_has_property_typed(caps1, "rate", GST_PROPS_INT_RANGE_TYPE)){
- int rate_min, rate_max;
+ ret = gst_structure_get_int (structure, "rate", &rate);
+ ret &= gst_structure_get_int (structure, "channels", &channels);
- gst_props_entry_get_int_range (gst_props_get_entry(caps1->properties, "rate"),
- &rate_min, &rate_max);
- gst_caps_set (caps1, "rate", GST_PROPS_INT_RANGE((rate_min+1)/2,
- rate_max*2));
- }else{
- gst_caps_get_int (caps1, "rate", &rate);
- gst_caps_set (caps1, "rate", GST_PROPS_INT_RANGE((rate+1)/2,rate*2));
- }
-#else
- gst_caps_set (caps1, "rate", GST_PROPS_INT_RANGE(4000,96000));
-#endif
- caps2 = gst_caps_intersect(caps1, peercaps);
- gst_caps_unref(caps1);
-
- if(caps2 == GST_CAPS_NONE){
- return GST_PAD_LINK_REFUSED;
- }
-
- if (GST_CAPS_IS_FIXED (caps2)) {
- ret = gst_pad_try_set_caps (audioscale->srcpad, caps2);
- gst_caps_get_int (caps, "rate", &rate);
+ r->channels = channels;
+ if (pad == audioscale->srcpad) {
+ r->i_rate = rate;
+ } else {
r->o_rate = rate;
- audioscale->targetfrequency = rate;
- resample_reinit(r);
- return ret;
}
-
- gst_caps_unref (caps2);
- return GST_PAD_LINK_DELAYED;
+ resample_reinit(r);
+
+ return GST_PAD_LINK_OK;
}
static void *
@@ -294,16 +265,17 @@ gst_audioscale_init (Audioscale *audioscale)
resample_t *r;
audioscale->sinkpad = gst_pad_new_from_template (
- GST_PAD_TEMPLATE_GET (sink_factory), "sink");
+ gst_static_pad_template_get (&gst_audioscale_sink_template), "sink");
gst_element_add_pad(GST_ELEMENT(audioscale),audioscale->sinkpad);
gst_pad_set_chain_function(audioscale->sinkpad,gst_audioscale_chain);
- gst_pad_set_link_function (audioscale->sinkpad, gst_audioscale_sink_link);
+ gst_pad_set_link_function (audioscale->sinkpad, gst_audioscale_link);
gst_pad_set_getcaps_function (audioscale->sinkpad, gst_audioscale_getcaps);
audioscale->srcpad = gst_pad_new_from_template (
- GST_PAD_TEMPLATE_GET (src_factory), "src");
+ gst_static_pad_template_get (&gst_audioscale_src_template), "src");
gst_element_add_pad(GST_ELEMENT(audioscale),audioscale->srcpad);
+ gst_pad_set_link_function (audioscale->srcpad, gst_audioscale_link);
gst_pad_set_getcaps_function (audioscale->srcpad, gst_audioscale_getcaps);
r = g_new0(resample_t,1);