Static pthread support
[mplayer/kovensky.git] / libmpcodecs / vf_vo.c
blob2e4257fb215adcba722911f224ff363fd5aba29b
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 */
36 static void draw_slice(struct vf_instance *vf, unsigned char **src, int *stride, int w,int h, int x, int y);
38 static int config(struct vf_instance* vf,
39 int width, int height, int d_width, int d_height,
40 unsigned int flags, unsigned int outfmt){
42 if ((width <= 0) || (height <= 0) || (d_width <= 0) || (d_height <= 0))
44 mp_msg(MSGT_CPLAYER, MSGL_ERR, "VO: invalid dimensions!\n");
45 return 0;
48 const vo_info_t *info = video_out->driver->info;
49 mp_msg(MSGT_CPLAYER,MSGL_INFO,"VO: [%s] %dx%d => %dx%d %s %s%s%s%s\n",info->short_name,
50 width, height,
51 d_width, d_height,
52 vo_format_name(outfmt),
53 (flags&VOFLAG_FULLSCREEN)?" [fs]":"",
54 (flags&VOFLAG_MODESWITCHING)?" [vm]":"",
55 (flags&VOFLAG_SWSCALE)?" [zoom]":"",
56 (flags&VOFLAG_FLIPPING)?" [flip]":"");
57 mp_msg(MSGT_CPLAYER,MSGL_V,"VO: Description: %s\n",info->name);
58 mp_msg(MSGT_CPLAYER,MSGL_V,"VO: Author: %s\n", info->author);
59 if(info->comment && strlen(info->comment) > 0)
60 mp_msg(MSGT_CPLAYER,MSGL_V,"VO: Comment: %s\n", info->comment);
62 // save vo's stride capability for the wanted colorspace:
63 vf->default_caps=query_format(vf,outfmt);
64 vf->draw_slice = (vf->default_caps & VOCAP_NOSLICES) ? NULL : draw_slice;
66 if (vo_config(video_out, width, height, d_width, d_height, flags, "MPlayer", outfmt))
67 return 0;
69 #ifdef CONFIG_ASS
70 if (vf->priv->ass_priv)
71 ass_configure(vf->priv->ass_priv, width, height, !!(vf->default_caps & VFCAP_EOSD_UNSCALED));
72 #endif
74 return 1;
77 static int control(struct vf_instance* vf, int request, void* data)
79 switch(request){
80 case VFCTRL_GET_DEINTERLACE:
82 if(!video_out) return CONTROL_FALSE; // vo not configured?
83 return vo_control(video_out, VOCTRL_GET_DEINTERLACE, data) == VO_TRUE;
85 case VFCTRL_SET_DEINTERLACE:
87 if(!video_out) return CONTROL_FALSE; // vo not configured?
88 return vo_control(video_out, VOCTRL_SET_DEINTERLACE, data) == VO_TRUE;
90 case VFCTRL_DRAW_OSD:
91 if(!video_out->config_ok) return CONTROL_FALSE; // vo not configured?
92 vo_draw_osd(video_out, data);
93 return CONTROL_TRUE;
94 case VFCTRL_REDRAW_OSD:
95 return vo_control(video_out, VOCTRL_REDRAW_OSD, data) == true;
96 case VFCTRL_FLIP_PAGE:
98 if(!video_out->config_ok) return CONTROL_FALSE; // vo not configured?
99 vo_flip_page(video_out);
100 return CONTROL_TRUE;
102 case VFCTRL_SET_EQUALIZER:
104 vf_equalizer_t *eq=data;
105 if(!video_out->config_ok) return CONTROL_FALSE; // vo not configured?
106 struct voctrl_set_equalizer_args param = {eq->item, eq->value};
107 return vo_control(video_out, VOCTRL_SET_EQUALIZER, &param) == VO_TRUE;
109 case VFCTRL_GET_EQUALIZER:
111 vf_equalizer_t *eq=data;
112 if(!video_out->config_ok) return CONTROL_FALSE; // vo not configured?
113 struct voctrl_get_equalizer_args param = {eq->item, &eq->value};
114 return vo_control(video_out, VOCTRL_GET_EQUALIZER, &param) == VO_TRUE;
116 #ifdef CONFIG_ASS
117 case VFCTRL_INIT_EOSD:
119 vf->priv->ass_priv = ass_renderer_init((ass_library_t*)data);
120 if (!vf->priv->ass_priv) return CONTROL_FALSE;
121 ass_configure_fonts(vf->priv->ass_priv);
122 vf->priv->prev_visibility = 0;
123 return CONTROL_TRUE;
125 case VFCTRL_DRAW_EOSD:
127 mp_eosd_images_t images = {NULL, 2};
128 double pts = vf->priv->pts;
129 if (!video_out->config_ok || !vf->priv->ass_priv) return CONTROL_FALSE;
130 if (sub_visibility && vf->priv->ass_priv && ass_track && (pts != MP_NOPTS_VALUE)) {
131 mp_eosd_res_t res;
132 memset(&res, 0, sizeof(res));
133 if (vo_control(video_out, VOCTRL_GET_EOSD_RES, &res) == VO_TRUE) {
134 ass_set_frame_size(vf->priv->ass_priv, res.w, res.h);
135 ass_set_margins(vf->priv->ass_priv, res.mt, res.mb, res.ml, res.mr);
136 ass_set_aspect_ratio(vf->priv->ass_priv, (double)res.w / res.h);
139 images.imgs = ass_mp_render_frame(vf->priv->ass_priv, ass_track, (pts+sub_delay) * 1000 + .5, &images.changed);
140 if (!vf->priv->prev_visibility)
141 images.changed = 2;
142 vf->priv->prev_visibility = 1;
143 } else
144 vf->priv->prev_visibility = 0;
145 vf->priv->prev_visibility = sub_visibility;
146 return vo_control(video_out, VOCTRL_DRAW_EOSD, &images) == VO_TRUE;
148 #endif
149 case VFCTRL_GET_PTS:
151 *(double *)data = vf->priv->pts;
152 return CONTROL_TRUE;
155 return CONTROL_UNKNOWN;
158 static int query_format(struct vf_instance* vf, unsigned int fmt){
159 int flags = vo_control(video_out, VOCTRL_QUERY_FORMAT, &fmt);
160 // draw_slice() accepts stride, draw_frame() doesn't:
161 if(flags)
162 if(fmt==IMGFMT_YV12 || fmt==IMGFMT_I420 || fmt==IMGFMT_IYUV)
163 flags|=VFCAP_ACCEPT_STRIDE;
164 return flags;
167 static void get_image(struct vf_instance* vf,
168 mp_image_t *mpi){
169 if (!video_out->config_ok)
170 return;
171 // GET_IMAGE is required for hardware-accelerated formats
172 if(vo_directrendering ||
173 IMGFMT_IS_XVMC(mpi->imgfmt) || IMGFMT_IS_VDPAU(mpi->imgfmt))
174 vo_control(video_out, VOCTRL_GET_IMAGE, mpi);
177 static int put_image(struct vf_instance* vf,
178 mp_image_t *mpi, double pts){
179 if(!video_out->config_ok) return 0; // vo not configured?
180 // record pts (potentially modified by filters) for main loop
181 vf->priv->pts = pts;
182 // first check, maybe the vo/vf plugin implements draw_image using mpi:
183 if (vo_control(video_out, VOCTRL_DRAW_IMAGE,mpi)==VO_TRUE) return 1; // done.
184 // nope, fallback to old draw_frame/draw_slice:
185 if(!(mpi->flags&(MP_IMGFLAG_DIRECT|MP_IMGFLAG_DRAW_CALLBACK))){
186 // blit frame:
187 // if(mpi->flags&MP_IMGFLAG_PLANAR)
188 if(vf->default_caps&VFCAP_ACCEPT_STRIDE)
189 vo_draw_slice(video_out, mpi->planes,mpi->stride,mpi->w,mpi->h,mpi->x,mpi->y);
190 else
191 vo_draw_frame(video_out, mpi->planes);
193 return 1;
196 static void start_slice(struct vf_instance* vf,
197 mp_image_t *mpi) {
198 if(!video_out->config_ok) return; // vo not configured?
199 vo_control(video_out, VOCTRL_START_SLICE,mpi);
202 static void draw_slice(struct vf_instance* vf,
203 unsigned char** src, int* stride, int w,int h, int x, int y){
204 if(!video_out->config_ok) return; // vo not configured?
205 vo_draw_slice(video_out, src,stride,w,h,x,y);
208 static void uninit(struct vf_instance* vf)
210 if (vf->priv) {
211 #ifdef CONFIG_ASS
212 if (vf->priv->ass_priv)
213 ass_renderer_done(vf->priv->ass_priv);
214 #endif
215 free(vf->priv);
218 //===========================================================================//
220 static int open(vf_instance_t *vf, char* args){
221 vf->config=config;
222 vf->control=control;
223 vf->query_format=query_format;
224 vf->get_image=get_image;
225 vf->put_image=put_image;
226 vf->draw_slice=draw_slice;
227 vf->start_slice=start_slice;
228 vf->uninit=uninit;
229 vf->priv=calloc(1, sizeof(struct vf_priv_s));
230 vf->priv->vo = (struct vo *)args;
231 if(!video_out) return 0; // no vo ?
232 return 1;
235 const vf_info_t vf_info_vo = {
236 "libvo wrapper",
237 "vo",
238 "A'rpi",
239 "for internal use",
240 open,
241 NULL
244 //===========================================================================//