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
* vf
, mp_image_t
*mpi
, double pts
);
46 void vf_menu_pause_update(struct vf_instance
* vf
) {
47 const struct vo
*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 vo_flip_page(video_out
);
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"))
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
,"click") == 0)
85 menu_read_cmd(priv
->current
,MENU_CMD_CLICK
);
86 else if(strcmp(arg
,"hide") == 0 || strcmp(arg
,"toggle") == 0)
87 priv
->current
->show
= 0;
89 mp_msg(MSGT_GLOBAL
,MSGL_WARN
,MSGTR_LIBMENU_UnknownMenuCommand
,arg
);
92 case MP_CMD_SET_MENU
: {
93 char* menu
= cmd
->args
[0].v
.s
;
94 menu_t
* l
= priv
->current
;
95 priv
->current
= menu_open(menu
);
97 mp_msg(MSGT_GLOBAL
,MSGL_WARN
,MSGTR_LIBMENU_FailedToOpenMenu
,menu
);
99 priv
->current
->show
= 0;
101 priv
->current
->show
= 1;
102 priv
->current
->parent
= l
;
110 static void get_image(struct vf_instance
* vf
, mp_image_t
*mpi
){
113 if(mpi
->type
== MP_IMGTYPE_TEMP
&& (!(mpi
->flags
&MP_IMGFLAG_PRESERVE
)) ) {
114 dmpi
= vf_get_image(vf
->next
,mpi
->imgfmt
,mpi
->type
, mpi
->flags
, mpi
->w
, mpi
->h
);
115 memcpy(mpi
->planes
,dmpi
->planes
,MP_MAX_PLANES
*sizeof(unsigned char*));
116 memcpy(mpi
->stride
,dmpi
->stride
,MP_MAX_PLANES
*sizeof(unsigned int));
117 mpi
->flags
|=MP_IMGFLAG_DIRECT
;
118 mpi
->priv
=(void*)dmpi
;
123 static int key_cb(int code
) {
124 return menu_read_key(st_priv
->current
,code
);
127 static int put_image(struct vf_instance
* vf
, mp_image_t
*mpi
, double pts
){
128 mp_image_t
*dmpi
= NULL
;
130 if (vf
->priv
->passthrough
) {
131 dmpi
=vf_get_image(vf
->next
, IMGFMT_MPEGPES
, MP_IMGTYPE_EXPORT
,
133 dmpi
->planes
[0]=mpi
->planes
[0];
134 return vf_next_put_image(vf
,dmpi
, pts
);
137 // Close all menu who requested it
138 while(vf
->priv
->current
->cl
&& vf
->priv
->current
!= vf
->priv
->root
) {
139 menu_t
* m
= vf
->priv
->current
;
140 vf
->priv
->current
= m
->parent
? m
->parent
: vf
->priv
->root
;
144 // Try to capture the last frame before pause, or fallback to use
145 // last captured frame.
146 if(pause_mpi
&& (mpi
->w
!= pause_mpi
->w
|| mpi
->h
!= pause_mpi
->h
||
147 mpi
->imgfmt
!= pause_mpi
->imgfmt
)) {
148 free_mp_image(pause_mpi
);
152 pause_mpi
= alloc_mpi(mpi
->w
,mpi
->h
,mpi
->imgfmt
);
153 copy_mpi(pause_mpi
,mpi
);
155 else if (mpctx_get_osd_function(vf
->priv
->root
->ctx
) == OSD_PAUSE
)
156 copy_mpi(pause_mpi
,mpi
);
158 if (vf
->priv
->current
->show
) {
159 if (!mp_input_key_cb
)
160 mp_input_key_cb
= key_cb
;
162 if(mpi
->flags
&MP_IMGFLAG_DIRECT
)
165 dmpi
= vf_get_image(vf
->next
,mpi
->imgfmt
,
166 MP_IMGTYPE_TEMP
, MP_IMGFLAG_ACCEPT_STRIDE
,
170 menu_draw(vf
->priv
->current
,dmpi
);
174 mp_input_key_cb
= NULL
;
176 if(mpi
->flags
&MP_IMGFLAG_DIRECT
)
179 dmpi
= vf_get_image(vf
->next
,mpi
->imgfmt
,
180 MP_IMGTYPE_EXPORT
, MP_IMGFLAG_ACCEPT_STRIDE
,
183 dmpi
->stride
[0] = mpi
->stride
[0];
184 dmpi
->stride
[1] = mpi
->stride
[1];
185 dmpi
->stride
[2] = mpi
->stride
[2];
186 dmpi
->planes
[0] = mpi
->planes
[0];
187 dmpi
->planes
[1] = mpi
->planes
[1];
188 dmpi
->planes
[2] = mpi
->planes
[2];
189 dmpi
->priv
= mpi
->priv
;
192 return vf_next_put_image(vf
,dmpi
, pts
);
195 static void uninit(vf_instance_t
*vf
) {
198 free_mp_image(pause_mpi
);
203 static int config(struct vf_instance
* vf
, int width
, int height
, int d_width
, int d_height
,
204 unsigned int flags
, unsigned int outfmt
) {
205 #ifdef CONFIG_FREETYPE
206 // here is the right place to get screen dimensions
207 if (force_load_font
) {
209 load_font_ft(width
,height
,&vo_font
,font_name
,osd_font_scale_factor
);
212 if(outfmt
== IMGFMT_MPEGPES
)
213 vf
->priv
->passthrough
= 1;
214 return vf_next_config(vf
,width
,height
,d_width
,d_height
,flags
,outfmt
);
217 static int query_format(struct vf_instance
* vf
, unsigned int fmt
){
218 return vf_next_query_format(vf
, fmt
);
221 static int open_vf(vf_instance_t
*vf
, char* args
){
223 st_priv
= calloc(1,sizeof(struct vf_priv_s
));
224 st_priv
->root
= st_priv
->current
= menu_open(args
);
225 if(!st_priv
->current
) {
230 st_priv
->root
->show
= menu_startup
;
231 mp_input_add_cmd_filter((mp_input_cmd_filter
)cmd_filter
,st_priv
);
235 vf
->query_format
=query_format
;
236 vf
->put_image
= put_image
;
237 vf
->get_image
= get_image
;
246 vf_info_t vf_info_menu
= {
247 "Internal filter for libmenu",