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.
30 #include "libmpcodecs/img_format.h"
31 #include "libmpcodecs/mp_image.h"
32 #include "libmpcodecs/vf.h"
34 #include "libvo/fastmemcpy.h"
35 #include "libvo/video_out.h"
36 #include "libvo/font_load.h"
37 #include "libvo/sub.h"
38 #include "input/input.h"
41 #include "access_mpcontext.h"
44 static struct vf_priv_s
* st_priv
= NULL
;
46 static mp_image_t
* pause_mpi
= NULL
;
47 static int go2pause
= 0;
48 /// if nonzero display menu at startup
57 static int put_image(struct vf_instance_s
* vf
, mp_image_t
*mpi
, double pts
);
59 void vf_menu_pause_update(struct vf_instance_s
* vf
) {
60 const vo_functions_t
*video_out
= mpctx_get_video_out(vf
->priv
->current
->ctx
);
62 put_image(vf
,pause_mpi
, MP_NOPTS_VALUE
);
63 // Don't draw the osd atm
64 //vf->control(vf,VFCTRL_DRAW_OSD,NULL);
65 video_out
->flip_page();
69 static int cmd_filter(mp_cmd_t
* cmd
, int paused
, struct vf_priv_s
* priv
) {
72 case MP_CMD_MENU
: { // Convert txt cmd from the users into libmenu stuff
73 char* arg
= cmd
->args
[0].v
.s
;
75 if (!priv
->current
->show
&& strcmp(arg
,"hide"))
76 priv
->current
->show
= 1;
77 else if(strcmp(arg
,"up") == 0)
78 menu_read_cmd(priv
->current
,MENU_CMD_UP
);
79 else if(strcmp(arg
,"down") == 0)
80 menu_read_cmd(priv
->current
,MENU_CMD_DOWN
);
81 else if(strcmp(arg
,"left") == 0)
82 menu_read_cmd(priv
->current
,MENU_CMD_LEFT
);
83 else if(strcmp(arg
,"right") == 0)
84 menu_read_cmd(priv
->current
,MENU_CMD_RIGHT
);
85 else if(strcmp(arg
,"ok") == 0)
86 menu_read_cmd(priv
->current
,MENU_CMD_OK
);
87 else if(strcmp(arg
,"cancel") == 0)
88 menu_read_cmd(priv
->current
,MENU_CMD_CANCEL
);
89 else if(strcmp(arg
,"home") == 0)
90 menu_read_cmd(priv
->current
,MENU_CMD_HOME
);
91 else if(strcmp(arg
,"end") == 0)
92 menu_read_cmd(priv
->current
,MENU_CMD_END
);
93 else if(strcmp(arg
,"pageup") == 0)
94 menu_read_cmd(priv
->current
,MENU_CMD_PAGE_UP
);
95 else if(strcmp(arg
,"pagedown") == 0)
96 menu_read_cmd(priv
->current
,MENU_CMD_PAGE_DOWN
);
97 else if(strcmp(arg
,"click") == 0)
98 menu_read_cmd(priv
->current
,MENU_CMD_CLICK
);
99 else if(strcmp(arg
,"hide") == 0 || strcmp(arg
,"toggle") == 0)
100 priv
->current
->show
= 0;
102 mp_msg(MSGT_GLOBAL
,MSGL_WARN
,MSGTR_LIBMENU_UnknownMenuCommand
,arg
);
105 case MP_CMD_SET_MENU
: {
106 char* menu
= cmd
->args
[0].v
.s
;
107 menu_t
* l
= priv
->current
;
108 priv
->current
= menu_open(menu
);
110 mp_msg(MSGT_GLOBAL
,MSGL_WARN
,MSGTR_LIBMENU_FailedToOpenMenu
,menu
);
112 priv
->current
->show
= 0;
114 priv
->current
->show
= 1;
115 priv
->current
->parent
= l
;
123 static void get_image(struct vf_instance_s
* vf
, mp_image_t
*mpi
){
126 if(mpi
->type
== MP_IMGTYPE_TEMP
&& (!(mpi
->flags
&MP_IMGFLAG_PRESERVE
)) ) {
127 dmpi
= vf_get_image(vf
->next
,mpi
->imgfmt
,mpi
->type
, mpi
->flags
, mpi
->w
, mpi
->h
);
128 memcpy(mpi
->planes
,dmpi
->planes
,MP_MAX_PLANES
*sizeof(unsigned char*));
129 memcpy(mpi
->stride
,dmpi
->stride
,MP_MAX_PLANES
*sizeof(unsigned int));
130 mpi
->flags
|=MP_IMGFLAG_DIRECT
;
131 mpi
->priv
=(void*)dmpi
;
136 static int key_cb(int code
) {
137 return menu_read_key(st_priv
->current
,code
);
140 static int put_image(struct vf_instance_s
* vf
, mp_image_t
*mpi
, double pts
){
141 mp_image_t
*dmpi
= NULL
;
143 if (vf
->priv
->passthrough
) {
144 dmpi
=vf_get_image(vf
->next
, IMGFMT_MPEGPES
, MP_IMGTYPE_EXPORT
,
146 dmpi
->planes
[0]=mpi
->planes
[0];
147 return vf_next_put_image(vf
,dmpi
, pts
);
150 // Close all menu who requested it
151 while(vf
->priv
->current
->cl
&& vf
->priv
->current
!= vf
->priv
->root
) {
152 menu_t
* m
= vf
->priv
->current
;
153 vf
->priv
->current
= m
->parent
? m
->parent
: vf
->priv
->root
;
157 // Try to capture the last frame before pause, or fallback to use
158 // last captured frame.
159 if(pause_mpi
&& (mpi
->w
!= pause_mpi
->w
|| mpi
->h
!= pause_mpi
->h
||
160 mpi
->imgfmt
!= pause_mpi
->imgfmt
)) {
161 free_mp_image(pause_mpi
);
165 pause_mpi
= alloc_mpi(mpi
->w
,mpi
->h
,mpi
->imgfmt
);
166 copy_mpi(pause_mpi
,mpi
);
168 else if (mpctx_get_osd_function(vf
->priv
->root
->ctx
) == OSD_PAUSE
)
169 copy_mpi(pause_mpi
,mpi
);
171 if (vf
->priv
->current
->show
) {
172 if (!mp_input_key_cb
)
173 mp_input_key_cb
= key_cb
;
175 if(mpi
->flags
&MP_IMGFLAG_DIRECT
)
178 dmpi
= vf_get_image(vf
->next
,mpi
->imgfmt
,
179 MP_IMGTYPE_TEMP
, MP_IMGFLAG_ACCEPT_STRIDE
,
183 menu_draw(vf
->priv
->current
,dmpi
);
187 mp_input_key_cb
= NULL
;
189 if(mpi
->flags
&MP_IMGFLAG_DIRECT
)
192 dmpi
= vf_get_image(vf
->next
,mpi
->imgfmt
,
193 MP_IMGTYPE_EXPORT
, MP_IMGFLAG_ACCEPT_STRIDE
,
196 dmpi
->stride
[0] = mpi
->stride
[0];
197 dmpi
->stride
[1] = mpi
->stride
[1];
198 dmpi
->stride
[2] = mpi
->stride
[2];
199 dmpi
->planes
[0] = mpi
->planes
[0];
200 dmpi
->planes
[1] = mpi
->planes
[1];
201 dmpi
->planes
[2] = mpi
->planes
[2];
202 dmpi
->priv
= mpi
->priv
;
205 return vf_next_put_image(vf
,dmpi
, pts
);
208 static void uninit(vf_instance_t
*vf
) {
211 free_mp_image(pause_mpi
);
216 static int config(struct vf_instance_s
* vf
, int width
, int height
, int d_width
, int d_height
,
217 unsigned int flags
, unsigned int outfmt
) {
218 #ifdef CONFIG_FREETYPE
219 // here is the right place to get screen dimensions
220 if (force_load_font
) {
222 load_font_ft(width
,height
,&vo_font
,font_name
,osd_font_scale_factor
);
225 if(outfmt
== IMGFMT_MPEGPES
)
226 vf
->priv
->passthrough
= 1;
227 return vf_next_config(vf
,width
,height
,d_width
,d_height
,flags
,outfmt
);
230 static int query_format(struct vf_instance_s
* vf
, unsigned int fmt
){
231 return vf_next_query_format(vf
,fmt
);
234 static int open_vf(vf_instance_t
*vf
, char* args
){
236 st_priv
= calloc(1,sizeof(struct vf_priv_s
));
237 st_priv
->root
= st_priv
->current
= menu_open(args
);
238 if(!st_priv
->current
) {
243 st_priv
->root
->show
= menu_startup
;
244 mp_input_add_cmd_filter((mp_input_cmd_filter
)cmd_filter
,st_priv
);
248 vf
->query_format
=query_format
;
249 vf
->put_image
= put_image
;
250 vf
->get_image
= get_image
;
259 vf_info_t vf_info_menu
= {
260 "Internal filter for libmenu",