Author: janderwald
Date: Sat Mar 7 22:59:57 2009
New Revision: 39902
URL:
http://svn.reactos.org/svn/reactos?rev=39902&view=rev
Log:
- Rewrite writing to common buffer to fix stuttering sound
Modified:
trunk/reactos/drivers/wdm/audio/backpln/portcls/pin_wavecyclic.c
Modified: trunk/reactos/drivers/wdm/audio/backpln/portcls/pin_wavecyclic.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/wdm/audio/backpln/…
==============================================================================
--- trunk/reactos/drivers/wdm/audio/backpln/portcls/pin_wavecyclic.c [iso-8859-1]
(original)
+++ trunk/reactos/drivers/wdm/audio/backpln/portcls/pin_wavecyclic.c [iso-8859-1] Sat Mar
7 22:59:57 2009
@@ -94,12 +94,78 @@
static
VOID
+UpdateCommonBuffer(
+ IPortPinWaveCyclicImpl * This,
+ ULONG Position)
+{
+ ULONG BufferLength;
+ ULONG BytesToCopy;
+ ULONG BufferSize;
+ PUCHAR Buffer;
+ NTSTATUS Status;
+
+ BufferLength = Position - This->CommonBufferOffset;
+ while(BufferLength)
+ {
+ Status = This->IrpQueue->lpVtbl->GetMapping(This->IrpQueue,
&Buffer, &BufferSize);
+ if (!NT_SUCCESS(Status))
+ return;
+
+ BytesToCopy = min(BufferLength, BufferSize);
+ This->DmaChannel->lpVtbl->CopyTo(This->DmaChannel,
+ (PUCHAR)This->CommonBuffer +
This->CommonBufferOffset,
+ Buffer,
+ BytesToCopy);
+
+ This->IrpQueue->lpVtbl->UpdateMapping(This->IrpQueue, BytesToCopy);
+ This->CommonBufferOffset += BytesToCopy;
+
+ BufferLength = Position - This->CommonBufferOffset;
+ }
+}
+
+static
+VOID
+UpdateCommonBufferOverlap(
+ IPortPinWaveCyclicImpl * This,
+ ULONG Position)
+{
+ ULONG BufferLength;
+ ULONG BytesToCopy;
+ ULONG BufferSize;
+ PUCHAR Buffer;
+ NTSTATUS Status;
+
+ BufferLength = This->CommonBufferSize - This->CommonBufferOffset;
+ while(BufferLength)
+ {
+ Status = This->IrpQueue->lpVtbl->GetMapping(This->IrpQueue,
&Buffer, &BufferSize);
+ if (!NT_SUCCESS(Status))
+ return;
+
+ BytesToCopy = min(BufferLength, BufferSize);
+ This->DmaChannel->lpVtbl->CopyTo(This->DmaChannel,
+ (PUCHAR)This->CommonBuffer +
This->CommonBufferOffset,
+ Buffer,
+ BytesToCopy);
+
+ This->IrpQueue->lpVtbl->UpdateMapping(This->IrpQueue, BytesToCopy);
+ This->CommonBufferOffset += BytesToCopy;
+
+ BufferLength = This->CommonBufferSize - This->CommonBufferOffset;
+ }
+ This->CommonBufferOffset = 0;
+ UpdateCommonBuffer(This, Position);
+}
+
+
+static
+VOID
NTAPI
IServiceSink_fnRequestService(
IServiceSink* iface)
{
ULONG Position;
- ULONG BufferLength, BytesToCopy;
NTSTATUS Status;
PUCHAR Buffer;
ULONG BufferSize;
@@ -134,57 +200,12 @@
if (Position < This->CommonBufferOffset)
{
- BufferLength = This->CommonBufferSize - This->CommonBufferOffset;
-
- BytesToCopy = min(BufferLength, BufferSize);
-
- DPRINT("Copying %u\n", BytesToCopy);
-
- if (BytesToCopy)
- {
- This->DmaChannel->lpVtbl->CopyTo(This->DmaChannel,
(PUCHAR)This->CommonBuffer + This->CommonBufferOffset, Buffer, BytesToCopy);
- This->IrpQueue->lpVtbl->UpdateMapping(This->IrpQueue,
BytesToCopy);
- This->CommonBufferOffset = 0;
- }
-
-
- Status = This->IrpQueue->lpVtbl->GetMapping(This->IrpQueue,
&Buffer, &BufferSize);
- if (!NT_SUCCESS(Status))
- {
- DPRINT("IServiceSink_fnRequestService> Waiting for mapping\n");
-
This->ServiceGroup->lpVtbl->RequestDelayedService(This->ServiceGroup,
-10000000L);
- This->RetryCount++;
- return;
- }
-
- BytesToCopy = min(Position, BufferSize);
-
- DPRINT("Copying %u\n", BytesToCopy);
-
- if (BytesToCopy)
- {
- This->DmaChannel->lpVtbl->CopyTo(This->DmaChannel,
(PUCHAR)(PUCHAR)This->CommonBuffer, Buffer, BytesToCopy);
- This->IrpQueue->lpVtbl->UpdateMapping(This->IrpQueue,
BytesToCopy);
- This->CommonBufferOffset = Position;
- }
-
+ UpdateCommonBufferOverlap(This, Position);
}
else if (Position >= This->CommonBufferOffset)
{
- BufferLength = Position - This->CommonBufferOffset;
-
- BytesToCopy = min(BufferLength, BufferSize);
- DPRINT("Copying %u\n", BytesToCopy);
-
- This->DmaChannel->lpVtbl->CopyTo(This->DmaChannel,
- (PUCHAR)This->CommonBuffer +
This->CommonBufferOffset,
- Buffer,
- BytesToCopy);
-
- This->IrpQueue->lpVtbl->UpdateMapping(This->IrpQueue, BytesToCopy);
- This->CommonBufferOffset = Position;
- }
-
+ UpdateCommonBuffer(This, Position);
+ }
}
static IServiceSinkVtbl vt_IServiceSink =