Mercurial > mplayer.hg
annotate libmenu/vf_menu.c @ 21402:8c43ea1ea79a
update for r21415 and r21416
author | henry |
---|---|
date | Fri, 01 Dec 2006 17:56:41 +0000 |
parents | 87c339558bc1 |
children | 3acc4b00bcc6 |
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 |
16862 | 14 #include "mp_msg.h" |
8197 | 15 |
16862 | 16 #include "libmpcodecs/img_format.h" |
17 #include "libmpcodecs/mp_image.h" | |
18 #include "libmpcodecs/vf.h" | |
8197 | 19 |
16862 | 20 #include "libvo/fastmemcpy.h" |
21 #include "libvo/video_out.h" | |
22 #include "libvo/font_load.h" | |
23 #include "input/input.h" | |
24 #include "m_struct.h" | |
8197 | 25 #include "menu.h" |
26 | |
27 extern vo_functions_t* video_out; | |
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; | |
40 }; | |
41 | |
17908 | 42 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts); |
8197 | 43 |
44 static mp_image_t* alloc_mpi(int w, int h, uint32_t fmt) { | |
45 mp_image_t* mpi = new_mp_image(w,h); | |
46 | |
47 mp_image_setfmt(mpi,fmt); | |
48 // IF09 - allocate space for 4. plane delta info - unused | |
49 if (mpi->imgfmt == IMGFMT_IF09) | |
50 { | |
51 mpi->planes[0]=memalign(64, mpi->bpp*mpi->width*(mpi->height+2)/8+ | |
52 mpi->chroma_width*mpi->chroma_height); | |
53 /* delta table, just for fun ;) */ | |
54 mpi->planes[3]=mpi->planes[0]+2*(mpi->chroma_width*mpi->chroma_height); | |
55 } | |
56 else | |
57 mpi->planes[0]=memalign(64, mpi->bpp*mpi->width*(mpi->height+2)/8); | |
58 if(mpi->flags&MP_IMGFLAG_PLANAR){ | |
59 // YV12/I420/YVU9/IF09. feel free to add other planar formats here... | |
60 if(!mpi->stride[0]) mpi->stride[0]=mpi->width; | |
61 if(!mpi->stride[1]) mpi->stride[1]=mpi->stride[2]=mpi->chroma_width; | |
62 if(mpi->flags&MP_IMGFLAG_SWAPPED){ | |
63 // I420/IYUV (Y,U,V) | |
64 mpi->planes[1]=mpi->planes[0]+mpi->width*mpi->height; | |
65 mpi->planes[2]=mpi->planes[1]+mpi->chroma_width*mpi->chroma_height; | |
66 } else { | |
67 // YV12,YVU9,IF09 (Y,V,U) | |
68 mpi->planes[2]=mpi->planes[0]+mpi->width*mpi->height; | |
69 mpi->planes[1]=mpi->planes[2]+mpi->chroma_width*mpi->chroma_height; | |
70 } | |
71 } else { | |
72 if(!mpi->stride[0]) mpi->stride[0]=mpi->width*mpi->bpp/8; | |
73 } | |
74 mpi->flags|=MP_IMGFLAG_ALLOCATED; | |
75 | |
76 return mpi; | |
77 } | |
78 | |
79 void vf_menu_pause_update(struct vf_instance_s* vf) { | |
80 if(pause_mpi) { | |
17908 | 81 put_image(vf,pause_mpi, MP_NOPTS_VALUE); |
8197 | 82 // Don't draw the osd atm |
83 //vf->control(vf,VFCTRL_DRAW_OSD,NULL); | |
84 video_out->flip_page(); | |
85 } | |
86 } | |
87 | |
88 static int cmd_filter(mp_cmd_t* cmd, int paused, struct vf_priv_s * priv) { | |
89 | |
90 switch(cmd->id) { | |
91 case MP_CMD_PAUSE : | |
9903
7d70e56f317a
10l fix by Vladimir Mosgalin <mosgalin@VM10124.spb.edu>
alex
parents:
9755
diff
changeset
|
92 #if 0 // http://mplayerhq.hu/pipermail/mplayer-dev-eng/2003-March/017331.html |
8197 | 93 if(!paused && !go2pause) { // Initial pause cmd -> wait the next put_image |
94 go2pause = 1; | |
95 return 1; | |
96 } | |
9903
7d70e56f317a
10l fix by Vladimir Mosgalin <mosgalin@VM10124.spb.edu>
alex
parents:
9755
diff
changeset
|
97 #endif |
8197 | 98 if(go2pause == 2) // Msg resent by put_image after saving the image |
99 go2pause = 0; | |
100 break; | |
101 case MP_CMD_MENU : { // Convert txt cmd from the users into libmenu stuff | |
102 char* arg = cmd->args[0].v.s; | |
103 | |
19489 | 104 if(!priv->current->show && !(strcmp(arg,"hide") == 0) ) |
8197 | 105 priv->current->show = 1; |
106 else if(strcmp(arg,"up") == 0) | |
107 menu_read_cmd(priv->current,MENU_CMD_UP); | |
108 else if(strcmp(arg,"down") == 0) | |
109 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
|
110 else if(strcmp(arg,"left") == 0) |
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
17908
diff
changeset
|
111 menu_read_cmd(priv->current,MENU_CMD_LEFT); |
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
17908
diff
changeset
|
112 else if(strcmp(arg,"right") == 0) |
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
17908
diff
changeset
|
113 menu_read_cmd(priv->current,MENU_CMD_RIGHT); |
8197 | 114 else if(strcmp(arg,"ok") == 0) |
115 menu_read_cmd(priv->current,MENU_CMD_OK); | |
116 else if(strcmp(arg,"cancel") == 0) | |
117 menu_read_cmd(priv->current,MENU_CMD_CANCEL); | |
19489 | 118 else if(strcmp(arg,"hide") == 0 || strcmp(arg,"toggle") == 0) |
8197 | 119 priv->current->show = 0; |
120 else | |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17945
diff
changeset
|
121 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_UnknownMenuCommand,arg); |
8197 | 122 return 1; |
123 } | |
124 case MP_CMD_SET_MENU : { | |
125 char* menu = cmd->args[0].v.s; | |
126 menu_t* l = priv->current; | |
127 priv->current = menu_open(menu); | |
128 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
|
129 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_FailedToOpenMenu,menu); |
8197 | 130 priv->current = l; |
131 priv->current->show = 0; | |
132 } else { | |
133 priv->current->show = 1; | |
134 priv->current->parent = l; | |
135 } | |
136 return 1; | |
137 } | |
138 } | |
139 return 0; | |
140 } | |
141 | |
142 static void get_image(struct vf_instance_s* vf, mp_image_t *mpi){ | |
143 mp_image_t *dmpi; | |
144 | |
145 if(mpi->type == MP_IMGTYPE_TEMP && (!(mpi->flags&MP_IMGFLAG_PRESERVE)) ) { | |
146 dmpi = vf_get_image(vf->next,mpi->imgfmt,mpi->type, mpi->flags, mpi->w, mpi->h); | |
147 memcpy(mpi->planes,dmpi->planes,MP_MAX_PLANES*sizeof(unsigned char*)); | |
148 memcpy(mpi->stride,dmpi->stride,MP_MAX_PLANES*sizeof(unsigned int)); | |
149 mpi->flags|=MP_IMGFLAG_DIRECT; | |
150 mpi->priv=(void*)dmpi; | |
151 return; | |
152 } | |
153 } | |
154 | |
155 static void key_cb(int code) { | |
156 menu_read_key(st_priv->current,code); | |
157 } | |
158 | |
159 | |
160 | |
161 inline static void copy_mpi(mp_image_t *dmpi, mp_image_t *mpi) { | |
162 if(mpi->flags&MP_IMGFLAG_PLANAR){ | |
163 memcpy_pic(dmpi->planes[0],mpi->planes[0], mpi->w, mpi->h, | |
164 dmpi->stride[0],mpi->stride[0]); | |
165 memcpy_pic(dmpi->planes[1],mpi->planes[1], mpi->chroma_width, mpi->chroma_height, | |
166 dmpi->stride[1],mpi->stride[1]); | |
167 memcpy_pic(dmpi->planes[2], mpi->planes[2], mpi->chroma_width, mpi->chroma_height, | |
168 dmpi->stride[2],mpi->stride[2]); | |
169 } else { | |
170 memcpy_pic(dmpi->planes[0],mpi->planes[0], | |
171 mpi->w*(dmpi->bpp/8), mpi->h, | |
172 dmpi->stride[0],mpi->stride[0]); | |
173 } | |
174 } | |
175 | |
176 | |
177 | |
17908 | 178 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){ |
8197 | 179 mp_image_t *dmpi = NULL; |
180 | |
8251 | 181 if(vf->priv->current->show |
182 || (vf->priv->current->parent && vf->priv->current->parent->show)) { | |
8197 | 183 // Close all menu who requested it |
184 while(vf->priv->current->cl && vf->priv->current != vf->priv->root) { | |
185 menu_t* m = vf->priv->current; | |
186 vf->priv->current = m->parent ? m->parent : vf->priv->root; | |
187 menu_close(m); | |
188 } | |
189 | |
190 // Step 1 : save the picture | |
191 while(go2pause == 1) { | |
192 static char delay = 0; // Hack : wait the 2 frame to be sure to show the right picture | |
193 delay ^= 1; // after a seek | |
194 if(!delay) break; | |
195 | |
196 if(pause_mpi && (mpi->w != pause_mpi->w || mpi->h != pause_mpi->h || | |
197 mpi->imgfmt != pause_mpi->imgfmt)) { | |
198 free_mp_image(pause_mpi); | |
199 pause_mpi = NULL; | |
200 } | |
201 if(!pause_mpi) | |
202 pause_mpi = alloc_mpi(mpi->w,mpi->h,mpi->imgfmt); | |
203 copy_mpi(pause_mpi,mpi); | |
204 mp_input_queue_cmd(mp_input_parse_cmd("pause")); | |
205 go2pause = 2; | |
206 break; | |
207 } | |
208 | |
209 // Grab // Ungrab the keys | |
210 if(!mp_input_key_cb && vf->priv->current->show) | |
211 mp_input_key_cb = key_cb; | |
212 if(mp_input_key_cb && !vf->priv->current->show) | |
213 mp_input_key_cb = NULL; | |
214 | |
215 if(mpi->flags&MP_IMGFLAG_DIRECT) | |
216 dmpi = mpi->priv; | |
217 else { | |
218 dmpi = vf_get_image(vf->next,mpi->imgfmt, | |
219 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, | |
220 mpi->w,mpi->h); | |
221 copy_mpi(dmpi,mpi); | |
222 } | |
223 menu_draw(vf->priv->current,dmpi); | |
224 | |
8244
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
225 } else { |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
226 if(mp_input_key_cb) |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
227 mp_input_key_cb = NULL; |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
228 dmpi = vf_get_image(vf->next,mpi->imgfmt, |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
229 MP_IMGTYPE_EXPORT, MP_IMGFLAG_ACCEPT_STRIDE, |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
230 mpi->w,mpi->h); |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
231 |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
232 dmpi->stride[0] = mpi->stride[0]; |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
233 dmpi->stride[1] = mpi->stride[1]; |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
234 dmpi->stride[2] = mpi->stride[2]; |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
235 dmpi->planes[0] = mpi->planes[0]; |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
236 dmpi->planes[1] = mpi->planes[1]; |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
237 dmpi->planes[2] = mpi->planes[2]; |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
238 dmpi->priv = mpi->priv; |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
239 } |
17908 | 240 return vf_next_put_image(vf,dmpi, pts); |
8197 | 241 } |
242 | |
243 static void uninit(vf_instance_t *vf) { | |
244 vf->priv=NULL; | |
245 if(pause_mpi) { | |
246 free_mp_image(pause_mpi); | |
247 pause_mpi = NULL; | |
248 } | |
249 } | |
250 | |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
251 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
|
252 unsigned int flags, unsigned int outfmt) { |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
253 #ifdef HAVE_FREETYPE |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
254 // 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
|
255 if (force_load_font) { |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
256 force_load_font = 0; |
8635
81dbd28ef7c0
these patches let ,,oldstyle'' and freetype subtitle renderers live
arpi
parents:
8623
diff
changeset
|
257 load_font_ft(width,height); |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
258 } |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
259 #endif |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
260 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
|
261 } |
8197 | 262 static int open(vf_instance_t *vf, char* args){ |
263 if(!st_priv) { | |
264 st_priv = calloc(1,sizeof(struct vf_priv_s)); | |
265 st_priv->root = st_priv->current = menu_open(args); | |
266 if(!st_priv->current) { | |
267 free(st_priv); | |
268 st_priv = NULL; | |
269 return 0; | |
270 } | |
13344
0d96af97ec00
option to display menu at startup, patch by Aurelien Jacobs <aurel at gnuage.org>
faust3
parents:
10397
diff
changeset
|
271 st_priv->root->show = menu_startup; |
8197 | 272 mp_input_add_cmd_filter((mp_input_cmd_filter)cmd_filter,st_priv); |
273 } | |
274 | |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
275 vf->config = config; |
8197 | 276 vf->put_image = put_image; |
277 vf->get_image = get_image; | |
278 vf->uninit=uninit; | |
279 vf->priv=st_priv; | |
280 go2pause=0; | |
281 | |
282 return 1; | |
283 } | |
284 | |
285 | |
286 vf_info_t vf_info_menu = { | |
287 "Internal filter for libmenu", | |
288 "menu", | |
289 "Albeu", | |
290 "", | |
9755 | 291 open, |
292 NULL | |
8197 | 293 }; |
294 | |
295 | |
296 |