1010
1111#include "vcam.h"
1212
13- static const char * short_options = "hcm:r:ls:p:d:" ;
13+ static const char * short_options = "hcm:r:ls:p:d:t: " ;
1414
1515const struct option long_options [] = {
16- {"help" , 0 , NULL , 'h' }, {"create" , 0 , NULL , 'c' },
17- {"modify" , 1 , NULL , 'm' }, {"list" , 0 , NULL , 'l' },
18- {"size" , 1 , NULL , 's' }, {"pixfmt" , 1 , NULL , 'p' },
19- {"device" , 1 , NULL , 'd' }, {"remove" , 1 , NULL , 'r' },
20- {NULL , 0 , NULL , 0 }};
16+ {"help" , 0 , NULL , 'h' }, {"create" , 0 , NULL , 'c' },
17+ {"modify" , 1 , NULL , 'm' }, {"list" , 0 , NULL , 'l' },
18+ {"size" , 1 , NULL , 's' }, {"pixfmt" , 1 , NULL , 'p' },
19+ {"device" , 1 , NULL , 'd' }, {"remove" , 1 , NULL , 'r' },
20+ {"memtype" , 1 , NULL , 't' }, { NULL , 0 , NULL , 0 }};
2121
2222const char * help =
2323 " -h --help Print this informations.\n"
@@ -37,6 +37,7 @@ const char *help =
3737 "and apply with crop ratio.\n"
3838 "\n"
3939 " -p --pixfmt pix_fmt Specify pixel format (rgb24,yuyv).\n"
40+ " -t --memtype mem_type Specify memory type (mmap,dmabuf).\n"
4041 " -d --device /dev/* Control device node.\n" ;
4142
4243enum ACTION { ACTION_NONE , ACTION_CREATE , ACTION_DESTROY , ACTION_MODIFY };
@@ -45,6 +46,7 @@ struct vcam_device_spec device_template = {
4546 .width = 640 ,
4647 .height = 480 ,
4748 .pix_fmt = VCAM_PIXFMT_RGB24 ,
49+ .mem_type = VCAM_MEMORY_MMAP ,
4850 .video_node = "" ,
4951 .fb_node = "" ,
5052};
@@ -102,6 +104,14 @@ int determine_pixfmt(char *pixfmt_str)
102104 return -1 ;
103105}
104106
107+ int determine_memtype (char * memtype_str )
108+ {
109+ if (!strncmp (memtype_str , "mmap" , 4 ))
110+ return VCAM_MEMORY_MMAP ;
111+ if (!strncmp (memtype_str , "dmabuf" , 6 ))
112+ return VCAM_MEMORY_DMABUF ;
113+ return -1 ;
114+ }
105115int create_device (struct vcam_device_spec * dev )
106116{
107117 int fd = open (ctl_path , O_RDWR );
@@ -118,6 +128,9 @@ int create_device(struct vcam_device_spec *dev)
118128 if (!dev -> pix_fmt )
119129 dev -> pix_fmt = device_template .pix_fmt ;
120130
131+ if (!dev -> mem_type )
132+ dev -> mem_type = device_template .mem_type ;
133+
121134 int res = ioctl (fd , VCAM_IOCTL_CREATE_DEVICE , dev );
122135 if (res ) {
123136 fprintf (stderr , "Failed to create a new device.\n" );
@@ -170,6 +183,9 @@ int modify_device(struct vcam_device_spec *dev)
170183 if (!dev -> pix_fmt )
171184 dev -> pix_fmt = orig_dev .pix_fmt ;
172185
186+ if (!dev -> mem_type )
187+ dev -> mem_type = orig_dev .mem_type ;
188+
173189 if (!dev -> cropratio .numerator || !dev -> cropratio .denominator )
174190 dev -> cropratio = orig_dev .cropratio ;
175191
@@ -195,10 +211,11 @@ int list_devices()
195211 printf ("Available virtual V4L2 compatible devices:\n" );
196212 while (!ioctl (fd , VCAM_IOCTL_GET_DEVICE , & dev )) {
197213 dev .idx ++ ;
198- printf ("%d. %s(%d,%d,%d/%d,%s) -> %s\n" , dev .idx , dev .fb_node ,
214+ printf ("%d. %s(%d,%d,%d/%d,%s,%s ) -> %s\n" , dev .idx , dev .fb_node ,
199215 dev .width , dev .height , dev .cropratio .numerator ,
200216 dev .cropratio .denominator ,
201217 dev .pix_fmt == VCAM_PIXFMT_RGB24 ? "rgb24" : "yuyv" ,
218+ dev .mem_type == VCAM_MEMORY_MMAP ? "mmap" : "dmabuf" ,
202219 dev .video_node );
203220 }
204221 close (fd );
@@ -258,6 +275,16 @@ int main(int argc, char *argv[])
258275 dev .pix_fmt = (char ) tmp ;
259276 printf ("Setting pixel format to %s.\n" , optarg );
260277 break ;
278+ case 't' :
279+ tmp = determine_memtype (optarg );
280+ if (tmp < 0 ) {
281+ fprintf (stderr , "Failed to recognize memory type %s.\n" ,
282+ optarg );
283+ exit (-1 );
284+ }
285+ dev .mem_type = (char ) tmp ;
286+ printf ("Setting memory type to %s.\n" , optarg );
287+ break ;
261288 case 'd' :
262289 printf ("Using device %s.\n" , optarg );
263290 strncpy (ctl_path , optarg , sizeof (ctl_path ) - 1 );
0 commit comments