[media] media: videobuf2: Refactor vb2_fileio_data and vb2_thread
[deliverable/linux.git] / include / media / videobuf2-v4l2.h
CommitLineData
c139990e
JS
1/*
2 * videobuf2-v4l2.h - V4L2 driver helper framework
3 *
4 * Copyright (C) 2010 Samsung Electronics
5 *
6 * Author: Pawel Osciak <pawel@osciak.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation.
11 */
12#ifndef _MEDIA_VIDEOBUF2_V4L2_H
13#define _MEDIA_VIDEOBUF2_V4L2_H
14
2d700715 15#include <linux/videodev2.h>
c139990e
JS
16#include <media/videobuf2-core.h>
17
bed04f93
JS
18#if VB2_MAX_FRAME != VIDEO_MAX_FRAME
19#error VB2_MAX_FRAME != VIDEO_MAX_FRAME
20#endif
21
22#if VB2_MAX_PLANES != VIDEO_MAX_PLANES
23#error VB2_MAX_PLANES != VIDEO_MAX_PLANES
24#endif
25
2d700715
JS
26/**
27 * struct vb2_v4l2_buffer - video buffer information for v4l2
28 * @vb2_buf: video buffer 2
29 * @flags: buffer informational flags
30 * @field: enum v4l2_field; field order of the image in the buffer
2d700715
JS
31 * @timecode: frame timecode
32 * @sequence: sequence count of this frame
33 * Should contain enough information to be able to cover all the fields
34 * of struct v4l2_buffer at videodev2.h
35 */
36struct vb2_v4l2_buffer {
37 struct vb2_buffer vb2_buf;
38
39 __u32 flags;
40 __u32 field;
2d700715
JS
41 struct v4l2_timecode timecode;
42 __u32 sequence;
43};
44
d383b579 45/*
2d700715
JS
46 * to_vb2_v4l2_buffer() - cast struct vb2_buffer * to struct vb2_v4l2_buffer *
47 */
48#define to_vb2_v4l2_buffer(vb) \
d383b579 49 container_of(vb, struct vb2_v4l2_buffer, vb2_buf)
2d700715 50
3c5be988
JS
51int vb2_querybuf(struct vb2_queue *q, struct v4l2_buffer *b);
52int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req);
53
54int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create);
55int vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b);
56
57int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b);
58int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb);
59int vb2_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking);
60
61int vb2_streamon(struct vb2_queue *q, enum v4l2_buf_type type);
62int vb2_streamoff(struct vb2_queue *q, enum v4l2_buf_type type);
63
64int __must_check vb2_queue_init(struct vb2_queue *q);
65void vb2_queue_release(struct vb2_queue *q);
66
67unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait);
68size_t vb2_read(struct vb2_queue *q, char __user *data, size_t count,
69 loff_t *ppos, int nonblock);
70size_t vb2_write(struct vb2_queue *q, const char __user *data, size_t count,
71 loff_t *ppos, int nonblock);
72
73/*
74 * vb2_thread_fnc - callback function for use with vb2_thread
75 *
76 * This is called whenever a buffer is dequeued in the thread.
77 */
78typedef int (*vb2_thread_fnc)(struct vb2_buffer *vb, void *priv);
79
80/**
81 * vb2_thread_start() - start a thread for the given queue.
82 * @q: videobuf queue
83 * @fnc: callback function
84 * @priv: priv pointer passed to the callback function
85 * @thread_name:the name of the thread. This will be prefixed with "vb2-".
86 *
87 * This starts a thread that will queue and dequeue until an error occurs
88 * or @vb2_thread_stop is called.
89 *
90 * This function should not be used for anything else but the videobuf2-dvb
91 * support. If you think you have another good use-case for this, then please
92 * contact the linux-media mailinglist first.
93 */
94int vb2_thread_start(struct vb2_queue *q, vb2_thread_fnc fnc, void *priv,
95 const char *thread_name);
96
97/**
98 * vb2_thread_stop() - stop the thread for the given queue.
99 * @q: videobuf queue
100 */
101int vb2_thread_stop(struct vb2_queue *q);
102
103/*
104 * The following functions are not part of the vb2 core API, but are simple
105 * helper functions that you can use in your struct v4l2_file_operations,
106 * struct v4l2_ioctl_ops and struct vb2_ops. They will serialize if vb2_queue->lock
107 * or video_device->lock is set, and they will set and test vb2_queue->owner
108 * to check if the calling filehandle is permitted to do the queuing operation.
109 */
110
111/* struct v4l2_ioctl_ops helpers */
112
113int vb2_ioctl_reqbufs(struct file *file, void *priv,
114 struct v4l2_requestbuffers *p);
115int vb2_ioctl_create_bufs(struct file *file, void *priv,
116 struct v4l2_create_buffers *p);
117int vb2_ioctl_prepare_buf(struct file *file, void *priv,
118 struct v4l2_buffer *p);
119int vb2_ioctl_querybuf(struct file *file, void *priv, struct v4l2_buffer *p);
120int vb2_ioctl_qbuf(struct file *file, void *priv, struct v4l2_buffer *p);
121int vb2_ioctl_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p);
122int vb2_ioctl_streamon(struct file *file, void *priv, enum v4l2_buf_type i);
123int vb2_ioctl_streamoff(struct file *file, void *priv, enum v4l2_buf_type i);
124int vb2_ioctl_expbuf(struct file *file, void *priv,
125 struct v4l2_exportbuffer *p);
126
127/* struct v4l2_file_operations helpers */
128
129int vb2_fop_mmap(struct file *file, struct vm_area_struct *vma);
130int vb2_fop_release(struct file *file);
131int _vb2_fop_release(struct file *file, struct mutex *lock);
132ssize_t vb2_fop_write(struct file *file, const char __user *buf,
133 size_t count, loff_t *ppos);
134ssize_t vb2_fop_read(struct file *file, char __user *buf,
135 size_t count, loff_t *ppos);
136unsigned int vb2_fop_poll(struct file *file, poll_table *wait);
137#ifndef CONFIG_MMU
138unsigned long vb2_fop_get_unmapped_area(struct file *file, unsigned long addr,
139 unsigned long len, unsigned long pgoff, unsigned long flags);
140#endif
141
142/* struct vb2_ops helpers, only use if vq->lock is non-NULL. */
143
144void vb2_ops_wait_prepare(struct vb2_queue *vq);
145void vb2_ops_wait_finish(struct vb2_queue *vq);
146
c139990e 147#endif /* _MEDIA_VIDEOBUF2_V4L2_H */
This page took 0.036117 seconds and 5 git commands to generate.