From 1e87469a012d6c60e34e873b5c1139bc0e7392a7 Mon Sep 17 00:00:00 2001 From: Sanjeev Reddy Date: Wed, 6 Feb 2019 18:20:26 -0800 Subject: Updating samples with RS5 changes and setting DriverTargetPlatform to Universal to enable API Validator --- avstream/avscamera/Package/package.VcxProj | 4 + avstream/avscamera/mft0/AvsCameraMft0.vcxproj | 13 ++- .../avscamera/mft0/AvsCameraMft0.vcxproj.Filters | 41 ++++++++-- avstream/avscamera/sys/CameraProfile.h | 2 +- avstream/avscamera/sys/Capture.cpp | 23 ++++-- avstream/avscamera/sys/Capture.h | 6 ++ avstream/avscamera/sys/Common.h | 5 +- avstream/avscamera/sys/Device.cpp | 95 +++++++++++++++++++++- avstream/avscamera/sys/Device.h | 18 ++-- avstream/avscamera/sys/Sensor.h | 1 + avstream/avscamera/sys/SensorSimulation.cpp | 53 ++++++++---- avstream/avscamera/sys/SensorSimulation.h | 8 ++ avstream/avscamera/sys/formats.cpp | 28 +++++++ avstream/avscamera/sys/hwsim.cpp | 51 +++++++++--- avstream/avscamera/sys/hwsim.h | 12 +++ 15 files changed, 307 insertions(+), 53 deletions(-) diff --git a/avstream/avscamera/Package/package.VcxProj b/avstream/avscamera/Package/package.VcxProj index 92690b1a..5b8aa6ef 100644 --- a/avstream/avscamera/Package/package.VcxProj +++ b/avstream/avscamera/Package/package.VcxProj @@ -42,18 +42,22 @@ Windows10 true + Universal Windows10 false + Universal Windows10 true + Universal Windows10 false + Universal diff --git a/avstream/avscamera/mft0/AvsCameraMft0.vcxproj b/avstream/avscamera/mft0/AvsCameraMft0.vcxproj index 3e071c71..19613a5f 100644 --- a/avstream/avscamera/mft0/AvsCameraMft0.vcxproj +++ b/avstream/avscamera/mft0/AvsCameraMft0.vcxproj @@ -31,7 +31,7 @@ Windows10 False - Desktop + Universal WindowsApplicationForDrivers10.0 DynamicLibrary @@ -39,7 +39,7 @@ Windows10 True - Desktop + Universal WindowsApplicationForDrivers10.0 DynamicLibrary @@ -47,7 +47,7 @@ Windows10 False - Desktop + Universal WindowsApplicationForDrivers10.0 DynamicLibrary @@ -55,7 +55,7 @@ Windows10 True - Desktop + Universal WindowsApplicationForDrivers10.0 DynamicLibrary @@ -175,7 +175,12 @@ %(AdditionalDependencies);mfplat.lib;uuid.lib;mfuuid.lib;OneCoreUAP.lib Mft0.def + + + + MultiThreadedDebugDLL + diff --git a/avstream/avscamera/mft0/AvsCameraMft0.vcxproj.Filters b/avstream/avscamera/mft0/AvsCameraMft0.vcxproj.Filters index ec3124e3..2968ed03 100644 --- a/avstream/avscamera/mft0/AvsCameraMft0.vcxproj.Filters +++ b/avstream/avscamera/mft0/AvsCameraMft0.vcxproj.Filters @@ -15,9 +15,6 @@ - - Source Files - Source Files @@ -30,13 +27,47 @@ Source Files - + Source Files - + Resource Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + Source Files + + \ No newline at end of file diff --git a/avstream/avscamera/sys/CameraProfile.h b/avstream/avscamera/sys/CameraProfile.h index 1a2aca8a..fd2f1fe4 100644 --- a/avstream/avscamera/sys/CameraProfile.h +++ b/avstream/avscamera/sys/CameraProfile.h @@ -28,7 +28,7 @@ public: public: CExtendedProfile( ULONGLONG flags=0, ULONG result=STATUS_SUCCESS ) - : CExtendedProfile( flags, result ) + : CExtendedHeader( flags, result ) { Size = sizeof(*this); m_Profile.ProfileId = KSCAMERAPROFILE_Legacy; diff --git a/avstream/avscamera/sys/Capture.cpp b/avstream/avscamera/sys/Capture.cpp index 77bd618c..e5d43ddd 100644 --- a/avstream/avscamera/sys/Capture.cpp +++ b/avstream/avscamera/sys/Capture.cpp @@ -2262,14 +2262,11 @@ UpdateAllocatorFraming() m_Pin->Descriptor->AllocatorFraming ); - Framing->FramingItem[0].Frames = m_DesiredFrames; - Framing->FramingItem[0].PhysicalRange.MinFrameSize = m_VideoInfoHeader->bmiHeader.biSizeImage; - Framing->FramingItem[0].PhysicalRange.MaxFrameSize = m_VideoInfoHeader->bmiHeader.biSizeImage; - Framing->FramingItem [0].FramingRange.Range.MinFrameSize = m_VideoInfoHeader->bmiHeader.biSizeImage; - Framing->FramingItem [0].FramingRange.Range.MaxFrameSize = m_VideoInfoHeader->bmiHeader.biSizeImage; + SetFramingSizes(Framing); - Framing->FramingItem [0].PhysicalRange.Stepping = 0; - Framing->FramingItem [0].FramingRange.Range.Stepping = 0; + Framing->FramingItem[0].Frames = m_DesiredFrames; + Framing->FramingItem[0].PhysicalRange.Stepping = 0; + Framing->FramingItem[0].FramingRange.Range.Stepping = 0; DBG_TRACE( "Advertising Frame requirement: %d", m_DesiredFrames ); DBG_TRACE("Image size estimate of: %d bytes", m_VideoInfoHeader->bmiHeader.biSizeImage ); @@ -2280,3 +2277,15 @@ UpdateAllocatorFraming() return Status; } +void +CCapturePin:: +SetFramingSizes( + PKSALLOCATOR_FRAMING_EX Framing +) +{ + Framing->FramingItem[0].PhysicalRange.MinFrameSize = m_VideoInfoHeader->bmiHeader.biSizeImage; + Framing->FramingItem[0].PhysicalRange.MaxFrameSize = m_VideoInfoHeader->bmiHeader.biSizeImage; + Framing->FramingItem[0].FramingRange.Range.MinFrameSize = m_VideoInfoHeader->bmiHeader.biSizeImage; + Framing->FramingItem[0].FramingRange.Range.MaxFrameSize = m_VideoInfoHeader->bmiHeader.biSizeImage; +} + diff --git a/avstream/avscamera/sys/Capture.h b/avstream/avscamera/sys/Capture.h index 0a065d24..21c9796a 100644 --- a/avstream/avscamera/sys/Capture.h +++ b/avstream/avscamera/sys/Capture.h @@ -188,6 +188,12 @@ protected: NTSTATUS Initialize(); + virtual + void + SetFramingSizes( + PKSALLOCATOR_FRAMING_EX Framing + ); + public: // // CCapturePin(): diff --git a/avstream/avscamera/sys/Common.h b/avstream/avscamera/sys/Common.h index 5c83f2fc..fdcb1c48 100644 --- a/avstream/avscamera/sys/Common.h +++ b/avstream/avscamera/sys/Common.h @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -190,8 +191,8 @@ void __cdecl operator delete[] // The number of ranges supported on the capture pin. // #define IMAGE_CAPTURE_PIN_DATA_RANGE_COUNT 2 -#define VIDEO_CAPTURE_PIN_DATA_RANGE_COUNT 30 -#define VIDEO_PREVIEW_PIN_DATA_RANGE_COUNT 15 +#define VIDEO_CAPTURE_PIN_DATA_RANGE_COUNT 32 +#define VIDEO_PREVIEW_PIN_DATA_RANGE_COUNT 16 // // CAPTURE_FILTER_CATEGORIES_COUNT: diff --git a/avstream/avscamera/sys/Device.cpp b/avstream/avscamera/sys/Device.cpp index 943b2f2b..99bc60ce 100644 --- a/avstream/avscamera/sys/Device.cpp +++ b/avstream/avscamera/sys/Device.cpp @@ -98,6 +98,98 @@ GetFilterIndex(PKSFILTER Filter) return i; } +NTSTATUS +CCaptureDevice:: +IrpSynchronousCompletion( + IN PDEVICE_OBJECT DeviceObject, + IN PIRP Irp, + IN PVOID pKevent + ) +{ + if (Irp->PendingReturned) + { + NT_ASSERT(pKevent); + KeSetEvent((PRKEVENT)pKevent, 0, FALSE); + } + + return STATUS_MORE_PROCESSING_REQUIRED; +} + +_Must_inspect_result_ +NTSTATUS +CCaptureDevice:: +QueryForInterface( + _In_ PDEVICE_OBJECT TopOfStack, + _In_ const GUID* InterfaceType, + _Out_ PINTERFACE Interface, + _In_ USHORT Size, + _In_ USHORT Version, + _In_opt_ PVOID InterfaceSpecificData + ) +{ + PAGED_CODE(); + + PIRP pIrp; + NTSTATUS status; + + if (TopOfStack == nullptr) + { + return STATUS_INVALID_PARAMETER; + } + + pIrp = IoAllocateIrp(TopOfStack->StackSize, FALSE); + + if (pIrp != NULL) + { + PIO_STACK_LOCATION stack; + KEVENT event; + + KeInitializeEvent(&event, NotificationEvent, FALSE); + + IoSetCompletionRoutine(pIrp, + IrpSynchronousCompletion, + &event, + TRUE, + TRUE, + TRUE); + + pIrp->IoStatus.Status = STATUS_NOT_SUPPORTED; + + stack = IoGetNextIrpStackLocation(pIrp); + + stack->MajorFunction = IRP_MJ_PNP; + stack->MinorFunction = IRP_MN_QUERY_INTERFACE; + + stack->Parameters.QueryInterface.Interface = Interface; + stack->Parameters.QueryInterface.InterfaceSpecificData = InterfaceSpecificData; + stack->Parameters.QueryInterface.Size = Size; + stack->Parameters.QueryInterface.Version = Version; + stack->Parameters.QueryInterface.InterfaceType = InterfaceType; + + status = IoCallDriver(TopOfStack, pIrp); + + if (status == STATUS_PENDING) + { + KeWaitForSingleObject( + &event, + Executive, + KernelMode, + FALSE, // Not alertable + NULL + ); + + status = pIrp->IoStatus.Status; + } + + IoFreeIrp(pIrp); + } + else { + status = STATUS_INSUFFICIENT_RESOURCES; + } + + return status; +} + NTSTATUS CCaptureDevice:: Prepare() @@ -111,6 +203,8 @@ Prepare() return Status; } + PKSDEVICE Device = m_Device; + // // Add the item to the object bag if we were successful. // Whenever the device goes away, the bag is cleaned up and @@ -120,7 +214,6 @@ Prepare() // the device mutex before doing this. For Windows XP, this is // not required, but it is still safe. // - PKSDEVICE Device = m_Device; LockDevice Lock(Device); Status = KsAddItemToObjectBag ( diff --git a/avstream/avscamera/sys/Device.h b/avstream/avscamera/sys/Device.h index 6a3133d6..95debada 100644 --- a/avstream/avscamera/sys/Device.h +++ b/avstream/avscamera/sys/Device.h @@ -106,6 +106,7 @@ protected: // This is a seperate helper function to allow the derived DispatchCreate // implementation to be as simple as is feasible. // + virtual NTSTATUS Prepare(); @@ -392,11 +393,18 @@ public: PDEVICE_OBJECT GetDeviceObject(); - PKSDEVICE - GetKsDevice() - { - return m_Device; - } + static IO_COMPLETION_ROUTINE CCaptureDevice::IrpSynchronousCompletion; + + virtual + NTSTATUS + QueryForInterface( + _In_ PDEVICE_OBJECT TopOfStack, + _In_ const GUID* InterfaceType, + _Out_ PINTERFACE Interface, + _In_ USHORT Size, + _In_ USHORT Version, + _In_opt_ PVOID InterfaceSpecificData + ); ULONG GetFilterIndex(PKSFILTER Filter); diff --git a/avstream/avscamera/sys/Sensor.h b/avstream/avscamera/sys/Sensor.h index 34997908..327b860a 100644 --- a/avstream/avscamera/sys/Sensor.h +++ b/avstream/avscamera/sys/Sensor.h @@ -446,6 +446,7 @@ public: // stop issuing. When this call returns, the "fake" hardware has // stopped accessing all s/g buffers, etc... // + virtual NTSTATUS Stop ( _In_ PKSPIN diff --git a/avstream/avscamera/sys/SensorSimulation.cpp b/avstream/avscamera/sys/SensorSimulation.cpp index 95824ca5..6ecd9007 100644 --- a/avstream/avscamera/sys/SensorSimulation.cpp +++ b/avstream/avscamera/sys/SensorSimulation.cpp @@ -493,6 +493,38 @@ Return Value: return STATUS_SUCCESS; } +NTSTATUS +CSensorSimulation:: +CreateHardwareSimulation( + _In_ LONG pinID, + _In_ const KSPIN_DESCRIPTOR_EX *pinDescriptors, + _Out_ CHardwareSimulation** pSim +) +{ + PAGED_CODE(); + // Video pin type + if (IsEqualGUID(*pinDescriptors[pinID].PinDescriptor.Category, PIN_CATEGORY_CAPTURE)) + { + *pSim = new (NonPagedPoolNx, 'ediV') CVideoHardwareSimulation(this, pinID); + m_VideoMask |= 1 << pinID; + } + else if (IsEqualGUID(*pinDescriptors[pinID].PinDescriptor.Category, PIN_CATEGORY_PREVIEW)) + { + *pSim = new (NonPagedPoolNx, 'verP') CPreviewHardwareSimulation(this, pinID); + m_PreviewMask |= 1 << pinID; // must set to enable photo confirmation... + } + else if (IsEqualGUID(*pinDescriptors[pinID].PinDescriptor.Category, PINNAME_IMAGE)) + { + *pSim = new (NonPagedPoolNx, 'litS') CImageHardwareSimulation(this, pinID); + m_StillMask |= 1 << pinID; + } + else { + return STATUS_NOT_FOUND; + } + + return STATUS_SUCCESS; +} + NTSTATUS CSensorSimulation:: Initialize() @@ -531,26 +563,11 @@ Return Value: { const KSPIN_DESCRIPTOR_EX *PinDescriptors = m_Descriptors->PinDescriptors; CHardwareSimulation *pSim=nullptr; - NT_ASSERT( m_Descriptors->PinDescriptorSize == sizeof( *PinDescriptors ) ); - // Video pin type - if( IsEqualGUID( *PinDescriptors[PinIndex].PinDescriptor.Category, PIN_CATEGORY_CAPTURE ) ) - { - pSim = new (NonPagedPoolNx, 'ediV') CVideoHardwareSimulation( this, PinIndex ); - m_VideoMask |= 1<ByteCount; + PUCHAR CommitBufferAddress = sGEntry->Virtual; + + ULONG BytesCopied = m_Synthesizer->DoCommit(CommitBufferAddress, CommitBufferSize, stride); + NT_ASSERT(BytesCopied); + DBG_TRACE("BytesCopied = %d", BytesCopied); + + return STATUS_SUCCESS; +} + +NTSTATUS +CHardwareSimulation:: +ValidateBuffer(PSCATTER_GATHER_ENTRY sGEntry) +{ + return STATUS_SUCCESS; +} + void CHardwareSimulation:: EmitFaceMetadata( @@ -1004,18 +1033,17 @@ Return Value: m_PinID, m_ImageSize, m_ScatterGatherMappingsQueued, m_ScatterGatherBytesQueued); NTSTATUS ntStatus = STATUS_SUCCESS; - ULONG BufferRemaining = m_ImageSize; // - // If there isn't a frame buffer queued, we justskip the frame and consider + // If there isn't a frame buffer queued, we just skip the frame and consider // it starvation. // while (BufferRemaining && !IsListEmpty(&m_ScatterGatherMappings) && - m_ScatterGatherBytesQueued >= BufferRemaining) + (!CheckForAvailableBuffer() || m_ScatterGatherBytesQueued >= BufferRemaining)) { - LIST_ENTRY *listEntry = RemoveHeadList (&m_ScatterGatherMappings); + LIST_ENTRY *listEntry = RemoveHeadList(&m_ScatterGatherMappings); m_ScatterGatherMappingsQueued--; PSCATTER_GATHER_ENTRY SGEntry = @@ -1050,10 +1078,13 @@ Return Value: Stride = (ULONG) ABS(FrameInfo->lSurfacePitch); } - // Have the synthesizer output a frame to the buffer. - ULONG BytesCopied = m_Synthesizer->DoCommit( SGEntry->Virtual, SGEntry->ByteCount, Stride ); - NT_ASSERT( BytesCopied ); - DBG_TRACE( "BytesCopied = %d", BytesCopied ); + ntStatus = ValidateBuffer(SGEntry); + if (!NT_SUCCESS(ntStatus)) + { + break; + } + + ntStatus = CommitImageData(SGEntry, Stride); //Adding time stamp if(m_PhotoConfirmationEntry.isRequired()) @@ -1091,9 +1122,9 @@ Return Value: } // Report an error if we used the last buffer. - if (BufferRemaining) + if (NT_SUCCESS(ntStatus) && BufferRemaining) { - //DBG_TRACE("BufferRemaining=%u", BufferRemaining); + DBG_TRACE("BufferRemaining=%u", BufferRemaining); ntStatus = STATUS_INSUFFICIENT_RESOURCES; } diff --git a/avstream/avscamera/sys/hwsim.h b/avstream/avscamera/sys/hwsim.h index 0a866eea..b326702f 100644 --- a/avstream/avscamera/sys/hwsim.h +++ b/avstream/avscamera/sys/hwsim.h @@ -145,6 +145,18 @@ protected: _Inout_ PKSSTREAM_HEADER pStreamHeader ); + virtual + bool + CheckForAvailableBuffer(); + + virtual + NTSTATUS + CommitImageData(PSCATTER_GATHER_ENTRY sGEntry, ULONG stride); + + virtual + NTSTATUS + ValidateBuffer(PSCATTER_GATHER_ENTRY sGEntry); + // Helper function to generate random face metadata. void EmitFaceMetadata( -- cgit v1.3.1 From d39c42d1fb29c0cce87e2cff76ba58ffdcad25c0 Mon Sep 17 00:00:00 2001 From: Sanjeev Reddy Date: Wed, 6 Feb 2019 18:27:10 -0800 Subject: Cleaning up extraneous project changes --- avstream/avscamera/mft0/AvsCameraMft0.vcxproj | 5 ----- 1 file changed, 5 deletions(-) diff --git a/avstream/avscamera/mft0/AvsCameraMft0.vcxproj b/avstream/avscamera/mft0/AvsCameraMft0.vcxproj index 19613a5f..518a324f 100644 --- a/avstream/avscamera/mft0/AvsCameraMft0.vcxproj +++ b/avstream/avscamera/mft0/AvsCameraMft0.vcxproj @@ -175,12 +175,7 @@ %(AdditionalDependencies);mfplat.lib;uuid.lib;mfuuid.lib;OneCoreUAP.lib Mft0.def - - - - MultiThreadedDebugDLL - -- cgit v1.3.1 From 2d1a3f431eb203f3ae7225a48cfbb7c584acb016 Mon Sep 17 00:00:00 2001 From: Sanjeev Reddy Date: Thu, 7 Feb 2019 16:01:00 -0800 Subject: Deleting project filters file --- .../avscamera/mft0/AvsCameraMft0.vcxproj.Filters | 73 ---------------------- 1 file changed, 73 deletions(-) delete mode 100644 avstream/avscamera/mft0/AvsCameraMft0.vcxproj.Filters diff --git a/avstream/avscamera/mft0/AvsCameraMft0.vcxproj.Filters b/avstream/avscamera/mft0/AvsCameraMft0.vcxproj.Filters deleted file mode 100644 index 2968ed03..00000000 --- a/avstream/avscamera/mft0/AvsCameraMft0.vcxproj.Filters +++ /dev/null @@ -1,73 +0,0 @@ - - - - - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx;* - {5293FBF9-AB37-479B-86A2-4DE6B858B90A} - - - h;hpp;hxx;hm;inl;inc;xsd - {BB11CFC9-BD19-4353-9E5F-42D5BA1A0CB3} - - - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms;man;xml - {49D3ED6A-39BD-49AC-96B4-4C1645E71934} - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - - - Resource Files - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - - - Source Files - - - \ No newline at end of file -- cgit v1.3.1