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