From 4df5d896f096c6ab730ba8f7cb2e9af6ff412b03 Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Sun, 15 May 2011 23:25:15 +0300 Subject: [PATCH] matroskaparse: calculate segment duration after parsing all the IDs Since the segment duration is given in terms of the GST_MATROSKA_ID_TIMECODESCALE we should only convert it into nanoseconds when we are sure that any scale specified in the file has been read. https://bugzilla.gnome.org/show_bug.cgi?id=650258 --- gst/matroska/matroska-parse.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/gst/matroska/matroska-parse.c b/gst/matroska/matroska-parse.c index 24a95a9cc1..7d488494cf 100644 --- a/gst/matroska/matroska-parse.c +++ b/gst/matroska/matroska-parse.c @@ -2808,6 +2808,7 @@ static GstFlowReturn gst_matroska_parse_parse_info (GstMatroskaParse * parse, GstEbmlRead * ebml) { GstFlowReturn ret = GST_FLOW_OK; + gdouble dur_f = -1.0; guint32 id; DEBUG_ELEMENT_START (parse, ebml, "SegmentInfo"); @@ -2836,23 +2837,15 @@ gst_matroska_parse_parse_info (GstMatroskaParse * parse, GstEbmlRead * ebml) } case GST_MATROSKA_ID_DURATION:{ - gdouble num; - GstClockTime dur; - - if ((ret = gst_ebml_read_float (ebml, &id, &num)) != GST_FLOW_OK) + if ((ret = gst_ebml_read_float (ebml, &id, &dur_f)) != GST_FLOW_OK) break; - if (num <= 0.0) { - GST_WARNING_OBJECT (parse, "Invalid duration %lf", num); + if (dur_f <= 0.0) { + GST_WARNING_OBJECT (parse, "Invalid duration %lf", dur_f); break; } - GST_DEBUG_OBJECT (parse, "Duration: %lf", num); - - dur = gst_gdouble_to_guint64 (num * - gst_guint64_to_gdouble (parse->time_scale)); - if (GST_CLOCK_TIME_IS_VALID (dur) && dur <= G_MAXINT64) - gst_segment_set_duration (&parse->segment, GST_FORMAT_TIME, dur); + GST_DEBUG_OBJECT (parse, "Duration: %lf", dur_f); break; } @@ -2923,6 +2916,15 @@ gst_matroska_parse_parse_info (GstMatroskaParse * parse, GstEbmlRead * ebml) } } + if (dur_f > 0.0) { + GstClockTime dur_u; + + dur_u = gst_gdouble_to_guint64 (dur_f * + gst_guint64_to_gdouble (parse->time_scale)); + if (GST_CLOCK_TIME_IS_VALID (dur_u) && dur_u <= G_MAXINT64) + gst_segment_set_duration (&parse->segment, GST_FORMAT_TIME, dur_u); + } + DEBUG_ELEMENT_STOP (parse, ebml, "SegmentInfo", ret); parse->segmentinfo_parsed = TRUE;