[MPlayer-dev-eng] BT848 patch v2.0

Charles Henrich henrich at sigbus.com
Tue Mar 26 03:56:40 CET 2002


Includes changes as suggested by Arpi.  Im off for two weeks, so I wont be
around to answer any replies.  I've been using this code for some time now
without trouble.  It requires the FreeBSD bt848 kernel patch as well, which
I've posted to the *bsd mailing lists.  I'll also attach it to this email for
reference.  (This kernel patch is a hack to fix bugs in the driver, im working
on a real fix as we speak).

-Crh

       Charles Henrich         Eon Entertainment         henrich at msu.edu

                       http://www.sigbus.com:81/~henrich
-------------- next part --------------
Index: main/cfg-common.h
===================================================================
RCS file: /cvsroot/mplayer/main/cfg-common.h,v
retrieving revision 1.30
diff -u -u -r1.30 cfg-common.h
--- main/cfg-common.h	15 Mar 2002 16:10:06 -0000	1.30
+++ main/cfg-common.h	26 Mar 2002 03:12:44 -0000
@@ -98,7 +98,11 @@
 #ifdef USE_TV
 struct config tvopts_conf[]={
 	{"on", &tv_param_on, CONF_TYPE_FLAG, 0, 0, 1, NULL},
+#ifdef HAVE_TV_BSDBT848
+	{"immediatemode", &tv_param_immediate, CONF_TYPE_FLAG, 0, 0, 0, NULL},
+#endif
 	{"noaudio", &tv_param_noaudio, CONF_TYPE_FLAG, 0, 0, 1, NULL},
+	{"audiorate", &tv_param_audiorate, CONF_TYPE_INT, 0, 0, 0, NULL},
 	{"driver", &tv_param_driver, CONF_TYPE_STRING, 0, 0, 0, NULL},
 	{"device", &tv_param_device, CONF_TYPE_STRING, 0, 0, 0, NULL},
 	{"freq", &tv_param_freq, CONF_TYPE_STRING, 0, 0, 0, NULL},
Index: main/configure
===================================================================
RCS file: /cvsroot/mplayer/main/configure,v
retrieving revision 1.412
diff -u -u -r1.412 configure
--- main/configure	20 Mar 2002 17:53:44 -0000	1.412
+++ main/configure	26 Mar 2002 03:12:45 -0000
@@ -3140,6 +3140,21 @@
   fi
 fi
 
+echocheck "ftello()"
+# if we dont have ftello map it to ftell
+cat > $TMPC << EOF
+#include <stdio.h>
+int main (void) { ftello(stdin); return 0; }
+EOF
+_ftello=no
+cc_check && _ftello=yes
+if test "$_ftello" = yes ; then
+ _def_ftello='#define HAVE_FTELLO 1'
+else
+ _def_ftello='#undef HAVE_FTELLO'
+fi
+echores "$_ftello"
+
 # Determine OS dependent libs
 if cygwin ; then
   _confcygwin='TARGET_CYGWIN = yes'
@@ -3414,6 +3429,13 @@
 
 /* Define this if your system has the header file for the OSS sound interface */
 $_def_sys_soundcard
+
+/* Define this if your system uses ftello() for off_t seeking */
+
+$_def_ftello
+#ifndef HAVE_FTELLO
+# define ftello(a) ftell(a)
+#endif
 
 /* Define this if your system has the "malloc.h" header file */
 $_def_malloc
Index: main/dec_video.c
===================================================================
RCS file: /cvsroot/mplayer/main/dec_video.c,v
retrieving revision 1.122
diff -u -u -r1.122 dec_video.c
--- main/dec_video.c	20 Mar 2002 15:37:54 -0000	1.122
+++ main/dec_video.c	26 Mar 2002 03:12:45 -0000
@@ -1141,7 +1141,8 @@
 //    planes[0]=start;
 //    blit_frame=2;
     sh_video->our_out_buffer = start;
-    blit_frame=3;
+    if(in_size<=0) blit_frame=0;
+    else           blit_frame=3;
     break;
   case VFM_RLE:
 //void AVI_Decode_RLE8(char *image,char *delta,int tdsize,
Index: main/mencoder.c
===================================================================
RCS file: /cvsroot/mplayer/main/mencoder.c,v
retrieving revision 1.101
diff -u -u -r1.101 mencoder.c
--- main/mencoder.c	25 Mar 2002 03:20:42 -0000	1.101
+++ main/mencoder.c	26 Mar 2002 03:12:48 -0000
@@ -16,6 +16,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <signal.h>
+#include <sys/time.h>
 
 #include "config.h"
 #include "mp_msg.h"
@@ -262,6 +263,7 @@
   }
 }
 
+
 //---------------------------------------------------------------------------
 
 // mini dummy libvo:
@@ -496,11 +498,19 @@
 int file_format=DEMUXER_TYPE_UNKNOWN;
 int i;
 
+uint32_t ptimer_start;
+uint32_t audiorate=0;
+uint32_t videorate=0;
+uint32_t audiosamples=1;
+uint32_t videosamples=1;
+uint32_t skippedframes=0;
+uint32_t duplicatedframes=0;
+
 aviwrite_t* muxer=NULL;
 aviwrite_stream_t* mux_a=NULL;
 aviwrite_stream_t* mux_v=NULL;
 FILE* muxer_f=NULL;
-int muxer_f_size=0;
+off_t muxer_f_size=0;
 
 #ifdef HAVE_DIVX4ENCORE
 ENC_FRAME enc_frame;
@@ -1349,6 +1359,13 @@
     demux_seek(demuxer, d, 1);
 }
 
+if(tv_param_on == 1) 
+	{
+	fprintf(stderr,"Forcing audio preload to 0, max pts correction to 0\n");
+	audio_preload = 0.0;
+	default_max_pts_correction = 0;
+	}
+
 while(!eof){
 
     float frame_time=0;
@@ -1359,7 +1376,7 @@
     int in_size;
     int skip_flag=0; // 1=skip  -1=duplicate
 
-    if((end_at_type == END_AT_SIZE && end_at <= ftell(muxer_f))  ||
+    if((end_at_type == END_AT_SIZE && end_at <= ftello(muxer_f))  ||
        (end_at_type == END_AT_TIME && end_at < sh_video->timer))
         break;
 
@@ -1372,6 +1389,9 @@
     // get audio:
     while(mux_a->timer-audio_preload<mux_v->timer){
 	int len=0;
+
+	ptimer_start = GetTimerMS();
+
 	if(mux_a->h.dwSampleSize){
 	    // CBR - copy 0.5 sec of audio
 	    switch(mux_a->codec){
@@ -1431,14 +1451,19 @@
 	    mux_a->buffer_len-=len;
 	    memcpy(mux_a->buffer,mux_a->buffer+len,mux_a->buffer_len);
 	}
+
+
+	audiosamples++;
+	audiorate+= (GetTimerMS() - ptimer_start);
     }
 }
 
     // get video frame!
+
     in_size=video_read_frame(sh_video,&frame_time,&start,force_fps);
     if(in_size<0){ eof=1; break; }
     sh_video->timer+=frame_time; ++decoded_frameno;
-    
+
     v_timer_corr-=frame_time-(float)mux_v->h.dwScale/mux_v->h.dwRate;
 
 if(demuxer2){
@@ -1451,7 +1476,7 @@
 	    if(len==4) next_frameno=start[0];
 	}
     if(eof) break;
-	if(skip_flag) printf("!!!!!!!!!!!!\n");
+	// if(skip_flag) printf("!!!!!!!!!!!!\n");
 	skip_flag=next_frameno-decoded_frameno;
     // find next frame:
 	while(next_frameno<=decoded_frameno){
@@ -1503,6 +1528,8 @@
  }
 #endif
 
+ptimer_start = GetTimerMS();
+
 switch(mux_v->codec){
 case VCODEC_COPY:
     mux_v->buffer=start;
@@ -1659,17 +1686,22 @@
     }
 }
 
+videosamples++;
+videorate+=(GetTimerMS() - ptimer_start);
+
 if(skip_flag<0){
     // duplicate frame
-    printf("\nduplicate %d frame(s)!!!    \n",-skip_flag);
+	if(!tv_param_on && !verbose) printf("\nduplicate %d frame(s)!!!    \n",-skip_flag);
     while(skip_flag<0){
+	duplicatedframes++;
 	aviwrite_write_chunk(muxer,mux_v,muxer_f,0,0);
 	++skip_flag;
     }
 } else
 if(skip_flag>0){
     // skip frame
-    printf("\nskip frame!!!    \n");
+	if(!tv_param_on && !verbose) printf("\nskip frame!!!    \n");
+	skippedframes++;
     --skip_flag;
 }
 
@@ -1736,18 +1768,31 @@
 	    (int)demuxer->filepos,
 	    (int)demuxer->movi_end);
 #else
-	mp_msg(MSGT_AVSYNC,MSGL_STATUS,"Pos:%6.1fs %6df (%2d%%) %3dfps Trem:%4dmin %3dmb  A-V:%5.3f [%d:%d]\r",
-	    mux_v->timer, decoded_frameno, (int)(p*100),
-	    (t>1) ? (int)(decoded_frameno/t) : 0,
-	    (p>0.001) ? (int)((t/p-t)/60) : 0, 
-	    (p>0.001) ? (int)(ftell(muxer_f)/p/1024/1024) : 0,
-	    v_pts_corr,
-	    (mux_v->timer>1) ? (int)(mux_v->size/mux_v->timer/125) : 0,
-	    (mux_a && mux_a->timer>1) ? (int)(mux_a->size/mux_a->timer/125) : 0
-	);
+	if(verbose) {
+		mp_msg(MSGT_AVSYNC,MSGL_STATUS,"Pos:%6.1fs %6df (%2d%%) %3dfps Trem:%4dmin %3dmb  A-V:%5.3f [%d:%d] A/Vms %d/%d D/S %d/%d \r",
+	    	mux_v->timer, decoded_frameno, (int)(p*100),
+	    	(t>1) ? (int)(decoded_frameno/t) : 0,
+	    	(p>0.001) ? (int)((t/p-t)/60) : 0, 
+	    	(p>0.001) ? (int)(ftello(muxer_f)/p/1024/1024) : 0,
+	    	v_pts_corr,
+	    	(mux_v->timer>1) ? (int)(mux_v->size/mux_v->timer/125) : 0,
+	    	(mux_a && mux_a->timer>1) ? (int)(mux_a->size/mux_a->timer/125) : 0,
+			audiorate/audiosamples, videorate/videosamples,
+			duplicatedframes, skippedframes
+		);
+	} else {
+		mp_msg(MSGT_AVSYNC,MSGL_STATUS,"Pos:%6.1fs %6df (%2d%%) %3dfps Trem:%4dmin %3dmb  A-V:%5.3f [%d:%d]\r",
+	    		mux_v->timer, decoded_frameno, (int)(p*100),
+	    		(t>1) ? (int)(decoded_frameno/t) : 0,
+	    		(p>0.001) ? (int)((t/p-t)/60) : 0, 
+	    		(p>0.001) ? (int)(ftell(muxer_f)/p/1024/1024) : 0,
+	    		v_pts_corr,
+	    		(mux_v->timer>1) ? (int)(mux_v->size/mux_v->timer/125) : 0,
+	    		(mux_a && mux_a->timer>1) ? (int)(mux_a->size/mux_a->timer/125) : 0
+	    		);
+	}
 #endif
     }
-
         fflush(stdout);
 
 
@@ -1772,7 +1817,7 @@
 
 printf("\nWriting AVI index...\n");
 aviwrite_write_index(muxer,muxer_f);
-muxer_f_size=ftell(muxer_f);
+muxer_f_size=ftello(muxer_f);
 printf("Fixup AVI header...\n");
 fseek(muxer_f,0,SEEK_SET);
 aviwrite_write_header(muxer,muxer_f); // update header
@@ -1785,10 +1830,10 @@
 }
 
 printf("\nVideo stream: %8.3f kbit/s  (%d bps)  size: %d bytes  %5.3f secs  %d frames\n",
-    (float)(mux_v->size/mux_v->timer*8.0f/1000.0f), (int)(mux_v->size/mux_v->timer), mux_v->size, (float)mux_v->timer, decoded_frameno);
+    (float)(mux_v->size/mux_v->timer*8.0f/1000.0f), (int)(mux_v->size/mux_v->timer), (int)mux_v->size, (float)mux_v->timer, decoded_frameno);
 if(sh_audio)
 printf("\nAudio stream: %8.3f kbit/s  (%d bps)  size: %d bytes  %5.3f secs\n",
-    (float)(mux_a->size/mux_a->timer*8.0f/1000.0f), (int)(mux_a->size/mux_a->timer), mux_a->size, (float)mux_a->timer);
+    (float)(mux_a->size/mux_a->timer*8.0f/1000.0f), (int)(mux_a->size/mux_a->timer), (int)mux_a->size, (float)mux_a->timer);
 
 if(stream) free_stream(stream); // kill cache thread
 
Index: main/mplayer.c
===================================================================
RCS file: /cvsroot/mplayer/main/mplayer.c,v
retrieving revision 1.447
diff -u -u -r1.447 mplayer.c
--- main/mplayer.c	25 Mar 2002 03:07:27 -0000	1.447
+++ main/mplayer.c	26 Mar 2002 03:12:49 -0000
@@ -745,6 +745,10 @@
 
 play_next_file:
 
+#ifdef HAVE_TV_BSDBT848
+tv_param_immediate = 1;
+#endif
+
 // We must enable getch2 here to be able to interrupt network connection
 // or cache filling
 if(!use_stdin && !slave_mode){
Index: main/libmpdemux/Makefile
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/Makefile,v
retrieving revision 1.26
diff -u -u -r1.26 Makefile
--- main/libmpdemux/Makefile	24 Mar 2002 02:25:41 -0000	1.26
+++ main/libmpdemux/Makefile	26 Mar 2002 03:12:49 -0000
@@ -4,6 +4,7 @@
 include ../config.mak
 
 SRCS = mp3_hdr.c video.c mpeg_hdr.c cache2.c asfheader.c aviheader.c aviprint.c aviwrite.c demux_asf.c demux_avi.c demux_mov.c parse_mp4.c demux_mpg.c demux_viv.c demuxer.c dvdauth.c open.c parse_es.c stream.c tv.c tvi_dummy.c tvi_v4l.c tvi_bsdbt848.c frequencies.c demux_fli.c demux_real.c demux_y4m.c yuv4mpeg.c yuv4mpeg_ratio.c demux_nuv.c demux_film.c demux_roq.c mf.c demux_mf.c demux_audio.c demux_demuxers.c opt-reg.c mpdemux.c demux_ogg.c demux_bmp.c
+
 ifeq ($(STREAMING),yes)
 SRCS += asf_streaming.c url.c http.c network.c rtp.c
 endif
Index: main/libmpdemux/aviwrite.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/aviwrite.c,v
retrieving revision 1.6
diff -u -u -r1.6 aviwrite.c
--- main/libmpdemux/aviwrite.c	3 Nov 2001 20:57:13 -0000	1.6
+++ main/libmpdemux/aviwrite.c	26 Mar 2002 03:12:49 -0000
@@ -2,6 +2,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/types.h>
 
 #include "config.h"
 
Index: main/libmpdemux/aviwrite.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/aviwrite.h,v
retrieving revision 1.3
diff -u -u -r1.3 aviwrite.h
--- main/libmpdemux/aviwrite.h	3 Nov 2001 20:57:13 -0000	1.3
+++ main/libmpdemux/aviwrite.h	26 Mar 2002 03:12:49 -0000
@@ -10,7 +10,7 @@
   int id;    // stream no
   unsigned int ckid; // chunk id (00dc 01wb etc)
   double timer;
-  unsigned int size;
+  off_t size;
   // buffering:
   unsigned char *buffer;
   unsigned int buffer_size;
Index: main/libmpdemux/demuxer.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/demuxer.c,v
retrieving revision 1.85
diff -u -u -r1.85 demuxer.c
--- main/libmpdemux/demuxer.c	20 Mar 2002 05:15:53 -0000	1.85
+++ main/libmpdemux/demuxer.c	26 Mar 2002 03:12:49 -0000
@@ -213,7 +213,7 @@
 extern tvi_handle_t *tv_handler;
 extern int tv_param_on;
 
-extern int demux_tv_fill_buffer(demuxer_t *demux, tvi_handle_t *tvh);
+extern int demux_tv_fill_buffer(demuxer_t *demux, demux_stream_t *ds, tvi_handle_t *tvh);
 extern int demux_open_tv(demuxer_t *demuxer, tvi_handle_t *tvh);
 #endif
 int demux_y4m_fill_buffer(demuxer_t *demux);
@@ -241,7 +241,7 @@
     case DEMUXER_TYPE_REAL: return demux_real_fill_buffer(demux);
     case DEMUXER_TYPE_NUV: return demux_nuv_fill_buffer(demux);
 #ifdef USE_TV
-    case DEMUXER_TYPE_TV: return demux_tv_fill_buffer(demux, tv_handler);
+    case DEMUXER_TYPE_TV: return demux_tv_fill_buffer(demux, ds, tv_handler);
 #endif
     case DEMUXER_TYPE_Y4M: return demux_y4m_fill_buffer(demux);
     case DEMUXER_TYPE_AUDIO: return demux_audio_fill_buffer(ds);
Index: main/libmpdemux/demuxer.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/demuxer.h,v
retrieving revision 1.35
diff -u -u -r1.35 demuxer.h
--- main/libmpdemux/demuxer.h	20 Mar 2002 05:15:53 -0000	1.35
+++ main/libmpdemux/demuxer.h	26 Mar 2002 03:12:49 -0000
@@ -2,7 +2,11 @@
 #define __DEMUXER_H 1
 
 #define MAX_PACKS 4096
+#ifdef HAVE_TV_BSDBT848
+#define MAX_PACK_BYTES 0x2000000
+#else
 #define MAX_PACK_BYTES 0x800000
+#endif
 
 #define DEMUXER_TYPE_UNKNOWN 0
 #define DEMUXER_TYPE_MPEG_ES 1
Index: main/libmpdemux/tv.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/tv.c,v
retrieving revision 1.25
diff -u -u -r1.25 tv.c
--- main/libmpdemux/tv.c	15 Mar 2002 16:07:06 -0000	1.25
+++ main/libmpdemux/tv.c	26 Mar 2002 03:12:50 -0000
@@ -6,7 +6,7 @@
  API idea based on libvo2
 
  Feb 19, 2002: Significant rewrites by Charles R. Henrich (henrich at msu.edu)
-	       try to fix audio support, and bktr *BSD support.
+				to add support for audio, and bktr *BSD support.
 
 */
 
@@ -37,7 +37,11 @@
 #include "frequencies.h"
 
 /* some default values */
+int tv_param_audiorate = 44100;
 int tv_param_noaudio = 0;
+#ifdef HAVE_TV_BSDBT848
+int tv_param_immediate = 0;
+#endif
 char *tv_param_freq = NULL;
 char *tv_param_channel = NULL;
 char *tv_param_norm = "pal";
@@ -58,57 +62,39 @@
 */
 /* fill demux->video and demux->audio */
 
-int demux_tv_fill_buffer(demuxer_t *demux, tvi_handle_t *tvh)
+int demux_tv_fill_buffer(demuxer_t *demux, demux_stream_t *ds, tvi_handle_t *tvh)
 {
     demux_packet_t* dp;
 
     sh_video_t *sh_video = demux->video->sh;
     u_int len;
-    u_int cframe;
     int aframeswaiting;
 
-    len = cframe = -1;
+    len = 0;
 
     /* ================== ADD AUDIO PACKET =================== */
 
-    if (tv_param_noaudio == 0 && 
+    if (ds==demux->audio && tv_param_noaudio == 0 && 
         tvh->functions->control(tvh->priv, 
                                 TVI_CONTROL_IS_AUDIO, 0) == TVI_CONTROL_TRUE)
         {
         len = tvh->functions->get_audio_framesize(tvh->priv);
 
-        do {
-            dp=new_demux_packet(len);
-            aframeswaiting=tvh->functions->grab_audio_frame(tvh->priv,
-                                                            dp->buffer,len);
-            dp->pts=tvh->seq/sh_video->fps;
-            dp->pos=tvh->seq*len;
-            ds_add_packet(demux->audio,dp);
-
-            tvh->seq++;
-
-           } while (aframeswaiting > 0);
+        dp=new_demux_packet(len);
+        dp->pts=tvh->functions->grab_audio_frame(tvh->priv, dp->buffer,len);
+        ds_add_packet(demux->audio,dp);
         }
 
     /* ================== ADD VIDEO PACKET =================== */
 
-    if (tvh->functions->control(tvh->priv, 
+    if (ds==demux->video && tvh->functions->control(tvh->priv, 
                             TVI_CONTROL_IS_VIDEO, 0) == TVI_CONTROL_TRUE)
         {
-        len = tvh->functions->get_video_framesize(tvh->priv);
-
-        dp=new_demux_packet(len);
-
-        cframe=tvh->functions->grab_video_frame(tvh->priv, dp->buffer, 
-                                                len);
-
-        if(tv_param_noaudio == 1) tvh->seq = cframe;
-
-        dp->pos=tvh->seq*len;
-        dp->pts=tvh->seq/sh_video->fps;
-
-        ds_add_packet(demux->video,dp);
-        }
+		len = tvh->functions->get_video_framesize(tvh->priv);
+       	dp=new_demux_packet(len);
+  		dp->pts=tvh->functions->grab_video_frame(tvh->priv, dp->buffer, len);
+   		ds_add_packet(demux->video,dp);
+		}
 
     return 1;
 }
@@ -190,7 +176,7 @@
     if (funcs->control(tvh->priv, TVI_CONTROL_IS_TUNER, 0) != TVI_CONTROL_TRUE)
     {
 	mp_msg(MSGT_TV, MSGL_WARN, "Selected input hasn't got a tuner!\n");	
-	goto start_device;
+	goto done;
     }
 
     /* select channel list */
@@ -214,7 +200,7 @@
     if (tv_param_freq && tv_param_channel)
     {
 	mp_msg(MSGT_TV, MSGL_WARN, "You can't set frequency and channel simultanly!\n");
-	goto start_device;
+	goto done;
     }
 
     /* we need to set frequency */
@@ -251,9 +237,9 @@
 	}
     }
 
-start_device:    
+done:    
     /* also start device! */
-    return(funcs->start(tvh->priv));	
+	return 1;
 }
 
 int demux_open_tv(demuxer_t *demuxer, tvi_handle_t *tvh)
@@ -261,6 +247,8 @@
     sh_video_t *sh_video = NULL;
     sh_audio_t *sh_audio = NULL;
     tvi_functions_t *funcs = tvh->functions;
+
+fprintf(stderr,"DEMUXOPEN\n");
     
     sh_video = new_sh_video(demuxer, 0);
 
@@ -286,6 +274,15 @@
 
     printf("fps: %f, frametime: %f\n", sh_video->fps, sh_video->frametime);
 
+#ifdef HAVE_TV_BSDBT848
+    /* If playback only mode, go to immediate mode, fail silently */
+    if(tv_param_immediate == 1)
+        {
+        funcs->control(tvh->priv, TVI_CONTROL_IMMEDIATE, 0);
+        tv_param_noaudio = 1; 
+        }
+#endif
+
     /* set width */
     funcs->control(tvh->priv, TVI_CONTROL_VID_GET_WIDTH, &sh_video->disp_w);
 
@@ -333,8 +330,14 @@
 		goto no_audio;
 	}
 	
+	funcs->control(tvh->priv, TVI_CONTROL_AUD_SET_SAMPLERATE, 
+				  &tv_param_audiorate);
+
 	sh_audio = new_sh_audio(demuxer, 0);
-	sh_audio->wf = (WAVEFORMATEX *)malloc(sizeof(WAVEFORMATEX));
+    sh_audio->wf = (WAVEFORMATEX *)malloc(sizeof(WAVEFORMATEX));
+
+    sh_audio->format = sh_audio_format;
+	sh_audio->sample_format = audio_format;
 
 	funcs->control(tvh->priv, TVI_CONTROL_AUD_GET_SAMPLERATE, 
                    &sh_audio->samplerate);
@@ -343,45 +346,33 @@
 	funcs->control(tvh->priv, TVI_CONTROL_AUD_GET_CHANNELS, 
                    &sh_audio->channels);
 
-	sh_audio->format = sh_audio_format;
-	sh_audio->sample_format = audio_format;
-
-	sh_audio->i_bps = sh_audio->o_bps =
-	    sh_audio->samplerate * sh_audio->samplesize/8 * 
-	    sh_audio->channels;
-
-	sh_audio->wf->wFormatTag = sh_audio->format;
-	sh_audio->wf->nChannels = sh_audio->channels;
-	switch(audio_format)
-	{
-	    case AFMT_U8:
-	    case AFMT_S8:
-		sh_audio->wf->wBitsPerSample = 8;
-		break;
-	    case AFMT_U16_LE:
-	    case AFMT_U16_BE:
-	    case AFMT_S16_LE:
-	    case AFMT_S16_BE:
-		sh_audio->wf->wBitsPerSample = 16;
-		break;
-	    case AFMT_S32_LE:
-	    case AFMT_S32_BE:
-		sh_audio->wf->wBitsPerSample = 32;
-		break;
-	}
-	sh_audio->wf->nSamplesPerSec = sh_audio->samplerate;
-	sh_audio->wf->nBlockAlign = sh_audio->wf->nAvgBytesPerSec;
-	sh_audio->wf->nAvgBytesPerSec = sh_audio->wf->nChannels * 
-                                    sh_audio->samplesize/8 * 
-                                    sh_audio->samplerate;
-
+    sh_audio->wf->nBlockAlign = sh_audio->wf->nAvgBytesPerSec;
 	demuxer->audio->sh = sh_audio;
 	sh_audio->ds = demuxer->audio;
 	demuxer->audio->id = 0;
+
+    sh_audio->o_bps = sh_audio->samplerate * sh_audio->samplesize * 
+                      sh_audio->channels;
+    sh_audio->i_bps = sh_audio->samplerate * sh_audio->samplesize * 
+                      sh_audio->channels;
+
+    // uncompressed PCM format
+    sh_audio->wf->wFormatTag = sh_audio->format;
+    sh_audio->wf->nChannels = sh_audio->channels;
+    sh_audio->wf->wBitsPerSample = sh_audio->samplesize*8;
+    sh_audio->wf->nSamplesPerSec = sh_audio->samplerate;
+    sh_audio->wf->nAvgBytesPerSec = sh_audio->wf->nChannels * 
+                                    sh_audio->samplesize * 
+                                    sh_audio->samplerate;
+
+    mp_msg(MSGT_DECVIDEO, MSGL_V, "  TV audio: %d channels, %d bits, %d Hz\n",
+          sh_audio->wf->nChannels, sh_audio->wf->wBitsPerSample,
+          sh_audio->wf->nSamplesPerSec);
+
     }
 no_audio:
 
-    return(1);
+    return(funcs->start(tvh->priv));	
 }
 
 /* ================== STREAM_TV ===================== */
Index: main/libmpdemux/tv.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/tv.h,v
retrieving revision 1.13
diff -u -u -r1.13 tv.h
--- main/libmpdemux/tv.h	15 Mar 2002 17:58:19 -0000	1.13
+++ main/libmpdemux/tv.h	26 Mar 2002 03:12:50 -0000
@@ -21,6 +21,8 @@
 extern char *tv_param_outfmt;
 extern float tv_param_fps;
 extern int tv_param_noaudio;
+extern int tv_param_immediate;
+extern int tv_param_audiorate;
 
 typedef struct tvi_info_s
 {
@@ -36,9 +38,12 @@
     int (*uninit)();
     int (*control)();
     int (*start)();
-    int (*grab_video_frame)();
+    double (*grab_video_frame)();
+#ifdef HAVE_TV_BSDBT848
+    double (*grabimmediate_video_frame)();
+#endif
     int (*get_video_framesize)();
-    int (*grab_audio_frame)();
+    double (*grab_audio_frame)();
     int (*get_audio_framesize)();
 } tvi_functions_t;
 
@@ -67,6 +72,9 @@
 #define TVI_CONTROL_IS_AUDIO		0x1
 #define TVI_CONTROL_IS_VIDEO		0x2
 #define TVI_CONTROL_IS_TUNER		0x3
+#ifdef HAVE_TV_BSDBT848
+#define TVI_CONTROL_IMMEDIATE       0x4
+#endif
 
 /* VIDEO controls */
 #define TVI_CONTROL_VID_GET_FPS		0x101
@@ -107,6 +115,7 @@
 #define TVI_CONTROL_AUD_GET_SAMPLERATE	0x302
 #define TVI_CONTROL_AUD_GET_SAMPLESIZE	0x303
 #define TVI_CONTROL_AUD_GET_CHANNELS	0x304
+#define TVI_CONTROL_AUD_SET_SAMPLERATE	0x305
 
 /* SPECIFIC controls */
 #define TVI_CONTROL_SPC_GET_INPUT	0x401	/* set input channel (tv,s-video,composite..) */
Index: main/libmpdemux/tvi_def.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/tvi_def.h,v
retrieving revision 1.6
diff -u -u -r1.6 tvi_def.h
--- main/libmpdemux/tvi_def.h	27 Dec 2001 23:52:48 -0000	1.6
+++ main/libmpdemux/tvi_def.h	26 Mar 2002 03:12:50 -0000
@@ -4,9 +4,12 @@
 static int uninit(priv_t *priv);
 static int control(priv_t *priv, int cmd, void *arg);
 static int start(priv_t *priv);
-static int grab_video_frame(priv_t *priv, char *buffer, int len);
+static double grab_video_frame(priv_t *priv, char *buffer, int len);
+#ifdef HAVE_TV_BSDBT848
+static double grabimmediate_video_frame(priv_t *priv, char *buffer, int len);
+#endif
 static int get_video_framesize(priv_t *priv);
-static int grab_audio_frame(priv_t *priv, char *buffer, int len);
+static double grab_audio_frame(priv_t *priv, char *buffer, int len);
 static int get_audio_framesize(priv_t *priv);
 
 static tvi_functions_t functions =
@@ -16,6 +19,9 @@
     control,
     start,
     grab_video_frame,
+#ifdef HAVE_TV_BSDBT848
+    grabimmediate_video_frame,
+#endif
     get_video_framesize,
     grab_audio_frame,
     get_audio_framesize
Index: main/libmpdemux/tvi_dummy.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/tvi_dummy.c,v
retrieving revision 1.7
diff -u -u -r1.7 tvi_dummy.c
--- main/libmpdemux/tvi_dummy.c	27 Dec 2001 23:52:48 -0000	1.7
+++ main/libmpdemux/tvi_dummy.c	26 Mar 2002 03:12:50 -0000
@@ -86,7 +86,15 @@
     return(TVI_CONTROL_UNKNOWN);
 }
 
-static int grab_video_frame(priv_t *priv, char *buffer, int len)
+#ifdef HAVE_TV_BSDBT848
+static double grabimmediate_video_frame(priv_t *priv, char *buffer, int len)
+{
+    memset(buffer, 0xCC, len);
+    return(1);
+}
+#endif
+
+static double grab_video_frame(priv_t *priv, char *buffer, int len)
 {
     memset(buffer, 0x42, len);
     return(1);
@@ -98,7 +106,7 @@
     return(priv->width*priv->height*12/8);
 }
 
-static int grab_audio_frame(priv_t *priv, char *buffer, int len)
+static double grab_audio_frame(priv_t *priv, char *buffer, int len)
 {
     memset(buffer, 0x42, len);
     return(1);
Index: main/libmpdemux/tvi_v4l.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/tvi_v4l.c,v
retrieving revision 1.19
diff -u -u -r1.19 tvi_v4l.c
--- main/libmpdemux/tvi_v4l.c	15 Mar 2002 16:08:14 -0000	1.19
+++ main/libmpdemux/tvi_v4l.c	26 Mar 2002 03:12:50 -0000
@@ -63,7 +63,6 @@
     struct video_mmap		*buf;
     int				nbuf;
     int				queue;
-	int				currentframe;
 
     /* audio */
     int				audio_id;
@@ -812,8 +811,6 @@
     int frame = priv->queue % priv->nbuf;
     int nextframe = (priv->queue+1) % priv->nbuf;
 
-	priv->currentframe++;
-
     mp_dbg(MSGT_TV, MSGL_DBG2, "grab_video_frame(priv=%p, buffer=%p, len=%d)\n",
 	priv, buffer, len);
 
@@ -841,7 +838,7 @@
     /* copy the actual frame */
     memcpy(buffer, priv->mmap+priv->mbuf.offsets[frame], len);
 
-    return(priv->currentframe);
+    return(0);
 }
 
 static int get_video_framesize(priv_t *priv)
Index: main/libmpdemux/video.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/video.c,v
retrieving revision 1.12
diff -u -u -r1.12 video.c
--- main/libmpdemux/video.c	16 Mar 2002 19:58:07 -0000	1.12
+++ main/libmpdemux/video.c	26 Mar 2002 03:12:50 -0000
@@ -291,6 +291,10 @@
           sh_video->fps=1.0f/d;
         }
     } else
+    if(demuxer->file_format==DEMUXER_TYPE_TV && !force_fps){
+        // TV has variable video frame rate, fixed audio...
+	frame_time=d_video->pts-pts1;
+	} else
     if(demuxer->file_format==DEMUXER_TYPE_MOV && !force_fps){
         // .MOV files has no fixed FPS - just frame durations!
 	frame_time=d_video->pts-pts1;
-------------- next part --------------
diff -u -r bktr.orig/CHANGELOG.TXT bktr/CHANGELOG.TXT
--- bktr.orig/CHANGELOG.TXT	Wed Nov  1 20:36:14 2000
+++ bktr/CHANGELOG.TXT	Tue Feb 19 11:37:38 2002
@@ -518,4 +518,9 @@
                   support for audio on Hauppauge cards without the audio mux.
                   The MSP is used for audio selection. (the 44xxx models)
 
-
+2.19  19 Feb 2002 Charles Henrich (henrich at sigbus.com)
+                  Modified frame synchronization code to allow arbitrary
+                  field pattern matchin (i.e. 2 even, 1 odd makes one clean
+                  frame).  This is probably bogus, but necessary for YUV format
+                  capture and frame signaling.  (its also cleaner code in my
+                  book :)
diff -u -r bktr.orig/bktr_core.c bktr/bktr_core.c
--- bktr.orig/bktr_core.c	Wed Nov  1 20:36:14 2000
+++ bktr/bktr_core.c	Tue Feb 19 11:43:40 2002
@@ -730,21 +730,6 @@
 		OUTB(bktr, BKTR_TDEC, 0);
 		OUTB(bktr, BKTR_TDEC, tdec_save);
 		
-		/*  Reset to no-fields captured state  */
-		if (bktr->flags & (METEOR_CONTIN | METEOR_SYNCAP)) {
-			switch(bktr->flags & METEOR_ONLY_FIELDS_MASK) {
-			case METEOR_ONLY_ODD_FIELDS:
-				bktr->flags |= METEOR_WANT_ODD;
-				break;
-			case METEOR_ONLY_EVEN_FIELDS:
-				bktr->flags |= METEOR_WANT_EVEN;
-				break;
-			default:
-				bktr->flags |= METEOR_WANT_MASK;
-				break;
-			}
-		}
-
 		OUTL(bktr, BKTR_RISC_STRT_ADD, vtophys(bktr->dma_prog));
 		OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_ENABLED);
 		OUTW(bktr, BKTR_GPIO_DMA_CTL, bktr->capcontrol);
@@ -780,6 +765,8 @@
 	/* Determine which field generated this interrupt */
 	field = ( bktr_status & BT848_INT_FIELD ) ? EVEN_F : ODD_F;
 
+	if(field == ODD_F) bktr->sync_fields++;
+	else			   bktr->sync_fields+=0x10;
 
 	/*
 	 * Process the VBI data if it is being captured. We do this once
@@ -803,61 +790,20 @@
 			selwakeup(&bktr->vbi_select);
 		}
 
-
-	}
-
-
-	/*
-	 *  Register the completed field
-	 *    (For dual-field mode, require fields from the same frame)
-	 */
-	switch ( bktr->flags & METEOR_WANT_MASK ) {
-		case METEOR_WANT_ODD  : w_field = ODD_F         ;  break;
-		case METEOR_WANT_EVEN : w_field = EVEN_F        ;  break;
-		default               : w_field = (ODD_F|EVEN_F);  break;
-	}
-	switch ( bktr->flags & METEOR_ONLY_FIELDS_MASK ) {
-		case METEOR_ONLY_ODD_FIELDS  : req_field = ODD_F  ;  break;
-		case METEOR_ONLY_EVEN_FIELDS : req_field = EVEN_F ;  break;
-		default                      : req_field = (ODD_F|EVEN_F);  
-			                       break;
 	}
 
-	if (( field == EVEN_F ) && ( w_field == EVEN_F ))
-		bktr->flags &= ~METEOR_WANT_EVEN;
-	else if (( field == ODD_F ) && ( req_field == ODD_F ) &&
-		 ( w_field == ODD_F ))
-		bktr->flags &= ~METEOR_WANT_ODD;
-	else if (( field == ODD_F ) && ( req_field == (ODD_F|EVEN_F) ) &&
-		 ( w_field == (ODD_F|EVEN_F) ))
-		bktr->flags &= ~METEOR_WANT_ODD;
-	else if (( field == ODD_F ) && ( req_field == (ODD_F|EVEN_F) ) &&
-		 ( w_field == ODD_F )) {
-		bktr->flags &= ~METEOR_WANT_ODD;
-		bktr->flags |=  METEOR_WANT_EVEN;
-	}
-	else {
-		/*  We're out of sync.  Start over.  */
-		if (bktr->flags & (METEOR_CONTIN | METEOR_SYNCAP)) {
-			switch(bktr->flags & METEOR_ONLY_FIELDS_MASK) {
-			case METEOR_ONLY_ODD_FIELDS:
-				bktr->flags |= METEOR_WANT_ODD;
-				break;
-			case METEOR_ONLY_EVEN_FIELDS:
-				bktr->flags |= METEOR_WANT_EVEN;
-				break;
-			default:
-				bktr->flags |= METEOR_WANT_MASK;
-				break;
-			}
-		}
+	if(bktr->sync_fields > bktr->sync_match) {
+	/* printf("Out of sync, starting over %x > %x\n", bktr->sync_fields, bktr->sync_match); */
+		bktr->sync_fields = 0;
 		return 1;
 	}
 
 	/*
 	 * If we have a complete frame.
 	 */
-	if (!(bktr->flags & METEOR_WANT_MASK)) {
+	if ((bktr->sync_fields & bktr->sync_match) == bktr->sync_match) {
+
+		bktr->sync_fields = 0;
 		bktr->frames_captured++;
 		/*
 		 * post the completion time. 
@@ -913,19 +859,6 @@
 * As a consequence, this fourth mode is currently unsupported.
 */
 
-		if (bktr->flags & (METEOR_CONTIN | METEOR_SYNCAP)) {
-			switch(bktr->flags & METEOR_ONLY_FIELDS_MASK) {
-			case METEOR_ONLY_ODD_FIELDS:
-				bktr->flags |= METEOR_WANT_ODD;
-				break;
-			case METEOR_ONLY_EVEN_FIELDS:
-				bktr->flags |= METEOR_WANT_EVEN;
-				break;
-			default:
-				bktr->flags |= METEOR_WANT_MASK;
-				break;
-			}
-		}
 	}
 
 	return 1;
@@ -1023,6 +956,8 @@
 	bktr->frames_captured = 0;
 	bktr->even_fields_captured = 0;
 	bktr->odd_fields_captured = 0;
+    bktr->sync_fields = 0;
+    bktr->sync_match = SYNC_RGB;
 	bktr->proc = (struct proc *)0;
 	set_fps(bktr, frame_rate);
 	bktr->video.addr = 0;
@@ -1770,17 +1705,21 @@
 			case 0:			/* default */
 			case METEOR_GEO_RGB16:
 				    bktr->format = METEOR_GEO_RGB16;
+					bktr->sync_match = SYNC_RGB;
 				    break;
 			case METEOR_GEO_RGB24:
 				    bktr->format = METEOR_GEO_RGB24;
+					bktr->sync_match = SYNC_RGB;
 				    break;
 			case METEOR_GEO_YUV_422:
 				    bktr->format = METEOR_GEO_YUV_422;
                                     if (geo->oformat & METEOR_GEO_YUV_12) 
 					bktr->format = METEOR_GEO_YUV_12;
+					bktr->sync_match = SYNC_YUV;
 				    break;
 			case METEOR_GEO_YUV_PACKED:
 				    bktr->format = METEOR_GEO_YUV_PACKED;
+					bktr->sync_match = SYNC_YUV;
 				    break;
 			}
 			bktr->pixfmt = oformat_meteor_to_bt( bktr->format );
@@ -1810,6 +1749,10 @@
 						    BT848_INT_FMTCHG);
 			}
 		}
+
+		if (geo->oformat & METEOR_GEO_ODD_ONLY) bktr->sync_match &= SYNC_ODD;
+		if (geo->oformat & METEOR_GEO_EVEN_ONLY) bktr->sync_match &= SYNC_EVEN;
+
 		break;
 	/* end of METEORSETGEO */
 
diff -u -r bktr.orig/bktr_reg.h bktr/bktr_reg.h
--- bktr.orig/bktr_reg.h	Wed Nov  1 20:36:14 2000
+++ bktr/bktr_reg.h	Tue Feb 19 11:44:32 2002
@@ -613,6 +613,12 @@
     int		frame_size;	/* number of bytes in a frame */
     u_long	fifo_errors;	/* number of fifo capture errors since open */
     u_long	dma_errors;	/* number of DMA capture errors since open */
+#define SYNC_YUV  0x00000012
+#define SYNC_RGB  0x00000011
+#define SYNC_ODD  0x0000000F
+#define SYNC_EVEN 0x000000F0
+    u_int   sync_match;
+    u_int   sync_fields;
     u_long	frames_captured;/* number of frames captured since open */
     u_long	even_fields_captured; /* number of even fields captured */
     u_long	odd_fields_captured; /* number of odd fields captured */


More information about the MPlayer-dev-eng mailing list