Here are some bugfixes for avifile that Maarten mainly did during
WineConf. The behaviour corresponds to what native avifil32 does. I will
add tests to show this and submit the patches then. (Maybe avifil32 does
a few more hacks like these, I'll add those too when I find them when
creating tests.)
If anyone has any comments on the patches as they are now already,
please let me know.
Thanks!
Julius
From 2e9c13211c0343fd59faf835a1d954416ab46203 Mon Sep 17 00:00:00 2001
From: Julius Schwartzenberg <julius.schwartzenberg(a)gmail.com>
Date: Sun, 8 Nov 2009 15:18:26 +0100
Subject: [PATCH 1/3] avifile: Fix header for audio stream
---
dlls/avifil32/avifile.c | 10 +++++++++-
1 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/dlls/avifil32/avifile.c b/dlls/avifil32/avifile.c
index 49e141f..4ecc6f6 100644
--- a/dlls/avifil32/avifile.c
+++ b/dlls/avifil32/avifile.c
@@ -1816,7 +1816,15 @@ static HRESULT AVIFILE_LoadFile(IAVIFileImpl *This)
if (FAILED(hr))
return hr;
};
-
+ if (pStream->lpFormat != NULL && pStream->sInfo.fccType == streamtypeAUDIO)
+ {
+ WAVEFORMATEX *wfx = pStream->lpFormat;
+ wfx->nBlockAlign = wfx->nChannels * wfx->wBitsPerSample / 8;
+ pStream->sInfo.dwSampleSize = wfx->nBlockAlign;
+ TRACE("Block size reset to %u, chan=%u bpp=%u\n", wfx->nBlockAlign, wfx->nChannels, wfx->wBitsPerSample);
+ pStream->sInfo.dwScale = 1;
+ pStream->sInfo.dwRate = wfx->nSamplesPerSec;
+ }
if (mmioAscend(This->hmmio, &ck, 0) != S_OK)
return AVIERR_FILEREAD;
}
--
1.6.3.3
From 969620de75ae75d13cf5f443842cee8bf28c4362 Mon Sep 17 00:00:00 2001
From: Julius Schwartzenberg <julius.schwartzenberg(a)gmail.com>
Date: Sun, 8 Nov 2009 15:28:19 +0100
Subject: [PATCH 2/3] avifile: Fix header suggested buffersize
---
dlls/avifil32/avifile.c | 12 +++++++++---
1 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/dlls/avifil32/avifile.c b/dlls/avifil32/avifile.c
index 4ecc6f6..c40cbd9 100644
--- a/dlls/avifil32/avifile.c
+++ b/dlls/avifil32/avifile.c
@@ -1652,7 +1652,7 @@ static HRESULT AVIFILE_LoadFile(IAVIFileImpl *This)
This->fInfo.dwCaps = AVIFILECAPS_CANREAD|AVIFILECAPS_CANWRITE;
This->fInfo.dwLength = MainAVIHdr.dwTotalFrames;
This->fInfo.dwStreams = MainAVIHdr.dwStreams;
- This->fInfo.dwSuggestedBufferSize = MainAVIHdr.dwSuggestedBufferSize;
+ This->fInfo.dwSuggestedBufferSize = 0;
This->fInfo.dwWidth = MainAVIHdr.dwWidth;
This->fInfo.dwHeight = MainAVIHdr.dwHeight;
LoadStringW(AVIFILE_hModule, IDS_AVIFILETYPE, This->fInfo.szFileType,
@@ -1754,8 +1754,7 @@ static HRESULT AVIFILE_LoadFile(IAVIFileImpl *This)
pStream->sInfo.dwRate = streamHdr.dwRate;
pStream->sInfo.dwStart = streamHdr.dwStart;
pStream->sInfo.dwLength = streamHdr.dwLength;
- pStream->sInfo.dwSuggestedBufferSize =
- streamHdr.dwSuggestedBufferSize;
+ pStream->sInfo.dwSuggestedBufferSize = 0;
pStream->sInfo.dwQuality = streamHdr.dwQuality;
pStream->sInfo.dwSampleSize = streamHdr.dwSampleSize;
pStream->sInfo.rcFrame.left = streamHdr.rcFrame.left;
@@ -1905,6 +1904,13 @@ static HRESULT AVIFILE_LoadFile(IAVIFileImpl *This)
}
}
+ for (nStream = 0; nStream < This->fInfo.dwStreams; nStream++)
+ {
+ DWORD sugbuf = This->ppStreams[nStream]->sInfo.dwSuggestedBufferSize;
+ if (This->fInfo.dwSuggestedBufferSize < sugbuf)
+ This->fInfo.dwSuggestedBufferSize = sugbuf;
+ }
+
/* find other chunks */
FindChunkAndKeepExtras(&This->fileextra, This->hmmio, &ck, &ckRIFF, 0);
--
1.6.3.3
From 39d6ecab76989b93d35a0568e105fd306fa32706 Mon Sep 17 00:00:00 2001
From: Julius Schwartzenberg <julius.schwartzenberg(a)gmail.com>
Date: Sun, 8 Nov 2009 15:32:33 +0100
Subject: [PATCH 3/3] avifile: Fix playback of fixed sample size audio stream
---
dlls/avifil32/avifile.c | 14 ++++++++++----
1 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/dlls/avifil32/avifile.c b/dlls/avifil32/avifile.c
index c40cbd9..5fa45ae 100644
--- a/dlls/avifil32/avifile.c
+++ b/dlls/avifil32/avifile.c
@@ -1093,6 +1093,9 @@ static HRESULT WINAPI IAVIStream_fnRead(IAVIStream *iface, LONG start,
/* convert samples to bytes */
samples *= This->sInfo.dwSampleSize;
+ if (!buffer)
+ buffersize = samples;
+
while (samples > 0 && buffersize > 0) {
if (block != This->dwCurrentFrame) {
hr = AVIFILE_ReadBlock(This, block, NULL, 0);
@@ -1102,11 +1105,12 @@ static HRESULT WINAPI IAVIStream_fnRead(IAVIStream *iface, LONG start,
size = min((DWORD)samples, (DWORD)buffersize);
size = min(size, This->cbBuffer - offset);
- memcpy(buffer, ((BYTE*)&This->lpBuffer[2]) + offset, size);
-
+ if (buffer)
+ memcpy(buffer, ((BYTE*)&This->lpBuffer[2]) + offset, size);
block++;
offset = 0;
- buffer = ((LPBYTE)buffer)+size;
+ if (buffer)
+ buffer = ((LPBYTE)buffer)+size;
samples -= size;
buffersize -= size;
@@ -1117,7 +1121,9 @@ static HRESULT WINAPI IAVIStream_fnRead(IAVIStream *iface, LONG start,
*samplesread += size / This->sInfo.dwSampleSize;
}
- if (samples == 0)
+ TRACE("Returning %d/%d\n", bytesread ? *bytesread : -1, samplesread ? *samplesread : -1);
+
+ if (samples == 0 || !buffer)
return AVIERR_OK;
else
return AVIERR_BUFFERTOOSMALL;
--
1.6.3.3