mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-28 03:00:35 +00:00
splitfilesrc: Implement binary search in find_part_for_offset
Implement binary search using gst_util_array_binary_search https://bugzilla.gnome.org/show_bug.cgi?id=749690
This commit is contained in:
parent
565cd49643
commit
d3997773fc
1 changed files with 24 additions and 11 deletions
|
@ -368,24 +368,37 @@ gst_split_file_src_stop (GstBaseSrc * basesrc)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static gint
|
||||
gst_split_file_src_part_search (GstFilePart * part, guint64 * offset,
|
||||
gpointer user_data)
|
||||
{
|
||||
if (*offset > part->stop)
|
||||
return -1; /* The target is after this part */
|
||||
else if (*offset < part->start)
|
||||
return 1; /* The target is before this part */
|
||||
else
|
||||
return 0; /* This is the target part */
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_split_file_src_find_part_for_offset (GstSplitFileSrc * src, guint64 offset,
|
||||
guint * part_number)
|
||||
{
|
||||
gboolean res = TRUE;
|
||||
GstFilePart *part;
|
||||
guint i;
|
||||
|
||||
/* TODO: could use gst_util_array_binary_search() here */
|
||||
part = src->parts;
|
||||
for (i = 0; i < src->num_parts; ++i) {
|
||||
if (offset >= part->start && offset <= part->stop) {
|
||||
*part_number = i;
|
||||
return TRUE;
|
||||
}
|
||||
++part;
|
||||
}
|
||||
part =
|
||||
gst_util_array_binary_search (src->parts, src->num_parts,
|
||||
sizeof (GstFilePart),
|
||||
(GCompareDataFunc) gst_split_file_src_part_search,
|
||||
GST_SEARCH_MODE_AFTER, &offset, NULL);
|
||||
|
||||
return FALSE;
|
||||
if (part)
|
||||
*part_number = part - src->parts;
|
||||
else
|
||||
res = FALSE;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static GstFlowReturn
|
||||
|
|
Loading…
Reference in a new issue