Added some missing prototypes.
[wine] / dlls / msvideo / msvideo_main.c
1 /*
2  * Copyright 1998 Marcus Meissner
3  */
4 #include <stdio.h>
5 #include <string.h>
6
7 #include "winbase.h"
8 #include "windef.h"
9 #include "wingdi.h"
10 #include "winuser.h"
11 #include "vfw.h"
12 #include "wine/winestring.h"
13 #include "driver.h"
14 #include "debugtools.h"
15
16 DEFAULT_DEBUG_CHANNEL(msvideo)
17
18 /***********************************************************************
19  *              VideoForWindowsVersion          [MSVFW.2][MSVIDEO.2]
20  * Returns the version in major.minor form.
21  * In Windows95 this returns 0x040003b6 (4.950)
22  */
23 DWORD WINAPI
24 VideoForWindowsVersion(void) {
25         return 0x040003B6; /* 4.950 */
26 }
27
28 /***********************************************************************
29  *              VideoCapDriverDescAndVer        [MSVIDEO.22]
30  */
31 DWORD WINAPI
32 VideoCapDriverDescAndVer(WORD nr,LPVOID buf1,WORD buf1len,LPVOID buf2,WORD buf2len) {
33         FIXME("(%d,%p,%d,%p,%d), stub!\n",nr,buf1,buf1len,buf2,buf2len);
34         return 0;
35 }
36
37 /* system.ini: [drivers] */
38
39 /***********************************************************************
40  *              ICInfo                          [MSVFW.33]
41  * Get information about an installable compressor. Return TRUE if there
42  * is one.
43  */
44 BOOL WINAPI
45 ICInfo(
46         DWORD fccType,          /* [in] type of compressor ('vidc') */
47         DWORD fccHandler,       /* [in] <n>th compressor */
48         ICINFO *lpicinfo        /* [out] information about compressor */
49 ) {
50         char    type[5],buf[2000];
51
52         memcpy(type,&fccType,4);type[4]=0;
53         TRACE("(%s,%ld,%p).\n",type,fccHandler,lpicinfo);
54         /* does OpenDriver/CloseDriver */
55         lpicinfo->dwSize = sizeof(ICINFO);
56         lpicinfo->fccType = fccType;
57         lpicinfo->dwFlags = 0;
58         if (GetPrivateProfileStringA("drivers32",NULL,NULL,buf,2000,"system.ini")) {
59                 char *s = buf;
60                 while (*s) {
61                         if (!lstrncmpiA(type,s,4)) {
62                                 if(!fccHandler--) {
63                                         lpicinfo->fccHandler = mmioStringToFOURCCA(s+5,0);
64                                         return TRUE;
65                                 }
66                         }
67                         s=s+lstrlenA(s)+1; /* either next char or \0 */
68                 }
69         }
70         return FALSE;
71 }
72
73 /***********************************************************************
74  *              ICOpen                          [MSVFW.37]
75  * Opens an installable compressor. Return special handle.
76  */
77 HIC WINAPI
78 ICOpen(DWORD fccType,DWORD fccHandler,UINT wMode) {
79         char            type[5],handler[5],codecname[20];
80         ICOPEN          icopen;
81         HDRVR           hdrv;
82         WINE_HIC        *whic;
83
84         memcpy(type,&fccType,4);type[4]=0;
85         memcpy(handler,&fccHandler,4);handler[4]=0;
86         TRACE("(%s,%s,0x%08lx)\n",type,handler,(DWORD)wMode);
87         sprintf(codecname,"%s.%s",type,handler);
88
89         /* Well, lParam2 is in fact a LPVIDEO_OPEN_PARMS, but it has the 
90          * same layout as ICOPEN
91          */
92         icopen.fccType          = fccType;
93         icopen.fccHandler       = fccHandler;
94         icopen.dwSize           = sizeof(ICOPEN);
95         icopen.dwFlags          = wMode;
96         /* FIXME: do we need to fill out the rest too? */
97         hdrv=OpenDriverA(codecname,"drivers32",(LPARAM)&icopen);
98         if (!hdrv) {
99             if (!strcasecmp(type,"vids")) {
100                 sprintf(codecname,"vidc.%s",handler);
101                 fccType = mmioFOURCC('v','i','d','c');
102             }
103             hdrv=OpenDriverA(codecname,"drivers32",(LPARAM)&icopen);
104             if (!hdrv)
105                     return 0;
106         }
107         whic = HeapAlloc(GetProcessHeap(),0,sizeof(WINE_HIC));
108         whic->hdrv      = hdrv;
109         whic->driverproc= NULL;
110         whic->private   = ICSendMessage((HIC)whic,DRV_OPEN,0,(LPARAM)&icopen);
111         return (HIC)whic;
112 }
113
114 /***********************************************************************
115  *              ICOpenFunction                  [MSVFW.38]
116  */
117 HIC VFWAPI ICOpenFunction(DWORD fccType, DWORD fccHandler, UINT wMode,
118 FARPROC lpfnHandler) {
119         char            type[5],handler[5];
120         HIC             hic;
121         WINE_HIC        *whic;
122
123         memcpy(type,&fccType,4);type[4]=0;
124         memcpy(handler,&fccHandler,4);handler[4]=0;
125         FIXME("(%s,%s,%d,%p), stub!\n",type,handler,wMode,lpfnHandler);
126         hic = ICOpen(fccType,fccHandler,wMode);
127         if (!hic)
128                 return hic;
129         whic = (WINE_HIC*)hic;
130         whic->driverproc = lpfnHandler;
131         return hic;
132 }
133
134
135 /***********************************************************************
136  *              ICGetInfo                       [MSVFW.30]
137  */
138 LRESULT WINAPI
139 ICGetInfo(HIC hic,ICINFO *picinfo,DWORD cb) {
140         LRESULT         ret;
141
142         TRACE("(0x%08lx,%p,%ld)\n",(DWORD)hic,picinfo,cb);
143         ret = ICSendMessage(hic,ICM_GETINFO,(DWORD)picinfo,cb);
144         TRACE(" -> 0x%08lx\n",ret);
145         return ret;
146 }
147
148 /***********************************************************************
149  *              ICLocate                        [MSVFW.35]
150  */
151 HIC  VFWAPI
152 ICLocate(
153         DWORD fccType, DWORD fccHandler, LPBITMAPINFOHEADER lpbiIn,
154         LPBITMAPINFOHEADER lpbiOut, WORD wMode
155 ) {
156         char    type[5],handler[5];
157         HIC     hic;
158         DWORD   querymsg;
159
160         switch (wMode) {
161         case ICMODE_FASTCOMPRESS:
162         case ICMODE_COMPRESS: 
163                 querymsg = ICM_COMPRESS_QUERY;
164                 break;
165         case ICMODE_DECOMPRESS:
166         case ICMODE_FASTDECOMPRESS:
167                 querymsg = ICM_DECOMPRESS_QUERY;
168                 break;
169         case ICMODE_DRAW:
170                 querymsg = ICM_DRAW_QUERY;
171                 break;
172         default:
173                 FIXME("Unknown mode (%d)\n",wMode);
174                 return 0;
175         }
176
177         /* Easy case: handler/type match, we just fire a query and return */
178         hic = ICOpen(fccType,fccHandler,wMode);
179         if (hic) {
180                 if (!ICSendMessage(hic,querymsg,(DWORD)lpbiIn,(DWORD)lpbiOut))
181                         return hic;
182                 ICClose(hic);
183         }
184         type[4]='\0';memcpy(type,&fccType,4);
185         handler[4]='\0';memcpy(handler,&fccHandler,4);
186         if (fccType==streamtypeVIDEO) {
187                 hic = ICLocate(ICTYPE_VIDEO,fccHandler,lpbiIn,lpbiOut,wMode);
188                 if (hic)
189                         return hic;
190         }
191         FIXME("(%s,%s,%p,%p,0x%04x),unhandled!\n",type,handler,lpbiIn,lpbiOut,wMode);
192         return 0;
193 }
194
195 /***********************************************************************
196  *              ICGetDisplayFormat                      [MSVFW.29]
197  */
198 HIC VFWAPI ICGetDisplayFormat(
199         HIC hic,LPBITMAPINFOHEADER lpbiIn,LPBITMAPINFOHEADER lpbiOut,
200         INT depth,INT dx,INT dy
201 ) {
202         HIC     tmphic = hic; 
203         LRESULT lres;
204
205         FIXME("(0x%08lx,%p,%p,%d,%d,%d),stub!\n",(DWORD)hic,lpbiIn,lpbiOut,depth,dx,dy);
206         if (!tmphic) {
207                 tmphic=ICLocate(ICTYPE_VIDEO,0,lpbiIn,NULL,ICMODE_DECOMPRESS);
208                 if (!tmphic)
209                         return tmphic;
210         }
211         if ((dy == lpbiIn->biHeight) || (dx == lpbiIn->biWidth))
212                 dy = dx = 0; /* no resize needed */
213         /* Can we decompress it ? */
214         lres = ICDecompressQuery(tmphic,lpbiIn,NULL);
215         if (lres)
216                 goto errout; /* no, sorry */
217         ICDecompressGetFormat(hic,lpbiIn,lpbiOut);
218         *lpbiOut=*lpbiIn;
219         lpbiOut->biCompression = 0;
220         lpbiOut->biSize = sizeof(*lpbiOut);
221         if (!depth) {
222                 HDC     hdc;
223
224                 hdc = GetDC(0);
225                 depth = GetDeviceCaps(hdc,12)*GetDeviceCaps(hdc,14);
226                 ReleaseDC(0,hdc);
227                 if (depth==15)  depth = 16;
228                 if (depth<8)    depth =  8;
229                 /* more constraints and tests */
230         }
231         if (lpbiIn->biBitCount == 8)
232                 depth = 8;
233         
234         return hic;
235 errout:
236         if (hic!=tmphic)
237                 ICClose(tmphic);
238         return 0;
239 }
240
241 /***********************************************************************
242  *              ICCompress                      [MSVFW.23]
243  */
244 DWORD VFWAPIV
245 ICCompress(
246         HIC hic,DWORD dwFlags,LPBITMAPINFOHEADER lpbiOutput,LPVOID lpData,
247         LPBITMAPINFOHEADER lpbiInput,LPVOID lpBits,LPDWORD lpckid,
248         LPDWORD lpdwFlags,LONG lFrameNum,DWORD dwFrameSize,DWORD dwQuality,
249         LPBITMAPINFOHEADER lpbiPrev,LPVOID lpPrev
250 ) {
251         ICCOMPRESS      iccmp;
252
253         iccmp.dwFlags           = dwFlags;
254
255         iccmp.lpbiOutput        = lpbiOutput;
256         iccmp.lpOutput          = lpData;
257         iccmp.lpbiInput         = lpbiInput;
258         iccmp.lpInput           = lpBits;
259
260         iccmp.lpckid            = lpckid;
261         iccmp.lpdwFlags         = lpdwFlags;
262         iccmp.lFrameNum         = lFrameNum;
263         iccmp.dwFrameSize       = dwFrameSize;
264         iccmp.dwQuality         = dwQuality;
265         iccmp.lpbiPrev          = lpbiPrev;
266         iccmp.lpPrev            = lpPrev;
267         return ICSendMessage(hic,ICM_COMPRESS,(LPARAM)&iccmp,sizeof(iccmp));
268 }
269
270 /***********************************************************************
271  *              ICDecompress                    [MSVFW.26]
272  */
273 DWORD VFWAPIV 
274 ICDecompress(HIC hic,DWORD dwFlags,LPBITMAPINFOHEADER lpbiFormat,LPVOID lpData,LPBITMAPINFOHEADER  lpbi,LPVOID lpBits) {
275         ICDECOMPRESS    icd;
276
277         icd.dwFlags     = dwFlags;
278         icd.lpbiInput   = lpbiFormat;
279         icd.lpInput     = lpData;
280
281         icd.lpbiOutput  = lpbi;
282         icd.lpOutput    = lpBits;
283         icd.ckid        = 0;
284         return ICSendMessage(hic,ICM_DECOMPRESS,(LPARAM)&icd,sizeof(icd));
285 }
286
287 /***********************************************************************
288  *              ICSendMessage                   [MSVFW.40]
289  */
290 LRESULT VFWAPI
291 ICSendMessage(HIC hic,UINT msg,DWORD lParam1,DWORD lParam2) {
292         LRESULT         ret;
293         WINE_HIC        *whic = (WINE_HIC*)hic;
294
295 #define XX(x) case x: TRACE("(0x%08lx,"#x",0x%08lx,0x%08lx)\n",(DWORD)hic,lParam1,lParam2);break;
296
297         switch (msg) {
298         XX(ICM_ABOUT)
299         XX(ICM_GETINFO)
300         XX(ICM_COMPRESS_FRAMES_INFO)
301         XX(ICM_COMPRESS_GET_FORMAT)
302         XX(ICM_COMPRESS_GET_SIZE)
303         XX(ICM_COMPRESS_QUERY)
304         XX(ICM_COMPRESS_BEGIN)
305         XX(ICM_COMPRESS)
306         XX(ICM_COMPRESS_END)
307         XX(ICM_DECOMPRESS_GET_FORMAT)
308         XX(ICM_DECOMPRESS_QUERY)
309         XX(ICM_DECOMPRESS_BEGIN)
310         XX(ICM_DECOMPRESS)
311         XX(ICM_DECOMPRESS_END)
312         XX(ICM_DECOMPRESS_SET_PALETTE)
313         XX(ICM_DECOMPRESS_GET_PALETTE)
314         XX(ICM_DRAW_QUERY)
315         XX(ICM_DRAW_BEGIN)
316         XX(ICM_DRAW_GET_PALETTE)
317         XX(ICM_DRAW_START)
318         XX(ICM_DRAW_STOP)
319         XX(ICM_DRAW_END)
320         XX(ICM_DRAW_GETTIME)
321         XX(ICM_DRAW)
322         XX(ICM_DRAW_WINDOW)
323         XX(ICM_DRAW_SETTIME)
324         XX(ICM_DRAW_REALIZE)
325         XX(ICM_DRAW_FLUSH)
326         XX(ICM_DRAW_RENDERBUFFER)
327         XX(ICM_DRAW_START_PLAY)
328         XX(ICM_DRAW_STOP_PLAY)
329         XX(ICM_DRAW_SUGGESTFORMAT)
330         XX(ICM_DRAW_CHANGEPALETTE)
331         XX(ICM_GETBUFFERSWANTED)
332         XX(ICM_GETDEFAULTKEYFRAMERATE)
333         XX(ICM_DECOMPRESSEX_BEGIN)
334         XX(ICM_DECOMPRESSEX_QUERY)
335         XX(ICM_DECOMPRESSEX)
336         XX(ICM_DECOMPRESSEX_END)
337         XX(ICM_SET_STATUS_PROC)
338         default:
339                 FIXME("(0x%08lx,0x%08lx,0x%08lx,0x%08lx)\n",(DWORD)hic,(DWORD)msg,lParam1,lParam2);
340         }
341 #if 0
342         if (whic->driverproc) {
343                 FIXME("(0x%08lx,0x%08lx,0x%08lx,0x%08lx), calling %p\n",(DWORD)hic,(DWORD)msg,lParam1,lParam2,whic->driverproc);
344                 ret = whic->driverproc(whic->hdrv,1,msg,lParam1,lParam2);
345         } else
346 #endif
347                 ret = SendDriverMessage(whic->hdrv,msg,lParam1,lParam2);
348         TRACE(" -> 0x%08lx\n",ret);
349         return ret;
350 }
351
352 /***********************************************************************
353  *              ICDrawBegin             [MSVFW.28]
354  */
355 DWORD   VFWAPIV ICDrawBegin(
356         HIC                     hic,
357         DWORD                   dwFlags,/* flags */
358         HPALETTE                hpal,   /* palette to draw with */
359         HWND                    hwnd,   /* window to draw to */
360         HDC                     hdc,    /* HDC to draw to */
361         INT                     xDst,   /* destination rectangle */
362         INT                     yDst,
363         INT                     dxDst,
364         INT                     dyDst,
365         LPBITMAPINFOHEADER      lpbi,   /* format of frame to draw */
366         INT                     xSrc,   /* source rectangle */
367         INT                     ySrc,
368         INT                     dxSrc,
369         INT                     dySrc,
370         DWORD                   dwRate, /* frames/second = (dwRate/dwScale) */
371         DWORD                   dwScale) {
372         ICDRAWBEGIN     icdb;
373
374         icdb.dwFlags = dwFlags;
375         icdb.hpal = hpal;
376         icdb.hwnd = hwnd;
377         icdb.hdc = hdc;
378         icdb.xDst = xDst;
379         icdb.yDst = yDst;
380         icdb.dxDst = dxDst;
381         icdb.dyDst = dyDst;
382         icdb.lpbi = lpbi;
383         icdb.xSrc = xSrc;
384         icdb.ySrc = ySrc;
385         icdb.dxSrc = dxSrc;
386         icdb.dySrc = dySrc;
387         icdb.dwRate = dwRate;
388         icdb.dwScale = dwScale;
389         return ICSendMessage(hic,ICM_DRAW_BEGIN,(LPARAM)&icdb,sizeof(icdb));
390 }
391
392 /***********************************************************************
393  *              ICDraw                  [MSVFW.27]
394  */
395 DWORD VFWAPIV ICDraw(
396         HIC hic,DWORD dwFlags,LPVOID lpFormat,LPVOID lpData,DWORD cbData,
397         LONG lTime
398 ) {
399         ICDRAW  icd;
400
401         icd.dwFlags = dwFlags;
402         icd.lpFormat = lpFormat;
403         icd.lpData = lpData;
404         icd.cbData = cbData;
405         icd.lTime = lTime;
406         return ICSendMessage(hic,ICM_DRAW,(LPARAM)&icd,sizeof(icd));
407 }
408
409 /***********************************************************************
410  *              ICClose                 [MSVFW.22]
411  */
412 LRESULT WINAPI ICClose(HIC hic) {
413         WINE_HIC        *whic = (WINE_HIC*)hic;
414         TRACE("(%d).\n",hic);
415         /* FIXME: correct? */
416         CloseDriver(whic->hdrv,0,0);
417         HeapFree(GetProcessHeap(),0,whic);
418         return 0;
419 }
420
421 /***********************************************************************
422  *              DrawDibOpen             [MSVFW.10]
423  */
424 HDRAWDIB VFWAPI
425 DrawDibOpen( void ) {
426         FIXME("stub!\n");
427         return 0xdead;
428 }
429
430 /***********************************************************************
431  *              DrawDibClose            [MSVFW.5]
432  */
433 BOOL VFWAPI
434 DrawDibClose( HDRAWDIB hDib ) {
435        FIXME("stub!\n");
436        return TRUE;
437 }
438
439 /***********************************************************************
440  *              DrawDibBegin            [MSVFW.3]
441  */
442 BOOL VFWAPI DrawDibBegin(HDRAWDIB hdd,
443                                     HDC      hdc,
444                                     INT      dxDst,
445                                     INT      dyDst,
446                                     LPBITMAPINFOHEADER lpbi,
447                                     INT      dxSrc,
448                                     INT      dySrc,
449                                     UINT     wFlags) {
450         FIXME("(%d,0x%lx,%d,%d,%p,%d,%d,0x%08lx), stub!\n",
451                 hdd,(DWORD)hdc,dxDst,dyDst,lpbi,dxSrc,dySrc,(DWORD)wFlags
452         );
453         return TRUE;
454 }
455
456
457 /***********************************************************************
458  *              DrawDibSetPalette       [MSVFW.13]
459  */
460 BOOL VFWAPI
461 DrawDibSetPalette(HDRAWDIB hdd, HPALETTE hpal) {
462         FIXME("(%d,%d),stub!\n",hdd,hpal);
463         return TRUE;
464 }
465
466 /***********************************************************************
467  *              DrawDibRealize          [MSVFW.12]
468  */
469 UINT VFWAPI DrawDibRealize(HDRAWDIB hdd, HDC hdc, BOOL fBackground) {
470         FIXME("(0x%08lx,0x%08lx,%d),stub!\n",(DWORD)hdd,(DWORD)hdc,fBackground);
471         return 0;
472 }
473
474 /***********************************************************************
475  *              MCIWndCreate            [MSVFW.44]
476  */
477 HWND VFWAPIV MCIWndCreate (HWND hwndParent, HINSTANCE hInstance,
478                       DWORD dwStyle,LPVOID szFile)
479 {       FIXME("%x %x %lx %p\n",hwndParent, hInstance, dwStyle, szFile);
480         return 0;
481 }
482
483 /***********************************************************************
484  *              MCIWndCreateA           [MSVFW.45]
485  */
486 HWND VFWAPIV MCIWndCreateA(HWND hwndParent, HINSTANCE hInstance,
487                       DWORD dwStyle,LPCSTR szFile)
488 {       FIXME("%x %x %lx %s\n",hwndParent, hInstance, dwStyle, szFile);
489         return 0;
490 }
491
492 /***********************************************************************
493  *              MCIWndCreateW           [MSVFW.46]
494  */
495 HWND VFWAPIV MCIWndCreateW(HWND hwndParent, HINSTANCE hInstance,
496                       DWORD dwStyle,LPCWSTR szFile)
497 {       FIXME("%x %x %lx %s\n",hwndParent, hInstance, dwStyle, debugstr_w(szFile));
498         return 0;
499 }