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