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.

445 lines
14 KiB

  1. /******************************************************************************
  2. *
  3. * $RCSfile: AnlgStrm.c $
  4. * $Source: u:/si/VXP/Wdm/Encore/AnlgStrm.c $
  5. * $Author: Max $
  6. * $Date: 1998/09/24 02:23:06 $
  7. * $Revision: 1.4 $
  8. *
  9. * Written by: Max Paklin
  10. * Purpose: Implementation of analog stream for WDM driver
  11. *
  12. *******************************************************************************
  13. *
  14. * Copyright 1996-98, AuraVision Corporation. All rights reserved.
  15. *
  16. * AuraVision Corporation makes no warranty of any kind, express or implied,
  17. * with regard to this software. In no event shall AuraVision Corporation
  18. * be liable for incidental or consequential damages in connection with or
  19. * arising from the furnishing, performance, or use of this software.
  20. *
  21. *******************************************************************************/
  22. #include "Headers.h"
  23. #pragma hdrstop
  24. #include "adapter.h"
  25. #include "zivawdm.h"
  26. #include "monovxd.h"
  27. #ifdef ENCORE
  28. #include "wingdi.h"
  29. #include "avwinwdm.h"
  30. #include "anlgstrm.h"
  31. #include "AvInt.h"
  32. void STREAMAPI RunAutoSetup( PHW_STREAM_REQUEST_BLOCK pSrb )
  33. {
  34. PHW_DEVICE_EXTENSION pHwDevExt = (PHW_DEVICE_EXTENSION)pSrb->HwDeviceExtension;
  35. ASSERT( pSrb->Status == STATUS_PENDING );
  36. pSrb->Status = STATUS_SUCCESS;
  37. if( pHwDevExt->nVGAMode == AP_NEWVGAAFTERFIRSTSTEP )
  38. {
  39. if( AV_DWSetColorKey( DEFCOLOR_REFERENCE1 ) )
  40. DoveGetReferenceStep1();
  41. pHwDevExt->nVGAMode = AP_NEWVGAAFTERSECONDSTEP;
  42. }
  43. else if( pHwDevExt->nVGAMode == AP_NEWVGAAFTERSECONDSTEP )
  44. {
  45. DoveGetReferenceStep2();
  46. pHwDevExt->nVGAMode = AP_NEWMODEAFTERFIRSTSTEP;
  47. }
  48. else if( pHwDevExt->nVGAMode == AP_NEWMODEAFTERFIRSTSTEP )
  49. { // If any of these functions fail we have to proceed anyway. Just to let it detect
  50. // the color key...
  51. AV_DWSetColorKey( DEFCOLOR_AUTOALIGN );
  52. DoveAutoColorKey2();
  53. DoveAutoAlign();
  54. // Typically automatic alignment is not accurate and it makes the window 2-3 points
  55. // to the right. Let's cheat and move the window 3 points to the left, it'll make the
  56. // things better in majority of the cases (could make it worse sometimes though)
  57. AV_SetParameter( AVXPOSITION, AV_GetParameter( AVXPOSITION )-3 );
  58. pHwDevExt->nVGAMode = AP_NEWMODEAFTERSECONDSTEP;
  59. }
  60. else if( pHwDevExt->nVGAMode == AP_NEWMODEAFTERSECONDSTEP )
  61. {
  62. BOOL bResult = AV_DWSetColorKey( pHwDevExt->dwColorKey );
  63. ASSERT( bResult );
  64. if( !DoveAutoColorKey2() )
  65. pSrb->Status = STATUS_IO_DEVICE_ERROR;
  66. else
  67. {
  68. if( pSrb->Flags & SRB_HW_FLAGS_STREAM_REQUEST )
  69. pSrb->Status = STATUS_NO_MORE_ENTRIES; // Win32 - ERROR_NO_MORE_ITEMS
  70. }
  71. pHwDevExt->nVGAMode = AP_KNOWNMODE;
  72. AV_SaveConfiguration();
  73. AV_UpdateVideo();
  74. }
  75. StreamClassCallAtNewPriority( pSrb->StreamObject, pSrb->HwDeviceExtension, LowToHigh,
  76. (PHW_PRIORITY_ROUTINE)AdapterReleaseRequest, pSrb );
  77. }
  78. void STREAMAPI DisplayChange( PHW_STREAM_REQUEST_BLOCK pSrb )
  79. {
  80. PHW_DEVICE_EXTENSION pHwDevExt = (PHW_DEVICE_EXTENSION)pSrb->HwDeviceExtension;
  81. KSDISPLAYCHANGE* pDisplayChange = (KSDISPLAYCHANGE*)pSrb->CommandData.PropertyInfo->PropertyInfo;
  82. ASSERT( pSrb->Status == STATUS_PENDING );
  83. pHwDevExt->nVGAMode = AV_SetNewVGAMode( pDisplayChange->DeviceID,
  84. pDisplayChange->PelsWidth,
  85. pDisplayChange->PelsHeight,
  86. pDisplayChange->BitsPerPel );
  87. if( pHwDevExt->nVGAMode != AP_KNOWNMODE ) // != TRUE
  88. pSrb->Status = STATUS_MORE_ENTRIES; // Win32 - ERROR_MORE_DATA
  89. else
  90. pSrb->Status = STATUS_SUCCESS;
  91. StreamClassCallAtNewPriority( pSrb->StreamObject, pSrb->HwDeviceExtension, LowToHigh,
  92. (PHW_PRIORITY_ROUTINE)AdapterReleaseRequest, pSrb );
  93. }
  94. static VOID GetAnalogProperty( PHW_STREAM_REQUEST_BLOCK pSrb )
  95. {
  96. PSTREAM_PROPERTY_DESCRIPTOR pSPD = pSrb->CommandData.PropertyInfo;
  97. PHW_DEVICE_EXTENSION pHwDevExt = (PHW_DEVICE_EXTENSION)pSrb->HwDeviceExtension;
  98. ULONG uId = pSPD->Property->Id;
  99. DebugPrint(( DebugLevelVerbose, "ZiVA: Begin GetAnalogProperty()\n" ));
  100. if( !IsEqualGUID( &KSPROPSETID_OverlayUpdate, &pSPD->Property->Set ) )
  101. {
  102. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  103. return;
  104. }
  105. pSrb->Status = STATUS_SUCCESS;
  106. switch( pSrb->CommandData.PropertyInfo->Property->Id )
  107. {
  108. case KSPROPERTY_OVERLAYUPDATE_INTERESTS:
  109. DebugPrint(( DebugLevelVerbose, "KSPROPERTY_OVERLAYUPDATE_INTERESTS" ));
  110. if( pSrb->CommandData.PropertyInfo->PropertyInputSize >= sizeof( ULONG ) )
  111. {
  112. *(ULONG*)(pSrb->CommandData.PropertyInfo->PropertyInfo) =
  113. KSPROPERTY_OVERLAYUPDATE_VIDEOPOSITION |
  114. KSPROPERTY_OVERLAYUPDATE_COLORKEY |
  115. KSPROPERTY_OVERLAYUPDATE_DISPLAYCHANGE |
  116. KSPROPERTY_OVERLAYUPDATE_COLORREF;
  117. pSrb->ActualBytesTransferred = sizeof( ULONG );
  118. }
  119. else
  120. pSrb->Status = STATUS_BUFFER_TOO_SMALL;
  121. break;
  122. case KSPROPERTY_OVERLAYUPDATE_COLORKEY:
  123. DebugPrint(( DebugLevelVerbose, "KSPROPERTY_OVERLAYUPDATE_COLORKEY" ));
  124. if( pSrb->CommandData.PropertyInfo->PropertyInputSize >= sizeof( COLORKEY ) )
  125. {
  126. COLORKEY* pColorKey = (COLORKEY*)pSrb->CommandData.PropertyInfo->PropertyInfo;
  127. pColorKey->KeyType = CK_RGB;
  128. pColorKey->PaletteIndex = 0;
  129. pColorKey->LowColorValue= pColorKey->HighColorValue = pHwDevExt->dwColorKey;
  130. pSrb->ActualBytesTransferred = sizeof( COLORKEY );
  131. }
  132. else
  133. pSrb->Status = STATUS_BUFFER_TOO_SMALL;
  134. break;
  135. case KSPROPERTY_OVERLAYUPDATE_COLORREF:
  136. DebugPrint(( DebugLevelVerbose, "KSPROPERTY_OVERLAYUPDATE_COLORREF" ));
  137. if( pSrb->CommandData.PropertyInfo->PropertyOutputSize >= sizeof( COLORREF ) )
  138. {
  139. COLORREF* pcrColorToReturn = (COLORREF*)pSrb->CommandData.PropertyInfo->PropertyInfo;
  140. if( pHwDevExt->nVGAMode == AP_NEWVGA )
  141. {
  142. *pcrColorToReturn = DEFCOLOR_REFERENCE1;
  143. pHwDevExt->nVGAMode = AP_NEWVGAAFTERFIRSTSTEP;
  144. }
  145. else if( pHwDevExt->nVGAMode == AP_NEWVGAAFTERFIRSTSTEP )
  146. {
  147. pSrb->Status = STATUS_PENDING;
  148. *pcrColorToReturn = DEFCOLOR_REFERENCE2;
  149. }
  150. else if( pHwDevExt->nVGAMode == AP_NEWVGAAFTERSECONDSTEP )
  151. {
  152. pSrb->Status = STATUS_PENDING;
  153. *pcrColorToReturn = DEFCOLOR_AUTOALIGN;
  154. }
  155. else if( pHwDevExt->nVGAMode == AP_NEWMODE )
  156. {
  157. pHwDevExt->nVGAMode = AP_NEWMODEAFTERFIRSTSTEP;
  158. *pcrColorToReturn = DEFCOLOR_AUTOALIGN;
  159. }
  160. else if( pHwDevExt->nVGAMode == AP_NEWMODEAFTERFIRSTSTEP )
  161. {
  162. pSrb->Status = STATUS_PENDING;
  163. *pcrColorToReturn = pHwDevExt->dwColorKey;
  164. }
  165. else
  166. {
  167. ASSERT( pHwDevExt->nVGAMode == AP_NEWMODEAFTERSECONDSTEP );
  168. pSrb->Status = STATUS_PENDING;
  169. }
  170. pSrb->ActualBytesTransferred = sizeof( COLORREF );
  171. if( pSrb->Status == STATUS_PENDING )
  172. StreamClassCallAtNewPriority( pSrb->StreamObject, pSrb->HwDeviceExtension,
  173. Low, (PHW_PRIORITY_ROUTINE)RunAutoSetup, pSrb );
  174. }
  175. else
  176. pSrb->Status = STATUS_BUFFER_TOO_SMALL;
  177. break;
  178. }
  179. DebugPrint(( DebugLevelVerbose, "ZiVA: End SetAnalogProperty()\n" ));
  180. }
  181. static VOID SetAnalogProperty( PHW_STREAM_REQUEST_BLOCK pSrb )
  182. {
  183. PSTREAM_PROPERTY_DESCRIPTOR pSPD = pSrb->CommandData.PropertyInfo;
  184. PHW_DEVICE_EXTENSION pHwDevExt = (PHW_DEVICE_EXTENSION)pSrb->HwDeviceExtension;
  185. PHW_STREAM_EXTENSION pStreamExt = (PHW_STREAM_EXTENSION)pSrb->StreamObject->HwStreamExtension;
  186. ULONG uId = pSPD->Property->Id;
  187. DebugPrint(( DebugLevelVerbose, "ZiVA: Begin SetAnalogProperty()\n" ));
  188. if( !IsEqualGUID( &KSPROPSETID_OverlayUpdate, &pSPD->Property->Set ) )
  189. {
  190. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  191. return;
  192. }
  193. pSrb->Status = STATUS_SUCCESS;
  194. switch( pSrb->CommandData.PropertyInfo->Property->Id )
  195. {
  196. case KSPROPERTY_OVERLAYUPDATE_VIDEOPOSITION:
  197. DebugPrint(( DebugLevelVerbose, "KSPROPERTY_OVERLAYUPDATE_VIDEOPOSITION" ));
  198. if( pSrb->CommandData.PropertyInfo->PropertyOutputSize >= 2*sizeof( RECT ) &&
  199. pStreamExt->bCanBeRun )
  200. {
  201. PRECT pSrcRect = (PRECT)pSrb->CommandData.PropertyInfo->PropertyInfo;
  202. PRECT pDestRect = pSrcRect+1;
  203. if( !AV_CreateWindow( pDestRect->left, pDestRect->top,
  204. pDestRect->right-pDestRect->left, pDestRect->bottom-pDestRect->top, 1 ) )
  205. {
  206. DebugPrint(( DebugLevelWarning, "AuraVision's AV_CreateWindow() failed" ));
  207. pSrb->Status = STATUS_IO_DEVICE_ERROR;
  208. }
  209. }
  210. break;
  211. case KSPROPERTY_OVERLAYUPDATE_COLORKEY:
  212. DebugPrint(( DebugLevelVerbose, "KSPROPERTY_OVERLAYUPDATE_COLORKEY" ));
  213. if( pSrb->CommandData.PropertyInfo->PropertyOutputSize >= sizeof( COLORKEY ) )
  214. {
  215. COLORKEY* pColorKey = (COLORKEY*)pSrb->CommandData.PropertyInfo->PropertyInfo;
  216. DWORD dwNewColorKey = pColorKey->HighColorValue-pColorKey->LowColorValue;
  217. dwNewColorKey = dwNewColorKey+pColorKey->LowColorValue;
  218. if( dwNewColorKey != pHwDevExt->dwColorKey )
  219. {
  220. if( !AV_DWSetColorKey( dwNewColorKey ) )
  221. pSrb->Status = STATUS_IO_DEVICE_ERROR;
  222. else
  223. pHwDevExt->dwColorKey = dwNewColorKey;
  224. }
  225. }
  226. break;
  227. case KSPROPERTY_OVERLAYUPDATE_DISPLAYCHANGE:
  228. DebugPrint(( DebugLevelVerbose, "KSPROPERTY_OVERLAYUPDATE_DISPLAYCHANGE" ));
  229. if( pSrb->CommandData.PropertyInfo->PropertyOutputSize >= sizeof( KSDISPLAYCHANGE ) )
  230. {
  231. if( pHwDevExt->nVGAMode == AP_KNOWNMODE )
  232. {
  233. pSrb->Status = STATUS_PENDING;
  234. StreamClassCallAtNewPriority( pSrb->StreamObject, pSrb->HwDeviceExtension,
  235. Low, (PHW_PRIORITY_ROUTINE)DisplayChange, pSrb );
  236. }
  237. }
  238. else
  239. pSrb->Status = STATUS_BUFFER_TOO_SMALL;
  240. break;
  241. }
  242. DebugPrint(( DebugLevelVerbose, "ZiVA: End GetAnalogProperty()\n" ));
  243. }
  244. static void STREAMAPI LoadRegistry( PHW_STREAM_REQUEST_BLOCK pSrb )
  245. {
  246. PHW_DEVICE_EXTENSION pHwDevExt = (PHW_DEVICE_EXTENSION)pSrb->HwDeviceExtension;
  247. ASSERT( pSrb->Status == STATUS_PENDING );
  248. if( !AV_Initialize() )
  249. {
  250. DebugPrint(( DebugLevelError, "\nZiVA: Can't initialize AuraVision's hardware\n" ));
  251. pSrb->Status = STATUS_IO_DEVICE_ERROR;
  252. }
  253. else
  254. {
  255. pSrb->Status = STATUS_SUCCESS;
  256. pHwDevExt->bOverlayInitialized = TRUE;
  257. }
  258. StreamClassCallAtNewPriority( pSrb->StreamObject, pHwDevExt, LowToHigh,
  259. (PHW_PRIORITY_ROUTINE)AdapterReleaseRequest, pSrb );
  260. }
  261. static void STREAMAPI SaveRegistry( PHW_STREAM_REQUEST_BLOCK pSrb )
  262. {
  263. ASSERT( pSrb->Status == STATUS_PENDING );
  264. if( !AV_SaveConfiguration()
  265. #ifdef _DEBUG
  266. || !AV_Exit()
  267. #endif
  268. )
  269. pSrb->Status = STATUS_IO_DEVICE_ERROR;
  270. else
  271. {
  272. #ifdef _DEBUG
  273. ((PHW_DEVICE_EXTENSION)pSrb->HwDeviceExtension)->bOverlayInitialized = FALSE;
  274. #endif
  275. pSrb->Status = STATUS_SUCCESS;
  276. }
  277. StreamClassCallAtNewPriority( pSrb->StreamObject, pSrb->HwDeviceExtension, LowToHigh,
  278. (PHW_PRIORITY_ROUTINE)AdapterReleaseRequest, pSrb );
  279. }
  280. static void STREAMAPI UninitializeDevice( PHW_STREAM_REQUEST_BLOCK pSrb )
  281. {
  282. ASSERT( pSrb->Status == STATUS_PENDING );
  283. if( !AV_Exit() )
  284. pSrb->Status = STATUS_ADAPTER_HARDWARE_ERROR;
  285. else
  286. pSrb->Status = STATUS_SUCCESS;
  287. StreamClassCallAtNewPriority( pSrb->StreamObject, pSrb->HwDeviceExtension, LowToHigh,
  288. (PHW_PRIORITY_ROUTINE)AdapterReleaseRequest, pSrb );
  289. }
  290. BOOL AnalogInitialize( PHW_STREAM_REQUEST_BLOCK pSrb )
  291. {
  292. PHW_DEVICE_EXTENSION pHwDevExt = (PHW_DEVICE_EXTENSION)pSrb->HwDeviceExtension;
  293. AV_SetVxpConfig( (LPVOID)pHwDevExt->dwDVDAMCCBaseAddress );
  294. AV_SetContextHandle( NULL, pHwDevExt->pPhysicalDeviceObj );
  295. //AV_SetContext( TRUE, L"\\Registry\\Machine\\Software\\Creative\\DVDEncore\\" );
  296. return TRUE;
  297. }
  298. VOID AnalogUninitialize( PHW_STREAM_REQUEST_BLOCK pSrb )
  299. {
  300. PHW_DEVICE_EXTENSION pHwDevExt = (PHW_DEVICE_EXTENSION)pSrb->HwDeviceExtension;
  301. if( pHwDevExt->bOverlayInitialized )
  302. {
  303. pHwDevExt->bOverlayInitialized = FALSE;
  304. pSrb->Status = STATUS_PENDING;
  305. StreamClassCallAtNewPriority( pSrb->StreamObject, pHwDevExt,
  306. Low, (PHW_PRIORITY_ROUTINE)UninitializeDevice, pSrb );
  307. }
  308. else
  309. pSrb->Status = STATUS_SUCCESS;
  310. }
  311. VOID AnalogOpenStream( PHW_STREAM_REQUEST_BLOCK pSrb )
  312. {
  313. PHW_DEVICE_EXTENSION pHwDevExt = (PHW_DEVICE_EXTENSION)pSrb->HwDeviceExtension;
  314. PHW_STREAM_EXTENSION pStreamExt = (PHW_STREAM_EXTENSION)pSrb->StreamObject->HwStreamExtension;
  315. DebugPrint(( DebugLevelVerbose, "\nZiVA: AnalogOpenStream()\n" ));
  316. if( !pHwDevExt->bOverlayInitialized )
  317. {
  318. pSrb->Status = STATUS_PENDING;
  319. StreamClassCallAtNewPriority( pSrb->StreamObject, pSrb->HwDeviceExtension,
  320. Low, (PHW_PRIORITY_ROUTINE)LoadRegistry, pSrb );
  321. }
  322. pStreamExt->ksState = KSSTATE_STOP;
  323. pStreamExt->bCanBeRun = FALSE;
  324. pStreamExt->bVideoEnabled = FALSE;
  325. DebugPrint(( DebugLevelVerbose, "\nZiVA: End AnalogOpenStream()\n" ));
  326. }
  327. VOID AnalogCloseStream( PHW_STREAM_REQUEST_BLOCK pSrb )
  328. {
  329. PHW_DEVICE_EXTENSION pHwDevExt = (PHW_DEVICE_EXTENSION)pSrb->HwDeviceExtension;
  330. PHW_STREAM_EXTENSION pStreamExt = (PHW_STREAM_EXTENSION)pSrb->StreamObject->HwStreamExtension;
  331. DebugPrint(( DebugLevelVerbose, "\nZiVA: AnalogCloseStream()\n" ));
  332. ASSERT( pStreamExt->ksState == KSSTATE_STOP );
  333. if( pHwDevExt->bOverlayInitialized )
  334. {
  335. // if( pStreamExt->bVideoEnabled )
  336. {
  337. if( !AV_DisableVideo() )
  338. {
  339. DebugPrint(( DebugLevelInfo, "AuraVision's AV_DisableVideo() failed" ));
  340. pSrb->Status = STATUS_IO_DEVICE_ERROR;
  341. }
  342. }
  343. if( NT_SUCCESS( pSrb->Status ) )
  344. {
  345. if( pHwDevExt->nAnalogStreamOpened == 0 )
  346. {
  347. pSrb->Status = STATUS_PENDING;
  348. StreamClassCallAtNewPriority( pSrb->StreamObject, pSrb->HwDeviceExtension,
  349. Low, (PHW_PRIORITY_ROUTINE)SaveRegistry, pSrb );
  350. }
  351. else
  352. pSrb->Status = STATUS_SUCCESS;
  353. }
  354. }
  355. DebugPrint(( DebugLevelVerbose, "\nZiVA: End AnalogCloseStream()\n" ));
  356. }
  357. VOID STREAMAPI AnalogReceiveCtrlPacket( IN PHW_STREAM_REQUEST_BLOCK pSrb )
  358. {
  359. DebugPrint(( DebugLevelVerbose, "\nZiVA: AnalogReceiveCtrlPacket()\n" ));
  360. switch( pSrb->Command )
  361. {
  362. case SRB_OPEN_MASTER_CLOCK: // We don't care about this stuff
  363. case SRB_INDICATE_MASTER_CLOCK:
  364. case SRB_CLOSE_MASTER_CLOCK:
  365. pSrb->Status = STATUS_SUCCESS;
  366. break;
  367. case SRB_SET_STREAM_STATE:
  368. AdapterSetState( pSrb );
  369. break;
  370. case SRB_GET_STREAM_PROPERTY:
  371. GetAnalogProperty( pSrb );
  372. break;
  373. case SRB_SET_STREAM_PROPERTY:
  374. SetAnalogProperty( pSrb );
  375. break;
  376. default:
  377. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  378. }
  379. AdapterReleaseRequest( pSrb );
  380. DebugPrint(( DebugLevelVerbose, "\nZiVA: End AnalogReceiveCtrlPacket()\n" ));
  381. }
  382. VOID STREAMAPI AnalogReceiveDataPacket( IN PHW_STREAM_REQUEST_BLOCK pSrb )
  383. {
  384. // As long as we're not going to process any data we just return error if we got here
  385. DebugPrint(( DebugLevelError,
  386. "\nZiVA: AnalogReceiveDataPacket() - we are not supposed to receieve this call!\n" ));
  387. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  388. AdapterReleaseRequest( pSrb );
  389. }
  390. #endif // #ifdef ENCORE