/* ------------------------------------------------------------------------ * Video buffers queue management. * * Video queues is initialized by uvcg_queue_init(). The function performs * basic initialization of the uvc_video_queue struct and never fails. * * Video buffers are managed by videobuf2. The driver uses a mutex to protect * the videobuf2 queue operations by serializing calls to videobuf2 and a * spinlock to protect the IRQ queue that holds the buffers to be processed by * the driver.
*/
if (likely(!(queue->flags & UVC_QUEUE_DISCONNECTED))) {
list_add_tail(&buf->queue, &queue->irqqueue);
} else { /* * If the device is disconnected return the buffer to userspace * directly. The next QBUF call will fail with -ENODEV.
*/
buf->state = UVC_BUF_STATE_ERROR;
vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
}
/* * Dequeue a video buffer. If nonblocking is false, block until a buffer is * available.
*/ int uvcg_dequeue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf, int nonblocking)
{ return vb2_dqbuf(&queue->queue, buf, nonblocking);
}
/* * Poll the video queue. * * This function implements video queue polling and is intended to be used by * the device poll handler.
*/
__poll_t uvcg_queue_poll(struct uvc_video_queue *queue, struct file *file,
poll_table *wait)
{ return vb2_poll(&queue->queue, file, wait);
}
#ifndef CONFIG_MMU /* * Get unmapped area. * * NO-MMU arch need this function to make mmap() work correctly.
*/ unsignedlong uvcg_queue_get_unmapped_area(struct uvc_video_queue *queue, unsignedlong pgoff)
{ return vb2_get_unmapped_area(&queue->queue, 0, 0, pgoff, 0);
} #endif
/* * Cancel the video buffers queue. * * Cancelling the queue marks all buffers on the irq queue as erroneous, * wakes them up and removes them from the queue. * * If the disconnect parameter is set, further calls to uvc_queue_buffer will * fail with -ENODEV. * * This function acquires the irq spinlock and can be called from interrupt * context.
*/ void uvcg_queue_cancel(struct uvc_video_queue *queue, int disconnect)
{ struct uvc_buffer *buf; unsignedlong flags;
/* * This must be protected by the irqlock spinlock to avoid race * conditions between uvc_queue_buffer and the disconnection event that * could result in an interruptible wait in uvc_dequeue_buffer. Do not * blindly replace this logic by checking for the UVC_DEV_DISCONNECTED * state outside the queue code.
*/ if (disconnect)
queue->flags |= UVC_QUEUE_DISCONNECTED;
spin_unlock_irqrestore(&queue->irqlock, flags);
}
/* * Enable or disable the video buffers queue. * * The queue must be enabled before starting video acquisition and must be * disabled after stopping it. This ensures that the video buffers queue * state can be properly initialized before buffers are accessed from the * interrupt handler. * * Enabling the video queue initializes parameters (such as sequence number, * sync pattern, ...). If the queue is already enabled, return -EBUSY. * * Disabling the video queue cancels the queue and removes all buffers from * the main queue. * * This function can't be called from interrupt context. Use * uvcg_queue_cancel() instead.
*/ int uvcg_queue_enable(struct uvc_video_queue *queue, int enable)
{ unsignedlong flags; int ret = 0;
if (enable) {
ret = vb2_streamon(&queue->queue, queue->queue.type); if (ret < 0) return ret;
/* * FIXME: We need to clear the DISCONNECTED flag to ensure that * applications will be able to queue buffers for the next * streaming run. However, clearing it here doesn't guarantee * that the device will be reconnected in the meantime.
*/
queue->flags &= ~UVC_QUEUE_DISCONNECTED;
spin_unlock_irqrestore(&queue->irqlock, flags);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.