Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
videobuf-core.h
Go to the documentation of this file.
1 /*
2  * generic helper functions for handling video4linux capture buffers
3  *
4  * (c) 2007 Mauro Carvalho Chehab, <[email protected]>
5  *
6  * Highly based on video-buf written originally by:
7  * (c) 2001,02 Gerd Knorr <[email protected]>
8  * (c) 2006 Mauro Carvalho Chehab, <[email protected]>
9  * (c) 2006 Ted Walther and John Sokol
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2
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 
25 struct videobuf_buffer;
26 struct videobuf_queue;
27 
28 /* --------------------------------------------------------------------- */
29 
30 /*
31  * A small set of helper functions to manage video4linux buffers.
32  *
33  * struct videobuf_buffer holds the data structures used by the helper
34  * functions, additionally some commonly used fields for v4l buffers
35  * (width, height, lists, waitqueue) are in there. That struct should
36  * be used as first element in the drivers buffer struct.
37  *
38  * about the mmap helpers (videobuf_mmap_*):
39  *
40  * The mmaper function allows to map any subset of contingous buffers.
41  * This includes one mmap() call for all buffers (which the original
42  * video4linux API uses) as well as one mmap() for every single buffer
43  * (which v4l2 uses).
44  *
45  * If there is a valid mapping for a buffer, buffer->baddr/bsize holds
46  * userspace address + size which can be feeded into the
47  * videobuf_dma_init_user function listed above.
48  *
49  */
50 
52  unsigned int count;
53  struct videobuf_queue *q;
54 };
55 
64 };
65 
67  unsigned int i;
69 
70  /* info about the buffer */
71  unsigned int width;
72  unsigned int height;
73  unsigned int bytesperline; /* use only if != 0 */
74  unsigned long size;
77  struct list_head stream; /* QBUF/DQBUF list */
78 
79  /* touched by irq handler */
80  struct list_head queue;
82  unsigned int field_count;
83  struct timeval ts;
84 
85  /* Memory type */
87 
88  /* buffer size */
89  size_t bsize;
90 
91  /* buffer offset (mmap + overlay) */
92  size_t boff;
93 
94  /* buffer addr (userland ptr!) */
95  unsigned long baddr;
96 
97  /* for mmap'ed buffers */
99 
100  /* Private pointer to allow specific methods to store their data */
101  int privsize;
102  void *priv;
103 };
104 
107  unsigned int *count, unsigned int *size);
109  struct videobuf_buffer *vb,
110  enum v4l2_field field);
112  struct videobuf_buffer *vb);
114  struct videobuf_buffer *vb);
115 };
116 
117 #define MAGIC_QTYPE_OPS 0x12261003
118 
119 /* Helper operations - device type dependent */
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);
131  struct videobuf_buffer *buf,
132  struct vm_area_struct *vma);
133 };
134 
136  struct mutex vb_lock;
137  struct mutex *ext_lock;
139  struct device *dev;
140 
141  wait_queue_head_t wait; /* wait if queue is empty */
142 
144  unsigned int msize;
146  enum v4l2_field last; /* for field=V4L2_FIELD_ALTERNATE */
148  const struct videobuf_queue_ops *ops;
150 
151  unsigned int streaming:1;
152  unsigned int reading:1;
153 
154  /* capture via mmap() + ioctl(QBUF/DQBUF) */
156 
157  /* capture via read() */
158  unsigned int read_off;
160 
161  /* driver private data */
162  void *priv_data;
163 };
164 
165 static inline void videobuf_queue_lock(struct videobuf_queue *q)
166 {
167  if (!q->ext_lock)
168  mutex_lock(&q->vb_lock);
169 }
170 
171 static inline void videobuf_queue_unlock(struct videobuf_queue *q)
172 {
173  if (!q->ext_lock)
174  mutex_unlock(&q->vb_lock);
175 }
176 
177 int videobuf_waiton(struct videobuf_queue *q, struct videobuf_buffer *vb,
178  int non_blocking, int intr);
179 int videobuf_iolock(struct videobuf_queue *q, struct videobuf_buffer *vb,
180  struct v4l2_framebuffer *fbuf);
181 
183 
184 /* Used on videobuf-dvb */
186  struct videobuf_buffer *buf);
187 
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);
199 void videobuf_queue_cancel(struct videobuf_queue *q);
200 
202 int videobuf_reqbufs(struct videobuf_queue *q,
203  struct v4l2_requestbuffers *req);
204 int videobuf_querybuf(struct videobuf_queue *q, struct v4l2_buffer *b);
205 int videobuf_qbuf(struct videobuf_queue *q,
206  struct v4l2_buffer *b);
207 int videobuf_dqbuf(struct videobuf_queue *q,
208  struct v4l2_buffer *b, int nonblocking);
209 int videobuf_streamon(struct videobuf_queue *q);
210 int videobuf_streamoff(struct videobuf_queue *q);
211 
212 void videobuf_stop(struct videobuf_queue *q);
213 
214 int videobuf_read_start(struct videobuf_queue *q);
215 void videobuf_read_stop(struct videobuf_queue *q);
217  char __user *data, size_t count, loff_t *ppos,
218  int vbihack, int nonblocking);
220  char __user *data, size_t count, loff_t *ppos,
221  int nonblocking);
222 unsigned int videobuf_poll_stream(struct file *file,
223  struct videobuf_queue *q,
224  poll_table *wait);
225 
226 int videobuf_mmap_setup(struct videobuf_queue *q,
227  unsigned int bcount, unsigned int bsize,
228  enum v4l2_memory memory);
230  unsigned int bcount, unsigned int bsize,
231  enum v4l2_memory memory);
232 int videobuf_mmap_free(struct videobuf_queue *q);
234  struct vm_area_struct *vma);
235 
236 #endif