Mercurial > mplayer.hg
annotate libmpcodecs/vd.c @ 5179:104cd0571dc4
changed status of 'null' codec to avoid prefering it over buggy codecs
author | arpi |
---|---|
date | Mon, 18 Mar 2002 01:55:38 +0000 |
parents | 0dab2d783817 |
children | 7e77d7344208 |
rev | line source |
---|---|
4878 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 | |
5 #include "config.h" | |
6 #include "mp_msg.h" | |
5075 | 7 #include "help_mp.h" |
4878 | 8 |
9 #ifdef HAVE_MALLOC_H | |
10 #include <malloc.h> | |
11 #endif | |
12 | |
13 #include "codec-cfg.h" | |
14 //#include "mp_image.h" | |
15 | |
16 #include "../libvo/img_format.h" | |
17 | |
18 #include "stream.h" | |
19 #include "demuxer.h" | |
20 #include "stheader.h" | |
21 | |
22 #include "vd.h" | |
23 //#include "vd_internal.h" | |
24 | |
25 extern vd_functions_t mpcodecs_vd_null; | |
4885 | 26 extern vd_functions_t mpcodecs_vd_cinepak; |
4915
f6990fad0ab3
Qt RPZA decoder interface by Roberto Togni <rtogni@bresciaonline.it>
arpi
parents:
4899
diff
changeset
|
27 extern vd_functions_t mpcodecs_vd_qtrpza; |
4951 | 28 extern vd_functions_t mpcodecs_vd_ffmpeg; |
4958 | 29 extern vd_functions_t mpcodecs_vd_dshow; |
4968 | 30 extern vd_functions_t mpcodecs_vd_vfw; |
31 extern vd_functions_t mpcodecs_vd_vfwex; | |
32 extern vd_functions_t mpcodecs_vd_odivx; | |
33 extern vd_functions_t mpcodecs_vd_divx4; | |
4969 | 34 extern vd_functions_t mpcodecs_vd_raw; |
35 extern vd_functions_t mpcodecs_vd_xanim; | |
36 extern vd_functions_t mpcodecs_vd_rle; | |
4987 | 37 extern vd_functions_t mpcodecs_vd_msvidc; |
38 extern vd_functions_t mpcodecs_vd_fli; | |
4989 | 39 extern vd_functions_t mpcodecs_vd_qtrle; |
40 extern vd_functions_t mpcodecs_vd_qtsmc; | |
41 extern vd_functions_t mpcodecs_vd_roqvideo; | |
42 extern vd_functions_t mpcodecs_vd_cyuv; | |
43 extern vd_functions_t mpcodecs_vd_nuv; | |
4998 | 44 extern vd_functions_t mpcodecs_vd_mpng; |
5029 | 45 extern vd_functions_t mpcodecs_vd_ijpg; |
4998 | 46 extern vd_functions_t mpcodecs_vd_libmpeg2; |
4878 | 47 |
48 vd_functions_t* mpcodecs_vd_drivers[] = { | |
49 &mpcodecs_vd_null, | |
4884 | 50 &mpcodecs_vd_cinepak, |
4915
f6990fad0ab3
Qt RPZA decoder interface by Roberto Togni <rtogni@bresciaonline.it>
arpi
parents:
4899
diff
changeset
|
51 &mpcodecs_vd_qtrpza, |
4951 | 52 #ifdef USE_LIBAVCODEC |
53 &mpcodecs_vd_ffmpeg, | |
54 #endif | |
4968 | 55 #ifdef USE_WIN32DLL |
4958 | 56 #ifdef USE_DIRECTSHOW |
57 &mpcodecs_vd_dshow, | |
58 #endif | |
4968 | 59 &mpcodecs_vd_vfw, |
60 &mpcodecs_vd_vfwex, | |
61 #endif | |
62 #ifdef USE_DIVX | |
63 &mpcodecs_vd_odivx, | |
64 #ifdef NEW_DECORE | |
65 &mpcodecs_vd_divx4, | |
66 #endif | |
67 #endif | |
4969 | 68 &mpcodecs_vd_raw, |
69 &mpcodecs_vd_rle, | |
4987 | 70 &mpcodecs_vd_msvidc, |
71 &mpcodecs_vd_fli, | |
4989 | 72 &mpcodecs_vd_qtrle, |
73 &mpcodecs_vd_qtsmc, | |
74 &mpcodecs_vd_roqvideo, | |
75 &mpcodecs_vd_cyuv, | |
76 &mpcodecs_vd_nuv, | |
4969 | 77 #ifdef USE_XANIM |
78 &mpcodecs_vd_xanim, | |
79 #endif | |
4998 | 80 #ifdef HAVE_PNG |
81 &mpcodecs_vd_mpng, | |
82 #endif | |
5029 | 83 #ifdef HAVE_JPEG |
84 &mpcodecs_vd_ijpg, | |
85 #endif | |
4998 | 86 &mpcodecs_vd_libmpeg2, |
4878 | 87 NULL |
88 }; | |
89 | |
4971 | 90 #include "libvo/video_out.h" |
4976 | 91 extern int vaa_use_dr; |
4971 | 92 |
5075 | 93 // libvo opts: |
94 int fullscreen=0; | |
95 int vidmode=0; | |
96 int softzoom=0; | |
97 int flip=-1; | |
98 int opt_screen_size_x=0; | |
99 int opt_screen_size_y=0; | |
100 int screen_size_xy=0; | |
101 float movie_aspect=-1.0; | |
102 int vo_flags=0; | |
103 | |
104 static vo_tune_info_t vtune; | |
105 | |
5156
1c250c1da93c
libvo printfs added (moved from mplayer.c), mpi buffers free'd to fix multifile playback
arpi
parents:
5131
diff
changeset
|
106 static mp_image_t* static_images[2]; |
1c250c1da93c
libvo printfs added (moved from mplayer.c), mpi buffers free'd to fix multifile playback
arpi
parents:
5131
diff
changeset
|
107 static mp_image_t* temp_images[1]; |
1c250c1da93c
libvo printfs added (moved from mplayer.c), mpi buffers free'd to fix multifile playback
arpi
parents:
5131
diff
changeset
|
108 static mp_image_t* export_images[1]; |
1c250c1da93c
libvo printfs added (moved from mplayer.c), mpi buffers free'd to fix multifile playback
arpi
parents:
5131
diff
changeset
|
109 static int static_idx=0; |
1c250c1da93c
libvo printfs added (moved from mplayer.c), mpi buffers free'd to fix multifile playback
arpi
parents:
5131
diff
changeset
|
110 |
4878 | 111 int mpcodecs_config_vo(sh_video_t *sh, int w, int h, unsigned int preferred_outfmt){ |
5131
cff03e88d331
prefer outfmt with no conversion (see vo's query flags)
arpi
parents:
5077
diff
changeset
|
112 int i,j; |
5075 | 113 unsigned int out_fmt=0; |
114 int screen_size_x=0;//SCREEN_SIZE_X; | |
115 int screen_size_y=0;//SCREEN_SIZE_Y; | |
116 vo_functions_t* video_out=sh->video_out; | |
117 | |
5004 | 118 mp_msg(MSGT_DECVIDEO,MSGL_INFO,"VDec: vo config request - %d x %d, %s \n", |
119 w,h,vo_format_name(preferred_outfmt)); | |
5075 | 120 |
5077 | 121 if(!video_out) return 1; // temp hack |
122 | |
5131
cff03e88d331
prefer outfmt with no conversion (see vo's query flags)
arpi
parents:
5077
diff
changeset
|
123 // check if libvo and codec has common outfmt (no conversion): |
cff03e88d331
prefer outfmt with no conversion (see vo's query flags)
arpi
parents:
5077
diff
changeset
|
124 j=-1; |
5075 | 125 for(i=0;i<CODECS_MAX_OUTFMT;i++){ |
126 out_fmt=sh->codec->outfmt[i]; | |
127 if(out_fmt==(signed int)0xFFFFFFFF) continue; | |
128 vo_flags=video_out->control(VOCTRL_QUERY_FORMAT, &out_fmt); | |
5131
cff03e88d331
prefer outfmt with no conversion (see vo's query flags)
arpi
parents:
5077
diff
changeset
|
129 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"vo_debug: query(%s) returned 0x%X (i=%d) \n",vo_format_name(out_fmt),vo_flags,i); |
5075 | 130 // TODO: check (query) if codec really support this outfmt... |
5131
cff03e88d331
prefer outfmt with no conversion (see vo's query flags)
arpi
parents:
5077
diff
changeset
|
131 if(vo_flags&2){j=i; break;} |
cff03e88d331
prefer outfmt with no conversion (see vo's query flags)
arpi
parents:
5077
diff
changeset
|
132 if(vo_flags && j<0) j=i; |
5075 | 133 } |
5131
cff03e88d331
prefer outfmt with no conversion (see vo's query flags)
arpi
parents:
5077
diff
changeset
|
134 if(j<0){ |
5075 | 135 // TODO: no match - we should use conversion... |
136 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_VOincompCodec); | |
137 return 0; // failed | |
138 } | |
5131
cff03e88d331
prefer outfmt with no conversion (see vo's query flags)
arpi
parents:
5077
diff
changeset
|
139 out_fmt=sh->codec->outfmt[j]; |
cff03e88d331
prefer outfmt with no conversion (see vo's query flags)
arpi
parents:
5077
diff
changeset
|
140 sh->outfmtidx=j; |
5075 | 141 |
142 // autodetect flipping | |
143 if(flip==-1){ | |
144 flip=0; | |
5131
cff03e88d331
prefer outfmt with no conversion (see vo's query flags)
arpi
parents:
5077
diff
changeset
|
145 if(sh->codec->outflags[j]&CODECS_FLAG_FLIP) |
cff03e88d331
prefer outfmt with no conversion (see vo's query flags)
arpi
parents:
5077
diff
changeset
|
146 if(!(sh->codec->outflags[j]&CODECS_FLAG_NOFLIP)) |
5075 | 147 flip=1; |
148 } | |
149 | |
150 // time to do aspect ratio corrections... | |
151 | |
152 if(movie_aspect>-1.0) sh->aspect = movie_aspect; // cmdline overrides autodetect | |
153 // if(!sh->aspect) sh->aspect=1.0; | |
154 screen_size_x = opt_screen_size_x; | |
155 screen_size_y = opt_screen_size_y; | |
156 if(screen_size_xy||screen_size_x||screen_size_y){ | |
157 if(screen_size_xy>0){ | |
158 if(screen_size_xy<=8){ | |
159 screen_size_x=screen_size_xy*sh->disp_w; | |
160 screen_size_y=screen_size_xy*sh->disp_h; | |
161 } else { | |
162 screen_size_x=screen_size_xy; | |
163 screen_size_y=screen_size_xy*sh->disp_h/sh->disp_w; | |
164 } | |
165 } else if(!vidmode){ | |
166 if(!screen_size_x) screen_size_x=SCREEN_SIZE_X; | |
167 if(!screen_size_y) screen_size_y=SCREEN_SIZE_Y; | |
168 if(screen_size_x<=8) screen_size_x*=sh->disp_w; | |
169 if(screen_size_y<=8) screen_size_y*=sh->disp_h; | |
170 } | |
171 } else { | |
172 // check source format aspect, calculate prescale ::atmos | |
173 screen_size_x=sh->disp_w; | |
174 screen_size_y=sh->disp_h; | |
175 if(sh->aspect>0.01){ | |
176 mp_msg(MSGT_CPLAYER,MSGL_INFO,"Movie-Aspect is %.2f:1 - prescaling to correct movie aspect.\n", | |
177 sh->aspect); | |
178 screen_size_x=(int)((float)sh->disp_h*sh->aspect); | |
179 screen_size_x+=screen_size_x%2; // round | |
180 if(screen_size_x<sh->disp_w){ | |
181 screen_size_x=sh->disp_w; | |
182 screen_size_y=(int)((float)sh->disp_w*(1.0/sh->aspect)); | |
183 screen_size_y+=screen_size_y%2; // round | |
184 } | |
185 } else { | |
186 mp_msg(MSGT_CPLAYER,MSGL_INFO,"Movie-Aspect is undefined - no prescaling applied.\n"); | |
187 } | |
188 } | |
189 | |
5172 | 190 if(video_out->get_info) |
5156
1c250c1da93c
libvo printfs added (moved from mplayer.c), mpi buffers free'd to fix multifile playback
arpi
parents:
5131
diff
changeset
|
191 { const vo_info_t *info = video_out->get_info(); |
1c250c1da93c
libvo printfs added (moved from mplayer.c), mpi buffers free'd to fix multifile playback
arpi
parents:
5131
diff
changeset
|
192 mp_msg(MSGT_CPLAYER,MSGL_INFO,"VO: [%s] %dx%d => %dx%d %s %s%s%s%s\n",info->short_name, |
1c250c1da93c
libvo printfs added (moved from mplayer.c), mpi buffers free'd to fix multifile playback
arpi
parents:
5131
diff
changeset
|
193 sh->disp_w,sh->disp_h, |
1c250c1da93c
libvo printfs added (moved from mplayer.c), mpi buffers free'd to fix multifile playback
arpi
parents:
5131
diff
changeset
|
194 screen_size_x,screen_size_y, |
1c250c1da93c
libvo printfs added (moved from mplayer.c), mpi buffers free'd to fix multifile playback
arpi
parents:
5131
diff
changeset
|
195 vo_format_name(out_fmt), |
1c250c1da93c
libvo printfs added (moved from mplayer.c), mpi buffers free'd to fix multifile playback
arpi
parents:
5131
diff
changeset
|
196 fullscreen?"fs ":"", |
1c250c1da93c
libvo printfs added (moved from mplayer.c), mpi buffers free'd to fix multifile playback
arpi
parents:
5131
diff
changeset
|
197 vidmode?"vm ":"", |
1c250c1da93c
libvo printfs added (moved from mplayer.c), mpi buffers free'd to fix multifile playback
arpi
parents:
5131
diff
changeset
|
198 softzoom?"zoom ":"", |
1c250c1da93c
libvo printfs added (moved from mplayer.c), mpi buffers free'd to fix multifile playback
arpi
parents:
5131
diff
changeset
|
199 (flip==1)?"flip ":""); |
1c250c1da93c
libvo printfs added (moved from mplayer.c), mpi buffers free'd to fix multifile playback
arpi
parents:
5131
diff
changeset
|
200 mp_msg(MSGT_CPLAYER,MSGL_V,"VO: Description: %s\n",info->name); |
1c250c1da93c
libvo printfs added (moved from mplayer.c), mpi buffers free'd to fix multifile playback
arpi
parents:
5131
diff
changeset
|
201 mp_msg(MSGT_CPLAYER,MSGL_V,"VO: Author: %s\n", info->author); |
1c250c1da93c
libvo printfs added (moved from mplayer.c), mpi buffers free'd to fix multifile playback
arpi
parents:
5131
diff
changeset
|
202 if(info->comment && strlen(info->comment) > 0) |
1c250c1da93c
libvo printfs added (moved from mplayer.c), mpi buffers free'd to fix multifile playback
arpi
parents:
5131
diff
changeset
|
203 mp_msg(MSGT_CPLAYER,MSGL_V,"VO: Comment: %s\n", info->comment); |
1c250c1da93c
libvo printfs added (moved from mplayer.c), mpi buffers free'd to fix multifile playback
arpi
parents:
5131
diff
changeset
|
204 } |
1c250c1da93c
libvo printfs added (moved from mplayer.c), mpi buffers free'd to fix multifile playback
arpi
parents:
5131
diff
changeset
|
205 |
5075 | 206 // Time to config libvo! |
207 mp_msg(MSGT_CPLAYER,MSGL_V,"video_out->init(%dx%d->%dx%d,flags=%d,'%s',0x%X)\n", | |
208 sh->disp_w,sh->disp_h, | |
209 screen_size_x,screen_size_y, | |
210 fullscreen|(vidmode<<1)|(softzoom<<2)|(flip<<3), | |
211 "MPlayer",out_fmt); | |
212 | |
5077 | 213 memset(&vtune,0,sizeof(vo_tune_info_t)); |
5075 | 214 if(video_out->config(sh->disp_w,sh->disp_h, |
215 screen_size_x,screen_size_y, | |
216 fullscreen|(vidmode<<1)|(softzoom<<2)|(flip<<3), | |
217 "MPlayer",out_fmt,&vtune)){ | |
218 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CannotInitVO); | |
219 return 0; // exit_player(MSGTR_Exit_error); | |
220 } | |
221 | |
5156
1c250c1da93c
libvo printfs added (moved from mplayer.c), mpi buffers free'd to fix multifile playback
arpi
parents:
5131
diff
changeset
|
222 #define FREE_MPI(mpi) if(mpi){if(mpi->flags&MP_IMGFLAG_ALLOCATED) free(mpi->planes[0]); free(mpi); mpi=NULL;} |
1c250c1da93c
libvo printfs added (moved from mplayer.c), mpi buffers free'd to fix multifile playback
arpi
parents:
5131
diff
changeset
|
223 FREE_MPI(static_images[0]) |
1c250c1da93c
libvo printfs added (moved from mplayer.c), mpi buffers free'd to fix multifile playback
arpi
parents:
5131
diff
changeset
|
224 FREE_MPI(static_images[1]) |
1c250c1da93c
libvo printfs added (moved from mplayer.c), mpi buffers free'd to fix multifile playback
arpi
parents:
5131
diff
changeset
|
225 FREE_MPI(temp_images[0]) |
1c250c1da93c
libvo printfs added (moved from mplayer.c), mpi buffers free'd to fix multifile playback
arpi
parents:
5131
diff
changeset
|
226 FREE_MPI(export_images[0]) |
1c250c1da93c
libvo printfs added (moved from mplayer.c), mpi buffers free'd to fix multifile playback
arpi
parents:
5131
diff
changeset
|
227 #undef FREE_MPI |
4878 | 228 return 1; |
229 } | |
230 | |
231 // mp_imgtype: buffering type, see mp_image.h | |
232 // mp_imgflag: buffer requirements (read/write, preserve, stride limits), see mp_image.h | |
233 // returns NULL or allocated mp_image_t* | |
234 // Note: buffer allocation may be moved to mpcodecs_config_vo() later... | |
235 mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h){ | |
236 mp_image_t* mpi=NULL; | |
4968 | 237 int w2=(mp_imgflag&MP_IMGFLAG_ACCEPT_STRIDE)?((w+15)&(~15)):w; |
4878 | 238 // Note: we should call libvo first to check if it supports direct rendering |
239 // and if not, then fallback to software buffers: | |
240 switch(mp_imgtype){ | |
241 case MP_IMGTYPE_EXPORT: | |
4951 | 242 // mpi=new_mp_image(w,h); |
4968 | 243 if(!export_images[0]) export_images[0]=new_mp_image(w2,h); |
4951 | 244 mpi=export_images[0]; |
4878 | 245 break; |
246 case MP_IMGTYPE_STATIC: | |
4968 | 247 if(!static_images[0]) static_images[0]=new_mp_image(w2,h); |
4878 | 248 mpi=static_images[0]; |
249 break; | |
250 case MP_IMGTYPE_TEMP: | |
4968 | 251 if(!temp_images[0]) temp_images[0]=new_mp_image(w2,h); |
4878 | 252 mpi=temp_images[0]; |
253 break; | |
254 case MP_IMGTYPE_IPB: | |
255 if(!(mp_imgflag&MP_IMGFLAG_READABLE)){ // B frame: | |
4968 | 256 if(!temp_images[0]) temp_images[0]=new_mp_image(w2,h); |
4878 | 257 mpi=temp_images[0]; |
258 break; | |
259 } | |
260 case MP_IMGTYPE_IP: | |
4968 | 261 if(!static_images[static_idx]) static_images[static_idx]=new_mp_image(w2,h); |
4878 | 262 mpi=static_images[static_idx]; |
263 static_idx^=1; | |
264 break; | |
265 } | |
266 if(mpi){ | |
267 mpi->type=mp_imgtype; | |
4971 | 268 mpi->flags&=~(MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE|MP_IMGFLAG_DIRECT); |
269 mpi->flags|=mp_imgflag&(MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE|MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_ACCEPT_WIDTH|MP_IMGFLAG_ALIGNED_STRIDE|MP_IMGFLAG_DRAW_CALLBACK); | |
4968 | 270 if((mpi->width!=w2 || mpi->height!=h) && !(mpi->flags&MP_IMGFLAG_DIRECT)){ |
271 mpi->width=w2; | |
4951 | 272 mpi->height=h; |
273 if(mpi->flags&MP_IMGFLAG_ALLOCATED){ | |
274 // need to re-allocate buffer memory: | |
275 free(mpi->planes[0]); | |
276 mpi->flags&=~MP_IMGFLAG_ALLOCATED; | |
277 } | |
278 } | |
4971 | 279 if(!mpi->bpp) mp_image_setfmt(mpi,sh->codec->outfmt[sh->outfmtidx]); |
280 if(!(mpi->flags&MP_IMGFLAG_ALLOCATED) && mpi->type>MP_IMGTYPE_EXPORT){ | |
281 | |
282 // check libvo first! | |
283 vo_functions_t* vo=sh->video_out; | |
4976 | 284 if(vo && vaa_use_dr) vo->control(VOCTRL_GET_IMAGE,mpi); |
4971 | 285 |
286 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ | |
4878 | 287 // non-direct and not yet allocaed image. allocate it! |
288 mpi->planes[0]=memalign(64, mpi->bpp*mpi->width*mpi->height/8); | |
289 if(mpi->flags&MP_IMGFLAG_PLANAR){ | |
290 // YV12/I420. feel free to add other planar formats here... | |
4899
c84d841ef43b
fixed stride for packed formats, more detailed printf at image allocation
arpi
parents:
4885
diff
changeset
|
291 if(!mpi->stride[0]) mpi->stride[0]=mpi->width; |
4878 | 292 if(!mpi->stride[1]) mpi->stride[1]=mpi->stride[2]=mpi->width/2; |
293 mpi->planes[1]=mpi->planes[0]+mpi->width*mpi->height; | |
294 mpi->planes[2]=mpi->planes[1]+mpi->width*mpi->height/4; | |
4899
c84d841ef43b
fixed stride for packed formats, more detailed printf at image allocation
arpi
parents:
4885
diff
changeset
|
295 } else { |
c84d841ef43b
fixed stride for packed formats, more detailed printf at image allocation
arpi
parents:
4885
diff
changeset
|
296 if(!mpi->stride[0]) mpi->stride[0]=mpi->width*mpi->bpp/8; |
4878 | 297 } |
298 mpi->flags|=MP_IMGFLAG_ALLOCATED; | |
4971 | 299 } |
300 if(!(mpi->flags&MP_IMGFLAG_TYPE_DISPLAYED)){ | |
301 mp_msg(MSGT_DECVIDEO,MSGL_INFO,"*** %s mp_image_t, %dx%dx%dbpp %s %s, %d bytes\n", | |
302 (mpi->flags&MP_IMGFLAG_DIRECT)?"Direct Rendering":"Allocating", | |
303 mpi->width,mpi->height,mpi->bpp, | |
304 (mpi->flags&MP_IMGFLAG_YUV)?"YUV":"RGB", | |
305 (mpi->flags&MP_IMGFLAG_PLANAR)?"planar":"packed", | |
306 mpi->bpp*mpi->width*mpi->height/8); | |
307 mpi->flags|=MP_IMGFLAG_TYPE_DISPLAYED; | |
308 } | |
309 | |
4878 | 310 } |
311 } | |
312 return mpi; | |
313 } | |
314 |