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.

697 lines
18 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1999 - 2000
  3. Module Name:
  4. msdvdef.h
  5. Abstract:
  6. Header file for all of msdv (digital camcorder)
  7. Last changed by:
  8. $Author:: $
  9. Environment:
  10. Kernel mode only
  11. Revision History:
  12. $Revision:: $
  13. $Date:: $
  14. --*/
  15. #ifndef _DVCRDEF_INC
  16. #define _DVCRDEF_INC
  17. //
  18. // Allocate memory with 'Msdv' tag
  19. //
  20. #ifdef ExAllocatePool
  21. #undef ExAllocatePool
  22. #endif
  23. #undef ExAllocatePool
  24. #define ExAllocatePool(type, size) ExAllocatePoolWithTag (type, size, 'vdsM')
  25. //
  26. // Need to reference this in PSTRMEX
  27. //
  28. typedef struct _DVCR_EXTENSION;
  29. //
  30. // The index MUST match
  31. //
  32. typedef enum {
  33. FMT_IDX_SD_DVCR_NTSC = 0,
  34. FMT_IDX_SD_DVCR_PAL,
  35. #ifdef MSDV_SUPPORT_HD_DVCR
  36. FMT_IDX_HD_DVCR_NTSC,
  37. FMT_IDX_HD_DVCR_PAL,
  38. #endif
  39. #ifdef MSDV_SUPPORT_SDL_DVCR
  40. FMT_IDX_SDL_DVCR_NTSC,
  41. FMT_IDX_SDL_DVCR_PAL,
  42. #endif
  43. } FMT_INDEX, *PFMT_INDEX;
  44. #if DBG
  45. //
  46. // Collect statistic for real time data transmission
  47. //
  48. #define MAX_STAT_DURATION 60 // Seconds
  49. #define MAX_XMT_FRAMES_TRACED 30 * MAX_STAT_DURATION // Max number of entries
  50. typedef struct _XMT_FRAME_STAT {
  51. KSSTATE StreamState;
  52. LONG cntSRBReceived; // Accumulative SRVB received.
  53. LONG cntSRBPending; // Number of SRB not yet completed.
  54. LONG cntSRBQueued; // SRB Queued
  55. LONG cntDataAttached; // Data attached
  56. LONGLONG FrameSlot; // Real time
  57. ULONGLONG tmStreamTime; // Stream time of the "FrameSlot"
  58. DWORD DropCount; // Accumulative drop count
  59. DWORD FrameNumber; // Actual frame number transmitted; (==FrameSlot: ontime); (<FrameSlot: late)
  60. DWORD OptionsFlags;
  61. ULONGLONG tmPresentation; // Actual frame's presentation time
  62. CYCLE_TIME tsTransmitted; // Frame actually transmitted (1394 CycleTime)
  63. } XMT_FRAME_STAT, *PXMT_FRAME_STAT;
  64. #endif
  65. //
  66. // this structure is our per stream extension structure. This stores
  67. // information that is relevant on a per stream basis. Whenever a new stream
  68. // is opened, the stream class driver will allocate whatever extension size
  69. // is specified in the HwInitData.PerStreamExtensionSize.
  70. //
  71. typedef struct _STREAMEX {
  72. //
  73. // Point to pSrb->HwDeviceExtension
  74. //
  75. struct _DVCR_EXTENSION * pDevExt;
  76. //
  77. // Cache pSrb->StreamObject:
  78. // ->HwStreamExtension (pStrmExt)
  79. // ->StreamNumber
  80. // ->HwDeviceExtension (pDevExt)
  81. //
  82. PHW_STREAM_OBJECT pStrmObject;
  83. //
  84. // ->NumberOfPossibleInstances;
  85. // ->DataFlow;
  86. //
  87. PHW_STREAM_INFORMATION pStrmInfo;
  88. //
  89. // Holds current stream state
  90. //
  91. KSSTATE StreamState;
  92. //
  93. // Holds previous stream state; use to determine the state transition.
  94. //
  95. KSSTATE StreamStatePrevious;
  96. //
  97. // Holds whether or not the dvcr is listening or receiving
  98. //
  99. // TRUE: successful REQUEST_ISOCH_LISTEN and REQUEST_ISOCH_TALK
  100. // FALSE: successful INIT and REQUEST_ISOCH_STOP
  101. //
  102. BOOLEAN bIsochIsActive; // Close associated with StreamState
  103. //
  104. // Set to TRUE when receiving KSSTREAM_HEADER_OPTIONSF_ENDOFSTREAM for SRB_WRITE_DATA
  105. // For SRB_WRITE_DATA only since then this driver servers as a renderer.
  106. //
  107. BOOL bEOStream;
  108. //
  109. // Count number of SRB_READ/WRITE_DATA received since last transiting to PAUSE state from STOP
  110. //
  111. LONGLONG cntSRBReceived;
  112. //
  113. // Statistic of the frame information since last start stream
  114. // PictureNumber = FramesProcessed + FramesDropped + cndSRBCancelled.
  115. //
  116. LONGLONG FramesProcessed; // Frame sent (including repeated)
  117. LONGLONG FramesDropped; // SRB not sent
  118. LONGLONG PictureNumber; // Number of SRB_XXX_DATA made it to or from 1394 bus
  119. //
  120. // Count number of SRB_READ/WRITE_DATA that was incompleted and cancelled
  121. //
  122. LONGLONG cntSRBCancelled;
  123. //
  124. // Count and list for the detach list
  125. //
  126. LONG cntDataDetached;
  127. LIST_ENTRY DataDetachedListHead;
  128. #if DBG
  129. //
  130. // Count number of SRB awaiting completion
  131. //
  132. LONG cntSRBPending;
  133. #endif
  134. //
  135. // Count and list for the SRB list
  136. //
  137. LONG cntSRBQueued; // Used only with SRB_WRITE_DATA
  138. LIST_ENTRY SRBQueuedListHead; // Used only with SRB_WRITE_DATA
  139. //
  140. // Count and list for the attach list
  141. //
  142. LONG cntDataAttached;
  143. LIST_ENTRY DataAttachedListHead;
  144. //
  145. // Lock to serialize attach and detach of list
  146. //
  147. KSPIN_LOCK * DataListLock;
  148. #if DBG
  149. KSPIN_LOCK * DataListLockSave;
  150. #endif
  151. //
  152. // The stream time (master clock or not) is "almost" or near 0
  153. // when setting to RUN state and start increment.
  154. //
  155. ULONGLONG CurrentStreamTime;
  156. //
  157. // Keep track of the last system time when the stream time was updated.
  158. // This is used to calibrate the current stream time when it is queries.
  159. //
  160. ULONGLONG LastSystemTime;
  161. //
  162. // For isoch talk only:
  163. // Signal arrival of a SRB so it can be processed in the case we are repeating frame.
  164. //
  165. KEVENT hSrbArriveEvent;
  166. #ifdef SUPPORT_PREROLL_AT_RUN_STATE
  167. //
  168. // Support wait in RUN state to "simulate" preroll
  169. //
  170. KEVENT hPreRollEvent;
  171. #endif
  172. //
  173. // Holds the master clock
  174. //
  175. HANDLE hMyClock; // If set, we can be a clock provider.
  176. HANDLE hMasterClock; // If set, we are the master clock.
  177. HANDLE hClock; // If set, other device on the same graph is the master clock.
  178. //
  179. // Since GetSystemTime() can be called at DISPATCH level so make sure the variable that it used is in nonpaged pool
  180. //
  181. HW_TIME_CONTEXT TimeContext;
  182. //
  183. // 2nd CIP Quadlet: 01:Fmt, 50/60:STYPE:RSv, SYT
  184. //
  185. BYTE cipQuad2[4];
  186. #ifdef MSDV_SUPPORT_EXTRACT_SUBCODE_DATA
  187. //
  188. // Timecode, RecDate and RecTime are all in pack format (4 bytes)
  189. //
  190. BOOL bATNUpdated;
  191. DWORD AbsTrackNumber; // LSB:BlankField
  192. BOOL bTimecodeUpdated;
  193. BYTE Timecode[4]; // hh:mm:ss,ff
  194. #endif
  195. //
  196. // This mutex is used to sychronize attaching a frame and cancellation of a frame
  197. //
  198. KMUTEX * hStreamMutex;
  199. //
  200. // Counter used to indicate starting of an work item to cancel; this is a token and it is either 0 or 1.
  201. //
  202. LONG lStartIsochToken;
  203. //
  204. // Data ready dispatch thread's object: used to wait for thread to terminate.
  205. //
  206. PVOID pAttachFrameThreadObject;
  207. //
  208. // Set when the system is to be terminated.
  209. //
  210. BOOL bTerminateThread;
  211. //
  212. // Used to signal the termination of a system thread.
  213. //
  214. KEVENT hThreadEndEvent;
  215. //
  216. // Increment this if there is a critical operation so the
  217. // attaching frame thread will stop on the hRunThreadEvent.
  218. //
  219. LONG lNeedService; // > 0 to indicate needing service (stop thread)
  220. //
  221. // Signal to run the attach frame thread
  222. //
  223. KEVENT hRunThreadEvent; // Signal when thread is running
  224. //
  225. // Sign to hal the attach frame thread for critical operation such as
  226. // power off and surprise removal.
  227. //
  228. KEVENT hStopThreadEvent; // Signal when thread has stopped.
  229. #ifdef SUPPORT_NEW_AVC
  230. //
  231. // Used to indicate a device to device connection
  232. //
  233. BOOL bDV2DVConnect;
  234. #endif
  235. //
  236. // The input and output plug of this stream (point-to-point connection).
  237. //
  238. HANDLE hOutputPcr; // DV or PC's oPCR[0]
  239. HANDLE hInputPcr; // DV or PC's iPCR[0]
  240. //
  241. // The connection handle from 61883.sys.
  242. //
  243. HANDLE hConnect; // Connect handle
  244. #ifdef NT51_61883 // This is needed starting with 61883.sys in Whistler
  245. //
  246. // Cyclic cycle count of last DV frame
  247. //
  248. ULONG CycleCount16bits;
  249. #endif // NT51_61883
  250. #if DBG
  251. LONG lPrevCycleCount;
  252. LONG lTotalCycleCount;
  253. ULONG lFramesAccumulatedRun;
  254. ULONG lFramesAccumulatedPaused;
  255. LONG lDiscontinuityCount;
  256. #endif
  257. //
  258. // Discontinuity is introduced when traistioning from RUN->PAUSE->RUN.
  259. // The stream time will not increment in PAUSE state but system time (1394 CycleTime) does.
  260. //
  261. BOOL b1stNewFrameFromPauseState;
  262. //
  263. // Use to mark the tick count when the stream start running.
  264. // It is later used to calculate current stream time and dropped frames.
  265. //
  266. ULONGLONG tmStreamStart;
  267. #if DBG
  268. ULONGLONG tmStreamPause; // When it is set to PAUSE state
  269. #endif
  270. //
  271. // Counter used to indicate starting of an work item to cancel; this is a token and it is either 0 or 1.
  272. //
  273. LONG lCancelStateWorkItem;
  274. //
  275. // Use to indicate aborting a stream.
  276. //
  277. BOOL bAbortPending;
  278. //
  279. // Hold the work item
  280. //
  281. #ifdef USE_WDM110 // Win2000 code base
  282. PIO_WORKITEM pIoWorkItem;
  283. #else
  284. WORK_QUEUE_ITEM IoWorkItem;
  285. #endif
  286. //
  287. // TO singal that an work item is completed.
  288. //
  289. KEVENT hCancelDoneEvent;
  290. //
  291. // A timer and Dpc objects to periodically check for expired clock events.
  292. //
  293. KDPC * DPCTimer;
  294. KTIMER * Timer;
  295. BOOL bTimerEnabled;
  296. #if DBG
  297. //
  298. // Used to keep track of transmission statistics
  299. //
  300. PXMT_FRAME_STAT paXmtStat;
  301. ULONG ulStatEntries;
  302. #endif
  303. #ifdef SUPPORT_QUALITY_CONTROL
  304. //
  305. // Use for keeping track of quality control
  306. //
  307. KSQUALITY KSQuality;
  308. #endif
  309. } STREAMEX, *PSTREAMEX;
  310. //
  311. // Device Extension for our Desktop Camera Driver
  312. //
  313. typedef struct _DVCR_EXTENSION {
  314. LONG cndStrmOpen;
  315. ULONG idxStreamNumber; // Index of current stream
  316. //
  317. // Can have only 1 Stream active at any time.
  318. // (Stream Class will allocate the stream extension at SRB_OPENSTREAM)
  319. //
  320. PSTREAMEX paStrmExt[3]; // We support three pins
  321. //
  322. // Holds the video format index; it's either PAL or NTSC. Default is NTSC.
  323. //
  324. FMT_INDEX VideoFormatIndex;
  325. //
  326. // Current Device Power State
  327. //
  328. DEVICE_POWER_STATE PowerState;
  329. //
  330. // Contain a table for the support formats
  331. //
  332. ULONG ulNumOfStreamSupported;
  333. HW_STREAM_INFORMATION * paCurrentStrmInfo;
  334. //
  335. // TRUE only after SRB_SURPRISE_REMOVAL;
  336. //
  337. BOOL bDevRemoved;
  338. //
  339. // The list of AVC commands that have been issued
  340. //
  341. LIST_ENTRY AVCCmdList;
  342. // Number of completed commands waiting to be removed from the list
  343. // This includes:
  344. // Command response has returned and processed in the completion routine
  345. // Interim response awaiting final response
  346. LONG cntCommandQueued;
  347. //
  348. // Protection for command processing
  349. //
  350. KSPIN_LOCK AVCCmdLock;
  351. //
  352. // The counted list of possible opcode values on response from Transport State status or notify
  353. //
  354. UCHAR TransportModes[5]; // 0x4, [0xC1, 0xC2, 0xC3, 0xC4]
  355. //
  356. // The device type (and its capabilities) cannot be determined until a tape is in
  357. //
  358. ULONG ulDevType; // 0: undetermined, ED_DEVTYPE_CAMERA or ED_DEVTYPE_VCR
  359. BOOL bHasTape;
  360. BOOL bWriteProtected;
  361. BOOL bDVCPro;
  362. //
  363. // Save Unit capabilities:
  364. // Speed
  365. // Vendor and Model IDs
  366. //
  367. ULONG NumOutputPlugs;
  368. ULONG NumInputPlugs;
  369. ULONG HardwareFlags; // detect PAE: AV_HOST_DMA_DOUBLE_BUFFERING_ENABLED
  370. ULONG MaxDataRate;
  371. ULONG ulVendorID;
  372. ULONG ulModelID;
  373. LARGE_INTEGER UniqueID;
  374. //
  375. // The DV's plug handles/PCRs (assume [0])
  376. //
  377. HANDLE hOPcrDV;
  378. HANDLE hIPcrDV;
  379. #ifdef NT51_61883
  380. //
  381. // PC local oPCR
  382. //
  383. HANDLE hOPcrPC; // PC's local oPCR
  384. #if 0 // Not used since DV does not intiate DV to PC connection.
  385. HANDLE hIPcrPC; // PC's local iPCR
  386. #endif
  387. //
  388. // Isochronous parameters obtained from 61883;
  389. // They are used for making isoch connection.
  390. //
  391. UNIT_ISOCH_PARAMS UnitIoschParams;
  392. #endif
  393. //
  394. // Holds the Device Object of our parent (1394 bus driver)
  395. //
  396. PDEVICE_OBJECT pBusDeviceObject; // IoCallDriver()
  397. //
  398. // Holds my Physical Device Object
  399. // pass it in PnP API, such as IoOpenDeviceRegistryKey()
  400. //
  401. PDEVICE_OBJECT pPhysicalDeviceObject;
  402. //
  403. // Serialize in the event of getting two consecutive SRB_OPEN_STREAMs
  404. //
  405. KMUTEX hMutex;
  406. #ifdef READ_CUTOMIZE_REG_VALUES
  407. #if 0 // Not used in millennium; needed to do frame accurated recording.
  408. //
  409. // Registry values used to achieve frame accurate recording
  410. //
  411. BOOL bATNSearch; // Support ATN search (or Timecode search)
  412. BOOL bSyncRecording; // Sychronize stream state with record/pause transport state
  413. DWORD tmMaxDataSync; // Time it take to sync to DV camcorder
  414. DWORD fmPlayPs2RecPs; // Switch from PLAY_PAUSE to RECORD_PAUSE (unit=frames)
  415. DWORD fmStop2RecPs; // Switch from STOP to RECORD_PAUSE (unit=frames)
  416. DWORD tmRecPs2Rec; // Time to switch from RECORD_PAUSE to RECORD
  417. #endif
  418. ULONG XprtStateChangeWait;
  419. #endif
  420. //
  421. // Since the signal format can dynamically changing, we will query
  422. // the device for the currect format whevever we are asked for doing
  423. // data intersection (note doing it in open is not enough!).
  424. // Instead of doing it always (since there could be a lot of data
  425. // intersection), we only query current format in a regular interval.
  426. //
  427. ULONGLONG tmLastFormatUpdate;
  428. //
  429. // Flow control for AVC command
  430. //
  431. KMUTEX hMutexIssueAVCCmd;
  432. #ifdef SUPPORT_OPTIMIZE_AVCCMD_RETRIES
  433. //
  434. // AVC Command retry count (default is 9 (avc.sys))
  435. //
  436. ULONG AVCCmdRetries; // This is retry count not the total count
  437. //
  438. // Collect statistis of AVC command response time during driver load time.
  439. //
  440. BOOL DrvLoadCompleted; // Collect statistic until loading of driver is completed.
  441. DWORD AVCCmdRespTimeMax; // msec unit
  442. DWORD AVCCmdRespTimeMin; // msec unit
  443. DWORD AVCCmdRespTimeSum; // msec unit
  444. DWORD AVCCmdCount;
  445. #endif
  446. } DVCR_EXTENSION, *PDVCR_EXTENSION;
  447. //
  448. // Used to queue a SRB
  449. //
  450. typedef struct _SRB_ENTRY {
  451. LIST_ENTRY ListEntry;
  452. PHW_STREAM_REQUEST_BLOCK pSrb;
  453. BOOL bStale; // TRUE if it is marked stale but is the only Srb in the SrbQ
  454. // Audio Mute indication; a frame could be repeatedly transmitted and its mute flag should be set only once.
  455. //
  456. BOOL bAudioMute;
  457. #if DBG
  458. ULONG SrbNum;
  459. #endif
  460. } SRB_ENTRY, *PSRB_ENTRY;
  461. //
  462. // Valid data entry states for a data request and they
  463. // can be Or'ed to show their data path.
  464. //
  465. // Examples of different possible code path:
  466. //
  467. // (A) Prepared->Attached->Callback->Completed_SRB
  468. // (B) Prepared->Callback->Attached->Completed_SRB
  469. // (C) Prepared->Attached->Cancelled->Completed_SRB
  470. //
  471. enum DATA_ENTRY_STATE {
  472. DE_PREPARED = 0x01,
  473. DE_IRP_ATTACHED_COMPLETED = 0x02,
  474. DE_IRP_CALLBACK_COMPLETED = 0x04,
  475. DE_IRP_SRB_COMPLETED = 0x08,
  476. DE_IRP_ERROR = 0x10,
  477. DE_IRP_CANCELLED = 0x20,
  478. };
  479. #define IsStateSet(state, bitmask) ((state & (bitmask)) == bitmask)
  480. //
  481. // This is the context used to attach a frame
  482. //
  483. typedef struct _SRB_DATA_PACKET {
  484. // Build list
  485. LIST_ENTRY ListEntry;
  486. //
  487. // Keep track of data entry state
  488. //
  489. enum DATA_ENTRY_STATE State;
  490. PHW_STREAM_REQUEST_BLOCK pSrb;
  491. KSSTATE StreamState; // StreamState when it was attached
  492. PSTREAMEX pStrmExt; // Can get this from pSrb, here for convenience only!
  493. // Used to send 61883 request
  494. PIRP pIrp; // Use to attach and release.
  495. PCIP_FRAME Frame;
  496. PVOID FrameBuffer;
  497. //
  498. // Add debug related info here
  499. //
  500. LONGLONG FrameNumber;
  501. // Use to send 61883 AV data request
  502. AV_61883_REQUEST AVReq;
  503. } SRB_DATA_PACKET, *PSRB_DATA_PACKET;
  504. #define MASK_AUX_50_60_BIT 0x00200000 // bit 5 of PC3 of both AAuxSrc and VAAuxSrc is the NTSC/PAL bit
  505. //
  506. // Wait time constants
  507. //
  508. #define DV_AVC_CMD_DELAY_STARTUP 500 // MSec
  509. #define DV_AVC_CMD_DELAY_INTER_CMD 20 // MSec
  510. #define DV_AVC_CMD_DELAY_DVCPRO 500 // MSec
  511. #define FORMAT_UPDATE_INTERVAL 100000000 // 10 seconds
  512. //
  513. // Default AVC Command settings
  514. //
  515. #define MAX_RESPONSE_TIME_FOR_ALERT 100 // msec
  516. //
  517. // The timeout value is set to give device sufficient time to response
  518. // to an AVC command following a transport state change. It is based
  519. // on trials of many camcorder (Sharp, Sony, Panasonic, Samsung..etc.)
  520. // to come to this value. The biggest delay (timeout) is from issuing
  521. // of PLAY command follow by REWIND command. Some test value:
  522. //
  523. // Hitachi
  524. // JVC DVL9600: Stop->PLAY: delay is less than 300msec (Known issue: no image if play graph before play tape!)
  525. // Panasonic MX2000: Stop->PLAY:2339; ->Rewind:3767 msec
  526. // Samsung VP-D55: Does not support XPrt State status command and will always
  527. // timeout its suqsequent command following XPrtState change
  528. // Sharp VL-WDW450U: Stop->PLAY:3514; ->Rewind:6120 msec
  529. // VL-PD3F: Stop->PLAY:3293; ->Rewind:6404 msec
  530. // Sony DCR-TRV10: Stop->PLAY:3617; ->Rewind:5323 msec
  531. // DA1: Non-compliant (Retry is 0!)
  532. // DA2: No transport state change.
  533. //
  534. #define MAX_AVC_CMD_RETRIES ((DEFAULT_AVC_RETRIES + 1) * 7 - 1) // Retries counts
  535. #endif