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.

829 lines
25 KiB

  1. //**************************************************************************
  2. //
  3. // Title : SchDat.cpp
  4. //
  5. // Date : 1998.03.10 1st making
  6. //
  7. // Author : Toshiba [PCS](PSY) Hideki Yagi
  8. //
  9. // Copyright 1997 Toshiba Corporation. All Rights Reserved.
  10. //
  11. // -------------------------------------------------------------------------
  12. //
  13. // Change log :
  14. //
  15. // Date Revision Description
  16. // ------------ ---------- -----------------------------------------------
  17. // 1998.03.10 000.0000 1st making.
  18. //
  19. //**************************************************************************
  20. #include "includes.h"
  21. #include "hal.h"
  22. #include "wdmkserv.h"
  23. #include "mpevent.h"
  24. #include "classlib.h"
  25. #include "ctime.h"
  26. #include "schdat.h"
  27. #include "ccque.h"
  28. #include "ctvctrl.h"
  29. #include "hlight.h"
  30. #include "hwdevex.h"
  31. #include "wdmbuff.h"
  32. #include "dvdinit.h"
  33. VOID ScanCallBack( PHW_DEVICE_EXTENSION pHwDevExt );
  34. CScheduleData::CScheduleData( void )
  35. {
  36. count = 0;
  37. pTopSrb = pBottomSrb = NULL;
  38. fScanCallBack = FALSE;
  39. #ifndef REARRANGEMENT
  40. InitRearrangement();
  41. #endif REARRANGEMENT
  42. }
  43. CScheduleData::~CScheduleData( void )
  44. {
  45. count = 0;
  46. pTopSrb = pBottomSrb = NULL;
  47. fScanCallBack = FALSE;
  48. }
  49. BOOL CScheduleData::Init( void )
  50. {
  51. count = 0;
  52. pTopSrb = pBottomSrb = NULL;
  53. fScanCallBack = FALSE;
  54. KeInitializeEvent( &m_Event,
  55. SynchronizationEvent,
  56. FALSE //TRUE,
  57. );
  58. #ifndef REARRANGEMENT
  59. InitRearrangement();
  60. #endif REARRANGEMENT
  61. return( TRUE );
  62. }
  63. BOOL CScheduleData::SendData( PHW_STREAM_REQUEST_BLOCK pSrb )
  64. //------------------------------------packet rearrangement code--------------------------------
  65. #ifndef REARRANGEMENT
  66. {
  67. KSSTREAM_HEADER * pHeader;
  68. WORD wOrderNumber = 0;
  69. WORD wReadPacketNumber = 0, wWdmBuffptr = 0, wDvdDataptr = 0, wSrbCounter = 0;
  70. WORD wLateNumber = 0;
  71. BOOL bLateData = FALSE;
  72. ULONG ulNumber = 0;
  73. ASSERT( pSrb != NULL );
  74. ASSERT( pSrb->SRBExtension != NULL );
  75. //------------------packet partition---------------
  76. for( ulNumber = 0; ulNumber < pSrb->NumberOfBuffers; ulNumber++ )
  77. {
  78. pHeader = ((PKSSTREAM_HEADER)pSrb->CommandData.DataBufferArray) + ulNumber;
  79. wOrderNumber = (WORD)(pHeader->TypeSpecificFlags >> 16); //get packet number
  80. DBG_PRINTF( ("DVDWDM:ScheduleData::SendData-Start--- pSrb=%x m_SendPacketNumber=%x wOrderNumber=%x\n\r", pSrb,m_SendPacketNumber,wOrderNumber));
  81. if ((ulNumber == 0) && (pSrb->Status == STATUS_PENDING))
  82. {
  83. if (m_SendPacketNumber == 0)
  84. {
  85. m_SendPacketNumber = wOrderNumber;
  86. if (wOrderNumber != 0)
  87. {
  88. WORD InvalidDataCnt;
  89. for(InvalidDataCnt = 0; InvalidDataCnt < wOrderNumber; InvalidDataCnt++)
  90. {
  91. if( m_bDvdDataTable[InvalidDataCnt] == INVALID_DVD_DATA)
  92. m_bDvdDataTable[InvalidDataCnt] = INIT_DVD_DATA;
  93. }
  94. }
  95. }
  96. wReadPacketNumber = wOrderNumber; //set original data
  97. wWdmBuffptr = 0; //init packet partition counter
  98. SetWdmBuff(pSrb, wWdmBuffptr, wReadPacketNumber, ulNumber);
  99. //---------------Late data check-----------
  100. if (((m_SendPacketNumber < 0x1000) && ((wOrderNumber < m_SendPacketNumber) || (wOrderNumber > (m_SendPacketNumber + 0xf000))))
  101. || ((m_SendPacketNumber >= 0x1000) && (((m_SendPacketNumber - 0x1000) < wOrderNumber) && (wOrderNumber < m_SendPacketNumber))))
  102. {
  103. wLateNumber = wOrderNumber;
  104. bLateData = TRUE;
  105. }
  106. }
  107. //---------------Set DVD data table--------
  108. if (pSrb->Status == STATUS_PENDING)
  109. m_bDvdDataTable[wOrderNumber] = VALID_DVD_DATA; //valid DVD data receive
  110. else
  111. {
  112. if (((m_SendPacketNumber < 0x1000) && ((wOrderNumber < m_SendPacketNumber) || (wOrderNumber > (m_SendPacketNumber + 0xf000))))
  113. || ((m_SendPacketNumber >= 0x1000) && (((m_SendPacketNumber - 0x1000) < wOrderNumber) && (wOrderNumber < m_SendPacketNumber))))
  114. {
  115. m_bDvdDataTable[wOrderNumber] = INIT_DVD_DATA; //invalid DVD data(Late) receive
  116. }
  117. else
  118. {
  119. m_bDvdDataTable[wOrderNumber] = INVALID_DVD_DATA; //invalid DVD data receive
  120. }
  121. DBG_PRINTF( ("DVDWDM:ScheduleData::SendData---InvalidData wOrderNumber = %x\n\r", wOrderNumber));
  122. return(TRUE);
  123. }
  124. if (wReadPacketNumber != wOrderNumber) //packet number continuity check
  125. { //packet partition
  126. (((PSRB_EXTENSION)(pSrb->SRBExtension))->m_wdmbuff[wWdmBuffptr]).m_EndFlag = FALSE;
  127. (((PSRB_EXTENSION)(pSrb->SRBExtension))->m_wdmbuff[wWdmBuffptr]).m_PacketNum =
  128. (WORD)(wReadPacketNumber - (((PSRB_EXTENSION)(pSrb->SRBExtension))->m_wdmbuff[wWdmBuffptr]).m_StartPacketNumber);
  129. wWdmBuffptr++; //packet partition counter up
  130. wReadPacketNumber = wOrderNumber; //set original data
  131. SetWdmBuff(pSrb, wWdmBuffptr, wReadPacketNumber, ulNumber);
  132. }
  133. if (wReadPacketNumber == (DVD_DATA_MAX - 1)) wReadPacketNumber = 0;
  134. else wReadPacketNumber++;
  135. ASSERT (wWdmBuffptr != WDM_BUFFER_MAX);
  136. }
  137. //last packet number institution
  138. (((PSRB_EXTENSION)(pSrb->SRBExtension))->m_wdmbuff[wWdmBuffptr]).m_PacketNum =
  139. (WORD)(wReadPacketNumber - (((PSRB_EXTENSION)(pSrb->SRBExtension))->m_wdmbuff[wWdmBuffptr]).m_StartPacketNumber);
  140. //--------------save srb pointer----------------
  141. wSrbCounter = SetSrbPointerTable( pSrb );
  142. ASSERT (wSrbCounter != SRB_POINTER_MAX);
  143. if (wSrbCounter == SRB_POINTER_MAX)
  144. return(FALSE);
  145. //--------------------------------receive-end------------------------------------
  146. //--------------------------------send-start-------------------------------------
  147. for(;;) //send packet
  148. {
  149. if ((wSrbCounter > 0x20) && (m_bDvdDataTable[m_SendPacketNumber] == INIT_DVD_DATA))
  150. {
  151. DBG_PRINTF( ("DVDWDM:ScheduleData::wSrbCounter > 3\n\r"));
  152. for( wDvdDataptr = 0; wDvdDataptr < DVD_DATA_MAX; wDvdDataptr++)
  153. {
  154. if (m_bDvdDataTable[m_SendPacketNumber] != INIT_DVD_DATA)
  155. break;
  156. IncSendPacketNumber();
  157. }
  158. }
  159. wSrbCounter = 0;
  160. SkipInvalidDvdData();
  161. //-----------------LateData Send ---------------------------
  162. if (bLateData == TRUE)
  163. {
  164. WORD CheckMax;
  165. DBG_PRINTF( ("DVDWDM:ScheduleData::LateData Start\n\r"));
  166. if (m_SendPacketNumber == 0) CheckMax = (WORD)(DVD_DATA_MAX - 1);
  167. else CheckMax = (WORD)(m_SendPacketNumber - 1);
  168. for( ;wLateNumber != CheckMax;)
  169. {
  170. if( m_bDvdDataTable[wLateNumber] == VALID_DVD_DATA)
  171. SendPacket(wLateNumber);
  172. if (wLateNumber == (DVD_DATA_MAX - 1)) wLateNumber = 0;
  173. else wLateNumber++;
  174. }
  175. bLateData = FALSE;
  176. DBG_PRINTF( ("DVDWDM:ScheduleData::LateData End\n\r"));
  177. }
  178. //-----------
  179. if( m_bDvdDataTable[m_SendPacketNumber] != VALID_DVD_DATA)
  180. break;
  181. //-----------------search send packet & SendData------------
  182. BOOL ret = SendPacket(m_SendPacketNumber);
  183. ASSERT (ret != FALSE);
  184. if (ret == FALSE)
  185. {
  186. IncSendPacketNumber();
  187. return(FALSE);
  188. }
  189. } //End For
  190. return( TRUE );
  191. }
  192. #else
  193. //------------------------------------before code--------------------------------
  194. {
  195. PHW_DEVICE_EXTENSION pHwDevExt;
  196. PKSSTREAM_HEADER pStruc;
  197. IMPEGBuffer *MPBuff;
  198. // PHW_STREAM_REQUEST_BLOCK pTmpSrb;
  199. DWORD WaitTime=0;
  200. ASSERT( pSrb != NULL );
  201. ASSERT( pSrb->SRBExtension != NULL );
  202. pHwDevExt = (PHW_DEVICE_EXTENSION)pSrb->HwDeviceExtension;
  203. pStruc = &((PKSSTREAM_HEADER)(pSrb->CommandData.DataBufferArray))[0];
  204. MPBuff = &(((PSRB_EXTENSION)(pSrb->SRBExtension))->m_wdmbuff);
  205. ASSERT( pHwDevExt != NULL );
  206. ASSERT( pStruc != NULL );
  207. ASSERT( MPBuff );
  208. DBG_PRINTF( ("DVDWDM:ScheduleData--- pHwDevExt->Rate=%d\n\r", pHwDevExt->Rate ));
  209. // F.F. or F.R.
  210. if( pHwDevExt->Rate < 10000 ){
  211. // FastSlowControl( pSrb ); // Modify PTS/DTS
  212. putSRB( pSrb );
  213. if( fScanCallBack==FALSE ){ // 1st time putting SRB?
  214. DWORD pts = GetDataPTS( pStruc );
  215. if( pts!=0xffffffff )
  216. {
  217. // pHwDevExt->ticktime.SetStreamTime( (ULONGLONG)pts * 1000 / 9 );
  218. WaitTime = pHwDevExt->scheduler.calcWaitTime( pSrb );
  219. if( WaitTime==0 ){
  220. WaitTime = 1;
  221. }
  222. //--- 98.09.17 S.Watanabe
  223. }
  224. else {
  225. WaitTime = 1;
  226. }
  227. //--- End.
  228. StreamClassScheduleTimer( pHwDevExt->pstroVid,
  229. pHwDevExt,
  230. WaitTime*1000,
  231. (PHW_TIMER_ROUTINE)ScanCallBack,
  232. pHwDevExt
  233. );
  234. fScanCallBack = TRUE;
  235. //--- 98.09.17 S.Watanabe
  236. // };
  237. // return( TRUE );
  238. //--- End.
  239. }
  240. }else{
  241. pHwDevExt->dvdstrm.SendData( MPBuff );
  242. }
  243. return( TRUE );
  244. }
  245. #endif REARRANGEMENT
  246. DWORD CScheduleData::GetDataPTS( PKSSTREAM_HEADER pStruc )
  247. {
  248. PUCHAR pDat;
  249. DWORD pts = 0xffffffff;
  250. if( pStruc->DataUsed ){
  251. pDat = (PUCHAR)pStruc->Data;
  252. if( *(pDat+21) & 0x80 ){
  253. pts = 0;
  254. pts += ((DWORD)(*(pDat+23)& 0x0E) ) << 29;
  255. pts += ((DWORD)(*(pDat+24)& 0xFF) ) << 22;
  256. pts += ((DWORD)(*(pDat+25)& 0xFE) ) << 14;
  257. pts += ((DWORD)(*(pDat+26)& 0xFF) ) << 7;
  258. pts += ((DWORD)(*(pDat+27)& 0xFE) ) >> 1;
  259. }
  260. }
  261. return( pts );
  262. }
  263. DWORD CScheduleData::calcWaitTime( PHW_STREAM_REQUEST_BLOCK pSrb )
  264. {
  265. PHW_DEVICE_EXTENSION pHwDevExt;
  266. PKSSTREAM_HEADER pStruc;
  267. pHwDevExt = (PHW_DEVICE_EXTENSION)pSrb->HwDeviceExtension;
  268. pStruc = &((PKSSTREAM_HEADER)(pSrb->CommandData.DataBufferArray))[0];
  269. DWORD WaitTime, pts, DataStrm;
  270. WaitTime = DataStrm= 0;
  271. // Get PTS value from data.
  272. pts = GetDataPTS( pStruc );
  273. if( pts!=0xffffffff ){
  274. DBG_PRINTF( ("DVDWDM: Data PTS = 0x%08x\n\r", pts) );
  275. DWORD dwstc;
  276. if( pHwDevExt->ticktime.GetStreamSTC( &dwstc ) ){
  277. DBG_PRINTF( ("DVDWDM: Borad STC = 0x%08x\n\r", dwstc) );
  278. if( dwstc < pts ){
  279. WaitTime = (pts - dwstc)/90; // ms unit
  280. WaitTime = WaitTime / (10000 / pHwDevExt->Rate );
  281. }
  282. }else{
  283. WaitTime = 0;
  284. }
  285. DBG_PRINTF( ("DVDWDM: Schedule Data---- WaitTime =0x%08x WaitTime(ms)=%0d\n\r", WaitTime, WaitTime ) );
  286. }
  287. //--- 98.09.07 S.Watanabe
  288. //--- 98.09.17 S.Watanabe
  289. // if( WaitTime > 300 ) {
  290. if( WaitTime > 500 ) {
  291. //--- End.
  292. DBG_PRINTF( ("DVDWDM: Invalid WaitTime!! change to 1ms!!\n\r" ) );
  293. WaitTime = 1;
  294. }
  295. //--- End.
  296. return( WaitTime );
  297. }
  298. void CScheduleData::putSRB( PHW_STREAM_REQUEST_BLOCK pSrb )
  299. {
  300. pSrb->NextSRB = NULL;
  301. if( pTopSrb == NULL ){
  302. pTopSrb = pBottomSrb = pSrb;
  303. count++;
  304. return;
  305. }
  306. pBottomSrb->NextSRB = pSrb;
  307. pBottomSrb = pSrb;
  308. count++;
  309. return;
  310. }
  311. PHW_STREAM_REQUEST_BLOCK CScheduleData::getSRB( void )
  312. {
  313. PHW_STREAM_REQUEST_BLOCK pTmp;
  314. if( pTopSrb==NULL ){
  315. return( NULL );
  316. }
  317. pTmp = pTopSrb;
  318. pTopSrb = pTopSrb->NextSRB;
  319. count--;
  320. if( count==0 ){
  321. pTopSrb = pBottomSrb = NULL;
  322. fScanCallBack = FALSE;
  323. }
  324. return( pTmp );
  325. }
  326. PHW_STREAM_REQUEST_BLOCK CScheduleData::checkTopSRB( void )
  327. {
  328. return( pTopSrb );
  329. }
  330. void CScheduleData::flushSRB()
  331. {
  332. PHW_STREAM_REQUEST_BLOCK pTmp;
  333. if( pTopSrb==NULL){
  334. return;
  335. }
  336. pTmp = getSRB();
  337. while( pTmp != NULL ){
  338. pTmp = getSRB();
  339. }
  340. //--- 98.09.17 S.Watanabe
  341. // fScanCallBack = TRUE;
  342. fScanCallBack = FALSE;
  343. //--- End.
  344. }
  345. void CScheduleData::FastSlowControl( PHW_STREAM_REQUEST_BLOCK pSrb )
  346. {
  347. PHW_DEVICE_EXTENSION pHwDevExt;
  348. ULONG i;
  349. PKSSTREAM_HEADER pStruc;
  350. PUCHAR pDat;
  351. LONGLONG pts, dts, tmp;
  352. LONG Rate;
  353. LONGLONG start;
  354. REFERENCE_TIME InterceptTime;
  355. pts = dts = tmp = 0;
  356. pHwDevExt = (PHW_DEVICE_EXTENSION)pSrb->HwDeviceExtension;
  357. for( i=0; i<pSrb->NumberOfBuffers; i++ ){
  358. pStruc = &((PKSSTREAM_HEADER)(pSrb->CommandData.DataBufferArray))[i];
  359. if( pStruc->DataUsed ){
  360. pDat = (PUCHAR)pStruc->Data;
  361. if( *(pDat+21) & 0x80 ){
  362. pts += ((DWORD)(*(pDat+23) & 0x0E)) << 29;
  363. pts += ((DWORD)(*(pDat+24) & 0xFF)) << 22;
  364. pts += ((DWORD)(*(pDat+25) & 0xFE)) << 14;
  365. pts += ((DWORD)(*(pDat+26) & 0xFF)) << 7;
  366. pts += ((DWORD)(*(pDat+27) & 0xFE)) >> 1;
  367. }
  368. }
  369. }
  370. pts = 0;
  371. if( pHwDevExt->Rate < 10000 ){
  372. Rate = pHwDevExt->Rate;
  373. InterceptTime = pHwDevExt->InterceptTime;
  374. start = pHwDevExt->StartTime * 9 / 1000;
  375. for( i=0; i<pSrb->NumberOfBuffers; i++ ){
  376. pStruc = &((PKSSTREAM_HEADER)(pSrb->CommandData.DataBufferArray))[i];
  377. if( pStruc->DataUsed ){
  378. pDat = (PUCHAR)pStruc->Data;
  379. // PTS modify
  380. if( *(pDat+21) & 0x80 ){
  381. pts += ((DWORD)(*(pDat+23) & 0x0E)) << 29;
  382. pts += ((DWORD)(*(pDat+24) & 0xFF)) << 22;
  383. pts += ((DWORD)(*(pDat+25) & 0xFE)) << 14;
  384. pts += ((DWORD)(*(pDat+26) & 0xFF)) << 7;
  385. pts += ((DWORD)(*(pDat+27) & 0xFE)) >> 1;
  386. tmp = pts;
  387. pts = Rate * ( pts-(InterceptTime * 9/ 1000) )/10000;
  388. *(pDat+23) = (UCHAR)(((pts & 0xC0000000) >> 29 ) | 0x11);
  389. *(pDat+24) = (UCHAR)(((pts & 0x3FC00000) >> 22 ) | 0x00);
  390. *(pDat+25) = (UCHAR)(((pts & 0x003F8000) >> 14 ) | 0x01);
  391. *(pDat+26) = (UCHAR)(((pts & 0x00007F80) >> 7 ) | 0x00);
  392. *(pDat+27) = (UCHAR)(((pts & 0x0000007F) << 1 ) | 0x01);
  393. }
  394. // DTS modify
  395. if( *(pDat+17) == 0xE0 ){
  396. if( (*(pDat+21) & 0xC0) == 0xC0 ){
  397. dts += ((DWORD)(*(pDat+28) & 0x0E)) << 29;
  398. dts += ((DWORD)(*(pDat+29) & 0xFF)) << 22;
  399. dts += ((DWORD)(*(pDat+30) & 0xFE)) << 14;
  400. dts += ((DWORD)(*(pDat+31) & 0xFF)) << 7;
  401. dts += ((DWORD)(*(pDat+32) & 0xFE)) >> 1;
  402. dts = pts - (tmp - dts);
  403. *(pDat+28) = (UCHAR)(((dts & 0xC0000000) >> 29 ) | 0x11);
  404. *(pDat+29) = (UCHAR)(((dts & 0x3FC00000) >> 22 ) | 0x00);
  405. *(pDat+30) = (UCHAR)(((dts & 0x003F8000) >> 14 ) | 0x01);
  406. *(pDat+31) = (UCHAR)(((dts & 0x00007F80) >> 7 ) | 0x00);
  407. *(pDat+32) = (UCHAR)(((dts & 0x0000007F) << 1 ) | 0x01);
  408. }
  409. }
  410. }
  411. }
  412. }
  413. }
  414. BOOL CScheduleData::removeSRB( PHW_STREAM_REQUEST_BLOCK pSrb )
  415. {
  416. if( pTopSrb==NULL ){
  417. return( FALSE );
  418. }
  419. if( pTopSrb == pSrb ){
  420. pTopSrb = pTopSrb->NextSRB;
  421. count--;
  422. // 1998.8.21 S.Watanabe
  423. // if( count==0 )
  424. // pTopSrb = pBottomSrb = NULL;
  425. if( count==0 ) {
  426. pTopSrb = pBottomSrb = NULL;
  427. fScanCallBack = FALSE;
  428. }
  429. // End
  430. return( TRUE );
  431. }
  432. PHW_STREAM_REQUEST_BLOCK srbPrev;
  433. PHW_STREAM_REQUEST_BLOCK srb;
  434. srbPrev = pTopSrb;
  435. srb = srbPrev->NextSRB;
  436. while( srb!=NULL ){
  437. if( srb==pSrb ){
  438. srbPrev->NextSRB = srb->NextSRB;
  439. // 1998.8.21 S.Watanabe
  440. // if( srbPrev->NextSRB == pBottomSrb ){
  441. if( srb == pBottomSrb ){
  442. // End
  443. pBottomSrb = srbPrev;
  444. }
  445. count--;
  446. return( TRUE );
  447. }
  448. srbPrev = srb;
  449. srb = srbPrev->NextSRB;
  450. }
  451. return( FALSE );
  452. }
  453. void ScanCallBack( PHW_DEVICE_EXTENSION pHwDevExt )
  454. {
  455. DBG_PRINTF( ("DVDWDM: ScanCallBack\n\r") );
  456. PKSSTREAM_HEADER pStruc = NULL;
  457. IMPEGBuffer *MPBuff = NULL;
  458. PHW_STREAM_REQUEST_BLOCK pTmpSrb = NULL;
  459. DWORD WaitTime=0;
  460. LIBSTATE strmState;
  461. DWORD pts;
  462. #ifndef REARRANGEMENT
  463. WORD wWdmBuffptr;
  464. #endif REARRANGEMENT
  465. ASSERT( pHwDevExt != NULL );
  466. pHwDevExt->kserv.DisableHwInt();
  467. pTmpSrb = pHwDevExt->scheduler.getSRB();
  468. if( pTmpSrb == NULL ){
  469. pHwDevExt->scheduler.fScanCallBack = FALSE;
  470. pHwDevExt->kserv.EnableHwInt();
  471. return;
  472. }else{
  473. pStruc = &((PKSSTREAM_HEADER)(pTmpSrb->CommandData.DataBufferArray))[0];
  474. pts = pHwDevExt->scheduler.GetDataPTS( pStruc );
  475. if( pts!=0xffffffff )
  476. pHwDevExt->ticktime.SetStreamTime( (ULONGLONG)pts * 1000 / 9 );
  477. #ifndef REARRANGEMENT
  478. for( wWdmBuffptr = 0; wWdmBuffptr < WDM_BUFFER_MAX; wWdmBuffptr++)
  479. {
  480. MPBuff = &(((PSRB_EXTENSION)(pTmpSrb->SRBExtension))->m_wdmbuff[wWdmBuffptr]);
  481. ASSERT( MPBuff );
  482. strmState = pHwDevExt->dvdstrm.GetState();
  483. if( strmState!=Stop && strmState!=PowerOff )
  484. {
  485. if ((((PSRB_EXTENSION)(pTmpSrb->SRBExtension))->m_wdmbuff[wWdmBuffptr]).m_Enable == TRUE)
  486. {
  487. pHwDevExt->dvdstrm.SendData( MPBuff );
  488. (((PSRB_EXTENSION)(pTmpSrb->SRBExtension))->m_wdmbuff[wWdmBuffptr]).m_Enable = FALSE;
  489. break;
  490. }
  491. }
  492. if ((((PSRB_EXTENSION)(pTmpSrb->SRBExtension))->m_wdmbuff[wWdmBuffptr]).m_EndFlag == TRUE)
  493. {
  494. break; //last buffer
  495. }
  496. }
  497. #else
  498. MPBuff = &(((PSRB_EXTENSION)(pTmpSrb->SRBExtension))->m_wdmbuff);
  499. ASSERT( MPBuff );
  500. strmState = pHwDevExt->dvdstrm.GetState();
  501. if( strmState!=Stop && strmState!=PowerOff ){
  502. pHwDevExt->dvdstrm.SendData( MPBuff );
  503. }
  504. #endif REARRANGEMENT
  505. }
  506. while( (pTmpSrb = pHwDevExt->scheduler.checkTopSRB())!=NULL ){
  507. pStruc = &((PKSSTREAM_HEADER)(pTmpSrb->CommandData.DataBufferArray))[0];
  508. // Check PTS is valid
  509. pts = pHwDevExt->scheduler.GetDataPTS( pStruc );
  510. if( pts!=0xffffffff ){
  511. WaitTime = pHwDevExt->scheduler.calcWaitTime( pTmpSrb );
  512. if( WaitTime==0 ){
  513. WaitTime = 1;
  514. }
  515. StreamClassScheduleTimer( pHwDevExt->pstroVid,
  516. pHwDevExt,
  517. WaitTime*1000,
  518. (PHW_TIMER_ROUTINE)ScanCallBack,
  519. pHwDevExt
  520. );
  521. pHwDevExt->kserv.EnableHwInt();
  522. return;
  523. }else{
  524. pTmpSrb = pHwDevExt->scheduler.getSRB();
  525. #ifndef REARRANGEMENT
  526. for( wWdmBuffptr = 0; wWdmBuffptr < WDM_BUFFER_MAX; wWdmBuffptr++)
  527. {
  528. MPBuff = &(((PSRB_EXTENSION)(pTmpSrb->SRBExtension))->m_wdmbuff[wWdmBuffptr]);
  529. ASSERT( MPBuff );
  530. strmState = pHwDevExt->dvdstrm.GetState();
  531. if( strmState!=Stop && strmState!=PowerOff )
  532. {
  533. if ((((PSRB_EXTENSION)(pTmpSrb->SRBExtension))->m_wdmbuff[wWdmBuffptr]).m_Enable == TRUE)
  534. {
  535. pHwDevExt->dvdstrm.SendData( MPBuff );
  536. (((PSRB_EXTENSION)(pTmpSrb->SRBExtension))->m_wdmbuff[wWdmBuffptr]).m_Enable = FALSE;
  537. break;
  538. }
  539. }
  540. if ((((PSRB_EXTENSION)(pTmpSrb->SRBExtension))->m_wdmbuff[wWdmBuffptr]).m_EndFlag == TRUE)
  541. {
  542. break; //last buffer
  543. }
  544. }
  545. #else
  546. MPBuff = &(((PSRB_EXTENSION)(pTmpSrb->SRBExtension))->m_wdmbuff);
  547. ASSERT( MPBuff );
  548. strmState = pHwDevExt->dvdstrm.GetState();
  549. if( strmState!=Stop && strmState!=PowerOff ){
  550. pHwDevExt->dvdstrm.SendData( MPBuff );
  551. }
  552. #endif REARRANGEMENT
  553. }
  554. }
  555. pHwDevExt->scheduler.fScanCallBack = FALSE;
  556. pHwDevExt->kserv.EnableHwInt();
  557. }
  558. #ifndef REARRANGEMENT
  559. void CScheduleData::InitRearrangement(void)
  560. {
  561. memset(m_bDvdDataTable, INIT_DVD_DATA, DVD_DATA_MAX);
  562. memset(m_SrbPointerTable, NULL, SRB_POINTER_MAX * 4);
  563. m_SendPacketNumber = 0;
  564. }
  565. WORD CScheduleData::SetSrbPointerTable( PHW_STREAM_REQUEST_BLOCK pSrb )
  566. {
  567. WORD wSrbptr;
  568. for( wSrbptr = 0; wSrbptr < SRB_POINTER_MAX; wSrbptr++) //search empty for SRB pointer table
  569. {
  570. if (m_SrbPointerTable[wSrbptr] == NULL)
  571. {
  572. m_SrbPointerTable[wSrbptr] = (LONG)pSrb; //set SRB pointer
  573. break;
  574. }
  575. }
  576. DBG_PRINTF( ("DVDWDM:ScheduleData::SetSrbPointerTable--- m_SrbPointerTable[%x]=%x\n\r", wSrbptr,pSrb));
  577. ASSERT(wSrbptr != SRB_POINTER_MAX);
  578. return(wSrbptr);
  579. }
  580. void CScheduleData::SkipInvalidDvdData(void)
  581. {
  582. WORD wDvdDataptr;
  583. for( wDvdDataptr = 0; wDvdDataptr < DVD_DATA_MAX; wDvdDataptr++)
  584. {
  585. if (m_bDvdDataTable[m_SendPacketNumber] != INVALID_DVD_DATA)
  586. break;
  587. m_bDvdDataTable[m_SendPacketNumber] = INIT_DVD_DATA;
  588. IncSendPacketNumber();
  589. DBG_PRINTF( ("DVDWDM:ScheduleData::SkipInvalidDvdData--- SKIP\n\r"));
  590. }
  591. DBG_PRINTF( ("DVDWDM:ScheduleData::SkipInvalidDvdData--- m_SendPacketNumber=%x\n\r", m_SendPacketNumber));
  592. }
  593. void CScheduleData::SetWdmBuff(PHW_STREAM_REQUEST_BLOCK pSrb, WORD wWdmBuffptr, WORD wReadPacketNumber, ULONG ulNumber)
  594. {
  595. (((PSRB_EXTENSION)(pSrb->SRBExtension))->m_wdmbuff[wWdmBuffptr]).m_BuffNumber = wWdmBuffptr;
  596. (((PSRB_EXTENSION)(pSrb->SRBExtension))->m_wdmbuff[wWdmBuffptr]).m_EndFlag = TRUE;
  597. (((PSRB_EXTENSION)(pSrb->SRBExtension))->m_wdmbuff[wWdmBuffptr]).m_StartPacketNumber = wReadPacketNumber;
  598. (((PSRB_EXTENSION)(pSrb->SRBExtension))->m_wdmbuff[wWdmBuffptr]).m_BeforePacketNum = (WORD)ulNumber;
  599. (((PSRB_EXTENSION)(pSrb->SRBExtension))->m_wdmbuff[wWdmBuffptr]).m_Enable = TRUE;
  600. DBG_PRINTF( ("DVDWDM:ScheduleData::SetWdmBuff--- Srb = %x m_wdmbuff[%x].m_StartPacketNumber=%x\n\r", pSrb,wWdmBuffptr,wReadPacketNumber));
  601. }
  602. void CScheduleData::IncSendPacketNumber(void)
  603. {
  604. m_SendPacketNumber++;
  605. if (m_SendPacketNumber >= DVD_DATA_MAX)
  606. m_SendPacketNumber = 0;
  607. }
  608. void CScheduleData::SendWdmBuff(PHW_STREAM_REQUEST_BLOCK pWorkSrb, IMPEGBuffer *MPBuff)
  609. {
  610. PHW_DEVICE_EXTENSION pHwDevExt;
  611. PKSSTREAM_HEADER pStruc;
  612. DWORD WaitTime = 0;
  613. pHwDevExt = (PHW_DEVICE_EXTENSION)pWorkSrb->HwDeviceExtension;
  614. pStruc = &((PKSSTREAM_HEADER)(pWorkSrb->CommandData.DataBufferArray))[0];
  615. ASSERT( pHwDevExt != NULL );
  616. ASSERT( pStruc != NULL );
  617. ASSERT( MPBuff );
  618. DBG_PRINTF( ("DVDWDM:ScheduleData--- pHwDevExt->Rate=%d\n\r", pHwDevExt->Rate )); // F.F. or F.R.
  619. if( pHwDevExt->Rate < 10000 )
  620. {
  621. putSRB( pWorkSrb );
  622. if( fScanCallBack==FALSE ) // 1st time putting SRB?
  623. {
  624. DWORD pts = GetDataPTS( pStruc );
  625. if( pts!=0xffffffff )
  626. {
  627. WaitTime = pHwDevExt->scheduler.calcWaitTime( pWorkSrb );
  628. if( WaitTime==0 )
  629. WaitTime = 1;
  630. }
  631. else
  632. WaitTime = 1;
  633. StreamClassScheduleTimer( pHwDevExt->pstroVid,
  634. pHwDevExt,
  635. WaitTime*1000,
  636. (PHW_TIMER_ROUTINE)ScanCallBack,
  637. pHwDevExt
  638. );
  639. DBG_PRINTF( ("DVDWDM:ScheduleData::SendWdmBuff-StreamClassScheduleTimer()--- Srb=%x\n\r", pWorkSrb));
  640. fScanCallBack = TRUE;
  641. }
  642. }
  643. else
  644. {
  645. pHwDevExt->dvdstrm.SendData( MPBuff );
  646. DBG_PRINTF( ("DVDWDM:ScheduleData::SendWdmBuff-SendData()--- Srb=%x\n\r", pWorkSrb));
  647. }
  648. }
  649. BOOL CScheduleData::SendPacket(INT SendNumber)
  650. {
  651. PHW_STREAM_REQUEST_BLOCK pWorkSrb = 0L;
  652. IMPEGBuffer *MPBuff = 0;
  653. WORD wSrbptr = 0, wWdmBuffptr = 0;
  654. BOOL Find = FALSE;
  655. for( wSrbptr = 0; wSrbptr < SRB_POINTER_MAX; wSrbptr++)
  656. {
  657. if (m_SrbPointerTable[wSrbptr] != NULL)
  658. {
  659. pWorkSrb = (PHW_STREAM_REQUEST_BLOCK)m_SrbPointerTable[wSrbptr]; //get SRB pointer
  660. for( wWdmBuffptr = 0; wWdmBuffptr < WDM_BUFFER_MAX; wWdmBuffptr++)
  661. {
  662. MPBuff = &(((PSRB_EXTENSION)(pWorkSrb->SRBExtension))->m_wdmbuff[wWdmBuffptr]);
  663. if (SendNumber == (((PSRB_EXTENSION)(pWorkSrb->SRBExtension))->m_wdmbuff[wWdmBuffptr]).m_StartPacketNumber)
  664. {
  665. DBG_PRINTF( ("DVDWDM:ScheduleData::SendPacket-Find--- Srb=%x m_wdmbuff[%x]\n\r", pWorkSrb,wWdmBuffptr));
  666. DBG_PRINTF( ("DVDWDM:ScheduleData::SendPacket-Find--- SendNumber=%x\n\r", SendNumber));
  667. Find = TRUE; //find send packet
  668. break;
  669. }
  670. if ((((PSRB_EXTENSION)(pWorkSrb->SRBExtension))->m_wdmbuff[wWdmBuffptr]).m_EndFlag == TRUE)
  671. break; //last buffer
  672. }
  673. if (Find == TRUE)
  674. {
  675. if((((PSRB_EXTENSION)(pWorkSrb->SRBExtension))->m_wdmbuff[wWdmBuffptr]).m_EndFlag == TRUE)
  676. m_SrbPointerTable[wSrbptr] = NULL;
  677. break;
  678. }
  679. }
  680. }
  681. if (wSrbptr == SRB_POINTER_MAX)
  682. {
  683. ASSERT (wSrbptr != SRB_POINTER_MAX);
  684. IncSendPacketNumber();
  685. return(FALSE);
  686. }
  687. if (SendNumber == m_SendPacketNumber)
  688. {
  689. for(int cnt1 = 0; cnt1 < (((PSRB_EXTENSION)(pWorkSrb->SRBExtension))->m_wdmbuff[wWdmBuffptr]).m_PacketNum; cnt1++)
  690. {
  691. IncSendPacketNumber();
  692. }
  693. DBG_PRINTF( ("DVDWDM:ScheduleData::SendPacket--- m_PacketNum=%x\n\r", (((PSRB_EXTENSION)(pWorkSrb->SRBExtension))->m_wdmbuff[wWdmBuffptr]).m_PacketNum));
  694. }
  695. for(int cnt2 = 0; cnt2 < (((PSRB_EXTENSION)(pWorkSrb->SRBExtension))->m_wdmbuff[wWdmBuffptr]).m_PacketNum; cnt2++)
  696. {
  697. m_bDvdDataTable[SendNumber] = INIT_DVD_DATA;
  698. if (SendNumber == (DVD_DATA_MAX - 1)) SendNumber = 0;
  699. else SendNumber++;
  700. }
  701. DBG_PRINTF( ("DVDWDM:ScheduleData::SendPacket--- m_SendPacketNumber=%x\n\r", m_SendPacketNumber));
  702. SendWdmBuff(pWorkSrb, MPBuff); // call SendData()
  703. return (TRUE);
  704. }
  705. #endif REARRANGEMENT