|
没人理我 上代码:
- NTSTATUS
- DriverEntry(
- IN PDRIVER_OBJECT DriverObject,
- IN PUNICODE_STRING RegistryPath
- )
- {
- NTSTATUS status;
- HW_INITIALIZATION_DATA HwInitData;
- KdPrint(("进入DriveEntry函数\n"));
- RtlZeroMemory(&HwInitData,sizeof(HwInitData));
- HwInitData.HwInitializationDataSize = sizeof(HwInitData);
- HwInitData.HwInterrupt = NULL;
- HwInitData.HwReceivePacket = AdapterReceivePacket;
- HwInitData.HwCancelPacket = AdapterCancelPacket;
- HwInitData.HwRequestTimeoutHandler = AdapterTimeoutPacket;
- HwInitData.DeviceExtensionSize = sizeof(HW_DEVICE_EXTENSION);
- HwInitData.PerRequestExtensionSize = sizeof(SRB_EXTENSION);
- HwInitData.FilterInstanceExtensionSize = 0;
- HwInitData.PerStreamExtensionSize = sizeof(STREAMEX);
- HwInitData.BusMasterDMA = FALSE;
- HwInitData.Dma24BitAddresses = FALSE;
- HwInitData.BufferAlignment = 3;
- HwInitData.DmaBufferSize = 0;
- HwInitData.TurnOffSynchronization = TRUE;
- status = StreamClassRegisterAdapter(DriverObject ,RegistryPath ,&HwInitData);
- KdPrint(("退出DriverEntry函数\n"));
- return status;
- }
- VOID AdapterReceivePacket(IN PHW_STREAM_REQUEST_BLOCK pSrb)
- {
- PHW_DEVICE_EXTENSION pHwDevExt = ((PHW_DEVICE_EXTENSION)pSrb->HwDeviceExtension);
- BOOL Busy;
- DEBUG_ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
- KdPrint(("TestCap: Receiving Adapter SRB %8x, %x\n", pSrb, pSrb->Command));
- // The very first time through, we need to initialize the adapter spinlock
- // and queue
- if (!pHwDevExt->AdapterQueueInitialized)
- {
- InitializeListHead (&pHwDevExt->AdapterSRBList);
- KeInitializeSpinLock (&pHwDevExt->AdapterSpinLock);
- pHwDevExt->AdapterQueueInitialized = TRUE;
- pHwDevExt->ProcessingAdapterSRB = FALSE;
- }
- //
- // If we're already processing an SRB, add it to the queue
- //
- Busy = AddToListIfBusy (
- pSrb,
- &pHwDevExt->AdapterSpinLock,
- &pHwDevExt->ProcessingAdapterSRB,
- &pHwDevExt->AdapterSRBList);
- if (Busy)
- {
- return;
- }
- //
- // This will run until the queue is empty
- //
- while (TRUE)
- {
- //
- // Assume success
- //
- pSrb->Status = STATUS_SUCCESS;
- //
- // determine the type of packet.
- //
- switch (pSrb->Command)
- {
- case SRB_INITIALIZE_DEVICE:
- // open the device
- HwInitialize(pSrb);
- break;
- case SRB_UNINITIALIZE_DEVICE:
- // close the device.
- HwUnInitialize(pSrb);
- break;
- case SRB_OPEN_STREAM:
- // open a stream
- AdapterOpenStream(pSrb);
- break;
- case SRB_CLOSE_STREAM:
- // close a stream
- AdapterCloseStream(pSrb);
- break;
- case SRB_GET_STREAM_INFO:
- //
- // return a block describing all the streams
- //
- AdapterStreamInfo(pSrb);
- break;
- case SRB_GET_DATA_INTERSECTION:
- //
- // Return a format, given a range
- //
- AdapterFormatFromRange(pSrb);
- break;
- case SRB_OPEN_DEVICE_INSTANCE:
- case SRB_CLOSE_DEVICE_INSTANCE:
- //
- // We should never get these since this is a single instance device
- //
- pSrb->Status = STATUS_NOT_IMPLEMENTED;
- break;
- case SRB_GET_DEVICE_PROPERTY:
- //
- // Get adapter wide properties
- //
- AdapterGetProperty (pSrb);
- break;
- case SRB_SET_DEVICE_PROPERTY:
- //
- // Set adapter wide properties
- //
- AdapterSetProperty (pSrb);
- break;
- case SRB_PAGING_OUT_DRIVER:
- //
- // The driver is being paged out
- // Disable Interrupts if you have them!
- //
- KdPrint(("'Testcap: Receiving SRB_PAGING_OUT_DRIVER -- SRB=%x\n", pSrb));
- break;
- case SRB_CHANGE_POWER_STATE:
- //
- // Changing the device power state, D0 ... D3
- //
- KdPrint(("'Testcap: Receiving SRB_CHANGE_POWER_STATE ------ SRB=%x\n", pSrb));
- AdapterPowerState(pSrb);
- break;
- case SRB_INITIALIZATION_COMPLETE:
- //
- // Stream class has finished initialization.
- // Now create DShow Medium interface BLOBs.
- // This needs to be done at low priority since it uses the registry
- //
- KdPrint(("'Testcap: Receiving SRB_INITIALIZATION_COMPLETE-- SRB=%x\n", pSrb));
- break;
- case SRB_UNKNOWN_DEVICE_COMMAND:
- default:
- //
- // this is a request that we do not understand. Indicate invalid
- // command and complete the request
- //
- pSrb->Status = STATUS_NOT_IMPLEMENTED;
- }
- //
- // Indicate back to the Stream Class that we're done with this SRB
- //
- CompleteDeviceSRB (pSrb);
- //
- // See if there's anything else on the queue
- //
- Busy = RemoveFromListIfAvailable (
- &pSrb,
- &pHwDevExt->AdapterSpinLock,
- &pHwDevExt->ProcessingAdapterSRB,
- &pHwDevExt->AdapterSRBList);
- if (!Busy)
- {
- break;
- }
- } // end of while there's anything in the queue
- }
- BOOLEAN STREAMAPI HwInitialize ( IN OUT PHW_STREAM_REQUEST_BLOCK pSrb )
- {
- STREAM_PHYSICAL_ADDRESS adr;
- ULONG Size;
- PUCHAR pDmaBuf;
- int j;
- PPORT_CONFIGURATION_INFORMATION ConfigInfo = pSrb->CommandData.ConfigInfo;
- PHW_DEVICE_EXTENSION pHwDevExt = (PHW_DEVICE_EXTENSION)ConfigInfo->HwDeviceExtension;
- KdPrint(("Enter the function of 'HwInitialize'\n"));
- KdPrint(("TestCap: Number of access ranges = %lx\n", ConfigInfo->NumberOfAccessRanges));
- KdPrint(("TestCap: Memory Range = %lx\n", pHwDevExt->ioBaseLocal));
- KdPrint(("TestCap: IRQ = %lx\n", ConfigInfo->BusInterruptLevel));
- if (ConfigInfo->NumberOfAccessRanges != 0)
- {
- pHwDevExt->ioBaseLocal = (PULONG)(ULONG_PTR)(ConfigInfo->AccessRanges[1].RangeStart.LowPart);
- }
- pHwDevExt->Irq = (USHORT)(ConfigInfo->BusInterruptLevel);
- ConfigInfo->StreamDescriptorSize = sizeof (HW_STREAM_HEADER) +
- DRIVER_STREAM_COUNT * sizeof (HW_STREAM_INFORMATION);
- pDmaBuf = StreamClassGetDmaBuffer(pHwDevExt);
- adr = StreamClassGetPhysicalAddress(pHwDevExt,
- NULL, pDmaBuf, DmaBuffer, &Size);
- // Init VideoProcAmp properties
- pHwDevExt->Brightness = BrightnessDefault;
- pHwDevExt->BrightnessFlags = KSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
- pHwDevExt->Contrast = ContrastDefault;
- pHwDevExt->ContrastFlags = KSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
- pHwDevExt->ColorEnable = ColorEnableDefault;
- pHwDevExt->ColorEnableFlags = KSPROPERTY_VIDEOPROCAMP_FLAGS_MANUAL;
- // Init CameraControl properties
- pHwDevExt->Focus = FocusDefault;
- pHwDevExt->FocusFlags = KSPROPERTY_CAMERACONTROL_FLAGS_AUTO;
- pHwDevExt->Zoom = ZoomDefault;
- pHwDevExt->ZoomFlags = KSPROPERTY_CAMERACONTROL_FLAGS_AUTO;
- // Init VideoControl properties
- pHwDevExt->VideoControlMode = 0;
- // Init VideoCompression properties
- pHwDevExt->CompressionSettings.CompressionKeyFrameRate = 15;
- pHwDevExt->CompressionSettings.CompressionPFramesPerKeyFrame = 3;
- pHwDevExt->CompressionSettings.CompressionQuality = 5000;
- pHwDevExt->PDO = ConfigInfo->RealPhysicalDeviceObject;
- KdPrint(("TestCap: Physical Device Object = %lx\n", pHwDevExt->PDO));
- for (j = 0; j < MAX_TESTCAP_STREAMS; j++)
- {
- // For each stream, maintain a separate queue for data and control
- InitializeListHead (&pHwDevExt->StreamSRBList[j]);
- InitializeListHead (&pHwDevExt->StreamControlSRBList[j]);
- KeInitializeSpinLock (&pHwDevExt->StreamSRBSpinLock[j]);
- pHwDevExt->StreamSRBListSize[j] = 0;
- }
- // Init ProtectionStatus
- pHwDevExt->ProtectionStatus = 0;
- // The following allows multiple instance of identical hardware
- // to be installed. GlobalDriverMediumInstanceCount is set in the Medium.Id field.
- pHwDevExt->DriverMediumInstanceCount = GlobalDriverMediumInstanceCount++;
- pSrb->Status = STATUS_SUCCESS;
-
- KdPrint(("Exit the function of 'HwInitialize'\n"));
- return (TRUE);
- }
复制代码 |
|