annotate libmpcodecs/vd_vfw.c @ 7260:3e7a601c5874

- vfwex redundancy removed - fixed 10l bug in GetPalette (outflags vs. outfmt)
author arpi
date Tue, 03 Sep 2002 21:13:48 +0000
parents 06a8e6a01180
children 5fc42290c305
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4968
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
1 #include <stdio.h>
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
2 #include <stdlib.h>
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
3
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
4 #include "config.h"
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
5 #include "mp_msg.h"
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
6 #include "help_mp.h"
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
7
7229
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
8 #ifdef USE_WIN32DLL
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
9
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
10 #include "loader.h"
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
11 //#include "wine/mmreg.h"
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
12 #include "wine/vfw.h"
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
13 #include "wine/avifmt.h"
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
14
4968
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
15 #include "vd_internal.h"
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
16
7176
42222161de9b 2*10l to me
arpi
parents: 7175
diff changeset
17 static vd_info_t info = {
7260
3e7a601c5874 - vfwex redundancy removed
arpi
parents: 7249
diff changeset
18 #ifdef BUILD_VFWEX
3e7a601c5874 - vfwex redundancy removed
arpi
parents: 7249
diff changeset
19 "Win32/VfWex video codecs",
3e7a601c5874 - vfwex redundancy removed
arpi
parents: 7249
diff changeset
20 "vfwex",
3e7a601c5874 - vfwex redundancy removed
arpi
parents: 7249
diff changeset
21 #else
4968
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
22 "Win32/VfW video codecs",
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
23 "vfw",
7260
3e7a601c5874 - vfwex redundancy removed
arpi
parents: 7249
diff changeset
24 #endif
7229
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
25 "A'rpi & Alex",
7260
3e7a601c5874 - vfwex redundancy removed
arpi
parents: 7249
diff changeset
26 "avifile.sf.net",
4968
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
27 "win32 codecs"
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
28 };
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
29
7260
3e7a601c5874 - vfwex redundancy removed
arpi
parents: 7249
diff changeset
30 #ifdef BUILD_VFWEX
3e7a601c5874 - vfwex redundancy removed
arpi
parents: 7249
diff changeset
31 LIBVD_EXTERN(vfwex)
3e7a601c5874 - vfwex redundancy removed
arpi
parents: 7249
diff changeset
32 #else
4968
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
33 LIBVD_EXTERN(vfw)
7260
3e7a601c5874 - vfwex redundancy removed
arpi
parents: 7249
diff changeset
34 #endif
4968
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
35
7229
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
36 typedef struct {
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
37 BITMAPINFOHEADER *o_bih;
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
38 HIC handle;
7243
5f1f724f7046 correct palette handling and query_format support (now huffyuv, cram and mwv1 is working nice)
alex
parents: 7230
diff changeset
39 unsigned char *palette;
7229
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
40 } vd_vfw_ctx;
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
41
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
42 extern int divx_quality;
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
43
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
44 static int vfw_set_postproc(sh_video_t* sh, int quality)
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
45 {
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
46 vd_vfw_ctx *priv = sh->context;
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
47 // Works only with opendivx/divx4 based DLL
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
48 return ICSendMessage(priv->handle, ICM_USER+80, (long)(&quality) ,NULL);
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
49 }
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
50
7249
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
51 static void set_csp(BITMAPINFOHEADER *o_bih,unsigned int outfmt){
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
52 int yuv = 0;
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
53
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
54 switch (outfmt)
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
55 {
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
56 /* planar format */
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
57 case IMGFMT_YV12:
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
58 case IMGFMT_I420:
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
59 case IMGFMT_IYUV:
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
60 o_bih->biBitCount=12;
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
61 yuv=1;
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
62 break;
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
63 case IMGFMT_YVU9:
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
64 case IMGFMT_IF09:
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
65 o_bih->biBitCount=9;
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
66 yuv=1;
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
67 break;
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
68 /* packed format */
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
69 case IMGFMT_YUY2:
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
70 case IMGFMT_UYVY:
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
71 case IMGFMT_YVYU:
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
72 o_bih->biBitCount=16;
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
73 yuv=1;
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
74 break;
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
75 /* rgb/bgr format */
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
76 case IMGFMT_RGB8:
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
77 case IMGFMT_BGR8:
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
78 o_bih->biBitCount=8;
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
79 break;
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
80 case IMGFMT_RGB15:
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
81 case IMGFMT_RGB16:
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
82 case IMGFMT_BGR15:
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
83 case IMGFMT_BGR16:
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
84 o_bih->biBitCount=16;
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
85 break;
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
86 case IMGFMT_RGB24:
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
87 case IMGFMT_BGR24:
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
88 o_bih->biBitCount=24;
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
89 break;
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
90 case IMGFMT_RGB32:
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
91 case IMGFMT_BGR32:
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
92 o_bih->biBitCount=32;
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
93 break;
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
94 default:
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
95 mp_msg(MSGT_WIN32,MSGL_ERR,"Unsupported image format: %s\n", vo_format_name(outfmt));
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
96 return;
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
97 }
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
98
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
99 o_bih->biSizeImage = abs(o_bih->biWidth * o_bih->biHeight * (o_bih->biBitCount/8));
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
100
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
101 // Note: we cannot rely on sh->outfmtidx here, it's undefined at this stage!!!
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
102 // if (yuv && !(sh->codec->outflags[sh->outfmtidx] & CODECS_FLAG_YUVHACK))
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
103 if (yuv)
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
104 o_bih->biCompression = outfmt;
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
105 else
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
106 o_bih->biCompression = 0;
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
107 }
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
108
4968
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
109 // to set/get/query special features/parameters
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
110 static int control(sh_video_t *sh,int cmd,void* arg,...){
7243
5f1f724f7046 correct palette handling and query_format support (now huffyuv, cram and mwv1 is working nice)
alex
parents: 7230
diff changeset
111 vd_vfw_ctx *priv = sh->context;
4968
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
112 switch(cmd){
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
113 case VDCTRL_QUERY_MAX_PP_LEVEL:
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
114 return 9;
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
115 case VDCTRL_SET_PP_LEVEL:
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
116 vfw_set_postproc(sh,10*(*((int*)arg)));
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
117 return CONTROL_OK;
7249
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
118 #if 0
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
119 // FIXME: make this optional...
7243
5f1f724f7046 correct palette handling and query_format support (now huffyuv, cram and mwv1 is working nice)
alex
parents: 7230
diff changeset
120 case VDCTRL_QUERY_FORMAT:
5f1f724f7046 correct palette handling and query_format support (now huffyuv, cram and mwv1 is working nice)
alex
parents: 7230
diff changeset
121 {
5f1f724f7046 correct palette handling and query_format support (now huffyuv, cram and mwv1 is working nice)
alex
parents: 7230
diff changeset
122 HRESULT ret;
7249
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
123 set_csp(priv->o_bih,*((int*)arg));
7260
3e7a601c5874 - vfwex redundancy removed
arpi
parents: 7249
diff changeset
124 #ifdef BUILD_VFWEX
3e7a601c5874 - vfwex redundancy removed
arpi
parents: 7249
diff changeset
125 ret = ICDecompressQueryEx(priv->handle, sh->bih, priv->o_bih);
3e7a601c5874 - vfwex redundancy removed
arpi
parents: 7249
diff changeset
126 #else
7243
5f1f724f7046 correct palette handling and query_format support (now huffyuv, cram and mwv1 is working nice)
alex
parents: 7230
diff changeset
127 ret = ICDecompressQuery(priv->handle, sh->bih, priv->o_bih);
7260
3e7a601c5874 - vfwex redundancy removed
arpi
parents: 7249
diff changeset
128 #endif
7243
5f1f724f7046 correct palette handling and query_format support (now huffyuv, cram and mwv1 is working nice)
alex
parents: 7230
diff changeset
129 if (ret)
5f1f724f7046 correct palette handling and query_format support (now huffyuv, cram and mwv1 is working nice)
alex
parents: 7230
diff changeset
130 {
5f1f724f7046 correct palette handling and query_format support (now huffyuv, cram and mwv1 is working nice)
alex
parents: 7230
diff changeset
131 mp_msg(MSGT_WIN32, MSGL_DBG2, "ICDecompressQuery failed:: Error %d\n", (int)ret);
5f1f724f7046 correct palette handling and query_format support (now huffyuv, cram and mwv1 is working nice)
alex
parents: 7230
diff changeset
132 return CONTROL_FALSE;
5f1f724f7046 correct palette handling and query_format support (now huffyuv, cram and mwv1 is working nice)
alex
parents: 7230
diff changeset
133 }
7249
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
134 return CONTROL_TRUE;
7243
5f1f724f7046 correct palette handling and query_format support (now huffyuv, cram and mwv1 is working nice)
alex
parents: 7230
diff changeset
135 }
7249
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
136 #endif
4968
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
137 }
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
138 return CONTROL_UNKNOWN;
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
139 }
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
140
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
141 // init driver
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
142 static int init(sh_video_t *sh){
7229
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
143 HRESULT ret;
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
144 int yuv=0;
7249
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
145 // unsigned int outfmt=sh->codec->outfmt[sh->outfmtidx];
7229
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
146 int i, o_bih_len;
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
147 vd_vfw_ctx *priv;
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
148
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
149 priv = malloc(sizeof(vd_vfw_ctx));
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
150 if (!priv)
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
151 return 0;
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
152 memset(priv, 0, sizeof(vd_vfw_ctx));
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
153 sh->context = priv;
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
154
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
155 mp_msg(MSGT_WIN32,MSGL_V,"======= Win32 (VFW) VIDEO Codec init =======\n");
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
156
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
157 win32_codec_name = sh->codec->dll;
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
158 // sh->hic = ICOpen( 0x63646976, sh->bih->biCompression, ICMODE_FASTDECOMPRESS);
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
159 priv->handle = ICOpen( 0x63646976, sh->bih->biCompression, ICMODE_DECOMPRESS);
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
160 if(!priv->handle){
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
161 mp_msg(MSGT_WIN32,MSGL_ERR,"ICOpen failed! unknown codec / wrong parameters?\n");
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
162 return 0;
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
163 }
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
164
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
165 // sh->bih->biBitCount=32;
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
166
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
167 o_bih_len = ICDecompressGetFormatSize(priv->handle, sh->bih);
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
168
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
169 priv->o_bih = malloc(o_bih_len);
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
170 memset(priv->o_bih, 0, o_bih_len);
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
171
7249
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
172 mp_msg(MSGT_WIN32,MSGL_V,"ICDecompressGetFormatSize ret: %d\n", o_bih_len);
7229
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
173
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
174 ret = ICDecompressGetFormat(priv->handle, sh->bih, priv->o_bih);
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
175 if(ret < 0){
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
176 mp_msg(MSGT_WIN32,MSGL_ERR,"ICDecompressGetFormat failed: Error %d\n", (int)ret);
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
177 for (i=0; i < o_bih_len; i++) mp_msg(MSGT_WIN32, MSGL_DBG2, "%02x ", priv->o_bih[i]);
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
178 return 0;
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
179 }
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
180 mp_msg(MSGT_WIN32,MSGL_V,"ICDecompressGetFormat OK\n");
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
181
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
182 #if 0
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
183 // workaround for pegasus MJPEG:
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
184 if(!sh_video->o_bih.biWidth) sh_video->o_bih.biWidth=sh_video->bih->biWidth;
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
185 if(!sh_video->o_bih.biHeight) sh_video->o_bih.biHeight=sh_video->bih->biHeight;
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
186 if(!sh_video->o_bih.biPlanes) sh_video->o_bih.biPlanes=sh_video->bih->biPlanes;
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
187 #endif
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
188
7249
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
189 // ok let libvo and vd core to handshake and decide the optimal csp:
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
190 if(!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YUY2)) return 0;
7229
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
191
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
192 if (!(sh->codec->outflags[sh->outfmtidx]&CODECS_FLAG_FLIP)) {
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
193 priv->o_bih->biHeight=-sh->bih->biHeight; // flip image!
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
194 }
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
195
7249
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
196 // ok, let's set the choosen colorspace:
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
197 set_csp(priv->o_bih,sh->codec->outfmt[sh->outfmtidx]);
7229
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
198
7249
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
199 // fake it to RGB for broken DLLs (divx3)
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
200 if(sh->codec->outflags[sh->outfmtidx] & CODECS_FLAG_YUVHACK)
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
201 priv->o_bih->biCompression = 0;
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
202
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
203 // sanity check:
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
204 #if 1
7260
3e7a601c5874 - vfwex redundancy removed
arpi
parents: 7249
diff changeset
205 #ifdef BUILD_VFWEX
3e7a601c5874 - vfwex redundancy removed
arpi
parents: 7249
diff changeset
206 ret = ICDecompressQueryEx(priv->handle, sh->bih, priv->o_bih);
3e7a601c5874 - vfwex redundancy removed
arpi
parents: 7249
diff changeset
207 #else
7243
5f1f724f7046 correct palette handling and query_format support (now huffyuv, cram and mwv1 is working nice)
alex
parents: 7230
diff changeset
208 ret = ICDecompressQuery(priv->handle, sh->bih, priv->o_bih);
7260
3e7a601c5874 - vfwex redundancy removed
arpi
parents: 7249
diff changeset
209 #endif
7243
5f1f724f7046 correct palette handling and query_format support (now huffyuv, cram and mwv1 is working nice)
alex
parents: 7230
diff changeset
210 if (ret)
7229
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
211 {
7249
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
212 mp_msg(MSGT_WIN32,MSGL_WARN,"ICDecompressQuery failed: Error %d\n", (int)ret);
7229
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
213 // return 0;
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
214 } else
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
215 mp_msg(MSGT_WIN32,MSGL_V,"ICDecompressQuery OK\n");
7243
5f1f724f7046 correct palette handling and query_format support (now huffyuv, cram and mwv1 is working nice)
alex
parents: 7230
diff changeset
216 #endif
7229
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
217
7260
3e7a601c5874 - vfwex redundancy removed
arpi
parents: 7249
diff changeset
218 #ifdef BUILD_VFWEX
3e7a601c5874 - vfwex redundancy removed
arpi
parents: 7249
diff changeset
219 ret = ICDecompressBeginEx(priv->handle, sh->bih, priv->o_bih);
3e7a601c5874 - vfwex redundancy removed
arpi
parents: 7249
diff changeset
220 #else
7243
5f1f724f7046 correct palette handling and query_format support (now huffyuv, cram and mwv1 is working nice)
alex
parents: 7230
diff changeset
221 ret = ICDecompressBegin(priv->handle, sh->bih, priv->o_bih);
7260
3e7a601c5874 - vfwex redundancy removed
arpi
parents: 7249
diff changeset
222 #endif
7243
5f1f724f7046 correct palette handling and query_format support (now huffyuv, cram and mwv1 is working nice)
alex
parents: 7230
diff changeset
223 if (ret)
7229
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
224 {
7249
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
225 mp_msg(MSGT_WIN32,MSGL_WARN,"ICDecompressBegin failed: Error %d\n", (int)ret);
7229
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
226 // return 0;
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
227 }
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
228
7249
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
229 // for broken codecs set it again:
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
230 if(sh->codec->outflags[sh->outfmtidx] & CODECS_FLAG_YUVHACK)
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
231 set_csp(priv->o_bih,sh->codec->outfmt[sh->outfmtidx]);
7229
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
232
7243
5f1f724f7046 correct palette handling and query_format support (now huffyuv, cram and mwv1 is working nice)
alex
parents: 7230
diff changeset
233 mp_msg(MSGT_WIN32, MSGL_V, "Input format:\n");
7249
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
234 if(verbose) print_video_header(sh->bih);
7243
5f1f724f7046 correct palette handling and query_format support (now huffyuv, cram and mwv1 is working nice)
alex
parents: 7230
diff changeset
235 mp_msg(MSGT_WIN32, MSGL_V, "Output format:\n");
7249
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
236 if(verbose) print_video_header(priv->o_bih);
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
237
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
238 // set postprocessing level in xvid/divx4 .dll
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
239 ICSendMessage(priv->handle, ICM_USER+80, (long)(&divx_quality) ,NULL);
7243
5f1f724f7046 correct palette handling and query_format support (now huffyuv, cram and mwv1 is working nice)
alex
parents: 7230
diff changeset
240
7249
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
241 // don't do this palette mess always, it makes div3 dll crashing...
7260
3e7a601c5874 - vfwex redundancy removed
arpi
parents: 7249
diff changeset
242 if((sh->codec->outfmt[sh->outfmtidx]==IMGFMT_BGR8) &&
7249
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
243 (!ICDecompressGetPalette(priv->handle, sh->bih, priv->o_bih)))
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
244 {
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
245 priv->palette = ((unsigned char*)priv->o_bih) + sh->bih->biSize;
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
246 mp_msg(MSGT_WIN32,MSGL_V,"ICDecompressGetPalette OK\n");
06a8e6a01180 fixed some problems with colorspace/init order, some cleanup
arpi
parents: 7243
diff changeset
247 }
7229
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
248
4968
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
249 mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: Win32 video codec init OK!\n");
5153
7091d4c46685 fixed colorspace detection
arpi
parents: 5124
diff changeset
250 return 1;
4968
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
251 }
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
252
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
253 // uninit driver
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
254 static void uninit(sh_video_t *sh){
7229
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
255 HRESULT ret;
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
256 vd_vfw_ctx *priv = sh->context;
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
257
7260
3e7a601c5874 - vfwex redundancy removed
arpi
parents: 7249
diff changeset
258 #ifdef BUILD_VFWEX
3e7a601c5874 - vfwex redundancy removed
arpi
parents: 7249
diff changeset
259 ret = ICDecompressEndEx(priv->handle);
3e7a601c5874 - vfwex redundancy removed
arpi
parents: 7249
diff changeset
260 #else
7229
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
261 ret = ICDecompressEnd(priv->handle);
7260
3e7a601c5874 - vfwex redundancy removed
arpi
parents: 7249
diff changeset
262 #endif
7229
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
263 if (ret)
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
264 {
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
265 mp_msg(MSGT_WIN32, MSGL_WARN, "ICDecompressEnd failed: %d\n", ret);
7243
5f1f724f7046 correct palette handling and query_format support (now huffyuv, cram and mwv1 is working nice)
alex
parents: 7230
diff changeset
266 return;
7229
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
267 }
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
268
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
269 ret = ICClose(priv->handle);
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
270 if (ret)
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
271 {
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
272 mp_msg(MSGT_WIN32, MSGL_WARN, "ICClose failed: %d\n", ret);
7243
5f1f724f7046 correct palette handling and query_format support (now huffyuv, cram and mwv1 is working nice)
alex
parents: 7230
diff changeset
273 return;
7229
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
274 }
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
275
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
276 free(priv->o_bih);
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
277 free(priv);
4968
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
278 }
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
279
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
280 // decode a frame
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
281 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
7229
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
282 vd_vfw_ctx *priv = sh->context;
4968
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
283 mp_image_t* mpi;
7229
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
284 HRESULT ret;
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
285
4968
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
286 if(len<=0) return NULL; // skipped frame
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
287
6105
b77b984120f9 iive is right - we shouldn't use IP buffering for vfw. it was changed
arpi
parents: 5769
diff changeset
288 mpi=mpcodecs_get_image(sh,
b77b984120f9 iive is right - we shouldn't use IP buffering for vfw. it was changed
arpi
parents: 5769
diff changeset
289 (sh->codec->outflags[sh->outfmtidx] & CODECS_FLAG_STATIC) ?
b77b984120f9 iive is right - we shouldn't use IP buffering for vfw. it was changed
arpi
parents: 5769
diff changeset
290 MP_IMGTYPE_STATIC : MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_WIDTH,
4968
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
291 sh->disp_w, sh->disp_h);
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
292 if(!mpi){ // temporary!
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
293 printf("couldn't allocate image for cinepak codec\n");
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
294 return NULL;
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
295 }
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
296
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
297 // set stride: (trick discovered by Andreas Ackermann - thanx!)
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
298 sh->bih->biWidth=mpi->width; //mpi->stride[0]/(mpi->bpp/8);
7229
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
299 priv->o_bih->biWidth=mpi->width; //mpi->stride[0]/(mpi->bpp/8);
4968
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
300
7229
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
301 sh->bih->biSizeImage = len;
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
302
7260
3e7a601c5874 - vfwex redundancy removed
arpi
parents: 7249
diff changeset
303 #ifdef BUILD_VFWEX
3e7a601c5874 - vfwex redundancy removed
arpi
parents: 7249
diff changeset
304 ret = ICDecompressEx(priv->handle,
3e7a601c5874 - vfwex redundancy removed
arpi
parents: 7249
diff changeset
305 #else
7229
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
306 ret = ICDecompress(priv->handle,
7260
3e7a601c5874 - vfwex redundancy removed
arpi
parents: 7249
diff changeset
307 #endif
7229
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
308 ( (sh->ds->flags&1) ? 0 : ICDECOMPRESS_NOTKEYFRAME ) |
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
309 ( ((flags&3)==2 && !(sh->ds->flags&1))?(ICDECOMPRESS_HURRYUP|ICDECOMPRESS_PREROL):0 ),
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
310 sh->bih, data, priv->o_bih, (flags&3) ? 0 : mpi->planes[0]);
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
311
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
312 if ((int)ret){
4968
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
313 mp_msg(MSGT_DECVIDEO,MSGL_WARN,"Error decompressing frame, err=%d\n",ret);
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
314 return NULL;
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
315 }
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
316
7229
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
317 // export palette:
7243
5f1f724f7046 correct palette handling and query_format support (now huffyuv, cram and mwv1 is working nice)
alex
parents: 7230
diff changeset
318 if (priv->palette)
7229
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
319 {
7243
5f1f724f7046 correct palette handling and query_format support (now huffyuv, cram and mwv1 is working nice)
alex
parents: 7230
diff changeset
320 mpi->planes[1] = priv->palette;
5f1f724f7046 correct palette handling and query_format support (now huffyuv, cram and mwv1 is working nice)
alex
parents: 7230
diff changeset
321 mpi->flags |= MP_IMGFLAG_RGB_PALETTE;
7229
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
322 mp_dbg(MSGT_DECVIDEO, MSGL_DBG2, "Found and copied palette\n");
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
323 }
b4d025d64eb3 merged with dll_init
alex
parents: 7180
diff changeset
324 else
6232
f8e0eac1256c grayscaled palette support
arpi
parents: 6105
diff changeset
325 mpi->planes[1]=NULL;
5769
f28c734f20b3 export palette for rgb8/bgr8
arpi
parents: 5451
diff changeset
326
4968
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
327 return mpi;
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
328 }
236b06410b03 vfw, vfwex, odivx, divx4 added
arpi
parents:
diff changeset
329 #endif