Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

594 lines
16 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. USBCAMDI.H
  5. Abstract:
  6. interface definition for .
  7. Environment:
  8. Kernel & user mode
  9. Revision History:
  10. --*/
  11. #ifndef __USBCAMDI_H__
  12. #define __USBCAMDI_H__
  13. // the purpose of this structure is to establish a connection between pipes discovered and
  14. // streams to be declared (video,still). the following structure will be be passed along with
  15. // USBD_PIPE_INFO structure in CamConfigEx to the cam driver. The Cam driver has to indicate
  16. // pipe stream asscociation by oring all the relevant streams associated with this particular
  17. // pipe. If there is more than one stream association, USBCAMD creates a virtual still pin,
  18. // and assumes the first stream is video followed by still stream.
  19. // The cam driver has to set the first field to USBCAMD_DONT_CARE_PIPE if a particular pipe should not be used by
  20. // usbcamd. For example, if you have an iso audio pipe, iso video pipe in a camera device that
  21. // supports stills and video .you should set the flag field in the first structure to
  22. // USBCAMD_DONT_CARE_PIPE, The second structure should be set as foolows:
  23. // {USBCAMD_VIDEO_STILL_STREAM,USBCAMD_MULTIPLEX_PIPE)}.
  24. // the assumption here is that cam has one config descr, and all alt.interfcaes have the same
  25. // number and types of pipes.
  26. // also, notice that the flags are mutually exclusive.
  27. //
  28. typedef struct _pipe_config_descriptor {
  29. CHAR StreamAssociation ; // video stream, still stream, or both
  30. UCHAR PipeConfigFlags; // USBCAMD_PIPECONFIG_*
  31. } USBCAMD_Pipe_Config_Descriptor, *PUSBCAMD_Pipe_Config_Descriptor;
  32. #define USBCAMD_DATA_PIPE 0x0001 // video or still data pipe
  33. #define USBCAMD_MULTIPLEX_PIPE 0x0002 // pipe used for both still & video
  34. #define USBCAMD_SYNC_PIPE 0x0004 // out-of-band signalling pipe.
  35. #define USBCAMD_DONT_CARE_PIPE 0x0008 // pipe is not to be used for streaming vidoe or still.
  36. #define USBCAMD_VIDEO_STREAM 0x1
  37. #define USBCAMD_STILL_STREAM 0x2
  38. #define USBCAMD_VIDEO_STILL_STREAM (USBCAMD_VIDEO_STREAM | USBCAMD_STILL_STREAM)
  39. // PacketFlag definitions for CamProcessUSBPacketEx
  40. // *** Notice *** : these flags are mutually exclusive.
  41. // current frame is unsalvageable, recycle the read IRP
  42. #define USBCAMD_PROCESSPACKETEX_DropFrame 0x0002
  43. // following frame is still.
  44. #define USBCAMD_PROCESSPACKETEX_NextFrameIsStill 0x0004
  45. // copy this frame to still pin. .
  46. #define USBCAMD_PROCESSPACKETEX_CurrentFrameIsStill 0x0008
  47. // these flags are used in PipeStateFlag in usbcamd_setpipestate function.
  48. #define USBCAMD_STOP_STREAM 0x00000001
  49. #define USBCAMD_START_STREAM 0x00000000
  50. //
  51. // the following flags are passed to usbcamd in USBCAMD_InitializeNewInterface.
  52. // If Cam driver doesn't need to operate on the still image raw frame, then it should
  53. // set the second flag in order to elminate on ebuffer copy. Likewise for the video frame.
  54. // the associatedformat flag is set if the cam driver use the same format fro video and
  55. // virtual still pin. Once, this flag is set, USBCAMD will not allow virtual still pin to be
  56. // opened at different format than the video pin. USE this flag only when the virtual still
  57. // pin produces frames that have exact format as video frames.
  58. // EnableDeviceEvents will expose a deviceevents to stream class & DSHOW which will enable an STI
  59. // Monitor to lunch a still image app if still button is pressed on the camera.
  60. typedef enum {
  61. USBCAMD_CamControlFlag_NoVideoRawProcessing = 0x0001,
  62. USBCAMD_CamControlFlag_NoStillRawProcessing = 0x0002,
  63. USBCAMD_CamControlFlag_AssociatedFormat = 0x0004,
  64. USBCAMD_CamControlFlag_EnableDeviceEvents = 0x0008,
  65. } USBCAMD_CamControlFlags;
  66. // ------------------------------------------------------------------------
  67. // The master list of all streams supported by this driver
  68. // ------------------------------------------------------------------------
  69. typedef
  70. NTSTATUS
  71. (*PCOMMAND_COMPLETE_FUNCTION)(
  72. PVOID DeviceContext,
  73. PVOID CommandContext,
  74. NTSTATUS NtStatus
  75. );
  76. typedef
  77. VOID
  78. (*PSTREAM_RECEIVE_PACKET) (
  79. IN PVOID Srb,
  80. IN PVOID DeviceContext,
  81. IN PBOOLEAN Completed
  82. );
  83. typedef
  84. NTSTATUS
  85. (*PCAM_INITIALIZE_ROUTINE)(
  86. PDEVICE_OBJECT BusDeviceObject,
  87. PVOID DeviceContext
  88. );
  89. typedef
  90. NTSTATUS
  91. (*PCAM_CONFIGURE_ROUTINE)(
  92. PDEVICE_OBJECT BusDeviceObject,
  93. PVOID DeviceContext,
  94. PUSBD_INTERFACE_INFORMATION Interface,
  95. PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
  96. PLONG DataPipeIndex,
  97. PLONG SyncPipeIndex
  98. );
  99. typedef
  100. NTSTATUS
  101. (*PCAM_CONFIGURE_ROUTINE_EX)(
  102. PDEVICE_OBJECT BusDeviceObject,
  103. PVOID DeviceContext,
  104. PUSBD_INTERFACE_INFORMATION Interface,
  105. PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
  106. ULONG PipeConfigListSize,
  107. PUSBCAMD_Pipe_Config_Descriptor PipeConfig,
  108. PUSB_DEVICE_DESCRIPTOR DeviceDescriptor
  109. );
  110. typedef
  111. NTSTATUS
  112. (*PCAM_START_CAPTURE_ROUTINE)(
  113. PDEVICE_OBJECT BusDeviceObject,
  114. PVOID DeviceContext
  115. );
  116. typedef
  117. NTSTATUS
  118. (*PCAM_START_CAPTURE_ROUTINE_EX)(
  119. PDEVICE_OBJECT BusDeviceObject,
  120. PVOID DeviceContext,
  121. ULONG StreamNumber
  122. );
  123. typedef
  124. NTSTATUS
  125. (*PCAM_ALLOCATE_BW_ROUTINE)(
  126. PDEVICE_OBJECT BusDeviceObject,
  127. PVOID DeviceContext,
  128. PULONG RawFrameLength,
  129. PVOID Format
  130. );
  131. typedef
  132. NTSTATUS
  133. (*PCAM_ALLOCATE_BW_ROUTINE_EX)(
  134. PDEVICE_OBJECT BusDeviceObject,
  135. PVOID DeviceContext,
  136. PULONG RawFrameLength,
  137. PVOID Format,
  138. ULONG StreamNumber
  139. );
  140. typedef
  141. NTSTATUS
  142. (*PCAM_FREE_BW_ROUTINE)(
  143. PDEVICE_OBJECT BusDeviceObject,
  144. PVOID DeviceContext
  145. );
  146. typedef
  147. NTSTATUS
  148. (*PCAM_FREE_BW_ROUTINE_EX)(
  149. PDEVICE_OBJECT BusDeviceObject,
  150. PVOID DeviceContext,
  151. ULONG STreamNumber
  152. );
  153. typedef
  154. VOID
  155. (*PADAPTER_RECEIVE_PACKET_ROUTINE)(
  156. IN PHW_STREAM_REQUEST_BLOCK Srb
  157. );
  158. typedef
  159. NTSTATUS
  160. (*PCAM_STOP_CAPTURE_ROUTINE)(
  161. PDEVICE_OBJECT BusDeviceObject,
  162. PVOID DeviceContext
  163. );
  164. typedef
  165. NTSTATUS
  166. (*PCAM_STOP_CAPTURE_ROUTINE_EX)(
  167. PDEVICE_OBJECT BusDeviceObject,
  168. PVOID DeviceContext,
  169. ULONG StreamNumber
  170. );
  171. typedef
  172. ULONG
  173. (*PCAM_PROCESS_PACKET_ROUTINE) (
  174. PDEVICE_OBJECT BusDeviceObject,
  175. PVOID DeviceContext,
  176. PVOID CurrentFrameContext,
  177. PUSBD_ISO_PACKET_DESCRIPTOR SyncPacket,
  178. PVOID SyncBuffer,
  179. PUSBD_ISO_PACKET_DESCRIPTOR DataPacket,
  180. PVOID DataBuffer,
  181. PBOOLEAN FrameComplete,
  182. PBOOLEAN NextFrameIsStill
  183. );
  184. typedef
  185. ULONG
  186. (*PCAM_PROCESS_PACKET_ROUTINE_EX) (
  187. PDEVICE_OBJECT BusDeviceObject,
  188. PVOID DeviceContext,
  189. PVOID CurrentFrameContext,
  190. PUSBD_ISO_PACKET_DESCRIPTOR SyncPacket,
  191. PVOID SyncBuffer,
  192. PUSBD_ISO_PACKET_DESCRIPTOR DataPacket,
  193. PVOID DataBuffer,
  194. PBOOLEAN FrameComplete,
  195. PULONG PacketFlag,
  196. PULONG ValidDataOffset
  197. );
  198. typedef
  199. VOID
  200. (*PCAM_NEW_FRAME_ROUTINE) (
  201. PVOID DeviceContext,
  202. PVOID FrameContext
  203. );
  204. typedef
  205. VOID
  206. (*PCAM_NEW_FRAME_ROUTINE_EX) (
  207. PVOID DeviceContext,
  208. PVOID FrameContext,
  209. ULONG StreamNumber,
  210. PULONG FrameLength
  211. );
  212. typedef
  213. NTSTATUS
  214. (*PCAM_PROCESS_RAW_FRAME_ROUTINE) (
  215. PDEVICE_OBJECT BusDeviceObject,
  216. PVOID DeviceContext,
  217. PVOID FrameContext,
  218. PVOID FrameBuffer,
  219. ULONG FrameLength,
  220. PVOID RawFrameBuffer,
  221. ULONG RawFrameLength,
  222. ULONG NumberOfPackets,
  223. PULONG BytesReturned
  224. );
  225. typedef
  226. NTSTATUS
  227. (*PCAM_PROCESS_RAW_FRAME_ROUTINE_EX) (
  228. PDEVICE_OBJECT BusDeviceObject,
  229. PVOID DeviceContext,
  230. PVOID FrameContext,
  231. PVOID FrameBuffer,
  232. ULONG FrameLength,
  233. PVOID RawFrameBuffer,
  234. ULONG RawFrameLength,
  235. ULONG NumberOfPackets,
  236. PULONG BytesReturned,
  237. ULONG ActualRawFrameLength,
  238. ULONG StreamNumber
  239. );
  240. typedef
  241. NTSTATUS
  242. (*PCAM_STATE_ROUTINE) (
  243. PDEVICE_OBJECT BusDeviceObject,
  244. PVOID DeviceContext
  245. );
  246. #ifdef DEBUG_LOG
  247. VOID
  248. USBCAMD_Debug_LogEntry(
  249. IN CHAR *Name,
  250. IN ULONG Info1,
  251. IN ULONG Info2,
  252. IN ULONG Info3
  253. );
  254. #define ILOGENTRY(sig, info1, info2, info3) \
  255. USBCAMD_Debug_LogEntry(sig, (ULONG)info1, (ULONG)info2, (ULONG)info3)
  256. #else
  257. #define ILOGENTRY(sig, info1, info2, info3)
  258. #endif /* DEBUG_LOG */
  259. typedef struct _USBCAMD_DEVICE_DATA {
  260. ULONG Sig;
  261. PCAM_INITIALIZE_ROUTINE CamInitialize;
  262. PCAM_INITIALIZE_ROUTINE CamUnInitialize;
  263. PCAM_PROCESS_PACKET_ROUTINE CamProcessUSBPacket;
  264. PCAM_NEW_FRAME_ROUTINE CamNewVideoFrame;
  265. PCAM_PROCESS_RAW_FRAME_ROUTINE CamProcessRawVideoFrame;
  266. PCAM_START_CAPTURE_ROUTINE CamStartCapture;
  267. PCAM_STOP_CAPTURE_ROUTINE CamStopCapture;
  268. PCAM_CONFIGURE_ROUTINE CamConfigure;
  269. PCAM_STATE_ROUTINE CamSaveState;
  270. PCAM_STATE_ROUTINE CamRestoreState;
  271. PCAM_ALLOCATE_BW_ROUTINE CamAllocateBandwidth;
  272. PCAM_FREE_BW_ROUTINE CamFreeBandwidth;
  273. } USBCAMD_DEVICE_DATA, *PUSBCAMD_DEVICE_DATA;
  274. typedef struct _USBCAMD_DEVICE_DATA2 {
  275. ULONG Sig;
  276. PCAM_INITIALIZE_ROUTINE CamInitialize;
  277. PCAM_INITIALIZE_ROUTINE CamUnInitialize;
  278. PCAM_PROCESS_PACKET_ROUTINE_EX CamProcessUSBPacketEx;
  279. PCAM_NEW_FRAME_ROUTINE_EX CamNewVideoFrameEx;
  280. PCAM_PROCESS_RAW_FRAME_ROUTINE_EX CamProcessRawVideoFrameEx;
  281. PCAM_START_CAPTURE_ROUTINE_EX CamStartCaptureEx;
  282. PCAM_STOP_CAPTURE_ROUTINE_EX CamStopCaptureEx;
  283. PCAM_CONFIGURE_ROUTINE_EX CamConfigureEx;
  284. PCAM_STATE_ROUTINE CamSaveState;
  285. PCAM_STATE_ROUTINE CamRestoreState;
  286. PCAM_ALLOCATE_BW_ROUTINE_EX CamAllocateBandwidthEx;
  287. PCAM_FREE_BW_ROUTINE_EX CamFreeBandwidthEx;
  288. } USBCAMD_DEVICE_DATA2, *PUSBCAMD_DEVICE_DATA2;
  289. //
  290. // USBCAMD services
  291. //
  292. /*
  293. This function is called from the "cam" driver DriverEntry routine to register
  294. the driver with USBCAMD. This effectively binds the two drivers together.
  295. Context1, Context2 - these are passed to the "cam" drivers DriverEntry and
  296. should simply be passed on
  297. DeviceContextSize - amount of memory needed for the "cam" driver's device
  298. specific context.
  299. FrameContextSize - size of an optional per video frame structure passed to
  300. NewVideoFrame and ProcessRawVideoFrame.
  301. */
  302. ULONG
  303. USBCAMD_DriverEntry(
  304. PVOID Context1,
  305. PVOID Context2,
  306. ULONG DeviceContextSize,
  307. ULONG FrameContextSize,
  308. PADAPTER_RECEIVE_PACKET_ROUTINE ReceivePacket
  309. );
  310. /*
  311. This function is called by the "cam" driver from the AdapterReceivePacket
  312. routine to allow USBCAMD to process an SRB.
  313. Srb - The srb passed to the "cam" driver's AdapterReceievPacket Routine.
  314. DeviceData - filled in USBCAMD_DEVICE_DATAx structure with entry points to the
  315. "cam" driver for iso stream processing.
  316. DeviceObject - this pointer will be filled in the device PDO, this is used by
  317. the "cam" driver for calls to the USB stack through IoCallDriver.
  318. NeedsCompletion - if this flag is true USBCAMD will process the SRB and
  319. complete it, otherwise USBCAMD will ignore the SRB and just return the
  320. DeveiceConext.
  321. Returns:
  322. Returns a pointer to the device specific context for this instance of the
  323. camera "DeviceContext".
  324. */
  325. PVOID
  326. USBCAMD_AdapterReceivePacket(
  327. IN PHW_STREAM_REQUEST_BLOCK Srb,
  328. IN PUSBCAMD_DEVICE_DATA DeviceData,
  329. IN PDEVICE_OBJECT *DeviceObject,
  330. IN BOOLEAN NeedsCompletion
  331. );
  332. /*
  333. This function is available to the "cam" driver to send vendor commands on the
  334. control pipe. This function may be called at IRQL >= PASSIVE_LEVEL. If the
  335. function is called at IRQL > PASSIVE_LEVEL the command will be deferred until
  336. passive level, once completed the callers CommandComplete function is called
  337. with a pointer to the CommandContext.
  338. DeviceContext - device specific context.
  339. Request - value for the bRequest field for the vendor command.
  340. Value - value for the wValue field of the vendor command.
  341. Index - value for the wIndex field of the vendor conmmand.
  342. Buffer - data buffer if the command has data, may be NULL.
  343. BufferLength - pointer length of Buffer in bytes, may be NULL if buffer is NULL
  344. GetData - flag indicating data direction, "GetData" indicates data is send
  345. device-to-host.
  346. CommandComplete - function called when command is completed.
  347. CommandContext - context passed to CommandComplete function
  348. Returns:
  349. Returns NTSTATUS code from command of STTAUS_PENDING if command is deferred.
  350. */
  351. NTSTATUS
  352. USBCAMD_ControlVendorCommand(
  353. IN PVOID DeviceContext,
  354. IN UCHAR Request,
  355. IN USHORT Value,
  356. IN USHORT Index,
  357. IN PVOID Buffer,
  358. IN OUT PULONG BufferLength,
  359. IN BOOLEAN GetData,
  360. IN PCOMMAND_COMPLETE_FUNCTION CommandComplete,
  361. IN PVOID CommandContext
  362. );
  363. /*
  364. This function is called by the "cam" driver to select an alternate interface,
  365. The RequestInterface structure is filled in with the information from the
  366. SELECT_INTERFACE request on successful completion. This function is
  367. typically called from the "cam" driver in response to a request to allocate
  368. or free bandwidth.
  369. DeviceContext - device specific context.
  370. RequestInterface - USBD_INTERFACE_INFORMATION structure for the appropriate
  371. interface to select. The same rules apply to this structure as for the
  372. SELECT_INTERFACE USBD request (see USBDI doc).
  373. Returns:
  374. Returns the status from the SELECT_INTERFACE request to USBD.
  375. */
  376. NTSTATUS
  377. USBCAMD_SelectAlternateInterface(
  378. IN PVOID DeviceContext,
  379. IN OUT PUSBD_INTERFACE_INFORMATION RequestInterface
  380. );
  381. /*
  382. Handy function to get a device instance specific registry key value
  383. */
  384. NTSTATUS
  385. USBCAMD_GetRegistryKeyValue (
  386. IN HANDLE Handle,
  387. IN PWCHAR KeyNameString,
  388. IN ULONG KeyNameStringLength,
  389. IN PVOID Data,
  390. IN ULONG DataLength
  391. );
  392. //
  393. // These services are new.
  394. //
  395. /*
  396. This function is called from the "cam" driver upon recieving SRB_INITIALIZE_DEVICE
  397. to provid usbcamd with all the necessary info to configure the cam driver correctly with
  398. stream class and USB Bus drivers.
  399. DeviceContext - device specific context.
  400. DeviceData - filled in USBCAMD_DEVICE_DATAx structure with entry points to the
  401. "cam" driver .
  402. Version - USBCAMD version
  403. CamControlFlag - flags to control interaction with cam driver.
  404. */
  405. ULONG
  406. USBCAMD_InitializeNewInterface(
  407. IN PVOID DeviceContext,
  408. IN PVOID DeviceData,
  409. IN ULONG Version,
  410. IN ULONG CamControlFlag
  411. );
  412. // To access the new USBCAMD functionality in a CAM driver , the driver sends
  413. // the following IRP to itself once it received SRB_INITIALIZATION_COMPLETE.
  414. // MajorFunction = IRP_MJ_PNP;
  415. // MinorFunction = IRP_MN_QUERY_INTERFACE;
  416. // {2BCB75C0-B27F-11d1-BA41-00A0C90D2B05}
  417. DEFINE_GUID( GUID_USBCAMD_INTERFACE ,
  418. 0x2bcb75c0, 0xb27f, 0x11d1, 0xba, 0x41, 0x0, 0xa0, 0xc9, 0xd, 0x2b, 0x5);
  419. //The QUERY_INTERFACE Irp will return an interface (set of function pointers)
  420. // of the type xxxxINTERFACE, defined below. This is essentially a table of
  421. // function pointers.
  422. typedef
  423. NTSTATUS
  424. (*PFNUSBCAMD_SetVideoFormat)(
  425. IN PVOID DeviceContext,
  426. IN IN PHW_STREAM_REQUEST_BLOCK pSrb
  427. );
  428. typedef
  429. NTSTATUS
  430. (*PFNUSBCAMD_WaitOnDeviceEvent)(
  431. IN PVOID DeviceContext,
  432. IN ULONG PipeIndex,
  433. IN PVOID Buffer,
  434. IN ULONG BufferLength,
  435. IN PCOMMAND_COMPLETE_FUNCTION EventComplete,
  436. IN PVOID EventContext,
  437. IN BOOLEAN LoopBack
  438. );
  439. // this function is callable at PASSIVE_LEVEL Only.
  440. typedef
  441. NTSTATUS
  442. (*PFNUSBCAMD_CancelBulkReadWrite)(
  443. IN PVOID DeviceContext,
  444. IN ULONG PipeIndex
  445. );
  446. typedef
  447. NTSTATUS
  448. (*PFNUSBCAMD_SetIsoPipeState)(
  449. IN PVOID DeviceContext,
  450. IN ULONG PipeStateFlags
  451. );
  452. typedef
  453. NTSTATUS
  454. (*PFNUSBCAMD_BulkReadWrite)(
  455. IN PVOID DeviceContext,
  456. IN USHORT PipeIndex,
  457. IN PVOID Buffer,
  458. IN ULONG BufferLength,
  459. IN PCOMMAND_COMPLETE_FUNCTION CommandComplete,
  460. IN PVOID CommandContext
  461. );
  462. #define USBCAMD_VERSION_200 0x200
  463. typedef struct {
  464. INTERFACE Interface;
  465. PFNUSBCAMD_WaitOnDeviceEvent USBCAMD_WaitOnDeviceEvent;
  466. PFNUSBCAMD_BulkReadWrite USBCAMD_BulkReadWrite;
  467. PFNUSBCAMD_SetVideoFormat USBCAMD_SetVideoFormat;
  468. PFNUSBCAMD_SetIsoPipeState USBCAMD_SetIsoPipeState;
  469. PFNUSBCAMD_CancelBulkReadWrite USBCAMD_CancelBulkReadWrite;
  470. } USBCAMD_INTERFACE, *PUSBCAMD_INTERFACE;
  471. #endif /* __USBCAMDI_H__ */