[MPlayer-dev-eng] tv input problems and partial solutions [PATCH]

Paul Ortyl ortylp at 3miasto.net
Mon Jun 24 03:04:31 CEST 2002


On Sun, Jun 23, 2002 at 09:06:35PM +0200, Alex Beregszaszi wrote:
> 
> btw, commited mencoder fix, could you try out it too?
> 
Works OK ;)

There is a path in the attatchment that uses timestamping for synchronizing
video stream with real time.  The audio stream is assumed to be correctly
timed.

The patch finally enables tv_audio!  If you think that it still should be
disabled then change it.   Audio reading routine was changed so that there
are only two attempts to read /dev/dsp -- previous solution (infinite loop)
caused sometimes too extensive system load...  

In my opinion the tv-input feature is worthless without asynchronic video
and audio grabbing!!!  In current implementation the mencoder "sleeps" too
much on waiting for next video frame, and when system for a moment is a bit
more loaded then automaticaly a few frames are LOST!  That is the reason of
free CPU and lost frames...  

It may be done using signals and timeouts + buffering (I couldn't manage to
do that today)  or  with threads...  Actually the threading is needed only
for tvi_v4l module so actualy it does not need to be too portable...  If you
agree on that kind of solution (threading) i can try to do this.  (Actually
I'm going on vacation tomorrow, so I could start coding it within a month...)

Regards,

	Paul

-- 
Paul Ortyl <mailto:ortylp at 3miasto.net>
  Technical University of Gdansk, Telecommunications Faculty
--
-------------- next part --------------
diff -Nur main.orig/libmpdemux/tvi_v4l.c main/libmpdemux/tvi_v4l.c
--- main.orig/libmpdemux/tvi_v4l.c	Sun Jun 23 19:42:27 2002
+++ main/libmpdemux/tvi_v4l.c	Mon Jun 24 02:24:50 2002
@@ -19,6 +19,7 @@
 #include <signal.h>
 #include <sys/ioctl.h>
 #include <sys/types.h>
+#include <sys/time.h>
 #include <linux/videodev.h>
 #include <linux/soundcard.h>
 #include <unistd.h>
@@ -75,6 +76,9 @@
     int				audio_samplesize[MAX_AUDIO_CHANNELS];
     int				audio_samplerate[MAX_AUDIO_CHANNELS];
     int				audio_blocksize;
+
+    /* other */
+    double			starttime;
 } priv_t;
 
 #include "tvi_def.h"
@@ -524,6 +528,12 @@
     }
 #endif
 
+    {
+      struct timeval curtime;
+      gettimeofday(&curtime, NULL);
+      priv->starttime=curtime.tv_sec + curtime.tv_usec*.000001;
+    }
+
     return(1);
 }
 
@@ -541,8 +551,6 @@
 	    return(TVI_CONTROL_FALSE);
 	}
 	case TVI_CONTROL_IS_AUDIO:
-	    return(TVI_CONTROL_FALSE);
-/* also disable audio for as it's not working! */
 	    if (priv->channels[priv->act_channel].flags & VIDEO_VC_AUDIO)
 	    {
 		return(TVI_CONTROL_TRUE);
@@ -821,6 +829,8 @@
 
 static double grab_video_frame(priv_t *priv, char *buffer, int len)
 {
+    struct timeval curtime;
+    double timestamp;
     int frame = priv->queue % priv->nbuf;
     int nextframe = (priv->queue+1) % priv->nbuf;
 
@@ -841,6 +851,9 @@
 
     priv->queue++;
     
+    gettimeofday(&curtime, NULL);
+    timestamp=curtime.tv_sec + curtime.tv_usec*.000001;
+
     mp_dbg(MSGT_TV, MSGL_DBG3, "mmap: %p + offset: %d => %p\n",
 	priv->mmap, priv->mbuf.offsets[frame],
 	priv->mmap+priv->mbuf.offsets[frame]);
@@ -851,7 +864,7 @@
     /* copy the actual frame */
     memcpy(buffer, priv->mmap+priv->mbuf.offsets[frame], len);
 
-    return(0);
+    return(timestamp-priv->starttime);
 }
 
 static int get_video_framesize(priv_t *priv)
@@ -862,13 +875,13 @@
 static double grab_audio_frame(priv_t *priv, char *buffer, int len)
 {
     int in_len = 0;
-//    int max_tries = 128;
+    int max_tries = 2;
 
     mp_dbg(MSGT_TV, MSGL_DBG2, "grab_audio_frame(priv=%p, buffer=%p, len=%d)\n",
 	priv, buffer, len);
     
-//    while (--max_tries > 0)
-    for (;;)
+    while (--max_tries > 0)
+//    for (;;)
     {
 	in_len = read(priv->audio_fd, buffer, len);
 //	printf("in_len: %d\n", in_len);
@@ -882,7 +895,6 @@
 	    break;
 	}
     }
-//    printf("tries: %d\n", 128-max_tries);
 
     return 0; //(in_len); // FIXME!
 }
diff -Nur main.orig/libmpdemux/video.c main/libmpdemux/video.c
--- main.orig/libmpdemux/video.c	Fri Jun 14 02:49:56 2002
+++ main/libmpdemux/video.c	Mon Jun 24 02:21:08 2002
@@ -288,7 +288,7 @@
 	if(d_video->pts>0 && pts1>0 && d_video->pts>pts1)
 	  frame_time=d_video->pts-pts1;
         break;
-#ifdef HAVE_TV_BSDBT848
+#ifdef USE_TV
       case DEMUXER_TYPE_TV:
 #endif
       case DEMUXER_TYPE_MOV:


More information about the MPlayer-dev-eng mailing list