Class: Wiretap::NodeFrames

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
ext/nodeframes.cpp,
lib/wiretap.rb,
ext/nodeframes.cpp

Overview

Access the frames of a clip. The object can be retrieved via Wiretap::Clip#frames

Direct Known Subclasses

AudioFrames

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



255
256
257
# File 'lib/wiretap.rb', line 255

def node
  @node
end

Instance Method Details

#[](index) ⇒ Object

Get frame by index. Returns a formatted Stone image buffer as value (a Ruby string).



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'ext/nodeframes.cpp', line 41

static VALUE wiretap_node_frames_get_at(VALUE self, VALUE index) {
	WireTapNodeHandle* node;
	Data_Get_Struct(self, WireTapNodeHandle, node);
	
	Check_Type(index, T_FIXNUM);
	WireTapClipFormat format;
	RUN(node->getClipFormat(format));

	VALUE frame = rb_str_buf_new(format.frameBufferSize());
	RSTRING(frame)->len = format.frameBufferSize();

	NODERUN_E(node, node->readFrame(FIX2INT(index), STR(frame), LEN(frame)));

	return frame;
}

#[]=(index, value) ⇒ Object

Set frame at index. Accepts a formatted Stone image buffer as value (a Ruby string).



60
61
62
63
64
65
66
67
# File 'ext/nodeframes.cpp', line 60

static VALUE wiretap_node_frames_set_at(VALUE self, VALUE index, VALUE value) {
	WireTapNodeHandle* node;
	Data_Get_Struct(self, WireTapNodeHandle, node);
	Check_Type(index, T_FIXNUM);
	Check_Type(value, T_STRING);
	NODERUN_E(node, node->writeFrame(FIX2INT(index), CSTR(value), LEN(value)));
	return self;
}

#countObject Also known as: size, length

Get frame count of clip. Also available as Wiretap::Clip#length



11
12
13
14
15
16
17
# File 'ext/nodeframes.cpp', line 11

static VALUE wiretap_node_frames_count(VALUE self) {
	WireTapNodeHandle* node;
	int num;
	Data_Get_Struct(self, WireTapNodeHandle, node);
	NODERUN_E(node, node->getNumFrames(num));
	return INT2FIX(num);
}

#count=(value) ⇒ Object

Set frames count in clip



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'ext/nodeframes.cpp', line 22

static VALUE wiretap_node_frames_set_count(VALUE self, VALUE value) {
	VALUE count = rb_funcall(value, rb_intern("to_i"), 0);

	WireTapNodeHandle* node;
	
	Data_Get_Struct(self, WireTapNodeHandle, node);
	int prev_count;
	NODERUN_E(node, node->getNumFrames(prev_count));
  if((prev_count != 0) && (prev_count != NUM2INT(count))) {
    rb_raise(eError, "Cannot reallocate the frames after the frame length has been set", __FILE__, __LINE__);
  }

	NODERUN_E(node, node->setNumFrames(NUM2INT(count)));
	return count;
}

#dump(index, file) ⇒ Object

Dump the frame at index to an SGI file



151
152
153
154
155
156
157
158
159
160
161
162
# File 'ext/nodeframes.cpp', line 151

static VALUE wiretap_node_frame_dump(VALUE self, VALUE index, VALUE file) {
	WireTapNodeHandle* node;
	unsigned long size;
	WireTapClipFormat* format;
	frame_prepare(self, &node, &size, &format);

	std::auto_ptr<unsigned char> frame(new unsigned char[size]);
	NODERUN_E_FRAME(node, node->readFrame(NUM2INT(index), frame.get(), size));

	wiretap_write_image_frame(format->width(), format->height(), format->bitsPerPixel(), frame.get(), CSTR(file));
	return self;
}

#dump_all(file_pattern) ⇒ Object

Dump all frames into files, matched by pattern.

@clip.frames.dump_all("/tmp/clip/%d.sgi")

It is substituted via snprintf



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'ext/nodeframes.cpp', line 129

static VALUE wiretap_node_frame_dump_all(VALUE self, VALUE file_pattern) {
	WireTapNodeHandle* node;
	unsigned long size;
	WireTapClipFormat* format;
	frame_prepare(self, &node, &size, &format);

	int frame_count = NUM2INT(rb_funcall(self, rb_intern("count"), 0));
	std::auto_ptr<unsigned char> frame(new unsigned char[size]);
	for(int i = 0; i < frame_count; i++) {
		NODERUN_E_FRAME(node, node->readFrame(i, frame.get(), size));
		size_t buffer_size = PATH_MAX;
		char file_name[buffer_size];
		snprintf(file_name, buffer_size, STR(file_pattern), i);
		wiretap_write_image_frame(format->width(), format->height(), format->bitsPerPixel(), frame.get(), file_name);
	}

	return self;
}

#eachObject

Eval block on each frame



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'ext/nodeframes.cpp', line 72

static VALUE wiretap_node_frames_each(VALUE self) {
	WireTapNodeHandle* node;
	int i, num;
	Data_Get_Struct(self, WireTapNodeHandle, node);
	RUN(node->getNumFrames(num));

	WireTapClipFormat format;
	RUN(node->getClipFormat(format));

	for(i = 0; i < num; i++) {
		VALUE frame = rb_str_buf_new(format.frameBufferSize());
		RSTRING(frame)->len = format.frameBufferSize();

		RUN(node->readFrame(i, STR(frame), LEN(frame)));
		//rb_iv_set(frame, "@path", wiretap_node_frames_get_path_at(self, INT2FIX(i)));
		rb_yield(frame);
	}
	return self;
}

#inspectObject

:nodoc:



260
261
262
# File 'lib/wiretap.rb', line 260

def inspect #:nodoc:
  super.gsub />$/, " length:#{length}>"
end

#length=(value) ⇒ Object

Set frames count in clip



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'ext/nodeframes.cpp', line 22

static VALUE wiretap_node_frames_set_count(VALUE self, VALUE value) {
	VALUE count = rb_funcall(value, rb_intern("to_i"), 0);

	WireTapNodeHandle* node;
	
	Data_Get_Struct(self, WireTapNodeHandle, node);
	int prev_count;
	NODERUN_E(node, node->getNumFrames(prev_count));
  if((prev_count != 0) && (prev_count != NUM2INT(count))) {
    rb_raise(eError, "Cannot reallocate the frames after the frame length has been set", __FILE__, __LINE__);
  }

	NODERUN_E(node, node->setNumFrames(NUM2INT(count)));
	return count;
}

#path_at(index) ⇒ Object

Get path of frame at index (will include the internal StoneFS frame counter identifier)



95
96
97
98
99
100
101
102
103
104
105
# File 'ext/nodeframes.cpp', line 95

static VALUE wiretap_node_frames_get_path_at(VALUE self, VALUE index) {
	WireTapNodeHandle* node;
	Data_Get_Struct(self, WireTapNodeHandle, node);
	
	Check_Type(index, T_FIXNUM);

	WireTapStr path;
	RUN(node->getFrameIdPath(FIX2INT(index), path));

	return wiretap_to_str(path);
}

#write_from_file(index, filename) ⇒ Object

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. You cannot change the number of frames afterwards.



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'ext/nodeframes.cpp', line 168

static VALUE wiretap_node_frame_write_from_file(VALUE self, VALUE index, VALUE filename) {
	WireTapNodeHandle* node;
	WireTapClipFormat format;

	Data_Get_Struct(self, WireTapNodeHandle, node);
	NODERUN_E(node, node->getClipFormat(format));
	int i = NUM2INT(index);

	std::auto_ptr<ImageIO> image(ImageIO::open(CSTR(filename), format));
	if(!image.get()) {
		THROW("Couldn't open file %s for reading", CSTR(filename));
	}
	image->read_format();
	std::auto_ptr<unsigned char> frame(image->read_data());
	if(!frame.get()) {
		frame.release();
		image.release();
		THROW("Couldn't read PPM image data from file %s", CSTR(filename));
	}
	int totalFrms;
	NODERUN_E_FRAME(node, node->getNumFrames(totalFrms));
  
	/* Edge case - If we are setting the first frame and the clip has no frames */
	if ((totalFrms == i) && (i == 0)) {
	  NODERUN_E_FRAME(node, node->setNumFrames(i+1)); /* wiretapd will crash on setNumFrames(0) */
	} else if (i >= totalFrms) {
	  /* Edge case - trying to add a frame to a clip after the fact will crash wiretapd */
	  frame.release();
	  THROW("You cannot add frames to an existing clip");
	}

	NODERUN_E_FRAME(node, node->writeFrame(i, frame.get(), format.frameBufferSize()));
	return self;
}