From cea403eaa59d707787b89e25b1ba1e79ffb29c71 Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Mon, 29 Jul 2013 08:14:57 +0200 Subject: [PATCH] mpegdefs: Simplify PCR/PTS/DTS => GST conversion macros We know we will not overflow 64 bits, therefore just use direct multiplication/division instead of the scale method (trims usage from 50 instruction calls to 2/3). --- gst/mpegtsdemux/gstmpegdefs.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/gst/mpegtsdemux/gstmpegdefs.h b/gst/mpegtsdemux/gstmpegdefs.h index 4f636d900e..6f8ebfdf3d 100644 --- a/gst/mpegtsdemux/gstmpegdefs.h +++ b/gst/mpegtsdemux/gstmpegdefs.h @@ -83,10 +83,16 @@ #define CLOCK_BASE 9LL #define CLOCK_FREQ (CLOCK_BASE * 10000) -#define PCRTIME_TO_GSTTIME(time) (gst_util_uint64_scale ((time), \ - GST_MSECOND/10, 300 * CLOCK_BASE)) -#define MPEGTIME_TO_GSTTIME(time) (gst_util_uint64_scale ((time), \ - GST_MSECOND/10, CLOCK_BASE)) +/* PCR_TO_GST calculation requires at least 10 extra bits. + * Since maximum PCR value is coded with 42 bits, we are + * safe to use direct calculation (10+42 < 63)*/ +#define PCRTIME_TO_GSTTIME(t) ((t) * 1000 / 27) + +/* MPEG_TO_GST calculation requires at least 17 extra bits (100000) + * Since maximum PTS/DTS value is coded with 33bits, we are + * safe to use direct calculation (17+33 < 63) */ +#define MPEGTIME_TO_GSTTIME(t) ((t) * 100000 / 9) + #define GSTTIME_TO_MPEGTIME(time) (gst_util_uint64_scale ((time), \ CLOCK_BASE, GST_MSECOND/10)) #define GSTTIME_TO_PCRTIME(time) (gst_util_uint64_scale ((time), \