typefindhelper: Use the new GstTypeFind * API

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3296>
This commit is contained in:
Sanchayan Maity 2022-10-31 19:09:06 +05:30 committed by GStreamer Marge Bot
parent 89da632219
commit 30841dae99

View File

@ -726,29 +726,19 @@ gst_type_find_helper_for_data_with_caps (GstObject * obj,
const guint8 * data, gsize size, GstCaps * caps, const guint8 * data, gsize size, GstCaps * caps,
GstTypeFindProbability * prob) GstTypeFindProbability * prob)
{ {
GstTypeFind find; GstTypeFind *find;
GstTypeFindBufHelper helper; GstTypeFindData *find_data;
GstTypeFindFactory *factory;
GList *l, *factories = NULL; GList *l, *factories = NULL;
GstCaps *result = NULL; GstCaps *result = NULL;
GstTypeFindProbability last_found_probability = GST_TYPE_FIND_NONE; GstTypeFindProbability found_probability, last_found_probability;
g_return_val_if_fail (data != NULL, NULL); g_return_val_if_fail (data != NULL, NULL);
g_return_val_if_fail (caps != NULL, NULL); g_return_val_if_fail (caps != NULL, NULL);
g_return_val_if_fail (size != 0, NULL); g_return_val_if_fail (size != 0, NULL);
helper.data = data; find_data = gst_type_find_data_new (obj, data, size);
helper.size = size; find = gst_type_find_data_get_typefind (find_data);
helper.best_probability = GST_TYPE_FIND_NONE;
helper.caps = NULL;
helper.obj = obj;
if (helper.data == NULL || helper.size == 0)
return NULL;
find.data = &helper;
find.peek = buf_helper_find_peek;
find.suggest = buf_helper_find_suggest;
find.get_length = NULL;
factories = gst_type_find_list_factories_for_caps (obj, caps); factories = gst_type_find_list_factories_for_caps (obj, caps);
if (!factories) { if (!factories) {
@ -757,13 +747,20 @@ gst_type_find_helper_for_data_with_caps (GstObject * obj,
goto out; goto out;
} }
for (l = factories; l; l = l->next) { found_probability = GST_TYPE_FIND_NONE;
helper.factory = GST_TYPE_FIND_FACTORY (l->data); last_found_probability = GST_TYPE_FIND_NONE;
gst_type_find_factory_call_function (helper.factory, &find);
for (l = factories; l; l = l->next) {
factory = GST_TYPE_FIND_FACTORY (l->data);
gst_type_find_factory_call_function (factory, find);
found_probability = gst_type_find_data_get_probability (find_data);
if (found_probability > last_found_probability) {
last_found_probability = found_probability;
result = gst_type_find_data_get_caps (find_data);
if (helper.best_probability > last_found_probability) {
last_found_probability = helper.best_probability;
result = helper.caps;
GST_DEBUG_OBJECT (obj, "Found %" GST_PTR_FORMAT " (probability = %u)", GST_DEBUG_OBJECT (obj, "Found %" GST_PTR_FORMAT " (probability = %u)",
result, (guint) last_found_probability); result, (guint) last_found_probability);
if (last_found_probability >= GST_TYPE_FIND_MAXIMUM) if (last_found_probability >= GST_TYPE_FIND_MAXIMUM)
@ -775,11 +772,13 @@ gst_type_find_helper_for_data_with_caps (GstObject * obj,
*prob = last_found_probability; *prob = last_found_probability;
GST_LOG_OBJECT (obj, "Returning %" GST_PTR_FORMAT " (probability = %u)", GST_LOG_OBJECT (obj, "Returning %" GST_PTR_FORMAT " (probability = %u)",
result, (guint) helper.best_probability); result, (guint) last_found_probability);
out: out:
g_list_free_full (factories, (GDestroyNotify) gst_object_unref); g_list_free_full (factories, (GDestroyNotify) gst_object_unref);
gst_type_find_data_free (find_data);
return result; return result;
} }