From: Jaeyun Date: Fri, 21 May 2021 08:11:24 +0000 (+0900) Subject: [Flex/Common] util functions to handle pad caps X-Git-Tag: accepted/tizen/unified/20210604.120706~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9d0284e398bf9789413a861da9718cbc9af83503;p=platform%2Fupstream%2Fnnstreamer.git [Flex/Common] util functions to handle pad caps add util fucntions to handle pad caps and move these to internal header. Signed-off-by: Jaeyun --- diff --git a/gst/nnstreamer/include/nnstreamer_plugin_api.h b/gst/nnstreamer/include/nnstreamer_plugin_api.h index e2e7b67..ec03102 100644 --- a/gst/nnstreamer/include/nnstreamer_plugin_api.h +++ b/gst/nnstreamer/include/nnstreamer_plugin_api.h @@ -385,16 +385,6 @@ extern const gchar * gst_tensor_get_type_string (tensor_type type); /** - * @brief Get tensors caps from tensors config and caps of the peer connected to the pad - * @param pad GstPad to check peer caps - * @param config tensors config structure - * @return caps for given config and pad. Caller is responsible for unreffing the returned caps. - */ -extern GstCaps * -gst_tensors_get_pad_caps (GstPad * pad, const GstTensorsConfig * config); - - -/** * @brief set alignment that default allocator would align to * @param alignment bytes of alignment */ diff --git a/gst/nnstreamer/nnstreamer_internal.h b/gst/nnstreamer/nnstreamer_internal.h index ec34acc..46dc084 100644 --- a/gst/nnstreamer/nnstreamer_internal.h +++ b/gst/nnstreamer/nnstreamer_internal.h @@ -77,5 +77,22 @@ gst_tensor_filter_detect_framework (const gchar * const *model_files, const guin extern gboolean gst_tensor_filter_check_hw_availability (const gchar * name, const accl_hw hw); +/** + * @brief Get pad caps from tensor config and caps of the peer connected to the pad. + * @param pad GstPad to get possible caps + * @param config tensors config structure + * @return caps for given config. Caller is responsible for unreffing the returned caps. + */ +extern GstCaps * +gst_tensor_pad_caps_from_config (GstPad * pad, const GstTensorsConfig * config); + +/** + * @brief Check current pad caps is flexible tensor. + * @param pad GstPad to check current caps + * @return TRUE if pad has flexible tensor caps. + */ +extern gboolean +gst_tensor_pad_caps_is_flexible (GstPad * pad); + G_END_DECLS #endif /* __NNSTREAMER_INTERNAL_H__ */ diff --git a/gst/nnstreamer/tensor_common.c b/gst/nnstreamer/tensor_common.c index 11c3e22..3b6c4e4 100644 --- a/gst/nnstreamer/tensor_common.c +++ b/gst/nnstreamer/tensor_common.c @@ -1015,14 +1015,10 @@ _peer_has_tensor_caps (GstPad * pad) peer_caps = gst_pad_peer_query_caps (pad, NULL); if (peer_caps) { GstCaps *caps = gst_caps_from_string (GST_TENSOR_CAP_DEFAULT); - GstCaps *intersection = - gst_caps_intersect_full (caps, peer_caps, GST_CAPS_INTERSECT_FIRST); - if (!gst_caps_is_empty (intersection)) - ret = TRUE; + ret = gst_caps_can_intersect (caps, peer_caps); gst_caps_unref (caps); - gst_caps_unref (intersection); gst_caps_unref (peer_caps); } @@ -1049,20 +1045,26 @@ _peer_is_flexible_tensor_caps (GstPad * pad) } /** - * @brief Get tensors caps from tensors config and caps of the peer connected to the pad - * @param pad GstPad to check peer caps + * @brief Get pad caps from tensor config and caps of the peer connected to the pad. + * @param pad GstPad to get possible caps * @param config tensors config structure - * @return caps for given config and pad. Caller is responsible for unreffing the returned caps. + * @return caps for given config. Caller is responsible for unreffing the returned caps. + * @note This function is included in nnstreamer internal header for native APIs. + * When changing the declaration, you should update the internal header (nnstreamer_internal.h). */ GstCaps * -gst_tensors_get_pad_caps (GstPad * pad, const GstTensorsConfig * config) +gst_tensor_pad_caps_from_config (GstPad * pad, const GstTensorsConfig * config) { GstCaps *caps = NULL; + GstCaps *templ; gboolean is_flexible; g_return_val_if_fail (GST_IS_PAD (pad), NULL); g_return_val_if_fail (config != NULL, NULL); + templ = gst_pad_get_pad_template_caps (pad); + + /* other/tensors-flexible */ is_flexible = gst_tensors_info_is_flexible (&config->info); /* check peer element is flexible */ @@ -1076,22 +1078,69 @@ gst_tensors_get_pad_caps (GstPad * pad, const GstTensorsConfig * config) gst_caps_set_simple (caps, "framerate", GST_TYPE_FRACTION, config->rate_n, config->rate_d, NULL); } - } else if (config->info.num_tensors == 1 && _peer_has_tensor_caps (pad)) { - GstTensorConfig tensor_config; - gst_tensor_config_init (&tensor_config); - tensor_config.info = config->info.info[0]; - tensor_config.rate_n = config->rate_n; - tensor_config.rate_d = config->rate_d; + goto intersectable; + } - caps = gst_tensor_caps_from_config (&tensor_config); - } else { - caps = gst_tensors_caps_from_config (config); + /* other/tensor */ + if (config->info.num_tensors == 1 && _peer_has_tensor_caps (pad)) { + GstTensorConfig c; + + gst_tensor_config_init (&c); + c.info = config->info.info[0]; + c.rate_n = config->rate_n; + c.rate_d = config->rate_d; + + caps = gst_tensor_caps_from_config (&c); + if (gst_caps_can_intersect (caps, templ)) + goto done; + + gst_caps_unref (caps); } + + /* other/tensors */ + caps = gst_tensors_caps_from_config (config); + +intersectable: + if (!gst_caps_can_intersect (caps, templ)) { + gst_caps_unref (caps); + caps = NULL; + } + +done: + gst_caps_unref (templ); return caps; } /** + * @brief Check current pad caps is flexible tensor. + * @param pad GstPad to check current caps + * @return TRUE if pad has flexible tensor caps. + * @note This function is included in nnstreamer internal header for native APIs. + * When changing the declaration, you should update the internal header (nnstreamer_internal.h). + */ +gboolean +gst_tensor_pad_caps_is_flexible (GstPad * pad) +{ + GstCaps *caps; + gboolean ret = FALSE; + + g_return_val_if_fail (GST_IS_PAD (pad), FALSE); + + caps = gst_pad_get_current_caps (pad); + if (caps) { + GstStructure *structure = gst_caps_get_structure (caps, 0); + const gchar *name = gst_structure_get_name (structure); + + if (name) + ret = g_str_equal (name, NNS_MIMETYPE_TENSORS_FLEXIBLE); + gst_caps_unref (caps); + } + + return ret; +} + +/** * @brief Get caps from tensors config (for other/tensors) * @param config tensors config info * @return caps for given config @@ -1277,6 +1326,8 @@ gst_tensor_get_element_count (const tensor_dim dim) gsize gst_tensor_get_element_size (tensor_type type) { + g_return_val_if_fail (type >= 0 && type <= _NNS_END, 0); + return tensor_element_size[type]; } @@ -1363,6 +1414,8 @@ gst_tensor_get_type (const gchar * typestr) const gchar * gst_tensor_get_type_string (tensor_type type) { + g_return_val_if_fail (type >= 0 && type <= _NNS_END, NULL); + return tensor_element_typename[type]; } diff --git a/gst/nnstreamer/tensor_common.h b/gst/nnstreamer/tensor_common.h index ca6ecc1..2f7d98f 100644 --- a/gst/nnstreamer/tensor_common.h +++ b/gst/nnstreamer/tensor_common.h @@ -163,5 +163,26 @@ gst_tensor_time_sync_flush (GstCollectPads * collect); extern gboolean gst_tensor_time_sync_buffer_from_collectpad (GstCollectPads * collect, tensor_time_sync_data * sync, GstClockTime current_time, GstBuffer * tensors_buf, GstTensorsConfig * configs, gboolean * is_eos); +/** + * @brief Get pad caps from tensor config and caps of the peer connected to the pad. + * @param pad GstPad to get possible caps + * @param config tensors config structure + * @return caps for given config. Caller is responsible for unreffing the returned caps. + * @note This function is included in nnstreamer internal header for native APIs. + * When changing the declaration, you should update the internal header (nnstreamer_internal.h). + */ +extern GstCaps * +gst_tensor_pad_caps_from_config (GstPad * pad, const GstTensorsConfig * config); + +/** + * @brief Check current pad caps is flexible tensor. + * @param pad GstPad to check current caps + * @return TRUE if pad has flexible tensor caps. + * @note This function is included in nnstreamer internal header for native APIs. + * When changing the declaration, you should update the internal header (nnstreamer_internal.h). + */ +extern gboolean +gst_tensor_pad_caps_is_flexible (GstPad * pad); + G_END_DECLS #endif /* __GST_TENSOR_COMMON_H__ */ diff --git a/gst/nnstreamer/tensor_converter/tensor_converter.c b/gst/nnstreamer/tensor_converter/tensor_converter.c index eec60b1..4b02a8c 100644 --- a/gst/nnstreamer/tensor_converter/tensor_converter.c +++ b/gst/nnstreamer/tensor_converter/tensor_converter.c @@ -1966,7 +1966,7 @@ gst_tensor_converter_update_caps (GstTensorConverter * self) GstCaps *curr_caps, *out_caps; config = &self->tensors_config; - out_caps = gst_tensors_get_pad_caps (self->srcpad, config); + out_caps = gst_tensor_pad_caps_from_config (self->srcpad, config); /* Update src pad caps if it is different. */ curr_caps = gst_pad_get_current_caps (self->srcpad); diff --git a/gst/nnstreamer/tensor_demux/gsttensordemux.c b/gst/nnstreamer/tensor_demux/gsttensordemux.c index 921d0f2..e557cc8 100644 --- a/gst/nnstreamer/tensor_demux/gsttensordemux.c +++ b/gst/nnstreamer/tensor_demux/gsttensordemux.c @@ -410,7 +410,7 @@ gst_tensor_demux_get_tensor_pad (GstTensorDemux * tensor_demux, /* configure nth pad caps */ if (gst_tensor_demux_get_tensor_config (tensor_demux, &config, nth, total)) { - caps = gst_tensors_get_pad_caps (pad, &config); + caps = gst_tensor_pad_caps_from_config (pad, &config); gst_pad_set_caps (pad, caps); gst_caps_unref (caps); diff --git a/gst/nnstreamer/tensor_if/gsttensorif.c b/gst/nnstreamer/tensor_if/gsttensorif.c index f4eb7b6..93c9670 100644 --- a/gst/nnstreamer/tensor_if/gsttensorif.c +++ b/gst/nnstreamer/tensor_if/gsttensorif.c @@ -732,7 +732,7 @@ gst_tensor_if_get_tensor_pad (GstTensorIf * tensor_if, gst_pad_set_active (pad, TRUE); gst_element_add_pad (GST_ELEMENT_CAST (tensor_if), pad); - caps = gst_tensors_get_pad_caps (pad, config); + caps = gst_tensor_pad_caps_from_config (pad, config); silent_debug_caps (caps, "out caps"); gst_pad_set_caps (pad, caps); diff --git a/gst/nnstreamer/tensor_mux/gsttensormux.c b/gst/nnstreamer/tensor_mux/gsttensormux.c index 8193a14..2c248c8 100644 --- a/gst/nnstreamer/tensor_mux/gsttensormux.c +++ b/gst/nnstreamer/tensor_mux/gsttensormux.c @@ -401,7 +401,8 @@ gst_tensor_mux_set_src_caps (GstTensorMux * tensor_mux) GstCaps *caps; if (gst_tensors_config_validate (&tensor_mux->tensors_config)) { - caps = gst_tensors_caps_from_config (&tensor_mux->tensors_config); + caps = gst_tensor_pad_caps_from_config (tensor_mux->srcpad, + &tensor_mux->tensors_config); if (gst_pad_set_caps (tensor_mux->srcpad, caps)) { tensor_mux->negotiated = TRUE;