10 #include "codec-cfg.h"
12 #include "img_format.h"
14 #include "stream/stream.h"
15 #include "libmpdemux/demuxer.h"
16 #include "libmpdemux/stheader.h"
17 #include "dec_video.h"
22 extern const vd_functions_t mpcodecs_vd_null
;
23 extern const vd_functions_t mpcodecs_vd_ffmpeg
;
24 extern const vd_functions_t mpcodecs_vd_theora
;
25 extern const vd_functions_t mpcodecs_vd_dshow
;
26 extern const vd_functions_t mpcodecs_vd_dmo
;
27 extern const vd_functions_t mpcodecs_vd_vfw
;
28 extern const vd_functions_t mpcodecs_vd_vfwex
;
29 extern const vd_functions_t mpcodecs_vd_raw
;
30 extern const vd_functions_t mpcodecs_vd_hmblck
;
31 extern const vd_functions_t mpcodecs_vd_xanim
;
32 extern const vd_functions_t mpcodecs_vd_mpng
;
33 extern const vd_functions_t mpcodecs_vd_ijpg
;
34 extern const vd_functions_t mpcodecs_vd_mtga
;
35 extern const vd_functions_t mpcodecs_vd_sgi
;
36 extern const vd_functions_t mpcodecs_vd_libmpeg2
;
37 extern const vd_functions_t mpcodecs_vd_mpegpes
;
38 extern const vd_functions_t mpcodecs_vd_zrmjpeg
;
39 extern const vd_functions_t mpcodecs_vd_realvid
;
40 extern const vd_functions_t mpcodecs_vd_xvid
;
41 extern const vd_functions_t mpcodecs_vd_libdv
;
42 extern const vd_functions_t mpcodecs_vd_lzo
;
43 extern const vd_functions_t mpcodecs_vd_qtvideo
;
45 /* Please do not add any new decoders here. If you want to implement a new
46 * decoder, add it to libavcodec, except for wrappers around external
47 * libraries and decoders requiring binary support. */
49 const vd_functions_t
* const mpcodecs_vd_drivers
[] = {
51 #ifdef CONFIG_LIBAVCODEC
54 #ifdef CONFIG_OGGTHEORA
57 #ifdef CONFIG_WIN32DLL
77 #ifdef CONFIG_LIBMPEG2
78 &mpcodecs_vd_libmpeg2
,
84 #ifdef CONFIG_REALCODECS
90 #ifdef CONFIG_LIBDV095
93 #ifdef CONFIG_QTX_CODECS
96 /* Please do not add any new decoders here. If you want to implement a new
97 * decoder, add it to libavcodec, except for wrappers around external
98 * libraries and decoders requiring binary support. */
102 #include "libvo/video_out.h"
104 int mpcodecs_config_vo(sh_video_t
*sh
, int w
, int h
,
105 unsigned int preferred_outfmt
)
107 struct MPOpts
*opts
= sh
->opts
;
109 unsigned int out_fmt
= 0;
110 int screen_size_x
= 0;
111 int screen_size_y
= 0;
112 vf_instance_t
*vf
= sh
->vfilter
, *sc
= NULL
;
121 if (!sh
->disp_w
|| !sh
->disp_h
)
124 mp_tmsg(MSGT_DECVIDEO
, MSGL_INFO
, "VDec: vo config request - %d x %d (preferred colorspace: %s)\n", w
, h
,
125 vo_format_name(preferred_outfmt
));
127 if (get_video_quality_max(sh
) <= 0 && divx_quality
) {
128 // user wants postprocess but no pp filter yet:
129 sh
->vfilter
= vf
= vf_open_filter(opts
, vf
, "pp", NULL
);
131 // check if libvo and codec has common outfmt (no conversion):
134 if (mp_msg_test(MSGT_DECVIDEO
, MSGL_V
)) {
135 vf_instance_t
*f
= vf
;
136 mp_msg(MSGT_DECVIDEO
, MSGL_V
, "Trying filter chain:");
137 for (f
= vf
; f
; f
= f
->next
)
138 mp_msg(MSGT_DECVIDEO
, MSGL_V
, " %s", f
->info
->name
);
139 mp_msg(MSGT_DECVIDEO
, MSGL_V
, "\n");
143 for (i
= 0; i
< CODECS_MAX_OUTFMT
; i
++) {
145 out_fmt
= sh
->codec
->outfmt
[i
];
146 if (out_fmt
== (unsigned int) 0xFFFFFFFF)
148 flags
= vf
->query_format(vf
, out_fmt
);
149 mp_msg(MSGT_CPLAYER
, MSGL_DBG2
,
150 "vo_debug: query(%s) returned 0x%X (i=%d) \n",
151 vo_format_name(out_fmt
), flags
, i
);
152 if ((flags
& VFCAP_CSP_SUPPORTED_BY_HW
)
153 || (flags
& VFCAP_CSP_SUPPORTED
&& j
< 0)) {
154 // check (query) if codec really support this outfmt...
155 sh
->outfmtidx
= j
; // pass index to the control() function this way
156 if (sh
->vd_driver
->control(sh
, VDCTRL_QUERY_FORMAT
, &out_fmt
) ==
158 mp_msg(MSGT_CPLAYER
, MSGL_DBG2
,
159 "vo_debug: codec query_format(%s) returned FALSE\n",
160 vo_format_name(out_fmt
));
164 sh
->output_flags
= flags
;
165 if (flags
& VFCAP_CSP_SUPPORTED_BY_HW
)
169 (VFCAP_CSP_SUPPORTED_BY_HW
| VFCAP_CSP_SUPPORTED
))
170 && (out_fmt
== IMGFMT_RGB8
|| out_fmt
== IMGFMT_BGR8
)) {
171 sh
->outfmtidx
= j
; // pass index to the control() function this way
172 if (sh
->vd_driver
->control(sh
, VDCTRL_QUERY_FORMAT
, &out_fmt
) !=
178 // TODO: no match - we should use conversion...
179 if (strcmp(vf
->info
->name
, "scale") && palette
!= -1) {
180 mp_tmsg(MSGT_DECVIDEO
, MSGL_INFO
, "Could not find matching colorspace - retrying with -vf scale...\n");
181 sc
= vf
= vf_open_filter(opts
, vf
, "scale", NULL
);
183 } else if (palette
== 1) {
184 mp_msg(MSGT_DECVIDEO
, MSGL_V
, "vd: Trying -vf palette...\n");
186 vf
= vf_open_filter(opts
, vf
, "palette", NULL
);
189 // sws failed, if the last filter (vf_vo) support MPEGPES try
191 vf_instance_t
*vo
, *vp
= NULL
, *ve
;
192 // Remove the scale filter if we added it ourselves
196 vf_uninit_filter(ve
);
198 // Find the last filter (vf_vo)
199 for (vo
= vf
; vo
->next
; vo
= vo
->next
)
201 if (vo
->query_format(vo
, IMGFMT_MPEGPES
)
202 && (!vp
|| (vp
&& strcmp(vp
->info
->name
, "lavc")))) {
203 ve
= vf_open_filter(opts
, vo
, "lavc", NULL
);
211 mp_tmsg(MSGT_CPLAYER
, MSGL_WARN
,
212 "The selected video_out device is incompatible with this codec.\n"\
213 "Try appending the scale filter to your filter list,\n"\
214 "e.g. -vf spp,scale instead of -vf spp.\n");
215 sh
->vf_initialized
= -1;
218 out_fmt
= sh
->codec
->outfmt
[j
];
219 mp_tmsg(MSGT_CPLAYER
, MSGL_INFO
, "VDec: using %s as output csp (no %d)\n",
220 vo_format_name(out_fmt
), j
);
224 // autodetect flipping
225 if (opts
->flip
== -1) {
227 if (sh
->codec
->outflags
[j
] & CODECS_FLAG_FLIP
)
228 if (!(sh
->codec
->outflags
[j
] & CODECS_FLAG_NOFLIP
))
231 if (sh
->output_flags
& VFCAP_FLIPPED
)
233 if (opts
->flip
&& !(sh
->output_flags
& VFCAP_FLIP
)) {
234 // we need to flip, but no flipping filter avail.
235 vf_add_before_vo(&vf
, "flip", NULL
);
238 // time to do aspect ratio corrections...
240 if (opts
->movie_aspect
> -1.0)
241 sh
->aspect
= opts
->movie_aspect
; // cmdline overrides autodetect
242 else if (sh
->stream_aspect
!= 0.0)
243 sh
->aspect
= sh
->stream_aspect
;
245 if (opts
->screen_size_x
|| opts
->screen_size_y
) {
246 screen_size_x
= opts
->screen_size_x
;
247 screen_size_y
= opts
->screen_size_y
;
248 if (!opts
->vidmode
) {
253 if (screen_size_x
<= 8)
254 screen_size_x
*= sh
->disp_w
;
255 if (screen_size_y
<= 8)
256 screen_size_y
*= sh
->disp_h
;
259 // check source format aspect, calculate prescale ::atmos
260 screen_size_x
= sh
->disp_w
;
261 screen_size_y
= sh
->disp_h
;
262 if (opts
->screen_size_xy
>= 0.001) {
263 if (opts
->screen_size_xy
<= 8) {
264 // -xy means x+y scale
265 screen_size_x
*= opts
->screen_size_xy
;
266 screen_size_y
*= opts
->screen_size_xy
;
268 // -xy means forced width while keeping correct aspect
269 screen_size_x
= opts
->screen_size_xy
;
270 screen_size_y
= opts
->screen_size_xy
* sh
->disp_h
/ sh
->disp_w
;
273 if (sh
->aspect
> 0.01) {
275 mp_tmsg(MSGT_CPLAYER
, MSGL_INFO
, "Movie-Aspect is %.2f:1 - prescaling to correct movie aspect.\n",
277 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_VIDEO_ASPECT=%1.4f\n",
279 w
= (int) ((float) screen_size_y
* sh
->aspect
);
281 // we don't like horizontal downscale || user forced width:
282 if (w
< screen_size_x
|| opts
->screen_size_xy
> 8) {
284 (int) ((float) screen_size_x
* (1.0 / sh
->aspect
));
285 screen_size_y
+= screen_size_y
% 2; // round
287 screen_size_x
= w
; // keep new width
289 mp_tmsg(MSGT_CPLAYER
, MSGL_INFO
, "Movie-Aspect is undefined - no prescaling applied.\n");
293 vocfg_flags
= (opts
->fullscreen
? VOFLAG_FULLSCREEN
: 0)
294 | (opts
->vidmode
? VOFLAG_MODESWITCHING
: 0)
295 | (opts
->softzoom
? VOFLAG_SWSCALE
: 0)
296 | (opts
->flip
? VOFLAG_FLIPPING
: 0);
298 // Time to config libvo!
299 mp_msg(MSGT_CPLAYER
, MSGL_V
,
300 "VO Config (%dx%d->%dx%d,flags=%d,'%s',0x%X)\n", sh
->disp_w
,
301 sh
->disp_h
, screen_size_x
, screen_size_y
, vocfg_flags
, "MPlayer",
306 if (vf_config_wrapper
307 (vf
, sh
->disp_w
, sh
->disp_h
, screen_size_x
, screen_size_y
, vocfg_flags
,
309 mp_tmsg(MSGT_CPLAYER
, MSGL_WARN
, "FATAL: Cannot initialize video driver.\n");
310 sh
->vf_initialized
= -1;
314 sh
->vf_initialized
= 1;
316 if (opts
->vo_gamma_gamma
!= 1000)
317 set_video_colors(sh
, "gamma", opts
->vo_gamma_gamma
);
318 if (opts
->vo_gamma_brightness
!= 1000)
319 set_video_colors(sh
, "brightness", opts
->vo_gamma_brightness
);
320 if (opts
->vo_gamma_contrast
!= 1000)
321 set_video_colors(sh
, "contrast", opts
->vo_gamma_contrast
);
322 if (opts
->vo_gamma_saturation
!= 1000)
323 set_video_colors(sh
, "saturation", opts
->vo_gamma_saturation
);
324 if (opts
->vo_gamma_hue
!= 1000)
325 set_video_colors(sh
, "hue", opts
->vo_gamma_hue
);
330 // mp_imgtype: buffering type, see mp_image.h
331 // mp_imgflag: buffer requirements (read/write, preserve, stride limits), see mp_image.h
332 // returns NULL or allocated mp_image_t*
333 // Note: buffer allocation may be moved to mpcodecs_config_vo() later...
334 mp_image_t
*mpcodecs_get_image(sh_video_t
*sh
, int mp_imgtype
, int mp_imgflag
,
338 vf_get_image(sh
->vfilter
, sh
->codec
->outfmt
[sh
->outfmtidx
], mp_imgtype
,
345 void mpcodecs_draw_slice(sh_video_t
*sh
, unsigned char **src
, int *stride
,
346 int w
, int h
, int x
, int y
)
348 struct vf_instance
*vf
= sh
->vfilter
;
351 vf
->draw_slice(vf
, src
, stride
, w
, h
, x
, y
);