[libdc] How do I flush the DMA ring buffer?
Capture and control API for IIDC compliant cameras
Brought to you by:
ddouxchamps,
gordp
From: Brack, G. L (383F) <gar...@jp...> - 2013-02-16 13:14:05
|
I think I have found a bug in the linux driver. I read the FAQ that says: How do I flush the DMA ring buffer? Stop the camera ISO transmission (optional); wait (sleep) at least one frame period (optional, to be sure you have one frame); repeatedly call dc1394_capture_dequeue(,DC1394_VIDEO1394_POLL) until it returns NULL Remember also to call dc1394_enqueue_buffer() after every successful call to a DMA capture function. So I implemented some code to flush the DMA buffer so I would be sure to get the most recent frame. /* flush any frames in queue */ while (dc1394_capture_dequeue (Camera, DC1394_CAPTURE_POLICY_POLL, &img) == DC1394_SUCCESS) { dc1394_capture_enqueue (Camera, img); cnt++; } return dc1394_capture_dequeue (Camera, DC1392_CAPTURE_POICY_WAIT, img); It was Seg Faulted on the call to dc1394_capture_enqueue(). The call to dc1394_capture_dequeue() was always returning SUCCESS. I traced the code down to the routine: dc1394error_t dc1394_juju_capture_dequeue (platform_camera_t * craw, dc1394capture_policy_t policy, dc1394video_frame_t **frame_return) Inside of it it does: fds[0].fd = craw->iso_fd; fds[0].events = POLLIN; while (1) { err = poll(fds, 1, (policy == DC1394_CAPTURE_POLICY_POLL) ? 0 : -1); if (err < 0) { if (errno == EINTR) continue; dc1394_log_error("poll() failed for device %s.", craw->filename); return DC1394_FAILURE; } else if (err == 0) { return DC1394_SUCCESS; } len = read (craw->iso_fd, &iso, sizeof iso); if (len < 0) { dc1394_log_error("Juju: dequeue failed to read a response: %m"); return DC1394_FAILURE; } if (iso.i.type == FW_CDEV_EVENT_ISO_INTERRUPT) break; } If I was following the logic correctly when there are no more frames on the queue the call to poll(fds, 1, 0) should return immediately with a 0. The (err == 0) case should be executed returning DC1394_SUCCESS, not NULL like the FAQ suggests. - Gary Brack |