1 /* 2 * usbcamdi.h 3 * 4 * USB Camera driver interface. 5 * 6 * This file is part of the ReactOS PSDK package. 7 * 8 * Contributors: 9 * Created by Casper S. Hornstrup <chorns@users.sourceforge.net> 10 * 11 * THIS SOFTWARE IS NOT COPYRIGHTED 12 * 13 * This source code is offered for use in the public domain. You may 14 * use, modify or distribute it freely. 15 * 16 * This code is distributed in the hope that it will be useful but 17 * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY 18 * DISCLAIMED. This includes but is not limited to warranties of 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 20 * 21 */ 22 23 #pragma once 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 #if defined(_BATTERYCLASS_) 30 #define USBCAMAPI 31 #else 32 #define USBCAMAPI DECLSPEC_IMPORT 33 #endif 34 35 typedef struct _pipe_config_descriptor { 36 CHAR StreamAssociation; 37 UCHAR PipeConfigFlags; 38 } USBCAMD_Pipe_Config_Descriptor, *PUSBCAMD_Pipe_Config_Descriptor; 39 40 #define USBCAMD_DATA_PIPE 0x0001 41 #define USBCAMD_MULTIPLEX_PIPE 0x0002 42 #define USBCAMD_SYNC_PIPE 0x0004 43 #define USBCAMD_DONT_CARE_PIPE 0x0008 44 45 #define USBCAMD_VIDEO_STREAM 0x1 46 #define USBCAMD_STILL_STREAM 0x2 47 #define USBCAMD_VIDEO_STILL_STREAM (USBCAMD_VIDEO_STREAM | USBCAMD_STILL_STREAM) 48 49 #define USBCAMD_PROCESSPACKETEX_DropFrame 0x0002 50 #define USBCAMD_PROCESSPACKETEX_NextFrameIsStill 0x0004 51 #define USBCAMD_PROCESSPACKETEX_CurrentFrameIsStill 0x0008 52 53 #define USBCAMD_STOP_STREAM 0x00000001 54 #define USBCAMD_START_STREAM 0x00000000 55 56 typedef enum { 57 USBCAMD_CamControlFlag_NoVideoRawProcessing = 1, 58 USBCAMD_CamControlFlag_NoStillRawProcessing = 2, 59 USBCAMD_CamControlFlag_AssociatedFormat = 4, 60 USBCAMD_CamControlFlag_EnableDeviceEvents = 8 61 } USBCAMD_CamControlFlags; 62 63 typedef NTSTATUS 64 (NTAPI *PCOMMAND_COMPLETE_FUNCTION)( 65 IN PVOID DeviceContext, 66 IN OUT PVOID CommandContext, 67 IN NTSTATUS NtStatus); 68 69 typedef VOID 70 (NTAPI *PSTREAM_RECEIVE_PACKET)( 71 IN PVOID Srb, 72 IN PVOID DeviceContext, 73 IN PBOOLEAN Completed); 74 75 typedef NTSTATUS 76 (NTAPI *PCAM_INITIALIZE_ROUTINE)( 77 PDEVICE_OBJECT BusDeviceObject, 78 PVOID DeviceContext); 79 80 typedef NTSTATUS 81 (NTAPI *PCAM_CONFIGURE_ROUTINE)( 82 IN PDEVICE_OBJECT BusDeviceObject, 83 IN PVOID DeviceContext, 84 IN PUSBD_INTERFACE_INFORMATION Interface, 85 IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor, 86 IN PLONG DataPipeIndex, 87 IN PLONG SyncPipeIndex); 88 89 typedef NTSTATUS 90 (NTAPI *PCAM_CONFIGURE_ROUTINE_EX)( 91 IN PDEVICE_OBJECT BusDeviceObject, 92 IN PVOID DeviceContext, 93 IN PUSBD_INTERFACE_INFORMATION Interface, 94 IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor, 95 IN ULONG PipeConfigListSize, 96 IN PUSBCAMD_Pipe_Config_Descriptor PipeConfig, 97 IN PUSB_DEVICE_DESCRIPTOR DeviceDescriptor); 98 99 typedef NTSTATUS 100 (NTAPI *PCAM_START_CAPTURE_ROUTINE)( 101 IN PDEVICE_OBJECT BusDeviceObject, 102 IN PVOID DeviceContext); 103 104 typedef NTSTATUS 105 (NTAPI *PCAM_START_CAPTURE_ROUTINE_EX)( 106 IN PDEVICE_OBJECT BusDeviceObject, 107 IN PVOID DeviceContext, 108 IN ULONG StreamNumber); 109 110 typedef NTSTATUS 111 (NTAPI *PCAM_ALLOCATE_BW_ROUTINE)( 112 IN PDEVICE_OBJECT BusDeviceObject, 113 IN PVOID DeviceContext, 114 IN PULONG RawFrameLength, 115 IN PVOID Format); 116 117 typedef NTSTATUS 118 (NTAPI *PCAM_ALLOCATE_BW_ROUTINE_EX)( 119 IN PDEVICE_OBJECT BusDeviceObject, 120 IN PVOID DeviceContext, 121 IN PULONG RawFrameLength, 122 IN PVOID Format, 123 IN ULONG StreamNumber); 124 125 typedef NTSTATUS 126 (NTAPI *PCAM_FREE_BW_ROUTINE)( 127 IN PDEVICE_OBJECT BusDeviceObject, 128 IN PVOID DeviceContext); 129 130 typedef NTSTATUS 131 (NTAPI *PCAM_FREE_BW_ROUTINE_EX)( 132 IN PDEVICE_OBJECT BusDeviceObject, 133 IN PVOID DeviceContext, 134 IN ULONG StreamNumber); 135 136 typedef VOID 137 (NTAPI *PADAPTER_RECEIVE_PACKET_ROUTINE)( 138 IN OUT PHW_STREAM_REQUEST_BLOCK Srb); 139 140 typedef NTSTATUS 141 (NTAPI *PCAM_STOP_CAPTURE_ROUTINE)( 142 IN PDEVICE_OBJECT BusDeviceObject, 143 IN PVOID DeviceContext); 144 145 typedef NTSTATUS 146 (NTAPI *PCAM_STOP_CAPTURE_ROUTINE_EX)( 147 IN PDEVICE_OBJECT BusDeviceObject, 148 IN PVOID DeviceContext, 149 IN ULONG StreamNumber); 150 151 typedef ULONG 152 (NTAPI *PCAM_PROCESS_PACKET_ROUTINE)( 153 IN PDEVICE_OBJECT BusDeviceObject, 154 IN PVOID DeviceContext, 155 IN PVOID CurrentFrameContext, 156 IN PUSBD_ISO_PACKET_DESCRIPTOR SyncPacket OPTIONAL, 157 IN PVOID SyncBuffer OPTIONAL, 158 IN PUSBD_ISO_PACKET_DESCRIPTOR DataPacket OPTIONAL, 159 IN OUT PVOID DataBuffer, 160 OUT PBOOLEAN FrameComplete, 161 OUT PBOOLEAN NextFrameIsStill); 162 163 typedef ULONG 164 (NTAPI *PCAM_PROCESS_PACKET_ROUTINE_EX)( 165 IN PDEVICE_OBJECT BusDeviceObject, 166 IN PVOID DeviceContext, 167 IN PVOID CurrentFrameContext, 168 IN PUSBD_ISO_PACKET_DESCRIPTOR SyncPacket OPTIONAL, 169 IN PVOID SyncBuffer OPTIONAL, 170 IN PUSBD_ISO_PACKET_DESCRIPTOR DataPacket OPTIONAL, 171 IN OUT PVOID DataBuffer, 172 OUT PBOOLEAN FrameComplete, 173 OUT PULONG PacketFlag, 174 OUT PULONG ValidDataOffset); 175 176 typedef VOID 177 (NTAPI *PCAM_NEW_FRAME_ROUTINE)( 178 IN PVOID DeviceContext, 179 IN PVOID FrameContext); 180 181 typedef VOID 182 (NTAPI *PCAM_NEW_FRAME_ROUTINE_EX)( 183 IN PVOID DeviceContext, 184 IN PVOID FrameContext, 185 IN ULONG StreamNumber, 186 OUT PULONG FrameLength); 187 188 typedef NTSTATUS 189 (NTAPI *PCAM_PROCESS_RAW_FRAME_ROUTINE)( 190 IN PDEVICE_OBJECT BusDeviceObject, 191 IN PVOID DeviceContext, 192 IN PVOID FrameContext, 193 IN PVOID FrameBuffer, 194 IN ULONG FrameLength, 195 OUT PVOID RawFrameBuffer, 196 IN ULONG RawFrameLength, 197 IN ULONG NumberOfPackets, 198 OUT PULONG BytesReturned); 199 200 typedef NTSTATUS 201 (NTAPI *PCAM_PROCESS_RAW_FRAME_ROUTINE_EX)( 202 IN PDEVICE_OBJECT BusDeviceObject, 203 IN PVOID DeviceContext, 204 IN PVOID FrameContext, 205 IN PVOID FrameBuffer, 206 IN ULONG FrameLength, 207 OUT PVOID RawFrameBuffer, 208 IN ULONG RawFrameLength, 209 IN ULONG NumberOfPackets, 210 OUT PULONG BytesReturned, 211 IN ULONG ActualRawFrameLength, 212 IN ULONG StreamNumber); 213 214 typedef NTSTATUS 215 (NTAPI *PCAM_STATE_ROUTINE)( 216 IN PDEVICE_OBJECT BusDeviceObject, 217 IN PVOID DeviceContext); 218 219 #if defined(DEBUG_LOG) 220 221 USBCAMAPI 222 VOID 223 NTAPI 224 USBCAMD_Debug_LogEntry( 225 IN CHAR *Name, 226 IN ULONG Info1, 227 IN ULONG Info2, 228 IN ULONG Info3); 229 230 #define ILOGENTRY(sig, info1, info2, info3) \ 231 USBCAMD_Debug_LogEntry(sig, (ULONG)info1, (ULONG)info2, (ULONG)info3) 232 233 #else 234 235 #define ILOGENTRY(sig, info1, info2, info3) 236 237 #endif /* DEBUG_LOG */ 238 239 typedef struct _USBCAMD_DEVICE_DATA { 240 ULONG Sig; 241 PCAM_INITIALIZE_ROUTINE CamInitialize; 242 PCAM_INITIALIZE_ROUTINE CamUnInitialize; 243 PCAM_PROCESS_PACKET_ROUTINE CamProcessUSBPacket; 244 PCAM_NEW_FRAME_ROUTINE CamNewVideoFrame; 245 PCAM_PROCESS_RAW_FRAME_ROUTINE CamProcessRawVideoFrame; 246 PCAM_START_CAPTURE_ROUTINE CamStartCapture; 247 PCAM_STOP_CAPTURE_ROUTINE CamStopCapture; 248 PCAM_CONFIGURE_ROUTINE CamConfigure; 249 PCAM_STATE_ROUTINE CamSaveState; 250 PCAM_STATE_ROUTINE CamRestoreState; 251 PCAM_ALLOCATE_BW_ROUTINE CamAllocateBandwidth; 252 PCAM_FREE_BW_ROUTINE CamFreeBandwidth; 253 } USBCAMD_DEVICE_DATA, *PUSBCAMD_DEVICE_DATA; 254 255 typedef struct _USBCAMD_DEVICE_DATA2 { 256 ULONG Sig; 257 PCAM_INITIALIZE_ROUTINE CamInitialize; 258 PCAM_INITIALIZE_ROUTINE CamUnInitialize; 259 PCAM_PROCESS_PACKET_ROUTINE_EX CamProcessUSBPacketEx; 260 PCAM_NEW_FRAME_ROUTINE_EX CamNewVideoFrameEx; 261 PCAM_PROCESS_RAW_FRAME_ROUTINE_EX CamProcessRawVideoFrameEx; 262 PCAM_START_CAPTURE_ROUTINE_EX CamStartCaptureEx; 263 PCAM_STOP_CAPTURE_ROUTINE_EX CamStopCaptureEx; 264 PCAM_CONFIGURE_ROUTINE_EX CamConfigureEx; 265 PCAM_STATE_ROUTINE CamSaveState; 266 PCAM_STATE_ROUTINE CamRestoreState; 267 PCAM_ALLOCATE_BW_ROUTINE_EX CamAllocateBandwidthEx; 268 PCAM_FREE_BW_ROUTINE_EX CamFreeBandwidthEx; 269 } USBCAMD_DEVICE_DATA2, *PUSBCAMD_DEVICE_DATA2; 270 271 DEFINE_GUID(GUID_USBCAMD_INTERFACE, 272 0x2bcb75c0, 0xb27f, 0x11d1, 0xba, 0x41, 0x0, 0xa0, 0xc9, 0xd, 0x2b, 0x5); 273 274 typedef NTSTATUS 275 (NTAPI *PFNUSBCAMD_SetVideoFormat)( 276 IN PVOID DeviceContext, 277 IN PHW_STREAM_REQUEST_BLOCK pSrb); 278 279 typedef NTSTATUS 280 (NTAPI *PFNUSBCAMD_WaitOnDeviceEvent)( 281 IN PVOID DeviceContext, 282 IN ULONG PipeIndex, 283 IN PVOID Buffer, 284 IN ULONG BufferLength, 285 IN PCOMMAND_COMPLETE_FUNCTION EventComplete, 286 IN PVOID EventContext, 287 IN BOOLEAN LoopBack); 288 289 typedef NTSTATUS 290 (NTAPI *PFNUSBCAMD_CancelBulkReadWrite)( 291 IN PVOID DeviceContext, 292 IN ULONG PipeIndex); 293 294 typedef NTSTATUS 295 (NTAPI *PFNUSBCAMD_SetIsoPipeState)( 296 IN PVOID DeviceContext, 297 IN ULONG PipeStateFlags); 298 299 typedef NTSTATUS 300 (NTAPI *PFNUSBCAMD_BulkReadWrite)( 301 IN PVOID DeviceContext, 302 IN USHORT PipeIndex, 303 IN PVOID Buffer, 304 IN ULONG BufferLength, 305 IN PCOMMAND_COMPLETE_FUNCTION CommandComplete, 306 IN PVOID CommandContext); 307 308 #define USBCAMD_VERSION_200 0x200 309 310 typedef struct _USBCAMD_INTERFACE { 311 INTERFACE Interface; 312 PFNUSBCAMD_WaitOnDeviceEvent USBCAMD_WaitOnDeviceEvent; 313 PFNUSBCAMD_BulkReadWrite USBCAMD_BulkReadWrite; 314 PFNUSBCAMD_SetVideoFormat USBCAMD_SetVideoFormat; 315 PFNUSBCAMD_SetIsoPipeState USBCAMD_SetIsoPipeState; 316 PFNUSBCAMD_CancelBulkReadWrite USBCAMD_CancelBulkReadWrite; 317 } USBCAMD_INTERFACE, *PUSBCAMD_INTERFACE; 318 319 /* FIXME : Do we need USBCAMAPI here ? */ 320 321 USBCAMAPI 322 ULONG 323 NTAPI 324 USBCAMD_DriverEntry( 325 IN PVOID Context1, 326 IN PVOID Context2, 327 IN ULONG DeviceContextSize, 328 IN ULONG FrameContextSize, 329 IN PADAPTER_RECEIVE_PACKET_ROUTINE ReceivePacket); 330 331 USBCAMAPI 332 PVOID 333 NTAPI 334 USBCAMD_AdapterReceivePacket( 335 IN PHW_STREAM_REQUEST_BLOCK Srb, 336 IN PUSBCAMD_DEVICE_DATA DeviceData, 337 IN PDEVICE_OBJECT *DeviceObject, 338 IN BOOLEAN NeedsCompletion); 339 340 USBCAMAPI 341 NTSTATUS 342 NTAPI 343 USBCAMD_ControlVendorCommand( 344 IN PVOID DeviceContext, 345 IN UCHAR Request, 346 IN USHORT Value, 347 IN USHORT Index, 348 IN OUT PVOID Buffer, 349 IN OUT PULONG BufferLength, 350 IN BOOLEAN GetData, 351 IN PCOMMAND_COMPLETE_FUNCTION CommandComplete OPTIONAL, 352 IN PVOID CommandContext OPTIONAL); 353 354 USBCAMAPI 355 NTSTATUS 356 NTAPI 357 USBCAMD_SelectAlternateInterface( 358 IN PVOID DeviceContext, 359 IN OUT PUSBD_INTERFACE_INFORMATION RequestInterface); 360 361 USBCAMAPI 362 NTSTATUS 363 NTAPI 364 USBCAMD_GetRegistryKeyValue( 365 IN HANDLE Handle, 366 IN PWCHAR KeyNameString, 367 IN ULONG KeyNameStringLength, 368 IN PVOID Data, 369 IN ULONG DataLength); 370 371 USBCAMAPI 372 ULONG 373 NTAPI 374 USBCAMD_InitializeNewInterface( 375 IN PVOID DeviceContext, 376 IN PVOID DeviceData, 377 IN ULONG Version, 378 IN ULONG CamControlFlag); 379 380 #ifdef __cplusplus 381 } 382 #endif 383 384 #endif /* !defined(__USB_H) && !defined(__USBDI_H) */ 385