Commit 57868acc authored by Satendra Singh Thakur's avatar Satendra Singh Thakur Committed by Mauro Carvalho Chehab

media: videobuf2: Add new uAPI for DVB streaming I/O

Adds a new uAPI for DVB to use streaming I/O which is implemented
based on videobuf2, using those new ioctls:

- DMX_REQBUFS:  Request kernel to allocate buffers which count and size
	        are dedicated by user.
- DMX_QUERYBUF: Get the buffer information like a memory offset which
		will mmap() and be shared with user-space.
- DMX_EXPBUF:   Just for testing whether buffer-exporting success or not.
- DMX_QBUF:     Pass the buffer to kernel-space.
- DMX_DQBUF:    Get back the buffer which may contain TS data.

Originally developed by: Junghak Sung <jh1009.sung@samsung.com>, as
seen at:
	https://patchwork.linuxtv.org/patch/31613/
	https://patchwork.kernel.org/patch/7334301/

The original patch was written before merging VB2-core functionalities
upstream. When such series was added, several adjustments were made,
fixing some issues with	V4L2, causing the original patch to be
non-trivially rebased.

After rebased, a few bugs in the patch were fixed. The patch was
also enhanced it and polling functionality got added.

The main changes over the original patch are:

dvb_vb2_fill_buffer():
	- Set the size of the outgoing buffer after while loop using
	  vb2_set_plane_payload;

	- Added NULL check for source buffer as per normal convention
	  of demux driver, this is called twice, first time with valid
	  buffer second time with NULL pointer, if its not handled,
	  it will result in  crash

	- Restricted spinlock for only list_* operations

dvb_vb2_init():
	- Restricted q->io_modes to only VB2_MMAP as its the only
	  supported mode

dvb_vb2_release():
	- Replaced the && in if condiion with &, because otherwise
	  it was always getting satisfied.

dvb_vb2_stream_off():
	- Added list_del code for enqueud buffers upon stream off

dvb_vb2_poll():
	- Added this new function in order to support polling

dvb_demux_poll() and dvb_dvr_poll()
	- dvb_vb2_poll() is now called from these functions

- Ported this patch and latest videobuf2 to lower kernel versions and
  tested auto scan.
Co-developed-by: default avatarJunghak Sung <jh1009.sung@samsung.com>

[mchehab@s-opensource.com: checkpatch fixes]
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 avatarSatendra Singh Thakur <satendra.t@samsung.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
parent 9eb124fe
......@@ -7,6 +7,6 @@ dvb-net-$(CONFIG_DVB_NET) := dvb_net.o
dvb-core-objs := dvbdev.o dmxdev.o dvb_demux.o \
dvb_ca_en50221.o dvb_frontend.o \
$(dvb-net-y) dvb_ringbuffer.o dvb_math.o
$(dvb-net-y) dvb_ringbuffer.o dvb_vb2.o dvb_math.o
obj-$(CONFIG_DVB_CORE) += dvb-core.o
This diff is collapsed.
......@@ -35,6 +35,7 @@
#include "dvbdev.h"
#include "demux.h"
#include "dvb_ringbuffer.h"
#include "dvb_vb2.h"
/**
* enum dmxdev_type - type of demux filter type.
......@@ -140,6 +141,7 @@ struct dmxdev_filter {
enum dmxdev_state state;
struct dmxdev *dev;
struct dvb_ringbuffer buffer;
struct dvb_vb2_ctx vb2_ctx;
struct mutex mutex;
......@@ -183,6 +185,8 @@ struct dmxdev {
struct dvb_ringbuffer dvr_buffer;
#define DVR_BUFFER_SIZE (10*188*1024)
struct dvb_vb2_ctx dvr_vb2_ctx;
struct mutex mutex;
spinlock_t lock;
};
......
This diff is collapsed.
/*
* dvb-vb2.h - DVB driver helper framework for streaming I/O
*
* Copyright (C) 2015 Samsung Electronics
*
* Author: jh1009.sung@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.
*/
#ifndef _DVB_VB2_H
#define _DVB_VB2_H
#include <linux/mutex.h>
#include <linux/poll.h>
#include <linux/dvb/dmx.h>
#include <media/videobuf2-core.h>
#include <media/videobuf2-dma-contig.h>
#include <media/videobuf2-vmalloc.h>
enum dvb_buf_type {
DVB_BUF_TYPE_CAPTURE = 1,
DVB_BUF_TYPE_OUTPUT = 2,
};
#define DVB_VB2_STATE_NONE (0x0)
#define DVB_VB2_STATE_INIT (0x1)
#define DVB_VB2_STATE_REQBUFS (0x2)
#define DVB_VB2_STATE_STREAMON (0x4)
#define DVB_VB2_NAME_MAX (20)
struct dvb_buffer {
struct vb2_buffer vb;
struct list_head list;
};
struct dvb_vb2_ctx {
struct vb2_queue vb_q;
struct mutex mutex;
spinlock_t slock;
struct list_head dvb_q;
struct dvb_buffer *buf;
int offset;
int remain;
int state;
int buf_siz;
int buf_cnt;
int nonblocking;
char name[DVB_VB2_NAME_MAX + 1];
};
int dvb_vb2_init(struct dvb_vb2_ctx *ctx, const char *name, int non_blocking);
int dvb_vb2_release(struct dvb_vb2_ctx *ctx);
int dvb_vb2_stream_on(struct dvb_vb2_ctx *ctx);
int dvb_vb2_stream_off(struct dvb_vb2_ctx *ctx);
int dvb_vb2_is_streaming(struct dvb_vb2_ctx *ctx);
int dvb_vb2_fill_buffer(struct dvb_vb2_ctx *ctx,
const unsigned char *src, int len);
int dvb_vb2_reqbufs(struct dvb_vb2_ctx *ctx, struct dmx_requestbuffers *req);
int dvb_vb2_querybuf(struct dvb_vb2_ctx *ctx, struct dmx_buffer *b);
int dvb_vb2_expbuf(struct dvb_vb2_ctx *ctx, struct dmx_exportbuffer *exp);
int dvb_vb2_qbuf(struct dvb_vb2_ctx *ctx, struct dmx_buffer *b);
int dvb_vb2_dqbuf(struct dvb_vb2_ctx *ctx, struct dmx_buffer *b);
int dvb_vb2_mmap(struct dvb_vb2_ctx *ctx, struct vm_area_struct *vma);
unsigned int dvb_vb2_poll(struct dvb_vb2_ctx *ctx, struct file *file,
poll_table *wait);
#endif /* _DVB_VB2_H */
......@@ -211,6 +211,64 @@ struct dmx_stc {
__u64 stc;
};
/**
* struct dmx_buffer - dmx buffer info
*
* @index: id number of the buffer
* @bytesused: number of bytes occupied by data in the buffer (payload);
* @offset: for buffers with memory == DMX_MEMORY_MMAP;
* offset from the start of the device memory for this plane,
* (or a "cookie" that should be passed to mmap() as offset)
* @length: size in bytes of the buffer
*
* Contains data exchanged by application and driver using one of the streaming
* I/O methods.
*/
struct dmx_buffer {
__u32 index;
__u32 bytesused;
__u32 offset;
__u32 length;
__u32 reserved[4];
};
/**
* struct dmx_requestbuffers - request dmx buffer information
*
* @count: number of requested buffers,
* @size: size in bytes of the requested buffer
*
* Contains data used for requesting a dmx buffer.
* All reserved fields must be set to zero.
*/
struct dmx_requestbuffers {
__u32 count;
__u32 size;
__u32 reserved[2];
};
/**
* struct dmx_exportbuffer - export of dmx buffer as DMABUF file descriptor
*
* @index: id number of the buffer
* @flags: flags for newly created file, currently only O_CLOEXEC is
* supported, refer to manual of open syscall for more details
* @fd: file descriptor associated with DMABUF (set by driver)
*
* Contains data used for exporting a dmx buffer as DMABUF file descriptor.
* The buffer is identified by a 'cookie' returned by DMX_QUERYBUF
* (identical to the cookie used to mmap() the buffer to userspace). All
* reserved fields must be set to zero. The field reserved0 is expected to
* become a structure 'type' allowing an alternative layout of the structure
* content. Therefore this field should not be used for any other extensions.
*/
struct dmx_exportbuffer {
__u32 index;
__u32 flags;
__s32 fd;
__u32 reserved[5];
};
#define DMX_START _IO('o', 41)
#define DMX_STOP _IO('o', 42)
#define DMX_SET_FILTER _IOW('o', 43, struct dmx_sct_filter_params)
......@@ -231,4 +289,10 @@ typedef struct dmx_filter dmx_filter_t;
#endif
#endif /* _UAPI_DVBDMX_H_ */
#define DMX_REQBUFS _IOWR('o', 60, struct dmx_requestbuffers)
#define DMX_QUERYBUF _IOWR('o', 61, struct dmx_buffer)
#define DMX_EXPBUF _IOWR('o', 62, struct dmx_exportbuffer)
#define DMX_QBUF _IOWR('o', 63, struct dmx_buffer)
#define DMX_DQBUF _IOWR('o', 64, struct dmx_buffer)
#endif /* _DVBDMX_H_ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment