diff options
Diffstat (limited to 'avstream/avshws')
| -rw-r--r-- | avstream/avshws/README.md | 19 | ||||
| -rw-r--r-- | avstream/avshws/avshws.h | 125 | ||||
| -rw-r--r-- | avstream/avshws/device.cpp | 185 |
3 files changed, 198 insertions, 131 deletions
diff --git a/avstream/avshws/README.md b/avstream/avshws/README.md index 73d4a389..19019304 100644 --- a/avstream/avshws/README.md +++ b/avstream/avshws/README.md @@ -1,3 +1,12 @@ +<!--- + name: AVStream simulated hardware sample driver (Avshws) + platform: WDM + language: cpp + category: Camera + description: A simulated hardware sample driver providing a pin-centric capture driver to simulate AV capture hardware. + samplefwlink: http://go.microsoft.com/fwlink/p/?LinkId=620185 +---> + AVStream simulated hardware sample driver (Avshws) ================================================== @@ -8,7 +17,7 @@ This sample features enhanced parameter validation and overflow detection. Provision a target computer --------------------------- -After you've installed the sample on your host computer, run Visual Studio, and from the **File** menu, select **Open**, then **Project/Solution...**, navigate to the directory where you've copied the Avshws sample, then to the C++ folder, and select **avshws.vcxproj** (the VC++ Project). +After you've cloned the sample repo to your host computer, run Visual Studio, and from the **File** menu, select **Open**, then **Project/Solution...**, navigate to the Avshws sample directory, and select **avshws.sln**. In the **Solution Explorer** pane in Visual Studio, at the top is **Solution 'avshws'**. Right-click this and select **Configuration Manager**. Follow the instructions in [Building a Driver with the WDK](http://msdn.microsoft.com/en-us/library/windows/hardware/ff554644) to set the platform, operating system, and debug configuration you want to use, and to build the sample. This sample project will automatically sign the driver package. @@ -17,7 +26,7 @@ Provision your target computer using instructions in, for example, [Preparing a Deploy the driver to the target computer ---------------------------------------- -Now you can deploy the Avshws driver that you've just built to the target computer, using guidance in [Deploying a Driver to a Test Computer](http://msdn.microsoft.com/en-us/library/windows/hardware/hh454834). Specifically, find the package file under the **Package** folder in the Avshws solution. Right-click **package** and select **Properties**. Under Configuration Properties, click **Driver install** and then **Deployment**. Here you must click the check box for **Enable deployment**, and then click the button to the right of **\<Configure Computer...\>**. In the next dialog you enter the **Target Computer Name** and can let the host computer automatically provision the target computer and set up debugger options. +Now you can deploy the Avshws driver that you've just built to the target computer, using guidance in [Deploying a Driver to a Test Computer](https://docs.microsoft.com/windows-hardware/drivers/develop/deploying-a-driver-to-a-test-computer). Specifically, in the Visual Studio Solution Explorer, right click the Avshws project and select **Properties**. Under Configuration Properties, click **Driver Install** and then **Deployment**. Enter the **Target Device Name** and the host computer automatically provisions the target computer and sets up debugger options. Finally, in Visual Studio, from the **Build** menu select **Deploy Solution** to deploy the sample to the target computer. On the target computer, you can see the deployed package in the **%Systemdrive%\\drivertest\\drivers** folder. @@ -26,7 +35,7 @@ Install the driver On the target computer, open Device Manager, and follow these steps: -1. In the **Action** menu, click **Add Legacy Hardware**, and the **Add Hardware Wizard** appears. Click **Next** and then **Next** again. +1. In the **Action** menu, select the top node and click **Add Legacy Hardware**. Click **Next** and then **Next** again. You might need to select **Have disk** and search for the driver in the target driver folder that was set up when the test computer was provisioned. 2. In the **Add Hardware** window, select **Show All Devices**. 3. In the **Manufacturer** list in the left pane, click **Microsoft**. 4. You should see the **AVStream Simulated Hardware Sample** in the **Model** pane on the right. Click this and then click **Next**. @@ -55,8 +64,8 @@ Run the sample Follow these steps to see how the sample driver functions: 1. After installation has completed, access the driver through the Graphedt tool. Graphedt.exe is available in the *tools* directory of the WDK. -2. Before running GraphEdit, use the regsvr32 utility to register the proppage.dll DLL and to enable GraphEdit to display property pages for some of the built-in Microsoft DirectShow filters. Open an elevated command window with Administrator privileges, and navigate to the WDK or SDK *tools* directory that contains proppage.dll. -3. On the command line, type regsvr32 proppage.dll. If the registration succeeds, you'll get a message, "DllRegisterServer in proppage.dll succeeded." Click OK. +2. Before running GraphEdt, use the regsvr32 utility to register the proppage.dll DLL and to enable GraphEdit to display property pages for some of the built-in Microsoft DirectShow filters. Open an elevated command window with Administrator privileges, and navigate to the WDK or SDK *tools* directory that contains proppage.dll. +3. On the command line, type `regsvr32 "c:\Program Files (x86)\Windows Kits\10\Tools\x64\proppage.dll"`. If the registration succeeds, you'll get a message, "DllRegisterServer in proppage.dll succeeded." Click OK. 4. In the Graphedt tool, click the **Graph** menu and click **Insert Filters**. The sample appears under "WDM Streaming Capture Devices" as "avshws Source." 5. Click **Insert Filter**. The sample appears in the graph as a single filter labeled, "avshws Source." There is one output pin, which is the video capture pin. This pin emits video in YUY2 format. 6. Attach this filter to either a DirectShow Video Renderer or to the VMR default video renderer. Then click **Play**. diff --git a/avstream/avshws/avshws.h b/avstream/avshws/avshws.h index 70f220f3..a6b3d8bc 100644 --- a/avstream/avshws/avshws.h +++ b/avstream/avshws/avshws.h @@ -10,7 +10,7 @@ Abstract: - AVStream Simulated Hardware Sample header file. This is the + AVStream Simulated Hardware Sample header file. This is the main header. History: @@ -43,6 +43,14 @@ extern "C" { #include <unknown.h> #include <ks.h> #include <ksmedia.h> + +// Note: Since VS2015 Update 2 overloaded operator new and operator delete may not +// be declared inline (Level 1 (/W1) on-by-default, warning C4595). +// See https://msdn.microsoft.com/en-us/library/mt656697.aspx +// +// To mitigate this issue, add "#define _NEW_DELETE_OPERATORS_" before "#include <kcom.h>" +// and implement non-inline operator new and operator delete locally. +#define _NEW_DELETE_OPERATORS_ #include <kcom.h> /************************************************* @@ -76,7 +84,7 @@ const DebugLevel = DEBUGLVL_TERSE; #define ABS(x) ((x) < 0 ? (-(x)) : (x)) -#ifndef mmioFOURCC +#ifndef mmioFOURCC #define mmioFOURCC( ch0, ch1, ch2, ch3 ) \ ( (DWORD)(BYTE)(ch0) | ( (DWORD)(BYTE)(ch1) << 8 ) | \ ( (DWORD)(BYTE)(ch2) << 16 ) | ( (DWORD)(BYTE)(ch3) << 24 ) ) @@ -137,12 +145,12 @@ CaptureFilterCategories [CAPTURE_FILTER_CATEGORIES_COUNT]; // // capture.cpp externs: // -extern +extern const KSALLOCATOR_FRAMING_EX CapturePinAllocatorFraming; -extern +extern const KSPIN_DISPATCH CapturePinDispatch; @@ -210,103 +218,38 @@ public: }; - /************************************************* Global Functions *************************************************/ -/*++ - -Routine Description: - - Array delete() operator. - -Arguments: - - pVoid - - The memory to free. - -Return Value: - - None - ---*/ -inline -void -__cdecl -operator delete[]( - PVOID pVoid -) -{ - if (pVoid) - { - ExFreePool(pVoid); - } -} - -/*++ - -Routine Description: - - Sized delete() operator. - -Arguments: - - pVoid - - The memory to free. - - size - - The size of the memory to free. - -Return Value: - - None - ---*/ -inline void __cdecl operator delete +void __cdecl operator delete[] ( - void *pVoid, - size_t /*size*/ -) -{ - if (pVoid) - { - ExFreePool(pVoid); - } -} - -/*++ + PVOID pVoid +); -Routine Description: - - Sized delete[]() operator. - -Arguments: - - pVoid - - The memory to free. - - size - - The size of the memory to free. - -Return Value: +void __cdecl operator delete +( + void *pVoid, + size_t /*size*/ +); - None +void __cdecl operator delete[] +( + void *pVoid, + size_t /*size*/ +); ---*/ -inline void __cdecl operator delete[] +PVOID operator new ( - void *pVoid, - size_t /*size*/ -) -{ - if (pVoid) - { - ExFreePool(pVoid); - } -} + size_t iSize, + _When_((poolType & NonPagedPoolMustSucceed) != 0, + __drv_reportError("Must succeed pool allocations are forbidden. " + "Allocation failures cause a system crash")) + POOL_TYPE poolType, + ULONG tag +); /************************************************* @@ -320,4 +263,4 @@ inline void __cdecl operator delete[] #include "filter.h" #include "capture.h" #include <uuids.h> -#endif //_avshws_h_
\ No newline at end of file +#endif //_avshws_h_ diff --git a/avstream/avshws/device.cpp b/avstream/avshws/device.cpp index 75b06cd5..2f54aca4 100644 --- a/avstream/avshws/device.cpp +++ b/avstream/avshws/device.cpp @@ -161,7 +161,7 @@ Return Value: // // By PnP, it's possible to receive multiple starts without an intervening // stop (to reevaluate resources, for example). Thus, we only perform - // creations of the simulation on the initial start and ignore any + // creations of the simulation on the initial start and ignore any // subsequent start. Hardware drivers with resources should evaluate // resources and make changes on 2nd start. // @@ -173,7 +173,7 @@ Return Value: // If we couldn't create the hardware simulation, fail. // Status = STATUS_INSUFFICIENT_RESOURCES; - + } else { Status = KsAddItemToObjectBag ( m_Device -> Bag, @@ -197,15 +197,15 @@ Return Value: // // Set up DMA... // - // Ordinarilly, we'd be using InterfaceBuffer or - // InterfaceTypeUndefined if !NT_SUCCESS (IfStatus) as the - // InterfaceType below; however, for the purposes of this sample, + // Ordinarilly, we'd be using InterfaceBuffer or + // InterfaceTypeUndefined if !NT_SUCCESS (IfStatus) as the + // InterfaceType below; however, for the purposes of this sample, // we lie and say we're on the PCI Bus. Otherwise, we're using map // registers on x86 32 bit physical to 32 bit logical and this isn't // what I want to show in this sample. // // - // NTSTATUS IfStatus = + // NTSTATUS IfStatus = IoGetDeviceProperty ( m_Device -> PhysicalDeviceObject, @@ -216,7 +216,7 @@ Return Value: ); // - // Initialize our fake device description. We claim to be a + // Initialize our fake device description. We claim to be a // bus-mastering 32-bit scatter/gather capable piece of hardware. // DeviceDescription.Version = DEVICE_DESCRIPTION_VERSION; @@ -229,7 +229,7 @@ Return Value: DeviceDescription.Dma32BitAddresses = TRUE; DeviceDescription.AutoInitialize = FALSE; DeviceDescription.MaximumLength = (ULONG) -1; - + // // Get a DMA adapter object from the system. // @@ -238,21 +238,21 @@ Return Value: &DeviceDescription, &m_NumberOfMapRegisters ); - + if (!m_DmaAdapterObject) { Status = STATUS_UNSUCCESSFUL; } - + } - + if (NT_SUCCESS (Status)) { // - // Initialize our DMA adapter object with AVStream. This is + // Initialize our DMA adapter object with AVStream. This is // **ONLY** necessary **IF** you are doing DMA directly into // capture buffers as this sample does. For this, // KSPIN_FLAG_GENERATE_MAPPINGS must be specified on a queue. // - + // // The (1 << 20) below is the maximum size of a single s/g mapping // that this hardware can handle. Note that I have pulled this @@ -264,11 +264,11 @@ Return Value: (1 << 20), sizeof (KSMAPPING) ); - + } #endif } - + return Status; } @@ -306,7 +306,7 @@ Return Value: // // Return the DMA adapter back to the system. // - m_DmaAdapterObject -> DmaOperations -> + m_DmaAdapterObject -> DmaOperations -> PutDmaAdapter (m_DmaAdapterObject); m_DmaAdapterObject = NULL; @@ -328,7 +328,7 @@ AcquireHardwareResources ( Routine Description: - Acquire hardware resources for the capture hardware. If the + Acquire hardware resources for the capture hardware. If the resources are already acquired, this will return an error. The hardware configuration must be passed as a VideoInfoHeader. @@ -376,44 +376,44 @@ Return Value: delete m_ImageSynth; m_ImageSynth = NULL; } - + // // Create the necessary type of image synthesizer. // if (m_VideoInfoHeader -> bmiHeader.biBitCount == 24 && m_VideoInfoHeader -> bmiHeader.biCompression == KS_BI_RGB) { - + // // If we're RGB24, create a new RGB24 synth. RGB24 surfaces // can be in either orientation. The origin is lower left if // height < 0. Otherwise, it's upper left. // - m_ImageSynth = new (NonPagedPoolNx, 'RysI') + m_ImageSynth = new (NonPagedPoolNx, 'RysI') CRGB24Synthesizer ( m_VideoInfoHeader -> bmiHeader.biHeight >= 0 ); - + } else if (m_VideoInfoHeader -> bmiHeader.biBitCount == 16 && (m_VideoInfoHeader -> bmiHeader.biCompression == FOURCC_YUY2)) { - + // // If we're UYVY, create the YUV synth. // m_ImageSynth = new(NonPagedPoolNx, 'YysI') CYUVSynthesizer; - + } else // // We don't synthesize anything but RGB 24 and UYVY. // Status = STATUS_INVALID_PARAMETER; - + if (NT_SUCCESS (Status) && !m_ImageSynth) { - + Status = STATUS_INSUFFICIENT_RESOURCES; - - } + + } if (NT_SUCCESS (Status)) { // @@ -428,7 +428,7 @@ Return Value: // ReleaseHardwareResources (); } - + } else { // @@ -660,9 +660,9 @@ Return Value: PAGED_CODE(); - - return + + return m_HardwareSimulation -> ProgramScatterGatherMappings ( Clone, Buffer, @@ -749,7 +749,7 @@ Return Value: // of hardware registers (ReadNumberOfMappingsCompleted) which would likely // be done in the ISR. // - ULONG NumMappingsCompleted = + ULONG NumMappingsCompleted = m_HardwareSimulation -> ReadNumberOfMappingsCompleted (); // @@ -774,7 +774,7 @@ Return Value: // CaptureFilterDescriptor: // // The filter descriptor for the capture device. -DEFINE_KSFILTER_DESCRIPTOR_TABLE (FilterDescriptors) { +DEFINE_KSFILTER_DESCRIPTOR_TABLE (FilterDescriptors) { &CaptureFilterDescriptor }; @@ -810,8 +810,8 @@ CaptureDeviceDispatch = { // This is the device descriptor for the capture device. It points to the // dispatch table and contains a list of filter descriptors that describe // filter-types that this device supports. Note that the filter-descriptors -// can be created dynamically and the factories created via -// KsCreateFilterFactory as well. +// can be created dynamically and the factories created via +// KsCreateFilterFactory as well. // const KSDEVICE_DESCRIPTOR @@ -865,7 +865,7 @@ Return Value: // at add & start. Everything is done based on the descriptors passed // here. // - return + return KsInitializeDriver ( DriverObject, RegistryPath, @@ -873,3 +873,118 @@ Return Value: ); } + +/************************************************* + + Global Functions + +*************************************************/ + +/*++ + +Routine Description: + + Array delete() operator. + +Arguments: + + pVoid - + The memory to free. + +Return Value: + + None + +--*/ +void +__cdecl +operator delete[]( + PVOID pVoid +) +{ + if (pVoid) + { + ExFreePool(pVoid); + } +} + +/*++ + +Routine Description: + + Sized delete() operator. + +Arguments: + + pVoid - + The memory to free. + + size - + The size of the memory to free. + +Return Value: + + None + +--*/ +void __cdecl operator delete +( + void *pVoid, + size_t /*size*/ +) +{ + if (pVoid) + { + ExFreePool(pVoid); + } +} + +/*++ + +Routine Description: + + Sized delete[]() operator. + +Arguments: + + pVoid - + The memory to free. + + size - + The size of the memory to free. + +Return Value: + + None + +--*/ +void __cdecl operator delete[] +( + void *pVoid, + size_t /*size*/ +) +{ + if (pVoid) + { + ExFreePool(pVoid); + } +} + +PVOID operator new +( + size_t iSize, + _When_((poolType & NonPagedPoolMustSucceed) != 0, + __drv_reportError("Must succeed pool allocations are forbidden. " + "Allocation failures cause a system crash")) + POOL_TYPE poolType, + ULONG tag +) +{ + PVOID result = ExAllocatePoolWithTag(poolType,iSize,tag); + + if (result) { + RtlZeroMemory(result,iSize); + } + + return result; +} |
