v4l2-ruby 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d31f555fce10530df57c6d98af41f9ad8008f666dd997a74d511ae8e41e0fec
4
- data.tar.gz: 812507ef8f3c6fa913d2b1e1513111b630850481e21cc93a3a9d8126f6f61f22
3
+ metadata.gz: 8cd2fedcc6514a3b25e69d923538b2c044ccca1a6883ce5320fe7b2e22f4819b
4
+ data.tar.gz: 0b90ab5883e8c9835477e91e411e75a9b657b32e91a66ea52768271313af6634
5
5
  SHA512:
6
- metadata.gz: 03b24506c311f989e117ef35926f93c5f2c00c593fec3810a44dc7d6c72619ae395aaf2a5dbce3ac9458526877807b40ce46194c39eeca192d4067e522bc18ad
7
- data.tar.gz: 9a1f9fe2899bf1e1ee40cd3305b4ff54f36c6341387fc342f435cf4b570ecc82d137f31c5ae45ae59f31ec8d1930bb86c7f5de5e03f68dc7ae70857ea276b40e
6
+ metadata.gz: a7f1da3bad3e6f4d1b45b5d8cf6c47765880ad557936de1a5fca4a829ea18930f208deb9382fbff57bab13bb33d6a74281df82226d08d00058a904ceb8d48173
7
+ data.tar.gz: e2631f2c448cd16b2ca1cb8de0ebe83e686b17397d0f56301b3b06824f6decfa120d2800d59729f3f44ab5b62b691bc0e8d52eec4c3d141fea38a99074c11ea0
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ .rbenv-gemsets
2
+ .ruby-version
3
+ Gemfile.lock
4
+ pkg/*
5
+ tags
data/README.md CHANGED
@@ -19,7 +19,7 @@ Or install it yourself as:
19
19
 
20
20
  ## Usage
21
21
 
22
- ```
22
+ ```ruby
23
23
  #! /usr/bin/env ruby
24
24
  # coding: utf-8
25
25
 
data/Rakefile CHANGED
@@ -3,6 +3,15 @@ require "rake/extensiontask"
3
3
 
4
4
  task :default => :spec
5
5
 
6
- Rake::ExtensionTask.new("v4l2") do |ext|
7
- ext.lib_dir = "lib/v4l2"
8
- end
6
+ spec = Gem::Specification.load("v4l2-ruby.gemspec")
7
+
8
+ # add your default gem packing task
9
+ Gem::PackageTask.new(spec) {|pkg|}
10
+
11
+ # feed the ExtensionTask with your spec
12
+ Rake::ExtensionTask.new('v4l2-ruby', spec) { |ext|
13
+ ext.name = "v4l2"
14
+ ext.ext_dir = "ext/v4l2"
15
+ ext.cross_compile = true
16
+ ext.lib_dir = File.join(*["lib", "v4l2", ENV["FAT_DIR"]].compact)
17
+ }
data/ext/v4l2/camera.c CHANGED
@@ -61,7 +61,7 @@
61
61
  #define ST_STOPPING (6)
62
62
  #define ST_FINALIZED (7)
63
63
 
64
- static int xioctl(int fh, int request, void *arg)
64
+ static int xioctl(int fh, unsigned long request, void *arg)
65
65
  {
66
66
  int r;
67
67
 
@@ -154,7 +154,7 @@ set_format(int fd, uint32_t fcc, int wd, int ht)
154
154
  fmt.fmt.pix.width = wd;
155
155
  fmt.fmt.pix.height = ht;
156
156
  fmt.fmt.pix.pixelformat = fcc;
157
- fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
157
+ fmt.fmt.pix.field = V4L2_FIELD_ANY;
158
158
 
159
159
  err = xioctl(fd, VIDIOC_S_FMT, &fmt);
160
160
  if (err < 0) {
@@ -1262,8 +1262,15 @@ camera_stop(camera_t* cam)
1262
1262
  for (i = 0; i < NUM_PLANE; i++) mb_discard(cam->mb + i);
1263
1263
 
1264
1264
  cam->fd = open(cam->device, O_RDWR);
1265
- cam->state = ST_INITIALIZED;
1266
- cam->latest = -1;
1265
+ if (cam->fd >= 0) {
1266
+ cam->state = ST_INITIALIZED;
1267
+ cam->latest = -1;
1268
+
1269
+ } else {
1270
+ cam->state = ST_ERROR;
1271
+ cam->latest = -1;
1272
+ break;
1273
+ }
1267
1274
 
1268
1275
  } else {
1269
1276
  /*
@@ -1378,7 +1385,7 @@ camera_check_busy(camera_t* cam, int* busy)
1378
1385
  fmt.fmt.pix.width = cam->width;
1379
1386
  fmt.fmt.pix.height = cam->height;
1380
1387
  fmt.fmt.pix.pixelformat = cam->format;
1381
- fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
1388
+ fmt.fmt.pix.field = V4L2_FIELD_ANY;
1382
1389
 
1383
1390
  err = xioctl(cam->fd, VIDIOC_S_FMT, &fmt);
1384
1391
  if (err >= 0) {
@@ -1397,6 +1404,36 @@ camera_check_busy(camera_t* cam, int* busy)
1397
1404
  return ret;
1398
1405
  }
1399
1406
 
1407
+ int
1408
+ camera_check_ready(camera_t* cam, int* ready)
1409
+ {
1410
+ int ret;
1411
+ int err;
1412
+ struct v4l2_format fmt;
1413
+
1414
+ do {
1415
+ /*
1416
+ * entry process
1417
+ */
1418
+ ret = !0;
1419
+
1420
+ /*
1421
+ * check arguments
1422
+ */
1423
+ if (cam == NULL) break;
1424
+ if (ready == NULL) break;
1425
+
1426
+ /*
1427
+ * do check (check state)
1428
+ */
1429
+ *ready = (cam->state == ST_READY);
1430
+
1431
+ ret = 0;
1432
+ } while(0);
1433
+
1434
+ return ret;
1435
+ }
1436
+
1400
1437
  int
1401
1438
  camera_check_error(camera_t* cam, int* error)
1402
1439
  {
data/ext/v4l2/camera.h CHANGED
@@ -23,7 +23,11 @@
23
23
  #include <pthread.h>
24
24
  #endif /* !defined(RUBY_EXTLIB) */
25
25
 
26
+ #ifdef __OpenBSD__
27
+ #include <sys/videoio.h>
28
+ #else
26
29
  #include <linux/videodev2.h>
30
+ #endif
27
31
 
28
32
  #define MAX_PLANE 3
29
33
 
@@ -68,13 +72,13 @@ typedef struct __camera__ {
68
72
  #ifndef V4L2_CTRL_TYPE_INTEGER_MENU
69
73
  #define V4L2_CTRL_TYPE_INTEGER_MENU 9
70
74
  struct __v4l2_querymenu_substitute_ {
71
- __u32 id;
72
- __u32 index;
75
+ uint32_t id;
76
+ uint32_t index;
73
77
  union {
74
- __u8 name[32];
75
- __s64 value;
78
+ uint8_t name[32];
79
+ int64_t value;
76
80
  };
77
- __u32 reserved;
81
+ uint32_t reserved;
78
82
  } __attribute__ ((packed));
79
83
 
80
84
  #define v4l2_querymenu __v4l2_querymenu_substitute_
@@ -109,6 +113,7 @@ extern int camera_set_framerate(camera_t* cam, int num, int denom);
109
113
  extern int camera_get_image_size(camera_t* cam, size_t* sz);
110
114
  extern int camera_get_image(camera_t* cam, void* ptr, size_t* used);
111
115
  extern int camera_check_busy(camera_t* cam, int *busy);
116
+ extern int camera_check_ready(camera_t* cam, int *ready);
112
117
  extern int camera_check_error(camera_t* cam, int *error);
113
118
 
114
119
  extern int camera_get_format_desc(camera_t* cam, int i,
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 Data_Make_Struct(camera_klass, camera_t, 0, rb_camera_free, ptr);
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
- Data_Get_Struct(self, camera_t, ptr);
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
- Data_Get_Struct(self, camera_t, ptr);
149
+ TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
132
150
 
133
151
  /*
134
- * convert
152
+ * do close
135
153
  */
136
- err = camera_finalize(ptr);
137
- if (err) {
138
- rb_raise(rb_eRuntimeError, "finalize camera context failed.");
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
- Data_Get_Struct(self, camera_t, ptr);
311
+ TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
278
312
 
279
313
  ret = rb_ary_new();
280
314
 
@@ -350,29 +384,35 @@ static uint32_t
350
384
  to_pixfmt(VALUE fmt)
351
385
  {
352
386
  uint32_t ret;
353
- ID sym;
354
-
355
- sym = rb_to_id(fmt);
356
387
 
357
- if (sym == id_yuyv || sym == id_yuv422) {
388
+ if (EQ_STR(fmt, "YUYV") || EQ_STR(fmt, "YUV422")) {
358
389
  ret = V4L2_PIX_FMT_YUYV;
359
390
 
360
- } else if (sym == id_nv12) {
391
+ } else if (EQ_STR(fmt, "NV12")) {
361
392
  ret = V4L2_PIX_FMT_NV12;
362
393
 
363
- } else if (sym == id_nv21) {
394
+ } else if (EQ_STR(fmt, "NV21")) {
364
395
  ret = V4L2_PIX_FMT_NV21;
365
396
 
366
- } else if (sym == id_nv16) {
397
+ } else if (EQ_STR(fmt, "NV16")) {
367
398
  ret = V4L2_PIX_FMT_NV16;
368
399
 
369
- } else if (sym == id_rgb565) {
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")) {
407
+ ret = V4L2_PIX_FMT_NV16;
408
+
409
+ } else if (EQ_STR(fmt, "RGB565") || EQ_STR(fmt, "RGBP")) {
370
410
  ret = V4L2_PIX_FMT_RGB565;
371
411
 
372
- } else if (sym == id_mjpeg) {
412
+ } else if (EQ_STR(fmt, "MJPEG") || EQ_STR(fmt, "MJPG")) {
373
413
  ret = V4L2_PIX_FMT_MJPEG;
374
414
 
375
- } else if (sym == id_h264) {
415
+ } else if (EQ_STR(fmt, "H264")) {
376
416
  ret = V4L2_PIX_FMT_H264;
377
417
 
378
418
  } else {
@@ -396,7 +436,7 @@ rb_camera_get_support_formats(VALUE self)
396
436
  VALUE fcc;
397
437
  VALUE str;
398
438
 
399
- Data_Get_Struct(self, camera_t, ptr);
439
+ TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
400
440
 
401
441
  ret = rb_ary_new();
402
442
 
@@ -501,9 +541,7 @@ rb_camera_get_frame_capabilities(VALUE self, VALUE _fmt)
501
541
  VALUE list;
502
542
  VALUE rate;
503
543
 
504
- Check_Type(_fmt, T_SYMBOL);
505
-
506
- Data_Get_Struct(self, camera_t, ptr);
544
+ TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
507
545
 
508
546
  ret = rb_ary_new();
509
547
  fmt = to_pixfmt(_fmt);
@@ -542,7 +580,7 @@ rb_camera_set_control(VALUE self, VALUE id, VALUE _val)
542
580
  int err;
543
581
  int val;
544
582
 
545
- Data_Get_Struct(self, camera_t, ptr);
583
+ TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
546
584
 
547
585
  switch (TYPE(_val)) {
548
586
  case T_TRUE:
@@ -576,7 +614,7 @@ rb_camera_get_control(VALUE self, VALUE id)
576
614
  int err;
577
615
  int32_t value;
578
616
 
579
- Data_Get_Struct( self, camera_t, ptr);
617
+ TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
580
618
 
581
619
  err = camera_get_control(ptr, FIX2INT(id), &value);
582
620
  if (err) {
@@ -592,15 +630,10 @@ rb_camera_set_format(VALUE self, VALUE fmt)
592
630
  camera_t* ptr;
593
631
  int err;
594
632
 
595
- /*
596
- * argument check
597
- */
598
- Check_Type(fmt, T_SYMBOL);
599
-
600
633
  /*
601
634
  * strip object
602
635
  */
603
- Data_Get_Struct(self, camera_t, ptr);
636
+ TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
604
637
 
605
638
  /*
606
639
  * set parameter
@@ -623,7 +656,7 @@ rb_camera_get_image_width(VALUE self)
623
656
  /*
624
657
  * strip object
625
658
  */
626
- Data_Get_Struct(self, camera_t, ptr);
659
+ TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
627
660
 
628
661
  /*
629
662
  * get parameter
@@ -642,20 +675,15 @@ rb_camera_set_image_width(VALUE self, VALUE val)
642
675
  camera_t* ptr;
643
676
  int err;
644
677
 
645
- /*
646
- * argument check
647
- */
648
- Check_Type(val, T_FIXNUM);
649
-
650
678
  /*
651
679
  * strip object
652
680
  */
653
- Data_Get_Struct(self, camera_t, ptr);
681
+ TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
654
682
 
655
683
  /*
656
684
  * set parameter
657
685
  */
658
- err = camera_set_image_width(ptr, FIX2INT(val));
686
+ err = camera_set_image_width(ptr, NUM2INT(val));
659
687
  if (err) {
660
688
  rb_raise(rb_eRuntimeError, "set image width failed.");
661
689
  }
@@ -673,7 +701,7 @@ rb_camera_get_image_height(VALUE self)
673
701
  /*
674
702
  * strip object
675
703
  */
676
- Data_Get_Struct(self, camera_t, ptr);
704
+ TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
677
705
 
678
706
  /*
679
707
  * get parameter
@@ -692,20 +720,15 @@ rb_camera_set_image_height(VALUE self, VALUE val)
692
720
  camera_t* ptr;
693
721
  int err;
694
722
 
695
- /*
696
- * argument check
697
- */
698
- Check_Type(val, T_FIXNUM);
699
-
700
723
  /*
701
724
  * strip object
702
725
  */
703
- Data_Get_Struct(self, camera_t, ptr);
726
+ TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
704
727
 
705
728
  /*
706
729
  * set parameter
707
730
  */
708
- err = camera_set_image_height(ptr, FIX2INT(val));
731
+ err = camera_set_image_height(ptr, NUM2INT(val));
709
732
  if (err) {
710
733
  rb_raise(rb_eRuntimeError, "set image height failed.");
711
734
  }
@@ -716,7 +739,21 @@ rb_camera_set_image_height(VALUE self, VALUE val)
716
739
  static VALUE
717
740
  rb_camera_get_framerate(VALUE self)
718
741
  {
719
- return Qnil;
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;
720
757
  }
721
758
 
722
759
  static VALUE
@@ -747,13 +784,13 @@ rb_camera_set_framerate(VALUE self, VALUE val)
747
784
  break;
748
785
 
749
786
  default:
750
- rb_raise(rb_eArgError, "illeagal framerate value.");
787
+ rb_raise(rb_eTypeError, "illeagal framerate value.");
751
788
  }
752
789
 
753
790
  /*
754
791
  * strip object
755
792
  */
756
- Data_Get_Struct(self, camera_t, ptr);
793
+ TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
757
794
 
758
795
  /*
759
796
  * set framerate
@@ -775,7 +812,7 @@ rb_camera_state( VALUE self)
775
812
  /*
776
813
  * strip object
777
814
  */
778
- Data_Get_Struct(self, camera_t, ptr);
815
+ TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
779
816
 
780
817
  /*
781
818
  * convert state code
@@ -818,21 +855,31 @@ rb_camera_start(VALUE self)
818
855
  {
819
856
  int err;
820
857
  camera_t* ptr;
858
+ int state;
821
859
 
822
860
  /*
823
861
  * strip object
824
862
  */
825
- Data_Get_Struct(self, camera_t, ptr);
863
+ TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
826
864
 
827
865
  /*
828
- * convert
866
+ * do start
829
867
  */
830
868
  err = camera_start(ptr);
831
869
  if (err) {
832
870
  rb_raise(rb_eRuntimeError, "start capture failed.");
833
871
  }
834
872
 
835
- return Qnil;
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;
836
883
  }
837
884
 
838
885
  static VALUE
@@ -844,7 +891,7 @@ rb_camera_stop(VALUE self)
844
891
  /*
845
892
  * strip object
846
893
  */
847
- Data_Get_Struct(self, camera_t, ptr);
894
+ TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
848
895
 
849
896
  /*
850
897
  * convert
@@ -854,7 +901,7 @@ rb_camera_stop(VALUE self)
854
901
  rb_raise(rb_eRuntimeError, "stop capture failed.");
855
902
  }
856
903
 
857
- return Qnil;
904
+ return self;
858
905
  }
859
906
 
860
907
 
@@ -869,7 +916,7 @@ rb_camera_capture(VALUE self)
869
916
  /*
870
917
  * strip object
871
918
  */
872
- Data_Get_Struct(self, camera_t, ptr);
919
+ TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
873
920
 
874
921
  /*
875
922
  * allocate return value.
@@ -902,7 +949,7 @@ rb_camera_is_busy(VALUE self)
902
949
  /*
903
950
  * strip object
904
951
  */
905
- Data_Get_Struct(self, camera_t, ptr);
952
+ TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
906
953
 
907
954
  /*
908
955
  * do check
@@ -915,6 +962,29 @@ rb_camera_is_busy(VALUE self)
915
962
  return (busy)? Qtrue: Qfalse;
916
963
  }
917
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
+
918
988
  static VALUE
919
989
  rb_camera_is_error(VALUE self)
920
990
  {
@@ -925,7 +995,7 @@ rb_camera_is_error(VALUE self)
925
995
  /*
926
996
  * strip object
927
997
  */
928
- Data_Get_Struct(self, camera_t, ptr);
998
+ TypedData_Get_Struct(self, camera_t, &camera_data_type, ptr);
929
999
 
930
1000
  /*
931
1001
  * do check
@@ -941,6 +1011,10 @@ rb_camera_is_error(VALUE self)
941
1011
  void
942
1012
  Init_v4l2()
943
1013
  {
1014
+ #ifdef HAVE_RB_EXT_RACTOR_SAFE
1015
+ rb_ext_ractor_safe(true);
1016
+ #endif /* defined(HAVE_RB_EXT_RACTOR_SAFE) */
1017
+
944
1018
  rb_require("monitor");
945
1019
 
946
1020
  module = rb_define_module("Video4Linux2");
@@ -968,6 +1042,7 @@ Init_v4l2()
968
1042
  rb_define_method(camera_klass, "stop", rb_camera_stop, 0);
969
1043
  rb_define_method(camera_klass, "capture", rb_camera_capture, 0);
970
1044
  rb_define_method(camera_klass, "busy?", rb_camera_is_busy, 0);
1045
+ rb_define_method(camera_klass, "ready?", rb_camera_is_ready, 0);
971
1046
  rb_define_method(camera_klass, "error?", rb_camera_is_error, 0);
972
1047
 
973
1048
  rb_define_attr(camera_klass, "name", !0, 0);
@@ -980,7 +1055,6 @@ Init_v4l2()
980
1055
  "Control", rb_cObject);
981
1056
  rb_define_attr(control_klass, "name", !0, 0);
982
1057
  rb_define_attr(control_klass, "id", !0, 0);
983
- rb_define_attr(control_klass, "value", !0, 0);
984
1058
 
985
1059
  integer_klass = rb_define_class_under(camera_klass,
986
1060
  "IntegerControl", control_klass);
@@ -1014,14 +1088,6 @@ Init_v4l2()
1014
1088
  rb_define_attr(fmt_desc_klass, "fcc", !0, 0);
1015
1089
  rb_define_attr(fmt_desc_klass, "description", !0, 0);
1016
1090
 
1017
- id_yuyv = rb_intern_const("YUYV");
1018
- id_yuv422 = rb_intern_const("YUV422");
1019
- id_nv12 = rb_intern_const("NV12");
1020
- id_nv21 = rb_intern_const("NV21");
1021
- id_nv16 = rb_intern_const("NV16");
1022
- id_rgb565 = rb_intern_const("RGB565");
1023
- id_mjpeg = rb_intern_const("MJPEG");
1024
- id_h264 = rb_intern_const("H264");
1025
1091
  id_iv_name = rb_intern_const("@name");
1026
1092
  id_iv_driver = rb_intern_const("@driver");
1027
1093
  id_iv_bus = rb_intern_const("@bus");
data/lib/v4l2/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Video4Linux2
2
- VERSION = "0.10.0"
2
+ VERSION = "0.11.0"
3
3
  end
data/pkg/.gitkeep ADDED
File without changes