subtitles: move global ass_track to struct osd_state
[mplayer/glamo.git] / libmpcodecs / vf_vo.c
blob81dff4cea9bdbe9ecb0dd45ac32a241ab6a38402
1 /*
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.
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <stdbool.h>
24 #include "config.h"
25 #include "mp_msg.h"
27 #include "mp_image.h"
28 #include "vf.h"
30 #include "libvo/video_out.h"
32 #include "ass_mp.h"
33 #include "libvo/sub.h"
35 //===========================================================================//
37 extern float sub_delay;
39 struct vf_priv_s {
40 struct vo *vo;
41 #ifdef CONFIG_ASS
42 ASS_Renderer *ass_priv;
43 int prev_visibility;
44 double scale_ratio;
45 #endif
47 #define video_out (vf->priv->vo)
49 static int query_format(struct vf_instance *vf, unsigned int fmt); /* forward declaration */
50 static void draw_slice(struct vf_instance *vf, unsigned char** src, int* stride, int w,int h, int x, int y);
52 static int config(struct vf_instance *vf,
53 int width, int height, int d_width, int d_height,
54 unsigned int flags, unsigned int outfmt){
56 if ((width <= 0) || (height <= 0) || (d_width <= 0) || (d_height <= 0))
58 mp_msg(MSGT_CPLAYER, MSGL_ERR, "VO: invalid dimensions!\n");
59 return 0;
62 const vo_info_t *info = video_out->driver->info;
63 mp_msg(MSGT_CPLAYER,MSGL_INFO,"VO: [%s] %dx%d => %dx%d %s %s%s%s%s\n",info->short_name,
64 width, height,
65 d_width, d_height,
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);
76 // save vo's stride capability for the wanted colorspace:
77 vf->default_caps=query_format(vf,outfmt);
78 vf->draw_slice = (vf->default_caps & VOCAP_NOSLICES) ? NULL : draw_slice;
80 if (vo_config(video_out, width, height, d_width, d_height, flags, "MPlayer", outfmt))
81 return 0;
83 #ifdef CONFIG_ASS
84 vf->priv->scale_ratio = (double) d_width / d_height * height / width;
86 if (vf->priv->ass_priv)
87 ass_configure(vf->priv->ass_priv, width, height, !!(vf->default_caps & VFCAP_EOSD_UNSCALED));
88 #endif
90 return 1;
93 static int control(struct vf_instance *vf, int request, void* data)
95 switch(request){
96 case VFCTRL_GET_DEINTERLACE:
98 if(!video_out) return CONTROL_FALSE; // vo not configured?
99 return vo_control(video_out, VOCTRL_GET_DEINTERLACE, data) == VO_TRUE;
101 case VFCTRL_SET_DEINTERLACE:
103 if(!video_out) return CONTROL_FALSE; // vo not configured?
104 return vo_control(video_out, VOCTRL_SET_DEINTERLACE, data) == VO_TRUE;
106 case VFCTRL_GET_YUV_COLORSPACE:
107 return vo_control(video_out, VOCTRL_GET_YUV_COLORSPACE, data) == true;
108 case VFCTRL_SET_YUV_COLORSPACE:
109 return vo_control(video_out, VOCTRL_SET_YUV_COLORSPACE, data) == true;
110 case VFCTRL_DRAW_OSD:
111 if(!video_out->config_ok) return CONTROL_FALSE; // vo not configured?
112 vo_draw_osd(video_out, data);
113 return CONTROL_TRUE;
114 case VFCTRL_REDRAW_OSD:
115 return vo_control(video_out, VOCTRL_REDRAW_OSD, data) == true;
116 case VFCTRL_SET_EQUALIZER:
118 vf_equalizer_t *eq=data;
119 if(!video_out->config_ok) return CONTROL_FALSE; // vo not configured?
120 struct voctrl_set_equalizer_args param = {eq->item, eq->value};
121 return vo_control(video_out, VOCTRL_SET_EQUALIZER, &param) == VO_TRUE;
123 case VFCTRL_GET_EQUALIZER:
125 vf_equalizer_t *eq=data;
126 if(!video_out->config_ok) return CONTROL_FALSE; // vo not configured?
127 struct voctrl_get_equalizer_args param = {eq->item, &eq->value};
128 return vo_control(video_out, VOCTRL_GET_EQUALIZER, &param) == VO_TRUE;
130 #ifdef CONFIG_ASS
131 case VFCTRL_INIT_EOSD:
133 vf->priv->ass_priv = ass_renderer_init((ASS_Library*)data);
134 if (!vf->priv->ass_priv) return CONTROL_FALSE;
135 ass_configure_fonts(vf->priv->ass_priv);
136 vf->priv->prev_visibility = 0;
137 return CONTROL_TRUE;
139 case VFCTRL_DRAW_EOSD:
141 struct osd_state *osd = data;
142 mp_eosd_images_t images = {NULL, 2};
143 double pts = video_out->next_pts;
144 if (!video_out->config_ok || !vf->priv->ass_priv) return CONTROL_FALSE;
145 if (sub_visibility && vf->priv->ass_priv && osd->ass_track
146 && (pts != MP_NOPTS_VALUE)) {
147 mp_eosd_res_t res;
148 memset(&res, 0, sizeof(res));
149 if (vo_control(video_out, VOCTRL_GET_EOSD_RES, &res) == VO_TRUE) {
150 ass_set_frame_size(vf->priv->ass_priv, res.w, res.h);
151 ass_set_margins(vf->priv->ass_priv, res.mt, res.mb, res.ml, res.mr);
152 ass_set_aspect_ratio(vf->priv->ass_priv, vf->priv->scale_ratio, 1);
155 images.imgs = ass_mp_render_frame(vf->priv->ass_priv,
156 osd->ass_track,
157 (pts+sub_delay) * 1000 + .5,
158 &images.changed);
159 if (!vf->priv->prev_visibility)
160 images.changed = 2;
161 vf->priv->prev_visibility = 1;
162 } else
163 vf->priv->prev_visibility = 0;
164 vf->priv->prev_visibility = sub_visibility;
165 return vo_control(video_out, VOCTRL_DRAW_EOSD, &images) == VO_TRUE;
167 #endif
169 return CONTROL_UNKNOWN;
172 static int query_format(struct vf_instance *vf, unsigned int fmt){
173 int flags = vo_control(video_out, VOCTRL_QUERY_FORMAT, &fmt);
174 // draw_slice() accepts stride, draw_frame() doesn't:
175 if(flags)
176 if(fmt==IMGFMT_YV12 || fmt==IMGFMT_I420 || fmt==IMGFMT_IYUV)
177 flags|=VFCAP_ACCEPT_STRIDE;
178 return flags;
181 static void get_image(struct vf_instance *vf,
182 mp_image_t *mpi){
183 if (!video_out->config_ok)
184 return;
185 // GET_IMAGE is required for hardware-accelerated formats
186 if(vo_directrendering ||
187 IMGFMT_IS_HWACCEL(mpi->imgfmt))
188 vo_control(video_out, VOCTRL_GET_IMAGE, mpi);
191 static int put_image(struct vf_instance *vf,
192 mp_image_t *mpi, double pts){
193 if(!video_out->config_ok) return 0; // vo not configured?
194 // first check, maybe the vo/vf plugin implements draw_image using mpi:
195 if (vo_draw_image(video_out, mpi, pts) >= 0)
196 return 1;
197 // nope, fallback to old draw_frame/draw_slice:
198 if(!(mpi->flags&(MP_IMGFLAG_DIRECT|MP_IMGFLAG_DRAW_CALLBACK))){
199 // blit frame:
200 // if(mpi->flags&MP_IMGFLAG_PLANAR)
201 if(vf->default_caps&VFCAP_ACCEPT_STRIDE)
202 vo_draw_slice(video_out, mpi->planes,mpi->stride,mpi->w,mpi->h,mpi->x,mpi->y);
203 else
204 vo_draw_frame(video_out, mpi->planes);
206 return 1;
209 static void start_slice(struct vf_instance *vf,
210 mp_image_t *mpi) {
211 if(!video_out->config_ok) return; // vo not configured?
212 vo_control(video_out, VOCTRL_START_SLICE,mpi);
215 static void draw_slice(struct vf_instance *vf,
216 unsigned char** src, int* stride, int w,int h, int x, int y){
217 if(!video_out->config_ok) return; // vo not configured?
218 vo_draw_slice(video_out, src,stride,w,h,x,y);
221 static void uninit(struct vf_instance *vf)
223 if (vf->priv) {
224 /* Allow VO (which may live on to work with another instance of vf_vo)
225 * to get rid of numbered-mpi references that will now be invalid. */
226 vo_seek_reset(video_out);
227 #ifdef CONFIG_ASS
228 if (vf->priv->ass_priv)
229 ass_renderer_done(vf->priv->ass_priv);
230 #endif
231 free(vf->priv);
234 //===========================================================================//
236 static int vf_open(vf_instance_t *vf, char *args){
237 vf->config=config;
238 vf->control=control;
239 vf->query_format=query_format;
240 vf->get_image=get_image;
241 vf->put_image=put_image;
242 vf->draw_slice=draw_slice;
243 vf->start_slice=start_slice;
244 vf->uninit=uninit;
245 vf->priv=calloc(1, sizeof(struct vf_priv_s));
246 vf->priv->vo = (struct vo *)args;
247 if(!video_out) return 0; // no vo ?
248 return 1;
251 const vf_info_t vf_info_vo = {
252 "libvo wrapper",
253 "vo",
254 "A'rpi",
255 "for internal use",
256 vf_open,
257 NULL
260 //===========================================================================//