comparison libvo/vo_matrixview.c @ 30140:12a49e9ca30e

Finally add matrixview vo. Heavily cleaned up/fixed etc. by me, improvements are still possible though. Patch originally by Pigeon <pigeon at pigeond.net>
author reimar
date Sun, 03 Jan 2010 14:54:51 +0000
parents
children 4e0755091f55
comparison
equal deleted inserted replaced
30139:47b031706571 30140:12a49e9ca30e
1 /*
2 * MatrixView video output driver for MPlayer
3 *
4 * by Pigeon <pigeon at pigeond.net>
5 *
6 * Based on MatrixView the screensaver from http://rss-glx.sf.net/
7 *
8 * This file is part of MPlayer.
9 *
10 * MPlayer is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * MPlayer is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 */
24
25 #include "config.h"
26
27 #include <stdint.h>
28
29 #include "mp_msg.h"
30 #include "subopt-helper.h"
31 #include "video_out.h"
32 #include "video_out_internal.h"
33 #include "gl_common.h"
34 #include "libswscale/swscale.h"
35 #include "libmpcodecs/vf_scale.h"
36 #include "osdep/timer.h"
37
38 #include "matrixview.h"
39
40 static const vo_info_t info =
41 {
42 "MatrixView (OpenGL)",
43 "matrixview",
44 "Pigeon <pigeon@pigeond.net>",
45 "Based on MatrixView from rss-glx.sf.net"
46 };
47
48 LIBVO_EXTERN(matrixview)
49
50 static MPGLContext glctx;
51
52 #ifdef CONFIG_GL_X11
53 static int wsGLXAttrib[] = {
54 GLX_RGBA,
55 GLX_RED_SIZE,1,
56 GLX_GREEN_SIZE,1,
57 GLX_BLUE_SIZE,1,
58 GLX_DEPTH_SIZE,1,
59 GLX_DOUBLEBUFFER,
60 None
61 };
62 #endif
63
64 static int int_pause;
65 static int eq_contrast;
66 static int eq_brightness;
67 static uint32_t image_width;
68 static uint32_t image_height;
69 static uint32_t image_format;
70 static struct SwsContext *sws;
71
72 static uint8_t *map_image[MP_MAX_PLANES];
73 static int map_stride[MP_MAX_PLANES];
74
75 #define DEFAULT_MATRIX_ROWS 96
76 #define DEFAULT_MATRIX_COLS 128
77 static int matrix_rows;
78 static int matrix_cols;
79
80 #define DEFAULT_CONTRAST 0.90f
81 #define CONTRAST_MULTIPLIER 0.02f
82
83 #define DEFAULT_BRIGHTNESS 1.0f
84 #define BRIGHTNESS_MULTIPLIER 0.02f
85
86
87 static void contrast_set(int value)
88 {
89 float contrast = value * CONTRAST_MULTIPLIER + DEFAULT_CONTRAST;
90 eq_contrast = value;
91 if (contrast < 0) contrast = 0;
92 matrixview_contrast_set(contrast);
93 }
94
95
96 static void brightness_set(int value)
97 {
98 float brightness = value * BRIGHTNESS_MULTIPLIER + DEFAULT_BRIGHTNESS;
99 eq_brightness = value;
100 if (brightness < 0) brightness = 0;
101 matrixview_brightness_set(brightness);
102 }
103
104
105 static int
106 config(uint32_t width, uint32_t height,
107 uint32_t d_width, uint32_t d_height,
108 uint32_t flags, char *title, uint32_t format)
109 {
110 image_height = height;
111 image_width = width;
112 image_format = format;
113
114 int_pause = 0;
115
116 #ifdef CONFIG_GL_WIN32
117 if (glctx.type == GLTYPE_W32 && !vo_w32_config(d_width, d_height, flags))
118 return -1;
119 #endif
120 #ifdef CONFIG_GL_X11
121 if (glctx.type == GLTYPE_X11) {
122 XVisualInfo *vinfo=glXChooseVisual( mDisplay,mScreen,wsGLXAttrib );
123 if (vinfo == NULL)
124 {
125 mp_msg(MSGT_VO, MSGL_ERR, "[matrixview] no GLX support present\n");
126 return -1;
127 }
128 mp_msg(MSGT_VO, MSGL_V, "[matrixview] GLX chose visual with ID 0x%x\n", (int)vinfo->visualid);
129
130 vo_x11_create_vo_window(vinfo, vo_dx, vo_dy, d_width, d_height, flags,
131 XCreateColormap(mDisplay, mRootWin, vinfo->visual, AllocNone),
132 "matrixview", title);
133 }
134 #endif /* CONFIG_GL_WIN32 */
135 if (glctx.setGlWindow(&glctx) == SET_WINDOW_FAILED)
136 return -1;
137
138 if(sws)
139 sws_freeContext(sws);
140
141 sws = sws_getContextFromCmdLine(image_width, image_height, image_format, matrix_cols, matrix_rows, IMGFMT_Y8);
142 if (!sws) {
143 mp_msg(MSGT_VO, MSGL_ERR, "[matrixview] Cannot create SwsContext context\n");
144 return -1;
145 }
146
147 if(!map_image[0])
148 map_image[0] = calloc(matrix_cols, matrix_rows);
149
150 map_stride[0] = matrix_cols;
151
152 matrixview_init(vo_dwidth, vo_dheight);
153 matrixview_matrix_resize(matrix_cols, matrix_rows);
154
155 contrast_set(eq_contrast);
156 brightness_set(eq_brightness);
157 matrixview_reshape(vo_dwidth, vo_dheight);
158 return 0;
159 }
160
161
162 static void check_events(void)
163 {
164 int e=glctx.check_events();
165 if(e & VO_EVENT_RESIZE) {
166 matrixview_reshape(vo_dwidth, vo_dheight);
167 }
168 if(e & VO_EVENT_EXPOSE && int_pause) flip_page();
169 }
170
171
172 static void draw_osd(void)
173 {
174 return;
175 }
176
177
178 static void flip_page(void)
179 {
180 matrixview_draw(vo_dwidth, vo_dheight, GetTimer(), 0.0, map_image[0]);
181 glctx.swapGlBuffers(&glctx);
182 }
183
184
185
186 static int draw_slice(uint8_t *src[], int stride[], int w, int h, int x, int y)
187 {
188 sws_scale(sws, src, stride, y, h, map_image, map_stride);
189 return 0;
190 }
191
192
193 static int draw_frame(uint8_t *src[])
194 {
195 return 0;
196 }
197
198
199 static int query_format(uint32_t format)
200 {
201 int caps = VFCAP_CSP_SUPPORTED | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN | VFCAP_ACCEPT_STRIDE;
202
203 switch(format) {
204 case IMGFMT_YV12:
205 case IMGFMT_BGR32:
206 case IMGFMT_BGR24:
207 case IMGFMT_BGR16:
208 case IMGFMT_BGR15:
209 case IMGFMT_RGB32:
210 case IMGFMT_RGB24:
211 case IMGFMT_ARGB:
212 return caps;
213 default:
214 break;
215 }
216
217 return 0;
218 }
219
220
221 static void uninit(void)
222 {
223 if (!vo_config_count) return;
224 uninit_mpglcontext(&glctx);
225 free(map_image[0]);
226 map_image[0] = NULL;
227 sws_freeContext(sws);
228 sws = NULL;
229 }
230
231
232 static const opt_t subopts[] =
233 {
234 { "rows", OPT_ARG_INT, &matrix_rows, int_pos },
235 { "cols", OPT_ARG_INT, &matrix_cols, int_pos },
236 { NULL }
237 };
238
239
240 static int preinit(const char *arg)
241 {
242 enum MPGLType gltype = GLTYPE_X11;
243 #ifdef CONFIG_GL_WIN32
244 gltype = GLTYPE_W32;
245 #endif
246 if(!init_mpglcontext(&glctx, gltype)) return -1;
247
248 matrix_rows = DEFAULT_MATRIX_ROWS;
249 matrix_cols = DEFAULT_MATRIX_COLS;
250
251 if(subopt_parse(arg, subopts) != 0) {
252 mp_msg(MSGT_VO, MSGL_FATAL,
253 "\n-vo matrixview command line help:\n"
254 "Example: mplayer -vo matrixview:cols=320:rows=240\n"
255 "\n"
256 "Options:\n"
257 "\n"
258 " cols=<12-320>\n"
259 " Specify the number of columns of the matrix view, default %d\n"
260 "\n"
261 " rows=<12-240>\n"
262 " Specify the number of rows of the matrix view, default %d\n"
263 "\n"
264 ,
265 DEFAULT_MATRIX_COLS, DEFAULT_MATRIX_ROWS
266 );
267 return -1;
268 }
269
270 return 0;
271 }
272
273
274 static int control(uint32_t request, void *data, ...)
275 {
276 switch (request) {
277 case VOCTRL_PAUSE:
278 case VOCTRL_RESUME:
279 int_pause = (request == VOCTRL_PAUSE);
280 return VO_TRUE;
281 case VOCTRL_QUERY_FORMAT:
282 return query_format(*(uint32_t*)data);
283 case VOCTRL_ONTOP:
284 glctx.ontop();
285 return VO_TRUE;
286 case VOCTRL_FULLSCREEN:
287 glctx.fullscreen();
288 matrixview_reshape(vo_dwidth, vo_dheight);
289 return VO_TRUE;
290 case VOCTRL_BORDER:
291 glctx.border();
292 return VO_TRUE;
293 case VOCTRL_GET_EQUALIZER:
294 {
295 va_list va;
296 int *value;
297 va_start(va, data);
298 value = va_arg(va, int *);
299 va_end(va);
300 if (strcasecmp(data, "contrast") == 0)
301 {
302 *value = eq_contrast;
303 }
304 else if (strcasecmp(data, "brightness") == 0)
305 {
306 *value = eq_brightness;
307 }
308 }
309 return VO_TRUE;
310 case VOCTRL_SET_EQUALIZER:
311 {
312 va_list va;
313 int value;
314 va_start(va, data);
315 value = va_arg(va, int);
316 va_end(va);
317 if (strcasecmp(data, "contrast") == 0)
318 {
319 contrast_set(value);
320 }
321 else if (strcasecmp(data, "brightness") == 0)
322 {
323 brightness_set(value);
324 }
325 }
326 return VO_TRUE;
327 case VOCTRL_UPDATE_SCREENINFO:
328 glctx.update_xinerama_info();
329 return VO_TRUE;
330 }
331 return VO_NOTIMPL;
332 }
333