aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/media/v4l2-core/videobuf2-core.c46
1 files changed, 40 insertions, 6 deletions
diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
index 3c07534e9ba5..dbc2b8ab8cdb 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -2310,6 +2310,22 @@ struct vb2_fileio_buf {
2310/** 2310/**
2311 * struct vb2_fileio_data - queue context used by file io emulator 2311 * struct vb2_fileio_data - queue context used by file io emulator
2312 * 2312 *
2313 * @cur_index: the index of the buffer currently being read from or
2314 * written to. If equal to q->num_buffers then a new buffer
2315 * must be dequeued.
2316 * @initial_index: in the read() case all buffers are queued up immediately
2317 * in __vb2_init_fileio() and __vb2_perform_fileio() just cycles
2318 * buffers. However, in the write() case no buffers are initially
2319 * queued, instead whenever a buffer is full it is queued up by
2320 * __vb2_perform_fileio(). Only once all available buffers have
2321 * been queued up will __vb2_perform_fileio() start to dequeue
2322 * buffers. This means that initially __vb2_perform_fileio()
2323 * needs to know what buffer index to use when it is queuing up
2324 * the buffers for the first time. That initial index is stored
2325 * in this field. Once it is equal to q->num_buffers all
2326 * available buffers have been queued and __vb2_perform_fileio()
2327 * should start the normal dequeue/queue cycle.
2328 *
2313 * vb2 provides a compatibility layer and emulator of file io (read and 2329 * vb2 provides a compatibility layer and emulator of file io (read and
2314 * write) calls on top of streaming API. For proper operation it required 2330 * write) calls on top of streaming API. For proper operation it required
2315 * this structure to save the driver state between each call of the read 2331 * this structure to save the driver state between each call of the read
@@ -2319,7 +2335,8 @@ struct vb2_fileio_data {
2319 struct v4l2_requestbuffers req; 2335 struct v4l2_requestbuffers req;
2320 struct v4l2_buffer b; 2336 struct v4l2_buffer b;
2321 struct vb2_fileio_buf bufs[VIDEO_MAX_FRAME]; 2337 struct vb2_fileio_buf bufs[VIDEO_MAX_FRAME];
2322 unsigned int index; 2338 unsigned int cur_index;
2339 unsigned int initial_index;
2323 unsigned int q_count; 2340 unsigned int q_count;
2324 unsigned int dq_count; 2341 unsigned int dq_count;
2325 unsigned int flags; 2342 unsigned int flags;
@@ -2419,7 +2436,12 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
2419 goto err_reqbufs; 2436 goto err_reqbufs;
2420 fileio->bufs[i].queued = 1; 2437 fileio->bufs[i].queued = 1;
2421 } 2438 }
2422 fileio->index = q->num_buffers; 2439 /*
2440 * All buffers have been queued, so mark that by setting
2441 * initial_index to q->num_buffers
2442 */
2443 fileio->initial_index = q->num_buffers;
2444 fileio->cur_index = q->num_buffers;
2423 } 2445 }
2424 2446
2425 /* 2447 /*
@@ -2498,7 +2520,7 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_
2498 /* 2520 /*
2499 * Check if we need to dequeue the buffer. 2521 * Check if we need to dequeue the buffer.
2500 */ 2522 */
2501 index = fileio->index; 2523 index = fileio->cur_index;
2502 if (index >= q->num_buffers) { 2524 if (index >= q->num_buffers) {
2503 /* 2525 /*
2504 * Call vb2_dqbuf to get buffer back. 2526 * Call vb2_dqbuf to get buffer back.
@@ -2512,7 +2534,7 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_
2512 return ret; 2534 return ret;
2513 fileio->dq_count += 1; 2535 fileio->dq_count += 1;
2514 2536
2515 index = fileio->b.index; 2537 fileio->cur_index = index = fileio->b.index;
2516 buf = &fileio->bufs[index]; 2538 buf = &fileio->bufs[index];
2517 2539
2518 /* 2540 /*
@@ -2588,8 +2610,20 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_
2588 buf->queued = 1; 2610 buf->queued = 1;
2589 buf->size = vb2_plane_size(q->bufs[index], 0); 2611 buf->size = vb2_plane_size(q->bufs[index], 0);
2590 fileio->q_count += 1; 2612 fileio->q_count += 1;
2591 if (fileio->index < q->num_buffers) 2613 /*
2592 fileio->index++; 2614 * If we are queuing up buffers for the first time, then
2615 * increase initial_index by one.
2616 */
2617 if (fileio->initial_index < q->num_buffers)
2618 fileio->initial_index++;
2619 /*
2620 * The next buffer to use is either a buffer that's going to be
2621 * queued for the first time (initial_index < q->num_buffers)
2622 * or it is equal to q->num_buffers, meaning that the next
2623 * time we need to dequeue a buffer since we've now queued up
2624 * all the 'first time' buffers.
2625 */
2626 fileio->cur_index = fileio->initial_index;
2593 } 2627 }
2594 2628
2595 /* 2629 /*