Mercurial > mplayer.hg
annotate libmpcodecs/vd.c @ 5101:870ba1ffdbf9
added mp_gettext macro for i18n
author | alex |
---|---|
date | Fri, 15 Mar 2002 21:07:48 +0000 |
parents | 2000ba19b606 |
children | cff03e88d331 |
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 | |
4878 | 106 int mpcodecs_config_vo(sh_video_t *sh, int w, int h, unsigned int preferred_outfmt){ |
5075 | 107 int i; |
108 unsigned int out_fmt=0; | |
109 int screen_size_x=0;//SCREEN_SIZE_X; | |
110 int screen_size_y=0;//SCREEN_SIZE_Y; | |
111 vo_functions_t* video_out=sh->video_out; | |
112 | |
5004 | 113 mp_msg(MSGT_DECVIDEO,MSGL_INFO,"VDec: vo config request - %d x %d, %s \n", |
114 w,h,vo_format_name(preferred_outfmt)); | |
5075 | 115 |
5077 | 116 if(!video_out) return 1; // temp hack |
117 | |
5075 | 118 // check if libvo and codec has common outfmt: |
119 for(i=0;i<CODECS_MAX_OUTFMT;i++){ | |
120 out_fmt=sh->codec->outfmt[i]; | |
121 if(out_fmt==(signed int)0xFFFFFFFF) continue; | |
122 vo_flags=video_out->control(VOCTRL_QUERY_FORMAT, &out_fmt); | |
123 mp_msg(MSGT_CPLAYER,MSGL_DBG2,"vo_debug: query(%s) returned 0x%X\n",vo_format_name(out_fmt),vo_flags); | |
124 // TODO: check (query) if codec really support this outfmt... | |
125 if(vo_flags) break; | |
126 } | |
127 if(i>=CODECS_MAX_OUTFMT){ | |
128 // TODO: no match - we should use conversion... | |
129 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_VOincompCodec); | |
130 return 0; // failed | |
131 } | |
132 sh->outfmtidx=i; | |
133 | |
134 // autodetect flipping | |
135 if(flip==-1){ | |
136 flip=0; | |
137 if(sh->codec->outflags[i]&CODECS_FLAG_FLIP) | |
138 if(!(sh->codec->outflags[i]&CODECS_FLAG_NOFLIP)) | |
139 flip=1; | |
140 } | |
141 | |
142 // time to do aspect ratio corrections... | |
143 | |
144 if(movie_aspect>-1.0) sh->aspect = movie_aspect; // cmdline overrides autodetect | |
145 // if(!sh->aspect) sh->aspect=1.0; | |
146 screen_size_x = opt_screen_size_x; | |
147 screen_size_y = opt_screen_size_y; | |
148 if(screen_size_xy||screen_size_x||screen_size_y){ | |
149 if(screen_size_xy>0){ | |
150 if(screen_size_xy<=8){ | |
151 screen_size_x=screen_size_xy*sh->disp_w; | |
152 screen_size_y=screen_size_xy*sh->disp_h; | |
153 } else { | |
154 screen_size_x=screen_size_xy; | |
155 screen_size_y=screen_size_xy*sh->disp_h/sh->disp_w; | |
156 } | |
157 } else if(!vidmode){ | |
158 if(!screen_size_x) screen_size_x=SCREEN_SIZE_X; | |
159 if(!screen_size_y) screen_size_y=SCREEN_SIZE_Y; | |
160 if(screen_size_x<=8) screen_size_x*=sh->disp_w; | |
161 if(screen_size_y<=8) screen_size_y*=sh->disp_h; | |
162 } | |
163 } else { | |
164 // check source format aspect, calculate prescale ::atmos | |
165 screen_size_x=sh->disp_w; | |
166 screen_size_y=sh->disp_h; | |
167 if(sh->aspect>0.01){ | |
168 mp_msg(MSGT_CPLAYER,MSGL_INFO,"Movie-Aspect is %.2f:1 - prescaling to correct movie aspect.\n", | |
169 sh->aspect); | |
170 screen_size_x=(int)((float)sh->disp_h*sh->aspect); | |
171 screen_size_x+=screen_size_x%2; // round | |
172 if(screen_size_x<sh->disp_w){ | |
173 screen_size_x=sh->disp_w; | |
174 screen_size_y=(int)((float)sh->disp_w*(1.0/sh->aspect)); | |
175 screen_size_y+=screen_size_y%2; // round | |
176 } | |
177 } else { | |
178 mp_msg(MSGT_CPLAYER,MSGL_INFO,"Movie-Aspect is undefined - no prescaling applied.\n"); | |
179 } | |
180 } | |
181 | |
182 // Time to config libvo! | |
183 mp_msg(MSGT_CPLAYER,MSGL_V,"video_out->init(%dx%d->%dx%d,flags=%d,'%s',0x%X)\n", | |
184 sh->disp_w,sh->disp_h, | |
185 screen_size_x,screen_size_y, | |
186 fullscreen|(vidmode<<1)|(softzoom<<2)|(flip<<3), | |
187 "MPlayer",out_fmt); | |
188 | |
5077 | 189 memset(&vtune,0,sizeof(vo_tune_info_t)); |
5075 | 190 if(video_out->config(sh->disp_w,sh->disp_h, |
191 screen_size_x,screen_size_y, | |
192 fullscreen|(vidmode<<1)|(softzoom<<2)|(flip<<3), | |
193 "MPlayer",out_fmt,&vtune)){ | |
194 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_CannotInitVO); | |
195 return 0; // exit_player(MSGTR_Exit_error); | |
196 } | |
197 | |
4878 | 198 return 1; |
199 } | |
200 | |
201 static mp_image_t* static_images[2]; | |
202 static mp_image_t* temp_images[1]; | |
4951 | 203 static mp_image_t* export_images[1]; |
4878 | 204 static int static_idx=0; |
205 | |
206 // mp_imgtype: buffering type, see mp_image.h | |
207 // mp_imgflag: buffer requirements (read/write, preserve, stride limits), see mp_image.h | |
208 // returns NULL or allocated mp_image_t* | |
209 // Note: buffer allocation may be moved to mpcodecs_config_vo() later... | |
210 mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h){ | |
211 mp_image_t* mpi=NULL; | |
4968 | 212 int w2=(mp_imgflag&MP_IMGFLAG_ACCEPT_STRIDE)?((w+15)&(~15)):w; |
4878 | 213 // Note: we should call libvo first to check if it supports direct rendering |
214 // and if not, then fallback to software buffers: | |
215 switch(mp_imgtype){ | |
216 case MP_IMGTYPE_EXPORT: | |
4951 | 217 // mpi=new_mp_image(w,h); |
4968 | 218 if(!export_images[0]) export_images[0]=new_mp_image(w2,h); |
4951 | 219 mpi=export_images[0]; |
4878 | 220 break; |
221 case MP_IMGTYPE_STATIC: | |
4968 | 222 if(!static_images[0]) static_images[0]=new_mp_image(w2,h); |
4878 | 223 mpi=static_images[0]; |
224 break; | |
225 case MP_IMGTYPE_TEMP: | |
4968 | 226 if(!temp_images[0]) temp_images[0]=new_mp_image(w2,h); |
4878 | 227 mpi=temp_images[0]; |
228 break; | |
229 case MP_IMGTYPE_IPB: | |
230 if(!(mp_imgflag&MP_IMGFLAG_READABLE)){ // B frame: | |
4968 | 231 if(!temp_images[0]) temp_images[0]=new_mp_image(w2,h); |
4878 | 232 mpi=temp_images[0]; |
233 break; | |
234 } | |
235 case MP_IMGTYPE_IP: | |
4968 | 236 if(!static_images[static_idx]) static_images[static_idx]=new_mp_image(w2,h); |
4878 | 237 mpi=static_images[static_idx]; |
238 static_idx^=1; | |
239 break; | |
240 } | |
241 if(mpi){ | |
242 mpi->type=mp_imgtype; | |
4971 | 243 mpi->flags&=~(MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE|MP_IMGFLAG_DIRECT); |
244 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 | 245 if((mpi->width!=w2 || mpi->height!=h) && !(mpi->flags&MP_IMGFLAG_DIRECT)){ |
246 mpi->width=w2; | |
4951 | 247 mpi->height=h; |
248 if(mpi->flags&MP_IMGFLAG_ALLOCATED){ | |
249 // need to re-allocate buffer memory: | |
250 free(mpi->planes[0]); | |
251 mpi->flags&=~MP_IMGFLAG_ALLOCATED; | |
252 } | |
253 } | |
4971 | 254 if(!mpi->bpp) mp_image_setfmt(mpi,sh->codec->outfmt[sh->outfmtidx]); |
255 if(!(mpi->flags&MP_IMGFLAG_ALLOCATED) && mpi->type>MP_IMGTYPE_EXPORT){ | |
256 | |
257 // check libvo first! | |
258 vo_functions_t* vo=sh->video_out; | |
4976 | 259 if(vo && vaa_use_dr) vo->control(VOCTRL_GET_IMAGE,mpi); |
4971 | 260 |
261 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ | |
4878 | 262 // non-direct and not yet allocaed image. allocate it! |
263 mpi->planes[0]=memalign(64, mpi->bpp*mpi->width*mpi->height/8); | |
264 if(mpi->flags&MP_IMGFLAG_PLANAR){ | |
265 // 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
|
266 if(!mpi->stride[0]) mpi->stride[0]=mpi->width; |
4878 | 267 if(!mpi->stride[1]) mpi->stride[1]=mpi->stride[2]=mpi->width/2; |
268 mpi->planes[1]=mpi->planes[0]+mpi->width*mpi->height; | |
269 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
|
270 } else { |
c84d841ef43b
fixed stride for packed formats, more detailed printf at image allocation
arpi
parents:
4885
diff
changeset
|
271 if(!mpi->stride[0]) mpi->stride[0]=mpi->width*mpi->bpp/8; |
4878 | 272 } |
273 mpi->flags|=MP_IMGFLAG_ALLOCATED; | |
4971 | 274 } |
275 if(!(mpi->flags&MP_IMGFLAG_TYPE_DISPLAYED)){ | |
276 mp_msg(MSGT_DECVIDEO,MSGL_INFO,"*** %s mp_image_t, %dx%dx%dbpp %s %s, %d bytes\n", | |
277 (mpi->flags&MP_IMGFLAG_DIRECT)?"Direct Rendering":"Allocating", | |
278 mpi->width,mpi->height,mpi->bpp, | |
279 (mpi->flags&MP_IMGFLAG_YUV)?"YUV":"RGB", | |
280 (mpi->flags&MP_IMGFLAG_PLANAR)?"planar":"packed", | |
281 mpi->bpp*mpi->width*mpi->height/8); | |
282 mpi->flags|=MP_IMGFLAG_TYPE_DISPLAYED; | |
283 } | |
284 | |
4878 | 285 } |
286 } | |
287 return mpi; | |
288 } | |
289 |