2
* This file is part of MPlayer.
4
* MPlayer is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* MPlayer is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License along
15
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
16
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25
#include "vd_internal.h"
26
#include "libmpdemux/aviprint.h"
27
#include "loader/wine/driver.h"
28
#include "loader/wine/vfw.h"
30
static const vd_info_t info = {
32
"Win32/VfWex video codecs",
35
"Win32/VfW video codecs",
50
BITMAPINFOHEADER *o_bih;
52
unsigned char *palette;
55
static int vfw_set_postproc(sh_video_t* sh, int quality)
57
vd_vfw_ctx *priv = sh->context;
58
// Works only with opendivx/divx4 based DLL
59
return ICSendMessage(priv->handle, ICM_USER+80, (long)(&quality), 0);
62
static void set_csp(BITMAPINFOHEADER *o_bih,unsigned int outfmt){
103
o_bih->biBitCount=32;
106
mp_msg(MSGT_WIN32,MSGL_ERR,"Unsupported image format: %s\n", vo_format_name(outfmt));
110
o_bih->biSizeImage = abs(o_bih->biWidth * o_bih->biHeight * (o_bih->biBitCount/8));
112
// Note: we cannot rely on sh->outfmtidx here, it's undefined at this stage!!!
113
// if (yuv && !(sh->codec->outflags[sh->outfmtidx] & CODECS_FLAG_YUVHACK))
115
o_bih->biCompression = outfmt;
117
o_bih->biCompression = 0;
120
// to set/get/query special features/parameters
121
static int control(sh_video_t *sh,int cmd,void* arg,...){
122
vd_vfw_ctx *priv = sh->context;
124
case VDCTRL_QUERY_MAX_PP_LEVEL:
126
case VDCTRL_SET_PP_LEVEL:
127
vfw_set_postproc(sh,10*(*((int*)arg)));
129
// FIXME: make this optional...
130
case VDCTRL_QUERY_FORMAT:
133
if(!(sh->codec->outflags[sh->outfmtidx]&CODECS_FLAG_QUERY))
134
return CONTROL_UNKNOWN; // do not query!
135
set_csp(priv->o_bih,*((int*)arg));
137
ret = ICDecompressQueryEx(priv->handle, sh->bih, priv->o_bih);
139
ret = ICDecompressQuery(priv->handle, sh->bih, priv->o_bih);
143
mp_msg(MSGT_WIN32, MSGL_DBG2, "ICDecompressQuery failed:: Error %d\n", (int)ret);
144
return CONTROL_FALSE;
149
return CONTROL_UNKNOWN;
153
static int init(sh_video_t *sh){
155
// unsigned int outfmt=sh->codec->outfmt[sh->outfmtidx];
159
/* Hack for VSSH codec: new dll can't decode old files
160
* In my samples old files have no extradata, so use that info
161
* to decide what dll should be used (here and in vd_dshow).
163
if (!strcmp(sh->codec->dll, "vssh264.dll") && (sh->bih->biSize > 40))
166
priv = malloc(sizeof(vd_vfw_ctx));
169
memset(priv, 0, sizeof(vd_vfw_ctx));
172
mp_msg(MSGT_WIN32,MSGL_V,"======= Win32 (VFW) VIDEO Codec init =======\n");
175
// win32_codec_name = sh->codec->dll;
176
// sh->hic = ICOpen( 0x63646976, sh->bih->biCompression, ICMODE_FASTDECOMPRESS);
177
// priv->handle = ICOpen( 0x63646976, sh->bih->biCompression, ICMODE_DECOMPRESS);
178
priv->handle = ICOpen( (long)(sh->codec->dll), sh->bih->biCompression, ICMODE_DECOMPRESS);
180
mp_msg(MSGT_WIN32,MSGL_ERR,"ICOpen failed! unknown codec / wrong parameters?\n");
184
// sh->bih->biBitCount=32;
186
o_bih_len = ICDecompressGetFormatSize(priv->handle, sh->bih);
188
if(o_bih_len < sizeof(BITMAPINFOHEADER)){
189
mp_msg(MSGT_WIN32,MSGL_ERR,"ICDecompressGetFormatSize returned a bogus value: %d\n", o_bih_len);
193
priv->o_bih = malloc(o_bih_len);
194
memset(priv->o_bih, 0, o_bih_len);
196
mp_msg(MSGT_WIN32,MSGL_V,"ICDecompressGetFormatSize ret: %d\n", o_bih_len);
198
ret = ICDecompressGetFormat(priv->handle, sh->bih, priv->o_bih);
200
mp_msg(MSGT_WIN32,MSGL_ERR,"ICDecompressGetFormat failed: Error %d\n", (int)ret);
201
for (i=0; i < o_bih_len; i++) mp_msg(MSGT_WIN32, MSGL_DBG2, "%02x ", priv->o_bih[i]);
204
mp_msg(MSGT_WIN32,MSGL_V,"ICDecompressGetFormat OK\n");
207
// workaround for pegasus MJPEG:
208
if(!sh_video->o_bih.biWidth) sh_video->o_bih.biWidth=sh_video->bih->biWidth;
209
if(!sh_video->o_bih.biHeight) sh_video->o_bih.biHeight=sh_video->bih->biHeight;
210
if(!sh_video->o_bih.biPlanes) sh_video->o_bih.biPlanes=sh_video->bih->biPlanes;
213
// ok let libvo and vd core to handshake and decide the optimal csp:
214
if(!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YUY2)) return 0;
216
if (!(sh->codec->outflags[sh->outfmtidx]&CODECS_FLAG_FLIP)) {
217
priv->o_bih->biHeight=-sh->bih->biHeight; // flip image!
220
// ok, let's set the choosen colorspace:
221
set_csp(priv->o_bih,sh->codec->outfmt[sh->outfmtidx]);
223
// fake it to RGB for broken DLLs (divx3)
224
if(sh->codec->outflags[sh->outfmtidx] & CODECS_FLAG_YUVHACK)
225
priv->o_bih->biCompression = 0;
229
ret = ICDecompressQueryEx(priv->handle, sh->bih, priv->o_bih);
231
ret = ICDecompressQuery(priv->handle, sh->bih, priv->o_bih);
235
mp_msg(MSGT_WIN32,MSGL_WARN,"ICDecompressQuery failed: Error %d\n", (int)ret);
238
mp_msg(MSGT_WIN32,MSGL_V,"ICDecompressQuery OK\n");
241
ret = ICDecompressBeginEx(priv->handle, sh->bih, priv->o_bih);
243
ret = ICDecompressBegin(priv->handle, sh->bih, priv->o_bih);
247
mp_msg(MSGT_WIN32,MSGL_WARN,"ICDecompressBegin failed: Error %d\n", (int)ret);
251
// for broken codecs set it again:
252
if(sh->codec->outflags[sh->outfmtidx] & CODECS_FLAG_YUVHACK)
253
set_csp(priv->o_bih,sh->codec->outfmt[sh->outfmtidx]);
255
mp_msg(MSGT_WIN32, MSGL_V, "Input format:\n");
256
if( mp_msg_test(MSGT_HEADER,MSGL_V) ) print_video_header(sh->bih,MSGL_V);
257
mp_msg(MSGT_WIN32, MSGL_V, "Output format:\n");
258
if( mp_msg_test(MSGT_HEADER,MSGL_V) ) print_video_header(priv->o_bih,MSGL_V);
260
// set postprocessing level in xvid/divx4 .dll
261
ICSendMessage(priv->handle, ICM_USER+80, (long)(&divx_quality), 0);
263
// don't do this palette mess always, it makes div3 dll crashing...
264
if(sh->codec->outfmt[sh->outfmtidx]==IMGFMT_BGR8){
265
if(ICDecompressGetPalette(priv->handle, sh->bih, priv->o_bih)){
266
priv->palette = (unsigned char*)(priv->o_bih+1);
267
mp_msg(MSGT_WIN32,MSGL_V,"ICDecompressGetPalette OK\n");
269
if(sh->bih->biSize>=40+4*4)
270
priv->palette = (unsigned char*)(sh->bih+1);
274
mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: Win32 video codec init OK!\n");
279
static void uninit(sh_video_t *sh){
281
vd_vfw_ctx *priv = sh->context;
284
ret = ICDecompressEndEx(priv->handle);
286
ret = ICDecompressEnd(priv->handle);
290
mp_msg(MSGT_WIN32, MSGL_WARN, "ICDecompressEnd failed: %ld\n", ret);
294
ret = ICClose(priv->handle);
297
mp_msg(MSGT_WIN32, MSGL_WARN, "ICClose failed: %ld\n", ret);
306
static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
307
vd_vfw_ctx *priv = sh->context;
311
if(len<=0) return NULL; // skipped frame
313
mpi=mpcodecs_get_image(sh,
314
(sh->codec->outflags[sh->outfmtidx] & CODECS_FLAG_STATIC) ?
315
MP_IMGTYPE_STATIC : MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_WIDTH,
316
sh->disp_w, sh->disp_h);
317
if(!mpi){ // temporary!
318
mp_tmsg(MSGT_DECVIDEO,MSGL_WARN,"[VD_DMO] Couldn't allocate image for cinepak codec.\n");
322
// set stride: (trick discovered by Andreas Ackermann - thanx!)
323
sh->bih->biWidth=mpi->width; //mpi->stride[0]/(mpi->bpp/8);
324
priv->o_bih->biWidth=mpi->width; //mpi->stride[0]/(mpi->bpp/8);
326
sh->bih->biSizeImage = len;
329
ret = ICDecompressEx(priv->handle,
331
ret = ICDecompress(priv->handle,
333
( (sh->ds->flags&1) ? 0 : ICDECOMPRESS_NOTKEYFRAME ) |
334
( ((flags&3)==2 && !(sh->ds->flags&1))?(ICDECOMPRESS_HURRYUP|ICDECOMPRESS_PREROL):0 ),
335
sh->bih, data, priv->o_bih, (flags&3) ? 0 : mpi->planes[0]);
338
mp_msg(MSGT_DECVIDEO,MSGL_WARN,"Error decompressing frame, err=%ld\n",ret);
343
if(mpi->imgfmt==IMGFMT_RGB8 || mpi->imgfmt==IMGFMT_BGR8){
346
mpi->planes[1] = priv->palette;
347
mp_dbg(MSGT_DECVIDEO, MSGL_DBG2, "Found and copied palette\n");