17 #include "libmpcodecs/img_format.h"
18 #include "libmpcodecs/mp_image.h"
19 #include "libmpcodecs/vf.h"
21 #include "libvo/fastmemcpy.h"
22 #include "libvo/video_out.h"
23 #include "libvo/font_load.h"
24 #include "input/input.h"
27 #include "access_mpcontext.h"
30 static struct vf_priv_s
* st_priv
= NULL
;
32 static mp_image_t
* pause_mpi
= NULL
;
33 static int go2pause
= 0;
34 /// if nonzero display menu at startup
35 int attribute_used menu_startup
= 0;
43 static int put_image(struct vf_instance_s
* vf
, mp_image_t
*mpi
, double pts
);
45 void vf_menu_pause_update(struct vf_instance_s
* vf
) {
46 vo_functions_t
*video_out
= mpctx_get_video_out(vf
->priv
->current
->ctx
);
48 put_image(vf
,pause_mpi
, MP_NOPTS_VALUE
);
49 // Don't draw the osd atm
50 //vf->control(vf,VFCTRL_DRAW_OSD,NULL);
51 video_out
->flip_page();
55 static int cmd_filter(mp_cmd_t
* cmd
, int paused
, struct vf_priv_s
* priv
) {
59 #if 0 // http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/2003-March/017286.html
60 if(!paused
&& !go2pause
) { // Initial pause cmd -> wait the next put_image
65 if(go2pause
== 2) // Msg resent by put_image after saving the image
68 case MP_CMD_MENU
: { // Convert txt cmd from the users into libmenu stuff
69 char* arg
= cmd
->args
[0].v
.s
;
71 if(!priv
->current
->show
&& !(strcmp(arg
,"hide") == 0) )
72 priv
->current
->show
= 1;
73 else if(strcmp(arg
,"up") == 0)
74 menu_read_cmd(priv
->current
,MENU_CMD_UP
);
75 else if(strcmp(arg
,"down") == 0)
76 menu_read_cmd(priv
->current
,MENU_CMD_DOWN
);
77 else if(strcmp(arg
,"left") == 0)
78 menu_read_cmd(priv
->current
,MENU_CMD_LEFT
);
79 else if(strcmp(arg
,"right") == 0)
80 menu_read_cmd(priv
->current
,MENU_CMD_RIGHT
);
81 else if(strcmp(arg
,"ok") == 0)
82 menu_read_cmd(priv
->current
,MENU_CMD_OK
);
83 else if(strcmp(arg
,"cancel") == 0)
84 menu_read_cmd(priv
->current
,MENU_CMD_CANCEL
);
85 else if(strcmp(arg
,"hide") == 0 || strcmp(arg
,"toggle") == 0)
86 priv
->current
->show
= 0;
88 mp_msg(MSGT_GLOBAL
,MSGL_WARN
,MSGTR_LIBMENU_UnknownMenuCommand
,arg
);
91 case MP_CMD_SET_MENU
: {
92 char* menu
= cmd
->args
[0].v
.s
;
93 menu_t
* l
= priv
->current
;
94 priv
->current
= menu_open(menu
);
96 mp_msg(MSGT_GLOBAL
,MSGL_WARN
,MSGTR_LIBMENU_FailedToOpenMenu
,menu
);
98 priv
->current
->show
= 0;
100 priv
->current
->show
= 1;
101 priv
->current
->parent
= l
;
109 static void get_image(struct vf_instance_s
* vf
, mp_image_t
*mpi
){
112 if(mpi
->type
== MP_IMGTYPE_TEMP
&& (!(mpi
->flags
&MP_IMGFLAG_PRESERVE
)) ) {
113 dmpi
= vf_get_image(vf
->next
,mpi
->imgfmt
,mpi
->type
, mpi
->flags
, mpi
->w
, mpi
->h
);
114 memcpy(mpi
->planes
,dmpi
->planes
,MP_MAX_PLANES
*sizeof(unsigned char*));
115 memcpy(mpi
->stride
,dmpi
->stride
,MP_MAX_PLANES
*sizeof(unsigned int));
116 mpi
->flags
|=MP_IMGFLAG_DIRECT
;
117 mpi
->priv
=(void*)dmpi
;
122 static void key_cb(int code
) {
123 menu_read_key(st_priv
->current
,code
);
126 static int put_image(struct vf_instance_s
* vf
, mp_image_t
*mpi
, double pts
){
127 mp_image_t
*dmpi
= NULL
;
129 if (vf
->priv
->passthrough
) {
130 dmpi
=vf_get_image(vf
->next
, IMGFMT_MPEGPES
, MP_IMGTYPE_EXPORT
,
132 dmpi
->planes
[0]=mpi
->planes
[0];
133 return vf_next_put_image(vf
,dmpi
, pts
);
136 if(vf
->priv
->current
->show
137 || (vf
->priv
->current
->parent
&& vf
->priv
->current
->parent
->show
)) {
138 // Close all menu who requested it
139 while(vf
->priv
->current
->cl
&& vf
->priv
->current
!= vf
->priv
->root
) {
140 menu_t
* m
= vf
->priv
->current
;
141 vf
->priv
->current
= m
->parent
? m
->parent
: vf
->priv
->root
;
145 // Step 1 : save the picture
146 while(go2pause
== 1) {
147 static char delay
= 0; // Hack : wait the 2 frame to be sure to show the right picture
148 delay
^= 1; // after a seek
151 if(pause_mpi
&& (mpi
->w
!= pause_mpi
->w
|| mpi
->h
!= pause_mpi
->h
||
152 mpi
->imgfmt
!= pause_mpi
->imgfmt
)) {
153 free_mp_image(pause_mpi
);
157 pause_mpi
= alloc_mpi(mpi
->w
,mpi
->h
,mpi
->imgfmt
);
158 copy_mpi(pause_mpi
,mpi
);
159 mp_input_queue_cmd(mp_input_parse_cmd("pause"));
164 // Grab // Ungrab the keys
165 if(!mp_input_key_cb
&& vf
->priv
->current
->show
)
166 mp_input_key_cb
= key_cb
;
167 if(mp_input_key_cb
&& !vf
->priv
->current
->show
)
168 mp_input_key_cb
= NULL
;
170 if(mpi
->flags
&MP_IMGFLAG_DIRECT
)
173 dmpi
= vf_get_image(vf
->next
,mpi
->imgfmt
,
174 MP_IMGTYPE_TEMP
, MP_IMGFLAG_ACCEPT_STRIDE
,
178 menu_draw(vf
->priv
->current
,dmpi
);
182 mp_input_key_cb
= NULL
;
184 if(mpi
->flags
&MP_IMGFLAG_DIRECT
)
187 dmpi
= vf_get_image(vf
->next
,mpi
->imgfmt
,
188 MP_IMGTYPE_EXPORT
, MP_IMGFLAG_ACCEPT_STRIDE
,
191 dmpi
->stride
[0] = mpi
->stride
[0];
192 dmpi
->stride
[1] = mpi
->stride
[1];
193 dmpi
->stride
[2] = mpi
->stride
[2];
194 dmpi
->planes
[0] = mpi
->planes
[0];
195 dmpi
->planes
[1] = mpi
->planes
[1];
196 dmpi
->planes
[2] = mpi
->planes
[2];
197 dmpi
->priv
= mpi
->priv
;
200 return vf_next_put_image(vf
,dmpi
, pts
);
203 static void uninit(vf_instance_t
*vf
) {
206 free_mp_image(pause_mpi
);
211 static int config(struct vf_instance_s
* vf
, int width
, int height
, int d_width
, int d_height
,
212 unsigned int flags
, unsigned int outfmt
) {
214 // here is the right place to get screen dimensions
215 if (force_load_font
) {
217 load_font_ft(width
,height
,&vo_font
,font_name
);
220 if(outfmt
== IMGFMT_MPEGPES
)
221 vf
->priv
->passthrough
= 1;
222 return vf_next_config(vf
,width
,height
,d_width
,d_height
,flags
,outfmt
);
225 static int query_format(struct vf_instance_s
* vf
, unsigned int fmt
){
226 return (vf_next_query_format(vf
,fmt
));
229 static int open_vf(vf_instance_t
*vf
, char* args
){
231 st_priv
= calloc(1,sizeof(struct vf_priv_s
));
232 st_priv
->root
= st_priv
->current
= menu_open(args
);
233 if(!st_priv
->current
) {
238 st_priv
->root
->show
= menu_startup
;
239 mp_input_add_cmd_filter((mp_input_cmd_filter
)cmd_filter
,st_priv
);
243 vf
->query_format
=query_format
;
244 vf
->put_image
= put_image
;
245 vf
->get_image
= get_image
;
254 vf_info_t vf_info_menu
= {
255 "Internal filter for libmenu",