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