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.

1011 lines
24 KiB

  1. //******************************************************************************/
  2. //* *
  3. //* ccaption.c - *
  4. //* *
  5. //* Copyright (c) C-Cube Microsystems 1996 *
  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 "strmini.h"
  13. #include "ksmedia.h"
  14. #include "zivawdm.h"
  15. #include "adapter.h"
  16. #include "monovxd.h"
  17. #include "cl6100.h"
  18. #include <ccaption.h>
  19. typedef struct _STREAMEX {
  20. DWORD EventCount;
  21. KSSTATE state;
  22. } STREAMEX, *PSTREAMEX;
  23. HANDLE hMaster;
  24. HANDLE hClk;
  25. void GetCCProperty(PHW_STREAM_REQUEST_BLOCK pSrb)
  26. {
  27. PHW_DEVICE_EXTENSION pHwDevExt = ((PHW_DEVICE_EXTENSION)pSrb->HwDeviceExtension);
  28. PKSALLOCATOR_FRAMING pfrm = (PKSALLOCATOR_FRAMING)pSrb->CommandData.PropertyInfo->PropertyInfo;
  29. PKSSTATE State;
  30. if(!pSrb)
  31. {
  32. #ifdef DBG
  33. DbgPrint(" ERROR : CCGetProp invalid SRB !!!!\n");
  34. DEBUG_BREAKPOINT();
  35. #endif
  36. return;
  37. }
  38. pSrb->Status = STATUS_SUCCESS;//STATUS_NOT_IMPLEMENTED;
  39. if (pSrb->CommandData.PropertyInfo->PropertySetID)
  40. {
  41. #ifdef DBG
  42. DbgPrint(" ERROR : CCGetProp returning NO MATCH !!!\n");
  43. #endif
  44. // invalid property
  45. pSrb->Status = STATUS_NO_MATCH;
  46. return;
  47. }
  48. switch(pSrb->CommandData.PropertyInfo->Property->Id)
  49. {
  50. case KSPROPERTY_CONNECTION_ALLOCATORFRAMING:
  51. {
  52. //This read-only property is used to retrieve any allocator framing requirements
  53. #ifdef DBG
  54. DbgPrint(" : CCGetProp - KSPROPERTY_CONNECTION_ALLOCATORFRAMING\n");
  55. #endif
  56. pfrm->OptionsFlags = 0;
  57. pfrm->PoolType = NonPagedPool;
  58. pfrm->Frames = 10;
  59. pfrm->FrameSize = 200;
  60. pfrm->FileAlignment = 0;
  61. pfrm->Reserved = 0;
  62. pSrb->ActualBytesTransferred = sizeof(KSALLOCATOR_FRAMING);
  63. pSrb->Status = STATUS_SUCCESS;
  64. break;
  65. }
  66. case KSPROPERTY_CONNECTION_STATE:
  67. State= (PKSSTATE) pSrb->CommandData.PropertyInfo->PropertyInfo;
  68. pSrb->ActualBytesTransferred = sizeof (State);
  69. // A very odd rule:
  70. // When transitioning from stop to pause, DShow tries to preroll
  71. // the graph. Capture sources can't preroll, and indicate this
  72. // by returning VFW_S_CANT_CUE in user mode. To indicate this
  73. // condition from drivers, they must return ERROR_NO_DATA_DETECTED
  74. if(pHwDevExt->pstroCC)
  75. {
  76. *State = ((PSTREAMEX)(pHwDevExt->pstroCC->HwStreamExtension))->state;
  77. if (((PSTREAMEX)pHwDevExt->pstroCC->HwStreamExtension)->state == KSSTATE_PAUSE)
  78. {
  79. // wierd stuff for capture type state change. When you transition
  80. // from stop to pause, we need to indicate that this device cannot
  81. // preroll, and has no data to send.
  82. pSrb->Status = STATUS_NO_DATA_DETECTED;
  83. // break;
  84. }
  85. }
  86. pSrb->Status = STATUS_SUCCESS;
  87. break;
  88. default:
  89. #ifdef DBG
  90. DbgPrint(" : CCGetProp Error - invalid cmd !!!\n");
  91. #endif
  92. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  93. break;
  94. }
  95. }
  96. ///////////////////////////////////////////////////////////////////////////////////////////
  97. void CCEnqueue(PHW_STREAM_REQUEST_BLOCK pSrb)
  98. {
  99. PHW_DEVICE_EXTENSION pHwDevExt = pSrb->HwDeviceExtension;
  100. PHW_STREAM_REQUEST_BLOCK pSrbTmp;
  101. ULONG cSrb;
  102. // if(pHwDevExt->pCCDevEx == NULL)
  103. // return;
  104. // pSrbTmp = CONTAINING_RECORD((&(pHwDevExt->pCCDevEx->pSrbQ)), HW_STREAM_REQUEST_BLOCK, NextSRB);
  105. // if(pSrbTmp == NULL)
  106. // return;
  107. // enqueue the given SRB on the device extension queue
  108. for (cSrb =0, pSrbTmp = CONTAINING_RECORD((&(pHwDevExt->pCCDevEx->pSrbQ)), HW_STREAM_REQUEST_BLOCK, NextSRB);
  109. pSrbTmp->NextSRB;
  110. pSrbTmp = pSrbTmp->NextSRB, cSrb++);
  111. pSrbTmp->NextSRB = pSrb;
  112. pSrb->NextSRB = NULL;
  113. pHwDevExt->cCCQ++;
  114. }
  115. ///////////////////////////////////////////////////////////////////////////////////////////
  116. PHW_STREAM_REQUEST_BLOCK
  117. CCDequeue(
  118. PHW_DEVICE_EXTENSION pHwDevExt
  119. )
  120. /*++
  121. Routine Description:
  122. Dequeue the CC queue
  123. Arguments:
  124. pHwDevExt - device exetension pointer
  125. Return Value:
  126. Dequeued SRB
  127. --*/
  128. {
  129. PHW_STREAM_REQUEST_BLOCK pRet = NULL;
  130. if(pHwDevExt->pCCDevEx == NULL)
  131. return NULL;
  132. if (pHwDevExt->pCCDevEx->pSrbQ)
  133. {
  134. pHwDevExt->cCCDeq++;
  135. pRet = pHwDevExt->pCCDevEx->pSrbQ;
  136. pHwDevExt->pCCDevEx->pSrbQ = pRet->NextSRB;
  137. pHwDevExt->cCCQ--;
  138. }
  139. return(pRet);
  140. }
  141. /////////////////////////////////////////////////////////////////////////////////////////////////////
  142. void CallBackError(PHW_STREAM_REQUEST_BLOCK pSrb)
  143. {
  144. PHW_DEVICE_EXTENSION pHwDevExt = pSrb->HwDeviceExtension;
  145. if(!pSrb)
  146. {
  147. #ifdef DBG
  148. DbgPrint(" ERROR : CallBackError - invalid arg !!!\n");
  149. #endif
  150. return;
  151. }
  152. pSrb->Status = STATUS_SUCCESS;
  153. // if (pHwDevExt->pSPstrmex)
  154. // {
  155. //
  156. // pHwDevExt->pSPstrmex->pdecctl.curData = 0;
  157. // pHwDevExt->pSPstrmex->pdecctl.decFlags = 0;
  158. //
  159. // }
  160. // StreamClassStreamNotification(StreamRequestComplete,
  161. // pSrb->StreamObject,
  162. //sri pSrb);
  163. }
  164. ///////////////////////////////////////////////////////////////////////////////////////////
  165. void
  166. CleanCCQueue(
  167. PHW_DEVICE_EXTENSION pHwDevExt
  168. )
  169. /*++
  170. Routine Description:
  171. Clean CC Queue
  172. Arguments:
  173. pHwDevExt - pointer to device extension
  174. Return Value:
  175. none
  176. --*/
  177. {
  178. PHW_STREAM_REQUEST_BLOCK pSrb;
  179. while (pSrb = CCDequeue(pHwDevExt))
  180. {
  181. CallBackError(pSrb);
  182. }
  183. }
  184. ///////////////////////////////////////////////////////////////////////////////////////////
  185. VOID STREAMAPI
  186. CCReceiveDataPacket(
  187. IN PHW_STREAM_REQUEST_BLOCK pSrb
  188. )
  189. /*++
  190. Routine Description:
  191. Receive the data packets to send to the close-caption decoder
  192. Arguments:
  193. pSrb - pointer to stream request block
  194. Return Value:
  195. none
  196. --*/
  197. {
  198. PHW_DEVICE_EXTENSION pHwDevExt = ((PHW_DEVICE_EXTENSION) pSrb->HwDeviceExtension);
  199. //
  200. // determine the type of packet.
  201. //
  202. switch (pSrb->Command)
  203. {
  204. case SRB_READ_DATA:
  205. pHwDevExt->cCCRec++;
  206. CCEnqueue(pSrb);
  207. #ifdef DBG
  208. //DbgPrint(" : CC Data Packet - pHwDevExt->cCCQ = %d\n",pHwDevExt->cCCQ);
  209. #endif
  210. //NEW
  211. pSrb->Status = STATUS_PENDING;
  212. pSrb->TimeoutCounter = 0;
  213. StreamClassStreamNotification(ReadyForNextStreamDataRequest,pSrb->StreamObject);
  214. return;
  215. case SRB_WRITE_DATA:
  216. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  217. break;
  218. default: // invalid / unsupported command. Fail it as such
  219. #ifdef DBG
  220. DbgPrint(" : CCReceiveDataPacket - invalid cmd !!!\n");
  221. #endif
  222. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  223. break;
  224. }
  225. StreamClassStreamNotification(ReadyForNextStreamDataRequest,
  226. pSrb->StreamObject);
  227. StreamClassStreamNotification(StreamRequestComplete,
  228. pSrb->StreamObject,
  229. pSrb);
  230. }
  231. /*
  232. ** CCReceiveCtrlPacket()
  233. */
  234. VOID STREAMAPI CCReceiveCtrlPacket( IN PHW_STREAM_REQUEST_BLOCK pSrb )
  235. {
  236. PHW_DEVICE_EXTENSION pHwDevExt = (PHW_DEVICE_EXTENSION)pSrb->HwDeviceExtension;
  237. DebugPrint(( DebugLevelTrace, ":CCReceiveCtrlPacket---------\r\n" ));
  238. switch( pSrb->Command ) {
  239. case SRB_SET_STREAM_STATE:
  240. AdapterSetState( pSrb );
  241. if(pHwDevExt->pstroCC)
  242. ((PSTREAMEX)(pHwDevExt->pstroCC->HwStreamExtension))->state = pSrb->CommandData.StreamState;
  243. pSrb->Status = STATUS_SUCCESS;
  244. break;
  245. case SRB_GET_STREAM_STATE:
  246. DebugPrint(( DebugLevelTrace, ": SRB_GET_STREAM_STATE\r\n" ));
  247. pSrb->Status = STATUS_SUCCESS;
  248. break;
  249. case SRB_GET_STREAM_PROPERTY:
  250. DebugPrint(( DebugLevelTrace, ": SRB_GET_STREAM_PROPERTY\r\n" ));
  251. GetCCProperty( pSrb );
  252. break;
  253. case SRB_SET_STREAM_PROPERTY:
  254. DebugPrint(( DebugLevelTrace, ": SRB_SET_STREAM_PROPERTY\r\n" ));
  255. // SetCCProperty( pSrb );
  256. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  257. break;
  258. case SRB_OPEN_MASTER_CLOCK:
  259. DebugPrint( (DebugLevelTrace, ": SRB_OPEN_MASTER_CLOCK\r\n") );
  260. hMaster = pSrb->CommandData.MasterClockHandle;
  261. pSrb->Status = STATUS_SUCCESS;
  262. break;
  263. case SRB_CLOSE_MASTER_CLOCK:
  264. DebugPrint(( DebugLevelTrace, ": SRB_CLOSE_MASTER_CLOCK\r\n" ));
  265. hMaster = pSrb->CommandData.MasterClockHandle;
  266. pSrb->Status = STATUS_SUCCESS;
  267. break;
  268. case SRB_INDICATE_MASTER_CLOCK:
  269. DebugPrint(( DebugLevelTrace, ": SRB_INDICATE_MASTER_CLOCK\r\n" ));
  270. hClk = pSrb->CommandData.MasterClockHandle;
  271. pSrb->Status = STATUS_SUCCESS;
  272. break;
  273. case SRB_BEGIN_FLUSH : // beginning flush state
  274. MonoOutStr("CC::BeginFlush");
  275. pSrb->Status = STATUS_SUCCESS;
  276. break;
  277. case SRB_UNKNOWN_STREAM_COMMAND:
  278. DebugPrint(( DebugLevelTrace, ": SRB_UNKNOWN_STREAM_COMMAND\r\n" ));
  279. // TRAP;
  280. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  281. break;
  282. case SRB_SET_STREAM_RATE:
  283. DebugPrint(( DebugLevelTrace, ": SRB_SET_STREAM_RATE\r\n" ));
  284. // TRAP;
  285. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  286. break;
  287. case SRB_PROPOSE_DATA_FORMAT:
  288. DebugPrint(( DebugLevelTrace, ": SRB_PROPOSE_DATA_FORMAT\r\n" ));
  289. // TRAP;
  290. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  291. break;
  292. default:
  293. DebugPrint(( DebugLevelTrace, ": default %d(0x%x)\r\n", pSrb->Command, pSrb->Command ));
  294. // TRAP;
  295. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  296. break;
  297. }
  298. StreamClassStreamNotification( ReadyForNextStreamControlRequest,
  299. pSrb->StreamObject );
  300. StreamClassStreamNotification( StreamRequestComplete,
  301. pSrb->StreamObject,
  302. pSrb );
  303. }
  304. static ULONGLONG ConvertPTStoStrm( ULONG pts )
  305. {
  306. ULONGLONG strm;
  307. strm = (ULONGLONG)pts;
  308. strm = (strm * 1000) / 9;
  309. return strm;
  310. }
  311. ////////////////////////////////////////////////////////////////////////////////
  312. /*
  313. void UserDataEvents(PHW_DEVICE_EXTENSION pHwDevExt)
  314. {
  315. PBYTE pDest;
  316. PHW_STREAM_REQUEST_BLOCK pSrb;
  317. PKSSTREAM_HEADER pPacket;
  318. DWORD *pdw;
  319. BYTE *pb;
  320. DWORD USR_Read_Ptr, USR_Write_Ptr, Data,UserDataBufferStart,UserDataBufferEnd;
  321. WORD wByteLen, wCount=0;
  322. WORD i = 0,j;
  323. WORD wPhase = 0;
  324. BYTE CC_Len;
  325. WORD CC_Data;
  326. // pdw = (DWORD *)LUXVideoUserData(pHwDevExt);
  327. USR_Read_Ptr = DVD_ReadDRAM( USER_DATA_READ );
  328. USR_Write_Ptr = DVD_ReadDRAM( USER_DATA_WRITE );
  329. UserDataBufferStart = DVD_ReadDRAM( USER_DATA_BUFFER_START );
  330. UserDataBufferEnd = DVD_ReadDRAM( USER_DATA_BUFFER_END );
  331. // Check for DRAM Buffer Overflow
  332. if ( USR_Read_Ptr == 0xFFFFFFFF )
  333. {
  334. // Set Read Ptr
  335. DVD_WriteDRAM( USER_DATA_READ, USR_Write_Ptr );
  336. return;
  337. }
  338. while( USR_Read_Ptr != USR_Write_Ptr )
  339. {
  340. // Get Data from USER_DATA DRAM Buffer
  341. Data = DVD_ReadDRAM( USR_Read_Ptr );
  342. // Store to Local Buffer
  343. USR_Data_Buff[ i++ ] = Data;//CL6100_DWSwap( Data );
  344. // Adjust Data Pointer
  345. USR_Read_Ptr += 4L;
  346. if ( USR_Read_Ptr >= UserDataBufferEnd)
  347. USR_Read_Ptr = UserDataBufferStart;
  348. }
  349. // Save DWORD Count
  350. wCount = i;
  351. // Set Read End Address to DRAM
  352. DVD_WriteDRAM( USER_DATA_READ, USR_Read_Ptr );
  353. if( (USR_Data_Buff[ 0 ] & 0x0000FFFF) == 0x0000EDFE )
  354. {
  355. // Get Data Count and Field Flag
  356. CC_Len = * ( ( ( LPBYTE )USR_Data_Buff ) + 8 );
  357. wCount = ( BYTE )( CC_Len & 0x3F );
  358. wCount = (wCount-1)*3 + sizeof(KSGOP_USERDATA);
  359. if (pHwDevExt->pstroCC && ((PSTREAMEX)(pHwDevExt->pstroCC->HwStreamExtension))->state==KSSTATE_RUN )
  360. {
  361. if (pSrb = CCDequeue(pHwDevExt))
  362. {
  363. //
  364. // check the SRB to ensure it can take at least the header
  365. // information from the GOP packet
  366. //
  367. if (pSrb->CommandData.DataBufferArray->FrameExtent < sizeof(KSGOP_USERDATA))
  368. {
  369. pSrb->Status = STATUS_INVALID_BUFFER_SIZE;
  370. pSrb->ActualBytesTransferred = 0;
  371. StreamClassStreamNotification(StreamRequestComplete,
  372. pSrb->StreamObject,
  373. pSrb);
  374. return;
  375. }
  376. pDest = pSrb->CommandData.DataBufferArray->Data;
  377. // move pdw pointer to the size of CC
  378. // pb = ((BYTE*)pdw)+8;
  379. //
  380. // numb = (DWORD)(*pb)&0x3f;
  381. // numb = (numb-1)*3 + sizeof(KSGOP_USERDATA);
  382. if (pSrb->CommandData.DataBufferArray->FrameExtent < wCount)
  383. {
  384. pSrb->Status = STATUS_INVALID_BUFFER_SIZE;
  385. pSrb->ActualBytesTransferred = 0;
  386. StreamClassStreamNotification(StreamRequestComplete,
  387. pSrb->StreamObject,
  388. pSrb);
  389. return;
  390. }
  391. pSrb->CommandData.DataBufferArray->DataUsed =
  392. pSrb->ActualBytesTransferred = wCount;
  393. // soff = (DWORD)pdw-pHwDevExt->luxbase;
  394. //
  395. // DVReadStr(luxbase,(DWORD)pDest,soff,numb);
  396. memcpy(pDest,USR_Data_Buff,wCount);
  397. pSrb->Status = STATUS_SUCCESS;
  398. pPacket = pSrb->CommandData.DataBufferArray;
  399. pPacket->OptionsFlags = KSSTREAM_HEADER_OPTIONSF_TIMEVALID |
  400. KSSTREAM_HEADER_OPTIONSF_DURATIONVALID;
  401. pSrb->NumberOfBuffers = 1;
  402. pPacket->PresentationTime.Time = ConvertPTStoStrm(DVD_GetSTC());
  403. pPacket->Duration = 1000;
  404. StreamClassStreamNotification(StreamRequestComplete,
  405. pSrb->StreamObject,
  406. pSrb);
  407. // return;
  408. }
  409. }
  410. }
  411. return;
  412. for( i = 0; i < wCount; i++ )
  413. {
  414. Data = USR_Data_Buff[ i ];
  415. switch( wPhase )
  416. {
  417. case 0:
  418. // Check USER_DATA DRAM Sync
  419. if ( ( Data & 0xFFFF0000 ) == 0xFEED0000)//0x0000EDFE )
  420. {
  421. wPhase = 1;
  422. }
  423. break;
  424. case 1:
  425. // Check USER_DATA ID (Closed Caption)
  426. if ( Data == 0xF8014343 )
  427. wPhase = 2;
  428. break;
  429. case 2:
  430. // Get Data Count and Field Flag
  431. CC_Len = * ( ( ( LPBYTE )USR_Data_Buff ) + 8 );
  432. wCount = ( BYTE )( CC_Len & 0x3F );
  433. wCount = (wCount-1)*3 + sizeof(KSGOP_USERDATA);
  434. if (pHwDevExt->pstroCC && ((PSTREAMEX)(pHwDevExt->pstroCC->HwStreamExtension))->state==KSSTATE_RUN )
  435. {
  436. if (pSrb = CCDequeue(pHwDevExt))
  437. {
  438. //
  439. // check the SRB to ensure it can take at least the header
  440. // information from the GOP packet
  441. //
  442. if (pSrb->CommandData.DataBufferArray->FrameExtent < sizeof(KSGOP_USERDATA))
  443. {
  444. pSrb->Status = STATUS_INVALID_BUFFER_SIZE;
  445. pSrb->ActualBytesTransferred = 0;
  446. StreamClassStreamNotification(StreamRequestComplete,
  447. pSrb->StreamObject,
  448. pSrb);
  449. return;
  450. }
  451. pDest = pSrb->CommandData.DataBufferArray->Data;
  452. // move pdw pointer to the size of CC
  453. // pb = ((BYTE*)pdw)+8;
  454. //
  455. // numb = (DWORD)(*pb)&0x3f;
  456. // numb = (numb-1)*3 + sizeof(KSGOP_USERDATA);
  457. //
  458. if (pSrb->CommandData.DataBufferArray->FrameExtent < wCount)
  459. {
  460. pSrb->Status = STATUS_INVALID_BUFFER_SIZE;
  461. pSrb->ActualBytesTransferred = 0;
  462. StreamClassStreamNotification(StreamRequestComplete,
  463. pSrb->StreamObject,
  464. pSrb);
  465. return;
  466. }
  467. pSrb->CommandData.DataBufferArray->DataUsed =
  468. pSrb->ActualBytesTransferred = wCount;
  469. // soff = (DWORD)pdw-pHwDevExt->luxbase;
  470. //
  471. // DVReadStr(luxbase,(DWORD)pDest,soff,numb);
  472. memcpy(pDest,USR_Data_Buff,wCount);
  473. pSrb->Status = STATUS_SUCCESS;
  474. pPacket = pSrb->CommandData.DataBufferArray;
  475. pPacket->OptionsFlags = KSSTREAM_HEADER_OPTIONSF_TIMEVALID |
  476. KSSTREAM_HEADER_OPTIONSF_DURATIONVALID;
  477. pSrb->NumberOfBuffers = 1;
  478. pPacket->PresentationTime.Time = ConvertPTStoStrm(DVD_GetSTC());
  479. pPacket->Duration = 1000;
  480. StreamClassStreamNotification(StreamRequestComplete,
  481. pSrb->StreamObject,
  482. pSrb);
  483. return;
  484. }
  485. }
  486. }
  487. }
  488. // if( *pdw != 0xB2010000)
  489. // {
  490. // pb = (BYTE *)pdw;
  491. // pb++;
  492. // pdw = (DWORD *)pb;
  493. // if( *pdw != 0xB2010000)
  494. // {
  495. // return;
  496. // }
  497. // }
  498. // check if the close caption pin is open and running, and that
  499. // we have a data packet avaiable
  500. }*/
  501. ////////////////////////////////////////////////////////////////////////////////
  502. void CCSendDiscontinuity(PHW_DEVICE_EXTENSION pHwDevExt)
  503. {
  504. PHW_STREAM_REQUEST_BLOCK pSrb;
  505. PKSSTREAM_HEADER pPacket;
  506. if (pHwDevExt->pstroCC && ((PSTREAMEX)(pHwDevExt->pstroCC->HwStreamExtension))->state == KSSTATE_RUN )
  507. {
  508. if (pSrb = CCDequeue(pHwDevExt))
  509. {
  510. // we have a request, send a discontinuity
  511. pSrb->Status = STATUS_SUCCESS;
  512. pPacket = pSrb->CommandData.DataBufferArray;
  513. pPacket->OptionsFlags = KSSTREAM_HEADER_OPTIONSF_DATADISCONTINUITY |
  514. KSSTREAM_HEADER_OPTIONSF_TIMEVALID | KSSTREAM_HEADER_OPTIONSF_DURATIONVALID;
  515. pPacket->DataUsed = 0;
  516. pSrb->NumberOfBuffers = 0;
  517. pPacket->PresentationTime.Time = ConvertPTStoStrm(DVD_GetSTC());
  518. pPacket->Duration = 1000;
  519. StreamClassStreamNotification(StreamRequestComplete,
  520. pSrb->StreamObject,
  521. pSrb);
  522. }
  523. }
  524. }
  525. /*VOID HighPrioritySend( IN PHW_STREAM_REQUEST_BLOCK pSrb )
  526. {
  527. StreamClassStreamNotification(StreamRequestComplete,
  528. pSrb->StreamObject,
  529. pSrb);
  530. }*/
  531. /*VOID PassiveSend(IN PHW_STREAM_REQUEST_BLOCK pSrb )
  532. {
  533. PBYTE pDest;
  534. // PHW_STREAM_REQUEST_BLOCK pSrb;
  535. PKSSTREAM_HEADER pPacket;
  536. DWORD *pdw;
  537. BYTE *pb;
  538. DWORD dwData;
  539. PHW_DEVICE_EXTENSION pHwDevExt = (PHW_DEVICE_EXTENSION)pSrb->HwDeviceExtension;
  540. dwData = pHwDevExt->dwUserDataBuffer[0];
  541. if( (dwData & 0xFFFF0000 ) == 0xFEED0000)
  542. MonoOutStr("Feed");
  543. if(pHwDevExt->dwUserDataBuffer[1] == 0x434301F8)
  544. MonoOutStr("CCID");
  545. // check if the close caption pin is open and running, and that
  546. // we have a data packet avaiable
  547. if (pHwDevExt->pstroCC && ((PSTREAMEX)(pHwDevExt->pstroCC->HwStreamExtension))->state==KSSTATE_RUN )
  548. {
  549. // if (pSrb = CCDequeue(pHwDevExt))
  550. {
  551. //
  552. // check the SRB to ensure it can take at least the header
  553. // information from the GOP packet
  554. //
  555. if (pSrb->CommandData.DataBufferArray->FrameExtent < sizeof(KSGOP_USERDATA))
  556. {
  557. pSrb->Status = STATUS_INVALID_BUFFER_SIZE;
  558. pSrb->ActualBytesTransferred = 0;
  559. StreamClassCallAtNewPriority(NULL, pHwDevExt, LowToHigh, HighPrioritySend, pSrb);
  560. return;
  561. }
  562. pDest = pSrb->CommandData.DataBufferArray->Data;
  563. // move pdw pointer to the size of CC
  564. pb = ((BYTE*)pdw)+8;
  565. // numb = (DWORD)(*pb)&0x3f;
  566. // numb = (numb-1)*3 + sizeof(KSGOP_USERDATA);
  567. numb = pHwDevExt->dwUserDataBufferSize;
  568. if (pSrb->CommandData.DataBufferArray->FrameExtent < numb)
  569. {
  570. pSrb->Status = STATUS_INVALID_BUFFER_SIZE;
  571. pSrb->ActualBytesTransferred = 0;
  572. StreamClassCallAtNewPriority(NULL, pHwDevExt, LowToHigh, HighPrioritySend, pSrb);
  573. MonoOutStr("Size<Req. ");
  574. return;
  575. }
  576. pSrb->CommandData.DataBufferArray->DataUsed = pSrb->ActualBytesTransferred = numb;
  577. RtlCopyMemory(pDest,pHwDevExt->pDiscKeyBufferLinear,numb);
  578. pSrb->Status = STATUS_SUCCESS;
  579. pPacket = pSrb->CommandData.DataBufferArray;
  580. pPacket->OptionsFlags = KSSTREAM_HEADER_OPTIONSF_TIMEVALID |
  581. KSSTREAM_HEADER_OPTIONSF_DURATIONVALID;
  582. pSrb->NumberOfBuffers = 1;
  583. pPacket->PresentationTime.Time = ConvertPTStoStrm(DVD_GetSTC());
  584. pPacket->Duration = 1000;
  585. StreamClassCallAtNewPriority(NULL, pHwDevExt, LowToHigh, HighPrioritySend, pSrb);
  586. return;
  587. }
  588. }
  589. }*/
  590. /*void BeginSendingData(IN PHW_STREAM_REQUEST_BLOCK pSrb)
  591. {
  592. PHW_DEVICE_EXTENSION pHwDevExt = (PHW_DEVICE_EXTENSION)pSrb->HwDeviceExtension;
  593. StreamClassCallAtNewPriority(NULL, pHwDevExt, Low, PassiveSend, pSrb);
  594. return;
  595. }*/
  596. ////////////////////////////////////////////////////////////////////////////////
  597. void UserDataEvents(PHW_DEVICE_EXTENSION pHwDevExt)
  598. {
  599. DWORD dwUserGopSize;
  600. PBYTE pDest;
  601. PHW_STREAM_REQUEST_BLOCK pSrb;
  602. PKSSTREAM_HEADER pPacket;
  603. int i=0;
  604. BOOL fCCData = FALSE;
  605. fCCData = ZivaHw_GetUserData(pHwDevExt);
  606. if(!fCCData )
  607. {
  608. MonoOutStr(" ReturnBecauseOfNoCCID ");
  609. return;
  610. }
  611. /* if(pHwDevExt->dwUserDataBufferSize == 0)
  612. {
  613. MonoOutStr(" ReturnBecauseOfNoData ");
  614. return;
  615. }
  616. else
  617. /* {
  618. RtlCopyMemory((void*)pHwDevExt->pDiscKeyBufferLinear,(void*)pHwDevExt->dwUserDataBuffer,pHwDevExt->dwUserDataBufferSize );
  619. if (pSrb = CCDequeue(pHwDevExt))
  620. {
  621. BeginSendingData(pSrb);
  622. return;
  623. }
  624. else
  625. {
  626. MonoOutStr("NoBufInQue");
  627. return;
  628. }
  629. }
  630. {
  631. // RtlCopyMemory((void*)pHwDevExt->pDiscKeyBufferLinear,(void*)pHwDevExt->dwUserDataBuffer,pHwDevExt->dwUserDataBufferSize );
  632. }*/
  633. /* dwData = pHwDevExt->dwUserDataBuffer[0];
  634. dwData = (((dwData & 0x000000FF) << 24) | ((dwData & 0x0000FF00) << 8)
  635. |((dwData & 0x00FF0000) >> 8)|((dwData & 0xFF000000) >> 24));
  636. if( (dwData & 0xFFFF0000 ) == 0xFEED0000)
  637. MonoOutStr(" Feed ");
  638. dwUserDataSize = dwData & 0x00000FFF;
  639. MonoOutStr(" SizeSpecifiedByFirst3Bytes ");
  640. MonoOutULong(dwUserDataSize);
  641. pHwDevExt->dwUserDataBuffer[0]= 0xB2010000;*/
  642. /* if(pHwDevExt->dwUserDataBuffer[1] == 0x434301F8)
  643. {
  644. MonoOutStr(" CCID ");
  645. fCCData = TRUE;
  646. }*/
  647. /* if( *pdw != 0x0000EDFE)
  648. {
  649. pb = (BYTE *)pdw;
  650. pb++;
  651. pdw = (DWORD *)pb;
  652. if( *pdw != 0xB2010000)
  653. {
  654. return;
  655. }
  656. }*/
  657. // check if the close caption pin is open and running, and that
  658. // we have a data packet avaiable
  659. if (fCCData && pHwDevExt->pstroCC && ((PSTREAMEX)(pHwDevExt->pstroCC->HwStreamExtension))->state==KSSTATE_RUN )
  660. {
  661. fCCData = FALSE;
  662. if (pSrb = CCDequeue(pHwDevExt))
  663. {
  664. MonoOutStr(" Dequeued new SRB ");
  665. //
  666. // check the SRB to ensure it can take at least the header
  667. // information from the GOP packet
  668. //
  669. if (pSrb->CommandData.DataBufferArray->FrameExtent < sizeof(KSGOP_USERDATA))
  670. {
  671. pSrb->Status = STATUS_INVALID_BUFFER_SIZE;
  672. pSrb->ActualBytesTransferred = 0;
  673. StreamClassStreamNotification(StreamRequestComplete,
  674. pSrb->StreamObject,
  675. pSrb);
  676. MonoOutStr(" ReturnBecauseSRBSize<KSGOP ");
  677. return;
  678. }
  679. pDest = pSrb->CommandData.DataBufferArray->Data;
  680. // move pdw pointer to the size of CC
  681. // pb = ((BYTE*)pHwDevExt->dwUserDataBuffer)+11;
  682. dwUserGopSize = (pHwDevExt->dwUserDataBuffer[2]&0x0000003F);
  683. // dwUserGopSize = (DWORD)(*pb)&0x3f;
  684. dwUserGopSize = (dwUserGopSize-1)*3 + sizeof(KSGOP_USERDATA);
  685. MonoOutStr(" SizeOfCCData+StartCode+CCID ");
  686. MonoOutULong(dwUserGopSize);
  687. // dwUserGopSize = pHwDevExt->dwUserDataBufferSize;
  688. // dwUserGopSize = dwUserDataSize;
  689. if (pSrb->CommandData.DataBufferArray->FrameExtent < dwUserGopSize)
  690. {
  691. pSrb->Status = STATUS_INVALID_BUFFER_SIZE;
  692. pSrb->ActualBytesTransferred = 0;
  693. StreamClassStreamNotification(StreamRequestComplete,
  694. pSrb->StreamObject,
  695. pSrb);
  696. MonoOutStr(" ReturnBacauseOfSRBBufSize<Req.");
  697. return;
  698. }
  699. pSrb->CommandData.DataBufferArray->DataUsed = pSrb->ActualBytesTransferred = dwUserGopSize;
  700. // *pDest = 's';
  701. RtlCopyMemory(pDest,(PBYTE)pHwDevExt->dwUserDataBuffer,dwUserGopSize);
  702. // for(i =0; i< dwUserGopSize ; i++)
  703. // *pDest++ = *pHwDevExt->pDiscKeyBufferLinear++;
  704. pSrb->Status = STATUS_SUCCESS;
  705. pPacket = pSrb->CommandData.DataBufferArray;
  706. pPacket->OptionsFlags = KSSTREAM_HEADER_OPTIONSF_TIMEVALID |
  707. KSSTREAM_HEADER_OPTIONSF_DURATIONVALID;
  708. pSrb->NumberOfBuffers = 1;
  709. pPacket->PresentationTime.Time = ConvertPTStoStrm(DVD_GetSTC());
  710. pPacket->Duration = 1000;
  711. StreamClassStreamNotification(StreamRequestComplete,
  712. pSrb->StreamObject,
  713. pSrb);
  714. MonoOutStr(" USR Req Complete ");
  715. return;
  716. }
  717. else
  718. {
  719. MonoOutStr(" NoSRBAvailableToFill");
  720. }
  721. }
  722. else
  723. MonoOutStr(" NoCCData/NotInRunState");
  724. }