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

Commit 2d700715 authored by Junghak Sung's avatar Junghak Sung Committed by Mauro Carvalho Chehab
Browse files

[media] media: videobuf2: Restructure vb2_buffer



Remove v4l2 stuff - v4l2_buf, v4l2_plane - from struct vb2_buffer.

Add new member variables - bytesused, length, offset, userptr, fd,
data_offset - to struct vb2_plane in order to cover all information
of v4l2_plane.
struct vb2_plane {
        <snip>
        unsigned int            bytesused;
        unsigned int            length;
        union {
                unsigned int    offset;
                unsigned long   userptr;
                int             fd;
        } m;
        unsigned int            data_offset;
}

Replace v4l2_buf with new member variables - index, type, memory - which
are common fields for buffer management.
struct vb2_buffer {
        <snip>
        unsigned int            index;
        unsigned int            type;
        unsigned int            memory;
        unsigned int            num_planes;
        struct vb2_plane        planes[VIDEO_MAX_PLANES];
        <snip>
};

v4l2 specific fields - flags, field, timestamp, timecode,
sequence - are moved to vb2_v4l2_buffer in videobuf2-v4l2.c
struct vb2_v4l2_buffer {
        struct vb2_buffer       vb2_buf;

        __u32                   flags;
        __u32                   field;
        struct timeval          timestamp;
        struct v4l2_timecode    timecode;
        __u32                   sequence;
};

Signed-off-by: default avatarJunghak Sung <jh1009.sung@samsung.com>
Signed-off-by: default avatarGeunyoung Kim <nenggun.kim@samsung.com>
Acked-by: default avatarSeung-Woo Kim <sw0312.kim@samsung.com>
Acked-by: default avatarInki Dae <inki.dae@samsung.com>
Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@osg.samsung.com>
parent c139990e
Loading
Loading
Loading
Loading
+9 −8
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@
#include <media/v4l2-device.h>
#include <media/v4l2-dev.h>
#include <media/v4l2-ioctl.h>
#include <media/videobuf2-v4l2.h>
#include <media/videobuf2-dma-sg.h>

/* read 512 bytes from endpoint 0x86 -> get header + blobs */
@@ -163,7 +164,7 @@ struct sur40_state {
};

struct sur40_buffer {
	struct vb2_buffer vb;
	struct vb2_v4l2_buffer vb;
	struct list_head list;
};

@@ -420,7 +421,7 @@ static void sur40_process_video(struct sur40_state *sur40)

	dev_dbg(sur40->dev, "header acquired\n");

	sgt = vb2_dma_sg_plane_desc(&new_buf->vb, 0);
	sgt = vb2_dma_sg_plane_desc(&new_buf->vb.vb2_buf, 0);

	result = usb_sg_init(&sgr, sur40->usbdev,
		usb_rcvbulkpipe(sur40->usbdev, VIDEO_ENDPOINT), 0,
@@ -443,15 +444,15 @@ static void sur40_process_video(struct sur40_state *sur40)
		goto err_poll;

	/* mark as finished */
	v4l2_get_timestamp(&new_buf->vb.v4l2_buf.timestamp);
	new_buf->vb.v4l2_buf.sequence = sur40->sequence++;
	new_buf->vb.v4l2_buf.field = V4L2_FIELD_NONE;
	vb2_buffer_done(&new_buf->vb, VB2_BUF_STATE_DONE);
	v4l2_get_timestamp(&new_buf->vb.timestamp);
	new_buf->vb.sequence = sur40->sequence++;
	new_buf->vb.field = V4L2_FIELD_NONE;
	vb2_buffer_done(&new_buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
	dev_dbg(sur40->dev, "buffer marked done\n");
	return;

err_poll:
	vb2_buffer_done(&new_buf->vb, VB2_BUF_STATE_ERROR);
	vb2_buffer_done(&new_buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
}

/* Initialize input device parameters. */
@@ -701,7 +702,7 @@ static void return_all_buffers(struct sur40_state *sur40,

	spin_lock(&sur40->qlock);
	list_for_each_entry_safe(buf, node, &sur40->buf_list, list) {
		vb2_buffer_done(&buf->vb, state);
		vb2_buffer_done(&buf->vb.vb2_buf, state);
		list_del(&buf->list);
	}
	spin_unlock(&sur40->qlock);
+12 −9
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@
#include <media/v4l2-ioctl.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-event.h>
#include <media/videobuf2-v4l2.h>
#include <media/videobuf2-vmalloc.h>

#include <linux/platform_device.h>
@@ -107,7 +108,8 @@ static const unsigned int NUM_FORMATS = ARRAY_SIZE(formats);

/* intermediate buffers with raw data from the USB device */
struct rtl2832_sdr_frame_buf {
	struct vb2_buffer vb;   /* common v4l buffer stuff -- must be first */
	/* common v4l buffer stuff -- must be first */
	struct vb2_v4l2_buffer vb;
	struct list_head list;
};

@@ -304,13 +306,13 @@ static void rtl2832_sdr_urb_complete(struct urb *urb)
		}

		/* fill framebuffer */
		ptr = vb2_plane_vaddr(&fbuf->vb, 0);
		ptr = vb2_plane_vaddr(&fbuf->vb.vb2_buf, 0);
		len = rtl2832_sdr_convert_stream(dev, ptr, urb->transfer_buffer,
				urb->actual_length);
		vb2_set_plane_payload(&fbuf->vb, 0, len);
		v4l2_get_timestamp(&fbuf->vb.v4l2_buf.timestamp);
		fbuf->vb.v4l2_buf.sequence = dev->sequence++;
		vb2_buffer_done(&fbuf->vb, VB2_BUF_STATE_DONE);
		vb2_set_plane_payload(&fbuf->vb.vb2_buf, 0, len);
		v4l2_get_timestamp(&fbuf->vb.timestamp);
		fbuf->vb.sequence = dev->sequence++;
		vb2_buffer_done(&fbuf->vb.vb2_buf, VB2_BUF_STATE_DONE);
	}
skip:
	usb_submit_urb(urb, GFP_ATOMIC);
@@ -464,7 +466,7 @@ static void rtl2832_sdr_cleanup_queued_bufs(struct rtl2832_sdr_dev *dev)
		buf = list_entry(dev->queued_bufs.next,
				struct rtl2832_sdr_frame_buf, list);
		list_del(&buf->list);
		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
		vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
	}
	spin_unlock_irqrestore(&dev->queued_bufs_lock, flags);
}
@@ -518,14 +520,15 @@ static int rtl2832_sdr_buf_prepare(struct vb2_buffer *vb)

static void rtl2832_sdr_buf_queue(struct vb2_buffer *vb)
{
	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
	struct rtl2832_sdr_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
	struct rtl2832_sdr_frame_buf *buf =
			container_of(vb, struct rtl2832_sdr_frame_buf, vb);
			container_of(vbuf, struct rtl2832_sdr_frame_buf, vb);
	unsigned long flags;

	/* Check the device has not disconnected between prep and queuing */
	if (!dev->udev) {
		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
		vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
		return;
	}

+4 −2
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@
#include <media/v4l2-ioctl.h>
#include <media/v4l2-device.h>
#include <media/v4l2-fh.h>
#include <media/videobuf2-v4l2.h>
#include <media/videobuf2-dma-sg.h>

#include "m00233_video_measure_memmap_package.h"
@@ -206,11 +207,12 @@ struct sg_dma_desc_info {
#define COBALT_STREAM_FL_ADV_IRQ		1

struct cobalt_buffer {
	struct vb2_buffer vb;
	struct vb2_v4l2_buffer vb;
	struct list_head list;
};

static inline struct cobalt_buffer *to_cobalt_buffer(struct vb2_buffer *vb2)
static inline
struct cobalt_buffer *to_cobalt_buffer(struct vb2_v4l2_buffer *vb2)
{
	return container_of(vb2, struct cobalt_buffer, vb);
}
+4 −3
Original line number Diff line number Diff line
@@ -134,11 +134,12 @@ static void cobalt_dma_stream_queue_handler(struct cobalt_stream *s)
		skip = true;
		s->skip_first_frames--;
	}
	v4l2_get_timestamp(&cb->vb.v4l2_buf.timestamp);
	v4l2_get_timestamp(&cb->vb.timestamp);
	/* TODO: the sequence number should be read from the FPGA so we
	   also know about dropped frames. */
	cb->vb.v4l2_buf.sequence = s->sequence++;
	vb2_buffer_done(&cb->vb, (skip || s->unstable_frame) ?
	cb->vb.sequence = s->sequence++;
	vb2_buffer_done(&cb->vb.vb2_buf,
			(skip || s->unstable_frame) ?
			VB2_BUF_STATE_REQUEUEING : VB2_BUF_STATE_DONE);
}

+11 −9
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ static int cobalt_buf_init(struct vb2_buffer *vb)
	const size_t bytes =
		COBALT_MAX_HEIGHT * max_pages_per_line * 0x20;
	const size_t audio_bytes = ((1920 * 4) / PAGE_SIZE + 1) * 0x20;
	struct sg_dma_desc_info *desc = &s->dma_desc_info[vb->v4l2_buf.index];
	struct sg_dma_desc_info *desc = &s->dma_desc_info[vb->index];
	struct sg_table *sg_desc = vb2_dma_sg_plane_desc(vb, 0);
	unsigned size;
	int ret;
@@ -105,17 +105,18 @@ static int cobalt_buf_init(struct vb2_buffer *vb)
static void cobalt_buf_cleanup(struct vb2_buffer *vb)
{
	struct cobalt_stream *s = vb->vb2_queue->drv_priv;
	struct sg_dma_desc_info *desc = &s->dma_desc_info[vb->v4l2_buf.index];
	struct sg_dma_desc_info *desc = &s->dma_desc_info[vb->index];

	descriptor_list_free(desc);
}

static int cobalt_buf_prepare(struct vb2_buffer *vb)
{
	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
	struct cobalt_stream *s = vb->vb2_queue->drv_priv;

	vb2_set_plane_payload(vb, 0, s->stride * s->height);
	vb->v4l2_buf.field = V4L2_FIELD_NONE;
	vbuf->field = V4L2_FIELD_NONE;
	return 0;
}

@@ -128,7 +129,7 @@ static void chain_all_buffers(struct cobalt_stream *s)

	list_for_each(p, &s->bufs) {
		cb = list_entry(p, struct cobalt_buffer, list);
		desc[i] = &s->dma_desc_info[cb->vb.v4l2_buf.index];
		desc[i] = &s->dma_desc_info[cb->vb.vb2_buf.index];
		if (i > 0)
			descriptor_list_chain(desc[i-1], desc[i]);
		i++;
@@ -137,10 +138,11 @@ static void chain_all_buffers(struct cobalt_stream *s)

static void cobalt_buf_queue(struct vb2_buffer *vb)
{
	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
	struct vb2_queue *q = vb->vb2_queue;
	struct cobalt_stream *s = q->drv_priv;
	struct cobalt_buffer *cb = to_cobalt_buffer(vb);
	struct sg_dma_desc_info *desc = &s->dma_desc_info[vb->v4l2_buf.index];
	struct cobalt_buffer *cb = to_cobalt_buffer(vbuf);
	struct sg_dma_desc_info *desc = &s->dma_desc_info[vb->index];
	unsigned long flags;

	/* Prepare new buffer */
@@ -284,7 +286,7 @@ static void cobalt_dma_start_streaming(struct cobalt_stream *s)
			  &vo->control);
	}
	cb = list_first_entry(&s->bufs, struct cobalt_buffer, list);
	omni_sg_dma_start(s, &s->dma_desc_info[cb->vb.v4l2_buf.index]);
	omni_sg_dma_start(s, &s->dma_desc_info[cb->vb.vb2_buf.index]);
	spin_unlock_irqrestore(&s->irqlock, flags);
}

@@ -381,7 +383,7 @@ static void cobalt_dma_stop_streaming(struct cobalt_stream *s)
	spin_lock_irqsave(&s->irqlock, flags);
	list_for_each(p, &s->bufs) {
		cb = list_entry(p, struct cobalt_buffer, list);
		desc = &s->dma_desc_info[cb->vb.v4l2_buf.index];
		desc = &s->dma_desc_info[cb->vb.vb2_buf.index];
		/* Stop DMA after this descriptor chain */
		descriptor_list_end_of_chain(desc);
	}
@@ -416,7 +418,7 @@ static void cobalt_stop_streaming(struct vb2_queue *q)
	list_for_each_safe(p, safe, &s->bufs) {
		cb = list_entry(p, struct cobalt_buffer, list);
		list_del(&cb->list);
		vb2_buffer_done(&cb->vb, VB2_BUF_STATE_ERROR);
		vb2_buffer_done(&cb->vb.vb2_buf, VB2_BUF_STATE_ERROR);
	}
	spin_unlock_irqrestore(&s->irqlock, flags);

Loading