v4l2-ruby 0.9.2 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +5 -0
- data/README.md +1 -1
- data/Rakefile +12 -3
- data/ext/v4l2/camera.c +42 -5
- data/ext/v4l2/camera.h +10 -5
- data/ext/v4l2/v4l2.c +188 -93
- data/lib/v4l2/version.rb +1 -1
- data/pkg/.gitkeep +0 -0
- data/tests/config.yml +5 -0
- data/tests/lib/config.rb +21 -0
- data/tests/lib/test_util.rb +10 -0
- data/tests/run_unit.rb +24 -0
- data/tests/template.rb +30 -0
- data/tests/unit/capture/test_start.rb +49 -0
- data/tests/unit/config/test_set_format.rb +48 -0
- data/tests/unit/config/test_set_framerate.rb +57 -0
- data/tests/unit/config/test_set_image_size.rb +85 -0
- data/tests/unit/create_object/test_simple_create.rb +53 -0
- data/tests/unit/device_info/.test_get_bus_name.rb.swp +0 -0
- data/tests/unit/device_info/test_get_bus_name.rb +34 -0
- data/tests/unit/device_info/test_get_controls.rb +92 -0
- data/tests/unit/device_info/test_get_device_name.rb +34 -0
- data/tests/unit/device_info/test_get_driver_name.rb +34 -0
- data/tests/unit/device_info/test_get_formats.rb +58 -0
- data/tests/unit/device_info/test_get_framecap.rb +56 -0
- data/tests/unit/ractor/test_ractor.rb +67 -0
- data/v4l2-ruby.gemspec +3 -3
- metadata +36 -16
data/ext/v4l2/v4l2.c
CHANGED
@@ -15,6 +15,8 @@
|
|
15
15
|
|
16
16
|
#define N(x) (sizeof((x))/sizeof(*(x)))
|
17
17
|
|
18
|
+
#define EQ_STR(val,str) (rb_to_id(val) == rb_intern(str))
|
19
|
+
|
18
20
|
extern rb_encoding* rb_utf8_encoding(void);
|
19
21
|
extern rb_encoding* rb_default_internal_encoding(void);
|
20
22
|
|
@@ -29,14 +31,6 @@ static VALUE menu_item_klass;
|
|
29
31
|
static VALUE frame_cap_klass;
|
30
32
|
static VALUE fmt_desc_klass;
|
31
33
|
|
32
|
-
static ID id_yuyv;
|
33
|
-
static ID id_yuv422;
|
34
|
-
static ID id_nv21;
|
35
|
-
static ID id_nv12;
|
36
|
-
static ID id_nv16;
|
37
|
-
static ID id_rgb565;
|
38
|
-
static ID id_mjpeg;
|
39
|
-
static ID id_h264;
|
40
34
|
static ID id_iv_name;
|
41
35
|
static ID id_iv_driver;
|
42
36
|
static ID id_iv_bus;
|
@@ -53,6 +47,21 @@ static ID id_iv_rate;
|
|
53
47
|
static ID id_iv_fcc;
|
54
48
|
static ID id_iv_desc;
|
55
49
|
|
50
|
+
static void rb_camera_free(void* ptr);
|
51
|
+
static size_t rb_camera_size(const void* ptr);
|
52
|
+
|
53
|
+
static const rb_data_type_t camera_data_type = {
|
54
|
+
"V4L2 for ruby", // wrap_struct_name
|
55
|
+
NULL, // function.dmark
|
56
|
+
rb_camera_free, // function.dfree
|
57
|
+
rb_camera_size, // function.dsize
|
58
|
+
NULL, // function.dcompact
|
59
|
+
NULL, // reserved[0]
|
60
|
+
NULL, // parent
|
61
|
+
NULL, // data
|
62
|
+
(VALUE)RUBY_TYPED_FREE_IMMEDIATELY // flags
|
63
|
+
};
|
64
|
+
|
56
65
|
static void
|
57
66
|
rb_camera_free(void* ptr)
|
58
67
|
{
|
@@ -63,12 +72,18 @@ rb_camera_free(void* ptr)
|
|
63
72
|
free( ptr);
|
64
73
|
}
|
65
74
|
|
75
|
+
static size_t
|
76
|
+
rb_camera_size(const void* ptr)
|
77
|
+
{
|
78
|
+
return sizeof(camera_t);
|
79
|
+
}
|
80
|
+
|
66
81
|
static VALUE
|
67
82
|
rb_camera_alloc(VALUE self)
|
68
83
|
{
|
69
84
|
camera_t* ptr;
|
70
85
|
|
71
|
-
return
|
86
|
+
return TypedData_Make_Struct(camera_klass, camera_t, &camera_data_type, ptr);
|
72
87
|
}
|
73
88
|
|
74
89
|
static VALUE
|
@@ -96,7 +111,7 @@ rb_camera_initialize(VALUE self, VALUE dev)
|
|
96
111
|
/*
|
97
112
|
* strip object
|
98
113
|
*/
|
99
|
-
|
114
|
+
TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
|
100
115
|
|
101
116
|
/*
|
102
117
|
* initialize struct
|
@@ -111,8 +126,10 @@ rb_camera_initialize(VALUE self, VALUE dev)
|
|
111
126
|
*/
|
112
127
|
rb_ivar_set(self, id_iv_name,
|
113
128
|
rb_enc_str_new_cstr(ptr->name, rb_utf8_encoding()));
|
129
|
+
|
114
130
|
rb_ivar_set(self, id_iv_driver,
|
115
131
|
rb_enc_str_new_cstr(ptr->driver, rb_utf8_encoding()));
|
132
|
+
|
116
133
|
rb_ivar_set(self, id_iv_bus,
|
117
134
|
rb_enc_str_new_cstr(ptr->bus, rb_utf8_encoding()));
|
118
135
|
|
@@ -124,19 +141,34 @@ rb_camera_close( VALUE self)
|
|
124
141
|
{
|
125
142
|
int err;
|
126
143
|
camera_t* ptr;
|
144
|
+
int ready;
|
127
145
|
|
128
146
|
/*
|
129
147
|
* strip object
|
130
148
|
*/
|
131
|
-
|
149
|
+
TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
|
132
150
|
|
133
151
|
/*
|
134
|
-
*
|
152
|
+
* do close
|
135
153
|
*/
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
154
|
+
do {
|
155
|
+
err = camera_check_ready(ptr, &ready);
|
156
|
+
if (err) {
|
157
|
+
rb_raise(rb_eRuntimeError, "camera_check_ready() failed.");
|
158
|
+
}
|
159
|
+
|
160
|
+
if (ready) {
|
161
|
+
err = camera_stop(ptr);
|
162
|
+
if (err) {
|
163
|
+
rb_raise(rb_eRuntimeError, "camera_stop() failed.");
|
164
|
+
}
|
165
|
+
}
|
166
|
+
|
167
|
+
err = camera_finalize(ptr);
|
168
|
+
if (err) {
|
169
|
+
rb_raise(rb_eRuntimeError, "finalize camera context failed.");
|
170
|
+
}
|
171
|
+
} while (0);
|
140
172
|
|
141
173
|
return Qnil;
|
142
174
|
}
|
@@ -204,9 +236,11 @@ get_control_info(camera_t* ptr, int ctrl)
|
|
204
236
|
VALUE name;
|
205
237
|
int err;
|
206
238
|
struct v4l2_queryctrl info;
|
239
|
+
VALUE list;
|
207
240
|
|
208
241
|
ret = Qnil;
|
209
242
|
err = camera_get_control_info(ptr, ctrl, &info);
|
243
|
+
|
210
244
|
if (!err) {
|
211
245
|
switch (info.type) {
|
212
246
|
case V4L2_CTRL_TYPE_INTEGER:
|
@@ -236,24 +270,24 @@ get_control_info(camera_t* ptr, int ctrl)
|
|
236
270
|
ret = rb_obj_alloc(menu_klass);
|
237
271
|
name = rb_enc_str_new_cstr((const char*)info.name,
|
238
272
|
rb_utf8_encoding());
|
273
|
+
list = get_menu_list(ptr, ctrl, info.minimum, info.maximum);
|
239
274
|
|
240
275
|
rb_ivar_set(ret, id_iv_name, name);
|
241
276
|
rb_ivar_set(ret, id_iv_id, INT2NUM(info.id));
|
242
277
|
rb_ivar_set(ret, id_iv_default, INT2FIX(info.default_value));
|
243
|
-
rb_ivar_set(ret, id_iv_items,
|
244
|
-
get_menu_list(ptr, ctrl, info.minimum, info.maximum));
|
278
|
+
rb_ivar_set(ret, id_iv_items, list);
|
245
279
|
break;
|
246
280
|
|
247
281
|
case V4L2_CTRL_TYPE_INTEGER_MENU:
|
248
282
|
ret = rb_obj_alloc(menu_klass);
|
249
283
|
name = rb_enc_str_new_cstr((const char*)info.name,
|
250
284
|
rb_utf8_encoding());
|
285
|
+
list = get_int_menu_list(ptr, ctrl, info.minimum, info.maximum);
|
251
286
|
|
252
287
|
rb_ivar_set(ret, id_iv_name, name);
|
253
288
|
rb_ivar_set(ret, id_iv_id, INT2NUM(info.id));
|
254
289
|
rb_ivar_set(ret, id_iv_default, INT2FIX(info.default_value));
|
255
|
-
rb_ivar_set(ret, id_iv_items,
|
256
|
-
get_int_menu_list(ptr, ctrl, info.minimum, info.maximum));
|
290
|
+
rb_ivar_set(ret, id_iv_items, list);
|
257
291
|
break;
|
258
292
|
|
259
293
|
default:
|
@@ -274,7 +308,7 @@ rb_camera_get_controls(VALUE self)
|
|
274
308
|
int i;
|
275
309
|
VALUE info;
|
276
310
|
|
277
|
-
|
311
|
+
TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
|
278
312
|
|
279
313
|
ret = rb_ary_new();
|
280
314
|
|
@@ -297,27 +331,49 @@ rb_camera_get_controls(VALUE self)
|
|
297
331
|
}
|
298
332
|
|
299
333
|
static VALUE
|
300
|
-
get_framerate_list(camera_t* cam,
|
334
|
+
get_framerate_list(camera_t* cam,
|
335
|
+
uint32_t fmt, struct v4l2_frmsize_discrete* size)
|
301
336
|
{
|
302
337
|
VALUE ret;
|
303
338
|
int i;
|
304
|
-
|
305
339
|
int err;
|
306
340
|
struct v4l2_frmivalenum intval;
|
307
341
|
VALUE rate;
|
342
|
+
int num;
|
343
|
+
int deno;
|
308
344
|
|
309
345
|
ret = rb_ary_new();
|
310
346
|
|
311
347
|
for (i = 0; ; i++) {
|
312
|
-
err = camera_get_frame_rate(cam,
|
348
|
+
err = camera_get_frame_rate(cam, fmt,
|
313
349
|
size->width, size->height, i, &intval);
|
314
350
|
if (err) break;
|
315
351
|
|
316
|
-
|
352
|
+
switch (intval.type) {
|
353
|
+
case V4L2_FRMIVAL_TYPE_DISCRETE:
|
317
354
|
rate = rb_rational_new(INT2FIX(intval.discrete.denominator),
|
318
355
|
INT2FIX(intval.discrete.numerator));
|
319
356
|
|
320
357
|
rb_ary_push(ret, rate);
|
358
|
+
break;
|
359
|
+
|
360
|
+
case V4L2_FRMIVAL_TYPE_CONTINUOUS:
|
361
|
+
case V4L2_FRMIVAL_TYPE_STEPWISE:
|
362
|
+
num = intval.stepwise.max.numerator;
|
363
|
+
deno = intval.stepwise.max.denominator;
|
364
|
+
|
365
|
+
while (num <= intval.stepwise.min.numerator) {
|
366
|
+
while (deno <= intval.stepwise.min.denominator) {
|
367
|
+
rate = rb_rational_new(INT2FIX(deno), INT2FIX(num));
|
368
|
+
rb_ary_push(ret, rate);
|
369
|
+
|
370
|
+
deno += intval.stepwise.step.denominator;
|
371
|
+
}
|
372
|
+
|
373
|
+
num += intval.stepwise.step.numerator;
|
374
|
+
deno = intval.stepwise.max.denominator;
|
375
|
+
}
|
376
|
+
break;
|
321
377
|
}
|
322
378
|
}
|
323
379
|
|
@@ -328,29 +384,35 @@ static uint32_t
|
|
328
384
|
to_pixfmt(VALUE fmt)
|
329
385
|
{
|
330
386
|
uint32_t ret;
|
331
|
-
ID sym;
|
332
387
|
|
333
|
-
|
334
|
-
|
335
|
-
if (sym == id_yuyv || sym == id_yuv422) {
|
388
|
+
if (EQ_STR(fmt, "YUYV") || EQ_STR(fmt, "YUV422")) {
|
336
389
|
ret = V4L2_PIX_FMT_YUYV;
|
337
390
|
|
338
|
-
} else if (
|
391
|
+
} else if (EQ_STR(fmt, "NV12")) {
|
339
392
|
ret = V4L2_PIX_FMT_NV12;
|
340
393
|
|
341
|
-
} else if (
|
394
|
+
} else if (EQ_STR(fmt, "NV21")) {
|
342
395
|
ret = V4L2_PIX_FMT_NV21;
|
343
396
|
|
344
|
-
} else if (
|
397
|
+
} else if (EQ_STR(fmt, "NV16")) {
|
398
|
+
ret = V4L2_PIX_FMT_NV16;
|
399
|
+
|
400
|
+
} else if (EQ_STR(fmt, "YUV420") || EQ_STR(fmt, "YU12")) {
|
401
|
+
ret = V4L2_PIX_FMT_YUV420;
|
402
|
+
|
403
|
+
} else if (EQ_STR(fmt, "YVU420") || EQ_STR(fmt, "YV12")) {
|
404
|
+
ret = V4L2_PIX_FMT_YVU420;
|
405
|
+
|
406
|
+
} else if (EQ_STR(fmt, "NV16")) {
|
345
407
|
ret = V4L2_PIX_FMT_NV16;
|
346
408
|
|
347
|
-
} else if (
|
409
|
+
} else if (EQ_STR(fmt, "RGB565") || EQ_STR(fmt, "RGBP")) {
|
348
410
|
ret = V4L2_PIX_FMT_RGB565;
|
349
411
|
|
350
|
-
} else if (
|
412
|
+
} else if (EQ_STR(fmt, "MJPEG") || EQ_STR(fmt, "MJPG")) {
|
351
413
|
ret = V4L2_PIX_FMT_MJPEG;
|
352
414
|
|
353
|
-
} else if (
|
415
|
+
} else if (EQ_STR(fmt, "H264")) {
|
354
416
|
ret = V4L2_PIX_FMT_H264;
|
355
417
|
|
356
418
|
} else {
|
@@ -374,7 +436,7 @@ rb_camera_get_support_formats(VALUE self)
|
|
374
436
|
VALUE fcc;
|
375
437
|
VALUE str;
|
376
438
|
|
377
|
-
|
439
|
+
TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
|
378
440
|
|
379
441
|
ret = rb_ary_new();
|
380
442
|
|
@@ -403,7 +465,8 @@ rb_camera_get_support_formats(VALUE self)
|
|
403
465
|
}
|
404
466
|
|
405
467
|
static void
|
406
|
-
make_dummy_capabilities(camera_t* ptr, VALUE ary,
|
468
|
+
make_dummy_capabilities(camera_t* ptr, VALUE ary,
|
469
|
+
uint32_t fmt, int max_width, int max_height)
|
407
470
|
{
|
408
471
|
struct v4l2_frmsize_discrete dsize;
|
409
472
|
VALUE capa;
|
@@ -419,7 +482,7 @@ make_dummy_capabilities(camera_t* ptr, VALUE ary, int max_width, int max_height)
|
|
419
482
|
capa = rb_obj_alloc(frame_cap_klass);
|
420
483
|
rb_ivar_set(capa, id_iv_width, INT2NUM(dsize.width));
|
421
484
|
rb_ivar_set(capa, id_iv_height, INT2NUM(dsize.height));
|
422
|
-
rb_ivar_set(capa, id_iv_rate, get_framerate_list(ptr, &dsize));
|
485
|
+
rb_ivar_set(capa, id_iv_rate, get_framerate_list(ptr, fmt, &dsize));
|
423
486
|
|
424
487
|
rb_ary_push(ary, capa);
|
425
488
|
|
@@ -428,7 +491,7 @@ make_dummy_capabilities(camera_t* ptr, VALUE ary, int max_width, int max_height)
|
|
428
491
|
capa = rb_obj_alloc(frame_cap_klass);
|
429
492
|
rb_ivar_set(capa, id_iv_width, INT2NUM(dsize.width));
|
430
493
|
rb_ivar_set(capa, id_iv_height, INT2NUM(dsize.height));
|
431
|
-
rb_ivar_set(capa, id_iv_rate, get_framerate_list(ptr, &dsize));
|
494
|
+
rb_ivar_set(capa, id_iv_rate, get_framerate_list(ptr, fmt, &dsize));
|
432
495
|
|
433
496
|
rb_ary_push(ary, capa);
|
434
497
|
}
|
@@ -446,7 +509,7 @@ make_dummy_capabilities(camera_t* ptr, VALUE ary, int max_width, int max_height)
|
|
446
509
|
capa = rb_obj_alloc(frame_cap_klass);
|
447
510
|
rb_ivar_set(capa, id_iv_width, INT2NUM(dsize.width));
|
448
511
|
rb_ivar_set(capa, id_iv_height, INT2NUM(dsize.height));
|
449
|
-
rb_ivar_set(capa, id_iv_rate, get_framerate_list(ptr, &dsize));
|
512
|
+
rb_ivar_set(capa, id_iv_rate, get_framerate_list(ptr, fmt, &dsize));
|
450
513
|
|
451
514
|
rb_ary_push(ary, capa);
|
452
515
|
|
@@ -455,7 +518,7 @@ make_dummy_capabilities(camera_t* ptr, VALUE ary, int max_width, int max_height)
|
|
455
518
|
capa = rb_obj_alloc(frame_cap_klass);
|
456
519
|
rb_ivar_set(capa, id_iv_width, INT2NUM(dsize.width));
|
457
520
|
rb_ivar_set(capa, id_iv_height, INT2NUM(dsize.height));
|
458
|
-
rb_ivar_set(capa, id_iv_rate, get_framerate_list(ptr, &dsize));
|
521
|
+
rb_ivar_set(capa, id_iv_rate, get_framerate_list(ptr, fmt, &dsize));
|
459
522
|
|
460
523
|
rb_ary_push(ary, capa);
|
461
524
|
}
|
@@ -463,12 +526,13 @@ make_dummy_capabilities(camera_t* ptr, VALUE ary, int max_width, int max_height)
|
|
463
526
|
}
|
464
527
|
|
465
528
|
static VALUE
|
466
|
-
rb_camera_get_frame_capabilities(VALUE self, VALUE
|
529
|
+
rb_camera_get_frame_capabilities(VALUE self, VALUE _fmt)
|
467
530
|
{
|
468
531
|
VALUE ret;
|
469
532
|
camera_t* ptr;
|
470
533
|
int i;
|
471
534
|
int j;
|
535
|
+
uint32_t fmt;
|
472
536
|
|
473
537
|
int err;
|
474
538
|
struct v4l2_frmsizeenum size;
|
@@ -477,26 +541,29 @@ rb_camera_get_frame_capabilities(VALUE self, VALUE fmt)
|
|
477
541
|
VALUE list;
|
478
542
|
VALUE rate;
|
479
543
|
|
480
|
-
|
481
|
-
|
482
|
-
Data_Get_Struct(self, camera_t, ptr);
|
544
|
+
TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
|
483
545
|
|
484
546
|
ret = rb_ary_new();
|
547
|
+
fmt = to_pixfmt(_fmt);
|
485
548
|
|
486
549
|
for (i = 0; ;i++){
|
487
|
-
err = camera_get_frame_size(ptr,
|
550
|
+
err = camera_get_frame_size(ptr, fmt, i, &size);
|
488
551
|
if (err) break;
|
489
552
|
|
490
553
|
if (size.type == V4L2_FRMSIZE_TYPE_DISCRETE) {
|
491
554
|
capa = rb_obj_alloc(frame_cap_klass);
|
555
|
+
list = get_framerate_list(ptr, fmt, &size.discrete);
|
556
|
+
|
492
557
|
rb_ivar_set(capa, id_iv_width, INT2NUM(size.discrete.width));
|
493
558
|
rb_ivar_set(capa, id_iv_height, INT2NUM(size.discrete.height));
|
494
|
-
rb_ivar_set(capa, id_iv_rate,
|
559
|
+
rb_ivar_set(capa, id_iv_rate, list);
|
495
560
|
|
496
561
|
rb_ary_push(ret, capa);
|
497
562
|
|
498
563
|
} else if (size.type == V4L2_FRMSIZE_TYPE_STEPWISE) {
|
499
|
-
make_dummy_capabilities(ptr,
|
564
|
+
make_dummy_capabilities(ptr,
|
565
|
+
ret,
|
566
|
+
fmt,
|
500
567
|
size.stepwise.max_width,
|
501
568
|
size.stepwise.max_height);
|
502
569
|
break;
|
@@ -513,7 +580,7 @@ rb_camera_set_control(VALUE self, VALUE id, VALUE _val)
|
|
513
580
|
int err;
|
514
581
|
int val;
|
515
582
|
|
516
|
-
|
583
|
+
TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
|
517
584
|
|
518
585
|
switch (TYPE(_val)) {
|
519
586
|
case T_TRUE:
|
@@ -547,7 +614,7 @@ rb_camera_get_control(VALUE self, VALUE id)
|
|
547
614
|
int err;
|
548
615
|
int32_t value;
|
549
616
|
|
550
|
-
|
617
|
+
TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
|
551
618
|
|
552
619
|
err = camera_get_control(ptr, FIX2INT(id), &value);
|
553
620
|
if (err) {
|
@@ -563,15 +630,10 @@ rb_camera_set_format(VALUE self, VALUE fmt)
|
|
563
630
|
camera_t* ptr;
|
564
631
|
int err;
|
565
632
|
|
566
|
-
/*
|
567
|
-
* argument check
|
568
|
-
*/
|
569
|
-
Check_Type(fmt, T_SYMBOL);
|
570
|
-
|
571
633
|
/*
|
572
634
|
* strip object
|
573
635
|
*/
|
574
|
-
|
636
|
+
TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
|
575
637
|
|
576
638
|
/*
|
577
639
|
* set parameter
|
@@ -594,7 +656,7 @@ rb_camera_get_image_width(VALUE self)
|
|
594
656
|
/*
|
595
657
|
* strip object
|
596
658
|
*/
|
597
|
-
|
659
|
+
TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
|
598
660
|
|
599
661
|
/*
|
600
662
|
* get parameter
|
@@ -613,20 +675,15 @@ rb_camera_set_image_width(VALUE self, VALUE val)
|
|
613
675
|
camera_t* ptr;
|
614
676
|
int err;
|
615
677
|
|
616
|
-
/*
|
617
|
-
* argument check
|
618
|
-
*/
|
619
|
-
Check_Type(val, T_FIXNUM);
|
620
|
-
|
621
678
|
/*
|
622
679
|
* strip object
|
623
680
|
*/
|
624
|
-
|
681
|
+
TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
|
625
682
|
|
626
683
|
/*
|
627
684
|
* set parameter
|
628
685
|
*/
|
629
|
-
err = camera_set_image_width(ptr,
|
686
|
+
err = camera_set_image_width(ptr, NUM2INT(val));
|
630
687
|
if (err) {
|
631
688
|
rb_raise(rb_eRuntimeError, "set image width failed.");
|
632
689
|
}
|
@@ -644,7 +701,7 @@ rb_camera_get_image_height(VALUE self)
|
|
644
701
|
/*
|
645
702
|
* strip object
|
646
703
|
*/
|
647
|
-
|
704
|
+
TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
|
648
705
|
|
649
706
|
/*
|
650
707
|
* get parameter
|
@@ -663,20 +720,15 @@ rb_camera_set_image_height(VALUE self, VALUE val)
|
|
663
720
|
camera_t* ptr;
|
664
721
|
int err;
|
665
722
|
|
666
|
-
/*
|
667
|
-
* argument check
|
668
|
-
*/
|
669
|
-
Check_Type(val, T_FIXNUM);
|
670
|
-
|
671
723
|
/*
|
672
724
|
* strip object
|
673
725
|
*/
|
674
|
-
|
726
|
+
TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
|
675
727
|
|
676
728
|
/*
|
677
729
|
* set parameter
|
678
730
|
*/
|
679
|
-
err = camera_set_image_height(ptr,
|
731
|
+
err = camera_set_image_height(ptr, NUM2INT(val));
|
680
732
|
if (err) {
|
681
733
|
rb_raise(rb_eRuntimeError, "set image height failed.");
|
682
734
|
}
|
@@ -687,7 +739,21 @@ rb_camera_set_image_height(VALUE self, VALUE val)
|
|
687
739
|
static VALUE
|
688
740
|
rb_camera_get_framerate(VALUE self)
|
689
741
|
{
|
690
|
-
|
742
|
+
VALUE ret;
|
743
|
+
camera_t* ptr;
|
744
|
+
|
745
|
+
/*
|
746
|
+
* strip object
|
747
|
+
*/
|
748
|
+
TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
|
749
|
+
|
750
|
+
/*
|
751
|
+
* create return object
|
752
|
+
*/
|
753
|
+
ret = rb_rational_new(INT2FIX(ptr->framerate.num),
|
754
|
+
INT2FIX(ptr->framerate.denom));
|
755
|
+
|
756
|
+
return ret;
|
691
757
|
}
|
692
758
|
|
693
759
|
static VALUE
|
@@ -718,13 +784,13 @@ rb_camera_set_framerate(VALUE self, VALUE val)
|
|
718
784
|
break;
|
719
785
|
|
720
786
|
default:
|
721
|
-
rb_raise(
|
787
|
+
rb_raise(rb_eTypeError, "illeagal framerate value.");
|
722
788
|
}
|
723
789
|
|
724
790
|
/*
|
725
791
|
* strip object
|
726
792
|
*/
|
727
|
-
|
793
|
+
TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
|
728
794
|
|
729
795
|
/*
|
730
796
|
* set framerate
|
@@ -746,7 +812,7 @@ rb_camera_state( VALUE self)
|
|
746
812
|
/*
|
747
813
|
* strip object
|
748
814
|
*/
|
749
|
-
|
815
|
+
TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
|
750
816
|
|
751
817
|
/*
|
752
818
|
* convert state code
|
@@ -789,21 +855,31 @@ rb_camera_start(VALUE self)
|
|
789
855
|
{
|
790
856
|
int err;
|
791
857
|
camera_t* ptr;
|
858
|
+
int state;
|
792
859
|
|
793
860
|
/*
|
794
861
|
* strip object
|
795
862
|
*/
|
796
|
-
|
863
|
+
TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
|
797
864
|
|
798
865
|
/*
|
799
|
-
*
|
866
|
+
* do start
|
800
867
|
*/
|
801
868
|
err = camera_start(ptr);
|
802
869
|
if (err) {
|
803
870
|
rb_raise(rb_eRuntimeError, "start capture failed.");
|
804
871
|
}
|
805
872
|
|
806
|
-
|
873
|
+
/*
|
874
|
+
*
|
875
|
+
*/
|
876
|
+
if (rb_block_given_p()) {
|
877
|
+
rb_protect(rb_yield, self, &state);
|
878
|
+
camera_stop(ptr);
|
879
|
+
if (state) rb_jump_tag(state);
|
880
|
+
}
|
881
|
+
|
882
|
+
return self;
|
807
883
|
}
|
808
884
|
|
809
885
|
static VALUE
|
@@ -815,7 +891,7 @@ rb_camera_stop(VALUE self)
|
|
815
891
|
/*
|
816
892
|
* strip object
|
817
893
|
*/
|
818
|
-
|
894
|
+
TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
|
819
895
|
|
820
896
|
/*
|
821
897
|
* convert
|
@@ -825,7 +901,7 @@ rb_camera_stop(VALUE self)
|
|
825
901
|
rb_raise(rb_eRuntimeError, "stop capture failed.");
|
826
902
|
}
|
827
903
|
|
828
|
-
return
|
904
|
+
return self;
|
829
905
|
}
|
830
906
|
|
831
907
|
|
@@ -840,7 +916,7 @@ rb_camera_capture(VALUE self)
|
|
840
916
|
/*
|
841
917
|
* strip object
|
842
918
|
*/
|
843
|
-
|
919
|
+
TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
|
844
920
|
|
845
921
|
/*
|
846
922
|
* allocate return value.
|
@@ -873,7 +949,7 @@ rb_camera_is_busy(VALUE self)
|
|
873
949
|
/*
|
874
950
|
* strip object
|
875
951
|
*/
|
876
|
-
|
952
|
+
TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
|
877
953
|
|
878
954
|
/*
|
879
955
|
* do check
|
@@ -886,6 +962,29 @@ rb_camera_is_busy(VALUE self)
|
|
886
962
|
return (busy)? Qtrue: Qfalse;
|
887
963
|
}
|
888
964
|
|
965
|
+
static VALUE
|
966
|
+
rb_camera_is_ready(VALUE self)
|
967
|
+
{
|
968
|
+
camera_t* ptr;
|
969
|
+
int err;
|
970
|
+
int ready;
|
971
|
+
|
972
|
+
/*
|
973
|
+
* strip object
|
974
|
+
*/
|
975
|
+
TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
|
976
|
+
|
977
|
+
/*
|
978
|
+
* do check
|
979
|
+
*/
|
980
|
+
err = camera_check_ready(ptr, &ready);
|
981
|
+
if (err) {
|
982
|
+
rb_raise(rb_eRuntimeError, "check failed.");
|
983
|
+
}
|
984
|
+
|
985
|
+
return (ready)? Qtrue: Qfalse;
|
986
|
+
}
|
987
|
+
|
889
988
|
static VALUE
|
890
989
|
rb_camera_is_error(VALUE self)
|
891
990
|
{
|
@@ -896,7 +995,7 @@ rb_camera_is_error(VALUE self)
|
|
896
995
|
/*
|
897
996
|
* strip object
|
898
997
|
*/
|
899
|
-
|
998
|
+
TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
|
900
999
|
|
901
1000
|
/*
|
902
1001
|
* do check
|
@@ -912,6 +1011,10 @@ rb_camera_is_error(VALUE self)
|
|
912
1011
|
void
|
913
1012
|
Init_v4l2()
|
914
1013
|
{
|
1014
|
+
#ifdef HAVE_RB_EXT_RACTOR_SAFE
|
1015
|
+
rb_ext_ractor_safe(true);
|
1016
|
+
#endif /* defined(HAVE_RB_EXT_RACTOR_SAFE) */
|
1017
|
+
|
915
1018
|
rb_require("monitor");
|
916
1019
|
|
917
1020
|
module = rb_define_module("Video4Linux2");
|
@@ -939,6 +1042,7 @@ Init_v4l2()
|
|
939
1042
|
rb_define_method(camera_klass, "stop", rb_camera_stop, 0);
|
940
1043
|
rb_define_method(camera_klass, "capture", rb_camera_capture, 0);
|
941
1044
|
rb_define_method(camera_klass, "busy?", rb_camera_is_busy, 0);
|
1045
|
+
rb_define_method(camera_klass, "ready?", rb_camera_is_ready, 0);
|
942
1046
|
rb_define_method(camera_klass, "error?", rb_camera_is_error, 0);
|
943
1047
|
|
944
1048
|
rb_define_attr(camera_klass, "name", !0, 0);
|
@@ -951,7 +1055,6 @@ Init_v4l2()
|
|
951
1055
|
"Control", rb_cObject);
|
952
1056
|
rb_define_attr(control_klass, "name", !0, 0);
|
953
1057
|
rb_define_attr(control_klass, "id", !0, 0);
|
954
|
-
rb_define_attr(control_klass, "value", !0, 0);
|
955
1058
|
|
956
1059
|
integer_klass = rb_define_class_under(camera_klass,
|
957
1060
|
"IntegerControl", control_klass);
|
@@ -985,14 +1088,6 @@ Init_v4l2()
|
|
985
1088
|
rb_define_attr(fmt_desc_klass, "fcc", !0, 0);
|
986
1089
|
rb_define_attr(fmt_desc_klass, "description", !0, 0);
|
987
1090
|
|
988
|
-
id_yuyv = rb_intern_const("YUYV");
|
989
|
-
id_yuv422 = rb_intern_const("YUV422");
|
990
|
-
id_nv12 = rb_intern_const("NV12");
|
991
|
-
id_nv21 = rb_intern_const("NV21");
|
992
|
-
id_nv16 = rb_intern_const("NV16");
|
993
|
-
id_rgb565 = rb_intern_const("RGB565");
|
994
|
-
id_mjpeg = rb_intern_const("MJPEG");
|
995
|
-
id_h264 = rb_intern_const("H264");
|
996
1091
|
id_iv_name = rb_intern_const("@name");
|
997
1092
|
id_iv_driver = rb_intern_const("@driver");
|
998
1093
|
id_iv_bus = rb_intern_const("@bus");
|
data/lib/v4l2/version.rb
CHANGED
data/pkg/.gitkeep
ADDED
File without changes
|
data/tests/config.yml
ADDED
data/tests/lib/config.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# coding: utf-8
|
3
|
+
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
module Config
|
7
|
+
class << self
|
8
|
+
def config
|
9
|
+
return @config ||= YAML.load_file("config.yml")
|
10
|
+
end
|
11
|
+
private :config
|
12
|
+
|
13
|
+
def device
|
14
|
+
return config["target_device"]
|
15
|
+
end
|
16
|
+
|
17
|
+
def show_data?
|
18
|
+
return config["show_data"]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|