From 4d37b6691be9150bc559bc3e0d3a1c054aa95bde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20G=C3=BCnnewig?= Date: Mon, 21 Jul 2003 19:59:57 +0000 Subject: [PATCH] - Fixed AVIStreamTimeToSample and AVIStreamSampleToTime methods to stay in bounds and behave like the native ones. - Fallback to mmioOpenA if mmioOpenW doesn't work (when using Win9x DLLs). - Fixed a bug of using mmioDescend/mmioAscend (occured with native libs). - Silent a message which could be incorrect for non-video streams. --- dlls/avifil32/api.c | 32 +++++++++++++++++++++++++++++--- dlls/avifil32/avifile.c | 23 ++++++++++++++++++----- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/dlls/avifil32/api.c b/dlls/avifil32/api.c index 4cde83ae233..29a77498eb3 100644 --- a/dlls/avifil32/api.c +++ b/dlls/avifil32/api.c @@ -899,6 +899,7 @@ LONG WINAPI AVIStreamLength(PAVISTREAM pstream) LONG WINAPI AVIStreamSampleToTime(PAVISTREAM pstream, LONG lSample) { AVISTREAMINFOW asiw; + LONG time; TRACE("(%p,%ld)\n", pstream, lSample); @@ -910,7 +911,19 @@ LONG WINAPI AVIStreamSampleToTime(PAVISTREAM pstream, LONG lSample) if (asiw.dwRate == 0) return -1; - return (LONG)(((float)lSample * asiw.dwScale * 1000.0) / asiw.dwRate); + /* limit to stream bounds */ + if (lSample < asiw.dwStart) + lSample = asiw.dwStart; + if (lSample > asiw.dwStart + asiw.dwLength) + lSample = asiw.dwStart + asiw.dwLength; + + if (asiw.dwRate / asiw.dwScale < 1000) + time = (LONG)(((float)lSample * asiw.dwScale * 1000) / asiw.dwRate); + else + time = (LONG)(((float)lSample * asiw.dwScale * 1000 + (asiw.dwRate - 1)) / asiw.dwRate); + + TRACE(" -> %ld\n",time); + return time; } /*********************************************************************** @@ -920,10 +933,11 @@ LONG WINAPI AVIStreamSampleToTime(PAVISTREAM pstream, LONG lSample) LONG WINAPI AVIStreamTimeToSample(PAVISTREAM pstream, LONG lTime) { AVISTREAMINFOW asiw; + LONG sample; TRACE("(%p,%ld)\n", pstream, lTime); - if (pstream == NULL) + if (pstream == NULL || lTime < 0) return -1; if (FAILED(IAVIStream_Info(pstream, &asiw, sizeof(asiw)))) @@ -931,7 +945,19 @@ LONG WINAPI AVIStreamTimeToSample(PAVISTREAM pstream, LONG lTime) if (asiw.dwScale == 0) return -1; - return (LONG)(((float)lTime * asiw.dwRate) / asiw.dwScale / 1000.0); + if (asiw.dwRate / asiw.dwScale < 1000) + sample = (LONG)((((float)asiw.dwRate * lTime) / (asiw.dwScale * 1000))); + else + sample = (LONG)(((float)asiw.dwRate * lTime + (asiw.dwScale * 1000 - 1)) / (asiw.dwScale * 1000)); + + /* limit to stream bounds */ + if (sample < asiw.dwStart) + sample = asiw.dwStart; + if (sample > asiw.dwStart + asiw.dwLength) + sample = asiw.dwStart + asiw.dwLength; + + TRACE(" -> %ld\n", sample); + return sample; } /*********************************************************************** diff --git a/dlls/avifil32/avifile.c b/dlls/avifil32/avifile.c index 9112b424043..f30edd67dac 100644 --- a/dlls/avifil32/avifile.c +++ b/dlls/avifil32/avifile.c @@ -635,8 +635,20 @@ static HRESULT WINAPI IPersistFile_fnLoad(IPersistFile *iface, /* try to open the file */ This->paf->hmmio = mmioOpenW(This->paf->szFileName, NULL, MMIO_ALLOCBUF | dwMode); - if (This->paf->hmmio == NULL) - return AVIERR_FILEOPEN; + if (This->paf->hmmio == NULL) { + /* mmioOpenW not in native DLLs of Win9x -- try mmioOpenA */ + LPSTR szFileName = LocalAlloc(LPTR, len * sizeof(CHAR)); + if (szFileName == NULL) + return AVIERR_MEMORY; + + WideCharToMultiByte(CP_ACP, 0, This->paf->szFileName, -1, szFileName, + len, NULL, NULL); + + This->paf->hmmio = mmioOpenA(szFileName, NULL, MMIO_ALLOCBUF | dwMode); + LocalFree((HLOCAL)szFileName); + if (This->paf->hmmio == NULL) + return AVIERR_FILEOPEN; + } /* should we create a new file? */ if (dwMode & OF_CREATE) { @@ -1792,9 +1804,9 @@ static HRESULT AVIFILE_LoadFile(IAVIFileImpl *This) hr = ReadChunkIntoExtra(&This->fileextra, This->hmmio, &ckLIST2); if (FAILED(hr)) return hr; - if (mmioAscend(This->hmmio, &ckLIST2, 0) != S_OK) - return AVIERR_FILEREAD; } + if (mmioAscend(This->hmmio, &ckLIST2, 0) != S_OK) + return AVIERR_FILEREAD; } /* read any extra headers in "LIST","hdrl" */ @@ -1936,7 +1948,8 @@ static HRESULT AVIFILE_LoadIndex(IAVIFileImpl *This, DWORD size, DWORD offset) for (n = 0; n < This->fInfo.dwStreams; n++) { IAVIStreamImpl *pStream = This->ppStreams[n]; - if (pStream->sInfo.dwLength != pStream->lLastFrame+1) + if (pStream->sInfo.dwSampleSize == 0 && + pStream->sInfo.dwLength != pStream->lLastFrame+1) ERR("stream %lu length mismatch: dwLength=%lu found=%ld\n", n, pStream->sInfo.dwLength, pStream->lLastFrame); }