qtdemux: compute framerate from average sample duration
authorMatej Knopp <matej.knopp@gmail.com>
Sun, 30 Jun 2013 19:01:20 +0000 (21:01 +0200)
committerSebastian Dröge <slomo@circular-chaos.org>
Mon, 1 Jul 2013 10:53:17 +0000 (12:53 +0200)
https://bugzilla.gnome.org/show_bug.cgi?id=703350

gst/isomp4/Makefile.am
gst/isomp4/qtdemux.c

index 3e806f9583ae3eef2cc4c0e1924d668d1d0fec41..09887126af547dfaa17ca05145cf9c988967ba11 100644 (file)
@@ -10,7 +10,7 @@ libgstisomp4_la_LIBADD = \
     -lgstrtp-@GST_API_VERSION@ \
     -lgsttag-@GST_API_VERSION@ \
     -lgstpbutils-@GST_API_VERSION@ \
-    $(GST_BASE_LIBS) $(GST_LIBS) $(ZLIB_LIBS)
+    $(GST_BASE_LIBS) $(GST_LIBS) $(ZLIB_LIBS) $(LIBM)
 libgstisomp4_la_LDFLAGS = ${GST_PLUGIN_LDFLAGS}
 libgstisomp4_la_SOURCES = isomp4-plugin.c gstrtpxqtdepay.c \
        qtdemux.c qtdemux_types.c qtdemux_dump.c qtdemux_lang.c \
index ff84f00e155283245f3f8e2880191f2c49439145..55d04eac49c06744cdbcc227ff01123c0ae902aa 100644 (file)
@@ -70,6 +70,9 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <math.h>
+#include <gst/math-compat.h>
+
 #ifdef HAVE_ZLIB
 # include <zlib.h>
 #endif
@@ -5528,11 +5531,19 @@ gst_qtdemux_configure_stream (GstQTDemux * qtdemux, QtDemuxStream * stream)
       stream->fps_n = 0;
       stream->fps_d = 1;
     } else {
-      stream->fps_n = stream->timescale;
-      if (stream->min_duration == 0)
-        stream->fps_d = 1;
+      /* we might need to scale the timescale to get precise framerate */
+      const int required_scale = rint (log (10000) / 2.303);    /* divide to get log10 */
+      int current_scale = rint (log (stream->timescale) / 2.303);
+      int factor = pow (10.0, MAX (0, required_scale - current_scale));
+
+      stream->fps_n = stream->timescale * factor;
+
+      if (stream->duration == 0)
+        stream->fps_d = factor;
       else
-        stream->fps_d = stream->min_duration;
+        stream->fps_d =
+            gst_util_uint64_scale_int_round (factor, stream->duration,
+            stream->n_samples);
     }
 
     if (stream->caps) {