Mercurial > mplayer.hg
annotate libmenu/vf_menu.c @ 17960:ec93436dc52d
Fix a/v desync for real some files
author | rtognimp |
---|---|
date | Sun, 26 Mar 2006 14:10:52 +0000 |
parents | 98f4e3704a76 |
children | 6927fabaef92 |
rev | line source |
---|---|
8197 | 1 |
16862 | 2 #include "config.h" |
8197 | 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 |
16862 | 12 #include "mp_msg.h" |
8197 | 13 |
16862 | 14 #include "libmpcodecs/img_format.h" |
15 #include "libmpcodecs/mp_image.h" | |
16 #include "libmpcodecs/vf.h" | |
8197 | 17 |
16862 | 18 #include "libvo/fastmemcpy.h" |
19 #include "libvo/video_out.h" | |
20 #include "libvo/font_load.h" | |
21 #include "input/input.h" | |
22 #include "m_struct.h" | |
8197 | 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 | |
17908 | 40 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts); |
8197 | 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) { | |
17908 | 79 put_image(vf,pause_mpi, MP_NOPTS_VALUE); |
8197 | 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); | |
17945
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
17908
diff
changeset
|
108 else if(strcmp(arg,"left") == 0) |
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
17908
diff
changeset
|
109 menu_read_cmd(priv->current,MENU_CMD_LEFT); |
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
17908
diff
changeset
|
110 else if(strcmp(arg,"right") == 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_RIGHT); |
8197 | 112 else if(strcmp(arg,"ok") == 0) |
113 menu_read_cmd(priv->current,MENU_CMD_OK); | |
114 else if(strcmp(arg,"cancel") == 0) | |
115 menu_read_cmd(priv->current,MENU_CMD_CANCEL); | |
116 else if(strcmp(arg,"hide") == 0) | |
117 priv->current->show = 0; | |
118 else | |
10397 | 119 printf("Unknown menu command: '%s'\n",arg); |
8197 | 120 return 1; |
121 } | |
122 case MP_CMD_SET_MENU : { | |
123 char* menu = cmd->args[0].v.s; | |
124 menu_t* l = priv->current; | |
125 priv->current = menu_open(menu); | |
126 if(!priv->current) { | |
127 printf("Failed to open menu '%s'\n",menu); | |
128 priv->current = l; | |
129 priv->current->show = 0; | |
130 } else { | |
131 priv->current->show = 1; | |
132 priv->current->parent = l; | |
133 } | |
134 return 1; | |
135 } | |
136 } | |
137 return 0; | |
138 } | |
139 | |
140 static void get_image(struct vf_instance_s* vf, mp_image_t *mpi){ | |
141 mp_image_t *dmpi; | |
142 | |
143 if(mpi->type == MP_IMGTYPE_TEMP && (!(mpi->flags&MP_IMGFLAG_PRESERVE)) ) { | |
144 dmpi = vf_get_image(vf->next,mpi->imgfmt,mpi->type, mpi->flags, mpi->w, mpi->h); | |
145 memcpy(mpi->planes,dmpi->planes,MP_MAX_PLANES*sizeof(unsigned char*)); | |
146 memcpy(mpi->stride,dmpi->stride,MP_MAX_PLANES*sizeof(unsigned int)); | |
147 mpi->flags|=MP_IMGFLAG_DIRECT; | |
148 mpi->priv=(void*)dmpi; | |
149 return; | |
150 } | |
151 } | |
152 | |
153 static void key_cb(int code) { | |
154 menu_read_key(st_priv->current,code); | |
155 } | |
156 | |
157 | |
158 | |
159 inline static void copy_mpi(mp_image_t *dmpi, mp_image_t *mpi) { | |
160 if(mpi->flags&MP_IMGFLAG_PLANAR){ | |
161 memcpy_pic(dmpi->planes[0],mpi->planes[0], mpi->w, mpi->h, | |
162 dmpi->stride[0],mpi->stride[0]); | |
163 memcpy_pic(dmpi->planes[1],mpi->planes[1], mpi->chroma_width, mpi->chroma_height, | |
164 dmpi->stride[1],mpi->stride[1]); | |
165 memcpy_pic(dmpi->planes[2], mpi->planes[2], mpi->chroma_width, mpi->chroma_height, | |
166 dmpi->stride[2],mpi->stride[2]); | |
167 } else { | |
168 memcpy_pic(dmpi->planes[0],mpi->planes[0], | |
169 mpi->w*(dmpi->bpp/8), mpi->h, | |
170 dmpi->stride[0],mpi->stride[0]); | |
171 } | |
172 } | |
173 | |
174 | |
175 | |
17908 | 176 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){ |
8197 | 177 mp_image_t *dmpi = NULL; |
178 | |
8251 | 179 if(vf->priv->current->show |
180 || (vf->priv->current->parent && vf->priv->current->parent->show)) { | |
8197 | 181 // Close all menu who requested it |
182 while(vf->priv->current->cl && vf->priv->current != vf->priv->root) { | |
183 menu_t* m = vf->priv->current; | |
184 vf->priv->current = m->parent ? m->parent : vf->priv->root; | |
185 menu_close(m); | |
186 } | |
187 | |
188 // Step 1 : save the picture | |
189 while(go2pause == 1) { | |
190 static char delay = 0; // Hack : wait the 2 frame to be sure to show the right picture | |
191 delay ^= 1; // after a seek | |
192 if(!delay) break; | |
193 | |
194 if(pause_mpi && (mpi->w != pause_mpi->w || mpi->h != pause_mpi->h || | |
195 mpi->imgfmt != pause_mpi->imgfmt)) { | |
196 free_mp_image(pause_mpi); | |
197 pause_mpi = NULL; | |
198 } | |
199 if(!pause_mpi) | |
200 pause_mpi = alloc_mpi(mpi->w,mpi->h,mpi->imgfmt); | |
201 copy_mpi(pause_mpi,mpi); | |
202 mp_input_queue_cmd(mp_input_parse_cmd("pause")); | |
203 go2pause = 2; | |
204 break; | |
205 } | |
206 | |
207 // Grab // Ungrab the keys | |
208 if(!mp_input_key_cb && vf->priv->current->show) | |
209 mp_input_key_cb = key_cb; | |
210 if(mp_input_key_cb && !vf->priv->current->show) | |
211 mp_input_key_cb = NULL; | |
212 | |
213 if(mpi->flags&MP_IMGFLAG_DIRECT) | |
214 dmpi = mpi->priv; | |
215 else { | |
216 dmpi = vf_get_image(vf->next,mpi->imgfmt, | |
217 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, | |
218 mpi->w,mpi->h); | |
219 copy_mpi(dmpi,mpi); | |
220 } | |
221 menu_draw(vf->priv->current,dmpi); | |
222 | |
8244
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
223 } else { |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
224 if(mp_input_key_cb) |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
225 mp_input_key_cb = NULL; |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
226 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
|
227 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
|
228 mpi->w,mpi->h); |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
229 |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
230 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
|
231 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
|
232 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
|
233 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
|
234 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
|
235 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
|
236 dmpi->priv = mpi->priv; |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
237 } |
17908 | 238 return vf_next_put_image(vf,dmpi, pts); |
8197 | 239 } |
240 | |
241 static void uninit(vf_instance_t *vf) { | |
242 vf->priv=NULL; | |
243 if(pause_mpi) { | |
244 free_mp_image(pause_mpi); | |
245 pause_mpi = NULL; | |
246 } | |
247 } | |
248 | |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
249 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
|
250 unsigned int flags, unsigned int outfmt) { |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
251 #ifdef HAVE_FREETYPE |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
252 // 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
|
253 if (force_load_font) { |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
254 force_load_font = 0; |
8635
81dbd28ef7c0
these patches let ,,oldstyle'' and freetype subtitle renderers live
arpi
parents:
8623
diff
changeset
|
255 load_font_ft(width,height); |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
256 } |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
257 #endif |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
258 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
|
259 } |
8197 | 260 static int open(vf_instance_t *vf, char* args){ |
261 if(!st_priv) { | |
262 st_priv = calloc(1,sizeof(struct vf_priv_s)); | |
263 st_priv->root = st_priv->current = menu_open(args); | |
264 if(!st_priv->current) { | |
265 free(st_priv); | |
266 st_priv = NULL; | |
267 return 0; | |
268 } | |
13344
0d96af97ec00
option to display menu at startup, patch by Aurelien Jacobs <aurel at gnuage.org>
faust3
parents:
10397
diff
changeset
|
269 st_priv->root->show = menu_startup; |
8197 | 270 mp_input_add_cmd_filter((mp_input_cmd_filter)cmd_filter,st_priv); |
271 } | |
272 | |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
273 vf->config = config; |
8197 | 274 vf->put_image = put_image; |
275 vf->get_image = get_image; | |
276 vf->uninit=uninit; | |
277 vf->priv=st_priv; | |
278 go2pause=0; | |
279 | |
280 return 1; | |
281 } | |
282 | |
283 | |
284 vf_info_t vf_info_menu = { | |
285 "Internal filter for libmenu", | |
286 "menu", | |
287 "Albeu", | |
288 "", | |
9755 | 289 open, |
290 NULL | |
8197 | 291 }; |
292 | |
293 | |
294 |