vivid: add support to set CVT, GTF timings
PATCH v2 2/2 vivid: add support to set CVT, GTF timings
In addition to v4l2_find_dv_timings_cap(), where timings are searched against the list of preset timings, the incoming timing from v4l2-ctl is checked against CVT and GTF standards. If it confirms to be CVT or GTF, it is treated as valid timing and vivid format is updated with new timings.
--- drivers/media/platform/vivid/vivid-vid-cap.c | 61 +++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-)
drivers/media/platform/vivid/vivid-vid-cap.c +60 -1
@@ -1552,6 +1552,63 @@ int vivid_vid_cap_s_std(struct file *file, void *priv, v4l2_std_id id)return 0 ; } +static void find_aspect_ratio (u32 width,u32 height, +u32 *num,u32 *denom) +{ +if (!(height %3 ) && ((height *4 /3 ) == width)) { + *num =4 ; + *denom =3 ; + }else if (!(height %9 ) && ((height *16 /9 ) == width)) { + *num =16 ; + *denom =9 ; + }else if (!(height %10 ) && ((height *16 /10 ) == width)) { + *num =16 ; + *denom =10 ; + }else if (!(height %4 ) && ((height *5 /4 ) == width)) { + *num =5 ; + *denom =4 ; + }else if (!(height %9 ) && ((height *15 /9 ) == width)) { + *num =15 ; + *denom =9 ; + }else {/* default to 16:9 */ + *num =16 ; + *denom =9 ; + } +} + +static bool valid_cvt_gtf_timings (struct v4l2_dv_timings *timings) +{ +struct v4l2_bt_timings *bt = &timings->bt; +u32 total_h_pixel; +u32 total_v_lines; +u32 h_freq; + +if (!v4l2_valid_dv_timings (timings, &vivid_dv_timings_cap, +NULL ,NULL )) +return false; + + total_h_pixel =V4L2_DV_BT_FRAME_WIDTH (bt); + total_v_lines =V4L2_DV_BT_FRAME_HEIGHT (bt); + + h_freq = (u32 )bt->pixelclock / total_h_pixel; + +if (bt->standards ==V4L2_DV_BT_STD_CVT ) +return v4l2_detect_cvt (total_v_lines, h_freq, bt->vsync, + bt->polarities, timings); + +if (bt->standards ==V4L2_DV_BT_STD_GTF ) { +struct v4l2_fract aspect_ratio; + +find_aspect_ratio (bt->width, bt->height, + &aspect_ratio.numerator, + &aspect_ratio.denominator); +return v4l2_detect_gtf (total_v_lines, h_freq, bt->vsync, + bt->polarities, aspect_ratio, timings); + } + +return false; +} +int vivid_vid_cap_s_dv_timings (struct file *file,void *_fh,struct v4l2_dv_timings *timings) {
@@ -1561,8 +1618,10 @@ int vivid_vid_cap_s_dv_timings(struct file *file, void *_fh,return -ENODATA ;if (vb2_is_busy (&dev->vb_vid_cap_q))return -EBUSY ; +if (!v4l2_find_dv_timings_cap (timings, &vivid_dv_timings_cap, -0 ,NULL ,NULL )) +0 ,NULL ,NULL ) + && !valid_cvt_gtf_timings (timings))return -EINVAL ;if (v4l2_match_dv_timings (timings, &dev->dv_timings_cap,0 ))return 0 ;
Signature · 1 line
1.9.1
Hi Prashant,
Quoted 51 lines · Prashant Laddha
In addition to
v4l2_find_dv_timings_cap(), where timings are searched against the list of preset timings, the incoming timing from v4l2-ctl is checked against CVT and GTF standards. If it confirms to be CVT or GTF, it is treated as valid timing and vivid format is updated with new timings.Cc Hans Verkuil <[email protected]>Signed-off-by Prashant Laddha <[email protected]>--- drivers/media/platform/vivid/vivid-vid-cap.c | 61 +++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-)drivers/media/platform/vivid/vivid-vid-cap.c +31
-0@@ -1552,6 +1552,63 @@ int vivid_vid_cap_s_std(struct file *file, void *priv, v4l2_std_id id)return 0 ; } +static void find_aspect_ratio (u32 width,u32 height, +u32 *num,u32 *denom) +{ +if (!(height %3 ) && ((height *4 /3 ) == width)) { + *num =4 ; + *denom =3 ; + }else if (!(height %9 ) && ((height *16 /9 ) == width)) { + *num =16 ; + *denom =9 ; + }else if (!(height %10 ) && ((height *16 /10 ) == width)) { + *num =16 ; + *denom =10 ; + }else if (!(height %4 ) && ((height *5 /4 ) == width)) { + *num =5 ; + *denom =4 ; + }else if (!(height %9 ) && ((height *15 /9 ) == width)) { + *num =15 ; + *denom =9 ; + }else {/* default to 16:9 */ + *num =16 ; + *denom =9 ; + } +} + +static bool valid_cvt_gtf_timings (struct v4l2_dv_timings *timings) +{ +struct v4l2_bt_timings *bt = &timings->bt; +u32 total_h_pixel; +u32 total_v_lines; +u32 h_freq; +
drivers/media/platform/vivid/vivid-vid-cap.c int vivid_vid_cap_s_std(struct file *file, void *priv, v4l2_std_id id) · line 1595
Quoted 10 lines
drivers/media/platform/vivid/vivid-vid-cap.c +10
-0+if (!v4l2_valid_dv_timings (timings, &vivid_dv_timings_cap, +NULL ,NULL )) +return false; + + total_h_pixel =V4L2_DV_BT_FRAME_WIDTH (bt); + total_v_lines =V4L2_DV_BT_FRAME_HEIGHT (bt); + + h_freq = (u32 )bt->pixelclock / total_h_pixel; + +if (bt->standards ==V4L2_DV_BT_STD_CVT )
This test and the next isn't right. Apologies that I didn't see that when I reviewed v1.
The correct test is:
if (bt->standard == 0 || (bt->standards & V4L2_DV_BT_STD_CVT))
drivers/media/platform/vivid/vivid-vid-cap.c int vivid_vid_cap_s_std(struct file *file, void *priv, v4l2_std_id id) · line 1597
Quoted 2 lines
drivers/media/platform/vivid/vivid-vid-cap.c +2
-0+return v4l2_detect_cvt (total_v_lines, h_freq, bt->vsync, + bt->polarities, timings);
Just returning here isn't right either: if a CVT format is detected, then it can return true, otherwise it should continue and try the GTF format.
drivers/media/platform/vivid/vivid-vid-cap.c int vivid_vid_cap_s_std(struct file *file, void *priv, v4l2_std_id id) · line 1599
Quoted 2 lines
drivers/media/platform/vivid/vivid-vid-cap.c +2
-0+ +if (bt->standards ==V4L2_DV_BT_STD_GTF ) {
And this becomes:
if (bt->standard == 0 || (bt->standards & V4L2_DV_BT_STD_GTF))
When it comes to autodetecting formats the driver can often detect only a few timing properties, and it is rarely able to say if it will be a CVT or GTF timing. So often they leave bt->standard to 0.
Regards,
Hans
Quoted 28 lines
drivers/media/platform/vivid/vivid-vid-cap.c +15
-1+struct v4l2_fract aspect_ratio; + +find_aspect_ratio (bt->width, bt->height, + &aspect_ratio.numerator, + &aspect_ratio.denominator); +return v4l2_detect_gtf (total_v_lines, h_freq, bt->vsync, + bt->polarities, aspect_ratio, timings); + } + +return false; +} +int vivid_vid_cap_s_dv_timings (struct file *file,void *_fh,struct v4l2_dv_timings *timings) {@@ -1561,8 +1618,10 @@ int vivid_vid_cap_s_dv_timings(struct file *file, void *_fh,return -ENODATA ;if (vb2_is_busy (&dev->vb_vid_cap_q))return -EBUSY ; +if (!v4l2_find_dv_timings_cap (timings, &vivid_dv_timings_cap, -0 ,NULL ,NULL )) +0 ,NULL ,NULL ) + && !valid_cvt_gtf_timings (timings))return -EINVAL ;if (v4l2_match_dv_timings (timings, &dev->dv_timings_cap,0 ))return 0 ;
Quoted 26 lines · Hans Verkuil
Hi Prashant,
drivers/media/platform/vivid/vivid-vid-cap.c int vivid_vid_cap_s_std(struct file *file, void *priv, v4l2_std_id id) · line 1595
Quoted 4 lines
drivers/media/platform/vivid/vivid-vid-cap.c +4
-0+ + h_freq = (u32 )bt->pixelclock / total_h_pixel; + +if (bt->standards ==V4L2_DV_BT_STD_CVT )This test and the next isn't right. Apologies that I didn't see that when I reviewed v1.
The correct test is:
if (bt->standard == 0 || (bt->standards & V4L2_DV_BT_STD_CVT))drivers/media/platform/vivid/vivid-vid-cap.c int vivid_vid_cap_s_std(struct file *file, void *priv, v4l2_std_id id) · line 1597
Quoted 2 lines
drivers/media/platform/vivid/vivid-vid-cap.c +2
-0+return v4l2_detect_cvt (total_v_lines, h_freq, bt->vsync, + bt->polarities, timings);Just returning here isn't right either: if a CVT format is detected, then it can return true, otherwise it should continue and try the GTF format.
Review
Quoted 2 lines
(quoted diff) +2
-0+ + if (bt->standards == V4L2_DV_BT_STD_GTF) {And this becomes:
Quoted 6 lines
If (bt->standard == 0 || (bt->standards & V4L2_DV_BT_STD_GTF))When it comes to autodetecting formats the driver can often detect only a few timing properties, and it is rarely able to say if it will be a CVT or GTF timing. So often they leave
bt->standardto 0.
Thanks Hans. I will fix it and post v3.
Regards,
Prashant