Browse code

ffplay: simplify video pts calculation

Also use frame->pts instead of a standalone variable

Signed-off-by: Marton Balint <cus@passwd.hu>

Marton Balint authored on 2013/04/01 22:04:14
Showing 1 changed files
... ...
@@ -1648,7 +1648,7 @@ static int queue_picture(VideoState *is, AVFrame *src_frame, double pts, int64_t
1648 1648
     return 0;
1649 1649
 }
1650 1650
 
1651
-static int get_video_frame(VideoState *is, AVFrame *frame, int64_t *pts, AVPacket *pkt, int *serial)
1651
+static int get_video_frame(VideoState *is, AVFrame *frame, AVPacket *pkt, int *serial)
1652 1652
 {
1653 1653
     int got_picture;
1654 1654
 
... ...
@@ -1679,22 +1679,22 @@ static int get_video_frame(VideoState *is, AVFrame *frame, int64_t *pts, AVPacke
1679 1679
         int ret = 1;
1680 1680
 
1681 1681
         if (decoder_reorder_pts == -1) {
1682
-            *pts = av_frame_get_best_effort_timestamp(frame);
1682
+            frame->pts = av_frame_get_best_effort_timestamp(frame);
1683 1683
         } else if (decoder_reorder_pts) {
1684
-            *pts = frame->pkt_pts;
1684
+            frame->pts = frame->pkt_pts;
1685 1685
         } else {
1686
-            *pts = frame->pkt_dts;
1686
+            frame->pts = frame->pkt_dts;
1687 1687
         }
1688 1688
 
1689
-        if (*pts == AV_NOPTS_VALUE) {
1690
-            *pts = 0;
1689
+        if (frame->pts == AV_NOPTS_VALUE) {
1690
+            frame->pts = 0;
1691 1691
         }
1692 1692
 
1693 1693
         if (framedrop>0 || (framedrop && get_master_sync_type(is) != AV_SYNC_VIDEO_MASTER)) {
1694 1694
             SDL_LockMutex(is->pictq_mutex);
1695
-            if (is->frame_last_pts != AV_NOPTS_VALUE && *pts) {
1695
+            if (is->frame_last_pts != AV_NOPTS_VALUE && frame->pts) {
1696 1696
                 double clockdiff = get_video_clock(is) - get_master_clock(is);
1697
-                double dpts = av_q2d(is->video_st->time_base) * *pts;
1697
+                double dpts = av_q2d(is->video_st->time_base) * frame->pts;
1698 1698
                 double ptsdiff = dpts - is->frame_last_pts;
1699 1699
                 if (!isnan(clockdiff) && fabs(clockdiff) < AV_NOSYNC_THRESHOLD &&
1700 1700
                      ptsdiff > 0 && ptsdiff < AV_NOSYNC_THRESHOLD &&
... ...
@@ -1886,7 +1886,6 @@ static int video_thread(void *arg)
1886 1886
     AVPacket pkt = { 0 };
1887 1887
     VideoState *is = arg;
1888 1888
     AVFrame *frame = av_frame_alloc();
1889
-    int64_t pts_int = AV_NOPTS_VALUE, pos = -1;
1890 1889
     double pts;
1891 1890
     int ret;
1892 1891
     int serial = 0;
... ...
@@ -1901,19 +1900,15 @@ static int video_thread(void *arg)
1901 1901
 #endif
1902 1902
 
1903 1903
     for (;;) {
1904
-#if CONFIG_AVFILTER
1905
-        AVRational tb;
1906
-#endif
1907 1904
         while (is->paused && !is->videoq.abort_request)
1908 1905
             SDL_Delay(10);
1909 1906
 
1910 1907
         avcodec_get_frame_defaults(frame);
1911 1908
         av_free_packet(&pkt);
1912 1909
 
1913
-        ret = get_video_frame(is, frame, &pts_int, &pkt, &serial);
1910
+        ret = get_video_frame(is, frame, &pkt, &serial);
1914 1911
         if (ret < 0)
1915 1912
             goto the_end;
1916
-
1917 1913
         if (!ret)
1918 1914
             continue;
1919 1915
 
... ...
@@ -1946,7 +1941,6 @@ static int video_thread(void *arg)
1946 1946
             last_serial = serial;
1947 1947
         }
1948 1948
 
1949
-        frame->pts = pts_int;
1950 1949
         frame->sample_aspect_ratio = av_guess_sample_aspect_ratio(is->ic, is->video_st, frame);
1951 1950
         ret = av_buffersrc_add_frame(filt_in, frame);
1952 1951
         if (ret < 0)
... ...
@@ -1968,23 +1962,12 @@ static int video_thread(void *arg)
1968 1968
             if (fabs(is->frame_last_filter_delay) > AV_NOSYNC_THRESHOLD / 10.0)
1969 1969
                 is->frame_last_filter_delay = 0;
1970 1970
 
1971
-            pts_int = frame->pts;
1972
-            tb      = filt_out->inputs[0]->time_base;
1973
-            pos     = av_frame_get_pkt_pos(frame);
1974
-            if (av_cmp_q(tb, is->video_st->time_base)) {
1975
-                av_unused int64_t pts1 = pts_int;
1976
-                pts_int = av_rescale_q(pts_int, tb, is->video_st->time_base);
1977
-                av_dlog(NULL, "video_thread(): "
1978
-                        "tb:%d/%d pts:%"PRId64" -> tb:%d/%d pts:%"PRId64"\n",
1979
-                        tb.num, tb.den, pts1,
1980
-                        is->video_st->time_base.num, is->video_st->time_base.den, pts_int);
1981
-            }
1982
-            pts = pts_int * av_q2d(is->video_st->time_base);
1983
-            ret = queue_picture(is, frame, pts, pos, serial);
1971
+            pts = frame->pts * av_q2d(filt_out->inputs[0]->time_base);
1972
+            ret = queue_picture(is, frame, pts, av_frame_get_pkt_pos(frame), serial);
1984 1973
             av_frame_unref(frame);
1985 1974
         }
1986 1975
 #else
1987
-        pts = pts_int * av_q2d(is->video_st->time_base);
1976
+        pts = frame->pts * av_q2d(is->video_st->time_base);
1988 1977
         ret = queue_picture(is, frame, pts, pkt.pos, serial);
1989 1978
         av_frame_unref(frame);
1990 1979
 #endif