ext/faad/gstfaad.c: Port to new caps system.

Original commit message from CVS:
2003-12-22  Benjamin Otte  <in7y118@public.uni-hamburg.de>

* ext/faad/gstfaad.c: (gst_faad_base_init), (gst_faad_init),
(gst_faad_sinkconnect), (gst_faad_srcgetcaps),
(gst_faad_srcconnect):
Port to new caps system.
This commit is contained in:
Benjamin Otte 2003-12-22 06:56:16 +00:00
parent b144bc6c58
commit 4718f83e7c
2 changed files with 129 additions and 151 deletions

View file

@ -1,3 +1,10 @@
2003-12-22 Benjamin Otte <in7y118@public.uni-hamburg.de>
* ext/faad/gstfaad.c: (gst_faad_base_init), (gst_faad_init),
(gst_faad_sinkconnect), (gst_faad_srcgetcaps),
(gst_faad_srcconnect):
Port to new caps system.
2003-12-21 Julien MOUTTE <julien@moutte.net> 2003-12-21 Julien MOUTTE <julien@moutte.net>
* examples/gstplay/player.c: (got_time_tick), (got_stream_length), * examples/gstplay/player.c: (got_time_tick), (got_stream_length),

View file

@ -25,53 +25,32 @@
#include "gstfaad.h" #include "gstfaad.h"
GST_PAD_TEMPLATE_FACTORY (sink_template, GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE (
"sink", "sink",
GST_PAD_SINK, GST_PAD_SINK,
GST_PAD_ALWAYS, GST_PAD_ALWAYS,
GST_CAPS_NEW ( GST_STATIC_CAPS ("audio/mpeg, "
"faad_mpeg_templ", "systemstream = (bool) FALSE, "
"audio/mpeg", "mpegversion = { (int) 2, (int) 4 }"
"systemstream", GST_PROPS_BOOLEAN (FALSE),
"mpegversion", GST_PROPS_LIST (
GST_PROPS_INT (2),
GST_PROPS_INT (4)
)
) )
); );
GST_PAD_TEMPLATE_FACTORY (src_template, GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE (
"src", "src",
GST_PAD_SRC, GST_PAD_SRC,
GST_PAD_ALWAYS, GST_PAD_ALWAYS,
GST_CAPS_NEW ( GST_STATIC_CAPS ("audio/x-raw-int, "
"faad_int_templ", "endianness = (int) BYTE_ORDER, "
"audio/x-raw-int", "signed = (bool) TRUE, "
"endianness", GST_PROPS_INT (G_BYTE_ORDER), "width = { (int) 16, (int) 24, (int) 32 }, "
"signed", GST_PROPS_BOOLEAN (TRUE), "depth = { (int) 16, (int) 24, (int) 32 }, "
"width", GST_PROPS_LIST ( "rate = (int) [ 8000, 96000 ], "
GST_PROPS_INT (16), "channels = (int) [ 1, 6 ];"
GST_PROPS_INT (24), "audio/x-raw-float, "
GST_PROPS_INT (32) "endianness = (int) BYTE_ORDER, "
), "depth = { (int) 32, (int) 64 }, "
"depth", GST_PROPS_LIST ( "rate = (int) [ 8000, 96000 ], "
GST_PROPS_INT (16), "channels = (int) [ 1, 6 ];"
GST_PROPS_INT (24),
GST_PROPS_INT (32)
),
"rate", GST_PROPS_INT_RANGE (8000, 96000),
"channels", GST_PROPS_INT_RANGE (1, 6)
),
GST_CAPS_NEW (
"faad_float_templ",
"audio/x-raw-float",
"endianness", GST_PROPS_INT (G_BYTE_ORDER),
"depth", GST_PROPS_LIST (
GST_PROPS_INT (32), /* float */
GST_PROPS_INT (64) /* double */
),
"rate", GST_PROPS_INT_RANGE (8000, 96000),
"channels", GST_PROPS_INT_RANGE (1, 6)
) )
); );
@ -81,12 +60,11 @@ static void gst_faad_init (GstFaad *faad);
static GstPadLinkReturn static GstPadLinkReturn
gst_faad_sinkconnect (GstPad *pad, gst_faad_sinkconnect (GstPad *pad,
GstCaps *caps); const GstCaps *caps);
static GstPadLinkReturn static GstPadLinkReturn
gst_faad_srcconnect (GstPad *pad, gst_faad_srcconnect (GstPad *pad,
GstCaps *caps); const GstCaps *caps);
static GstCaps *gst_faad_srcgetcaps (GstPad *pad, static GstCaps *gst_faad_srcgetcaps (GstPad *pad);
GstCaps *caps);
static void gst_faad_chain (GstPad *pad, static void gst_faad_chain (GstPad *pad,
GstData *data); GstData *data);
static GstElementStateReturn static GstElementStateReturn
@ -133,9 +111,9 @@ gst_faad_base_init (GstFaadClass *klass)
GstElementClass *element_class = GST_ELEMENT_CLASS (klass); GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
gst_element_class_add_pad_template (element_class, gst_element_class_add_pad_template (element_class,
GST_PAD_TEMPLATE_GET (src_template)); gst_static_pad_template_get (&src_template));
gst_element_class_add_pad_template (element_class, gst_element_class_add_pad_template (element_class,
GST_PAD_TEMPLATE_GET (sink_template)); gst_static_pad_template_get (&sink_template));
gst_element_class_set_details (element_class, &gst_faad_details); gst_element_class_set_details (element_class, &gst_faad_details);
} }
@ -160,13 +138,13 @@ gst_faad_init (GstFaad *faad)
GST_FLAG_SET (faad, GST_ELEMENT_EVENT_AWARE); GST_FLAG_SET (faad, GST_ELEMENT_EVENT_AWARE);
faad->sinkpad = gst_pad_new_from_template ( faad->sinkpad = gst_pad_new_from_template (
GST_PAD_TEMPLATE_GET (sink_template), "sink"); gst_static_pad_template_get (&sink_template), "sink");
gst_element_add_pad (GST_ELEMENT (faad), faad->sinkpad); gst_element_add_pad (GST_ELEMENT (faad), faad->sinkpad);
gst_pad_set_chain_function (faad->sinkpad, gst_faad_chain); gst_pad_set_chain_function (faad->sinkpad, gst_faad_chain);
gst_pad_set_link_function (faad->sinkpad, gst_faad_sinkconnect); gst_pad_set_link_function (faad->sinkpad, gst_faad_sinkconnect);
faad->srcpad = gst_pad_new_from_template ( faad->srcpad = gst_pad_new_from_template (
GST_PAD_TEMPLATE_GET (src_template), "src"); gst_static_pad_template_get (&src_template), "src");
gst_element_add_pad (GST_ELEMENT (faad), faad->srcpad); gst_element_add_pad (GST_ELEMENT (faad), faad->srcpad);
gst_pad_set_link_function (faad->srcpad, gst_faad_srcconnect); gst_pad_set_link_function (faad->srcpad, gst_faad_srcconnect);
@ -179,19 +157,15 @@ gst_faad_init (GstFaad *faad)
static GstPadLinkReturn static GstPadLinkReturn
gst_faad_sinkconnect (GstPad *pad, gst_faad_sinkconnect (GstPad *pad,
GstCaps *caps) const GstCaps *caps)
{ {
if (!GST_CAPS_IS_FIXED (caps))
return GST_PAD_LINK_DELAYED;
/* oh, we really don't care what's in here. We'll /* oh, we really don't care what's in here. We'll
* get AAC audio (MPEG-2/4) anyway, so why bother? */ * get AAC audio (MPEG-2/4) anyway, so why bother? */
return GST_PAD_LINK_OK; return GST_PAD_LINK_OK;
} }
static GstCaps * static GstCaps *
gst_faad_srcgetcaps (GstPad *pad, gst_faad_srcgetcaps (GstPad *pad)
GstCaps *caps)
{ {
GstFaad *faad = GST_FAAD (gst_pad_get_parent (pad)); GstFaad *faad = GST_FAAD (gst_pad_get_parent (pad));
@ -204,149 +178,146 @@ gst_faad_srcgetcaps (GstPad *pad,
switch (conf->outputFormat) { switch (conf->outputFormat) {
case FAAD_FMT_16BIT: case FAAD_FMT_16BIT:
caps = GST_CAPS_NEW ("faad_src_int16", caps = gst_caps_new_simple ("audio/x-raw-int",
"audio/x-raw-int", "signed", G_TYPE_BOOLEAN, TRUE,
"signed", GST_PROPS_BOOLEAN (TRUE), "width", G_TYPE_INT, 16,
"width", GST_PROPS_INT (16), "depth", G_TYPE_INT, 16,
"depth", GST_PROPS_INT (16)); NULL);
break; break;
case FAAD_FMT_24BIT: case FAAD_FMT_24BIT:
caps = GST_CAPS_NEW ("faad_src_int24", caps = gst_caps_new_simple ("audio/x-raw-int",
"audio/x-raw-int", "signed", G_TYPE_BOOLEAN, TRUE,
"signed", GST_PROPS_BOOLEAN (TRUE), "width", G_TYPE_INT, 24,
"width", GST_PROPS_INT (24), "depth", G_TYPE_INT, 24,
"depth", GST_PROPS_INT (24)); NULL);
break; break;
case FAAD_FMT_32BIT: case FAAD_FMT_32BIT:
caps = GST_CAPS_NEW ("faad_src_int32", caps = gst_caps_new_simple ("audio/x-raw-int",
"audio/x-raw-int", "signed", G_TYPE_BOOLEAN, TRUE,
"signed", GST_PROPS_BOOLEAN (TRUE), "width", G_TYPE_INT, 32,
"width", GST_PROPS_INT (32), "depth", G_TYPE_INT, 32,
"depth", GST_PROPS_INT (32)); NULL);
break; break;
case FAAD_FMT_FLOAT: case FAAD_FMT_FLOAT:
caps = GST_CAPS_NEW ("faad_src_float32", caps = gst_caps_new_simple ("audio/x-raw-float",
"audio/x-raw-float", "depth", G_TYPE_INT, 32,
"depth", GST_PROPS_INT (32)); NULL);
break; break;
case FAAD_FMT_DOUBLE: case FAAD_FMT_DOUBLE:
caps = GST_CAPS_NEW ("faad_src_float64", caps = gst_caps_new_simple ("audio/x-raw-float",
"audio/x-raw-float", "depth", G_TYPE_INT, 64,
"depth", GST_PROPS_INT (64)); NULL);
break; break;
default: default:
caps = GST_CAPS_NONE; caps = gst_caps_new_empty ();
break; break;
} }
if (caps) { if (!gst_caps_is_empty (caps)) {
GstPropsEntry *samplerate, *channels, *endianness; GstStructure *structure = gst_caps_get_structure (caps, 0);
if (faad->samplerate != -1) { if (faad->samplerate != -1) {
samplerate = gst_props_entry_new ("rate", gst_structure_set (structure,
GST_PROPS_INT (faad->samplerate)); "rate", G_TYPE_INT, faad->samplerate,
NULL);
} else { } else {
samplerate = gst_props_entry_new ("rate", gst_structure_set (structure,
GST_PROPS_INT_RANGE (8000, 96000)); "rate", GST_TYPE_INT_RANGE, 8000, 96000,
NULL);
} }
gst_props_add_entry (caps->properties, samplerate);
if (faad->channels != -1) { if (faad->channels != -1) {
channels = gst_props_entry_new ("channels", gst_structure_set (structure,
GST_PROPS_INT (faad->channels)); "channels", G_TYPE_INT, faad->channels,
NULL);
} else { } else {
channels = gst_props_entry_new ("channels", gst_structure_set (structure,
GST_PROPS_INT_RANGE (1, 6)); "channels", GST_TYPE_INT_RANGE, 1, 6,
NULL);
} }
gst_props_add_entry (caps->properties, channels);
endianness = gst_props_entry_new ("endianness", gst_structure_set (structure,
GST_PROPS_INT (G_BYTE_ORDER)); "endianness", G_TYPE_INT, G_BYTE_ORDER,
gst_props_add_entry (caps->properties, endianness); NULL);
} }
return caps; return caps;
} }
return gst_pad_template_get_caps ( return GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad));
GST_PAD_TEMPLATE_GET (src_template));
} }
static GstPadLinkReturn static GstPadLinkReturn
gst_faad_srcconnect (GstPad *pad, gst_faad_srcconnect (GstPad *pad,
GstCaps *caps) const GstCaps *caps)
{ {
GstStructure *structure;
const gchar *mimetype;
gint fmt;
gint depth;
GstFaad *faad = GST_FAAD (gst_pad_get_parent (pad)); GstFaad *faad = GST_FAAD (gst_pad_get_parent (pad));
GstCaps *t;
if (!faad->handle || if (!faad->handle ||
(faad->samplerate == -1 || faad->channels == -1)) { (faad->samplerate == -1 || faad->channels == -1)) {
return GST_PAD_LINK_DELAYED; return GST_PAD_LINK_DELAYED;
} }
/* we do samplerate/channels ourselves */ structure = gst_caps_get_structure (caps, 0);
for (t = caps; t != NULL; t = t->next) { mimetype = gst_structure_get_name (structure);
gst_props_remove_entry_by_name (t->properties, "rate");
gst_props_remove_entry_by_name (t->properties, "channels"); if (!strcmp (mimetype, "audio/x-raw-int")) {
gint width;
if (!gst_structure_get_int (structure, "depth", &depth) ||
!gst_structure_get_int (structure, "width", &width))
return GST_PAD_LINK_REFUSED;
if (depth != width)
return GST_PAD_LINK_REFUSED;
switch (depth) {
case 16:
fmt = FAAD_FMT_16BIT;
break;
case 24:
fmt = FAAD_FMT_24BIT;
break;
case 32:
fmt = FAAD_FMT_32BIT;
break;
}
} else {
if (!gst_structure_get_int (structure, "depth", &depth))
return GST_PAD_LINK_REFUSED;
switch (depth) {
case 32:
fmt = FAAD_FMT_FLOAT;
break;
case 64:
fmt = FAAD_FMT_DOUBLE;
break;
}
} }
/* go through list */ if (fmt) {
caps = gst_caps_normalize (caps); GstCaps *newcaps, *intersect;
for ( ; caps != NULL; caps = caps->next) { faacDecConfiguration *conf;
const gchar *mimetype = gst_caps_get_mime (caps);
gint depth = 0, fmt = 0;
if (!strcmp (mimetype, "audio/x-raw-int")) { conf = faacDecGetCurrentConfiguration (faad->handle);
gint width = 0; conf->outputFormat = fmt;
faacDecSetConfiguration (faad->handle, conf);
/* FIXME: handle return value, how? */
if (gst_caps_has_fixed_property (caps, "depth") && newcaps = gst_faad_srcgetcaps (pad);
gst_caps_has_fixed_property (caps, "width")) g_assert (gst_caps_is_fixed (newcaps));
gst_caps_get (caps, "depth", &depth, intersect = gst_caps_intersect (newcaps, caps);
"width", &width, NULL); gst_caps_free (newcaps);
if (depth != width) if (!gst_caps_is_empty (intersect)) {
continue; gst_caps_free (intersect);
faad->bps = depth / 8;
switch (depth) { return GST_PAD_LINK_OK;
case 16:
fmt = FAAD_FMT_16BIT;
break;
case 24:
fmt = FAAD_FMT_24BIT;
break;
case 32:
fmt = FAAD_FMT_32BIT;
break;
}
} else {
if (gst_caps_has_fixed_property (caps, "depth"))
gst_caps_get_int (caps, "depth", &depth);
switch (depth) {
case 32:
fmt = FAAD_FMT_FLOAT;
break;
case 64:
fmt = FAAD_FMT_DOUBLE;
break;
}
}
if (fmt) {
GstCaps *newcaps;
faacDecConfiguration *conf;
conf = faacDecGetCurrentConfiguration (faad->handle);
conf->outputFormat = fmt;
faacDecSetConfiguration (faad->handle, conf);
/* FIXME: handle return value, how? */
newcaps = gst_faad_srcgetcaps (pad, NULL);
g_assert (GST_CAPS_IS_FIXED (newcaps));
if (gst_pad_try_set_caps (pad, newcaps) > 0) {
faad->bps = depth / 8;
return GST_PAD_LINK_DONE;
}
} }
gst_caps_free (intersect);
} }
return GST_PAD_LINK_REFUSED; return GST_PAD_LINK_REFUSED;