On Mittwoch 24 Januar 2007 21:01, Stefan Lucke wrote:
> On Dienstag 23 Januar 2007 01:25, Torgeir Veimo wrote:
> > On 22 Jan 2007, at 20:26, Stefan Lucke wrote:
> 
> > > So my system skips around 9 to 10 frames per minute.
> > > 60 * 25 = 1500 frames.
> > > So the TV frame rate is 25 * 1490 / 1500 = 24.833 Hz .
> > >
> > > I guess I've to ask Ville if there is a way to increase the dot clock
> > > of my card in some way.
> > 
> > This assumes your soundcard is perfectly clocked to the incoming DVB  
> > stream? I'd assume that eventually if the soundcard is a bit faster  
> > than the DVB stream, you'd get an xrun. Maybe it's an idea to add  
> > xrun counts as well.
> 
> Yes, there are e few assumptions which may slightly influence calculation.
> These numbers are from recording playback. During live view, they are
> a bit different, but the direction is the same.

So here comes my first try of moving the sync code to cVideoDevice.
I guess this is not it's final place, but we should first look at th reported
numbers (thats from live view):

Jan 28 18:33:06 bodega1 vdr: [6995] [VideoOut]: video now synced (43 - -316)

This message is issued the first time after ataching a new VideoStreamDecoder
and measured sync offset is within +/- 1 frame.

xrun and other messages are removed.

Each 7500 frames (25 * 60 * 5 ~ 5minutes) a statistic message is printed.
I'm a bit surprised, that repeated frame counter grows wtih drop frame counter.

Jan 28 18:38:04 bodega1 vdr: [6995] [VideoOut]: sync info: repF = 22, drpF = 
11, totF = 7500
Jan 28 18:43:04 bodega1 vdr: [6995] [VideoOut]: sync info: repF = 26, drpF = 
20, totF = 15000
Jan 28 18:48:04 bodega1 vdr: [6995] [VideoOut]: sync info: repF = 66, drpF = 
42, totF = 22500
Jan 28 18:53:04 bodega1 vdr: [6995] [VideoOut]: sync info: repF = 74, drpF = 
54, totF = 30000
Jan 28 18:58:04 bodega1 vdr: [6995] [VideoOut]: sync info: repF = 85, drpF = 
73, totF = 37500
Jan 28 19:03:05 bodega1 vdr: [6995] [VideoOut]: sync info: repF = 85, drpF = 
73, totF = 45000
Jan 28 19:08:04 bodega1 vdr: [6995] [VideoOut]: sync info: repF = 92, drpF = 
85, totF = 52500
Jan 28 19:13:04 bodega1 vdr: [6995] [VideoOut]: sync info: repF = 98, drpF = 
96, totF = 60000

-- 
Stefan Lucke
Index: mpeg2decoder.c
===================================================================
RCS file: /cvsroot/softdevice/softdevice/mpeg2decoder.c,v
retrieving revision 1.70
diff -U3 -r1.70 mpeg2decoder.c
--- mpeg2decoder.c	7 Nov 2006 19:01:37 -0000	1.70
+++ mpeg2decoder.c	28 Jan 2007 17:30:14 -0000
@@ -594,10 +594,9 @@
 
   // init A-V syncing variables
   offset=0;
-  delay=0;
-  hurry_up=0;
   syncTimer = new cSyncTimer ((eSyncMode) setupStore.syncTimerMode);
   syncTimer->Reset();
+  videoOut->ResetDelay();
 
   default_frametime = DEFAULT_FRAMETIME;
   trickspeed = Trickspeed;
@@ -627,7 +626,9 @@
 };
 
 uint64_t cVideoStreamDecoder::GetPTS() {
-  return pts - (delay + syncTimer->GetRelTime(false))/100;
+  return pts;
+// Was pts of next frame reduced by time to display next frame.
+//  return pts - (delay + syncTimer->GetRelTime(false))/100;
 }
 
 int cVideoStreamDecoder::DecodePicture_avcodec(sPicBuffer *&pic, int &got_picture,
@@ -882,12 +883,8 @@
   if (pic->pts != AV_NOPTS_VALUE )
           pts=pic->pts;
 
-  if (!hurry_up || frame % 2 ) {
-    MPGDEB("DrawVideo...delay : %d\n",delay);
-    videoOut->DrawVideo_420pl(syncTimer, &delay, pic);
-    MPGDEB("end DrawVideo\n");
-  } else
-    fprintf(stderr,"+");
+  videoOut->DrawVideo_420pl(syncTimer, pic);
+
   // we just displayed a frame, now it's the right time to
   // measure the A-V offset
   // the A-V syncing code is partly based on MPlayer...
@@ -895,42 +892,11 @@
   // update video pts
   cClock::AdjustVideoPTS(pts);
 
-  if ( aPTS )
-    offset = aPTS - pts ;
-  else offset = 0;
-  if ( abs(offset) > 100000)
-          offset=0;
-
-  // this few lines does the whole syncing
-  int pts_corr;
-
-  // calculate pts correction. Correct 1/10 of offset at a time
-  pts_corr = offset/10;
-
-  //Max. correction is 2/10 frametime.
-  if (pts_corr > 2*frametime() / 10 )
-    pts_corr = 2*frametime() / 10;
-  else if (pts_corr < -2*frametime() / 10 )
-    pts_corr = -2*frametime() / 10;
-
-  // calculate delay
-  delay += ( frametime() - pts_corr  ) * 100;
+  videoOut->EvaluateDelay (aPTS, pts, frametime());
   // update video pts
   pts += frametime();
 
-  if (delay > 2*frametime()*100)
-    delay = 2*frametime()*100;
-  else if (delay < -frametime()*100)
-    delay = -frametime()*100;
-
-  if (offset >  8*frametime())
-     hurry_up=1;
-  else if ( (offset < 2*frametime()) && (hurry_up > 0) )
-     hurry_up=0;
-
-#if 1
-  int dispTime=syncTimer->GetRelTime();
-  delay-=dispTime;
+#if 0
   if (!(frame % 1) || context->hurry_up) {
     MPGDEB("Frame# %-5d A-V(ms) %-5d delay %d FrameT: %s, dispTime(ms): %1.2f\n",
       frame,(int)(clock->GetPTS()-pts),delay,
@@ -942,7 +908,8 @@
   }
 #endif
 
-#ifdef AV_STATS
+#if 0
+//#ifdef AV_STATS
   {
     const int Freq=10;
     static float offsetSum=0;
Index: mpeg2decoder.h
===================================================================
RCS file: /cvsroot/softdevice/softdevice/mpeg2decoder.h,v
retrieving revision 1.38
diff -U3 -r1.38 mpeg2decoder.h
--- mpeg2decoder.h	17 Jun 2006 16:27:35 -0000	1.38
+++ mpeg2decoder.h	28 Jan 2007 17:30:14 -0000
@@ -237,9 +237,7 @@
     cVideoOut           *videoOut;
 
     // A-V syncing stuff
-    int                hurry_up;
     int                offset;
-    int                delay;
     int                trickspeed;
     int                default_frametime;
     inline int frametime()
Index: setup-softdevice.c
===================================================================
RCS file: /cvsroot/softdevice/softdevice/setup-softdevice.c,v
retrieving revision 1.48
diff -U3 -r1.48 setup-softdevice.c
--- setup-softdevice.c	3 Dec 2006 18:26:21 -0000	1.48
+++ setup-softdevice.c	28 Jan 2007 17:30:19 -0000
@@ -74,17 +74,6 @@
 
 /* ----------------------------------------------------------------------------
  */
-static inline int clamp (int min, int val, int max)
-{
-  if (val < min)
-    return min;
-  if (val > max)
-    return max;
-  return val;
-}
-
-/* ----------------------------------------------------------------------------
- */
 cSetupStore setupStore;
 
 cSetupStore::cSetupStore ()
Index: setup-softdevice.h
===================================================================
RCS file: /cvsroot/softdevice/softdevice/setup-softdevice.h,v
retrieving revision 1.36
diff -U3 -r1.36 setup-softdevice.h
--- setup-softdevice.h	3 Dec 2006 18:26:21 -0000	1.36
+++ setup-softdevice.h	28 Jan 2007 17:30:19 -0000
@@ -177,6 +177,17 @@
 #define OSDMODE_PSEUDO    0
 #define OSDMODE_SOFTWARE  1
 
+/* ----------------------------------------------------------------------------
+ */
+static inline int clamp (int min, int val, int max)
+{
+  if (val < min)
+    return min;
+  if (val > max)
+    return max;
+  return val;
+}
+
 extern cSetupStore setupStore;
 
 #endif //__SETUP_SOFTDEVICE_H
Index: video.c
===================================================================
RCS file: /cvsroot/softdevice/softdevice/video.c,v
retrieving revision 1.72
diff -U3 -r1.72 video.c
--- video.c	15 Jan 2007 20:30:08 -0000	1.72
+++ video.c	28 Jan 2007 17:30:19 -0000
@@ -24,6 +24,8 @@
 #define OSDDEB(out...)
 #endif
 
+/* ---------------------------------------------------------------------------
+ */
 cVideoOut::cVideoOut(cSetupStore *setupStore)
 {
   OsdWidth=OSD_FULL_WIDTH;
@@ -50,6 +52,11 @@
   videoInitialized = false;
   oldPicture = NULL;
 
+  hurryUp = 0;
+  delay = 0;
+  repeatedFrames = droppedFrames = frame = 0;
+  offsetInHold = false;
+
   for (int i = 0; i < SETUP_VIDEOASPECTNAMES_COUNT; ++i)
     parValues [i] = 1.0;
 
@@ -433,9 +440,16 @@
 
 /* ---------------------------------------------------------------------------
  */
-void cVideoOut::DrawVideo_420pl(cSyncTimer *syncTimer, int *delay,
+void cVideoOut::DrawVideo_420pl(cSyncTimer *syncTimer,
                                 sPicBuffer *pic)
 {
+  if (hurryUp && frame % 2) {
+    ++frame;
+    ++droppedFrames;
+    fprintf(stderr,"X");
+    return;
+  }
+
   sPicBuffer *scale_pic=NULL;
   if (scaleVid != 0) {
           scale_pic=GetBuffer(pic->format,pic->max_width,pic->max_height);
@@ -451,7 +465,10 @@
           pic=scale_pic;
   };
 
-  Sync(syncTimer, delay);
+  if (delay > frametime * 100)
+    ++repeatedFrames;
+
+  Sync(syncTimer, &delay);
   oldPictureMutex.Lock();
 
   OsdRefreshCounter=0;
@@ -463,9 +480,12 @@
   SetOldPicture(pic);
 
   oldPictureMutex.Unlock();
+  delay -= dispTime = syncTimer->GetRelTime();
+
   ProcessEvents();
   if (scale_pic)
           ReleaseBuffer(scale_pic);
+  ++frame;
 }
 
 /* ---------------------------------------------------------------------------
@@ -487,6 +507,72 @@
 
 /* ---------------------------------------------------------------------------
  */
+void cVideoOut::EvaluateDelay(int aPTS, int pts, int frametime)
+{
+    int   offset,
+          pts_corr;
+
+  this->frametime = frametime;
+  offset = (aPTS) ? aPTS - pts : 0;
+
+  if (abs(offset) > 100000)
+    offset=0;
+  // this few lines does the whole syncing
+  // calculate pts correction. Correct 1/10 of offset at a time
+  pts_corr = offset/10;
+
+  //Max. correction is 2/10 frametime.
+  pts_corr = clamp (-2*frametime / 10, pts_corr, 2*frametime / 10);
+
+  // calculate delay
+  delay += ( frametime - pts_corr  ) * 100;
+
+  delay = clamp (-frametime*100, delay, 2*frametime*100);
+
+  if (offset >  8*frametime)
+    hurryUp=1;
+  else if ((offset < 2*frametime) && (hurryUp > 0))
+    hurryUp=0;
+
+  if (frame > 8 /* && frame < 200*/) {
+    if (!offsetInHold) {
+      if (abs(offset) < frametime) {
+        offsetInHold = true;
+        fprintf(stderr,
+                "[VideoOut]: video now synced (%d - %d)\n",
+                frame, offset);
+        dsyslog("[VideoOut]: video now synced (%d - %d)\n",
+                frame, offset);
+        //fprintf (stderr, "%d offset = %d delay = %d\n", frame, offset, delay);
+      }
+    }
+  }
+  if (frame && !(frame % 7500)) {
+    dsyslog("[VideoOut]: sync info: repF = %d, drpF = %d, totF = %d\n",
+            repeatedFrames, droppedFrames, frame);
+  }
+}
+
+/* ---------------------------------------------------------------------------
+ */
+void cVideoOut::ResetDelay()
+{
+  fprintf(stderr,"ResetDelay\n");
+  hurryUp = 0;
+  delay = 0;
+  offsetInHold = false;
+
+  fprintf(stderr, "[VideoOut]: sync info: repF = %d, drpF = %d, totF = %d\n",
+          repeatedFrames, droppedFrames, frame);
+
+  dsyslog("[VideoOut]: sync info: repF = %d, drpF = %d, totF = %d\n",
+          repeatedFrames, droppedFrames, frame);
+
+  repeatedFrames = droppedFrames = frame = 0;
+}
+
+/* ---------------------------------------------------------------------------
+ */
 void cVideoOut::ClearOSD()
 {
   OSDDEB("ClearOSD\n");
@@ -517,7 +603,7 @@
 }
 
 void cVideoOut::SetVidWin(int ScaleVid, int VidX1, int VidY1,
-                int VidX2, int VidY2) 
+                int VidX2, int VidY2)
 {
   OSDDEB("SetVidWin ScaleVid %d: %d,%d  %d,%d\n",
                   ScaleVid,VidX1,VidY1,VidX2,VidY2);
Index: video.h
===================================================================
RCS file: /cvsroot/softdevice/softdevice/video.h,v
retrieving revision 1.49
diff -U3 -r1.49 video.h
--- video.h	3 Dec 2006 19:32:59 -0000	1.49
+++ video.h	28 Jan 2007 17:30:19 -0000
@@ -118,6 +118,17 @@
      */
     virtual bool IsSoftOSDMode();
 
+    /* -----------------------------------------------------------------------
+     */
+    int     frame,
+            droppedFrames,
+            repeatedFrames;
+    bool    offsetInHold;
+    int     hurryUp;
+    int     delay;
+    int     dispTime;
+    int     frametime;
+
 public:
     cVideoOut(cSetupStore *setupStore);
     virtual ~cVideoOut();
@@ -135,9 +146,11 @@
     virtual void CheckAspect(int new_afd, double new_asp);
     virtual void CheckAspectDimensions (sPicBuffer *pic);
     virtual void CheckArea(int w, int h);
-    virtual void DrawVideo_420pl(cSyncTimer *syncTimer, int *delay,
-                                  sPicBuffer *pic);
+    virtual void DrawVideo_420pl(cSyncTimer *syncTimer,
+                                 sPicBuffer *pic);
     virtual void DrawStill_420pl(sPicBuffer *buf);
+    virtual void EvaluateDelay(int aPTS, int pts, int frametime);
+    virtual void ResetDelay(void);
     virtual bool Initialize(void) {videoInitialized = true; return 1;};
     virtual bool Reconfigure (int format = 0,
                     int width = SRC_WIDTH, int height = SRC_HEIGHT)
@@ -186,7 +199,7 @@
     // clear the OSD buffer
 
     virtual void OpenOSD();
-    virtual void SetVidWin(int ScaleVid, int VidX1, int VidY1, 
+    virtual void SetVidWin(int ScaleVid, int VidX1, int VidY1,
                     int VidX2, int VidY2);
     virtual int GetOSDColorkey();
     virtual void CloseOSD();
_______________________________________________
Softdevice-devel mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/softdevice-devel

Reply via email to