Skip to content

Commit 3634315

Browse files
committed
v4l2: unused support of USER_PTR method
1 parent 661ded2 commit 3634315

File tree

2 files changed

+65
-25
lines changed

2 files changed

+65
-25
lines changed

src/arvv4l2interface.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ arv_v4l2_interface_device_infos_new (const char *device_file, const char *name)
109109
return infos;
110110
}
111111

112-
arv_warning_interface ("No suitable pixel format found for v4l2 device '%s'",
112+
arv_info_interface ("No suitable pixel format found for v4l2 device '%s'",
113113
device_file);
114114
}
115115
v4l2_close (fd);

src/arvv4l2stream.c

+64-24
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,38 @@ G_DEFINE_TYPE_WITH_CODE (ArvV4l2Stream, arv_v4l2_stream, ARV_TYPE_STREAM, G_ADD_
103103

104104
/* Acquisition thread */
105105

106+
static void
107+
_queue_buffers (ArvV4l2StreamThreadData *thread_data, GHashTable *buffers)
108+
{
109+
ArvBuffer *arv_buffer;
110+
struct v4l2_buffer bufd = {0};
111+
112+
do {
113+
arv_buffer = arv_stream_pop_input_buffer (thread_data->stream);
114+
if (ARV_IS_BUFFER (arv_buffer)) {
115+
memset (&bufd, 0, sizeof bufd);
116+
bufd.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
117+
bufd.index = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (arv_buffer), "v4l2-index"));
118+
if (thread_data->io_method == ARV_V4L2_STREAM_IO_METHOD_MMAP) {
119+
bufd.memory = V4L2_MEMORY_MMAP;
120+
} else {
121+
bufd.memory = V4L2_MEMORY_USERPTR;
122+
bufd.m.userptr = (unsigned long) arv_buffer->priv->data;
123+
bufd.length = arv_buffer->priv->allocated_size;
124+
}
125+
126+
if (v4l2_ioctl (thread_data->device_fd, VIDIOC_QBUF, &bufd) == -1) {
127+
arv_warning_stream_thread ("Failed to queue v4l2 buffer (%s)",
128+
strerror (errno));
129+
arv_stream_push_output_buffer(thread_data->stream, arv_buffer);
130+
} else {
131+
arv_trace_stream_thread ("Queue buffer %d\n", bufd.index);
132+
g_hash_table_replace (buffers, GINT_TO_POINTER (bufd.index), arv_buffer);
133+
}
134+
}
135+
} while (arv_buffer != NULL);
136+
}
137+
106138
static void *
107139
arv_v4l2_stream_thread (void *data)
108140
{
@@ -118,36 +150,20 @@ arv_v4l2_stream_thread (void *data)
118150
thread_data->callback (thread_data->callback_data, ARV_STREAM_CALLBACK_TYPE_INIT, NULL);
119151

120152
buffers = g_hash_table_new (g_direct_hash, g_direct_equal);
153+
_queue_buffers(thread_data, buffers);
121154

122155
g_mutex_lock (&thread_data->thread_started_mutex);
123156
thread_data->thread_started = TRUE;
124157
g_cond_signal (&thread_data->thread_started_cond);
125158
g_mutex_unlock (&thread_data->thread_started_mutex);
126159

127-
g_usleep (100000);
128-
129160
while (!g_atomic_int_get (&thread_data->cancel)) {
130161
struct v4l2_buffer bufd = {0};
131162
fd_set fds;
132163
struct timeval tv;
133164
int result;
134165

135-
do {
136-
arv_buffer = arv_stream_pop_input_buffer (thread_data->stream);
137-
if (ARV_IS_BUFFER (arv_buffer)) {
138-
bufd.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
139-
bufd.memory = V4L2_MEMORY_MMAP;
140-
bufd.index = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (arv_buffer), "v4l2-index"));
141-
142-
if (v4l2_ioctl (thread_data->device_fd, VIDIOC_QBUF, &bufd) == -1) {
143-
arv_warning_stream_thread ("Failed to queue v4l2 buffer");
144-
arv_stream_push_output_buffer(thread_data->stream, arv_buffer);
145-
} else {
146-
arv_trace_stream_thread ("Queue buffer %d\n", bufd.index);
147-
g_hash_table_replace (buffers, GINT_TO_POINTER (bufd.index), arv_buffer);
148-
}
149-
}
150-
} while (arv_buffer != NULL);
166+
_queue_buffers(thread_data, buffers);
151167

152168
FD_ZERO(&fds);
153169
FD_SET(thread_data->device_fd, &fds);
@@ -164,13 +180,19 @@ arv_v4l2_stream_thread (void *data)
164180
if (result == 0)
165181
continue;
166182

183+
memset (&bufd, 0, sizeof bufd);
167184
bufd.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
168-
bufd.memory = V4L2_MEMORY_MMAP;
185+
bufd.memory = thread_data->io_method == ARV_V4L2_STREAM_IO_METHOD_MMAP ?
186+
V4L2_MEMORY_MMAP : V4L2_MEMORY_USERPTR;
169187
bufd.index = 0;
170188

171-
if(v4l2_ioctl(thread_data->device_fd, VIDIOC_DQBUF, &bufd) == -1)
189+
if(v4l2_ioctl(thread_data->device_fd, VIDIOC_DQBUF, &bufd) == -1) {
172190
arv_warning_stream_thread("DeQueue buffer error (%s)", strerror(errno));
173-
else
191+
switch (errno) {
192+
case EAGAIN:
193+
continue;
194+
}
195+
} else
174196
arv_trace_stream_thread ("Dequeued buffer %d\n", bufd.index);
175197

176198
arv_buffer = g_hash_table_lookup (buffers, GINT_TO_POINTER (bufd.index));
@@ -227,7 +249,7 @@ arv_v4l2_stream_thread (void *data)
227249
return NULL;
228250
}
229251

230-
/* ArvV4l2Stream implemenation */
252+
/* ArvV4l2Stream implementation */
231253

232254
static gboolean
233255
arv_v4l2_stream_start_acquisition (ArvStream *stream, GError **error)
@@ -241,6 +263,7 @@ arv_v4l2_stream_start_acquisition (ArvStream *stream, GError **error)
241263
guint32 bytes_per_line;
242264
guint32 payload_size;
243265
guint32 width_pixels;
266+
guint32 index = 0;
244267

245268
g_return_val_if_fail (priv->thread == NULL, FALSE);
246269
g_return_val_if_fail (priv->thread_data != NULL, FALSE);
@@ -269,9 +292,11 @@ arv_v4l2_stream_start_acquisition (ArvStream *stream, GError **error)
269292
thread_data->io_method = ARV_V4L2_STREAM_IO_METHOD_MMAP;
270293
} else {
271294
if (thread_data->io_method != ARV_V4L2_STREAM_IO_METHOD_UNKNOWN &&
272-
thread_data->io_method != ARV_V4L2_STREAM_IO_METHOD_READ)
295+
thread_data->io_method != ARV_V4L2_STREAM_IO_METHOD_USER_POINTER)
273296
mixed_io_method = TRUE;
274-
thread_data->io_method = ARV_V4L2_STREAM_IO_METHOD_READ;
297+
thread_data->io_method = ARV_V4L2_STREAM_IO_METHOD_USER_POINTER;
298+
g_object_set_data (G_OBJECT(buffer), "v4l2-index", GINT_TO_POINTER(index));
299+
index++;
275300
}
276301

277302
arv_stream_push_buffer(stream, buffer);
@@ -284,6 +309,21 @@ arv_v4l2_stream_start_acquisition (ArvStream *stream, GError **error)
284309
return FALSE;
285310
}
286311

312+
if (thread_data->io_method == ARV_V4L2_STREAM_IO_METHOD_USER_POINTER) {
313+
struct v4l2_requestbuffers req = {0};
314+
315+
req.count = index;
316+
req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
317+
req.memory = V4L2_MEMORY_USERPTR;
318+
319+
if (v4l2_ioctl(priv->thread_data->device_fd, VIDIOC_REQBUFS, &req) == -1) {
320+
g_set_error (error, ARV_DEVICE_ERROR, ARV_DEVICE_ERROR_PROTOCOL_ERROR,
321+
"V4l2 user pointer method not supported (%s)",
322+
strerror (errno));
323+
return FALSE;
324+
}
325+
}
326+
287327
if (!arv_v4l2_device_get_image_format (priv->thread_data->v4l2_device,
288328
&payload_size,
289329
&thread_data->pixel_format,

0 commit comments

Comments
 (0)