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.
31 #include "libvo/video_out.h"
33 #include "sub/ass_mp.h"
36 extern float sub_delay
;
41 ASS_Renderer
*renderer_realaspect
;
42 ASS_Renderer
*renderer_vsfilter
;
47 #define video_out (vf->priv->vo)
49 static int query_format(struct vf_instance
*vf
, unsigned int fmt
);
50 static void draw_slice(struct vf_instance
*vf
, unsigned char **src
,
51 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
)
58 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",
68 vo_format_name(outfmt
),
69 (flags
& VOFLAG_FULLSCREEN
) ? " [fs]" : "",
70 (flags
& VOFLAG_MODESWITCHING
) ? " [vm]" : "",
71 (flags
& VOFLAG_SWSCALE
) ? " [zoom]" : "",
72 (flags
& VOFLAG_FLIPPING
) ? " [flip]" : "");
73 mp_msg(MSGT_CPLAYER
, MSGL_V
, "VO: Description: %s\n", info
->name
);
74 mp_msg(MSGT_CPLAYER
, MSGL_V
, "VO: Author: %s\n", info
->author
);
75 if (info
->comment
&& strlen(info
->comment
) > 0)
76 mp_msg(MSGT_CPLAYER
, MSGL_V
, "VO: Comment: %s\n", info
->comment
);
78 // save vo's stride capability for the wanted colorspace:
79 vf
->default_caps
= query_format(vf
, outfmt
);
80 vf
->draw_slice
= (vf
->default_caps
& VOCAP_NOSLICES
) ? NULL
: draw_slice
;
82 if (vo_config(video_out
, width
, height
, d_width
, d_height
, flags
, outfmt
))
86 vf
->priv
->scale_ratio
= (double) d_width
/ d_height
* height
/ width
;
88 if (vf
->priv
->renderer_realaspect
) {
89 mp_ass_configure(vf
->priv
->renderer_realaspect
, vf
->opts
, width
, height
,
90 vf
->default_caps
& VFCAP_EOSD_UNSCALED
);
91 mp_ass_configure(vf
->priv
->renderer_vsfilter
, vf
->opts
, width
, height
,
92 vf
->default_caps
& VFCAP_EOSD_UNSCALED
);
95 // force EOSD change detection reset
96 vf
->priv
->prev_visibility
= false;
102 static int control(struct vf_instance
*vf
, int request
, void *data
)
105 case VFCTRL_GET_DEINTERLACE
:
107 return CONTROL_FALSE
; // vo not configured?
108 return vo_control(video_out
, VOCTRL_GET_DEINTERLACE
, data
) == VO_TRUE
;
109 case VFCTRL_SET_DEINTERLACE
:
111 return CONTROL_FALSE
; // vo not configured?
112 return vo_control(video_out
, VOCTRL_SET_DEINTERLACE
, data
) == VO_TRUE
;
113 case VFCTRL_GET_YUV_COLORSPACE
:
114 return vo_control(video_out
, VOCTRL_GET_YUV_COLORSPACE
, data
) == true;
115 case VFCTRL_SET_YUV_COLORSPACE
:
116 return vo_control(video_out
, VOCTRL_SET_YUV_COLORSPACE
, data
) == true;
117 case VFCTRL_DRAW_OSD
:
118 if (!video_out
->config_ok
)
119 return CONTROL_FALSE
; // vo not configured?
120 vo_draw_osd(video_out
, data
);
122 case VFCTRL_SET_EQUALIZER
: {
123 vf_equalizer_t
*eq
= data
;
124 if (!video_out
->config_ok
)
125 return CONTROL_FALSE
; // vo not configured?
126 struct voctrl_set_equalizer_args param
= {
129 return vo_control(video_out
, VOCTRL_SET_EQUALIZER
, ¶m
) == VO_TRUE
;
131 case VFCTRL_GET_EQUALIZER
: {
132 vf_equalizer_t
*eq
= data
;
133 if (!video_out
->config_ok
)
134 return CONTROL_FALSE
; // vo not configured?
135 struct voctrl_get_equalizer_args param
= {
138 return vo_control(video_out
, VOCTRL_GET_EQUALIZER
, ¶m
) == VO_TRUE
;
141 case VFCTRL_INIT_EOSD
: {
142 vf
->priv
->renderer_realaspect
= ass_renderer_init(data
);
143 if (!vf
->priv
->renderer_realaspect
)
144 return CONTROL_FALSE
;
145 vf
->priv
->renderer_vsfilter
= ass_renderer_init(data
);
146 if (!vf
->priv
->renderer_vsfilter
) {
147 ass_renderer_done(vf
->priv
->renderer_realaspect
);
148 return CONTROL_FALSE
;
150 mp_ass_configure_fonts(vf
->priv
->renderer_realaspect
);
151 mp_ass_configure_fonts(vf
->priv
->renderer_vsfilter
);
152 vf
->priv
->prev_visibility
= false;
155 case VFCTRL_DRAW_EOSD
: {
156 struct osd_state
*osd
= data
;
157 mp_eosd_images_t images
= { NULL
, 2 };
158 ASS_Renderer
*renderer
;
160 if (osd
->vsfilter_aspect
&& vf
->opts
->ass_vsfilter_aspect_compat
) {
161 renderer
= vf
->priv
->renderer_vsfilter
;
162 scale
= vf
->priv
->scale_ratio
;
164 renderer
= vf
->priv
->renderer_realaspect
;
167 if (!video_out
->config_ok
|| !renderer
)
168 return CONTROL_FALSE
;
169 if (osd
->ass_track_changed
)
170 vf
->priv
->prev_visibility
= false;
171 osd
->ass_track_changed
= false;
172 if (sub_visibility
&& osd
->ass_track
&& (osd
->pts
!= MP_NOPTS_VALUE
)) {
173 struct mp_eosd_res res
= { 0 };
174 if (vo_control(video_out
, VOCTRL_GET_EOSD_RES
, &res
) == VO_TRUE
) {
175 ass_set_frame_size(renderer
, res
.w
, res
.h
);
176 ass_set_margins(renderer
, res
.mt
, res
.mb
, res
.ml
, res
.mr
);
177 ass_set_aspect_ratio(renderer
, scale
, 1);
180 if (osd
->ass_force_reload
) {
181 mp_ass_reload_options(vf
->priv
->renderer_realaspect
, vf
->opts
);
182 mp_ass_reload_options(vf
->priv
->renderer_vsfilter
, vf
->opts
);
184 images
.imgs
= ass_render_frame(renderer
, osd
->ass_track
,
185 (osd
->pts
+ sub_delay
) * 1000 + .5,
187 if (!vf
->priv
->prev_visibility
|| osd
->ass_force_reload
)
189 osd
->ass_force_reload
= false;
190 vf
->priv
->prev_visibility
= true;
192 vf
->priv
->prev_visibility
= false;
193 return vo_control(video_out
, VOCTRL_DRAW_EOSD
, &images
) == VO_TRUE
;
197 return CONTROL_UNKNOWN
;
200 static int query_format(struct vf_instance
*vf
, unsigned int fmt
)
202 int flags
= vo_control(video_out
, VOCTRL_QUERY_FORMAT
, &fmt
);
203 // draw_slice() accepts stride, draw_frame() doesn't:
205 if (fmt
== IMGFMT_YV12
|| fmt
== IMGFMT_I420
|| fmt
== IMGFMT_IYUV
)
206 flags
|= VFCAP_ACCEPT_STRIDE
;
210 static void get_image(struct vf_instance
*vf
,
213 if (!video_out
->config_ok
)
215 // GET_IMAGE is required for hardware-accelerated formats
216 if (vo_directrendering
|| IMGFMT_IS_HWACCEL(mpi
->imgfmt
))
217 vo_control(video_out
, VOCTRL_GET_IMAGE
, mpi
);
220 static int put_image(struct vf_instance
*vf
, mp_image_t
*mpi
, double pts
)
222 if (!video_out
->config_ok
)
224 // first check, maybe the vo/vf plugin implements draw_image using mpi:
225 if (vo_draw_image(video_out
, mpi
, pts
) >= 0)
227 // nope, fallback to old draw_frame/draw_slice:
228 if (!(mpi
->flags
& (MP_IMGFLAG_DIRECT
| MP_IMGFLAG_DRAW_CALLBACK
))) {
230 if (vf
->default_caps
& VFCAP_ACCEPT_STRIDE
)
231 vo_draw_slice(video_out
, mpi
->planes
, mpi
->stride
, mpi
->w
, mpi
->h
,
234 vo_draw_frame(video_out
, mpi
->planes
);
239 static void start_slice(struct vf_instance
*vf
, mp_image_t
*mpi
)
241 if (!video_out
->config_ok
)
243 vo_control(video_out
, VOCTRL_START_SLICE
, mpi
);
246 static void draw_slice(struct vf_instance
*vf
, unsigned char **src
,
247 int *stride
, int w
, int h
, int x
, int y
)
249 if (!video_out
->config_ok
)
251 vo_draw_slice(video_out
, src
, stride
, w
, h
, x
, y
);
254 static void uninit(struct vf_instance
*vf
)
257 /* Allow VO (which may live on to work with another instance of vf_vo)
258 * to get rid of numbered-mpi references that will now be invalid. */
259 vo_seek_reset(video_out
);
261 if (vf
->priv
->renderer_realaspect
) {
262 ass_renderer_done(vf
->priv
->renderer_realaspect
);
263 ass_renderer_done(vf
->priv
->renderer_vsfilter
);
270 static int vf_open(vf_instance_t
*vf
, char *args
)
273 vf
->control
= control
;
274 vf
->query_format
= query_format
;
275 vf
->get_image
= get_image
;
276 vf
->put_image
= put_image
;
277 vf
->draw_slice
= draw_slice
;
278 vf
->start_slice
= start_slice
;
280 vf
->priv
= calloc(1, sizeof(struct vf_priv_s
));
281 vf
->priv
->vo
= (struct vo
*)args
;
287 const vf_info_t vf_info_vo
= {