[PATCH v3 2/4] vb2: add allow_zero_bytesused flag to the vb2_queue struct

2015-02-19 Thread Kamil Debski
The vb2: fix bytesused == 0 handling (8a75ffb) patch changed the behavior
of __fill_vb2_buffer function, so that if bytesused is 0 it is set to the
size of the buffer. However, bytesused set to 0 is used by older codec
drivers as as indication used to mark the end of stream.

To keep backward compatibility, this patch adds a flag passed to the
vb2_queue_init function - allow_zero_bytesused. If the flag is set upon
initialization of the queue, the videobuf2 keeps the value of bytesused
intact in the OUTPUT queue and passes it to the driver.

Reported-by: Nicolas Dufresne 
Signed-off-by: Kamil Debski 
---
 drivers/media/v4l2-core/videobuf2-core.c |   29 +++--
 include/media/videobuf2-core.h   |1 +
 2 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index 62531956..487e31f 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -1276,13 +1276,22 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, 
const struct v4l2_buffer *b
 * userspace clearly never bothered to set it and
 * it's a safe assumption that they really meant to
 * use the full plane sizes.
+*
+* Some drivers, e.g. old codec drivers, use bytesused
+* == 0 as a way to indicate that streaming is finished.
+* In that case, the driver should use the
+* allow_zero_bytesused flag to keep old userspace
+* applications working.
 */
for (plane = 0; plane < vb->num_planes; ++plane) {
struct v4l2_plane *pdst = &v4l2_planes[plane];
struct v4l2_plane *psrc = &b->m.planes[plane];
 
-   pdst->bytesused = psrc->bytesused ?
-   psrc->bytesused : pdst->length;
+   if (vb->vb2_queue->allow_zero_bytesused)
+   pdst->bytesused = psrc->bytesused;
+   else
+   pdst->bytesused = psrc->bytesused ?
+   psrc->bytesused : pdst->length;
pdst->data_offset = psrc->data_offset;
}
}
@@ -1295,6 +1304,11 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, 
const struct v4l2_buffer *b
 *
 * If bytesused == 0 for the output buffer, then fall back
 * to the full buffer size as that's a sensible default.
+*
+* Some drivers, e.g. old codec drivers, use bytesused * == 0 as
+* a way to indicate that streaming is finished. In that case,
+* the driver should use the allow_zero_bytesused flag to keep
+* old userspace applications working.
 */
if (b->memory == V4L2_MEMORY_USERPTR) {
v4l2_planes[0].m.userptr = b->m.userptr;
@@ -1306,10 +1320,13 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, 
const struct v4l2_buffer *b
v4l2_planes[0].length = b->length;
}
 
-   if (V4L2_TYPE_IS_OUTPUT(b->type))
-   v4l2_planes[0].bytesused = b->bytesused ?
-   b->bytesused : v4l2_planes[0].length;
-   else
+   if (V4L2_TYPE_IS_OUTPUT(b->type)) {
+   if (vb->vb2_queue->allow_zero_bytesused)
+   v4l2_planes[0].bytesused = b->bytesused;
+   else
+   v4l2_planes[0].bytesused = b->bytesused ?
+   b->bytesused : v4l2_planes[0].length;
+   } else
v4l2_planes[0].bytesused = 0;
 
}
diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
index 1346693..50111bd573 100644
--- a/include/media/videobuf2-core.h
+++ b/include/media/videobuf2-core.h
@@ -388,6 +388,7 @@ struct vb2_queue {
unsigned intio_modes;
unsignedfileio_read_once:1;
unsignedfileio_write_immediately:1;
+   unsignedallow_zero_bytesused:1;
 
struct mutex*lock;
struct v4l2_fh  *owner;
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 2/4] vb2: add allow_zero_bytesused flag to the vb2_queue struct

2015-02-19 Thread Hans Verkuil
On 02/19/15 11:11, Kamil Debski wrote:
> The vb2: fix bytesused == 0 handling (8a75ffb) patch changed the behavior
> of __fill_vb2_buffer function, so that if bytesused is 0 it is set to the
> size of the buffer. However, bytesused set to 0 is used by older codec
> drivers as as indication used to mark the end of stream.
> 
> To keep backward compatibility, this patch adds a flag passed to the
> vb2_queue_init function - allow_zero_bytesused. If the flag is set upon
> initialization of the queue, the videobuf2 keeps the value of bytesused
> intact in the OUTPUT queue and passes it to the driver.
> 
> Reported-by: Nicolas Dufresne 
> Signed-off-by: Kamil Debski 
> ---
>  drivers/media/v4l2-core/videobuf2-core.c |   29 +++--
>  include/media/videobuf2-core.h   |1 +
>  2 files changed, 24 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
> b/drivers/media/v4l2-core/videobuf2-core.c
> index 62531956..487e31f 100644
> --- a/drivers/media/v4l2-core/videobuf2-core.c
> +++ b/drivers/media/v4l2-core/videobuf2-core.c
> @@ -1276,13 +1276,22 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, 
> const struct v4l2_buffer *b
>* userspace clearly never bothered to set it and
>* it's a safe assumption that they really meant to
>* use the full plane sizes.
> +  *
> +  * Some drivers, e.g. old codec drivers, use bytesused
> +  * == 0 as a way to indicate that streaming is finished.
> +  * In that case, the driver should use the
> +  * allow_zero_bytesused flag to keep old userspace
> +  * applications working.
>*/
>   for (plane = 0; plane < vb->num_planes; ++plane) {
>   struct v4l2_plane *pdst = &v4l2_planes[plane];
>   struct v4l2_plane *psrc = &b->m.planes[plane];
>  
> - pdst->bytesused = psrc->bytesused ?
> - psrc->bytesused : pdst->length;
> + if (vb->vb2_queue->allow_zero_bytesused)
> + pdst->bytesused = psrc->bytesused;
> + else
> + pdst->bytesused = psrc->bytesused ?
> + psrc->bytesused : pdst->length;
>   pdst->data_offset = psrc->data_offset;
>   }
>   }
> @@ -1295,6 +1304,11 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, 
> const struct v4l2_buffer *b
>*
>* If bytesused == 0 for the output buffer, then fall back
>* to the full buffer size as that's a sensible default.
> +  *
> +  * Some drivers, e.g. old codec drivers, use bytesused * == 0 as
> +  * a way to indicate that streaming is finished. In that case,
> +  * the driver should use the allow_zero_bytesused flag to keep
> +  * old userspace applications working.
>*/
>   if (b->memory == V4L2_MEMORY_USERPTR) {
>   v4l2_planes[0].m.userptr = b->m.userptr;
> @@ -1306,10 +1320,13 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, 
> const struct v4l2_buffer *b
>   v4l2_planes[0].length = b->length;
>   }
>  
> - if (V4L2_TYPE_IS_OUTPUT(b->type))
> - v4l2_planes[0].bytesused = b->bytesused ?
> - b->bytesused : v4l2_planes[0].length;
> - else
> + if (V4L2_TYPE_IS_OUTPUT(b->type)) {
> + if (vb->vb2_queue->allow_zero_bytesused)
> + v4l2_planes[0].bytesused = b->bytesused;
> + else
> + v4l2_planes[0].bytesused = b->bytesused ?
> + b->bytesused : v4l2_planes[0].length;
> + } else
>   v4l2_planes[0].bytesused = 0;
>  
>   }
> diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
> index 1346693..50111bd573 100644
> --- a/include/media/videobuf2-core.h
> +++ b/include/media/videobuf2-core.h
> @@ -388,6 +388,7 @@ struct vb2_queue {
>   unsigned intio_modes;
>   unsignedfileio_read_once:1;
>   unsignedfileio_write_immediately:1;
> + unsignedallow_zero_bytesused:1;

Needs to be documentation in the struct vb2_queue comments.

Regards,

Hans

>  
>   struct mutex*lock;
>   struct v4l2_fh  *owner;
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a mes