Skip to contentSkip to conversation

media add change_source handler support

PATCH New Shuah Khan 2 participants 6 messages Mar 10, 2016

Subsystems (2)
lore
Share & tools
lore

Shuah Khan

author
#0 lore raw

cover media add change_source handler support

This patch series:
1. Adds change_source function pointer to struct media_device. Using the change_source handler, driver can disable current source and enable new one in one step when user selects a new input.
2. Add a new common v4l interface to call change_source handler
3. Add change_source hanlder to au0828-core
4. Change change vidioc_s_input() to call v4l_change_media_source()

Shuah Khan (4):
media: add change_source handler function pointer
media: v4l2-mc add v4l_change_media_source() to invoke change_source
media: au0828 add media device change_source handler
media: au0828 change vidioc_s_input() to call
v4l_change_media_source()

 drivers/media/usb/au0828/au0828-core.c  | 64 +++++++++++++++++++++++----------
 drivers/media/usb/au0828/au0828-video.c |  8 ++---
 drivers/media/v4l2-core/v4l2-mc.c       | 14 ++++++++
 include/media/media-device.h            | 18 ++++++++--
 include/media/v4l2-mc.h                 | 20 ++++++++++-
 5 files changed, 97 insertions(+), 27 deletions(-)
Signature · 1 line
2.5.0
author
#1 lore raw

PATCH 1/4 media: add change_source handler function pointer

Add change_source handler function pointer to struct media_device. Using the change_source handler, driver can disable current source and enable new one in one step when user selects a new input.

---
 include/media/media-device.h | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
include/media/media-device.h +15 -3
index df74cfa..d9867ed 100644
@@ -309,9 +309,11 @@ struct media_entity_notify {
  * @pm_count_walk: Graph walk for power state walk. Access serialised using
  *		   graph_mutex.
  *
- * @source_priv: Driver Private data for enable/disable source handlers
+ * @source_priv: Driver Private data for enable/disable/change source
+ *		 handlers
  * @enable_source: Enable Source Handler function pointer
  * @disable_source: Disable Source Handler function pointer
+ * @change_source: Change Source Handler function pointer
  *
  * @link_notify: Link state change notification callback
  *
@@ -326,14 +328,22 @@ struct media_entity_notify {
  * be unique.
  *
  * @enable_source is a handler to find source entity for the
- * sink entity  and activate the link between them if source
+ * sink entity and activate the link between them if source
  * entity is free. Drivers should call this handler before
  * accessing the source.
  *
  * @disable_source is a handler to find source entity for the
- * sink entity  and deactivate the link between them. Drivers
+ * sink entity and deactivate the link between them. Drivers
  * should call this handler to release the source.
  *
+ * @change_source is a handler to find source entity for the
+ * sink entity and deactivate the link between them. Once the
+ * existing link is deactivated, it will find and activate the
+ * source for the sink for the newly selected input. Drivers
+ * should call this handler to change the source when user
+ * changes input. Using change_source helps not loose the hold
+ * on the media resource when a new input is selected.
+ *
  * Note: Bridge driver is expected to implement and set the
  * handler when media_device is registered or when
  * bridge driver finds the media_device during probe.
@@ -381,6 +391,8 @@ struct media_device {
 	int (*enable_source)(struct media_entity *entity,
 			     struct media_pipeline *pipe);
 	void (*disable_source)(struct media_entity *entity);
+	int (*change_source)(struct media_entity *entity,
+			     struct media_pipeline *pipe);
 
 	int (*link_notify)(struct media_link *link, u32 flags,
 			   unsigned int notification);
Signature · 1 line
2.5.0
author
#2 lore raw

PATCH 2/4 media: v4l2-mc add v4l_change_media_source() to invoke change_source

In reply to Shuah Khan

Add a common routine to invoke media device change_source handler.

---
 drivers/media/v4l2-core/v4l2-mc.c | 14 ++++++++++++++
 include/media/v4l2-mc.h           | 20 +++++++++++++++++++-
 2 files changed, 33 insertions(+), 1 deletion(-)
drivers/media/v4l2-core/v4l2-mc.c +14 -0
index ae661ac..478b2768 100644
@@ -217,6 +217,20 @@ void v4l_disable_media_source(struct video_device *vdev)
 }
 EXPORT_SYMBOL_GPL(v4l_disable_media_source);
 
+int v4l_change_media_source(struct video_device *vdev)
+{
+	struct media_device *mdev = vdev->entity.graph_obj.mdev;
+	int ret;
+
+	if (!mdev || !mdev->change_source)
+		return 0;
+	ret = mdev->change_source(&vdev->entity, &vdev->pipe);
+	if (ret)
+		return -EBUSY;
+	return 0;
+}
+EXPORT_SYMBOL_GPL(v4l_change_media_source);
+
 int v4l_vb2q_enable_media_source(struct vb2_queue *q)
 {
 	struct v4l2_fh *fh = q->owner;
include/media/v4l2-mc.h +19 -1
index 98a938a..884b969 100644
@@ -154,8 +154,26 @@ int v4l_enable_media_source(struct video_device *vdev);
  */
 void v4l_disable_media_source(struct video_device *vdev);
 
+/**
+ * v4l_change_media_source() -	Hold media source for exclusive use
+ *				if free
+ *
+ * @vdev:	pointer to struct video_device
+ *
+ * This interface calls change_source handler to change
+ * the current source it is holding. The change_source
+ * disables the current source and starts pipeline to
+ * the new source. This interface should be used when
+ * user changes source using s_input handler to keep
+ * the previously granted permission for exclusive use
+ * with a new input source.
+ *
+ * Return: returns zero on success or a negative error code.
+ */
+int v4l_change_media_source(struct video_device *vdev);
+
 /*
- * v4l_vb2q_enable_media_tuner -  Hold media source for exclusive use
+ * v4l_vb2q_enable_media_source - Hold media source for exclusive use
  *				  if free.
  * @q - pointer to struct vb2_queue
  *
Signature · 1 line
2.5.0
author
#3 lore raw

PATCH 3/4 media: au0828 add media device change_source handler

In reply to Shuah Khan

Add media device change_source handler. Using the change_source handler, driver can disable current source and enable new one in one step when user selects a new input.

---
 drivers/media/usb/au0828/au0828-core.c | 64 ++++++++++++++++++++++++----------
 1 file changed, 46 insertions(+), 18 deletions(-)
drivers/media/usb/au0828/au0828-core.c +46 -18
index 5dc82e8..01dba5a 100644
@@ -258,8 +258,8 @@ create_link:
 	}
 }
 
-static int au0828_enable_source(struct media_entity *entity,
-				struct media_pipeline *pipe)
+static int __au0828_enable_source(struct media_entity *entity,
+				  struct media_pipeline *pipe)
 {
 	struct media_entity  *source, *find_source;
 	struct media_entity *sink;
@@ -268,11 +268,6 @@ static int au0828_enable_source(struct media_entity *entity,
 	struct media_device *mdev = entity->graph_obj.mdev;
 	struct au0828_dev *dev;
 
-	if (!mdev)
-		return -ENODEV;
-
-	mutex_lock(&mdev->graph_mutex);
-
 	dev = mdev->source_priv;
 
 	/*
@@ -399,28 +394,36 @@ static int au0828_enable_source(struct media_entity *entity,
 		 dev->active_source->name, dev->active_sink->name,
 		 dev->active_link_owner->name, ret);
 end:
-	mutex_unlock(&mdev->graph_mutex);
 	pr_debug("au0828_enable_source() end %s %d %d\n",
 		 entity->name, entity->function, ret);
 	return ret;
 }
 
-static void au0828_disable_source(struct media_entity *entity)
+static int au0828_enable_source(struct media_entity *entity,
+				struct media_pipeline *pipe)
 {
-	int ret = 0;
 	struct media_device *mdev = entity->graph_obj.mdev;
-	struct au0828_dev *dev;
+	int ret;
 
 	if (!mdev)
-		return;
+		return -ENODEV;
 
 	mutex_lock(&mdev->graph_mutex);
+	ret = __au0828_enable_source(entity, pipe);
+	mutex_unlock(&mdev->graph_mutex);
+	return ret;
+}
+
+static void __au0828_disable_source(struct media_entity *entity)
+{
+	int ret = 0;
+	struct media_device *mdev = entity->graph_obj.mdev;
+	struct au0828_dev *dev;
+
 	dev = mdev->source_priv;
 
-	if (!dev->active_link) {
-		ret = -ENODEV;
-		goto end;
-	}
+	if (!dev->active_link)
+		return;
 
 	/* link is active - stop pipeline from source (tuner) */
 	if (dev->active_link->sink->entity == dev->active_sink &&
@@ -430,7 +433,7 @@ static void au0828_disable_source(struct media_entity *entity)
 		 * has active pipeline
 		*/
 		if (dev->active_link_owner != entity)
-			goto end;
+			return;
 		__media_entity_pipeline_stop(entity);
 		ret = __media_entity_setup_link(dev->active_link, 0);
 		if (ret)
@@ -445,10 +448,34 @@ static void au0828_disable_source(struct media_entity *entity)
 		dev->active_source = NULL;
 		dev->active_sink = NULL;
 	}
+}
 
-end:
+static void au0828_disable_source(struct media_entity *entity)
+{
+	struct media_device *mdev = entity->graph_obj.mdev;
+
+	if (!mdev)
+		return;
+
+	mutex_lock(&mdev->graph_mutex);
+	__au0828_disable_source(entity);
 	mutex_unlock(&mdev->graph_mutex);
 }
+static int au0828_change_source(struct media_entity *entity,
+				struct media_pipeline *pipe)
+{
+	struct media_device *mdev = entity->graph_obj.mdev;
+	int ret;
+
+	if (!mdev)
+		return -ENODEV;
+
+	mutex_lock(&mdev->graph_mutex);
+	__au0828_disable_source(entity);
+	ret = __au0828_enable_source(entity, pipe);
+	mutex_unlock(&mdev->graph_mutex);
+	return ret;
+}
 #endif
 
 static int au0828_media_device_register(struct au0828_dev *dev,
@@ -520,6 +547,7 @@ static int au0828_media_device_register(struct au0828_dev *dev,
 	dev->media_dev->source_priv = (void *) dev;
 	dev->media_dev->enable_source = au0828_enable_source;
 	dev->media_dev->disable_source = au0828_disable_source;
+	dev->media_dev->change_source = au0828_change_source;
 #endif
 	return 0;
 }
Signature · 1 line
2.5.0
author
#4 lore raw

PATCH 4/4 media: au0828 change vidioc_s_input() to call v4l_change_media_source()

In reply to Shuah Khan

Change vidioc_s_input() to call v4l_change_media_source() to disable current source and enable new source when user switches input.

---
 drivers/media/usb/au0828/au0828-video.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/media/usb/au0828/au0828-video.c +3 -5
index aeaf27e..020c9d5 100644
@@ -1545,12 +1545,10 @@ static int vidioc_s_input(struct file *file, void *priv, unsigned int index)
 	au0828_s_input(dev, index);
 
 	/*
-	 * Input has been changed. Disable the media source
-	 * associated with the old input and enable source
-	 * for the newly set input
+	 * Input has been changed. Change to media source
+	 * associated with the for the newly set input.
 	 */
-	v4l_disable_media_source(vfd);
-	return v4l_enable_media_source(vfd);
+	return v4l_change_media_source(vfd);
 }
 
 static int vidioc_enumaudio(struct file *file, void *priv, struct v4l2_audio *a)
Signature · 1 line
2.5.0
#5 lore raw

Re: [PATCH 4/4] media: au0828 change vidioc_s_input() to call v4l_change_media_source()

reproduce:

Hi Shuah,

[auto build test ERROR on sailus-media/master]
[cannot apply to v4.5-rc7 next-20160309]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]

url:    https://github.com/0day-ci/linux/commits/Shuah-Khan/media-add-change_source-handler-support/20160310-131140
base:   git://linuxtv.org/media_tree.git master
config: x86_64-rhel (attached as .config)
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All errors (new ones prefixed by >>):

drivers/media/usb/au0828/au0828-video.c: In function 'vidioc_s_input':

>> drivers/media/usb/au0828/au0828-video.c:1474:2: error: implicit declaration of function 'v4l_change_media_source' [-Werror=implicit-function-declaration]
     return v4l_change_media_source(vfd);
     ^

cc1: some warnings being treated as errors

vim +/v4l_change_media_source +1474 drivers/media/usb/au0828/au0828-video.c

1468 au0828_s_input(dev, index);
1469
1470 /*
1471 * Input has been changed. Change to media source
1472 * associated with the for the newly set input.
1473 */

> 1474		return v4l_change_media_source(vfd);

1475 }
1476
1477 static int vidioc_enumaudio(struct file *file, void *priv, struct v4l2_audio *a)

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation