vo_glamo: sub.h was moved to sub directory in c9026cb3210205b07e2e068467a18ee40f9259a3
[mplayer/glamo.git] / libmpcodecs / vf_vo.c
blob8bbaf465b31b47574d18b7ac4f620c8ca9d89052
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 #include "sub/ass_mp.h"
33 #include "sub/sub.h"
35 //===========================================================================//
37 extern float sub_delay;
39 struct vf_priv_s {
40 struct vo *vo;
41 #ifdef CONFIG_ASS
42 ASS_Renderer *renderer_realaspect;
43 ASS_Renderer *renderer_vsfilter;
44 bool prev_visibility;
45 double scale_ratio;
46 #endif
48 #define video_out (vf->priv->vo)
50 static int query_format(struct vf_instance *vf, unsigned int fmt); /* forward declaration */
51 static void draw_slice(struct vf_instance *vf, unsigned char** src, int* stride, int w,int h, int x, int y);
53 static int config(struct vf_instance *vf,
54 int width, int height, int d_width, int d_height,
55 unsigned int flags, unsigned int outfmt){
57 if ((width <= 0) || (height <= 0) || (d_width <= 0) || (d_height <= 0))
59 mp_msg(MSGT_CPLAYER, MSGL_ERR, "VO: invalid dimensions!\n");
60 return 0;
63 const vo_info_t *info = video_out->driver->info;
64 mp_msg(MSGT_CPLAYER,MSGL_INFO,"VO: [%s] %dx%d => %dx%d %s %s%s%s%s\n",info->short_name,
65 width, height,
66 d_width, d_height,
67 vo_format_name(outfmt),
68 (flags&VOFLAG_FULLSCREEN)?" [fs]":"",
69 (flags&VOFLAG_MODESWITCHING)?" [vm]":"",
70 (flags&VOFLAG_SWSCALE)?" [zoom]":"",
71 (flags&VOFLAG_FLIPPING)?" [flip]":"");
72 mp_msg(MSGT_CPLAYER,MSGL_V,"VO: Description: %s\n",info->name);
73 mp_msg(MSGT_CPLAYER,MSGL_V,"VO: Author: %s\n", info->author);
74 if(info->comment && strlen(info->comment) > 0)
75 mp_msg(MSGT_CPLAYER,MSGL_V,"VO: Comment: %s\n", info->comment);
77 // save vo's stride capability for the wanted colorspace:
78 vf->default_caps=query_format(vf,outfmt);
79 vf->draw_slice = (vf->default_caps & VOCAP_NOSLICES) ? NULL : draw_slice;
81 if (vo_config(video_out, width, height, d_width, d_height, flags, "MPlayer", outfmt))
82 return 0;
84 #ifdef CONFIG_ASS
85 vf->priv->scale_ratio = (double) d_width / d_height * height / width;
87 if (vf->priv->renderer_realaspect) {
88 mp_ass_configure(vf->priv->renderer_realaspect, width, height,
89 vf->default_caps & VFCAP_EOSD_UNSCALED);
90 mp_ass_configure(vf->priv->renderer_vsfilter, width, height,
91 vf->default_caps & VFCAP_EOSD_UNSCALED);
93 #endif
95 return 1;
98 static int control(struct vf_instance *vf, int request, void* data)
100 switch(request){
101 case VFCTRL_GET_DEINTERLACE:
103 if(!video_out) return CONTROL_FALSE; // vo not configured?
104 return vo_control(video_out, VOCTRL_GET_DEINTERLACE, data) == VO_TRUE;
106 case VFCTRL_SET_DEINTERLACE:
108 if(!video_out) return CONTROL_FALSE; // vo not configured?
109 return vo_control(video_out, VOCTRL_SET_DEINTERLACE, data) == VO_TRUE;
111 case VFCTRL_GET_YUV_COLORSPACE:
112 return vo_control(video_out, VOCTRL_GET_YUV_COLORSPACE, data) == true;
113 case VFCTRL_SET_YUV_COLORSPACE:
114 return vo_control(video_out, VOCTRL_SET_YUV_COLORSPACE, data) == true;
115 case VFCTRL_DRAW_OSD:
116 if(!video_out->config_ok) return CONTROL_FALSE; // vo not configured?
117 vo_draw_osd(video_out, data);
118 return CONTROL_TRUE;
119 case VFCTRL_REDRAW_OSD:
120 return vo_control(video_out, VOCTRL_REDRAW_OSD, data) == true;
121 case VFCTRL_SET_EQUALIZER:
123 vf_equalizer_t *eq=data;
124 if(!video_out->config_ok) return CONTROL_FALSE; // vo not configured?
125 struct voctrl_set_equalizer_args param = {eq->item, eq->value};
126 return vo_control(video_out, VOCTRL_SET_EQUALIZER, &param) == VO_TRUE;
128 case VFCTRL_GET_EQUALIZER:
130 vf_equalizer_t *eq=data;
131 if(!video_out->config_ok) return CONTROL_FALSE; // vo not configured?
132 struct voctrl_get_equalizer_args param = {eq->item, &eq->value};
133 return vo_control(video_out, VOCTRL_GET_EQUALIZER, &param) == VO_TRUE;
135 #ifdef CONFIG_ASS
136 case VFCTRL_INIT_EOSD:
138 vf->priv->renderer_realaspect = ass_renderer_init(data);
139 if (!vf->priv->renderer_realaspect)
140 return CONTROL_FALSE;
141 vf->priv->renderer_vsfilter = ass_renderer_init(data);
142 if (!vf->priv->renderer_vsfilter) {
143 ass_renderer_done(vf->priv->renderer_realaspect);
144 return CONTROL_FALSE;
146 mp_ass_configure_fonts(vf->priv->renderer_realaspect);
147 mp_ass_configure_fonts(vf->priv->renderer_vsfilter);
148 vf->priv->prev_visibility = false;
149 return CONTROL_TRUE;
151 case VFCTRL_DRAW_EOSD:
153 struct osd_state *osd = data;
154 mp_eosd_images_t images = {NULL, 2};
155 double pts = video_out->next_pts;
156 ASS_Renderer *renderer;
157 double scale;
158 if (osd->vsfilter_aspect) {
159 renderer = vf->priv->renderer_vsfilter;
160 scale = vf->priv->scale_ratio;
161 } else {
162 renderer = vf->priv->renderer_realaspect;
163 scale = 1;
165 if (!video_out->config_ok || !renderer)
166 return CONTROL_FALSE;
167 if (osd->ass_track_changed)
168 vf->priv->prev_visibility = false;
169 osd->ass_track_changed = false;
170 if (sub_visibility && osd->ass_track && (pts != MP_NOPTS_VALUE)) {
171 struct mp_eosd_res res = {0};
172 if (vo_control(video_out, VOCTRL_GET_EOSD_RES, &res) == VO_TRUE) {
173 ass_set_frame_size(renderer, res.w, res.h);
174 ass_set_margins(renderer, res.mt, res.mb, res.ml, res.mr);
175 ass_set_aspect_ratio(renderer, scale, 1);
178 images.imgs = mp_ass_render_frame(renderer,
179 osd->ass_track,
180 (pts+sub_delay) * 1000 + .5,
181 &images.changed);
182 if (!vf->priv->prev_visibility)
183 images.changed = 2;
184 vf->priv->prev_visibility = true;
185 } else
186 vf->priv->prev_visibility = false;
187 return vo_control(video_out, VOCTRL_DRAW_EOSD, &images) == VO_TRUE;
189 #endif
191 return CONTROL_UNKNOWN;
194 static int query_format(struct vf_instance *vf, unsigned int fmt){
195 int flags = vo_control(video_out, VOCTRL_QUERY_FORMAT, &fmt);
196 // draw_slice() accepts stride, draw_frame() doesn't:
197 if(flags)
198 if(fmt==IMGFMT_YV12 || fmt==IMGFMT_I420 || fmt==IMGFMT_IYUV)
199 flags|=VFCAP_ACCEPT_STRIDE;
200 return flags;
203 static void get_image(struct vf_instance *vf,
204 mp_image_t *mpi){
205 if (!video_out->config_ok)
206 return;
207 // GET_IMAGE is required for hardware-accelerated formats
208 if(vo_directrendering ||
209 IMGFMT_IS_HWACCEL(mpi->imgfmt))
210 vo_control(video_out, VOCTRL_GET_IMAGE, mpi);
213 static int put_image(struct vf_instance *vf,
214 mp_image_t *mpi, double pts){
215 if(!video_out->config_ok) return 0; // vo not configured?
216 // first check, maybe the vo/vf plugin implements draw_image using mpi:
217 if (vo_draw_image(video_out, mpi, pts) >= 0)
218 return 1;
219 // nope, fallback to old draw_frame/draw_slice:
220 if(!(mpi->flags&(MP_IMGFLAG_DIRECT|MP_IMGFLAG_DRAW_CALLBACK))){
221 // blit frame:
222 // if(mpi->flags&MP_IMGFLAG_PLANAR)
223 if(vf->default_caps&VFCAP_ACCEPT_STRIDE)
224 vo_draw_slice(video_out, mpi->planes,mpi->stride,mpi->w,mpi->h,mpi->x,mpi->y);
225 else
226 vo_draw_frame(video_out, mpi->planes);
228 return 1;
231 static void start_slice(struct vf_instance *vf,
232 mp_image_t *mpi) {
233 if(!video_out->config_ok) return; // vo not configured?
234 vo_control(video_out, VOCTRL_START_SLICE,mpi);
237 static void draw_slice(struct vf_instance *vf,
238 unsigned char** src, int* stride, int w,int h, int x, int y){
239 if(!video_out->config_ok) return; // vo not configured?
240 vo_draw_slice(video_out, src,stride,w,h,x,y);
243 static void uninit(struct vf_instance *vf)
245 if (vf->priv) {
246 /* Allow VO (which may live on to work with another instance of vf_vo)
247 * to get rid of numbered-mpi references that will now be invalid. */
248 vo_seek_reset(video_out);
249 #ifdef CONFIG_ASS
250 if (vf->priv->renderer_realaspect) {
251 ass_renderer_done(vf->priv->renderer_realaspect);
252 ass_renderer_done(vf->priv->renderer_vsfilter);
254 #endif
255 free(vf->priv);
258 //===========================================================================//
260 static int vf_open(vf_instance_t *vf, char *args){
261 vf->config=config;
262 vf->control=control;
263 vf->query_format=query_format;
264 vf->get_image=get_image;
265 vf->put_image=put_image;
266 vf->draw_slice=draw_slice;
267 vf->start_slice=start_slice;
268 vf->uninit=uninit;
269 vf->priv=calloc(1, sizeof(struct vf_priv_s));
270 vf->priv->vo = (struct vo *)args;
271 if(!video_out) return 0; // no vo ?
272 return 1;
275 const vf_info_t vf_info_vo = {
276 "libvo wrapper",
277 "vo",
278 "A'rpi",
279 "for internal use",
280 vf_open,
281 NULL
284 //===========================================================================//