wiretap 0.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. data/README +2 -1
  2. data/ext/Makefile +27 -24
  3. data/ext/audio_format.cpp +10 -8
  4. data/ext/charstream.h +41 -0
  5. data/ext/extconf.rb +8 -10
  6. data/ext/frame_io.cpp +120 -0
  7. data/ext/frame_io.h +45 -0
  8. data/ext/image_format.cpp +49 -169
  9. data/ext/image_io.cpp +466 -0
  10. data/ext/image_io.h +73 -0
  11. data/ext/node.cpp +71 -48
  12. data/ext/nodeframes.cpp +36 -34
  13. data/ext/nodemetadata.cpp +21 -3
  14. data/ext/server.cpp +2 -2
  15. data/ext/serverlist.cpp +20 -8
  16. data/ext/wiretap.cpp +11 -8
  17. data/ext/wiretap.h +17 -13
  18. data/lib/wiretap.rb +65 -5
  19. data/test_new/common.rb +8 -0
  20. data/{test/wiretap-images → test_new/fixtures/img/ppm-8bit}/01.ppm +0 -0
  21. data/test_new/fixtures/raw/cube_2k_12bitP_1f/0.stoneimage +0 -0
  22. data/test_new/fixtures/raw/cube_2k_8bit_1f/0.stoneimage +0 -0
  23. data/test_new/fixtures/raw/cube_SD_10bit_5f/0.stoneimage +0 -0
  24. data/test_new/fixtures/raw/cube_SD_10bit_5f/1.stoneimage +0 -0
  25. data/test_new/fixtures/raw/cube_SD_10bit_5f/2.stoneimage +0 -0
  26. data/test_new/fixtures/raw/cube_SD_10bit_5f/3.stoneimage +0 -0
  27. data/test_new/fixtures/raw/cube_SD_10bit_5f/4.stoneimage +0 -0
  28. data/test_new/fixtures/raw/cube_SD_12bitP_5f/0.stoneimage +0 -0
  29. data/test_new/fixtures/raw/cube_SD_12bitP_5f/1.stoneimage +0 -0
  30. data/test_new/fixtures/raw/cube_SD_12bitP_5f/2.stoneimage +0 -0
  31. data/test_new/fixtures/raw/cube_SD_12bitP_5f/3.stoneimage +0 -0
  32. data/test_new/fixtures/raw/cube_SD_12bitP_5f/4.stoneimage +0 -0
  33. data/test_new/fixtures/raw/cube_SD_12bitU_5f/0.stoneimage +0 -0
  34. data/test_new/fixtures/raw/cube_SD_12bitU_5f/1.stoneimage +0 -0
  35. data/test_new/fixtures/raw/cube_SD_12bitU_5f/2.stoneimage +0 -0
  36. data/test_new/fixtures/raw/cube_SD_12bitU_5f/3.stoneimage +0 -0
  37. data/test_new/fixtures/raw/cube_SD_12bitU_5f/4.stoneimage +0 -0
  38. data/test_new/fixtures/raw/cube_SD_8bit_8f/0.stoneimage +0 -0
  39. data/test_new/fixtures/raw/cube_SD_8bit_8f/1.stoneimage +0 -0
  40. data/test_new/fixtures/raw/cube_SD_8bit_8f/2.stoneimage +0 -0
  41. data/test_new/fixtures/raw/cube_SD_8bit_8f/3.stoneimage +0 -0
  42. data/test_new/fixtures/raw/cube_SD_8bit_8f/4.stoneimage +0 -0
  43. data/test_new/fixtures/raw/cube_SD_8bit_8f/5.stoneimage +0 -0
  44. data/test_new/fixtures/raw/cube_SD_8bit_8f/6.stoneimage +0 -0
  45. data/test_new/fixtures/raw/cube_SD_8bit_8f/7.stoneimage +0 -0
  46. data/{test/wiretap-images/b1.stonesound → test_new/fixtures/raw-snd/simple.stonesound} +0 -0
  47. data/{test/wiretap-images/output.wav → test_new/fixtures/snd/simple-wave.wav} +0 -0
  48. data/test_new/test_audio_conversions.rb +28 -0
  49. data/test_new/test_image_conversions.rb +132 -0
  50. data/test_new/test_parts/connect_to_test_host.rb +27 -0
  51. data/test_new/test_parts/constants.rb +7 -0
  52. data/test_new/test_parts/create_test_project.rb +37 -0
  53. data/test_new/test_parts/raw_formats_and_uploads.rb +170 -0
  54. data/test_new/test_parts/server_list.rb +20 -0
  55. data/test_new/test_parts/simple_node_lookup_and_browsing.rb +76 -0
  56. data/test_new/test_suite.rb +70 -0
  57. data/{test/convert.rb → test_new/test_thread_worker.rb} +2 -3
  58. metadata +71 -61
  59. data/ext/bmp.cpp +0 -65
  60. data/ext/image.h +0 -27
  61. data/ext/ppm.cpp +0 -132
  62. data/ext/sgi.cpp +0 -69
  63. data/test/audio.rb +0 -27
  64. data/test/image.rb +0 -101
  65. data/test/read_frames.rb +0 -142
  66. data/test/wiretap-images/32bit.stoneimage +0 -621
  67. data/test/wiretap-images/36bit.stoneimage +0 -1036
  68. data/test/wiretap-images/48bit.stoneimage +1 -800
  69. data/test/wiretap-images/a.stoneimage +0 -0
  70. data/test/wiretap-images/a0.stoneimage +0 -0
  71. data/test/wiretap-images/a1.stoneimage +0 -0
  72. data/test/wiretap-images/a2.stoneimage +0 -0
  73. data/test/wiretap-images/a3.stoneimage +0 -0
  74. data/test/wiretap-images/a4.stoneimage +0 -0
  75. data/test/wiretap-images/importable-seq/00000001.ppm +0 -0
  76. data/test/wiretap-images/importable-seq/00000002.ppm +0 -0
  77. data/test/wiretap-images/importable-seq/00000003.ppm +0 -0
  78. data/test/wiretap-images/importable-seq/00000004.ppm +0 -0
  79. data/test/wiretap-images/importable-seq/00000005.ppm +0 -0
  80. data/test/wiretap-images/importable-seq/00000006.ppm +0 -0
  81. data/test/wiretap-images/importable-seq/00000007.ppm +0 -0
  82. data/test/wiretap-images/importable-seq/00000008.ppm +0 -0
  83. data/test/wiretap-images/importable-seq/00000009.ppm +0 -0
  84. data/test/wiretap-images/importable-seq/00000010.ppm +0 -0
  85. data/test/wiretap-images/importable-seq/00000011.ppm +0 -0
  86. data/test/wiretap-images/importable-seq/00000012.ppm +0 -0
  87. data/test/wiretap-images/monsters_001.tif +0 -0
  88. data/test/wiretap-images/monsters_002.tif +0 -0
  89. data/test/wiretap-images/monsters_003.tif +0 -0
  90. data/test/wiretap-images/output.mov +0 -0
  91. data/test/write_frames.rb +0 -82
data/ext/node.cpp CHANGED
@@ -30,12 +30,18 @@ static VALUE node_detect_klass(WireTapNodeHandle* node) {
30
30
  case IFFFS_WT_TYPE_REEL: {
31
31
  return cReel;
32
32
  }
33
- case IFFFS_WT_TYPE_CLIP:
34
- case IFFFS_WT_TYPE_CLIP_HIRES:
35
- case IFFFS_WT_TYPE_CLIP_LOWRES:
36
- case IFFFS_WT_TYPE_CLIP_SLATE: {
37
- return cClip;
38
- }
33
+ case IFFFS_WT_TYPE_CLIP: {
34
+ return cClip;
35
+ }
36
+ case IFFFS_WT_TYPE_CLIP_HIRES: {
37
+ return cHiresClip;
38
+ }
39
+ case IFFFS_WT_TYPE_CLIP_LOWRES: {
40
+ return cLowresClip;
41
+ }
42
+ case IFFFS_WT_TYPE_CLIP_SLATE: {
43
+ return cSlateClip;
44
+ }
39
45
  case IFFFS_WT_TYPE_CLIP_AUDIO:
40
46
  case IFFFS_WT_TYPE_CLIP_AUDIO_STREAM: {
41
47
  return cAudio;
@@ -63,6 +69,7 @@ static VALUE wiretap_node_allocate(VALUE klass) {
63
69
  return Data_Wrap_Struct(klass, 0, node_free, new_node);
64
70
  }
65
71
 
72
+ /* Returns the node ID of the given node - a unique path to the node on the particular Wiretap host */
66
73
  static VALUE wiretap_node_get_id(VALUE self) {
67
74
  Check_Node_Alive(self);
68
75
 
@@ -71,16 +78,18 @@ static VALUE wiretap_node_get_id(VALUE self) {
71
78
  return rb_str_new2(node->getNodeId().id());
72
79
  }
73
80
 
81
+ /* Sets the node ID, use with caution */
74
82
  static VALUE wiretap_node_set_id(VALUE self, VALUE id) {
75
83
  Check_Node_Alive(self);
76
84
 
77
85
  WireTapNodeHandle* node;
78
86
  Check_Type(id, T_STRING);
79
87
  Data_Get_Struct(self, WireTapNodeHandle, node);
80
- // node->setNodeId(WireTapNodeId(STR(id)));
88
+ node->setNodeId(WireTapNodeId(STR(id)));
81
89
  return self;
82
90
  }
83
91
 
92
+ /* Reload the node information from the server */
84
93
  static VALUE wiretap_node_reload(VALUE self) {
85
94
  Check_Node_Alive(self);
86
95
 
@@ -93,6 +102,7 @@ static VALUE wiretap_node_reload(VALUE self) {
93
102
  return self;
94
103
  }
95
104
 
105
+ /* Find a Wiretap node in the children of the current node */
96
106
  static VALUE wiretap_node_find(VALUE self, VALUE path) {
97
107
  Check_Node_Alive(self);
98
108
 
@@ -114,7 +124,7 @@ static VALUE wiretap_node_find(VALUE self, VALUE path) {
114
124
  return wiretap_node_create_with(child, rb_iv_get(self, "@server"), self);
115
125
  }
116
126
 
117
-
127
+ /* Import a directory of PPM files into the clip */
118
128
  static VALUE wiretap_clip_import_directory(VALUE self, VALUE dir_name) {
119
129
  Check_Node_Alive(self);
120
130
 
@@ -142,41 +152,30 @@ static VALUE wiretap_clip_import_directory(VALUE self, VALUE dir_name) {
142
152
  }
143
153
 
144
154
 
145
- NODERUN_E(node, node->setNumFrames(count));
155
+ NODERUN_EX_E(node, node->setNumFrames(count));
146
156
  WireTapClipFormat format;
147
157
  NODERUN_E(node, node->getClipFormat(format));
148
- unsigned char frame[format.frameBufferSize()];
149
-
150
- /** TODO - refactor to use write_frame **/
151
158
 
152
159
  for(int i = 0; i < count; i++) {
153
160
  char filename[PATH_MAX];
154
161
  snprintf(filename, sizeof(filename), "%s/%08d.ppm", STR(dir_name), i+1);
155
162
  //rb_warn("Opening file %s", filename);
156
163
 
157
-
158
- FILE* infile = fopen(filename, "r");
159
- if(!infile) {
160
- THROW("Couldn't open file %s for read", filename);
161
- }
162
-
163
- if(!ppm_read_format(infile, NULL)) {
164
- fclose(infile);
165
- THROW("Couldn't read PPM format from file %s", filename);
164
+ std::auto_ptr<ImageIO> image(ImageIO::open(filename, format));
165
+ if(!image.get()) {
166
+ image.release();
167
+ THROW("Couldn't open file %s for reading", filename);
166
168
  }
167
-
168
- if(!ppm_read_image(infile, frame, format.width(), format.height(), format.bitsPerPixel())) {
169
- fclose(infile);
170
- rb_warn("Couldn't read PPM image data from file %s", filename);
171
- return Qnil;
172
- }
173
- fclose(infile);
174
-
175
- NODERUN_E(node, node->writeFrame(i, frame, sizeof(frame)));
169
+ image->read_format();
170
+ std::auto_ptr<unsigned char> frame(image->read_data());
171
+ NODERUN_EX_E(node, node->writeFrame(i, frame.get(), format.frameBufferSize()));
176
172
  }
177
173
  return self;
178
174
  }
179
175
 
176
+ /*
177
+ * Get extended type of the particular node as string
178
+ */
180
179
  static VALUE wiretap_node_get_type(VALUE self) {
181
180
  Check_Node_Alive(self);
182
181
 
@@ -187,6 +186,9 @@ static VALUE wiretap_node_get_type(VALUE self) {
187
186
  return wiretap_to_str(type);
188
187
  }
189
188
 
189
+ /*
190
+ * Get name of the particular node
191
+ */
190
192
  static VALUE wiretap_node_get_name(VALUE self) {
191
193
  Check_Node_Alive(self);
192
194
 
@@ -198,6 +200,7 @@ static VALUE wiretap_node_get_name(VALUE self) {
198
200
  }
199
201
 
200
202
 
203
+ /* Provided a name and a type creates a child node */
201
204
  static VALUE wiretap_node_create_node(int argc, VALUE* argv, VALUE self) {
202
205
  Check_Node_Alive(self);
203
206
 
@@ -214,10 +217,10 @@ static VALUE wiretap_node_create_node(int argc, VALUE* argv, VALUE self) {
214
217
  }
215
218
  switch(TYPE(extended_type)) {
216
219
  case T_FIXNUM:
217
- NODERUN_E(node, node->createNode(CSTR(display_name), NUM2INT(extended_type), node_return));
220
+ NODERUN_EX_E(node, node->createNode(CSTR(display_name), NUM2INT(extended_type), node_return));
218
221
  break;
219
222
  case T_STRING:
220
- NODERUN_E(node, node->createNode(CSTR(display_name), CSTR(extended_type), node_return));
223
+ NODERUN_EX_E(node, node->createNode(CSTR(display_name), CSTR(extended_type), node_return));
221
224
  break;
222
225
  default:
223
226
  rb_raise(rb_eArgError, "extended type must be integer or string");
@@ -239,7 +242,7 @@ static VALUE wiretap_node_create_clip(int argc, VALUE* argv, VALUE self) {
239
242
  WireTapNodeHandle node_return;
240
243
 
241
244
  if(extended_type == Qnil) {
242
- extended_type = INT2FIX(0);
245
+ extended_type = INT2FIX(IFFFS_WT_TYPE_CLIP);
243
246
  }
244
247
  if(format == Qnil) {
245
248
  format = rb_funcall(self, rb_intern("format"), 0);
@@ -250,23 +253,28 @@ static VALUE wiretap_node_create_clip(int argc, VALUE* argv, VALUE self) {
250
253
 
251
254
  switch(TYPE(extended_type)) {
252
255
  case T_FIXNUM:
253
- NODERUN_E(node, node->createClipNode(CSTR(display_name), *f, NUM2INT(extended_type), node_return));
256
+ NODERUN_EX_E(node, node->createClipNode(CSTR(display_name), *f, NUM2INT(extended_type), node_return));
254
257
  break;
255
258
  case T_STRING:
256
- NODERUN_E(node, node->createClipNode(CSTR(display_name), *f, CSTR(extended_type), node_return));
259
+ NODERUN_EX_E(node, node->createClipNode(CSTR(display_name), *f, CSTR(extended_type), node_return));
257
260
  break;
258
261
  default:
259
- rb_raise(rb_eArgError, "extended type must be integer or string");
262
+ rb_raise(rb_eArgError, "extended type must be integer or string (for instance CLIP, CLIP_SLATE, PROJECT etc.)");
260
263
  }
261
264
 
262
265
  return wiretap_node_create_with(node_return, rb_iv_get(self, "@server"), self);
263
266
  }
264
267
 
265
-
266
- static VALUE wiretap_node_destroy(VALUE self) {
268
+ /* Deletes the node from the server */
269
+ static VALUE wiretap_node_destroy_self(VALUE self) {
267
270
  WireTapNodeHandle* node;
271
+ VALUE is_destroyed = rb_iv_get(self, "@destroyed");
272
+ if(is_destroyed == Qtrue) {
273
+ return Qtrue;
274
+ }
275
+
268
276
  Data_Get_Struct(self, WireTapNodeHandle, node);
269
- NODERUN_E(node, node->destroyNode());
277
+ NODERUN_EX_E(node, node->destroyNode());
270
278
  rb_iv_set(self, "@destroyed", Qtrue);
271
279
  return Qtrue;
272
280
  }
@@ -274,7 +282,7 @@ static VALUE wiretap_node_destroy(VALUE self) {
274
282
 
275
283
 
276
284
  /*
277
- * Extract metadata from node
285
+ * Extract the node metadata object
278
286
  * @node.metadata
279
287
  */
280
288
  static VALUE wiretap_node_metadata(VALUE self) {
@@ -295,7 +303,7 @@ static VALUE wiretap_node_metadata(VALUE self) {
295
303
  }
296
304
 
297
305
 
298
-
306
+ /* Returns the format of the clip */
299
307
  static VALUE wiretap_clip_format(VALUE self) {
300
308
  Check_Node_Alive(self);
301
309
 
@@ -308,7 +316,7 @@ static VALUE wiretap_clip_format(VALUE self) {
308
316
  return clipformat;
309
317
  }
310
318
 
311
-
319
+ /* Returns the format of the audio node */
312
320
  static VALUE wiretap_audio_format(VALUE self) {
313
321
  Check_Node_Alive(self);
314
322
 
@@ -321,7 +329,7 @@ static VALUE wiretap_audio_format(VALUE self) {
321
329
  return audioformat;
322
330
  }
323
331
 
324
-
332
+ /* Returns a Wiretap::NodeFrames object that gives access to the frames of the clip */
325
333
  static VALUE wiretap_clip_frames(VALUE self) {
326
334
  Check_Node_Alive(self);
327
335
 
@@ -355,22 +363,37 @@ void Init_node() {
355
363
  cLibrary = rb_define_class_under(mWiretap, "Library", cNode);
356
364
  cProject = rb_define_class_under(mWiretap, "Project", cNode);
357
365
  cVolume = rb_define_class_under(mWiretap, "Volume", cNode);
358
- cHost = rb_define_class_under(mWiretap, "Host", cNode);
359
366
 
367
+ cSlateClip = rb_define_class_under(mWiretap, "SlateClip", cClip);
368
+ cHiresClip = rb_define_class_under(mWiretap, "HiresClip", cClip);
369
+ cLowresClip = rb_define_class_under(mWiretap, "LowresClip", cClip);
370
+ cSlateClip = rb_define_class_under(mWiretap, "SlateClip", cClip);
371
+
372
+ cHost = rb_define_class_under(mWiretap, "Host", cNode);
373
+
360
374
  rb_define_alloc_func(cNode, wiretap_node_allocate);
361
375
  rb_define_method(cNode, "id", VALUEFUNC(wiretap_node_get_id), 0);
362
376
  rb_define_method(cNode, "id=", VALUEFUNC(wiretap_node_set_id), 1);
363
377
  rb_define_method(cNode, "reload", VALUEFUNC(wiretap_node_reload), 0);
364
378
 
365
379
  rb_define_method(cNode, "metadata", VALUEFUNC(wiretap_node_metadata), 0);
380
+ rb_define_method(cNode, "meta", VALUEFUNC(wiretap_node_metadata), 0);
381
+
366
382
 
367
383
  rb_define_method(cClip, "format", VALUEFUNC(wiretap_clip_format), 0);
368
384
  rb_define_method(cAudio, "format", VALUEFUNC(wiretap_audio_format), 0);
369
385
  rb_define_method(cClip, "frames", VALUEFUNC(wiretap_clip_frames), 0);
370
386
  rb_define_method(cAudio, "frames", VALUEFUNC(wiretap_audio_frames), 0);
371
-
372
387
 
388
+ rb_define_method(cNode, "slate?", VALUEFUNC(wiretap_false), -1);
389
+ rb_define_method(cNode, "lowres?", VALUEFUNC(wiretap_false), -1);
390
+ rb_define_method(cNode, "hires?", VALUEFUNC(wiretap_false), -1);
391
+
392
+ rb_define_method(cSlateClip, "slate?", VALUEFUNC(wiretap_true), -1);
393
+ rb_define_method(cLowresClip, "lowres?", VALUEFUNC(wiretap_true), -1);
394
+ rb_define_method(cHiresClip, "hires?", VALUEFUNC(wiretap_true), -1);
373
395
 
396
+ rb_define_method(cNode, "node?", VALUEFUNC(wiretap_true), -1);
374
397
  rb_define_method(cNode, "host?", VALUEFUNC(wiretap_false), -1);
375
398
  rb_define_method(cNode, "volume?", VALUEFUNC(wiretap_false), -1);
376
399
  rb_define_method(cNode, "project?", VALUEFUNC(wiretap_false), -1);
@@ -394,8 +417,8 @@ void Init_node() {
394
417
  rb_define_method(cNode, "name", VALUEFUNC(wiretap_node_get_name), 0);
395
418
 
396
419
  rb_define_method(cClip, "import_directory", VALUEFUNC(wiretap_clip_import_directory), 1);
397
- rb_define_protected_method(cNode, "create_node", VALUEFUNC(wiretap_node_create_node), -1);
398
- rb_define_protected_method(cNode, "create_clip", VALUEFUNC(wiretap_node_create_clip), -1);
420
+ rb_define_method(cNode, "create_node", VALUEFUNC(wiretap_node_create_node), -1);
421
+ rb_define_method(cNode, "create_clip", VALUEFUNC(wiretap_node_create_clip), -1);
399
422
 
400
- rb_define_method(cNode, "destroy!", VALUEFUNC(wiretap_node_destroy), 0);
423
+ rb_define_private_method(cNode, "destroy_self", VALUEFUNC(wiretap_node_destroy_self), 0);
401
424
  }
data/ext/nodeframes.cpp CHANGED
@@ -6,7 +6,7 @@
6
6
  }}
7
7
 
8
8
  /*
9
- * Get frames count of clip
9
+ * Get frame count of clip. Also available as Wiretap::Clip#length
10
10
  */
11
11
  static VALUE wiretap_node_frames_count(VALUE self) {
12
12
  WireTapNodeHandle* node;
@@ -23,13 +23,20 @@ static VALUE wiretap_node_frames_set_count(VALUE self, VALUE value) {
23
23
  VALUE count = rb_funcall(value, rb_intern("to_i"), 0);
24
24
 
25
25
  WireTapNodeHandle* node;
26
+
26
27
  Data_Get_Struct(self, WireTapNodeHandle, node);
28
+ int prev_count;
29
+ NODERUN_E(node, node->getNumFrames(prev_count));
30
+ if((prev_count != 0) && (prev_count != NUM2INT(count))) {
31
+ rb_raise(eError, "Cannot reallocate the frames after the frame length has been set", __FILE__, __LINE__);
32
+ }
33
+
27
34
  NODERUN_E(node, node->setNumFrames(NUM2INT(count)));
28
35
  return count;
29
36
  }
30
37
 
31
38
  /*
32
- * Get frame by index.
39
+ * Get frame by index. Returns a formatted Stone image buffer as value (a Ruby string).
33
40
  */
34
41
  static VALUE wiretap_node_frames_get_at(VALUE self, VALUE index) {
35
42
  WireTapNodeHandle* node;
@@ -48,14 +55,13 @@ static VALUE wiretap_node_frames_get_at(VALUE self, VALUE index) {
48
55
  }
49
56
 
50
57
  /*
51
- * Set frame at index. Accepts the formatted Stone image buffer as value.
58
+ * Set frame at index. Accepts a formatted Stone image buffer as value (a Ruby string).
52
59
  */
53
60
  static VALUE wiretap_node_frames_set_at(VALUE self, VALUE index, VALUE value) {
54
61
  WireTapNodeHandle* node;
55
62
  Data_Get_Struct(self, WireTapNodeHandle, node);
56
- Check_Type(index, T_STRING);
63
+ Check_Type(index, T_FIXNUM);
57
64
  Check_Type(value, T_STRING);
58
-
59
65
  NODERUN_E(node, node->writeFrame(FIX2INT(index), CSTR(value), LEN(value)));
60
66
  return self;
61
67
  }
@@ -84,7 +90,7 @@ static VALUE wiretap_node_frames_each(VALUE self) {
84
90
  }
85
91
 
86
92
  /*
87
- * Get path of frame at index
93
+ * Get path of frame at index (will include the internal StoneFS frame counter identifier)
88
94
  */
89
95
  static VALUE wiretap_node_frames_get_path_at(VALUE self, VALUE index) {
90
96
  WireTapNodeHandle* node;
@@ -140,7 +146,7 @@ static VALUE wiretap_node_frame_dump_all(VALUE self, VALUE file_pattern) {
140
146
  }
141
147
 
142
148
  /*
143
- * Dump one frame to file
149
+ * Dump the frame at index to an SGI file
144
150
  */
145
151
  static VALUE wiretap_node_frame_dump(VALUE self, VALUE index, VALUE file) {
146
152
  WireTapNodeHandle* node;
@@ -156,9 +162,8 @@ static VALUE wiretap_node_frame_dump(VALUE self, VALUE index, VALUE file) {
156
162
  }
157
163
 
158
164
  /*
159
- * Read one frame from a PPM file. If this is the first frame (index 0) and the clip has no frames yet one frame will be allocated.
165
+ * Read one frame from an SGI, PPM or BMP file. If this is the first frame (index 0) and the clip has no frames yet one frame will be allocated.
160
166
  * You cannot change the number of frames afterwards.
161
- * THIS METHOD SHOULD BE PRIVATE DAMN!
162
167
  */
163
168
  static VALUE wiretap_node_frame_write_from_file(VALUE self, VALUE index, VALUE filename) {
164
169
  WireTapNodeHandle* node;
@@ -166,32 +171,19 @@ static VALUE wiretap_node_frame_write_from_file(VALUE self, VALUE index, VALUE f
166
171
 
167
172
  Data_Get_Struct(self, WireTapNodeHandle, node);
168
173
  NODERUN_E(node, node->getClipFormat(format));
169
-
170
- unsigned int bufSize = format.frameBufferSize();
171
- std::auto_ptr<unsigned char> frame(new unsigned char[bufSize]);
172
-
173
174
  int i = NUM2INT(index);
174
-
175
- FILE* infile = fopen(CSTR(filename), "r");
176
- if(!infile) {
177
- frame.release();
178
- THROW("Couldn't open file %s for reading", filename);
179
- }
180
-
181
- if(!ppm_read_format(infile, &format)) {
182
- frame.release();
183
- fclose(infile);
184
- THROW("Couldn't read PPM format from file %s", filename);
175
+
176
+ std::auto_ptr<ImageIO> image(ImageIO::open(CSTR(filename), format));
177
+ if(!image.get()) {
178
+ THROW("Couldn't open file %s for reading", CSTR(filename));
185
179
  }
186
-
187
- if(!ppm_read_image(infile, frame.get(), format.width(), format.height(), format.bitsPerPixel())) {
180
+ image->read_format();
181
+ std::auto_ptr<unsigned char> frame(image->read_data());
182
+ if(!frame.get()) {
188
183
  frame.release();
189
- fclose(infile);
190
- THROW("Couldn't read PPM image data from file %s", filename);
184
+ image.release();
185
+ THROW("Couldn't read PPM image data from file %s", CSTR(filename));
191
186
  }
192
-
193
- fclose(infile);
194
-
195
187
  int totalFrms;
196
188
  NODERUN_E_FRAME(node, node->getNumFrames(totalFrms));
197
189
 
@@ -204,17 +196,27 @@ static VALUE wiretap_node_frame_write_from_file(VALUE self, VALUE index, VALUE f
204
196
  THROW("You cannot add frames to an existing clip");
205
197
  }
206
198
 
207
- NODERUN_E_FRAME(node, node->writeFrame(i, frame.get(), bufSize));
199
+ NODERUN_E_FRAME(node, node->writeFrame(i, frame.get(), format.frameBufferSize()));
208
200
  return self;
209
201
  }
210
202
 
211
203
 
212
204
  void Init_nodeframes() {
213
-
214
- cNodeFrames = rb_define_class_under(mWiretap, "NodeFrames", rb_cObject);
205
+
206
+
207
+ /*
208
+ * Document-class: Wiretap::NodeFrames
209
+ *
210
+ * Access the frames of a clip. The object can be retrieved via Wiretap::Clip#frames
211
+ */
212
+ cNodeFrames = rb_define_class_under(mWiretap, "NodeFrames", rb_cObject);
215
213
 
216
214
  rb_define_method(cNodeFrames, "count", VALUEFUNC(wiretap_node_frames_count), 0);
215
+ rb_define_method(cNodeFrames, "length", VALUEFUNC(wiretap_node_frames_count), 0);
216
+
217
217
  rb_define_method(cNodeFrames, "count=", VALUEFUNC(wiretap_node_frames_set_count), 1);
218
+ rb_define_method(cNodeFrames, "length=", VALUEFUNC(wiretap_node_frames_set_count), 1);
219
+
218
220
  rb_define_method(cNodeFrames, "[]", VALUEFUNC(wiretap_node_frames_get_at), 1);
219
221
  rb_define_method(cNodeFrames, "[]=", VALUEFUNC(wiretap_node_frames_set_at), 2);
220
222
  rb_define_method(cNodeFrames, "path_at", VALUEFUNC(wiretap_node_frames_get_path_at), 1);
data/ext/nodemetadata.cpp CHANGED
@@ -1,7 +1,6 @@
1
1
  #include "wiretap.h"
2
2
 
3
3
 
4
-
5
4
  /*
6
5
  * Get count of node metadata entries
7
6
  */
@@ -51,7 +50,7 @@ static VALUE wiretap_node_metadata_set_at(VALUE self, VALUE index, VALUE value)
51
50
  }
52
51
 
53
52
  /*
54
- * eval block on each metadata entry
53
+ * Run a block on each metadata entry - the metadata stream name and the content of the stream will be passed to the block
55
54
  */
56
55
  static VALUE wiretap_node_metadata_each(VALUE self) {
57
56
  WireTapNodeHandle* node;
@@ -70,8 +69,25 @@ static VALUE wiretap_node_metadata_each(VALUE self) {
70
69
  return self;
71
70
  }
72
71
 
72
+ static VALUE wiretap_node_metadata_stream_names(VALUE self) {
73
+ VALUE stream_names = rb_ary_new();
74
+
75
+ int i, num;
76
+
77
+ WireTapNodeHandle* node;
78
+ Data_Get_Struct(self, WireTapNodeHandle, node);
79
+ NODERUN_E(node, node->getNumAvailableMetaDataStreams(num));
80
+
81
+ for(i = 0; i < num; i++) {
82
+ WireTapStr stream;
83
+ NODERUN_E(node, node->getAvailableMetaDataStream(i, stream));
84
+ rb_ary_push(stream_names, wiretap_to_str(stream));
85
+ }
86
+ return stream_names;
87
+ }
88
+
73
89
  /*
74
- * Access to metadata directly.
90
+ * Access metadata body directly.
75
91
  */
76
92
  static VALUE wiretap_node_metadata_body(VALUE self) {
77
93
  WireTapNodeHandle* node;
@@ -83,6 +99,8 @@ void Init_metadata() {
83
99
 
84
100
  cNodeMetaData = rb_define_class_under(mWiretap, "NodeMetaData", rb_cObject);
85
101
  rb_define_method(cNodeMetaData, "count", VALUEFUNC(wiretap_node_metadata_count), 0);
102
+ rb_define_method(cNodeMetaData, "length", VALUEFUNC(wiretap_node_metadata_count), 0);
103
+ rb_define_method(cNodeMetaData, "streams", VALUEFUNC(wiretap_node_metadata_stream_names), 0);
86
104
  rb_define_method(cNodeMetaData, "[]", VALUEFUNC(wiretap_node_metadata_get_at), -1);
87
105
  rb_define_method(cNodeMetaData, "[]=", VALUEFUNC(wiretap_node_metadata_set_at), 2);
88
106
  rb_define_method(cNodeMetaData, "each", VALUEFUNC(wiretap_node_metadata_each), 0);
data/ext/server.cpp CHANGED
@@ -3,7 +3,7 @@
3
3
  #define Safe_Get_Server(obj, server) do { \
4
4
  Data_Get_Struct(obj, WireTapServerHandle, server); \
5
5
  if(!server) { \
6
- rb_warn("Connection to server is already closed on %s: %d", __FILE__, __LINE__); \
6
+ rb_raise(eError, "Connection to server already closed on %s: %d", __FILE__, __LINE__); \
7
7
  return Qnil; \
8
8
  } \
9
9
  } while(0)
@@ -97,7 +97,7 @@ static VALUE wiretap_server_vendor(VALUE self) {
97
97
  }
98
98
 
99
99
  /*
100
- * Get product name, installed on server
100
+ * Get product name of the server
101
101
  */
102
102
  static VALUE wiretap_server_product(VALUE self) {
103
103
  WireTapStr str;
data/ext/serverlist.cpp CHANGED
@@ -95,14 +95,14 @@ static VALUE wiretap_server_list_s_allocate(VALUE klass) {
95
95
  }
96
96
 
97
97
  /*
98
- * Server list doesn't require any params for initialization
98
+ * ServerList doesn't require any params for initialization
99
99
  */
100
100
  static VALUE wiretap_server_list_initialize(VALUE self) {
101
101
  return self;
102
102
  }
103
103
 
104
104
  /*
105
- * resolve server by it's storage ID
105
+ * Resolve server by it's storage ID
106
106
  */
107
107
  static VALUE wiretap_server_list_resolve(VALUE self, VALUE storage) {
108
108
  WireTapServerList* server_list;
@@ -122,10 +122,7 @@ static VALUE wiretap_server_list_count(VALUE self) {
122
122
  Data_Get_Struct(self, WireTapServerList, server_list);
123
123
 
124
124
  int num = 0;
125
- //RUN_E(server_list->getNumNodes(num), server_list);
126
- if(!server_list->getNumNodes(num)) {
127
- rb_warn("Problem in wiretap: %s. File: %s: %d", server_list->lastError(), __FILE__, __LINE__);
128
- }
125
+ RUN_E(server_list->getNumNodes(num), server_list);
129
126
  return INT2FIX(num);
130
127
  }
131
128
 
@@ -161,16 +158,31 @@ static VALUE wiretap_server_list_each(VALUE self) {
161
158
  }
162
159
 
163
160
 
161
+
164
162
  void Init_serverlist() {
165
- cServerList = rb_define_class_under(mWiretap, "ServerList", rb_cObject);
163
+ /*
164
+ * Document-class: ServerList
165
+ *
166
+ * Use ServerList to autodiscover hosts on the Wiretap network
167
+ *
168
+ * Wiretap::ServerList.new.each do | server_info |
169
+ * puts "Product is #{server_info.product}"
170
+ * puts "Server is #{server_info.server}"
171
+ * end
172
+ */
173
+ cServerList = rb_define_class_under(mWiretap, "ServerList", rb_cObject);
166
174
  rb_define_alloc_func(cServerList, wiretap_server_list_s_allocate);
167
175
  rb_define_method(cServerList, "initialize", VALUEFUNC(wiretap_server_list_initialize), 0);
168
176
  rb_define_method(cServerList, "resolve", VALUEFUNC(wiretap_server_list_resolve), 1);
169
- rb_define_method(cServerList, "length", VALUEFUNC(wiretap_server_list_count), 0);
170
177
  rb_define_method(cServerList, "count", VALUEFUNC(wiretap_server_list_count), 0);
171
178
  rb_define_method(cServerList, "[]", VALUEFUNC(wiretap_server_list_get_at), 1);
172
179
  rb_define_method(cServerList, "each", VALUEFUNC(wiretap_server_list_each), 0);
173
180
 
181
+ /*
182
+ * Document-class: ServerInfo
183
+ *
184
+ * Gets returned from ServerList to describe a Wiretap host that you can connect to
185
+ */
174
186
  cServerInfo = rb_define_class_under(mWiretap, "ServerInfo", rb_cObject);
175
187
  rb_define_method(cServerInfo, "hostname", VALUEFUNC(wiretap_server_info_hostname), 0);
176
188
  rb_define_method(cServerInfo, "version", VALUEFUNC(wiretap_server_info_version), 0);
data/ext/wiretap.cpp CHANGED
@@ -3,18 +3,20 @@
3
3
 
4
4
  VALUE mWiretap, mPPM, cServer, cNodeChildren, cServerList, cServerInfo;
5
5
  VALUE cClipFormat, cAudioFormat, cNodeMetaData, cNodeFrames, cAudioFrames;
6
- VALUE cNode, cHost, cVolume, cClip, cAudio, cReel, cLibrary, cProject;
7
- VALUE eError;
6
+ VALUE cNode, cHost, cVolume, cClip, cHiresClip, cLowresClip, cSlateClip, cAudio, cReel, cLibrary, cProject;
7
+ VALUE eError, eConcurrentLockError;
8
8
  ID to_i;
9
9
 
10
10
  VALUE wiretap_to_str(WireTapStr& str) {
11
11
  return rb_str_new(str.c_str(), str.length());
12
12
  }
13
13
 
14
-
14
+ /* Always returns false for this object */
15
15
  VALUE wiretap_false(int argc, VALUE* argv, VALUE self) {
16
16
  return Qfalse;
17
17
  }
18
+
19
+ /* Always returns true for this object */
18
20
  VALUE wiretap_true(int argc, VALUE* argv, VALUE self) {
19
21
  return Qtrue;
20
22
  }
@@ -43,16 +45,17 @@ void Init_wiretap_bin() {
43
45
  to_i = rb_intern("to_i");
44
46
 
45
47
  mWiretap = rb_define_module("Wiretap");
48
+ rb_define_const(mWiretap, "CLIENT_VERSION", rb_str_new2(VERSION));
46
49
  eError = rb_define_class_under(mWiretap, "Error", rb_eStandardError);
47
-
50
+ eConcurrentLockError = rb_define_class_under(mWiretap, "LibraryLocked", eError);
51
+
48
52
  #ifdef HAVE_SNDFILE_H
49
- rb_define_singleton_method(mWiretap, "supports_audio?", VALUEFUNC(wiretap_true), -1);
53
+ rb_define_const(mWiretap, "AUDIO", Qtrue);
50
54
  #else
51
- rb_define_singleton_method(mWiretap, "supports_audio?", VALUEFUNC(wiretap_false), -1);
55
+ rb_define_const(mWiretap, "AUDIO", Qfalse);
52
56
  #endif
53
57
 
54
- Init_ppm();
55
-
58
+
56
59
  Init_server();
57
60
  Init_node();
58
61
  Init_children();
data/ext/wiretap.h CHANGED
@@ -2,6 +2,7 @@
2
2
  #define _WIRETAP_H_
3
3
 
4
4
  #include <WireTapClientAPI.h>
5
+ #include <WIRETAP_VERSION>
5
6
  #include <ifffsWTTypes.h>
6
7
  #include <stdlib.h>
7
8
  #include <stdio.h>
@@ -11,9 +12,11 @@
11
12
  #include <sys/stat.h>
12
13
  #include <sys/types.h>
13
14
  #include <stdarg.h>
14
- #include "image.h"
15
15
  #include <memory>
16
16
 
17
+ #include "frame_io.h"
18
+ #include "image_io.h"
19
+
17
20
 
18
21
  #ifdef __cplusplus
19
22
  # ifndef RUBY_METHOD_FUNC /* These definitions should work for Ruby 1.4.6 */
@@ -55,6 +58,17 @@
55
58
  #define NODERUN_E(node, x) RUN_E(x, node)
56
59
  #define SERVERRUN_E(server, x) RUN_E(x, server)
57
60
 
61
+ // A special wrapper to be used when we might potentially stumble upon concurrency problems with locked
62
+ // libraries (typical for IFFS). We use a special macro for this to be able to catch concurrency errors and
63
+ // raise accordingly
64
+ #define NODERUN_EX_E(container, expr) {if(!(expr)) { \
65
+ if(strstr(container->lastError(), "locked")) { \
66
+ rb_raise(eConcurrentLockError, "%s. File: %s: %d", container->lastError(), __FILE__, __LINE__); \
67
+ } else { \
68
+ rb_raise(eError, "Problem in wiretap: %s. File: %s: %d", container->lastError(), __FILE__, __LINE__); \
69
+ } \
70
+ }}
71
+
58
72
  #define Check_Node_Alive(node) \
59
73
  if(rb_iv_get(self, "@destroyed") == Qtrue) { \
60
74
  rb_warn("Node is already destroyed"); \
@@ -82,10 +96,6 @@ void Init_children();
82
96
  void Init_metadata();
83
97
  void Init_nodeframes();
84
98
 
85
- void Init_ppm();
86
- bool ppm_read_format(FILE* f, WireTapClipFormat* format);
87
- bool ppm_read_image(FILE* f, unsigned char* frame, int width, int height, int bpp);
88
-
89
99
 
90
100
  void Init_image_format();
91
101
  bool wiretap_write_image_frame(int width, int height, int bpp, unsigned char* frame, const char* filename);
@@ -99,17 +109,11 @@ void Init_thread_worker();
99
109
  extern "C" {
100
110
  void Init_wiretap_bin(void);
101
111
  extern VALUE mWiretap, mPPM, cServer, cServerList, cServerInfo;
102
- extern VALUE cNode, cHost, cVolume, cClip, cAudio, cReel, cLibrary, cProject;
112
+ extern VALUE cNode, cHost, cVolume, cClip, cHiresClip, cLowresClip, cSlateClip, cAudio, cReel, cLibrary, cProject;
103
113
  extern VALUE cNodeChildren, cNodeFrames, cAudioFrames, cNodeMetaData, cClipFormat, cAudioFormat;
104
- extern VALUE eError;
114
+ extern VALUE eError, eConcurrentLockError;
105
115
  extern ID to_i;
106
116
 
107
117
  } /* extern "C" { */
108
118
 
109
-
110
-
111
-
112
-
113
119
  #endif
114
-
115
-