stream.h: Add 2 prototypes instead of declaring them in cache2.c
[mplayer.git] / libmpcodecs / vf_vo.c
blob4f47bc184774dd4c0be63bee335d2e33e3817250
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 struct vo *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* vf, unsigned int fmt); /* forward declaration */
36 static int config(struct vf_instance* 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 const vo_info_t *info = video_out->driver->info;
47 mp_msg(MSGT_CPLAYER,MSGL_INFO,"VO: [%s] %dx%d => %dx%d %s %s%s%s%s\n",info->short_name,
48 width, height,
49 d_width, d_height,
50 vo_format_name(outfmt),
51 (flags&VOFLAG_FULLSCREEN)?" [fs]":"",
52 (flags&VOFLAG_MODESWITCHING)?" [vm]":"",
53 (flags&VOFLAG_SWSCALE)?" [zoom]":"",
54 (flags&VOFLAG_FLIPPING)?" [flip]":"");
55 mp_msg(MSGT_CPLAYER,MSGL_V,"VO: Description: %s\n",info->name);
56 mp_msg(MSGT_CPLAYER,MSGL_V,"VO: Author: %s\n", info->author);
57 if(info->comment && strlen(info->comment) > 0)
58 mp_msg(MSGT_CPLAYER,MSGL_V,"VO: Comment: %s\n", info->comment);
60 // save vo's stride capability for the wanted colorspace:
61 vf->default_caps=query_format(vf,outfmt);
63 if (vo_config(video_out, width, height, d_width, d_height, flags, "MPlayer", outfmt))
64 return 0;
66 #ifdef CONFIG_ASS
67 if (vf->priv->ass_priv)
68 ass_configure(vf->priv->ass_priv, width, height, !!(vf->default_caps & VFCAP_EOSD_UNSCALED));
69 #endif
71 return 1;
74 static int control(struct vf_instance* vf, int request, void* data)
76 switch(request){
77 case VFCTRL_GET_DEINTERLACE:
79 if(!video_out) return CONTROL_FALSE; // vo not configured?
80 return vo_control(video_out, VOCTRL_GET_DEINTERLACE, data) == VO_TRUE;
82 case VFCTRL_SET_DEINTERLACE:
84 if(!video_out) return CONTROL_FALSE; // vo not configured?
85 return vo_control(video_out, VOCTRL_SET_DEINTERLACE, data) == VO_TRUE;
87 case VFCTRL_DRAW_OSD:
88 if(!video_out->config_ok) return CONTROL_FALSE; // vo not configured?
89 vo_draw_osd(video_out, data);
90 return CONTROL_TRUE;
91 case VFCTRL_FLIP_PAGE:
93 if(!video_out->config_ok) return CONTROL_FALSE; // vo not configured?
94 vo_flip_page(video_out);
95 return CONTROL_TRUE;
97 case VFCTRL_SET_EQUALIZER:
99 vf_equalizer_t *eq=data;
100 if(!video_out->config_ok) return CONTROL_FALSE; // vo not configured?
101 struct voctrl_set_equalizer_args param = {eq->item, eq->value};
102 return vo_control(video_out, VOCTRL_SET_EQUALIZER, &param) == VO_TRUE;
104 case VFCTRL_GET_EQUALIZER:
106 vf_equalizer_t *eq=data;
107 if(!video_out->config_ok) return CONTROL_FALSE; // vo not configured?
108 struct voctrl_get_equalizer_args param = {eq->item, &eq->value};
109 return vo_control(video_out, VOCTRL_GET_EQUALIZER, &param) == VO_TRUE;
111 #ifdef CONFIG_ASS
112 case VFCTRL_INIT_EOSD:
114 vf->priv->ass_priv = ass_renderer_init((ass_library_t*)data);
115 if (!vf->priv->ass_priv) return CONTROL_FALSE;
116 ass_configure_fonts(vf->priv->ass_priv);
117 vf->priv->prev_visibility = 0;
118 return CONTROL_TRUE;
120 case VFCTRL_DRAW_EOSD:
122 mp_eosd_images_t images = {NULL, 2};
123 double pts = vf->priv->pts;
124 if (!video_out->config_ok || !vf->priv->ass_priv) return CONTROL_FALSE;
125 if (sub_visibility && vf->priv->ass_priv && ass_track && (pts != MP_NOPTS_VALUE)) {
126 mp_eosd_res_t res;
127 memset(&res, 0, sizeof(res));
128 if (vo_control(video_out, VOCTRL_GET_EOSD_RES, &res) == VO_TRUE) {
129 ass_set_frame_size(vf->priv->ass_priv, res.w, res.h);
130 ass_set_margins(vf->priv->ass_priv, res.mt, res.mb, res.ml, res.mr);
131 ass_set_aspect_ratio(vf->priv->ass_priv, (double)res.w / res.h);
134 images.imgs = ass_mp_render_frame(vf->priv->ass_priv, ass_track, (pts+sub_delay) * 1000 + .5, &images.changed);
135 if (!vf->priv->prev_visibility)
136 images.changed = 2;
137 vf->priv->prev_visibility = 1;
138 } else
139 vf->priv->prev_visibility = 0;
140 vf->priv->prev_visibility = sub_visibility;
141 return vo_control(video_out, VOCTRL_DRAW_EOSD, &images) == VO_TRUE;
143 #endif
144 case VFCTRL_GET_PTS:
146 *(double *)data = vf->priv->pts;
147 return CONTROL_TRUE;
150 return CONTROL_UNKNOWN;
153 static int query_format(struct vf_instance* vf, unsigned int fmt){
154 int flags = vo_control(video_out, VOCTRL_QUERY_FORMAT, &fmt);
155 // draw_slice() accepts stride, draw_frame() doesn't:
156 if(flags)
157 if(fmt==IMGFMT_YV12 || fmt==IMGFMT_I420 || fmt==IMGFMT_IYUV)
158 flags|=VFCAP_ACCEPT_STRIDE;
159 return flags;
162 static void get_image(struct vf_instance* vf,
163 mp_image_t *mpi){
164 if(vo_directrendering && video_out->config_ok)
165 vo_control(video_out, VOCTRL_GET_IMAGE, mpi);
168 static int put_image(struct vf_instance* vf,
169 mp_image_t *mpi, double pts){
170 if(!video_out->config_ok) return 0; // vo not configured?
171 // record pts (potentially modified by filters) for main loop
172 vf->priv->pts = pts;
173 // first check, maybe the vo/vf plugin implements draw_image using mpi:
174 if (vo_control(video_out, VOCTRL_DRAW_IMAGE,mpi)==VO_TRUE) return 1; // done.
175 // nope, fallback to old draw_frame/draw_slice:
176 if(!(mpi->flags&(MP_IMGFLAG_DIRECT|MP_IMGFLAG_DRAW_CALLBACK))){
177 // blit frame:
178 // if(mpi->flags&MP_IMGFLAG_PLANAR)
179 if(vf->default_caps&VFCAP_ACCEPT_STRIDE)
180 vo_draw_slice(video_out, mpi->planes,mpi->stride,mpi->w,mpi->h,mpi->x,mpi->y);
181 else
182 vo_draw_frame(video_out, mpi->planes);
184 return 1;
187 static void start_slice(struct vf_instance* vf,
188 mp_image_t *mpi) {
189 if(!video_out->config_ok) return; // vo not configured?
190 vo_control(video_out, VOCTRL_START_SLICE,mpi);
193 static void draw_slice(struct vf_instance* vf,
194 unsigned char** src, int* stride, int w,int h, int x, int y){
195 if(!video_out->config_ok) return; // vo not configured?
196 vo_draw_slice(video_out, src,stride,w,h,x,y);
199 static void uninit(struct vf_instance* vf)
201 if (vf->priv) {
202 #ifdef CONFIG_ASS
203 if (vf->priv->ass_priv)
204 ass_renderer_done(vf->priv->ass_priv);
205 #endif
206 free(vf->priv);
209 //===========================================================================//
211 static int open(vf_instance_t *vf, char* args){
212 vf->config=config;
213 vf->control=control;
214 vf->query_format=query_format;
215 vf->get_image=get_image;
216 vf->put_image=put_image;
217 vf->draw_slice=draw_slice;
218 vf->start_slice=start_slice;
219 vf->uninit=uninit;
220 vf->priv=calloc(1, sizeof(struct vf_priv_s));
221 vf->priv->vo = (struct vo *)args;
222 if(!video_out) return 0; // no vo ?
223 return 1;
226 const vf_info_t vf_info_vo = {
227 "libvo wrapper",
228 "vo",
229 "A'rpi",
230 "for internal use",
231 open,
232 NULL
235 //===========================================================================//