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