15 #include "codec-cfg.h"
16 //#include "mp_image.h"
18 #include "img_format.h"
23 #include "dec_video.h"
28 //#include "vd_internal.h"
30 extern vd_functions_t mpcodecs_vd_null
;
31 extern vd_functions_t mpcodecs_vd_ffmpeg
;
32 extern vd_functions_t mpcodecs_vd_theora
;
33 extern vd_functions_t mpcodecs_vd_dshow
;
34 extern vd_functions_t mpcodecs_vd_dmo
;
35 extern vd_functions_t mpcodecs_vd_vfw
;
36 extern vd_functions_t mpcodecs_vd_vfwex
;
37 extern vd_functions_t mpcodecs_vd_odivx
;
38 extern vd_functions_t mpcodecs_vd_divx4
;
39 extern vd_functions_t mpcodecs_vd_raw
;
40 extern vd_functions_t mpcodecs_vd_hmblck
;
41 extern vd_functions_t mpcodecs_vd_xanim
;
42 extern vd_functions_t mpcodecs_vd_nuv
;
43 extern vd_functions_t mpcodecs_vd_mpng
;
44 extern vd_functions_t mpcodecs_vd_ijpg
;
45 extern vd_functions_t mpcodecs_vd_mtga
;
46 extern vd_functions_t mpcodecs_vd_sgi
;
47 extern vd_functions_t mpcodecs_vd_libmpeg2
;
48 extern vd_functions_t mpcodecs_vd_mpegpes
;
49 extern vd_functions_t mpcodecs_vd_zrmjpeg
;
50 extern vd_functions_t mpcodecs_vd_realvid
;
51 extern vd_functions_t mpcodecs_vd_xvid
;
52 extern vd_functions_t mpcodecs_vd_libdv
;
53 extern vd_functions_t mpcodecs_vd_lzo
;
54 extern vd_functions_t mpcodecs_vd_qtvideo
;
56 vd_functions_t
* mpcodecs_vd_drivers
[] = {
94 &mpcodecs_vd_libmpeg2
,
100 #ifdef USE_REALCODECS
101 &mpcodecs_vd_realvid
,
103 #if defined(HAVE_XVID3) || defined(HAVE_XVID4)
109 #if defined(USE_QTX_CODECS) || defined(MACOSX)
110 &mpcodecs_vd_qtvideo
,
115 #include "libvo/video_out.h"
122 int opt_screen_size_x
=0;
123 int opt_screen_size_y
=0;
124 float screen_size_xy
=0;
125 float movie_aspect
=-1.0;
129 /** global variables for gamma, brightness, contrast, saturation and hue
130 modified by mplayer.c and Gui/mplayer/gtk/eq.c:
132 1000 if the vo default should be used
134 int vo_gamma_gamma
= 1000;
135 int vo_gamma_brightness
= 1000;
136 int vo_gamma_contrast
= 1000;
137 int vo_gamma_saturation
= 1000;
138 int vo_gamma_hue
= 1000;
140 extern vd_functions_t
* mpvdec
; // FIXME!
141 extern int divx_quality
;
143 int mpcodecs_config_vo(sh_video_t
*sh
, int w
, int h
, unsigned int preferred_outfmt
){
145 unsigned int out_fmt
=0;
146 int screen_size_x
=0;//SCREEN_SIZE_X;
147 int screen_size_y
=0;//SCREEN_SIZE_Y;
148 // vo_functions_t* video_out=sh->video_out;
149 vf_instance_t
* vf
=sh
->vfilter
,*sc
=NULL
;
153 if(!sh
->disp_w
|| !sh
->disp_h
)
154 mp_msg(MSGT_DECVIDEO
,MSGL_WARN
, MSGTR_CodecDidNotSet
);
155 /* XXX: HACK, if sh->disp_* aren't set,
156 * but we have w and h, set them :: atmos */
162 if(!sh
->disp_w
|| !sh
->disp_h
)
165 mp_msg(MSGT_DECVIDEO
,MSGL_INFO
,MSGTR_VoConfigRequest
,w
,h
,vo_format_name(preferred_outfmt
));
167 // if(!vf) return 1; // temp hack
169 if(get_video_quality_max(sh
)<=0 && divx_quality
){
170 // user wants postprocess but no pp filter yet:
171 sh
->vfilter
=vf
=vf_open_filter(vf
,"pp",NULL
);
174 // check if libvo and codec has common outfmt (no conversion):
177 if( mp_msg_test(MSGT_DECVIDEO
,MSGL_V
) ){
179 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"Trying filter chain:");
180 for(f
= vf
; f
; f
= f
->next
)
181 mp_msg(MSGT_DECVIDEO
,MSGL_V
," %s",f
->info
->name
);
182 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"\n");
186 for(i
=0;i
<CODECS_MAX_OUTFMT
;i
++){
188 out_fmt
=sh
->codec
->outfmt
[i
];
189 if(out_fmt
==(unsigned int)0xFFFFFFFF) continue;
190 flags
=vf
->query_format(vf
,out_fmt
);
191 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"vo_debug: query(%s) returned 0x%X (i=%d) \n",vo_format_name(out_fmt
),flags
,i
);
192 if((flags
&VFCAP_CSP_SUPPORTED_BY_HW
) || (flags
&VFCAP_CSP_SUPPORTED
&& j
<0)){
193 // check (query) if codec really support this outfmt...
194 sh
->outfmtidx
=j
; // pass index to the control() function this way
195 if(mpvdec
->control(sh
,VDCTRL_QUERY_FORMAT
,&out_fmt
)==CONTROL_FALSE
){
196 mp_msg(MSGT_CPLAYER
,MSGL_DBG2
,"vo_debug: codec query_format(%s) returned FALSE\n",vo_format_name(out_fmt
));
199 j
=i
; vo_flags
=flags
; if(flags
&VFCAP_CSP_SUPPORTED_BY_HW
) break;
201 if(!palette
&& !(flags
&(VFCAP_CSP_SUPPORTED_BY_HW
|VFCAP_CSP_SUPPORTED
)) && (out_fmt
==IMGFMT_RGB8
||out_fmt
==IMGFMT_BGR8
)){
202 sh
->outfmtidx
=j
; // pass index to the control() function this way
203 if(mpvdec
->control(sh
,VDCTRL_QUERY_FORMAT
,&out_fmt
)!=CONTROL_FALSE
)
208 // TODO: no match - we should use conversion...
209 if(strcmp(vf
->info
->name
,"scale") && palette
!=-1){
210 mp_msg(MSGT_DECVIDEO
,MSGL_INFO
,MSGTR_CouldNotFindColorspace
);
211 sc
=vf
=vf_open_filter(vf
,"scale",NULL
);
215 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"vd: Trying -vf palette...\n");
217 vf
=vf_open_filter(vf
,"palette",NULL
);
220 { // sws failed, if the last filter (vf_vo) support MPEGPES try to append vf_lavc
221 vf_instance_t
* vo
, *vp
= NULL
, *ve
;
222 // Remove the scale filter if we added it ourself
226 vf_uninit_filter(ve
);
228 // Find the last filter (vf_vo)
229 for(vo
= vf
; vo
->next
; vo
= vo
->next
)
231 if(vo
->query_format(vo
,IMGFMT_MPEGPES
) && (!vp
|| (vp
&& strcmp(vp
->info
->name
,"lavc")))) {
232 ve
= vf_open_filter(vo
,"lavc",NULL
);
233 if(vp
) vp
->next
= ve
;
238 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_VOincompCodec
);
242 out_fmt
=sh
->codec
->outfmt
[j
];
243 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,"VDec: using %s as output csp (no %d)\n",vo_format_name(out_fmt
),j
);
247 // autodetect flipping
250 if(sh
->codec
->outflags
[j
]&CODECS_FLAG_FLIP
)
251 if(!(sh
->codec
->outflags
[j
]&CODECS_FLAG_NOFLIP
))
254 if(vo_flags
&VFCAP_FLIPPED
) flip
^=1;
255 if(flip
&& !(vo_flags
&VFCAP_FLIP
)){
256 // we need to flip, but no flipping filter avail.
257 vf_add_before_vo(&vf
, "flip", NULL
);
261 // time to do aspect ratio corrections...
263 if(movie_aspect
>-1.0) sh
->aspect
= movie_aspect
; // cmdline overrides autodetect
264 // if(!sh->aspect) sh->aspect=1.0;
266 if(opt_screen_size_x
||opt_screen_size_y
){
267 screen_size_x
= opt_screen_size_x
;
268 screen_size_y
= opt_screen_size_y
;
270 if(!screen_size_x
) screen_size_x
=SCREEN_SIZE_X
;
271 if(!screen_size_y
) screen_size_y
=SCREEN_SIZE_Y
;
272 if(screen_size_x
<=8) screen_size_x
*=sh
->disp_w
;
273 if(screen_size_y
<=8) screen_size_y
*=sh
->disp_h
;
276 // check source format aspect, calculate prescale ::atmos
277 screen_size_x
=sh
->disp_w
;
278 screen_size_y
=sh
->disp_h
;
279 if(screen_size_xy
>=0.001){
280 if(screen_size_xy
<=8){
281 // -xy means x+y scale
282 screen_size_x
*=screen_size_xy
;
283 screen_size_y
*=screen_size_xy
;
285 // -xy means forced width while keeping correct aspect
286 screen_size_x
=screen_size_xy
;
287 screen_size_y
=screen_size_xy
*sh
->disp_h
/sh
->disp_w
;
292 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MovieAspectIsSet
,sh
->aspect
);
293 w
=(int)((float)screen_size_y
*sh
->aspect
); w
+=w
%2; // round
294 // we don't like horizontal downscale || user forced width:
295 if(w
<screen_size_x
|| screen_size_xy
>8){
296 screen_size_y
=(int)((float)screen_size_x
*(1.0/sh
->aspect
));
297 screen_size_y
+=screen_size_y
%2; // round
298 } else screen_size_x
=w
; // keep new width
300 mp_msg(MSGT_CPLAYER
,MSGL_INFO
,MSGTR_MovieAspectUndefined
);
304 vocfg_flags
= (fullscreen
? VOFLAG_FULLSCREEN
:0)
305 | (vidmode
? VOFLAG_MODESWITCHING
:0)
306 | (softzoom
? VOFLAG_SWSCALE
:0)
307 | (flip
? VOFLAG_FLIPPING
:0);
309 // Time to config libvo!
310 mp_msg(MSGT_CPLAYER
,MSGL_V
,"VO Config (%dx%d->%dx%d,flags=%d,'%s',0x%X)\n",
311 sh
->disp_w
,sh
->disp_h
,
312 screen_size_x
,screen_size_y
,
318 if(vf_config_wrapper(vf
,sh
->disp_w
,sh
->disp_h
,
319 screen_size_x
,screen_size_y
,
322 // "MPlayer",out_fmt)){
323 mp_msg(MSGT_CPLAYER
,MSGL_WARN
,MSGTR_CannotInitVO
);
330 if (vo_gamma_gamma
!= 1000)
331 set_video_colors(sh
, "gamma", vo_gamma_gamma
);
332 if (vo_gamma_brightness
!= 1000)
333 set_video_colors(sh
, "brightness", vo_gamma_brightness
);
334 if (vo_gamma_contrast
!= 1000)
335 set_video_colors(sh
, "contrast", vo_gamma_contrast
);
336 if (vo_gamma_saturation
!= 1000)
337 set_video_colors(sh
, "saturation", vo_gamma_saturation
);
338 if (vo_gamma_hue
!= 1000)
339 set_video_colors(sh
, "hue", vo_gamma_hue
);
344 // mp_imgtype: buffering type, see mp_image.h
345 // mp_imgflag: buffer requirements (read/write, preserve, stride limits), see mp_image.h
346 // returns NULL or allocated mp_image_t*
347 // Note: buffer allocation may be moved to mpcodecs_config_vo() later...
348 mp_image_t
* mpcodecs_get_image(sh_video_t
*sh
, int mp_imgtype
, int mp_imgflag
, int w
, int h
){
349 mp_image_t
* mpi
=vf_get_image(sh
->vfilter
,sh
->codec
->outfmt
[sh
->outfmtidx
],mp_imgtype
,mp_imgflag
,w
,h
);
354 void mpcodecs_draw_slice(sh_video_t
*sh
, unsigned char** src
, int* stride
, int w
,int h
, int x
, int y
) {
355 struct vf_instance_s
* vf
= sh
->vfilter
;
358 vf
->draw_slice(vf
,src
,stride
,w
,h
,x
,y
);