Changelog: - 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. Michael Günnewig
Index: dlls/avifil32/api.c =================================================================== RCS file: /home/wine/wine/dlls/avifil32/api.c,v retrieving revision 1.19 diff -d -u -r1.19 api.c --- dlls/avifil32/api.c 9 Jul 2003 02:52:58 -0000 1.19 +++ dlls/avifil32/api.c 19 Jul 2003 17:06:07 -0000 @@ -899,6 +899,7 @@ LONG WINAPI AVIStreamSampleToTime(PAVISTREAM pstream, LONG lSample) { AVISTREAMINFOW asiw; + LONG time; TRACE("(%p,%ld)\n", pstream, lSample); @@ -910,7 +911,20 @@ 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); + + //return (LONG)(((float)lSample * asiw.dwScale * 1000.0) / asiw.dwRate) + TRACE(" -> %ld\n",time); + return time; } /*********************************************************************** @@ -920,10 +934,11 @@ 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 +946,19 @@ 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; } /*********************************************************************** Index: dlls/avifil32/avifile.c =================================================================== RCS file: /home/wine/wine/dlls/avifil32/avifile.c,v retrieving revision 1.35 diff -d -u -r1.35 avifile.c --- dlls/avifil32/avifile.c 2 Jul 2003 00:38:57 -0000 1.35 +++ dlls/avifil32/avifile.c 19 Jul 2003 17:06:22 -0000 @@ -635,8 +635,20 @@ /* 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 @@ 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 @@ 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); }