Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit adc589d2 authored by Lucas A. M. Magalhães's avatar Lucas A. M. Magalhães Committed by Mauro Carvalho Chehab
Browse files

media: vimc: Add vimc-streamer for stream control



Add a linear pipeline logic for the stream control. It's created by
walking backwards on the entity graph. When the stream starts it will
simply loop through the pipeline calling the respective process_frame
function of each entity.

Fixes: f2fe8906 ("vimc: Virtual Media Controller core, capture
and sensor")

Cc: stable@vger.kernel.org # for v4.20
Signed-off-by: default avatarLucas A. M. Magalhães <lucmaga@gmail.com>
Acked-by: default avatarHelen Koike <helen.koike@collabora.com>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
[hverkuil-cisco@xs4all.nl: fixed small space-after-tab issue in the patch]
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+samsung@kernel.org>
parent 276c1f06
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -5,6 +5,7 @@ vimc_common-objs := vimc-common.o
vimc_debayer-objs := vimc-debayer.o
vimc_debayer-objs := vimc-debayer.o
vimc_scaler-objs := vimc-scaler.o
vimc_scaler-objs := vimc-scaler.o
vimc_sensor-objs := vimc-sensor.o
vimc_sensor-objs := vimc-sensor.o
vimc_streamer-objs := vimc-streamer.o


obj-$(CONFIG_VIDEO_VIMC) += vimc.o vimc_capture.o vimc_common.o vimc-debayer.o \
obj-$(CONFIG_VIDEO_VIMC) += vimc.o vimc_capture.o vimc_common.o vimc-debayer.o \
				vimc_scaler.o vimc_sensor.o
			    vimc_scaler.o vimc_sensor.o vimc_streamer.o
+9 −9
Original line number Original line Diff line number Diff line
@@ -24,6 +24,7 @@
#include <media/videobuf2-vmalloc.h>
#include <media/videobuf2-vmalloc.h>


#include "vimc-common.h"
#include "vimc-common.h"
#include "vimc-streamer.h"


#define VIMC_CAP_DRV_NAME "vimc-capture"
#define VIMC_CAP_DRV_NAME "vimc-capture"


@@ -44,7 +45,7 @@ struct vimc_cap_device {
	spinlock_t qlock;
	spinlock_t qlock;
	struct mutex lock;
	struct mutex lock;
	u32 sequence;
	u32 sequence;
	struct media_pipeline pipe;
	struct vimc_stream stream;
};
};


static const struct v4l2_pix_format fmt_default = {
static const struct v4l2_pix_format fmt_default = {
@@ -248,14 +249,13 @@ static int vimc_cap_start_streaming(struct vb2_queue *vq, unsigned int count)
	vcap->sequence = 0;
	vcap->sequence = 0;


	/* Start the media pipeline */
	/* Start the media pipeline */
	ret = media_pipeline_start(entity, &vcap->pipe);
	ret = media_pipeline_start(entity, &vcap->stream.pipe);
	if (ret) {
	if (ret) {
		vimc_cap_return_all_buffers(vcap, VB2_BUF_STATE_QUEUED);
		vimc_cap_return_all_buffers(vcap, VB2_BUF_STATE_QUEUED);
		return ret;
		return ret;
	}
	}


	/* Enable streaming from the pipe */
	ret = vimc_streamer_s_stream(&vcap->stream, &vcap->ved, 1);
	ret = vimc_pipeline_s_stream(&vcap->vdev.entity, 1);
	if (ret) {
	if (ret) {
		media_pipeline_stop(entity);
		media_pipeline_stop(entity);
		vimc_cap_return_all_buffers(vcap, VB2_BUF_STATE_QUEUED);
		vimc_cap_return_all_buffers(vcap, VB2_BUF_STATE_QUEUED);
@@ -273,8 +273,7 @@ static void vimc_cap_stop_streaming(struct vb2_queue *vq)
{
{
	struct vimc_cap_device *vcap = vb2_get_drv_priv(vq);
	struct vimc_cap_device *vcap = vb2_get_drv_priv(vq);


	/* Disable streaming from the pipe */
	vimc_streamer_s_stream(&vcap->stream, &vcap->ved, 0);
	vimc_pipeline_s_stream(&vcap->vdev.entity, 0);


	/* Stop the media pipeline */
	/* Stop the media pipeline */
	media_pipeline_stop(&vcap->vdev.entity);
	media_pipeline_stop(&vcap->vdev.entity);
@@ -355,8 +354,8 @@ static void vimc_cap_comp_unbind(struct device *comp, struct device *master,
	kfree(vcap);
	kfree(vcap);
}
}


static void vimc_cap_process_frame(struct vimc_ent_device *ved,
static void *vimc_cap_process_frame(struct vimc_ent_device *ved,
				   struct media_pad *sink, const void *frame)
				    const void *frame)
{
{
	struct vimc_cap_device *vcap = container_of(ved, struct vimc_cap_device,
	struct vimc_cap_device *vcap = container_of(ved, struct vimc_cap_device,
						    ved);
						    ved);
@@ -370,7 +369,7 @@ static void vimc_cap_process_frame(struct vimc_ent_device *ved,
					    typeof(*vimc_buf), list);
					    typeof(*vimc_buf), list);
	if (!vimc_buf) {
	if (!vimc_buf) {
		spin_unlock(&vcap->qlock);
		spin_unlock(&vcap->qlock);
		return;
		return ERR_PTR(-EAGAIN);
	}
	}


	/* Remove this entry from the list */
	/* Remove this entry from the list */
@@ -391,6 +390,7 @@ static void vimc_cap_process_frame(struct vimc_ent_device *ved,
	vb2_set_plane_payload(&vimc_buf->vb2.vb2_buf, 0,
	vb2_set_plane_payload(&vimc_buf->vb2.vb2_buf, 0,
			      vcap->format.sizeimage);
			      vcap->format.sizeimage);
	vb2_buffer_done(&vimc_buf->vb2.vb2_buf, VB2_BUF_STATE_DONE);
	vb2_buffer_done(&vimc_buf->vb2.vb2_buf, VB2_BUF_STATE_DONE);
	return NULL;
}
}


static int vimc_cap_comp_bind(struct device *comp, struct device *master,
static int vimc_cap_comp_bind(struct device *comp, struct device *master,
+0 −35
Original line number Original line Diff line number Diff line
@@ -207,41 +207,6 @@ const struct vimc_pix_map *vimc_pix_map_by_pixelformat(u32 pixelformat)
}
}
EXPORT_SYMBOL_GPL(vimc_pix_map_by_pixelformat);
EXPORT_SYMBOL_GPL(vimc_pix_map_by_pixelformat);


int vimc_propagate_frame(struct media_pad *src, const void *frame)
{
	struct media_link *link;

	if (!(src->flags & MEDIA_PAD_FL_SOURCE))
		return -EINVAL;

	/* Send this frame to all sink pads that are direct linked */
	list_for_each_entry(link, &src->entity->links, list) {
		if (link->source == src &&
		    (link->flags & MEDIA_LNK_FL_ENABLED)) {
			struct vimc_ent_device *ved = NULL;
			struct media_entity *entity = link->sink->entity;

			if (is_media_entity_v4l2_subdev(entity)) {
				struct v4l2_subdev *sd =
					container_of(entity, struct v4l2_subdev,
						     entity);
				ved = v4l2_get_subdevdata(sd);
			} else if (is_media_entity_v4l2_video_device(entity)) {
				struct video_device *vdev =
					container_of(entity,
						     struct video_device,
						     entity);
				ved = video_get_drvdata(vdev);
			}
			if (ved && ved->process_frame)
				ved->process_frame(ved, link->sink, frame);
		}
	}

	return 0;
}
EXPORT_SYMBOL_GPL(vimc_propagate_frame);

/* Helper function to allocate and initialize pads */
/* Helper function to allocate and initialize pads */
struct media_pad *vimc_pads_init(u16 num_pads, const unsigned long *pads_flag)
struct media_pad *vimc_pads_init(u16 num_pads, const unsigned long *pads_flag)
{
{
+2 −13
Original line number Original line Diff line number Diff line
@@ -115,23 +115,12 @@ struct vimc_pix_map {
struct vimc_ent_device {
struct vimc_ent_device {
	struct media_entity *ent;
	struct media_entity *ent;
	struct media_pad *pads;
	struct media_pad *pads;
	void (*process_frame)(struct vimc_ent_device *ved,
	void * (*process_frame)(struct vimc_ent_device *ved,
			      struct media_pad *sink, const void *frame);
				const void *frame);
	void (*vdev_get_format)(struct vimc_ent_device *ved,
	void (*vdev_get_format)(struct vimc_ent_device *ved,
			      struct v4l2_pix_format *fmt);
			      struct v4l2_pix_format *fmt);
};
};


/**
 * vimc_propagate_frame - propagate a frame through the topology
 *
 * @src:	the source pad where the frame is being originated
 * @frame:	the frame to be propagated
 *
 * This function will call the process_frame callback from the vimc_ent_device
 * struct of the nodes directly connected to the @src pad
 */
int vimc_propagate_frame(struct media_pad *src, const void *frame);

/**
/**
 * vimc_pads_init - initialize pads
 * vimc_pads_init - initialize pads
 *
 *
+4 −22
Original line number Original line Diff line number Diff line
@@ -321,7 +321,6 @@ static void vimc_deb_set_rgb_mbus_fmt_rgb888_1x24(struct vimc_deb_device *vdeb,
static int vimc_deb_s_stream(struct v4l2_subdev *sd, int enable)
static int vimc_deb_s_stream(struct v4l2_subdev *sd, int enable)
{
{
	struct vimc_deb_device *vdeb = v4l2_get_subdevdata(sd);
	struct vimc_deb_device *vdeb = v4l2_get_subdevdata(sd);
	int ret;


	if (enable) {
	if (enable) {
		const struct vimc_pix_map *vpix;
		const struct vimc_pix_map *vpix;
@@ -351,22 +350,10 @@ static int vimc_deb_s_stream(struct v4l2_subdev *sd, int enable)
		if (!vdeb->src_frame)
		if (!vdeb->src_frame)
			return -ENOMEM;
			return -ENOMEM;


		/* Turn the stream on in the subdevices directly connected */
		ret = vimc_pipeline_s_stream(&vdeb->sd.entity, 1);
		if (ret) {
			vfree(vdeb->src_frame);
			vdeb->src_frame = NULL;
			return ret;
		}
	} else {
	} else {
		if (!vdeb->src_frame)
		if (!vdeb->src_frame)
			return 0;
			return 0;


		/* Disable streaming from the pipe */
		ret = vimc_pipeline_s_stream(&vdeb->sd.entity, 0);
		if (ret)
			return ret;

		vfree(vdeb->src_frame);
		vfree(vdeb->src_frame);
		vdeb->src_frame = NULL;
		vdeb->src_frame = NULL;
	}
	}
@@ -480,8 +467,7 @@ static void vimc_deb_calc_rgb_sink(struct vimc_deb_device *vdeb,
	}
	}
}
}


static void vimc_deb_process_frame(struct vimc_ent_device *ved,
static void *vimc_deb_process_frame(struct vimc_ent_device *ved,
				   struct media_pad *sink,
				    const void *sink_frame)
				    const void *sink_frame)
{
{
	struct vimc_deb_device *vdeb = container_of(ved, struct vimc_deb_device,
	struct vimc_deb_device *vdeb = container_of(ved, struct vimc_deb_device,
@@ -491,7 +477,7 @@ static void vimc_deb_process_frame(struct vimc_ent_device *ved,


	/* If the stream in this node is not active, just return */
	/* If the stream in this node is not active, just return */
	if (!vdeb->src_frame)
	if (!vdeb->src_frame)
		return;
		return ERR_PTR(-EINVAL);


	for (i = 0; i < vdeb->sink_fmt.height; i++)
	for (i = 0; i < vdeb->sink_fmt.height; i++)
		for (j = 0; j < vdeb->sink_fmt.width; j++) {
		for (j = 0; j < vdeb->sink_fmt.width; j++) {
@@ -499,12 +485,8 @@ static void vimc_deb_process_frame(struct vimc_ent_device *ved,
			vdeb->set_rgb_src(vdeb, i, j, rgb);
			vdeb->set_rgb_src(vdeb, i, j, rgb);
		}
		}


	/* Propagate the frame through all source pads */
	return vdeb->src_frame;
	for (i = 1; i < vdeb->sd.entity.num_pads; i++) {
		struct media_pad *pad = &vdeb->sd.entity.pads[i];


		vimc_propagate_frame(pad, vdeb->src_frame);
	}
}
}


static void vimc_deb_comp_unbind(struct device *comp, struct device *master,
static void vimc_deb_comp_unbind(struct device *comp, struct device *master,
Loading