discoverer: try harder to obtain a duration if we don't get one right away

If we don't get a duration right away, set the pipeline to playing
and sleep a bit, then try again. This is ugly, but the least worst
we can do right now. The alternative would be to make parsers etc.
return some bogus duration estimate even after only having pushed
a single frame, for example.

Fixes discoverer showing 0 durations for some mp3 and aac files
(e.g. soweto-adts.aac).
This commit is contained in:
Tim-Philipp Müller 2012-02-14 19:23:27 +00:00
parent e832929080
commit e40ea30972

View file

@ -1026,6 +1026,31 @@ discoverer_collect (GstDiscoverer * dc)
GST_DEBUG ("Got duration %" GST_TIME_FORMAT, GST_TIME_ARGS (dur));
dc->priv->current_info->duration = (guint64) dur;
}
} else {
GstStateChangeReturn sret;
/* Some parsers may not even return a rough estimate right away, e.g.
* because they've only processed a single frame so far, so if we
* didn't get a duration the first time, spin a bit and try again.
* Ugly, but still better than making parsers or other elements return
* completely bogus values. We need some API extensions to solve this
* better. */
GST_INFO ("No duration yet, try a bit harder..");
sret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
if (sret != GST_STATE_CHANGE_FAILURE) {
int i;
for (i = 0; i < 2; ++i) {
g_usleep (G_USEC_PER_SEC / 20);
if (gst_element_query_duration (pipeline, &format, &dur) &&
format == GST_FORMAT_TIME && dur > 0) {
GST_DEBUG ("Got duration %" GST_TIME_FORMAT, GST_TIME_ARGS (dur));
dc->priv->current_info->duration = (guint64) dur;
break;
}
}
gst_element_set_state (pipeline, GST_STATE_PAUSED);
}
}
if (dc->priv->seeking_query) {