8 #include "vd_internal.h"
10 #include "loader/wine/driver.h"
11 #include "loader/wine/vfw.h"
13 static const vd_info_t info
= {
15 "Win32/VfWex video codecs",
18 "Win32/VfW video codecs",
33 BITMAPINFOHEADER
*o_bih
;
35 unsigned char *palette
;
38 static int vfw_set_postproc(sh_video_t
* sh
, int quality
)
40 vd_vfw_ctx
*priv
= sh
->context
;
41 // Works only with opendivx/divx4 based DLL
42 return ICSendMessage(priv
->handle
, ICM_USER
+80, (long)(&quality
), 0);
45 static void set_csp(BITMAPINFOHEADER
*o_bih
,unsigned int outfmt
){
89 mp_msg(MSGT_WIN32
,MSGL_ERR
,"Unsupported image format: %s\n", vo_format_name(outfmt
));
93 o_bih
->biSizeImage
= abs(o_bih
->biWidth
* o_bih
->biHeight
* (o_bih
->biBitCount
/8));
95 // Note: we cannot rely on sh->outfmtidx here, it's undefined at this stage!!!
96 // if (yuv && !(sh->codec->outflags[sh->outfmtidx] & CODECS_FLAG_YUVHACK))
98 o_bih
->biCompression
= outfmt
;
100 o_bih
->biCompression
= 0;
103 // to set/get/query special features/parameters
104 static int control(sh_video_t
*sh
,int cmd
,void* arg
,...){
105 vd_vfw_ctx
*priv
= sh
->context
;
107 case VDCTRL_QUERY_MAX_PP_LEVEL
:
109 case VDCTRL_SET_PP_LEVEL
:
110 vfw_set_postproc(sh
,10*(*((int*)arg
)));
113 // FIXME: make this optional...
114 case VDCTRL_QUERY_FORMAT
:
117 if(!(sh
->codec
->outflags
[sh
->outfmtidx
]&CODECS_FLAG_QUERY
))
118 return CONTROL_UNKNOWN
; // do not query!
119 set_csp(priv
->o_bih
,*((int*)arg
));
121 ret
= ICDecompressQueryEx(priv
->handle
, sh
->bih
, priv
->o_bih
);
123 ret
= ICDecompressQuery(priv
->handle
, sh
->bih
, priv
->o_bih
);
127 mp_msg(MSGT_WIN32
, MSGL_DBG2
, "ICDecompressQuery failed:: Error %d\n", (int)ret
);
128 return CONTROL_FALSE
;
134 return CONTROL_UNKNOWN
;
137 void print_video_header(BITMAPINFOHEADER
*h
, int verbose_level
);
140 static int init(sh_video_t
*sh
){
142 // unsigned int outfmt=sh->codec->outfmt[sh->outfmtidx];
146 /* Hack for VSSH codec: new dll can't decode old files
147 * In my samples old files have no extradata, so use that info
148 * to decide what dll should be used (here and in vd_dshow).
150 if (!strcmp(sh
->codec
->dll
, "vssh264.dll") && (sh
->bih
->biSize
> 40))
153 priv
= malloc(sizeof(vd_vfw_ctx
));
156 memset(priv
, 0, sizeof(vd_vfw_ctx
));
159 mp_msg(MSGT_WIN32
,MSGL_V
,"======= Win32 (VFW) VIDEO Codec init =======\n");
162 // win32_codec_name = sh->codec->dll;
163 // sh->hic = ICOpen( 0x63646976, sh->bih->biCompression, ICMODE_FASTDECOMPRESS);
164 // priv->handle = ICOpen( 0x63646976, sh->bih->biCompression, ICMODE_DECOMPRESS);
165 priv
->handle
= ICOpen( (long)(sh
->codec
->dll
), sh
->bih
->biCompression
, ICMODE_DECOMPRESS
);
167 mp_msg(MSGT_WIN32
,MSGL_ERR
,"ICOpen failed! unknown codec / wrong parameters?\n");
171 // sh->bih->biBitCount=32;
173 o_bih_len
= ICDecompressGetFormatSize(priv
->handle
, sh
->bih
);
175 if(o_bih_len
< sizeof(BITMAPINFOHEADER
)){
176 mp_msg(MSGT_WIN32
,MSGL_ERR
,"ICDecompressGetFormatSize returned a bogus value: %d\n", o_bih_len
);
180 priv
->o_bih
= malloc(o_bih_len
);
181 memset(priv
->o_bih
, 0, o_bih_len
);
183 mp_msg(MSGT_WIN32
,MSGL_V
,"ICDecompressGetFormatSize ret: %d\n", o_bih_len
);
185 ret
= ICDecompressGetFormat(priv
->handle
, sh
->bih
, priv
->o_bih
);
187 mp_msg(MSGT_WIN32
,MSGL_ERR
,"ICDecompressGetFormat failed: Error %d\n", (int)ret
);
188 for (i
=0; i
< o_bih_len
; i
++) mp_msg(MSGT_WIN32
, MSGL_DBG2
, "%02x ", priv
->o_bih
[i
]);
191 mp_msg(MSGT_WIN32
,MSGL_V
,"ICDecompressGetFormat OK\n");
194 // workaround for pegasus MJPEG:
195 if(!sh_video
->o_bih
.biWidth
) sh_video
->o_bih
.biWidth
=sh_video
->bih
->biWidth
;
196 if(!sh_video
->o_bih
.biHeight
) sh_video
->o_bih
.biHeight
=sh_video
->bih
->biHeight
;
197 if(!sh_video
->o_bih
.biPlanes
) sh_video
->o_bih
.biPlanes
=sh_video
->bih
->biPlanes
;
200 // ok let libvo and vd core to handshake and decide the optimal csp:
201 if(!mpcodecs_config_vo(sh
,sh
->disp_w
,sh
->disp_h
,IMGFMT_YUY2
)) return 0;
203 if (!(sh
->codec
->outflags
[sh
->outfmtidx
]&CODECS_FLAG_FLIP
)) {
204 priv
->o_bih
->biHeight
=-sh
->bih
->biHeight
; // flip image!
207 // ok, let's set the choosen colorspace:
208 set_csp(priv
->o_bih
,sh
->codec
->outfmt
[sh
->outfmtidx
]);
210 // fake it to RGB for broken DLLs (divx3)
211 if(sh
->codec
->outflags
[sh
->outfmtidx
] & CODECS_FLAG_YUVHACK
)
212 priv
->o_bih
->biCompression
= 0;
217 ret
= ICDecompressQueryEx(priv
->handle
, sh
->bih
, priv
->o_bih
);
219 ret
= ICDecompressQuery(priv
->handle
, sh
->bih
, priv
->o_bih
);
223 mp_msg(MSGT_WIN32
,MSGL_WARN
,"ICDecompressQuery failed: Error %d\n", (int)ret
);
226 mp_msg(MSGT_WIN32
,MSGL_V
,"ICDecompressQuery OK\n");
230 ret
= ICDecompressBeginEx(priv
->handle
, sh
->bih
, priv
->o_bih
);
232 ret
= ICDecompressBegin(priv
->handle
, sh
->bih
, priv
->o_bih
);
236 mp_msg(MSGT_WIN32
,MSGL_WARN
,"ICDecompressBegin failed: Error %d\n", (int)ret
);
240 // for broken codecs set it again:
241 if(sh
->codec
->outflags
[sh
->outfmtidx
] & CODECS_FLAG_YUVHACK
)
242 set_csp(priv
->o_bih
,sh
->codec
->outfmt
[sh
->outfmtidx
]);
244 mp_msg(MSGT_WIN32
, MSGL_V
, "Input format:\n");
245 if( mp_msg_test(MSGT_HEADER
,MSGL_V
) ) print_video_header(sh
->bih
,MSGL_V
);
246 mp_msg(MSGT_WIN32
, MSGL_V
, "Output format:\n");
247 if( mp_msg_test(MSGT_HEADER
,MSGL_V
) ) print_video_header(priv
->o_bih
,MSGL_V
);
249 // set postprocessing level in xvid/divx4 .dll
250 ICSendMessage(priv
->handle
, ICM_USER
+80, (long)(&divx_quality
), 0);
252 // don't do this palette mess always, it makes div3 dll crashing...
253 if(sh
->codec
->outfmt
[sh
->outfmtidx
]==IMGFMT_BGR8
){
254 if(ICDecompressGetPalette(priv
->handle
, sh
->bih
, priv
->o_bih
)){
255 priv
->palette
= (unsigned char*)(priv
->o_bih
+1);
256 mp_msg(MSGT_WIN32
,MSGL_V
,"ICDecompressGetPalette OK\n");
258 if(sh
->bih
->biSize
>=40+4*4)
259 priv
->palette
= (unsigned char*)(sh
->bih
+1);
263 mp_msg(MSGT_DECVIDEO
,MSGL_V
,"INFO: Win32 video codec init OK!\n");
268 static void uninit(sh_video_t
*sh
){
270 vd_vfw_ctx
*priv
= sh
->context
;
273 ret
= ICDecompressEndEx(priv
->handle
);
275 ret
= ICDecompressEnd(priv
->handle
);
279 mp_msg(MSGT_WIN32
, MSGL_WARN
, "ICDecompressEnd failed: %ld\n", ret
);
283 ret
= ICClose(priv
->handle
);
286 mp_msg(MSGT_WIN32
, MSGL_WARN
, "ICClose failed: %ld\n", ret
);
295 static mp_image_t
* decode(sh_video_t
*sh
,void* data
,int len
,int flags
){
296 vd_vfw_ctx
*priv
= sh
->context
;
300 if(len
<=0) return NULL
; // skipped frame
302 mpi
=mpcodecs_get_image(sh
,
303 (sh
->codec
->outflags
[sh
->outfmtidx
] & CODECS_FLAG_STATIC
) ?
304 MP_IMGTYPE_STATIC
: MP_IMGTYPE_TEMP
, MP_IMGFLAG_ACCEPT_WIDTH
,
305 sh
->disp_w
, sh
->disp_h
);
306 if(!mpi
){ // temporary!
307 mp_tmsg(MSGT_DECVIDEO
,MSGL_WARN
,"[VD_DMO] Couldn't allocate image for cinepak codec.\n");
311 // set stride: (trick discovered by Andreas Ackermann - thanx!)
312 sh
->bih
->biWidth
=mpi
->width
; //mpi->stride[0]/(mpi->bpp/8);
313 priv
->o_bih
->biWidth
=mpi
->width
; //mpi->stride[0]/(mpi->bpp/8);
315 sh
->bih
->biSizeImage
= len
;
318 ret
= ICDecompressEx(priv
->handle
,
320 ret
= ICDecompress(priv
->handle
,
322 ( (sh
->ds
->flags
&1) ? 0 : ICDECOMPRESS_NOTKEYFRAME
) |
323 ( ((flags
&3)==2 && !(sh
->ds
->flags
&1))?(ICDECOMPRESS_HURRYUP
|ICDECOMPRESS_PREROL
):0 ),
324 sh
->bih
, data
, priv
->o_bih
, (flags
&3) ? 0 : mpi
->planes
[0]);
327 mp_msg(MSGT_DECVIDEO
,MSGL_WARN
,"Error decompressing frame, err=%ld\n",ret
);
332 if(mpi
->imgfmt
==IMGFMT_RGB8
|| mpi
->imgfmt
==IMGFMT_BGR8
){
335 mpi
->planes
[1] = priv
->palette
;
336 mpi
->flags
|= MP_IMGFLAG_RGB_PALETTE
;
337 mp_dbg(MSGT_DECVIDEO
, MSGL_DBG2
, "Found and copied palette\n");