Mercurial > mplayer.hg
annotate libmenu/vf_menu.c @ 28481:b78c8cb3959b
partial sync with obsolete section removal
author | diego |
---|---|
date | Tue, 10 Feb 2009 00:23:50 +0000 |
parents | f8b6c7045cf8 |
children | df67d03dde3b |
rev | line source |
---|---|
28113 | 1 /* |
2 * This file is part of MPlayer. | |
3 * | |
4 * MPlayer is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; either version 2 of the License, or | |
7 * (at your option) any later version. | |
8 * | |
9 * MPlayer is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU General Public License along | |
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., | |
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
17 */ | |
8197 | 18 |
16862 | 19 #include "config.h" |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17945
diff
changeset
|
20 #include "mp_msg.h" |
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17945
diff
changeset
|
21 #include "help_mp.h" |
8197 | 22 |
23 #include <stdio.h> | |
24 #include <stdlib.h> | |
25 #include <string.h> | |
26 | |
8623
440301fef3fe
Added/reordered #includes to silence warnings about "implicit declaration".
rathann
parents:
8251
diff
changeset
|
27 #ifdef HAVE_MALLOC_H |
440301fef3fe
Added/reordered #includes to silence warnings about "implicit declaration".
rathann
parents:
8251
diff
changeset
|
28 #include <malloc.h> |
440301fef3fe
Added/reordered #includes to silence warnings about "implicit declaration".
rathann
parents:
8251
diff
changeset
|
29 #endif |
8197 | 30 |
23338
2a66d95355f0
add new -subfont option, that allows having a different font for OSD (controls and menu) and subtitles
ben
parents:
22284
diff
changeset
|
31 #include "mplayer.h" |
16862 | 32 #include "mp_msg.h" |
8197 | 33 |
16862 | 34 #include "libmpcodecs/img_format.h" |
35 #include "libmpcodecs/mp_image.h" | |
36 #include "libmpcodecs/vf.h" | |
8197 | 37 |
16862 | 38 #include "libvo/fastmemcpy.h" |
39 #include "libvo/video_out.h" | |
40 #include "libvo/font_load.h" | |
25026
afead6ecb8ba
Remove the pause filter and the cmd queue hack, to know the mplayer going to
ulion
parents:
24960
diff
changeset
|
41 #include "libvo/sub.h" |
16862 | 42 #include "input/input.h" |
43 #include "m_struct.h" | |
8197 | 44 #include "menu.h" |
22284 | 45 #include "access_mpcontext.h" |
8197 | 46 |
47 | |
48 static struct vf_priv_s* st_priv = NULL; | |
49 | |
50 static mp_image_t* pause_mpi = NULL; | |
51 static int go2pause = 0; | |
13344
0d96af97ec00
option to display menu at startup, patch by Aurelien Jacobs <aurel at gnuage.org>
faust3
parents:
10397
diff
changeset
|
52 /// if nonzero display menu at startup |
27746
38fbba4327fa
Remove pointless attribute_used from variable declaration.
diego
parents:
27393
diff
changeset
|
53 int menu_startup = 0; |
8197 | 54 |
55 struct vf_priv_s { | |
56 menu_t* root; | |
57 menu_t* current; | |
21803
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
58 int passthrough; |
8197 | 59 }; |
60 | |
17908 | 61 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts); |
8197 | 62 |
63 void vf_menu_pause_update(struct vf_instance_s* vf) { | |
25219
e82ecde2cbd4
Mark several uses of vo_functions_t as const to stop some of the current
reimar
parents:
25026
diff
changeset
|
64 const vo_functions_t *video_out = mpctx_get_video_out(vf->priv->current->ctx); |
8197 | 65 if(pause_mpi) { |
17908 | 66 put_image(vf,pause_mpi, MP_NOPTS_VALUE); |
8197 | 67 // Don't draw the osd atm |
68 //vf->control(vf,VFCTRL_DRAW_OSD,NULL); | |
69 video_out->flip_page(); | |
70 } | |
71 } | |
72 | |
73 static int cmd_filter(mp_cmd_t* cmd, int paused, struct vf_priv_s * priv) { | |
74 | |
75 switch(cmd->id) { | |
76 case MP_CMD_MENU : { // Convert txt cmd from the users into libmenu stuff | |
77 char* arg = cmd->args[0].v.s; | |
78 | |
25496 | 79 if (!priv->current->show && strcmp(arg,"hide")) |
8197 | 80 priv->current->show = 1; |
81 else if(strcmp(arg,"up") == 0) | |
82 menu_read_cmd(priv->current,MENU_CMD_UP); | |
83 else if(strcmp(arg,"down") == 0) | |
84 menu_read_cmd(priv->current,MENU_CMD_DOWN); | |
17945
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
17908
diff
changeset
|
85 else if(strcmp(arg,"left") == 0) |
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
17908
diff
changeset
|
86 menu_read_cmd(priv->current,MENU_CMD_LEFT); |
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
17908
diff
changeset
|
87 else if(strcmp(arg,"right") == 0) |
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
17908
diff
changeset
|
88 menu_read_cmd(priv->current,MENU_CMD_RIGHT); |
8197 | 89 else if(strcmp(arg,"ok") == 0) |
90 menu_read_cmd(priv->current,MENU_CMD_OK); | |
91 else if(strcmp(arg,"cancel") == 0) | |
92 menu_read_cmd(priv->current,MENU_CMD_CANCEL); | |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25219
diff
changeset
|
93 else if(strcmp(arg,"home") == 0) |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25219
diff
changeset
|
94 menu_read_cmd(priv->current,MENU_CMD_HOME); |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25219
diff
changeset
|
95 else if(strcmp(arg,"end") == 0) |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25219
diff
changeset
|
96 menu_read_cmd(priv->current,MENU_CMD_END); |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25219
diff
changeset
|
97 else if(strcmp(arg,"pageup") == 0) |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25219
diff
changeset
|
98 menu_read_cmd(priv->current,MENU_CMD_PAGE_UP); |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25219
diff
changeset
|
99 else if(strcmp(arg,"pagedown") == 0) |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25219
diff
changeset
|
100 menu_read_cmd(priv->current,MENU_CMD_PAGE_DOWN); |
25461 | 101 else if(strcmp(arg,"click") == 0) |
102 menu_read_cmd(priv->current,MENU_CMD_CLICK); | |
19489 | 103 else if(strcmp(arg,"hide") == 0 || strcmp(arg,"toggle") == 0) |
8197 | 104 priv->current->show = 0; |
105 else | |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17945
diff
changeset
|
106 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_UnknownMenuCommand,arg); |
8197 | 107 return 1; |
108 } | |
109 case MP_CMD_SET_MENU : { | |
110 char* menu = cmd->args[0].v.s; | |
111 menu_t* l = priv->current; | |
112 priv->current = menu_open(menu); | |
113 if(!priv->current) { | |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17945
diff
changeset
|
114 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_FailedToOpenMenu,menu); |
8197 | 115 priv->current = l; |
116 priv->current->show = 0; | |
117 } else { | |
118 priv->current->show = 1; | |
119 priv->current->parent = l; | |
120 } | |
121 return 1; | |
122 } | |
123 } | |
124 return 0; | |
125 } | |
126 | |
127 static void get_image(struct vf_instance_s* vf, mp_image_t *mpi){ | |
128 mp_image_t *dmpi; | |
129 | |
130 if(mpi->type == MP_IMGTYPE_TEMP && (!(mpi->flags&MP_IMGFLAG_PRESERVE)) ) { | |
131 dmpi = vf_get_image(vf->next,mpi->imgfmt,mpi->type, mpi->flags, mpi->w, mpi->h); | |
23458
973e53dc7df5
Do not use fast_memcpy for small size copy, esp. when the size is constant
reimar
parents:
23457
diff
changeset
|
132 memcpy(mpi->planes,dmpi->planes,MP_MAX_PLANES*sizeof(unsigned char*)); |
973e53dc7df5
Do not use fast_memcpy for small size copy, esp. when the size is constant
reimar
parents:
23457
diff
changeset
|
133 memcpy(mpi->stride,dmpi->stride,MP_MAX_PLANES*sizeof(unsigned int)); |
8197 | 134 mpi->flags|=MP_IMGFLAG_DIRECT; |
135 mpi->priv=(void*)dmpi; | |
136 return; | |
137 } | |
138 } | |
139 | |
25502
605d4e3e403f
From now on, libmenu does not steal all input keys from input modules.
ulion
parents:
25496
diff
changeset
|
140 static int key_cb(int code) { |
605d4e3e403f
From now on, libmenu does not steal all input keys from input modules.
ulion
parents:
25496
diff
changeset
|
141 return menu_read_key(st_priv->current,code); |
8197 | 142 } |
143 | |
17908 | 144 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){ |
8197 | 145 mp_image_t *dmpi = NULL; |
146 | |
21803
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
147 if (vf->priv->passthrough) { |
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
148 dmpi=vf_get_image(vf->next, IMGFMT_MPEGPES, MP_IMGTYPE_EXPORT, |
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
149 0, mpi->w, mpi->h); |
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
150 dmpi->planes[0]=mpi->planes[0]; |
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
151 return vf_next_put_image(vf,dmpi, pts); |
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
152 } |
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
153 |
8197 | 154 // Close all menu who requested it |
155 while(vf->priv->current->cl && vf->priv->current != vf->priv->root) { | |
156 menu_t* m = vf->priv->current; | |
157 vf->priv->current = m->parent ? m->parent : vf->priv->root; | |
158 menu_close(m); | |
159 } | |
160 | |
25026
afead6ecb8ba
Remove the pause filter and the cmd queue hack, to know the mplayer going to
ulion
parents:
24960
diff
changeset
|
161 // Try to capture the last frame before pause, or fallback to use |
afead6ecb8ba
Remove the pause filter and the cmd queue hack, to know the mplayer going to
ulion
parents:
24960
diff
changeset
|
162 // last captured frame. |
8197 | 163 if(pause_mpi && (mpi->w != pause_mpi->w || mpi->h != pause_mpi->h || |
164 mpi->imgfmt != pause_mpi->imgfmt)) { | |
165 free_mp_image(pause_mpi); | |
166 pause_mpi = NULL; | |
167 } | |
25026
afead6ecb8ba
Remove the pause filter and the cmd queue hack, to know the mplayer going to
ulion
parents:
24960
diff
changeset
|
168 if (!pause_mpi) { |
afead6ecb8ba
Remove the pause filter and the cmd queue hack, to know the mplayer going to
ulion
parents:
24960
diff
changeset
|
169 pause_mpi = alloc_mpi(mpi->w,mpi->h,mpi->imgfmt); |
8197 | 170 copy_mpi(pause_mpi,mpi); |
171 } | |
25026
afead6ecb8ba
Remove the pause filter and the cmd queue hack, to know the mplayer going to
ulion
parents:
24960
diff
changeset
|
172 else if (mpctx_get_osd_function(vf->priv->root->ctx) == OSD_PAUSE) |
afead6ecb8ba
Remove the pause filter and the cmd queue hack, to know the mplayer going to
ulion
parents:
24960
diff
changeset
|
173 copy_mpi(pause_mpi,mpi); |
8197 | 174 |
25026
afead6ecb8ba
Remove the pause filter and the cmd queue hack, to know the mplayer going to
ulion
parents:
24960
diff
changeset
|
175 if (vf->priv->current->show) { |
afead6ecb8ba
Remove the pause filter and the cmd queue hack, to know the mplayer going to
ulion
parents:
24960
diff
changeset
|
176 if (!mp_input_key_cb) |
afead6ecb8ba
Remove the pause filter and the cmd queue hack, to know the mplayer going to
ulion
parents:
24960
diff
changeset
|
177 mp_input_key_cb = key_cb; |
8197 | 178 |
179 if(mpi->flags&MP_IMGFLAG_DIRECT) | |
180 dmpi = mpi->priv; | |
181 else { | |
182 dmpi = vf_get_image(vf->next,mpi->imgfmt, | |
183 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, | |
184 mpi->w,mpi->h); | |
185 copy_mpi(dmpi,mpi); | |
186 } | |
187 menu_draw(vf->priv->current,dmpi); | |
188 | |
8244
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
189 } else { |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
190 if(mp_input_key_cb) |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
191 mp_input_key_cb = NULL; |
21924
422eef67d14a
speeds up mplayer execution by over FIVE times when all of the of the following apply:
gpoirier
parents:
21818
diff
changeset
|
192 |
422eef67d14a
speeds up mplayer execution by over FIVE times when all of the of the following apply:
gpoirier
parents:
21818
diff
changeset
|
193 if(mpi->flags&MP_IMGFLAG_DIRECT) |
422eef67d14a
speeds up mplayer execution by over FIVE times when all of the of the following apply:
gpoirier
parents:
21818
diff
changeset
|
194 dmpi = mpi->priv; |
422eef67d14a
speeds up mplayer execution by over FIVE times when all of the of the following apply:
gpoirier
parents:
21818
diff
changeset
|
195 else { |
21925 | 196 dmpi = vf_get_image(vf->next,mpi->imgfmt, |
197 MP_IMGTYPE_EXPORT, MP_IMGFLAG_ACCEPT_STRIDE, | |
198 mpi->w,mpi->h); | |
8244
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
199 |
21925 | 200 dmpi->stride[0] = mpi->stride[0]; |
201 dmpi->stride[1] = mpi->stride[1]; | |
202 dmpi->stride[2] = mpi->stride[2]; | |
203 dmpi->planes[0] = mpi->planes[0]; | |
204 dmpi->planes[1] = mpi->planes[1]; | |
205 dmpi->planes[2] = mpi->planes[2]; | |
206 dmpi->priv = mpi->priv; | |
207 } | |
21924
422eef67d14a
speeds up mplayer execution by over FIVE times when all of the of the following apply:
gpoirier
parents:
21818
diff
changeset
|
208 } |
17908 | 209 return vf_next_put_image(vf,dmpi, pts); |
8197 | 210 } |
211 | |
212 static void uninit(vf_instance_t *vf) { | |
213 vf->priv=NULL; | |
214 if(pause_mpi) { | |
215 free_mp_image(pause_mpi); | |
216 pause_mpi = NULL; | |
217 } | |
218 } | |
219 | |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
220 static int config(struct vf_instance_s* vf, int width, int height, int d_width, int d_height, |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
221 unsigned int flags, unsigned int outfmt) { |
27393 | 222 #ifdef CONFIG_FREETYPE |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
223 // here is the right place to get screen dimensions |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
224 if (force_load_font) { |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
225 force_load_font = 0; |
25851
9ebd00825df2
Allow independent scaling of vo_font and sub_font.
reimar
parents:
25502
diff
changeset
|
226 load_font_ft(width,height,&vo_font,font_name,osd_font_scale_factor); |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
227 } |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
228 #endif |
21803
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
229 if(outfmt == IMGFMT_MPEGPES) |
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
230 vf->priv->passthrough = 1; |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
231 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
232 } |
21803
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
233 |
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
234 static int query_format(struct vf_instance_s* vf, unsigned int fmt){ |
26759
8eff880f638c
cosmetics: Remove useless parentheses from return statements.
diego
parents:
25851
diff
changeset
|
235 return vf_next_query_format(vf,fmt); |
21803
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
236 } |
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
237 |
23366
b344b6520518
rename some menu open functions, to avoid confusion with libc native open()
ben
parents:
23338
diff
changeset
|
238 static int open_vf(vf_instance_t *vf, char* args){ |
8197 | 239 if(!st_priv) { |
240 st_priv = calloc(1,sizeof(struct vf_priv_s)); | |
241 st_priv->root = st_priv->current = menu_open(args); | |
242 if(!st_priv->current) { | |
243 free(st_priv); | |
244 st_priv = NULL; | |
245 return 0; | |
246 } | |
13344
0d96af97ec00
option to display menu at startup, patch by Aurelien Jacobs <aurel at gnuage.org>
faust3
parents:
10397
diff
changeset
|
247 st_priv->root->show = menu_startup; |
8197 | 248 mp_input_add_cmd_filter((mp_input_cmd_filter)cmd_filter,st_priv); |
249 } | |
250 | |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
251 vf->config = config; |
21803
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
252 vf->query_format=query_format; |
8197 | 253 vf->put_image = put_image; |
254 vf->get_image = get_image; | |
255 vf->uninit=uninit; | |
256 vf->priv=st_priv; | |
257 go2pause=0; | |
258 | |
259 return 1; | |
260 } | |
261 | |
262 | |
263 vf_info_t vf_info_menu = { | |
264 "Internal filter for libmenu", | |
265 "menu", | |
266 "Albeu", | |
267 "", | |
23366
b344b6520518
rename some menu open functions, to avoid confusion with libc native open()
ben
parents:
23338
diff
changeset
|
268 open_vf, |
9755 | 269 NULL |
8197 | 270 }; |
271 | |
272 | |
273 |