+static int __ms_node_set_pad_format(media_streamer_node_s *node, const char *pad_name, media_format_h fmt)
+{
+ gboolean can_accept = FALSE;
+ GstElement *element = NULL;
+ GstCaps *fmt_caps = NULL;
+ GstElementFactory *factory = NULL;
+ GstPad *node_pad = NULL;
+
+ ms_retvm_if(!node, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL");
+ ms_retvm_if(!node->gst_element, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "gst_element is NULL");
+ ms_retvm_if(!pad_name, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "pad_name is NULL");
+ ms_retvm_if(!fmt, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "fmt is NULL");
+
+ element = node->gst_element;
+
+ fmt_caps = ms_create_caps_from_fmt(fmt, nodes_info[node->type].default_name);
+ ms_retvm_if(!fmt_caps, MEDIA_STREAMER_ERROR_INVALID_OPERATION, "Can't convert fmt into Caps");
+
+ factory = gst_element_get_factory(element);
+ node_pad = gst_element_get_static_pad(element, pad_name);
+ if (!node_pad) {
+ gst_caps_unref(fmt_caps);
+ ms_error("Failed to gst_element_get_static_pad(), pad_name[%s]", pad_name);
+ return MEDIA_STREAMER_ERROR_INVALID_OPERATION;
+ }
+
+ if (GST_PAD_IS_SRC(node_pad))
+ can_accept = gst_element_factory_can_src_any_caps(factory, fmt_caps);
+ else if (GST_PAD_IS_SINK(node_pad))
+ can_accept = gst_element_factory_can_sink_any_caps(factory, fmt_caps);
+ else
+ ms_error("[%s] doesn`t have valid pad [%s]", GST_ELEMENT_NAME(element), pad_name);
+
+ MS_SAFE_UNREF(node_pad);
+
+ if (!can_accept) {
+ gst_caps_unref(fmt_caps);
+ ms_error("[%s]'s pad [%s] can`t be set with the given format", GST_ELEMENT_NAME(element), pad_name);
+ return MEDIA_STREAMER_ERROR_INVALID_OPERATION;
+ }
+
+ MS_SET_INT_CAPS_PARAM(element, pad_name, fmt_caps);
+ gst_caps_unref(fmt_caps);
+
+ ms_info("[%s]'s pad [%s] was set with given format", GST_ELEMENT_NAME(element), pad_name);
+
+ return MEDIA_STREAMER_ERROR_NONE;
+}
+