After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 679695 - toc: improvement gst_toc_find_entry()
toc: improvement gst_toc_find_entry()
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gstreamer (core)
git master
Other Linux
: Normal normal
: 0.11.x
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2012-07-10 16:51 UTC by Anton Belka
Modified: 2012-07-11 14:11 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
[PATCH] toc: improvement gst_toc_find_entry() (2.02 KB, patch)
2012-07-10 16:51 UTC, Anton Belka
committed Details | Review

Description Anton Belka 2012-07-10 16:51:50 UTC
Created attachment 218446 [details] [review]
[PATCH] toc: improvement gst_toc_find_entry()

Previously gst_toc_find_entry () returns the top-level entry. I think this bad, because impossible found needed entry on second, third, etc levels. Now, this function returns the entry with the UID on different levels, because the search recursively. I'm bad at English, but I hope that you understand my idea. If patch will be commited, please fix commit message (reason above). Many thanks.
Comment 1 Anton Belka 2012-07-10 16:55:16 UTC
Comment on attachment 218446 [details] [review]
[PATCH] toc: improvement gst_toc_find_entry()

From 471917e6f2f0435f2a712b94e7fd5b1efd0d7587 Mon Sep 17 00:00:00 2001
From: Anton Belka <antonbelka@gmail.com>
Date: Tue, 10 Jul 2012 18:15:20 +0300
Subject: [PATCH] toc: improvement gst_toc_find_entry()

Recursive search for the required entry. Instead of return top-level entry, return entry with needed UID.
---
 gst/gsttoc.c |   31 +++++++++++++++++++++----------
 1 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/gst/gsttoc.c b/gst/gsttoc.c
index c1e713a..95accc3 100644
--- a/gst/gsttoc.c
+++ b/gst/gsttoc.c
@@ -298,25 +298,29 @@ gst_toc_entry_free (GstTocEntry * entry)
   g_slice_free (GstTocEntry, entry);
 }
 
-static gboolean
-gst_toc_check_entry_for_uid (const GstTocEntry * entry, const gchar * uid)
+static GstTocEntry *
+gst_toc_check_subentries_for_uid (const GstTocEntry * entry, const gchar * uid)
 {
   GList *cur;
+  GstTocEntry *subentry, *tmp;
 
   g_return_val_if_fail (entry != NULL, FALSE);
   g_return_val_if_fail (uid != NULL, FALSE);
 
-  if (g_strcmp0 (entry->uid, uid) == 0)
-    return TRUE;
-
   cur = entry->subentries;
   while (cur != NULL) {
-    if (gst_toc_check_entry_for_uid (cur->data, uid))
-      return TRUE;
+    subentry = cur->data;
+    if (g_strcmp0 (subentry->uid, uid) == 0) {
+      return subentry;
+    } else {
+      tmp = gst_toc_check_subentries_for_uid (subentry, uid);
+      if (tmp != NULL)
+        return tmp;
+    }
     cur = cur->next;
   }
 
-  return FALSE;
+  return NULL;
 }
 
 /**
@@ -334,14 +338,21 @@ GstTocEntry *
 gst_toc_find_entry (const GstToc * toc, const gchar * uid)
 {
   GList *cur;
+  GstTocEntry *entry, *subentry;
 
   g_return_val_if_fail (toc != NULL, NULL);
   g_return_val_if_fail (uid != NULL, NULL);
 
   cur = toc->entries;
   while (cur != NULL) {
-    if (gst_toc_check_entry_for_uid (cur->data, uid))
-      return cur->data;
+    entry = cur->data;
+    if (g_strcmp0 (entry->uid, uid) == 0) {
+      return entry;
+    } else {
+      subentry = gst_toc_check_subentries_for_uid (entry, uid);
+      if (subentry != NULL)
+        return subentry;
+    }
     cur = cur->next;
   }
 
-- 
1.7.4.1
Comment 2 Anton Belka 2012-07-10 16:57:19 UTC
Right patch in second comment. Sorry.
P.S. I will check all before sending patches. :)
Comment 3 Sebastian Dröge (slomo) 2012-07-11 10:36:47 UTC
Please attach instead of pasting into a comment in the future.

Author: Anton Belka <antonbelka@gmail.com>
Date:   Tue Jul 10 18:15:20 2012 +0300

    toc: Fix gst_toc_find_entry()
    
    Recursive search for the required entry, instead of returning the
    top-level entry that contains an entry with the search UID.
Comment 4 Anton Belka 2012-07-11 14:11:36 UTC
Sebastian, thanks for commit and fix. :)