2001-02-14 22:49:22 +01:00
|
|
|
/* -*- tab-width: 8; c-basic-offset: 4 -*- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Digital video MCI Wine Driver
|
|
|
|
*
|
|
|
|
* Copyright 1999, 2000 Eric POUECH
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2001-02-14 22:49:22 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "private_mciavi.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2001-02-14 22:49:22 +01:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(mciavi);
|
2001-02-14 22:49:22 +01:00
|
|
|
|
|
|
|
static BOOL MCIAVI_GetInfoAudio(WINE_MCIAVI* wma, const MMCKINFO* mmckList)
|
|
|
|
{
|
|
|
|
MMCKINFO mmckInfo;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
mmckInfo.ckid = ckidSTREAMHEADER;
|
|
|
|
if (mmioDescend(wma->hFile, &mmckInfo, mmckList, MMIO_FINDCHUNK) != 0) {
|
|
|
|
WARN("Can't find 'strh' chunk\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
mmioRead(wma->hFile, (LPSTR)&wma->ash_audio, sizeof(wma->ash_audio));
|
2002-06-01 01:06:46 +02:00
|
|
|
|
|
|
|
TRACE("ash.fccType='%c%c%c%c'\n", LOBYTE(LOWORD(wma->ash_audio.fccType)),
|
|
|
|
HIBYTE(LOWORD(wma->ash_audio.fccType)),
|
|
|
|
LOBYTE(HIWORD(wma->ash_audio.fccType)),
|
2001-02-14 22:49:22 +01:00
|
|
|
HIBYTE(HIWORD(wma->ash_audio.fccType)));
|
2002-06-01 01:06:46 +02:00
|
|
|
TRACE("ash.fccHandler='%c%c%c%c'\n", LOBYTE(LOWORD(wma->ash_audio.fccHandler)),
|
|
|
|
HIBYTE(LOWORD(wma->ash_audio.fccHandler)),
|
|
|
|
LOBYTE(HIWORD(wma->ash_audio.fccHandler)),
|
2001-02-14 22:49:22 +01:00
|
|
|
HIBYTE(HIWORD(wma->ash_audio.fccHandler)));
|
|
|
|
TRACE("ash.dwFlags=%ld\n", wma->ash_audio.dwFlags);
|
|
|
|
TRACE("ash.wPriority=%d\n", wma->ash_audio.wPriority);
|
|
|
|
TRACE("ash.wLanguage=%d\n", wma->ash_audio.wLanguage);
|
|
|
|
TRACE("ash.dwInitialFrames=%ld\n", wma->ash_audio.dwInitialFrames);
|
|
|
|
TRACE("ash.dwScale=%ld\n", wma->ash_audio.dwScale);
|
|
|
|
TRACE("ash.dwRate=%ld\n", wma->ash_audio.dwRate);
|
|
|
|
TRACE("ash.dwStart=%ld\n", wma->ash_audio.dwStart);
|
|
|
|
TRACE("ash.dwLength=%ld\n", wma->ash_audio.dwLength);
|
|
|
|
TRACE("ash.dwSuggestedBufferSize=%ld\n", wma->ash_audio.dwSuggestedBufferSize);
|
|
|
|
TRACE("ash.dwQuality=%ld\n", wma->ash_audio.dwQuality);
|
|
|
|
TRACE("ash.dwSampleSize=%ld\n", wma->ash_audio.dwSampleSize);
|
2002-06-01 01:06:46 +02:00
|
|
|
TRACE("ash.rcFrame=(%d,%d,%d,%d)\n", wma->ash_audio.rcFrame.top, wma->ash_audio.rcFrame.left,
|
2001-02-14 22:49:22 +01:00
|
|
|
wma->ash_audio.rcFrame.bottom, wma->ash_audio.rcFrame.right);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
mmioAscend(wma->hFile, &mmckInfo, 0);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
mmckInfo.ckid = ckidSTREAMFORMAT;
|
|
|
|
if (mmioDescend(wma->hFile, &mmckInfo, mmckList, MMIO_FINDCHUNK) != 0) {
|
|
|
|
WARN("Can't find 'strh' chunk\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (mmckInfo.cksize < sizeof(WAVEFORMAT)) {
|
|
|
|
WARN("Size of strf chunk (%ld) < audio format struct\n", mmckInfo.cksize);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
wma->lpWaveFormat = HeapAlloc(GetProcessHeap(), 0, mmckInfo.cksize);
|
|
|
|
if (!wma->lpWaveFormat) {
|
|
|
|
WARN("Can't alloc WaveFormat\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
mmioRead(wma->hFile, (LPSTR)wma->lpWaveFormat, mmckInfo.cksize);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
TRACE("waveFormat.wFormatTag=%d\n", wma->lpWaveFormat->wFormatTag);
|
|
|
|
TRACE("waveFormat.nChannels=%d\n", wma->lpWaveFormat->nChannels);
|
|
|
|
TRACE("waveFormat.nSamplesPerSec=%ld\n", wma->lpWaveFormat->nSamplesPerSec);
|
|
|
|
TRACE("waveFormat.nAvgBytesPerSec=%ld\n", wma->lpWaveFormat->nAvgBytesPerSec);
|
|
|
|
TRACE("waveFormat.nBlockAlign=%d\n", wma->lpWaveFormat->nBlockAlign);
|
|
|
|
TRACE("waveFormat.wBitsPerSample=%d\n", wma->lpWaveFormat->wBitsPerSample);
|
|
|
|
if (mmckInfo.cksize >= sizeof(WAVEFORMATEX))
|
|
|
|
TRACE("waveFormat.cbSize=%d\n", wma->lpWaveFormat->cbSize);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
mmioAscend(wma->hFile, &mmckInfo, 0);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL MCIAVI_GetInfoVideo(WINE_MCIAVI* wma, const MMCKINFO* mmckList)
|
|
|
|
{
|
|
|
|
MMCKINFO mmckInfo;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
mmckInfo.ckid = ckidSTREAMHEADER;
|
|
|
|
if (mmioDescend(wma->hFile, &mmckInfo, mmckList, MMIO_FINDCHUNK) != 0) {
|
|
|
|
WARN("Can't find 'strh' chunk\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
mmioRead(wma->hFile, (LPSTR)&wma->ash_video, sizeof(wma->ash_video));
|
2002-06-01 01:06:46 +02:00
|
|
|
|
|
|
|
TRACE("ash.fccType='%c%c%c%c'\n", LOBYTE(LOWORD(wma->ash_video.fccType)),
|
|
|
|
HIBYTE(LOWORD(wma->ash_video.fccType)),
|
|
|
|
LOBYTE(HIWORD(wma->ash_video.fccType)),
|
2001-02-14 22:49:22 +01:00
|
|
|
HIBYTE(HIWORD(wma->ash_video.fccType)));
|
2002-06-01 01:06:46 +02:00
|
|
|
TRACE("ash.fccHandler='%c%c%c%c'\n", LOBYTE(LOWORD(wma->ash_video.fccHandler)),
|
|
|
|
HIBYTE(LOWORD(wma->ash_video.fccHandler)),
|
|
|
|
LOBYTE(HIWORD(wma->ash_video.fccHandler)),
|
2001-02-14 22:49:22 +01:00
|
|
|
HIBYTE(HIWORD(wma->ash_video.fccHandler)));
|
|
|
|
TRACE("ash.dwFlags=%ld\n", wma->ash_video.dwFlags);
|
|
|
|
TRACE("ash.wPriority=%d\n", wma->ash_video.wPriority);
|
|
|
|
TRACE("ash.wLanguage=%d\n", wma->ash_video.wLanguage);
|
|
|
|
TRACE("ash.dwInitialFrames=%ld\n", wma->ash_video.dwInitialFrames);
|
|
|
|
TRACE("ash.dwScale=%ld\n", wma->ash_video.dwScale);
|
|
|
|
TRACE("ash.dwRate=%ld\n", wma->ash_video.dwRate);
|
|
|
|
TRACE("ash.dwStart=%ld\n", wma->ash_video.dwStart);
|
|
|
|
TRACE("ash.dwLength=%ld\n", wma->ash_video.dwLength);
|
|
|
|
TRACE("ash.dwSuggestedBufferSize=%ld\n", wma->ash_video.dwSuggestedBufferSize);
|
|
|
|
TRACE("ash.dwQuality=%ld\n", wma->ash_video.dwQuality);
|
|
|
|
TRACE("ash.dwSampleSize=%ld\n", wma->ash_video.dwSampleSize);
|
2002-06-01 01:06:46 +02:00
|
|
|
TRACE("ash.rcFrame=(%d,%d,%d,%d)\n", wma->ash_video.rcFrame.top, wma->ash_video.rcFrame.left,
|
2001-02-14 22:49:22 +01:00
|
|
|
wma->ash_video.rcFrame.bottom, wma->ash_video.rcFrame.right);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
mmioAscend(wma->hFile, &mmckInfo, 0);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
mmckInfo.ckid = ckidSTREAMFORMAT;
|
|
|
|
if (mmioDescend(wma->hFile, &mmckInfo, mmckList, MMIO_FINDCHUNK) != 0) {
|
|
|
|
WARN("Can't find 'strh' chunk\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
wma->inbih = HeapAlloc(GetProcessHeap(), 0, mmckInfo.cksize);
|
|
|
|
if (!wma->inbih) {
|
|
|
|
WARN("Can't alloc input BIH\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
mmioRead(wma->hFile, (LPSTR)wma->inbih, mmckInfo.cksize);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
TRACE("bih.biSize=%ld\n", wma->inbih->biSize);
|
|
|
|
TRACE("bih.biWidth=%ld\n", wma->inbih->biWidth);
|
|
|
|
TRACE("bih.biHeight=%ld\n", wma->inbih->biHeight);
|
|
|
|
TRACE("bih.biPlanes=%d\n", wma->inbih->biPlanes);
|
|
|
|
TRACE("bih.biBitCount=%d\n", wma->inbih->biBitCount);
|
|
|
|
TRACE("bih.biCompression=%lx\n", wma->inbih->biCompression);
|
|
|
|
TRACE("bih.biSizeImage=%ld\n", wma->inbih->biSizeImage);
|
|
|
|
TRACE("bih.biXPelsPerMeter=%ld\n", wma->inbih->biXPelsPerMeter);
|
|
|
|
TRACE("bih.biYPelsPerMeter=%ld\n", wma->inbih->biYPelsPerMeter);
|
|
|
|
TRACE("bih.biClrUsed=%ld\n", wma->inbih->biClrUsed);
|
|
|
|
TRACE("bih.biClrImportant=%ld\n", wma->inbih->biClrImportant);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
mmioAscend(wma->hFile, &mmckInfo, 0);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct AviListBuild {
|
|
|
|
DWORD numVideoFrames;
|
|
|
|
DWORD numAudioAllocated;
|
|
|
|
DWORD numAudioBlocks;
|
|
|
|
DWORD inVideoSize;
|
|
|
|
DWORD inAudioSize;
|
|
|
|
};
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
static BOOL MCIAVI_AddFrame(WINE_MCIAVI* wma, LPMMCKINFO mmck,
|
2001-02-14 22:49:22 +01:00
|
|
|
struct AviListBuild* alb)
|
|
|
|
{
|
|
|
|
if (mmck->ckid == ckidAVIPADDING) return TRUE;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
switch (TWOCCFromFOURCC(mmck->ckid)) {
|
|
|
|
case cktypeDIBbits:
|
|
|
|
case cktypeDIBcompressed:
|
|
|
|
case cktypePALchange:
|
2002-06-01 01:06:46 +02:00
|
|
|
TRACE("Adding video frame[%ld]: %ld bytes\n",
|
2001-02-14 22:49:22 +01:00
|
|
|
alb->numVideoFrames, mmck->cksize);
|
|
|
|
if (alb->numVideoFrames < wma->dwPlayableVideoFrames) {
|
|
|
|
wma->lpVideoIndex[alb->numVideoFrames].dwOffset = mmck->dwDataOffset;
|
|
|
|
wma->lpVideoIndex[alb->numVideoFrames].dwSize = mmck->cksize;
|
|
|
|
if (alb->inVideoSize < mmck->cksize)
|
|
|
|
alb->inVideoSize = mmck->cksize;
|
|
|
|
alb->numVideoFrames++;
|
|
|
|
} else {
|
|
|
|
WARN("Too many video frames\n");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case cktypeWAVEbytes:
|
2002-06-01 01:06:46 +02:00
|
|
|
TRACE("Adding audio frame[%ld]: %ld bytes\n",
|
2001-02-14 22:49:22 +01:00
|
|
|
alb->numAudioBlocks, mmck->cksize);
|
|
|
|
if (wma->lpWaveFormat) {
|
|
|
|
if (alb->numAudioBlocks >= alb->numAudioAllocated) {
|
|
|
|
alb->numAudioAllocated += 32;
|
2002-06-01 01:06:46 +02:00
|
|
|
wma->lpAudioIndex = HeapReAlloc(GetProcessHeap(), 0,
|
|
|
|
wma->lpAudioIndex,
|
2001-02-14 22:49:22 +01:00
|
|
|
alb->numAudioAllocated * sizeof(struct MMIOPos));
|
|
|
|
if (!wma->lpAudioIndex) return FALSE;
|
|
|
|
}
|
|
|
|
wma->lpAudioIndex[alb->numAudioBlocks].dwOffset = mmck->dwDataOffset;
|
|
|
|
wma->lpAudioIndex[alb->numAudioBlocks].dwSize = mmck->cksize;
|
|
|
|
if (alb->inAudioSize < mmck->cksize)
|
|
|
|
alb->inAudioSize = mmck->cksize;
|
|
|
|
alb->numAudioBlocks++;
|
|
|
|
} else {
|
|
|
|
WARN("Wave chunk without wave format... discarding\n");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WARN("Unknown frame type %04x\n", TWOCCFromFOURCC(mmck->ckid));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL MCIAVI_GetInfo(WINE_MCIAVI* wma)
|
|
|
|
{
|
|
|
|
MMCKINFO ckMainRIFF;
|
|
|
|
MMCKINFO mmckHead;
|
|
|
|
MMCKINFO mmckList;
|
|
|
|
MMCKINFO mmckInfo;
|
|
|
|
struct AviListBuild alb;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
if (mmioDescend(wma->hFile, &ckMainRIFF, NULL, 0) != 0) {
|
|
|
|
WARN("Can't find 'RIFF' chunk\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
if ((ckMainRIFF.ckid != FOURCC_RIFF) || (ckMainRIFF.fccType != formtypeAVI)) {
|
|
|
|
WARN("Can't find 'AVI ' chunk\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
mmckHead.fccType = listtypeAVIHEADER;
|
|
|
|
if (mmioDescend(wma->hFile, &mmckHead, &ckMainRIFF, MMIO_FINDLIST) != 0) {
|
|
|
|
WARN("Can't find 'hdrl' list\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
mmckInfo.ckid = ckidAVIMAINHDR;
|
|
|
|
if (mmioDescend(wma->hFile, &mmckInfo, &mmckHead, MMIO_FINDCHUNK) != 0) {
|
|
|
|
WARN("Can't find 'avih' chunk\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
mmioRead(wma->hFile, (LPSTR)&wma->mah, sizeof(wma->mah));
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
TRACE("mah.dwMicroSecPerFrame=%ld\n", wma->mah.dwMicroSecPerFrame);
|
|
|
|
TRACE("mah.dwMaxBytesPerSec=%ld\n", wma->mah.dwMaxBytesPerSec);
|
|
|
|
TRACE("mah.dwPaddingGranularity=%ld\n", wma->mah.dwPaddingGranularity);
|
|
|
|
TRACE("mah.dwFlags=%ld\n", wma->mah.dwFlags);
|
|
|
|
TRACE("mah.dwTotalFrames=%ld\n", wma->mah.dwTotalFrames);
|
|
|
|
TRACE("mah.dwInitialFrames=%ld\n", wma->mah.dwInitialFrames);
|
|
|
|
TRACE("mah.dwStreams=%ld\n", wma->mah.dwStreams);
|
|
|
|
TRACE("mah.dwSuggestedBufferSize=%ld\n", wma->mah.dwSuggestedBufferSize);
|
|
|
|
TRACE("mah.dwWidth=%ld\n", wma->mah.dwWidth);
|
|
|
|
TRACE("mah.dwHeight=%ld\n", wma->mah.dwHeight);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
mmioAscend(wma->hFile, &mmckInfo, 0);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
mmckList.fccType = listtypeSTREAMHEADER;
|
|
|
|
if (mmioDescend(wma->hFile, &mmckList, &mmckHead, MMIO_FINDLIST) != 0) {
|
|
|
|
WARN("Can't find 'strl' list\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
if (!MCIAVI_GetInfoVideo(wma, &mmckList)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
mmioAscend(wma->hFile, &mmckList, 0);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
mmckList.fccType = listtypeSTREAMHEADER;
|
|
|
|
if (mmioDescend(wma->hFile, &mmckList, &mmckHead, MMIO_FINDLIST) == 0) {
|
|
|
|
if (!MCIAVI_GetInfoAudio(wma, &mmckList)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
mmioAscend(wma->hFile, &mmckList, 0);
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
mmioAscend(wma->hFile, &mmckHead, 0);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
/* no need to read optional JUNK chunk */
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
mmckList.fccType = listtypeAVIMOVIE;
|
|
|
|
if (mmioDescend(wma->hFile, &mmckList, &ckMainRIFF, MMIO_FINDLIST) != 0) {
|
|
|
|
WARN("Can't find 'movi' list\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
wma->dwPlayableVideoFrames = wma->mah.dwTotalFrames;
|
2002-06-01 01:06:46 +02:00
|
|
|
wma->lpVideoIndex = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
2001-02-14 22:49:22 +01:00
|
|
|
wma->dwPlayableVideoFrames * sizeof(struct MMIOPos));
|
|
|
|
if (!wma->lpVideoIndex) {
|
|
|
|
WARN("Can't alloc video index array\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
wma->dwPlayableAudioBlocks = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
wma->lpAudioIndex = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
2001-02-14 22:49:22 +01:00
|
|
|
wma->dwPlayableVideoFrames * sizeof(struct MMIOPos));
|
|
|
|
if (!wma->lpAudioIndex) {
|
|
|
|
WARN("Can't alloc audio index array\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
alb.numAudioBlocks = alb.numVideoFrames = 0;
|
|
|
|
alb.inVideoSize = alb.inAudioSize = 0;
|
|
|
|
alb.numAudioAllocated = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
while (mmioDescend(wma->hFile, &mmckInfo, &mmckList, 0) == 0) {
|
2002-06-01 01:06:46 +02:00
|
|
|
if (mmckInfo.fccType == listtypeAVIRECORD) {
|
2001-02-14 22:49:22 +01:00
|
|
|
MMCKINFO tmp;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
while (mmioDescend(wma->hFile, &tmp, &mmckInfo, 0) == 0) {
|
|
|
|
MCIAVI_AddFrame(wma, &tmp, &alb);
|
|
|
|
mmioAscend(wma->hFile, &tmp, 0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
MCIAVI_AddFrame(wma, &mmckInfo, &alb);
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
mmioAscend(wma->hFile, &mmckInfo, 0);
|
|
|
|
}
|
|
|
|
if (alb.numVideoFrames != wma->dwPlayableVideoFrames) {
|
2002-06-01 01:06:46 +02:00
|
|
|
WARN("Found %ld video frames (/%ld), reducing playable frames\n",
|
2001-02-14 22:49:22 +01:00
|
|
|
alb.numVideoFrames, wma->dwPlayableVideoFrames);
|
|
|
|
wma->dwPlayableVideoFrames = alb.numVideoFrames;
|
|
|
|
}
|
|
|
|
wma->dwPlayableAudioBlocks = alb.numAudioBlocks;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
if (alb.inVideoSize > wma->ash_video.dwSuggestedBufferSize) {
|
|
|
|
WARN("inVideoSize=%ld suggestedSize=%ld\n", alb.inVideoSize, wma->ash_video.dwSuggestedBufferSize);
|
|
|
|
wma->ash_video.dwSuggestedBufferSize = alb.inVideoSize;
|
|
|
|
}
|
|
|
|
if (alb.inAudioSize > wma->ash_audio.dwSuggestedBufferSize) {
|
|
|
|
WARN("inAudioSize=%ld suggestedSize=%ld\n", alb.inAudioSize, wma->ash_audio.dwSuggestedBufferSize);
|
|
|
|
wma->ash_audio.dwSuggestedBufferSize = alb.inAudioSize;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
wma->indata = HeapAlloc(GetProcessHeap(), 0, wma->ash_video.dwSuggestedBufferSize);
|
|
|
|
if (!wma->indata) {
|
|
|
|
WARN("Can't alloc input buffer\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL MCIAVI_OpenVideo(WINE_MCIAVI* wma)
|
|
|
|
{
|
|
|
|
DWORD outSize;
|
|
|
|
FOURCC fcc = wma->ash_video.fccHandler;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
/* check uncompressed AVI */
|
2002-06-01 01:06:46 +02:00
|
|
|
if ((fcc == mmioFOURCC('D','I','B',' ')) ||
|
2001-02-14 22:49:22 +01:00
|
|
|
(fcc == mmioFOURCC('R','L','E',' '))) {
|
2002-06-01 01:06:46 +02:00
|
|
|
wma->hic = 0;
|
2001-02-14 22:49:22 +01:00
|
|
|
MCIAVI_DrawFrame(wma);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
/* get the right handle */
|
|
|
|
if (fcc == 0) fcc = wma->inbih->biCompression;
|
|
|
|
if (fcc == mmioFOURCC('C','R','A','M')) fcc = mmioFOURCC('M','S','V','C');
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
/* try to get a decompressor for that type */
|
|
|
|
wma->hic = ICLocate(ICTYPE_VIDEO, fcc, wma->inbih, NULL, ICMODE_DECOMPRESS);
|
|
|
|
if (!wma->hic) {
|
|
|
|
WARN("Can't locate codec for the file\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
outSize = sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
wma->outbih = HeapAlloc(GetProcessHeap(), 0, outSize);
|
|
|
|
if (!wma->outbih) {
|
|
|
|
WARN("Can't alloc output BIH\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!ICGetDisplayFormat(wma->hic, wma->inbih, wma->outbih, 0, 0, 0)) {
|
|
|
|
WARN("Can't open decompressor\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
TRACE("bih.biSize=%ld\n", wma->outbih->biSize);
|
|
|
|
TRACE("bih.biWidth=%ld\n", wma->outbih->biWidth);
|
|
|
|
TRACE("bih.biHeight=%ld\n", wma->outbih->biHeight);
|
|
|
|
TRACE("bih.biPlanes=%d\n", wma->outbih->biPlanes);
|
|
|
|
TRACE("bih.biBitCount=%d\n", wma->outbih->biBitCount);
|
|
|
|
TRACE("bih.biCompression=%lx\n", wma->outbih->biCompression);
|
|
|
|
TRACE("bih.biSizeImage=%ld\n", wma->outbih->biSizeImage);
|
|
|
|
TRACE("bih.biXPelsPerMeter=%ld\n", wma->outbih->biXPelsPerMeter);
|
|
|
|
TRACE("bih.biYPelsPerMeter=%ld\n", wma->outbih->biYPelsPerMeter);
|
|
|
|
TRACE("bih.biClrUsed=%ld\n", wma->outbih->biClrUsed);
|
|
|
|
TRACE("bih.biClrImportant=%ld\n", wma->outbih->biClrImportant);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
wma->outdata = HeapAlloc(GetProcessHeap(), 0, wma->outbih->biSizeImage);
|
|
|
|
if (!wma->outdata) {
|
|
|
|
WARN("Can't alloc output buffer\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
|
|
|
if (ICSendMessage(wma->hic, ICM_DECOMPRESS_BEGIN,
|
2001-02-14 22:49:22 +01:00
|
|
|
(DWORD)wma->inbih, (DWORD)wma->outbih) != ICERR_OK) {
|
|
|
|
WARN("Can't begin decompression\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
MCIAVI_DrawFrame(wma);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
static void CALLBACK MCIAVI_waveCallback(HWAVEOUT hwo, UINT uMsg, DWORD dwInstance,
|
2001-02-14 22:49:22 +01:00
|
|
|
DWORD dwParam1, DWORD dwParam2)
|
|
|
|
{
|
|
|
|
WINE_MCIAVI* wma = (WINE_MCIAVI*)dwInstance;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
switch (uMsg) {
|
|
|
|
case WOM_OPEN:
|
|
|
|
case WOM_CLOSE:
|
|
|
|
break;
|
|
|
|
case WOM_DONE:
|
|
|
|
InterlockedIncrement(&wma->dwEventCount);
|
|
|
|
TRACE("Returning waveHdr=%lx\n", dwParam1);
|
|
|
|
SetEvent(wma->hEvent);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("Unknown uMsg=%d\n", uMsg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD MCIAVI_OpenAudio(WINE_MCIAVI* wma, unsigned* nHdr, LPWAVEHDR* pWaveHdr)
|
|
|
|
{
|
|
|
|
DWORD dwRet;
|
|
|
|
LPWAVEHDR waveHdr;
|
|
|
|
unsigned i;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-10-19 19:20:02 +02:00
|
|
|
dwRet = waveOutOpen((HWAVEOUT *)&wma->hWave, WAVE_MAPPER, wma->lpWaveFormat,
|
2001-02-14 22:49:22 +01:00
|
|
|
(DWORD)MCIAVI_waveCallback, (DWORD)wma, CALLBACK_FUNCTION);
|
|
|
|
if (dwRet != 0) {
|
|
|
|
TRACE("Can't open low level audio device %ld\n", dwRet);
|
|
|
|
dwRet = MCIERR_DEVICE_OPEN;
|
|
|
|
wma->hWave = 0;
|
|
|
|
goto cleanUp;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
/* FIXME: should set up a heuristic to compute the number of wave headers
|
|
|
|
* to be used...
|
|
|
|
*/
|
|
|
|
*nHdr = 7;
|
2002-06-01 01:06:46 +02:00
|
|
|
waveHdr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
2001-02-14 22:49:22 +01:00
|
|
|
*nHdr * (sizeof(WAVEHDR) + wma->ash_audio.dwSuggestedBufferSize));
|
|
|
|
if (!waveHdr) {
|
|
|
|
TRACE("Can't alloc wave headers\n");
|
|
|
|
dwRet = MCIERR_DEVICE_OPEN;
|
|
|
|
goto cleanUp;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
for (i = 0; i < *nHdr; i++) {
|
|
|
|
/* other fields are zero:ed on allocation */
|
2002-06-01 01:06:46 +02:00
|
|
|
waveHdr[i].lpData = (char*)waveHdr +
|
2001-02-14 22:49:22 +01:00
|
|
|
*nHdr * sizeof(WAVEHDR) + i * wma->ash_audio.dwSuggestedBufferSize;
|
|
|
|
waveHdr[i].dwBufferLength = wma->ash_audio.dwSuggestedBufferSize;
|
|
|
|
if (waveOutPrepareHeader(wma->hWave, &waveHdr[i], sizeof(WAVEHDR))) {
|
|
|
|
dwRet = MCIERR_INTERNAL;
|
|
|
|
goto cleanUp;
|
|
|
|
}
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
if (wma->dwCurrVideoFrame != 0 && wma->lpWaveFormat) {
|
2001-05-09 19:31:31 +02:00
|
|
|
FIXME("Should recompute dwCurrAudioBlock, except unsynchronized sound & video\n");
|
2001-02-14 22:49:22 +01:00
|
|
|
}
|
|
|
|
wma->dwCurrAudioBlock = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
wma->hEvent = CreateEventA(NULL, FALSE, FALSE, NULL);
|
|
|
|
wma->dwEventCount = *nHdr - 1;
|
|
|
|
*pWaveHdr = waveHdr;
|
|
|
|
cleanUp:
|
|
|
|
return dwRet;
|
2002-06-01 01:06:46 +02:00
|
|
|
}
|
2001-02-14 22:49:22 +01:00
|
|
|
|
|
|
|
void MCIAVI_PlayAudioBlocks(WINE_MCIAVI* wma, unsigned nHdr, LPWAVEHDR waveHdr)
|
|
|
|
{
|
|
|
|
TRACE("%ld (ec=%lu)\n", wma->lpAudioIndex[wma->dwCurrAudioBlock].dwOffset, wma->dwEventCount);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
/* push as many blocks as possible => audio gets priority */
|
2002-06-01 01:06:46 +02:00
|
|
|
while (wma->dwStatus != MCI_MODE_STOP && wma->dwStatus != MCI_MODE_NOT_READY &&
|
2001-02-14 22:49:22 +01:00
|
|
|
wma->dwCurrAudioBlock < wma->dwPlayableAudioBlocks) {
|
|
|
|
unsigned whidx = wma->dwCurrAudioBlock % nHdr;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
ResetEvent(wma->hEvent);
|
|
|
|
if (InterlockedDecrement(&wma->dwEventCount) < 0 ||
|
|
|
|
!wma->lpAudioIndex[wma->dwCurrAudioBlock].dwOffset)
|
|
|
|
break;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
mmioSeek(wma->hFile, wma->lpAudioIndex[wma->dwCurrAudioBlock].dwOffset, SEEK_SET);
|
|
|
|
mmioRead(wma->hFile, waveHdr[whidx].lpData, wma->lpAudioIndex[wma->dwCurrAudioBlock].dwSize);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
waveHdr[whidx].dwFlags &= ~WHDR_DONE;
|
|
|
|
waveHdr[whidx].dwBufferLength = wma->lpAudioIndex[wma->dwCurrAudioBlock].dwSize;
|
|
|
|
waveOutWrite(wma->hWave, &waveHdr[whidx], sizeof(WAVEHDR));
|
|
|
|
wma->dwCurrAudioBlock++;
|
|
|
|
}
|
|
|
|
InterlockedIncrement(&wma->dwEventCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT MCIAVI_PaintFrame(WINE_MCIAVI* wma, HDC hDC)
|
|
|
|
{
|
|
|
|
void* pBitmapData = NULL;
|
|
|
|
LPBITMAPINFO pBitmapInfo = NULL;
|
|
|
|
HDC hdcMem;
|
|
|
|
HBITMAP hbmOld;
|
|
|
|
int nWidth;
|
|
|
|
int nHeight;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
if (!hDC || !wma->inbih)
|
|
|
|
return TRUE;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
TRACE("Painting frame %lu\n", wma->dwCurrVideoFrame);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
if (wma->hic) {
|
|
|
|
pBitmapData = wma->outdata;
|
|
|
|
pBitmapInfo = (LPBITMAPINFO)wma->outbih;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
nWidth = wma->outbih->biWidth;
|
2002-06-01 01:06:46 +02:00
|
|
|
nHeight = wma->outbih->biHeight;
|
|
|
|
} else {
|
2001-02-14 22:49:22 +01:00
|
|
|
pBitmapData = wma->indata;
|
|
|
|
pBitmapInfo = (LPBITMAPINFO)wma->inbih;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
nWidth = wma->inbih->biWidth;
|
2002-06-01 01:06:46 +02:00
|
|
|
nHeight = wma->inbih->biHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!wma->hbmFrame)
|
2001-02-14 22:49:22 +01:00
|
|
|
wma->hbmFrame = CreateCompatibleBitmap(hDC, nWidth, nHeight);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
|
|
|
SetDIBits(hDC, wma->hbmFrame, 0, nHeight, pBitmapData, pBitmapInfo, DIB_RGB_COLORS);
|
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
hdcMem = CreateCompatibleDC(hDC);
|
|
|
|
hbmOld = SelectObject(hdcMem, wma->hbmFrame);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
|
|
|
BitBlt(hDC, 0, 0, nWidth, nHeight, hdcMem, 0, 0, SRCCOPY);
|
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
SelectObject(hdcMem, hbmOld);
|
|
|
|
DeleteDC(hdcMem);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT MCIAVI_DrawFrame(WINE_MCIAVI* wma)
|
|
|
|
{
|
|
|
|
HDC hDC;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
TRACE("Drawing frame %lu\n", wma->dwCurrVideoFrame);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
if (!wma->lpVideoIndex[wma->dwCurrVideoFrame].dwOffset)
|
|
|
|
return FALSE;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
EnterCriticalSection(&wma->cs);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
mmioSeek(wma->hFile, wma->lpVideoIndex[wma->dwCurrVideoFrame].dwOffset, SEEK_SET);
|
|
|
|
mmioRead(wma->hFile, wma->indata, wma->lpVideoIndex[wma->dwCurrVideoFrame].dwSize);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
/* FIXME ? */
|
|
|
|
wma->inbih->biSizeImage = wma->lpVideoIndex[wma->dwCurrVideoFrame].dwSize;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
if (wma->hic &&
|
2002-06-01 01:06:46 +02:00
|
|
|
ICDecompress(wma->hic, 0, wma->inbih, wma->indata,
|
2001-02-14 22:49:22 +01:00
|
|
|
wma->outbih, wma->outdata) != ICERR_OK) {
|
|
|
|
LeaveCriticalSection(&wma->cs);
|
|
|
|
WARN("Decompression error\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
if (IsWindowVisible(wma->hWnd) && (hDC = GetDC(wma->hWnd)) != 0) {
|
|
|
|
MCIAVI_PaintFrame(wma, hDC);
|
|
|
|
ReleaseDC(wma->hWnd, hDC);
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
LeaveCriticalSection(&wma->cs);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-02-14 22:49:22 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|