static GstBin * kms_agnostic_bin2_create_bin_for_caps (KmsAgnosticBin2 * self, GstCaps * caps) { GstBin *dec_bin; KmsEncTreeBin *enc_bin; GstElement *input_element, *output_tee; dec_bin = kms_agnostic_bin2_get_or_create_dec_bin (self, caps); if (dec_bin == NULL) { return NULL; } if (is_raw_caps (caps)) { return dec_bin; } enc_bin = kms_enc_tree_bin_new (caps, self->priv->default_bitrate); if (enc_bin == NULL) { return NULL; } gst_bin_add (GST_BIN (self), GST_ELEMENT (enc_bin)); gst_element_sync_state_with_parent (GST_ELEMENT (enc_bin)); output_tee = kms_tree_bin_get_output_tee (KMS_TREE_BIN (dec_bin)); input_element = kms_tree_bin_get_input_element (KMS_TREE_BIN (enc_bin)); link_element_to_tee (output_tee, input_element); kms_agnostic_bin2_insert_bin (self, GST_BIN (enc_bin)); return GST_BIN (enc_bin); }
static void kms_agnostic_bin2_link_to_tee (KmsAgnosticBin2 * self, GstPad * pad, GstElement * tee, GstCaps * caps) { GstElement *queue = gst_element_factory_make ("queue", NULL); GstPad *target; gst_bin_add (GST_BIN (self), queue); gst_element_sync_state_with_parent (queue); if (!gst_caps_is_any (caps) && is_raw_caps (caps)) { GstElement *convert = kms_utils_create_convert_for_caps (caps); GstElement *rate = kms_utils_create_rate_for_caps (caps); GstElement *mediator = kms_utils_create_mediator_element (caps); remove_element_on_unlinked (convert, "src", "sink"); remove_element_on_unlinked (rate, "src", "sink"); remove_element_on_unlinked (mediator, "src", "sink"); gst_bin_add_many (GST_BIN (self), convert, rate, mediator, NULL); gst_element_sync_state_with_parent (mediator); gst_element_sync_state_with_parent (convert); gst_element_sync_state_with_parent (rate); gst_element_link_many (queue, rate, convert, mediator, NULL); target = gst_element_get_static_pad (mediator, "src"); } else { target = gst_element_get_static_pad (queue, "src"); } gst_ghost_pad_set_target (GST_GHOST_PAD (pad), target); g_object_unref (target); link_element_to_tee (tee, queue); }
static GstBin * kms_agnostic_bin2_create_dec_bin (KmsAgnosticBin2 * self, const GstCaps * raw_caps) { KmsDecTreeBin *dec_bin; GstElement *output_tee, *input_element; GstCaps *caps = self->priv->input_bin_src_caps; if (caps == NULL || raw_caps == NULL) { return NULL; } dec_bin = kms_dec_tree_bin_new (caps, raw_caps); if (dec_bin == NULL) { return NULL; } gst_bin_add (GST_BIN (self), GST_ELEMENT (dec_bin)); gst_element_sync_state_with_parent (GST_ELEMENT (dec_bin)); output_tee = kms_tree_bin_get_output_tee (KMS_TREE_BIN (self->priv->input_bin)); input_element = kms_tree_bin_get_input_element (KMS_TREE_BIN (dec_bin)); link_element_to_tee (output_tee, input_element); return GST_BIN (dec_bin); }
static void kms_agnostic_bin2_link_to_tee (KmsAgnosticBin2 * self, GstPad * pad, GstElement * tee, GstCaps * caps) { GstElement *queue = gst_element_factory_make ("queue", NULL); GstPad *target; GstProxyPad *proxy; gst_bin_add (GST_BIN (self), queue); gst_element_sync_state_with_parent (queue); if (!(gst_caps_is_any (caps) || gst_caps_is_empty (caps)) && kms_utils_caps_are_raw (caps)) { GstElement *convert = kms_utils_create_convert_for_caps (caps); GstElement *rate = kms_utils_create_rate_for_caps (caps); GstElement *mediator = kms_utils_create_mediator_element (caps); remove_element_on_unlinked (convert, "src", "sink"); if (rate) { remove_element_on_unlinked (rate, "src", "sink"); } remove_element_on_unlinked (mediator, "src", "sink"); if (rate) { gst_bin_add (GST_BIN (self), rate); } gst_bin_add_many (GST_BIN (self), convert, mediator, NULL); gst_element_sync_state_with_parent (mediator); gst_element_sync_state_with_parent (convert); if (rate) { gst_element_sync_state_with_parent (rate); } if (rate) { gst_element_link_many (queue, rate, mediator, NULL); } else { gst_element_link (queue, mediator); } gst_element_link_many (mediator, convert, NULL); target = gst_element_get_static_pad (convert, "src"); } else { target = gst_element_get_static_pad (queue, "src"); } gst_ghost_pad_set_target (GST_GHOST_PAD (pad), target); proxy = gst_proxy_pad_get_internal (GST_PROXY_PAD (pad)); gst_pad_set_query_function (GST_PAD_CAST (proxy), proxy_src_pad_query_function); g_object_unref (proxy); g_object_unref (target); link_element_to_tee (tee, queue); }
static void kms_agnostic_bin2_configure_input (KmsAgnosticBin2 * self, const GstCaps * caps) { KmsParseTreeBin *parse_bin; GstElement *parser; GstPad *parser_src; GstElement *input_element; KMS_AGNOSTIC_BIN2_LOCK (self); if (self->priv->input_bin != NULL) { kms_tree_bin_unlink_input_element_from_tee (KMS_TREE_BIN (self-> priv->input_bin)); } parse_bin = kms_parse_tree_bin_new (caps); self->priv->input_bin = GST_BIN (parse_bin); parser = kms_parse_tree_bin_get_parser (KMS_PARSE_TREE_BIN (parse_bin)); parser_src = gst_element_get_static_pad (parser, "src"); gst_pad_add_probe (parser_src, GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM, input_bin_src_caps_probe, g_object_ref (parse_bin), g_object_unref); g_object_unref (parser_src); gst_bin_add (GST_BIN (self), GST_ELEMENT (parse_bin)); gst_element_sync_state_with_parent (GST_ELEMENT (parse_bin)); input_element = kms_tree_bin_get_input_element (KMS_TREE_BIN (parse_bin)); link_element_to_tee (self->priv->input_tee, input_element); self->priv->started = FALSE; GST_DEBUG ("Removing old treebins"); g_hash_table_foreach (self->priv->bins, remove_bin, self); g_hash_table_remove_all (self->priv->bins); KMS_AGNOSTIC_BIN2_UNLOCK (self); }