- if (GST_BUFFER_SIZE (typefind->store) < TYPE_FIND_MIN_SIZE) {
- GST_DEBUG_OBJECT (typefind, "not enough data for typefinding yet");
- return GST_FLOW_OK;
- }
-
- if (typefind->possibilities == NULL) {
- /* not yet started, get all typefinding functions into our "queue" */
- GList *all_factories = gst_type_find_factory_get_list ();
-
- GST_INFO_OBJECT (typefind, "starting with %u typefinding functions",
- g_list_length (all_factories));
-
- all_factories = g_list_sort (all_factories, compare_type_find_factory);
- walk = all_factories;
- while (walk) {
- entry = new_entry ();
-
- entry->factory = gst_object_ref (GST_TYPE_FIND_FACTORY (walk->data));
- entry->self = typefind;
- entry->probability = 0;
- typefind->possibilities =
- g_list_prepend (typefind->possibilities, entry);
- walk = g_list_next (walk);
- }
- gst_plugin_feature_list_free (all_factories);
- }
-
- /* call every typefind function once */
- walk = typefind->possibilities;
- GST_INFO_OBJECT (typefind, "iterating %u typefinding functions",
- g_list_length (walk));
- while (walk) {
- find.data = entry = (TypeFindEntry *) walk->data;
- if (entry->probability != 0) {
- /* Probability already known, just continue along the list */
- walk = g_list_next (walk);
- continue;
- }
-
- entry->requested_size = 0;
- gst_type_find_factory_call_function (entry->factory, &find);
-
- if (entry->probability == 0 && entry->requested_size == 0) {
- GList *next;
-
- GST_DEBUG_OBJECT (typefind,
- "'%s' was removed - no chance of being the right plugin",
- GST_PLUGIN_FEATURE_NAME (entry->factory));
- next = g_list_next (walk);
- free_entry (entry);
- typefind->possibilities =
- g_list_delete_link (typefind->possibilities, walk);
- walk = next;
- } else if (entry->probability >= typefind->max_probability) {
- /* wooha, got caps */
- GstCaps *found_caps = entry->caps;
- guint probability = entry->probability;
-
- GST_INFO_OBJECT (typefind,
- "'%s' returned %u/%u probability, using it NOW",
- GST_PLUGIN_FEATURE_NAME (entry->factory), probability,
- typefind->max_probability);
- g_signal_emit (typefind, gst_type_find_element_signals[HAVE_TYPE], 0,
- probability, found_caps);
-
- g_list_foreach (typefind->possibilities, (GFunc) free_entry, NULL);
- g_list_free (typefind->possibilities);
- typefind->possibilities = NULL;
- break;
- } else {
- walk = g_list_next (walk);
- if (entry->requested_size != 0)
- done = FALSE;
- }
- }
-
- /* we may now already have caps or we might be left without functions to try */
- if (typefind->caps) {
- stop_typefinding (typefind);
- } else if (typefind->possibilities == NULL) {
- if (GST_BUFFER_SIZE (typefind->store) > TYPE_FIND_MAX_SIZE) {
- GST_ELEMENT_ERROR (typefind, STREAM, TYPE_NOT_FOUND, (NULL), (NULL));
- stop_typefinding (typefind);
- return GST_FLOW_ERROR;
- } else {
- GST_DEBUG_OBJECT (typefind, "no type found with %u bytes - waiting "
- "for more data", GST_BUFFER_SIZE (typefind->store));
- return GST_FLOW_OK;
- }
- } else if (done) {
- TypeFindEntry *best;
-
- if ((best = gst_type_find_element_get_best_possibility (typefind))) {
- GST_INFO_OBJECT (typefind,
- "'%s' is the best typefind left, using it now (probability %u)",
- GST_PLUGIN_FEATURE_NAME (best->factory), best->probability);
- g_signal_emit (typefind, gst_type_find_element_signals[HAVE_TYPE],
- 0, best->probability, best->caps);
- g_list_foreach (typefind->possibilities, (GFunc) free_entry, NULL);
- g_list_free (typefind->possibilities);
- typefind->possibilities = NULL;
- stop_typefinding (typefind);
- } else {
- GST_ELEMENT_ERROR (typefind, STREAM, TYPE_NOT_FOUND, (NULL), (NULL));
- stop_typefinding (typefind);
- return GST_FLOW_ERROR;
- }
- }