summaryrefslogtreecommitdiff
path: root/general/SimpleMediaSource/SimpleMediaSourceDriver/Device.c
diff options
context:
space:
mode:
authorPeihsun Yeh <[email protected]>2018-08-14 12:16:17 -0700
committerPeihsun Yeh <[email protected]>2018-08-14 12:16:17 -0700
commitc6a43d3aad9a76d1ba702e4cabd394082ce4f70a (patch)
tree09e183ac1a637631ee570db135f99f9e7942eae0 /general/SimpleMediaSource/SimpleMediaSourceDriver/Device.c
parentfd1d9958e8df60ad1e3dfb4312d4ff13e1e7ea92 (diff)
Added driver project, but it is not building yet
Diffstat (limited to 'general/SimpleMediaSource/SimpleMediaSourceDriver/Device.c')
-rw-r--r--general/SimpleMediaSource/SimpleMediaSourceDriver/Device.c115
1 files changed, 115 insertions, 0 deletions
diff --git a/general/SimpleMediaSource/SimpleMediaSourceDriver/Device.c b/general/SimpleMediaSource/SimpleMediaSourceDriver/Device.c
new file mode 100644
index 00000000..0cf7979e
--- /dev/null
+++ b/general/SimpleMediaSource/SimpleMediaSourceDriver/Device.c
@@ -0,0 +1,115 @@
+/*++
+
+Module Name:
+
+ device.c - Device handling events for example driver.
+
+Abstract:
+
+ This file contains the device entry points and callbacks.
+
+Environment:
+
+ User-mode Driver Framework 2
+
+--*/
+
+#include "driver.h"
+#include "device.tmh"
+
+GUID CAMERA_CATEGORY = { STATIC_KSCATEGORY_VIDEO_CAMERA };
+GUID CAPTURE_CATEGORY = { STATIC_KSCATEGORY_CAPTURE };
+GUID VIDEO_CATEGORY = { STATIC_KSCATEGORY_VIDEO };
+
+NTSTATUS
+SimpleMediaSourceDriverCreateDevice(
+ _Inout_ PWDFDEVICE_INIT DeviceInit
+ )
+/*++
+
+Routine Description:
+
+ Worker routine called to create a device and its software resources.
+
+Arguments:
+
+ DeviceInit - Pointer to an opaque init structure. Memory for this
+ structure will be freed by the framework when the WdfDeviceCreate
+ succeeds. So don't access the structure after that point.
+
+Return Value:
+
+ NTSTATUS
+
+--*/
+{
+ WDF_OBJECT_ATTRIBUTES deviceAttributes;
+ PDEVICE_CONTEXT deviceContext;
+ WDFDEVICE device;
+ NTSTATUS status;
+
+ WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&deviceAttributes, DEVICE_CONTEXT);
+
+ status = WdfDeviceCreate(&DeviceInit, &deviceAttributes, &device);
+
+ if (NT_SUCCESS(status)) {
+ //
+ // Get a pointer to the device context structure that we just associated
+ // with the device object. We define this structure in the device.h
+ // header file. DeviceGetContext is an inline function generated by
+ // using the WDF_DECLARE_CONTEXT_TYPE_WITH_NAME macro in device.h.
+ // This function will do the type checking and return the device context.
+ // If you pass a wrong object handle it will return NULL and assert if
+ // run under framework verifier mode.
+ //
+ deviceContext = DeviceGetContext(device);
+
+ //
+ // Initialize the context.
+ //
+ deviceContext->PrivateDeviceData = 0;
+
+ //
+ // Create a device interface so that applications can find and talk
+ // to us.
+ //
+ status = WdfDeviceCreateDeviceInterface(
+ device,
+ &GUID_DEVINTERFACE_SimpleMediaSourceDriver,
+ NULL // ReferenceString
+ );
+
+ if (NT_SUCCESS(status)) {
+ //
+ // Create a device interface so that application can find and talk
+ // to us.
+ //
+ status = WdfDeviceCreateDeviceInterface(
+ device,
+ &CAPTURE_CATEGORY,
+ NULL // ReferenceString
+ );
+ }
+
+ if (NT_SUCCESS(status)) {
+ //
+ // Create a device interface so that application can find and talk
+ // to us.
+ //
+ status = WdfDeviceCreateDeviceInterface(
+ device,
+ &VIDEO_CATEGORY,
+ NULL // ReferenceString
+ );
+ }
+
+ if (NT_SUCCESS(status)) {
+ //
+ // Initialize the I/O Package and any Queues
+ //
+ status = SimpleMediaSourceDriverQueueInitialize(device);
+ }
+ }
+
+ return status;
+}