Commit 4d37b669 authored by Michael Günnewig's avatar Michael Günnewig Committed by Alexandre Julliard

- 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.
parent 2429d51f
...@@ -899,6 +899,7 @@ LONG WINAPI AVIStreamLength(PAVISTREAM pstream) ...@@ -899,6 +899,7 @@ LONG WINAPI AVIStreamLength(PAVISTREAM pstream)
LONG WINAPI AVIStreamSampleToTime(PAVISTREAM pstream, LONG lSample) LONG WINAPI AVIStreamSampleToTime(PAVISTREAM pstream, LONG lSample)
{ {
AVISTREAMINFOW asiw; AVISTREAMINFOW asiw;
LONG time;
TRACE("(%p,%ld)\n", pstream, lSample); TRACE("(%p,%ld)\n", pstream, lSample);
...@@ -910,7 +911,19 @@ LONG WINAPI AVIStreamSampleToTime(PAVISTREAM pstream, LONG lSample) ...@@ -910,7 +911,19 @@ LONG WINAPI AVIStreamSampleToTime(PAVISTREAM pstream, LONG lSample)
if (asiw.dwRate == 0) if (asiw.dwRate == 0)
return -1; 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) ...@@ -920,10 +933,11 @@ LONG WINAPI AVIStreamSampleToTime(PAVISTREAM pstream, LONG lSample)
LONG WINAPI AVIStreamTimeToSample(PAVISTREAM pstream, LONG lTime) LONG WINAPI AVIStreamTimeToSample(PAVISTREAM pstream, LONG lTime)
{ {
AVISTREAMINFOW asiw; AVISTREAMINFOW asiw;
LONG sample;
TRACE("(%p,%ld)\n", pstream, lTime); TRACE("(%p,%ld)\n", pstream, lTime);
if (pstream == NULL) if (pstream == NULL || lTime < 0)
return -1; return -1;
if (FAILED(IAVIStream_Info(pstream, &asiw, sizeof(asiw)))) if (FAILED(IAVIStream_Info(pstream, &asiw, sizeof(asiw))))
...@@ -931,7 +945,19 @@ LONG WINAPI AVIStreamTimeToSample(PAVISTREAM pstream, LONG lTime) ...@@ -931,7 +945,19 @@ LONG WINAPI AVIStreamTimeToSample(PAVISTREAM pstream, LONG lTime)
if (asiw.dwScale == 0) if (asiw.dwScale == 0)
return -1; 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;
} }
/*********************************************************************** /***********************************************************************
......
...@@ -635,8 +635,20 @@ static HRESULT WINAPI IPersistFile_fnLoad(IPersistFile *iface, ...@@ -635,8 +635,20 @@ static HRESULT WINAPI IPersistFile_fnLoad(IPersistFile *iface,
/* try to open the file */ /* try to open the file */
This->paf->hmmio = mmioOpenW(This->paf->szFileName, NULL, This->paf->hmmio = mmioOpenW(This->paf->szFileName, NULL,
MMIO_ALLOCBUF | dwMode); MMIO_ALLOCBUF | dwMode);
if (This->paf->hmmio == NULL) if (This->paf->hmmio == NULL) {
return AVIERR_FILEOPEN; /* 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? */ /* should we create a new file? */
if (dwMode & OF_CREATE) { if (dwMode & OF_CREATE) {
...@@ -1792,9 +1804,9 @@ static HRESULT AVIFILE_LoadFile(IAVIFileImpl *This) ...@@ -1792,9 +1804,9 @@ static HRESULT AVIFILE_LoadFile(IAVIFileImpl *This)
hr = ReadChunkIntoExtra(&This->fileextra, This->hmmio, &ckLIST2); hr = ReadChunkIntoExtra(&This->fileextra, This->hmmio, &ckLIST2);
if (FAILED(hr)) if (FAILED(hr))
return 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" */ /* read any extra headers in "LIST","hdrl" */
...@@ -1936,7 +1948,8 @@ static HRESULT AVIFILE_LoadIndex(IAVIFileImpl *This, DWORD size, DWORD offset) ...@@ -1936,7 +1948,8 @@ static HRESULT AVIFILE_LoadIndex(IAVIFileImpl *This, DWORD size, DWORD offset)
for (n = 0; n < This->fInfo.dwStreams; n++) { for (n = 0; n < This->fInfo.dwStreams; n++) {
IAVIStreamImpl *pStream = This->ppStreams[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", ERR("stream %lu length mismatch: dwLength=%lu found=%ld\n",
n, pStream->sInfo.dwLength, pStream->lLastFrame); n, pStream->sInfo.dwLength, pStream->lLastFrame);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment