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 (at) 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 PVOID DeviceContext, 66 PVOID CommandContext, 67 NTSTATUS NtStatus); 68 69 typedef VOID 70 (NTAPI *PSTREAM_RECEIVE_PACKET)( 71 PVOID Srb, 72 PVOID DeviceContext, 73 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 PDEVICE_OBJECT BusDeviceObject, 83 PVOID DeviceContext, 84 PUSBD_INTERFACE_INFORMATION Interface, 85 PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor, 86 PLONG DataPipeIndex, 87 PLONG SyncPipeIndex); 88 89 typedef NTSTATUS 90 (NTAPI *PCAM_CONFIGURE_ROUTINE_EX)( 91 PDEVICE_OBJECT BusDeviceObject, 92 PVOID DeviceContext, 93 PUSBD_INTERFACE_INFORMATION Interface, 94 PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor, 95 ULONG PipeConfigListSize, 96 PUSBCAMD_Pipe_Config_Descriptor PipeConfig, 97 PUSB_DEVICE_DESCRIPTOR DeviceDescriptor); 98 99 typedef NTSTATUS 100 (NTAPI *PCAM_START_CAPTURE_ROUTINE)( 101 PDEVICE_OBJECT BusDeviceObject, 102 PVOID DeviceContext); 103 104 typedef NTSTATUS 105 (NTAPI *PCAM_START_CAPTURE_ROUTINE_EX)( 106 PDEVICE_OBJECT BusDeviceObject, 107 PVOID DeviceContext, 108 ULONG StreamNumber); 109 110 typedef NTSTATUS 111 (NTAPI *PCAM_ALLOCATE_BW_ROUTINE)( 112 PDEVICE_OBJECT BusDeviceObject, 113 PVOID DeviceContext, 114 PULONG RawFrameLength, 115 PVOID Format); 116 117 typedef NTSTATUS 118 (NTAPI *PCAM_ALLOCATE_BW_ROUTINE_EX)( 119 PDEVICE_OBJECT BusDeviceObject, 120 PVOID DeviceContext, 121 PULONG RawFrameLength, 122 PVOID Format, 123 ULONG StreamNumber); 124 125 typedef NTSTATUS 126 (NTAPI *PCAM_FREE_BW_ROUTINE)( 127 PDEVICE_OBJECT BusDeviceObject, 128 PVOID DeviceContext); 129 130 typedef NTSTATUS 131 (NTAPI *PCAM_FREE_BW_ROUTINE_EX)( 132 PDEVICE_OBJECT BusDeviceObject, 133 PVOID DeviceContext, 134 ULONG StreamNumber); 135 136 typedef VOID 137 (NTAPI *PADAPTER_RECEIVE_PACKET_ROUTINE)( 138 PHW_STREAM_REQUEST_BLOCK Srb); 139 140 typedef NTSTATUS 141 (NTAPI *PCAM_STOP_CAPTURE_ROUTINE)( 142 PDEVICE_OBJECT BusDeviceObject, 143 PVOID DeviceContext); 144 145 typedef NTSTATUS 146 (NTAPI *PCAM_STOP_CAPTURE_ROUTINE_EX)( 147 PDEVICE_OBJECT BusDeviceObject, 148 PVOID DeviceContext, 149 ULONG StreamNumber); 150 151 typedef ULONG 152 (NTAPI *PCAM_PROCESS_PACKET_ROUTINE)( 153 PDEVICE_OBJECT BusDeviceObject, 154 PVOID DeviceContext, 155 PVOID CurrentFrameContext, 156 PUSBD_ISO_PACKET_DESCRIPTOR SyncPacket, 157 PVOID SyncBuffer, 158 PUSBD_ISO_PACKET_DESCRIPTOR DataPacket, 159 PVOID DataBuffer, 160 PBOOLEAN FrameComplete, 161 PBOOLEAN NextFrameIsStill); 162 163 typedef ULONG 164 (NTAPI *PCAM_PROCESS_PACKET_ROUTINE_EX)( 165 PDEVICE_OBJECT BusDeviceObject, 166 PVOID DeviceContext, 167 PVOID CurrentFrameContext, 168 PUSBD_ISO_PACKET_DESCRIPTOR SyncPacket, 169 PVOID SyncBuffer, 170 PUSBD_ISO_PACKET_DESCRIPTOR DataPacket, 171 PVOID DataBuffer, 172 PBOOLEAN FrameComplete, 173 PULONG PacketFlag, 174 PULONG ValidDataOffset); 175 176 typedef VOID 177 (NTAPI *PCAM_NEW_FRAME_ROUTINE)( 178 PVOID DeviceContext, 179 PVOID FrameContext); 180 181 typedef VOID 182 (NTAPI *PCAM_NEW_FRAME_ROUTINE_EX)( 183 PVOID DeviceContext, 184 PVOID FrameContext, 185 ULONG StreamNumber, 186 PULONG FrameLength); 187 188 typedef NTSTATUS 189 (NTAPI *PCAM_PROCESS_RAW_FRAME_ROUTINE)( 190 PDEVICE_OBJECT BusDeviceObject, 191 PVOID DeviceContext, 192 PVOID FrameContext, 193 PVOID FrameBuffer, 194 ULONG FrameLength, 195 PVOID RawFrameBuffer, 196 ULONG RawFrameLength, 197 ULONG NumberOfPackets, 198 PULONG BytesReturned); 199 200 typedef NTSTATUS 201 (NTAPI *PCAM_PROCESS_RAW_FRAME_ROUTINE_EX)( 202 PDEVICE_OBJECT BusDeviceObject, 203 PVOID DeviceContext, 204 PVOID FrameContext, 205 PVOID FrameBuffer, 206 ULONG FrameLength, 207 PVOID RawFrameBuffer, 208 ULONG RawFrameLength, 209 ULONG NumberOfPackets, 210 PULONG BytesReturned, 211 ULONG ActualRawFrameLength, 212 ULONG StreamNumber); 213 214 typedef NTSTATUS 215 (NTAPI *PCAM_STATE_ROUTINE)( 216 PDEVICE_OBJECT BusDeviceObject, 217 PVOID DeviceContext); 218 219 #if defined(DEBUG_LOG) 220 221 USBCAMAPI 222 VOID 223 NTAPI 224 USBCAMD_Debug_LogEntry( 225 CHAR *Name, 226 ULONG Info1, 227 ULONG Info2, 228 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 PVOID DeviceContext, 277 PHW_STREAM_REQUEST_BLOCK pSrb); 278 279 typedef NTSTATUS 280 (NTAPI *PFNUSBCAMD_WaitOnDeviceEvent)( 281 PVOID DeviceContext, 282 ULONG PipeIndex, 283 PVOID Buffer, 284 ULONG BufferLength, 285 PCOMMAND_COMPLETE_FUNCTION EventComplete, 286 PVOID EventContext, 287 BOOLEAN LoopBack); 288 289 typedef NTSTATUS 290 (NTAPI *PFNUSBCAMD_CancelBulkReadWrite)( 291 PVOID DeviceContext, 292 ULONG PipeIndex); 293 294 typedef NTSTATUS 295 (NTAPI *PFNUSBCAMD_SetIsoPipeState)( 296 PVOID DeviceContext, 297 ULONG PipeStateFlags); 298 299 typedef NTSTATUS 300 (NTAPI *PFNUSBCAMD_BulkReadWrite)( 301 PVOID DeviceContext, 302 USHORT PipeIndex, 303 PVOID Buffer, 304 ULONG BufferLength, 305 PCOMMAND_COMPLETE_FUNCTION CommandComplete, 306 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 PVOID Context1, 326 PVOID Context2, 327 ULONG DeviceContextSize, 328 ULONG FrameContextSize, 329 PADAPTER_RECEIVE_PACKET_ROUTINE ReceivePacket); 330 331 USBCAMAPI 332 PVOID 333 NTAPI 334 USBCAMD_AdapterReceivePacket( 335 PHW_STREAM_REQUEST_BLOCK Srb, 336 PUSBCAMD_DEVICE_DATA DeviceData, 337 PDEVICE_OBJECT *DeviceObject, 338 BOOLEAN NeedsCompletion); 339 340 USBCAMAPI 341 NTSTATUS 342 NTAPI 343 USBCAMD_ControlVendorCommand( 344 PVOID DeviceContext, 345 UCHAR Request, 346 USHORT Value, 347 USHORT Index, 348 PVOID Buffer, 349 PULONG BufferLength, 350 BOOLEAN GetData, 351 PCOMMAND_COMPLETE_FUNCTION CommandComplete, 352 PVOID CommandContext); 353 354 USBCAMAPI 355 NTSTATUS 356 NTAPI 357 USBCAMD_SelectAlternateInterface( 358 PVOID DeviceContext, 359 PUSBD_INTERFACE_INFORMATION RequestInterface); 360 361 USBCAMAPI 362 NTSTATUS 363 NTAPI 364 USBCAMD_GetRegistryKeyValue( 365 HANDLE Handle, 366 PWCHAR KeyNameString, 367 ULONG KeyNameStringLength, 368 PVOID Data, 369 ULONG DataLength); 370 371 USBCAMAPI 372 ULONG 373 NTAPI 374 USBCAMD_InitializeNewInterface( 375 PVOID DeviceContext, 376 PVOID DeviceData, 377 ULONG Version, 378 ULONG CamControlFlag); 379 380 #ifdef __cplusplus 381 } 382 #endif 383 384 #endif /* !defined(__USB_H) && !defined(__USBDI_H) */ 385