Re: [PATCH v5 1/2] [media] v4l: Add source change event

2014-05-14 Thread Sylwester Nawrocki
Hi Arun,

On 14/05/14 08:59, Arun Kumar K wrote:
> This event indicates that the video device has encountered
> a source parameter change during runtime. This can typically be a
> resolution change detected by a video decoder OR a format change
> detected by an input connector.
> 
> This needs to be nofified to the userspace and the application may
> be expected to reallocate buffers before proceeding. The application
> can subscribe to events on a specific pad or input port which
> it is interested in.
> 
> Signed-off-by: Arun Kumar K 

This looks like a nice API enhancement.

Acked-by: Sylwester Nawrocki 

> ---
>  Documentation/DocBook/media/v4l/vidioc-dqevent.xml |   33 ++
>  .../DocBook/media/v4l/vidioc-subscribe-event.xml   |   20 +++
>  drivers/media/v4l2-core/v4l2-event.c   |   36 
> 
>  include/media/v4l2-event.h |4 +++
>  include/uapi/linux/videodev2.h |8 +
>  5 files changed, 101 insertions(+)
> 
> diff --git a/Documentation/DocBook/media/v4l/vidioc-dqevent.xml 
> b/Documentation/DocBook/media/v4l/vidioc-dqevent.xml
> index 89891ad..820f86e 100644
> --- a/Documentation/DocBook/media/v4l/vidioc-dqevent.xml
> +++ b/Documentation/DocBook/media/v4l/vidioc-dqevent.xml
> @@ -242,6 +242,22 @@
>
>  
>  
> +
> +  struct v4l2_event_src_change
> +  
> + &cs-str;
> + 
> +   
> + __u32
> + changes
> + 
> +   A bitmask that tells what has changed. See  linkend="src-changes-flags" />.
> + 
> +   
> + 
> +  
> +
> +
>  
>Changes
>
> @@ -270,6 +286,23 @@
>   
>
>  
> +
> +
> +  Source Changes
> +  
> + &cs-def;
> + 
> +   
> + V4L2_EVENT_SRC_CH_RESOLUTION
> + 0x0001
> + This event gets triggered when a resolution change is
> + detected at an input. This can come from an input connector or
> + from a video decoder.
> + 
> +   
> + 
> +  
> +
>
>
>  &return-value;
> diff --git a/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml 
> b/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
> index 5c70b61..f016254 100644
> --- a/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
> +++ b/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
> @@ -155,6 +155,26 @@
>   
> 
> 
> + V4L2_EVENT_SOURCE_CHANGE
> + 5
> + 
> +   This event is triggered when a source parameter change is
> +detected during runtime by the video device. It can be a
> +runtime resolution change triggered by a video decoder or the
> +format change happening on an input connector.
> +This event requires that the id
> +matches the input index (when used with a video device node)
> +or the pad index (when used with a subdevice node) from which
> +you want to receive events.
> +
> +  This event has a &v4l2-event-source-change; associated
> +   with it. The changes bitfield denotes
> +   what has changed for the subscribed pad. If multiple events
> +   occurred before application could dequeue them, then the changes
> +   will have the ORed value of all the events generated.
> + 
> +   
> +   
>   V4L2_EVENT_PRIVATE_START
>   0x0800
>   Base event number for driver-private events.
> diff --git a/drivers/media/v4l2-core/v4l2-event.c 
> b/drivers/media/v4l2-core/v4l2-event.c
> index 86dcb54..8761aab 100644
> --- a/drivers/media/v4l2-core/v4l2-event.c
> +++ b/drivers/media/v4l2-core/v4l2-event.c
> @@ -318,3 +318,39 @@ int v4l2_event_subdev_unsubscribe(struct v4l2_subdev 
> *sd, struct v4l2_fh *fh,
>   return v4l2_event_unsubscribe(fh, sub);
>  }
>  EXPORT_SYMBOL_GPL(v4l2_event_subdev_unsubscribe);
> +
> +static void v4l2_event_src_replace(struct v4l2_event *old,
> + const struct v4l2_event *new)
> +{
> + u32 old_changes = old->u.src_change.changes;
> +
> + old->u.src_change = new->u.src_change;
> + old->u.src_change.changes |= old_changes;
> +}
> +
> +static void v4l2_event_src_merge(const struct v4l2_event *old,
> + struct v4l2_event *new)
> +{
> + new->u.src_change.changes |= old->u.src_change.changes;
> +}
> +
> +static const struct v4l2_subscribed_event_ops v4l2_event_src_ch_ops = {
> + .replace = v4l2_event_src_replace,
> + .merge = v4l2_event_src_merge,
> +};
> +
> +int v4l2_src_change_event_subscribe(struct v4l2_fh *fh,
> + const struct v4l2_event_subscription *sub)
> +{
> + if (sub->type == V4L2_EVENT_SOURCE_CHANGE)
> + return v4l2_event_subscribe(fh, sub, 0, &v4l2_event_src_ch_ops);
> + return -EINVAL;
> +}
> +EXPORT_SYMBOL_GPL(v4l2_src_

[PATCH v5 1/2] [media] v4l: Add source change event

2014-05-14 Thread Arun Kumar K
This event indicates that the video device has encountered
a source parameter change during runtime. This can typically be a
resolution change detected by a video decoder OR a format change
detected by an input connector.

This needs to be nofified to the userspace and the application may
be expected to reallocate buffers before proceeding. The application
can subscribe to events on a specific pad or input port which
it is interested in.

Signed-off-by: Arun Kumar K 
---
 Documentation/DocBook/media/v4l/vidioc-dqevent.xml |   33 ++
 .../DocBook/media/v4l/vidioc-subscribe-event.xml   |   20 +++
 drivers/media/v4l2-core/v4l2-event.c   |   36 
 include/media/v4l2-event.h |4 +++
 include/uapi/linux/videodev2.h |8 +
 5 files changed, 101 insertions(+)

diff --git a/Documentation/DocBook/media/v4l/vidioc-dqevent.xml 
b/Documentation/DocBook/media/v4l/vidioc-dqevent.xml
index 89891ad..820f86e 100644
--- a/Documentation/DocBook/media/v4l/vidioc-dqevent.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-dqevent.xml
@@ -242,6 +242,22 @@
   
 
 
+
+  struct v4l2_event_src_change
+  
+   &cs-str;
+   
+ 
+   __u32
+   changes
+   
+ A bitmask that tells what has changed. See .
+   
+ 
+   
+  
+
+
 
   Changes
   
@@ -270,6 +286,23 @@

   
 
+
+
+  Source Changes
+  
+   &cs-def;
+   
+ 
+   V4L2_EVENT_SRC_CH_RESOLUTION
+   0x0001
+   This event gets triggered when a resolution change is
+   detected at an input. This can come from an input connector or
+   from a video decoder.
+   
+ 
+   
+  
+
   
   
 &return-value;
diff --git a/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml 
b/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
index 5c70b61..f016254 100644
--- a/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-subscribe-event.xml
@@ -155,6 +155,26 @@

  
  
+   V4L2_EVENT_SOURCE_CHANGE
+   5
+   
+ This event is triggered when a source parameter change is
+  detected during runtime by the video device. It can be a
+  runtime resolution change triggered by a video decoder or the
+  format change happening on an input connector.
+  This event requires that the id
+  matches the input index (when used with a video device node)
+  or the pad index (when used with a subdevice node) from which
+  you want to receive events.
+
+  This event has a &v4l2-event-source-change; associated
+ with it. The changes bitfield denotes
+ what has changed for the subscribed pad. If multiple events
+ occurred before application could dequeue them, then the changes
+ will have the ORed value of all the events generated.
+   
+ 
+ 
V4L2_EVENT_PRIVATE_START
0x0800
Base event number for driver-private events.
diff --git a/drivers/media/v4l2-core/v4l2-event.c 
b/drivers/media/v4l2-core/v4l2-event.c
index 86dcb54..8761aab 100644
--- a/drivers/media/v4l2-core/v4l2-event.c
+++ b/drivers/media/v4l2-core/v4l2-event.c
@@ -318,3 +318,39 @@ int v4l2_event_subdev_unsubscribe(struct v4l2_subdev *sd, 
struct v4l2_fh *fh,
return v4l2_event_unsubscribe(fh, sub);
 }
 EXPORT_SYMBOL_GPL(v4l2_event_subdev_unsubscribe);
+
+static void v4l2_event_src_replace(struct v4l2_event *old,
+   const struct v4l2_event *new)
+{
+   u32 old_changes = old->u.src_change.changes;
+
+   old->u.src_change = new->u.src_change;
+   old->u.src_change.changes |= old_changes;
+}
+
+static void v4l2_event_src_merge(const struct v4l2_event *old,
+   struct v4l2_event *new)
+{
+   new->u.src_change.changes |= old->u.src_change.changes;
+}
+
+static const struct v4l2_subscribed_event_ops v4l2_event_src_ch_ops = {
+   .replace = v4l2_event_src_replace,
+   .merge = v4l2_event_src_merge,
+};
+
+int v4l2_src_change_event_subscribe(struct v4l2_fh *fh,
+   const struct v4l2_event_subscription *sub)
+{
+   if (sub->type == V4L2_EVENT_SOURCE_CHANGE)
+   return v4l2_event_subscribe(fh, sub, 0, &v4l2_event_src_ch_ops);
+   return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(v4l2_src_change_event_subscribe);
+
+int v4l2_src_change_event_subdev_subscribe(struct v4l2_subdev *sd,
+   struct v4l2_fh *fh, struct v4l2_event_subscription *sub)
+{
+   return v4l2_src_change_event_subscribe(fh, sub);
+}
+EXPORT_SYMBOL_GPL(v4l2_src_change_event_subdev_subscribe);
diff --git a/include/media/v4l2