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.
31 #include "libvo/video_out.h"
33 #include "sub/dec_sub.h"
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");
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",
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
))
77 vf
->priv
->scale_ratio
= (double) d_width
/ d_height
* height
/ width
;
82 static int control(struct vf_instance
*vf
, int request
, void *data
)
85 case VFCTRL_GET_DEINTERLACE
:
87 return CONTROL_FALSE
; // vo not configured?
88 return vo_control(video_out
, VOCTRL_GET_DEINTERLACE
, data
) == VO_TRUE
;
89 case VFCTRL_SET_DEINTERLACE
:
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;
98 if (!video_out
->config_ok
)
99 return CONTROL_FALSE
; // vo not configured?
100 vo_draw_osd(video_out
, data
);
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
= {
109 return vo_control(video_out
, VOCTRL_SET_EQUALIZER
, ¶m
) == 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
= {
118 return vo_control(video_out
, VOCTRL_GET_EQUALIZER
, ¶m
) == 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:
143 if (fmt
== IMGFMT_YV12
|| fmt
== IMGFMT_I420
|| fmt
== IMGFMT_IYUV
)
144 flags
|= VFCAP_ACCEPT_STRIDE
;
148 static void get_image(struct vf_instance
*vf
,
151 if (!video_out
->config_ok
)
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
)
162 // first check, maybe the vo/vf plugin implements draw_image using mpi:
163 if (vo_draw_image(video_out
, mpi
, pts
) >= 0)
165 // nope, fallback to old draw_frame/draw_slice:
166 if (!(mpi
->flags
& (MP_IMGFLAG_DIRECT
| MP_IMGFLAG_DRAW_CALLBACK
))) {
168 if (vf
->default_caps
& VFCAP_ACCEPT_STRIDE
)
169 vo_draw_slice(video_out
, mpi
->planes
, mpi
->stride
, mpi
->w
, mpi
->h
,
172 vo_draw_frame(video_out
, mpi
->planes
);
177 static void start_slice(struct vf_instance
*vf
, mp_image_t
*mpi
)
179 if (!video_out
->config_ok
)
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
)
189 vo_draw_slice(video_out
, src
, stride
, w
, h
, x
, y
);
192 static void uninit(struct vf_instance
*vf
)
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
);
202 static int vf_open(vf_instance_t
*vf
, char *args
)
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
;
212 vf
->priv
= calloc(1, sizeof(struct vf_priv_s
));
213 vf
->priv
->vo
= (struct vo
*)args
;
219 const vf_info_t vf_info_vo
= {