winmm: Fix handling of mmio file buffers.

This commit is contained in:
Akihiro Sagawa 2012-11-29 00:00:19 +09:00 committed by Alexandre Julliard
parent 579f4f9da0
commit c2cf4ddb93
2 changed files with 22 additions and 26 deletions

View File

@ -771,6 +771,8 @@ LONG WINAPI mmioRead(HMMIO hmmio, HPSTR pch, LONG cch)
return send_message(wm->ioProc, &wm->info, MMIOM_READ, (LPARAM)pch, cch, FALSE);
/* first try from current buffer */
if (cch && wm->info.fccIOProc != FOURCC_MEM && wm->info.pchNext == wm->info.pchEndRead)
MMIO_GrabNextBuffer(wm, TRUE);
if (wm->info.pchNext != wm->info.pchEndRead) {
count = wm->info.pchEndRead - wm->info.pchNext;
if (count > cch || count < 0) count = cch;
@ -796,6 +798,8 @@ LONG WINAPI mmioRead(HMMIO hmmio, HPSTR pch, LONG cch)
cch -= size;
count += size;
}
wm->bBufferLoaded = FALSE;
mmioSeek(hmmio, 0, SEEK_CUR);
}
TRACE("count=%d\n", count);
@ -887,35 +891,27 @@ LONG WINAPI mmioSeek(HMMIO hmmio, LONG lOffset, INT iOrigin)
return -1;
}
if (offset && offset >= wm->dwFileSize && wm->info.fccIOProc != FOURCC_MEM) {
/* should check that write mode exists */
if (MMIO_Flush(wm, 0) != MMSYSERR_NOERROR)
return -1;
wm->info.lBufOffset = offset;
wm->info.pchEndRead = wm->info.pchBuffer;
wm->info.pchEndWrite = wm->info.pchBuffer + wm->info.cchBuffer;
if ((wm->info.dwFlags & MMIO_RWMODE) == MMIO_READ) {
wm->info.lDiskOffset = wm->dwFileSize;
}
} else if ((wm->info.cchBuffer > 0) &&
/* stay in same buffer ? */
/* some memory mapped buffers are defined with -1 as a size */
if ((wm->info.cchBuffer > 0) &&
((offset < wm->info.lBufOffset) ||
(offset >= wm->info.lBufOffset + wm->info.cchBuffer) ||
(offset > wm->dwFileSize && wm->info.fccIOProc != FOURCC_MEM) ||
!wm->bBufferLoaded)) {
/* stay in same buffer ? */
/* some memory mapped buffers are defined with -1 as a size */
/* condition to change buffer */
if ((wm->info.fccIOProc == FOURCC_MEM) ||
MMIO_Flush(wm, 0) != MMSYSERR_NOERROR ||
/* this also sets the wm->info.lDiskOffset field */
send_message(wm->ioProc, &wm->info, MMIOM_SEEK,
(offset / wm->info.cchBuffer) * wm->info.cchBuffer,
SEEK_SET, FALSE) == -1)
offset, SEEK_SET, FALSE) == -1)
return -1;
MMIO_GrabNextBuffer(wm, TRUE);
wm->info.lBufOffset = offset;
wm->bBufferLoaded = FALSE;
wm->info.pchNext = wm->info.pchEndRead = wm->info.pchBuffer;
}
wm->info.pchNext = wm->info.pchBuffer + (offset - wm->info.lBufOffset);
else
wm->info.pchNext = wm->info.pchBuffer + (offset - wm->info.lBufOffset);
TRACE("=> %d\n", offset);
return offset;

View File

@ -812,14 +812,14 @@ static void test_mmio_end_of_file(void)
ok(sizeof(RIFF_buf) == ret, "got %d\n", ret);
ret = mmioRead(hmmio, data, sizeof(data));
todo_wine ok(ret == 0, "expected %d, got %d\n", 0, ret);
ok(ret == 0, "expected %d, got %d\n", 0, ret);
res = mmioGetInfo(hmmio, &mmio, 0);
ok(res == MMSYSERR_NOERROR, "expected 0, got %d\n", res);
res = mmioAdvance(hmmio, &mmio, MMIO_READ);
ok(res == MMSYSERR_NOERROR, "expected 0, got %d\n", res);
todo_wine ok(mmio.pchNext == mmio.pchEndRead, "expected %p, got %p\n", mmio.pchEndRead, mmio.pchNext);
ok(mmio.pchNext == mmio.pchEndRead, "expected %p, got %p\n", mmio.pchEndRead, mmio.pchNext);
mmioClose(hmmio, 0);
DeleteFileA(test_file);
@ -874,18 +874,18 @@ static void test_mmio_buffer_pointer(void)
ok(pos == size, "failed to seek, got %d\n", pos);
res = mmioGetInfo(hmmio, &mmio, 0);
ok(res == MMSYSERR_NOERROR, "expected 0, got %d\n", res);
todo_wine ok(mmio.lBufOffset == size, "expected %d, got %d\n", size, mmio.lBufOffset);
todo_wine ok(mmio.pchNext == mmio.pchBuffer, "expected %p, got %p\n", mmio.pchBuffer, mmio.pchNext);
todo_wine ok(mmio.pchEndRead == mmio.pchBuffer, "expected %p, got %p\n", mmio.pchBuffer, mmio.pchEndRead);
ok(mmio.lBufOffset == size, "expected %d, got %d\n", size, mmio.lBufOffset);
ok(mmio.pchNext == mmio.pchBuffer, "expected %p, got %p\n", mmio.pchBuffer, mmio.pchNext);
ok(mmio.pchEndRead == mmio.pchBuffer, "expected %p, got %p\n", mmio.pchBuffer, mmio.pchEndRead);
/* reading a lot (as sizeof(data) > mmio.cchBuffer), the buffer is empty */
size = mmioRead(hmmio, data, sizeof(data));
ok(size == sizeof(data), "failed to read, got %d\n", size);
res = mmioGetInfo(hmmio, &mmio, 0);
ok(res == MMSYSERR_NOERROR, "expected 0, got %d\n", res);
todo_wine ok(mmio.lBufOffset == pos+size, "expected %d, got %d\n", pos+size, mmio.lBufOffset);
todo_wine ok(mmio.pchNext == mmio.pchBuffer, "expected %p, got %p\n", mmio.pchBuffer, mmio.pchNext);
todo_wine ok(mmio.pchEndRead == mmio.pchBuffer, "expected %p, got %p\n", mmio.pchBuffer, mmio.pchEndRead);
ok(mmio.lBufOffset == pos+size, "expected %d, got %d\n", pos+size, mmio.lBufOffset);
ok(mmio.pchNext == mmio.pchBuffer, "expected %p, got %p\n", mmio.pchBuffer, mmio.pchNext);
ok(mmio.pchEndRead == mmio.pchBuffer, "expected %p, got %p\n", mmio.pchBuffer, mmio.pchEndRead);
mmioClose(hmmio, 0);
DeleteFileA(test_file);