File fix_synchro.patch of Package xdtv

--- src/divx.c.old	2014-09-20 10:59:56.973793466 +0200
+++ src/divx.c	2014-09-20 11:32:34.651285105 +0200
@@ -416,6 +416,7 @@
 static long long dropped_audio_samples;
 extern double videostampmin,videostampmax;
 double audiostamp=0.0;
+clockid_t clock_id=CLOCK_REALTIME; // v4l2 uses CLOCK_MONOTONIC for timestamps starting with kernel 3.9
 #endif // SYNCHRO
 #endif // NOAUDIO
 
@@ -956,7 +957,7 @@
   char *fourcc = NULL;
   char *filename = NULL;
   char *codec_name = NULL;
-  struct timeval tv;
+  struct timespec tv;
 
   strcpy(xawmessage,translate("Record Informations:\n\n"));
 
@@ -2140,10 +2141,18 @@
   dropped_audio_samples = 0;
   dropped_audio_buffers = 0;
 #endif
-  gettimeofday(&tv, NULL);
-  if(audiostamp==0.0) audiostamp=tv.tv_usec/1000000.0+tv.tv_sec;
+  clock_gettime(clock_id, &tv);
+  if(audiostamp==0.0)
+  {  
+    audiostamp=tv.tv_nsec/1000000000.0+tv.tv_sec;
+    if(videostampmin!=0.0 && fabs(audiostamp-videostampmin)>10000)
+    {
+      clock_gettime(clock_id=CLOCK_MONOTONIC, &tv);
+      audiostamp=tv.tv_nsec/1000000000.0+tv.tv_sec;
+    }
+  }
   if(videostampmin==0.0)
-    videostampmin=videostampmax=tv.tv_usec/1000000.0+tv.tv_sec;
+    videostampmin=videostampmax=tv.tv_nsec/1000000000.0+tv.tv_sec;
   divx_audio_must_start=1;
 #endif
 
@@ -2760,7 +2769,7 @@
 {
   int error;
   short int *buffer;
-  struct timeval tv;
+  struct timespec tv;
 
   pthread_setcancelstate(PTHREAD_CANCEL_DISABLE,NULL);
   buffer = (short int *)malloc (/*BUFFER_SIZE*/divx.audio_buffer_size * sizeof (short int));
@@ -2783,8 +2792,8 @@
 	goto error;
       }
       r /= (divx.audio_fmt==AUDIO_U8 ? 1 : 2);
-      gettimeofday (&tv, NULL);
-      audiostamp=tv.tv_usec/1000000.0+tv.tv_sec;
+      clock_gettime (clock_id, &tv);
+      audiostamp=tv.tv_nsec/1000000000.0+tv.tv_sec;
       write_audio_to_avi(buffer, r);
 
       pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,NULL);
openSUSE Build Service is sponsored by