1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
4 * Digital video MCI Wine Driver
6 * Copyright 1999, 2000 Eric POUECH
7 * Copyright 2003 Dmitry Timoshkov
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "private_mciavi.h"
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(mciavi);
29 static BOOL MCIAVI_GetInfoAudio(WINE_MCIAVI* wma, const MMCKINFO* mmckList, MMCKINFO *mmckStream)
33 mmioRead(wma->hFile, (LPSTR)&wma->ash_audio, sizeof(wma->ash_audio));
35 TRACE("ash.fccType='%c%c%c%c'\n", LOBYTE(LOWORD(wma->ash_audio.fccType)),
36 HIBYTE(LOWORD(wma->ash_audio.fccType)),
37 LOBYTE(HIWORD(wma->ash_audio.fccType)),
38 HIBYTE(HIWORD(wma->ash_audio.fccType)));
39 if (wma->ash_audio.fccHandler) /* not all streams specify a handler */
40 TRACE("ash.fccHandler='%c%c%c%c'\n", LOBYTE(LOWORD(wma->ash_audio.fccHandler)),
41 HIBYTE(LOWORD(wma->ash_audio.fccHandler)),
42 LOBYTE(HIWORD(wma->ash_audio.fccHandler)),
43 HIBYTE(HIWORD(wma->ash_audio.fccHandler)));
45 TRACE("ash.fccHandler=0, no handler specified\n");
46 TRACE("ash.dwFlags=%ld\n", wma->ash_audio.dwFlags);
47 TRACE("ash.wPriority=%d\n", wma->ash_audio.wPriority);
48 TRACE("ash.wLanguage=%d\n", wma->ash_audio.wLanguage);
49 TRACE("ash.dwInitialFrames=%ld\n", wma->ash_audio.dwInitialFrames);
50 TRACE("ash.dwScale=%ld\n", wma->ash_audio.dwScale);
51 TRACE("ash.dwRate=%ld\n", wma->ash_audio.dwRate);
52 TRACE("ash.dwStart=%ld\n", wma->ash_audio.dwStart);
53 TRACE("ash.dwLength=%ld\n", wma->ash_audio.dwLength);
54 TRACE("ash.dwSuggestedBufferSize=%ld\n", wma->ash_audio.dwSuggestedBufferSize);
55 TRACE("ash.dwQuality=%ld\n", wma->ash_audio.dwQuality);
56 TRACE("ash.dwSampleSize=%ld\n", wma->ash_audio.dwSampleSize);
57 TRACE("ash.rcFrame=(%d,%d,%d,%d)\n", wma->ash_audio.rcFrame.top, wma->ash_audio.rcFrame.left,
58 wma->ash_audio.rcFrame.bottom, wma->ash_audio.rcFrame.right);
60 /* rewind to the start of the stream */
61 mmioAscend(wma->hFile, mmckStream, 0);
63 mmckInfo.ckid = ckidSTREAMFORMAT;
64 if (mmioDescend(wma->hFile, &mmckInfo, mmckList, MMIO_FINDCHUNK) != 0) {
65 WARN("Can't find 'strf' chunk\n");
68 if (mmckInfo.cksize < sizeof(WAVEFORMAT)) {
69 WARN("Size of strf chunk (%ld) < audio format struct\n", mmckInfo.cksize);
72 wma->lpWaveFormat = HeapAlloc(GetProcessHeap(), 0, mmckInfo.cksize);
73 if (!wma->lpWaveFormat) {
74 WARN("Can't alloc WaveFormat\n");
78 mmioRead(wma->hFile, (LPSTR)wma->lpWaveFormat, mmckInfo.cksize);
80 TRACE("waveFormat.wFormatTag=%d\n", wma->lpWaveFormat->wFormatTag);
81 TRACE("waveFormat.nChannels=%d\n", wma->lpWaveFormat->nChannels);
82 TRACE("waveFormat.nSamplesPerSec=%ld\n", wma->lpWaveFormat->nSamplesPerSec);
83 TRACE("waveFormat.nAvgBytesPerSec=%ld\n", wma->lpWaveFormat->nAvgBytesPerSec);
84 TRACE("waveFormat.nBlockAlign=%d\n", wma->lpWaveFormat->nBlockAlign);
85 TRACE("waveFormat.wBitsPerSample=%d\n", wma->lpWaveFormat->wBitsPerSample);
86 if (mmckInfo.cksize >= sizeof(WAVEFORMATEX))
87 TRACE("waveFormat.cbSize=%d\n", wma->lpWaveFormat->cbSize);
92 static BOOL MCIAVI_GetInfoVideo(WINE_MCIAVI* wma, const MMCKINFO* mmckList, MMCKINFO* mmckStream)
96 mmioRead(wma->hFile, (LPSTR)&wma->ash_video, sizeof(wma->ash_video));
98 TRACE("ash.fccType='%c%c%c%c'\n", LOBYTE(LOWORD(wma->ash_video.fccType)),
99 HIBYTE(LOWORD(wma->ash_video.fccType)),
100 LOBYTE(HIWORD(wma->ash_video.fccType)),
101 HIBYTE(HIWORD(wma->ash_video.fccType)));
102 TRACE("ash.fccHandler='%c%c%c%c'\n", LOBYTE(LOWORD(wma->ash_video.fccHandler)),
103 HIBYTE(LOWORD(wma->ash_video.fccHandler)),
104 LOBYTE(HIWORD(wma->ash_video.fccHandler)),
105 HIBYTE(HIWORD(wma->ash_video.fccHandler)));
106 TRACE("ash.dwFlags=%ld\n", wma->ash_video.dwFlags);
107 TRACE("ash.wPriority=%d\n", wma->ash_video.wPriority);
108 TRACE("ash.wLanguage=%d\n", wma->ash_video.wLanguage);
109 TRACE("ash.dwInitialFrames=%ld\n", wma->ash_video.dwInitialFrames);
110 TRACE("ash.dwScale=%ld\n", wma->ash_video.dwScale);
111 TRACE("ash.dwRate=%ld\n", wma->ash_video.dwRate);
112 TRACE("ash.dwStart=%ld\n", wma->ash_video.dwStart);
113 TRACE("ash.dwLength=%ld\n", wma->ash_video.dwLength);
114 TRACE("ash.dwSuggestedBufferSize=%ld\n", wma->ash_video.dwSuggestedBufferSize);
115 TRACE("ash.dwQuality=%ld\n", wma->ash_video.dwQuality);
116 TRACE("ash.dwSampleSize=%ld\n", wma->ash_video.dwSampleSize);
117 TRACE("ash.rcFrame=(%d,%d,%d,%d)\n", wma->ash_video.rcFrame.top, wma->ash_video.rcFrame.left,
118 wma->ash_video.rcFrame.bottom, wma->ash_video.rcFrame.right);
120 /* rewind to the start of the stream */
121 mmioAscend(wma->hFile, mmckStream, 0);
123 mmckInfo.ckid = ckidSTREAMFORMAT;
124 if (mmioDescend(wma->hFile, &mmckInfo, mmckList, MMIO_FINDCHUNK) != 0) {
125 WARN("Can't find 'strf' chunk\n");
129 wma->inbih = HeapAlloc(GetProcessHeap(), 0, mmckInfo.cksize);
131 WARN("Can't alloc input BIH\n");
135 mmioRead(wma->hFile, (LPSTR)wma->inbih, mmckInfo.cksize);
137 TRACE("bih.biSize=%ld\n", wma->inbih->biSize);
138 TRACE("bih.biWidth=%ld\n", wma->inbih->biWidth);
139 TRACE("bih.biHeight=%ld\n", wma->inbih->biHeight);
140 TRACE("bih.biPlanes=%d\n", wma->inbih->biPlanes);
141 TRACE("bih.biBitCount=%d\n", wma->inbih->biBitCount);
142 TRACE("bih.biCompression=%lx\n", wma->inbih->biCompression);
143 TRACE("bih.biSizeImage=%ld\n", wma->inbih->biSizeImage);
144 TRACE("bih.biXPelsPerMeter=%ld\n", wma->inbih->biXPelsPerMeter);
145 TRACE("bih.biYPelsPerMeter=%ld\n", wma->inbih->biYPelsPerMeter);
146 TRACE("bih.biClrUsed=%ld\n", wma->inbih->biClrUsed);
147 TRACE("bih.biClrImportant=%ld\n", wma->inbih->biClrImportant);
149 wma->source.left = 0;
151 wma->source.right = wma->inbih->biWidth;
152 wma->source.bottom = wma->inbih->biHeight;
154 wma->dest = wma->source;
159 struct AviListBuild {
160 DWORD numVideoFrames;
161 DWORD numAudioAllocated;
162 DWORD numAudioBlocks;
167 static BOOL MCIAVI_AddFrame(WINE_MCIAVI* wma, LPMMCKINFO mmck,
168 struct AviListBuild* alb)
174 if (mmck->ckid == ckidAVIPADDING) return TRUE;
176 p = (const BYTE *)&mmck->ckid;
178 if (!isxdigit(p[0]) || !isxdigit(p[1]))
180 WARN("wrongly encoded stream #\n");
184 stream_n = (p[0] <= '9') ? (p[0] - '0') : (tolower(p[0]) - 'a' + 10);
186 stream_n |= (p[1] <= '9') ? (p[1] - '0') : (tolower(p[1]) - 'a' + 10);
188 TRACE("ckid %4.4s (stream #%ld)\n", (LPSTR)&mmck->ckid, stream_n);
190 /* Some (rare?) AVI files have video streams name XXYY where XX = stream number and YY = TWOCC
191 * of the last 2 characters of the biCompression member of the BITMAPINFOHEADER structure.
192 * Ex: fccHandler = IV32 & biCompression = IV32 => stream name = XX32
193 * fccHandler = MSVC & biCompression = CRAM => stream name = XXAM
194 * Another possibility is that these TWOCC are simply ignored.
195 * Default to cktypeDIBcompressed when this case happens.
197 twocc = TWOCCFromFOURCC(mmck->ckid);
198 if (twocc == TWOCCFromFOURCC(wma->inbih->biCompression))
199 twocc = cktypeDIBcompressed;
203 case cktypeDIBcompressed:
204 case cktypePALchange:
205 if (stream_n != wma->video_stream_n)
207 TRACE("data belongs to another video stream #%ld\n", stream_n);
211 TRACE("Adding video frame[%ld]: %ld bytes\n",
212 alb->numVideoFrames, mmck->cksize);
214 if (alb->numVideoFrames < wma->dwPlayableVideoFrames) {
215 wma->lpVideoIndex[alb->numVideoFrames].dwOffset = mmck->dwDataOffset;
216 wma->lpVideoIndex[alb->numVideoFrames].dwSize = mmck->cksize;
217 if (alb->inVideoSize < mmck->cksize)
218 alb->inVideoSize = mmck->cksize;
219 alb->numVideoFrames++;
221 WARN("Too many video frames\n");
224 case cktypeWAVEbytes:
225 if (stream_n != wma->audio_stream_n)
227 TRACE("data belongs to another audio stream #%ld\n", stream_n);
231 TRACE("Adding audio frame[%ld]: %ld bytes\n",
232 alb->numAudioBlocks, mmck->cksize);
233 if (wma->lpWaveFormat) {
234 if (alb->numAudioBlocks >= alb->numAudioAllocated) {
235 alb->numAudioAllocated += 32;
236 if (!wma->lpAudioIndex)
237 wma->lpAudioIndex = HeapAlloc(GetProcessHeap(), 0,
238 alb->numAudioAllocated * sizeof(struct MMIOPos));
240 wma->lpAudioIndex = HeapReAlloc(GetProcessHeap(), 0, wma->lpAudioIndex,
241 alb->numAudioAllocated * sizeof(struct MMIOPos));
242 if (!wma->lpAudioIndex) return FALSE;
244 wma->lpAudioIndex[alb->numAudioBlocks].dwOffset = mmck->dwDataOffset;
245 wma->lpAudioIndex[alb->numAudioBlocks].dwSize = mmck->cksize;
246 if (alb->inAudioSize < mmck->cksize)
247 alb->inAudioSize = mmck->cksize;
248 alb->numAudioBlocks++;
250 WARN("Wave chunk without wave format... discarding\n");
254 WARN("Unknown frame type %4.4s\n", (LPSTR)&mmck->ckid);
260 BOOL MCIAVI_GetInfo(WINE_MCIAVI* wma)
266 struct AviListBuild alb;
269 if (mmioDescend(wma->hFile, &ckMainRIFF, NULL, 0) != 0) {
270 WARN("Can't find 'RIFF' chunk\n");
274 if ((ckMainRIFF.ckid != FOURCC_RIFF) || (ckMainRIFF.fccType != formtypeAVI)) {
275 WARN("Can't find 'AVI ' chunk\n");
279 mmckHead.fccType = listtypeAVIHEADER;
280 if (mmioDescend(wma->hFile, &mmckHead, &ckMainRIFF, MMIO_FINDLIST) != 0) {
281 WARN("Can't find 'hdrl' list\n");
285 mmckInfo.ckid = ckidAVIMAINHDR;
286 if (mmioDescend(wma->hFile, &mmckInfo, &mmckHead, MMIO_FINDCHUNK) != 0) {
287 WARN("Can't find 'avih' chunk\n");
291 mmioRead(wma->hFile, (LPSTR)&wma->mah, sizeof(wma->mah));
293 TRACE("mah.dwMicroSecPerFrame=%ld\n", wma->mah.dwMicroSecPerFrame);
294 TRACE("mah.dwMaxBytesPerSec=%ld\n", wma->mah.dwMaxBytesPerSec);
295 TRACE("mah.dwPaddingGranularity=%ld\n", wma->mah.dwPaddingGranularity);
296 TRACE("mah.dwFlags=%ld\n", wma->mah.dwFlags);
297 TRACE("mah.dwTotalFrames=%ld\n", wma->mah.dwTotalFrames);
298 TRACE("mah.dwInitialFrames=%ld\n", wma->mah.dwInitialFrames);
299 TRACE("mah.dwStreams=%ld\n", wma->mah.dwStreams);
300 TRACE("mah.dwSuggestedBufferSize=%ld\n", wma->mah.dwSuggestedBufferSize);
301 TRACE("mah.dwWidth=%ld\n", wma->mah.dwWidth);
302 TRACE("mah.dwHeight=%ld\n", wma->mah.dwHeight);
304 mmioAscend(wma->hFile, &mmckInfo, 0);
306 TRACE("Start of streams\n");
307 wma->video_stream_n = 0;
308 wma->audio_stream_n = 0;
310 for (stream_n = 0; stream_n < wma->mah.dwStreams; stream_n++)
314 mmckList.fccType = listtypeSTREAMHEADER;
315 if (mmioDescend(wma->hFile, &mmckList, &mmckHead, MMIO_FINDLIST) != 0)
318 mmckStream.ckid = ckidSTREAMHEADER;
319 if (mmioDescend(wma->hFile, &mmckStream, &mmckList, MMIO_FINDCHUNK) != 0)
321 WARN("Can't find 'strh' chunk\n");
325 TRACE("Stream #%ld fccType %4.4s\n", stream_n, (LPSTR)&mmckStream.fccType);
327 if (mmckStream.fccType == streamtypeVIDEO)
329 TRACE("found video stream\n");
331 WARN("ignoring another video stream\n");
334 if (!MCIAVI_GetInfoVideo(wma, &mmckList, &mmckStream))
336 wma->video_stream_n = stream_n;
339 else if (mmckStream.fccType == streamtypeAUDIO)
341 TRACE("found audio stream\n");
342 if (wma->lpWaveFormat)
343 WARN("ignoring another audio stream\n");
346 if (!MCIAVI_GetInfoAudio(wma, &mmckList, &mmckStream))
348 wma->audio_stream_n = stream_n;
352 TRACE("Unsupported stream type %4.4s\n", (LPSTR)&mmckStream.fccType);
354 mmioAscend(wma->hFile, &mmckList, 0);
357 TRACE("End of streams\n");
359 mmioAscend(wma->hFile, &mmckHead, 0);
361 /* no need to read optional JUNK chunk */
363 mmckList.fccType = listtypeAVIMOVIE;
364 if (mmioDescend(wma->hFile, &mmckList, &ckMainRIFF, MMIO_FINDLIST) != 0) {
365 WARN("Can't find 'movi' list\n");
369 wma->dwPlayableVideoFrames = wma->mah.dwTotalFrames;
370 wma->lpVideoIndex = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
371 wma->dwPlayableVideoFrames * sizeof(struct MMIOPos));
372 if (!wma->lpVideoIndex) {
373 WARN("Can't alloc video index array\n");
376 wma->dwPlayableAudioBlocks = 0;
377 wma->lpAudioIndex = NULL;
379 alb.numAudioBlocks = alb.numVideoFrames = 0;
380 alb.inVideoSize = alb.inAudioSize = 0;
381 alb.numAudioAllocated = 0;
383 while (mmioDescend(wma->hFile, &mmckInfo, &mmckList, 0) == 0) {
384 if (mmckInfo.fccType == listtypeAVIRECORD) {
387 while (mmioDescend(wma->hFile, &tmp, &mmckInfo, 0) == 0) {
388 MCIAVI_AddFrame(wma, &tmp, &alb);
389 mmioAscend(wma->hFile, &tmp, 0);
392 MCIAVI_AddFrame(wma, &mmckInfo, &alb);
395 mmioAscend(wma->hFile, &mmckInfo, 0);
397 if (alb.numVideoFrames != wma->dwPlayableVideoFrames) {
398 WARN("Found %ld video frames (/%ld), reducing playable frames\n",
399 alb.numVideoFrames, wma->dwPlayableVideoFrames);
400 wma->dwPlayableVideoFrames = alb.numVideoFrames;
402 wma->dwPlayableAudioBlocks = alb.numAudioBlocks;
404 if (alb.inVideoSize > wma->ash_video.dwSuggestedBufferSize) {
405 WARN("inVideoSize=%ld suggestedSize=%ld\n", alb.inVideoSize, wma->ash_video.dwSuggestedBufferSize);
406 wma->ash_video.dwSuggestedBufferSize = alb.inVideoSize;
408 if (alb.inAudioSize > wma->ash_audio.dwSuggestedBufferSize) {
409 WARN("inAudioSize=%ld suggestedSize=%ld\n", alb.inAudioSize, wma->ash_audio.dwSuggestedBufferSize);
410 wma->ash_audio.dwSuggestedBufferSize = alb.inAudioSize;
413 wma->indata = HeapAlloc(GetProcessHeap(), 0, wma->ash_video.dwSuggestedBufferSize);
415 WARN("Can't alloc input buffer\n");
422 BOOL MCIAVI_OpenVideo(WINE_MCIAVI* wma)
426 FOURCC fcc = wma->ash_video.fccHandler;
428 TRACE("fcc %4.4s\n", (LPSTR)&fcc);
430 wma->dwCachedFrame = -1;
432 /* get the right handle */
433 if (fcc == mmioFOURCC('C','R','A','M')) fcc = mmioFOURCC('M','S','V','C');
435 /* try to get a decompressor for that type */
436 wma->hic = ICLocate(ICTYPE_VIDEO, fcc, wma->inbih, NULL, ICMODE_DECOMPRESS);
438 /* check for builtin DIB compressions */
439 fcc = wma->inbih->biCompression;
440 if ((fcc == mmioFOURCC('D','I','B',' ')) ||
441 (fcc == mmioFOURCC('R','L','E',' ')) ||
442 (fcc == BI_RGB) || (fcc == BI_RLE8) ||
443 (fcc == BI_RLE4) || (fcc == BI_BITFIELDS))
446 WARN("Can't locate codec for the file\n");
450 outSize = sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD);
452 wma->outbih = HeapAlloc(GetProcessHeap(), 0, outSize);
454 WARN("Can't alloc output BIH\n");
457 if (!ICGetDisplayFormat(wma->hic, wma->inbih, wma->outbih, 0, 0, 0)) {
458 WARN("Can't open decompressor\n");
462 TRACE("bih.biSize=%ld\n", wma->outbih->biSize);
463 TRACE("bih.biWidth=%ld\n", wma->outbih->biWidth);
464 TRACE("bih.biHeight=%ld\n", wma->outbih->biHeight);
465 TRACE("bih.biPlanes=%d\n", wma->outbih->biPlanes);
466 TRACE("bih.biBitCount=%d\n", wma->outbih->biBitCount);
467 TRACE("bih.biCompression=%lx\n", wma->outbih->biCompression);
468 TRACE("bih.biSizeImage=%ld\n", wma->outbih->biSizeImage);
469 TRACE("bih.biXPelsPerMeter=%ld\n", wma->outbih->biXPelsPerMeter);
470 TRACE("bih.biYPelsPerMeter=%ld\n", wma->outbih->biYPelsPerMeter);
471 TRACE("bih.biClrUsed=%ld\n", wma->outbih->biClrUsed);
472 TRACE("bih.biClrImportant=%ld\n", wma->outbih->biClrImportant);
474 wma->outdata = HeapAlloc(GetProcessHeap(), 0, wma->outbih->biSizeImage);
476 WARN("Can't alloc output buffer\n");
480 if (ICSendMessage(wma->hic, ICM_DECOMPRESS_BEGIN,
481 (DWORD)wma->inbih, (DWORD)wma->outbih) != ICERR_OK) {
482 WARN("Can't begin decompression\n");
487 hDC = wma->hWndPaint ? GetDC(wma->hWndPaint) : 0;
490 MCIAVI_PaintFrame(wma, hDC);
491 ReleaseDC(wma->hWndPaint, hDC);
496 static void CALLBACK MCIAVI_waveCallback(HWAVEOUT hwo, UINT uMsg, DWORD_PTR dwInstance,
497 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
499 WINE_MCIAVI *wma = (WINE_MCIAVI *)MCIAVI_mciGetOpenDev(dwInstance);
503 EnterCriticalSection(&wma->cs);
510 InterlockedIncrement(&wma->dwEventCount);
511 TRACE("Returning waveHdr=%lx\n", dwParam1);
512 SetEvent(wma->hEvent);
515 ERR("Unknown uMsg=%d\n", uMsg);
518 LeaveCriticalSection(&wma->cs);
521 DWORD MCIAVI_OpenAudio(WINE_MCIAVI* wma, unsigned* nHdr, LPWAVEHDR* pWaveHdr)
527 dwRet = waveOutOpen((HWAVEOUT *)&wma->hWave, WAVE_MAPPER, wma->lpWaveFormat,
528 (DWORD_PTR)MCIAVI_waveCallback, wma->wDevID, CALLBACK_FUNCTION);
530 TRACE("Can't open low level audio device %ld\n", dwRet);
531 dwRet = MCIERR_DEVICE_OPEN;
536 /* FIXME: should set up a heuristic to compute the number of wave headers
540 waveHdr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
541 *nHdr * (sizeof(WAVEHDR) + wma->ash_audio.dwSuggestedBufferSize));
543 TRACE("Can't alloc wave headers\n");
544 dwRet = MCIERR_DEVICE_OPEN;
548 for (i = 0; i < *nHdr; i++) {
549 /* other fields are zero:ed on allocation */
550 waveHdr[i].lpData = (char*)waveHdr +
551 *nHdr * sizeof(WAVEHDR) + i * wma->ash_audio.dwSuggestedBufferSize;
552 waveHdr[i].dwBufferLength = wma->ash_audio.dwSuggestedBufferSize;
553 if (waveOutPrepareHeader(wma->hWave, &waveHdr[i], sizeof(WAVEHDR))) {
554 dwRet = MCIERR_INTERNAL;
559 if (wma->dwCurrVideoFrame != 0 && wma->lpWaveFormat) {
560 FIXME("Should recompute dwCurrAudioBlock, except unsynchronized sound & video\n");
562 wma->dwCurrAudioBlock = 0;
564 wma->hEvent = CreateEventA(NULL, FALSE, FALSE, NULL);
565 wma->dwEventCount = *nHdr - 1;
571 void MCIAVI_PlayAudioBlocks(WINE_MCIAVI* wma, unsigned nHdr, LPWAVEHDR waveHdr)
573 if (!wma->lpAudioIndex)
575 TRACE("%ld (ec=%lu)\n", wma->lpAudioIndex[wma->dwCurrAudioBlock].dwOffset, wma->dwEventCount);
577 /* push as many blocks as possible => audio gets priority */
578 while (wma->dwStatus != MCI_MODE_STOP && wma->dwStatus != MCI_MODE_NOT_READY &&
579 wma->dwCurrAudioBlock < wma->dwPlayableAudioBlocks) {
580 unsigned whidx = wma->dwCurrAudioBlock % nHdr;
582 ResetEvent(wma->hEvent);
583 if (InterlockedDecrement(&wma->dwEventCount) < 0 ||
584 !wma->lpAudioIndex[wma->dwCurrAudioBlock].dwOffset)
586 InterlockedIncrement(&wma->dwEventCount);
590 mmioSeek(wma->hFile, wma->lpAudioIndex[wma->dwCurrAudioBlock].dwOffset, SEEK_SET);
591 mmioRead(wma->hFile, waveHdr[whidx].lpData, wma->lpAudioIndex[wma->dwCurrAudioBlock].dwSize);
593 waveHdr[whidx].dwFlags &= ~WHDR_DONE;
594 waveHdr[whidx].dwBufferLength = wma->lpAudioIndex[wma->dwCurrAudioBlock].dwSize;
595 waveOutWrite(wma->hWave, &waveHdr[whidx], sizeof(WAVEHDR));
596 wma->dwCurrAudioBlock++;
600 LRESULT MCIAVI_PaintFrame(WINE_MCIAVI* wma, HDC hDC)
602 void* pBitmapData = NULL;
603 LPBITMAPINFO pBitmapInfo = NULL;
609 if (!hDC || !wma->inbih)
612 TRACE("Painting frame %lu (cached %lu)\n", wma->dwCurrVideoFrame, wma->dwCachedFrame);
614 if (wma->dwCurrVideoFrame != wma->dwCachedFrame)
616 if (!wma->lpVideoIndex[wma->dwCurrVideoFrame].dwOffset)
619 if (wma->lpVideoIndex[wma->dwCurrVideoFrame].dwSize)
621 mmioSeek(wma->hFile, wma->lpVideoIndex[wma->dwCurrVideoFrame].dwOffset, SEEK_SET);
622 mmioRead(wma->hFile, wma->indata, wma->lpVideoIndex[wma->dwCurrVideoFrame].dwSize);
625 wma->inbih->biSizeImage = wma->lpVideoIndex[wma->dwCurrVideoFrame].dwSize;
627 if (wma->hic && ICDecompress(wma->hic, 0, wma->inbih, wma->indata,
628 wma->outbih, wma->outdata) != ICERR_OK)
630 WARN("Decompression error\n");
635 wma->dwCachedFrame = wma->dwCurrVideoFrame;
639 pBitmapData = wma->outdata;
640 pBitmapInfo = (LPBITMAPINFO)wma->outbih;
642 nWidth = wma->outbih->biWidth;
643 nHeight = wma->outbih->biHeight;
645 pBitmapData = wma->indata;
646 pBitmapInfo = (LPBITMAPINFO)wma->inbih;
648 nWidth = wma->inbih->biWidth;
649 nHeight = wma->inbih->biHeight;
653 wma->hbmFrame = CreateCompatibleBitmap(hDC, nWidth, nHeight);
655 SetDIBits(hDC, wma->hbmFrame, 0, nHeight, pBitmapData, pBitmapInfo, DIB_RGB_COLORS);
657 hdcMem = CreateCompatibleDC(hDC);
658 hbmOld = SelectObject(hdcMem, wma->hbmFrame);
661 wma->dest.left, wma->dest.top, wma->dest.right, wma->dest.bottom,
663 wma->source.left, wma->source.top, wma->source.right, wma->source.bottom,
666 SelectObject(hdcMem, hbmOld);