Mercurial > mplayer.hg
annotate libmpcodecs/ve_vfw.c @ 8838:246a4b986d44
100l to doxmaintainers
author | arpi |
---|---|
date | Tue, 07 Jan 2003 23:10:09 +0000 |
parents | 27da710563c2 |
children | c671e9adbe22 |
rev | line source |
---|---|
5550 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
7238 | 4 #include <unistd.h> |
8585 | 5 #include <inttypes.h> |
5550 | 6 |
7 #include "../config.h" | |
8 #ifdef USE_WIN32DLL | |
9 | |
10 #include "../mp_msg.h" | |
11 | |
12 #include "codec-cfg.h" | |
7231 | 13 //#include "stream.h" |
14 //#include "demuxer.h" | |
15 //#include "stheader.h" | |
16 | |
17 #include "loader.h" | |
18 //#include "wine/mmreg.h" | |
19 #include "wine/vfw.h" | |
20 #include "wine/avifmt.h" | |
5550 | 21 |
5607 | 22 #include "img_format.h" |
23 #include "mp_image.h" | |
5550 | 24 #include "vf.h" |
25 | |
8585 | 26 #include "muxer.h" |
27 | |
28 extern void mencoder_write_chunk(muxer_stream_t *s,int len,unsigned int flags); | |
7127 | 29 |
5550 | 30 //===========================================================================// |
31 | |
6083 | 32 static char *vfw_param_codec = NULL; |
33 | |
34 #include "cfgparser.h" | |
35 | |
36 struct config vfwopts_conf[]={ | |
37 {"codec", &vfw_param_codec, CONF_TYPE_STRING, 0, 0, 0, NULL}, | |
38 {NULL, NULL, 0, 0, 0, 0, NULL} | |
39 }; | |
40 | |
5550 | 41 struct vf_priv_s { |
8585 | 42 muxer_stream_t* mux; |
5550 | 43 BITMAPINFOHEADER* bih; |
44 }; | |
45 | |
7557 | 46 static HIC encoder_hic; |
7231 | 47 static void* encoder_buf=NULL; |
48 static int encoder_buf_size=0; | |
49 static int encoder_frameno=0; | |
50 | |
51 //int init_vfw_encoder(char *dll_name, BITMAPINFOHEADER *input_bih, BITMAPINFOHEADER *output_bih) | |
52 static BITMAPINFOHEADER* vfw_open_encoder(char *dll_name, BITMAPINFOHEADER *input_bih,unsigned int out_fourcc) | |
53 { | |
54 HRESULT ret; | |
55 BITMAPINFOHEADER* output_bih=NULL; | |
56 int temp_len; | |
57 | |
58 //sh_video = malloc(sizeof(sh_video_t)); | |
59 | |
60 mp_msg(MSGT_WIN32,MSGL_V,"======= Win32 (VFW) VIDEO Encoder init =======\n"); | |
61 | |
62 // memset(&sh_video->o_bih, 0, sizeof(BITMAPINFOHEADER)); | |
63 // output_bih->biSize = sizeof(BITMAPINFOHEADER); | |
64 | |
7390 | 65 // encoder_hic = ICOpen( 0x63646976, out_fourcc, ICMODE_COMPRESS); |
7557 | 66 encoder_hic = ICOpen( (long) dll_name, out_fourcc, ICMODE_COMPRESS); |
7231 | 67 if(!encoder_hic){ |
68 mp_msg(MSGT_WIN32,MSGL_ERR,"ICOpen failed! unknown codec / wrong parameters?\n"); | |
69 return NULL; | |
70 } | |
71 printf("HIC: %x\n", encoder_hic); | |
72 | |
73 #if 1 | |
74 { | |
75 ICINFO icinfo; | |
76 | |
77 ret = ICGetInfo(encoder_hic, &icinfo, sizeof(ICINFO)); | |
8123
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
7557
diff
changeset
|
78 printf("%ld - %ld - %d\n", ret, icinfo.dwSize, sizeof(ICINFO)); |
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
7557
diff
changeset
|
79 printf("Compressor type: %.4lx\n", icinfo.fccType); |
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
7557
diff
changeset
|
80 printf("Compressor subtype: %.4lx\n", icinfo.fccHandler); |
7231 | 81 printf("Compressor flags: %lu, version %lu, ICM version: %lu\n", |
82 icinfo.dwFlags, icinfo.dwVersion, icinfo.dwVersionICM); | |
83 //printf("Compressor name: %s\n", icinfo.szName); | |
84 //printf("Compressor description: %s\n", icinfo.szDescription); | |
85 | |
86 printf("Flags:"); | |
87 if (icinfo.dwFlags & VIDCF_QUALITY) | |
88 printf(" quality"); | |
89 if (icinfo.dwFlags & VIDCF_FASTTEMPORALD) | |
90 printf(" fast-decompr"); | |
91 if (icinfo.dwFlags & VIDCF_QUALITYTIME) | |
92 printf(" temp-quality"); | |
93 printf("\n"); | |
94 } | |
95 #endif | |
96 | |
97 temp_len = ICCompressGetFormatSize(encoder_hic, input_bih); | |
98 printf("ICCompressGetFormatSize ret: %d\n", temp_len); | |
99 | |
100 if (temp_len < sizeof(BITMAPINFOHEADER)) temp_len=sizeof(BITMAPINFOHEADER); | |
101 | |
102 output_bih = malloc(temp_len+4); | |
103 memset(output_bih,0,temp_len); | |
104 output_bih->biSize = temp_len; //sizeof(BITMAPINFOHEADER); | |
105 | |
106 return output_bih; | |
107 } | |
108 | |
109 static int vfw_start_encoder(BITMAPINFOHEADER *input_bih, BITMAPINFOHEADER *output_bih){ | |
110 HRESULT ret; | |
111 int temp_len=output_bih->biSize; | |
112 int i; | |
113 | |
114 ret = ICCompressGetFormat(encoder_hic, input_bih, output_bih); | |
115 if(ret < 0){ | |
116 unsigned char* temp=(unsigned char*)output_bih; | |
117 mp_msg(MSGT_WIN32,MSGL_ERR,"ICCompressGetFormat failed: Error %d (0x%X)\n", (int)ret, (int)ret); | |
118 for (i=0; i < temp_len; i++) mp_msg(MSGT_WIN32, MSGL_DBG2, "%02x ", temp[i]); | |
119 return 0; | |
120 } | |
121 mp_msg(MSGT_WIN32,MSGL_V,"ICCompressGetFormat OK\n"); | |
122 | |
123 if (temp_len > sizeof(BITMAPINFOHEADER)) | |
124 { | |
125 unsigned char* temp=(unsigned char*)output_bih; | |
126 mp_msg(MSGT_WIN32, MSGL_V, "Extra info in o_bih (%d bytes)!\n", | |
127 temp_len-sizeof(BITMAPINFOHEADER)); | |
128 for(i=sizeof(output_bih);i<temp_len;i++) mp_msg(MSGT_WIN32, MSGL_DBG2, "%02X ",temp[i]); | |
129 } | |
130 | |
131 // if(verbose) { | |
132 printf("Starting compression:\n"); | |
133 printf(" Input format:\n"); | |
8123
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
7557
diff
changeset
|
134 printf(" biSize %d\n", input_bih->biSize); |
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
7557
diff
changeset
|
135 printf(" biWidth %d\n", input_bih->biWidth); |
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
7557
diff
changeset
|
136 printf(" biHeight %d\n", input_bih->biHeight); |
7231 | 137 printf(" biPlanes %d\n", input_bih->biPlanes); |
138 printf(" biBitCount %d\n", input_bih->biBitCount); | |
8123
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
7557
diff
changeset
|
139 printf(" biCompression 0x%x ('%.4s')\n", input_bih->biCompression, (char *)&input_bih->biCompression); |
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
7557
diff
changeset
|
140 printf(" biSizeImage %d\n", input_bih->biSizeImage); |
7231 | 141 printf(" Output format:\n"); |
8123
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
7557
diff
changeset
|
142 printf(" biSize %d\n", output_bih->biSize); |
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
7557
diff
changeset
|
143 printf(" biWidth %d\n", output_bih->biWidth); |
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
7557
diff
changeset
|
144 printf(" biHeight %d\n", output_bih->biHeight); |
7231 | 145 printf(" biPlanes %d\n", output_bih->biPlanes); |
146 printf(" biBitCount %d\n", output_bih->biBitCount); | |
8123
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
7557
diff
changeset
|
147 printf(" biCompression 0x%x ('%.4s')\n", output_bih->biCompression, (char *)&output_bih->biCompression); |
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
7557
diff
changeset
|
148 printf(" biSizeImage %d\n", output_bih->biSizeImage); |
7231 | 149 // } |
150 | |
151 output_bih->biWidth=input_bih->biWidth; | |
152 output_bih->biHeight=input_bih->biHeight; | |
153 | |
154 ret = ICCompressQuery(encoder_hic, input_bih, output_bih); | |
155 if(ret){ | |
156 mp_msg(MSGT_WIN32,MSGL_ERR,"ICCompressQuery failed: Error %d\n", (int)ret); | |
157 return 0; | |
158 } else | |
159 mp_msg(MSGT_WIN32,MSGL_V,"ICCompressQuery OK\n"); | |
160 | |
161 ret = ICCompressBegin(encoder_hic, input_bih, output_bih); | |
162 if(ret){ | |
163 mp_msg(MSGT_WIN32,MSGL_ERR,"ICCompressBegin failed: Error %d\n", (int)ret); | |
164 // return 0; | |
165 } else | |
166 mp_msg(MSGT_WIN32,MSGL_V,"ICCompressBegin OK\n"); | |
167 | |
168 printf(" Output format after query/begin:\n"); | |
8123
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
7557
diff
changeset
|
169 printf(" biSize %d\n", output_bih->biSize); |
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
7557
diff
changeset
|
170 printf(" biWidth %d\n", output_bih->biWidth); |
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
7557
diff
changeset
|
171 printf(" biHeight %d\n", output_bih->biHeight); |
7231 | 172 printf(" biPlanes %d\n", output_bih->biPlanes); |
173 printf(" biBitCount %d\n", output_bih->biBitCount); | |
8123
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
7557
diff
changeset
|
174 printf(" biCompression 0x%x ('%.4s')\n", output_bih->biCompression, (char *)&output_bih->biCompression); |
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
7557
diff
changeset
|
175 printf(" biSizeImage %d\n", output_bih->biSizeImage); |
7231 | 176 |
177 encoder_buf_size=input_bih->biSizeImage; | |
178 encoder_buf=malloc(encoder_buf_size); | |
179 encoder_frameno=0; | |
180 | |
181 mp_msg(MSGT_WIN32,MSGL_V,"VIDEO CODEC Init OK!!! ;-)\n"); | |
182 return 1; | |
183 } | |
184 | |
185 static int vfw_encode_frame(BITMAPINFOHEADER* biOutput,void* OutBuf, | |
186 BITMAPINFOHEADER* biInput,void* Image, | |
187 long* keyframe, int quality){ | |
188 HRESULT ret; | |
189 | |
190 //long VFWAPIV ICCompress( | |
191 // HIC hic,long dwFlags,LPBITMAPINFOHEADER lpbiOutput,void* lpOutputBuf, | |
192 // LPBITMAPINFOHEADER lpbiInput,void* lpImage,long* lpckid, | |
193 // long* lpdwFlags,long lFrameNum,long dwFrameSize,long dwQuality, | |
194 // LPBITMAPINFOHEADER lpbiInputPrev,void* lpImagePrev | |
195 //); | |
196 | |
197 // printf("vfw_encode_frame(%p,%p, %p,%p, %p,%d)\n",biOutput,OutBuf,biInput,Image,keyframe,quality); | |
198 | |
199 ret=ICCompress(encoder_hic, 0, | |
200 biOutput, OutBuf, | |
201 biInput, Image, | |
202 NULL, keyframe, encoder_frameno, 0, quality, | |
203 biInput, encoder_buf); | |
204 | |
205 // printf("ok. size=%d\n",biOutput->biSizeImage); | |
206 | |
207 memcpy(encoder_buf,Image,encoder_buf_size); | |
208 ++encoder_frameno; | |
209 | |
210 return (int)ret; | |
211 } | |
5550 | 212 #define mux_v (vf->priv->mux) |
213 #define vfw_bih (vf->priv->bih) | |
214 | |
215 static int config(struct vf_instance_s* vf, | |
216 int width, int height, int d_width, int d_height, | |
217 unsigned int flags, unsigned int outfmt){ | |
218 | |
219 vfw_bih->biWidth=width; | |
220 vfw_bih->biHeight=height; | |
221 vfw_bih->biSizeImage=width*height*((vfw_bih->biBitCount+7)/8); | |
5551 | 222 |
223 if(!vfw_start_encoder(vfw_bih, mux_v->bih)) return 0; | |
224 | |
225 // mux_v->bih->biWidth=width; | |
226 // mux_v->bih->biHeight=height; | |
227 // mux_v->bih->biSizeImage=width*height*((mux_v->bih->biBitCount+7)/8); | |
5550 | 228 |
229 return 1; | |
230 } | |
231 | |
232 static int control(struct vf_instance_s* vf, int request, void* data){ | |
233 | |
234 return CONTROL_UNKNOWN; | |
235 } | |
236 | |
237 static int query_format(struct vf_instance_s* vf, unsigned int fmt){ | |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5551
diff
changeset
|
238 if(fmt==IMGFMT_BGR24) return 3 | VFCAP_FLIPPED; |
5550 | 239 return 0; |
240 } | |
241 | |
7368 | 242 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){ |
5550 | 243 long flags=0; |
244 int ret; | |
245 // flip_upside_down(vo_image_ptr,vo_image_ptr,3*vo_w,vo_h); // dirty hack | |
246 ret=vfw_encode_frame(mux_v->bih, mux_v->buffer, vfw_bih, mpi->planes[0], &flags, 10000); | |
247 mencoder_write_chunk(mux_v,mux_v->bih->biSizeImage,flags); | |
7368 | 248 return 1; |
5550 | 249 } |
250 | |
251 //===========================================================================// | |
252 | |
253 static int vf_open(vf_instance_t *vf, char* args){ | |
254 vf->config=config; | |
255 vf->control=control; | |
256 vf->query_format=query_format; | |
257 vf->put_image=put_image; | |
258 vf->priv=malloc(sizeof(struct vf_priv_s)); | |
259 memset(vf->priv,0,sizeof(struct vf_priv_s)); | |
8585 | 260 vf->priv->mux=(muxer_stream_t*)args; |
5550 | 261 |
262 vfw_bih=malloc(sizeof(BITMAPINFOHEADER)); | |
263 vfw_bih->biSize=sizeof(BITMAPINFOHEADER); | |
264 vfw_bih->biWidth=0; // FIXME ? | |
265 vfw_bih->biHeight=0; | |
266 vfw_bih->biPlanes=1; | |
267 vfw_bih->biBitCount=24; | |
268 vfw_bih->biCompression=0; | |
269 // vfw_bih->biSizeImage=vo_w*vo_h*((vfw_bih->biBitCount+7)/8); | |
6083 | 270 |
271 if (!vfw_param_codec) | |
272 { | |
273 printf("No VfW codec specified! It's required!\n"); | |
274 return 0; | |
275 } | |
5550 | 276 // mux_v->bih=vfw_open_encoder("divxc32.dll",vfw_bih,mmioFOURCC('D', 'I', 'V', '3')); |
6083 | 277 // mux_v->bih=vfw_open_encoder("AvidAVICodec.dll",vfw_bih, 0); |
278 mux_v->bih = vfw_open_encoder(vfw_param_codec, vfw_bih, 0); | |
5550 | 279 if(!mux_v->bih) return 0; |
280 | |
281 return 1; | |
282 } | |
283 | |
284 vf_info_t ve_info_vfw = { | |
285 "Win32/VfW encoders", | |
286 "vfw", | |
287 "A'rpi", | |
288 "for internal use by mencoder", | |
289 vf_open | |
290 }; | |
291 | |
292 //===========================================================================// | |
293 #endif |