static gboolean mx_gst_pad_is_compatible(MxGstGraphElementPad *src, MxGstGraphElementPad *dest) { GstCaps *src_caps = gst_pad_get_caps(src->priv->pad); GstCaps *dest_caps = gst_pad_get_caps(dest->priv->pad); if( (GST_PAD_SRC != gst_pad_get_direction(src->priv->pad)) || (GST_PAD_SINK != gst_pad_get_direction(dest->priv->pad)) ) { return FALSE; } if(gst_caps_is_any(src_caps) || gst_caps_is_any(dest_caps)) { return TRUE; } if(gst_caps_is_empty(src_caps) || gst_caps_is_empty(dest_caps)) { return FALSE; } return !gst_caps_is_empty(gst_caps_intersect(src_caps, dest_caps)); }
static void gst_test_element_class_init (GstTestElementClass * klass) { GstElementClass *element_class = GST_ELEMENT_CLASS (klass); GstPadTemplate *templ; gst_element_class_set_metadata (element_class, "Test element", "Element", "Does nothing", "Foo Bar <*****@*****.**>"); fail_unless_equals_int (g_list_length (gst_element_class_get_pad_template_list (element_class)), 0); fail_unless (gst_element_class_get_pad_template (element_class, "test") == NULL); gst_element_class_add_pad_template (element_class, gst_pad_template_new ("test", GST_PAD_SRC, GST_PAD_ALWAYS, GST_CAPS_ANY)); fail_unless_equals_int (g_list_length (gst_element_class_get_pad_template_list (element_class)), 1); fail_unless ((templ = gst_element_class_get_pad_template (element_class, "test")) != NULL); fail_unless (gst_caps_is_any (templ->caps)); gst_element_class_add_pad_template (element_class, gst_pad_template_new ("test2", GST_PAD_SRC, GST_PAD_ALWAYS, GST_CAPS_ANY)); fail_unless_equals_int (g_list_length (gst_element_class_get_pad_template_list (element_class)), 2); fail_unless ((templ = gst_element_class_get_pad_template (element_class, "test2")) != NULL); fail_unless (gst_caps_is_any (templ->caps)); /* Add "test" again, with NONE caps this time */ gst_element_class_add_pad_template (element_class, gst_pad_template_new ("test", GST_PAD_SRC, GST_PAD_ALWAYS, GST_CAPS_NONE)); fail_unless_equals_int (g_list_length (gst_element_class_get_pad_template_list (element_class)), 2); fail_unless ((templ = gst_element_class_get_pad_template (element_class, "test")) != NULL); fail_unless (gst_caps_is_empty (templ->caps)); }
static gboolean srcpad_can_dmabuf (GstMsdkDec * thiz) { gboolean ret = FALSE; GstCaps *caps, *out_caps; GstPad *srcpad; srcpad = GST_VIDEO_DECODER_SRC_PAD (thiz); caps = gst_pad_get_pad_template_caps (srcpad); out_caps = gst_pad_peer_query_caps (srcpad, caps); if (!out_caps) goto done; if (gst_caps_is_any (out_caps) || gst_caps_is_empty (out_caps) || out_caps == caps) goto done; if (_gst_caps_has_feature (out_caps, GST_CAPS_FEATURE_MEMORY_DMABUF)) ret = TRUE; done: if (caps) gst_caps_unref (caps); if (out_caps) gst_caps_unref (out_caps); return ret; }
static GstCaps * gst_speex_enc_sink_getcaps (GstPad * pad) { GstCaps *caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad)); GstCaps *peercaps = NULL; GstSpeexEnc *enc = GST_SPEEX_ENC (gst_pad_get_parent_element (pad)); peercaps = gst_pad_peer_get_caps (enc->srcpad); if (peercaps) { if (!gst_caps_is_empty (peercaps) && !gst_caps_is_any (peercaps)) { GstStructure *ps = gst_caps_get_structure (peercaps, 0); GstStructure *s = gst_caps_get_structure (caps, 0); gint rate, channels; if (gst_structure_get_int (ps, "rate", &rate)) { gst_structure_fixate_field_nearest_int (s, "rate", rate); } if (gst_structure_get_int (ps, "channels", &channels)) { gst_structure_fixate_field_nearest_int (s, "channels", channels); } } gst_caps_unref (peercaps); } gst_object_unref (enc); return caps; }
static gboolean missing_structure_get_caps_detail (const GstStructure * s, GstCaps ** p_caps) { const GstCaps *caps; const GValue *val; GType detail_type; *p_caps = NULL; detail_type = gst_structure_get_field_type (s, "detail"); if (!g_type_is_a (detail_type, GST_TYPE_CAPS)) { GST_WARNING ("expected 'detail' field to be of GST_TYPE_CAPS"); return FALSE; } val = gst_structure_get_value (s, "detail"); caps = gst_value_get_caps (val); if (gst_caps_is_empty (caps) || gst_caps_is_any (caps)) { GST_WARNING ("EMPTY or ANY caps not allowed"); return FALSE; } *p_caps = gst_caps_copy (caps); return TRUE; }
int iterate_plugins_elements (GstElementFactory *factory, GHashTable *hashtable) { GstElement *element; const GList *pads; GstStaticPadTemplate *padtemplate; const GstCaps * caps; int i; factory = GST_ELEMENT_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE (factory))); if (!factory) { g_error ("element plugin couldn't be loaded"); return -1; } element = gst_element_factory_create (factory, NULL); if (!element) { g_error ("couldn't construct element for some reason"); return -1; } if (factory->numpadtemplates) { pads = factory->staticpadtemplates; while (pads) { padtemplate = (GstStaticPadTemplate *) (pads->data); pads = g_list_next (pads); if (padtemplate->direction == GST_PAD_SINK && padtemplate->presence == GST_PAD_ALWAYS && padtemplate->static_caps.string) { caps = gst_static_caps_get (&padtemplate->static_caps); if (caps != NULL && !gst_caps_is_any (caps) && !gst_caps_is_empty (caps)) { for (i = 0; i < gst_caps_get_size (caps); i++) { GstStructure *structure = gst_caps_get_structure (caps, i); const gchar *mime = gst_structure_get_name (structure); if (g_str_has_prefix (mime, "audio")) { g_hash_table_insert(hashtable, (gpointer)mime, (gpointer)&ONE); } } } } } } gst_object_unref (element); gst_object_unref (factory); return 0; }
static void print_caps (const GstCaps * caps, const gchar * pfx) { guint i; g_return_if_fail (caps != NULL); if (gst_caps_is_any (caps)) { n_print ("%sANY\n", pfx); return; } if (gst_caps_is_empty (caps)) { n_print ("%sEMPTY\n", pfx); return; } for (i = 0; i < gst_caps_get_size (caps); i++) { GstStructure *structure = gst_caps_get_structure (caps, i); GstCapsFeatures *features = gst_caps_get_features (caps, i); if (features && (gst_caps_features_is_any (features) || !gst_caps_features_is_equal (features, GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY))) { gchar *features_string = gst_caps_features_to_string (features); n_print ("%s%s(%s)\n", pfx, gst_structure_get_name (structure), features_string); g_free (features_string); } else { n_print ("%s%s\n", pfx, gst_structure_get_name (structure)); } gst_structure_foreach (structure, print_field, (gpointer) pfx); } }
/** * gst_missing_encoder_message_new: * @element: the #GstElement posting the message * @encode_caps: the (fixed) caps for which an encoder element is needed * * Creates a missing-plugin message for @element to notify the application * that an encoder element for a particular set of (fixed) caps is missing. * This function is mainly for use in plugins. * * Returns: (transfer full): a new #GstMessage, or NULL on error */ GstMessage * gst_missing_encoder_message_new (GstElement * element, const GstCaps * encode_caps) { GstStructure *s; GstCaps *caps; gchar *description; g_return_val_if_fail (element != NULL, NULL); g_return_val_if_fail (GST_IS_ELEMENT (element), NULL); g_return_val_if_fail (encode_caps != NULL, NULL); g_return_val_if_fail (GST_IS_CAPS (encode_caps), NULL); g_return_val_if_fail (!gst_caps_is_any (encode_caps), NULL); g_return_val_if_fail (!gst_caps_is_empty (encode_caps), NULL); g_return_val_if_fail (gst_caps_is_fixed (encode_caps), NULL); description = gst_pb_utils_get_encoder_description (encode_caps); caps = copy_and_clean_caps (encode_caps); s = gst_structure_new ("missing-plugin", "type", G_TYPE_STRING, "encoder", "detail", GST_TYPE_CAPS, caps, "name", G_TYPE_STRING, description, NULL); gst_caps_unref (caps); g_free (description); return gst_message_new_element (GST_OBJECT_CAST (element), s); }
bool tcam_gst_fixate_caps (GstCaps* caps) { if (caps == nullptr || gst_caps_is_empty(caps) || gst_caps_is_any(caps)) { return FALSE; } GstStructure* structure = gst_caps_get_structure(caps, 0); if (gst_structure_has_field(structure, "width")) { gst_structure_fixate_field_nearest_int(structure, "width", G_MAXINT); } if (gst_structure_has_field(structure, "height")) { gst_structure_fixate_field_nearest_int(structure, "height", G_MAXINT); } if (gst_structure_has_field(structure, "framerate")) { gst_structure_fixate_field_nearest_fraction(structure, "framerate", G_MAXINT, 1); } return TRUE; }
gint main (gint argc, gchar ** argv) { GstCaps *caps; GstElement *sink, *identity; GstElement *pipeline; gst_init (&argc, &argv); pipeline = gst_pipeline_new ("pipeline"); g_assert (pipeline); identity = gst_element_factory_make ("identity", NULL); g_assert (identity); sink = gst_element_factory_make ("fakesink", NULL); g_assert (sink); gst_bin_add_many (GST_BIN (pipeline), identity, sink, NULL); gst_element_link_filtered (identity, sink, gst_caps_new_simple ("audio/x-raw-int", NULL)); caps = gst_pad_get_caps (gst_element_get_pad (identity, "sink")); g_print ("caps: %s\n", gst_caps_to_string (caps)); g_assert (!gst_caps_is_any (caps)); caps = gst_pad_get_allowed_caps (gst_element_get_pad (identity, "sink")); g_print ("allowed caps: %s\n", gst_caps_to_string (caps)); /* get_allowed_caps doesn't mean anything if you aren't connected */ g_assert (!caps); return 0; }
static gboolean gst_type_find_element_setcaps (GstPad * pad, GstCaps * caps) { GstTypeFindElement *typefind; typefind = GST_TYPE_FIND_ELEMENT (GST_PAD_PARENT (pad)); /* don't operate on ANY caps */ if (gst_caps_is_any (caps)) return TRUE; g_signal_emit (typefind, gst_type_find_element_signals[HAVE_TYPE], 0, GST_TYPE_FIND_MAXIMUM, caps); /* Shortcircuit typefinding if we get caps */ if (typefind->mode == MODE_TYPEFIND) { GST_DEBUG_OBJECT (typefind, "Skipping typefinding, using caps from " "upstream buffer: %" GST_PTR_FORMAT, caps); typefind->mode = MODE_NORMAL; gst_type_find_element_send_cached_events (typefind); if (typefind->store) { GST_DEBUG_OBJECT (typefind, "Pushing store: %d", GST_BUFFER_SIZE (typefind->store)); gst_buffer_set_caps (typefind->store, typefind->caps); gst_pad_push (typefind->src, typefind->store); typefind->store = NULL; } } return TRUE; }
/* Based on gstbasetextoverlay.c */ static GstCaps * gst_overlay_composition_src_query_caps (GstOverlayComposition * self, GstCaps * filter) { GstCaps *peer_caps = NULL, *caps = NULL, *overlay_filter = NULL; if (filter) { /* duplicate filter caps which contains the composition into one version * with the meta and one without. Filter the other caps by the software * caps */ GstCaps *sw_caps = gst_static_caps_get (&overlay_composition_caps); overlay_filter = intersect_by_feature (filter, GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION, sw_caps); gst_caps_unref (sw_caps); } peer_caps = gst_pad_peer_query_caps (self->sinkpad, overlay_filter); if (overlay_filter) gst_caps_unref (overlay_filter); if (peer_caps) { GST_DEBUG_OBJECT (self->srcpad, "peer caps %" GST_PTR_FORMAT, peer_caps); if (gst_caps_is_any (peer_caps)) { /* if peer returns ANY caps, return filtered sink pad template caps */ caps = gst_caps_copy (gst_pad_get_pad_template_caps (self->sinkpad)); } else { /* return upstream caps + composition feature + upstream caps * filtered by the software caps. */ GstCaps *sw_caps = gst_static_caps_get (&overlay_composition_caps); caps = add_feature_and_intersect (peer_caps, GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION, sw_caps); gst_caps_unref (sw_caps); } gst_caps_unref (peer_caps); } else { /* no peer, our padtemplate is enough then */ caps = gst_pad_get_pad_template_caps (self->srcpad); } if (filter) { GstCaps *intersection; intersection = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST); gst_caps_unref (caps); caps = intersection; } GST_DEBUG_OBJECT (self->srcpad, "returning %" GST_PTR_FORMAT, caps); return caps; }
static GstBin * kms_agnostic_bin2_get_or_create_dec_bin (KmsAgnosticBin2 * self, GstCaps * caps) { GstCaps *raw_caps; if (kms_utils_caps_are_raw (self->priv->input_caps) || gst_caps_is_empty (caps) || gst_caps_is_any (caps)) { return self->priv->input_bin; } raw_caps = kms_agnostic_bin2_get_raw_caps (caps); if (raw_caps != NULL) { GstBin *dec_bin; GST_DEBUG ("Raw caps: %" GST_PTR_FORMAT, raw_caps); dec_bin = kms_agnostic_bin2_find_bin_for_caps (self, raw_caps); if (dec_bin == NULL) { dec_bin = kms_agnostic_bin2_create_dec_bin (self, raw_caps); if (dec_bin != NULL) { kms_agnostic_bin2_insert_bin (self, dec_bin); } } gst_caps_unref (raw_caps); return dec_bin; } else { GST_ELEMENT_WARNING (self, CORE, NEGOTIATION, ("Formats are not compatible"), ("Formats are not compatible")); return NULL; } }
static GstBin * kms_agnostic_bin2_find_bin_for_caps (KmsAgnosticBin2 * self, GstCaps * caps) { GList *bins, *l; GstBin *bin = NULL; if (gst_caps_is_any (caps) || gst_caps_is_empty (caps)) { return self->priv->input_bin; } if (check_bin (KMS_TREE_BIN (self->priv->input_bin), caps)) { bin = self->priv->input_bin; } bins = g_hash_table_get_values (self->priv->bins); for (l = bins; l != NULL && bin == NULL; l = l->next) { KmsTreeBin *tree_bin = KMS_TREE_BIN (l->data); if (check_bin (tree_bin, caps)) { bin = GST_BIN_CAST (tree_bin); } } g_list_free (bins); return 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 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 gboolean gst_droid_cam_src_vfsrc_setcaps (GstPad * pad, GstCaps * caps) { GstDroidCamSrc *src = GST_DROID_CAM_SRC (GST_OBJECT_PARENT (pad)); GstDroidCamSrcClass *klass = GST_DROID_CAM_SRC_GET_CLASS (src); int width, height; int fps_n, fps_d; int fps; GST_DEBUG_OBJECT (src, "vfsrc setcaps %" GST_PTR_FORMAT, caps); if (!caps || gst_caps_is_empty (caps) || gst_caps_is_any (caps)) { /* We are happy. */ return TRUE; } if (!gst_video_format_parse_caps (caps, NULL, &width, &height)) { GST_ELEMENT_ERROR (src, STREAM, FORMAT, ("Failed to parse caps"), (NULL)); return FALSE; } if (!gst_video_parse_caps_framerate (caps, &fps_n, &fps_d)) { GST_ELEMENT_ERROR (src, STREAM, FORMAT, ("Failed to parse caps framerate"), (NULL)); return FALSE; } if (width == 0 || height == 0) { GST_ELEMENT_ERROR (src, STREAM, FORMAT, ("Invalid dimensions"), (NULL)); return FALSE; } fps = fps_n / fps_d; GST_OBJECT_LOCK (src); camera_params_set_viewfinder_size (src->camera_params, width, height); camera_params_set_viewfinder_fps (src->camera_params, fps); GST_OBJECT_UNLOCK (src); if (klass->set_camera_params (src)) { /* buffer pool needs to know about FPS */ GST_CAMERA_BUFFER_POOL_LOCK (src->pool); /* TODO: Make sure we are not overwriting a previous value. */ src->pool->buffer_duration = gst_util_uint64_scale_int (GST_SECOND, fps_d, fps_n); src->pool->fps_n = fps_n; src->pool->fps_d = fps_d; GST_CAMERA_BUFFER_POOL_UNLOCK (src->pool); return TRUE; } return FALSE; }
static void gst_test_element2_class_init (GstTestElement2Class * klass) { GstElementClass *element_class = GST_ELEMENT_CLASS (klass); GstPadTemplate *templ; gst_element_class_set_metadata (element_class, "Test element 2", "Element", "Does nothing", "Foo Bar <*****@*****.**>"); fail_unless_equals_int (g_list_length (gst_element_class_get_pad_template_list (element_class)), 2); fail_unless ((templ = gst_element_class_get_pad_template (element_class, "test")) != NULL); fail_unless (gst_caps_is_empty (templ->caps)); fail_unless ((templ = gst_element_class_get_pad_template (element_class, "test2")) != NULL); fail_unless (gst_caps_is_any (templ->caps)); /* Add "test" pad with ANY caps, should have "test" pad with EMPTY caps before */ gst_element_class_add_pad_template (element_class, gst_pad_template_new ("test", GST_PAD_SRC, GST_PAD_ALWAYS, GST_CAPS_ANY)); fail_unless_equals_int (g_list_length (gst_element_class_get_pad_template_list (element_class)), 2); fail_unless ((templ = gst_element_class_get_pad_template (element_class, "test")) != NULL); fail_unless (gst_caps_is_any (templ->caps)); gst_element_class_add_pad_template (element_class, gst_pad_template_new ("test4", GST_PAD_SRC, GST_PAD_ALWAYS, GST_CAPS_ANY)); fail_unless_equals_int (g_list_length (gst_element_class_get_pad_template_list (element_class)), 3); fail_unless ((templ = gst_element_class_get_pad_template (element_class, "test4")) != NULL); fail_unless (gst_caps_is_any (templ->caps)); }
void test_merge_fundamental() { GstCaps *c1, *c2; //xmlfile = "test_merge_fundamental"; std_log(LOG_FILENAME_LINE, "Test Started test_merge_fundamental"); /* ANY + specific = ANY */ c1 = gst_caps_from_string ("audio/x-raw-int,rate=44100"); c2 = gst_caps_new_any (); gst_caps_merge (c2, c1); GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2); fail_unless (gst_caps_get_size (c2) == 0, NULL); fail_unless (gst_caps_is_any (c2), NULL); gst_caps_unref (c2); /* specific + ANY = ANY */ c2 = gst_caps_from_string ("audio/x-raw-int,rate=44100"); c1 = gst_caps_new_any (); gst_caps_merge (c2, c1); GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2); fail_unless (gst_caps_get_size (c2) == 0, NULL); fail_unless (gst_caps_is_any (c2), NULL); gst_caps_unref (c2); /* EMPTY + specific = specific */ c1 = gst_caps_from_string ("audio/x-raw-int,rate=44100"); c2 = gst_caps_new_empty (); gst_caps_merge (c2, c1); GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2); fail_unless (gst_caps_get_size (c2) == 1, NULL); fail_if (gst_caps_is_empty (c2), NULL); gst_caps_unref (c2); /* specific + EMPTY = specific */ c2 = gst_caps_from_string ("audio/x-raw-int,rate=44100"); c1 = gst_caps_new_empty (); gst_caps_merge (c2, c1); GST_DEBUG ("merged: (%d) %" GST_PTR_FORMAT, gst_caps_get_size (c2), c2); fail_unless (gst_caps_get_size (c2) == 1, NULL); fail_if (gst_caps_is_empty (c2), NULL); gst_caps_unref (c2); std_log(LOG_FILENAME_LINE, "Test Successful"); create_xml(0); }
static GString * _print_caps(GstCaps *caps, gboolean full) { GString *caps_str = g_string_new("Caps: "); if (gst_caps_is_any (caps)) { g_string_append_printf(caps_str, "ANY\n"); } else if (gst_caps_is_empty (caps)) { g_string_append_printf(caps_str, "EMPTY\n"); } else { g_string_append_printf(caps_str, "\n"); int i=0; if(!full) { GList *caps_names = NULL; for (i = 0; i < gst_caps_get_size (caps); i++) { GstStructure *structure = gst_caps_get_structure (caps, i); gchar *cap_name = (gchar *)gst_structure_get_name(structure); if(NULL == g_list_find_custom(caps_names, cap_name, (GCompareFunc)g_strcmp0)) { caps_names = g_list_prepend(caps_names, cap_name); } } caps_names = g_list_reverse(caps_names); while(NULL != caps_names) { gchar *name = (gchar *)caps_names->data; caps_names = g_list_delete_link(caps_names, caps_names); g_string_append_printf(caps_str, "%s\n", name); } } else { for (i = 0; i < gst_caps_get_size (caps); i++) { GstStructure *structure = gst_caps_get_structure (caps, i); g_string_append_printf(caps_str, "%s\n", gst_structure_get_name (structure)); gst_structure_foreach (structure, _caps_print_field, (gpointer) caps_str); } } } caps_str = g_string_truncate(caps_str, caps_str->len-1); return caps_str; }
static GstCaps * mulawenc_getcaps (GstPad * pad) { GstMuLawEnc *mulawenc; GstPad *otherpad; GstCaps *base_caps, *othercaps; mulawenc = GST_MULAWENC (GST_PAD_PARENT (pad)); base_caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad)); if (pad == mulawenc->srcpad) { otherpad = mulawenc->sinkpad; } else { otherpad = mulawenc->srcpad; } othercaps = gst_pad_peer_get_caps (otherpad); if (othercaps) { GstStructure *structure; const GValue *orate, *ochans; const GValue *rate, *chans; GValue irate = { 0 }, ichans = { 0}; if (gst_caps_is_empty (othercaps) || gst_caps_is_any (othercaps)) goto done; structure = gst_caps_get_structure (othercaps, 0); orate = gst_structure_get_value (structure, "rate"); ochans = gst_structure_get_value (structure, "channels"); if (!orate || !ochans) goto done; structure = gst_caps_get_structure (base_caps, 0); rate = gst_structure_get_value (structure, "rate"); chans = gst_structure_get_value (structure, "channels"); if (!rate || !chans) goto done; gst_value_intersect (&irate, orate, rate); gst_value_intersect (&ichans, ochans, chans); /* Set the samplerate/channels on the to-be-returned caps */ structure = gst_caps_get_structure (base_caps, 0); gst_structure_set_value (structure, "rate", &irate); gst_structure_set_value (structure, "channels", &ichans); done: gst_caps_unref (othercaps); } return base_caps; }
static gchar * debug_dump_describe_caps (GstCaps * caps, GstDebugGraphDetails details) { gchar *media = NULL; if (details & GST_DEBUG_GRAPH_SHOW_CAPS_DETAILS) { if (gst_caps_is_any (caps) || gst_caps_is_empty (caps)) { media = gst_caps_to_string (caps); } else { GString *str = NULL; guint i; guint slen = 0; for (i = 0; i < gst_caps_get_size (caps); i++) { slen += 25 + STRUCTURE_ESTIMATED_STRING_LEN (gst_caps_get_structure (caps, i)); } str = g_string_sized_new (slen); for (i = 0; i < gst_caps_get_size (caps); i++) { GstCapsFeatures *features = __gst_caps_get_features_unchecked (caps, i); GstStructure *structure = gst_caps_get_structure (caps, i); g_string_append (str, gst_structure_get_name (structure)); if (features && (gst_caps_features_is_any (features) || !gst_caps_features_is_equal (features, GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY))) { g_string_append_c (str, '('); priv_gst_caps_features_append_to_gstring (features, str); g_string_append_c (str, ')'); } g_string_append (str, "\\l"); gst_structure_foreach (structure, string_append_field, (gpointer) str); } media = g_string_free (str, FALSE); } } else { if (GST_CAPS_IS_SIMPLE (caps)) media = g_strdup (gst_structure_get_name (gst_caps_get_structure (caps, 0))); else media = g_strdup ("*"); } return media; }
static void rc_tag_gst_new_decoded_pad_cb(GstElement *decodebin, GstPad *pad, gboolean last, RCTagDecodedPadData *data) { GstCaps *caps; GstStructure *structure; const gchar *mimetype; gboolean cancel = FALSE; GstPad *sink_pad; caps = gst_pad_get_caps(pad); /* we get "ANY" caps for text/plain files etc. */ if(gst_caps_is_empty(caps) || gst_caps_is_any(caps)) { rc_debug_module_print(module_name, "Decoded pad with no caps or " "any caps. This file is boring."); cancel = TRUE; data->non_audio_flag = TRUE; } else { sink_pad = gst_element_get_static_pad(data->fakesink, "sink"); gst_pad_link(pad, sink_pad); gst_object_unref(sink_pad); /* Is this pad audio? */ structure = gst_caps_get_structure(caps, 0); mimetype = gst_structure_get_name(structure); if(g_str_has_prefix(mimetype, "audio/x-raw")) { rc_debug_module_print(module_name, "Got decoded audio pad of type %s", mimetype); data->audio_flag = TRUE; } else if(g_str_has_prefix(mimetype, "video/")) { rc_debug_module_print(module_name, "Got decoded video pad of type %s", mimetype); data->video_flag = TRUE; } else { rc_debug_module_print(module_name, "Got decoded pad of non-audio type %s", mimetype); data->non_audio_flag = TRUE; } } gst_caps_unref(caps); /* If this is non-audio, cancel the operation. * This seems to cause some deadlocks with video files, so only do it * when we get no/any caps. */ if(cancel) gst_element_set_state(data->pipeline, GST_STATE_NULL); }
/* check if caps are found on given element */ static gboolean check_caps_compatibility (GstElementFactory *factory, GstCaps *caps, GstCaps **matched_caps) { const GList *pads; GstStaticPadTemplate *padtemplate; GstCaps *padtemplate_caps = NULL; if (!factory->numpadtemplates) { return FALSE; } pads = factory->staticpadtemplates; while (pads) { padtemplate = (GstStaticPadTemplate *) (pads->data); pads = g_list_next (pads); padtemplate_caps = gst_static_caps_get (&padtemplate->static_caps); if (gst_caps_is_any (padtemplate_caps)) { goto next; } if (caps) { GstCaps *intersection = gst_caps_intersect (padtemplate_caps, caps); gboolean have_intersection = !gst_caps_is_empty (intersection); if (have_intersection) { *matched_caps = intersection; gst_caps_unref (padtemplate_caps); return TRUE; } gst_caps_unref (intersection); } next: if (padtemplate_caps) { gst_caps_unref (padtemplate_caps); } } *matched_caps = NULL; return FALSE; }
void ly_mdh_new_with_uri_pipe_cb (GstElement *decodebin,GstPad *pad, gboolean last, gpointer data) { static GstCaps *caps; static GstPad *sink_pad; caps = gst_pad_get_caps(pad); if(!(gst_caps_is_empty(caps) || gst_caps_is_any(caps))) { sink_pad = gst_element_get_static_pad(GST_ELEMENT(data), "sink"); gst_pad_link(pad, sink_pad); gst_object_unref(sink_pad); } gst_caps_unref (caps); }
static GstCaps * handler (GObject * object, GstCaps * caps, gpointer user_data) { g_print ("in handler %p, %p, %p\n", object, caps, user_data); g_assert (GST_IS_PAD (object)); g_print ("caps: %s\n", gst_caps_to_string (caps)); if (gst_caps_is_any (caps)) { return gst_caps_new_simple ("application/x-foo", "field", GST_TYPE_INT_RANGE, 1, 10, NULL); } return NULL; }
static GstCaps * gst_jpegenc_getcaps (GstPad * pad) { GstJpegEnc *jpegenc = GST_JPEGENC (gst_pad_get_parent (pad)); GstCaps *caps, *othercaps; const GstCaps *templ; gint i, j; GstStructure *structure = NULL; /* we want to proxy properties like width, height and framerate from the other end of the element */ othercaps = gst_pad_get_allowed_caps (jpegenc->srcpad); if (othercaps == NULL || gst_caps_is_empty (othercaps) || gst_caps_is_any (othercaps)) { caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad)); goto done; } caps = gst_caps_new_empty (); templ = gst_pad_get_pad_template_caps (pad); for (i = 0; i < gst_caps_get_size (templ); i++) { /* pick fields from peer caps */ for (j = 0; j < gst_caps_get_size (othercaps); j++) { GstStructure *s = gst_caps_get_structure (othercaps, j); const GValue *val; structure = gst_structure_copy (gst_caps_get_structure (templ, i)); if ((val = gst_structure_get_value (s, "width"))) gst_structure_set_value (structure, "width", val); if ((val = gst_structure_get_value (s, "height"))) gst_structure_set_value (structure, "height", val); if ((val = gst_structure_get_value (s, "framerate"))) gst_structure_set_value (structure, "framerate", val); gst_caps_merge_structure (caps, structure); } } done: gst_caps_replace (&othercaps, NULL); gst_object_unref (jpegenc); return caps; }
static gboolean gst_type_find_element_setcaps (GstTypeFindElement * typefind, GstCaps * caps) { /* don't operate on ANY caps */ if (gst_caps_is_any (caps)) return TRUE; gst_type_find_element_emit_have_type (typefind, GST_TYPE_FIND_MAXIMUM, caps); /* Shortcircuit typefinding if we get caps */ GST_DEBUG_OBJECT (typefind, "Skipping typefinding, using caps from " "upstream: %" GST_PTR_FORMAT, caps); stop_typefinding (typefind); return TRUE; }
/** * gst_encoding_profile_get_input_caps: * @profile: a #GstEncodingProfile * * Computes the full output caps that this @profile will be able to consume. * * Returns: (transfer full): The full caps the given @profile can consume. Call * gst_caps_unref() when you are done with the caps. */ GstCaps * gst_encoding_profile_get_input_caps (GstEncodingProfile * profile) { GstCaps *out, *tmp; GList *ltmp; GstStructure *st, *outst; GQuark out_name; guint i, len; GstCaps *fcaps; g_return_val_if_fail (GST_IS_ENCODING_PROFILE (profile), NULL); if (GST_IS_ENCODING_CONTAINER_PROFILE (profile)) { GstCaps *res = gst_caps_new_empty (); for (ltmp = GST_ENCODING_CONTAINER_PROFILE (profile)->encodingprofiles; ltmp; ltmp = ltmp->next) { GstEncodingProfile *sprof = (GstEncodingProfile *) ltmp->data; res = gst_caps_merge (res, gst_encoding_profile_get_input_caps (sprof)); } return res; } fcaps = profile->format; /* fast-path */ if ((profile->restriction == NULL) || gst_caps_is_any (profile->restriction)) return gst_caps_ref (fcaps); /* Combine the format with the restriction caps */ outst = gst_caps_get_structure (fcaps, 0); out_name = gst_structure_get_name_id (outst); tmp = gst_caps_new_empty (); len = gst_caps_get_size (profile->restriction); for (i = 0; i < len; i++) { st = gst_structure_copy (gst_caps_get_structure (profile->restriction, i)); st->name = out_name; gst_caps_append_structure (tmp, st); } out = gst_caps_intersect (tmp, fcaps); gst_caps_unref (tmp); return out; }
static GstCaps * gst_video_rate_divider_transform_caps (GstBaseTransform * trans, GstPadDirection direction, GstCaps * caps) { GstVideoRateDivider *videorate = GST_VIDEO_RATE_DIVIDER (trans); GstCaps *ret; GstStructure *s, *s2; gint rate_numerator, rate_denominator; ret = gst_caps_copy (caps); /* Any caps simply return */ if (gst_caps_is_any (caps)) { GST_DEBUG_OBJECT (trans, "transform caps: %" GST_PTR_FORMAT " (direction = %s) ANY", caps, get_direction_name(direction)); return ret; } s = gst_caps_get_structure (ret, 0); gst_structure_get_fraction (s, "framerate", &rate_numerator, &rate_denominator); GST_DEBUG_OBJECT (trans, "transform caps: %" GST_PTR_FORMAT " (direction = %s framerate = %d/%d)", caps, get_direction_name(direction), rate_numerator, rate_denominator); s2 = gst_structure_copy (s); if (direction == GST_PAD_SINK) { /* correct input flow framerate */ /* store inpute framerate */ videorate->from_rate_numerator = rate_numerator; videorate->from_rate_denominator = rate_denominator; gst_caps_remove_structure (ret, 0); gst_structure_set (s2, "framerate", GST_TYPE_FRACTION, rate_numerator, rate_denominator * videorate->factor, NULL); gst_caps_merge_structure (ret, s2); } return ret; }