Merge svn changes up to r28610
[mplayer.git] / libmpcodecs / vf_vo.c
blob09425adcb097998274ac46258825b08f830d26fa
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <stdbool.h>
6 #include "config.h"
7 #include "mp_msg.h"
9 #include "mp_image.h"
10 #include "vf.h"
12 #include "libvo/video_out.h"
14 #ifdef CONFIG_ASS
15 #include "libass/ass.h"
16 #include "libass/ass_mp.h"
17 extern ass_track_t* ass_track;
18 #endif
20 //===========================================================================//
22 extern int sub_visibility;
23 extern float sub_delay;
25 struct vf_priv_s {
26 double pts;
27 struct vo *vo;
28 #ifdef CONFIG_ASS
29 ass_renderer_t* ass_priv;
30 int prev_visibility;
31 #endif
33 #define video_out (vf->priv->vo)
35 static int query_format(struct vf_instance* vf, unsigned int fmt); /* forward declaration */
37 static int config(struct vf_instance* vf,
38 int width, int height, int d_width, int d_height,
39 unsigned int flags, unsigned int outfmt){
41 if ((width <= 0) || (height <= 0) || (d_width <= 0) || (d_height <= 0))
43 mp_msg(MSGT_CPLAYER, MSGL_ERR, "VO: invalid dimensions!\n");
44 return 0;
47 const vo_info_t *info = video_out->driver->info;
48 mp_msg(MSGT_CPLAYER,MSGL_INFO,"VO: [%s] %dx%d => %dx%d %s %s%s%s%s\n",info->short_name,
49 width, height,
50 d_width, d_height,
51 vo_format_name(outfmt),
52 (flags&VOFLAG_FULLSCREEN)?" [fs]":"",
53 (flags&VOFLAG_MODESWITCHING)?" [vm]":"",
54 (flags&VOFLAG_SWSCALE)?" [zoom]":"",
55 (flags&VOFLAG_FLIPPING)?" [flip]":"");
56 mp_msg(MSGT_CPLAYER,MSGL_V,"VO: Description: %s\n",info->name);
57 mp_msg(MSGT_CPLAYER,MSGL_V,"VO: Author: %s\n", info->author);
58 if(info->comment && strlen(info->comment) > 0)
59 mp_msg(MSGT_CPLAYER,MSGL_V,"VO: Comment: %s\n", info->comment);
61 // save vo's stride capability for the wanted colorspace:
62 vf->default_caps=query_format(vf,outfmt);
64 if (vo_config(video_out, width, height, d_width, d_height, flags, "MPlayer", outfmt))
65 return 0;
67 #ifdef CONFIG_ASS
68 if (vf->priv->ass_priv)
69 ass_configure(vf->priv->ass_priv, width, height, !!(vf->default_caps & VFCAP_EOSD_UNSCALED));
70 #endif
72 return 1;
75 static int control(struct vf_instance* vf, int request, void* data)
77 switch(request){
78 case VFCTRL_GET_DEINTERLACE:
80 if(!video_out) return CONTROL_FALSE; // vo not configured?
81 return vo_control(video_out, VOCTRL_GET_DEINTERLACE, data) == VO_TRUE;
83 case VFCTRL_SET_DEINTERLACE:
85 if(!video_out) return CONTROL_FALSE; // vo not configured?
86 return vo_control(video_out, VOCTRL_SET_DEINTERLACE, data) == VO_TRUE;
88 case VFCTRL_DRAW_OSD:
89 if(!video_out->config_ok) return CONTROL_FALSE; // vo not configured?
90 vo_draw_osd(video_out, data);
91 return CONTROL_TRUE;
92 case VFCTRL_REDRAW_OSD:
93 return vo_control(video_out, VOCTRL_REDRAW_OSD, data) == true;
94 case VFCTRL_FLIP_PAGE:
96 if(!video_out->config_ok) return CONTROL_FALSE; // vo not configured?
97 vo_flip_page(video_out);
98 return CONTROL_TRUE;
100 case VFCTRL_SET_EQUALIZER:
102 vf_equalizer_t *eq=data;
103 if(!video_out->config_ok) return CONTROL_FALSE; // vo not configured?
104 struct voctrl_set_equalizer_args param = {eq->item, eq->value};
105 return vo_control(video_out, VOCTRL_SET_EQUALIZER, &param) == VO_TRUE;
107 case VFCTRL_GET_EQUALIZER:
109 vf_equalizer_t *eq=data;
110 if(!video_out->config_ok) return CONTROL_FALSE; // vo not configured?
111 struct voctrl_get_equalizer_args param = {eq->item, &eq->value};
112 return vo_control(video_out, VOCTRL_GET_EQUALIZER, &param) == VO_TRUE;
114 #ifdef CONFIG_ASS
115 case VFCTRL_INIT_EOSD:
117 vf->priv->ass_priv = ass_renderer_init((ass_library_t*)data);
118 if (!vf->priv->ass_priv) return CONTROL_FALSE;
119 ass_configure_fonts(vf->priv->ass_priv);
120 vf->priv->prev_visibility = 0;
121 return CONTROL_TRUE;
123 case VFCTRL_DRAW_EOSD:
125 mp_eosd_images_t images = {NULL, 2};
126 double pts = vf->priv->pts;
127 if (!video_out->config_ok || !vf->priv->ass_priv) return CONTROL_FALSE;
128 if (sub_visibility && vf->priv->ass_priv && ass_track && (pts != MP_NOPTS_VALUE)) {
129 mp_eosd_res_t res;
130 memset(&res, 0, sizeof(res));
131 if (vo_control(video_out, VOCTRL_GET_EOSD_RES, &res) == VO_TRUE) {
132 ass_set_frame_size(vf->priv->ass_priv, res.w, res.h);
133 ass_set_margins(vf->priv->ass_priv, res.mt, res.mb, res.ml, res.mr);
134 ass_set_aspect_ratio(vf->priv->ass_priv, (double)res.w / res.h);
137 images.imgs = ass_mp_render_frame(vf->priv->ass_priv, ass_track, (pts+sub_delay) * 1000 + .5, &images.changed);
138 if (!vf->priv->prev_visibility)
139 images.changed = 2;
140 vf->priv->prev_visibility = 1;
141 } else
142 vf->priv->prev_visibility = 0;
143 vf->priv->prev_visibility = sub_visibility;
144 return vo_control(video_out, VOCTRL_DRAW_EOSD, &images) == VO_TRUE;
146 #endif
147 case VFCTRL_GET_PTS:
149 *(double *)data = vf->priv->pts;
150 return CONTROL_TRUE;
153 return CONTROL_UNKNOWN;
156 static int query_format(struct vf_instance* vf, unsigned int fmt){
157 int flags = vo_control(video_out, VOCTRL_QUERY_FORMAT, &fmt);
158 // draw_slice() accepts stride, draw_frame() doesn't:
159 if(flags)
160 if(fmt==IMGFMT_YV12 || fmt==IMGFMT_I420 || fmt==IMGFMT_IYUV)
161 flags|=VFCAP_ACCEPT_STRIDE;
162 return flags;
165 static void get_image(struct vf_instance* vf,
166 mp_image_t *mpi){
167 if (!video_out->config_ok)
168 return;
169 // GET_IMAGE is required for hardware-accelerated formats
170 if(vo_directrendering ||
171 IMGFMT_IS_XVMC(mpi->imgfmt) || IMGFMT_IS_VDPAU(mpi->imgfmt))
172 vo_control(video_out, VOCTRL_GET_IMAGE, mpi);
175 static int put_image(struct vf_instance* vf,
176 mp_image_t *mpi, double pts){
177 if(!video_out->config_ok) return 0; // vo not configured?
178 // record pts (potentially modified by filters) for main loop
179 vf->priv->pts = pts;
180 // first check, maybe the vo/vf plugin implements draw_image using mpi:
181 if (vo_control(video_out, VOCTRL_DRAW_IMAGE,mpi)==VO_TRUE) return 1; // done.
182 // nope, fallback to old draw_frame/draw_slice:
183 if(!(mpi->flags&(MP_IMGFLAG_DIRECT|MP_IMGFLAG_DRAW_CALLBACK))){
184 // blit frame:
185 // if(mpi->flags&MP_IMGFLAG_PLANAR)
186 if(vf->default_caps&VFCAP_ACCEPT_STRIDE)
187 vo_draw_slice(video_out, mpi->planes,mpi->stride,mpi->w,mpi->h,mpi->x,mpi->y);
188 else
189 vo_draw_frame(video_out, mpi->planes);
191 return 1;
194 static void start_slice(struct vf_instance* vf,
195 mp_image_t *mpi) {
196 if(!video_out->config_ok) return; // vo not configured?
197 vo_control(video_out, VOCTRL_START_SLICE,mpi);
200 static void draw_slice(struct vf_instance* vf,
201 unsigned char** src, int* stride, int w,int h, int x, int y){
202 if(!video_out->config_ok) return; // vo not configured?
203 vo_draw_slice(video_out, src,stride,w,h,x,y);
206 static void uninit(struct vf_instance* vf)
208 if (vf->priv) {
209 #ifdef CONFIG_ASS
210 if (vf->priv->ass_priv)
211 ass_renderer_done(vf->priv->ass_priv);
212 #endif
213 free(vf->priv);
216 //===========================================================================//
218 static int open(vf_instance_t *vf, char* args){
219 vf->config=config;
220 vf->control=control;
221 vf->query_format=query_format;
222 vf->get_image=get_image;
223 vf->put_image=put_image;
224 vf->draw_slice=draw_slice;
225 vf->start_slice=start_slice;
226 vf->uninit=uninit;
227 vf->priv=calloc(1, sizeof(struct vf_priv_s));
228 vf->priv->vo = (struct vo *)args;
229 if(!video_out) return 0; // no vo ?
230 return 1;
233 const vf_info_t vf_info_vo = {
234 "libvo wrapper",
235 "vo",
236 "A'rpi",
237 "for internal use",
238 open,
239 NULL
242 //===========================================================================//