Mercurial > mplayer.hg
annotate libmenu/vf_menu.c @ 24954:a4cf3ff9b70e
Fix the prevent system idle code. Original code also works, but not as expected.
The update function was always called, but it should only be called every 30
seconds.
author | ulion |
---|---|
date | Tue, 06 Nov 2007 12:52:54 +0000 |
parents | ea73d155ef00 |
children | 983806685c44 |
rev | line source |
---|---|
8197 | 1 |
16862 | 2 #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
|
3 #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
|
4 #include "help_mp.h" |
8197 | 5 |
6 #include <stdio.h> | |
7 #include <stdlib.h> | |
8 #include <string.h> | |
9 | |
8623
440301fef3fe
Added/reordered #includes to silence warnings about "implicit declaration".
rathann
parents:
8251
diff
changeset
|
10 #ifdef HAVE_MALLOC_H |
440301fef3fe
Added/reordered #includes to silence warnings about "implicit declaration".
rathann
parents:
8251
diff
changeset
|
11 #include <malloc.h> |
440301fef3fe
Added/reordered #includes to silence warnings about "implicit declaration".
rathann
parents:
8251
diff
changeset
|
12 #endif |
8197 | 13 |
23338
2a66d95355f0
add new -subfont option, that allows having a different font for OSD (controls and menu) and subtitles
ben
parents:
22284
diff
changeset
|
14 #include "mplayer.h" |
16862 | 15 #include "mp_msg.h" |
8197 | 16 |
16862 | 17 #include "libmpcodecs/img_format.h" |
18 #include "libmpcodecs/mp_image.h" | |
19 #include "libmpcodecs/vf.h" | |
8197 | 20 |
16862 | 21 #include "libvo/fastmemcpy.h" |
22 #include "libvo/video_out.h" | |
23 #include "libvo/font_load.h" | |
24 #include "input/input.h" | |
25 #include "m_struct.h" | |
8197 | 26 #include "menu.h" |
22284 | 27 #include "access_mpcontext.h" |
8197 | 28 |
29 | |
30 static struct vf_priv_s* st_priv = NULL; | |
31 | |
32 static mp_image_t* pause_mpi = NULL; | |
33 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
|
34 /// if nonzero display menu at startup |
13528 | 35 int attribute_used menu_startup = 0; |
8197 | 36 |
37 struct vf_priv_s { | |
38 menu_t* root; | |
39 menu_t* current; | |
21803
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
40 int passthrough; |
8197 | 41 }; |
42 | |
17908 | 43 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts); |
8197 | 44 |
45 void vf_menu_pause_update(struct vf_instance_s* vf) { | |
22284 | 46 vo_functions_t *video_out = mpctx_get_video_out(vf->priv->current->ctx); |
8197 | 47 if(pause_mpi) { |
17908 | 48 put_image(vf,pause_mpi, MP_NOPTS_VALUE); |
8197 | 49 // Don't draw the osd atm |
50 //vf->control(vf,VFCTRL_DRAW_OSD,NULL); | |
51 video_out->flip_page(); | |
52 } | |
53 } | |
54 | |
55 static int cmd_filter(mp_cmd_t* cmd, int paused, struct vf_priv_s * priv) { | |
56 | |
57 switch(cmd->id) { | |
58 case MP_CMD_PAUSE : | |
24929
ea73d155ef00
Fix link to email explaining the paused vf_menu behaviour change
reimar
parents:
23994
diff
changeset
|
59 #if 0 |
ea73d155ef00
Fix link to email explaining the paused vf_menu behaviour change
reimar
parents:
23994
diff
changeset
|
60 /* disabled because of |
ea73d155ef00
Fix link to email explaining the paused vf_menu behaviour change
reimar
parents:
23994
diff
changeset
|
61 * http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/2003-March/017281.html |
ea73d155ef00
Fix link to email explaining the paused vf_menu behaviour change
reimar
parents:
23994
diff
changeset
|
62 * Subject: -menu & pause bug fix? |
ea73d155ef00
Fix link to email explaining the paused vf_menu behaviour change
reimar
parents:
23994
diff
changeset
|
63 * Date: Sun Mar 23 11:00:49 CET 2003 |
ea73d155ef00
Fix link to email explaining the paused vf_menu behaviour change
reimar
parents:
23994
diff
changeset
|
64 */ |
8197 | 65 if(!paused && !go2pause) { // Initial pause cmd -> wait the next put_image |
66 go2pause = 1; | |
67 return 1; | |
68 } | |
9903
7d70e56f317a
10l fix by Vladimir Mosgalin <mosgalin@VM10124.spb.edu>
alex
parents:
9755
diff
changeset
|
69 #endif |
8197 | 70 if(go2pause == 2) // Msg resent by put_image after saving the image |
71 go2pause = 0; | |
72 break; | |
73 case MP_CMD_MENU : { // Convert txt cmd from the users into libmenu stuff | |
74 char* arg = cmd->args[0].v.s; | |
75 | |
19489 | 76 if(!priv->current->show && !(strcmp(arg,"hide") == 0) ) |
8197 | 77 priv->current->show = 1; |
78 else if(strcmp(arg,"up") == 0) | |
79 menu_read_cmd(priv->current,MENU_CMD_UP); | |
80 else if(strcmp(arg,"down") == 0) | |
81 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
|
82 else if(strcmp(arg,"left") == 0) |
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
17908
diff
changeset
|
83 menu_read_cmd(priv->current,MENU_CMD_LEFT); |
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
17908
diff
changeset
|
84 else if(strcmp(arg,"right") == 0) |
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
17908
diff
changeset
|
85 menu_read_cmd(priv->current,MENU_CMD_RIGHT); |
8197 | 86 else if(strcmp(arg,"ok") == 0) |
87 menu_read_cmd(priv->current,MENU_CMD_OK); | |
88 else if(strcmp(arg,"cancel") == 0) | |
89 menu_read_cmd(priv->current,MENU_CMD_CANCEL); | |
19489 | 90 else if(strcmp(arg,"hide") == 0 || strcmp(arg,"toggle") == 0) |
8197 | 91 priv->current->show = 0; |
92 else | |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17945
diff
changeset
|
93 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_UnknownMenuCommand,arg); |
8197 | 94 return 1; |
95 } | |
96 case MP_CMD_SET_MENU : { | |
97 char* menu = cmd->args[0].v.s; | |
98 menu_t* l = priv->current; | |
99 priv->current = menu_open(menu); | |
100 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
|
101 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_FailedToOpenMenu,menu); |
8197 | 102 priv->current = l; |
103 priv->current->show = 0; | |
104 } else { | |
105 priv->current->show = 1; | |
106 priv->current->parent = l; | |
107 } | |
108 return 1; | |
109 } | |
110 } | |
111 return 0; | |
112 } | |
113 | |
114 static void get_image(struct vf_instance_s* vf, mp_image_t *mpi){ | |
115 mp_image_t *dmpi; | |
116 | |
117 if(mpi->type == MP_IMGTYPE_TEMP && (!(mpi->flags&MP_IMGFLAG_PRESERVE)) ) { | |
118 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
|
119 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
|
120 memcpy(mpi->stride,dmpi->stride,MP_MAX_PLANES*sizeof(unsigned int)); |
8197 | 121 mpi->flags|=MP_IMGFLAG_DIRECT; |
122 mpi->priv=(void*)dmpi; | |
123 return; | |
124 } | |
125 } | |
126 | |
127 static void key_cb(int code) { | |
128 menu_read_key(st_priv->current,code); | |
129 } | |
130 | |
17908 | 131 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){ |
8197 | 132 mp_image_t *dmpi = NULL; |
133 | |
21803
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
134 if (vf->priv->passthrough) { |
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
135 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
|
136 0, mpi->w, mpi->h); |
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
137 dmpi->planes[0]=mpi->planes[0]; |
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
138 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
|
139 } |
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
140 |
8251 | 141 if(vf->priv->current->show |
142 || (vf->priv->current->parent && vf->priv->current->parent->show)) { | |
8197 | 143 // Close all menu who requested it |
144 while(vf->priv->current->cl && vf->priv->current != vf->priv->root) { | |
145 menu_t* m = vf->priv->current; | |
146 vf->priv->current = m->parent ? m->parent : vf->priv->root; | |
147 menu_close(m); | |
148 } | |
149 | |
150 // Step 1 : save the picture | |
151 while(go2pause == 1) { | |
152 static char delay = 0; // Hack : wait the 2 frame to be sure to show the right picture | |
153 delay ^= 1; // after a seek | |
154 if(!delay) break; | |
155 | |
156 if(pause_mpi && (mpi->w != pause_mpi->w || mpi->h != pause_mpi->h || | |
157 mpi->imgfmt != pause_mpi->imgfmt)) { | |
158 free_mp_image(pause_mpi); | |
159 pause_mpi = NULL; | |
160 } | |
161 if(!pause_mpi) | |
162 pause_mpi = alloc_mpi(mpi->w,mpi->h,mpi->imgfmt); | |
163 copy_mpi(pause_mpi,mpi); | |
164 mp_input_queue_cmd(mp_input_parse_cmd("pause")); | |
165 go2pause = 2; | |
166 break; | |
167 } | |
168 | |
169 // Grab // Ungrab the keys | |
170 if(!mp_input_key_cb && vf->priv->current->show) | |
171 mp_input_key_cb = key_cb; | |
172 if(mp_input_key_cb && !vf->priv->current->show) | |
173 mp_input_key_cb = NULL; | |
174 | |
175 if(mpi->flags&MP_IMGFLAG_DIRECT) | |
176 dmpi = mpi->priv; | |
177 else { | |
178 dmpi = vf_get_image(vf->next,mpi->imgfmt, | |
179 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, | |
180 mpi->w,mpi->h); | |
181 copy_mpi(dmpi,mpi); | |
182 } | |
183 menu_draw(vf->priv->current,dmpi); | |
184 | |
8244
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
185 } else { |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
186 if(mp_input_key_cb) |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
187 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
|
188 |
422eef67d14a
speeds up mplayer execution by over FIVE times when all of the of the following apply:
gpoirier
parents:
21818
diff
changeset
|
189 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
|
190 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
|
191 else { |
21925 | 192 dmpi = vf_get_image(vf->next,mpi->imgfmt, |
193 MP_IMGTYPE_EXPORT, MP_IMGFLAG_ACCEPT_STRIDE, | |
194 mpi->w,mpi->h); | |
8244
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
195 |
21925 | 196 dmpi->stride[0] = mpi->stride[0]; |
197 dmpi->stride[1] = mpi->stride[1]; | |
198 dmpi->stride[2] = mpi->stride[2]; | |
199 dmpi->planes[0] = mpi->planes[0]; | |
200 dmpi->planes[1] = mpi->planes[1]; | |
201 dmpi->planes[2] = mpi->planes[2]; | |
202 dmpi->priv = mpi->priv; | |
203 } | |
21924
422eef67d14a
speeds up mplayer execution by over FIVE times when all of the of the following apply:
gpoirier
parents:
21818
diff
changeset
|
204 } |
17908 | 205 return vf_next_put_image(vf,dmpi, pts); |
8197 | 206 } |
207 | |
208 static void uninit(vf_instance_t *vf) { | |
209 vf->priv=NULL; | |
210 if(pause_mpi) { | |
211 free_mp_image(pause_mpi); | |
212 pause_mpi = NULL; | |
213 } | |
214 } | |
215 | |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
216 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
|
217 unsigned int flags, unsigned int outfmt) { |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
218 #ifdef HAVE_FREETYPE |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
219 // 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
|
220 if (force_load_font) { |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
221 force_load_font = 0; |
23338
2a66d95355f0
add new -subfont option, that allows having a different font for OSD (controls and menu) and subtitles
ben
parents:
22284
diff
changeset
|
222 load_font_ft(width,height,&vo_font,font_name); |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
223 } |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
224 #endif |
21803
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
225 if(outfmt == IMGFMT_MPEGPES) |
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
226 vf->priv->passthrough = 1; |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
227 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
|
228 } |
21803
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
229 |
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
230 static int query_format(struct vf_instance_s* vf, unsigned int fmt){ |
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
231 return (vf_next_query_format(vf,fmt)); |
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
232 } |
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
233 |
23366
b344b6520518
rename some menu open functions, to avoid confusion with libc native open()
ben
parents:
23338
diff
changeset
|
234 static int open_vf(vf_instance_t *vf, char* args){ |
8197 | 235 if(!st_priv) { |
236 st_priv = calloc(1,sizeof(struct vf_priv_s)); | |
237 st_priv->root = st_priv->current = menu_open(args); | |
238 if(!st_priv->current) { | |
239 free(st_priv); | |
240 st_priv = NULL; | |
241 return 0; | |
242 } | |
13344
0d96af97ec00
option to display menu at startup, patch by Aurelien Jacobs <aurel at gnuage.org>
faust3
parents:
10397
diff
changeset
|
243 st_priv->root->show = menu_startup; |
8197 | 244 mp_input_add_cmd_filter((mp_input_cmd_filter)cmd_filter,st_priv); |
245 } | |
246 | |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
247 vf->config = config; |
21803
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
248 vf->query_format=query_format; |
8197 | 249 vf->put_image = put_image; |
250 vf->get_image = get_image; | |
251 vf->uninit=uninit; | |
252 vf->priv=st_priv; | |
253 go2pause=0; | |
254 | |
255 return 1; | |
256 } | |
257 | |
258 | |
259 vf_info_t vf_info_menu = { | |
260 "Internal filter for libmenu", | |
261 "menu", | |
262 "Albeu", | |
263 "", | |
23366
b344b6520518
rename some menu open functions, to avoid confusion with libc native open()
ben
parents:
23338
diff
changeset
|
264 open_vf, |
9755 | 265 NULL |
8197 | 266 }; |
267 | |
268 | |
269 |