[mythtv] vsync and frame timing adjustments

Bruce Markey bjm at lvcm.com
Fri Aug 27 16:26:14 EDT 2004


Doug Larrick wrote:
> Doug Larrick wrote:
> 
>> Thanks, will do.  I found enough time last night to get some 
>> instrumentation code in place, and will try to run some experiments 
>> over the next few days with all three variants of the code.
> 
> 
> As promised... here is some data.  They're pretty big, so I've not 
> attached them.

Got it! "We're late!" therefore update nextrigger and return
without calling KeepPhase? Wrong! =)

Somewhere in my code, possibly DRM, possibly earlier code, I
didn't want to go on in the code if it was already past the
time. This logic propagated to other methods and turned into
an unnecessary check that prevents reaching KeepPhase(). We
don't need to find out "if (m_delay <= 0)" is true because
"while (m_delay > 0)" will be false and fall through anyway.


> HTML version (big): http://jekyl.ddts.net/doug/frame-logs.html

The events you highlighted plus lines 80-92 are clearly straddle
events. In 191-213, at 292 PostDelay is -121 but PhaseAdj is 0(!).
It continues straddling until PostPrepare is > 0 on line 213. At
that point KeepPhase() does get called and the problem gets fixed.

Please try the attached with your instrumentation. Run it without
the counter adjust so that it can grow past one refresh interval.
It probably doesn't need the counter adjust for production but
it's your call 'cause I think there are pluses and minuses either
way =).

--  bjm
-------------- next part --------------
Index: libs/libmythtv/vsync.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/vsync.cpp,v
retrieving revision 1.3
diff -u -r1.3 vsync.cpp
--- libs/libmythtv/vsync.cpp	23 Aug 2004 01:44:30 -0000	1.3
+++ libs/libmythtv/vsync.cpp	27 Aug 2004 19:40:28 -0000
@@ -165,7 +165,6 @@
 
 void VideoSync::KeepPhase()
 {
-    m_delay = CalcDelay();
     // Keep our nexttrigger from drifting too close to the exact retrace.
     // If delay is near 0, some frames will be delay < 0 and others delay > 0.
     // This will cause continous rapid fire stuttering. Nexttrigger only
@@ -173,8 +172,13 @@
     // falls in the DMZ. Otherwise, nexttrigger should be left alone.
     // This method is only useful for those sync methods where WaitForFrame
     // targets hardware retrace rather than targeting nexttrigger.
-    if (m_delay > -1000)
+
+    cerr << m_delay << endl;
+    if (m_delay > -500)
         OffsetTimeval(m_nexttrigger, -2000);
+    // May not be necessary, may not hurt (shrug ;-)  --  bjm
+    //else if (m_delay < -(m_refresh_interval/2))
+    //    OffsetTimeval(m_nexttrigger, 200);
 }
 
 #define DRM_VBLANK_RELATIVE 0x1;
@@ -269,17 +273,15 @@
     // Do the wait
     m_delay = CalcDelay();
     
-    if (m_delay <= 0) 
+    if (m_delay > 0) 
     {
-        UpdateNexttrigger();
-        return; // We're late!
+        drm_wait_vblank_t blank;
+        blank.request.type = DRM_VBLANK_RELATIVE;
+        blank.request.sequence =
+            (int)(ceil((double)m_delay / m_refresh_interval));
+        drmWaitVBlank(m_dri_fd, &blank);
     }
 
-    drm_wait_vblank_t blank;
-    blank.request.type = DRM_VBLANK_RELATIVE;
-    blank.request.sequence = (int)(ceil((double)m_delay / m_refresh_interval));
-    drmWaitVBlank(m_dri_fd, &blank);
-
     KeepPhase();
     
     UpdateNexttrigger();
@@ -345,13 +347,7 @@
     OffsetTimeval(m_nexttrigger, sync_delay);
     
     m_delay = CalcDelay();
-    
-    if (m_delay <= 0) 
-    {
-        UpdateNexttrigger();
-        return; // We're late!
-    }
-    
+
     while (m_delay > 0)
     {
         dopoll();
@@ -472,13 +468,6 @@
     // Do the wait
     m_delay = CalcDelay();
     //cout << "Delay " << m_delay;
-    
-    if (m_delay <= 0) 
-    {
-        UpdateNexttrigger();
-        //cout << " negative!" << endl;
-        return; // We're late!
-    }
 
     int n = 0;
     while (m_delay > 0) 
@@ -561,13 +550,8 @@
 {
     OffsetTimeval(m_nexttrigger, sync_delay);
 
-    // Do the wait
     m_delay = CalcDelay();
-    if (m_delay <= 0)
-    {
-        UpdateNexttrigger();
-        return; // We're late!
-    }
+
     unsigned long rtcdata;
     while (m_delay > 0)
     {
@@ -601,12 +585,7 @@
 
     m_delay = CalcDelay();
 
-    if (m_delay <= 0)
-    {
-        UpdateNexttrigger();
-        return;
-    }
-    else
+    if (m_delay > 0)
     {
         int cnt = 0;
         m_cheat += 100;


More information about the mythtv-dev mailing list