From brandt@fokus.gmd.de  Thu Mar 28 01:25:16 2002
Return-Path: <brandt@fokus.gmd.de>
Received: from mailhub.fokus.gmd.de (mailhub.fokus.gmd.de [193.174.154.14])
	by hub.freebsd.org (Postfix) with ESMTP id B180637B416
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 28 Mar 2002 01:25:15 -0800 (PST)
Received: from fokus.gmd.de (beagle [193.175.132.100])
	by mailhub.fokus.gmd.de (8.11.6/8.11.6) with ESMTP id g2S9PDL17868
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 28 Mar 2002 10:25:13 +0100 (MET)
Received: (from root@localhost)
	by fokus.gmd.de (8.11.6/8.11.0) id g2S9PD413433;
	Thu, 28 Mar 2002 10:25:13 +0100 (CET)
	(envelope-from hbb)
Message-Id: <200203280925.g2S9PD413433@fokus.gmd.de>
Date: Thu, 28 Mar 2002 10:25:13 +0100 (CET)
From: Hartmut Brandt <brandt@fokus.gmd.de>
Reply-To: Hartmut Brandt <brandt@fokus.gmd.de>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: the bktr driver incorrectly handles the setting of frame rates
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         36415
>Category:       kern
>Synopsis:       [bktr] [patch] driver incorrectly handles the setting of frame rates
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Mar 28 01:30:01 PST 2002
>Closed-Date:    
>Last-Modified:  Thu Nov 04 08:16:50 GMT 2004
>Originator:     Hartmut Brandt
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
FhI Fokus
>Environment:
System: FreeBSD beagle.fokus.gmd.de 5.0-CURRENT FreeBSD 5.0-CURRENT #31: Wed Mar 27 14:48:19 CET 2002 hbb@beagle.fokus.gmd.de:/opt/obj/usr/src/sys/BEAGLE i386


	
>Description:

In the case when the driver captures both fields of a frame the temporal
decimation register is incorrectly set. This leads to a wrong resulting
frame rate. The register is set to drop frames not fields (by setting bit
7 to zero). Therefor the number of dropped items need not to be multiplied by
2 for the case when both fields are captured for a frame. The chip itself takes
care for dropping both fields of the dropped frame.

As a sidenote:

(2) Bktr fails to compile if BT848_DUMP is defined.

>How-To-Repeat:

Use an application that captures full size PAL and request a frame
of 12 fps from the driver. Observe the frame rate dropping to 1 fps.

This is due the computation in bktr_core.c:set_fps(). When both WANT
flags are 1 (capturing both fields) the difference between the maximum frame
rate (25 for PAL) and the requested frame rate (12) is multiplied by two
falsely assuming, that the register must contain the number of fields to drop.
This yields a value of 24 and the chip drops 24 out of 25 frames resulting
in a frame rate of 1.

(2) Define BT848_DUMP and observe the compile to fail.

>Fix:

Apply the following patch. This corrects both problems:


Index: bktr_core.c
===================================================================
RCS file: /usr/ncvs/src/sys/dev/bktr/bktr_core.c,v
retrieving revision 1.118
diff -u -r1.118 bktr_core.c
--- bktr_core.c	14 Mar 2002 01:32:21 -0000	1.118
+++ bktr_core.c	28 Mar 2002 09:15:56 -0000
@@ -962,7 +962,7 @@
 	bktr->flags |= METEOR_OPEN;
 
 #ifdef BT848_DUMP
-	dump_bt848( bt848 );
+	dump_bt848(bktr);
 #endif
 
         bktr->clr_on_start = FALSE;
@@ -1640,7 +1640,7 @@
 			                    BT848_INT_VSYNC      |
 					    BT848_INT_FMTCHG);
 #ifdef BT848_DUMP
-			dump_bt848( bt848 );
+			dump_bt848(bktr);
 #endif
 			break;
 		
@@ -2473,7 +2473,7 @@
 /*
  * 
  */
-#ifdef BT848_DEBUG 
+#if defined(BT848_DEBUG) || defined(BT848_DUMP)
 static int
 dump_bt848( bktr_ptr_t bktr )
 {
@@ -2493,7 +2493,7 @@
 		       r[i], INL(bktr, r[i]),
 		       r[i+1], INL(bktr, r[i+1]),
 		       r[i+2], INL(bktr, r[i+2]),
-		       r[i+3], INL(bktr, r[i+3]]));
+		       r[i+3], INL(bktr, r[i+3]));
 	}
 
 	printf("%s: INT STAT %x \n", bktr_name(bktr),
@@ -3657,28 +3657,26 @@
 
 
 /*
- * 
+ * Set the temporal decimation register to get the desired frame rate.
+ * We use the 'skip frame' modus always and always start dropping on an
+ * odd field.
  */
 static void
 set_fps( bktr_ptr_t bktr, u_short fps )
 {
 	struct format_params	*fp;
-	int i_flag;
 
 	fp = &format_params[bktr->format_params];
 
 	switch(bktr->flags & METEOR_ONLY_FIELDS_MASK) {
 	case METEOR_ONLY_EVEN_FIELDS:
 		bktr->flags |= METEOR_WANT_EVEN;
-		i_flag = 1;
 		break;
 	case METEOR_ONLY_ODD_FIELDS:
 		bktr->flags |= METEOR_WANT_ODD;
-		i_flag = 1;
 		break;
 	default:
 		bktr->flags |= METEOR_WANT_MASK;
-		i_flag = 2;
 		break;
 	}
 
@@ -3689,7 +3687,7 @@
 	OUTB(bktr, BKTR_TDEC, 0);
 
 	if (fps < fp->frame_rate)
-		OUTB(bktr, BKTR_TDEC, i_flag*(fp->frame_rate - fps) & 0x3f);
+		OUTB(bktr, BKTR_TDEC, (fp->frame_rate - fps) & 0x3f);
 	else
 		OUTB(bktr, BKTR_TDEC, 0);
 	return;
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->roger 
Responsible-Changed-By: johan 
Responsible-Changed-When: Tue Aug 20 14:18:42 PDT 2002 
Responsible-Changed-Why:  
Over to bktr maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=36415 
Responsible-Changed-From-To: roger->freebsd-bugs 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Thu Nov 4 08:15:53 GMT 2004 
Responsible-Changed-Why:  
Assignee is currently away from doing FreeBSD work at the moment, so 
at his request, return this one to the pool. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=36415 
>Unformatted:
