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.

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