* [PATCH 1/2] [media] v4l2-mc: add a generic function to create the media graph
@ 2016-02-05 9:51 Mauro Carvalho Chehab
2016-02-05 9:51 ` [PATCH 2/2] [media] em2xx: use v4l2_mc_create_media_graph() Mauro Carvalho Chehab
2016-02-05 14:25 ` [PATCH 1/2] [media] v4l2-mc: add a generic function to create the media graph Shuah Khan
0 siblings, 2 replies; 4+ messages in thread
From: Mauro Carvalho Chehab @ 2016-02-05 9:51 UTC (permalink / raw)
Cc: Mauro Carvalho Chehab, Linux Media Mailing List,
Mauro Carvalho Chehab, Hans Verkuil, Seung-Woo Kim, Junghak Sung,
Geunyoung Kim, Jacek Anaszewski, Philipp Zabel
The em28xx_v4l2_create_media_graph() is almost generic enough to
be at the core, as an ancillary function. Make it even more generic,
by getting rid of em28xx-specific code, relying only at the
media_device, in order to discover all entities found on PC-customer's
hardware and add it at the V4L2 core.
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
---
drivers/media/v4l2-core/Makefile | 1 +
drivers/media/v4l2-core/v4l2-mc.c | 181 ++++++++++++++++++++++++++++++++++++++
include/media/v4l2-mc.h | 24 +++++
3 files changed, 206 insertions(+)
create mode 100644 drivers/media/v4l2-core/v4l2-mc.c
diff --git a/drivers/media/v4l2-core/Makefile b/drivers/media/v4l2-core/Makefile
index 1dc8bba2b198..795a5352761d 100644
--- a/drivers/media/v4l2-core/Makefile
+++ b/drivers/media/v4l2-core/Makefile
@@ -16,6 +16,7 @@ endif
ifeq ($(CONFIG_TRACEPOINTS),y)
videodev-objs += vb2-trace.o v4l2-trace.o
endif
+videodev-$(CONFIG_MEDIA_CONTROLLER) += v4l2-mc.o
obj-$(CONFIG_VIDEO_V4L2) += videodev.o
obj-$(CONFIG_VIDEO_V4L2) += v4l2-common.o
diff --git a/drivers/media/v4l2-core/v4l2-mc.c b/drivers/media/v4l2-core/v4l2-mc.c
new file mode 100644
index 000000000000..7276dbbbe830
--- /dev/null
+++ b/drivers/media/v4l2-core/v4l2-mc.c
@@ -0,0 +1,181 @@
+/*
+ * Media Controller ancillary functions
+ *
+ * (c) 2016 Mauro Carvalho Chehab <mchehab@osg.samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/module.h>
+#include <media/media-entity.h>
+#include <media/v4l2-mc.h>
+
+int v4l2_mc_create_media_graph(struct media_device *mdev)
+
+{
+ struct media_entity *entity;
+ struct media_entity *if_vid = NULL, *if_aud = NULL, *sensor = NULL;
+ struct media_entity *tuner = NULL, *decoder = NULL;
+ struct media_entity *io_v4l = NULL, *io_vbi = NULL, *io_swradio = NULL;
+ bool is_webcam = false;
+ int ret;
+
+ if (!mdev)
+ return 0;
+
+ media_device_for_each_entity(entity, mdev) {
+ switch (entity->function) {
+ case MEDIA_ENT_F_IF_VID_DECODER:
+ if_vid = entity;
+ break;
+ case MEDIA_ENT_F_IF_AUD_DECODER:
+ if_aud = entity;
+ break;
+ case MEDIA_ENT_F_TUNER:
+ tuner = entity;
+ break;
+ case MEDIA_ENT_F_ATV_DECODER:
+ decoder = entity;
+ break;
+ case MEDIA_ENT_F_IO_V4L:
+ io_v4l = entity;
+ break;
+ case MEDIA_ENT_F_IO_VBI:
+ io_vbi = entity;
+ break;
+ case MEDIA_ENT_F_IO_SWRADIO:
+ io_swradio = entity;
+ break;
+ case MEDIA_ENT_F_CAM_SENSOR:
+ sensor = entity;
+ is_webcam = true;
+ break;
+ }
+ }
+
+ /* It should have at least one I/O entity */
+ if (!io_v4l && !io_vbi && !io_swradio)
+ return -EINVAL;
+
+ /*
+ * Here, webcams are modeled on a very simple way: the sensor is
+ * connected directly to the I/O entity. All dirty details, like
+ * scaler and crop HW are hidden. While such mapping is not enough
+ * for mc-centric hardware, it is enough for v4l2 interface centric
+ * PC-consumer's hardware.
+ */
+ if (is_webcam) {
+ if (!io_v4l)
+ return -EINVAL;
+
+ media_device_for_each_entity(entity, mdev) {
+ if (entity->function != MEDIA_ENT_F_CAM_SENSOR)
+ continue;
+ ret = media_create_pad_link(entity, 0,
+ io_v4l, 0,
+ MEDIA_LNK_FL_ENABLED);
+ if (ret)
+ return ret;
+ }
+ if (!decoder)
+ return 0;
+ }
+
+ /* The device isn't a webcam. So, it should have a decoder */
+ if (!decoder)
+ return -EINVAL;
+
+ /* Link the tuner and IF video output pads */
+ if (tuner) {
+ if (if_vid) {
+ ret = media_create_pad_link(tuner, TUNER_PAD_OUTPUT,
+ if_vid,
+ IF_VID_DEC_PAD_IF_INPUT,
+ MEDIA_LNK_FL_ENABLED);
+ if (ret)
+ return ret;
+ ret = media_create_pad_link(if_vid, IF_VID_DEC_PAD_OUT,
+ decoder, DEMOD_PAD_IF_INPUT,
+ MEDIA_LNK_FL_ENABLED);
+ if (ret)
+ return ret;
+ } else {
+ ret = media_create_pad_link(tuner, TUNER_PAD_OUTPUT,
+ decoder, DEMOD_PAD_IF_INPUT,
+ MEDIA_LNK_FL_ENABLED);
+ if (ret)
+ return ret;
+ }
+
+ if (if_aud) {
+ ret = media_create_pad_link(tuner, TUNER_PAD_AUD_OUT,
+ if_aud,
+ IF_AUD_DEC_PAD_IF_INPUT,
+ MEDIA_LNK_FL_ENABLED);
+ if (ret)
+ return ret;
+ } else {
+ if_aud = tuner;
+ }
+
+ }
+
+ /* Create demod to V4L, VBI and SDR radio links */
+ if (io_v4l) {
+ ret = media_create_pad_link(decoder, DEMOD_PAD_VID_OUT,
+ io_v4l, 0,
+ MEDIA_LNK_FL_ENABLED);
+ if (ret)
+ return ret;
+ }
+
+ if (io_swradio) {
+ ret = media_create_pad_link(decoder, DEMOD_PAD_VID_OUT,
+ io_swradio, 0,
+ MEDIA_LNK_FL_ENABLED);
+ if (ret)
+ return ret;
+ }
+
+ if (io_vbi) {
+ ret = media_create_pad_link(decoder, DEMOD_PAD_VBI_OUT,
+ io_vbi, 0,
+ MEDIA_LNK_FL_ENABLED);
+ if (ret)
+ return ret;
+ }
+
+ /* Create links for the media connectors */
+ media_device_for_each_entity(entity, mdev) {
+ switch (entity->function) {
+ case MEDIA_ENT_F_CONN_RF:
+ if (!tuner)
+ continue;
+
+ ret = media_create_pad_link(entity, 0, tuner,
+ TUNER_PAD_RF_INPUT,
+ MEDIA_LNK_FL_ENABLED);
+ break;
+ case MEDIA_ENT_F_CONN_SVIDEO:
+ case MEDIA_ENT_F_CONN_COMPOSITE:
+ case MEDIA_ENT_F_CONN_TEST:
+ ret = media_create_pad_link(entity, 0, decoder,
+ DEMOD_PAD_IF_INPUT, 0);
+ break;
+ default:
+ continue;
+ }
+ if (ret)
+ return ret;
+ }
+ return 0;
+}
+EXPORT_SYMBOL_GPL(v4l2_mc_create_media_graph);
diff --git a/include/media/v4l2-mc.h b/include/media/v4l2-mc.h
index df115195690e..3097493e6cf1 100644
--- a/include/media/v4l2-mc.h
+++ b/include/media/v4l2-mc.h
@@ -14,6 +14,8 @@
* GNU General Public License for more details.
*/
+#include <media/media-device.h>
+
/**
* enum tuner_pad_index - tuner pad index for MEDIA_ENT_F_TUNER
*
@@ -89,3 +91,25 @@ enum demod_pad_index {
DEMOD_PAD_VBI_OUT,
DEMOD_NUM_PADS
};
+
+/**
+ * v4l2_mc_create_media_graph() - create Media Controller links at the graph.
+ *
+ * @mdev: pointer to the &media_device struct.
+ *
+ * Add links between the entities commonly found on PC customer's hardware at
+ * the V4L2 side: camera sensors, audio and video PLL-IF decoders, tuners,
+ * analog TV decoder and I/O entities (video, VBI and Software Defined Radio).
+ * NOTE: webcams are modeled on a very simple way: the sensor is
+ * connected directly to the I/O entity. All dirty details, like
+ * scaler and crop HW are hidden. While such mapping is enough for v4l2
+ * interface centric PC-consumer's hardware, V4L2 subdev centric camera
+ * hardware should not use this routine, as it will not build the right graph.
+ */
+#ifdef CONFIG_MEDIA_CONTROLLER
+int v4l2_mc_create_media_graph(struct media_device *mdev);
+#else
+static inline int v4l2_mc_create_media_graph(struct media_device *mdev) {
+ return 0;
+}
+#endif
--
2.5.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] [media] em2xx: use v4l2_mc_create_media_graph()
2016-02-05 9:51 [PATCH 1/2] [media] v4l2-mc: add a generic function to create the media graph Mauro Carvalho Chehab
@ 2016-02-05 9:51 ` Mauro Carvalho Chehab
2016-02-05 14:25 ` [PATCH 1/2] [media] v4l2-mc: add a generic function to create the media graph Shuah Khan
1 sibling, 0 replies; 4+ messages in thread
From: Mauro Carvalho Chehab @ 2016-02-05 9:51 UTC (permalink / raw)
Cc: Mauro Carvalho Chehab, Linux Media Mailing List, Mauro Carvalho Chehab
Now that the core has a function to create the media graph,
we can get rid of the specialized code at em28xx.
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
---
drivers/media/usb/em28xx/em28xx-video.c | 131 +-------------------------------
1 file changed, 1 insertion(+), 130 deletions(-)
diff --git a/drivers/media/usb/em28xx/em28xx-video.c b/drivers/media/usb/em28xx/em28xx-video.c
index 16a2d4039330..e7fd0bac4a08 100644
--- a/drivers/media/usb/em28xx/em28xx-video.c
+++ b/drivers/media/usb/em28xx/em28xx-video.c
@@ -883,135 +883,6 @@ static void em28xx_v4l2_media_release(struct em28xx *dev)
* Media Controller helper functions
*/
-static int em28xx_v4l2_create_media_graph(struct em28xx *dev)
-{
-#ifdef CONFIG_MEDIA_CONTROLLER
- struct em28xx_v4l2 *v4l2 = dev->v4l2;
- struct media_device *mdev = dev->media_dev;
- struct media_entity *entity;
- struct media_entity *if_vid = NULL, *if_aud = NULL;
- struct media_entity *tuner = NULL, *decoder = NULL;
- int i, ret;
-
- if (!mdev)
- return 0;
-
- /* Webcams are really simple */
- if (dev->board.is_webcam) {
- media_device_for_each_entity(entity, mdev) {
- if (entity->function != MEDIA_ENT_F_CAM_SENSOR)
- continue;
- ret = media_create_pad_link(entity, 0,
- &v4l2->vdev.entity, 0,
- MEDIA_LNK_FL_ENABLED);
- if (ret)
- return ret;
- }
- return 0;
- }
-
- /* Non-webcams have analog TV decoder and other complexities */
-
- media_device_for_each_entity(entity, mdev) {
- switch (entity->function) {
- case MEDIA_ENT_F_IF_VID_DECODER:
- if_vid = entity;
- break;
- case MEDIA_ENT_F_IF_AUD_DECODER:
- if_aud = entity;
- break;
- case MEDIA_ENT_F_TUNER:
- tuner = entity;
- break;
- case MEDIA_ENT_F_ATV_DECODER:
- decoder = entity;
- break;
- }
- }
-
- /* Analog setup, using tuner as a link */
-
- /* Something bad happened! */
- if (!decoder)
- return -EINVAL;
-
- if (tuner) {
- if (if_vid) {
- ret = media_create_pad_link(tuner, TUNER_PAD_OUTPUT,
- if_vid,
- IF_VID_DEC_PAD_IF_INPUT,
- MEDIA_LNK_FL_ENABLED);
- if (ret)
- return ret;
- ret = media_create_pad_link(if_vid, IF_VID_DEC_PAD_OUT,
- decoder, DEMOD_PAD_IF_INPUT,
- MEDIA_LNK_FL_ENABLED);
- if (ret)
- return ret;
- } else {
- ret = media_create_pad_link(tuner, TUNER_PAD_OUTPUT,
- decoder, DEMOD_PAD_IF_INPUT,
- MEDIA_LNK_FL_ENABLED);
- if (ret)
- return ret;
- }
-
- if (if_aud) {
- ret = media_create_pad_link(tuner, TUNER_PAD_AUD_OUT,
- if_aud,
- IF_AUD_DEC_PAD_IF_INPUT,
- MEDIA_LNK_FL_ENABLED);
- if (ret)
- return ret;
- } else {
- if_aud = tuner;
- }
-
- }
- ret = media_create_pad_link(decoder, DEMOD_PAD_VID_OUT,
- &v4l2->vdev.entity, 0,
- MEDIA_LNK_FL_ENABLED);
- if (ret)
- return ret;
-
- if (em28xx_vbi_supported(dev)) {
- ret = media_create_pad_link(decoder, DEMOD_PAD_VBI_OUT,
- &v4l2->vbi_dev.entity, 0,
- MEDIA_LNK_FL_ENABLED);
- if (ret)
- return ret;
- }
-
- for (i = 0; i < MAX_EM28XX_INPUT; i++) {
- struct media_entity *ent = &dev->input_ent[i];
-
- if (!INPUT(i)->type)
- break;
-
- switch (INPUT(i)->type) {
- case EM28XX_VMUX_COMPOSITE:
- case EM28XX_VMUX_SVIDEO:
- ret = media_create_pad_link(ent, 0, decoder,
- DEMOD_PAD_IF_INPUT, 0);
- if (ret)
- return ret;
- break;
- default: /* EM28XX_VMUX_TELEVISION or EM28XX_RADIO */
- if (!tuner)
- break;
-
- ret = media_create_pad_link(ent, 0, tuner,
- TUNER_PAD_RF_INPUT,
- MEDIA_LNK_FL_ENABLED);
- if (ret)
- return ret;
- break;
- }
- }
-#endif
- return 0;
-}
-
static int em28xx_enable_analog_tuner(struct em28xx *dev)
{
#ifdef CONFIG_MEDIA_CONTROLLER
@@ -2842,7 +2713,7 @@ static int em28xx_v4l2_init(struct em28xx *dev)
/* Init entities at the Media Controller */
em28xx_v4l2_create_entities(dev);
- ret = em28xx_v4l2_create_media_graph(dev);
+ ret = v4l2_mc_create_media_graph(dev->media_dev);
if (ret) {
em28xx_errdev("failed to create media graph\n");
em28xx_v4l2_media_release(dev);
--
2.5.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] [media] v4l2-mc: add a generic function to create the media graph
2016-02-05 9:51 [PATCH 1/2] [media] v4l2-mc: add a generic function to create the media graph Mauro Carvalho Chehab
2016-02-05 9:51 ` [PATCH 2/2] [media] em2xx: use v4l2_mc_create_media_graph() Mauro Carvalho Chehab
@ 2016-02-05 14:25 ` Shuah Khan
2016-02-05 15:36 ` Mauro Carvalho Chehab
1 sibling, 1 reply; 4+ messages in thread
From: Shuah Khan @ 2016-02-05 14:25 UTC (permalink / raw)
To: Mauro Carvalho Chehab
Cc: Linux Media Mailing List, Mauro Carvalho Chehab, Hans Verkuil,
Seung-Woo Kim, Junghak Sung, Geunyoung Kim, Jacek Anaszewski,
Philipp Zabel, Shuah Khan
On 02/05/2016 02:51 AM, Mauro Carvalho Chehab wrote:
> The em28xx_v4l2_create_media_graph() is almost generic enough to
> be at the core, as an ancillary function. Make it even more generic,
> by getting rid of em28xx-specific code, relying only at the
> media_device, in order to discover all entities found on PC-customer's
> hardware and add it at the V4L2 core.
>
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> ---
> drivers/media/v4l2-core/Makefile | 1 +
> drivers/media/v4l2-core/v4l2-mc.c | 181 ++++++++++++++++++++++++++++++++++++++
> include/media/v4l2-mc.h | 24 +++++
> 3 files changed, 206 insertions(+)
> create mode 100644 drivers/media/v4l2-core/v4l2-mc.c
Hi Mauro,
The following patch I sent a couple of days ago creates
this file rivers/media/v4l2-core/v4l2-mc.c
You had some minor comments on that patch and I am working
on addressing them.
[PATCH v2 07/22] media: v4l-core add enable/disable source common interfaces
https://lkml.org/lkml/2016/2/3/1500
Looks like you added it in your patch. This would lead a conflict
between our patches. How do you propose to resolve this?
thanks,
-- Shuah
>
> diff --git a/drivers/media/v4l2-core/Makefile b/drivers/media/v4l2-core/Makefile
> index 1dc8bba2b198..795a5352761d 100644
> --- a/drivers/media/v4l2-core/Makefile
> +++ b/drivers/media/v4l2-core/Makefile
> @@ -16,6 +16,7 @@ endif
> ifeq ($(CONFIG_TRACEPOINTS),y)
> videodev-objs += vb2-trace.o v4l2-trace.o
> endif
> +videodev-$(CONFIG_MEDIA_CONTROLLER) += v4l2-mc.o
>
> obj-$(CONFIG_VIDEO_V4L2) += videodev.o
> obj-$(CONFIG_VIDEO_V4L2) += v4l2-common.o
> diff --git a/drivers/media/v4l2-core/v4l2-mc.c b/drivers/media/v4l2-core/v4l2-mc.c
> new file mode 100644
> index 000000000000..7276dbbbe830
> --- /dev/null
> +++ b/drivers/media/v4l2-core/v4l2-mc.c
> @@ -0,0 +1,181 @@
> +/*
> + * Media Controller ancillary functions
> + *
> + * (c) 2016 Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + */
> +
> +#include <linux/module.h>
> +#include <media/media-entity.h>
> +#include <media/v4l2-mc.h>
> +
> +int v4l2_mc_create_media_graph(struct media_device *mdev)
> +
> +{
> + struct media_entity *entity;
> + struct media_entity *if_vid = NULL, *if_aud = NULL, *sensor = NULL;
> + struct media_entity *tuner = NULL, *decoder = NULL;
> + struct media_entity *io_v4l = NULL, *io_vbi = NULL, *io_swradio = NULL;
> + bool is_webcam = false;
> + int ret;
> +
> + if (!mdev)
> + return 0;
> +
> + media_device_for_each_entity(entity, mdev) {
> + switch (entity->function) {
> + case MEDIA_ENT_F_IF_VID_DECODER:
> + if_vid = entity;
> + break;
> + case MEDIA_ENT_F_IF_AUD_DECODER:
> + if_aud = entity;
> + break;
> + case MEDIA_ENT_F_TUNER:
> + tuner = entity;
> + break;
> + case MEDIA_ENT_F_ATV_DECODER:
> + decoder = entity;
> + break;
> + case MEDIA_ENT_F_IO_V4L:
> + io_v4l = entity;
> + break;
> + case MEDIA_ENT_F_IO_VBI:
> + io_vbi = entity;
> + break;
> + case MEDIA_ENT_F_IO_SWRADIO:
> + io_swradio = entity;
> + break;
> + case MEDIA_ENT_F_CAM_SENSOR:
> + sensor = entity;
> + is_webcam = true;
> + break;
> + }
> + }
> +
> + /* It should have at least one I/O entity */
> + if (!io_v4l && !io_vbi && !io_swradio)
> + return -EINVAL;
> +
> + /*
> + * Here, webcams are modeled on a very simple way: the sensor is
> + * connected directly to the I/O entity. All dirty details, like
> + * scaler and crop HW are hidden. While such mapping is not enough
> + * for mc-centric hardware, it is enough for v4l2 interface centric
> + * PC-consumer's hardware.
> + */
> + if (is_webcam) {
> + if (!io_v4l)
> + return -EINVAL;
> +
> + media_device_for_each_entity(entity, mdev) {
> + if (entity->function != MEDIA_ENT_F_CAM_SENSOR)
> + continue;
> + ret = media_create_pad_link(entity, 0,
> + io_v4l, 0,
> + MEDIA_LNK_FL_ENABLED);
> + if (ret)
> + return ret;
> + }
> + if (!decoder)
> + return 0;
> + }
> +
> + /* The device isn't a webcam. So, it should have a decoder */
> + if (!decoder)
> + return -EINVAL;
> +
> + /* Link the tuner and IF video output pads */
> + if (tuner) {
> + if (if_vid) {
> + ret = media_create_pad_link(tuner, TUNER_PAD_OUTPUT,
> + if_vid,
> + IF_VID_DEC_PAD_IF_INPUT,
> + MEDIA_LNK_FL_ENABLED);
> + if (ret)
> + return ret;
> + ret = media_create_pad_link(if_vid, IF_VID_DEC_PAD_OUT,
> + decoder, DEMOD_PAD_IF_INPUT,
> + MEDIA_LNK_FL_ENABLED);
> + if (ret)
> + return ret;
> + } else {
> + ret = media_create_pad_link(tuner, TUNER_PAD_OUTPUT,
> + decoder, DEMOD_PAD_IF_INPUT,
> + MEDIA_LNK_FL_ENABLED);
> + if (ret)
> + return ret;
> + }
> +
> + if (if_aud) {
> + ret = media_create_pad_link(tuner, TUNER_PAD_AUD_OUT,
> + if_aud,
> + IF_AUD_DEC_PAD_IF_INPUT,
> + MEDIA_LNK_FL_ENABLED);
> + if (ret)
> + return ret;
> + } else {
> + if_aud = tuner;
> + }
> +
> + }
> +
> + /* Create demod to V4L, VBI and SDR radio links */
> + if (io_v4l) {
> + ret = media_create_pad_link(decoder, DEMOD_PAD_VID_OUT,
> + io_v4l, 0,
> + MEDIA_LNK_FL_ENABLED);
> + if (ret)
> + return ret;
> + }
> +
> + if (io_swradio) {
> + ret = media_create_pad_link(decoder, DEMOD_PAD_VID_OUT,
> + io_swradio, 0,
> + MEDIA_LNK_FL_ENABLED);
> + if (ret)
> + return ret;
> + }
> +
> + if (io_vbi) {
> + ret = media_create_pad_link(decoder, DEMOD_PAD_VBI_OUT,
> + io_vbi, 0,
> + MEDIA_LNK_FL_ENABLED);
> + if (ret)
> + return ret;
> + }
> +
> + /* Create links for the media connectors */
> + media_device_for_each_entity(entity, mdev) {
> + switch (entity->function) {
> + case MEDIA_ENT_F_CONN_RF:
> + if (!tuner)
> + continue;
> +
> + ret = media_create_pad_link(entity, 0, tuner,
> + TUNER_PAD_RF_INPUT,
> + MEDIA_LNK_FL_ENABLED);
> + break;
> + case MEDIA_ENT_F_CONN_SVIDEO:
> + case MEDIA_ENT_F_CONN_COMPOSITE:
> + case MEDIA_ENT_F_CONN_TEST:
> + ret = media_create_pad_link(entity, 0, decoder,
> + DEMOD_PAD_IF_INPUT, 0);
> + break;
> + default:
> + continue;
> + }
> + if (ret)
> + return ret;
> + }
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(v4l2_mc_create_media_graph);
> diff --git a/include/media/v4l2-mc.h b/include/media/v4l2-mc.h
> index df115195690e..3097493e6cf1 100644
> --- a/include/media/v4l2-mc.h
> +++ b/include/media/v4l2-mc.h
> @@ -14,6 +14,8 @@
> * GNU General Public License for more details.
> */
>
> +#include <media/media-device.h>
> +
> /**
> * enum tuner_pad_index - tuner pad index for MEDIA_ENT_F_TUNER
> *
> @@ -89,3 +91,25 @@ enum demod_pad_index {
> DEMOD_PAD_VBI_OUT,
> DEMOD_NUM_PADS
> };
> +
> +/**
> + * v4l2_mc_create_media_graph() - create Media Controller links at the graph.
> + *
> + * @mdev: pointer to the &media_device struct.
> + *
> + * Add links between the entities commonly found on PC customer's hardware at
> + * the V4L2 side: camera sensors, audio and video PLL-IF decoders, tuners,
> + * analog TV decoder and I/O entities (video, VBI and Software Defined Radio).
> + * NOTE: webcams are modeled on a very simple way: the sensor is
> + * connected directly to the I/O entity. All dirty details, like
> + * scaler and crop HW are hidden. While such mapping is enough for v4l2
> + * interface centric PC-consumer's hardware, V4L2 subdev centric camera
> + * hardware should not use this routine, as it will not build the right graph.
> + */
> +#ifdef CONFIG_MEDIA_CONTROLLER
> +int v4l2_mc_create_media_graph(struct media_device *mdev);
> +#else
> +static inline int v4l2_mc_create_media_graph(struct media_device *mdev) {
> + return 0;
> +}
> +#endif
>
--
Shuah Khan
Sr. Linux Kernel Developer
Open Source Innovation Group
Samsung Research America (Silicon Valley)
shuahkh@osg.samsung.com | (970) 217-8978
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] [media] v4l2-mc: add a generic function to create the media graph
2016-02-05 14:25 ` [PATCH 1/2] [media] v4l2-mc: add a generic function to create the media graph Shuah Khan
@ 2016-02-05 15:36 ` Mauro Carvalho Chehab
0 siblings, 0 replies; 4+ messages in thread
From: Mauro Carvalho Chehab @ 2016-02-05 15:36 UTC (permalink / raw)
To: Shuah Khan
Cc: Linux Media Mailing List, Mauro Carvalho Chehab, Hans Verkuil,
Seung-Woo Kim, Junghak Sung, Geunyoung Kim, Jacek Anaszewski,
Philipp Zabel
Em Fri, 05 Feb 2016 07:25:29 -0700
Shuah Khan <shuahkh@osg.samsung.com> escreveu:
> On 02/05/2016 02:51 AM, Mauro Carvalho Chehab wrote:
> > The em28xx_v4l2_create_media_graph() is almost generic enough to
> > be at the core, as an ancillary function. Make it even more generic,
> > by getting rid of em28xx-specific code, relying only at the
> > media_device, in order to discover all entities found on PC-customer's
> > hardware and add it at the V4L2 core.
> >
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > ---
> > drivers/media/v4l2-core/Makefile | 1 +
> > drivers/media/v4l2-core/v4l2-mc.c | 181 ++++++++++++++++++++++++++++++++++++++
> > include/media/v4l2-mc.h | 24 +++++
> > 3 files changed, 206 insertions(+)
> > create mode 100644 drivers/media/v4l2-core/v4l2-mc.c
>
>
> Hi Mauro,
>
> The following patch I sent a couple of days ago creates
> this file rivers/media/v4l2-core/v4l2-mc.c
>
> You had some minor comments on that patch and I am working
> on addressing them.
>
> [PATCH v2 07/22] media: v4l-core add enable/disable source common interfaces
> https://lkml.org/lkml/2016/2/3/1500
>
> Looks like you added it in your patch. This would lead a conflict
> between our patches. How do you propose to resolve this?
Don't worry with that. As it is just line additions, such conflict is
easily handle. No need to rebase.
>
> thanks,
> -- Shuah
>
>
> >
> > diff --git a/drivers/media/v4l2-core/Makefile b/drivers/media/v4l2-core/Makefile
> > index 1dc8bba2b198..795a5352761d 100644
> > --- a/drivers/media/v4l2-core/Makefile
> > +++ b/drivers/media/v4l2-core/Makefile
> > @@ -16,6 +16,7 @@ endif
> > ifeq ($(CONFIG_TRACEPOINTS),y)
> > videodev-objs += vb2-trace.o v4l2-trace.o
> > endif
> > +videodev-$(CONFIG_MEDIA_CONTROLLER) += v4l2-mc.o
> >
> > obj-$(CONFIG_VIDEO_V4L2) += videodev.o
> > obj-$(CONFIG_VIDEO_V4L2) += v4l2-common.o
> > diff --git a/drivers/media/v4l2-core/v4l2-mc.c b/drivers/media/v4l2-core/v4l2-mc.c
> > new file mode 100644
> > index 000000000000..7276dbbbe830
> > --- /dev/null
> > +++ b/drivers/media/v4l2-core/v4l2-mc.c
> > @@ -0,0 +1,181 @@
> > +/*
> > + * Media Controller ancillary functions
> > + *
> > + * (c) 2016 Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > + *
> > + * This program is free software; you can redistribute it and/or modify
> > + * it under the terms of the GNU General Public License as published by
> > + * the Free Software Foundation; either version 2 of the License, or
> > + * (at your option) any later version.
> > + *
> > + * This program is distributed in the hope that it will be useful,
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> > + * GNU General Public License for more details.
> > + */
> > +
> > +#include <linux/module.h>
> > +#include <media/media-entity.h>
> > +#include <media/v4l2-mc.h>
> > +
> > +int v4l2_mc_create_media_graph(struct media_device *mdev)
> > +
> > +{
> > + struct media_entity *entity;
> > + struct media_entity *if_vid = NULL, *if_aud = NULL, *sensor = NULL;
> > + struct media_entity *tuner = NULL, *decoder = NULL;
> > + struct media_entity *io_v4l = NULL, *io_vbi = NULL, *io_swradio = NULL;
> > + bool is_webcam = false;
> > + int ret;
> > +
> > + if (!mdev)
> > + return 0;
> > +
> > + media_device_for_each_entity(entity, mdev) {
> > + switch (entity->function) {
> > + case MEDIA_ENT_F_IF_VID_DECODER:
> > + if_vid = entity;
> > + break;
> > + case MEDIA_ENT_F_IF_AUD_DECODER:
> > + if_aud = entity;
> > + break;
> > + case MEDIA_ENT_F_TUNER:
> > + tuner = entity;
> > + break;
> > + case MEDIA_ENT_F_ATV_DECODER:
> > + decoder = entity;
> > + break;
> > + case MEDIA_ENT_F_IO_V4L:
> > + io_v4l = entity;
> > + break;
> > + case MEDIA_ENT_F_IO_VBI:
> > + io_vbi = entity;
> > + break;
> > + case MEDIA_ENT_F_IO_SWRADIO:
> > + io_swradio = entity;
> > + break;
> > + case MEDIA_ENT_F_CAM_SENSOR:
> > + sensor = entity;
> > + is_webcam = true;
> > + break;
> > + }
> > + }
> > +
> > + /* It should have at least one I/O entity */
> > + if (!io_v4l && !io_vbi && !io_swradio)
> > + return -EINVAL;
> > +
> > + /*
> > + * Here, webcams are modeled on a very simple way: the sensor is
> > + * connected directly to the I/O entity. All dirty details, like
> > + * scaler and crop HW are hidden. While such mapping is not enough
> > + * for mc-centric hardware, it is enough for v4l2 interface centric
> > + * PC-consumer's hardware.
> > + */
> > + if (is_webcam) {
> > + if (!io_v4l)
> > + return -EINVAL;
> > +
> > + media_device_for_each_entity(entity, mdev) {
> > + if (entity->function != MEDIA_ENT_F_CAM_SENSOR)
> > + continue;
> > + ret = media_create_pad_link(entity, 0,
> > + io_v4l, 0,
> > + MEDIA_LNK_FL_ENABLED);
> > + if (ret)
> > + return ret;
> > + }
> > + if (!decoder)
> > + return 0;
> > + }
> > +
> > + /* The device isn't a webcam. So, it should have a decoder */
> > + if (!decoder)
> > + return -EINVAL;
> > +
> > + /* Link the tuner and IF video output pads */
> > + if (tuner) {
> > + if (if_vid) {
> > + ret = media_create_pad_link(tuner, TUNER_PAD_OUTPUT,
> > + if_vid,
> > + IF_VID_DEC_PAD_IF_INPUT,
> > + MEDIA_LNK_FL_ENABLED);
> > + if (ret)
> > + return ret;
> > + ret = media_create_pad_link(if_vid, IF_VID_DEC_PAD_OUT,
> > + decoder, DEMOD_PAD_IF_INPUT,
> > + MEDIA_LNK_FL_ENABLED);
> > + if (ret)
> > + return ret;
> > + } else {
> > + ret = media_create_pad_link(tuner, TUNER_PAD_OUTPUT,
> > + decoder, DEMOD_PAD_IF_INPUT,
> > + MEDIA_LNK_FL_ENABLED);
> > + if (ret)
> > + return ret;
> > + }
> > +
> > + if (if_aud) {
> > + ret = media_create_pad_link(tuner, TUNER_PAD_AUD_OUT,
> > + if_aud,
> > + IF_AUD_DEC_PAD_IF_INPUT,
> > + MEDIA_LNK_FL_ENABLED);
> > + if (ret)
> > + return ret;
> > + } else {
> > + if_aud = tuner;
> > + }
> > +
> > + }
> > +
> > + /* Create demod to V4L, VBI and SDR radio links */
> > + if (io_v4l) {
> > + ret = media_create_pad_link(decoder, DEMOD_PAD_VID_OUT,
> > + io_v4l, 0,
> > + MEDIA_LNK_FL_ENABLED);
> > + if (ret)
> > + return ret;
> > + }
> > +
> > + if (io_swradio) {
> > + ret = media_create_pad_link(decoder, DEMOD_PAD_VID_OUT,
> > + io_swradio, 0,
> > + MEDIA_LNK_FL_ENABLED);
> > + if (ret)
> > + return ret;
> > + }
> > +
> > + if (io_vbi) {
> > + ret = media_create_pad_link(decoder, DEMOD_PAD_VBI_OUT,
> > + io_vbi, 0,
> > + MEDIA_LNK_FL_ENABLED);
> > + if (ret)
> > + return ret;
> > + }
> > +
> > + /* Create links for the media connectors */
> > + media_device_for_each_entity(entity, mdev) {
> > + switch (entity->function) {
> > + case MEDIA_ENT_F_CONN_RF:
> > + if (!tuner)
> > + continue;
> > +
> > + ret = media_create_pad_link(entity, 0, tuner,
> > + TUNER_PAD_RF_INPUT,
> > + MEDIA_LNK_FL_ENABLED);
> > + break;
> > + case MEDIA_ENT_F_CONN_SVIDEO:
> > + case MEDIA_ENT_F_CONN_COMPOSITE:
> > + case MEDIA_ENT_F_CONN_TEST:
> > + ret = media_create_pad_link(entity, 0, decoder,
> > + DEMOD_PAD_IF_INPUT, 0);
> > + break;
> > + default:
> > + continue;
> > + }
> > + if (ret)
> > + return ret;
> > + }
> > + return 0;
> > +}
> > +EXPORT_SYMBOL_GPL(v4l2_mc_create_media_graph);
> > diff --git a/include/media/v4l2-mc.h b/include/media/v4l2-mc.h
> > index df115195690e..3097493e6cf1 100644
> > --- a/include/media/v4l2-mc.h
> > +++ b/include/media/v4l2-mc.h
> > @@ -14,6 +14,8 @@
> > * GNU General Public License for more details.
> > */
> >
> > +#include <media/media-device.h>
> > +
> > /**
> > * enum tuner_pad_index - tuner pad index for MEDIA_ENT_F_TUNER
> > *
> > @@ -89,3 +91,25 @@ enum demod_pad_index {
> > DEMOD_PAD_VBI_OUT,
> > DEMOD_NUM_PADS
> > };
> > +
> > +/**
> > + * v4l2_mc_create_media_graph() - create Media Controller links at the graph.
> > + *
> > + * @mdev: pointer to the &media_device struct.
> > + *
> > + * Add links between the entities commonly found on PC customer's hardware at
> > + * the V4L2 side: camera sensors, audio and video PLL-IF decoders, tuners,
> > + * analog TV decoder and I/O entities (video, VBI and Software Defined Radio).
> > + * NOTE: webcams are modeled on a very simple way: the sensor is
> > + * connected directly to the I/O entity. All dirty details, like
> > + * scaler and crop HW are hidden. While such mapping is enough for v4l2
> > + * interface centric PC-consumer's hardware, V4L2 subdev centric camera
> > + * hardware should not use this routine, as it will not build the right graph.
> > + */
> > +#ifdef CONFIG_MEDIA_CONTROLLER
> > +int v4l2_mc_create_media_graph(struct media_device *mdev);
> > +#else
> > +static inline int v4l2_mc_create_media_graph(struct media_device *mdev) {
> > + return 0;
> > +}
> > +#endif
> >
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-02-05 15:36 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-05 9:51 [PATCH 1/2] [media] v4l2-mc: add a generic function to create the media graph Mauro Carvalho Chehab
2016-02-05 9:51 ` [PATCH 2/2] [media] em2xx: use v4l2_mc_create_media_graph() Mauro Carvalho Chehab
2016-02-05 14:25 ` [PATCH 1/2] [media] v4l2-mc: add a generic function to create the media graph Shuah Khan
2016-02-05 15:36 ` Mauro Carvalho Chehab
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).