[Ffmpeg-devel] [PATCH] get rid of AVFrac

Reimar Döffinger Reimar.Doeffinger
Sat Oct 14 19:01:59 CEST 2006


Hello,
On Fri, Oct 13, 2006 at 09:33:18PM +0200, Michael Niedermayer wrote:
[...]
> this doesnt look correct ...

Hmm.. well, no idea what exactly the old code does and how.
Here is another try, it's the best I can do without further hints.

Greetings,
Reimar D?ffinger
-------------- next part --------------
Index: libavformat/avformat.h
===================================================================
--- libavformat/avformat.h	(revision 6688)
+++ libavformat/avformat.h	(working copy)
@@ -25,8 +25,8 @@
 extern "C" {
 #endif
 
-#define LIBAVFORMAT_VERSION_INT ((50<<16)+(6<<8)+0)
-#define LIBAVFORMAT_VERSION     50.6.0
+#define LIBAVFORMAT_VERSION_INT ((51<<16)+(0<<8)+0)
+#define LIBAVFORMAT_VERSION     51.0.0
 #define LIBAVFORMAT_BUILD       LIBAVFORMAT_VERSION_INT
 
 #define LIBAVFORMAT_IDENT       "Lavf" AV_STRINGIFY(LIBAVFORMAT_VERSION)
@@ -93,15 +93,6 @@
 }
 
 /*************************************************/
-/* fractional numbers for exact pts handling */
-
-/* the exact value of the fractional number is: 'val + num / den'. num
-   is assumed to be such as 0 <= num < den */
-typedef struct AVFrac {
-    int64_t val, num, den;
-} AVFrac attribute_deprecated;
-
-/*************************************************/
 /* input/output formats */
 
 struct AVFormatContext;
@@ -246,7 +237,7 @@
     int64_t codec_info_duration;
     int codec_info_nb_frames;
     /* encoding: PTS generation when outputing stream */
-    AVFrac pts;
+    int64_t pts;
 
     /**
      * this is the fundamental unit of time (in seconds) in terms
Index: libavformat/utils.c
===================================================================
--- libavformat/utils.c	(revision 6688)
+++ libavformat/utils.c	(working copy)
@@ -30,10 +30,6 @@
  * Various utility functions for using ffmpeg library.
  */
 
-static void av_frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den);
-static void av_frac_add(AVFrac *f, int64_t incr);
-static void av_frac_set(AVFrac *f, int64_t val);
-
 /** head of registered input format linked list. */
 AVInputFormat *first_iformat = NULL;
 /** head of registered output format linked list. */
@@ -2177,24 +2173,9 @@
 
     /* init PTS generation */
     for(i=0;i<s->nb_streams;i++) {
-        int64_t den = AV_NOPTS_VALUE;
         st = s->streams[i];
 
-        switch (st->codec->codec_type) {
-        case CODEC_TYPE_AUDIO:
-            den = (int64_t)st->time_base.num * st->codec->sample_rate;
-            break;
-        case CODEC_TYPE_VIDEO:
-            den = (int64_t)st->time_base.num * st->codec->time_base.den;
-            break;
-        default:
-            break;
-        }
-        if (den != AV_NOPTS_VALUE) {
-            if (den <= 0)
-                return AVERROR_INVALIDDATA;
-            av_frac_init(&st->pts, 0, 0, den);
-        }
+        st->pts = AV_NOPTS_VALUE;
     }
     return 0;
 }
@@ -2221,7 +2202,7 @@
     if((pkt->pts == 0 || pkt->pts == AV_NOPTS_VALUE) && pkt->dts == AV_NOPTS_VALUE && !delay){
         pkt->dts=
 //        pkt->pts= st->cur_dts;
-        pkt->pts= st->pts.val;
+        pkt->pts= st->pts;
     }
 
     //calculate dts from pts
@@ -2246,7 +2227,7 @@
 
 //    av_log(NULL, AV_LOG_DEBUG, "av_write_frame: pts2:%lld dts2:%lld\n", pkt->pts, pkt->dts);
     st->cur_dts= pkt->dts;
-    st->pts.val= pkt->dts;
+    st->pts= pkt->dts;
 
     /* update pts */
     switch (st->codec->codec_type) {
@@ -2255,12 +2236,16 @@
 
         /* HACK/FIXME, we skip the initial 0-size packets as they are most likely equal to the encoder delay,
            but it would be better if we had the real timestamps from the encoder */
-        if (frame_size >= 0 && (pkt->size || st->pts.num!=st->pts.den>>1 || st->pts.val)) {
-            av_frac_add(&st->pts, (int64_t)st->time_base.den * frame_size);
+        if (frame_size >= 0 && (pkt->size || st->pts != AV_NOPTS_VALUE)) {
+            if (st->pts == AV_NOPTS_VALUE)
+                st->pts = 0;
+            st->pts += (int64_t)st->time_base.den * frame_size;
         }
         break;
     case CODEC_TYPE_VIDEO:
-        av_frac_add(&st->pts, (int64_t)st->time_base.den * st->codec->time_base.num);
+        if (st->pts == AV_NOPTS_VALUE)
+            st->pts = 0;
+        st->pts += (int64_t)st->time_base.den * st->codec->time_base.num;
         break;
     default:
         break;
@@ -3034,66 +3019,7 @@
     s->time_base.den = pts_den;
 }
 
-/* fraction handling */
-
 /**
- * f = val + (num / den) + 0.5.
- *
- * 'num' is normalized so that it is such as 0 <= num < den.
- *
- * @param f fractional number
- * @param val integer value
- * @param num must be >= 0
- * @param den must be >= 1
- */
-static void av_frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den)
-{
-    num += (den >> 1);
-    if (num >= den) {
-        val += num / den;
-        num = num % den;
-    }
-    f->val = val;
-    f->num = num;
-    f->den = den;
-}
-
-/**
- * Set f to (val + 0.5).
- */
-static void av_frac_set(AVFrac *f, int64_t val)
-{
-    f->val = val;
-    f->num = f->den >> 1;
-}
-
-/**
- * Fractionnal addition to f: f = f + (incr / f->den).
- *
- * @param f fractional number
- * @param incr increment, can be positive or negative
- */
-static void av_frac_add(AVFrac *f, int64_t incr)
-{
-    int64_t num, den;
-
-    num = f->num + incr;
-    den = f->den;
-    if (num < 0) {
-        f->val += num / den;
-        num = num % den;
-        if (num < 0) {
-            num += den;
-            f->val--;
-        }
-    } else if (num >= den) {
-        f->val += num / den;
-        num = num % den;
-    }
-    f->num = num;
-}
-
-/**
  * register a new image format
  * @param img_fmt Image format descriptor
  */



More information about the ffmpeg-devel mailing list