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.

502 lines
14 KiB

  1. /*
  2. ]ǗNX
  3. iNP2)@Sachiko Yasukawa
  4. */
  5. #include "stdafx.h"
  6. #include "includes.h"
  7. #include "classlib.h"
  8. #ifdef TEST
  9. IMBoardListItem *pbuffers1[20];
  10. IMBoardListItem *pbuffers2[20];
  11. #endif
  12. #define ISSETDMABUFFER (m_LinerAdd == NULL) ? FALSE : ((m_PhysAdd == NULL) ? FALSE : ((m_DMABufferSize == 0) ? FALSE : TRUE))
  13. #define ISENDTRANSFERINIT (m_pStreamObject == NULL) ? FALSE : TRUE
  14. BOOL CTransfer::Init( void )
  15. {
  16. m_pStreamObject = NULL;
  17. m_DMABufferSize = 0;
  18. m_pTopEventList = NULL;
  19. m_pLastEventList = NULL;
  20. m_pTopQueuedMPEGBuffer = NULL;
  21. m_pLastQueuedMPEGBuffer = NULL;
  22. m_pNextTransferMPEGBuffer = NULL;
  23. m_TopPagePoint = 1;
  24. m_LastPagePoint = 1;
  25. //�f�o�b�O�p
  26. BufCount = 0;
  27. StreamCount = 0;
  28. return TRUE;
  29. };
  30. //�f�X�g���N�^�@�����������o�b�t�@���c����������������
  31. CTransfer::~CTransfer()
  32. {
  33. CTransferStreamList *pDeleteStreamList;
  34. for( ;m_pStreamObject; ){
  35. pDeleteStreamList = m_pStreamObject;
  36. m_pStreamObject = (CTransferStreamList *)m_pStreamObject->GetNext();
  37. delete pDeleteStreamList;
  38. //�f�o�b�O�p
  39. StreamCount--;
  40. }
  41. ASSERT(StreamCount == 0);
  42. // DBG_PRINTF(("CLASSLIB:StreamCount = %d\n", StreamCount));
  43. }
  44. //�C�x���g�I�u�W�F�N�g���Z�b�g�����B
  45. BOOL CTransfer::SetSink(IMPEGBoardEvent *pEvent)
  46. {
  47. ASSERT(pEvent);
  48. // �󂯎������C�x���g�I�u�W�F�N�g��Next��������
  49. pEvent->SetNext( NULL );
  50. //�����ƈ��‚����Ȃ����B
  51. //�C�x���g���X�g�ɒlj�����
  52. if(m_pTopEventList == NULL)
  53. m_pTopEventList = m_pLastEventList = (IMBoardListItem *)pEvent;//�����̓L���X�g������
  54. else{
  55. m_pLastEventList->SetNext((IMBoardListItem *)pEvent);//�����̓L���X�g������
  56. m_pLastEventList = (IMBoardListItem *)pEvent;//�����̓L���X�g������
  57. }
  58. return TRUE;
  59. }
  60. //�C�x���g�I�u�W�F�N�g���폜�����BAdd by Nakamura
  61. BOOL CTransfer::UnSetSink(IMPEGBoardEvent *pEvent)
  62. {
  63. ASSERT(pEvent);
  64. //�C�x���g���X�g�����폜�����B
  65. // �C�x���g���X�g�����݂��Ȃ��ꍇ�́A�G���[
  66. if(m_pTopEventList == NULL || m_pLastEventList == NULL )
  67. return FALSE;
  68. // �P�‚����o�^�����Ă��Ȃ��ꍇ
  69. if( m_pTopEventList == pEvent && m_pLastEventList == pEvent )
  70. {
  71. m_pTopEventList = m_pLastEventList = NULL;
  72. return TRUE;
  73. };
  74. // �Q�ˆȏ��o�^�����Ă��āA�擪�̃I�u�W�F�N�g���폜�g�p�Ƃ����ꍇ
  75. if( m_pTopEventList == pEvent && m_pLastEventList != pEvent )
  76. {
  77. m_pTopEventList = m_pTopEventList->GetNext();
  78. return TRUE;
  79. };
  80. // �Q�ˆȏ��o�^�����Ă��āA�Q�–ڈȍ~���폜���悤�Ƃ��Ă����ꍇ
  81. IMBoardListItem *pTmpEvent;
  82. for( pTmpEvent = m_pTopEventList; pTmpEvent != NULL; pTmpEvent = pTmpEvent->GetNext() )
  83. {
  84. // ���X�g���̍폜�ΏۃC�x���g�I�u�W�F�N�g�Ɠ������H
  85. if( pTmpEvent->GetNext() == pEvent )
  86. {
  87. // �폜���悤�Ƃ��Ă����I�u�W�F�N�g���A�Ō��ł����ꍇ
  88. if( pTmpEvent->GetNext() == m_pLastEventList )
  89. m_pLastEventList = pTmpEvent;
  90. // ���X�g�̒����Ȃ���
  91. pTmpEvent->SetNext( pTmpEvent->GetNext()->GetNext() );
  92. return TRUE;
  93. };
  94. };
  95. DBG_PRINTF(("CLASSLIB: CALLED CTransfer::UnSetSinkError!!!\n"));
  96. DBG_BREAK();
  97. return FALSE;
  98. }
  99. //DMABuffer���ݒ肷���B
  100. BOOL CTransfer::SetDMABuffer(DWORD size, BYTE* LinerAdd, BYTE *PhysAdd)
  101. {
  102. ASSERT(LinerAdd);
  103. ASSERT(PhysAdd);
  104. /*
  105. if(!ISENDTRANSFERINIT)
  106. return MBC_NOTINITIALIZE;
  107. m_LinerAdd = LinerAdd;
  108. m_PhysAdd = PhysAdd;
  109. m_DMABufferSize = size;
  110. */
  111. return TRUE;
  112. }
  113. //Queue�ɓ����ĂȂ����̂��������B
  114. BOOL CTransfer::EnQueue( IMPEGBuffer *pBuffer )
  115. {
  116. ASSERT( pBuffer != NULL );
  117. pBuffer->SetNext( NULL );
  118. //�]�����ׂ��o�b�t�@�ɒlj�
  119. if(m_pTopQueuedMPEGBuffer == NULL){
  120. m_pTopQueuedMPEGBuffer = m_pLastQueuedMPEGBuffer = m_pNextTransferMPEGBuffer = pBuffer;
  121. m_TopPagePoint = 1;
  122. m_LastPagePoint = 1;
  123. // DBG_PRINTF(("CLASSLIB: m_pTopQueuedTOPMPEGBuffer = 0x%X\n", (DWORD)m_pTopQueuedMPEGBuffer));
  124. // DBG_PRINTF(("CLASSLIB: m_pLastQueuedTOPMPEGBuffer = 0x%X\n", (DWORD)m_pLastQueuedMPEGBuffer));
  125. // DBG_PRINTF(("CLASSLIB: PageSize = %d\n", pBuffer->GetPageNum()));
  126. }
  127. else{
  128. m_pLastQueuedMPEGBuffer->SetNext(pBuffer);
  129. m_pLastQueuedMPEGBuffer = pBuffer;
  130. if( m_pNextTransferMPEGBuffer == NULL )
  131. {
  132. m_pNextTransferMPEGBuffer = m_pLastQueuedMPEGBuffer;
  133. m_LastPagePoint = 1;
  134. };
  135. // DBG_PRINTF(("CLASSLIB: m_pTopQueuedTOPMPEGBuffer = 0x%X\n", (DWORD)m_pTopQueuedMPEGBuffer));
  136. // DBG_PRINTF(("CLASSLIB: m_pLastQueuedTOPMPEGBuffer = 0x%X\n", (DWORD)m_pLastQueuedMPEGBuffer));
  137. // DBG_PRINTF(("CLASSLIB: PageSize = %d\n", pBuffer->GetPageNum()));
  138. }
  139. // DBG_PRINTF(("CLASSLIB: CALLED CTransfer::EnQueue\n"));
  140. if(!ISENDTRANSFERINIT){
  141. DBG_PRINTF(("CLASSLIB:CTRANSFER::ENQUEUE:NOT INTIALIZE CTRANSFER\n"));
  142. DBG_BREAK();
  143. return FALSE;
  144. }
  145. return TRUE;
  146. }
  147. //Queue�����Ƃ肾���ē]������
  148. BOOL CTransfer::DeQueue()
  149. {
  150. DWORD PageNum;
  151. CBaseStream *pStream;
  152. CTransferStreamList *pStreamList;
  153. IHALStreamControl *pHALStream;
  154. DWORD pLinear, pPhys, Flag;
  155. int BufSize;
  156. // DBG_PRINTF(("CLASSLIB: CALLED CTransfer::DeQueue\n"));
  157. if(!ISENDTRANSFERINIT){
  158. DBG_PRINTF(("CLASSLIB:CTRANSFER::DEQUEUE:NOT INTIALIZE CTRANSFER\n"));
  159. DBG_BREAK();
  160. return FALSE;
  161. }
  162. //pStream = m_pStreamObject->GetBaseStrem();
  163. //DMA�o�b�t�@���‚����ꍇ�̏���
  164. if(ISSETDMABUFFER){
  165. }
  166. //DMA�o�b�t�@���g���Ȃ��ꍇ�̏���
  167. else{
  168. for(pStreamList = m_pStreamObject; pStreamList; pStreamList = (CTransferStreamList *)pStreamList->GetNext()){
  169. pStream = pStreamList->GetBaseStream();
  170. ASSERT(pStream);
  171. pHALStream = pStream->GetHALStreamControl();
  172. ASSERT(pHALStream);
  173. DWORD QueueNum;
  174. HALRESULT st;
  175. DWORD Count;
  176. //�ϊ������ă��X�g�ɓ����Ă��o�b�t�@�����ۂɃf�[�^�]��
  177. if((st = pHALStream->GetAvailableQueue( &QueueNum )) != HAL_SUCCESS){
  178. _RPT0(_CRT_WARN, "CAN'T GETAVAILABLEQUEUE\n");
  179. DBG_PRINTF(("CLASSLIB:CTransfer::DeQueue:CAN'T GETAVAILABLEQUEUE\n"));
  180. DBG_BREAK();
  181. return FALSE;
  182. }
  183. for(Count = 0; Count < QueueNum ; Count++){
  184. IMPEGBuffer *pBuffer = NULL;
  185. if( GetNextTransferPoint( &pBuffer, &PageNum ) == FALSE )
  186. return TRUE;
  187. if(!pBuffer->GetPagePointer(PageNum, &pLinear, &pPhys)){
  188. return FALSE;
  189. }
  190. //CClassLibBuffer�����邽�߂ɃT�C�Y���擾
  191. BufSize = pBuffer->GetPageSize(PageNum);
  192. //CClassLibBuffer�����邽�߂�flag���擾
  193. if(PageNum == 1)
  194. Flag = pBuffer->GetBufferFlag();
  195. else
  196. Flag = 0; //�����̓R�[�f�B���O������
  197. //�V�����o�b�t�@�Ǘ��N���X������
  198. CClassLibBuffer *pBuf = m_Mem.Alloc(pBuffer, pStream, PageNum, BufSize, pPhys, pLinear, Flag);//�f�[�^���ݒ�
  199. if(!pBuf){
  200. _RPTF0(_CRT_WARN, "CAN'T New");
  201. DBG_PRINTF(("CLASSLIB:CTRANSFER::ENQUEUE:CAN'T NEW\n"));
  202. DBG_BREAK();
  203. return FALSE;
  204. }
  205. //�f�o�b�O�p
  206. BufCount++;
  207. // DBG_PRINTF(("CLASSLIB: Dequeue: Senddata(%d) pBuffer = 0x%X IMPEGBuff=0x%x\n", BufCount, (DWORD)pBuf,pBuffer ));
  208. if((st = pHALStream->SendData(pBuf)) != HAL_SUCCESS){
  209. _RPT0(_CRT_WARN, "CAN'T SENDDATA TO HAL\n");
  210. DBG_PRINTF(("CLASSLIB:CTransfer::DeQueue:CAN'T SENDDATA TO HAL\n"));
  211. DBG_BREAK();
  212. return FALSE;
  213. }
  214. }
  215. }
  216. }
  217. return TRUE;
  218. }
  219. //Transfer�I�u�W�F�N�g�ɃX�g���[�����lj������B
  220. BOOL CTransfer::AddStreamObject(IBaseStream *INewStreamObject)
  221. {
  222. //CBaseStream *pBSt1, *pBSt2;
  223. CTransferStreamList *pNewTransferStreamList, *pStreamList;
  224. ASSERT(INewStreamObject);
  225. //378742 PNPBOOT: tosdvd03 leaks 1 page of memory on unload.
  226. // pNewTransferStreamList = new CTransferStreamList((CBaseStream *)INewStreamObject);
  227. m_pNewTransferStreamList.Init( (CBaseStream *)INewStreamObject );
  228. pNewTransferStreamList = &m_pNewTransferStreamList;
  229. //
  230. if(!pNewTransferStreamList){
  231. DBG_PRINTF(("CLASSLIB:CTRANSFER::AddStreamObject:CAN'T NEW\n"));
  232. DBG_BREAK();
  233. return FALSE;
  234. }
  235. //�f�o�b�O�p
  236. StreamCount++;
  237. //�܂����‚��X�g���[�����lj������Ă��Ȃ��B
  238. if(m_pStreamObject == NULL){
  239. m_pStreamObject = pNewTransferStreamList;
  240. //pBSt1 = m_pStreamObject->GetBaseStream();
  241. //pHALStream = m_pBSt1->GetHALStreamControl();
  242. m_pIHAL = m_pStreamObject->GetBaseStream()->GetClassLibHAL();
  243. m_EndOfTransferEvent.SetEventType(ClassLibEvent_SendData);
  244. m_EndOfTransferEvent.SetTransfer(this);
  245. m_pIHAL->SetSinkClassLib((IMPEGBoardEvent *)/*(CClassLibEvent *)*/&m_EndOfTransferEvent);
  246. }
  247. //�V�����X�g���[�����lj�
  248. else{
  249. //pBSt1 = pNewTransferStreamList;
  250. for(pStreamList = m_pStreamObject; pStreamList->GetNext() != NULL; pStreamList = (CTransferStreamList *)pStreamList->GetNext());
  251. pStreamList->SetNext((IMBoardListItem *)pNewTransferStreamList);
  252. }
  253. return TRUE;
  254. }
  255. //Transfer�I�u�W�F�N�g�����X�g���[�������������B
  256. BOOL CTransfer::ReleaseStreamObject(IBaseStream *IStreamObject)
  257. {
  258. CTransferStreamList *pStreamList, *pNextStreamList;
  259. CBaseStream *pBaseStream;
  260. ASSERT(IStreamObject);
  261. //�������ׂ��X�g���[�����Ȃ��̂ŃG���[
  262. if(m_pStreamObject == NULL){
  263. _RPTF0(_CRT_WARN, "CTransfer:THERE IS NO STREAM WHICH SHOULD BE RELEASED\n");
  264. DBG_PRINTF(("CLASSLIB:CTRANSFER::ReleaseStreamObject:THERE IS NO STREAM WHICH SHOULD BE RELEASED\n"));
  265. DBG_BREAK();
  266. return FALSE;
  267. }
  268. else{
  269. for(pStreamList = m_pStreamObject; ; pStreamList = (CTransferStreamList *)pStreamList->GetNext()){
  270. if((pNextStreamList = (CTransferStreamList *)pStreamList->GetNext()) == NULL){
  271. _RPTF0(_CRT_WARN, "CTransfer:THERE IS SUCH A STREAM WHICH SHOULD BE RELEASED\n");
  272. DBG_PRINTF(("CLASSLIB:CTRANSFER::ReleaseStreamObject:THERE IS SUCH A STREAM WHICH SHOULD BE RELEASED\n"));
  273. DBG_BREAK();
  274. return FALSE;
  275. }
  276. if((pBaseStream = (CBaseStream *)pNextStreamList->GetBaseStream()) == (CBaseStream *)IStreamObject){
  277. break;
  278. }
  279. ASSERT(pBaseStream);
  280. }
  281. pStreamList->SetNext(pNextStreamList->GetNext());
  282. //378742 PNPBOOT: tosdvd03 leaks 1 page of memory on unload.
  283. // delete pNextStreamList;
  284. //
  285. //�f�o�b�O�p
  286. StreamCount--;
  287. }
  288. return TRUE;
  289. }
  290. //Queue���t���b�V�������B
  291. void CTransfer::Flush()
  292. {
  293. CTransferStreamList *pStreamList;
  294. CBaseStream *pBaseStream;
  295. IMPEGBoardEvent *pEvent;
  296. DBG_PRINTF(("CLASSLIB:Before flash BufCount = %d\n", BufCount));
  297. m_Mem.Flush();
  298. BufCount=0;
  299. for(pStreamList = m_pStreamObject; pStreamList; pStreamList = (CTransferStreamList *)pStreamList->GetNext()){
  300. pBaseStream = pStreamList->GetBaseStream();
  301. DWORD PageNum;
  302. ASSERT(pBaseStream);
  303. IMPEGBuffer *pBuffer = NULL;
  304. BOOL NeedAdvice = FALSE;
  305. // Stream��Queue�Ɏ����Ă����o�b�t�@�����ׂāA�]�����Ƀ}�[�N�����B
  306. while( TRUE )
  307. {
  308. if( GetNextTransferPoint( &pBuffer, &PageNum ) == FALSE )
  309. break;
  310. }
  311. while( HasQueuedBuffer() == TRUE )
  312. {
  313. NeedAdvice = FreeTopTransferPoint(&pBuffer);
  314. if( NeedAdvice == TRUE )
  315. {
  316. for(pEvent = (IMPEGBoardEvent *)m_pTopEventList; pEvent != NULL;pEvent = (IMPEGBoardEvent *)((IMBoardListItem *)pEvent)->GetNext())
  317. {
  318. if((/*(CClassLibEvent *)*/pEvent)->GetEventType() == ClassLibEvent_SendData){
  319. //MPEGBuffer�̐擪���ЂƂ‚������ɂ��炷
  320. //Wrapper�ɂ����g���I���������Ƃ��m�点��
  321. pEvent->Advice(pBuffer);
  322. }
  323. }
  324. };
  325. }
  326. }
  327. DBG_PRINTF(("CLASSLIB:After flush BufCount = %d\n", BufCount));
  328. ASSERT( BufCount == 0 );
  329. }
  330. //�f�[�^�]���I���̏���
  331. BOOL CTransfer::EndOfTransfer(CClassLibBuffer *pBuffer)
  332. {
  333. IMPEGBoardEvent *pEvent;
  334. CBaseStream *pStream;
  335. CTransferStreamList *pStreamList;
  336. // DBG_PRINTF(("CLASSLIB: EndOfTransfer(%d) pBuffer = 0x%X\n", BufCount, (DWORD)pBuffer));
  337. // DBG_PRINTF(("CLASSLIB: pBuffer->GetIMPEGBuffer() = 0x%X\n", (DWORD)pBuffer->GetIMPEGBuffer()));
  338. ASSERT(pBuffer);
  339. pStream = pBuffer->GetStream();
  340. ASSERT(pStream);
  341. IMPEGBuffer *pFree = NULL;
  342. if( FreeTopTransferPoint(&pFree) == TRUE )
  343. {
  344. // DBG_PRINTF(("CLASSLIB: Free IMPEGBuffer() = 0x%X\n", (DWORD)pFree ));
  345. ASSERT( pFree == pBuffer->GetIMPEGBuffer() );
  346. //Wrapper�����n���ꂽ�o�b�t�@�̍Ō��̃y�[�W�Ȃ��o�b�t�@�[�J��
  347. for(pEvent = (IMPEGBoardEvent *)m_pTopEventList; pEvent != NULL;pEvent = (IMPEGBoardEvent *)((IMBoardListItem *)pEvent)->GetNext()){
  348. if(pEvent->GetEventType() == ClassLibEvent_SendData){
  349. //Wrapper�ɂ����g���I���������Ƃ��m�点��
  350. // DBG_PRINTF(("CLASSLIB: EndOfTransfer Advice Buffer = 0x%X\n", pBuffer->GetIMPEGBuffer() ));
  351. pEvent->Advice(pBuffer->GetIMPEGBuffer());
  352. }
  353. }
  354. }
  355. //���X�g�����͂�����CClassLibBuffer������
  356. m_Mem.Free(pBuffer);
  357. //�f�o�b�O�p
  358. BufCount--;
  359. ASSERT(BufCount>=0);
  360. //STOP���Ԃ̂Ƃ���HAL�ɑ΂���SendData���Ȃ�
  361. for(pStreamList = m_pStreamObject; pStreamList; pStreamList = (CTransferStreamList *)pStreamList->GetNext()){
  362. pStream = pStreamList->GetBaseStream();
  363. ASSERT(pStream);
  364. if(pStream->GetState() == Stop)
  365. return TRUE;
  366. }
  367. if(DeQueue() == FALSE){
  368. DBG_PRINTF(("CLASSLIB:CTRANSFER::EndOfTransfer:CAN'T DEQUEUE\n"));
  369. DBG_BREAK();
  370. return FALSE;
  371. }
  372. return TRUE;
  373. }
  374. BOOL CTransfer::HasQueuedBuffer( void )
  375. {
  376. if( m_pTopQueuedMPEGBuffer == NULL )
  377. return FALSE;
  378. return TRUE;
  379. };
  380. BOOL CTransfer::GetNextTransferPoint( IMPEGBuffer **Point, DWORD *Page )
  381. {
  382. if( m_pNextTransferMPEGBuffer == NULL )
  383. {
  384. *Point = NULL;
  385. *Page = 0;
  386. return FALSE;
  387. };
  388. *Point = m_pNextTransferMPEGBuffer;
  389. *Page = m_LastPagePoint;
  390. if( m_pNextTransferMPEGBuffer->GetPageNum() == m_LastPagePoint )
  391. {
  392. m_pNextTransferMPEGBuffer = (IMPEGBuffer *)m_pNextTransferMPEGBuffer->GetNext();
  393. m_LastPagePoint = 1;
  394. return TRUE;
  395. };
  396. m_LastPagePoint ++;
  397. return TRUE;
  398. };
  399. BOOL CTransfer::FreeTopTransferPoint( IMPEGBuffer **Free )
  400. {
  401. ASSERT( m_pTopQueuedMPEGBuffer != NULL );
  402. if( m_pTopQueuedMPEGBuffer == NULL
  403. || ( m_pTopQueuedMPEGBuffer == m_pNextTransferMPEGBuffer && m_LastPagePoint == m_TopPagePoint ) )
  404. {
  405. *Free = NULL;
  406. return FALSE;
  407. };
  408. if( m_TopPagePoint == m_pTopQueuedMPEGBuffer->GetPageNum() )
  409. {
  410. *Free = m_pTopQueuedMPEGBuffer;
  411. m_pTopQueuedMPEGBuffer = (IMPEGBuffer *)m_pTopQueuedMPEGBuffer->GetNext();
  412. m_TopPagePoint = 1;
  413. return TRUE; // Need Advice
  414. };
  415. *Free = NULL;
  416. m_TopPagePoint ++;
  417. return FALSE; // Not Need Advice
  418. };
  419. //HAL�ɂ����ł��炢����
  420. void CClassLibEvent::Advice(PVOID pBuffer)
  421. {
  422. ASSERT(m_pTransfer);
  423. m_pTransfer->EndOfTransfer((CClassLibBuffer *)pBuffer);
  424. }