baseparse: minor code simplification

Use gst_pad_peer_query_duration() and remove a few
unnecessary levels of indentation. Rest of code might
looks a bit questionable, but leave it as is for now.
This commit is contained in:
Tim-Philipp Müller 2015-08-15 16:39:40 +01:00
parent 1176fbf6dc
commit bc1fb2d8b0

View file

@ -1543,41 +1543,30 @@ no_duration_bytes:
} }
static void static void
gst_base_parse_update_duration (GstBaseParse * baseparse) gst_base_parse_update_duration (GstBaseParse * parse)
{ {
GstPad *peer; gint64 ptot, dest_value;
GstBaseParse *parse;
parse = GST_BASE_PARSE (baseparse); if (!gst_pad_peer_query_duration (parse->sinkpad, GST_FORMAT_BYTES, &ptot))
return;
peer = gst_pad_get_peer (parse->sinkpad); if (!gst_base_parse_convert (parse, GST_FORMAT_BYTES, ptot,
if (peer) { GST_FORMAT_TIME, &dest_value))
gboolean qres = FALSE; return;
gint64 ptot, dest_value;
qres = gst_pad_query_duration (peer, GST_FORMAT_BYTES, &ptot); /* inform if duration changed, but try to avoid spamming */
gst_object_unref (GST_OBJECT (peer)); parse->priv->estimated_drift += dest_value - parse->priv->estimated_duration;
if (qres) {
if (gst_base_parse_convert (parse, GST_FORMAT_BYTES, ptot,
GST_FORMAT_TIME, &dest_value)) {
/* inform if duration changed, but try to avoid spamming */ parse->priv->estimated_duration = dest_value;
parse->priv->estimated_drift += GST_LOG_OBJECT (parse,
dest_value - parse->priv->estimated_duration; "updated estimated duration to %" GST_TIME_FORMAT,
GST_TIME_ARGS (dest_value));
parse->priv->estimated_duration = dest_value; if (parse->priv->estimated_drift > GST_SECOND ||
GST_LOG_OBJECT (parse, parse->priv->estimated_drift < -GST_SECOND) {
"updated estimated duration to %" GST_TIME_FORMAT, gst_element_post_message (GST_ELEMENT (parse),
GST_TIME_ARGS (dest_value)); gst_message_new_duration_changed (GST_OBJECT (parse)));
parse->priv->estimated_drift = 0;
if (parse->priv->estimated_drift > GST_SECOND ||
parse->priv->estimated_drift < -GST_SECOND) {
gst_element_post_message (GST_ELEMENT (parse),
gst_message_new_duration_changed (GST_OBJECT (parse)));
parse->priv->estimated_drift = 0;
}
}
}
} }
} }