diff options
Diffstat (limited to 'drivers/media/v4l2-core/videobuf2-core.c')
-rw-r--r-- | drivers/media/v4l2-core/videobuf2-core.c | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c index c359006074a8..25d3ae2188cb 100644 --- a/drivers/media/v4l2-core/videobuf2-core.c +++ b/drivers/media/v4l2-core/videobuf2-core.c | |||
@@ -971,6 +971,7 @@ static int __reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req) | |||
971 | * to the userspace. | 971 | * to the userspace. |
972 | */ | 972 | */ |
973 | req->count = allocated_buffers; | 973 | req->count = allocated_buffers; |
974 | q->waiting_for_buffers = !V4L2_TYPE_IS_OUTPUT(q->type); | ||
974 | 975 | ||
975 | return 0; | 976 | return 0; |
976 | } | 977 | } |
@@ -1018,6 +1019,7 @@ static int __create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create | |||
1018 | memset(q->plane_sizes, 0, sizeof(q->plane_sizes)); | 1019 | memset(q->plane_sizes, 0, sizeof(q->plane_sizes)); |
1019 | memset(q->alloc_ctx, 0, sizeof(q->alloc_ctx)); | 1020 | memset(q->alloc_ctx, 0, sizeof(q->alloc_ctx)); |
1020 | q->memory = create->memory; | 1021 | q->memory = create->memory; |
1022 | q->waiting_for_buffers = !V4L2_TYPE_IS_OUTPUT(q->type); | ||
1021 | } | 1023 | } |
1022 | 1024 | ||
1023 | num_buffers = min(create->count, VIDEO_MAX_FRAME - q->num_buffers); | 1025 | num_buffers = min(create->count, VIDEO_MAX_FRAME - q->num_buffers); |
@@ -1130,7 +1132,7 @@ EXPORT_SYMBOL_GPL(vb2_plane_vaddr); | |||
1130 | */ | 1132 | */ |
1131 | void *vb2_plane_cookie(struct vb2_buffer *vb, unsigned int plane_no) | 1133 | void *vb2_plane_cookie(struct vb2_buffer *vb, unsigned int plane_no) |
1132 | { | 1134 | { |
1133 | if (plane_no > vb->num_planes || !vb->planes[plane_no].mem_priv) | 1135 | if (plane_no >= vb->num_planes || !vb->planes[plane_no].mem_priv) |
1134 | return NULL; | 1136 | return NULL; |
1135 | 1137 | ||
1136 | return call_ptr_memop(vb, cookie, vb->planes[plane_no].mem_priv); | 1138 | return call_ptr_memop(vb, cookie, vb->planes[plane_no].mem_priv); |
@@ -1165,13 +1167,10 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state) | |||
1165 | if (WARN_ON(vb->state != VB2_BUF_STATE_ACTIVE)) | 1167 | if (WARN_ON(vb->state != VB2_BUF_STATE_ACTIVE)) |
1166 | return; | 1168 | return; |
1167 | 1169 | ||
1168 | if (!q->start_streaming_called) { | 1170 | if (WARN_ON(state != VB2_BUF_STATE_DONE && |
1169 | if (WARN_ON(state != VB2_BUF_STATE_QUEUED)) | 1171 | state != VB2_BUF_STATE_ERROR && |
1170 | state = VB2_BUF_STATE_QUEUED; | 1172 | state != VB2_BUF_STATE_QUEUED)) |
1171 | } else if (WARN_ON(state != VB2_BUF_STATE_DONE && | 1173 | state = VB2_BUF_STATE_ERROR; |
1172 | state != VB2_BUF_STATE_ERROR)) { | ||
1173 | state = VB2_BUF_STATE_ERROR; | ||
1174 | } | ||
1175 | 1174 | ||
1176 | #ifdef CONFIG_VIDEO_ADV_DEBUG | 1175 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
1177 | /* | 1176 | /* |
@@ -1762,6 +1761,12 @@ static int vb2_start_streaming(struct vb2_queue *q) | |||
1762 | q->start_streaming_called = 0; | 1761 | q->start_streaming_called = 0; |
1763 | 1762 | ||
1764 | dprintk(1, "driver refused to start streaming\n"); | 1763 | dprintk(1, "driver refused to start streaming\n"); |
1764 | /* | ||
1765 | * If you see this warning, then the driver isn't cleaning up properly | ||
1766 | * after a failed start_streaming(). See the start_streaming() | ||
1767 | * documentation in videobuf2-core.h for more information how buffers | ||
1768 | * should be returned to vb2 in start_streaming(). | ||
1769 | */ | ||
1765 | if (WARN_ON(atomic_read(&q->owned_by_drv_count))) { | 1770 | if (WARN_ON(atomic_read(&q->owned_by_drv_count))) { |
1766 | unsigned i; | 1771 | unsigned i; |
1767 | 1772 | ||
@@ -1777,6 +1782,12 @@ static int vb2_start_streaming(struct vb2_queue *q) | |||
1777 | /* Must be zero now */ | 1782 | /* Must be zero now */ |
1778 | WARN_ON(atomic_read(&q->owned_by_drv_count)); | 1783 | WARN_ON(atomic_read(&q->owned_by_drv_count)); |
1779 | } | 1784 | } |
1785 | /* | ||
1786 | * If done_list is not empty, then start_streaming() didn't call | ||
1787 | * vb2_buffer_done(vb, VB2_BUF_STATE_QUEUED) but STATE_ERROR or | ||
1788 | * STATE_DONE. | ||
1789 | */ | ||
1790 | WARN_ON(!list_empty(&q->done_list)); | ||
1780 | return ret; | 1791 | return ret; |
1781 | } | 1792 | } |
1782 | 1793 | ||
@@ -1812,6 +1823,7 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b) | |||
1812 | */ | 1823 | */ |
1813 | list_add_tail(&vb->queued_entry, &q->queued_list); | 1824 | list_add_tail(&vb->queued_entry, &q->queued_list); |
1814 | q->queued_count++; | 1825 | q->queued_count++; |
1826 | q->waiting_for_buffers = false; | ||
1815 | vb->state = VB2_BUF_STATE_QUEUED; | 1827 | vb->state = VB2_BUF_STATE_QUEUED; |
1816 | if (V4L2_TYPE_IS_OUTPUT(q->type)) { | 1828 | if (V4L2_TYPE_IS_OUTPUT(q->type)) { |
1817 | /* | 1829 | /* |
@@ -2123,6 +2135,12 @@ static void __vb2_queue_cancel(struct vb2_queue *q) | |||
2123 | if (q->start_streaming_called) | 2135 | if (q->start_streaming_called) |
2124 | call_void_qop(q, stop_streaming, q); | 2136 | call_void_qop(q, stop_streaming, q); |
2125 | 2137 | ||
2138 | /* | ||
2139 | * If you see this warning, then the driver isn't cleaning up properly | ||
2140 | * in stop_streaming(). See the stop_streaming() documentation in | ||
2141 | * videobuf2-core.h for more information how buffers should be returned | ||
2142 | * to vb2 in stop_streaming(). | ||
2143 | */ | ||
2126 | if (WARN_ON(atomic_read(&q->owned_by_drv_count))) { | 2144 | if (WARN_ON(atomic_read(&q->owned_by_drv_count))) { |
2127 | for (i = 0; i < q->num_buffers; ++i) | 2145 | for (i = 0; i < q->num_buffers; ++i) |
2128 | if (q->bufs[i]->state == VB2_BUF_STATE_ACTIVE) | 2146 | if (q->bufs[i]->state == VB2_BUF_STATE_ACTIVE) |
@@ -2272,6 +2290,7 @@ static int vb2_internal_streamoff(struct vb2_queue *q, enum v4l2_buf_type type) | |||
2272 | * their normal dequeued state. | 2290 | * their normal dequeued state. |
2273 | */ | 2291 | */ |
2274 | __vb2_queue_cancel(q); | 2292 | __vb2_queue_cancel(q); |
2293 | q->waiting_for_buffers = !V4L2_TYPE_IS_OUTPUT(q->type); | ||
2275 | 2294 | ||
2276 | dprintk(3, "successful\n"); | 2295 | dprintk(3, "successful\n"); |
2277 | return 0; | 2296 | return 0; |
@@ -2590,10 +2609,17 @@ unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait) | |||
2590 | } | 2609 | } |
2591 | 2610 | ||
2592 | /* | 2611 | /* |
2593 | * There is nothing to wait for if no buffer has been queued and the | 2612 | * There is nothing to wait for if the queue isn't streaming, or if the |
2594 | * queue isn't streaming, or if the error flag is set. | 2613 | * error flag is set. |
2614 | */ | ||
2615 | if (!vb2_is_streaming(q) || q->error) | ||
2616 | return res | POLLERR; | ||
2617 | /* | ||
2618 | * For compatibility with vb1: if QBUF hasn't been called yet, then | ||
2619 | * return POLLERR as well. This only affects capture queues, output | ||
2620 | * queues will always initialize waiting_for_buffers to false. | ||
2595 | */ | 2621 | */ |
2596 | if ((list_empty(&q->queued_list) && !vb2_is_streaming(q)) || q->error) | 2622 | if (q->waiting_for_buffers) |
2597 | return res | POLLERR; | 2623 | return res | POLLERR; |
2598 | 2624 | ||
2599 | /* | 2625 | /* |