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 "libvo/video_out.h"
32 #include "sub/ass_mp.h"
35 //===========================================================================//
37 extern float sub_delay
;
42 ASS_Renderer
*renderer_realaspect
;
43 ASS_Renderer
*renderer_vsfilter
;
48 #define video_out (vf->priv->vo)
50 static int query_format(struct vf_instance
*vf
, unsigned int fmt
); /* forward declaration */
51 static void draw_slice(struct vf_instance
*vf
, unsigned char** src
, int* stride
, int w
,int h
, int x
, int y
);
53 static int config(struct vf_instance
*vf
,
54 int width
, int height
, int d_width
, int d_height
,
55 unsigned int flags
, unsigned int outfmt
){
57 if ((width
<= 0) || (height
<= 0) || (d_width
<= 0) || (d_height
<= 0))
59 mp_msg(MSGT_CPLAYER
, MSGL_ERR
, "VO: invalid dimensions!\n");
63 const vo_info_t
*info
= video_out
->driver
->info
;
64 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"VO: [%s] %dx%d => %dx%d %s %s%s%s%s\n",info
->short_name
,
67 vo_format_name(outfmt
),
68 (flags
&VOFLAG_FULLSCREEN
)?" [fs]":"",
69 (flags
&VOFLAG_MODESWITCHING
)?" [vm]":"",
70 (flags
&VOFLAG_SWSCALE
)?" [zoom]":"",
71 (flags
&VOFLAG_FLIPPING
)?" [flip]":"");
72 mp_msg(MSGT_CPLAYER
,MSGL_V
,"VO: Description: %s\n",info
->name
);
73 mp_msg(MSGT_CPLAYER
,MSGL_V
,"VO: Author: %s\n", info
->author
);
74 if(info
->comment
&& strlen(info
->comment
) > 0)
75 mp_msg(MSGT_CPLAYER
,MSGL_V
,"VO: Comment: %s\n", info
->comment
);
77 // save vo's stride capability for the wanted colorspace:
78 vf
->default_caps
=query_format(vf
,outfmt
);
79 vf
->draw_slice
= (vf
->default_caps
& VOCAP_NOSLICES
) ? NULL
: draw_slice
;
81 if (vo_config(video_out
, width
, height
, d_width
, d_height
, flags
, "MPlayer", outfmt
))
85 vf
->priv
->scale_ratio
= (double) d_width
/ d_height
* height
/ width
;
87 if (vf
->priv
->renderer_realaspect
) {
88 mp_ass_configure(vf
->priv
->renderer_realaspect
, width
, height
,
89 vf
->default_caps
& VFCAP_EOSD_UNSCALED
);
90 mp_ass_configure(vf
->priv
->renderer_vsfilter
, width
, height
,
91 vf
->default_caps
& VFCAP_EOSD_UNSCALED
);
98 static int control(struct vf_instance
*vf
, int request
, void* data
)
101 case VFCTRL_GET_DEINTERLACE
:
103 if(!video_out
) return CONTROL_FALSE
; // vo not configured?
104 return vo_control(video_out
, VOCTRL_GET_DEINTERLACE
, data
) == VO_TRUE
;
106 case VFCTRL_SET_DEINTERLACE
:
108 if(!video_out
) return CONTROL_FALSE
; // vo not configured?
109 return vo_control(video_out
, VOCTRL_SET_DEINTERLACE
, data
) == VO_TRUE
;
111 case VFCTRL_GET_YUV_COLORSPACE
:
112 return vo_control(video_out
, VOCTRL_GET_YUV_COLORSPACE
, data
) == true;
113 case VFCTRL_SET_YUV_COLORSPACE
:
114 return vo_control(video_out
, VOCTRL_SET_YUV_COLORSPACE
, data
) == true;
115 case VFCTRL_DRAW_OSD
:
116 if(!video_out
->config_ok
) return CONTROL_FALSE
; // vo not configured?
117 vo_draw_osd(video_out
, data
);
119 case VFCTRL_REDRAW_OSD
:
120 return vo_control(video_out
, VOCTRL_REDRAW_OSD
, data
) == true;
121 case VFCTRL_SET_EQUALIZER
:
123 vf_equalizer_t
*eq
=data
;
124 if(!video_out
->config_ok
) return CONTROL_FALSE
; // vo not configured?
125 struct voctrl_set_equalizer_args param
= {eq
->item
, eq
->value
};
126 return vo_control(video_out
, VOCTRL_SET_EQUALIZER
, ¶m
) == VO_TRUE
;
128 case VFCTRL_GET_EQUALIZER
:
130 vf_equalizer_t
*eq
=data
;
131 if(!video_out
->config_ok
) return CONTROL_FALSE
; // vo not configured?
132 struct voctrl_get_equalizer_args param
= {eq
->item
, &eq
->value
};
133 return vo_control(video_out
, VOCTRL_GET_EQUALIZER
, ¶m
) == VO_TRUE
;
136 case VFCTRL_INIT_EOSD
:
138 vf
->priv
->renderer_realaspect
= ass_renderer_init(data
);
139 if (!vf
->priv
->renderer_realaspect
)
140 return CONTROL_FALSE
;
141 vf
->priv
->renderer_vsfilter
= ass_renderer_init(data
);
142 if (!vf
->priv
->renderer_vsfilter
) {
143 ass_renderer_done(vf
->priv
->renderer_realaspect
);
144 return CONTROL_FALSE
;
146 mp_ass_configure_fonts(vf
->priv
->renderer_realaspect
);
147 mp_ass_configure_fonts(vf
->priv
->renderer_vsfilter
);
148 vf
->priv
->prev_visibility
= false;
151 case VFCTRL_DRAW_EOSD
:
153 struct osd_state
*osd
= data
;
154 mp_eosd_images_t images
= {NULL
, 2};
155 double pts
= video_out
->next_pts
;
156 ASS_Renderer
*renderer
;
158 if (osd
->vsfilter_aspect
) {
159 renderer
= vf
->priv
->renderer_vsfilter
;
160 scale
= vf
->priv
->scale_ratio
;
162 renderer
= vf
->priv
->renderer_realaspect
;
165 if (!video_out
->config_ok
|| !renderer
)
166 return CONTROL_FALSE
;
167 if (osd
->ass_track_changed
)
168 vf
->priv
->prev_visibility
= false;
169 osd
->ass_track_changed
= false;
170 if (sub_visibility
&& osd
->ass_track
&& (pts
!= MP_NOPTS_VALUE
)) {
171 struct mp_eosd_res res
= {0};
172 if (vo_control(video_out
, VOCTRL_GET_EOSD_RES
, &res
) == VO_TRUE
) {
173 ass_set_frame_size(renderer
, res
.w
, res
.h
);
174 ass_set_margins(renderer
, res
.mt
, res
.mb
, res
.ml
, res
.mr
);
175 ass_set_aspect_ratio(renderer
, scale
, 1);
178 images
.imgs
= mp_ass_render_frame(renderer
,
180 (pts
+sub_delay
) * 1000 + .5,
182 if (!vf
->priv
->prev_visibility
)
184 vf
->priv
->prev_visibility
= true;
186 vf
->priv
->prev_visibility
= false;
187 return vo_control(video_out
, VOCTRL_DRAW_EOSD
, &images
) == VO_TRUE
;
191 return CONTROL_UNKNOWN
;
194 static int query_format(struct vf_instance
*vf
, unsigned int fmt
){
195 int flags
= vo_control(video_out
, VOCTRL_QUERY_FORMAT
, &fmt
);
196 // draw_slice() accepts stride, draw_frame() doesn't:
198 if(fmt
==IMGFMT_YV12
|| fmt
==IMGFMT_I420
|| fmt
==IMGFMT_IYUV
)
199 flags
|=VFCAP_ACCEPT_STRIDE
;
203 static void get_image(struct vf_instance
*vf
,
205 if (!video_out
->config_ok
)
207 // GET_IMAGE is required for hardware-accelerated formats
208 if(vo_directrendering
||
209 IMGFMT_IS_HWACCEL(mpi
->imgfmt
))
210 vo_control(video_out
, VOCTRL_GET_IMAGE
, mpi
);
213 static int put_image(struct vf_instance
*vf
,
214 mp_image_t
*mpi
, double pts
){
215 if(!video_out
->config_ok
) return 0; // vo not configured?
216 // first check, maybe the vo/vf plugin implements draw_image using mpi:
217 if (vo_draw_image(video_out
, mpi
, pts
) >= 0)
219 // nope, fallback to old draw_frame/draw_slice:
220 if(!(mpi
->flags
&(MP_IMGFLAG_DIRECT
|MP_IMGFLAG_DRAW_CALLBACK
))){
222 // if(mpi->flags&MP_IMGFLAG_PLANAR)
223 if(vf
->default_caps
&VFCAP_ACCEPT_STRIDE
)
224 vo_draw_slice(video_out
, mpi
->planes
,mpi
->stride
,mpi
->w
,mpi
->h
,mpi
->x
,mpi
->y
);
226 vo_draw_frame(video_out
, mpi
->planes
);
231 static void start_slice(struct vf_instance
*vf
,
233 if(!video_out
->config_ok
) return; // vo not configured?
234 vo_control(video_out
, VOCTRL_START_SLICE
,mpi
);
237 static void draw_slice(struct vf_instance
*vf
,
238 unsigned char** src
, int* stride
, int w
,int h
, int x
, int y
){
239 if(!video_out
->config_ok
) return; // vo not configured?
240 vo_draw_slice(video_out
, src
,stride
,w
,h
,x
,y
);
243 static void uninit(struct vf_instance
*vf
)
246 /* Allow VO (which may live on to work with another instance of vf_vo)
247 * to get rid of numbered-mpi references that will now be invalid. */
248 vo_seek_reset(video_out
);
250 if (vf
->priv
->renderer_realaspect
) {
251 ass_renderer_done(vf
->priv
->renderer_realaspect
);
252 ass_renderer_done(vf
->priv
->renderer_vsfilter
);
258 //===========================================================================//
260 static int vf_open(vf_instance_t
*vf
, char *args
){
263 vf
->query_format
=query_format
;
264 vf
->get_image
=get_image
;
265 vf
->put_image
=put_image
;
266 vf
->draw_slice
=draw_slice
;
267 vf
->start_slice
=start_slice
;
269 vf
->priv
=calloc(1, sizeof(struct vf_priv_s
));
270 vf
->priv
->vo
= (struct vo
*)args
;
271 if(!video_out
) return 0; // no vo ?
275 const vf_info_t vf_info_vo
= {
284 //===========================================================================//