Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1605544

[PATCH 2/3] [media] v4l2-dv-timings: Introduce v4l2_calc_timeperframe helper

From Jose Abreu <Jose.Abreu@synopsys.com>
Newsgroups linux.kernel
Subject [PATCH 2/3] [media] v4l2-dv-timings: Introduce v4l2_calc_timeperframe helper
Date 2017-03-21 13:00 +0100
Message-ID <tnqCe-2Qk-13@gated-at.bofh.it> (permalink)
References <tnqsz-2K1-49@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


A new helper function was introduced to facilitate the calculation
of time per frame value whenever we have access to the full
v4l2_dv_timings structure.

This should be used only for receivers and only when there is
enough accuracy in the measured pixel clock value as well as in
the horizontal/vertical values.

Signed-off-by: Jose Abreu <joabreu@synopsys.com>
Cc: Carlos Palminha <palminha@synopsys.com>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: Hans Verkuil <hans.verkuil@cisco.com>
Cc: linux-media@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/media/v4l2-core/v4l2-dv-timings.c | 39 +++++++++++++++++++++++++++++++
 include/media/v4l2-dv-timings.h           | 11 +++++++++
 2 files changed, 50 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-dv-timings.c b/drivers/media/v4l2-core/v4l2-dv-timings.c
index 5c8c49d..b7b39c2 100644
--- a/drivers/media/v4l2-core/v4l2-dv-timings.c
+++ b/drivers/media/v4l2-core/v4l2-dv-timings.c
@@ -814,3 +814,42 @@ struct v4l2_fract v4l2_calc_aspect_ratio(u8 hor_landscape, u8 vert_portrait)
 	return aspect;
 }
 EXPORT_SYMBOL_GPL(v4l2_calc_aspect_ratio);
+
+/** v4l2_calc_timeperframe - helper function to calculate timeperframe based
+ *	v4l2_dv_timings fields.
+ * @t - Timings for the video mode.
+ *
+ * Calculates the expected timeperframe using the pixel clock value and
+ * horizontal/vertical measures. This means that v4l2_dv_timings structure
+ * must be correctly and fully filled.
+ */
+struct v4l2_fract v4l2_calc_timeperframe(const struct v4l2_dv_timings *t)
+{
+	const struct v4l2_bt_timings *bt = &t->bt;
+	struct v4l2_fract fps_fract = { 1, 1 };
+	unsigned long n, d;
+	u32 htot, vtot, fps;
+	u64 pclk;
+
+	if (t->type != V4L2_DV_BT_656_1120)
+		return fps_fract;
+
+	htot = V4L2_DV_BT_FRAME_WIDTH(bt);
+	vtot = V4L2_DV_BT_FRAME_HEIGHT(bt);
+	pclk = bt->pixelclock;
+
+	if ((bt->flags & V4L2_DV_FL_CAN_DETECT_REDUCED_FPS) &&
+	    (bt->flags & V4L2_DV_FL_REDUCED_FPS))
+		pclk = div_u64(pclk * 1000ULL, 1001);
+
+	fps = (htot * vtot) > 0 ? div_u64((100 * pclk), (htot * vtot)) : 0;
+	if (!fps)
+		return fps_fract;
+
+	rational_best_approximation(fps, 100, fps, 100, &n, &d);
+
+	fps_fract.numerator = d;
+	fps_fract.denominator = n;
+	return fps_fract;
+}
+EXPORT_SYMBOL_GPL(v4l2_calc_timeperframe);
diff --git a/include/media/v4l2-dv-timings.h b/include/media/v4l2-dv-timings.h
index 61a1889..c1eef08 100644
--- a/include/media/v4l2-dv-timings.h
+++ b/include/media/v4l2-dv-timings.h
@@ -203,6 +203,17 @@ bool v4l2_detect_gtf(unsigned frame_height, unsigned hfreq, unsigned vsync,
  */
 struct v4l2_fract v4l2_dv_timings_aspect_ratio(const struct v4l2_dv_timings *t);
 
+/**
+ * v4l2_calc_timeperframe - helper function to calculate timeperframe based
+ *	v4l2_dv_timings fields.
+ * @t - Timings for the video mode.
+ *
+ * Calculates the expected timeperframe using the pixel clock value and
+ * horizontal/vertical measures. This means that v4l2_dv_timings structure
+ * must be correctly and fully filled.
+ */
+struct v4l2_fract v4l2_calc_timeperframe(const struct v4l2_dv_timings *t);
+
 /*
  * reduce_fps - check if conditions for reduced fps are true.
  * bt - v4l2 timing structure
-- 
1.9.1

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 0/3] Handling of reduced FPS in V4L2 Jose Abreu <Jose.Abreu@synopsys.com> - 2017-03-21 12:50 +0100
  [PATCH 3/3] [media] cobalt: Use v4l2_calc_timeperframe helper Jose Abreu <Jose.Abreu@synopsys.com> - 2017-03-21 13:00 +0100
  [PATCH 1/3] [media] videodev2.h: Add new DV flag CAN_DETECT_REDUCED_FPS Jose Abreu <Jose.Abreu@synopsys.com> - 2017-03-21 13:00 +0100
  [PATCH 2/3] [media] v4l2-dv-timings: Introduce v4l2_calc_timeperframe helper Jose Abreu <Jose.Abreu@synopsys.com> - 2017-03-21 13:00 +0100
  Re: [PATCH 0/3] Handling of reduced FPS in V4L2 Jose Abreu <Jose.Abreu@synopsys.com> - 2017-03-24 12:20 +0100
    Re: [PATCH 0/3] Handling of reduced FPS in V4L2 Hans Verkuil <hansverk@cisco.com> - 2017-03-24 12:30 +0100
      Re: [PATCH 0/3] Handling of reduced FPS in V4L2 Jose Abreu <Jose.Abreu@synopsys.com> - 2017-03-24 13:00 +0100
        Re: [PATCH 0/3] Handling of reduced FPS in V4L2 Hans Verkuil <hansverk@cisco.com> - 2017-03-24 13:20 +0100
          Re: [PATCH 0/3] Handling of reduced FPS in V4L2 Jose Abreu <Jose.Abreu@synopsys.com> - 2017-03-24 13:30 +0100
            Re: [PATCH 0/3] Handling of reduced FPS in V4L2 Hans Verkuil <hansverk@cisco.com> - 2017-03-24 13:30 +0100
              Re: [PATCH 0/3] Handling of reduced FPS in V4L2 Jose Abreu <Jose.Abreu@synopsys.com> - 2017-03-27 14:10 +0200

csiph-web