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.

582 lines
17 KiB

  1. //==========================================================================;
  2. //
  3. // CWDMVideoPortStream - Video Port Stream class implementation
  4. //
  5. // $Date: 05 Aug 1998 11:11:22 $
  6. // $Revision: 1.0 $
  7. // $Author: Tashjian $
  8. //
  9. // $Copyright: (c) 1997 - 1998 ATI Technologies Inc. All Rights Reserved. $
  10. //
  11. //==========================================================================;
  12. extern "C"
  13. {
  14. #include "strmini.h"
  15. #include "ksmedia.h"
  16. }
  17. #include "wdmvdec.h"
  18. #include "wdmdrv.h"
  19. #include "aticonfg.h"
  20. #include "capdebug.h"
  21. CWDMVideoPortStream::CWDMVideoPortStream(PHW_STREAM_OBJECT pStreamObject,
  22. CWDMVideoDecoder * pVideoDecoder,
  23. PUINT puiErrorCode)
  24. : CWDMVideoStream(pStreamObject, pVideoDecoder, puiErrorCode)
  25. {
  26. DBGTRACE(("CWDMVideoPortStream::CWDMVideoPortStream()\n"));
  27. int StreamNumber = pStreamObject->StreamNumber;
  28. if (StreamNumber == STREAM_VPVideo)
  29. {
  30. }
  31. else if (StreamNumber == STREAM_VPVBI)
  32. {
  33. }
  34. *puiErrorCode = WDMMINI_NOERROR;
  35. }
  36. CWDMVideoPortStream::~CWDMVideoPortStream()
  37. {
  38. DBGTRACE(("CWDMVideoPortStream::~CWDMVideoPortStream()\n"));
  39. if (m_Registered)
  40. {
  41. m_pVideoPort->UnregisterForDirectDrawEvents( this);
  42. }
  43. }
  44. VOID STREAMAPI CWDMVideoPortStream::VideoReceiveDataPacket(IN PHW_STREAM_REQUEST_BLOCK pSrb)
  45. {
  46. DBGERROR(("Unexpected data packet on non VP stream.\n"));
  47. ASSERT(0);
  48. }
  49. /*
  50. ** VideoSetProperty()
  51. **
  52. ** Routine to process video property requests
  53. **
  54. ** Arguments:
  55. **
  56. ** pSrb - pointer to the stream request block for properties
  57. **
  58. ** Returns:
  59. **
  60. ** Side Effects: none
  61. */
  62. VOID CWDMVideoPortStream::VideoSetProperty(PHW_STREAM_REQUEST_BLOCK pSrb)
  63. {
  64. PSTREAM_PROPERTY_DESCRIPTOR pSPD = pSrb->CommandData.PropertyInfo;
  65. if (IsEqualGUID (KSPROPSETID_VPConfig, pSPD->Property->Set)) {
  66. SetVideoPortProperty (pSrb);
  67. }
  68. else if (IsEqualGUID (KSPROPSETID_VPVBIConfig, pSPD->Property->Set)) {
  69. SetVideoPortVBIProperty (pSrb);
  70. }
  71. else {
  72. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  73. }
  74. }
  75. /*
  76. ** VideoGetProperty()
  77. **
  78. ** Routine to process video property requests
  79. **
  80. ** Arguments:
  81. **
  82. ** pSrb - pointer to the stream request block for properties
  83. **
  84. ** Returns:
  85. **
  86. ** Side Effects: none
  87. */
  88. VOID CWDMVideoPortStream::VideoGetProperty(PHW_STREAM_REQUEST_BLOCK pSrb)
  89. {
  90. PSTREAM_PROPERTY_DESCRIPTOR pSPD = pSrb->CommandData.PropertyInfo;
  91. if (IsEqualGUID (KSPROPSETID_Connection, pSPD->Property->Set)) {
  92. VideoStreamGetConnectionProperty (pSrb);
  93. }
  94. else if (IsEqualGUID (KSPROPSETID_VPConfig, pSPD->Property->Set)) {
  95. m_pDevice->GetVideoPortProperty (pSrb);
  96. }
  97. else if (IsEqualGUID (KSPROPSETID_VPVBIConfig, pSPD->Property->Set)) {
  98. m_pDevice->GetVideoPortVBIProperty (pSrb);
  99. }
  100. else {
  101. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  102. }
  103. }
  104. /*
  105. ** VideoSetState()
  106. **
  107. ** Sets the current state of the requested stream
  108. **
  109. ** Arguments:
  110. **
  111. ** pSrb - pointer to the stream request block for properties
  112. **
  113. ** Returns:
  114. **
  115. ** Side Effects: none
  116. */
  117. VOID CWDMVideoPortStream::VideoSetState(PHW_STREAM_REQUEST_BLOCK pSrb, BOOL bVPConnected, BOOL bVPVBIConnected)
  118. {
  119. //
  120. // For each stream, the following states are used:
  121. //
  122. // Stop: Absolute minimum resources are used. No outstanding IRPs.
  123. // Pause: Getting ready to run. Allocate needed resources so that
  124. // the eventual transition to Run is as fast as possible.
  125. // SRBs will be queued at either the Stream class or in your
  126. // driver.
  127. // Run: Streaming.
  128. //
  129. // Moving to Stop or Run ALWAYS transitions through Pause, so that ONLY
  130. // the following transitions are possible:
  131. //
  132. // Stop -> Pause
  133. // Pause -> Run
  134. // Run -> Pause
  135. // Pause -> Stop
  136. //
  137. // Note that it is quite possible to transition repeatedly between states:
  138. // Stop -> Pause -> Stop -> Pause -> Run -> Pause -> Run -> Pause -> Stop
  139. //
  140. DBGINFO(("CWDMVideoPortStream::VideoSetState for stream %d\n", pSrb->StreamObject->StreamNumber));
  141. pSrb->Status = STATUS_SUCCESS;
  142. switch (pSrb->CommandData.StreamState)
  143. {
  144. case KSSTATE_STOP:
  145. DBGINFO((" state KSSTATE_STOP"));
  146. m_pDevice->SetOutputEnabled(FALSE);
  147. // Reset the overridden flag so that the next time we go to the
  148. // Run state, output will be enabled (unless the app overrides
  149. // it again later). We should really do this after the graph
  150. // has been stopped so that if a filter that has yet to be stopped
  151. // cleans up by clearing the flag, it is not considered to be
  152. // overriding it again. Since we are not called after the graph
  153. // has been fully stopped, this is the best we can do.
  154. //
  155. // An alternative (and probably less confusing) approach is to
  156. // leave the overridden flag set and force the app to control
  157. // the output enabled feature if it changes it once.
  158. //
  159. // We have decided to follow the latter approach.
  160. // m_pDevice->SetOutputEnabledOverridden(FALSE);
  161. break;
  162. case KSSTATE_ACQUIRE:
  163. DBGINFO((" state KSSTATE_ACQUIRE"));
  164. ASSERT(m_KSState == KSSTATE_STOP);
  165. break;
  166. case KSSTATE_PAUSE:
  167. DBGINFO((" state KSSTATE_PAUSE"));
  168. if (m_pVideoDecoder->PreEventOccurred() &&
  169. (!m_pDevice->IsOutputEnabledOverridden() || m_pDevice->IsOutputEnabled()) &&
  170. (m_KSState == KSSTATE_STOP || m_KSState == KSSTATE_ACQUIRE))
  171. {
  172. DBGERROR(("VpStrm Pause: Overridden = %d, OutputEnabled = %d",
  173. m_pDevice->IsOutputEnabledOverridden(),
  174. m_pDevice->IsOutputEnabled()
  175. ));
  176. pSrb->Status = STATUS_UNSUCCESSFUL;
  177. }
  178. break;
  179. case KSSTATE_RUN:
  180. DBGINFO((" state KSSTATE_RUN"));
  181. ASSERT(m_KSState == KSSTATE_ACQUIRE || m_KSState == KSSTATE_PAUSE);
  182. if (m_pVideoDecoder->PreEventOccurred() &&
  183. (!m_pDevice->IsOutputEnabledOverridden() ||
  184. m_pDevice->IsOutputEnabled()))
  185. {
  186. DBGERROR(("VpStrm Run: Overridden = %d, OutputEnabled = %d",
  187. m_pDevice->IsOutputEnabledOverridden(),
  188. m_pDevice->IsOutputEnabled()
  189. ));
  190. pSrb->Status = STATUS_UNSUCCESSFUL;
  191. }
  192. else if (!m_pDevice->IsOutputEnabledOverridden())
  193. m_pDevice->SetOutputEnabled(TRUE);
  194. break;
  195. }
  196. if (pSrb->Status == STATUS_SUCCESS) {
  197. m_KSState = pSrb->CommandData.StreamState;
  198. DBGINFO((" entered\n"));
  199. }
  200. else
  201. DBGINFO((" NOT entered ***\n"));
  202. }
  203. VOID CWDMVideoPortStream::SetVideoPortProperty(PHW_STREAM_REQUEST_BLOCK pSrb)
  204. {
  205. PSTREAM_PROPERTY_DESCRIPTOR pSpd = pSrb->CommandData.PropertyInfo;
  206. ULONG Id = pSpd->Property->Id; // index of the property
  207. ULONG nS = pSpd->PropertyOutputSize; // size of data supplied
  208. pSrb->Status = STATUS_SUCCESS;
  209. ASSERT (m_pDevice != NULL);
  210. switch (Id)
  211. {
  212. case KSPROPERTY_VPCONFIG_DDRAWHANDLE:
  213. ASSERT (nS >= sizeof(ULONG_PTR));
  214. if (!m_pVideoPort->ConfigDirectDrawHandle(*(PULONG_PTR)pSpd->PropertyInfo)) {
  215. pSrb->Status = STATUS_UNSUCCESSFUL;
  216. break;
  217. }
  218. if (!m_Registered) {
  219. m_Registered = m_pVideoPort->RegisterForDirectDrawEvents(this);
  220. if (!m_Registered) {
  221. pSrb->Status = STATUS_UNSUCCESSFUL;
  222. break;
  223. }
  224. }
  225. break;
  226. case KSPROPERTY_VPCONFIG_VIDEOPORTID:
  227. ASSERT (nS >= sizeof(ULONG));
  228. if (!m_pVideoPort->ConfigVideoPortHandle(*(PULONG)pSpd->PropertyInfo)) {
  229. pSrb->Status = STATUS_UNSUCCESSFUL;
  230. }
  231. break;
  232. case KSPROPERTY_VPCONFIG_DDRAWSURFACEHANDLE:
  233. ASSERT (nS >= sizeof(ULONG_PTR));
  234. {
  235. // This sample does not use the surface kernel handles,
  236. // but the validation is as follows.
  237. ULONG_PTR cHandles = *(PULONG_PTR)pSpd->PropertyInfo;
  238. if (nS != (cHandles + 1) * sizeof(ULONG_PTR)) {
  239. pSrb->Status = STATUS_INVALID_BUFFER_SIZE;
  240. break;
  241. }
  242. m_pVideoDecoder->ResetEvents();
  243. }
  244. break;
  245. case KSPROPERTY_VPCONFIG_SETCONNECTINFO :
  246. ASSERT (nS >= sizeof(ULONG));
  247. {
  248. // Indexes are correlated to the implementation of KSPROPERTY_VPCONFIG_GETCONNECTINFO
  249. ULONG Index = *(PULONG)pSpd->PropertyInfo;
  250. switch (Index)
  251. {
  252. case 0:
  253. m_pDevice->Set16BitDataStream(FALSE);
  254. break;
  255. #ifdef BT829_SUPPORT_16BIT
  256. case 1:
  257. m_pDevice->Set16BitDataStream(TRUE);
  258. break;
  259. #endif
  260. default:
  261. pSrb->Status = STATUS_INVALID_PARAMETER;
  262. }
  263. }
  264. break;
  265. case KSPROPERTY_VPCONFIG_INVERTPOLARITY :
  266. m_pDevice->SetHighOdd(!m_pDevice->IsHighOdd());
  267. break;
  268. case KSPROPERTY_VPCONFIG_SETVIDEOFORMAT :
  269. ASSERT (nS >= sizeof(ULONG));
  270. //
  271. // pSrb->CommandData.PropertInfo->PropertyInfo
  272. // points to a ULONG which is an index into the array of
  273. // VIDEOFORMAT structs returned to the caller from the
  274. // Get call to FORMATINFO
  275. //
  276. // Since the sample only supports one FORMAT type right
  277. // now, we will ensure that the requested index is 0.
  278. //
  279. switch (*(PULONG)pSrb->CommandData.PropertyInfo->PropertyInfo)
  280. {
  281. case 0:
  282. //
  283. // at this point, we would program the hardware to use
  284. // the right connection information for the videoport.
  285. // since we are only supporting one connection, we don't
  286. // need to do anything, so we will just indicate success
  287. //
  288. break;
  289. default:
  290. pSrb->Status = STATUS_NO_MATCH;
  291. break;
  292. }
  293. break;
  294. case KSPROPERTY_VPCONFIG_INFORMVPINPUT:
  295. ASSERT (nS >= sizeof(DDPIXELFORMAT));
  296. // This would be supported if we wanted to be informed of the available formats
  297. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  298. break;
  299. case KSPROPERTY_VPCONFIG_SCALEFACTOR :
  300. ASSERT (nS >= sizeof(KS_AMVPSIZE));
  301. {
  302. PKS_AMVPSIZE pAMVPSize;
  303. pAMVPSize = (PKS_AMVPSIZE)(pSrb->CommandData.PropertyInfo->PropertyInfo);
  304. MRect t(0, 0, pAMVPSize->dwWidth, pAMVPSize->dwHeight);
  305. m_pDevice->SetRect(t);
  306. }
  307. break;
  308. case KSPROPERTY_VPCONFIG_SURFACEPARAMS :
  309. ASSERT(nS >= sizeof(KSVPSURFACEPARAMS));
  310. m_pDevice->ConfigVPSurfaceParams((PKSVPSURFACEPARAMS)pSpd->PropertyInfo);
  311. break;
  312. default:
  313. TRAP();
  314. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  315. break;
  316. }
  317. }
  318. VOID CWDMVideoPortStream::SetVideoPortVBIProperty(PHW_STREAM_REQUEST_BLOCK pSrb)
  319. {
  320. PSTREAM_PROPERTY_DESCRIPTOR pSpd = pSrb->CommandData.PropertyInfo;
  321. ULONG Id = pSpd->Property->Id; // index of the property
  322. ULONG nS = pSpd->PropertyOutputSize; // size of data supplied
  323. pSrb->Status = STATUS_SUCCESS;
  324. ASSERT (m_pDevice != NULL);
  325. switch (Id)
  326. {
  327. case KSPROPERTY_VPCONFIG_DDRAWHANDLE:
  328. ASSERT (nS >= sizeof(ULONG_PTR));
  329. if (!m_pVideoPort->ConfigDirectDrawHandle(*(PULONG_PTR)pSpd->PropertyInfo)) {
  330. pSrb->Status = STATUS_UNSUCCESSFUL;
  331. break;
  332. }
  333. if (!m_Registered) {
  334. m_Registered = m_pVideoPort->RegisterForDirectDrawEvents(this);
  335. if (!m_Registered) {
  336. pSrb->Status = STATUS_UNSUCCESSFUL;
  337. break;
  338. }
  339. }
  340. break;
  341. case KSPROPERTY_VPCONFIG_VIDEOPORTID:
  342. ASSERT (nS >= sizeof(ULONG));
  343. if (!m_pVideoPort->ConfigVideoPortHandle(*(PULONG)pSpd->PropertyInfo)) {
  344. pSrb->Status = STATUS_UNSUCCESSFUL;
  345. }
  346. break;
  347. case KSPROPERTY_VPCONFIG_DDRAWSURFACEHANDLE:
  348. ASSERT (nS >= sizeof(ULONG_PTR));
  349. {
  350. // This sample does not use the surface kernel handles,
  351. // but the validation is as follows.
  352. ULONG_PTR cHandles = *(PULONG_PTR)pSpd->PropertyInfo;
  353. if (nS != (cHandles + 1) * sizeof(ULONG_PTR)) {
  354. pSrb->Status = STATUS_INVALID_BUFFER_SIZE;
  355. break;
  356. }
  357. m_pVideoDecoder->ResetEvents();
  358. }
  359. break;
  360. case KSPROPERTY_VPCONFIG_SETCONNECTINFO :
  361. ASSERT (nS >= sizeof(ULONG));
  362. {
  363. // Indexes are correlated to the implementation of KSPROPERTY_VPCONFIG_GETCONNECTINFO
  364. ULONG Index = *(PULONG)pSpd->PropertyInfo;
  365. switch (Index)
  366. {
  367. case 0:
  368. m_pDevice->Set16BitDataStream(FALSE);
  369. break;
  370. #ifdef BT829_SUPPORT_16BIT
  371. case 1:
  372. m_pDevice->Set16BitDataStream(TRUE);
  373. break;
  374. #endif
  375. default:
  376. pSrb->Status = STATUS_INVALID_PARAMETER;
  377. }
  378. }
  379. break;
  380. case KSPROPERTY_VPCONFIG_INVERTPOLARITY :
  381. m_pDevice->SetHighOdd(!m_pDevice->IsHighOdd());
  382. break;
  383. case KSPROPERTY_VPCONFIG_SETVIDEOFORMAT :
  384. ASSERT (nS >= sizeof(ULONG));
  385. //
  386. // pSrb->CommandData.PropertInfo->PropertyInfo
  387. // points to a ULONG which is an index into the array of
  388. // VIDEOFORMAT structs returned to the caller from the
  389. // Get call to FORMATINFO
  390. //
  391. // Since the sample only supports one FORMAT type right
  392. // now, we will ensure that the requested index is 0.
  393. //
  394. switch (*(PULONG)pSrb->CommandData.PropertyInfo->PropertyInfo)
  395. {
  396. case 0:
  397. //
  398. // at this point, we would program the hardware to use
  399. // the right connection information for the videoport.
  400. // since we are only supporting one connection, we don't
  401. // need to do anything, so we will just indicate success
  402. //
  403. break;
  404. default:
  405. pSrb->Status = STATUS_NO_MATCH;
  406. break;
  407. }
  408. break;
  409. case KSPROPERTY_VPCONFIG_INFORMVPINPUT:
  410. ASSERT (nS >= sizeof(DDPIXELFORMAT));
  411. // This would be supported if we wanted to be informed of the available formats
  412. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  413. break;
  414. case KSPROPERTY_VPCONFIG_SCALEFACTOR :
  415. ASSERT (nS >= sizeof(KS_AMVPSIZE));
  416. // TBD
  417. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  418. break;
  419. case KSPROPERTY_VPCONFIG_SURFACEPARAMS :
  420. ASSERT(nS >= sizeof(KSVPSURFACEPARAMS));
  421. m_pDevice->ConfigVPVBISurfaceParams((PKSVPSURFACEPARAMS)pSpd->PropertyInfo);
  422. break;
  423. default:
  424. TRAP();
  425. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  426. break;
  427. }
  428. }
  429. VOID CWDMVideoPortStream::PreResChange()
  430. {
  431. DBGTRACE(("DDNOTIFY_PRERESCHANGE; stream = %d\n", m_pStreamObject->StreamNumber));
  432. m_pVideoDecoder->SetPreEvent();
  433. }
  434. VOID CWDMVideoPortStream::PostResChange()
  435. {
  436. DBGTRACE(("DDNOTIFY_POSTRESCHANGE; stream = %d\n", m_pStreamObject->StreamNumber));
  437. m_pVideoDecoder->SetPostEvent();
  438. DBGTRACE(("Before Attempted Renegotiation due to DDNOTIFY_POSTRESCHANGE\n"));
  439. AttemptRenegotiation();
  440. DBGTRACE(("Afer Attempted Renegotiation due to DDNOTIFY_POSTRESCHANGE\n"));
  441. }
  442. VOID CWDMVideoPortStream::PreDosBox()
  443. {
  444. DBGTRACE(("DDNOTIFY_PREDOSBOX; stream = %d\n", m_pStreamObject->StreamNumber));
  445. m_pVideoDecoder->SetPreEvent();
  446. }
  447. VOID CWDMVideoPortStream::PostDosBox()
  448. {
  449. DBGTRACE(("DDNOTIFY_POSTDOSBOX; stream = %d\n", m_pStreamObject->StreamNumber));
  450. m_pVideoDecoder->SetPostEvent();
  451. DBGTRACE(("Before Attempted Renegotiation due to DDNOTIFY_POSTDOSBOX\n"));
  452. AttemptRenegotiation();
  453. DBGTRACE(("After Attempted Renegotiation due to DDNOTIFY_POSTDOSBOX\n"));
  454. }
  455. NTSTATUS STREAMAPI VPStreamEventProc (PHW_EVENT_DESCRIPTOR pEvent)
  456. {
  457. CWDMVideoPortStream* pstrm=(CWDMVideoPortStream*)pEvent->StreamObject->HwStreamExtension;
  458. pstrm->StreamEventProc(pEvent);
  459. return STATUS_SUCCESS;
  460. }
  461. NTSTATUS STREAMAPI VPVBIStreamEventProc (PHW_EVENT_DESCRIPTOR pEvent)
  462. {
  463. CWDMVideoPortStream* pstrm=(CWDMVideoPortStream*)pEvent->StreamObject->HwStreamExtension;
  464. pstrm->StreamEventProc(pEvent);
  465. return STATUS_SUCCESS;
  466. }