Skip to contentSkip to conversation

vivid: reduced fps support

RFC New Prashant Laddha 1 participant 5 messages Sep 22, 2015 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

v2 cover vivid: reduced fps support

Hi,

Please find RFC v2 for adding reduced fps support in vivid video transmit and receive.

Changes since v1:
1. Added helper function to check if all necessary conditions for reduced fps are met.
2. This function can now common for vivid-vid-out and vivid-vid-cap
3. Same helper function can also be used by v4l2-dv-timings before setting the flag for reduced fps.
4. Incorporated other review comments. Also split patches into smaller and well separated changes.

Please review and share your comments.

Regards,
Prashant

Prashant Laddha (4):
v4l2-dv-timings: add condition checks for reduced fps
vivid: add support for reduced fps in video out
vivid-capture: add control for reduced frame rate
vivid: add support for reduced frame rate in video capture

 drivers/media/platform/vivid/vivid-core.h    |  1 +
 drivers/media/platform/vivid/vivid-ctrls.c   | 15 +++++++++++++++
 drivers/media/platform/vivid/vivid-vid-cap.c | 10 +++++++++-
 drivers/media/platform/vivid/vivid-vid-out.c |  9 ++++++++-
 drivers/media/v4l2-core/v4l2-dv-timings.c    |  5 +++++
 include/media/v4l2-dv-timings.h              | 21 +++++++++++++++++++++
 6 files changed, 59 insertions(+), 2 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

RFC v2 1/4 v4l2-dv-timings: add condition checks for reduced fps

Added a helper function to check necessary conditions required for reduced fps. The reduced fps is supported for CVT and CEA861 timings. CVT supports reduced fps only if reduced blanking v2 (indicated by vsync = 8) is true. Whereas CEA861 supports reduced fps if V4L2_DV_FL_CAN_REDUCE_FPS flag is true.

---
 drivers/media/v4l2-core/v4l2-dv-timings.c |  5 +++++
 include/media/v4l2-dv-timings.h           | 21 +++++++++++++++++++++
 2 files changed, 26 insertions(+)
drivers/media/v4l2-core/v4l2-dv-timings.c +5 -0
index 6a83d61..d8e62f6 100644
@@ -210,7 +210,12 @@ bool v4l2_find_dv_timings_cap(struct v4l2_dv_timings *t,
 					  fnc, fnc_handle) &&
 		    v4l2_match_dv_timings(t, v4l2_dv_timings_presets + i,
 					  pclock_delta)) {
+			u32 flags = t->bt.flags & V4L2_DV_FL_REDUCED_FPS;
+
 			*t = v4l2_dv_timings_presets[i];
+			if (can_reduce_fps(&t->bt))
+				t->bt.flags |= flags;
+
 			return true;
 		}
 	}
include/media/v4l2-dv-timings.h +21 -0
index b6130b5..49c2328 100644
@@ -183,4 +183,25 @@ bool v4l2_detect_gtf(unsigned frame_height, unsigned hfreq, unsigned vsync,
  */
 struct v4l2_fract v4l2_calc_aspect_ratio(u8 hor_landscape, u8 vert_portrait);
 
+/*
+ * reduce_fps - check if conditions for reduced fps are true.
+ * bt - v4l2 timing structure
+ * For different timings reduced fps is allowed if following conditions
+ * are met -
+ * For CVT timings: if reduced blanking v2 (vsync == 8) is true.
+ * For CEA861 timings: if V4L2_DV_FL_CAN_REDUCE_FPS flag is true.
+ */
+static inline  bool can_reduce_fps(struct v4l2_bt_timings *bt)
+{
+	if ((bt->standards & V4L2_DV_BT_STD_CVT) && (bt->vsync == 8))
+		return true;
+
+	if ((bt->standards & V4L2_DV_BT_STD_CEA861) &&
+	    (bt->flags & V4L2_DV_FL_CAN_REDUCE_FPS))
+		return true;
+
+	return false;
+}
+
+
 #endif
Signature · 1 line
1.9.1
#2 lore raw

RFC v2 2/4 vivid: add support for reduced fps in video out

In reply to Prashant Laddha

If reduced fps flag is set then check if other necessary conditions are true for the given bt timing. If yes, then reduce the frame rate. For vivid transmitter, timeperframe_vid_out controls the frame rate. Adjusting the timeperframe_vid_out by scaling down pixel clock by factor of 1000 / 1001.

---
 drivers/media/platform/vivid/vivid-vid-out.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/media/platform/vivid/vivid-vid-out.c +8 -1
index c404e27..e860347 100644
@@ -220,6 +220,7 @@ void vivid_update_format_out(struct vivid_dev *dev)
 {
 	struct v4l2_bt_timings *bt = &dev->dv_timings_out.bt;
 	unsigned size, p;
+	u64 pixelclock;
 
 	switch (dev->output_type[dev->output]) {
 	case SVID:
@@ -241,8 +242,14 @@ void vivid_update_format_out(struct vivid_dev *dev)
 		dev->sink_rect.width = bt->width;
 		dev->sink_rect.height = bt->height;
 		size = V4L2_DV_BT_FRAME_WIDTH(bt) * V4L2_DV_BT_FRAME_HEIGHT(bt);
+
+		if (can_reduce_fps(bt) && (bt->flags & V4L2_DV_FL_REDUCED_FPS))
+			pixelclock = div_u64(bt->pixelclock * 1000, 1001);
+		else
+			pixelclock = bt->pixelclock;
+
 		dev->timeperframe_vid_out = (struct v4l2_fract) {
-			size / 100, (u32)bt->pixelclock / 100
+			size / 100, (u32)pixelclock / 100
 		};
 		if (bt->interlaced)
 			dev->field_out = V4L2_FIELD_ALTERNATE;
Signature · 1 line
1.9.1
#3 lore raw

RFC v2 3/4 vivid-capture: add control for reduced frame rate

In reply to Prashant Laddha

A boolean control Reduced Framerate is added to vivid controls for controlling the reduced fps option for vivid capture from gui.

---
 drivers/media/platform/vivid/vivid-core.h  |  1 +
 drivers/media/platform/vivid/vivid-ctrls.c | 15 +++++++++++++++
 2 files changed, 16 insertions(+)
drivers/media/platform/vivid/vivid-core.h +1 -0
index c72349c..4a2c8b7 100644
@@ -263,6 +263,7 @@ struct vivid_dev {
 	bool				vflip;
 	bool				vbi_cap_interlaced;
 	bool				loop_video;
+	bool				reduced_fps;
 
 	/* Framebuffer */
 	unsigned long			video_pbase;
drivers/media/platform/vivid/vivid-ctrls.c +15 -0
index 339c8b7..30d472a 100644
@@ -78,6 +78,7 @@
 #define VIVID_CID_TIME_WRAP		(VIVID_CID_VIVID_BASE + 39)
 #define VIVID_CID_MAX_EDID_BLOCKS	(VIVID_CID_VIVID_BASE + 40)
 #define VIVID_CID_PERCENTAGE_FILL	(VIVID_CID_VIVID_BASE + 41)
+#define VIVID_CID_REDUCED_FPS		(VIVID_CID_VIVID_BASE + 42)
 
 #define VIVID_CID_STD_SIGNAL_MODE	(VIVID_CID_VIVID_BASE + 60)
 #define VIVID_CID_STANDARD		(VIVID_CID_VIVID_BASE + 61)
@@ -422,6 +423,10 @@ static int vivid_vid_cap_s_ctrl(struct v4l2_ctrl *ctrl)
 		dev->sensor_vflip = ctrl->val;
 		tpg_s_vflip(&dev->tpg, dev->sensor_vflip ^ dev->vflip);
 		break;
+	case VIVID_CID_REDUCED_FPS:
+		dev->reduced_fps = ctrl->val;
+		vivid_update_format_cap(dev, true);
+		break;
 	case VIVID_CID_HAS_CROP_CAP:
 		dev->has_crop_cap = ctrl->val;
 		vivid_update_format_cap(dev, true);
@@ -599,6 +604,15 @@ static const struct v4l2_ctrl_config vivid_ctrl_vflip = {
 	.step = 1,
 };
 
+static const struct v4l2_ctrl_config vivid_ctrl_reduced_fps = {
+	.ops = &vivid_vid_cap_ctrl_ops,
+	.id = VIVID_CID_REDUCED_FPS,
+	.name = "Reduced Framerate",
+	.type = V4L2_CTRL_TYPE_BOOLEAN,
+	.max = 1,
+	.step = 1,
+};
+
 static const struct v4l2_ctrl_config vivid_ctrl_has_crop_cap = {
 	.ops = &vivid_vid_cap_ctrl_ops,
 	.id = VIVID_CID_HAS_CROP_CAP,
@@ -1379,6 +1393,7 @@ int vivid_create_controls(struct vivid_dev *dev, bool show_ccs_cap,
 		v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_vflip, NULL);
 		v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_insert_sav, NULL);
 		v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_insert_eav, NULL);
+		v4l2_ctrl_new_custom(hdl_vid_cap, &vivid_ctrl_reduced_fps, NULL);
 		if (show_ccs_cap) {
 			dev->ctrl_has_crop_cap = v4l2_ctrl_new_custom(hdl_vid_cap,
 				&vivid_ctrl_has_crop_cap, NULL);
Signature · 1 line
1.9.1
#4 lore raw

RFC v2 4/4 vivid: add support for reduced frame rate in video capture

In reply to Prashant Laddha

With this patch, vivid capture thread can now generate a video with frame rate reduced by a factor of 1000 / 1001. This option can be selected using a control Reduced Framerate from gui.

---
 drivers/media/platform/vivid/vivid-vid-cap.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/media/platform/vivid/vivid-vid-cap.c +9 -1
index ed0b878..74ba98f 100644
@@ -401,6 +401,7 @@ void vivid_update_format_cap(struct vivid_dev *dev, bool keep_controls)
 {
 	struct v4l2_bt_timings *bt = &dev->dv_timings_cap.bt;
 	unsigned size;
+	u64 pixelclock;
 
 	switch (dev->input_type[dev->input]) {
 	case WEBCAM:
@@ -430,8 +431,15 @@ void vivid_update_format_cap(struct vivid_dev *dev, bool keep_controls)
 		dev->src_rect.width = bt->width;
 		dev->src_rect.height = bt->height;
 		size = V4L2_DV_BT_FRAME_WIDTH(bt) * V4L2_DV_BT_FRAME_HEIGHT(bt);
+		if (dev->reduced_fps && can_reduce_fps(bt)) {
+			pixelclock = div_u64(bt->pixelclock * 1000, 1001);
+			bt->flags |= V4L2_DV_FL_REDUCED_FPS;
+		} else {
+			pixelclock = bt->pixelclock;
+			bt->flags &= ~V4L2_DV_FL_REDUCED_FPS;
+		}
 		dev->timeperframe_vid_cap = (struct v4l2_fract) {
-			size / 100, (u32)bt->pixelclock / 100
+			size / 100, (u32)pixelclock / 100
 		};
 		if (bt->interlaced)
 			dev->field_cap = V4L2_FIELD_ALTERNATE;
Signature · 1 line
1.9.1