1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#ifndef _VIDEOBUF_CORE_H
17#define _VIDEOBUF_CORE_H
18
19#include <linux/poll.h>
20#include <linux/videodev2.h>
21
22#define UNSET (-1U)
23
24
25struct videobuf_buffer;
26struct videobuf_queue;
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51struct videobuf_mapping {
52 unsigned int count;
53 struct videobuf_queue *q;
54};
55
56enum videobuf_state {
57 VIDEOBUF_NEEDS_INIT = 0,
58 VIDEOBUF_PREPARED = 1,
59 VIDEOBUF_QUEUED = 2,
60 VIDEOBUF_ACTIVE = 3,
61 VIDEOBUF_DONE = 4,
62 VIDEOBUF_ERROR = 5,
63 VIDEOBUF_IDLE = 6,
64};
65
66struct videobuf_buffer {
67 unsigned int i;
68 u32 magic;
69
70
71 unsigned int width;
72 unsigned int height;
73 unsigned int bytesperline;
74 unsigned long size;
75 enum v4l2_field field;
76 enum videobuf_state state;
77 struct list_head stream;
78
79
80 struct list_head queue;
81 wait_queue_head_t done;
82 unsigned int field_count;
83 struct timeval ts;
84
85
86 enum v4l2_memory memory;
87
88
89 size_t bsize;
90
91
92 size_t boff;
93
94
95 unsigned long baddr;
96
97
98 struct videobuf_mapping *map;
99
100
101 int privsize;
102 void *priv;
103};
104
105struct videobuf_queue_ops {
106 int (*buf_setup)(struct videobuf_queue *q,
107 unsigned int *count, unsigned int *size);
108 int (*buf_prepare)(struct videobuf_queue *q,
109 struct videobuf_buffer *vb,
110 enum v4l2_field field);
111 void (*buf_queue)(struct videobuf_queue *q,
112 struct videobuf_buffer *vb);
113 void (*buf_release)(struct videobuf_queue *q,
114 struct videobuf_buffer *vb);
115};
116
117#define MAGIC_QTYPE_OPS 0x12261003
118
119
120struct videobuf_qtype_ops {
121 u32 magic;
122
123 struct videobuf_buffer *(*alloc_vb)(size_t size);
124 void *(*vaddr) (struct videobuf_buffer *buf);
125 int (*iolock) (struct videobuf_queue *q,
126 struct videobuf_buffer *vb,
127 struct v4l2_framebuffer *fbuf);
128 int (*sync) (struct videobuf_queue *q,
129 struct videobuf_buffer *buf);
130 int (*mmap_mapper) (struct videobuf_queue *q,
131 struct videobuf_buffer *buf,
132 struct vm_area_struct *vma);
133};
134
135struct videobuf_queue {
136 struct mutex vb_lock;
137 struct mutex *ext_lock;
138 spinlock_t *irqlock;
139 struct device *dev;
140
141 wait_queue_head_t wait;
142
143 enum v4l2_buf_type type;
144 unsigned int msize;
145 enum v4l2_field field;
146 enum v4l2_field last;
147 struct videobuf_buffer *bufs[VIDEO_MAX_FRAME];
148 const struct videobuf_queue_ops *ops;
149 struct videobuf_qtype_ops *int_ops;
150
151 unsigned int streaming:1;
152 unsigned int reading:1;
153
154
155 struct list_head stream;
156
157
158 unsigned int read_off;
159 struct videobuf_buffer *read_buf;
160
161
162 void *priv_data;
163};
164
165static inline void videobuf_queue_lock(struct videobuf_queue *q)
166{
167 if (!q->ext_lock)
168 mutex_lock(&q->vb_lock);
169}
170
171static inline void videobuf_queue_unlock(struct videobuf_queue *q)
172{
173 if (!q->ext_lock)
174 mutex_unlock(&q->vb_lock);
175}
176
177int videobuf_waiton(struct videobuf_queue *q, struct videobuf_buffer *vb,
178 int non_blocking, int intr);
179int videobuf_iolock(struct videobuf_queue *q, struct videobuf_buffer *vb,
180 struct v4l2_framebuffer *fbuf);
181
182struct videobuf_buffer *videobuf_alloc_vb(struct videobuf_queue *q);
183
184
185void *videobuf_queue_to_vaddr(struct videobuf_queue *q,
186 struct videobuf_buffer *buf);
187
188void videobuf_queue_core_init(struct videobuf_queue *q,
189 const struct videobuf_queue_ops *ops,
190 struct device *dev,
191 spinlock_t *irqlock,
192 enum v4l2_buf_type type,
193 enum v4l2_field field,
194 unsigned int msize,
195 void *priv,
196 struct videobuf_qtype_ops *int_ops,
197 struct mutex *ext_lock);
198int videobuf_queue_is_busy(struct videobuf_queue *q);
199void videobuf_queue_cancel(struct videobuf_queue *q);
200
201enum v4l2_field videobuf_next_field(struct videobuf_queue *q);
202int videobuf_reqbufs(struct videobuf_queue *q,
203 struct v4l2_requestbuffers *req);
204int videobuf_querybuf(struct videobuf_queue *q, struct v4l2_buffer *b);
205int videobuf_qbuf(struct videobuf_queue *q,
206 struct v4l2_buffer *b);
207int videobuf_dqbuf(struct videobuf_queue *q,
208 struct v4l2_buffer *b, int nonblocking);
209int videobuf_streamon(struct videobuf_queue *q);
210int videobuf_streamoff(struct videobuf_queue *q);
211
212void videobuf_stop(struct videobuf_queue *q);
213
214int videobuf_read_start(struct videobuf_queue *q);
215void videobuf_read_stop(struct videobuf_queue *q);
216ssize_t videobuf_read_stream(struct videobuf_queue *q,
217 char __user *data, size_t count, loff_t *ppos,
218 int vbihack, int nonblocking);
219ssize_t videobuf_read_one(struct videobuf_queue *q,
220 char __user *data, size_t count, loff_t *ppos,
221 int nonblocking);
222unsigned int videobuf_poll_stream(struct file *file,
223 struct videobuf_queue *q,
224 poll_table *wait);
225
226int videobuf_mmap_setup(struct videobuf_queue *q,
227 unsigned int bcount, unsigned int bsize,
228 enum v4l2_memory memory);
229int __videobuf_mmap_setup(struct videobuf_queue *q,
230 unsigned int bcount, unsigned int bsize,
231 enum v4l2_memory memory);
232int videobuf_mmap_free(struct videobuf_queue *q);
233int videobuf_mmap_mapper(struct videobuf_queue *q,
234 struct vm_area_struct *vma);
235
236#endif
237