@@ -717,7 +717,6 @@ static int vidioc_querycap(struct file *file, void *fh,
717
717
static int vidioc_enum_framesizes (struct file * file , void * fh ,
718
718
struct v4l2_frmsizeenum * argp )
719
719
{
720
- #warning handle pre-negotiated formats
721
720
struct v4l2_loopback_device * dev ;
722
721
723
722
/* there can be only one... */
@@ -726,6 +725,18 @@ static int vidioc_enum_framesizes(struct file *file, void *fh,
726
725
727
726
dev = file_to_loopdev (file );
728
727
728
+ if (is_format_locked (dev )) {
729
+ /* format is negotiated, so there's only a single valid format */
730
+ if (dev -> pix_format .pixelformat != argp -> pixel_format )
731
+ return - EINVAL ;
732
+ argp -> type = V4L2_FRMSIZE_TYPE_DISCRETE ;
733
+
734
+ argp -> discrete .width = dev -> pix_format .width ;
735
+ argp -> discrete .height = dev -> pix_format .height ;
736
+
737
+ return 0 ;
738
+ }
739
+
729
740
if (NULL == format_by_fourcc (argp -> pixel_format ))
730
741
return - EINVAL ;
731
742
@@ -872,11 +883,30 @@ static int vidioc_s_fmt_cap(struct file *file, void *fh,
872
883
static int vidioc_enum_fmt_out (struct file * file , void * fh ,
873
884
struct v4l2_fmtdesc * f )
874
885
{
886
+ struct v4l2_loopback_device * dev = file_to_loopdev (file );
875
887
const struct v4l2l_format * fmt ;
876
-
877
888
if (f -> index < 0 || f -> index >= FORMATS )
878
889
return - EINVAL ;
879
890
891
+ if (is_format_locked (dev )) {
892
+ int i ;
893
+ MARK ();
894
+ if (f -> index )
895
+ return - EINVAL ;
896
+ f -> index = -1 ;
897
+ MARK ();
898
+ for (i = 0 ; i < FORMATS ; i ++ ) {
899
+ printk (KERN_ERR "JMZ: format#%d" , i );
900
+ if (formats [i ].fourcc == dev -> pix_format .pixelformat ) {
901
+ f -> index = i ;
902
+ break ;
903
+ }
904
+ }
905
+ if (f -> index < 0 )
906
+ return - EINVAL ;
907
+ MARK ();
908
+ }
909
+
880
910
fmt = & formats [f -> index ];
881
911
f -> pixelformat = fmt -> fourcc ;
882
912
snprintf (f -> description , sizeof (f -> description ), "%s" , fmt -> name );
@@ -918,7 +948,6 @@ static int vidioc_g_fmt_out(struct file *file, void *fh,
918
948
static int vidioc_try_fmt_out (struct file * file , void * fh ,
919
949
struct v4l2_format * fmt )
920
950
{
921
- #warning handle pre-negotiated formats
922
951
struct v4l2_loopback_device * dev = file_to_loopdev (file );
923
952
__u32 w = fmt -> fmt .pix .width ;
924
953
__u32 h = fmt -> fmt .pix .height ;
@@ -932,6 +961,12 @@ static int vidioc_try_fmt_out(struct file *file, void *fh,
932
961
V4L2LOOPBACK_SIZE_DEFAULT_HEIGHT ;
933
962
dprintk ("trying image %dx%d\n" , w , h );
934
963
964
+ if (is_format_locked (dev )) {
965
+ w = dev -> pix_format .width ;
966
+ h = dev -> pix_format .height ;
967
+ pixfmt = dev -> pix_format .pixelformat ;
968
+ }
969
+
935
970
format = format_by_fourcc (pixfmt );
936
971
if (NULL == format )
937
972
format = & formats [0 ];
0 commit comments