10 #include "vd_internal.h"
12 #include "wine/driver.h"
15 static vd_info_t info
= {
17 "Win32/VfWex video codecs",
20 "Win32/VfW video codecs",
35 BITMAPINFOHEADER
*o_bih
;
37 unsigned char *palette
;
40 extern int divx_quality
;
42 static int vfw_set_postproc(sh_video_t
* sh
, int quality
)
44 vd_vfw_ctx
*priv
= sh
->context
;
45 // Works only with opendivx/divx4 based DLL
46 return ICSendMessage(priv
->handle
, ICM_USER
+80, (long)(&quality
), 0);
49 static void set_csp(BITMAPINFOHEADER
*o_bih
,unsigned int outfmt
){
93 mp_msg(MSGT_WIN32
,MSGL_ERR
,"Unsupported image format: %s\n", vo_format_name(outfmt
));
97 o_bih
->biSizeImage
= abs(o_bih
->biWidth
* o_bih
->biHeight
* (o_bih
->biBitCount
/8));
99 // Note: we cannot rely on sh->outfmtidx here, it's undefined at this stage!!!
100 // if (yuv && !(sh->codec->outflags[sh->outfmtidx] & CODECS_FLAG_YUVHACK))
102 o_bih
->biCompression
= outfmt
;
104 o_bih
->biCompression
= 0;
107 // to set/get/query special features/parameters
108 static int control(sh_video_t
*sh
,int cmd
,void* arg
,...){
109 vd_vfw_ctx
*priv
= sh
->context
;
111 case VDCTRL_QUERY_MAX_PP_LEVEL
:
113 case VDCTRL_SET_PP_LEVEL
:
114 vfw_set_postproc(sh
,10*(*((int*)arg
)));
117 // FIXME: make this optional...
118 case VDCTRL_QUERY_FORMAT
:
121 if(!(sh
->codec
->outflags
[sh
->outfmtidx
]&CODECS_FLAG_QUERY
))
122 return CONTROL_UNKNOWN
; // do not query!
123 set_csp(priv
->o_bih
,*((int*)arg
));
125 ret
= ICDecompressQueryEx(priv
->handle
, sh
->bih
, priv
->o_bih
);
127 ret
= ICDecompressQuery(priv
->handle
, sh
->bih
, priv
->o_bih
);
131 mp_msg(MSGT_WIN32
, MSGL_DBG2
, "ICDecompressQuery failed:: Error %d\n", (int)ret
);
132 return CONTROL_FALSE
;
138 return CONTROL_UNKNOWN
;
141 extern void print_video_header(BITMAPINFOHEADER
*h
, int verbose_level
);
144 static int init(sh_video_t
*sh
){
146 // unsigned int outfmt=sh->codec->outfmt[sh->outfmtidx];
150 /* Hack for VSSH codec: new dll can't decode old files
151 * In my samples old files have no extradata, so use that info
152 * to decide what dll should be used (here and in vd_dshow).
154 if (!strcmp(sh
->codec
->dll
, "vssh264.dll") && (sh
->bih
->biSize
> 40))
157 priv
= malloc(sizeof(vd_vfw_ctx
));
160 memset(priv
, 0, sizeof(vd_vfw_ctx
));
163 mp_msg(MSGT_WIN32
,MSGL_V
,"======= Win32 (VFW) VIDEO Codec init =======\n");
166 // win32_codec_name = sh->codec->dll;
167 // sh->hic = ICOpen( 0x63646976, sh->bih->biCompression, ICMODE_FASTDECOMPRESS);
168 // priv->handle = ICOpen( 0x63646976, sh->bih->biCompression, ICMODE_DECOMPRESS);
169 priv
->handle
= ICOpen( (long)(sh
->codec
->dll
), sh
->bih
->biCompression
, ICMODE_DECOMPRESS
);
171 mp_msg(MSGT_WIN32
,MSGL_ERR
,"ICOpen failed! unknown codec / wrong parameters?\n");
175 // sh->bih->biBitCount=32;
177 o_bih_len
= ICDecompressGetFormatSize(priv
->handle
, sh
->bih
);
179 priv
->o_bih
= malloc(o_bih_len
);
180 memset(priv
->o_bih
, 0, o_bih_len
);
182 mp_msg(MSGT_WIN32
,MSGL_V
,"ICDecompressGetFormatSize ret: %d\n", o_bih_len
);
184 ret
= ICDecompressGetFormat(priv
->handle
, sh
->bih
, priv
->o_bih
);
186 mp_msg(MSGT_WIN32
,MSGL_ERR
,"ICDecompressGetFormat failed: Error %d\n", (int)ret
);
187 for (i
=0; i
< o_bih_len
; i
++) mp_msg(MSGT_WIN32
, MSGL_DBG2
, "%02x ", priv
->o_bih
[i
]);
190 mp_msg(MSGT_WIN32
,MSGL_V
,"ICDecompressGetFormat OK\n");
193 // workaround for pegasus MJPEG:
194 if(!sh_video
->o_bih
.biWidth
) sh_video
->o_bih
.biWidth
=sh_video
->bih
->biWidth
;
195 if(!sh_video
->o_bih
.biHeight
) sh_video
->o_bih
.biHeight
=sh_video
->bih
->biHeight
;
196 if(!sh_video
->o_bih
.biPlanes
) sh_video
->o_bih
.biPlanes
=sh_video
->bih
->biPlanes
;
199 // ok let libvo and vd core to handshake and decide the optimal csp:
200 if(!mpcodecs_config_vo(sh
,sh
->disp_w
,sh
->disp_h
,IMGFMT_YUY2
)) return 0;
202 if (!(sh
->codec
->outflags
[sh
->outfmtidx
]&CODECS_FLAG_FLIP
)) {
203 priv
->o_bih
->biHeight
=-sh
->bih
->biHeight
; // flip image!
206 // ok, let's set the choosen colorspace:
207 set_csp(priv
->o_bih
,sh
->codec
->outfmt
[sh
->outfmtidx
]);
209 // fake it to RGB for broken DLLs (divx3)
210 if(sh
->codec
->outflags
[sh
->outfmtidx
] & CODECS_FLAG_YUVHACK
)
211 priv
->o_bih
->biCompression
= 0;
216 ret
= ICDecompressQueryEx(priv
->handle
, sh
->bih
, priv
->o_bih
);
218 ret
= ICDecompressQuery(priv
->handle
, sh
->bih
, priv
->o_bih
);
222 mp_msg(MSGT_WIN32
,MSGL_WARN
,"ICDecompressQuery failed: Error %d\n", (int)ret
);
225 mp_msg(MSGT_WIN32
,MSGL_V
,"ICDecompressQuery OK\n");
229 ret
= ICDecompressBeginEx(priv
->handle
, sh
->bih
, priv
->o_bih
);
231 ret
= ICDecompressBegin(priv
->handle
, sh
->bih
, priv
->o_bih
);
235 mp_msg(MSGT_WIN32
,MSGL_WARN
,"ICDecompressBegin failed: Error %d\n", (int)ret
);
239 // for broken codecs set it again:
240 if(sh
->codec
->outflags
[sh
->outfmtidx
] & CODECS_FLAG_YUVHACK
)
241 set_csp(priv
->o_bih
,sh
->codec
->outfmt
[sh
->outfmtidx
]);
243 mp_msg(MSGT_WIN32
, MSGL_V
, "Input format:\n");
244 if( mp_msg_test(MSGT_HEADER
,MSGL_V
) ) print_video_header(sh
->bih
,MSGL_V
);
245 mp_msg(MSGT_WIN32
, MSGL_V
, "Output format:\n");
246 if( mp_msg_test(MSGT_HEADER
,MSGL_V
) ) print_video_header(priv
->o_bih
,MSGL_V
);
248 // set postprocessing level in xvid/divx4 .dll
249 ICSendMessage(priv
->handle
, ICM_USER
+80, (long)(&divx_quality
), 0);
251 // don't do this palette mess always, it makes div3 dll crashing...
252 if(sh
->codec
->outfmt
[sh
->outfmtidx
]==IMGFMT_BGR8
){
253 if(ICDecompressGetPalette(priv
->handle
, sh
->bih
, priv
->o_bih
)){
254 priv
->palette
= (unsigned char*)(priv
->o_bih
+1);
255 mp_msg(MSGT_WIN32
,MSGL_V
,"ICDecompressGetPalette OK\n");
257 if(sh
->bih
->biSize
>=40+4*4)
258 priv
->palette
= (unsigned char*)(sh
->bih
+1);
262 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"INFO: Win32 video codec init OK!\n");
267 static void uninit(sh_video_t
*sh
){
269 vd_vfw_ctx
*priv
= sh
->context
;
272 ret
= ICDecompressEndEx(priv
->handle
);
274 ret
= ICDecompressEnd(priv
->handle
);
278 mp_msg(MSGT_WIN32
, MSGL_WARN
, "ICDecompressEnd failed: %ld\n", ret
);
282 ret
= ICClose(priv
->handle
);
285 mp_msg(MSGT_WIN32
, MSGL_WARN
, "ICClose failed: %ld\n", ret
);
294 static mp_image_t
* decode(sh_video_t
*sh
,void* data
,int len
,int flags
){
295 vd_vfw_ctx
*priv
= sh
->context
;
299 if(len
<=0) return NULL
; // skipped frame
301 mpi
=mpcodecs_get_image(sh
,
302 (sh
->codec
->outflags
[sh
->outfmtidx
] & CODECS_FLAG_STATIC
) ?
303 MP_IMGTYPE_STATIC
: MP_IMGTYPE_TEMP
, MP_IMGFLAG_ACCEPT_WIDTH
,
304 sh
->disp_w
, sh
->disp_h
);
305 if(!mpi
){ // temporary!
306 mp_msg(MSGT_DECVIDEO
,MSGL_WARN
,MSGTR_MPCODECS_CouldntAllocateImageForCinepakCodec
);
310 // set stride: (trick discovered by Andreas Ackermann - thanx!)
311 sh
->bih
->biWidth
=mpi
->width
; //mpi->stride[0]/(mpi->bpp/8);
312 priv
->o_bih
->biWidth
=mpi
->width
; //mpi->stride[0]/(mpi->bpp/8);
314 sh
->bih
->biSizeImage
= len
;
317 ret
= ICDecompressEx(priv
->handle
,
319 ret
= ICDecompress(priv
->handle
,
321 ( (sh
->ds
->flags
&1) ? 0 : ICDECOMPRESS_NOTKEYFRAME
) |
322 ( ((flags
&3)==2 && !(sh
->ds
->flags
&1))?(ICDECOMPRESS_HURRYUP
|ICDECOMPRESS_PREROL
):0 ),
323 sh
->bih
, data
, priv
->o_bih
, (flags
&3) ? 0 : mpi
->planes
[0]);
326 mp_msg(MSGT_DECVIDEO
,MSGL_WARN
,"Error decompressing frame, err=%ld\n",ret
);
331 if(mpi
->imgfmt
==IMGFMT_RGB8
|| mpi
->imgfmt
==IMGFMT_BGR8
){
334 mpi
->planes
[1] = priv
->palette
;
335 mpi
->flags
|= MP_IMGFLAG_RGB_PALETTE
;
336 mp_dbg(MSGT_DECVIDEO
, MSGL_DBG2
, "Found and copied palette\n");