1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use aravis_sys;
use glib::object::IsA;
use glib::translate::*;
use std::fmt;
use std::mem;
use BufferPayloadType;
use BufferStatus;
use PixelFormat;

glib_wrapper! {
	pub struct Buffer(Object<aravis_sys::ArvBuffer, aravis_sys::ArvBufferClass, BufferClass>);

	match fn {
		get_type => || aravis_sys::arv_buffer_get_type(),
	}
}

impl Buffer {
	//pub fn new(size: usize, preallocated: /*Unimplemented*/Option<Fundamental: Pointer>) -> Buffer {
	//    unsafe { TODO: call aravis_sys:arv_buffer_new() }
	//}

	/// Creates a new buffer for the storage of the video stream images.
	/// The data space is allocated by this function, and will
	/// be freed when the buffer is destroyed.
	/// ## `size`
	/// payload size
	///
	/// # Returns
	///
	/// a new `Buffer` object
	pub fn new_allocate(size: usize) -> Buffer {
		assert_initialized_main_thread!();
		unsafe { from_glib_full(aravis_sys::arv_buffer_new_allocate(size)) }
	}
}

unsafe impl Send for Buffer {}

pub const NONE_BUFFER: Option<&Buffer> = None;

/// Trait containing all `Buffer` methods.
///
/// # Implementors
///
/// [`Buffer`](struct.Buffer.html)
pub trait BufferExt: 'static {
	/// Chunk data accessor.
	/// ## `chunk_id`
	/// chunk id
	/// ## `size`
	/// location to store chunk data size, or `None`
	///
	/// # Returns
	///
	/// a pointer to the chunk data.
	fn get_chunk_data(&self, chunk_id: u64) -> Vec<u8>;

	/// Gets the buffer frame id. For GigEVision devices, valid values are in the
	/// 1..65535 range.
	///
	/// # Returns
	///
	/// frame id, 0 on error.
	fn get_frame_id(&self) -> u64;

	/// Gets the image width. This function must only be called on buffer containing a `BufferPayloadType::Image` payload.
	///
	/// # Returns
	///
	/// image height, in pixels.
	fn get_image_height(&self) -> i32;

	/// Gets the image pixel format. This function must only be called on buffer containing a `BufferPayloadType::Image` payload.
	///
	/// # Returns
	///
	/// image pixel format.
	fn get_image_pixel_format(&self) -> PixelFormat;

	/// Gets the image region. This function must only be called on buffer containing a `BufferPayloadType::Image` payload.
	/// ## `x`
	/// image x offset placeholder
	/// ## `y`
	/// image y offset placeholder
	/// ## `width`
	/// image width placholder
	/// ## `height`
	/// image height placeholder
	fn get_image_region(&self) -> (i32, i32, i32, i32);

	/// Gets the image width. This function must only be called on buffer containing a `BufferPayloadType::Image` payload.
	///
	/// # Returns
	///
	/// image width, in pixels.
	fn get_image_width(&self) -> i32;

	/// Gets the image x offset. This function must only be called on buffer containing a `BufferPayloadType::Image` payload.
	///
	/// # Returns
	///
	/// image x offset, in pixels.
	fn get_image_x(&self) -> i32;

	/// Gets the image y offset. This function must only be called on buffer containing a `BufferPayloadType::Image` payload.
	///
	/// # Returns
	///
	/// image y offset, in pixels.
	fn get_image_y(&self) -> i32;

	/// Gets the buffer payload type.
	///
	/// # Returns
	///
	/// payload type.
	fn get_payload_type(&self) -> BufferPayloadType;

	/// Gets the buffer acquisition status.
	///
	/// # Returns
	///
	/// buffer acquisition status.
	fn get_status(&self) -> BufferStatus;

	/// Gets the system timestamp for when the frame was received. Expressed in
	/// nanoseconds.
	///
	/// # Returns
	///
	/// buffer system timestamp, in nanoseconds.
	fn get_system_timestamp(&self) -> u64;

	/// Gets the buffer camera timestamp, expressed as nanoseconds. Not all devices
	/// provide reliable timestamp, which means sometimes its better to rely on the
	/// buffer completion host local time, or to use
	/// `BufferExt::get_system_timestamp`.
	///
	/// # Returns
	///
	/// buffer timestamp, in nanoseconds.
	fn get_timestamp(&self) -> u64;

	//fn get_user_data(&self) -> /*Unimplemented*/Option<Fundamental: Pointer>;

	///
	/// # Returns
	///
	/// `true` if `self` has a payload type that contains chunk data.
	fn has_chunks(&self) -> bool;

	/// Sets the system timestamp for when the frame was received. Expressed in
	/// nanoseconds.
	/// ## `timestamp_ns`
	/// a timestamp, expressed as nanoseconds
	fn set_system_timestamp(&self, timestamp_ns: u64);

	/// Sets the buffer timestamp, which allows to override the timpestamp set by
	/// the camera, which in some case is incorrect.
	/// ## `timestamp_ns`
	/// a timestamp, expressed as nanoseconds
	fn set_timestamp(&self, timestamp_ns: u64);
}

impl<O: IsA<Buffer>> BufferExt for O {
	fn get_chunk_data(&self, chunk_id: u64) -> Vec<u8> {
		unsafe {
			let mut size = mem::MaybeUninit::uninit();
			let ret = FromGlibContainer::from_glib_none_num(
				aravis_sys::arv_buffer_get_chunk_data(
					self.as_ref().to_glib_none().0,
					chunk_id,
					size.as_mut_ptr(),
				),
				size.assume_init() as usize,
			);
			ret
		}
	}

	fn get_frame_id(&self) -> u64 {
		unsafe { aravis_sys::arv_buffer_get_frame_id(self.as_ref().to_glib_none().0) }
	}

	fn get_image_height(&self) -> i32 {
		unsafe { aravis_sys::arv_buffer_get_image_height(self.as_ref().to_glib_none().0) }
	}

	fn get_image_pixel_format(&self) -> PixelFormat {
		unsafe {
			from_glib(aravis_sys::arv_buffer_get_image_pixel_format(
				self.as_ref().to_glib_none().0,
			))
		}
	}

	fn get_image_region(&self) -> (i32, i32, i32, i32) {
		unsafe {
			let mut x = mem::MaybeUninit::uninit();
			let mut y = mem::MaybeUninit::uninit();
			let mut width = mem::MaybeUninit::uninit();
			let mut height = mem::MaybeUninit::uninit();
			aravis_sys::arv_buffer_get_image_region(
				self.as_ref().to_glib_none().0,
				x.as_mut_ptr(),
				y.as_mut_ptr(),
				width.as_mut_ptr(),
				height.as_mut_ptr(),
			);
			let x = x.assume_init();
			let y = y.assume_init();
			let width = width.assume_init();
			let height = height.assume_init();
			(x, y, width, height)
		}
	}

	fn get_image_width(&self) -> i32 {
		unsafe { aravis_sys::arv_buffer_get_image_width(self.as_ref().to_glib_none().0) }
	}

	fn get_image_x(&self) -> i32 {
		unsafe { aravis_sys::arv_buffer_get_image_x(self.as_ref().to_glib_none().0) }
	}

	fn get_image_y(&self) -> i32 {
		unsafe { aravis_sys::arv_buffer_get_image_y(self.as_ref().to_glib_none().0) }
	}

	fn get_payload_type(&self) -> BufferPayloadType {
		unsafe {
			from_glib(aravis_sys::arv_buffer_get_payload_type(
				self.as_ref().to_glib_none().0,
			))
		}
	}

	fn get_status(&self) -> BufferStatus {
		unsafe {
			from_glib(aravis_sys::arv_buffer_get_status(
				self.as_ref().to_glib_none().0,
			))
		}
	}

	fn get_system_timestamp(&self) -> u64 {
		unsafe { aravis_sys::arv_buffer_get_system_timestamp(self.as_ref().to_glib_none().0) }
	}

	fn get_timestamp(&self) -> u64 {
		unsafe { aravis_sys::arv_buffer_get_timestamp(self.as_ref().to_glib_none().0) }
	}

	//fn get_user_data(&self) -> /*Unimplemented*/Option<Fundamental: Pointer> {
	//    unsafe { TODO: call aravis_sys:arv_buffer_get_user_data() }
	//}

	fn has_chunks(&self) -> bool {
		unsafe {
			from_glib(aravis_sys::arv_buffer_has_chunks(
				self.as_ref().to_glib_none().0,
			))
		}
	}

	fn set_system_timestamp(&self, timestamp_ns: u64) {
		unsafe {
			aravis_sys::arv_buffer_set_system_timestamp(
				self.as_ref().to_glib_none().0,
				timestamp_ns,
			);
		}
	}

	fn set_timestamp(&self, timestamp_ns: u64) {
		unsafe {
			aravis_sys::arv_buffer_set_timestamp(self.as_ref().to_glib_none().0, timestamp_ns);
		}
	}
}

impl fmt::Display for Buffer {
	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
		write!(f, "Buffer")
	}
}