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 "libvo/sub.h"
30 #include "libvo/video_out.h"
33 #include "libass/ass_mp.h"
36 //===========================================================================//
40 const vo_functions_t *vo;
42 ass_renderer_t* ass_priv;
46 #define video_out (vf->priv->vo)
48 static int query_format(struct vf_instance *vf, unsigned int fmt); /* forward declaration */
49 static void draw_slice(struct vf_instance *vf, unsigned char** src, int* stride, int w,int h, int x, int y);
51 static int config(struct vf_instance *vf,
52 int width, int height, int d_width, int d_height,
53 unsigned int flags, unsigned int outfmt){
55 if ((width <= 0) || (height <= 0) || (d_width <= 0) || (d_height <= 0))
57 mp_msg(MSGT_CPLAYER, MSGL_ERR, "VO: invalid dimensions!\n");
62 { const vo_info_t *info = video_out->info;
63 mp_msg(MSGT_CPLAYER,MSGL_INFO,"VO: [%s] %dx%d => %dx%d %s %s%s%s%s\n",info->short_name,
66 vo_format_name(outfmt),
67 (flags&VOFLAG_FULLSCREEN)?" [fs]":"",
68 (flags&VOFLAG_MODESWITCHING)?" [vm]":"",
69 (flags&VOFLAG_SWSCALE)?" [zoom]":"",
70 (flags&VOFLAG_FLIPPING)?" [flip]":"");
71 mp_msg(MSGT_CPLAYER,MSGL_V,"VO: Description: %s\n",info->name);
72 mp_msg(MSGT_CPLAYER,MSGL_V,"VO: Author: %s\n", info->author);
73 if(info->comment && strlen(info->comment) > 0)
74 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(config_video_out(video_out,width,height,d_width,d_height,flags,"MPlayer",outfmt))
85 if (vf->priv->ass_priv)
86 ass_configure(vf->priv->ass_priv, width, height, !!(vf->default_caps & VFCAP_EOSD_UNSCALED));
93 static int control(struct vf_instance *vf, int request, void* data)
96 case VFCTRL_GET_DEINTERLACE:
98 if(!video_out) return CONTROL_FALSE; // vo not configured?
99 return(video_out->control(VOCTRL_GET_DEINTERLACE, data)
100 == VO_TRUE) ? CONTROL_TRUE : CONTROL_FALSE;
102 case VFCTRL_SET_DEINTERLACE:
104 if(!video_out) return CONTROL_FALSE; // vo not configured?
105 return(video_out->control(VOCTRL_SET_DEINTERLACE, data)
106 == VO_TRUE) ? CONTROL_TRUE : CONTROL_FALSE;
108 case VFCTRL_DRAW_OSD:
109 if(!vo_config_count) return CONTROL_FALSE; // vo not configured?
110 video_out->draw_osd();
112 case VFCTRL_FLIP_PAGE:
114 if(!vo_config_count) return CONTROL_FALSE; // vo not configured?
115 video_out->flip_page();
118 case VFCTRL_SET_EQUALIZER:
120 vf_equalizer_t *eq=data;
121 if(!vo_config_count) return CONTROL_FALSE; // vo not configured?
122 return (video_out->control(VOCTRL_SET_EQUALIZER, eq->item, eq->value) == VO_TRUE) ? CONTROL_TRUE : CONTROL_FALSE;
124 case VFCTRL_GET_EQUALIZER:
126 vf_equalizer_t *eq=data;
127 if(!vo_config_count) return CONTROL_FALSE; // vo not configured?
128 return (video_out->control(VOCTRL_GET_EQUALIZER, eq->item, &eq->value) == VO_TRUE) ? CONTROL_TRUE : CONTROL_FALSE;
131 case VFCTRL_INIT_EOSD:
133 vf->priv->ass_priv = ass_renderer_init((ass_library_t*)data);
134 if (!vf->priv->ass_priv) return CONTROL_FALSE;
135 ass_configure_fonts(vf->priv->ass_priv);
136 vf->priv->prev_visibility = 0;
139 case VFCTRL_DRAW_EOSD:
141 mp_eosd_images_t images = {NULL, 2};
142 double pts = vf->priv->pts;
143 if (!vo_config_count || !vf->priv->ass_priv) return CONTROL_FALSE;
144 if (sub_visibility && vf->priv->ass_priv && ass_track && (pts != MP_NOPTS_VALUE)) {
146 memset(&res, 0, sizeof(res));
147 if (video_out->control(VOCTRL_GET_EOSD_RES, &res) == VO_TRUE) {
148 double dar = (double) (res.w - res.ml - res.mr) / (res.h - res.mt - res.mb);
149 ass_set_frame_size(vf->priv->ass_priv, res.w, res.h);
150 ass_set_margins(vf->priv->ass_priv, res.mt, res.mb, res.ml, res.mr);
151 #if defined(LIBASS_VERSION) && LIBASS_VERSION >= 0x00907010
152 ass_set_aspect_ratio(vf->priv->ass_priv, dar, (double)res.srcw/res.srch);
154 ass_set_aspect_ratio(vf->priv->ass_priv, (double)res.w / res.h);
158 images.imgs = ass_mp_render_frame(vf->priv->ass_priv, ass_track, (pts+sub_delay) * 1000 + .5, &images.changed);
159 if (!vf->priv->prev_visibility)
161 vf->priv->prev_visibility = 1;
163 vf->priv->prev_visibility = 0;
164 vf->priv->prev_visibility = sub_visibility;
165 return (video_out->control(VOCTRL_DRAW_EOSD, &images) == VO_TRUE) ? CONTROL_TRUE : CONTROL_FALSE;
170 *(double *)data = vf->priv->pts;
174 // return video_out->control(request,data);
175 return CONTROL_UNKNOWN;
178 static int query_format(struct vf_instance *vf, unsigned int fmt){
179 int flags=video_out->control(VOCTRL_QUERY_FORMAT,&fmt);
180 // draw_slice() accepts stride, draw_frame() doesn't:
182 if(fmt==IMGFMT_YV12 || fmt==IMGFMT_I420 || fmt==IMGFMT_IYUV)
183 flags|=VFCAP_ACCEPT_STRIDE;
187 static void get_image(struct vf_instance *vf,
189 if(!vo_config_count) return;
190 // GET_IMAGE is required for hardware-accelerated formats
191 if(vo_directrendering ||
192 IMGFMT_IS_XVMC(mpi->imgfmt) || IMGFMT_IS_VDPAU(mpi->imgfmt))
193 video_out->control(VOCTRL_GET_IMAGE,mpi);
196 static int put_image(struct vf_instance *vf,
197 mp_image_t *mpi, double pts){
198 if(!vo_config_count) return 0; // vo not configured?
199 // record pts (potentially modified by filters) for main loop
201 // first check, maybe the vo/vf plugin implements draw_image using mpi:
202 if(video_out->control(VOCTRL_DRAW_IMAGE,mpi)==VO_TRUE) return 1; // done.
203 // nope, fallback to old draw_frame/draw_slice:
204 if(!(mpi->flags&(MP_IMGFLAG_DIRECT|MP_IMGFLAG_DRAW_CALLBACK))){
206 // if(mpi->flags&MP_IMGFLAG_PLANAR)
207 if(vf->default_caps&VFCAP_ACCEPT_STRIDE)
208 video_out->draw_slice(mpi->planes,mpi->stride,mpi->w,mpi->h,mpi->x,mpi->y);
210 video_out->draw_frame(mpi->planes);
215 static void start_slice(struct vf_instance *vf,
217 if(!vo_config_count) return; // vo not configured?
218 video_out->control(VOCTRL_START_SLICE,mpi);
221 static void draw_slice(struct vf_instance *vf,
222 unsigned char** src, int* stride, int w,int h, int x, int y){
223 if(!vo_config_count) return; // vo not configured?
224 video_out->draw_slice(src,stride,w,h,x,y);
227 static void uninit(struct vf_instance *vf)
231 if (vf->priv->ass_priv)
232 ass_renderer_done(vf->priv->ass_priv);
237 //===========================================================================//
239 static int vf_open(vf_instance_t *vf, char *args){
242 vf->query_format=query_format;
243 vf->get_image=get_image;
244 vf->put_image=put_image;
245 vf->draw_slice=draw_slice;
246 vf->start_slice=start_slice;
248 vf->priv=calloc(1, sizeof(struct vf_priv_s));
249 vf->priv->vo = (const vo_functions_t *)args;
250 if(!video_out) return 0; // no vo ?
254 const vf_info_t vf_info_vo = {
263 //===========================================================================//