2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include "libmpcodecs/img_format.h"
30 #include "libmpcodecs/mp_image.h"
31 #include "libmpcodecs/vf.h"
33 #include "libvo/fastmemcpy.h"
34 #include "libvo/video_out.h"
35 #include "libvo/font_load.h"
36 #include "libvo/sub.h"
37 #include "input/input.h"
40 #include "access_mpcontext.h"
43 static struct vf_priv_s
* st_priv
= NULL
;
45 static mp_image_t
* pause_mpi
= NULL
;
46 static int go2pause
= 0;
47 /// if nonzero display menu at startup
56 static int put_image(struct vf_instance
* vf
, mp_image_t
*mpi
, double pts
);
58 void vf_menu_pause_update(struct vf_instance
* vf
) {
59 const struct vo
*video_out
= mpctx_get_video_out(vf
->priv
->current
->ctx
);
61 put_image(vf
,pause_mpi
, MP_NOPTS_VALUE
);
62 // Don't draw the osd atm
63 //vf->control(vf,VFCTRL_DRAW_OSD,NULL);
64 vo_flip_page(video_out
, 0, -1);
68 static int cmd_filter(mp_cmd_t
* cmd
, int paused
, struct vf_priv_s
* priv
) {
71 case MP_CMD_MENU
: { // Convert txt cmd from the users into libmenu stuff
72 char* arg
= cmd
->args
[0].v
.s
;
74 if (!priv
->current
->show
&& strcmp(arg
,"hide"))
75 priv
->current
->show
= 1;
76 else if(strcmp(arg
,"up") == 0)
77 menu_read_cmd(priv
->current
,MENU_CMD_UP
);
78 else if(strcmp(arg
,"down") == 0)
79 menu_read_cmd(priv
->current
,MENU_CMD_DOWN
);
80 else if(strcmp(arg
,"left") == 0)
81 menu_read_cmd(priv
->current
,MENU_CMD_LEFT
);
82 else if(strcmp(arg
,"right") == 0)
83 menu_read_cmd(priv
->current
,MENU_CMD_RIGHT
);
84 else if(strcmp(arg
,"ok") == 0)
85 menu_read_cmd(priv
->current
,MENU_CMD_OK
);
86 else if(strcmp(arg
,"cancel") == 0)
87 menu_read_cmd(priv
->current
,MENU_CMD_CANCEL
);
88 else if(strcmp(arg
,"home") == 0)
89 menu_read_cmd(priv
->current
,MENU_CMD_HOME
);
90 else if(strcmp(arg
,"end") == 0)
91 menu_read_cmd(priv
->current
,MENU_CMD_END
);
92 else if(strcmp(arg
,"pageup") == 0)
93 menu_read_cmd(priv
->current
,MENU_CMD_PAGE_UP
);
94 else if(strcmp(arg
,"pagedown") == 0)
95 menu_read_cmd(priv
->current
,MENU_CMD_PAGE_DOWN
);
96 else if(strcmp(arg
,"click") == 0)
97 menu_read_cmd(priv
->current
,MENU_CMD_CLICK
);
98 else if(strcmp(arg
,"hide") == 0 || strcmp(arg
,"toggle") == 0)
99 priv
->current
->show
= 0;
101 mp_tmsg(MSGT_GLOBAL
,MSGL_WARN
,"[MENU] Unknown command: '%s'.\n",arg
);
104 case MP_CMD_SET_MENU
: {
105 char* menu
= cmd
->args
[0].v
.s
;
106 menu_t
* l
= priv
->current
;
107 priv
->current
= menu_open(menu
);
109 mp_tmsg(MSGT_GLOBAL
,MSGL_WARN
,"[MENU] Failed to open menu: '%s'.\n",menu
);
111 priv
->current
->show
= 0;
113 priv
->current
->show
= 1;
114 priv
->current
->parent
= l
;
122 static void get_image(struct vf_instance
* vf
, mp_image_t
*mpi
){
125 if(mpi
->type
== MP_IMGTYPE_TEMP
&& (!(mpi
->flags
&MP_IMGFLAG_PRESERVE
)) ) {
126 dmpi
= vf_get_image(vf
->next
,mpi
->imgfmt
,mpi
->type
, mpi
->flags
, mpi
->w
, mpi
->h
);
127 memcpy(mpi
->planes
,dmpi
->planes
,MP_MAX_PLANES
*sizeof(unsigned char*));
128 memcpy(mpi
->stride
,dmpi
->stride
,MP_MAX_PLANES
*sizeof(unsigned int));
129 mpi
->flags
|=MP_IMGFLAG_DIRECT
;
130 mpi
->priv
=(void*)dmpi
;
135 static int key_cb(int code
) {
136 return menu_read_key(st_priv
->current
,code
);
139 static int put_image(struct vf_instance
* vf
, mp_image_t
*mpi
, double pts
){
140 mp_image_t
*dmpi
= NULL
;
142 if (vf
->priv
->passthrough
) {
143 dmpi
=vf_get_image(vf
->next
, IMGFMT_MPEGPES
, MP_IMGTYPE_EXPORT
,
145 dmpi
->planes
[0]=mpi
->planes
[0];
146 return vf_next_put_image(vf
,dmpi
, pts
);
149 // Close all menu who requested it
150 while(vf
->priv
->current
->cl
&& vf
->priv
->current
!= vf
->priv
->root
) {
151 menu_t
* m
= vf
->priv
->current
;
152 vf
->priv
->current
= m
->parent
? m
->parent
: vf
->priv
->root
;
156 // Try to capture the last frame before pause, or fallback to use
157 // last captured frame.
158 if(pause_mpi
&& (mpi
->w
!= pause_mpi
->w
|| mpi
->h
!= pause_mpi
->h
||
159 mpi
->imgfmt
!= pause_mpi
->imgfmt
)) {
160 free_mp_image(pause_mpi
);
164 pause_mpi
= alloc_mpi(mpi
->w
,mpi
->h
,mpi
->imgfmt
);
165 copy_mpi(pause_mpi
,mpi
);
167 else if (mpctx_get_osd_function(vf
->priv
->root
->ctx
) == OSD_PAUSE
)
168 copy_mpi(pause_mpi
,mpi
);
170 if (vf
->priv
->current
->show
) {
171 if (!mp_input_key_cb
)
172 mp_input_key_cb
= key_cb
;
174 if(mpi
->flags
&MP_IMGFLAG_DIRECT
)
177 dmpi
= vf_get_image(vf
->next
,mpi
->imgfmt
,
178 MP_IMGTYPE_TEMP
, MP_IMGFLAG_ACCEPT_STRIDE
,
182 menu_draw(vf
->priv
->current
,dmpi
);
186 mp_input_key_cb
= NULL
;
188 if(mpi
->flags
&MP_IMGFLAG_DIRECT
)
191 dmpi
= vf_get_image(vf
->next
,mpi
->imgfmt
,
192 MP_IMGTYPE_EXPORT
, MP_IMGFLAG_ACCEPT_STRIDE
,
195 dmpi
->stride
[0] = mpi
->stride
[0];
196 dmpi
->stride
[1] = mpi
->stride
[1];
197 dmpi
->stride
[2] = mpi
->stride
[2];
198 dmpi
->planes
[0] = mpi
->planes
[0];
199 dmpi
->planes
[1] = mpi
->planes
[1];
200 dmpi
->planes
[2] = mpi
->planes
[2];
201 dmpi
->priv
= mpi
->priv
;
204 return vf_next_put_image(vf
,dmpi
, pts
);
207 static void uninit(vf_instance_t
*vf
) {
210 free_mp_image(pause_mpi
);
215 static int config(struct vf_instance
* vf
, int width
, int height
, int d_width
, int d_height
,
216 unsigned int flags
, unsigned int outfmt
) {
217 #ifdef CONFIG_FREETYPE
218 // here is the right place to get screen dimensions
219 if (force_load_font
) {
221 load_font_ft(width
,height
,&vo_font
,font_name
,osd_font_scale_factor
);
224 if(outfmt
== IMGFMT_MPEGPES
)
225 vf
->priv
->passthrough
= 1;
226 return vf_next_config(vf
,width
,height
,d_width
,d_height
,flags
,outfmt
);
229 static int query_format(struct vf_instance
* vf
, unsigned int fmt
){
230 return vf_next_query_format(vf
, fmt
);
233 static int open_vf(vf_instance_t
*vf
, char* args
){
235 st_priv
= calloc(1,sizeof(struct vf_priv_s
));
236 st_priv
->root
= st_priv
->current
= menu_open(args
);
237 if(!st_priv
->current
) {
242 st_priv
->root
->show
= menu_startup
;
243 mp_input_add_cmd_filter((mp_input_cmd_filter
)cmd_filter
,st_priv
);
247 vf
->query_format
=query_format
;
248 vf
->put_image
= put_image
;
249 vf
->get_image
= get_image
;
258 vf_info_t vf_info_menu
= {
259 "Internal filter for libmenu",