]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Use a simpler, but sufficient, timescaler
authorAndreas Öman <andreas@lonelycoder.com>
Thu, 24 Jun 2010 06:43:26 +0000 (06:43 +0000)
committerAndreas Öman <andreas@lonelycoder.com>
Thu, 24 Jun 2010 06:43:26 +0000 (06:43 +0000)
src/dvr/mkmux.c
src/htsp.c
src/tvhead.h
src/utils.c

index 94f5931c3509e155990acbddd6f1a7abea464438..8234e479bb336c163e8473b391bfeebd11b92948 100644 (file)
@@ -36,10 +36,6 @@ TAILQ_HEAD(mk_cue_queue, mk_cue);
 #define MATROSKA_TIMESCALE 1000000 // in nS
 
 
-static const Rational mpeg_tc = {1, 90000};
-static const Rational mkv_tc  = {1, 1000};
-static const Rational ns_tc  = {1, 1000000000};
-
 /**
  *
  */
@@ -237,7 +233,7 @@ mk_build_tracks(mk_mux_t *mkm, const struct streaming_start *ss)
     }
 
     if(ssc->ssc_frameduration) {
-      int d = rescale_q(ssc->ssc_frameduration, mpeg_tc, ns_tc);
+      int d = ts_rescale(ssc->ssc_frameduration, 1000000000);
       ebml_append_uint(t, 0x23e383, d);
     }
     
@@ -580,8 +576,8 @@ mk_write_frame_i(mk_mux_t *mkm, mk_track *t, th_pkt_t *pkt)
   if(pts != PTS_UNSET) {
     t->nextpts = pts + (pkt->pkt_duration >> pkt->pkt_field);
        
-    nxt = rescale_q(t->nextpts, mpeg_tc, mkv_tc);
-    pts = rescale_q(pts,        mpeg_tc, mkv_tc);
+    nxt = ts_rescale(t->nextpts, 1000000000 / MATROSKA_TIMESCALE);
+    pts = ts_rescale(pts,        1000000000 / MATROSKA_TIMESCALE);
 
     if(mkm->totduration < nxt)
       mkm->totduration = nxt;
index fbeda54cd77ea06a4d994540e91f447ef263946c..54008c6b4d118889468a763cb2e7998b2e7cc7d8 100644 (file)
@@ -1372,9 +1372,6 @@ const static char frametypearray[PKT_NTYPES] = {
   [PKT_B_FRAME] = 'B',
 };
 
-const static Rational mpeg_tc = {1, 90000};
-const static Rational htsp_tc = {1, 1000000};
-
 /**
  * Build a htsmsg from a th_pkt and enqueue it on our HTSP transport
  */
@@ -1407,16 +1404,16 @@ htsp_stream_deliver(htsp_subscription_t *hs, th_pkt_t *pkt)
 
 
   if(pkt->pkt_pts != PTS_UNSET) {
-    int64_t pts = rescale_q(pkt->pkt_pts, mpeg_tc, htsp_tc);
+    int64_t pts = ts_rescale(pkt->pkt_pts, 1000000);
     htsmsg_add_s64(m, "pts", pts);
   }
 
   if(pkt->pkt_dts != PTS_UNSET) {
-    int64_t dts = rescale_q(pkt->pkt_dts, mpeg_tc, htsp_tc);
+    int64_t dts = ts_rescale(pkt->pkt_dts, 1000000);
     htsmsg_add_s64(m, "dts", dts);
   }
 
-  uint32_t dur = rescale_q(pkt->pkt_duration, mpeg_tc, htsp_tc);
+  uint32_t dur = ts_rescale(pkt->pkt_duration, 1000000);
   htsmsg_add_u32(m, "duration", dur);
   
   pkt = pkt_merge_global(pkt);
index fe28e9d525340651fd2c7a3e6313d42ed2006cad..efb46f3887823a6f86343c8123c2a29009dcb639 100644 (file)
@@ -842,11 +842,10 @@ int base64_decode(uint8_t *out, const char *in, int out_size);
 
 int put_utf8(char *out, int c);
 
-typedef struct Rational{
-    int num; ///< numerator
-    int den; ///< denominator
-} Rational;
-
-int64_t rescale_q(int64_t a, Rational bq, Rational cq);
+static inline int64_t ts_rescale(int64_t ts, int tb)
+{
+  //  return (ts * tb + (tb / 2)) / 90000LL;
+  return (ts * tb ) / 90000LL;
+}
 
 #endif /* TV_HEAD_H */
index 33e8b466331460df139233e9e219c83c3348bf02..507882176c1551ae987f59301da3fb32fef6d558 100644 (file)
@@ -210,63 +210,3 @@ put_utf8(char *out, int c)
   *out++ = 0x80 | (0x3f &  c);
   return 6;
 }
-
-
-
-enum AVRounding {
-    AV_ROUND_ZERO     = 0, ///< Round toward zero.
-    AV_ROUND_INF      = 1, ///< Round away from zero.
-    AV_ROUND_DOWN     = 2, ///< Round toward -infinity.
-    AV_ROUND_UP       = 3, ///< Round toward +infinity.
-    AV_ROUND_NEAR_INF = 5, ///< Round to nearest and halfway cases away from zero.
-};
-
-
-static int64_t rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd){
-    int64_t r=0;
-    assert(c > 0);
-    assert(b >=0);
-    assert(rnd >=0 && rnd<=5 && rnd!=4);
-
-    if(a<0 && a != INT64_MIN) return -rescale_rnd(-a, b, c, rnd ^ ((rnd>>1)&1));
-
-    if(rnd==AV_ROUND_NEAR_INF) r= c/2;
-    else if(rnd&1)             r= c-1;
-
-    if(b<=INT_MAX && c<=INT_MAX){
-        if(a<=INT_MAX)
-            return (a * b + r)/c;
-        else
-            return a/c*b + (a%c*b + r)/c;
-    }else{
-        uint64_t a0= a&0xFFFFFFFF;
-        uint64_t a1= a>>32;
-        uint64_t b0= b&0xFFFFFFFF;
-        uint64_t b1= b>>32;
-        uint64_t t1= a0*b1 + a1*b0;
-        uint64_t t1a= t1<<32;
-        int i;
-
-        a0 = a0*b0 + t1a;
-        a1 = a1*b1 + (t1>>32) + (a0<t1a);
-        a0 += r;
-        a1 += a0<r;
-
-        for(i=63; i>=0; i--){
-//            int o= a1 & 0x8000000000000000ULL;
-            a1+= a1 + ((a0>>i)&1);
-            t1+=t1;
-            if(/*o || */c <= a1){
-                a1 -= c;
-                t1++;
-            }
-        }
-        return t1;
-    }
-}
-
-int64_t rescale_q(int64_t a, Rational bq, Rational cq){
-    int64_t b= bq.num * (int64_t)cq.den;
-    int64_t c= cq.num * (int64_t)bq.den;
-    return rescale_rnd(a, b, c, AV_ROUND_NEAR_INF);
-}