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 "libvo/sub.h"
25 #include "input/input.h"
28 #include "access_mpcontext.h"
31 static struct vf_priv_s
* st_priv
= NULL
;
33 static mp_image_t
* pause_mpi
= NULL
;
34 static int go2pause
= 0;
35 /// if nonzero display menu at startup
36 int attribute_used menu_startup
= 0;
44 static int put_image(struct vf_instance_s
* vf
, mp_image_t
*mpi
, double pts
);
46 void vf_menu_pause_update(struct vf_instance_s
* vf
) {
47 const vo_functions_t
*video_out
= mpctx_get_video_out(vf
->priv
->current
->ctx
);
49 put_image(vf
,pause_mpi
, MP_NOPTS_VALUE
);
50 // Don't draw the osd atm
51 //vf->control(vf,VFCTRL_DRAW_OSD,NULL);
52 video_out
->flip_page();
56 static int cmd_filter(mp_cmd_t
* cmd
, int paused
, struct vf_priv_s
* priv
) {
59 case MP_CMD_MENU
: { // Convert txt cmd from the users into libmenu stuff
60 char* arg
= cmd
->args
[0].v
.s
;
62 if(!priv
->current
->show
&& !(strcmp(arg
,"hide") == 0) )
63 priv
->current
->show
= 1;
64 else if(strcmp(arg
,"up") == 0)
65 menu_read_cmd(priv
->current
,MENU_CMD_UP
);
66 else if(strcmp(arg
,"down") == 0)
67 menu_read_cmd(priv
->current
,MENU_CMD_DOWN
);
68 else if(strcmp(arg
,"left") == 0)
69 menu_read_cmd(priv
->current
,MENU_CMD_LEFT
);
70 else if(strcmp(arg
,"right") == 0)
71 menu_read_cmd(priv
->current
,MENU_CMD_RIGHT
);
72 else if(strcmp(arg
,"ok") == 0)
73 menu_read_cmd(priv
->current
,MENU_CMD_OK
);
74 else if(strcmp(arg
,"cancel") == 0)
75 menu_read_cmd(priv
->current
,MENU_CMD_CANCEL
);
76 else if(strcmp(arg
,"home") == 0)
77 menu_read_cmd(priv
->current
,MENU_CMD_HOME
);
78 else if(strcmp(arg
,"end") == 0)
79 menu_read_cmd(priv
->current
,MENU_CMD_END
);
80 else if(strcmp(arg
,"pageup") == 0)
81 menu_read_cmd(priv
->current
,MENU_CMD_PAGE_UP
);
82 else if(strcmp(arg
,"pagedown") == 0)
83 menu_read_cmd(priv
->current
,MENU_CMD_PAGE_DOWN
);
84 else if(strcmp(arg
,"hide") == 0 || strcmp(arg
,"toggle") == 0)
85 priv
->current
->show
= 0;
87 mp_msg(MSGT_GLOBAL
,MSGL_WARN
,MSGTR_LIBMENU_UnknownMenuCommand
,arg
);
90 case MP_CMD_SET_MENU
: {
91 char* menu
= cmd
->args
[0].v
.s
;
92 menu_t
* l
= priv
->current
;
93 priv
->current
= menu_open(menu
);
95 mp_msg(MSGT_GLOBAL
,MSGL_WARN
,MSGTR_LIBMENU_FailedToOpenMenu
,menu
);
97 priv
->current
->show
= 0;
99 priv
->current
->show
= 1;
100 priv
->current
->parent
= l
;
108 static void get_image(struct vf_instance_s
* vf
, mp_image_t
*mpi
){
111 if(mpi
->type
== MP_IMGTYPE_TEMP
&& (!(mpi
->flags
&MP_IMGFLAG_PRESERVE
)) ) {
112 dmpi
= vf_get_image(vf
->next
,mpi
->imgfmt
,mpi
->type
, mpi
->flags
, mpi
->w
, mpi
->h
);
113 memcpy(mpi
->planes
,dmpi
->planes
,MP_MAX_PLANES
*sizeof(unsigned char*));
114 memcpy(mpi
->stride
,dmpi
->stride
,MP_MAX_PLANES
*sizeof(unsigned int));
115 mpi
->flags
|=MP_IMGFLAG_DIRECT
;
116 mpi
->priv
=(void*)dmpi
;
121 static void key_cb(int code
) {
122 menu_read_key(st_priv
->current
,code
);
125 static int put_image(struct vf_instance_s
* vf
, mp_image_t
*mpi
, double pts
){
126 mp_image_t
*dmpi
= NULL
;
128 if (vf
->priv
->passthrough
) {
129 dmpi
=vf_get_image(vf
->next
, IMGFMT_MPEGPES
, MP_IMGTYPE_EXPORT
,
131 dmpi
->planes
[0]=mpi
->planes
[0];
132 return vf_next_put_image(vf
,dmpi
, pts
);
135 // Close all menu who requested it
136 while(vf
->priv
->current
->cl
&& vf
->priv
->current
!= vf
->priv
->root
) {
137 menu_t
* m
= vf
->priv
->current
;
138 vf
->priv
->current
= m
->parent
? m
->parent
: vf
->priv
->root
;
142 // Try to capture the last frame before pause, or fallback to use
143 // last captured frame.
144 if(pause_mpi
&& (mpi
->w
!= pause_mpi
->w
|| mpi
->h
!= pause_mpi
->h
||
145 mpi
->imgfmt
!= pause_mpi
->imgfmt
)) {
146 free_mp_image(pause_mpi
);
150 pause_mpi
= alloc_mpi(mpi
->w
,mpi
->h
,mpi
->imgfmt
);
151 copy_mpi(pause_mpi
,mpi
);
153 else if (mpctx_get_osd_function(vf
->priv
->root
->ctx
) == OSD_PAUSE
)
154 copy_mpi(pause_mpi
,mpi
);
156 if (vf
->priv
->current
->show
) {
157 if (!mp_input_key_cb
)
158 mp_input_key_cb
= key_cb
;
160 if(mpi
->flags
&MP_IMGFLAG_DIRECT
)
163 dmpi
= vf_get_image(vf
->next
,mpi
->imgfmt
,
164 MP_IMGTYPE_TEMP
, MP_IMGFLAG_ACCEPT_STRIDE
,
168 menu_draw(vf
->priv
->current
,dmpi
);
172 mp_input_key_cb
= NULL
;
174 if(mpi
->flags
&MP_IMGFLAG_DIRECT
)
177 dmpi
= vf_get_image(vf
->next
,mpi
->imgfmt
,
178 MP_IMGTYPE_EXPORT
, MP_IMGFLAG_ACCEPT_STRIDE
,
181 dmpi
->stride
[0] = mpi
->stride
[0];
182 dmpi
->stride
[1] = mpi
->stride
[1];
183 dmpi
->stride
[2] = mpi
->stride
[2];
184 dmpi
->planes
[0] = mpi
->planes
[0];
185 dmpi
->planes
[1] = mpi
->planes
[1];
186 dmpi
->planes
[2] = mpi
->planes
[2];
187 dmpi
->priv
= mpi
->priv
;
190 return vf_next_put_image(vf
,dmpi
, pts
);
193 static void uninit(vf_instance_t
*vf
) {
196 free_mp_image(pause_mpi
);
201 static int config(struct vf_instance_s
* vf
, int width
, int height
, int d_width
, int d_height
,
202 unsigned int flags
, unsigned int outfmt
) {
204 // here is the right place to get screen dimensions
205 if (force_load_font
) {
207 load_font_ft(width
,height
,&vo_font
,font_name
);
210 if(outfmt
== IMGFMT_MPEGPES
)
211 vf
->priv
->passthrough
= 1;
212 return vf_next_config(vf
,width
,height
,d_width
,d_height
,flags
,outfmt
);
215 static int query_format(struct vf_instance_s
* vf
, unsigned int fmt
){
216 return (vf_next_query_format(vf
,fmt
));
219 static int open_vf(vf_instance_t
*vf
, char* args
){
221 st_priv
= calloc(1,sizeof(struct vf_priv_s
));
222 st_priv
->root
= st_priv
->current
= menu_open(args
);
223 if(!st_priv
->current
) {
228 st_priv
->root
->show
= menu_startup
;
229 mp_input_add_cmd_filter((mp_input_cmd_filter
)cmd_filter
,st_priv
);
233 vf
->query_format
=query_format
;
234 vf
->put_image
= put_image
;
235 vf
->get_image
= get_image
;
244 vf_info_t vf_info_menu
= {
245 "Internal filter for libmenu",