Skip to content

Commit

Permalink
request-pads: use newer gstreamer api
Browse files Browse the repository at this point in the history
Cache elementfactories and in some cases pad-templates. Use them when requesting
pads.
  • Loading branch information
ensonic committed Jan 28, 2013
1 parent 6c2b703 commit edeedf4
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 66 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
dnl dependencies
REQ_GLIB=2.32.0
REQ_GTK=2.20.0
REQ_GST=0.10.28
REQ_GST=0.10.32


dnl
Expand Down
1 change: 1 addition & 0 deletions docs/reference/bt-core/buzztard-core-sections.txt
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,7 @@ bt_gst_analyzer_get_waittime
bt_gst_check_core_elements
bt_gst_check_elements
bt_gst_debug_pad_link_return
bt_gst_element_factory_get_pad_template
bt_gst_element_factory_can_sink_media_type
bt_gst_registry_get_element_factories_matching_all_categories
bt_gst_registry_get_element_names_matching_all_categories
Expand Down
78 changes: 60 additions & 18 deletions src/lib/core/machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,11 @@ static gchar *sink_pn[] = {
"sink" /* tee */
};

static GstElementFactory *factories[PART_COUNT];
// for tee and adder
static GstPadTemplate *src_pt;
static GstPadTemplate *sink_pt;


//-- the class

Expand Down Expand Up @@ -672,8 +677,8 @@ bt_machine_insert_element (BtMachine * const self, GstPad * const peer,
bt_machine_link_elements (self, src_pads[pos],
sink_pads[post]))) {
if ((wire =
(self->dst_wires ? (BtWire *) (self->dst_wires->
data) : NULL))) {
(self->dst_wires ? (BtWire *) (self->
dst_wires->data) : NULL))) {
if (!(res = bt_wire_reconnect (wire))) {
GST_WARNING_OBJECT (self,
"failed to reconnect wire after linking '%s' before '%s'",
Expand Down Expand Up @@ -701,8 +706,8 @@ bt_machine_insert_element (BtMachine * const self, GstPad * const peer,
if ((res =
bt_machine_link_elements (self, src_pads[pre], sink_pads[pos]))) {
if ((wire =
(self->src_wires ? (BtWire *) (self->src_wires->
data) : NULL))) {
(self->src_wires ? (BtWire *) (self->
src_wires->data) : NULL))) {
if (!(res = bt_wire_reconnect (wire))) {
GST_WARNING_OBJECT (self,
"failed to reconnect wire after linking '%s' after '%s'",
Expand Down Expand Up @@ -831,22 +836,40 @@ bt_machine_make_internal_element (const BtMachine * const self,
{
gboolean res = FALSE;
GstElement *m;
GstElementFactory *f;
const gchar *const parent_name = GST_OBJECT_NAME (self);
gchar *const name =
g_alloca (strlen (parent_name) + 2 + strlen (element_name));
gpointer item;

g_return_val_if_fail ((self->priv->machines[part] == NULL), TRUE);

// for the core machine we don't cache the factory
if (part == PART_MACHINE) {
if (!(f = gst_element_factory_find (factory_name))) {
GST_WARNING_OBJECT (self, "failed to lookup factory %s", factory_name);
goto Error;
}
} else {
if (!factories[part]) {
// we never unref them, instead we keep them until the end
if (!(factories[part] = gst_element_factory_find (factory_name))) {
GST_WARNING_OBJECT (self, "failed to lookup factory %s", factory_name);
goto Error;
}
}
f = factories[part];
}

// create internal element
//strcat(name,parent_name);strcat(name,":");strcat(name,element_name);
g_sprintf (name, "%s:%s", parent_name, element_name);
if (!(self->priv->machines[part] = m =
gst_element_factory_make (factory_name, name))) {
if (!(self->priv->machines[part] = gst_element_factory_create (f, name))) {
GST_WARNING_OBJECT (self, "failed to create %s from factory %s",
element_name, factory_name);
goto Error;
}
m = self->priv->machines[part];
// disable deep notify
{
GObjectClass *gobject_class = G_OBJECT_GET_CLASS (m);
Expand Down Expand Up @@ -909,8 +932,11 @@ bt_machine_make_internal_element (const BtMachine * const self,
}
}

gst_bin_add (GST_BIN (self), self->priv->machines[part]);
gst_element_sync_state_with_parent (self->priv->machines[part]);
gst_bin_add (GST_BIN (self), m);
gst_element_sync_state_with_parent (m);
if (part == PART_MACHINE) {
gst_object_unref (f);
}
res = TRUE;
Error:
return (res);
Expand Down Expand Up @@ -1332,8 +1358,8 @@ bt_machine_init_global_params (const BtMachine * const self)
//g_assert(gst_child_proxy_get_children_count(GST_CHILD_PROXY(self->priv->machines[PART_MACHINE])));
// get child for voice 0
if ((voice_child =
gst_child_proxy_get_child_by_index (GST_CHILD_PROXY (self->priv->
machines[PART_MACHINE]), 0))) {
gst_child_proxy_get_child_by_index (GST_CHILD_PROXY (self->
priv->machines[PART_MACHINE]), 0))) {
child_properties =
g_object_class_list_properties (G_OBJECT_CLASS (GST_OBJECT_GET_CLASS
(voice_child)), &number_of_child_properties);
Expand Down Expand Up @@ -1395,8 +1421,8 @@ bt_machine_init_voice_params (const BtMachine * const self)
// register voice params
// get child for voice 0
if ((voice_child =
gst_child_proxy_get_child_by_index (GST_CHILD_PROXY (self->priv->
machines[PART_MACHINE]), 0))) {
gst_child_proxy_get_child_by_index (GST_CHILD_PROXY (self->
priv->machines[PART_MACHINE]), 0))) {
GParamSpec **properties;
guint number_of_properties;

Expand Down Expand Up @@ -3049,15 +3075,31 @@ bt_machine_request_new_pad (GstElement * element, GstPadTemplate * templ,

// check direction
if (GST_PAD_TEMPLATE_DIRECTION (templ) == GST_PAD_SRC) {
target =
gst_element_get_request_pad (self->priv->machines[PART_SPREADER],
"src%d");
if (!src_pt) {
src_pt =
bt_gst_element_factory_get_pad_template (factories[PART_SPREADER],
"src%d");
}

if (!(target = gst_element_request_pad (self->priv->machines[PART_SPREADER],
src_pt, NULL, NULL))) {
GST_WARNING_OBJECT (element, "failed to request pad 'src%d'");
return NULL;
}
name = g_strdup_printf ("src%d", self->priv->src_pad_counter++);
GST_INFO_OBJECT (element, "request src pad: %s", name);
} else {
target =
gst_element_get_request_pad (self->priv->machines[PART_ADDER],
"sink%d");
if (!sink_pt) {
sink_pt =
bt_gst_element_factory_get_pad_template (factories[PART_ADDER],
"sink%d");
}

if (!(target = gst_element_request_pad (self->priv->machines[PART_ADDER],
sink_pt, NULL, NULL))) {
GST_WARNING_OBJECT (element, "failed to request pad 'sink%d'");
return NULL;
}
name = g_strdup_printf ("sink%d", self->priv->sink_pad_counter++);
GST_INFO_OBJECT (element, "request sink pad: %s", name);
}
Expand Down
61 changes: 40 additions & 21 deletions src/lib/core/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ link_wire (const BtSetup * const self, GstElement * wire)
{
GstPadLinkReturn link_res;
GstElement *src, *dst;
GstPadTemplate *tmpl;
GstPad *src_pad, *dst_pad, *peer;
gboolean res = TRUE;

Expand All @@ -521,29 +522,38 @@ link_wire (const BtSetup * const self, GstElement * wire)
dst_pad = gst_element_get_static_pad (GST_ELEMENT (wire), "sink");
GST_INFO_OBJECT (dst_pad, "linking start of wire");
if (!(peer = gst_pad_get_peer (dst_pad))) {
if ((src_pad = gst_element_get_request_pad (GST_ELEMENT (src), "src%d"))) {
if ((tmpl =
gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS (src),
"src%d"))) {
if ((src_pad =
gst_element_request_pad (GST_ELEMENT (src), tmpl, NULL, NULL))) {
#if USE_PAD_BLOCK
if ( /*(BT_IS_SOURCE_MACHINE(src) && (GST_STATE(self->priv->bin)==GST_STATE_PLAYING)) || */
(GST_STATE (src) == GST_STATE_PLAYING)) {
if (gst_pad_is_active (src_pad)) {
if (gst_pad_set_blocked (src_pad, TRUE)) {
self->priv->blocked_pads =
g_slist_prepend (self->priv->blocked_pads,
gst_object_ref (src_pad));
if ( /*(BT_IS_SOURCE_MACHINE(src) && (GST_STATE(self->priv->bin)==GST_STATE_PLAYING)) || */
(GST_STATE (src) == GST_STATE_PLAYING)) {
if (gst_pad_is_active (src_pad)) {
if (gst_pad_set_blocked (src_pad, TRUE)) {
self->priv->blocked_pads =
g_slist_prepend (self->priv->blocked_pads,
gst_object_ref (src_pad));
}
}
}
}
#endif
if (GST_PAD_LINK_FAILED (link_res = gst_pad_link (src_pad, dst_pad))) {
GST_WARNING ("Can't link start of wire : %s",
bt_gst_debug_pad_link_return (link_res, src_pad, dst_pad));
if (GST_PAD_LINK_FAILED (link_res = gst_pad_link (src_pad, dst_pad))) {
GST_WARNING ("Can't link start of wire : %s",
bt_gst_debug_pad_link_return (link_res, src_pad, dst_pad));
res = FALSE;
gst_element_release_request_pad (src, src_pad);
// TODO(ensonic): unblock the pad
}
} else {
GST_WARNING_OBJECT (src,
"Can't get request pad for src-peer of start of wire");
res = FALSE;
gst_element_release_request_pad (src, src_pad);
// TODO(ensonic): unblock the pad
}
} else {
GST_WARNING_OBJECT (src,
"Can't get request pad for src-peer of start of wire");
"Can't lookup pad-template 'src%d' for src-peer of start of wire");
res = FALSE;
}
} else {
Expand All @@ -558,16 +568,25 @@ link_wire (const BtSetup * const self, GstElement * wire)
src_pad = gst_element_get_static_pad (GST_ELEMENT (wire), "src");
GST_INFO_OBJECT (src_pad, "linking end of wire");
if (!(peer = gst_pad_get_peer (src_pad))) {
if ((dst_pad = gst_element_get_request_pad (GST_ELEMENT (dst), "sink%d"))) {
if (GST_PAD_LINK_FAILED (link_res = gst_pad_link (src_pad, dst_pad))) {
GST_WARNING ("Can't link end of wire : %s",
bt_gst_debug_pad_link_return (link_res, src_pad, dst_pad));
if ((tmpl =
gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS (dst),
"sink%d"))) {
if ((dst_pad =
gst_element_request_pad (GST_ELEMENT (dst), tmpl, NULL, NULL))) {
if (GST_PAD_LINK_FAILED (link_res = gst_pad_link (src_pad, dst_pad))) {
GST_WARNING ("Can't link end of wire : %s",
bt_gst_debug_pad_link_return (link_res, src_pad, dst_pad));
res = FALSE;
gst_element_release_request_pad (dst, dst_pad);
}
} else {
GST_WARNING_OBJECT (dst,
"Can't get request pad for sink-peer of end of wire");
res = FALSE;
gst_element_release_request_pad (dst, dst_pad);
}
} else {
GST_WARNING_OBJECT (dst,
"Can't get request pad for sink-peer of end of wire");
"Can't lookup pad-template 'sink%d' for sink-peer of end of wire");
res = FALSE;
}
} else {
Expand Down
27 changes: 18 additions & 9 deletions src/lib/core/sink-bin.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,8 @@ bt_sink_bin_get_recorder_elements (const BtSinkBin * const self)

// generate recorder profile and set encodebin accordingly
profile =
bt_sink_bin_create_recording_profile (&formats[self->priv->
record_format]);
bt_sink_bin_create_recording_profile (&formats[self->
priv->record_format]);
if (profile) {
element = gst_element_factory_make ("encodebin", "sink-encodebin");
GST_DEBUG_OBJECT (element, "set profile");
Expand Down Expand Up @@ -772,7 +772,13 @@ bt_sink_bin_update (const BtSinkBin * const self)
break;
}
case BT_SINK_BIN_MODE_PASS_THRU:{
GstPad *target_pad = gst_element_get_request_pad (tee, "src%d");
GstPadTemplate *tmpl =
gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS (tee),
"src%d");
GstPad *target_pad = gst_element_request_pad (tee, tmpl, NULL, NULL);
if (!target_pad) {
GST_WARNING_OBJECT (tee, "failed to get request 'src' request-pad");
}

self->priv->src = gst_ghost_pad_new ("src", target_pad);
gst_pad_set_active (self->priv->src, TRUE);
Expand All @@ -789,16 +795,19 @@ bt_sink_bin_update (const BtSinkBin * const self)
gst_element_get_static_pad (self->priv->caps_filter, "sink");
GstPad *req_sink_pad = NULL;

GST_INFO ("updating ghostpad: %p", self->priv->sink);
GST_INFO_OBJECT (self->priv->sink, "updating ghostpad: %p",
self->priv->sink);

if (!sink_pad) {
GST_INFO ("failed to get static 'sink' pad for element '%s'",
GST_OBJECT_NAME (self->priv->caps_filter));
GST_INFO_OBJECT (self->priv->caps_filter,
"failed to get static 'sink' pad");
GstElementClass *klass = GST_ELEMENT_GET_CLASS (self->priv->caps_filter);
sink_pad = req_sink_pad =
gst_element_get_request_pad (self->priv->caps_filter, "sink_%d");
gst_element_request_pad (self->priv->caps_filter,
gst_element_class_get_pad_template (klass, "sink_%d"), NULL, NULL);
if (!sink_pad) {
GST_INFO ("failed to get request 'sink' request-pad for element '%s'",
GST_OBJECT_NAME (self->priv->caps_filter));
GST_WARNING_OBJECT (self->priv->caps_filter,
"failed to get request 'sink' request-pad");
}
}
GST_INFO_OBJECT (self->priv->caps_filter,
Expand Down
31 changes: 30 additions & 1 deletion src/lib/core/tools.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,33 @@ bt_gst_registry_get_element_names_matching_all_categories (const gchar *
return (res);
}

/**
* bt_gst_element_factory_get_pad_template:
* @factory: element factory
* @name: name of the pad-template, e.g. "src" or "sink%d"
*
* Lookup a pad template by name.
*
* Returns: the pad template or %NULL if not found
*/
GstPadTemplate *
bt_gst_element_factory_get_pad_template (GstElementFactory * factory,
const gchar * name)
{
/* get pad templates */
const GList *list = gst_element_factory_get_static_pad_templates (factory);
for (; list; list = g_list_next (list)) {
GstStaticPadTemplate *t = (GstStaticPadTemplate *) list->data;

GST_INFO_OBJECT (factory, "Checking pad-template '%s'", t->name_template);
if (g_strcmp0 (t->name_template, name) == 0) {
return gst_static_pad_template_get (t);
}
}
GST_WARNING_OBJECT (factory, "No pad-template '%s'", name);
return NULL;
}

/**
* bt_gst_element_factory_can_sink_media_type:
* @factory: element factory to check
Expand Down Expand Up @@ -327,6 +354,7 @@ bt_bin_activate_tee_chain (GstBin * bin, GstElement * tee, GList * analyzers,
gboolean res = TRUE;
const GList *node;
GstElement *prev = NULL, *next;
GstElementClass *tee_class = GST_ELEMENT_GET_CLASS (tee);
GstPad *tee_src, *analyzer_sink;

g_return_val_if_fail (GST_IS_BIN (bin), FALSE);
Expand All @@ -353,7 +381,8 @@ bt_bin_activate_tee_chain (GstBin * bin, GstElement * tee, GList * analyzers,
prev = next;
}
GST_INFO_OBJECT (bin, "blocking tee.src");
tee_src = gst_element_get_request_pad (tee, "src%d");
tee_src = gst_element_request_pad (tee,
gst_element_class_get_pad_template (tee_class, "src%d"), NULL, NULL);
analyzer_sink =
gst_element_get_static_pad (GST_ELEMENT (analyzers->data), "sink");
if (is_playing)
Expand Down
2 changes: 2 additions & 0 deletions src/lib/core/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

GList *bt_gst_registry_get_element_factories_matching_all_categories(const gchar *class_filter);
GList *bt_gst_registry_get_element_names_matching_all_categories(const gchar *class_filter);

GstPadTemplate * bt_gst_element_factory_get_pad_template(GstElementFactory *factory, const gchar *name);
gboolean bt_gst_element_factory_can_sink_media_type(GstElementFactory *factory,const gchar *name);

GList *bt_gst_check_elements(GList *list);
Expand Down
Loading

0 comments on commit edeedf4

Please sign in to comment.