Move setting of O_NONBLOCK before lirc_readconfig, this avoids a memleak
[mplayer/glamo.git] / libmpcodecs / vf_vo.c
blob7e42c77034273d2fe9d0227c2ab2b127d91f3825
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
5 #include "config.h"
6 #include "mp_msg.h"
8 #include "mp_image.h"
9 #include "vf.h"
11 #include "libvo/video_out.h"
13 #ifdef CONFIG_ASS
14 #include "libass/ass.h"
15 #include "libass/ass_mp.h"
16 extern ass_track_t* ass_track;
17 #endif
19 //===========================================================================//
21 extern int sub_visibility;
22 extern float sub_delay;
24 struct vf_priv_s {
25 double pts;
26 const vo_functions_t *vo;
27 #ifdef CONFIG_ASS
28 ass_renderer_t* ass_priv;
29 int prev_visibility;
30 #endif
32 #define video_out (vf->priv->vo)
34 static int query_format(struct vf_instance_s* vf, unsigned int fmt); /* forward declaration */
36 static int config(struct vf_instance_s* vf,
37 int width, int height, int d_width, int d_height,
38 unsigned int flags, unsigned int outfmt){
40 if ((width <= 0) || (height <= 0) || (d_width <= 0) || (d_height <= 0))
42 mp_msg(MSGT_CPLAYER, MSGL_ERR, "VO: invalid dimensions!\n");
43 return 0;
46 if(video_out->info)
47 { const vo_info_t *info = video_out->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);
62 // save vo's stride capability for the wanted colorspace:
63 vf->default_caps=query_format(vf,outfmt);
65 if(config_video_out(video_out,width,height,d_width,d_height,flags,"MPlayer",outfmt))
66 return 0;
68 #ifdef CONFIG_ASS
69 if (vf->priv->ass_priv)
70 ass_configure(vf->priv->ass_priv, width, height, !!(vf->default_caps & VFCAP_EOSD_UNSCALED));
71 #endif
73 ++vo_config_count;
74 return 1;
77 static int control(struct vf_instance_s* 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(video_out->control(VOCTRL_GET_DEINTERLACE, data)
84 == VO_TRUE) ? CONTROL_TRUE : CONTROL_FALSE;
86 case VFCTRL_SET_DEINTERLACE:
88 if(!video_out) return CONTROL_FALSE; // vo not configured?
89 return(video_out->control(VOCTRL_SET_DEINTERLACE, data)
90 == VO_TRUE) ? CONTROL_TRUE : CONTROL_FALSE;
92 case VFCTRL_DRAW_OSD:
93 if(!vo_config_count) return CONTROL_FALSE; // vo not configured?
94 video_out->draw_osd();
95 return CONTROL_TRUE;
96 case VFCTRL_FLIP_PAGE:
98 if(!vo_config_count) return CONTROL_FALSE; // vo not configured?
99 video_out->flip_page();
100 return CONTROL_TRUE;
102 case VFCTRL_SET_EQUALIZER:
104 vf_equalizer_t *eq=data;
105 if(!vo_config_count) return CONTROL_FALSE; // vo not configured?
106 return (video_out->control(VOCTRL_SET_EQUALIZER, eq->item, eq->value) == VO_TRUE) ? CONTROL_TRUE : CONTROL_FALSE;
108 case VFCTRL_GET_EQUALIZER:
110 vf_equalizer_t *eq=data;
111 if(!vo_config_count) return CONTROL_FALSE; // vo not configured?
112 return (video_out->control(VOCTRL_GET_EQUALIZER, eq->item, &eq->value) == VO_TRUE) ? CONTROL_TRUE : CONTROL_FALSE;
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 (!vo_config_count || !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 (video_out->control(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 (video_out->control(VOCTRL_DRAW_EOSD, &images) == VO_TRUE) ? CONTROL_TRUE : CONTROL_FALSE;
146 #endif
147 case VFCTRL_GET_PTS:
149 *(double *)data = vf->priv->pts;
150 return CONTROL_TRUE;
153 // return video_out->control(request,data);
154 return CONTROL_UNKNOWN;
157 static int query_format(struct vf_instance_s* vf, unsigned int fmt){
158 int flags=video_out->control(VOCTRL_QUERY_FORMAT,&fmt);
159 // draw_slice() accepts stride, draw_frame() doesn't:
160 if(flags)
161 if(fmt==IMGFMT_YV12 || fmt==IMGFMT_I420 || fmt==IMGFMT_IYUV)
162 flags|=VFCAP_ACCEPT_STRIDE;
163 return flags;
166 static void get_image(struct vf_instance_s* vf,
167 mp_image_t *mpi){
168 if(vo_directrendering && vo_config_count)
169 video_out->control(VOCTRL_GET_IMAGE,mpi);
172 static int put_image(struct vf_instance_s* vf,
173 mp_image_t *mpi, double pts){
174 if(!vo_config_count) return 0; // vo not configured?
175 // record pts (potentially modified by filters) for main loop
176 vf->priv->pts = pts;
177 // first check, maybe the vo/vf plugin implements draw_image using mpi:
178 if(video_out->control(VOCTRL_DRAW_IMAGE,mpi)==VO_TRUE) return 1; // done.
179 // nope, fallback to old draw_frame/draw_slice:
180 if(!(mpi->flags&(MP_IMGFLAG_DIRECT|MP_IMGFLAG_DRAW_CALLBACK))){
181 // blit frame:
182 // if(mpi->flags&MP_IMGFLAG_PLANAR)
183 if(vf->default_caps&VFCAP_ACCEPT_STRIDE)
184 video_out->draw_slice(mpi->planes,mpi->stride,mpi->w,mpi->h,mpi->x,mpi->y);
185 else
186 video_out->draw_frame(mpi->planes);
188 return 1;
191 static void start_slice(struct vf_instance_s* vf,
192 mp_image_t *mpi) {
193 if(!vo_config_count) return; // vo not configured?
194 video_out->control(VOCTRL_START_SLICE,mpi);
197 static void draw_slice(struct vf_instance_s* vf,
198 unsigned char** src, int* stride, int w,int h, int x, int y){
199 if(!vo_config_count) return; // vo not configured?
200 video_out->draw_slice(src,stride,w,h,x,y);
203 static void uninit(struct vf_instance_s* vf)
205 if (vf->priv) {
206 #ifdef CONFIG_ASS
207 if (vf->priv->ass_priv)
208 ass_renderer_done(vf->priv->ass_priv);
209 #endif
210 free(vf->priv);
213 //===========================================================================//
215 static int open(vf_instance_t *vf, char* args){
216 vf->config=config;
217 vf->control=control;
218 vf->query_format=query_format;
219 vf->get_image=get_image;
220 vf->put_image=put_image;
221 vf->draw_slice=draw_slice;
222 vf->start_slice=start_slice;
223 vf->uninit=uninit;
224 vf->priv=calloc(1, sizeof(struct vf_priv_s));
225 vf->priv->vo = (const vo_functions_t *)args;
226 if(!video_out) return 0; // no vo ?
227 // if(video_out->preinit(args)) return 0; // preinit failed
228 return 1;
231 const vf_info_t vf_info_vo = {
232 "libvo wrapper",
233 "vo",
234 "A'rpi",
235 "for internal use",
236 open,
237 NULL
240 //===========================================================================//