All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] v4l2-utils: miscellaneous fixes in cvt, gtf modeline
@ 2015-06-16  9:17 Prashant Laddha
  2015-06-16  9:17 ` [PATCH 1/3] v4l2-utils: handle interlace fraction correctly in gtf Prashant Laddha
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Prashant Laddha @ 2015-06-16  9:17 UTC (permalink / raw)
  To: linux-media

Hi,

Recently, while testing reduced blanking implementation, I came across few differences
between the results produced by cvt, gtf modeline implementation and results given by
standards spreadsheet. The resultant timing differences were minor and seen only for
few input combinations. However, it would be good to have it fixed. Please find the
fixes for the same.

Regards,
Prashant

Prashant Laddha (3):
  v4l2-utils: handle interlace fraction correctly in gtf
  v4l2-utils gtf: use round instead of roundown for v_lines_rnd
  v4l2-utils: fix pixel clock calc for cvt reduced blanking

 utils/v4l2-ctl/v4l2-ctl-modes.cpp | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)

-- 
1.9.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] v4l2-utils: handle interlace fraction correctly in gtf
  2015-06-16  9:17 [PATCH 0/3] v4l2-utils: miscellaneous fixes in cvt, gtf modeline Prashant Laddha
@ 2015-06-16  9:17 ` Prashant Laddha
  2015-06-16  9:17 ` [PATCH 2/3] v4l2-utils gtf: use round instead of roundown for v_lines_rnd Prashant Laddha
  2015-06-16  9:17 ` [PATCH 3/3] v4l2-utils: fix pixel clock calc for cvt reduced blanking Prashant Laddha
  2 siblings, 0 replies; 4+ messages in thread
From: Prashant Laddha @ 2015-06-16  9:17 UTC (permalink / raw)
  To: linux-media; +Cc: Hans Verkuil, Prashant Laddha

For interlaced format, the standards equation use interlace = 0.5.
Modified the implementation to handle this fraction correctly.

Cc: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Prashant Laddha <prladdha@cisco.com>
---
 utils/v4l2-ctl/v4l2-ctl-modes.cpp | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/utils/v4l2-ctl/v4l2-ctl-modes.cpp b/utils/v4l2-ctl/v4l2-ctl-modes.cpp
index 7422bc5..ef528c0 100644
--- a/utils/v4l2-ctl/v4l2-ctl-modes.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl-modes.cpp
@@ -229,7 +229,6 @@ bool calc_cvt_modeline(int image_width, int image_height,
 
 		h_bp = h_blank / 2;
 		h_fp = h_blank - h_bp - h_sync;
-
 	} else {
 		/* Reduced blanking */
 
@@ -424,12 +423,12 @@ bool calc_gtf_modeline(int image_width, int image_height,
 	active_h_pixel = h_pixel_rnd;
 	active_v_lines = v_lines_rnd;
 
-		/* estimate the horizontal period */
+	/* estimate the horizontal period */
 	tmp1 = HV_FACTOR * 1000000  -
 		   GTF_MIN_VSYNC_BP * HV_FACTOR * v_refresh;
-	tmp2 = active_v_lines + GTF_MIN_PORCH + interlace;
+	tmp2 = 2 * (active_v_lines + GTF_MIN_PORCH) + interlace;
 
-	h_period_est = tmp1 / (tmp2 * v_refresh);
+	h_period_est = 2 * tmp1 / (tmp2 * v_refresh);
 
 	v_sync_bp = GTF_MIN_VSYNC_BP * HV_FACTOR * 100 / h_period_est;
 	v_sync_bp = (v_sync_bp + 50) / 100;
@@ -439,10 +438,10 @@ bool calc_gtf_modeline(int image_width, int image_height,
 	v_fp = GTF_MIN_PORCH;
 
 	v_blank = v_sync + v_bp + v_fp;
-	total_v_lines = active_v_lines + v_blank + interlace;
+	total_v_lines = active_v_lines + v_blank;
 
-	v_refresh_est = (HV_FACTOR * (long long)1000000) /
-			(h_period_est * total_v_lines / HV_FACTOR);
+	v_refresh_est = (2 * HV_FACTOR * (long long)1000000) /
+			(h_period_est * (2 * total_v_lines + interlace) / HV_FACTOR);
 
 	h_period = ((long long)h_period_est * v_refresh_est) /
 		   (v_refresh * HV_FACTOR);
@@ -454,12 +453,10 @@ bool calc_gtf_modeline(int image_width, int image_height,
 		ideal_blank_duty_cycle = (GTF_S_C_PRIME * HV_FACTOR) -
 				      GTF_S_M_PRIME * h_period / 1000;
 
-
 	h_blank = active_h_pixel * (long long)ideal_blank_duty_cycle /
 			 (100 * HV_FACTOR - ideal_blank_duty_cycle);
 	h_blank = ((h_blank + GTF_CELL_GRAN) / (2 * GTF_CELL_GRAN))
 			  * (2 * GTF_CELL_GRAN);
-
 	total_h_pixel = active_h_pixel + h_blank;
 
 	h_sync = (total_h_pixel * GTF_HSYNC_PERCENT) / 100;
@@ -475,7 +472,6 @@ bool calc_gtf_modeline(int image_width, int image_height,
 	 * truncation
 	 * */
 	/*pixel_clock -= pixel_clock  % GTF_PXL_CLK_GRAN;*/
-
 	gtf->standards 	 = V4L2_DV_BT_STD_GTF;
 
 	gtf->width       = h_pixel;
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] v4l2-utils gtf: use round instead of roundown for v_lines_rnd
  2015-06-16  9:17 [PATCH 0/3] v4l2-utils: miscellaneous fixes in cvt, gtf modeline Prashant Laddha
  2015-06-16  9:17 ` [PATCH 1/3] v4l2-utils: handle interlace fraction correctly in gtf Prashant Laddha
@ 2015-06-16  9:17 ` Prashant Laddha
  2015-06-16  9:17 ` [PATCH 3/3] v4l2-utils: fix pixel clock calc for cvt reduced blanking Prashant Laddha
  2 siblings, 0 replies; 4+ messages in thread
From: Prashant Laddha @ 2015-06-16  9:17 UTC (permalink / raw)
  To: linux-media; +Cc: Hans Verkuil, Prashant Laddha

GTF standards document specifies to use round() for v_lines_rnd
calculations. This change will affect only if image height is odd.

Cc: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Prashant Laddha <prladdha@cisco.com>
---
 utils/v4l2-ctl/v4l2-ctl-modes.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/utils/v4l2-ctl/v4l2-ctl-modes.cpp b/utils/v4l2-ctl/v4l2-ctl-modes.cpp
index ef528c0..d65cd75 100644
--- a/utils/v4l2-ctl/v4l2-ctl-modes.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl-modes.cpp
@@ -410,7 +410,7 @@ bool calc_gtf_modeline(int image_width, int image_height,
 
 	if (interlaced) {
 		interlace = 1;
-		v_lines_rnd = v_lines / 2;
+		v_lines_rnd = (v_lines + 1) / 2;
 		v_refresh = v_refresh * 2;
 	} else {
 		interlace = 0;
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] v4l2-utils: fix pixel clock calc for cvt reduced blanking
  2015-06-16  9:17 [PATCH 0/3] v4l2-utils: miscellaneous fixes in cvt, gtf modeline Prashant Laddha
  2015-06-16  9:17 ` [PATCH 1/3] v4l2-utils: handle interlace fraction correctly in gtf Prashant Laddha
  2015-06-16  9:17 ` [PATCH 2/3] v4l2-utils gtf: use round instead of roundown for v_lines_rnd Prashant Laddha
@ 2015-06-16  9:17 ` Prashant Laddha
  2 siblings, 0 replies; 4+ messages in thread
From: Prashant Laddha @ 2015-06-16  9:17 UTC (permalink / raw)
  To: linux-media; +Cc: Hans Verkuil, Prashant Laddha

In case of CVT reduced blanking, pixel clock calculation does not
use h period estimates, it rather directly uses refresh rate and
total vertical lines. This difference can lead to a minor mismatch
between the pixel clocks calculated by v4l2-utils and the standards
spreadsheet.

Cc: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Prashant Laddha <prladdha@cisco.com>
---
 utils/v4l2-ctl/v4l2-ctl-modes.cpp | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/utils/v4l2-ctl/v4l2-ctl-modes.cpp b/utils/v4l2-ctl/v4l2-ctl-modes.cpp
index d65cd75..7768998 100644
--- a/utils/v4l2-ctl/v4l2-ctl-modes.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl-modes.cpp
@@ -139,6 +139,7 @@ bool calc_cvt_modeline(int image_width, int image_height,
 	int active_h_pixel;
 	int active_v_lines;
 	int total_h_pixel;
+	int total_v_lines;
 
 	int h_blank;
 	int v_blank;
@@ -229,6 +230,10 @@ bool calc_cvt_modeline(int image_width, int image_height,
 
 		h_bp = h_blank / 2;
 		h_fp = h_blank - h_bp - h_sync;
+
+		pixel_clock =  ((long long)total_h_pixel * HV_FACTOR * 1000000)
+				/ h_period;
+		pixel_clock -= pixel_clock  % CVT_PXL_CLK_GRAN;
 	} else {
 		/* Reduced blanking */
 
@@ -247,11 +252,12 @@ bool calc_cvt_modeline(int image_width, int image_height,
 		if (vbi_lines < (CVT_RB_V_FPORCH + v_sync + CVT_MIN_V_BPORCH))
 			vbi_lines = CVT_RB_V_FPORCH + v_sync + CVT_MIN_V_BPORCH;
 
-		total_h_pixel = active_h_pixel + CVT_RB_H_BLANK;
-
 		h_blank = CVT_RB_H_BLANK;
 		v_blank = vbi_lines;
 
+		total_h_pixel = active_h_pixel + h_blank;
+		total_v_lines = active_v_lines + v_blank;
+
 		h_sync = CVT_RB_H_SYNC;
 
 		h_bp = h_blank / 2;
@@ -259,11 +265,11 @@ bool calc_cvt_modeline(int image_width, int image_height,
 
 		v_fp = CVT_RB_V_FPORCH;
 		v_bp = v_blank - v_fp - v_sync;
-	}
 
-	pixel_clock =  ((long long)total_h_pixel * HV_FACTOR * 1000000)
-			/ h_period;
-	pixel_clock -= pixel_clock  % CVT_PXL_CLK_GRAN;
+		pixel_clock = v_refresh * total_h_pixel *
+			      (2 * total_v_lines + interlace) / 2;
+		pixel_clock -= pixel_clock  % CVT_PXL_CLK_GRAN;
+	}
 
 	cvt->standards 	 = V4L2_DV_BT_STD_CVT;
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-06-16  9:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-16  9:17 [PATCH 0/3] v4l2-utils: miscellaneous fixes in cvt, gtf modeline Prashant Laddha
2015-06-16  9:17 ` [PATCH 1/3] v4l2-utils: handle interlace fraction correctly in gtf Prashant Laddha
2015-06-16  9:17 ` [PATCH 2/3] v4l2-utils gtf: use round instead of roundown for v_lines_rnd Prashant Laddha
2015-06-16  9:17 ` [PATCH 3/3] v4l2-utils: fix pixel clock calc for cvt reduced blanking Prashant Laddha

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.