Mercurial > mplayer.hg
annotate libvo/vo_matrixview.c @ 36327:797bbffdd112
vo png: Switch to avcodec_encode_video2
The older function is deprecated and the newer function seems to not
have the minimum buffer size limitation.
Patch by Jiang Jiang >gzjjgod at gmail com<
author | al |
---|---|
date | Wed, 14 Aug 2013 10:16:46 +0000 |
parents | 406e87858d1f |
children | 5d3f93051de9 |
rev | line source |
---|---|
30140 | 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> | |
35903 | 28 #include <strings.h> |
30140 | 29 |
30 #include "mp_msg.h" | |
31 #include "subopt-helper.h" | |
32 #include "video_out.h" | |
33 #include "video_out_internal.h" | |
33301
899d817e56fc
Implement control() VOCTRL_SET/GET_EQUALIZER using a vf_equalize struct,
iive
parents:
30925
diff
changeset
|
34 #include "libmpcodecs/vf.h" |
30140 | 35 #include "gl_common.h" |
36 #include "libswscale/swscale.h" | |
37 #include "libmpcodecs/vf_scale.h" | |
38 #include "osdep/timer.h" | |
39 | |
40 #include "matrixview.h" | |
41 | |
30153 | 42 static const vo_info_t info = { |
30140 | 43 "MatrixView (OpenGL)", |
44 "matrixview", | |
45 "Pigeon <pigeon@pigeond.net>", | |
46 "Based on MatrixView from rss-glx.sf.net" | |
47 }; | |
48 | |
30925
f8939d5b14b5
Mark some more LIBVO_EXTERN declarations as const where possible.
reimar
parents:
30633
diff
changeset
|
49 const LIBVO_EXTERN(matrixview) |
30140 | 50 |
51 static MPGLContext glctx; | |
52 | |
53 static int eq_contrast; | |
54 static int eq_brightness; | |
55 static uint32_t image_width; | |
56 static uint32_t image_height; | |
57 static uint32_t image_format; | |
58 static struct SwsContext *sws; | |
59 | |
60 static uint8_t *map_image[MP_MAX_PLANES]; | |
61 static int map_stride[MP_MAX_PLANES]; | |
62 | |
63 #define DEFAULT_MATRIX_ROWS 96 | |
64 #define DEFAULT_MATRIX_COLS 128 | |
65 static int matrix_rows; | |
66 static int matrix_cols; | |
67 | |
68 #define DEFAULT_CONTRAST 0.90f | |
69 #define CONTRAST_MULTIPLIER 0.02f | |
70 | |
71 #define DEFAULT_BRIGHTNESS 1.0f | |
72 #define BRIGHTNESS_MULTIPLIER 0.02f | |
73 | |
74 | |
75 static void contrast_set(int value) | |
76 { | |
77 float contrast = value * CONTRAST_MULTIPLIER + DEFAULT_CONTRAST; | |
78 eq_contrast = value; | |
30153 | 79 if (contrast < 0) |
80 contrast = 0; | |
30140 | 81 matrixview_contrast_set(contrast); |
82 } | |
83 | |
84 | |
85 static void brightness_set(int value) | |
86 { | |
87 float brightness = value * BRIGHTNESS_MULTIPLIER + DEFAULT_BRIGHTNESS; | |
88 eq_brightness = value; | |
30153 | 89 if (brightness < 0) |
90 brightness = 0; | |
30140 | 91 matrixview_brightness_set(brightness); |
92 } | |
93 | |
36229 | 94 static void resize(void) |
95 { | |
96 matrixview_reshape(vo_dwidth, vo_dheight); | |
97 flip_page(); | |
98 } | |
30140 | 99 |
30153 | 100 static int config(uint32_t width, uint32_t height, |
101 uint32_t d_width, uint32_t d_height, | |
102 uint32_t flags, char *title, uint32_t format) | |
30140 | 103 { |
104 image_height = height; | |
30153 | 105 image_width = width; |
30140 | 106 image_format = format; |
107 | |
36219 | 108 if (mpglcontext_create_window(&glctx, d_width, d_height, flags, title) < 0) |
30153 | 109 return -1; |
30140 | 110 if (glctx.setGlWindow(&glctx) == SET_WINDOW_FAILED) |
111 return -1; | |
112 | |
30153 | 113 if (sws) |
30140 | 114 sws_freeContext(sws); |
115 | |
30153 | 116 sws = sws_getContextFromCmdLine(image_width, image_height, image_format, |
117 matrix_cols, matrix_rows, IMGFMT_Y8); | |
30140 | 118 if (!sws) { |
119 mp_msg(MSGT_VO, MSGL_ERR, "[matrixview] Cannot create SwsContext context\n"); | |
120 return -1; | |
121 } | |
122 | |
30153 | 123 if (!map_image[0]) |
30140 | 124 map_image[0] = calloc(matrix_cols, matrix_rows); |
125 | |
126 map_stride[0] = matrix_cols; | |
127 | |
128 matrixview_init(vo_dwidth, vo_dheight); | |
129 matrixview_matrix_resize(matrix_cols, matrix_rows); | |
130 | |
131 contrast_set(eq_contrast); | |
132 brightness_set(eq_brightness); | |
133 matrixview_reshape(vo_dwidth, vo_dheight); | |
36229 | 134 |
135 #ifdef CONFIG_GL_OSX | |
136 vo_osx_redraw_func = resize; | |
137 #endif | |
30140 | 138 return 0; |
139 } | |
140 | |
141 | |
142 static void check_events(void) | |
143 { | |
30153 | 144 int e = glctx.check_events(); |
145 if (e & VO_EVENT_RESIZE) { | |
36229 | 146 resize(); |
36230 | 147 } else if (e & VO_EVENT_EXPOSE) |
30153 | 148 flip_page(); |
30140 | 149 } |
150 | |
151 | |
152 static void draw_osd(void) | |
153 { | |
154 return; | |
155 } | |
156 | |
157 | |
158 static void flip_page(void) | |
159 { | |
36227 | 160 matrixview_draw(GetTimer(), map_image[0]); |
36226 | 161 // Needed at least on PPC Mac Mini on OSX. Should not hurt |
162 // much to do always. | |
163 mpglFlush(); | |
30140 | 164 glctx.swapGlBuffers(&glctx); |
165 } | |
166 | |
167 | |
168 | |
169 static int draw_slice(uint8_t *src[], int stride[], int w, int h, int x, int y) | |
170 { | |
171 sws_scale(sws, src, stride, y, h, map_image, map_stride); | |
172 return 0; | |
173 } | |
174 | |
175 | |
176 static int draw_frame(uint8_t *src[]) | |
177 { | |
178 return 0; | |
179 } | |
180 | |
181 | |
182 static int query_format(uint32_t format) | |
183 { | |
184 int caps = VFCAP_CSP_SUPPORTED | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN | VFCAP_ACCEPT_STRIDE; | |
185 | |
30153 | 186 switch (format) { |
187 case IMGFMT_YV12: | |
188 case IMGFMT_BGR32: | |
189 case IMGFMT_BGR24: | |
190 case IMGFMT_BGR16: | |
191 case IMGFMT_BGR15: | |
192 case IMGFMT_RGB32: | |
193 case IMGFMT_RGB24: | |
194 return caps; | |
195 default: | |
196 break; | |
30140 | 197 } |
198 | |
199 return 0; | |
200 } | |
201 | |
202 | |
203 static void uninit(void) | |
204 { | |
30153 | 205 if (!vo_config_count) |
206 return; | |
30140 | 207 uninit_mpglcontext(&glctx); |
208 free(map_image[0]); | |
209 map_image[0] = NULL; | |
210 sws_freeContext(sws); | |
211 sws = NULL; | |
212 } | |
213 | |
214 | |
215 static const opt_t subopts[] = | |
216 { | |
30153 | 217 { "rows", OPT_ARG_INT, &matrix_rows, int_pos }, |
218 { "cols", OPT_ARG_INT, &matrix_cols, int_pos }, | |
30140 | 219 { NULL } |
220 }; | |
221 | |
222 | |
223 static int preinit(const char *arg) | |
224 { | |
36219 | 225 enum MPGLType gltype = GLTYPE_AUTO; |
30153 | 226 if (!init_mpglcontext(&glctx, gltype)) |
227 return -1; | |
30140 | 228 |
229 matrix_rows = DEFAULT_MATRIX_ROWS; | |
230 matrix_cols = DEFAULT_MATRIX_COLS; | |
231 | |
30153 | 232 if (subopt_parse(arg, subopts) != 0) { |
30140 | 233 mp_msg(MSGT_VO, MSGL_FATAL, |
234 "\n-vo matrixview command line help:\n" | |
235 "Example: mplayer -vo matrixview:cols=320:rows=240\n" | |
236 "\n" | |
237 "Options:\n" | |
238 "\n" | |
239 " cols=<12-320>\n" | |
240 " Specify the number of columns of the matrix view, default %d\n" | |
241 "\n" | |
242 " rows=<12-240>\n" | |
243 " Specify the number of rows of the matrix view, default %d\n" | |
244 "\n" | |
245 , | |
246 DEFAULT_MATRIX_COLS, DEFAULT_MATRIX_ROWS | |
247 ); | |
248 return -1; | |
249 } | |
250 | |
251 return 0; | |
252 } | |
253 | |
254 | |
33305
ddb45e9443ec
Remove the variable arguments from the libvo control() functions.
iive
parents:
33301
diff
changeset
|
255 static int control(uint32_t request, void *data) |
30140 | 256 { |
257 switch (request) { | |
258 case VOCTRL_QUERY_FORMAT: | |
259 return query_format(*(uint32_t*)data); | |
260 case VOCTRL_ONTOP: | |
261 glctx.ontop(); | |
262 return VO_TRUE; | |
263 case VOCTRL_FULLSCREEN: | |
264 glctx.fullscreen(); | |
36229 | 265 resize(); |
30140 | 266 return VO_TRUE; |
267 case VOCTRL_BORDER: | |
268 glctx.border(); | |
269 return VO_TRUE; | |
270 case VOCTRL_GET_EQUALIZER: | |
271 { | |
33301
899d817e56fc
Implement control() VOCTRL_SET/GET_EQUALIZER using a vf_equalize struct,
iive
parents:
30925
diff
changeset
|
272 vf_equalizer_t *eq=data; |
899d817e56fc
Implement control() VOCTRL_SET/GET_EQUALIZER using a vf_equalize struct,
iive
parents:
30925
diff
changeset
|
273 |
899d817e56fc
Implement control() VOCTRL_SET/GET_EQUALIZER using a vf_equalize struct,
iive
parents:
30925
diff
changeset
|
274 if (strcasecmp(eq->item, "contrast") == 0) { |
899d817e56fc
Implement control() VOCTRL_SET/GET_EQUALIZER using a vf_equalize struct,
iive
parents:
30925
diff
changeset
|
275 eq->value = eq_contrast; |
899d817e56fc
Implement control() VOCTRL_SET/GET_EQUALIZER using a vf_equalize struct,
iive
parents:
30925
diff
changeset
|
276 } else if (strcasecmp(eq->item, "brightness") == 0) { |
899d817e56fc
Implement control() VOCTRL_SET/GET_EQUALIZER using a vf_equalize struct,
iive
parents:
30925
diff
changeset
|
277 eq->value = eq_brightness; |
30140 | 278 } |
279 } | |
280 return VO_TRUE; | |
281 case VOCTRL_SET_EQUALIZER: | |
282 { | |
33301
899d817e56fc
Implement control() VOCTRL_SET/GET_EQUALIZER using a vf_equalize struct,
iive
parents:
30925
diff
changeset
|
283 vf_equalizer_t *eq=data; |
899d817e56fc
Implement control() VOCTRL_SET/GET_EQUALIZER using a vf_equalize struct,
iive
parents:
30925
diff
changeset
|
284 if (strcasecmp(eq->item, "contrast") == 0) { |
899d817e56fc
Implement control() VOCTRL_SET/GET_EQUALIZER using a vf_equalize struct,
iive
parents:
30925
diff
changeset
|
285 contrast_set(eq->value); |
899d817e56fc
Implement control() VOCTRL_SET/GET_EQUALIZER using a vf_equalize struct,
iive
parents:
30925
diff
changeset
|
286 } else if (strcasecmp(eq->item, "brightness") == 0) { |
899d817e56fc
Implement control() VOCTRL_SET/GET_EQUALIZER using a vf_equalize struct,
iive
parents:
30925
diff
changeset
|
287 brightness_set(eq->value); |
30140 | 288 } |
289 } | |
290 return VO_TRUE; | |
291 case VOCTRL_UPDATE_SCREENINFO: | |
292 glctx.update_xinerama_info(); | |
293 return VO_TRUE; | |
294 } | |
295 return VO_NOTIMPL; | |
296 } |