MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / xs_camera_loop

Function xs_camera_loop

modules/io/imagein/camera/lin/camera.c:175–254  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

173}
174
175static gpointer xs_camera_loop(gpointer it)
176{
177 Camera camera = it;
178 int fd = camera->fd;
179 enum v4l2_buf_type type;
180 CameraBuffer buffer;
181 struct v4l2_buffer buf;
182 fd_set fds;
183 struct timeval tv;
184
185 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
186 if (-1 == xioctl(fd, VIDIOC_STREAMON, &type))
187 fprintf(stderr, "VIDIOC_STREAMON: %s\n", strerror(errno));
188
189 for (;;) {
190 g_mutex_lock(&(camera->threadMutex));
191 while ((camera->threadBuffer == NULL) && (camera->destructing == 0))
192 g_cond_wait(&(camera->threadCondition), &(camera->threadMutex));
193 buffer = xs_camera_dequeueBuffer(&(camera->threadBuffer));
194 g_mutex_unlock(&(camera->threadMutex));
195 if (camera->destructing)
196 break;
197
198 memset(&buf, 0, sizeof(buf));
199 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
200 buf.memory = V4L2_MEMORY_MMAP;
201 buf.index = buffer->index;
202 if (-1 == xioctl(fd, VIDIOC_QBUF, &buf))
203 fprintf(stderr, "%s\n", strerror(errno));
204
205 again:
206 FD_ZERO(&fds);
207 FD_SET(fd, &fds);
208 tv.tv_sec = 2;
209 tv.tv_usec = 0;
210 int result = select(fd + 1, &fds, NULL, NULL, &tv);
211 if (-1 == result) {
212 if (EINTR == errno)
213 goto again;
214 fprintf(stderr, "select: %s\n", strerror(errno));
215 break;
216 }
217 else if (0 == result) {
218 fprintf(stderr, "select: timeout\n");
219 break;
220 }
221 memset(&buf, 0, sizeof(buf));
222 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
223 buf.memory = V4L2_MEMORY_MMAP;
224 if (-1 == xioctl(fd, VIDIOC_DQBUF, &buf)) {
225 if (EAGAIN == errno)
226 goto again;
227 fprintf(stderr, "VIDIOC_DQBUF: %s\n", strerror(errno));
228 break;
229 }
230
231 buffer = &(camera->queueBuffers[buf.index]);
232 if (camera->yuvToRGB)

Callers

nothing calls this directly

Calls 4

xioctlFunction · 0.85
selectFunction · 0.85
xs_camera_dequeueBufferFunction · 0.70
xs_camera_enqueueBufferFunction · 0.70

Tested by

no test coverage detected