10
10
11
11
#include "vcam.h"
12
12
13
- static const char * short_options = "hcm:r:ls:p:d:" ;
13
+ static const char * short_options = "hcm:r:ls:p:d:t: " ;
14
14
15
15
const 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 }};
21
21
22
22
const char * help =
23
23
" -h --help Print this informations.\n"
@@ -37,6 +37,7 @@ const char *help =
37
37
"and apply with crop ratio.\n"
38
38
"\n"
39
39
" -p --pixfmt pix_fmt Specify pixel format (rgb24,yuyv).\n"
40
+ " -t --memtype mem_type Specify memory type (mmap,dmabuf).\n"
40
41
" -d --device /dev/* Control device node.\n" ;
41
42
42
43
enum ACTION { ACTION_NONE , ACTION_CREATE , ACTION_DESTROY , ACTION_MODIFY };
@@ -45,6 +46,7 @@ struct vcam_device_spec device_template = {
45
46
.width = 640 ,
46
47
.height = 480 ,
47
48
.pix_fmt = VCAM_PIXFMT_RGB24 ,
49
+ .mem_type = VCAM_MEMORY_MMAP ,
48
50
.video_node = "" ,
49
51
.fb_node = "" ,
50
52
};
@@ -102,6 +104,14 @@ int determine_pixfmt(char *pixfmt_str)
102
104
return -1 ;
103
105
}
104
106
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
+ }
105
115
int create_device (struct vcam_device_spec * dev )
106
116
{
107
117
int fd = open (ctl_path , O_RDWR );
@@ -118,6 +128,9 @@ int create_device(struct vcam_device_spec *dev)
118
128
if (!dev -> pix_fmt )
119
129
dev -> pix_fmt = device_template .pix_fmt ;
120
130
131
+ if (!dev -> mem_type )
132
+ dev -> mem_type = device_template .mem_type ;
133
+
121
134
int res = ioctl (fd , VCAM_IOCTL_CREATE_DEVICE , dev );
122
135
if (res ) {
123
136
fprintf (stderr , "Failed to create a new device.\n" );
@@ -170,6 +183,9 @@ int modify_device(struct vcam_device_spec *dev)
170
183
if (!dev -> pix_fmt )
171
184
dev -> pix_fmt = orig_dev .pix_fmt ;
172
185
186
+ if (!dev -> mem_type )
187
+ dev -> mem_type = orig_dev .mem_type ;
188
+
173
189
if (!dev -> cropratio .numerator || !dev -> cropratio .denominator )
174
190
dev -> cropratio = orig_dev .cropratio ;
175
191
@@ -195,10 +211,11 @@ int list_devices()
195
211
printf ("Available virtual V4L2 compatible devices:\n" );
196
212
while (!ioctl (fd , VCAM_IOCTL_GET_DEVICE , & dev )) {
197
213
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 ,
199
215
dev .width , dev .height , dev .cropratio .numerator ,
200
216
dev .cropratio .denominator ,
201
217
dev .pix_fmt == VCAM_PIXFMT_RGB24 ? "rgb24" : "yuyv" ,
218
+ dev .mem_type == VCAM_MEMORY_MMAP ? "mmap" : "dmabuf" ,
202
219
dev .video_node );
203
220
}
204
221
close (fd );
@@ -258,6 +275,16 @@ int main(int argc, char *argv[])
258
275
dev .pix_fmt = (char ) tmp ;
259
276
printf ("Setting pixel format to %s.\n" , optarg );
260
277
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 ;
261
288
case 'd' :
262
289
printf ("Using device %s.\n" , optarg );
263
290
strncpy (ctl_path , optarg , sizeof (ctl_path ) - 1 );
0 commit comments