sd_ass: initialize structs for external tracks properly
[mplayer.git] / libmpcodecs / vf_vo.c
blob1d838cf447ef8e54a5c23baaa79c0338d2b4bb0c
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"
26 #include "options.h"
28 #include "mp_image.h"
29 #include "vf.h"
31 #include "libvo/video_out.h"
33 #include "sub/dec_sub.h"
35 struct vf_priv_s {
36 struct vo *vo;
37 double scale_ratio;
39 #define video_out (vf->priv->vo)
41 static int query_format(struct vf_instance *vf, unsigned int fmt);
42 static void draw_slice(struct vf_instance *vf, unsigned char **src,
43 int *stride, int w, int h, int x, int y);
45 static int config(struct vf_instance *vf,
46 int width, int height, int d_width, int d_height,
47 unsigned int flags, unsigned int outfmt)
50 if ((width <= 0) || (height <= 0) || (d_width <= 0) || (d_height <= 0)) {
51 mp_msg(MSGT_CPLAYER, MSGL_ERR, "VO: invalid dimensions!\n");
52 return 0;
55 const vo_info_t *info = video_out->driver->info;
56 mp_msg(MSGT_CPLAYER, MSGL_INFO, "VO: [%s] %dx%d => %dx%d %s %s%s%s%s\n",
57 info->short_name,
58 width, height,
59 d_width, d_height,
60 vo_format_name(outfmt),
61 (flags & VOFLAG_FULLSCREEN) ? " [fs]" : "",
62 (flags & VOFLAG_MODESWITCHING) ? " [vm]" : "",
63 (flags & VOFLAG_SWSCALE) ? " [zoom]" : "",
64 (flags & VOFLAG_FLIPPING) ? " [flip]" : "");
65 mp_msg(MSGT_CPLAYER, MSGL_V, "VO: Description: %s\n", info->name);
66 mp_msg(MSGT_CPLAYER, MSGL_V, "VO: Author: %s\n", info->author);
67 if (info->comment && strlen(info->comment) > 0)
68 mp_msg(MSGT_CPLAYER, MSGL_V, "VO: Comment: %s\n", info->comment);
70 // save vo's stride capability for the wanted colorspace:
71 vf->default_caps = query_format(vf, outfmt);
72 vf->draw_slice = (vf->default_caps & VOCAP_NOSLICES) ? NULL : draw_slice;
74 if (vo_config(video_out, width, height, d_width, d_height, flags, outfmt))
75 return 0;
77 vf->priv->scale_ratio = (double) d_width / d_height * height / width;
79 return 1;
82 static int control(struct vf_instance *vf, int request, void *data)
84 switch (request) {
85 case VFCTRL_GET_DEINTERLACE:
86 if (!video_out)
87 return CONTROL_FALSE; // vo not configured?
88 return vo_control(video_out, VOCTRL_GET_DEINTERLACE, data) == VO_TRUE;
89 case VFCTRL_SET_DEINTERLACE:
90 if (!video_out)
91 return CONTROL_FALSE; // vo not configured?
92 return vo_control(video_out, VOCTRL_SET_DEINTERLACE, data) == VO_TRUE;
93 case VFCTRL_GET_YUV_COLORSPACE:
94 return vo_control(video_out, VOCTRL_GET_YUV_COLORSPACE, data) == true;
95 case VFCTRL_SET_YUV_COLORSPACE:
96 return vo_control(video_out, VOCTRL_SET_YUV_COLORSPACE, data) == true;
97 case VFCTRL_DRAW_OSD:
98 if (!video_out->config_ok)
99 return CONTROL_FALSE; // vo not configured?
100 vo_draw_osd(video_out, data);
101 return CONTROL_TRUE;
102 case VFCTRL_SET_EQUALIZER: {
103 vf_equalizer_t *eq = data;
104 if (!video_out->config_ok)
105 return CONTROL_FALSE; // vo not configured?
106 struct voctrl_set_equalizer_args param = {
107 eq->item, eq->value
109 return vo_control(video_out, VOCTRL_SET_EQUALIZER, &param) == VO_TRUE;
111 case VFCTRL_GET_EQUALIZER: {
112 vf_equalizer_t *eq = data;
113 if (!video_out->config_ok)
114 return CONTROL_FALSE; // vo not configured?
115 struct voctrl_get_equalizer_args param = {
116 eq->item, &eq->value
118 return vo_control(video_out, VOCTRL_GET_EQUALIZER, &param) == VO_TRUE;
120 case VFCTRL_DRAW_EOSD: {
121 struct osd_state *osd = data;
122 osd->support_rgba = vf->default_caps & VFCAP_EOSD_RGBA;
123 osd->dim = (struct mp_eosd_res){0};
124 if (!video_out->config_ok ||
125 vo_control(video_out, VOCTRL_GET_EOSD_RES, &osd->dim) != true)
126 return CONTROL_FALSE;
127 osd->normal_scale = 1;
128 osd->vsfilter_scale = vf->priv->scale_ratio;
129 osd->unscaled = vf->default_caps & VFCAP_EOSD_UNSCALED;
130 struct sub_bitmaps images;
131 sub_get_bitmaps(osd, &images);
132 return vo_control(video_out, VOCTRL_DRAW_EOSD, &images) == VO_TRUE;
135 return CONTROL_UNKNOWN;
138 static int query_format(struct vf_instance *vf, unsigned int fmt)
140 int flags = vo_control(video_out, VOCTRL_QUERY_FORMAT, &fmt);
141 // draw_slice() accepts stride, draw_frame() doesn't:
142 if (flags)
143 if (fmt == IMGFMT_YV12 || fmt == IMGFMT_I420 || fmt == IMGFMT_IYUV)
144 flags |= VFCAP_ACCEPT_STRIDE;
145 return flags;
148 static void get_image(struct vf_instance *vf,
149 mp_image_t *mpi)
151 if (!video_out->config_ok)
152 return;
153 // GET_IMAGE is required for hardware-accelerated formats
154 if (vo_directrendering || IMGFMT_IS_HWACCEL(mpi->imgfmt))
155 vo_control(video_out, VOCTRL_GET_IMAGE, mpi);
158 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
160 if (!video_out->config_ok)
161 return 0;
162 // first check, maybe the vo/vf plugin implements draw_image using mpi:
163 if (vo_draw_image(video_out, mpi, pts) >= 0)
164 return 1;
165 // nope, fallback to old draw_frame/draw_slice:
166 if (!(mpi->flags & (MP_IMGFLAG_DIRECT | MP_IMGFLAG_DRAW_CALLBACK))) {
167 // blit frame:
168 if (vf->default_caps & VFCAP_ACCEPT_STRIDE)
169 vo_draw_slice(video_out, mpi->planes, mpi->stride, mpi->w, mpi->h,
170 0, 0);
171 else
172 vo_draw_frame(video_out, mpi->planes);
174 return 1;
177 static void start_slice(struct vf_instance *vf, mp_image_t *mpi)
179 if (!video_out->config_ok)
180 return;
181 vo_control(video_out, VOCTRL_START_SLICE, mpi);
184 static void draw_slice(struct vf_instance *vf, unsigned char **src,
185 int *stride, int w, int h, int x, int y)
187 if (!video_out->config_ok)
188 return;
189 vo_draw_slice(video_out, src, stride, w, h, x, y);
192 static void uninit(struct vf_instance *vf)
194 if (vf->priv) {
195 /* Allow VO (which may live on to work with another instance of vf_vo)
196 * to get rid of numbered-mpi references that will now be invalid. */
197 vo_seek_reset(video_out);
198 free(vf->priv);
202 static int vf_open(vf_instance_t *vf, char *args)
204 vf->config = config;
205 vf->control = control;
206 vf->query_format = query_format;
207 vf->get_image = get_image;
208 vf->put_image = put_image;
209 vf->draw_slice = draw_slice;
210 vf->start_slice = start_slice;
211 vf->uninit = uninit;
212 vf->priv = calloc(1, sizeof(struct vf_priv_s));
213 vf->priv->vo = (struct vo *)args;
214 if (!video_out)
215 return 0;
216 return 1;
219 const vf_info_t vf_info_vo = {
220 "libvo wrapper",
221 "vo",
222 "A'rpi",
223 "for internal use",
224 vf_open,
225 NULL