- Use free index directly
authorJohannes Anderwald <johannes.anderwald@reactos.org>
Sat, 11 Jul 2009 23:23:40 +0000 (23:23 +0000)
committerJohannes Anderwald <johannes.anderwald@reactos.org>
Sat, 11 Jul 2009 23:23:40 +0000 (23:23 +0000)
- Update interface

svn path=/trunk/; revision=41901

reactos/drivers/wdm/audio/legacy/wdmaud/control.c
reactos/drivers/wdm/audio/legacy/wdmaud/interface.h

index 795f0ff..2f9507c 100644 (file)
@@ -146,6 +146,7 @@ WdmAudControlOpen(
     KSDATAFORMAT_WAVEFORMATEX * DataFormat;
     ULONG FilterId;
     ULONG PinId;
+    ULONG FreeIndex;
 
     if (DeviceInfo->DeviceType == MIXER_DEVICE_TYPE)
     {
@@ -166,12 +167,14 @@ WdmAudControlOpen(
     }
 
     /* close pin handle which uses same virtual audio device id and pin id */
+    FreeIndex = (ULONG)-1;
     for(Index = 0; Index < ClientInfo->NumPins; Index++)
     {
-        if (ClientInfo->hPins[Index].FilterId == FilterId && ClientInfo->hPins[Index].PinId == PinId && ClientInfo->hPins[Index].Handle)
+        if (ClientInfo->hPins[Index].FilterId == FilterId && ClientInfo->hPins[Index].PinId == PinId && ClientInfo->hPins[Index].Handle && ClientInfo->hPins[Index].Type == DeviceInfo->DeviceType)
         {
             ZwClose(ClientInfo->hPins[Index].Handle);
             ClientInfo->hPins[Index].Handle = NULL;
+            FreeIndex = Index;
         }
     }
 
@@ -248,19 +251,16 @@ WdmAudControlOpen(
     {
         PWDMAUD_HANDLE Handels;
 
-        for(Index = 0; Index < ClientInfo->NumPins; Index++)
+        if (FreeIndex != (ULONG)-1)
         {
-            if (ClientInfo->hPins[Index].Handle == NULL)
-            {
-                /* re-use a free index */
-                ClientInfo->hPins[Index].Handle = PinHandle;
-                ClientInfo->hPins[Index].FilterId = FilterId;
-                ClientInfo->hPins[Index].PinId = PinId;
-                ClientInfo->hPins[Index].Type = DeviceInfo->DeviceType;
-
-                DeviceInfo->hDevice = PinHandle;
-                return SetIrpIoStatus(Irp, Status, sizeof(WDMAUD_DEVICE_INFO));
-            }
+            /* re-use a free index */
+            ClientInfo->hPins[Index].Handle = PinHandle;
+            ClientInfo->hPins[Index].FilterId = FilterId;
+            ClientInfo->hPins[Index].PinId = PinId;
+            ClientInfo->hPins[Index].Type = DeviceInfo->DeviceType;
+
+            DeviceInfo->hDevice = PinHandle;
+            return SetIrpIoStatus(Irp, Status, sizeof(WDMAUD_DEVICE_INFO));
         }
 
         Handels = ExAllocatePool(NonPagedPool, sizeof(WDMAUD_HANDLE) * (ClientInfo->NumPins+1));
@@ -411,7 +411,7 @@ WdmAudControlDeviceState(
     Property.Id = KSPROPERTY_CONNECTION_STATE;
     Property.Flags = KSPROPERTY_TYPE_SET;
 
-    State = DeviceInfo->State;
+    State = DeviceInfo->u.State;
 
     Status = KsSynchronousIoControlDevice(FileObject, KernelMode, IOCTL_KS_PROPERTY, (PVOID)&Property, sizeof(KSPROPERTY), (PVOID)&State, sizeof(KSSTATE), &BytesReturned);
 
@@ -647,6 +647,8 @@ WdmAudDeviceControl(
             return WdmAudCapabilities(DeviceObject, Irp, DeviceInfo, ClientInfo);
         case IOCTL_CLOSE_WDMAUD:
             return WdmAudIoctlClose(DeviceObject, Irp, DeviceInfo, ClientInfo);
+        case IOCTL_GETPOS:
+            DPRINT1("IOCTL_GETPOS\n");
         case IOCTL_GETDEVID:
         case IOCTL_GETVOLUME:
         case IOCTL_SETVOLUME:
index e541453..7221fc4 100644 (file)
@@ -30,8 +30,6 @@ typedef struct
 
     HANDLE hDevice;
     ULONG DeviceCount;
-    KSSTATE State;
-    ULONG Volume;
 
     ULONG BufferSize;
     PUCHAR Buffer;
@@ -41,7 +39,10 @@ typedef struct
         WAVEFORMATEX WaveFormatEx;
         WAVEOUTCAPSW WaveOutCaps;
         AUXCAPSW     AuxCaps;
-        WAVEINCAPSW WaveInCaps;
+        WAVEINCAPSW  WaveInCaps;
+        ULONGLONG    Position;
+        KSSTATE State;
+        ULONG Volume;
     }u;
 
 }WDMAUD_DEVICE_INFO, *PWDMAUD_DEVICE_INFO;
@@ -204,5 +205,22 @@ typedef struct
              METHOD_BUFFERED, \
              FILE_CREATE_TREE_CONNECTION | FILE_ANY_ACCESS)
 
+/// IOCTL_GETPOS
+///
+/// Description: This IOCTL retrieves the current playback / write position
+///
+/// Arguments:  InputBuffer is a pointer to a WDMAUD_DEVICE_INFO structure,
+///             InputBufferSize is size of WDMAUD_DEVICE_INFO structure
+/// Note:       The DeviceType and hDevice must be set
+/// Result:     The result is returned in Volume
+/// ReturnCode:  STATUS_SUCCESS indicates success
+/// Prequsites: opened device
+
+#define IOCTL_GETPOS \
+    CTL_CODE(FILE_DEVICE_SOUND, \
+             9, \
+             METHOD_BUFFERED, \
+             FILE_CREATE_TREE_CONNECTION | FILE_ANY_ACCESS)
+
 
 #endif