Leaked source code of windows server 2003
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.

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