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.

2203 lines
58 KiB

  1. /******************************************************************************\
  2. * *
  3. * ADAPTER.C - Adapter control related code. *
  4. * *
  5. * Copyright (c) C-Cube Microsystems 1996 - 1999 *
  6. * All Rights Reserved. *
  7. * *
  8. * Use of C-Cube Microsystems code is governed by terms and conditions *
  9. * stated in the accompanying licensing statement. *
  10. * *
  11. \******************************************************************************/
  12. #include "Headers.h"
  13. #pragma hdrstop
  14. #include "vidstrm.h"
  15. #include "audstrm.h"
  16. #include "sbpstrm.h"
  17. #include "ccaption.h"
  18. #ifdef ENCORE
  19. #include "avwinwdm.h"
  20. #include "anlgstrm.h"
  21. #else
  22. #include "vpestrm.h"
  23. #include "dataXfer.h"
  24. #endif
  25. #include "zivaguid.h"
  26. #include "boardio.h"
  27. #include "bmaster.h"
  28. #include "cl6100.h"
  29. #include "Hwif.h"
  30. static VOID HwInitialize( IN PHW_STREAM_REQUEST_BLOCK pSrb );
  31. static VOID HwUninitialize( IN PHW_STREAM_REQUEST_BLOCK pSrb );
  32. static VOID AdapterOpenStream( PHW_STREAM_REQUEST_BLOCK pSrb );
  33. static VOID AdapterCloseStream( PHW_STREAM_REQUEST_BLOCK pSrb );
  34. static VOID AdapterStreamInfo( PHW_STREAM_REQUEST_BLOCK pSrb );
  35. static VOID AdapterGetDataIntersection( PHW_STREAM_REQUEST_BLOCK pSrb );
  36. static VOID BeginHwInitialize( IN PHW_STREAM_REQUEST_BLOCK pSrb );
  37. static VOID HighPriorityInit( IN PHW_STREAM_REQUEST_BLOCK pSrb );
  38. static VOID PassiveInit( IN PHW_STREAM_REQUEST_BLOCK pSrb );
  39. static VOID HighPriorityInit( IN PHW_STREAM_REQUEST_BLOCK pSrb );
  40. VOID STREAMAPI AdapterReleaseCurrentSrb( PHW_STREAM_REQUEST_BLOCK pSrb );
  41. #pragma alloc_text( page, HwInitialize )
  42. #pragma alloc_text( page, HwUninitialize )
  43. #if 0
  44. static void STREAMAPI CreateFile(PHW_STREAM_REQUEST_BLOCK pSrb );
  45. OBJECT_ATTRIBUTES InitializedAttributes;
  46. IO_STATUS_BLOCK IOStatusBlock;
  47. HANDLE Handle;
  48. WCHAR wPath[] = L"ohm.dat";
  49. UNICODE_STRING pathUnicodeString;
  50. LARGE_INTEGER AllocSize ;
  51. long dwCountTotal=0;
  52. #endif
  53. PHW_DEVICE_EXTENSION pDevEx;
  54. /******************************************************************************
  55. Adapter Based Request Handling Routines
  56. ******************************************************************************/
  57. /*
  58. ** AdapterReceivePacket()
  59. **
  60. ** Main entry point for receiving adapter based request SRBs. This routine
  61. ** will always be called at High Priority.
  62. **
  63. ** Note: This is an asyncronous entry point. The request does not complete
  64. ** on return from this function, the request only completes when a
  65. ** StreamClassDeviceNotification on this request block, of type
  66. ** DeviceRequestComplete, is issued.
  67. **
  68. ** Arguments:
  69. **
  70. ** pSrb - Pointer to the STREAM_REQUEST_BLOCK
  71. ** pSrb->HwDeviceExtension - will be the hardware device extension for
  72. ** as initialised in HwInitialise
  73. **
  74. ** Returns:
  75. **
  76. ** Side Effects: none
  77. */
  78. VOID STREAMAPI AdapterReceivePacket( IN PHW_STREAM_REQUEST_BLOCK pSrb )
  79. {
  80. PHW_DEVICE_EXTENSION pHwDevExt = (PHW_DEVICE_EXTENSION)pSrb->CommandData.ConfigInfo->HwDeviceExtension;
  81. DebugPrint(( DebugLevelVerbose, "ZiVA: Begin AdapterReceivePacket->" ));
  82. #ifdef DEBUG
  83. if( KeGetCurrentIrql() <= DISPATCH_LEVEL )
  84. {
  85. DebugPrint(( DebugLevelError, "IRQL is screwed!\n" ));
  86. ASSERT( FALSE );
  87. MonoOutSetBlink( TRUE );
  88. MonoOutStr( "IRQL" );
  89. MonoOutSetBlink( FALSE );
  90. }
  91. #endif
  92. switch( pSrb->Command )
  93. {
  94. case SRB_INITIALIZE_DEVICE:
  95. DebugPrint(( DebugLevelVerbose, "SRB_INITIALIZE_DEVICE\n" ));
  96. // HwInitialize( pSrb );
  97. // break;
  98. BeginHwInitialize( pSrb ); //MS update
  99. return;
  100. case SRB_UNINITIALIZE_DEVICE:
  101. DebugPrint(( DebugLevelVerbose, "SRB_UNINITIALIZE_DEVICE\n" ));
  102. HwUninitialize( pSrb );
  103. break;
  104. case SRB_OPEN_STREAM:
  105. DebugPrint(( DebugLevelVerbose, "SRB_OPEN_STREAM\n" ));
  106. AdapterOpenStream( pSrb );
  107. break;
  108. case SRB_CLOSE_STREAM:
  109. DebugPrint(( DebugLevelVerbose, "SRB_CLOSE_STREAM\n" ));
  110. AdapterCloseStream( pSrb );
  111. break;
  112. case SRB_GET_STREAM_INFO:
  113. DebugPrint(( DebugLevelVerbose, "SRB_GET_STREAM_INFO\n" ));
  114. AdapterStreamInfo( pSrb );
  115. break;
  116. case SRB_GET_DATA_INTERSECTION:
  117. DebugPrint(( DebugLevelVerbose, "SRB_GET_DATA_INTERSECTION\n" ));
  118. AdapterGetDataIntersection( pSrb );
  119. break;
  120. case SRB_GET_DEVICE_PROPERTY:
  121. AdapterGetProperty( pSrb );
  122. MonoOutStr("SRB_GET_DEVICE_PROPERTY");
  123. break;
  124. case SRB_SET_DEVICE_PROPERTY:
  125. AdapterSetProperty( pSrb );
  126. MonoOutStr("SRB_SET_DEVICE_PROPERTY");
  127. break;
  128. case SRB_CHANGE_POWER_STATE:
  129. DebugPrint(( DebugLevelVerbose, "SRB_CHANGE_POWER_STATE\n" ));
  130. #if defined(DECODER_DVDPC)
  131. if (pSrb->CommandData.DeviceState == PowerDeviceD0)
  132. {
  133. //
  134. // bugbug - need to turn power back on here.
  135. //
  136. // Vinod.
  137. //sri ZivaHw_Initialize(pHwDevExt);
  138. // Commented for bug fix on GateWay Chameleon
  139. }
  140. else
  141. {
  142. //
  143. // bugbug - need to turn power off here, as well as disabling
  144. // interrupts.
  145. //
  146. //DisableIT();
  147. }
  148. #endif
  149. pSrb->Status = STATUS_SUCCESS;
  150. break;
  151. case SRB_PAGING_OUT_DRIVER:
  152. DebugPrint(( DebugLevelVerbose, "SRB_PAGING_OUT_DRIVER\n" ));
  153. //TRAP
  154. //DisableIT();
  155. pSrb->Status = STATUS_SUCCESS;
  156. break;
  157. default:
  158. DebugPrint(( DebugLevelInfo, "!!!! UNKNOWN COMMAND !!!! :::> %X\n", pSrb->Command ));
  159. // This is a request that we do not understand. Indicate invalid
  160. // command and complete the request
  161. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  162. }
  163. AdapterReleaseRequest( pSrb );
  164. DebugPrint(( DebugLevelVerbose, "ZiVA: End AdapterReceivePacket\n" ));
  165. }
  166. /******************************************************************************/
  167. /******************* Adapter Initialization Section *************************/
  168. /******************************************************************************/
  169. /*
  170. ** BeginHwInitialize()
  171. **
  172. ** Stub for the init sequence
  173. **
  174. ** Arguments:
  175. **
  176. ** pSRB - pointer to the request packet for the initialise command
  177. **
  178. ** ->ConfigInfo - provides the I/O port, memory windows, IRQ, and DMA levels
  179. ** that should be used to access this instance of the device
  180. **
  181. ** Returns:
  182. **
  183. **
  184. **
  185. ** Side Effects: none
  186. */
  187. static VOID BeginHwInitialize( IN PHW_STREAM_REQUEST_BLOCK pSrb )
  188. {
  189. PPORT_CONFIGURATION_INFORMATION ConfigInfo = pSrb->CommandData.ConfigInfo;
  190. PHW_DEVICE_EXTENSION pHwDevExt = (PHW_DEVICE_EXTENSION)ConfigInfo->HwDeviceExtension;
  191. DebugPrint(( DebugLevelVerbose, "ZiVA: BeginHwInitialize()\n" ));
  192. StreamClassCallAtNewPriority(NULL, pHwDevExt, Low, PassiveInit, pSrb);
  193. return;
  194. }
  195. /*
  196. ** PassiveInit()
  197. **
  198. ** Passive level callback for the init sequence
  199. **
  200. ** Arguments:
  201. **
  202. ** pSRB - pointer to the request packet for the initialise command
  203. **
  204. ** ->ConfigInfo - provides the I/O port, memory windows, IRQ, and DMA levels
  205. ** that should be used to access this instance of the device
  206. **
  207. ** Returns:
  208. **
  209. **
  210. **
  211. ** Side Effects: none
  212. */
  213. static VOID PassiveInit( IN PHW_STREAM_REQUEST_BLOCK pSrb )
  214. {
  215. PPORT_CONFIGURATION_INFORMATION ConfigInfo = pSrb->CommandData.ConfigInfo;
  216. PHW_DEVICE_EXTENSION pHwDevExt = (PHW_DEVICE_EXTENSION)ConfigInfo->HwDeviceExtension;
  217. InitializeHost(pSrb);
  218. StreamClassCallAtNewPriority(NULL, pHwDevExt, LowToHigh, HighPriorityInit, pSrb);
  219. return;
  220. }
  221. /*
  222. ** HighPriorityInit()
  223. **
  224. ** High priority callback for the init sequence
  225. **
  226. ** Arguments:
  227. **
  228. ** pSRB - pointer to the request packet for the initialise command
  229. **
  230. ** ->ConfigInfo - provides the I/O port, memory windows, IRQ, and DMA levels
  231. ** that should be used to access this instance of the device
  232. **
  233. ** Returns:
  234. **
  235. **
  236. **
  237. ** Side Effects: none
  238. */
  239. static VOID HighPriorityInit( IN PHW_STREAM_REQUEST_BLOCK pSrb )
  240. {
  241. HwInitialize(pSrb);
  242. AdapterReleaseRequest( pSrb );
  243. }
  244. /*
  245. ** HwInitialize()
  246. **
  247. ** Initializes an adapter accessed through the information provided in the
  248. ** ConfigInfo structure
  249. **
  250. ** Arguments:
  251. **
  252. ** pSRB - pointer to the request packet for the initialise command
  253. **
  254. ** ->ConfigInfo - provides the I/O port, memory windows, IRQ, and DMA levels
  255. ** that should be used to access this instance of the device
  256. **
  257. ** Returns:
  258. **
  259. ** STATUS_SUCCESS - if the card initializes correctly
  260. ** STATUS_NO_SUCH_DEVICE - or other if the card is not found, or does
  261. ** not initialize correctly.
  262. **
  263. **
  264. ** Side Effects: none
  265. */
  266. static VOID HwInitialize( IN PHW_STREAM_REQUEST_BLOCK pSrb )
  267. {
  268. PPORT_CONFIGURATION_INFORMATION ConfigInfo = pSrb->CommandData.ConfigInfo;
  269. PHW_DEVICE_EXTENSION pHwDevExt = (PHW_DEVICE_EXTENSION)ConfigInfo->HwDeviceExtension;
  270. ULONG dwSize;
  271. DebugPrint(( DebugLevelVerbose, "ZiVA: Begin HwInitialize()\n" ));
  272. // InitializeHost(pSrb);
  273. pHwDevExt->bVideoStreamOpened = FALSE;
  274. pHwDevExt->bAudioStreamOpened = FALSE;
  275. pHwDevExt->bSubPictureStreamOpened = FALSE;
  276. pHwDevExt->bOverlayInitialized = FALSE;
  277. pHwDevExt->nAnalogStreamOpened = 0;
  278. pHwDevExt->iTotalOpenedStreams = 0;
  279. pHwDevExt->bVideoCanAuthenticate = FALSE;
  280. pHwDevExt->bAudioCanAuthenticate = FALSE;
  281. pHwDevExt->bSubPictureCanAuthenticate = FALSE;
  282. pHwDevExt->iStreamToAuthenticateOn = -1;
  283. pHwDevExt->bValidSPU = FALSE;
  284. pHwDevExt->hli.StartPTM = 0;
  285. pHwDevExt->pCurrentVideoSrb = NULL;
  286. pHwDevExt->dwCurrentVideoSample = 0;
  287. pHwDevExt->pCurrentAudioSrb = NULL;
  288. pHwDevExt->dwCurrentAudioSample = 0;
  289. pHwDevExt->pCurrentSubPictureSrb = NULL;
  290. pHwDevExt->dwCurrentSubPictureSample = 0;
  291. pHwDevExt->CurrentlySentStream = ZivaNumberOfStreams; // Just make sure it is none of them
  292. pHwDevExt->wNextSrbOrderNumber = 0;
  293. pHwDevExt->bInterruptPending = FALSE;
  294. pHwDevExt->bPlayCommandPending = FALSE;
  295. pHwDevExt->bScanCommandPending = FALSE;
  296. pHwDevExt->bSlowCommandPending = FALSE;
  297. pHwDevExt->nStopCount = 0;
  298. pHwDevExt->nPauseCount = 0;
  299. pHwDevExt->nPlayCount = 0;
  300. pHwDevExt->nTimeoutCount = AUTHENTICATION_TIMEOUT_COUNT;
  301. pHwDevExt->NewRate = 10000;
  302. pHwDevExt->bToBeDiscontinued = FALSE;
  303. pHwDevExt->bDiscontinued = FALSE;
  304. pHwDevExt->bAbortAtPause = FALSE;
  305. pHwDevExt->bRateChangeFromSlowMotion = FALSE;
  306. pHwDevExt->dwVideoDataUsed =0;
  307. pHwDevExt->dwAudioDataUsed =0;
  308. pHwDevExt->dwSubPictureDataUsed =0;
  309. pHwDevExt->bEndFlush = FALSE;
  310. pHwDevExt->bTimerScheduled = FALSE;
  311. pHwDevExt->dwCurrentVideoPage = 0;
  312. pHwDevExt->dwCurrentAudioPage = 0;
  313. pHwDevExt->dwCurrentSubPicturePage = 0;
  314. pHwDevExt->bStreamNumberCouldBeChanged = FALSE;
  315. pHwDevExt->wCurrentStreamNumber = -1;
  316. pHwDevExt->bSwitchDecryptionOn = FALSE;
  317. pHwDevExt->zInitialState = ZIVA_STATE_STOP;
  318. pHwDevExt->bHliPending = FALSE;
  319. pHwDevExt->gdwCount = 0;
  320. pHwDevExt->dwFirstVideoOrdNum = -1;
  321. pHwDevExt->dwFirstAudioOrdNum = -1;
  322. pHwDevExt->dwFirstSbpOrdNum = -1;
  323. pHwDevExt->dwVSyncCount =0;
  324. pHwDevExt->nApsMode = -1;
  325. pHwDevExt->VidSystem = -1;
  326. pHwDevExt->ulLevel =0;
  327. pHwDevExt->fAtleastOne = TRUE;
  328. pHwDevExt->dwPrevSTC = 0;
  329. pHwDevExt->bTrickModeToPlay =FALSE;
  330. pHwDevExt->prevStrm =0;
  331. pHwDevExt->fFirstSTC = FALSE;
  332. pHwDevExt->cCCRec=0;
  333. pHwDevExt->cCCDeq=0;
  334. pHwDevExt->cCCCB=0;
  335. pHwDevExt->cCCQ=0;
  336. pHwDevExt->pstroCC = NULL;
  337. pHwDevExt->dwUserDataSize=0;
  338. pHwDevExt->fReSync = FALSE;
  339. pHwDevExt->bInitialized = TRUE;
  340. pDevEx = pHwDevExt ;
  341. pHwDevExt->pPhysicalDeviceObj = ConfigInfo->PhysicalDeviceObject;
  342. pHwDevExt->pDiscKeyBufferLinear = (PUCHAR)StreamClassGetDmaBuffer( pHwDevExt );
  343. pHwDevExt->pDiscKeyBufferPhysical = StreamClassGetPhysicalAddress(
  344. pHwDevExt,
  345. NULL,
  346. pHwDevExt->pDiscKeyBufferLinear,
  347. DmaBuffer,
  348. &dwSize );
  349. // Indicate the size of the structure necessary to describe all streams
  350. // that are supported by this hardware
  351. ConfigInfo->StreamDescriptorSize = sizeof( HW_STREAM_HEADER )+ // Stream header and
  352. ZivaNumberOfStreams * sizeof( HW_STREAM_INFORMATION ); // stream descriptors
  353. pHwDevExt->pCCDevEx = pHwDevExt;
  354. pSrb->Status = STATUS_SUCCESS;
  355. #if defined (LOAD_UCODE_FROM_FILE)
  356. // Do nothing.
  357. #else
  358. if( !ZivaHw_Initialize( pHwDevExt ) || !InitializeOutputStream( pSrb ))
  359. pSrb->Status = STATUS_IO_DEVICE_ERROR;
  360. #endif
  361. DebugPrint(( DebugLevelVerbose, "ZiVA: End HwInitialize()\n" ));
  362. }
  363. /*
  364. ** HwUninitialize()
  365. **
  366. ** Release all resources and clean up the hardware
  367. **
  368. ** Arguments:
  369. **
  370. ** DeviceExtension - pointer to the deviceextension structure for the
  371. ** the device to be free'd
  372. **
  373. ** Returns:
  374. **
  375. ** Side Effects: none
  376. */
  377. static VOID HwUninitialize( IN PHW_STREAM_REQUEST_BLOCK pSrb )
  378. {
  379. DebugPrint(( DebugLevelVerbose, "ZiVA: Begin HwUninitialize()\n" ));
  380. #ifdef ENCORE
  381. AnalogUninitialize( pSrb );
  382. #else
  383. pSrb->Status = STATUS_SUCCESS;
  384. #endif
  385. DebugPrint(( DebugLevelVerbose, "ZiVA: End HwUninitialize()\n" ));
  386. }
  387. /*
  388. ** AdapterOpenStream()
  389. **
  390. ** This routine is called when an OpenStream SRB request is received
  391. **
  392. ** Arguments:
  393. **
  394. ** pSrb - pointer to stream request block for the Open command
  395. **
  396. ** Returns:
  397. **
  398. ** Side Effects: none
  399. */
  400. static VOID AdapterOpenStream( PHW_STREAM_REQUEST_BLOCK pSrb )
  401. {
  402. int i;
  403. PHW_DEVICE_EXTENSION pHwDevExt = (PHW_DEVICE_EXTENSION)pSrb->HwDeviceExtension;
  404. DebugPrint(( DebugLevelVerbose, "ZiVA: Begin AdapterOpenStream\n" ));
  405. pSrb->Status = STATUS_TOO_MANY_NODES;
  406. for( i = 0; i < SIZEOF_ARRAY( infoStreams ); i++ )
  407. {
  408. if( infoStreams[i].hwStreamObject.StreamNumber == pSrb->StreamObject->StreamNumber )
  409. { // This is the stream we're interested in.
  410. // Then copy stream object structure into passed buffer
  411. PVOID pHwStreamExtension = pSrb->StreamObject->HwStreamExtension;
  412. *(pSrb->StreamObject) = infoStreams[i].hwStreamObject;
  413. pSrb->StreamObject->HwStreamExtension = pHwStreamExtension;
  414. pSrb->StreamObject->HwDeviceExtension = pHwDevExt;
  415. pSrb->Status = STATUS_SUCCESS;
  416. break;
  417. }
  418. }
  419. if( pSrb->Status == STATUS_SUCCESS )
  420. {
  421. ++pHwDevExt->iTotalOpenedStreams;
  422. ++pHwDevExt->nStopCount;
  423. ++pHwDevExt->nPauseCount;
  424. ++pHwDevExt->nPlayCount;
  425. switch( pSrb->StreamObject->StreamNumber )
  426. {
  427. case ZivaVideo:
  428. pHwDevExt->bVideoStreamOpened = TRUE;
  429. #if defined(DECODER_DVDPC) || defined(EZDVD)
  430. ProcessVideoFormat( pSrb->CommandData.OpenFormat, pHwDevExt );
  431. #endif
  432. break;
  433. case ZivaAudio:
  434. pHwDevExt->bAudioStreamOpened = TRUE;
  435. pHwDevExt->pstroAud = pSrb->StreamObject;
  436. break;
  437. case ZivaSubpicture:
  438. pHwDevExt->bSubPictureStreamOpened = TRUE;
  439. break;
  440. #ifdef ENCORE
  441. case ZivaAnalog:
  442. ++pHwDevExt->nAnalogStreamOpened;
  443. AnalogOpenStream( pSrb );
  444. break;
  445. #endif
  446. #if defined(DECODER_DVDPC) || defined(EZDVD)
  447. case ZivaYUV:
  448. pHwDevExt->pstroYUV = pSrb->StreamObject;
  449. pSrb->StreamObject->HwEventRoutine = (PHW_EVENT_ROUTINE) CycEvent;
  450. break;
  451. #endif
  452. case ZivaCCOut:
  453. pHwDevExt->pstroCC = pSrb->StreamObject;
  454. break;
  455. default:
  456. ASSERT( FALSE );
  457. }
  458. }
  459. else
  460. DebugPrint(( DebugLevelWarning, "ZiVA: !!! Strange Stream Number\n" ));
  461. if ( pHwDevExt->iTotalOpenedStreams == 1 )
  462. {
  463. pHwDevExt->dwVideoDataUsed = 0;
  464. pHwDevExt->dwAudioDataUsed = 0;
  465. pHwDevExt->dwSubPictureDataUsed = 0;
  466. pHwDevExt->bStreamNumberCouldBeChanged = FALSE;
  467. pHwDevExt->wCurrentStreamNumber = -1;
  468. pHwDevExt->bSwitchDecryptionOn = FALSE;
  469. pHwDevExt->zInitialState = ZIVA_STATE_STOP;
  470. pHwDevExt->bEndFlush = FALSE;
  471. pHwDevExt->bTimerScheduled = FALSE;
  472. if ( !ZivaHw_Initialize( pHwDevExt ) )
  473. {
  474. DebugPrint((DebugLevelFatal,"ZiVA: Could not Initialize the HW on first Stream Open\n"));
  475. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  476. }
  477. }
  478. DebugPrint(( DebugLevelVerbose, "ZiVA: End AdapterOpenStream\n" ));
  479. }
  480. /*
  481. ** AdapterCloseStream()
  482. **
  483. ** Close the requested data stream
  484. **
  485. ** Arguments:
  486. **
  487. ** pSrb the request block requesting to close the stream
  488. **
  489. ** Returns:
  490. **
  491. ** Side Effects: none
  492. */
  493. static VOID AdapterCloseStream( PHW_STREAM_REQUEST_BLOCK pSrb )
  494. {
  495. PHW_DEVICE_EXTENSION pHwDevExt = (PHW_DEVICE_EXTENSION)pSrb->HwDeviceExtension;
  496. DebugPrint(( DebugLevelVerbose, "ZiVA: Begin AdapterCloseStream\n" ));
  497. pSrb->Status = STATUS_SUCCESS;
  498. ASSERT( pHwDevExt->nStopCount == pHwDevExt->iTotalOpenedStreams );
  499. ASSERT( pHwDevExt->nPauseCount == pHwDevExt->iTotalOpenedStreams );
  500. ASSERT( pHwDevExt->nPlayCount == pHwDevExt->iTotalOpenedStreams );
  501. --pHwDevExt->iTotalOpenedStreams;
  502. --pHwDevExt->nStopCount;
  503. --pHwDevExt->nPauseCount;
  504. --pHwDevExt->nPlayCount;
  505. // Determine which stream number is being closed. This number indicates
  506. // the offset into the array of streaminfo structures that was filled out
  507. // in the AdapterStreamInfo call.
  508. switch( pSrb->StreamObject->StreamNumber )
  509. {
  510. case ZivaVideo:
  511. pHwDevExt->bVideoStreamOpened = FALSE;
  512. break;
  513. case ZivaAudio:
  514. pHwDevExt->bAudioStreamOpened = FALSE;
  515. pHwDevExt->pstroAud = NULL;
  516. break;
  517. case ZivaSubpicture:
  518. pHwDevExt->bSubPictureStreamOpened = FALSE;
  519. break;
  520. #ifdef ENCORE
  521. case ZivaAnalog:
  522. --pHwDevExt->nAnalogStreamOpened;
  523. AnalogCloseStream( pSrb );
  524. break;
  525. #endif
  526. #if defined(DECODER_DVDPC) || defined(EZDVD)
  527. case ZivaYUV:
  528. pHwDevExt->pstroYUV = NULL;
  529. pHwDevExt->VideoPort = 0; // Disable
  530. break;
  531. #endif
  532. case ZivaCCOut:
  533. CleanCCQueue(pHwDevExt);
  534. pHwDevExt->pstroCC = NULL;
  535. break;
  536. default:
  537. ++pHwDevExt->iTotalOpenedStreams;
  538. ++pHwDevExt->nStopCount;
  539. ++pHwDevExt->nPauseCount;
  540. ++pHwDevExt->nPlayCount;
  541. DebugPrint(( DebugLevelWarning, "ZiVA: !!! Strange Stream Number\n" ));
  542. ASSERT( FALSE );
  543. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  544. //TRAP
  545. }
  546. //
  547. // Reset the Authenticated Stream if anyone is being closed
  548. //
  549. pHwDevExt->iStreamToAuthenticateOn = -1;
  550. //
  551. // Reset the HW on last Stream Close
  552. //
  553. if( pHwDevExt->iTotalOpenedStreams == 0 )
  554. {
  555. pHwDevExt->wNextSrbOrderNumber = 0;
  556. // Make sure next Authentication request will be postponed
  557. // until "last packet" flag has come on each stream.
  558. AdapterClearAuthenticationStatus( pHwDevExt );
  559. // Clean up the hardware
  560. if( !ZivaHw_Reset() )
  561. {
  562. DebugPrint(( DebugLevelError, "ZiVA: Could not Reset the HW on last Stream Closed\n" ));
  563. pSrb->Status = STATUS_IO_DEVICE_ERROR;
  564. }
  565. #if defined(ENCORE)
  566. else
  567. AnalogCloseStream( pSrb );
  568. #endif
  569. }
  570. #ifdef DEBUG
  571. if( pHwDevExt->iTotalOpenedStreams < 0 )
  572. DebugPrint(( DebugLevelWarning, "ZiVA: !!!!!!!!!!!!!!!!!! Open/Close streams mismatch !!!!!!!!!!!!!!!!\n" ));
  573. #endif
  574. DebugPrint(( DebugLevelVerbose, "ZiVA: End AdapterCloseStream\n" ));
  575. }
  576. void AdapterInitLocals(PHW_DEVICE_EXTENSION pHwDevExt)
  577. {
  578. pHwDevExt->pCurrentVideoSrb = NULL;
  579. pHwDevExt->dwCurrentVideoSample = 0;
  580. pHwDevExt->pCurrentAudioSrb = NULL;
  581. pHwDevExt->dwCurrentAudioSample = 0;
  582. pHwDevExt->pCurrentSubPictureSrb = NULL;
  583. pHwDevExt->dwCurrentSubPictureSample = 0;
  584. pHwDevExt->CurrentlySentStream = ZivaNumberOfStreams; // Just make sure it is none of them
  585. pHwDevExt->bInterruptPending = FALSE;
  586. pHwDevExt->bPlayCommandPending = FALSE;
  587. pHwDevExt->bScanCommandPending = FALSE;
  588. pHwDevExt->bSlowCommandPending = FALSE;
  589. pHwDevExt->bHliPending = FALSE;
  590. pHwDevExt->NewRate = 10000;
  591. pHwDevExt->dwVideoDataUsed = 0;
  592. pHwDevExt->dwCurrentVideoPage = 0;
  593. pHwDevExt->dwCurrentAudioPage = 0;
  594. pHwDevExt->dwCurrentSubPicturePage = 0;
  595. pHwDevExt->dwAudioDataUsed = 0;
  596. pHwDevExt->dwSubPictureDataUsed = 0;
  597. pHwDevExt->bToBeDiscontinued = FALSE;
  598. pHwDevExt->bDiscontinued = FALSE;
  599. pHwDevExt->bAbortAtPause = FALSE;
  600. pHwDevExt->bRateChangeFromSlowMotion = FALSE;
  601. pHwDevExt->gdwCount = 0;
  602. pHwDevExt->dwFirstVideoOrdNum = -1;
  603. pHwDevExt->dwFirstAudioOrdNum = -1;
  604. pHwDevExt->dwFirstSbpOrdNum = -1;
  605. pHwDevExt->dwVSyncCount =0;
  606. pHwDevExt->nApsMode = -1;
  607. pHwDevExt->VidSystem = -1;
  608. pHwDevExt->ulLevel =0;
  609. pHwDevExt->fAtleastOne = TRUE;
  610. //temp pHwDevExt->dwPrevSTC = 0;
  611. pHwDevExt->bTrickModeToPlay =FALSE;
  612. pHwDevExt->prevStrm =0;
  613. pHwDevExt->fFirstSTC = TRUE;
  614. pHwDevExt->cCCRec=0;
  615. pHwDevExt->cCCDeq=0;
  616. pHwDevExt->cCCCB=0;
  617. pHwDevExt->cCCQ=0;
  618. // pHwDevExt->pstroCC = NULL;
  619. // pHwDevExt->dwUserDataBuffer[]={0};
  620. pHwDevExt->dwUserDataSize=0;
  621. pHwDevExt->fReSync = FALSE;
  622. CleanCCQueue(pHwDevExt);
  623. #ifdef EZDVD
  624. ZivaHw_Initialize(pHwDevExt);
  625. #endif
  626. }
  627. /*
  628. ** AdapterStreamInfo()
  629. **
  630. ** Returns the information of all streams that are supported by the
  631. ** mini-driver
  632. **
  633. ** Arguments:
  634. **
  635. ** pSrb - Pointer to the STREAM_REQUEST_BLOCK
  636. ** pSrb->HwDeviceExtension - will be the hardware device extension for
  637. ** as initialised in HwInitialise
  638. **
  639. ** Returns:
  640. **
  641. ** Side Effects: none
  642. */
  643. static VOID AdapterStreamInfo( PHW_STREAM_REQUEST_BLOCK pSrb )
  644. {
  645. int i;
  646. PHW_DEVICE_EXTENSION pdevext = (PHW_DEVICE_EXTENSION)pSrb->HwDeviceExtension;
  647. PHW_STREAM_HEADER pStrHdr = &(pSrb->CommandData.StreamBuffer->StreamHeader);
  648. PHW_STREAM_INFORMATION pstrinfo = &(pSrb->CommandData.StreamBuffer->StreamInfo);
  649. DebugPrint(( DebugLevelVerbose, "ZiVA: Begin AdapterStreamInfo\n" ));
  650. // Fill stream header structure
  651. pStrHdr->NumberOfStreams = ZivaNumberOfStreams;
  652. pStrHdr->SizeOfHwStreamInformation = sizeof( HW_STREAM_INFORMATION );
  653. pStrHdr->Topology = (PKSTOPOLOGY)&Topology;
  654. #ifdef ENCORE
  655. pStrHdr->NumDevPropArrayEntries = SIZEOF_ARRAY( psEncore );
  656. pStrHdr->DevicePropertiesArray = (PKSPROPERTY_SET)psEncore;
  657. #else
  658. pStrHdr->NumDevPropArrayEntries = 0;
  659. pStrHdr->DevicePropertiesArray = NULL;
  660. #endif
  661. for( i = 0; i < SIZEOF_ARRAY( infoStreams ); i++, pstrinfo++ )
  662. { // Copy stream information structure into passed buffer
  663. *pstrinfo = infoStreams[i].hwStreamInfo;
  664. }
  665. pSrb->Status = STATUS_SUCCESS;
  666. DebugPrint(( DebugLevelVerbose, "ZiVA: End AdapterStreamInfo\n" ));
  667. }
  668. /*
  669. ** AdapterGetDataIntersection()
  670. **
  671. **
  672. **
  673. ** Arguments:
  674. **
  675. **
  676. **
  677. ** Returns:
  678. **
  679. ** Side Effects:
  680. */
  681. static VOID AdapterGetDataIntersection( PHW_STREAM_REQUEST_BLOCK pSrb )
  682. {
  683. PSTREAM_DATA_INTERSECT_INFO IntersectInfo = pSrb->CommandData.IntersectInfo;
  684. PKSDATARANGE DataRange = IntersectInfo->DataRange;
  685. PKSDATAFORMAT* pFormat;
  686. ULONG i, formatSize;
  687. if( IntersectInfo->StreamNumber >= ZivaNumberOfStreams )
  688. { // Incorrect stream number
  689. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  690. return;
  691. }
  692. pSrb->Status = STATUS_NO_MATCH;
  693. #if defined (ENCORE)
  694. if( IntersectInfo->StreamNumber == ZivaAnalog )
  695. {
  696. PKSDATAFORMAT pFrmt = (PKSDATAFORMAT)&ZivaFormatAnalogOverlayOut;
  697. pFormat = &pFrmt;
  698. }
  699. /* else if(IntersectInfo->StreamNumber == ZivaCCOut)
  700. {
  701. // *pFormat = &hwfmtiCCOut;
  702. // formatSize = sizeof hwfmtiCCOut;
  703. MonoOutStr("CCOut");
  704. pFormat = infoStreams[IntersectInfo->StreamNumber].hwStreamInfo.StreamFormatsArray;
  705. }*/
  706. else
  707. #endif
  708. pFormat = infoStreams[IntersectInfo->StreamNumber].hwStreamInfo.StreamFormatsArray;
  709. for( i = 0; i < infoStreams[IntersectInfo->StreamNumber].hwStreamInfo.NumberOfFormatArrayEntries;
  710. pFormat++, i++ )
  711. { // Check format
  712. formatSize = (*pFormat)->FormatSize;
  713. #if defined (ENCORE)
  714. if( IntersectInfo->StreamNumber != ZivaAnalog && DataRange->FormatSize != formatSize )
  715. continue;
  716. #endif
  717. if( IsEqualGUID( &DataRange->MajorFormat, &((*pFormat)->MajorFormat) ) &&
  718. IsEqualGUID( &DataRange->SubFormat, &((*pFormat)->SubFormat) ) &&
  719. IsEqualGUID( &DataRange->Specifier, &((*pFormat)->Specifier) ) )
  720. {
  721. pSrb->Status = STATUS_SUCCESS;
  722. break;
  723. }
  724. }
  725. if( pSrb->Status != STATUS_SUCCESS )
  726. return;
  727. // Check to see if the size of the passed in buffer is a ULONG.
  728. // if so, this indicates that we are to return only the size
  729. // needed, and not return the actual data.
  730. if( IntersectInfo->SizeOfDataFormatBuffer != sizeof( ULONG ) )
  731. { //
  732. // we are to copy the data, not just return the size
  733. //
  734. if( IntersectInfo->SizeOfDataFormatBuffer < formatSize )
  735. pSrb->Status = STATUS_BUFFER_TOO_SMALL;
  736. else
  737. {
  738. RtlCopyMemory( IntersectInfo->DataFormatBuffer, *pFormat, formatSize );
  739. pSrb->ActualBytesTransferred = formatSize;
  740. pSrb->Status = STATUS_SUCCESS;
  741. }
  742. }
  743. else // if sizeof ULONG specified
  744. {
  745. // Caller wants just the size of the buffer. Get that.
  746. *(PULONG)IntersectInfo->DataFormatBuffer = formatSize;
  747. pSrb->ActualBytesTransferred = sizeof( ULONG );
  748. } // if sizeof ULONG
  749. }
  750. VOID STREAMAPI adapterUpdateNextSrbOrderNumberOnDiscardSrb( PHW_STREAM_REQUEST_BLOCK pSrb )
  751. {
  752. PHW_DEVICE_EXTENSION pHwDevExt = (PHW_DEVICE_EXTENSION)pSrb->HwDeviceExtension;
  753. ULONG ulSample;
  754. KSSTREAM_HEADER * pHeader;
  755. WORD wMaxDiscardedOrderNumber = 0;
  756. for( ulSample = 0; ulSample < pSrb->NumberOfBuffers; ulSample++ )
  757. {
  758. pHeader = ((PKSSTREAM_HEADER)pSrb->CommandData.DataBufferArray) + ulSample;
  759. wMaxDiscardedOrderNumber = max( (WORD)((pHeader->TypeSpecificFlags) >> 16), wMaxDiscardedOrderNumber );
  760. }
  761. if ( wMaxDiscardedOrderNumber >= pHwDevExt->wNextSrbOrderNumber )
  762. {
  763. pHwDevExt->wNextSrbOrderNumber = wMaxDiscardedOrderNumber + 1;
  764. MonoOutStr( "<<< Updating NextSrbOrderNumber to " );
  765. MonoOutULong( pHwDevExt->wNextSrbOrderNumber );
  766. MonoOutStr( " >>>" );
  767. }
  768. return ;
  769. }
  770. /*
  771. ** MoveToNextSample()
  772. **
  773. ** This routine is being called when there is a need to move
  774. ** to the next Sample(buffer) in the current Srb.
  775. **
  776. ** Arguments:
  777. ** pSrb - the request block to advance Sample Number.
  778. **
  779. ** Returns:
  780. ** TRUE - Successfuly moved to next Sample
  781. ** FALSE - There was no more samples and current Srb was released
  782. **
  783. ** Side Effects: unknown
  784. */
  785. BOOLEAN STREAMAPI MoveToNextSample( PHW_STREAM_REQUEST_BLOCK pSrb )
  786. {
  787. PHW_DEVICE_EXTENSION pHwDevExt = (PHW_DEVICE_EXTENSION)pSrb->HwDeviceExtension;
  788. DWORD* pdwCurrentSrbSample;
  789. DWORD* pdwCurrentSrbPage;
  790. switch( pSrb->StreamObject->StreamNumber )
  791. {
  792. case ZivaVideo:
  793. pdwCurrentSrbSample = &pHwDevExt->dwCurrentVideoSample;
  794. pdwCurrentSrbPage = &pHwDevExt->dwCurrentVideoPage;
  795. break;
  796. case ZivaAudio:
  797. pdwCurrentSrbSample = &pHwDevExt->dwCurrentAudioSample;
  798. pdwCurrentSrbPage = &pHwDevExt->dwCurrentAudioPage;
  799. break;
  800. case ZivaSubpicture:
  801. pdwCurrentSrbSample = &pHwDevExt->dwCurrentSubPictureSample;
  802. pdwCurrentSrbPage = &pHwDevExt->dwCurrentSubPicturePage;
  803. break;
  804. default:
  805. MonoOutStr( "!!!!!!!!!!!!!!!!!!! WRONG STREAM # IN MoveToNextSample ROUTINE !!!!!!!!!!!!!!!!!!!!!!!!!!!" );
  806. return FALSE;
  807. }
  808. // if(dwDataUsed == 0)
  809. // {
  810. (*pdwCurrentSrbSample)++;
  811. // pHwDevExt->wNextSrbOrderNumber++;
  812. // }
  813. (*pdwCurrentSrbPage)++;
  814. if( *pdwCurrentSrbSample >= pSrb->NumberOfBuffers)
  815. {
  816. if( *pdwCurrentSrbSample > pSrb->NumberOfBuffers )
  817. {
  818. MonoOutSetBlink( TRUE );
  819. MonoOutStr( "<<< Current sample number is higher than the number of buffers >>>" );
  820. MonoOutSetBlink( FALSE );
  821. }
  822. // MonoOutStr("MoveToNextSample()::RSRB");
  823. AdapterReleaseCurrentSrb( pSrb );
  824. return FALSE;
  825. }
  826. return TRUE;
  827. }
  828. VOID CancelPacket( PHW_STREAM_REQUEST_BLOCK pSrb, BOOL bCancel )
  829. {
  830. PHW_DEVICE_EXTENSION pHwDevExt = (PHW_DEVICE_EXTENSION)pSrb->HwDeviceExtension;
  831. ULONG ulSample;
  832. PKSSTREAM_HEADER pHeader;
  833. WORD wMaxOrder = 0, wMinOrder = 0xFFFF;
  834. #ifdef DEBUG
  835. LPSTR pszFuncString, pszPacketString = NULL;
  836. pszFuncString = bCancel ? "Cancel" : "Timeout";
  837. DebugPrint(( DebugLevelVerbose,"ZiVA: Adapter%sPacket ->", pszFuncString ));
  838. MonoOutSetUnderscore( TRUE );
  839. MonoOutChar( ' ' );
  840. MonoOutStr( pszFuncString );
  841. MonoOutStr( "->" );
  842. #endif
  843. if( !(pSrb->Flags & SRB_HW_FLAGS_DATA_TRANSFER) )
  844. {
  845. DebugPrint(( DebugLevelVerbose," As a Control\n" ));
  846. MonoOutStr( "(Control or Device)" );
  847. AdapterReleaseRequest( pSrb );
  848. return;
  849. }
  850. // We need to find this packet, pull it off our queues, and cancel it
  851. // Try to find this Srb in the Pending List. If it's there just
  852. // empty the slot
  853. if(bCancel)
  854. {
  855. if( pHwDevExt->pCurrentVideoSrb == pSrb )
  856. {
  857. #ifdef DEBUG
  858. pszPacketString = "Video";
  859. #endif
  860. pHwDevExt->pCurrentVideoSrb = NULL;
  861. pHwDevExt->dwCurrentVideoSample = 0;
  862. pHwDevExt->dwCurrentVideoPage = 0;
  863. pHwDevExt->dwVideoDataUsed =0;
  864. }
  865. else if( pHwDevExt->pCurrentAudioSrb == pSrb )
  866. {
  867. #ifdef DEBUG
  868. pszPacketString = "Audio";
  869. #endif
  870. pHwDevExt->pCurrentAudioSrb = NULL;
  871. pHwDevExt->dwCurrentAudioSample = 0;
  872. pHwDevExt->dwCurrentAudioPage = 0;
  873. pHwDevExt->dwAudioDataUsed = 0;
  874. }
  875. else if( pHwDevExt->pCurrentSubPictureSrb == pSrb )
  876. {
  877. #ifdef DEBUG
  878. pszPacketString = "Subpicture";
  879. #endif
  880. pHwDevExt->pCurrentSubPictureSrb = NULL;
  881. pHwDevExt->dwCurrentSubPictureSample = 0;
  882. pHwDevExt->dwCurrentSubPicturePage = 0;
  883. pHwDevExt->dwSubPictureDataUsed = 0;
  884. }
  885. }
  886. else //added 11/6/98
  887. {
  888. if( pHwDevExt->bInterruptPending )
  889. MoveToNextSample( pSrb );
  890. }
  891. #ifdef DEBUG
  892. if( pszPacketString )
  893. {
  894. DebugPrint(( DebugLevelVerbose, pszPacketString ));
  895. MonoOutStr( pszPacketString );
  896. }
  897. #endif
  898. // Reset the HW if it was the currently sending Srb.
  899. // It usually means that hardware messed up so we'll schedule "play",
  900. // "slow motion" or "scan" commands if one of them was in effect, reset
  901. // hardware and cancel this packet
  902. if( pHwDevExt->CurrentlySentStream == (ZIVA_STREAM)pSrb->StreamObject->StreamNumber )
  903. {
  904. ZIVA_STATE zState;
  905. DebugPrint(( DebugLevelVerbose, "Current" ));
  906. MonoOutStr( " Current Strm# " );
  907. MonoOutInt( pSrb->StreamObject->StreamNumber );
  908. // This request is in a middle of a Bus Master transferring and most likely
  909. // that the interrupt is pending. If so we have to reset the
  910. // Bus Master device.
  911. if( pHwDevExt->bInterruptPending )
  912. {
  913. pHwDevExt->bInterruptPending = FALSE;
  914. MonoOutStr( " Cancel pending interrupt" );
  915. }
  916. // Lets do a clean start (Abort->Play) for the upcoming stream
  917. zState = ZivaHw_GetState();
  918. if( zState != ZIVA_STATE_STOP )
  919. {
  920. MonoOutStr( " Aborting" );
  921. if( !ZivaHw_Abort() )
  922. ZivaHw_Reset();
  923. pHwDevExt->bInterruptPending = FALSE;
  924. pHwDevExt->bScanCommandPending = TRUE;
  925. }
  926. // Clean the CurrentlySentStream
  927. pHwDevExt->CurrentlySentStream = ZivaNumberOfStreams;
  928. }
  929. if(bCancel)
  930. pSrb->Status = STATUS_CANCELLED;
  931. // It is necessary to call the request back correctly. Determine which type of
  932. // command it is and then find all stream commands, and do stream notifications
  933. switch( pSrb->Flags & (SRB_HW_FLAGS_DATA_TRANSFER | SRB_HW_FLAGS_STREAM_REQUEST) )
  934. {
  935. case SRB_HW_FLAGS_STREAM_REQUEST | SRB_HW_FLAGS_DATA_TRANSFER:
  936. DebugPrint(( DebugLevelVerbose," As a Data\n" ));
  937. MonoOutStr( "(Data)" );
  938. // Find the smallest and the biggest discarded order number in this packet
  939. for( ulSample = 0; ulSample < pSrb->NumberOfBuffers; ulSample++ )
  940. {
  941. pHeader = (PKSSTREAM_HEADER)pSrb->CommandData.DataBufferArray + ulSample;
  942. wMaxOrder = max( (WORD)(pHeader->TypeSpecificFlags >> 16), wMaxOrder );
  943. wMinOrder = min( (WORD)(pHeader->TypeSpecificFlags >> 16), wMinOrder );
  944. }
  945. MonoOutStr( " Min:" );
  946. MonoOutInt( wMinOrder );
  947. MonoOutStr( " Max:" );
  948. MonoOutInt( wMaxOrder );
  949. MonoOutStr( " Curr:" );
  950. MonoOutInt( pHwDevExt->wNextSrbOrderNumber );
  951. if(bCancel)
  952. {
  953. if( /*wMinOrder <= pHwDevExt->wNextSrbOrderNumber &&*/
  954. wMaxOrder >= pHwDevExt->wNextSrbOrderNumber )
  955. {
  956. pHwDevExt->wNextSrbOrderNumber = wMaxOrder + 1;
  957. MonoOutStr( "<<< Updating NextSrbOrderNumber to " );
  958. MonoOutULong( pHwDevExt->wNextSrbOrderNumber );
  959. MonoOutStr( " >>>" );
  960. }
  961. else
  962. MonoOutChar( ' ' );
  963. MonoOutStr("Cancel::ARR");
  964. AdapterReleaseRequest( pSrb );
  965. }
  966. else
  967. {
  968. if(pHwDevExt->pCurrentSubPictureSrb)
  969. {
  970. pHeader = (PKSSTREAM_HEADER)pHwDevExt->pCurrentSubPictureSrb->CommandData.DataBufferArray ;
  971. pHeader += pHwDevExt->dwCurrentSubPictureSample;
  972. wMinOrder = min( (WORD)(pHeader->TypeSpecificFlags >> 16), wMinOrder );
  973. }
  974. if(pHwDevExt->pCurrentVideoSrb)
  975. {
  976. pHeader = (PKSSTREAM_HEADER)pHwDevExt->pCurrentVideoSrb->CommandData.DataBufferArray ;
  977. pHeader += pHwDevExt->dwCurrentVideoSample;
  978. wMinOrder = min( (WORD)(pHeader->TypeSpecificFlags >> 16), wMinOrder );
  979. }
  980. if(pHwDevExt->pCurrentAudioSrb)
  981. {
  982. pHeader = (PKSSTREAM_HEADER)pHwDevExt->pCurrentAudioSrb->CommandData.DataBufferArray ;
  983. pHeader += pHwDevExt->dwCurrentAudioSample;
  984. wMinOrder = min( (WORD)(pHeader->TypeSpecificFlags >> 16), wMinOrder );
  985. }
  986. pHwDevExt->wNextSrbOrderNumber = wMinOrder ;
  987. AdapterSendData(pHwDevExt);
  988. }
  989. MonoOutStr( "(Current->" );
  990. if( pHwDevExt->pCurrentVideoSrb )
  991. MonoOutStr( "V" );
  992. if( pHwDevExt->pCurrentAudioSrb )
  993. MonoOutStr( "A" );
  994. if( pHwDevExt->pCurrentSubPictureSrb )
  995. MonoOutStr( "S" );
  996. if( !pHwDevExt->pCurrentVideoSrb && !pHwDevExt->pCurrentAudioSrb && !pHwDevExt->pCurrentSubPictureSrb )
  997. MonoOutStr( "Queue empty" );
  998. MonoOutStr( ")" );
  999. break;
  1000. case SRB_HW_FLAGS_STREAM_REQUEST:
  1001. DebugPrint(( DebugLevelVerbose," As a Control\n" ));
  1002. MonoOutStr( "(Control)" );
  1003. AdapterReleaseRequest( pSrb );
  1004. break;
  1005. default:
  1006. // this must be a device request. Use device notifications
  1007. DebugPrint(( DebugLevelVerbose," As a Device\n" ));
  1008. MonoOutStr( "(Device)" );
  1009. AdapterReleaseRequest( pSrb );
  1010. }
  1011. MonoOutSetUnderscore( FALSE );
  1012. DebugPrint(( DebugLevelVerbose, "ZiVA: End Adapter%sPacket\n", pszFuncString ));
  1013. }
  1014. /*** AdapterCancelPacket()
  1015. **
  1016. ** Request to cancel a packet that is currently in process in the minidriver
  1017. **
  1018. ** Arguments:
  1019. **
  1020. ** pSrb - pointer to request packet to cancel
  1021. **
  1022. ** Returns:
  1023. **
  1024. ** Side Effects: none
  1025. */
  1026. VOID STREAMAPI AdapterCancelPacket( PHW_STREAM_REQUEST_BLOCK pSrb )
  1027. {
  1028. CancelPacket( pSrb, TRUE );
  1029. }
  1030. /*
  1031. ** AdapterTimeoutPacket()
  1032. **
  1033. ** This routine is called when a packet has been in the minidriver for
  1034. ** too long. The adapter must decide what to do with the packet
  1035. **
  1036. ** Arguments:
  1037. **
  1038. ** pSrb - pointer to the request packet that timed out
  1039. **
  1040. ** Returns:
  1041. **
  1042. ** Side Effects: none
  1043. */
  1044. VOID STREAMAPI AdapterTimeoutPacket( PHW_STREAM_REQUEST_BLOCK pSrb )
  1045. {
  1046. PHW_DEVICE_EXTENSION pHwDevExt = (PHW_DEVICE_EXTENSION)pSrb->HwDeviceExtension;
  1047. // If this is a data request, and the device is paused (we probably have run out of
  1048. // data buffer) or busy with overlay calibration we need more time, so just reset the
  1049. // timer, and let the packet continue
  1050. if( ZivaHw_GetState() == ZIVA_STATE_PAUSE
  1051. #ifdef ENCORE
  1052. || pHwDevExt->nVGAMode != AP_KNOWNMODE
  1053. #endif
  1054. )
  1055. {
  1056. DebugPrint(( DebugLevelVerbose, "Timeout: Stream is PAUSED\n" ));
  1057. // reset the timeout counter, and continue
  1058. pSrb->TimeoutCounter = pSrb->TimeoutOriginal;
  1059. return;
  1060. }
  1061. CleanCCQueue(pHwDevExt);
  1062. CancelPacket( pSrb, FALSE );
  1063. }
  1064. void FinishCurrentPacketAndSendNextOne( PHW_DEVICE_EXTENSION pHwDevExt )
  1065. {
  1066. DWORD dwSample;
  1067. PHW_STREAM_REQUEST_BLOCK pSrb = NULL;
  1068. DWORD dwCurBuf=0;
  1069. switch( pHwDevExt->CurrentlySentStream )
  1070. {
  1071. case ZivaVideo:
  1072. pSrb = pHwDevExt->pCurrentVideoSrb;
  1073. ++pHwDevExt->dwCurrentVideoPage;
  1074. if(pHwDevExt->dwVideoDataUsed <= 0)
  1075. {
  1076. pHwDevExt->wNextSrbOrderNumber++;
  1077. ++pHwDevExt->dwCurrentVideoSample;
  1078. dwCurBuf = pHwDevExt->dwCurrentVideoSample;
  1079. }
  1080. dwSample = pHwDevExt->dwCurrentVideoPage;
  1081. break;
  1082. case ZivaAudio:
  1083. pSrb = pHwDevExt->pCurrentAudioSrb;
  1084. ++pHwDevExt->dwCurrentAudioPage;
  1085. if(pHwDevExt->dwAudioDataUsed <= 0)
  1086. {
  1087. pHwDevExt->wNextSrbOrderNumber++;
  1088. ++pHwDevExt->dwCurrentAudioSample;
  1089. dwCurBuf = pHwDevExt->dwCurrentAudioSample;
  1090. }
  1091. dwSample = pHwDevExt->dwCurrentAudioPage;
  1092. break;
  1093. case ZivaSubpicture:
  1094. pSrb = pHwDevExt->pCurrentSubPictureSrb;
  1095. ++pHwDevExt->dwCurrentSubPicturePage;
  1096. if(pHwDevExt->dwSubPictureDataUsed <= 0)
  1097. {
  1098. pHwDevExt->wNextSrbOrderNumber++;
  1099. ++pHwDevExt->dwCurrentSubPictureSample;
  1100. dwCurBuf = pHwDevExt->dwCurrentSubPictureSample;
  1101. }
  1102. dwSample = pHwDevExt->dwCurrentSubPicturePage;
  1103. break;
  1104. }
  1105. if( pSrb )
  1106. {
  1107. if( ( dwSample >= pSrb->NumberOfPhysicalPages) || (dwCurBuf >= pSrb->NumberOfBuffers))
  1108. {
  1109. if( dwSample > pSrb->NumberOfPhysicalPages)
  1110. {
  1111. MonoOutSetBlink( TRUE );
  1112. MonoOutStr( "<<< Current sample number is higher than the number of buffers >>>" );
  1113. MonoOutSetBlink( FALSE );
  1114. }
  1115. //tmp MonoOutStr("RSRB");
  1116. AdapterReleaseCurrentSrb( pSrb );
  1117. }
  1118. // Clean the CurrentlySentStream
  1119. pHwDevExt->CurrentlySentStream = ZivaNumberOfStreams;
  1120. // Send next chunk of data
  1121. AdapterSendData( pHwDevExt );
  1122. }
  1123. }
  1124. UINT AdapterPrepareDataForSending( PHW_DEVICE_EXTENSION pHwDevExt,
  1125. PHW_STREAM_REQUEST_BLOCK pCurrentStreamSrb,
  1126. DWORD dwCurrentStreamSample,
  1127. PHW_STREAM_REQUEST_BLOCK* ppSrb, DWORD* pdwSample,
  1128. DWORD* dwCurrentSample,DWORD dwCurrentPage,
  1129. LONG* pdwDataUsed)
  1130. {
  1131. PKSSTREAM_HEADER pHeader;
  1132. static DWORD wPrevOrderNumber=0xfff;
  1133. // Check if this guy has any data to send
  1134. pHeader = (PKSSTREAM_HEADER)pCurrentStreamSrb->CommandData.DataBufferArray+dwCurrentStreamSample;
  1135. if(pHeader == NULL)
  1136. {
  1137. MonoOutStr("PHeader NULL");
  1138. MoveToNextSample( pCurrentStreamSrb );
  1139. pHwDevExt->wNextSrbOrderNumber++;
  1140. // Sorry, but we have to start all over again...
  1141. return TRUE;
  1142. }
  1143. if( pHeader->OptionsFlags & KSSTREAM_HEADER_OPTIONSF_TYPECHANGED )
  1144. {
  1145. MonoOutStr( "!!!! Skipping TYPECHANGED buffer !!!!" );
  1146. MoveToNextSample( pCurrentStreamSrb );
  1147. // Sorry, but we have to start all over again...
  1148. return TRUE;
  1149. }
  1150. if( (WORD)(pHeader->TypeSpecificFlags >> 16) == pHwDevExt->wNextSrbOrderNumber )
  1151. {
  1152. if( !pHeader->DataUsed )
  1153. {
  1154. MonoOutStr( "!!!! DataUsed is 0 !!!!" );
  1155. MoveToNextSample( pCurrentStreamSrb );
  1156. pHwDevExt->wNextSrbOrderNumber++;
  1157. // Sorry, but we have to start all over again...
  1158. return TRUE;
  1159. }
  1160. // Found our SRB
  1161. if((*pdwDataUsed <= 0))
  1162. {
  1163. *pdwDataUsed += pHeader->DataUsed;
  1164. if(*pdwDataUsed == 0)
  1165. {
  1166. MoveToNextSample(pCurrentStreamSrb);
  1167. pHwDevExt->wNextSrbOrderNumber++;
  1168. return TRUE;
  1169. }
  1170. }
  1171. if(pHeader->PresentationTime.Time)
  1172. pHwDevExt->VideoSTC = pHeader->PresentationTime.Time;
  1173. *ppSrb = pCurrentStreamSrb;
  1174. *pdwSample = dwCurrentPage;
  1175. *dwCurrentSample = dwCurrentStreamSample;
  1176. }
  1177. return FALSE;
  1178. }
  1179. UpdateOrdinalNumber(IN PHW_DEVICE_EXTENSION pHwDevExt)
  1180. {
  1181. if(( (pHwDevExt->pCurrentVideoSrb) || (pHwDevExt->pCurrentAudioSrb) || (pHwDevExt->pCurrentSubPictureSrb)) )
  1182. {
  1183. PKSSTREAM_HEADER pHeader;
  1184. WORD wMinOrder = 0xFFFF;
  1185. if( pHwDevExt->pCurrentVideoSrb )
  1186. {
  1187. pHeader = (PKSSTREAM_HEADER)(pHwDevExt->pCurrentVideoSrb->CommandData.DataBufferArray)+
  1188. pHwDevExt->dwCurrentVideoSample;
  1189. wMinOrder = (WORD)(pHeader->TypeSpecificFlags >> 16);
  1190. }
  1191. if( pHwDevExt->pCurrentAudioSrb )
  1192. {
  1193. pHeader = (PKSSTREAM_HEADER)(pHwDevExt->pCurrentAudioSrb->CommandData.DataBufferArray)+
  1194. pHwDevExt->dwCurrentAudioSample;
  1195. wMinOrder = min( (WORD)(pHeader->TypeSpecificFlags >> 16), wMinOrder );
  1196. }
  1197. if( pHwDevExt->pCurrentSubPictureSrb )
  1198. {
  1199. pHeader = (PKSSTREAM_HEADER)(pHwDevExt->pCurrentSubPictureSrb->CommandData.DataBufferArray)+
  1200. pHwDevExt->dwCurrentSubPictureSample;
  1201. wMinOrder = min( (WORD)(pHeader->TypeSpecificFlags >> 16), wMinOrder );
  1202. }
  1203. ASSERT( wMinOrder != 0xFFFF );
  1204. pHwDevExt->wNextSrbOrderNumber = wMinOrder;
  1205. MonoOutSetBlink( TRUE );
  1206. MonoOutStr( "<<< Self recovering NextSrbOrderNumber to " );
  1207. MonoOutULong( pHwDevExt->wNextSrbOrderNumber );
  1208. MonoOutStr( " >>>" );
  1209. MonoOutSetBlink( FALSE );
  1210. }
  1211. }
  1212. BOOLEAN CanUpdateOrdinalNumber(IN PHW_DEVICE_EXTENSION pHwDevExt)
  1213. {
  1214. BOOLEAN bReturn = FALSE;
  1215. if(pHwDevExt->bScanCommandPending)
  1216. {
  1217. if((pHwDevExt->NewRate == 10000) || (pHwDevExt->bRateChangeFromSlowMotion) )
  1218. {
  1219. pHwDevExt->bRateChangeFromSlowMotion = FALSE;
  1220. if(pHwDevExt->bDiscontinued)
  1221. {
  1222. pHwDevExt->bDiscontinued = FALSE;
  1223. UpdateOrdinalNumber(pHwDevExt);
  1224. bReturn = TRUE;
  1225. }
  1226. }
  1227. }
  1228. return bReturn;
  1229. }
  1230. void IssuePendingCommands(PHW_DEVICE_EXTENSION pHwDevExt)
  1231. {
  1232. pHwDevExt->bEndFlush = FALSE;
  1233. pHwDevExt->bTimerScheduled = FALSE;
  1234. DisableThresholdInt();
  1235. if( pHwDevExt->bPlayCommandPending == TRUE )
  1236. { // If "Play" command is pending - it's time to fire it
  1237. pHwDevExt->bPlayCommandPending = FALSE;
  1238. ZivaHw_FlushBuffers( );
  1239. pHwDevExt->bInterruptPending = FALSE;
  1240. if( !ZivaHw_Play() )
  1241. DebugPrint(( DebugLevelInfo, "ZiVA: !!!!!!!!! Play command did not succeed !!!!!!!!!\n" ));
  1242. }
  1243. if( pHwDevExt->bScanCommandPending == TRUE )
  1244. {
  1245. pHwDevExt->bScanCommandPending = FALSE;
  1246. if(pHwDevExt->NewRate == 10000)
  1247. {
  1248. ZivaHw_Abort();//sri
  1249. pHwDevExt->bInterruptPending = FALSE;
  1250. ZivaHw_Play();
  1251. }
  1252. else if(pHwDevExt->NewRate < 10000)
  1253. {
  1254. ZivaHw_Abort();//sri
  1255. pHwDevExt->bInterruptPending = FALSE;
  1256. ZivaHw_Scan();
  1257. }
  1258. else
  1259. {
  1260. ZivaHw_Abort();//sri
  1261. pHwDevExt->bInterruptPending = FALSE;
  1262. ZivaHw_SlowMotion( 8 );
  1263. }
  1264. }
  1265. }
  1266. void CallAdapterSendAtALaterTime( PHW_DEVICE_EXTENSION pHwDevExt )
  1267. {
  1268. // UpdateOrdinalNumber(pHwDevExt);
  1269. MonoOutStr("CallAdapterSendAtALaterTime");
  1270. if(pHwDevExt->bTimerScheduled)
  1271. {
  1272. pHwDevExt->bTimerScheduled = FALSE;
  1273. MonoOutStr("CallAdapterSend");
  1274. UpdateOrdinalNumber(pHwDevExt);
  1275. AdapterSendData(pHwDevExt);
  1276. }
  1277. }
  1278. BOOL UpdateOrdNum_MinOfAllThree(PHW_DEVICE_EXTENSION pHwDevExt)
  1279. {
  1280. if( ((!pHwDevExt->bVideoStreamOpened || pHwDevExt->pCurrentVideoSrb) &&
  1281. (!pHwDevExt->bAudioStreamOpened || pHwDevExt->pCurrentAudioSrb) &&
  1282. (!pHwDevExt->bSubPictureStreamOpened || pHwDevExt->pCurrentSubPictureSrb))
  1283. )
  1284. {
  1285. PKSSTREAM_HEADER pHeader;
  1286. WORD wMinOrder = 0xFFFF;
  1287. if( pHwDevExt->pCurrentVideoSrb )
  1288. {
  1289. pHeader = (PKSSTREAM_HEADER)(pHwDevExt->pCurrentVideoSrb->CommandData.DataBufferArray)+
  1290. pHwDevExt->dwCurrentVideoSample;
  1291. wMinOrder = (WORD)(pHeader->TypeSpecificFlags >> 16);
  1292. }
  1293. if( pHwDevExt->pCurrentAudioSrb )
  1294. {
  1295. pHeader = (PKSSTREAM_HEADER)(pHwDevExt->pCurrentAudioSrb->CommandData.DataBufferArray)+
  1296. pHwDevExt->dwCurrentAudioSample;
  1297. wMinOrder = min( (WORD)(pHeader->TypeSpecificFlags >> 16), wMinOrder );
  1298. }
  1299. if( pHwDevExt->pCurrentSubPictureSrb )
  1300. {
  1301. pHeader = (PKSSTREAM_HEADER)(pHwDevExt->pCurrentSubPictureSrb->CommandData.DataBufferArray)+
  1302. pHwDevExt->dwCurrentSubPictureSample;
  1303. wMinOrder = min( (WORD)(pHeader->TypeSpecificFlags >> 16), wMinOrder );
  1304. }
  1305. ASSERT( wMinOrder != 0xFFFF );
  1306. pHwDevExt->wNextSrbOrderNumber = wMinOrder;
  1307. MonoOutSetBlink( TRUE );
  1308. MonoOutStr( "<<< Self recovering NextSrbOrderNumber to " );
  1309. MonoOutULong( pHwDevExt->wNextSrbOrderNumber );
  1310. MonoOutStr( " >>>" );
  1311. MonoOutSetBlink( FALSE );
  1312. return TRUE;
  1313. }
  1314. else
  1315. return FALSE;
  1316. }
  1317. /*BOOL StartUpDiscontinue(PHW_DEVICE_EXTENSION pHwDevExt)
  1318. {
  1319. if(pHwDevExt->dwFirstVideoOrdNum != -1)
  1320. wMinOrder = min( (WORD)pHwDevExt->dwFirstVideoOrdNum, wMinOrder );
  1321. if(pHwDevExt->dwFirstAudioOrdNum != -1)
  1322. wMinOrder = min( (WORD)pHwDevExt->dwFirstAudioOrdNum, wMinOrder );
  1323. if(pHwDevExt->dwFirstSbpOrdNum != -1)
  1324. wMinOrder = min( (WORD)pHwDevExt->dwFirstSbpOrdNum, wMinOrder );
  1325. if((wMinOrder != -1) && (wMinOrder > pHwDevExt->wNextSrbOrderNumber) )
  1326. {
  1327. pHwDevExt->wNextSrbOrderNumber = wMinOrder ;
  1328. return TRUE;
  1329. }
  1330. else
  1331. return FALSE;
  1332. }*/
  1333. /*
  1334. ** AdapterSendData()
  1335. **
  1336. ** This routine is being scheduled by the either one of the input
  1337. ** streams when it receives data or by the ISR when sending of the
  1338. ** previos block is completed and there still Srbs pending.
  1339. **
  1340. ** Arguments:
  1341. **
  1342. ** pHwDevExt - the hardware device extension.
  1343. **
  1344. ** Returns: none
  1345. **
  1346. ** Side Effects: none
  1347. */
  1348. VOID STREAMAPI AdapterSendData( IN PHW_DEVICE_EXTENSION pHwDevExt )
  1349. {
  1350. PHW_STREAM_REQUEST_BLOCK pSrb;
  1351. DWORD dwPageToSend;
  1352. DWORD dwCurrentSample;
  1353. #ifndef DECODER_DVDPC
  1354. if(pHwDevExt->bAbortAtPause)
  1355. return;
  1356. #endif
  1357. // Check if HW is not busy and there is something to send
  1358. if( pHwDevExt->bInterruptPending ||
  1359. (pHwDevExt->pCurrentVideoSrb == NULL &&
  1360. pHwDevExt->pCurrentAudioSrb == NULL && pHwDevExt->pCurrentSubPictureSrb == NULL) )
  1361. return;
  1362. // Find the next Sample by the order number
  1363. for( ;; )
  1364. {
  1365. pSrb = NULL;
  1366. if( pHwDevExt->pCurrentVideoSrb &&
  1367. AdapterPrepareDataForSending( pHwDevExt, pHwDevExt->pCurrentVideoSrb,
  1368. pHwDevExt->dwCurrentVideoSample, &pSrb, &dwPageToSend,&dwCurrentSample,
  1369. pHwDevExt->dwCurrentVideoPage,&pHwDevExt->dwVideoDataUsed) )
  1370. continue;
  1371. if( pHwDevExt->pCurrentAudioSrb && pSrb == NULL &&
  1372. AdapterPrepareDataForSending( pHwDevExt, pHwDevExt->pCurrentAudioSrb,
  1373. pHwDevExt->dwCurrentAudioSample, &pSrb, &dwPageToSend,&dwCurrentSample,
  1374. pHwDevExt->dwCurrentAudioPage,&pHwDevExt->dwAudioDataUsed) )
  1375. continue;
  1376. if( pHwDevExt->pCurrentSubPictureSrb && pSrb == NULL &&
  1377. AdapterPrepareDataForSending( pHwDevExt, pHwDevExt->pCurrentSubPictureSrb,
  1378. pHwDevExt->dwCurrentSubPictureSample, &pSrb, &dwPageToSend,&dwCurrentSample,
  1379. pHwDevExt->dwCurrentSubPicturePage,&pHwDevExt->dwSubPictureDataUsed) )
  1380. continue;
  1381. if( pSrb != NULL ) // Found the right SRB
  1382. {
  1383. pHwDevExt->CurrentlySentStream = pSrb->StreamObject->StreamNumber;
  1384. break;
  1385. }
  1386. if(CanUpdateOrdinalNumber(pHwDevExt))
  1387. {
  1388. UpdateOrdinalNumber(pHwDevExt);
  1389. continue;
  1390. }
  1391. if(pHwDevExt->bEndFlush)
  1392. {
  1393. pHwDevExt->bEndFlush = FALSE;
  1394. MonoOutStr("Timer Scheduled for AdapterSendData");
  1395. StreamClassScheduleTimer( NULL, pHwDevExt,
  1396. 400000,
  1397. (PHW_TIMER_ROUTINE)CallAdapterSendAtALaterTime,
  1398. pHwDevExt );
  1399. pHwDevExt->bTimerScheduled = TRUE;
  1400. }
  1401. if(UpdateOrdNum_MinOfAllThree(pHwDevExt))
  1402. continue;
  1403. // if(StartUpDiscontinue(pHwDevExt))
  1404. // continue;
  1405. MonoOutStr( "!! CD !!" );
  1406. //MonoOutStr( "!!!!!!!!!!!!!!! COUNTER DISCONTINUITY !!!!!!!!!!!!!!!!!!!" );
  1407. // Clean the CurrentlySentStream
  1408. pHwDevExt->CurrentlySentStream = ZivaNumberOfStreams;
  1409. return;
  1410. }
  1411. XferData(pSrb,pHwDevExt,dwPageToSend,dwCurrentSample);
  1412. }
  1413. /*
  1414. ** AdapterReleaseCurrentSrb()
  1415. **
  1416. ** This routine is called by the AdapterSendData() and HWInterrupt() functions
  1417. ** when there is no more data in the Currently processing Srb.
  1418. **
  1419. ** Arguments:
  1420. **
  1421. ** pSrb - the request block to release.
  1422. **
  1423. ** Returns:
  1424. **
  1425. ** Side Effects: none
  1426. */
  1427. VOID STREAMAPI AdapterReleaseCurrentSrb( PHW_STREAM_REQUEST_BLOCK pSrb )
  1428. {
  1429. PHW_DEVICE_EXTENSION pHwDevExt = (PHW_DEVICE_EXTENSION)pSrb->HwDeviceExtension;
  1430. PKSSTREAM_HEADER pHeader;
  1431. pSrb->Status = STATUS_SUCCESS;
  1432. // Clear the CurrentSrb and Sample count for this Srb
  1433. switch( pSrb->StreamObject->StreamNumber )
  1434. {
  1435. case ZivaVideo:
  1436. pHwDevExt->pCurrentVideoSrb = NULL;
  1437. pHwDevExt->dwCurrentVideoSample = 0;
  1438. pHwDevExt->dwCurrentVideoPage = 0;
  1439. pHwDevExt->dwVideoDataUsed=0;
  1440. break;
  1441. case ZivaAudio:
  1442. pHwDevExt->pCurrentAudioSrb = NULL;
  1443. pHwDevExt->dwCurrentAudioSample = 0;
  1444. pHwDevExt->dwCurrentAudioPage = 0;
  1445. pHwDevExt->dwAudioDataUsed=0;
  1446. break;
  1447. case ZivaSubpicture:
  1448. pHwDevExt->pCurrentSubPictureSrb = NULL;
  1449. pHwDevExt->dwCurrentSubPictureSample = 0;
  1450. pHwDevExt->dwCurrentSubPicturePage = 0;
  1451. pHwDevExt->dwSubPictureDataUsed=0;
  1452. break;
  1453. default:
  1454. MonoOutStr( "!!!!!!!! Releasing Srb for UNKNOWN stream !!!!!!!!" );
  1455. }
  1456. // Check if this is the last Srb for current title
  1457. pHeader = (PKSSTREAM_HEADER)pSrb->CommandData.DataBufferArray+pSrb->NumberOfBuffers-1;
  1458. if( pHeader->TypeSpecificFlags & KS_AM_UseNewCSSKey )
  1459. {
  1460. switch( pSrb->StreamObject->StreamNumber )
  1461. {
  1462. case ZivaVideo:
  1463. MonoOutStr( "!!! Last video Srb !!!" );
  1464. pHwDevExt->bVideoCanAuthenticate = TRUE;
  1465. break;
  1466. case ZivaAudio:
  1467. MonoOutStr( "!!! Last audio Srb !!!" );
  1468. pHwDevExt->bAudioCanAuthenticate = TRUE;
  1469. break;
  1470. case ZivaSubpicture:
  1471. MonoOutStr( "!!! Last SP Srb !!!" );
  1472. pHwDevExt->bSubPictureCanAuthenticate = TRUE;
  1473. break;
  1474. default:
  1475. MonoOutStr( "!!!!!!!! Last Srb for UNKNOWN stream !!!!!!!!" );
  1476. }
  1477. }
  1478. AdapterReleaseRequest( pSrb );
  1479. }
  1480. /*
  1481. ** AdapterReleaseRequest()
  1482. **
  1483. ** This routine is called when any of the open pins (streams) wants
  1484. ** to dispose an used request block.
  1485. **
  1486. ** Arguments:
  1487. **
  1488. ** pSrb - the request block to release.
  1489. **
  1490. ** Returns:
  1491. **
  1492. ** Side Effects: none
  1493. */
  1494. VOID STREAMAPI AdapterReleaseRequest( PHW_STREAM_REQUEST_BLOCK pSrb )
  1495. {
  1496. if( pSrb->Status == STATUS_PENDING )
  1497. MonoOutStr( " !!! Srb is PENDING - not releasing !!! " );
  1498. else
  1499. {
  1500. if( pSrb->Flags & SRB_HW_FLAGS_STREAM_REQUEST )
  1501. {
  1502. if( pSrb->Flags & SRB_HW_FLAGS_DATA_TRANSFER )
  1503. {
  1504. StreamClassStreamNotification( ReadyForNextStreamDataRequest, pSrb->StreamObject );
  1505. // MonoOutStr(" Release D");
  1506. }
  1507. else
  1508. {
  1509. StreamClassStreamNotification( ReadyForNextStreamControlRequest, pSrb->StreamObject );
  1510. // MonoOutStr(" Release C");
  1511. }
  1512. StreamClassStreamNotification( StreamRequestComplete, pSrb->StreamObject, pSrb );
  1513. }
  1514. else
  1515. {
  1516. StreamClassDeviceNotification( ReadyForNextDeviceRequest, pSrb->HwDeviceExtension );
  1517. StreamClassDeviceNotification( DeviceRequestComplete, pSrb->HwDeviceExtension, pSrb );
  1518. }
  1519. }
  1520. }
  1521. /*
  1522. ** AdapterCanAuthenticateNow()
  1523. **
  1524. ** This routine is called when Authentication request was made by the
  1525. ** Class Driver.
  1526. **
  1527. ** Arguments:
  1528. **
  1529. ** pHwDevExt - hardware device extension.
  1530. **
  1531. ** Returns:
  1532. **
  1533. ** TRUE if Authentication is allowed at this moment, FALSE otherwise.
  1534. **
  1535. ** Side Effects: none
  1536. */
  1537. BOOL STREAMAPI AdapterCanAuthenticateNow( IN PHW_DEVICE_EXTENSION pHwDevExt )
  1538. {
  1539. if( (pHwDevExt->bVideoStreamOpened == FALSE ||
  1540. (pHwDevExt->bVideoStreamOpened == TRUE && pHwDevExt->bVideoCanAuthenticate == TRUE)) &&
  1541. (pHwDevExt->bAudioStreamOpened == FALSE ||
  1542. (pHwDevExt->bAudioStreamOpened == TRUE && pHwDevExt->bAudioCanAuthenticate == TRUE)) &&
  1543. (pHwDevExt->bSubPictureStreamOpened == FALSE ||
  1544. (pHwDevExt->bSubPictureStreamOpened == TRUE && pHwDevExt->bSubPictureCanAuthenticate == TRUE)) )
  1545. return TRUE;
  1546. return FALSE;
  1547. }
  1548. /*
  1549. ** AdapterClearAuthenticationStatus()
  1550. **
  1551. ** This routine is called when Authentication and key exchange was
  1552. ** completed.
  1553. **
  1554. ** Arguments:
  1555. **
  1556. ** pHwDevExt - hardware device extension.
  1557. **
  1558. ** Returns:
  1559. **
  1560. ** Side Effects: none
  1561. */
  1562. VOID STREAMAPI AdapterClearAuthenticationStatus( IN PHW_DEVICE_EXTENSION pHwDevExt )
  1563. {
  1564. pHwDevExt->bVideoCanAuthenticate = FALSE;
  1565. pHwDevExt->bAudioCanAuthenticate = FALSE;
  1566. pHwDevExt->bSubPictureCanAuthenticate = FALSE;
  1567. }
  1568. /*
  1569. ** AdapterSetState()
  1570. **
  1571. ** Sets the current state
  1572. **
  1573. ** Arguments:
  1574. **
  1575. ** pSrb - pointer to the stream request block for properties
  1576. **
  1577. ** Returns:
  1578. **
  1579. ** Side Effects: none
  1580. */
  1581. BOOL AdapterSetState( PHW_STREAM_REQUEST_BLOCK pSrb )
  1582. {
  1583. PHW_DEVICE_EXTENSION pHwDevExt = (PHW_DEVICE_EXTENSION)pSrb->HwDeviceExtension;
  1584. PHW_STREAM_EXTENSION pStreamExt = (PHW_STREAM_EXTENSION)pSrb->StreamObject->HwStreamExtension;
  1585. DebugPrint(( DebugLevelVerbose, "ZiVA: AdapterSetState() -> " ));
  1586. pSrb->Status = STATUS_SUCCESS;
  1587. // Execute appropriate command only when it comes for every stream
  1588. switch( pSrb->CommandData.StreamState )
  1589. {
  1590. case KSSTATE_STOP:
  1591. pStreamExt->ksState = pSrb->CommandData.StreamState;
  1592. #ifdef ENCORE
  1593. if( pSrb->StreamObject->StreamNumber == ZivaAnalog && pHwDevExt->nAnalogStreamOpened > 1 )
  1594. pHwDevExt->nStopCount -= pHwDevExt->nAnalogStreamOpened-1;
  1595. #endif
  1596. if( --pHwDevExt->nStopCount == 0 )
  1597. {
  1598. // ZwClose(Handle);
  1599. pHwDevExt->nStopCount = pHwDevExt->iTotalOpenedStreams;
  1600. DebugPrint(( DebugLevelVerbose, "Stop" ));
  1601. if( !ZivaHw_Abort() )
  1602. pSrb->Status = STATUS_IO_DEVICE_ERROR;
  1603. else
  1604. pHwDevExt->bInterruptPending = FALSE;
  1605. AdapterInitLocals(pHwDevExt);
  1606. }
  1607. break;
  1608. case KSSTATE_PAUSE:
  1609. pStreamExt->ksState = pSrb->CommandData.StreamState;
  1610. pStreamExt->bCanBeRun = TRUE;
  1611. if( (ZivaHw_GetState( ) == ZIVA_STATE_SCAN) || (ZivaHw_GetState( ) ==ZIVA_STATE_SLOWMOTION) )//sri
  1612. pHwDevExt->bAbortAtPause = TRUE;
  1613. #ifdef ENCORE
  1614. if( pSrb->StreamObject->StreamNumber == ZivaAnalog && pHwDevExt->nAnalogStreamOpened > 1 )
  1615. pHwDevExt->nPauseCount -= pHwDevExt->nAnalogStreamOpened-1;
  1616. #endif
  1617. if( --pHwDevExt->nPauseCount == 0 )
  1618. {
  1619. pHwDevExt->nPauseCount = pHwDevExt->iTotalOpenedStreams;
  1620. DebugPrint(( DebugLevelVerbose, "Pause" ));
  1621. if( !ZivaHw_Pause() )
  1622. {
  1623. MonoOutStr("Pause Failed");
  1624. pSrb->Status = STATUS_IO_DEVICE_ERROR;
  1625. }
  1626. }
  1627. break;
  1628. case KSSTATE_RUN:
  1629. pStreamExt->ksState = pSrb->CommandData.StreamState;
  1630. #ifdef ENCORE
  1631. if( pSrb->StreamObject->StreamNumber == ZivaAnalog && pHwDevExt->nAnalogStreamOpened > 1 )
  1632. pHwDevExt->nPlayCount -= pHwDevExt->nAnalogStreamOpened-1;
  1633. #endif
  1634. if( --pHwDevExt->nPlayCount == 0 )
  1635. {
  1636. pHwDevExt->nPlayCount = pHwDevExt->iTotalOpenedStreams;
  1637. DebugPrint(( DebugLevelVerbose, "Run" ));
  1638. // We could be resuming playback here after Pause mode
  1639. if(pHwDevExt->bAbortAtPause)
  1640. {
  1641. pHwDevExt->bAbortAtPause = FALSE;
  1642. ZivaHw_Abort();
  1643. #ifdef DECODER_DVDPC
  1644. if( !ZivaHw_Play() ) // Just run the hardware
  1645. pSrb->Status = STATUS_IO_DEVICE_ERROR;
  1646. // pHwDevExt->bPlayCommandPending = TRUE;
  1647. // AdapterSendData(pHwDevExt);
  1648. #endif
  1649. #ifndef DECODER_DVDPC
  1650. pHwDevExt->bInterruptPending = FALSE;
  1651. pHwDevExt->bPlayCommandPending = TRUE;
  1652. FinishCurrentPacketAndSendNextOne( pHwDevExt );
  1653. AdapterSendData(pHwDevExt);
  1654. #endif
  1655. }
  1656. else
  1657. {
  1658. if( pHwDevExt->bInterruptPending )
  1659. {
  1660. if( !ZivaHw_Play() ) // Just run the hardware
  1661. pSrb->Status = STATUS_IO_DEVICE_ERROR;
  1662. }
  1663. else
  1664. {
  1665. // Since Authentication and Key Exchange comes in between
  1666. // "Run" command and actual data sending and ZiVA Microcode
  1667. // cannot sustain it - postpone issuing Play command to ZiVA
  1668. // until first packet of the data arrives.
  1669. pHwDevExt->bPlayCommandPending = TRUE;
  1670. // Kick the Adapter to start transferring data
  1671. AdapterSendData( pHwDevExt );
  1672. }
  1673. }
  1674. EnableVideo(pSrb);
  1675. }
  1676. break;
  1677. }
  1678. DebugPrint(( DebugLevelVerbose, "\nZiVA: End AdapterSetState()\n" ));
  1679. return TRUE;
  1680. }
  1681. /*
  1682. ** AdapterReleaseControlRequest()
  1683. **
  1684. ** This routine is called when any of the open pins (streams) wants
  1685. ** to dispose an used control request block.
  1686. **
  1687. ** Arguments:
  1688. **
  1689. ** pSrb - the request block to release.
  1690. **
  1691. ** Returns:
  1692. **
  1693. ** Side Effects: none
  1694. */
  1695. VOID STREAMAPI AdapterReleaseControlRequest( PHW_STREAM_REQUEST_BLOCK pSrb )
  1696. {
  1697. if ( pSrb->Status == STATUS_PENDING )
  1698. {
  1699. MonoOutStr( " !!! Srb is PENDING - not releasing !!! " );
  1700. }
  1701. else
  1702. {
  1703. StreamClassStreamNotification( ReadyForNextStreamControlRequest,
  1704. pSrb->StreamObject);
  1705. StreamClassStreamNotification( StreamRequestComplete,
  1706. pSrb->StreamObject,
  1707. pSrb);
  1708. // MonoOutStr(" Release ");
  1709. }
  1710. }
  1711. /*
  1712. ** AdapterReleaseDataRequest()
  1713. **
  1714. ** This routine is called when any of the open pins (streams) wants
  1715. ** to dispose an used data request block.
  1716. **
  1717. ** Arguments:
  1718. **
  1719. ** pSrb - the request block to release.
  1720. **
  1721. ** Returns:
  1722. **
  1723. ** Side Effects: none
  1724. */
  1725. VOID STREAMAPI AdapterReleaseDataRequest( PHW_STREAM_REQUEST_BLOCK pSrb )
  1726. {
  1727. if ( pSrb->Status == STATUS_PENDING )
  1728. {
  1729. MonoOutStr( " !!! Srb is PENDING - not releasing !!! " );
  1730. }
  1731. else
  1732. {
  1733. StreamClassStreamNotification( ReadyForNextStreamDataRequest,
  1734. pSrb->StreamObject);
  1735. StreamClassStreamNotification( StreamRequestComplete,
  1736. pSrb->StreamObject,
  1737. pSrb);
  1738. // MonoOutStr(" ReleaseData ");
  1739. }
  1740. }
  1741. /*
  1742. ** AdapterReleaseDeviceRequest()
  1743. **
  1744. ** This routine is called when any of the open pins (streams) wants
  1745. ** to dispose an used device request block.
  1746. **
  1747. ** Arguments:
  1748. **
  1749. ** pSrb - the request block to release.
  1750. **
  1751. ** Returns:
  1752. **
  1753. ** Side Effects: none
  1754. */
  1755. VOID STREAMAPI AdapterReleaseDeviceRequest( PHW_STREAM_REQUEST_BLOCK pSrb )
  1756. {
  1757. StreamClassDeviceNotification( ReadyForNextDeviceRequest,
  1758. pSrb->HwDeviceExtension);
  1759. StreamClassDeviceNotification( DeviceRequestComplete,
  1760. pSrb->HwDeviceExtension,
  1761. pSrb);
  1762. }
  1763. VOID STREAMAPI AdapterReleaseCtrlDataSrb( PHW_STREAM_REQUEST_BLOCK pSrb )
  1764. {
  1765. PHW_DEVICE_EXTENSION pHwDevExt = ((PHW_DEVICE_EXTENSION)pSrb->HwDeviceExtension);
  1766. KSSTREAM_HEADER *pHeader;
  1767. //
  1768. // Clear the CurrentSrb and Sample count for this Srb
  1769. //
  1770. pSrb->Status = STATUS_SUCCESS;
  1771. //
  1772. // Check if this is the last Srb for current title
  1773. //
  1774. pHeader = ((KSSTREAM_HEADER *)(pSrb->CommandData.DataBufferArray)) ;
  1775. if ( pHeader->TypeSpecificFlags & KS_AM_UseNewCSSKey )
  1776. {
  1777. switch ( pSrb->StreamObject->StreamNumber )
  1778. {
  1779. case ZivaVideo:
  1780. pHwDevExt->bVideoCanAuthenticate = TRUE;
  1781. break;
  1782. case ZivaAudio:
  1783. pHwDevExt->bAudioCanAuthenticate = TRUE;
  1784. break;
  1785. case ZivaSubpicture:
  1786. pHwDevExt->bSubPictureCanAuthenticate = TRUE;
  1787. break;
  1788. default:
  1789. MonoOutStr( "!!!!!!!! Last Srb for UNKNOWN stream !!!!!!!!" );
  1790. }
  1791. }
  1792. AdapterReleaseDataRequest( pSrb );
  1793. }
  1794. BOOL CheckAndReleaseIfCtrlPkt(PHW_STREAM_REQUEST_BLOCK pSrb)
  1795. {
  1796. KSSTREAM_HEADER *pHeader;
  1797. pHeader = ((PKSSTREAM_HEADER)pSrb->CommandData.DataBufferArray);
  1798. if (pHeader->TypeSpecificFlags & KS_AM_UseNewCSSKey)
  1799. {
  1800. if (pSrb->NumberOfBuffers == 0)
  1801. {
  1802. AdapterReleaseCtrlDataSrb(pSrb);
  1803. return TRUE;
  1804. }
  1805. else if (pSrb->NumberOfBuffers == 1)
  1806. {
  1807. BYTE *pData;
  1808. DWORD dwDataUsed;
  1809. pData = pHeader->Data;
  1810. dwDataUsed = pHeader->DataUsed;
  1811. if ((dwDataUsed == 0) ||
  1812. (pData && *((DWORD*)pData) != 0xBA010000))
  1813. {
  1814. AdapterReleaseCtrlDataSrb(pSrb);
  1815. return TRUE;;
  1816. }
  1817. }
  1818. }
  1819. return FALSE;
  1820. }
  1821. #if 0
  1822. static void STREAMAPI CreateFile(PHW_STREAM_REQUEST_BLOCK pSrb )
  1823. {
  1824. NTSTATUS ntStatus;
  1825. ASSERT( pSrb->Status == STATUS_PENDING );
  1826. RtlInitUnicodeString (&pathUnicodeString,wPath);
  1827. InitializeObjectAttributes(&InitializedAttributes,&pathUnicodeString,OBJ_CASE_INSENSITIVE,NULL,NULL);
  1828. // InitializedAttributes.Length = 2048;
  1829. // AllocSize.QuadPart=0xffff;
  1830. // ntStatus = ZwCreateFile(&Handle,FILE_WRITE_DATA,
  1831. // &InitializedAttributes,&IOStatusBlock,
  1832. // 0,FILE_ATTRIBUTE_NORMAL,0,FILE_SUPERSEDE,
  1833. // FILE_NO_INTERMEDIATE_BUFFERING,NULL,0);
  1834. ntStatus = ZwCreateFile( &Handle,
  1835. GENERIC_WRITE,
  1836. &InitializedAttributes,
  1837. &IOStatusBlock,
  1838. NULL, // alloc size = none
  1839. FILE_ATTRIBUTE_NORMAL,
  1840. 0,
  1841. FILE_CREATE,
  1842. FILE_WRITE_THROUGH,
  1843. NULL, // eabuffer
  1844. 0 ); // ealength
  1845. if(NT_SUCCESS(ntStatus))
  1846. MonoOutStr("File Creation success");
  1847. MonoOutULong(IOStatusBlock.Information);
  1848. if( (IOStatusBlock.Information == FILE_CREATED) || (IOStatusBlock.Information == FILE_OPENED) )
  1849. MonoOutStr("File Creation success");
  1850. else
  1851. MonoOutStr("File Creation failed");
  1852. pSrb->Status = STATUS_SUCCESS;
  1853. StreamClassCallAtNewPriority( pSrb->StreamObject, pSrb->HwDeviceExtension, LowToHigh,
  1854. (PHW_PRIORITY_ROUTINE)AdapterReleaseRequest, pSrb );
  1855. }
  1856. #endif
  1857. /*WriteFile()
  1858. {
  1859. if(STATUS_SUCCESS != ZwWriteFile(Handle,NULL,NULL,NULL,&IOStatusBlock,pdwPhysAddress ,dwCount,NULL,NULL))
  1860. MonoOutStr("WriteOperationFailed");
  1861. }*/