2 * Digital video MCI Wine Driver
4 * Copyright 1999, 2000 Eric POUECH
5 * Copyright 2003 Dmitry Timoshkov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "private_mciavi.h"
23 #include "wine/debug.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(mciavi
);
27 static BOOL
MCIAVI_GetInfoAudio(WINE_MCIAVI
* wma
, const MMCKINFO
* mmckList
, MMCKINFO
*mmckStream
)
31 TRACE("ash.fccType='%c%c%c%c'\n", LOBYTE(LOWORD(wma
->ash_audio
.fccType
)),
32 HIBYTE(LOWORD(wma
->ash_audio
.fccType
)),
33 LOBYTE(HIWORD(wma
->ash_audio
.fccType
)),
34 HIBYTE(HIWORD(wma
->ash_audio
.fccType
)));
35 if (wma
->ash_audio
.fccHandler
) /* not all streams specify a handler */
36 TRACE("ash.fccHandler='%c%c%c%c'\n", LOBYTE(LOWORD(wma
->ash_audio
.fccHandler
)),
37 HIBYTE(LOWORD(wma
->ash_audio
.fccHandler
)),
38 LOBYTE(HIWORD(wma
->ash_audio
.fccHandler
)),
39 HIBYTE(HIWORD(wma
->ash_audio
.fccHandler
)));
41 TRACE("ash.fccHandler=0, no handler specified\n");
42 TRACE("ash.dwFlags=%d\n", wma
->ash_audio
.dwFlags
);
43 TRACE("ash.wPriority=%d\n", wma
->ash_audio
.wPriority
);
44 TRACE("ash.wLanguage=%d\n", wma
->ash_audio
.wLanguage
);
45 TRACE("ash.dwInitialFrames=%d\n", wma
->ash_audio
.dwInitialFrames
);
46 TRACE("ash.dwScale=%d\n", wma
->ash_audio
.dwScale
);
47 TRACE("ash.dwRate=%d\n", wma
->ash_audio
.dwRate
);
48 TRACE("ash.dwStart=%d\n", wma
->ash_audio
.dwStart
);
49 TRACE("ash.dwLength=%d\n", wma
->ash_audio
.dwLength
);
50 TRACE("ash.dwSuggestedBufferSize=%d\n", wma
->ash_audio
.dwSuggestedBufferSize
);
51 TRACE("ash.dwQuality=%d\n", wma
->ash_audio
.dwQuality
);
52 TRACE("ash.dwSampleSize=%d\n", wma
->ash_audio
.dwSampleSize
);
53 TRACE("ash.rcFrame=(%d,%d,%d,%d)\n", wma
->ash_audio
.rcFrame
.top
, wma
->ash_audio
.rcFrame
.left
,
54 wma
->ash_audio
.rcFrame
.bottom
, wma
->ash_audio
.rcFrame
.right
);
56 /* rewind to the start of the stream */
57 mmioAscend(wma
->hFile
, mmckStream
, 0);
59 mmckInfo
.ckid
= ckidSTREAMFORMAT
;
60 if (mmioDescend(wma
->hFile
, &mmckInfo
, mmckList
, MMIO_FINDCHUNK
) != 0) {
61 WARN("Can't find 'strf' chunk\n");
64 if (mmckInfo
.cksize
< sizeof(WAVEFORMAT
)) {
65 WARN("Size of strf chunk (%d) < audio format struct\n", mmckInfo
.cksize
);
68 wma
->lpWaveFormat
= HeapAlloc(GetProcessHeap(), 0, mmckInfo
.cksize
);
69 if (!wma
->lpWaveFormat
) {
70 WARN("Can't alloc WaveFormat\n");
74 mmioRead(wma
->hFile
, (LPSTR
)wma
->lpWaveFormat
, mmckInfo
.cksize
);
76 TRACE("waveFormat.wFormatTag=%d\n", wma
->lpWaveFormat
->wFormatTag
);
77 TRACE("waveFormat.nChannels=%d\n", wma
->lpWaveFormat
->nChannels
);
78 TRACE("waveFormat.nSamplesPerSec=%d\n", wma
->lpWaveFormat
->nSamplesPerSec
);
79 TRACE("waveFormat.nAvgBytesPerSec=%d\n", wma
->lpWaveFormat
->nAvgBytesPerSec
);
80 TRACE("waveFormat.nBlockAlign=%d\n", wma
->lpWaveFormat
->nBlockAlign
);
81 TRACE("waveFormat.wBitsPerSample=%d\n", wma
->lpWaveFormat
->wBitsPerSample
);
82 if (mmckInfo
.cksize
>= sizeof(WAVEFORMATEX
))
83 TRACE("waveFormat.cbSize=%d\n", wma
->lpWaveFormat
->cbSize
);
88 static BOOL
MCIAVI_GetInfoVideo(WINE_MCIAVI
* wma
, const MMCKINFO
* mmckList
, MMCKINFO
* mmckStream
)
92 TRACE("ash.fccType='%c%c%c%c'\n", LOBYTE(LOWORD(wma
->ash_video
.fccType
)),
93 HIBYTE(LOWORD(wma
->ash_video
.fccType
)),
94 LOBYTE(HIWORD(wma
->ash_video
.fccType
)),
95 HIBYTE(HIWORD(wma
->ash_video
.fccType
)));
96 TRACE("ash.fccHandler='%c%c%c%c'\n", LOBYTE(LOWORD(wma
->ash_video
.fccHandler
)),
97 HIBYTE(LOWORD(wma
->ash_video
.fccHandler
)),
98 LOBYTE(HIWORD(wma
->ash_video
.fccHandler
)),
99 HIBYTE(HIWORD(wma
->ash_video
.fccHandler
)));
100 TRACE("ash.dwFlags=%d\n", wma
->ash_video
.dwFlags
);
101 TRACE("ash.wPriority=%d\n", wma
->ash_video
.wPriority
);
102 TRACE("ash.wLanguage=%d\n", wma
->ash_video
.wLanguage
);
103 TRACE("ash.dwInitialFrames=%d\n", wma
->ash_video
.dwInitialFrames
);
104 TRACE("ash.dwScale=%d\n", wma
->ash_video
.dwScale
);
105 TRACE("ash.dwRate=%d\n", wma
->ash_video
.dwRate
);
106 TRACE("ash.dwStart=%d\n", wma
->ash_video
.dwStart
);
107 TRACE("ash.dwLength=%d\n", wma
->ash_video
.dwLength
);
108 TRACE("ash.dwSuggestedBufferSize=%d\n", wma
->ash_video
.dwSuggestedBufferSize
);
109 TRACE("ash.dwQuality=%d\n", wma
->ash_video
.dwQuality
);
110 TRACE("ash.dwSampleSize=%d\n", wma
->ash_video
.dwSampleSize
);
111 TRACE("ash.rcFrame=(%d,%d,%d,%d)\n", wma
->ash_video
.rcFrame
.top
, wma
->ash_video
.rcFrame
.left
,
112 wma
->ash_video
.rcFrame
.bottom
, wma
->ash_video
.rcFrame
.right
);
114 /* rewind to the start of the stream */
115 mmioAscend(wma
->hFile
, mmckStream
, 0);
117 mmckInfo
.ckid
= ckidSTREAMFORMAT
;
118 if (mmioDescend(wma
->hFile
, &mmckInfo
, mmckList
, MMIO_FINDCHUNK
) != 0) {
119 WARN("Can't find 'strf' chunk\n");
123 wma
->inbih
= HeapAlloc(GetProcessHeap(), 0, mmckInfo
.cksize
);
125 WARN("Can't alloc input BIH\n");
129 mmioRead(wma
->hFile
, (LPSTR
)wma
->inbih
, mmckInfo
.cksize
);
131 TRACE("bih.biSize=%d\n", wma
->inbih
->biSize
);
132 TRACE("bih.biWidth=%d\n", wma
->inbih
->biWidth
);
133 TRACE("bih.biHeight=%d\n", wma
->inbih
->biHeight
);
134 TRACE("bih.biPlanes=%d\n", wma
->inbih
->biPlanes
);
135 TRACE("bih.biBitCount=%d\n", wma
->inbih
->biBitCount
);
136 TRACE("bih.biCompression=%x\n", wma
->inbih
->biCompression
);
137 TRACE("bih.biSizeImage=%d\n", wma
->inbih
->biSizeImage
);
138 TRACE("bih.biXPelsPerMeter=%d\n", wma
->inbih
->biXPelsPerMeter
);
139 TRACE("bih.biYPelsPerMeter=%d\n", wma
->inbih
->biYPelsPerMeter
);
140 TRACE("bih.biClrUsed=%d\n", wma
->inbih
->biClrUsed
);
141 TRACE("bih.biClrImportant=%d\n", wma
->inbih
->biClrImportant
);
143 wma
->source
.left
= 0;
145 wma
->source
.right
= wma
->inbih
->biWidth
;
146 wma
->source
.bottom
= wma
->inbih
->biHeight
;
148 wma
->dest
= wma
->source
;
153 struct AviListBuild
{
154 DWORD numVideoFrames
;
155 DWORD numAudioAllocated
;
156 DWORD numAudioBlocks
;
161 static BOOL
MCIAVI_AddFrame(WINE_MCIAVI
* wma
, LPMMCKINFO mmck
,
162 struct AviListBuild
* alb
)
168 if (mmck
->ckid
== ckidAVIPADDING
) return TRUE
;
170 p
= (const BYTE
*)&mmck
->ckid
;
172 if (!isxdigit(p
[0]) || !isxdigit(p
[1]))
174 WARN("wrongly encoded stream #\n");
178 stream_n
= (p
[0] <= '9') ? (p
[0] - '0') : (tolower(p
[0]) - 'a' + 10);
180 stream_n
|= (p
[1] <= '9') ? (p
[1] - '0') : (tolower(p
[1]) - 'a' + 10);
182 TRACE("ckid %4.4s (stream #%d)\n", (LPSTR
)&mmck
->ckid
, stream_n
);
184 /* Some (rare?) AVI files have video streams name XXYY where XX = stream number and YY = TWOCC
185 * of the last 2 characters of the biCompression member of the BITMAPINFOHEADER structure.
186 * Ex: fccHandler = IV32 & biCompression = IV32 => stream name = XX32
187 * fccHandler = MSVC & biCompression = CRAM => stream name = XXAM
188 * Another possibility is that these TWOCC are simply ignored.
189 * Default to cktypeDIBcompressed when this case happens.
191 twocc
= TWOCCFromFOURCC(mmck
->ckid
);
192 if (twocc
== TWOCCFromFOURCC(wma
->inbih
->biCompression
))
193 twocc
= cktypeDIBcompressed
;
197 case cktypeDIBcompressed
:
198 case cktypePALchange
:
199 if (stream_n
!= wma
->video_stream_n
)
201 TRACE("data belongs to another video stream #%d\n", stream_n
);
205 TRACE("Adding video frame[%d]: %d bytes\n",
206 alb
->numVideoFrames
, mmck
->cksize
);
208 if (alb
->numVideoFrames
< wma
->dwPlayableVideoFrames
) {
209 wma
->lpVideoIndex
[alb
->numVideoFrames
].dwOffset
= mmck
->dwDataOffset
;
210 wma
->lpVideoIndex
[alb
->numVideoFrames
].dwSize
= mmck
->cksize
;
211 if (alb
->inVideoSize
< mmck
->cksize
)
212 alb
->inVideoSize
= mmck
->cksize
;
213 alb
->numVideoFrames
++;
215 WARN("Too many video frames\n");
218 case cktypeWAVEbytes
:
219 if (stream_n
!= wma
->audio_stream_n
)
221 TRACE("data belongs to another audio stream #%d\n", stream_n
);
225 TRACE("Adding audio frame[%d]: %d bytes\n",
226 alb
->numAudioBlocks
, mmck
->cksize
);
227 if (wma
->lpWaveFormat
) {
228 if (alb
->numAudioBlocks
>= alb
->numAudioAllocated
) {
229 alb
->numAudioAllocated
+= 32;
230 if (!wma
->lpAudioIndex
)
231 wma
->lpAudioIndex
= HeapAlloc(GetProcessHeap(), 0,
232 alb
->numAudioAllocated
* sizeof(struct MMIOPos
));
234 wma
->lpAudioIndex
= HeapReAlloc(GetProcessHeap(), 0, wma
->lpAudioIndex
,
235 alb
->numAudioAllocated
* sizeof(struct MMIOPos
));
236 if (!wma
->lpAudioIndex
) return FALSE
;
238 wma
->lpAudioIndex
[alb
->numAudioBlocks
].dwOffset
= mmck
->dwDataOffset
;
239 wma
->lpAudioIndex
[alb
->numAudioBlocks
].dwSize
= mmck
->cksize
;
240 if (alb
->inAudioSize
< mmck
->cksize
)
241 alb
->inAudioSize
= mmck
->cksize
;
242 alb
->numAudioBlocks
++;
244 WARN("Wave chunk without wave format... discarding\n");
248 WARN("Unknown frame type %4.4s\n", (LPSTR
)&mmck
->ckid
);
254 BOOL
MCIAVI_GetInfo(WINE_MCIAVI
* wma
)
260 AVIStreamHeader strh
;
261 struct AviListBuild alb
;
264 if (mmioDescend(wma
->hFile
, &ckMainRIFF
, NULL
, 0) != 0) {
265 WARN("Can't find 'RIFF' chunk\n");
269 if ((ckMainRIFF
.ckid
!= FOURCC_RIFF
) || (ckMainRIFF
.fccType
!= formtypeAVI
)) {
270 WARN("Can't find 'AVI ' chunk\n");
274 mmckHead
.fccType
= listtypeAVIHEADER
;
275 if (mmioDescend(wma
->hFile
, &mmckHead
, &ckMainRIFF
, MMIO_FINDLIST
) != 0) {
276 WARN("Can't find 'hdrl' list\n");
280 mmckInfo
.ckid
= ckidAVIMAINHDR
;
281 if (mmioDescend(wma
->hFile
, &mmckInfo
, &mmckHead
, MMIO_FINDCHUNK
) != 0) {
282 WARN("Can't find 'avih' chunk\n");
286 mmioRead(wma
->hFile
, (LPSTR
)&wma
->mah
, sizeof(wma
->mah
));
288 TRACE("mah.dwMicroSecPerFrame=%d\n", wma
->mah
.dwMicroSecPerFrame
);
289 TRACE("mah.dwMaxBytesPerSec=%d\n", wma
->mah
.dwMaxBytesPerSec
);
290 TRACE("mah.dwPaddingGranularity=%d\n", wma
->mah
.dwPaddingGranularity
);
291 TRACE("mah.dwFlags=%d\n", wma
->mah
.dwFlags
);
292 TRACE("mah.dwTotalFrames=%d\n", wma
->mah
.dwTotalFrames
);
293 TRACE("mah.dwInitialFrames=%d\n", wma
->mah
.dwInitialFrames
);
294 TRACE("mah.dwStreams=%d\n", wma
->mah
.dwStreams
);
295 TRACE("mah.dwSuggestedBufferSize=%d\n", wma
->mah
.dwSuggestedBufferSize
);
296 TRACE("mah.dwWidth=%d\n", wma
->mah
.dwWidth
);
297 TRACE("mah.dwHeight=%d\n", wma
->mah
.dwHeight
);
299 mmioAscend(wma
->hFile
, &mmckInfo
, 0);
301 TRACE("Start of streams\n");
302 wma
->video_stream_n
= 0;
303 wma
->audio_stream_n
= 0;
305 for (stream_n
= 0; stream_n
< wma
->mah
.dwStreams
; stream_n
++)
309 mmckList
.fccType
= listtypeSTREAMHEADER
;
310 if (mmioDescend(wma
->hFile
, &mmckList
, &mmckHead
, MMIO_FINDLIST
) != 0)
313 mmckStream
.ckid
= ckidSTREAMHEADER
;
314 if (mmioDescend(wma
->hFile
, &mmckStream
, &mmckList
, MMIO_FINDCHUNK
) != 0)
316 WARN("Can't find 'strh' chunk\n");
320 mmioRead(wma
->hFile
, (LPSTR
)&strh
, sizeof(strh
));
322 TRACE("Stream #%d fccType %4.4s\n", stream_n
, (LPSTR
)&strh
.fccType
);
324 if (strh
.fccType
== streamtypeVIDEO
)
326 TRACE("found video stream\n");
328 WARN("ignoring another video stream\n");
331 wma
->ash_audio
= strh
;
333 if (!MCIAVI_GetInfoVideo(wma
, &mmckList
, &mmckStream
))
335 wma
->video_stream_n
= stream_n
;
338 else if (strh
.fccType
== streamtypeAUDIO
)
340 TRACE("found audio stream\n");
341 if (wma
->lpWaveFormat
)
342 WARN("ignoring another audio stream\n");
345 wma
->ash_video
= strh
;
347 if (!MCIAVI_GetInfoAudio(wma
, &mmckList
, &mmckStream
))
349 wma
->audio_stream_n
= stream_n
;
353 TRACE("Unsupported stream type %4.4s\n", (LPSTR
)&strh
.fccType
);
355 mmioAscend(wma
->hFile
, &mmckList
, 0);
358 TRACE("End of streams\n");
360 mmioAscend(wma
->hFile
, &mmckHead
, 0);
362 /* no need to read optional JUNK chunk */
364 mmckList
.fccType
= listtypeAVIMOVIE
;
365 if (mmioDescend(wma
->hFile
, &mmckList
, &ckMainRIFF
, MMIO_FINDLIST
) != 0) {
366 WARN("Can't find 'movi' list\n");
370 wma
->dwPlayableVideoFrames
= wma
->mah
.dwTotalFrames
;
371 wma
->lpVideoIndex
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
372 wma
->dwPlayableVideoFrames
* sizeof(struct MMIOPos
));
373 if (!wma
->lpVideoIndex
) {
374 WARN("Can't alloc video index array\n");
377 wma
->dwPlayableAudioBlocks
= 0;
378 wma
->lpAudioIndex
= NULL
;
380 alb
.numAudioBlocks
= alb
.numVideoFrames
= 0;
381 alb
.inVideoSize
= alb
.inAudioSize
= 0;
382 alb
.numAudioAllocated
= 0;
384 while (mmioDescend(wma
->hFile
, &mmckInfo
, &mmckList
, 0) == 0) {
385 if (mmckInfo
.fccType
== listtypeAVIRECORD
) {
388 while (mmioDescend(wma
->hFile
, &tmp
, &mmckInfo
, 0) == 0) {
389 MCIAVI_AddFrame(wma
, &tmp
, &alb
);
390 mmioAscend(wma
->hFile
, &tmp
, 0);
393 MCIAVI_AddFrame(wma
, &mmckInfo
, &alb
);
396 mmioAscend(wma
->hFile
, &mmckInfo
, 0);
398 if (alb
.numVideoFrames
!= wma
->dwPlayableVideoFrames
) {
399 WARN("Found %d video frames (/%d), reducing playable frames\n",
400 alb
.numVideoFrames
, wma
->dwPlayableVideoFrames
);
401 wma
->dwPlayableVideoFrames
= alb
.numVideoFrames
;
403 wma
->dwPlayableAudioBlocks
= alb
.numAudioBlocks
;
405 if (alb
.inVideoSize
> wma
->ash_video
.dwSuggestedBufferSize
) {
406 WARN("inVideoSize=%d suggestedSize=%d\n", alb
.inVideoSize
, wma
->ash_video
.dwSuggestedBufferSize
);
407 wma
->ash_video
.dwSuggestedBufferSize
= alb
.inVideoSize
;
409 if (alb
.inAudioSize
> wma
->ash_audio
.dwSuggestedBufferSize
) {
410 WARN("inAudioSize=%d suggestedSize=%d\n", alb
.inAudioSize
, wma
->ash_audio
.dwSuggestedBufferSize
);
411 wma
->ash_audio
.dwSuggestedBufferSize
= alb
.inAudioSize
;
414 wma
->indata
= HeapAlloc(GetProcessHeap(), 0, wma
->ash_video
.dwSuggestedBufferSize
);
416 WARN("Can't alloc input buffer\n");
423 BOOL
MCIAVI_OpenVideo(WINE_MCIAVI
* wma
)
427 FOURCC fcc
= wma
->ash_video
.fccHandler
;
429 TRACE("fcc %4.4s\n", (LPSTR
)&fcc
);
431 wma
->dwCachedFrame
= -1;
433 /* get the right handle */
434 if (fcc
== mmioFOURCC('C','R','A','M')) fcc
= mmioFOURCC('M','S','V','C');
436 /* try to get a decompressor for that type */
437 wma
->hic
= ICLocate(ICTYPE_VIDEO
, fcc
, wma
->inbih
, NULL
, ICMODE_DECOMPRESS
);
439 /* check for builtin DIB compressions */
440 fcc
= wma
->inbih
->biCompression
;
441 if ((fcc
== mmioFOURCC('D','I','B',' ')) ||
442 (fcc
== mmioFOURCC('R','L','E',' ')) ||
443 (fcc
== BI_RGB
) || (fcc
== BI_RLE8
) ||
444 (fcc
== BI_RLE4
) || (fcc
== BI_BITFIELDS
))
447 WARN("Can't locate codec for the file\n");
451 outSize
= sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
);
453 wma
->outbih
= HeapAlloc(GetProcessHeap(), 0, outSize
);
455 WARN("Can't alloc output BIH\n");
458 if (!ICGetDisplayFormat(wma
->hic
, wma
->inbih
, wma
->outbih
, 0, 0, 0)) {
459 WARN("Can't open decompressor\n");
463 TRACE("bih.biSize=%d\n", wma
->outbih
->biSize
);
464 TRACE("bih.biWidth=%d\n", wma
->outbih
->biWidth
);
465 TRACE("bih.biHeight=%d\n", wma
->outbih
->biHeight
);
466 TRACE("bih.biPlanes=%d\n", wma
->outbih
->biPlanes
);
467 TRACE("bih.biBitCount=%d\n", wma
->outbih
->biBitCount
);
468 TRACE("bih.biCompression=%x\n", wma
->outbih
->biCompression
);
469 TRACE("bih.biSizeImage=%d\n", wma
->outbih
->biSizeImage
);
470 TRACE("bih.biXPelsPerMeter=%d\n", wma
->outbih
->biXPelsPerMeter
);
471 TRACE("bih.biYPelsPerMeter=%d\n", wma
->outbih
->biYPelsPerMeter
);
472 TRACE("bih.biClrUsed=%d\n", wma
->outbih
->biClrUsed
);
473 TRACE("bih.biClrImportant=%d\n", wma
->outbih
->biClrImportant
);
475 wma
->outdata
= HeapAlloc(GetProcessHeap(), 0, wma
->outbih
->biSizeImage
);
477 WARN("Can't alloc output buffer\n");
481 if (ICSendMessage(wma
->hic
, ICM_DECOMPRESS_BEGIN
,
482 (DWORD_PTR
)wma
->inbih
, (DWORD_PTR
)wma
->outbih
) != ICERR_OK
) {
483 WARN("Can't begin decompression\n");
488 hDC
= wma
->hWndPaint
? GetDC(wma
->hWndPaint
) : 0;
491 MCIAVI_PaintFrame(wma
, hDC
);
492 ReleaseDC(wma
->hWndPaint
, hDC
);
497 static void CALLBACK
MCIAVI_waveCallback(HWAVEOUT hwo
, UINT uMsg
, DWORD_PTR dwInstance
,
498 DWORD_PTR dwParam1
, DWORD_PTR dwParam2
)
500 WINE_MCIAVI
*wma
= MCIAVI_mciGetOpenDev(dwInstance
);
504 EnterCriticalSection(&wma
->cs
);
511 InterlockedIncrement(&wma
->dwEventCount
);
512 TRACE("Returning waveHdr=%lx\n", dwParam1
);
513 SetEvent(wma
->hEvent
);
516 ERR("Unknown uMsg=%d\n", uMsg
);
519 LeaveCriticalSection(&wma
->cs
);
522 DWORD
MCIAVI_OpenAudio(WINE_MCIAVI
* wma
, unsigned* nHdr
, LPWAVEHDR
* pWaveHdr
)
528 dwRet
= waveOutOpen((HWAVEOUT
*)&wma
->hWave
, WAVE_MAPPER
, wma
->lpWaveFormat
,
529 (DWORD_PTR
)MCIAVI_waveCallback
, wma
->wDevID
, CALLBACK_FUNCTION
);
531 TRACE("Can't open low level audio device %d\n", dwRet
);
532 dwRet
= MCIERR_DEVICE_OPEN
;
537 /* FIXME: should set up a heuristic to compute the number of wave headers
541 waveHdr
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
542 *nHdr
* (sizeof(WAVEHDR
) + wma
->ash_audio
.dwSuggestedBufferSize
));
544 TRACE("Can't alloc wave headers\n");
545 dwRet
= MCIERR_DEVICE_OPEN
;
549 for (i
= 0; i
< *nHdr
; i
++) {
550 /* other fields are zero:ed on allocation */
551 waveHdr
[i
].lpData
= (char*)waveHdr
+
552 *nHdr
* sizeof(WAVEHDR
) + i
* wma
->ash_audio
.dwSuggestedBufferSize
;
553 waveHdr
[i
].dwBufferLength
= wma
->ash_audio
.dwSuggestedBufferSize
;
554 if (waveOutPrepareHeader(wma
->hWave
, &waveHdr
[i
], sizeof(WAVEHDR
))) {
555 dwRet
= MCIERR_INTERNAL
;
560 if (wma
->dwCurrVideoFrame
!= 0 && wma
->lpWaveFormat
) {
561 FIXME("Should recompute dwCurrAudioBlock, except unsynchronized sound & video\n");
563 wma
->dwCurrAudioBlock
= 0;
565 wma
->hEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
566 wma
->dwEventCount
= *nHdr
- 1;
572 void MCIAVI_PlayAudioBlocks(WINE_MCIAVI
* wma
, unsigned nHdr
, LPWAVEHDR waveHdr
)
574 if (!wma
->lpAudioIndex
)
576 TRACE("%d (ec=%u)\n", wma
->lpAudioIndex
[wma
->dwCurrAudioBlock
].dwOffset
, wma
->dwEventCount
);
578 /* push as many blocks as possible => audio gets priority */
579 while (wma
->dwStatus
!= MCI_MODE_STOP
&& wma
->dwStatus
!= MCI_MODE_NOT_READY
&&
580 wma
->dwCurrAudioBlock
< wma
->dwPlayableAudioBlocks
) {
581 unsigned whidx
= wma
->dwCurrAudioBlock
% nHdr
;
583 ResetEvent(wma
->hEvent
);
584 if (InterlockedDecrement(&wma
->dwEventCount
) < 0 ||
585 !wma
->lpAudioIndex
[wma
->dwCurrAudioBlock
].dwOffset
)
587 InterlockedIncrement(&wma
->dwEventCount
);
591 mmioSeek(wma
->hFile
, wma
->lpAudioIndex
[wma
->dwCurrAudioBlock
].dwOffset
, SEEK_SET
);
592 mmioRead(wma
->hFile
, waveHdr
[whidx
].lpData
, wma
->lpAudioIndex
[wma
->dwCurrAudioBlock
].dwSize
);
594 waveHdr
[whidx
].dwFlags
&= ~WHDR_DONE
;
595 waveHdr
[whidx
].dwBufferLength
= wma
->lpAudioIndex
[wma
->dwCurrAudioBlock
].dwSize
;
596 waveOutWrite(wma
->hWave
, &waveHdr
[whidx
], sizeof(WAVEHDR
));
597 wma
->dwCurrAudioBlock
++;
601 LRESULT
MCIAVI_PaintFrame(WINE_MCIAVI
* wma
, HDC hDC
)
604 LPBITMAPINFO pBitmapInfo
;
606 if (!hDC
|| !wma
->inbih
)
609 TRACE("Painting frame %u (cached %u)\n", wma
->dwCurrVideoFrame
, wma
->dwCachedFrame
);
611 if (wma
->dwCurrVideoFrame
!= wma
->dwCachedFrame
)
613 if (!wma
->lpVideoIndex
[wma
->dwCurrVideoFrame
].dwOffset
)
616 if (wma
->lpVideoIndex
[wma
->dwCurrVideoFrame
].dwSize
)
618 mmioSeek(wma
->hFile
, wma
->lpVideoIndex
[wma
->dwCurrVideoFrame
].dwOffset
, SEEK_SET
);
619 mmioRead(wma
->hFile
, wma
->indata
, wma
->lpVideoIndex
[wma
->dwCurrVideoFrame
].dwSize
);
621 wma
->inbih
->biSizeImage
= wma
->lpVideoIndex
[wma
->dwCurrVideoFrame
].dwSize
;
623 if (wma
->hic
&& ICDecompress(wma
->hic
, 0, wma
->inbih
, wma
->indata
,
624 wma
->outbih
, wma
->outdata
) != ICERR_OK
)
626 WARN("Decompression error\n");
631 wma
->dwCachedFrame
= wma
->dwCurrVideoFrame
;
635 pBitmapData
= wma
->outdata
;
636 pBitmapInfo
= (LPBITMAPINFO
)wma
->outbih
;
638 pBitmapData
= wma
->indata
;
639 pBitmapInfo
= (LPBITMAPINFO
)wma
->inbih
;
643 wma
->dest
.left
, wma
->dest
.top
,
644 wma
->dest
.right
- wma
->dest
.left
, wma
->dest
.bottom
- wma
->dest
.top
,
645 wma
->source
.left
, wma
->source
.top
,
646 wma
->source
.right
- wma
->source
.left
, wma
->source
.bottom
- wma
->source
.top
,
647 pBitmapData
, pBitmapInfo
, DIB_RGB_COLORS
, SRCCOPY
);