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