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
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from ../gir-files
// DO NOT EDIT

use crate::BufferPayloadType;
use crate::BufferStatus;
use crate::PixelFormat;
use glib::translate::*;
use std::fmt;
use std::mem;

glib::wrapper! {
	#[doc(alias = "ArvBuffer")]
	pub struct Buffer(Object<ffi::ArvBuffer, ffi::ArvBufferClass>);

	match fn {
		type_ => || ffi::arv_buffer_get_type(),
	}
}

impl Buffer {
	//#[doc(alias = "arv_buffer_new")]
	//pub fn new(size: usize, preallocated: /*Unimplemented*/Option<Fundamental: Pointer>) -> Buffer {
	//    unsafe { TODO: call ffi: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`][crate::Buffer] object
	#[doc(alias = "arv_buffer_new_allocate")]
	pub fn new_allocate(size: usize) -> Buffer {
		assert_initialized_main_thread!();
		unsafe { from_glib_full(ffi::arv_buffer_new_allocate(size)) }
	}

	/// Chunk data accessor.
	/// ## `chunk_id`
	/// chunk id
	///
	/// # Returns
	///
	/// a pointer to the chunk data.
	#[doc(alias = "arv_buffer_get_chunk_data")]
	#[doc(alias = "get_chunk_data")]
	pub fn chunk_data(&self, chunk_id: u64) -> Vec<u8> {
		unsafe {
			let mut size = mem::MaybeUninit::uninit();
			let ret = FromGlibContainer::from_glib_none_num(
				ffi::arv_buffer_get_chunk_data(self.to_glib_none().0, chunk_id, size.as_mut_ptr()),
				size.assume_init() as usize,
			);
			ret
		}
	}

	/// Gets the buffer frame id. For GigEVision devices, 0 is an invalid value.
	///
	/// # Returns
	///
	/// frame id, 0 on error.
	#[doc(alias = "arv_buffer_get_frame_id")]
	#[doc(alias = "get_frame_id")]
	pub fn frame_id(&self) -> u64 {
		unsafe { ffi::arv_buffer_get_frame_id(self.to_glib_none().0) }
	}

	/// Gets the image width. This function must only be called on buffer containing a [`BufferPayloadType::Image`][crate::BufferPayloadType::Image] payload.
	///
	/// # Returns
	///
	/// image height, in pixels.
	#[doc(alias = "arv_buffer_get_image_height")]
	#[doc(alias = "get_image_height")]
	pub fn image_height(&self) -> i32 {
		unsafe { ffi::arv_buffer_get_image_height(self.to_glib_none().0) }
	}

	/// Gets the image pixel format. This function must only be called on buffer containing a [`BufferPayloadType::Image`][crate::BufferPayloadType::Image] payload.
	///
	/// # Returns
	///
	/// image pixel format.
	#[doc(alias = "arv_buffer_get_image_pixel_format")]
	#[doc(alias = "get_image_pixel_format")]
	pub fn image_pixel_format(&self) -> PixelFormat {
		unsafe {
			from_glib(ffi::arv_buffer_get_image_pixel_format(
				self.to_glib_none().0,
			))
		}
	}

	/// Gets the image region. This function must only be called on buffer containing a [`BufferPayloadType::Image`][crate::BufferPayloadType::Image] payload.
	///
	/// # Returns
	///
	///
	/// ## `x`
	/// image x offset placeholder
	///
	/// ## `y`
	/// image y offset placeholder
	///
	/// ## `width`
	/// image width placholder
	///
	/// ## `height`
	/// image height placeholder
	#[doc(alias = "arv_buffer_get_image_region")]
	#[doc(alias = "get_image_region")]
	pub fn 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();
			ffi::arv_buffer_get_image_region(
				self.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)
		}
	}

	/// Gets the image width. This function must only be called on buffer containing a [`BufferPayloadType::Image`][crate::BufferPayloadType::Image] payload.
	///
	/// # Returns
	///
	/// image width, in pixels.
	#[doc(alias = "arv_buffer_get_image_width")]
	#[doc(alias = "get_image_width")]
	pub fn image_width(&self) -> i32 {
		unsafe { ffi::arv_buffer_get_image_width(self.to_glib_none().0) }
	}

	/// Gets the image x offset. This function must only be called on buffer containing a [`BufferPayloadType::Image`][crate::BufferPayloadType::Image] payload.
	///
	/// # Returns
	///
	/// image x offset, in pixels.
	#[doc(alias = "arv_buffer_get_image_x")]
	#[doc(alias = "get_image_x")]
	pub fn image_x(&self) -> i32 {
		unsafe { ffi::arv_buffer_get_image_x(self.to_glib_none().0) }
	}

	/// Gets the image y offset. This function must only be called on buffer containing a [`BufferPayloadType::Image`][crate::BufferPayloadType::Image] payload.
	///
	/// # Returns
	///
	/// image y offset, in pixels.
	#[doc(alias = "arv_buffer_get_image_y")]
	#[doc(alias = "get_image_y")]
	pub fn image_y(&self) -> i32 {
		unsafe { ffi::arv_buffer_get_image_y(self.to_glib_none().0) }
	}

	/// Gets the buffer payload type.
	///
	/// # Returns
	///
	/// payload type.
	#[doc(alias = "arv_buffer_get_payload_type")]
	#[doc(alias = "get_payload_type")]
	pub fn payload_type(&self) -> BufferPayloadType {
		unsafe { from_glib(ffi::arv_buffer_get_payload_type(self.to_glib_none().0)) }
	}

	/// Gets the buffer acquisition status.
	///
	/// # Returns
	///
	/// buffer acquisition status.
	#[doc(alias = "arv_buffer_get_status")]
	#[doc(alias = "get_status")]
	pub fn status(&self) -> BufferStatus {
		unsafe { from_glib(ffi::arv_buffer_get_status(self.to_glib_none().0)) }
	}

	/// Gets the system timestamp for when the frame was received. Expressed in
	/// nanoseconds.
	///
	/// # Returns
	///
	/// buffer system timestamp, in nanoseconds.
	#[doc(alias = "arv_buffer_get_system_timestamp")]
	#[doc(alias = "get_system_timestamp")]
	pub fn system_timestamp(&self) -> u64 {
		unsafe { ffi::arv_buffer_get_system_timestamp(self.to_glib_none().0) }
	}

	/// 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
	/// [`system_timestamp()`][Self::system_timestamp()].
	///
	/// # Returns
	///
	/// buffer timestamp, in nanoseconds.
	#[doc(alias = "arv_buffer_get_timestamp")]
	#[doc(alias = "get_timestamp")]
	pub fn timestamp(&self) -> u64 {
		unsafe { ffi::arv_buffer_get_timestamp(self.to_glib_none().0) }
	}

	//#[doc(alias = "arv_buffer_get_user_data")]
	//#[doc(alias = "get_user_data")]
	//pub fn user_data(&self) -> /*Unimplemented*/Option<Fundamental: Pointer> {
	//    unsafe { TODO: call ffi:arv_buffer_get_user_data() }
	//}

	///
	/// # Returns
	///
	/// [`true`] if `self` has a payload type that contains chunk data.
	#[doc(alias = "arv_buffer_has_chunks")]
	pub fn has_chunks(&self) -> bool {
		unsafe { from_glib(ffi::arv_buffer_has_chunks(self.to_glib_none().0)) }
	}

	/// Sets the buffer frame id. For GigEVision devices, 0 is an invalid value.
	/// ## `frame_id`
	/// a `guint64`
	#[cfg(any(feature = "v0_8_3", feature = "dox"))]
	#[cfg_attr(feature = "dox", doc(cfg(feature = "v0_8_3")))]
	#[doc(alias = "arv_buffer_set_frame_id")]
	pub fn set_frame_id(&self, frame_id: u64) {
		unsafe {
			ffi::arv_buffer_set_frame_id(self.to_glib_none().0, frame_id);
		}
	}

	/// Sets the system timestamp for when the frame was received. Expressed in
	/// nanoseconds.
	/// ## `timestamp_ns`
	/// a timestamp, expressed as nanoseconds
	#[doc(alias = "arv_buffer_set_system_timestamp")]
	pub fn set_system_timestamp(&self, timestamp_ns: u64) {
		unsafe {
			ffi::arv_buffer_set_system_timestamp(self.to_glib_none().0, timestamp_ns);
		}
	}

	/// 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
	#[doc(alias = "arv_buffer_set_timestamp")]
	pub fn set_timestamp(&self, timestamp_ns: u64) {
		unsafe {
			ffi::arv_buffer_set_timestamp(self.to_glib_none().0, timestamp_ns);
		}
	}
}

unsafe impl Send for Buffer {}

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