Use proper length specifiers in mp_msg calls, fixes the warnings:
[mplayer/greg.git] / libmpcodecs / vd.c
blob811cf38a8b432314318b29c81e22c560e7d44513
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
5 #define USE_THEORA
7 #include "config.h"
8 #include "mp_msg.h"
9 #include "help_mp.h"
11 #ifdef HAVE_MALLOC_H
12 #include <malloc.h>
13 #endif
15 #include "codec-cfg.h"
16 //#include "mp_image.h"
18 #include "img_format.h"
20 #include "stream/stream.h"
21 #include "libmpdemux/demuxer.h"
22 #include "libmpdemux/stheader.h"
23 #include "dec_video.h"
25 #include "vd.h"
26 #include "vf.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_raw;
38 extern vd_functions_t mpcodecs_vd_hmblck;
39 extern vd_functions_t mpcodecs_vd_xanim;
40 extern vd_functions_t mpcodecs_vd_nuv;
41 extern vd_functions_t mpcodecs_vd_mpng;
42 extern vd_functions_t mpcodecs_vd_ijpg;
43 extern vd_functions_t mpcodecs_vd_mtga;
44 extern vd_functions_t mpcodecs_vd_sgi;
45 extern vd_functions_t mpcodecs_vd_libmpeg2;
46 extern vd_functions_t mpcodecs_vd_mpegpes;
47 extern vd_functions_t mpcodecs_vd_zrmjpeg;
48 extern vd_functions_t mpcodecs_vd_realvid;
49 extern vd_functions_t mpcodecs_vd_xvid;
50 extern vd_functions_t mpcodecs_vd_libdv;
51 extern vd_functions_t mpcodecs_vd_lzo;
52 extern vd_functions_t mpcodecs_vd_qtvideo;
54 vd_functions_t* mpcodecs_vd_drivers[] = {
55 &mpcodecs_vd_null,
56 #ifdef USE_LIBAVCODEC
57 &mpcodecs_vd_ffmpeg,
58 #endif
59 #ifdef HAVE_OGGTHEORA
60 &mpcodecs_vd_theora,
61 #endif
62 #ifdef USE_WIN32DLL
63 &mpcodecs_vd_dshow,
64 &mpcodecs_vd_dmo,
65 &mpcodecs_vd_vfw,
66 &mpcodecs_vd_vfwex,
67 #endif
68 &mpcodecs_vd_lzo,
69 &mpcodecs_vd_raw,
70 &mpcodecs_vd_hmblck,
71 &mpcodecs_vd_nuv,
72 #ifdef USE_XANIM
73 &mpcodecs_vd_xanim,
74 #endif
75 #ifdef HAVE_PNG
76 &mpcodecs_vd_mpng,
77 #endif
78 #ifdef HAVE_JPEG
79 &mpcodecs_vd_ijpg,
80 #endif
81 &mpcodecs_vd_mtga,
82 &mpcodecs_vd_sgi,
83 #ifdef USE_LIBMPEG2
84 &mpcodecs_vd_libmpeg2,
85 #endif
86 &mpcodecs_vd_mpegpes,
87 #ifdef HAVE_ZR
88 &mpcodecs_vd_zrmjpeg,
89 #endif
90 #ifdef USE_REALCODECS
91 &mpcodecs_vd_realvid,
92 #endif
93 #ifdef HAVE_XVID4
94 &mpcodecs_vd_xvid,
95 #endif
96 #ifdef HAVE_LIBDV095
97 &mpcodecs_vd_libdv,
98 #endif
99 #if defined(USE_QTX_CODECS) || defined(MACOSX)
100 &mpcodecs_vd_qtvideo,
101 #endif
102 NULL
105 #include "libvo/video_out.h"
107 // libvo opts:
108 int fullscreen=0;
109 int vidmode=0;
110 int softzoom=0;
111 int flip=-1;
112 int opt_screen_size_x=0;
113 int opt_screen_size_y=0;
114 float screen_size_xy=0;
115 float movie_aspect=-1.0;
116 int vo_flags=0;
117 int vd_use_slices=1;
119 /** global variables for gamma, brightness, contrast, saturation and hue
120 modified by mplayer.c and gui/mplayer/gtk/eq.c:
121 ranges -100 - 100
122 1000 if the vo default should be used
124 int vo_gamma_gamma = 1000;
125 int vo_gamma_brightness = 1000;
126 int vo_gamma_contrast = 1000;
127 int vo_gamma_saturation = 1000;
128 int vo_gamma_hue = 1000;
130 extern vd_functions_t* mpvdec; // FIXME!
132 int mpcodecs_config_vo(sh_video_t *sh, int w, int h, unsigned int preferred_outfmt){
133 int i,j;
134 unsigned int out_fmt=0;
135 int screen_size_x=0;//SCREEN_SIZE_X;
136 int screen_size_y=0;//SCREEN_SIZE_Y;
137 vf_instance_t* vf=sh->vfilter,*sc=NULL;
138 int palette=0;
139 int vocfg_flags=0;
141 if(w)
142 sh->disp_w=w;
143 if(h)
144 sh->disp_h=h;
146 if(!sh->disp_w || !sh->disp_h)
147 return 0;
149 mp_msg(MSGT_DECVIDEO,MSGL_INFO,MSGTR_VoConfigRequest,w,h,vo_format_name(preferred_outfmt));
151 // if(!vf) return 1; // temp hack
153 if(get_video_quality_max(sh)<=0 && divx_quality){
154 // user wants postprocess but no pp filter yet:
155 sh->vfilter=vf=vf_open_filter(vf,"pp",NULL);
158 // check if libvo and codec has common outfmt (no conversion):
159 csp_again:
161 if( mp_msg_test(MSGT_DECVIDEO,MSGL_V) ){
162 vf_instance_t* f=vf;
163 mp_msg(MSGT_DECVIDEO,MSGL_V,"Trying filter chain:");
164 for(f = vf ; f ; f = f->next)
165 mp_msg(MSGT_DECVIDEO,MSGL_V," %s",f->info->name);
166 mp_msg(MSGT_DECVIDEO,MSGL_V,"\n");
169 j=-1;
170 for(i=0;i<CODECS_MAX_OUTFMT;i++){
171 int flags;
172 out_fmt=sh->codec->outfmt[i];
173 if(out_fmt==(unsigned int)0xFFFFFFFF) continue;
174 flags=vf->query_format(vf,out_fmt);
175 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"vo_debug: query(%s) returned 0x%X (i=%d) \n",vo_format_name(out_fmt),flags,i);
176 if((flags&VFCAP_CSP_SUPPORTED_BY_HW) || (flags&VFCAP_CSP_SUPPORTED && j<0)){
177 // check (query) if codec really support this outfmt...
178 sh->outfmtidx=j; // pass index to the control() function this way
179 if(mpvdec->control(sh,VDCTRL_QUERY_FORMAT,&out_fmt)==CONTROL_FALSE){
180 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"vo_debug: codec query_format(%s) returned FALSE\n",vo_format_name(out_fmt));
181 continue;
183 j=i; vo_flags=flags; if(flags&VFCAP_CSP_SUPPORTED_BY_HW) break;
184 } else
185 if(!palette && !(flags&(VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_CSP_SUPPORTED)) && (out_fmt==IMGFMT_RGB8||out_fmt==IMGFMT_BGR8)){
186 sh->outfmtidx=j; // pass index to the control() function this way
187 if(mpvdec->control(sh,VDCTRL_QUERY_FORMAT,&out_fmt)!=CONTROL_FALSE)
188 palette=1;
191 if(j<0){
192 // TODO: no match - we should use conversion...
193 if(strcmp(vf->info->name,"scale") && palette!=-1){
194 mp_msg(MSGT_DECVIDEO,MSGL_INFO,MSGTR_CouldNotFindColorspace);
195 sc=vf=vf_open_filter(vf,"scale",NULL);
196 goto csp_again;
197 } else
198 if(palette==1){
199 mp_msg(MSGT_DECVIDEO,MSGL_V,"vd: Trying -vf palette...\n");
200 palette=-1;
201 vf=vf_open_filter(vf,"palette",NULL);
202 goto csp_again;
203 } else
204 { // sws failed, if the last filter (vf_vo) support MPEGPES try to append vf_lavc
205 vf_instance_t* vo, *vp = NULL, *ve;
206 // Remove the scale filter if we added it ourself
207 if(vf == sc) {
208 ve = vf;
209 vf = vf->next;
210 vf_uninit_filter(ve);
212 // Find the last filter (vf_vo)
213 for(vo = vf ; vo->next ; vo = vo->next)
214 vp = vo;
215 if(vo->query_format(vo,IMGFMT_MPEGPES) && (!vp || (vp && strcmp(vp->info->name,"lavc")))) {
216 ve = vf_open_filter(vo,"lavc",NULL);
217 if(vp) vp->next = ve;
218 else vf = ve;
219 goto csp_again;
222 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_VOincompCodec);
223 sh->vf_inited=-1;
224 return 0; // failed
226 out_fmt=sh->codec->outfmt[j];
227 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_UsingXAsOutputCspNoY,vo_format_name(out_fmt),j);
228 sh->outfmtidx=j;
229 sh->vfilter=vf;
231 // autodetect flipping
232 if(flip==-1){
233 flip=0;
234 if(sh->codec->outflags[j]&CODECS_FLAG_FLIP)
235 if(!(sh->codec->outflags[j]&CODECS_FLAG_NOFLIP))
236 flip=1;
238 if(vo_flags&VFCAP_FLIPPED) flip^=1;
239 if(flip && !(vo_flags&VFCAP_FLIP)){
240 // we need to flip, but no flipping filter avail.
241 vf_add_before_vo(&vf, "flip", NULL);
242 sh->vfilter = vf;
245 // time to do aspect ratio corrections...
247 if(movie_aspect>-1.0) sh->aspect = movie_aspect; // cmdline overrides autodetect
248 else if(sh->stream_aspect!=0.0) sh->aspect = sh->stream_aspect;
249 // if(!sh->aspect) sh->aspect=1.0;
251 if(opt_screen_size_x||opt_screen_size_y){
252 screen_size_x = opt_screen_size_x;
253 screen_size_y = opt_screen_size_y;
254 if(!vidmode){
255 if(!screen_size_x) screen_size_x=SCREEN_SIZE_X;
256 if(!screen_size_y) screen_size_y=SCREEN_SIZE_Y;
257 if(screen_size_x<=8) screen_size_x*=sh->disp_w;
258 if(screen_size_y<=8) screen_size_y*=sh->disp_h;
260 } else {
261 // check source format aspect, calculate prescale ::atmos
262 screen_size_x=sh->disp_w;
263 screen_size_y=sh->disp_h;
264 if(screen_size_xy>=0.001){
265 if(screen_size_xy<=8){
266 // -xy means x+y scale
267 screen_size_x*=screen_size_xy;
268 screen_size_y*=screen_size_xy;
269 } else {
270 // -xy means forced width while keeping correct aspect
271 screen_size_x=screen_size_xy;
272 screen_size_y=screen_size_xy*sh->disp_h/sh->disp_w;
275 if(sh->aspect>0.01){
276 int w;
277 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MovieAspectIsSet,sh->aspect);
278 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_ASPECT=%1.4f\n", sh->aspect);
279 w=(int)((float)screen_size_y*sh->aspect); w+=w%2; // round
280 // we don't like horizontal downscale || user forced width:
281 if(w<screen_size_x || screen_size_xy>8){
282 screen_size_y=(int)((float)screen_size_x*(1.0/sh->aspect));
283 screen_size_y+=screen_size_y%2; // round
284 } else screen_size_x=w; // keep new width
285 } else {
286 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MovieAspectUndefined);
290 vocfg_flags = (fullscreen ? VOFLAG_FULLSCREEN:0)
291 | (vidmode ? VOFLAG_MODESWITCHING:0)
292 | (softzoom ? VOFLAG_SWSCALE:0)
293 | (flip ? VOFLAG_FLIPPING:0);
295 // Time to config libvo!
296 mp_msg(MSGT_CPLAYER,MSGL_V,"VO Config (%dx%d->%dx%d,flags=%d,'%s',0x%X)\n",
297 sh->disp_w,sh->disp_h,
298 screen_size_x,screen_size_y,
299 vocfg_flags,
300 "MPlayer",out_fmt);
302 vf->w = sh->disp_w;
303 vf->h = sh->disp_h;
304 if(vf_config_wrapper(vf,sh->disp_w,sh->disp_h,
305 screen_size_x,screen_size_y,
306 vocfg_flags,
307 out_fmt)==0){
308 // "MPlayer",out_fmt)){
309 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_CannotInitVO);
310 sh->vf_inited=-1;
311 return 0;
314 sh->vf_inited=1;
316 if (vo_gamma_gamma != 1000)
317 set_video_colors(sh, "gamma", vo_gamma_gamma);
318 if (vo_gamma_brightness != 1000)
319 set_video_colors(sh, "brightness", vo_gamma_brightness);
320 if (vo_gamma_contrast != 1000)
321 set_video_colors(sh, "contrast", vo_gamma_contrast);
322 if (vo_gamma_saturation != 1000)
323 set_video_colors(sh, "saturation", vo_gamma_saturation);
324 if (vo_gamma_hue != 1000)
325 set_video_colors(sh, "hue", vo_gamma_hue);
327 return 1;
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, int w, int h){
335 mp_image_t* mpi=vf_get_image(sh->vfilter,sh->codec->outfmt[sh->outfmtidx],mp_imgtype,mp_imgflag,w,h);
336 mpi->x=mpi->y=0;
337 return mpi;
340 void mpcodecs_draw_slice(sh_video_t *sh, unsigned char** src, int* stride, int w,int h, int x, int y) {
341 struct vf_instance_s* vf = sh->vfilter;
343 if(vf->draw_slice)
344 vf->draw_slice(vf,src,stride,w,h,x,y);