vf_stereo3d: Add stereo3d filter
[mplayer/glamo.git] / libmpcodecs / vf_vo.c
blob3d48b5fce0ee42caaa845d2cb50ed1e313522ae8
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 #ifdef CONFIG_ASS
33 #include "ass_mp.h"
34 extern ASS_Track *ass_track;
35 #endif
37 //===========================================================================//
39 extern int sub_visibility;
40 extern float sub_delay;
42 struct vf_priv_s {
43 struct vo *vo;
44 #ifdef CONFIG_ASS
45 ASS_Renderer *ass_priv;
46 int prev_visibility;
47 double scale_ratio;
48 #endif
50 #define video_out (vf->priv->vo)
52 static int query_format(struct vf_instance *vf, unsigned int fmt); /* forward declaration */
53 static void draw_slice(struct vf_instance *vf, unsigned char** src, int* stride, int w,int h, int x, int y);
55 static int config(struct vf_instance *vf,
56 int width, int height, int d_width, int d_height,
57 unsigned int flags, unsigned int outfmt){
59 if ((width <= 0) || (height <= 0) || (d_width <= 0) || (d_height <= 0))
61 mp_msg(MSGT_CPLAYER, MSGL_ERR, "VO: invalid dimensions!\n");
62 return 0;
65 const vo_info_t *info = video_out->driver->info;
66 mp_msg(MSGT_CPLAYER,MSGL_INFO,"VO: [%s] %dx%d => %dx%d %s %s%s%s%s\n",info->short_name,
67 width, height,
68 d_width, d_height,
69 vo_format_name(outfmt),
70 (flags&VOFLAG_FULLSCREEN)?" [fs]":"",
71 (flags&VOFLAG_MODESWITCHING)?" [vm]":"",
72 (flags&VOFLAG_SWSCALE)?" [zoom]":"",
73 (flags&VOFLAG_FLIPPING)?" [flip]":"");
74 mp_msg(MSGT_CPLAYER,MSGL_V,"VO: Description: %s\n",info->name);
75 mp_msg(MSGT_CPLAYER,MSGL_V,"VO: Author: %s\n", info->author);
76 if(info->comment && strlen(info->comment) > 0)
77 mp_msg(MSGT_CPLAYER,MSGL_V,"VO: Comment: %s\n", info->comment);
79 // save vo's stride capability for the wanted colorspace:
80 vf->default_caps=query_format(vf,outfmt);
81 vf->draw_slice = (vf->default_caps & VOCAP_NOSLICES) ? NULL : draw_slice;
83 if (vo_config(video_out, width, height, d_width, d_height, flags, "MPlayer", outfmt))
84 return 0;
86 #ifdef CONFIG_ASS
87 vf->priv->scale_ratio = (double) d_width / d_height * height / width;
89 if (vf->priv->ass_priv)
90 ass_configure(vf->priv->ass_priv, width, height, !!(vf->default_caps & VFCAP_EOSD_UNSCALED));
91 #endif
93 return 1;
96 static int control(struct vf_instance *vf, int request, void* data)
98 switch(request){
99 case VFCTRL_GET_DEINTERLACE:
101 if(!video_out) return CONTROL_FALSE; // vo not configured?
102 return vo_control(video_out, VOCTRL_GET_DEINTERLACE, data) == VO_TRUE;
104 case VFCTRL_SET_DEINTERLACE:
106 if(!video_out) return CONTROL_FALSE; // vo not configured?
107 return vo_control(video_out, VOCTRL_SET_DEINTERLACE, data) == VO_TRUE;
109 case VFCTRL_GET_YUV_COLORSPACE:
110 return vo_control(video_out, VOCTRL_GET_YUV_COLORSPACE, data) == true;
111 case VFCTRL_SET_YUV_COLORSPACE:
112 return vo_control(video_out, VOCTRL_SET_YUV_COLORSPACE, data) == true;
113 case VFCTRL_DRAW_OSD:
114 if(!video_out->config_ok) return CONTROL_FALSE; // vo not configured?
115 vo_draw_osd(video_out, data);
116 return CONTROL_TRUE;
117 case VFCTRL_REDRAW_OSD:
118 return vo_control(video_out, VOCTRL_REDRAW_OSD, data) == true;
119 case VFCTRL_SET_EQUALIZER:
121 vf_equalizer_t *eq=data;
122 if(!video_out->config_ok) return CONTROL_FALSE; // vo not configured?
123 struct voctrl_set_equalizer_args param = {eq->item, eq->value};
124 return vo_control(video_out, VOCTRL_SET_EQUALIZER, &param) == VO_TRUE;
126 case VFCTRL_GET_EQUALIZER:
128 vf_equalizer_t *eq=data;
129 if(!video_out->config_ok) return CONTROL_FALSE; // vo not configured?
130 struct voctrl_get_equalizer_args param = {eq->item, &eq->value};
131 return vo_control(video_out, VOCTRL_GET_EQUALIZER, &param) == VO_TRUE;
133 #ifdef CONFIG_ASS
134 case VFCTRL_INIT_EOSD:
136 vf->priv->ass_priv = ass_renderer_init((ASS_Library*)data);
137 if (!vf->priv->ass_priv) return CONTROL_FALSE;
138 ass_configure_fonts(vf->priv->ass_priv);
139 vf->priv->prev_visibility = 0;
140 return CONTROL_TRUE;
142 case VFCTRL_DRAW_EOSD:
144 mp_eosd_images_t images = {NULL, 2};
145 double pts = video_out->next_pts;
146 if (!video_out->config_ok || !vf->priv->ass_priv) return CONTROL_FALSE;
147 if (sub_visibility && vf->priv->ass_priv && ass_track && (pts != MP_NOPTS_VALUE)) {
148 mp_eosd_res_t res;
149 memset(&res, 0, sizeof(res));
150 if (vo_control(video_out, VOCTRL_GET_EOSD_RES, &res) == VO_TRUE) {
151 ass_set_frame_size(vf->priv->ass_priv, res.w, res.h);
152 ass_set_margins(vf->priv->ass_priv, res.mt, res.mb, res.ml, res.mr);
153 ass_set_aspect_ratio(vf->priv->ass_priv, vf->priv->scale_ratio, 1);
156 images.imgs = ass_mp_render_frame(vf->priv->ass_priv, ass_track, (pts+sub_delay) * 1000 + .5, &images.changed);
157 if (!vf->priv->prev_visibility)
158 images.changed = 2;
159 vf->priv->prev_visibility = 1;
160 } else
161 vf->priv->prev_visibility = 0;
162 vf->priv->prev_visibility = sub_visibility;
163 return vo_control(video_out, VOCTRL_DRAW_EOSD, &images) == VO_TRUE;
165 #endif
167 return CONTROL_UNKNOWN;
170 static int query_format(struct vf_instance *vf, unsigned int fmt){
171 int flags = vo_control(video_out, VOCTRL_QUERY_FORMAT, &fmt);
172 // draw_slice() accepts stride, draw_frame() doesn't:
173 if(flags)
174 if(fmt==IMGFMT_YV12 || fmt==IMGFMT_I420 || fmt==IMGFMT_IYUV)
175 flags|=VFCAP_ACCEPT_STRIDE;
176 return flags;
179 static void get_image(struct vf_instance *vf,
180 mp_image_t *mpi){
181 if (!video_out->config_ok)
182 return;
183 // GET_IMAGE is required for hardware-accelerated formats
184 if(vo_directrendering ||
185 IMGFMT_IS_XVMC(mpi->imgfmt) || IMGFMT_IS_VDPAU(mpi->imgfmt))
186 vo_control(video_out, VOCTRL_GET_IMAGE, mpi);
189 static int put_image(struct vf_instance *vf,
190 mp_image_t *mpi, double pts){
191 if(!video_out->config_ok) return 0; // vo not configured?
192 // first check, maybe the vo/vf plugin implements draw_image using mpi:
193 if (vo_draw_image(video_out, mpi, pts) >= 0)
194 return 1;
195 // nope, fallback to old draw_frame/draw_slice:
196 if(!(mpi->flags&(MP_IMGFLAG_DIRECT|MP_IMGFLAG_DRAW_CALLBACK))){
197 // blit frame:
198 // if(mpi->flags&MP_IMGFLAG_PLANAR)
199 if(vf->default_caps&VFCAP_ACCEPT_STRIDE)
200 vo_draw_slice(video_out, mpi->planes,mpi->stride,mpi->w,mpi->h,mpi->x,mpi->y);
201 else
202 vo_draw_frame(video_out, mpi->planes);
204 return 1;
207 static void start_slice(struct vf_instance *vf,
208 mp_image_t *mpi) {
209 if(!video_out->config_ok) return; // vo not configured?
210 vo_control(video_out, VOCTRL_START_SLICE,mpi);
213 static void draw_slice(struct vf_instance *vf,
214 unsigned char** src, int* stride, int w,int h, int x, int y){
215 if(!video_out->config_ok) return; // vo not configured?
216 vo_draw_slice(video_out, src,stride,w,h,x,y);
219 static void uninit(struct vf_instance *vf)
221 if (vf->priv) {
222 /* Allow VO (which may live on to work with another instance of vf_vo)
223 * to get rid of numbered-mpi references that will now be invalid. */
224 vo_seek_reset(video_out);
225 #ifdef CONFIG_ASS
226 if (vf->priv->ass_priv)
227 ass_renderer_done(vf->priv->ass_priv);
228 #endif
229 free(vf->priv);
232 //===========================================================================//
234 static int vf_open(vf_instance_t *vf, char *args){
235 vf->config=config;
236 vf->control=control;
237 vf->query_format=query_format;
238 vf->get_image=get_image;
239 vf->put_image=put_image;
240 vf->draw_slice=draw_slice;
241 vf->start_slice=start_slice;
242 vf->uninit=uninit;
243 vf->priv=calloc(1, sizeof(struct vf_priv_s));
244 vf->priv->vo = (struct vo *)args;
245 if(!video_out) return 0; // no vo ?
246 return 1;
249 const vf_info_t vf_info_vo = {
250 "libvo wrapper",
251 "vo",
252 "A'rpi",
253 "for internal use",
254 vf_open,
255 NULL
258 //===========================================================================//