Remove internal NuppelVideo decoder, the code in libavcodec can decode
[mplayer/glamo.git] / libmpcodecs / vd.c
blobfa2f74ef00d42a051d4b97b96a88cd07c0015b5e
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
5 #include "config.h"
6 #include "mp_msg.h"
7 #include "help_mp.h"
9 #if HAVE_MALLOC_H
10 #include <malloc.h>
11 #endif
13 #include "codec-cfg.h"
14 //#include "mp_image.h"
16 #include "img_format.h"
18 #include "stream/stream.h"
19 #include "libmpdemux/demuxer.h"
20 #include "libmpdemux/stheader.h"
21 #include "dec_video.h"
23 #include "vd.h"
24 #include "vf.h"
26 //#include "vd_internal.h"
28 extern vd_functions_t mpcodecs_vd_null;
29 extern vd_functions_t mpcodecs_vd_ffmpeg;
30 extern vd_functions_t mpcodecs_vd_theora;
31 extern vd_functions_t mpcodecs_vd_dshow;
32 extern vd_functions_t mpcodecs_vd_dmo;
33 extern vd_functions_t mpcodecs_vd_vfw;
34 extern vd_functions_t mpcodecs_vd_vfwex;
35 extern vd_functions_t mpcodecs_vd_raw;
36 extern vd_functions_t mpcodecs_vd_hmblck;
37 extern vd_functions_t mpcodecs_vd_xanim;
38 extern vd_functions_t mpcodecs_vd_mpng;
39 extern vd_functions_t mpcodecs_vd_ijpg;
40 extern vd_functions_t mpcodecs_vd_mtga;
41 extern vd_functions_t mpcodecs_vd_sgi;
42 extern vd_functions_t mpcodecs_vd_libmpeg2;
43 extern vd_functions_t mpcodecs_vd_mpegpes;
44 extern vd_functions_t mpcodecs_vd_zrmjpeg;
45 extern vd_functions_t mpcodecs_vd_realvid;
46 extern vd_functions_t mpcodecs_vd_xvid;
47 extern vd_functions_t mpcodecs_vd_libdv;
48 extern vd_functions_t mpcodecs_vd_lzo;
49 extern vd_functions_t mpcodecs_vd_qtvideo;
51 /* Please do not add any new decoders here. If you want to implement a new
52 * decoder, add it to libavcodec, except for wrappers around external
53 * libraries and decoders requiring binary support. */
55 const vd_functions_t * const mpcodecs_vd_drivers[] = {
56 &mpcodecs_vd_null,
57 #ifdef CONFIG_LIBAVCODEC
58 &mpcodecs_vd_ffmpeg,
59 #endif
60 #ifdef CONFIG_OGGTHEORA
61 &mpcodecs_vd_theora,
62 #endif
63 #ifdef CONFIG_WIN32DLL
64 &mpcodecs_vd_dshow,
65 &mpcodecs_vd_dmo,
66 &mpcodecs_vd_vfw,
67 &mpcodecs_vd_vfwex,
68 #endif
69 &mpcodecs_vd_lzo,
70 &mpcodecs_vd_raw,
71 &mpcodecs_vd_hmblck,
72 #ifdef CONFIG_XANIM
73 &mpcodecs_vd_xanim,
74 #endif
75 #ifdef CONFIG_PNG
76 &mpcodecs_vd_mpng,
77 #endif
78 #ifdef CONFIG_JPEG
79 &mpcodecs_vd_ijpg,
80 #endif
81 &mpcodecs_vd_mtga,
82 &mpcodecs_vd_sgi,
83 #ifdef CONFIG_LIBMPEG2
84 &mpcodecs_vd_libmpeg2,
85 #endif
86 &mpcodecs_vd_mpegpes,
87 #ifdef CONFIG_ZR
88 &mpcodecs_vd_zrmjpeg,
89 #endif
90 #ifdef CONFIG_REALCODECS
91 &mpcodecs_vd_realvid,
92 #endif
93 #ifdef CONFIG_XVID4
94 &mpcodecs_vd_xvid,
95 #endif
96 #ifdef CONFIG_LIBDV095
97 &mpcodecs_vd_libdv,
98 #endif
99 #ifdef CONFIG_QTX_CODECS
100 &mpcodecs_vd_qtvideo,
101 #endif
102 /* Please do not add any new decoders here. If you want to implement a new
103 * decoder, add it to libavcodec, except for wrappers around external
104 * libraries and decoders requiring binary support. */
105 NULL
108 #include "libvo/video_out.h"
110 // libvo opts:
111 int fullscreen=0;
112 int vidmode=0;
113 int softzoom=0;
114 int flip=-1;
115 int opt_screen_size_x=0;
116 int opt_screen_size_y=0;
117 float screen_size_xy=0;
118 float movie_aspect=-1.0;
119 int vo_flags=0;
120 int vd_use_slices=1;
122 /** global variables for gamma, brightness, contrast, saturation and hue
123 modified by mplayer.c and gui/mplayer/gtk/eq.c:
124 ranges -100 - 100
125 1000 if the vo default should be used
127 int vo_gamma_gamma = 1000;
128 int vo_gamma_brightness = 1000;
129 int vo_gamma_contrast = 1000;
130 int vo_gamma_saturation = 1000;
131 int vo_gamma_hue = 1000;
133 extern vd_functions_t* mpvdec; // FIXME!
135 #define SCREEN_SIZE_X 1
136 #define SCREEN_SIZE_Y 1
138 int mpcodecs_config_vo(sh_video_t *sh, int w, int h, unsigned int preferred_outfmt){
139 int i,j;
140 unsigned int out_fmt=0;
141 int screen_size_x=0;//SCREEN_SIZE_X;
142 int screen_size_y=0;//SCREEN_SIZE_Y;
143 vf_instance_t* vf=sh->vfilter,*sc=NULL;
144 int palette=0;
145 int vocfg_flags=0;
147 if(w)
148 sh->disp_w=w;
149 if(h)
150 sh->disp_h=h;
152 if(!sh->disp_w || !sh->disp_h)
153 return 0;
155 mp_msg(MSGT_DECVIDEO,MSGL_INFO,MSGTR_VoConfigRequest,w,h,vo_format_name(preferred_outfmt));
157 // if(!vf) return 1; // temp hack
159 if(get_video_quality_max(sh)<=0 && divx_quality){
160 // user wants postprocess but no pp filter yet:
161 sh->vfilter=vf=vf_open_filter(vf,"pp",NULL);
164 // check if libvo and codec has common outfmt (no conversion):
165 csp_again:
167 if( mp_msg_test(MSGT_DECVIDEO,MSGL_V) ){
168 vf_instance_t* f=vf;
169 mp_msg(MSGT_DECVIDEO,MSGL_V,"Trying filter chain:");
170 for(f = vf ; f ; f = f->next)
171 mp_msg(MSGT_DECVIDEO,MSGL_V," %s",f->info->name);
172 mp_msg(MSGT_DECVIDEO,MSGL_V,"\n");
175 j=-1;
176 for(i=0;i<CODECS_MAX_OUTFMT;i++){
177 int flags;
178 out_fmt=sh->codec->outfmt[i];
179 if(out_fmt==(unsigned int)0xFFFFFFFF) continue;
180 flags=vf->query_format(vf,out_fmt);
181 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"vo_debug: query(%s) returned 0x%X (i=%d) \n",vo_format_name(out_fmt),flags,i);
182 if((flags&VFCAP_CSP_SUPPORTED_BY_HW) || (flags&VFCAP_CSP_SUPPORTED && j<0)){
183 // check (query) if codec really support this outfmt...
184 sh->outfmtidx=j; // pass index to the control() function this way
185 if(mpvdec->control(sh,VDCTRL_QUERY_FORMAT,&out_fmt)==CONTROL_FALSE){
186 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"vo_debug: codec query_format(%s) returned FALSE\n",vo_format_name(out_fmt));
187 continue;
189 j=i; vo_flags=flags; if(flags&VFCAP_CSP_SUPPORTED_BY_HW) break;
190 } else
191 if(!palette && !(flags&(VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_CSP_SUPPORTED)) && (out_fmt==IMGFMT_RGB8||out_fmt==IMGFMT_BGR8)){
192 sh->outfmtidx=j; // pass index to the control() function this way
193 if(mpvdec->control(sh,VDCTRL_QUERY_FORMAT,&out_fmt)!=CONTROL_FALSE)
194 palette=1;
197 if(j<0){
198 // TODO: no match - we should use conversion...
199 if(strcmp(vf->info->name,"scale") && palette!=-1){
200 mp_msg(MSGT_DECVIDEO,MSGL_INFO,MSGTR_CouldNotFindColorspace);
201 sc=vf=vf_open_filter(vf,"scale",NULL);
202 goto csp_again;
203 } else
204 if(palette==1){
205 mp_msg(MSGT_DECVIDEO,MSGL_V,"vd: Trying -vf palette...\n");
206 palette=-1;
207 vf=vf_open_filter(vf,"palette",NULL);
208 goto csp_again;
209 } else
210 { // sws failed, if the last filter (vf_vo) support MPEGPES try to append vf_lavc
211 vf_instance_t* vo, *vp = NULL, *ve;
212 // Remove the scale filter if we added it ourself
213 if(vf == sc) {
214 ve = vf;
215 vf = vf->next;
216 vf_uninit_filter(ve);
218 // Find the last filter (vf_vo)
219 for(vo = vf ; vo->next ; vo = vo->next)
220 vp = vo;
221 if(vo->query_format(vo,IMGFMT_MPEGPES) && (!vp || (vp && strcmp(vp->info->name,"lavc")))) {
222 ve = vf_open_filter(vo,"lavc",NULL);
223 if(vp) vp->next = ve;
224 else vf = ve;
225 goto csp_again;
228 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_VOincompCodec);
229 sh->vf_initialized=-1;
230 return 0; // failed
232 out_fmt=sh->codec->outfmt[j];
233 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_UsingXAsOutputCspNoY,vo_format_name(out_fmt),j);
234 sh->outfmtidx=j;
235 sh->vfilter=vf;
237 // autodetect flipping
238 if(flip==-1){
239 flip=0;
240 if(sh->codec->outflags[j]&CODECS_FLAG_FLIP)
241 if(!(sh->codec->outflags[j]&CODECS_FLAG_NOFLIP))
242 flip=1;
244 if(vo_flags&VFCAP_FLIPPED) flip^=1;
245 if(flip && !(vo_flags&VFCAP_FLIP)){
246 // we need to flip, but no flipping filter avail.
247 vf_add_before_vo(&vf, "flip", NULL);
248 sh->vfilter = vf;
251 // time to do aspect ratio corrections...
253 if(movie_aspect>-1.0) sh->aspect = movie_aspect; // cmdline overrides autodetect
254 else if(sh->stream_aspect!=0.0) sh->aspect = sh->stream_aspect;
255 // if(!sh->aspect) sh->aspect=1.0;
257 if(opt_screen_size_x||opt_screen_size_y){
258 screen_size_x = opt_screen_size_x;
259 screen_size_y = opt_screen_size_y;
260 if(!vidmode){
261 if(!screen_size_x) screen_size_x=SCREEN_SIZE_X;
262 if(!screen_size_y) screen_size_y=SCREEN_SIZE_Y;
263 if(screen_size_x<=8) screen_size_x*=sh->disp_w;
264 if(screen_size_y<=8) screen_size_y*=sh->disp_h;
266 } else {
267 // check source format aspect, calculate prescale ::atmos
268 screen_size_x=sh->disp_w;
269 screen_size_y=sh->disp_h;
270 if(screen_size_xy>=0.001){
271 if(screen_size_xy<=8){
272 // -xy means x+y scale
273 screen_size_x*=screen_size_xy;
274 screen_size_y*=screen_size_xy;
275 } else {
276 // -xy means forced width while keeping correct aspect
277 screen_size_x=screen_size_xy;
278 screen_size_y=screen_size_xy*sh->disp_h/sh->disp_w;
281 if(sh->aspect>0.01){
282 int w;
283 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MovieAspectIsSet,sh->aspect);
284 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_ASPECT=%1.4f\n", sh->aspect);
285 w=(int)((float)screen_size_y*sh->aspect); w+=w%2; // round
286 // we don't like horizontal downscale || user forced width:
287 if(w<screen_size_x || screen_size_xy>8){
288 screen_size_y=(int)((float)screen_size_x*(1.0/sh->aspect));
289 screen_size_y+=screen_size_y%2; // round
290 } else screen_size_x=w; // keep new width
291 } else {
292 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MovieAspectUndefined);
296 vocfg_flags = (fullscreen ? VOFLAG_FULLSCREEN:0)
297 | (vidmode ? VOFLAG_MODESWITCHING:0)
298 | (softzoom ? VOFLAG_SWSCALE:0)
299 | (flip ? VOFLAG_FLIPPING:0);
301 // Time to config libvo!
302 mp_msg(MSGT_CPLAYER,MSGL_V,"VO Config (%dx%d->%dx%d,flags=%d,'%s',0x%X)\n",
303 sh->disp_w,sh->disp_h,
304 screen_size_x,screen_size_y,
305 vocfg_flags,
306 "MPlayer",out_fmt);
308 vf->w = sh->disp_w;
309 vf->h = sh->disp_h;
310 if(vf_config_wrapper(vf,sh->disp_w,sh->disp_h,
311 screen_size_x,screen_size_y,
312 vocfg_flags,
313 out_fmt)==0){
314 // "MPlayer",out_fmt)){
315 mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_CannotInitVO);
316 sh->vf_initialized=-1;
317 return 0;
320 sh->vf_initialized=1;
322 if (vo_gamma_gamma != 1000)
323 set_video_colors(sh, "gamma", vo_gamma_gamma);
324 if (vo_gamma_brightness != 1000)
325 set_video_colors(sh, "brightness", vo_gamma_brightness);
326 if (vo_gamma_contrast != 1000)
327 set_video_colors(sh, "contrast", vo_gamma_contrast);
328 if (vo_gamma_saturation != 1000)
329 set_video_colors(sh, "saturation", vo_gamma_saturation);
330 if (vo_gamma_hue != 1000)
331 set_video_colors(sh, "hue", vo_gamma_hue);
333 return 1;
336 // mp_imgtype: buffering type, see mp_image.h
337 // mp_imgflag: buffer requirements (read/write, preserve, stride limits), see mp_image.h
338 // returns NULL or allocated mp_image_t*
339 // Note: buffer allocation may be moved to mpcodecs_config_vo() later...
340 mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h){
341 mp_image_t* mpi=vf_get_image(sh->vfilter,sh->codec->outfmt[sh->outfmtidx],mp_imgtype,mp_imgflag,w,h);
342 if (mpi) mpi->x=mpi->y=0;
343 return mpi;
346 void mpcodecs_draw_slice(sh_video_t *sh, unsigned char** src, int* stride, int w,int h, int x, int y) {
347 struct vf_instance_s* vf = sh->vfilter;
349 if(vf->draw_slice)
350 vf->draw_slice(vf,src,stride,w,h,x,y);