diff options
Diffstat (limited to 'include/media')
-rw-r--r-- | include/media/v4l2-mem2mem.h | 201 |
1 files changed, 201 insertions, 0 deletions
diff --git a/include/media/v4l2-mem2mem.h b/include/media/v4l2-mem2mem.h new file mode 100644 index 000000000000..8d149f1c58d0 --- /dev/null +++ b/include/media/v4l2-mem2mem.h | |||
@@ -0,0 +1,201 @@ | |||
1 | /* | ||
2 | * Memory-to-memory device framework for Video for Linux 2. | ||
3 | * | ||
4 | * Helper functions for devices that use memory buffers for both source | ||
5 | * and destination. | ||
6 | * | ||
7 | * Copyright (c) 2009 Samsung Electronics Co., Ltd. | ||
8 | * Pawel Osciak, <p.osciak@samsung.com> | ||
9 | * Marek Szyprowski, <m.szyprowski@samsung.com> | ||
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 the | ||
13 | * Free Software Foundation; either version 2 of the | ||
14 | * License, or (at your option) any later version | ||
15 | */ | ||
16 | |||
17 | #ifndef _MEDIA_V4L2_MEM2MEM_H | ||
18 | #define _MEDIA_V4L2_MEM2MEM_H | ||
19 | |||
20 | #include <media/videobuf-core.h> | ||
21 | |||
22 | /** | ||
23 | * struct v4l2_m2m_ops - mem-to-mem device driver callbacks | ||
24 | * @device_run: required. Begin the actual job (transaction) inside this | ||
25 | * callback. | ||
26 | * The job does NOT have to end before this callback returns | ||
27 | * (and it will be the usual case). When the job finishes, | ||
28 | * v4l2_m2m_job_finish() has to be called. | ||
29 | * @job_ready: optional. Should return 0 if the driver does not have a job | ||
30 | * fully prepared to run yet (i.e. it will not be able to finish a | ||
31 | * transaction without sleeping). If not provided, it will be | ||
32 | * assumed that one source and one destination buffer are all | ||
33 | * that is required for the driver to perform one full transaction. | ||
34 | * This method may not sleep. | ||
35 | * @job_abort: required. Informs the driver that it has to abort the currently | ||
36 | * running transaction as soon as possible (i.e. as soon as it can | ||
37 | * stop the device safely; e.g. in the next interrupt handler), | ||
38 | * even if the transaction would not have been finished by then. | ||
39 | * After the driver performs the necessary steps, it has to call | ||
40 | * v4l2_m2m_job_finish() (as if the transaction ended normally). | ||
41 | * This function does not have to (and will usually not) wait | ||
42 | * until the device enters a state when it can be stopped. | ||
43 | */ | ||
44 | struct v4l2_m2m_ops { | ||
45 | void (*device_run)(void *priv); | ||
46 | int (*job_ready)(void *priv); | ||
47 | void (*job_abort)(void *priv); | ||
48 | }; | ||
49 | |||
50 | struct v4l2_m2m_dev; | ||
51 | |||
52 | struct v4l2_m2m_queue_ctx { | ||
53 | /* private: internal use only */ | ||
54 | struct videobuf_queue q; | ||
55 | |||
56 | /* Queue for buffers ready to be processed as soon as this | ||
57 | * instance receives access to the device */ | ||
58 | struct list_head rdy_queue; | ||
59 | u8 num_rdy; | ||
60 | }; | ||
61 | |||
62 | struct v4l2_m2m_ctx { | ||
63 | /* private: internal use only */ | ||
64 | struct v4l2_m2m_dev *m2m_dev; | ||
65 | |||
66 | /* Capture (output to memory) queue context */ | ||
67 | struct v4l2_m2m_queue_ctx cap_q_ctx; | ||
68 | |||
69 | /* Output (input from memory) queue context */ | ||
70 | struct v4l2_m2m_queue_ctx out_q_ctx; | ||
71 | |||
72 | /* For device job queue */ | ||
73 | struct list_head queue; | ||
74 | unsigned long job_flags; | ||
75 | |||
76 | /* Instance private data */ | ||
77 | void *priv; | ||
78 | }; | ||
79 | |||
80 | void *v4l2_m2m_get_curr_priv(struct v4l2_m2m_dev *m2m_dev); | ||
81 | |||
82 | struct videobuf_queue *v4l2_m2m_get_vq(struct v4l2_m2m_ctx *m2m_ctx, | ||
83 | enum v4l2_buf_type type); | ||
84 | |||
85 | void v4l2_m2m_job_finish(struct v4l2_m2m_dev *m2m_dev, | ||
86 | struct v4l2_m2m_ctx *m2m_ctx); | ||
87 | |||
88 | int v4l2_m2m_reqbufs(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, | ||
89 | struct v4l2_requestbuffers *reqbufs); | ||
90 | |||
91 | int v4l2_m2m_querybuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, | ||
92 | struct v4l2_buffer *buf); | ||
93 | |||
94 | int v4l2_m2m_qbuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, | ||
95 | struct v4l2_buffer *buf); | ||
96 | int v4l2_m2m_dqbuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, | ||
97 | struct v4l2_buffer *buf); | ||
98 | |||
99 | int v4l2_m2m_streamon(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, | ||
100 | enum v4l2_buf_type type); | ||
101 | int v4l2_m2m_streamoff(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, | ||
102 | enum v4l2_buf_type type); | ||
103 | |||
104 | unsigned int v4l2_m2m_poll(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, | ||
105 | struct poll_table_struct *wait); | ||
106 | |||
107 | int v4l2_m2m_mmap(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, | ||
108 | struct vm_area_struct *vma); | ||
109 | |||
110 | struct v4l2_m2m_dev *v4l2_m2m_init(struct v4l2_m2m_ops *m2m_ops); | ||
111 | void v4l2_m2m_release(struct v4l2_m2m_dev *m2m_dev); | ||
112 | |||
113 | struct v4l2_m2m_ctx *v4l2_m2m_ctx_init(void *priv, struct v4l2_m2m_dev *m2m_dev, | ||
114 | void (*vq_init)(void *priv, struct videobuf_queue *, | ||
115 | enum v4l2_buf_type)); | ||
116 | void v4l2_m2m_ctx_release(struct v4l2_m2m_ctx *m2m_ctx); | ||
117 | |||
118 | void v4l2_m2m_buf_queue(struct v4l2_m2m_ctx *m2m_ctx, struct videobuf_queue *vq, | ||
119 | struct videobuf_buffer *vb); | ||
120 | |||
121 | /** | ||
122 | * v4l2_m2m_num_src_bufs_ready() - return the number of source buffers ready for | ||
123 | * use | ||
124 | */ | ||
125 | static inline | ||
126 | unsigned int v4l2_m2m_num_src_bufs_ready(struct v4l2_m2m_ctx *m2m_ctx) | ||
127 | { | ||
128 | return m2m_ctx->cap_q_ctx.num_rdy; | ||
129 | } | ||
130 | |||
131 | /** | ||
132 | * v4l2_m2m_num_src_bufs_ready() - return the number of destination buffers | ||
133 | * ready for use | ||
134 | */ | ||
135 | static inline | ||
136 | unsigned int v4l2_m2m_num_dst_bufs_ready(struct v4l2_m2m_ctx *m2m_ctx) | ||
137 | { | ||
138 | return m2m_ctx->out_q_ctx.num_rdy; | ||
139 | } | ||
140 | |||
141 | void *v4l2_m2m_next_buf(struct v4l2_m2m_ctx *m2m_ctx, enum v4l2_buf_type type); | ||
142 | |||
143 | /** | ||
144 | * v4l2_m2m_next_src_buf() - return next source buffer from the list of ready | ||
145 | * buffers | ||
146 | */ | ||
147 | static inline void *v4l2_m2m_next_src_buf(struct v4l2_m2m_ctx *m2m_ctx) | ||
148 | { | ||
149 | return v4l2_m2m_next_buf(m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); | ||
150 | } | ||
151 | |||
152 | /** | ||
153 | * v4l2_m2m_next_dst_buf() - return next destination buffer from the list of | ||
154 | * ready buffers | ||
155 | */ | ||
156 | static inline void *v4l2_m2m_next_dst_buf(struct v4l2_m2m_ctx *m2m_ctx) | ||
157 | { | ||
158 | return v4l2_m2m_next_buf(m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); | ||
159 | } | ||
160 | |||
161 | /** | ||
162 | * v4l2_m2m_get_src_vq() - return videobuf_queue for source buffers | ||
163 | */ | ||
164 | static inline | ||
165 | struct videobuf_queue *v4l2_m2m_get_src_vq(struct v4l2_m2m_ctx *m2m_ctx) | ||
166 | { | ||
167 | return v4l2_m2m_get_vq(m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); | ||
168 | } | ||
169 | |||
170 | /** | ||
171 | * v4l2_m2m_get_dst_vq() - return videobuf_queue for destination buffers | ||
172 | */ | ||
173 | static inline | ||
174 | struct videobuf_queue *v4l2_m2m_get_dst_vq(struct v4l2_m2m_ctx *m2m_ctx) | ||
175 | { | ||
176 | return v4l2_m2m_get_vq(m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); | ||
177 | } | ||
178 | |||
179 | void *v4l2_m2m_buf_remove(struct v4l2_m2m_ctx *m2m_ctx, | ||
180 | enum v4l2_buf_type type); | ||
181 | |||
182 | /** | ||
183 | * v4l2_m2m_src_buf_remove() - take off a source buffer from the list of ready | ||
184 | * buffers and return it | ||
185 | */ | ||
186 | static inline void *v4l2_m2m_src_buf_remove(struct v4l2_m2m_ctx *m2m_ctx) | ||
187 | { | ||
188 | return v4l2_m2m_buf_remove(m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); | ||
189 | } | ||
190 | |||
191 | /** | ||
192 | * v4l2_m2m_dst_buf_remove() - take off a destination buffer from the list of | ||
193 | * ready buffers and return it | ||
194 | */ | ||
195 | static inline void *v4l2_m2m_dst_buf_remove(struct v4l2_m2m_ctx *m2m_ctx) | ||
196 | { | ||
197 | return v4l2_m2m_buf_remove(m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); | ||
198 | } | ||
199 | |||
200 | #endif /* _MEDIA_V4L2_MEM2MEM_H */ | ||
201 | |||