dashdemux: Add binary search for stream_sidx_seek

Add binary search to optimize in stream_sidx_seek.

https://bugzilla.gnome.org/show_bug.cgi?id=749653
This commit is contained in:
Jimmy Ohn 2015-07-29 22:31:30 +09:00 committed by Thiago Santos
parent ef84f294c0
commit 7093ad482b

View file

@ -313,8 +313,8 @@ gst_dash_demux_get_live_seek_range (GstAdaptiveDemux * demux, gint64 * start,
GstDashDemux *self = GST_DASH_DEMUX (demux); GstDashDemux *self = GST_DASH_DEMUX (demux);
GDateTime *now = gst_dash_demux_get_server_now_utc (self); GDateTime *now = gst_dash_demux_get_server_now_utc (self);
GDateTime *mstart = GDateTime *mstart =
gst_date_time_to_g_date_time (self->client-> gst_date_time_to_g_date_time (self->client->mpd_node->
mpd_node->availabilityStartTime); availabilityStartTime);
GTimeSpan stream_now; GTimeSpan stream_now;
stream_now = g_date_time_difference (now, mstart); stream_now = g_date_time_difference (now, mstart);
@ -611,9 +611,9 @@ gst_dash_demux_setup_all_streams (GstDashDemux * demux)
active_stream->cur_adapt_set->RepresentationBase && active_stream->cur_adapt_set->RepresentationBase &&
active_stream->cur_adapt_set->RepresentationBase->ContentProtection) { active_stream->cur_adapt_set->RepresentationBase->ContentProtection) {
GST_DEBUG_OBJECT (demux, "Adding ContentProtection events to source pad"); GST_DEBUG_OBJECT (demux, "Adding ContentProtection events to source pad");
g_list_foreach (active_stream->cur_adapt_set-> g_list_foreach (active_stream->cur_adapt_set->RepresentationBase->
RepresentationBase->ContentProtection, ContentProtection, gst_dash_demux_send_content_protection_event,
gst_dash_demux_send_content_protection_event, stream); stream);
} }
gst_isoff_sidx_parser_init (&stream->sidx_parser); gst_isoff_sidx_parser_init (&stream->sidx_parser);
@ -1039,24 +1039,43 @@ gst_dash_demux_stream_update_fragment_info (GstAdaptiveDemuxStream * stream)
return GST_FLOW_EOS; return GST_FLOW_EOS;
} }
static gint
gst_dash_demux_index_entry_search (GstSidxBoxEntry * entry, GstClockTime * ts,
gpointer user_data)
{
GstClockTime entry_ts = entry->pts + entry->duration;
if (entry_ts < *ts)
return -1;
else if (entry->pts > *ts)
return 1;
else
return 0;
}
static void static void
gst_dash_demux_stream_sidx_seek (GstDashDemuxStream * dashstream, gst_dash_demux_stream_sidx_seek (GstDashDemuxStream * dashstream,
GstClockTime ts) GstClockTime ts)
{ {
GstSidxBox *sidx = SIDX (dashstream); GstSidxBox *sidx = SIDX (dashstream);
gint i; GstSidxBoxEntry *entry;
gint idx = sidx->entries_count;
/* TODO optimize to a binary search */ /* check whether ts is already past the last element or not */
for (i = 0; i < sidx->entries_count; i++) { if (sidx->entries[idx - 1].pts + sidx->entries[idx - 1].duration < ts) {
if (sidx->entries[i].pts + sidx->entries[i].duration >= ts)
break;
}
sidx->entry_index = i;
dashstream->sidx_index = i;
if (i < sidx->entries_count)
dashstream->sidx_current_remaining = sidx->entries[i].size;
else
dashstream->sidx_current_remaining = 0; dashstream->sidx_current_remaining = 0;
} else {
entry =
gst_util_array_binary_search (sidx->entries, sidx->entries_count,
sizeof (GstSidxBoxEntry),
(GCompareDataFunc) gst_dash_demux_index_entry_search,
GST_SEARCH_MODE_BEFORE, &ts, NULL);
idx = entry - sidx->entries;
dashstream->sidx_current_remaining = sidx->entries[idx].size;
}
sidx->entry_index = idx;
dashstream->sidx_index = idx;
} }
static GstFlowReturn static GstFlowReturn