vivid: reduced fps support
RFC PATCH 1/2 vivid: add support for reduced fps in video out.
In reply to Prashant LaddhaIf bt timing has REDUCED_FPS flag set, then reduce the frame rate by factor of 1000 / 1001. For vivid, timeperframe_vid_out indicates the frame timings used by video out thread. The timeperframe_vid_out is derived from pixel clock. Adjusting the timeperframe_vid_out by scaling down pixel clock with factor of 1000 / 1001.
The reduced fps is supported for CVT timings if reduced blanking v2 (indicated by vsync = 8) is true. For CEA861 timings, reduced fps is supported if V4L2_DV_FL_CAN_REDUCE_FPS flag is true. For GTF timings, reduced fps is not supported.
The reduced fps will allow refresh rates like 29.97, 59.94 etc.
--- drivers/media/platform/vivid/vivid-vid-out.c | 30 +++++++++++++++++++++++++++- drivers/media/v4l2-core/v4l2-dv-timings.c | 5 +++++ 2 files changed, 34 insertions(+), 1 deletion(-)
drivers/media/platform/vivid/vivid-vid-out.c +29 -1
@@ -213,6 +213,27 @@ const struct vb2_ops vivid_vid_out_qops = { };/* +* Called to check conditions for reduced fps. For CVT timings, reduced +* fps is allowed only with reduced blanking v2 (vsync == 8). For CEA861 +* timings, reduced fps is allowed if V4L2_DV_FL_CAN_REDUCE_FPS flag is +* true. +*/ +static bool reduce_fps (struct v4l2_bt_timings *bt) +{ +if (!(bt->flags &V4L2_DV_FL_REDUCED_FPS )) +return false; + +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; +} + +/* * Called whenever the format has to be reset which can occur when * changing outputs, standard, timings, etc. */
@@ -220,6 +241,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 +263,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 (reduce_fps (bt)) + 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 ;
drivers/media/v4l2-core/v4l2-dv-timings.c +5 -0
@@ -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 (t->bt.flags &V4L2_DV_FL_CAN_REDUCE_FPS ) + t->bt.flags |= flags; +return true; } }
Signature · 1 line
1.9.1
RFC PATCH 2/2 vivid: add support for reduced fps in video capture
In reply to Prashant LaddhaWith this patch, vivid capture thread can now generate reduced fps by factor of 1000 / 1001. This is controlled using a boolean VIVID_CID_REDUCED_FPS added in vivid control. For reduced fps, capture time is controlled by scaling down timeperframe_vid_cap with a factor of 1000 / 1001 if VIVID_CID_REDUCED_FPS is true.
--- drivers/media/platform/vivid/vivid-core.h | 1 + drivers/media/platform/vivid/vivid-ctrls.c | 15 +++++++++++++++ drivers/media/platform/vivid/vivid-vid-cap.c | 7 ++++++- 3 files changed, 22 insertions(+), 1 deletion(-)
drivers/media/platform/vivid/vivid-core.h +1 -0
@@ -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
@@ -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 fps" , + .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 );
drivers/media/platform/vivid/vivid-vid-cap.c +6 -1
@@ -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,12 @@ 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) + pixelclock =div_u64 ((bt->pixelclock *1000 ),1001 ); +else + pixelclock = bt->pixelclock; 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
cover vivid: reduced fps support
Hi,
Following patches add reduced fps support in vivid video transmit and capture. Please review and share your comments.
Regards,
Prashant
Prashant Laddha (2):
vivid: add support for reduced fps in video out.
vivid: add support for reduced fps 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 | 7 ++++++- drivers/media/platform/vivid/vivid-vid-out.c | 30 +++++++++++++++++++++++++++- drivers/media/v4l2-core/v4l2-dv-timings.c | 5 +++++ 5 files changed, 56 insertions(+), 2 deletions(-)
Signature · 1 line
1.9.1
Re: [RFC PATCH 1/2] vivid: add support for reduced fps in video out.
In reply to Prashant LaddhaHi Prashant,
Sorry for the late review, but here it is (finally):
Quoted 29 lines · Prashant Laddha
If bt timing has
REDUCED_FPSflag set, then reduce the frame rate by factor of 1000 / 1001. For vivid,timeperframe_vid_outindicates the frame timings used by video out thread. Thetimeperframe_vid_outis derived from pixel clock. Adjusting thetimeperframe_vid_outby scaling down pixel clock with factor of 1000 / 1001.The reduced fps is supported for CVT timings if reduced blanking v2 (indicated by vsync = 8) is true. For CEA861 timings, reduced fps is supported if
V4L2_DV_FL_CAN_REDUCE_FPSflag is true. For GTF timings, reduced fps is not supported.The reduced fps will allow refresh rates like 29.97, 59.94 etc.
Cc Hans Verkuil <[email protected]>Signed-off-by Prashant Laddha <[email protected]>--- drivers/media/platform/vivid/vivid-vid-out.c | 30 +++++++++++++++++++++++++++- drivers/media/v4l2-core/v4l2-dv-timings.c | 5 +++++ 2 files changed, 34 insertions(+), 1 deletion(-)drivers/media/platform/vivid/vivid-vid-out.c +1
-0@@ -213,6 +213,27 @@ const struct vb2_ops vivid_vid_out_qops = { };/* +* Called to check conditions for reduced fps. For CVT timings, reduced
drivers/media/platform/vivid/vivid-vid-out.c const struct vb2_ops vivid_vid_out_qops = { · line 226
Quoted 10 lines
drivers/media/platform/vivid/vivid-vid-out.c +10
-0+* fps is allowed only with reduced blanking v2 (vsync == 8). For CEA861 +* timings, reduced fps is allowed if V4L2_DV_FL_CAN_REDUCE_FPS flag is +* true. +*/ +static bool reduce_fps (struct v4l2_bt_timings *bt) +{ +if (!(bt->flags &V4L2_DV_FL_REDUCED_FPS )) +return false; + +if ((bt->standards &V4L2_DV_BT_STD_CVT ) && (bt->vsync ==8 ))
I propose that you add a static inline helper function to v4l2-dv-timings.h to test for reduced blanking v2. This condition is way too magical...
If you add such a helper, then you should check if there is existing code that could switch to this helper.
drivers/media/platform/vivid/vivid-vid-out.c const struct vb2_ops vivid_vid_out_qops = { · line 227
Quoted 1 line
drivers/media/platform/vivid/vivid-vid-out.c +1
-0+return true;
Bad indentation (one tab too far to the right).
drivers/media/platform/vivid/vivid-vid-out.c const struct vb2_ops vivid_vid_out_qops = { · line 231
Quoted 4 lines
drivers/media/platform/vivid/vivid-vid-out.c +4
-0+ +if ((bt->standards &V4L2_DV_BT_STD_CEA861 ) && + (bt->flags &V4L2_DV_FL_CAN_REDUCE_FPS )) +return true;
Ditto.
Quoted 17 lines
drivers/media/platform/vivid/vivid-vid-out.c +6
-0+ +return false; +} + +/* * Called whenever the format has to be reset which can occur when * changing outputs, standard, timings, etc. */ @@ -220,6 +241,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 :
drivers/media/platform/vivid/vivid-vid-out.c void vivid_update_format_out(struct vivid_dev *dev) · line 268
Quoted 6 lines
drivers/media/platform/vivid/vivid-vid-out.c +3
-0@@ -241,8 +263,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 (reduce_fps (bt)) + pixelclock =div_u64 ((bt->pixelclock *1000 ),1001 );
No need for the parenthesis around bt->pixelclock * 1000.
Quoted 14 lines
drivers/media/platform/vivid/vivid-vid-out.c +4
-1+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 ;drivers/media/v4l2-core/v4l2-dv-timings.c +0
-0
drivers/media/v4l2-core/v4l2-dv-timings.c bool v4l2_find_dv_timings_cap(struct v4l2_dv_timings *t, · line 218
Quoted 9 lines
drivers/media/v4l2-core/v4l2-dv-timings.c +5
-0@@ -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 (t->bt.flags &V4L2_DV_FL_CAN_REDUCE_FPS ) + t->bt.flags |= flags; +
This isn't quite right. This doesn't support V4L2_DV_BT_DMT_4096X2160P60_RB which is a CVT format with reduced blanking v2 and so it should support reduced fps.
In theory the 'if' above should check for both the V4L2_DV_FL_CAN_REDUCE_FPS and for CVT RB v2 (using the helper function I've proposed). However, that would cause weird behavior with the V4L2_DV_BT_DMT_4096X2160P59_94_RB timings since these are already reduced fps.
I think the best approach is to add V4L2_DV_FL_CAN_REDUCE_FPS to the V4L2_DV_BT_DMT_4096X2160P60_RB definition in v4l2-dv-timings.h.
That way the code above is unchanged, and it will work as expected with V4L2_DV_BT_DMT_4096X2160P60_RB.
Regards,
Hans
Re: [RFC PATCH 2/2] vivid: add support for reduced fps in video capture
In reply to Prashant LaddhaQuoted 50 lines · Prashant Laddha
With this patch, vivid capture thread can now generate reduced fps by factor of 1000 / 1001. This is controlled using a boolean
VIVID_CID_REDUCED_FPSadded in vivid control. For reduced fps, capture time is controlled by scaling downtimeperframe_vid_capwith a factor of 1000 / 1001 ifVIVID_CID_REDUCED_FPSis true.Cc Hans Verkuil <[email protected]>Signed-off-by Prashant Laddha <[email protected]>--- drivers/media/platform/vivid/vivid-core.h | 1 + drivers/media/platform/vivid/vivid-ctrls.c | 15 +++++++++++++++ drivers/media/platform/vivid/vivid-vid-cap.c | 7 ++++++- 3 files changed, 22 insertions(+), 1 deletion(-)drivers/media/platform/vivid/vivid-core.h +1
-0@@ -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 +5
-0@@ -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);
drivers/media/platform/vivid/vivid-ctrls.c static const struct v4l2_ctrl_config vivid_ctrl_vflip = { · line 610
Quoted 7 lines
drivers/media/platform/vivid/vivid-ctrls.c +4
-0@@ -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 fps" ,
I think "Reduced Framerate" is a better description.
Quoted 29 lines
drivers/media/platform/vivid/vivid-ctrls.c +6
-0+ .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 );drivers/media/platform/vivid/vivid-vid-cap.c +1
-0@@ -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 :
drivers/media/platform/vivid/vivid-vid-cap.c void vivid_update_format_cap(struct vivid_dev *dev, bool keep_controls) · line 434
Quoted 4 lines
drivers/media/platform/vivid/vivid-vid-cap.c +1
-0@@ -430,8 +431,12 @@ 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)
This needs a check similar to reduce_fps() in patch 1/2. Except for the fact that the bt->flags & V4L2_DV_FL_REDUCED_FPS check is invalid for receivers. Perhaps that check should be moved out of reduce_fps() so that that function can be shared between capture and output.
The reduced_fps flag should only be honored for timings that allow it.
drivers/media/platform/vivid/vivid-vid-cap.c void vivid_update_format_cap(struct vivid_dev *dev, bool keep_controls) · line 435
Quoted 1 line
drivers/media/platform/vivid/vivid-vid-cap.c +1
-0+ pixelclock =div_u64 ((bt->pixelclock *1000 ),1001 );
No parenthesis needed around bt->pixelclock * 1000.
drivers/media/platform/vivid/vivid-vid-cap.c void vivid_update_format_cap(struct vivid_dev *dev, bool keep_controls) · line 442
Quoted 9 lines
drivers/media/platform/vivid/vivid-vid-cap.c +3
-1+else + pixelclock = bt->pixelclock; 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 ;
Regards,
Hans