Advertisement
Guest User

Untitled

a guest
May 10th, 2015
907
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 99.69 KB | None | 0 0
  1. diff -u -r -N a/EDCB-work-plus-s/BonCtrl/arib_std_b25.h b/EDCB-work-plus-s/BonCtrl/arib_std_b25.h
  2. --- a/EDCB-work-plus-s/BonCtrl/arib_std_b25.h   1970-01-01 09:00:00.000000000 +0900
  3. +++ b/EDCB-work-plus-s/BonCtrl/arib_std_b25.h   2015-02-13 00:07:58.000000000 +0900
  4. @@ -0,0 +1,49 @@
  5. +#ifndef ARIB_STD_B25_H
  6. +#define ARIB_STD_B25_H
  7. +
  8. +#include "portable.h"
  9. +#include "b_cas_card.h"
  10. +
  11. +typedef struct {
  12. +   uint8_t *data;
  13. +   int32_t  size;
  14. +} ARIB_STD_B25_BUFFER;
  15. +
  16. +typedef struct {
  17. +
  18. +   int32_t  program_number; /* channel */
  19. +
  20. +   int32_t  ecm_unpurchased_count;
  21. +   int32_t  last_ecm_error_code;
  22. +
  23. +   int32_t  padding;
  24. +
  25. +   int64_t  total_packet_count;
  26. +   int64_t  undecrypted_packet_count;
  27. +
  28. +} ARIB_STD_B25_PROGRAM_INFO;
  29. +
  30. +typedef struct {
  31. +
  32. +   void *private_data;
  33. +
  34. +   void (* release)(void *std_b25);
  35. +
  36. +   int (* set_multi2_round)(void *std_b25, int32_t round);
  37. +   int (* set_strip)(void *std_b25, int32_t strip);
  38. +   int (* set_emm_proc)(void *std_b25, int32_t on);
  39. +
  40. +   int (* set_b_cas_card)(void *std_b25, B_CAS_CARD *bcas);
  41. +
  42. +   int (* reset)(void *std_b25);
  43. +   int (* flush)(void *std_b25);
  44. +
  45. +   int (* put)(void *std_b25, ARIB_STD_B25_BUFFER *buf);
  46. +   int (* get)(void *std_b25, ARIB_STD_B25_BUFFER *buf);
  47. +
  48. +   int (* get_program_count)(void *std_b25);
  49. +   int (* get_program_info)(void *std_b25, ARIB_STD_B25_PROGRAM_INFO *info, int32_t idx);
  50. +
  51. +} ARIB_STD_B25;
  52. +
  53. +#endif /* ARIB_STD_B25_H */
  54. diff -u -r -N a/EDCB-work-plus-s/BonCtrl/b_cas_card.h b/EDCB-work-plus-s/BonCtrl/b_cas_card.h
  55. --- a/EDCB-work-plus-s/BonCtrl/b_cas_card.h 1970-01-01 09:00:00.000000000 +0900
  56. +++ b/EDCB-work-plus-s/BonCtrl/b_cas_card.h 2015-02-13 00:08:58.000000000 +0900
  57. @@ -0,0 +1,65 @@
  58. +#ifndef B_CAS_CARD_H
  59. +#define B_CAS_CARD_H
  60. +
  61. +#include "portable.h"
  62. +
  63. +typedef struct {
  64. +   uint8_t  system_key[32];
  65. +   uint8_t  init_cbc[8];
  66. +   int64_t  bcas_card_id;
  67. +   int32_t  card_status;
  68. +   int32_t  ca_system_id;
  69. +} B_CAS_INIT_STATUS;
  70. +
  71. +typedef struct {
  72. +   int64_t *data;
  73. +   int32_t  count;
  74. +} B_CAS_ID;
  75. +
  76. +typedef struct {
  77. +
  78. +   int32_t  s_yy; /* start date : year  */
  79. +   int32_t  s_mm; /* start date : month */
  80. +   int32_t  s_dd; /* start date : day   */
  81. +
  82. +   int32_t  l_yy; /* limit date : year  */
  83. +   int32_t  l_mm; /* limit date : month */
  84. +   int32_t  l_dd; /* limit date : day   */
  85. +
  86. +   int32_t  hold_time; /* in hour unit  */
  87. +
  88. +   int32_t  broadcaster_group_id;
  89. +
  90. +   int32_t  network_id;
  91. +   int32_t  transport_id;
  92. +
  93. +} B_CAS_PWR_ON_CTRL;
  94. +
  95. +typedef struct {
  96. +   B_CAS_PWR_ON_CTRL *data;
  97. +   int32_t  count;
  98. +} B_CAS_PWR_ON_CTRL_INFO;
  99. +
  100. +typedef struct {
  101. +   uint8_t  scramble_key[16];
  102. +   uint32_t return_code;
  103. +} B_CAS_ECM_RESULT;
  104. +
  105. +typedef struct {
  106. +
  107. +   void *private_data;
  108. +
  109. +   void (* release)(void *bcas);
  110. +
  111. +   int (* init)(void *bcas);
  112. +
  113. +   int (* get_init_status)(void *bcas, B_CAS_INIT_STATUS *stat);
  114. +   int (* get_id)(void *bcas, B_CAS_ID *dst);
  115. +   int (* get_pwr_on_ctrl)(void *bcas, B_CAS_PWR_ON_CTRL_INFO *dst);
  116. +
  117. +   int (* proc_ecm)(void *bcas, B_CAS_ECM_RESULT *dst, uint8_t *src, int len);
  118. +   int (* proc_emm)(void *bcas, uint8_t *src, int len);
  119. +
  120. +} B_CAS_CARD;
  121. +
  122. +#endif /* B_CAS_CARD_H */
  123. diff -u -r -N a/EDCB-work-plus-s/BonCtrl/BonCtrl.cpp b/EDCB-work-plus-s/BonCtrl/BonCtrl.cpp
  124. --- a/EDCB-work-plus-s/BonCtrl/BonCtrl.cpp  2015-05-06 02:05:26.000000000 +0900
  125. +++ b/EDCB-work-plus-s/BonCtrl/BonCtrl.cpp  2015-04-28 19:26:09.000000000 +0900
  126. @@ -546,10 +546,11 @@
  127.  
  128.     {
  129.         CBlockLock lock(&this->buffLock);
  130. -       for( size_t i=0; i<this->TSBuff.size(); i++ ){
  131. -           SAFE_DELETE(this->TSBuff[i]);
  132. +       while (!this->TSBuff.empty()){
  133. +           TS_DATA *p = this->TSBuff.front();
  134. +           this->TSBuff.pop_front();
  135. +           delete p;
  136.         }
  137. -       this->TSBuff.clear();
  138.         this->totalTSBuffSize = 0;
  139.     }
  140.     this->packetInit.ClearBuff();
  141. @@ -570,26 +571,27 @@
  142.         DWORD remain = 0;
  143.         try{
  144.             if( sys->bonUtil.GetTsStream(&data,&size,&remain) == TRUE ){
  145. -               if( size != 0 && data != NULL){
  146. +               if( size != 0 ){
  147.                     TS_DATA* item = new TS_DATA;
  148.                     try{
  149.                         if( sys->packetInit.GetTSData(data, size, &item->data, &item->size) == TRUE ){
  150.                             CBlockLock lock(&sys->buffLock);
  151. -                           if( sys->totalTSBuffSize / 48128 > sys->tsBuffMaxCount ){
  152. -                               while( sys->TSBuff.empty() == false && sys->totalTSBuffSize / 48128 + 1000 > sys->tsBuffMaxCount ){
  153. -                                   sys->totalTSBuffSize -= sys->TSBuff.back()->size;
  154. -                                   SAFE_DELETE(sys->TSBuff.back());
  155. +                           if( sys->totalTSBuffSize / (188 * 256) > sys->tsBuffMaxCount ){
  156. +                               while (!sys->TSBuff.empty() && sys->totalTSBuffSize / (188 * 256) + 1000 > sys->tsBuffMaxCount){
  157. +                                   TS_DATA *p = sys->TSBuff.back();
  158.                                     sys->TSBuff.pop_back();
  159. +                                   sys->totalTSBuffSize -= p->size;
  160. +                                   delete p;
  161.                                 }
  162.                             }
  163. +                           sys->totalTSBuffSize += item->size;
  164.                             sys->TSBuff.push_back(item);
  165. -                           sys->totalTSBuffSize += sys->TSBuff.back()->size;
  166.                         }else{
  167.                             delete item;
  168.                         }
  169.                     }catch(...){
  170.                         delete item;
  171. -                       _OutputDebugString(L"★★RecvThread Exception2");
  172. +                       OutputDebugString(L"★★RecvThread Exception2");
  173.                     }
  174.                 }else{
  175.                     Sleep(10);
  176. @@ -598,7 +600,7 @@
  177.                 Sleep(10);
  178.             }
  179.         }catch(...){
  180. -           _OutputDebugString(L"★★RecvThread Exception1");
  181. +           OutputDebugString(L"★★RecvThread Exception1");
  182.         }
  183.     }
  184.     return 0;
  185. @@ -618,21 +620,21 @@
  186.         TS_DATA* data = NULL;
  187.         {
  188.             CBlockLock lock(&sys->buffLock);
  189. -           if( sys->TSBuff.empty() == false ){
  190. +           if( !sys->TSBuff.empty() ){
  191.                 data = sys->TSBuff.front();
  192. +               sys->TSBuff.pop_front();
  193.                 sys->totalTSBuffSize -= data->size;
  194. -               sys->TSBuff.erase(sys->TSBuff.begin());
  195.             }
  196.         }
  197.         try{
  198.             if( data != NULL ){
  199.                 sys->tsOut.AddTSBuff(data);
  200. -               SAFE_DELETE(data);
  201. +               delete data;
  202.             }else{
  203.                 Sleep(5);
  204.             }
  205.         }catch(...){
  206. -           _OutputDebugString(L"★★AnalyzeThread Exception2");
  207. +           OutputDebugString(L"★★AnalyzeThread Exception2");
  208.         }
  209.     }
  210.     return 0;
  211. @@ -1365,7 +1367,7 @@
  212.     DWORD wait = 0;
  213.     DWORD startTime = 0;
  214.     DWORD chkCount = 0;
  215. -   DWORD chkWait = 8;
  216. +   DWORD chkWait = 5;
  217.  
  218.     BOOL chkBS = FALSE;
  219.     BOOL chkCS1 = FALSE;
  220. @@ -1405,7 +1407,7 @@
  221.             startTime = GetTickCount();
  222.             chkNext = FALSE;
  223.             startCap = FALSE;
  224. -           wait = 1000;
  225. +           wait = 1 * 1000;
  226.             if( sys->epgCapChList[chkCount].ONID == 4 ){
  227.                 chkBS = TRUE;
  228.             }else if( sys->epgCapChList[chkCount].ONID == 6 ){
  229. @@ -1418,18 +1420,18 @@
  230.             BOOL chChgErr = FALSE;
  231.             if( sys->tsOut.IsChChanging(&chChgErr) == TRUE ){
  232.                 if( GetTickCount() - startTime > chkWait * 1000 ){
  233. -                   //チャンネル切り替えに10秒以上かかってるので無信号と判断
  234. +                   //チャンネル切り替えにchkWait秒以上かかってるので無信号と判断
  235.                     chkNext = TRUE;
  236.                 }
  237.             }else{
  238. -               if( GetTickCount() - startTime > (chkWait + timeOut * 60) * 1000 || chChgErr == TRUE){
  239. -                   //15分以上かかっているなら停止
  240. +               if( GetTickCount() - startTime > (chkWait + (timeOut * 60)) * 1000 || chChgErr == TRUE){
  241. +                   //timeOut分以上かかっているなら停止
  242.                     sys->tsOut.StopSaveEPG(saveTimeOut);
  243.                     chkNext = TRUE;
  244.                     wait = 0;
  245.                     _OutputDebugString(L"++%d分でEPG取得完了せず or Ch変更でエラー", timeOut);
  246.                 }else if( GetTickCount() - startTime > chkWait * 1000 ){
  247. -                   //切り替えから15秒以上過ぎているので取得処理
  248. +                   //切り替えからchkWait秒以上過ぎているので取得処理
  249.                     if( startCap == FALSE ){
  250.                         //取得開始
  251.                         startCap = TRUE;
  252. @@ -1437,7 +1439,7 @@
  253.                         sys->GetEpgDataFilePath(sys->epgCapChList[chkCount].ONID, sys->epgCapChList[chkCount].TSID, epgDataPath, BSBasic, CS1Basic, CS2Basic);
  254.                         sys->tsOut.StartSaveEPG(epgDataPath);
  255.                         sys->tsOut.ClearSectionStatus();
  256. -                       wait = 60*1000;
  257. +                       wait = 30 * 1000;
  258.                     }else{
  259.                         //蓄積状態チェック
  260.                         BOOL leitFlag = sys->chUtil.IsPartial(sys->epgCapChList[chkCount].ONID, sys->epgCapChList[chkCount].TSID, sys->epgCapChList[chkCount].SID);
  261. @@ -1465,7 +1467,7 @@
  262.                             sys->tsOut.StopSaveEPG(TRUE);
  263.                             wait = 0;
  264.                         }else{
  265. -                           wait = 10*1000;
  266. +                           wait = 10 * 1000;
  267.                         }
  268.                     }
  269.                 }
  270. @@ -1728,7 +1730,7 @@
  271.             break;
  272.         }else{
  273.             if( GetTickCount() - startTime > timeOut * 60 * 1000 ){
  274. -               //15分以上かかっているなら停止
  275. +               //timeOut分以上かかっているなら停止
  276.                 sys->tsOut.StopSaveEPG(saveTimeOut);
  277.                 CSendCtrlCmd cmd;
  278.                 cmd.SetConnectTimeOut(1000);
  279. diff -u -r -N a/EDCB-work-plus-s/BonCtrl/BonCtrlDef.h b/EDCB-work-plus-s/BonCtrl/BonCtrlDef.h
  280. --- a/EDCB-work-plus-s/BonCtrl/BonCtrlDef.h 2015-05-06 02:05:26.000000000 +0900
  281. +++ b/EDCB-work-plus-s/BonCtrl/BonCtrlDef.h 2015-02-14 22:18:02.000000000 +0900
  282. @@ -23,7 +23,7 @@
  283.         size = 0;
  284.     }
  285.     ~_TS_DATA(void){
  286. -       SAFE_DELETE_ARRAY(data);
  287. +       delete[] data;
  288.     }
  289.  } TS_DATA;
  290.  
  291. diff -u -r -N a/EDCB-work-plus-s/BonCtrl/BonCtrl.h b/EDCB-work-plus-s/BonCtrl/BonCtrl.h
  292. --- a/EDCB-work-plus-s/BonCtrl/BonCtrl.h    2015-05-06 02:05:26.000000000 +0900
  293. +++ b/EDCB-work-plus-s/BonCtrl/BonCtrl.h    2015-02-14 02:36:32.000000000 +0900
  294. @@ -474,7 +474,7 @@
  295.     HANDLE lockEvent;
  296.  
  297.     CRITICAL_SECTION buffLock;
  298. -   vector<TS_DATA*> TSBuff;
  299. +   deque<TS_DATA*> TSBuff;
  300.     DWORD totalTSBuffSize;
  301.  
  302.     HANDLE recvThread;
  303. diff -u -r -N a/EDCB-work-plus-s/BonCtrl/CATUtil.cpp b/EDCB-work-plus-s/BonCtrl/CATUtil.cpp
  304. --- a/EDCB-work-plus-s/BonCtrl/CATUtil.cpp  2015-05-06 02:05:26.000000000 +0900
  305. +++ b/EDCB-work-plus-s/BonCtrl/CATUtil.cpp  2015-04-29 04:01:57.000000000 +0900
  306. @@ -19,17 +19,16 @@
  307.         return FALSE;
  308.     }
  309.     if( buffUtil.Add188TS(packet) == TRUE ){
  310. -       BYTE* section = NULL;
  311. -       DWORD sectionSize = 0;
  312. +       BYTE* section;
  313. +       DWORD sectionSize;
  314.         while( buffUtil.GetSectionBuff( &section, &sectionSize ) == TRUE ){
  315.             if( DecodeCAT(section, sectionSize) == FALSE ){
  316.                 return FALSE;
  317.             }
  318.         }
  319. -   }else{
  320. -       return FALSE;
  321. +       return TRUE;
  322.     }
  323. -   return TRUE;
  324. +   return FALSE;
  325.  }
  326.  
  327.  BOOL CCATUtil::DecodeCAT(BYTE* data, DWORD dataSize)
  328. diff -u -r -N a/EDCB-work-plus-s/BonCtrl/CreatePATPacket.cpp b/EDCB-work-plus-s/BonCtrl/CreatePATPacket.cpp
  329. --- a/EDCB-work-plus-s/BonCtrl/CreatePATPacket.cpp  2015-05-06 02:05:26.000000000 +0900
  330. +++ b/EDCB-work-plus-s/BonCtrl/CreatePATPacket.cpp  2015-05-08 10:44:59.000000000 +0900
  331. @@ -140,7 +140,7 @@
  332.     SAFE_DELETE_ARRAY(this->packet);
  333.  
  334.     //TSパケットを作成
  335. -   int iPacketNum = (this->PSISize/184) + 1;
  336. +   int iPacketNum = ((this->PSISize-1)/184) + 1;
  337.     this->packetSize = 188*iPacketNum;
  338.  
  339.     this->packet = new BYTE[this->packetSize];
  340. diff -u -r -N a/EDCB-work-plus-s/BonCtrl/CreatePMTPacket.cpp b/EDCB-work-plus-s/BonCtrl/CreatePMTPacket.cpp
  341. --- a/EDCB-work-plus-s/BonCtrl/CreatePMTPacket.cpp  2015-05-06 02:05:26.000000000 +0900
  342. +++ b/EDCB-work-plus-s/BonCtrl/CreatePMTPacket.cpp  2015-05-01 05:36:56.000000000 +0900
  343. @@ -64,15 +64,20 @@
  344.     if( packet == NULL ){
  345.         return ERR_FALSE;
  346.     }
  347. -   DWORD ret = ERR_NEED_NEXT_PACKET;
  348. -   ret = buffUtil.Add188TS(packet);
  349. -   if( ret == TRUE ){
  350. -       this->lastPmtPID = packet->PID;
  351. -
  352. -       BYTE* section = NULL;
  353. -       DWORD sectionSize = 0;
  354. -       while( buffUtil.GetSectionBuff( &section, &sectionSize ) == TRUE ){
  355. -           ret = DecodePMT(section, sectionSize);
  356. +   DWORD ret = buffUtil.Add188TS(packet);
  357. +   if (ret != TRUE){
  358. +       if (ret == ERR_ADD_NEXT && this->createPacket != NULL){
  359. +           return ERR_NO_CHAGE;
  360. +       }
  361. +       return ERR_FALSE;
  362. +   }
  363. +   this->lastPmtPID = packet->PID;
  364. +   ret = ERR_FALSE;
  365. +   BYTE* section;
  366. +   DWORD sectionSize;
  367. +   while( buffUtil.GetSectionBuff( &section, &sectionSize ) == TRUE ){
  368. +       if (DecodePMT(section, sectionSize) != ERR_FALSE){
  369. +           ret = NO_ERR;
  370.         }
  371.     }
  372.     return ret;
  373. @@ -80,10 +85,11 @@
  374.  
  375.  DWORD CCreatePMTPacket::DecodePMT(BYTE* data, DWORD dataSize)
  376.  {
  377. +/*
  378.     if( data == NULL ){
  379.         return ERR_FALSE;
  380.     }
  381. -
  382. +*/
  383.     if( dataSize < 7 ){
  384.         return ERR_FALSE;
  385.     }
  386. @@ -100,14 +106,12 @@
  387.     WORD program_info_length;
  388.     DWORD crc32;
  389.  
  390. -
  391. -   DWORD readSize = 0;
  392.     //////////////////////////////////////////////////////
  393.     //解析処理
  394.     table_id = data[0];
  395.     section_syntax_indicator = (data[1]&0x80)>>7;
  396.     section_length = ((WORD)data[1]&0x0F)<<8 | data[2];
  397. -   readSize+=3;
  398. +   DWORD readSize = 3;
  399.  
  400.     if( section_syntax_indicator != 1 ){
  401.         //固定値がおかしい
  402. @@ -237,7 +241,7 @@
  403.  
  404.     CreatePMT();
  405.  
  406. -   return TRUE;
  407. +   return NO_ERR;
  408.  }
  409.  
  410.  void CCreatePMTPacket::CreatePMT()
  411. @@ -315,6 +319,10 @@
  412.                     secondSize+=secondDescBuff[i]->descBuffSize;
  413.                 }
  414.                 break;
  415. +           case 0x24:
  416. +               //HEVC VIDEO
  417. +               secondSize += secondDescBuff[i]->descBuffSize;
  418. +               break;
  419.             case 0x06:
  420.                 //字幕
  421.                 if( this->needCaption == TRUE ){
  422. @@ -334,17 +342,16 @@
  423.     this->createPSISize += secondSize;
  424.  
  425.     this->createPSI = new BYTE[this->createPSISize];
  426. -   ZeroMemory(this->createPSI, this->createPSISize);
  427. +// ZeroMemory(this->createPSI, this->createPSISize);
  428. +   this->createPSI[0] = 0;
  429.     //最初のDescriptorループまでコピー
  430.     memcpy( this->createPSI + 1, this->firstDescBuff, this->firstDescBuffSize );
  431.  
  432.     //SectionLength
  433. -   this->createPSI[2] = (BYTE)(((this->createPSISize-4)&0x00000F00)>>8);
  434. -   this->createPSI[2] |= 0xB0;
  435. +   this->createPSI[2] = (BYTE)(((this->createPSISize-4)&0x00000F00)>>8) | 0xB0;
  436.     this->createPSI[3] = (BYTE)((this->createPSISize-4)&0x000000FF);
  437.     //バージョン
  438. -   this->createPSI[6] = this->createVer<<1;
  439. -   this->createPSI[6] |= 0xC1;
  440. +   this->createPSI[6] = (this->createVer<<1) | 0xC1;
  441.  
  442.     DWORD writeSize = this->firstDescBuffSize+1;
  443.     for( size_t i=0; i<secondDescBuff.size(); i++ ){
  444. @@ -393,6 +400,12 @@
  445.                     this->needPIDList.insert(pair<WORD,WORD>(secondDescBuff[i]->elementary_PID, secondDescBuff[i]->stream_type));
  446.                 }
  447.                 break;
  448. +           case 0x24:
  449. +               //HEVC VIDEO
  450. +               memcpy(this->createPSI + writeSize, secondDescBuff[i]->descBuff, secondDescBuff[i]->descBuffSize);
  451. +               writeSize += secondDescBuff[i]->descBuffSize;
  452. +               this->needPIDList.insert(pair<WORD, WORD>(secondDescBuff[i]->elementary_PID, secondDescBuff[i]->stream_type));
  453. +               break;
  454.             case 0x06:
  455.                 //字幕
  456.                 if( this->needCaption == TRUE ){
  457. @@ -429,7 +442,7 @@
  458.     SAFE_DELETE_ARRAY(this->createPacket);
  459.  
  460.     //TSパケットを作成
  461. -   int packetNum = (this->createPSISize/184) + 1;
  462. +   int packetNum = ((this->createPSISize-1)/184) + 1;
  463.     this->createPacketSize = 188*packetNum;
  464.  
  465.     this->createPacket = new BYTE[this->createPacketSize];
  466. @@ -491,15 +504,14 @@
  467.     BOOL incrementFlag
  468.  )
  469.  {
  470. -   if( incrementFlag == TRUE ){
  471. -       IncrementCounter();
  472. -   }
  473. -   if( this->createPacket != NULL ){
  474. -       *buff = this->createPacket;
  475. -       *size = (DWORD)this->createPacketSize;
  476. -   }else{
  477. +   if (this->createPacket == NULL){
  478.         return FALSE;
  479.     }
  480. +   if (incrementFlag == TRUE){
  481. +       IncrementCounter();
  482. +   }
  483. +   *buff = this->createPacket;
  484. +   *size = (DWORD)this->createPacketSize;
  485.     return TRUE;
  486.  }
  487.  
  488. @@ -533,10 +545,6 @@
  489.  
  490.  void CCreatePMTPacket::IncrementCounter()
  491.  {
  492. -   if( this->createPacket == NULL ){
  493. -       return ;
  494. -   }
  495. -
  496.     for( int i = 0 ; i<this->createPacketSize; i+=188 ){
  497.         this->createPacket[i+3] = (BYTE)(this->createCounter | 0x10);
  498.         this->createCounter++;
  499. diff -u -r -N a/EDCB-work-plus-s/BonCtrl/decoder.cpp b/EDCB-work-plus-s/BonCtrl/decoder.cpp
  500. --- a/EDCB-work-plus-s/BonCtrl/decoder.cpp  1970-01-01 09:00:00.000000000 +0900
  501. +++ b/EDCB-work-plus-s/BonCtrl/decoder.cpp  2015-02-13 00:40:34.000000000 +0900
  502. @@ -0,0 +1,188 @@
  503. +// -*- coding: utf-8 -*-
  504. +#include "StdAfx.h"
  505. +#include "decoder.h"
  506. +#include <cassert>
  507. +
  508. +#ifdef NDEBUG
  509. +#define report(fmt, ...) ((void) 0)
  510. +#else
  511. +#include <windows.h>
  512. +#define report OutputDebugStringA
  513. +#endif
  514. +
  515. +int B25Decoder::multi2_round = 4;
  516. +int B25Decoder::strip = 1;
  517. +int B25Decoder::emm_proc;
  518. +
  519. +B25Decoder::B25Decoder(t_create_b_cas_card f_bcas, t_create_arib_std_b25 f_b25)
  520. +   : f_create_b_cas_card(f_bcas)
  521. +   , f_create_arib_std_b25(f_b25)
  522. +   , _bcas(NULL)
  523. +   , _b25(NULL)
  524. +   , _init_called(false)
  525. +   , _pass_through_bytes(0)
  526. +{
  527. +}
  528. +
  529. +B25Decoder::~B25Decoder()
  530. +{
  531. +   release();
  532. +}
  533. +
  534. +int B25Decoder::init()
  535. +{
  536. +   _init_called = true;
  537. +
  538. +   report("B25Decoder::init() start\n");
  539. +
  540. +   const char *fn;
  541. +   int rc;
  542. +
  543. +   assert(_bcas == NULL);
  544. +   assert(_b25  == NULL);
  545. +
  546. +   _bcas = f_create_b_cas_card(),
  547. +       fn = "create_b_cas_card", rc = 0;
  548. +   if (!_bcas) goto err;
  549. +
  550. +   rc = _bcas->init(_bcas),
  551. +       fn = "bcas::init";
  552. +   if (rc < 0) goto err;
  553. +
  554. +   _b25 = f_create_arib_std_b25(),
  555. +       fn = "create_arib_std_b25", rc = 0;
  556. +   if (!_b25) goto err;
  557. +
  558. +   rc = _b25->set_b_cas_card(_b25, _bcas),
  559. +       fn = "b25::set_b_cas_card";
  560. +   if (rc < 0) goto err;
  561. +
  562. +   rc = _b25->set_strip(_b25, strip),
  563. +       fn = "b25::set_strip";
  564. +   if (rc < 0) goto err;
  565. +
  566. +   rc = _b25->set_emm_proc(_b25, emm_proc),
  567. +       fn = "b25::set_emm_proc";
  568. +   if (rc < 0) goto err;
  569. +
  570. +   rc = _b25->set_multi2_round(_b25, multi2_round),
  571. +       fn = "b25::set_multi2_round";
  572. +   if (rc < 0) goto err;
  573. +
  574. +   report("B25Decoder::init() ok\n");
  575. +
  576. +   return rc;
  577. +
  578. +err:
  579. +
  580. +   if (_pass_through_bytes == 0) // 外部からの呼び出し時に限る
  581. +   {
  582. +       char tmp[64];
  583. +       sprintf_s(tmp, "%s failed. (%d)\n", fn, rc);
  584. +       report(tmp);
  585. +   }
  586. +
  587. +   release();
  588. +
  589. +   return rc;
  590. +}
  591. +
  592. +void B25Decoder::release()
  593. +{
  594. +   if (_b25)
  595. +   {
  596. +       _b25->release(_b25);
  597. +       _b25 = NULL;
  598. +       report("B25Decoder::release()\n");
  599. +   }
  600. +
  601. +   if (_bcas)
  602. +   {
  603. +       _bcas->release(_bcas);
  604. +       _bcas = NULL;
  605. +   }
  606. +}
  607. +
  608. +int B25Decoder::put(ARIB_STD_B25_BUFFER *buf)
  609. +{
  610. +   if (isPassThrough())
  611. +   {
  612. +       _pass_through_buf = *buf;
  613. +
  614. +       if (!_init_called)
  615. +           return 0;
  616. +
  617. +       // 一定間隔でinitを試みる
  618. +
  619. +       _pass_through_bytes += buf->size;
  620. +       if (_pass_through_bytes > 1024*1024*8)
  621. +       {
  622. +           if (init() >= 0)
  623. +               goto ready;
  624. +           _pass_through_bytes = 0;
  625. +       }
  626. +
  627. +       return 0;
  628. +   }
  629. +
  630. +ready:
  631. +
  632. +   const int rc = _b25->put(_b25, buf);
  633. +   if (rc < 0)
  634. +   {
  635. +       char tmp[64];
  636. +       sprintf_s(tmp, "b25::put failed. (%d)\n", rc);
  637. +       report(tmp);
  638. +
  639. +       // 乱暴だけどエラーコードに関係なくB-CASカードが抜かれたと判断。
  640. +       // 以降、パススルー動作。
  641. +       // ※カードを抜くとARIB_STD_B25_ERROR_ECM_PROC_FAILURE(-9)
  642. +
  643. +       release();
  644. +       _pass_through_buf = *buf;
  645. +       _pass_through_bytes = buf->size;
  646. +   }
  647. +
  648. +   return rc;
  649. +}
  650. +
  651. +int B25Decoder::get(ARIB_STD_B25_BUFFER *buf)
  652. +{
  653. +   if (isPassThrough())
  654. +   {
  655. +       *buf = _pass_through_buf;
  656. +       return 0;
  657. +   }
  658. +
  659. +   const int rc = _b25->get(_b25, buf);
  660. +   if (rc < 0)
  661. +   {
  662. +       char tmp[64];
  663. +       sprintf_s(tmp, "b25::get failed. (%d)\n", rc);
  664. +       report(tmp);
  665. +       return rc;
  666. +   }
  667. +
  668. +   if (buf->size)
  669. +       return rc;
  670. +
  671. +   return rc;
  672. +}
  673. +
  674. +int B25Decoder::flush()
  675. +{
  676. +   report("B25Decoder::flush()\n");
  677. +
  678. +   if (isPassThrough())
  679. +       return 0;
  680. +
  681. +   const int rc = _b25->flush(_b25);
  682. +   if (rc < 0)
  683. +   {
  684. +       char tmp[64];
  685. +       sprintf_s(tmp, "b25::flush failed. (%d)\n", rc);
  686. +       report(tmp);
  687. +   }
  688. +
  689. +   return rc;
  690. +}
  691. diff -u -r -N a/EDCB-work-plus-s/BonCtrl/decoder.h b/EDCB-work-plus-s/BonCtrl/decoder.h
  692. --- a/EDCB-work-plus-s/BonCtrl/decoder.h    1970-01-01 09:00:00.000000000 +0900
  693. +++ b/EDCB-work-plus-s/BonCtrl/decoder.h    2015-02-09 19:56:28.000000000 +0900
  694. @@ -0,0 +1,56 @@
  695. +// -*- coding: utf-8 -*-
  696. +#pragma once
  697. +
  698. +#include "arib_std_b25.h"
  699. +
  700. +typedef B_CAS_CARD *(*t_create_b_cas_card)();
  701. +typedef ARIB_STD_B25 *(*t_create_arib_std_b25)();
  702. +
  703. +class B25Decoder
  704. +{
  705. +   t_create_b_cas_card f_create_b_cas_card;
  706. +   t_create_arib_std_b25 f_create_arib_std_b25;
  707. +
  708. +   B_CAS_CARD   *_bcas;
  709. +   ARIB_STD_B25 *_b25;
  710. +
  711. +   bool                _init_called;
  712. +   ARIB_STD_B25_BUFFER _pass_through_buf;
  713. +   uint32_t            _pass_through_bytes;
  714. +
  715. +public:
  716. +   B25Decoder(t_create_b_cas_card f_bcas, t_create_arib_std_b25 f_b25);
  717. +
  718. +   ~B25Decoder();
  719. +
  720. +   int init();
  721. +
  722. +   void release();
  723. +
  724. +   int put(ARIB_STD_B25_BUFFER *buf);
  725. +
  726. +   int get(ARIB_STD_B25_BUFFER *buf);
  727. +
  728. +   void decode(ARIB_STD_B25_BUFFER *buf)
  729. +   {
  730. +       (void) put(buf); // putは常に成功する
  731. +       (void) get(buf); // getもlibarib25を読む限り常に成功する
  732. +   }
  733. +
  734. +   int flush();
  735. +
  736. +   bool isValid() const { return _b25 != 0; }
  737. +
  738. +   bool isPassThrough() const { return _b25 == 0; }
  739. +
  740. +   // initialize parameter
  741. +
  742. +   static int multi2_round;
  743. +   static int strip;
  744. +   static int emm_proc;
  745. +
  746. +private:
  747. +
  748. +   B25Decoder(const B25Decoder &); // undef
  749. +   B25Decoder &operator=(const B25Decoder &); // undef
  750. +};
  751. diff -u -r -N a/EDCB-work-plus-s/BonCtrl/DropCount.cpp b/EDCB-work-plus-s/BonCtrl/DropCount.cpp
  752. --- a/EDCB-work-plus-s/BonCtrl/DropCount.cpp    2015-05-06 02:05:26.000000000 +0900
  753. +++ b/EDCB-work-plus-s/BonCtrl/DropCount.cpp    2015-05-04 20:34:50.000000000 +0900
  754. @@ -31,13 +31,7 @@
  755.             map<WORD, DROP_INFO>::iterator itr;
  756.             itr = this->infoMap.find(packet.PID);
  757.             if( itr == this->infoMap.end() ){
  758. -               DROP_INFO item;
  759. -               item.PID = packet.PID;
  760. -               item.lastCounter = packet.continuity_counter;
  761. -               item.total++;
  762. -               if( packet.transport_scrambling_control != 0 ){
  763. -                   item.scramble++;
  764. -               }
  765. +               DROP_INFO item(packet.PID, packet.continuity_counter, ((packet.transport_scrambling_control) != 0));
  766.                 this->infoMap.insert(pair<WORD, DROP_INFO>(item.PID, item));
  767.             }else{
  768.                 CheckCounter(&packet, &(itr->second));
  769. @@ -96,90 +90,75 @@
  770.     }
  771.     info->total++;
  772.  
  773. -   if( tsPacket->PID == 0x1FFF){
  774. +   if( tsPacket->PID == 0x1FFF ){
  775.         return;
  776.     }
  777.     if( tsPacket->transport_scrambling_control != 0 ){
  778.         info->scramble++;
  779.         this->scramble++;
  780.     }
  781. -  
  782. -   if( tsPacket->adaptation_field_control == 0x00 || tsPacket->adaptation_field_control == 0x02 ){
  783. +
  784. +   if( (tsPacket->adaptation_field_control & 0x1) == 0 ){
  785.         //ペイロードが存在しない場合は意味なし
  786. -       info->duplicateFlag = FALSE;
  787.         goto CHK_END;
  788.     }
  789. -   if( info->lastCounter == tsPacket->continuity_counter ){
  790. -       if( tsPacket->adaptation_field_control == 0x01 || tsPacket->adaptation_field_control == 0x03 ){
  791. -           if( tsPacket->transport_scrambling_control == 0 ){
  792. -               if( info->duplicateFlag == FALSE ){
  793. -                   //重送?一応連続と判定
  794. -                   info->duplicateFlag = TRUE;
  795. -                   if( tsPacket->adaptation_field_control == 0x02 || tsPacket->adaptation_field_control == 0x03 ){
  796. -                       if(tsPacket->discontinuity_indicator == 1){
  797. -                           //不連続の判定だが正常
  798. -                           info->duplicateFlag = FALSE;
  799. -                       }
  800. -                   }
  801. -                   goto CHK_END;
  802. -               }else{
  803. -                   //前回重送と判断してるので不連続
  804. -                   info->duplicateFlag = FALSE;
  805. -                   info->drop++;
  806. -                   this->drop++;
  807. -                   goto CHK_END;
  808. -               }
  809. -           }else{
  810. -               goto CHK_END;
  811. -           }
  812. +
  813. +   if( ((info->lastCounter+1) & 0x0F) != tsPacket->continuity_counter ){
  814. +       if( tsPacket->discontinuity_indicator == 1 ){
  815. +           //discontinuity_indicatorがtrueの場合は正常として扱う
  816. +           //3連続以上は起こり得ない事になっているが、とりあえず考慮しない
  817. +           goto CHK_END;
  818.         }
  819. -   }
  820. -   if( info->lastCounter+1 != tsPacket->continuity_counter ){
  821. -       if( info->lastCounter != 0x0F && tsPacket->continuity_counter != 0x00 ){
  822. -           if(tsPacket->discontinuity_indicator == 1){
  823. -               //不連続の判定だが正常
  824. -               goto CHK_END;
  825. +       if( info->lastCounter == tsPacket->continuity_counter ){
  826. +           if( info->duplicateFlag == FALSE ){
  827. +               //重送?一応連続と判定
  828. +               info->duplicateFlag = TRUE;
  829. +               goto CHK_END2;
  830.             }
  831. -           //カウンターが飛んだので不連続
  832. -           ULONGLONG count = 0;
  833. -           if( tsPacket->continuity_counter <= info->lastCounter ){
  834. -               count = (tsPacket->continuity_counter+15) - info->lastCounter;
  835. -           }else{
  836. -               count = tsPacket->continuity_counter - info->lastCounter;
  837. -           }
  838. -
  839. -           info->drop+= count;
  840. -           this->drop+= count;
  841. -           info->total+= count-1;
  842. +           //前回重送と判断してるので不連続
  843. +           info->drop++;   //数値としてはおかしいがどのみちこの時点では既に正確な値はわからない
  844. +           this->drop++;
  845. +           //オリジナルではスクランブル未解除ではこの場合のドロップを検出していないが、
  846. +           //スクランブルされていても当然ドロップの発生はあり得るので…
  847.             goto CHK_END;
  848.         }
  849. +       //カウンターが飛んだので不連続
  850. +       //同じ値の場合はここには来ないのでこれで大丈夫
  851. +       //なおオリジナルと数値が異なる場合(lastCounter=0,continuity_counter=2の場合等)があるが
  852. +       //ドロップ数のカウントとしてはこちらの方が正しいはず
  853. +       int count = (((tsPacket->continuity_counter + 0x10) - info->lastCounter) & 0x0F) - 1;
  854. +       info->drop += count;
  855. +       this->drop += count;
  856. +       info->total += count;
  857.     }
  858.  
  859.  CHK_END:
  860. +   //重送->しばらく普通->また重送の様なパターンを考慮してフラグは毎回リセットする
  861. +   info->duplicateFlag = FALSE;
  862. +CHK_END2:
  863.     info->lastCounter = tsPacket->continuity_counter;
  864. -   if( GetTickCount() - this->lastLogTime > 5000 ){
  865. -       if( this->lastLogDrop != this->drop ||
  866. -           this->lastLogScramble != this->scramble
  867. -           ){
  868. -               wstring log;
  869. -               SYSTEMTIME now;
  870. -               GetLocalTime(&now);
  871. -               Format(log, L"%04d/%02d/%02d %02d:%02d:%02d Drop:%I64d Scramble:%I64d Signal: %.02f",
  872. -                   now.wYear,
  873. -                   now.wMonth,
  874. -                   now.wDay,
  875. -                   now.wHour,
  876. -                   now.wMinute,
  877. -                   now.wSecond,
  878. -                   this->drop,
  879. -                   this->scramble,
  880. -                   this->signalLv
  881. -                   );
  882. -               this->log.push_back(log);
  883. -               this->lastLogDrop = this->drop;
  884. -               this->lastLogScramble = this->scramble;
  885. +   if( this->lastLogDrop != this->drop || this->lastLogScramble != this->scramble ){
  886. +       DWORD t;
  887. +       if( ((t = GetTickCount()) - this->lastLogTime) > 5000 ){
  888. +           wstring log;
  889. +           SYSTEMTIME now;
  890. +           GetLocalTime(&now);
  891. +           Format(log, L"%04d/%02d/%02d %02d:%02d:%02d Drop:%I64d Scramble:%I64d Signal: %.02f",
  892. +               now.wYear,
  893. +               now.wMonth,
  894. +               now.wDay,
  895. +               now.wHour,
  896. +               now.wMinute,
  897. +               now.wSecond,
  898. +               this->drop,
  899. +               this->scramble,
  900. +               this->signalLv
  901. +               );
  902. +           this->log.push_back(log);
  903. +           this->lastLogDrop = this->drop;
  904. +           this->lastLogScramble = this->scramble;
  905. +           this->lastLogTime = t;
  906.         }
  907. -       this->lastLogTime = GetTickCount();
  908.     }
  909.  }
  910.  
  911. @@ -284,12 +263,10 @@
  912.     }
  913.  }
  914.  
  915. -void CDropCount::SetPIDName(
  916. -   map<WORD, string>* pidName
  917. -   )
  918. +void CDropCount::SetPIDName(map<WORD, string>* pidName)
  919.  {
  920.     map<WORD, string>::iterator itrIn;
  921. -   for(itrIn = pidName->begin(); itrIn != pidName->end(); itrIn++){
  922. +   for( itrIn = pidName->begin(); itrIn != pidName->end(); itrIn++ ){
  923.         map<WORD, string>::iterator itrSet;
  924.         itrSet = this->pidName.find(itrIn->first);
  925.         if( itrSet != this->pidName.end() ){
  926. diff -u -r -N a/EDCB-work-plus-s/BonCtrl/DropCount.h b/EDCB-work-plus-s/BonCtrl/DropCount.h
  927. --- a/EDCB-work-plus-s/BonCtrl/DropCount.h  2015-05-06 02:05:26.000000000 +0900
  928. +++ b/EDCB-work-plus-s/BonCtrl/DropCount.h  2015-04-28 18:52:26.000000000 +0900
  929. @@ -35,13 +35,13 @@
  930.         ULONGLONG total;
  931.         ULONGLONG drop;
  932.         ULONGLONG scramble;
  933. -       _DROP_INFO(){
  934. -           PID = 0xFFFF;
  935. -           lastCounter = 0;
  936. +       _DROP_INFO(WORD pid, BYTE lc, BOOL bsc){
  937. +           PID = pid;
  938. +           lastCounter = lc;
  939.             duplicateFlag = FALSE;
  940. -           total = 0;
  941.             drop = 0;
  942. -           scramble = 0;
  943. +           scramble = bsc ? 1 : 0;
  944. +           total = 1;
  945.         };
  946.     }DROP_INFO;
  947.  
  948. diff -u -r -N a/EDCB-work-plus-s/BonCtrl/OneServiceUtil.cpp b/EDCB-work-plus-s/BonCtrl/OneServiceUtil.cpp
  949. --- a/EDCB-work-plus-s/BonCtrl/OneServiceUtil.cpp   2015-05-06 02:05:26.000000000 +0900
  950. +++ b/EDCB-work-plus-s/BonCtrl/OneServiceUtil.cpp   2015-05-08 10:48:45.000000000 +0900
  951. @@ -19,6 +19,8 @@
  952.     this->pittariStart = FALSE;
  953.     this->pittariEndChk = FALSE;
  954.     this->maxBuffCount = -1;
  955. +
  956. +   this->buff.reserve(188*256);
  957.  }
  958.  
  959.  
  960. @@ -111,7 +113,7 @@
  961.             while(1){
  962.                 Format(key, L"%s%d_%d", MUTEX_UDP_PORT_NAME, (*sendList)[i].ip, (*sendList)[i].port );
  963.                 HANDLE mutex = ::OpenMutex(MUTEX_ALL_ACCESS, FALSE, key.c_str());
  964. -      
  965. +
  966.                 if(mutex){
  967.                     ::CloseHandle(mutex);
  968.                     (*sendList)[i].port++;
  969. @@ -165,7 +167,7 @@
  970.             while(1){
  971.                 Format(key, L"%s%d_%d", MUTEX_TCP_PORT_NAME, (*sendList)[i].ip, (*sendList)[i].port );
  972.                 HANDLE mutex = ::OpenMutex(MUTEX_ALL_ACCESS, FALSE, key.c_str());
  973. -      
  974. +
  975.                 if(mutex){
  976.                     ::CloseHandle(mutex);
  977.                     (*sendList)[i].port++;
  978. @@ -208,7 +210,7 @@
  979.             CTSPacketUtil packet;
  980.             if( packet.Set188TS(data + i, 188) == TRUE ){
  981.                 if( packet.PID == this->pmtPID ){
  982. -                   DWORD err = createPmt.AddData(&packet);
  983. +                   createPmt.AddData(&packet);
  984.                 }
  985.             }
  986.         }
  987. @@ -229,21 +231,20 @@
  988.                     }
  989.                 }else if( packet.PID == this->pmtPID ){
  990.                     //PMT
  991. -                   DWORD err = createPmt.AddData(&packet);
  992. -                   if( err == NO_ERR || err == ERR_NO_CHAGE ){
  993. -                       BYTE* pmtBuff = NULL;
  994. -                       DWORD pmtBuffSize = 0;
  995. +                   if (createPmt.AddData(&packet) == ERR_FALSE){
  996. +                       OutputDebugString(L"createPmt.AddData Err");
  997. +                       //そのまま
  998. +                       //this->buff.insert(this->buff.end(), data + i, data + i + 188);
  999. +                   }else{
  1000. +                       BYTE* pmtBuff;
  1001. +                       DWORD pmtBuffSize;
  1002.                         if( createPmt.GetPacket(&pmtBuff, &pmtBuffSize) == TRUE ){
  1003.                             this->buff.insert(this->buff.end(), pmtBuff, pmtBuff + pmtBuffSize);
  1004.                         }else{
  1005. -                           _OutputDebugString(L"createPmt.GetPacket Err");
  1006. +                           OutputDebugString(L"createPmt.GetPacket Err");
  1007.                             //そのまま
  1008. -                           this->buff.insert(this->buff.end(), data + i, data + i + 188);
  1009. +                           //this->buff.insert(this->buff.end(), data + i, data + i + 188);
  1010.                         }
  1011. -                   }else if( err == FALSE ){
  1012. -                       _OutputDebugString(L"createPmt.AddData Err");
  1013. -                       //そのまま
  1014. -                       this->buff.insert(this->buff.end(), data + i, data + i + 188);
  1015.                     }
  1016.                 }else{
  1017.                     //その他
  1018. @@ -338,11 +339,11 @@
  1019.         item.PMTPID = pmtPID;
  1020.         item.SID = this->SID;
  1021.         PIDMap.insert(pair<WORD, CCreatePATPacket::PROGRAM_PID_INFO>(item.PMTPID,item));
  1022. -      
  1023. +
  1024.         item.PMTPID = 0x0010;
  1025.         item.SID = 0x00;
  1026.         PIDMap.insert(pair<WORD, CCreatePATPacket::PROGRAM_PID_INFO>(item.PMTPID,item));
  1027. -      
  1028. +
  1029.         createPat.SetParam(TSID, &PIDMap);
  1030.  
  1031.         this->pmtPID = pmtPID;
  1032. @@ -549,7 +550,6 @@
  1033.     this->dropCount.SaveLog(filePath);
  1034.  }
  1035.  
  1036. -
  1037.  void COneServiceUtil::SetSignalLevel(
  1038.     float signalLv
  1039.     )
  1040. diff -u -r -N a/EDCB-work-plus-s/BonCtrl/PacketInit.cpp b/EDCB-work-plus-s/BonCtrl/PacketInit.cpp
  1041. --- a/EDCB-work-plus-s/BonCtrl/PacketInit.cpp   2015-05-06 02:05:26.000000000 +0900
  1042. +++ b/EDCB-work-plus-s/BonCtrl/PacketInit.cpp   2015-05-01 05:22:07.000000000 +0900
  1043. @@ -1,6 +1,7 @@
  1044.  #include "StdAfx.h"
  1045.  #include "PacketInit.h"
  1046.  
  1047. +#ifndef USE_MOD_SYNCLOGIC
  1048.  CPacketInit::CPacketInit(void)
  1049.  {
  1050.     this->nextStartSize = 0;
  1051. @@ -32,7 +33,7 @@
  1052.     DWORD inSize,
  1053.     BYTE** outData,
  1054.     DWORD* outSize
  1055. -)
  1056. +   )
  1057.  {
  1058.     if( inData == NULL || inSize == 0 || outData == NULL || outSize == NULL ){
  1059.         return FALSE;
  1060. @@ -121,3 +122,231 @@
  1061.     }
  1062.     return FALSE;
  1063.  }
  1064. +#else
  1065. +CPacketInit::CPacketInit(void)
  1066. +{
  1067. +   m_dwSyncBufPos = 0;
  1068. +   m_dwUnitSize = 0;
  1069. +}
  1070. +
  1071. +CPacketInit::~CPacketInit(void)
  1072. +{
  1073. +}
  1074. +
  1075. +void CPacketInit::ClearBuff()
  1076. +{
  1077. +   m_dwSyncBufPos = 0;
  1078. +   m_dwUnitSize = 0;
  1079. +}
  1080. +
  1081. +//入力バッファを188バイト単位のTSに変換し、188の倍数になるようにそろえる
  1082. +//戻り値:
  1083. +// TRUE(成功)、FALSE(失敗)
  1084. +//引数:
  1085. +// pSrc            [IN]入力TSデータ
  1086. +// dwSrc       [IN]pSrcのサイズ(BYTE単位)
  1087. +// ppDst       [OUT]188バイトに整列したバッファ(呼び出し元でdeleteする必要あり)
  1088. +// pdwDst      [OUT]ppDstのサイズ(BYTE単位)
  1089. +BOOL CPacketInit::GetTSData(
  1090. +   BYTE* pSrc,
  1091. +   DWORD dwSrc,
  1092. +   BYTE** ppDst,
  1093. +   DWORD* pdwDst
  1094. +   )
  1095. +{
  1096. +   // 既に同期済みか?
  1097. +   if (m_dwUnitSize != 0)
  1098. +   {
  1099. +       for (DWORD pos = m_dwUnitSize - m_dwSyncBufPos; pos < dwSrc; pos += m_dwUnitSize)
  1100. +       {
  1101. +           if (pSrc[pos] != TS_SYNC_BYTE)
  1102. +           {
  1103. +               // 今回の入力バッファで同期が崩れてしまうので要再同期
  1104. +               m_dwUnitSize = 0;
  1105. +               break;
  1106. +           }
  1107. +       }
  1108. +       if (m_dwUnitSize != 0)
  1109. +       {
  1110. +           DWORD dwDst = TS_PKTSIZE * ((m_dwSyncBufPos + dwSrc) / m_dwUnitSize);
  1111. +           if (dwDst == 0)
  1112. +           {
  1113. +               // 同期用繰り越しバッファと今回の入力バッファを合わせてもユニットサイズに届かなかったので、
  1114. +               // 今回の入力バッファを同期用繰り越しバッファに追加するだけで終了
  1115. +               ::memcpy(&m_SyncBuf[m_dwSyncBufPos], pSrc, dwSrc);
  1116. +               m_dwSyncBufPos += dwSrc;
  1117. +               *ppDst = NULL;  // 呼び出し側でのdelete[]を保証する
  1118. +               *pdwDst = 0;
  1119. +               return FALSE;
  1120. +           }
  1121. +           BYTE *pDst = new BYTE[dwDst];
  1122. +           if (m_dwSyncBufPos == 0)
  1123. +               ::memcpy(pDst, pSrc, TS_PKTSIZE);
  1124. +           else
  1125. +           {
  1126. +               if (m_dwSyncBufPos >= TS_PKTSIZE)
  1127. +                   ::memcpy(pDst, m_SyncBuf, TS_PKTSIZE);
  1128. +               else
  1129. +               {
  1130. +                   ::memcpy(pDst, m_SyncBuf, m_dwSyncBufPos);
  1131. +                   ::memcpy(&pDst[m_dwSyncBufPos], pSrc, TS_PKTSIZE - m_dwSyncBufPos);
  1132. +               }
  1133. +           }
  1134. +           DWORD dwSrcPos = m_dwUnitSize - m_dwSyncBufPos;
  1135. +           if (m_dwUnitSize == TS_PKTSIZE)
  1136. +           {
  1137. +               // 普通のTSパケットの場合はそのままコピーできる
  1138. +               ::memcpy(&pDst[TS_PKTSIZE], &pSrc[dwSrcPos], (dwDst - TS_PKTSIZE));
  1139. +               dwSrcPos += (dwDst - TS_PKTSIZE);
  1140. +           }
  1141. +           else
  1142. +           {
  1143. +               // それ以外のパケットの場合は普通のTSパケットに変換
  1144. +               for (DWORD pos = TS_PKTSIZE; (dwSrcPos + m_dwUnitSize) <= dwSrc; dwSrcPos += m_dwUnitSize, pos += TS_PKTSIZE)
  1145. +                   ::memcpy(&pDst[pos], &pSrc[dwSrcPos], TS_PKTSIZE);
  1146. +           }
  1147. +           if ((dwSrc - dwSrcPos) > 0)
  1148. +           {
  1149. +               // 入力バッファに余りがあるので同期用繰り越しバッファに保存
  1150. +               ::memcpy(m_SyncBuf, &pSrc[dwSrcPos], (dwSrc - dwSrcPos));
  1151. +               m_dwSyncBufPos = dwSrc - dwSrcPos;
  1152. +           }
  1153. +           else
  1154. +               m_dwSyncBufPos = 0;
  1155. +           *ppDst = pDst;
  1156. +           *pdwDst = dwDst;
  1157. +           return TRUE;
  1158. +       }
  1159. +   }
  1160. +
  1161. +   // 同期処理開始
  1162. +   DWORD dwSyncBufPos = m_dwSyncBufPos;
  1163. +   for (DWORD off = 0; (off + TS_PKTSIZE) < (dwSyncBufPos + dwSrc); off++)
  1164. +   {
  1165. +       if (((off >= dwSyncBufPos) && (pSrc[off - dwSyncBufPos] == TS_SYNC_BYTE)) || ((off < dwSyncBufPos) && (m_SyncBuf[off] == TS_SYNC_BYTE)))
  1166. +       {
  1167. +           for (int type = 0; type < 4; type++)
  1168. +           {
  1169. +               DWORD dwUnitSize;
  1170. +               switch (type)
  1171. +               {
  1172. +               case 0:
  1173. +                   dwUnitSize = TS_PKTSIZE;
  1174. +                   break;
  1175. +               case 1:
  1176. +                   dwUnitSize = TTS_PKTSIZE;
  1177. +                   break;
  1178. +               case 2:
  1179. +                   dwUnitSize = TS_FEC_PKTSIZE;
  1180. +                   break;
  1181. +               default:
  1182. +                   dwUnitSize = TTS_FEC_PKTSIZE;
  1183. +                   break;
  1184. +               }
  1185. +               BOOL bSync = TRUE;
  1186. +               if (dwUnitSize >= dwSyncBufPos)
  1187. +               {
  1188. +                   DWORD pos = off + (dwUnitSize - dwSyncBufPos);
  1189. +                   if (pos >= dwSrc)
  1190. +                   {
  1191. +                       // bSync = FALSE;
  1192. +                       // これ以降のユニットサイズではこの場所で同期成功する事は無いのでbreak
  1193. +                       break;
  1194. +                   }
  1195. +                   else
  1196. +                   {
  1197. +                       // 同一ユニットサイズのバッファが8個もしくは今回の入力バッファの
  1198. +                       // 最後まで並んでいるなら同期成功とみなす
  1199. +                       int n = 0;
  1200. +                       do
  1201. +                       {
  1202. +                           if (pSrc[pos] != TS_SYNC_BYTE)
  1203. +                           {
  1204. +                               bSync = FALSE;
  1205. +                               break;
  1206. +                           }
  1207. +                           pos += dwUnitSize;
  1208. +                           n++;
  1209. +                       } while ((n < 8) && (pos < dwSrc));
  1210. +                   }
  1211. +               }
  1212. +               else
  1213. +               {
  1214. +                   DWORD pos = off + dwUnitSize;
  1215. +                   if (pos >= (dwSyncBufPos + dwSrc))
  1216. +                   {
  1217. +                       // bSync = FALSE;
  1218. +                       // これ以降のユニットサイズではこの場所で同期成功する事は無いのでbreak
  1219. +                       break;
  1220. +                   }
  1221. +                   else
  1222. +                   {
  1223. +                       // 同一ユニットサイズのバッファが8個もしくは今回の入力バッファの
  1224. +                       // 最後まで並んでいるなら同期成功とみなす
  1225. +                       int n = 0;
  1226. +                       do
  1227. +                       {
  1228. +                           if (((pos >= dwSyncBufPos) && (pSrc[pos - dwSyncBufPos] != TS_SYNC_BYTE)) || ((pos < dwSyncBufPos) && (m_SyncBuf[pos] != TS_SYNC_BYTE)))
  1229. +                           {
  1230. +                               bSync = FALSE;
  1231. +                               break;
  1232. +                           }
  1233. +                           pos += dwUnitSize;
  1234. +                           n++;
  1235. +                       } while ((n < 8) && (pos < (dwSyncBufPos + dwSrc)));
  1236. +                   }
  1237. +               }
  1238. +               if (bSync)
  1239. +               {
  1240. +                   m_dwUnitSize = dwUnitSize;
  1241. +                   if (off < dwSyncBufPos)
  1242. +                   {
  1243. +                       if (off > 0)
  1244. +                       {
  1245. +                           dwSyncBufPos -= off;
  1246. +                           ::memmove(m_SyncBuf, &m_SyncBuf[off], dwSyncBufPos);
  1247. +                       }
  1248. +                       // この同期検出ロジックでは↓の状態は起こり得ないハズ
  1249. +#if 0
  1250. +                       // 同期済み時の同期用繰り越しバッファサイズはユニットサイズ以下である必要がある
  1251. +                       if (dwSyncBufPos > dwUnitSize)
  1252. +                       {
  1253. +                           dwSyncBufPos -= dwUnitSize;
  1254. +                           ::memmove(m_SyncBuf, &m_SyncBuf[dwUnitSize], dwSyncBufPos);
  1255. +                       }
  1256. +#endif
  1257. +                       m_dwSyncBufPos = dwSyncBufPos;
  1258. +                       return GetTSData(pSrc, dwSrc, ppDst, pdwDst);
  1259. +                   }
  1260. +                   else
  1261. +                   {
  1262. +                       m_dwSyncBufPos = 0;
  1263. +                       return GetTSData(&pSrc[off - dwSyncBufPos], (dwSrc - (off - dwSyncBufPos)), ppDst, pdwDst);
  1264. +                   }
  1265. +               }
  1266. +           }
  1267. +       }
  1268. +   }
  1269. +
  1270. +   // 今回の入力では同期できなかったので、同期用繰り越しバッファに保存だけして終了
  1271. +   if (dwSrc >= sizeof(m_SyncBuf))
  1272. +   {
  1273. +       ::memcpy(m_SyncBuf, &pSrc[dwSrc - sizeof(m_SyncBuf)], sizeof(m_SyncBuf));
  1274. +       m_dwSyncBufPos = sizeof(m_SyncBuf);
  1275. +   }
  1276. +   else if ((dwSyncBufPos + dwSrc) > sizeof(m_SyncBuf))
  1277. +   {
  1278. +       ::memmove(m_SyncBuf, &m_SyncBuf[(dwSyncBufPos + dwSrc) - sizeof(m_SyncBuf)], (sizeof(m_SyncBuf) - dwSrc));
  1279. +       ::memcpy(&m_SyncBuf[sizeof(m_SyncBuf) - dwSrc], pSrc, dwSrc);
  1280. +       m_dwSyncBufPos = sizeof(m_SyncBuf);
  1281. +   }
  1282. +   else
  1283. +   {
  1284. +       ::memcpy(&m_SyncBuf[dwSyncBufPos], pSrc, dwSrc);
  1285. +       m_dwSyncBufPos += dwSrc;
  1286. +   }
  1287. +   *ppDst = NULL;  // 呼び出し側でのdelete[]を保証する
  1288. +   *pdwDst = 0;
  1289. +   return FALSE;
  1290. +}
  1291. +#endif
  1292. diff -u -r -N a/EDCB-work-plus-s/BonCtrl/PacketInit.h b/EDCB-work-plus-s/BonCtrl/PacketInit.h
  1293. --- a/EDCB-work-plus-s/BonCtrl/PacketInit.h 2015-05-06 02:05:26.000000000 +0900
  1294. +++ b/EDCB-work-plus-s/BonCtrl/PacketInit.h 2015-05-01 05:21:52.000000000 +0900
  1295. @@ -1,9 +1,12 @@
  1296.  #pragma once
  1297.  
  1298. +#define USE_MOD_SYNCLOGIC
  1299. +
  1300.  #include <windows.h>
  1301.  
  1302.  #include "../Common/Util.h"
  1303.  
  1304. +#ifndef USE_MOD_SYNCLOGIC
  1305.  class CPacketInit
  1306.  {
  1307.  public:
  1308. @@ -34,3 +37,40 @@
  1309.  
  1310.     DWORD packetSize;
  1311.  };
  1312. +#else
  1313. +#define TS_SYNC_BYTE   0x47
  1314. +#define TS_PKTSIZE     188
  1315. +#define TTS_PKTSIZE        192
  1316. +#define TS_FEC_PKTSIZE 204
  1317. +#define TTS_FEC_PKTSIZE    208
  1318. +class CPacketInit
  1319. +{
  1320. +public:
  1321. +   CPacketInit(void);
  1322. +   ~CPacketInit(void);
  1323. +
  1324. +   //入力バッファを188バイト単位のTSに変換し、188の倍数になるようにそろえる
  1325. +   //戻り値:
  1326. +   // TRUE(成功)、FALSE(失敗)
  1327. +   //引数:
  1328. +   // inData           [IN]入力TSデータ
  1329. +   // inSize           [IN]inDataのサイズ(BYTE単位)
  1330. +   // outData          [OUT]188バイトに整列したバッファ(呼び出し元でdeleteする必要あり)
  1331. +   // outSize          [OUT]outDataのサイズ(BYTE単位)
  1332. +   BOOL GetTSData(
  1333. +       BYTE* pSrc,
  1334. +       DWORD dwSrc,
  1335. +       BYTE** ppDst,
  1336. +       DWORD* pdwDst
  1337. +       );
  1338. +
  1339. +   //内部バッファのクリア
  1340. +   void ClearBuff();
  1341. +
  1342. +protected:
  1343. +   BYTE m_SyncBuf[256];
  1344. +   DWORD m_dwSyncBufPos;
  1345. +
  1346. +   DWORD m_dwUnitSize;
  1347. +};
  1348. +#endif
  1349. \ No newline at end of file
  1350. diff -u -r -N a/EDCB-work-plus-s/BonCtrl/PMTUtil.cpp b/EDCB-work-plus-s/BonCtrl/PMTUtil.cpp
  1351. --- a/EDCB-work-plus-s/BonCtrl/PMTUtil.cpp  2015-05-06 02:05:26.000000000 +0900
  1352. +++ b/EDCB-work-plus-s/BonCtrl/PMTUtil.cpp  2015-04-29 06:07:47.000000000 +0900
  1353. @@ -7,10 +7,10 @@
  1354.  CPMTUtil::CPMTUtil(void)
  1355.  {
  1356.     this->program_number = 0xFFFF;
  1357. +   this->version_number = 0xFF;
  1358.     this->PCR_PID = 0xFFFF;
  1359.  }
  1360.  
  1361. -
  1362.  CPMTUtil::~CPMTUtil(void)
  1363.  {
  1364.     Clear();
  1365. @@ -22,17 +22,18 @@
  1366.         return FALSE;
  1367.     }
  1368.     if( buffUtil.Add188TS(packet) == TRUE ){
  1369. -       BYTE* section = NULL;
  1370. -       DWORD sectionSize = 0;
  1371. +       BYTE* section;
  1372. +       DWORD sectionSize;
  1373. +       BOOL ret = FALSE;
  1374.         while( buffUtil.GetSectionBuff( &section, &sectionSize ) == TRUE ){
  1375. -           if( DecodePMT(section, sectionSize) == FALSE ){
  1376. -               return FALSE;
  1377. +           if (DecodePMT(section, sectionSize) == TRUE){
  1378. +               // 一回でも新PMTが来たらTRUEを返す(バッファを空にするためループは最後まで回す)
  1379. +               ret = TRUE;
  1380.             }
  1381.         }
  1382. -   }else{
  1383. -       return FALSE;
  1384. +       return ret;
  1385.     }
  1386. -   return TRUE;
  1387. +   return FALSE;
  1388.  }
  1389.  
  1390.  void CPMTUtil::Clear()
  1391. @@ -41,29 +42,26 @@
  1392.         SAFE_DELETE(ESInfoList[i]);
  1393.     }
  1394.     ESInfoList.clear();
  1395. -
  1396.     PIDList.clear();
  1397.  }
  1398.  
  1399.  BOOL CPMTUtil::DecodePMT(BYTE* data, DWORD dataSize)
  1400.  {
  1401. -   Clear();
  1402. -
  1403. +/*
  1404.     if( data == NULL ){
  1405.         return FALSE;
  1406.     }
  1407. -
  1408. +*/
  1409.     if( dataSize < 7 ){
  1410.         return FALSE;
  1411.     }
  1412.  
  1413. -   DWORD readSize = 0;
  1414.     //////////////////////////////////////////////////////
  1415.     //解析処理
  1416.     table_id = data[0];
  1417.     section_syntax_indicator = (data[1]&0x80)>>7;
  1418.     section_length = ((WORD)data[1]&0x0F)<<8 | data[2];
  1419. -   readSize+=3;
  1420. +   DWORD readSize = 3;
  1421.  
  1422.     if( section_syntax_indicator != 1 ){
  1423.         //固定値がおかしい
  1424. @@ -91,12 +89,24 @@
  1425.     }
  1426.  
  1427.     if( section_length > 12 ){
  1428. -       program_number = ((WORD)data[readSize])<<8 | data[readSize+1];
  1429. -       version_number = (data[readSize+2]&0x3E)>>1;
  1430. +
  1431. +       WORD new_program_number = ((WORD)data[readSize]) << 8 | data[readSize + 1];
  1432. +       BYTE new_version_number = (data[readSize + 2] >> 1) & 0x1F;
  1433. +       WORD new_PCR_PID = ((WORD)data[readSize + 5] & 0x1F) << 8 | data[readSize + 6];
  1434. +       if (PCR_PID == new_PCR_PID && program_number == new_program_number && version_number == new_version_number){
  1435. +           //バージョン同じ
  1436. +           return FALSE;
  1437. +       }
  1438. +
  1439. +       // リストがつくり直しになるのでここでClear()
  1440. +       Clear();
  1441. +
  1442. +       program_number = new_program_number;
  1443. +       version_number = new_version_number;
  1444.         current_next_indicator = data[readSize+2]&0x01;
  1445.         section_number = data[readSize+3];
  1446.         last_section_number = data[readSize+4];
  1447. -       PCR_PID = ((WORD)data[readSize+5]&0x1F)<<8 | data[readSize+6];
  1448. +       PCR_PID = new_PCR_PID;
  1449.         program_info_length = ((WORD)data[readSize+7]&0x0F)<<8 | data[readSize+8];
  1450.         readSize += 9;
  1451.  
  1452. diff -u -r -N a/EDCB-work-plus-s/BonCtrl/portable.h b/EDCB-work-plus-s/BonCtrl/portable.h
  1453. --- a/EDCB-work-plus-s/BonCtrl/portable.h   1970-01-01 09:00:00.000000000 +0900
  1454. +++ b/EDCB-work-plus-s/BonCtrl/portable.h   2015-02-13 00:10:58.000000000 +0900
  1455. @@ -0,0 +1,21 @@
  1456. +#ifndef PORTABLE_H
  1457. +#define PORTABLE_H
  1458. +
  1459. +#if (defined(_WINDOWS) && MSC_VER < 1300)
  1460. +
  1461. +typedef unsigned char     uint8_t;
  1462. +typedef   signed char      int8_t;
  1463. +typedef unsigned short   uint16_t;
  1464. +typedef   signed short    int16_t;
  1465. +typedef unsigned int     uint32_t;
  1466. +typedef   signed int      int32_t;
  1467. +typedef unsigned __int64 uint64_t;
  1468. +typedef   signed __int64  int64_t;
  1469. +
  1470. +#else
  1471. +
  1472. +#include <inttypes.h>
  1473. +
  1474. +#endif
  1475. +
  1476. +#endif /* PORTABLE_H */
  1477. diff -u -r -N a/EDCB-work-plus-s/BonCtrl/ScrambleDecoderUtil.cpp b/EDCB-work-plus-s/BonCtrl/ScrambleDecoderUtil.cpp
  1478. --- a/EDCB-work-plus-s/BonCtrl/ScrambleDecoderUtil.cpp  2015-05-06 02:05:26.000000000 +0900
  1479. +++ b/EDCB-work-plus-s/BonCtrl/ScrambleDecoderUtil.cpp  2015-02-14 06:01:12.000000000 +0900
  1480. @@ -6,9 +6,8 @@
  1481.  {
  1482.     this->currentDll = L"";
  1483.  
  1484. -   this->decodeIF = NULL;
  1485. -   this->decodeIF2 = NULL;
  1486.     this->module = NULL;
  1487. +   this->b25 = NULL;
  1488.  
  1489.     this->emmEnable = false;
  1490.  }
  1491. @@ -27,30 +26,23 @@
  1492.     if( this->module == NULL ){
  1493.         return FALSE;
  1494.     }
  1495. -   IB25Decoder* (*func)();
  1496. -   func = (IB25Decoder* (*)())::GetProcAddress( this->module, "CreateB25Decoder");
  1497. -   if( !func ){
  1498. +   t_create_b_cas_card f_bcas;
  1499. +   f_bcas = (t_create_b_cas_card)::GetProcAddress(this->module, "create_b_cas_card");
  1500. +   if( !f_bcas ){
  1501.         ret = FALSE;
  1502.         goto ERR_END;
  1503.     }
  1504. -   this->decodeIF = func();
  1505. -   if( this->decodeIF->Initialize() == FALSE ){
  1506. -       this->decodeIF->Release();
  1507. -       this->decodeIF = NULL;
  1508. +   t_create_arib_std_b25 f_b25;
  1509. +   f_b25 = (t_create_arib_std_b25)::GetProcAddress(this->module, "create_arib_std_b25");
  1510. +   if( !f_b25 ){
  1511. +       ret = FALSE;
  1512. +       goto ERR_END;
  1513. +   }
  1514. +
  1515. +   this->b25 = new B25Decoder(f_bcas, f_b25);
  1516. +   B25Decoder::emm_proc = this->emmEnable ? 1 : 0;
  1517. +   if( this->b25->init() < 0 ){
  1518.         ret = FALSE;
  1519. -   }else{
  1520. -       try{
  1521. -           this->decodeIF2 = dynamic_cast<IB25Decoder2 *>(this->decodeIF);
  1522. -           if( this->decodeIF2 != NULL ){
  1523. -               //this->decodeIF2->EnableEmmProcess(false);
  1524. -               this->decodeIF2->DiscardNullPacket(true);
  1525. -               this->decodeIF2->DiscardScramblePacket(false);
  1526. -               this->decodeIF2->EnableEmmProcess(this->emmEnable);
  1527. -           }
  1528. -       }
  1529. -       catch(std::__non_rtti_object){
  1530. -           this->decodeIF2 = NULL;
  1531. -       }
  1532.     }
  1533.  ERR_END:
  1534.     if( ret == FALSE ){
  1535. @@ -62,10 +54,9 @@
  1536.  
  1537.  void CScrambleDecoderUtil::UnLoadDll()
  1538.  {
  1539. -   if( this->decodeIF != NULL ){
  1540. -       this->decodeIF->Release();
  1541. -       this->decodeIF = NULL;
  1542. -       this->decodeIF2 = NULL;
  1543. +   if( this->b25 != NULL ){
  1544. +       delete this->b25;
  1545. +       this->b25 = NULL;
  1546.     }
  1547.     if( this->module != NULL ){
  1548.         ::FreeLibrary( this->module );
  1549. @@ -114,8 +105,8 @@
  1550.         dllPath += defDll;
  1551.         this->loadDll = defDll;
  1552.     }else{
  1553. -       dllPath += L"\\B25Decoder.dll";
  1554. -       this->loadDll = L"B25Decoder.dll";
  1555. +       dllPath += L"\\arib_std_b25.dll";
  1556. +       this->loadDll = L"arib_std_b25.dll";
  1557.     }
  1558.  
  1559.     if( CompareNoCase(dllPath, this->currentDll) != 0 ){
  1560. @@ -126,6 +117,8 @@
  1561.             this->currentDll = dllPath;
  1562.             ret = TRUE;
  1563.         }
  1564. +   }else{
  1565. +       ret = TRUE;
  1566.     }
  1567.  
  1568.     return ret;
  1569. @@ -133,31 +126,33 @@
  1570.  
  1571.  BOOL CScrambleDecoderUtil::Decode(BYTE* src, DWORD srcSize, BYTE** dest, DWORD* destSize)
  1572.  {
  1573. -   if( this->decodeIF == NULL ){
  1574. +   if( this->b25 == NULL ){
  1575.         return FALSE;
  1576.     }
  1577. -   return this->decodeIF->Decode(src, srcSize, dest, destSize);
  1578. +   ARIB_STD_B25_BUFFER buf;
  1579. +   buf.data = src;
  1580. +   buf.size = srcSize;
  1581. +   this->b25->decode(&buf);
  1582. +   *dest = buf.data;
  1583. +   *destSize = buf.size;
  1584. +   return TRUE;
  1585.  }
  1586.  
  1587. +/*
  1588.  void CScrambleDecoderUtil::Reset()
  1589.  {
  1590. -   if( this->decodeIF == NULL ){
  1591. +   if( this->b25 == NULL ){
  1592.         return ;
  1593.     }
  1594. -   this->decodeIF->Reset();
  1595. +   this->b25->Reset();
  1596.  }
  1597. -
  1598. +*/
  1599.  
  1600.  BOOL CScrambleDecoderUtil::SetEmm(BOOL enable)
  1601.  {
  1602. -   if( this->decodeIF2 == NULL ){
  1603. -       return FALSE;
  1604. -   }
  1605.     if( enable == TRUE ){
  1606. -       this->decodeIF2->EnableEmmProcess(true);
  1607.         this->emmEnable = true;
  1608.     }else{
  1609. -       this->decodeIF2->EnableEmmProcess(false);
  1610.         this->emmEnable = false;
  1611.     }
  1612.     return TRUE;
  1613. @@ -165,10 +160,7 @@
  1614.  
  1615.  DWORD CScrambleDecoderUtil::GetEmmCount()
  1616.  {
  1617. -   if( this->decodeIF2 == NULL ){
  1618. -       return 0;
  1619. -   }
  1620. -   return this->decodeIF2->GetEmmProcessNum();
  1621. +   return 0;
  1622.  }
  1623.  
  1624.  BOOL CScrambleDecoderUtil::GetLoadStatus(wstring& loadErrDll)
  1625. @@ -180,4 +172,3 @@
  1626.         return TRUE;
  1627.     }
  1628.  }
  1629. -
  1630. diff -u -r -N a/EDCB-work-plus-s/BonCtrl/ScrambleDecoderUtil.h b/EDCB-work-plus-s/BonCtrl/ScrambleDecoderUtil.h
  1631. --- a/EDCB-work-plus-s/BonCtrl/ScrambleDecoderUtil.h    2015-05-06 02:05:26.000000000 +0900
  1632. +++ b/EDCB-work-plus-s/BonCtrl/ScrambleDecoderUtil.h    2015-02-13 00:23:28.000000000 +0900
  1633. @@ -7,7 +7,7 @@
  1634.  #include "../Common/StringUtil.h"
  1635.  #include "../Common/ErrDef.h"
  1636.  
  1637. -#include "IB25Decoder.h"
  1638. +#include "decoder.h"
  1639.  
  1640.  class CScrambleDecoderUtil
  1641.  {
  1642. @@ -32,8 +32,7 @@
  1643.     wstring currentDll;
  1644.     wstring loadDll;
  1645.  
  1646. -   IB25Decoder* decodeIF;
  1647. -   IB25Decoder2* decodeIF2;
  1648. +   B25Decoder *b25;
  1649.     HMODULE module;
  1650.  
  1651.     bool emmEnable;
  1652. @@ -41,4 +40,3 @@
  1653.  protected:
  1654.     BOOL LoadDll(LPCWSTR dllPath);
  1655.  };
  1656. -
  1657. diff -u -r -N a/EDCB-work-plus-s/BonCtrl/SendUDP.cpp b/EDCB-work-plus-s/BonCtrl/SendUDP.cpp
  1658. --- a/EDCB-work-plus-s/BonCtrl/SendUDP.cpp  2015-05-06 02:05:26.000000000 +0900
  1659. +++ b/EDCB-work-plus-s/BonCtrl/SendUDP.cpp  2015-04-25 07:28:42.000000000 +0900
  1660. @@ -47,7 +47,7 @@
  1661.         m_hSendStopEvent = NULL;
  1662.     }
  1663.  
  1664. -   if( m_hCriticalEvent == NULL ){
  1665. +   if( m_hCriticalEvent != NULL ){
  1666.         ::WaitForSingleObject(m_hCriticalEvent, 300);
  1667.         ::CloseHandle(m_hCriticalEvent);
  1668.         m_hCriticalEvent = NULL;
  1669. diff -u -r -N a/EDCB-work-plus-s/BonCtrl/TSOut.cpp b/EDCB-work-plus-s/BonCtrl/TSOut.cpp
  1670. --- a/EDCB-work-plus-s/BonCtrl/TSOut.cpp    2015-05-06 02:05:26.000000000 +0900
  1671. +++ b/EDCB-work-plus-s/BonCtrl/TSOut.cpp    2015-05-01 10:31:42.000000000 +0900
  1672. @@ -25,6 +25,8 @@
  1673.     this->nextCtrlID = 1;
  1674.  
  1675.     this->epgFile = NULL;
  1676. +
  1677. +   this->decodeBuff.reserve(188*256);
  1678.  }
  1679.  
  1680.  
  1681. @@ -166,11 +168,11 @@
  1682.  
  1683.     if( this->enableDecodeFlag != FALSE || this->emmEnableFlag != FALSE ){
  1684.         //スクランブル解除かEMM処理が設定されている場合だけ実行
  1685. -       if( this->decodeUtil.SetNetwork(onid, tsid) == FALSE ){
  1686. +       this->decodeUtil.SetEmm(this->emmEnableFlag);
  1687. +       if (this->decodeUtil.SetNetwork(onid, tsid) == FALSE){
  1688.             OutputDebugString(L"★★Decode DLL load err [CTSOut::OnChChanged()]\r\n");
  1689.             //再試行は意味がなさそうなので廃止
  1690.         }
  1691. -       this->decodeUtil.SetEmm(this->emmEnableFlag);
  1692.     }
  1693.     ResetErrCount();
  1694.  
  1695. @@ -209,26 +211,14 @@
  1696.                         UnLock();
  1697.                         return NO_ERR;
  1698.                     }
  1699. -                   //簡易パケット解析
  1700. -                   if( packet.transport_scrambling_control != 0 ){
  1701. -                       //スクランブルパケットなので解析できない
  1702. -                       continue;
  1703. -                   }
  1704. -                   if( packet.data_byteSize < 3 ){
  1705. -                       //サイズが小さすぎる
  1706. -                       continue;
  1707. -                   }
  1708. -                   if(packet.payload_unit_start_indicator == 1 &&
  1709. -                       packet.data_byte[0] == 0x00 &&
  1710. -                       packet.data_byte[1] == 0x00 &&
  1711. -                       packet.data_byte[2] == 0x01){
  1712. -                       //PES
  1713. +                   if( packet.PID > 0x30 ){
  1714. +                       //PIDが0x30以下のパケット以外は不要
  1715.                         continue;
  1716.                     }
  1717.                     try{
  1718.                         this->epgUtil.AddTSPacket(data->data + i, 188);
  1719.                     }catch(...){
  1720. -                       _OutputDebugString(L"★★CTSOut::AddTSBuff epgUtil.AddTSPacket");
  1721. +                       OutputDebugString(L"★★CTSOut::AddTSBuff epgUtil.AddTSPacket");
  1722.                         this->epgUtil.UnInitialize();
  1723.                         this->epgUtil.Initialize(FALSE);
  1724.                     }
  1725. @@ -237,9 +227,8 @@
  1726.                     if( this->epgUtil.GetTSID(&onid, &tsid) == NO_ERR ){
  1727.                         if( onid != this->lastONID || tsid != this->lastTSID ){
  1728.                             OutputDebugString(L"★Ch Change Complete\r\n");
  1729. -                       _OutputDebugString(L"★Ch 0x%04X 0x%04X => 0x%04X 0x%04X\r\n", this->lastONID, this->lastTSID, onid, tsid);
  1730. +                           _OutputDebugString(L"★Ch 0x%04X 0x%04X => 0x%04X 0x%04X\r\n", this->lastONID, this->lastTSID, onid, tsid);
  1731.                             OnChChanged(onid, tsid);
  1732. -
  1733.                         }else if( GetTickCount() - this->chChangeTime > 7000 ){
  1734.                             OutputDebugString(L"★Ch NoChange\r\n");
  1735.                             OnChChanged(onid, tsid);
  1736. @@ -256,8 +245,8 @@
  1737.                             this->lastONID = onid;
  1738.                             this->lastTSID = tsid;
  1739.                             //this->epgUtil.ClearSectionStatus();
  1740. -                           //this->decodeUtil.SetNetwork(onid, tsid);
  1741.                             //this->decodeUtil.SetEmm(this->emmEnableFlag);
  1742. +                           //this->decodeUtil.SetNetwork(onid, tsid);
  1743.                             //ResetErrCount();
  1744.                         }
  1745.                         continue;
  1746. @@ -274,9 +263,8 @@
  1747.                             if(this->catUtil->AddPacket(&packet) == TRUE){
  1748.                                 CheckNeedPID();
  1749.                             }
  1750. -                       }
  1751. -                       //PMT
  1752. -                       if( packet.payload_unit_start_indicator == 1 && packet.data_byteSize > 0){
  1753. +                       }else if( packet.payload_unit_start_indicator == 1 && packet.data_byteSize > 0){
  1754. +                           // PMT探しなのでCATだとわかっている物は除外しても大丈夫
  1755.                             BYTE pointer = packet.data_byte[0];
  1756.                             if( pointer+1 < packet.data_byteSize ){
  1757.                                 if( packet.data_byte[1+pointer] == 0x02 ){
  1758. @@ -346,8 +334,8 @@
  1759.                         this->lastONID = 0xFFFF;
  1760.                         this->lastTSID = 0xFFFF;
  1761.                         //this->epgUtil.ClearSectionStatus();
  1762. -                       //this->decodeUtil.SetNetwork(onid, tsid);
  1763.                         //this->decodeUtil.SetEmm(this->emmEnableFlag);
  1764. +                       //this->decodeUtil.SetNetwork(onid, tsid);
  1765.                         //ResetErrCount();
  1766.                     }
  1767.                 }
  1768. @@ -367,10 +355,11 @@
  1769.             }
  1770.         }
  1771.     }catch(...){
  1772. -       _OutputDebugString(L"★★CTSOut::AddTSBuff Exception1");
  1773. +       OutputDebugString(L"★★CTSOut::AddTSBuff Exception1");
  1774.         UnLock();
  1775.         return ERR_FALSE;
  1776.     }
  1777. +
  1778.     try{
  1779.         if( this->decodeBuff.empty() == false ){
  1780.             if( this->enableDecodeFlag == TRUE && this->chChangeFlag == FALSE ){
  1781. @@ -393,19 +382,24 @@
  1782.             }
  1783.         }
  1784.     }catch(...){
  1785. -       _OutputDebugString(L"★★CTSOut::AddTSBuff Exception2");
  1786. +       OutputDebugString(L"★★CTSOut::AddTSBuff Exception2");
  1787.         //デコード失敗
  1788.         decodeData = &this->decodeBuff.front();
  1789.         decodeSize = (DWORD)this->decodeBuff.size();
  1790.     }
  1791. -  
  1792. +
  1793.     //デコード済みのデータを解析させる
  1794.     try{
  1795.         for( DWORD i=0; i<decodeSize; i+=188 ){
  1796. -           this->epgUtil.AddTSPacket(decodeData + i, 188);
  1797. +           WORD pid = ((((WORD)decodeData[i + 1] & 0x1f) << 8) | decodeData[i + 2]);
  1798. +           if( pid <= 0x30 ){
  1799. +               // PIDが0x30以下のパケットのみEPG解析に回す
  1800. +               // PMTに関しては内部でパースはされるものの使用はされていないので渡さなくても大丈夫
  1801. +               this->epgUtil.AddTSPacket(decodeData + i, 188);
  1802. +           }
  1803.         }
  1804.     }catch(...){
  1805. -       _OutputDebugString(L"★★CTSOut::AddTSBuff Exception3");
  1806. +       OutputDebugString(L"★★CTSOut::AddTSBuff Exception3");
  1807.         this->epgUtil.UnInitialize();
  1808.         this->epgUtil.Initialize(FALSE);
  1809.         UnLock();
  1810. @@ -419,7 +413,7 @@
  1811.             itrService->second->AddTSBuff(decodeData, decodeSize);
  1812.         }
  1813.     }catch(...){
  1814. -       _OutputDebugString(L"★★CTSOut::AddTSBuff Exception4");
  1815. +       OutputDebugString(L"★★CTSOut::AddTSBuff Exception4");
  1816.         UnLock();
  1817.         return ERR_FALSE;
  1818.     }
  1819. @@ -441,8 +435,8 @@
  1820.  
  1821.     map<WORD, string> pidName;
  1822.     map<WORD, CPMTUtil*>::iterator itrPmt;
  1823. -   for( itrPmt = pmtUtilMap.begin(); itrPmt != pmtUtilMap.end(); itrPmt++ ){
  1824. -       string name = "";
  1825. +   for( itrPmt = pmtUtilMap.begin(); itrPmt != pmtUtilMap.end(); ++itrPmt ){
  1826. +       string name;
  1827.         Format(name, "PMT(ServiceID 0x%04X)", itrPmt->second->program_number);
  1828.         pidName.insert(pair<WORD, string>(itrPmt->first, name));
  1829.         map<WORD, WORD>::iterator itrPID;
  1830. @@ -460,6 +454,9 @@
  1831.             case 0x1B:
  1832.                 name = "MPEG4 VIDEO";
  1833.                 break;
  1834. +           case 0x24:
  1835. +               name = "HEVC VIDEO";
  1836. +               break;
  1837.             case 0x04:
  1838.                 name = "MPEG2 AUDIO";
  1839.                 break;
  1840. @@ -491,12 +488,12 @@
  1841.  
  1842.     //各サービスのPMTを探す
  1843.     map<DWORD, COneServiceUtil*>::iterator itrService;
  1844. -   for( itrService = serviceUtilMap.begin(); itrService != serviceUtilMap.end(); itrService++ ){
  1845. +   for( itrService = serviceUtilMap.begin(); itrService != serviceUtilMap.end(); ++itrService ){
  1846.         if( itrService->second->GetSID() == 0xFFFF ){
  1847.             //全サービス対象
  1848.             this->serviceOnlyFlag = FALSE;
  1849.             map<WORD, CPMTUtil*>::iterator itrPmt;
  1850. -           for( itrPmt = pmtUtilMap.begin(); itrPmt != pmtUtilMap.end(); itrPmt++ ){
  1851. +           for( itrPmt = pmtUtilMap.begin(); itrPmt != pmtUtilMap.end(); ++itrPmt ){
  1852.                 //PAT作成用のPMTリスト作成
  1853.                 CCreatePATPacket::PROGRAM_PID_INFO item;
  1854.                 item.PMTPID = itrPmt->first;
  1855. @@ -506,12 +503,12 @@
  1856.                 //PMT記載のPIDを登録
  1857.                 this->needPIDMap.insert(pair<WORD,WORD>(itrPmt->first, 0));
  1858.                 map<WORD,WORD>::iterator itrPID;
  1859. -               for( itrPID = itrPmt->second->PIDList.begin(); itrPID != itrPmt->second->PIDList.end(); itrPID++ ){
  1860. +               for( itrPID = itrPmt->second->PIDList.begin(); itrPID != itrPmt->second->PIDList.end(); ++itrPID ){
  1861.                     this->needPIDMap.insert(pair<WORD,WORD>(itrPID->first, itrPID->second));
  1862.                 }
  1863.             }
  1864.         }else{
  1865. -           for( itrPmt = pmtUtilMap.begin(); itrPmt != pmtUtilMap.end(); itrPmt++ ){
  1866. +           for( itrPmt = pmtUtilMap.begin(); itrPmt != pmtUtilMap.end(); ++itrPmt ){
  1867.                 if( itrService->second->GetSID() == itrPmt->second->program_number ){
  1868.                     //PMT発見
  1869.                     itrService->second->SetPmtPID(this->lastTSID, itrPmt->first);
  1870. @@ -519,7 +516,6 @@
  1871.                         itrService->second->SetEmmPID(&catUtil->PIDList);
  1872.                     }
  1873.  
  1874. -
  1875.                     //PAT作成用のPMTリスト作成
  1876.                     CCreatePATPacket::PROGRAM_PID_INFO item2;
  1877.                     item2.PMTPID = itrPmt->first;
  1878. @@ -530,7 +526,7 @@
  1879.                     this->needPIDMap.insert(pair<WORD,WORD>(itrPmt->first, 0));
  1880.                     this->needPIDMap.insert(pair<WORD,WORD>(itrPmt->second->PCR_PID, 0));
  1881.                     map<WORD,WORD>::iterator itrPID;
  1882. -                   for( itrPID = itrPmt->second->PIDList.begin(); itrPID != itrPmt->second->PIDList.end(); itrPID++ ){
  1883. +                   for( itrPID = itrPmt->second->PIDList.begin(); itrPID != itrPmt->second->PIDList.end(); ++itrPID ){
  1884.                         this->needPIDMap.insert(pair<WORD,WORD>(itrPID->first, itrPID->second));
  1885.                     }
  1886.                 }
  1887. @@ -539,14 +535,15 @@
  1888.         itrService->second->SetPIDName(&pidName);
  1889.     }
  1890.     this->patUtil.SetParam(this->lastTSID, &PIDMap);
  1891. -
  1892.  }
  1893.  
  1894.  BOOL CTSOut::IsNeedPID(CTSPacketUtil* packet)
  1895.  {
  1896. +/*
  1897.     if( packet == NULL ){
  1898.         return FALSE;
  1899.     }
  1900. +*/
  1901.     if( packet->PID <= 0x30 ){
  1902.         return TRUE;
  1903.     }
  1904. @@ -663,6 +660,7 @@
  1905.             if( enable != FALSE && this->enableDecodeFlag == FALSE && this->emmEnableFlag == FALSE ){
  1906.                 //最初に EMM 処理が設定される場合は DLL を読み込む
  1907.                 //スクランブル解除が設定されている場合は読み込み済みなので除外
  1908. +               this->decodeUtil.SetEmm(TRUE);
  1909.                 if( this->decodeUtil.SetNetwork(this->lastONID, this->lastTSID) == FALSE ){
  1910.                     OutputDebugString(L"★★Decode DLL load err [CTSOut::SetEmm()]\r\n");
  1911.                 }
  1912. @@ -673,11 +671,10 @@
  1913.         return FALSE;
  1914.     }
  1915.  
  1916. -   BOOL err = this->decodeUtil.SetEmm(enable);
  1917.     this->emmEnableFlag = enable;
  1918.  
  1919.     UnLock();
  1920. -   return err;
  1921. +   return TRUE;
  1922.  }
  1923.  
  1924.  //EMM処理を行った数
  1925. @@ -1204,6 +1201,7 @@
  1926.             if( enable != FALSE && this->enableDecodeFlag == FALSE && this->emmEnableFlag == FALSE ){
  1927.                 //最初にスクランブル解除が設定される場合は DLL を再読み込みする
  1928.                 //EMM 処理が設定されている場合は読み込み済みなので除外
  1929. +               this->decodeUtil.SetEmm(FALSE);
  1930.                 if( this->decodeUtil.SetNetwork(this->lastONID, this->lastTSID) == FALSE ){
  1931.                     OutputDebugString(L"★★Decode DLL load err [CTSOut::SetScramble()]\r\n");
  1932.                 }
  1933. diff -u -r -N a/EDCB-work-plus-s/Common/SendCtrlCmd.cpp b/EDCB-work-plus-s/Common/SendCtrlCmd.cpp
  1934. --- a/EDCB-work-plus-s/Common/SendCtrlCmd.cpp   2015-05-06 02:05:26.000000000 +0900
  1935. +++ b/EDCB-work-plus-s/Common/SendCtrlCmd.cpp   2015-05-02 02:00:19.000000000 +0900
  1936. @@ -238,7 +238,6 @@
  1937.     server.sin_addr.S_un.S_addr = inet_addr(strA.c_str());
  1938.     DWORD socketBuffSize = 1024*1024;
  1939.     setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (const char*)&socketBuffSize, sizeof(socketBuffSize));
  1940. -   setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (const char*)&socketBuffSize, sizeof(socketBuffSize));
  1941.  
  1942.     int ret = connect(sock, (struct sockaddr *)&server, sizeof(server));
  1943.     if( ret == SOCKET_ERROR ){
  1944. diff -u -r -N a/EDCB-work-plus-s/Common/StringUtil.cpp b/EDCB-work-plus-s/Common/StringUtil.cpp
  1945. --- a/EDCB-work-plus-s/Common/StringUtil.cpp    2015-05-06 02:05:26.000000000 +0900
  1946. +++ b/EDCB-work-plus-s/Common/StringUtil.cpp    2015-04-29 05:25:43.000000000 +0900
  1947. @@ -6,17 +6,16 @@
  1948.     va_list params;
  1949.  
  1950.     va_start(params, format);
  1951. -   int iResult;
  1952. -   char *buff;
  1953.     int length = _vscprintf(format, params);
  1954. -   buff = new char [length + 1];
  1955. -   iResult = vsprintf_s(buff, length + 1, format, params);
  1956. -   buff[length] = '\0';
  1957. -   if (buff != NULL) {
  1958. +   char *buff = new char[length + 1];
  1959. +   if (buff == NULL){
  1960. +       strBuff = "";
  1961. +   }else{
  1962. +       vsprintf_s(buff, length + 1, format, params);
  1963. +       buff[length] = '\0';
  1964.         strBuff = buff;
  1965.         delete[] buff;
  1966.     }
  1967. -
  1968.     va_end(params);
  1969.  }
  1970.  
  1971. diff -u -r -N a/EDCB-work-plus-s/Common/TSBuffUtil.cpp b/EDCB-work-plus-s/Common/TSBuffUtil.cpp
  1972. --- a/EDCB-work-plus-s/Common/TSBuffUtil.cpp    2015-05-06 02:05:26.000000000 +0900
  1973. +++ b/EDCB-work-plus-s/Common/TSBuffUtil.cpp    2015-04-29 15:45:59.000000000 +0900
  1974. @@ -23,11 +23,11 @@
  1975.  
  1976.  void CTSBuffUtil::Clear()
  1977.  {
  1978. -   for(size_t i=0; i<this->packetList.size(); i++ ){
  1979. -       SAFE_DELETE(this->packetList[i]);
  1980. +   while (!this->packetList.empty()){
  1981. +       SECTION_BUFF *p = this->packetList.front();
  1982. +       this->packetList.pop_front();
  1983. +       delete p;
  1984.     }
  1985. -   this->packetList.clear();
  1986. -
  1987.     this->lastPID = 0xFFFF;
  1988.     this->lastCounter = 0xFF;
  1989.  
  1990. @@ -43,64 +43,57 @@
  1991.         this->duplicateFlag = FALSE;
  1992.         return TRUE;
  1993.     }
  1994. -   if( this->lastPID != 0xFFFF || this->lastCounter != 0xFF ){
  1995. -       if( this->lastPID != tsPacket->PID ){
  1996. -           //PID変更されたので不連続
  1997. -           this->duplicateFlag = FALSE;
  1998. -           return FALSE;
  1999. -       }else{
  2000. -           if( tsPacket->adaptation_field_control == 0x00 || tsPacket->adaptation_field_control == 0x02 ){
  2001. -               //ペイロードが存在しない場合は意味なし
  2002. -               this->duplicateFlag = FALSE;
  2003. -               if( tsPacket->adaptation_field_control == 0x02 || tsPacket->adaptation_field_control == 0x03 ){
  2004. -                   if( tsPacket->transport_scrambling_control == 0 ){
  2005. -                       if(tsPacket->discontinuity_indicator == 1){
  2006. -                           //不連続の判定が必要
  2007. -                           return FALSE;
  2008. -                       }else{
  2009. -                           return TRUE;
  2010. -                       }
  2011. -                   }else{
  2012. -                       return TRUE;
  2013. -                   }
  2014. -               }else{
  2015. -                   return TRUE;
  2016. -               }
  2017. -           }
  2018. -           if( this->lastCounter == tsPacket->continuity_counter ){
  2019. -               if( tsPacket->adaptation_field_control == 0x01 || tsPacket->adaptation_field_control == 0x03 ){
  2020. -                   if( tsPacket->transport_scrambling_control == 0 ){
  2021. -                       if( this->duplicateFlag == FALSE ){
  2022. -                           //重送?一応連続と判定
  2023. -                           this->duplicateFlag = TRUE;
  2024. -                           if( tsPacket->adaptation_field_control == 0x02 || tsPacket->adaptation_field_control == 0x03 ){
  2025. -                               if(tsPacket->discontinuity_indicator == 1){
  2026. -                                   //不連続の判定が必要
  2027. -                                   return FALSE;
  2028. -                               }else{
  2029. -                                   return TRUE;
  2030. -                               }
  2031. -                           }else{
  2032. -                               return TRUE;
  2033. -                           }
  2034. -                       }else{
  2035. -                           //前回重送と判断してるので不連続
  2036. -                           this->duplicateFlag = FALSE;
  2037. -                           return FALSE;
  2038. -                       }
  2039. -                   }else{
  2040. -                       return TRUE;
  2041. -                   }
  2042. +
  2043. +   if (this->lastPID == 0xFFFF){
  2044. +       // 初回
  2045. +       return TRUE;
  2046. +   }
  2047. +
  2048. +   if( this->lastPID != tsPacket->PID ){
  2049. +       //PID変更されたので不連続
  2050. +       this->duplicateFlag = FALSE;
  2051. +       return FALSE;
  2052. +   }
  2053. +
  2054. +   if ((tsPacket->adaptation_field_control & 0x01) == 0){
  2055. +       //ペイロードが存在しない場合は意味なし
  2056. +       this->duplicateFlag = FALSE;
  2057. +       if( tsPacket->adaptation_field_control == 0x02 ){
  2058. +           if( tsPacket->transport_scrambling_control == 0 ){
  2059. +               if(tsPacket->discontinuity_indicator == 1){
  2060. +                   //不連続の判定が必要
  2061. +                   return FALSE;
  2062.                 }
  2063.             }
  2064. -           if( this->lastCounter+1 != tsPacket->continuity_counter ){
  2065. -               if( this->lastCounter != 0x0F && tsPacket->continuity_counter != 0x00 ){
  2066. -                   //カウンターが飛んだので不連続
  2067. +       }
  2068. +       return TRUE;
  2069. +   }
  2070. +
  2071. +   if( this->lastCounter == tsPacket->continuity_counter ){
  2072. +       if (this->duplicateFlag == TRUE){
  2073. +           //前回重送と判断してるので不連続
  2074. +           this->duplicateFlag = FALSE;
  2075. +           return FALSE;
  2076. +       }
  2077. +       if (tsPacket->transport_scrambling_control == 0){
  2078. +           if( tsPacket->adaptation_field_control == 0x03 ){
  2079. +               if(tsPacket->discontinuity_indicator == 1){
  2080. +                   //不連続の判定が必要
  2081. +                   this->duplicateFlag = FALSE;
  2082.                     return FALSE;
  2083.                 }
  2084.             }
  2085.         }
  2086. +       //重送?一応連続と判定
  2087. +       this->duplicateFlag = TRUE;
  2088. +       return TRUE;
  2089.     }
  2090. +
  2091. +   if( ((this->lastCounter+1) & 0x0F) != tsPacket->continuity_counter ){
  2092. +       //カウンターが飛んだので不連続
  2093. +       return FALSE;
  2094. +   }
  2095. +
  2096.     return TRUE;
  2097.  }
  2098.  
  2099. @@ -149,33 +142,21 @@
  2100.             Clear();
  2101.             return ERR_NOT_SUPPORT;
  2102.         }
  2103. -   }
  2104. -
  2105. -   if( this->lastPID == 0xFFFF && this->lastCounter == 0xFF ){
  2106. -       //初回
  2107. -       if( tsPacket->payload_unit_start_indicator == 1 ){
  2108. -           //PSI
  2109. -           this->lastPID = tsPacket->PID;
  2110. -           this->lastCounter = tsPacket->continuity_counter;
  2111. -           if( this->PESMode == FALSE ){
  2112. -               return AddSectionBuff(tsPacket);
  2113. -           }else{
  2114. -               return AddPESBuff(tsPacket);
  2115. -           }
  2116. -       }else{
  2117. -           //スタート位置ではない
  2118. -           return ERR_ADD_NEXT;
  2119. -       }
  2120.     }else{
  2121. -       this->lastPID = tsPacket->PID;
  2122. -       this->lastCounter = tsPacket->continuity_counter;
  2123. -       if( this->PESMode == FALSE ){
  2124. -           return AddSectionBuff(tsPacket);
  2125. -       }else{
  2126. -           return AddPESBuff(tsPacket);
  2127. +       if (this->lastPID == 0xFFFF){
  2128. +           //初回だけどスタート位置ではない
  2129. +           return ERR_ADD_NEXT;
  2130.         }
  2131.     }
  2132.  
  2133. +   //PSI
  2134. +   this->lastPID = tsPacket->PID;
  2135. +   this->lastCounter = tsPacket->continuity_counter;
  2136. +   if( this->PESMode == FALSE ){
  2137. +       return AddSectionBuff(tsPacket);
  2138. +   }else{
  2139. +       return AddPESBuff(tsPacket);
  2140. +   }
  2141.  }
  2142.  
  2143.  BOOL CTSBuffUtil::IsPES()
  2144. @@ -185,13 +166,13 @@
  2145.  
  2146.  BOOL CTSBuffUtil::GetSectionBuff(BYTE** sectionData, DWORD* dataSize)
  2147.  {
  2148. -   SAFE_DELETE(lastGetBuff);
  2149.     if( packetList.size() == 0 ){
  2150.         return FALSE;
  2151.     }
  2152.  
  2153. -   lastGetBuff = packetList[0];
  2154. -   packetList.erase(packetList.begin());
  2155. +   delete lastGetBuff;
  2156. +   lastGetBuff = packetList.front();
  2157. +   packetList.pop_front();
  2158.  
  2159.     *sectionData = lastGetBuff->data;
  2160.     *dataSize = lastGetBuff->dataSize;
  2161. @@ -204,19 +185,16 @@
  2162.     if( tsPacket->data_byteSize == 0 || tsPacket->data_byte == NULL ){
  2163.         return ERR_ADD_NEXT;
  2164.     }
  2165. -   if( tsPacket->payload_unit_start_indicator != 1 && creatingBuff == NULL ){
  2166. -       return ERR_ADD_NEXT;
  2167. -   }
  2168.  
  2169. -   BYTE readSize = 0;
  2170. -   if( tsPacket->payload_unit_start_indicator == 1 ){
  2171. -       BOOL addBuff = FALSE;
  2172. +   BOOL addBuff = FALSE;
  2173. +   DWORD readSize;
  2174. +   if (tsPacket->payload_unit_start_indicator == 1){
  2175.         BYTE pointer_field = tsPacket->data_byte[0];
  2176. -       readSize++;
  2177. -       if( pointer_field != 0 ){
  2178. +       readSize = 1;
  2179. +       if (pointer_field != 0){
  2180.             //マルチセクション
  2181. -           if( creatingBuff != NULL ){
  2182. -               if( creatingBuff->dataSize - creatingBuff->copySize == pointer_field ){
  2183. +           if (creatingBuff != NULL){
  2184. +               if (creatingBuff->dataSize - creatingBuff->copySize == pointer_field){
  2185.                     memcpy(creatingBuff->data + creatingBuff->copySize, tsPacket->data_byte + readSize, pointer_field);
  2186.                     creatingBuff->copySize += pointer_field;
  2187.                     packetList.push_back(creatingBuff);
  2188. @@ -228,88 +206,83 @@
  2189.                     SAFE_DELETE(creatingBuff);
  2190.                 }
  2191.             }
  2192. -       }else{
  2193. -           if( creatingBuff != NULL ){
  2194. +           readSize += pointer_field;
  2195. +           if (readSize > tsPacket->data_byteSize){
  2196. +               //サイズが小さすぎる
  2197. +               _OutputDebugString(L"★psi size err PID 0x%04X\r\n", tsPacket->PID);
  2198.                 SAFE_DELETE(creatingBuff);
  2199. -               creatingBuff = NULL;
  2200. -           }
  2201. -       }
  2202. -       readSize+=pointer_field;
  2203. -
  2204. -       if( pointer_field + 1 > tsPacket->data_byteSize ){
  2205. -           //サイズが小さすぎる
  2206. -           SAFE_DELETE(creatingBuff);
  2207. -           _OutputDebugString(L"★psi size err PID 0x%04X\r\n", tsPacket->PID);
  2208. -           if( addBuff == TRUE ){
  2209. -               return TRUE;
  2210. -           }else{
  2211. +               if (addBuff == TRUE){
  2212. +                   return TRUE;
  2213. +               }
  2214.                 return FALSE;
  2215.             }
  2216. -       }
  2217. -
  2218. -       //マルチセクションチェック
  2219. -       while( readSize+3 < tsPacket->data_byteSize ){
  2220. -           if( tsPacket->data_byte[readSize] == 0xFF &&
  2221. -               tsPacket->data_byte[readSize+1] == 0xFF &&
  2222. -               tsPacket->data_byte[readSize+2] == 0xFF){
  2223. -               //残りはスタッフィングバイト
  2224. -               break;
  2225. -           }
  2226. -
  2227. -           SECTION_BUFF* buff = new SECTION_BUFF;
  2228. -           buff->dataSize = (((DWORD)tsPacket->data_byte[readSize+1]&0x0F) << 8 | tsPacket->data_byte[readSize+2]) + 3;
  2229. -           buff->data = new BYTE[buff->dataSize];
  2230. -
  2231. -           if( buff->dataSize <= (DWORD)tsPacket->data_byteSize - readSize ){
  2232. -               buff->copySize = buff->dataSize;
  2233. -           }else{
  2234. -               buff->copySize = tsPacket->data_byteSize - readSize;
  2235. -           }
  2236. -
  2237. -           memcpy( buff->data, tsPacket->data_byte+readSize, buff->copySize );
  2238. -           readSize += (BYTE)buff->copySize;
  2239. -
  2240. -           if( buff->copySize == buff->dataSize ){
  2241. -               //このパケットだけで完結
  2242. -               packetList.push_back(buff);
  2243. -           }else{
  2244. -               //次のパケットが必要
  2245. -               creatingBuff = buff;
  2246. -               break;
  2247. -           }
  2248. -       }
  2249. -       if( creatingBuff == NULL ){
  2250. -           return TRUE;
  2251.         }else{
  2252. -           //次のパケット必要
  2253. -           if( addBuff == TRUE ){
  2254. -               return TRUE;
  2255. -           }else{
  2256. -               return ERR_ADD_NEXT;
  2257. -           }
  2258. +           SAFE_DELETE(creatingBuff);
  2259.         }
  2260.     }else{
  2261.         //複数パケットにまたがっている
  2262. -       DWORD copySize = 0;
  2263. +       if (creatingBuff == NULL){
  2264. +           //先頭からのデータを保持していなかったらエラー
  2265. +           return FALSE;
  2266. +       }
  2267. +       DWORD copySize;
  2268.         DWORD needSize = creatingBuff->dataSize - creatingBuff->copySize;
  2269. -
  2270. -       if( needSize <= tsPacket->data_byteSize ){
  2271. +       if (needSize <= tsPacket->data_byteSize){
  2272.             copySize = needSize;
  2273.         }else{
  2274.             copySize = tsPacket->data_byteSize;
  2275.         }
  2276. -
  2277. -       memcpy( creatingBuff->data + creatingBuff->copySize, tsPacket->data_byte, copySize );
  2278. -
  2279. +       memcpy(creatingBuff->data + creatingBuff->copySize, tsPacket->data_byte, copySize);
  2280.         creatingBuff->copySize += copySize;
  2281. -       if( creatingBuff->dataSize == creatingBuff->copySize ){
  2282. +       if (creatingBuff->copySize == creatingBuff->dataSize){
  2283. +           //完成した
  2284.             packetList.push_back(creatingBuff);
  2285.             creatingBuff = NULL;
  2286. -           return TRUE;
  2287. +           addBuff = TRUE;
  2288.         }else{
  2289. +           //次のパケットが必要(creatingBuffはそのまま持ちこし)
  2290.             return ERR_ADD_NEXT;
  2291.         }
  2292. +       readSize = copySize;
  2293. +   }
  2294. +
  2295. +   //マルチセクションチェック
  2296. +   while( readSize+3 < tsPacket->data_byteSize ){
  2297. +       if( tsPacket->data_byte[readSize] == 0xFF &&
  2298. +           tsPacket->data_byte[readSize+1] == 0xFF &&
  2299. +           tsPacket->data_byte[readSize+2] == 0xFF){
  2300. +           //残りはスタッフィングバイト
  2301. +           break;
  2302. +       }
  2303. +
  2304. +       SECTION_BUFF* buff = new SECTION_BUFF;
  2305. +       buff->dataSize = (((DWORD)tsPacket->data_byte[readSize+1]&0x0F) << 8 | tsPacket->data_byte[readSize+2]) + 3;
  2306. +       buff->data = new BYTE[buff->dataSize];
  2307. +
  2308. +       if( buff->dataSize <= (DWORD)tsPacket->data_byteSize - readSize ){
  2309. +           buff->copySize = buff->dataSize;
  2310. +       }else{
  2311. +           buff->copySize = tsPacket->data_byteSize - readSize;
  2312. +       }
  2313. +
  2314. +       memcpy( buff->data, tsPacket->data_byte+readSize, buff->copySize );
  2315. +       readSize += buff->copySize;
  2316. +
  2317. +       if( buff->copySize == buff->dataSize ){
  2318. +           //このパケットだけで完結
  2319. +           packetList.push_back(buff);
  2320. +           addBuff = TRUE;
  2321. +       }else{
  2322. +           //次のパケットが必要
  2323. +           creatingBuff = buff;
  2324. +           break;
  2325. +       }
  2326.     }
  2327. +   if( addBuff != TRUE ){
  2328. +       //このパケットでは一つも完成しなかった
  2329. +       return ERR_ADD_NEXT;
  2330. +   }
  2331. +   return TRUE;
  2332.  }
  2333.  
  2334.  DWORD CTSBuffUtil::AddPESBuff(CTSPacketUtil* tsPacket)
  2335. @@ -317,9 +290,6 @@
  2336.     if( tsPacket->data_byteSize == 0 || tsPacket->data_byte == NULL ){
  2337.         return ERR_ADD_NEXT;
  2338.     }
  2339. -   if( tsPacket->payload_unit_start_indicator != 1 && creatingBuff == NULL ){
  2340. -       return ERR_ADD_NEXT;
  2341. -   }
  2342.  
  2343.     if( tsPacket->payload_unit_start_indicator == 1 ){
  2344.         if(tsPacket->data_byteSize < 6 || tsPacket->data_byte[0] != 0x00 || tsPacket->data_byte[1] != 0x00 || tsPacket->data_byte[2] != 0x01){
  2345. @@ -358,28 +328,27 @@
  2346.                 return ERR_ADD_NEXT;
  2347.             }else{
  2348.                 packetList.push_back(buff);
  2349. -               creatingBuff = NULL;
  2350.                 return TRUE;
  2351.             }
  2352.         }
  2353.     }else{
  2354.         //複数パケットにまたがっている
  2355. -       if( creatingBuff->unknownSize == TRUE ){
  2356. +       if (creatingBuff == NULL){
  2357. +           return ERR_ADD_NEXT;
  2358. +       }
  2359. +       if (creatingBuff->unknownSize == TRUE){
  2360.             if( tsPacket->data_byteSize + creatingBuff->copySize > creatingBuff->dataSize ){
  2361.                 BYTE* newBuff = new BYTE[creatingBuff->dataSize*2];
  2362.                 memcpy(newBuff, creatingBuff->data, creatingBuff->copySize);
  2363. -               memcpy(newBuff + creatingBuff->copySize, tsPacket->data_byte, tsPacket->data_byteSize);
  2364. -               SAFE_DELETE_ARRAY(creatingBuff->data);
  2365. +               delete[] creatingBuff->data;
  2366.                 creatingBuff->data = newBuff;
  2367.                 creatingBuff->dataSize = creatingBuff->dataSize*2;
  2368. -               creatingBuff->copySize += tsPacket->data_byteSize;
  2369. -           }else{
  2370. -               memcpy(creatingBuff->data + creatingBuff->copySize, tsPacket->data_byte, tsPacket->data_byteSize);
  2371. -               creatingBuff->copySize += tsPacket->data_byteSize;
  2372.             }
  2373. +           memcpy(creatingBuff->data + creatingBuff->copySize, tsPacket->data_byte, tsPacket->data_byteSize);
  2374. +           creatingBuff->copySize += tsPacket->data_byteSize;
  2375.             return ERR_ADD_NEXT;
  2376.         }else{
  2377. -           DWORD copySize = 0;
  2378. +           DWORD copySize;
  2379.             DWORD needSize = creatingBuff->dataSize - creatingBuff->copySize;
  2380.  
  2381.             if( needSize <= tsPacket->data_byteSize ){
  2382. diff -u -r -N a/EDCB-work-plus-s/Common/TSBuffUtil.h b/EDCB-work-plus-s/Common/TSBuffUtil.h
  2383. --- a/EDCB-work-plus-s/Common/TSBuffUtil.h  2015-05-06 02:05:26.000000000 +0900
  2384. +++ b/EDCB-work-plus-s/Common/TSBuffUtil.h  2015-04-29 15:44:46.000000000 +0900
  2385. @@ -31,7 +31,7 @@
  2386.             SAFE_DELETE_ARRAY(data);
  2387.         };
  2388.     }SECTION_BUFF;
  2389. -   vector<SECTION_BUFF*> packetList;
  2390. +   deque<SECTION_BUFF*> packetList;
  2391.  
  2392.     WORD lastPID;
  2393.     BYTE lastCounter;
  2394. diff -u -r -N a/EDCB-work-plus-s/Common/TSPacketUtil.cpp b/EDCB-work-plus-s/Common/TSPacketUtil.cpp
  2395. --- a/EDCB-work-plus-s/Common/TSPacketUtil.cpp  2015-05-06 02:05:26.000000000 +0900
  2396. +++ b/EDCB-work-plus-s/Common/TSPacketUtil.cpp  2015-05-04 10:31:48.000000000 +0900
  2397. @@ -13,6 +13,116 @@
  2398.  
  2399.  BOOL CTSPacketUtil::Set188TS(BYTE* data, DWORD dataSize)
  2400.  {
  2401. +#ifdef DELETE_UNUSED_MEMBER
  2402. +/*
  2403. +   if( data == NULL || dataSize != 188){
  2404. +       return FALSE;
  2405. +   }
  2406. +*/
  2407. +   data_byteSize = 0;
  2408. +
  2409. +   if( data[0] != 0x47 ){
  2410. +       return FALSE;
  2411. +   }
  2412. +   //transport_error_indicator
  2413. +   if ((data[1] >> 7) & 0x1){
  2414. +       return FALSE;
  2415. +   }
  2416. +   payload_unit_start_indicator = (data[1] >> 6) & 0x1;
  2417. +   PID = (((WORD)data[1] & 0x1f) << 8) | data[2];
  2418. +   transport_scrambling_control = (data[3] >> 6) & 0x3;
  2419. +   adaptation_field_control = (data[3] >> 4) & 0x3;
  2420. +   continuity_counter = data[3] & 0x0f;
  2421. +   DWORD readSize = 4;
  2422. +
  2423. +   if( adaptation_field_control & 0x02 ){
  2424. +       adaptation_field_length = data[4];
  2425. +       readSize++;
  2426. +       if( adaptation_field_length > 0 ){
  2427. +           /*
  2428. +           discontinuity_indicator : 1;
  2429. +           random_access_indicator : 1;
  2430. +           elementary_stream_priority_indicator : 1;
  2431. +           PCR_flag : 1;
  2432. +           OPCR_flag : 1;
  2433. +           splicing_point_flag : 1;
  2434. +           transport_private_data_flag : 1;
  2435. +           adaptation_field_extension_flag : 1;
  2436. +           */
  2437. +           BYTE flags = data[readSize];
  2438. +           discontinuity_indicator = (flags >> 7) & 0x1;
  2439. +           random_access_indicator = (flags >> 6) & 0x1;
  2440. +           PCR_flag = (flags >> 4) & 0x1;
  2441. +           OPCR_flag = (flags >> 3) & 0x1;
  2442. +           readSize++;
  2443. +           if( PCR_flag ){
  2444. +               program_clock_reference_base = ((ULONGLONG)data[readSize])<<25 |
  2445. +                   ((ULONGLONG)data[readSize+1])<<17 |
  2446. +                   ((ULONGLONG)data[readSize+2])<<9 |
  2447. +                   ((ULONGLONG)data[readSize+3])<<1 |
  2448. +                   ((ULONGLONG)data[readSize+4])>>7;
  2449. +               readSize+=6;
  2450. +           }
  2451. +           if( OPCR_flag ){
  2452. +               readSize+=6;
  2453. +           }
  2454. +           if( flags & 0x04 ){
  2455. +               readSize++;
  2456. +           }
  2457. +           if( flags & 0x02 ){
  2458. +               readSize += 1 + data[readSize];
  2459. +           }
  2460. +           if( flags & 0x01 ){
  2461. +               if( readSize + 1 >= 188 ){
  2462. +                   return FALSE;
  2463. +               }
  2464. +               /*
  2465. +               ltw_flag : 1
  2466. +               piecewise_rate_flag : 1
  2467. +               seamless_splice_flag : 1
  2468. +               reserved : 5
  2469. +               */
  2470. +               BYTE flags2 = data[readSize+1];
  2471. +               readSize+=2;
  2472. +               if( flags2 & 0x80 ){
  2473. +                   readSize+=2;
  2474. +               }
  2475. +               if( flags2 & 0x40 ){
  2476. +                   readSize+=3;
  2477. +               }
  2478. +               if( flags2 & 0x20 ){
  2479. +                   readSize+=5;
  2480. +               }
  2481. +           }
  2482. +           //ここまでのデータのどれかが異常なのでエラー
  2483. +           if( readSize > 188 ){
  2484. +               return FALSE;
  2485. +           }
  2486. +           readSize = 5 + adaptation_field_length;
  2487. +       }else{
  2488. +           discontinuity_indicator = 0;
  2489. +           random_access_indicator = 0;
  2490. +           PCR_flag = 0;
  2491. +           OPCR_flag = 0;
  2492. +       }
  2493. +   }else{
  2494. +       adaptation_field_length = 0;
  2495. +       discontinuity_indicator = 0;
  2496. +       random_access_indicator = 0;
  2497. +       PCR_flag = 0;
  2498. +       OPCR_flag = 0;
  2499. +   }
  2500. +
  2501. +   if( adaptation_field_control & 0x01 ){
  2502. +       if( readSize >= 188 ){
  2503. +           return FALSE;
  2504. +       }
  2505. +       data_byteSize = (BYTE)(188-readSize);
  2506. +       data_byte = data+readSize;
  2507. +   }
  2508. +
  2509. +   return TRUE;
  2510. +#else
  2511.     if( data == NULL || dataSize != 188){
  2512.         return FALSE;
  2513.     }
  2514. @@ -145,4 +255,5 @@
  2515.         }
  2516.     }
  2517.     return TRUE;
  2518. +#endif
  2519.  }
  2520. diff -u -r -N a/EDCB-work-plus-s/Common/TSPacketUtil.h b/EDCB-work-plus-s/Common/TSPacketUtil.h
  2521. --- a/EDCB-work-plus-s/Common/TSPacketUtil.h    2015-05-06 02:05:26.000000000 +0900
  2522. +++ b/EDCB-work-plus-s/Common/TSPacketUtil.h    2015-05-01 05:03:58.000000000 +0900
  2523. @@ -84,12 +84,29 @@
  2524.  }
  2525.  
  2526.  */
  2527. +#define DELETE_UNUSED_MEMBER
  2528.  
  2529.  #include "Util.h"
  2530.  
  2531.  class CTSPacketUtil
  2532.  {
  2533.  public:
  2534. +#ifdef DELETE_UNUSED_MEMBER
  2535. +   BYTE payload_unit_start_indicator;
  2536. +   WORD PID;
  2537. +   BYTE transport_scrambling_control;
  2538. +   BYTE adaptation_field_control;
  2539. +   BYTE continuity_counter;
  2540. +   BYTE data_byteSize;
  2541. +   BYTE* data_byte;
  2542. +
  2543. +   BYTE adaptation_field_length;
  2544. +   BYTE discontinuity_indicator;
  2545. +   BYTE random_access_indicator;
  2546. +   BYTE PCR_flag;
  2547. +   BYTE OPCR_flag;
  2548. +   ULONGLONG program_clock_reference_base;
  2549. +#else
  2550.     BYTE sync_byte;
  2551.     BYTE transport_error_indicator;
  2552.     BYTE payload_unit_start_indicator;
  2553. @@ -127,6 +144,7 @@
  2554.     DWORD piecewise_rate;
  2555.     BYTE splice_type;
  2556.     ULONGLONG DTS_next_AU;
  2557. +#endif
  2558.  
  2559.  public:
  2560.     CTSPacketUtil(void);
  2561. diff -u -r -N a/EDCB-work-plus-s/Common/Util.h b/EDCB-work-plus-s/Common/Util.h
  2562. --- a/EDCB-work-plus-s/Common/Util.h    2015-05-06 02:05:26.000000000 +0900
  2563. +++ b/EDCB-work-plus-s/Common/Util.h    2015-05-01 05:01:25.000000000 +0900
  2564. @@ -18,6 +18,7 @@
  2565.  #include <string>
  2566.  #include <map>
  2567.  #include <vector>
  2568. +#include <deque>
  2569.  #include <algorithm>
  2570.  #endif
  2571.  using std::string;
  2572. @@ -26,6 +27,7 @@
  2573.  using std::map;
  2574.  using std::multimap;
  2575.  using std::vector;
  2576. +using std::deque;
  2577.  
  2578.  #include <TCHAR.h>
  2579.  #include <windows.h>
  2580. diff -u -r -N a/EDCB-work-plus-s/EpgDataCap3/EpgDataCap3/AribDescriptor.cpp b/EDCB-work-plus-s/EpgDataCap3/EpgDataCap3/AribDescriptor.cpp
  2581. --- a/EDCB-work-plus-s/EpgDataCap3/EpgDataCap3/AribDescriptor.cpp   2015-05-06 02:05:26.000000000 +0900
  2582. +++ b/EDCB-work-plus-s/EpgDataCap3/EpgDataCap3/AribDescriptor.cpp   2015-05-10 10:46:28.000000000 +0900
  2583. @@ -908,6 +908,7 @@
  2584.  
  2585.  CDescriptor::CDescriptor()
  2586.  {
  2587. +   rootProperty.reserve(8);
  2588.  }
  2589.  
  2590.  CDescriptor::~CDescriptor()
  2591. @@ -980,6 +981,7 @@
  2592.  
  2593.     //ローカル参照用スタック
  2594.     std::vector<DESCRIPTOR_PROPERTY> localProperty;
  2595. +   localProperty.reserve(8);
  2596.  
  2597.     int readSize = DecodeProperty(data, dataSize, &parser, &this->rootProperty, &localProperty);
  2598.     if( readSize < 0 ){
  2599. diff -u -r -N a/EDCB-work-plus-s/EpgDataCap3/EpgDataCap3/DecodeUtil.cpp b/EDCB-work-plus-s/EpgDataCap3/EpgDataCap3/DecodeUtil.cpp
  2600. --- a/EDCB-work-plus-s/EpgDataCap3/EpgDataCap3/DecodeUtil.cpp   2015-05-06 02:05:26.000000000 +0900
  2601. +++ b/EDCB-work-plus-s/EpgDataCap3/EpgDataCap3/DecodeUtil.cpp   2015-05-10 10:42:23.000000000 +0900
  2602. @@ -36,7 +36,7 @@
  2603.  {
  2604.     map<WORD, CTSBuffUtil*>::iterator itr;
  2605.     for( itr = this->buffUtilMap.begin(); itr != this->buffUtilMap.end(); itr++ ){
  2606. -       SAFE_DELETE(itr->second);
  2607. +       delete itr->second;
  2608.     }
  2609.     this->buffUtilMap.clear();
  2610.  
  2611. @@ -44,7 +44,7 @@
  2612.  
  2613.     map<WORD, CPMTTable*>::iterator itrPmt;
  2614.     for( itrPmt = this->pmtMap.begin(); itrPmt != this->pmtMap.end(); itrPmt++ ){
  2615. -       SAFE_DELETE(itrPmt->second);
  2616. +       delete itrPmt->second;
  2617.     }
  2618.     this->pmtMap.clear();
  2619.  
  2620. @@ -71,7 +71,7 @@
  2621.     itr = this->buffUtilMap.begin();
  2622.     while( itr != this->buffUtilMap.end() ){
  2623.         if( itr->first != noClearPid ){
  2624. -           SAFE_DELETE(itr->second);
  2625. +           delete itr->second;
  2626.             this->buffUtilMap.erase(itr++);
  2627.         }else{
  2628.             itr++;
  2629. @@ -87,7 +87,7 @@
  2630.  
  2631.     map<WORD, CPMTTable*>::iterator itrPmt;
  2632.     for( itrPmt = this->pmtMap.begin(); itrPmt != this->pmtMap.end(); itrPmt++ ){
  2633. -       SAFE_DELETE(itrPmt->second);
  2634. +       delete itrPmt->second;
  2635.     }
  2636.     this->pmtMap.clear();
  2637.  
  2638. @@ -109,87 +109,84 @@
  2639.  
  2640.  void CDecodeUtil::AddTSData(BYTE* data)
  2641.  {
  2642. -   {
  2643. -       CTSPacketUtil tsPacket;
  2644. -       if( tsPacket.Set188TS(data, 188) == TRUE ){
  2645. -           if( tsPacket.PID == 0x1FFF ){
  2646. -               return;
  2647. -           }
  2648. -           CTSBuffUtil* buffUtil = NULL;
  2649. -
  2650. -           map<WORD, CTSBuffUtil*>::iterator itr;
  2651. -           itr = this->buffUtilMap.find( tsPacket.PID );
  2652. -           if( itr == this->buffUtilMap.end() ){
  2653. -               //まだPIDがないので新規
  2654. -               buffUtil = new CTSBuffUtil;
  2655. -               this->buffUtilMap.insert(pair<WORD, CTSBuffUtil*>(tsPacket.PID, buffUtil));
  2656. -           }else{
  2657. -               buffUtil = itr->second;
  2658. -           }
  2659. -           if( buffUtil->Add188TS(&tsPacket) == TRUE ){
  2660. -               BYTE* section = NULL;
  2661. -               DWORD sectionSize = 0;
  2662. -               while( buffUtil->GetSectionBuff( &section, &sectionSize ) == TRUE ){
  2663. -                   if( buffUtil->IsPES() == TRUE ){
  2664. -                       continue;
  2665. -                   }
  2666. -                   CTableUtil tableUtil;
  2667. -
  2668. -                   vector<TABLE_DATA*> tableList;
  2669. -                   DWORD decodeReadSize = 0;
  2670. -                   if( tableUtil.Decode(section, sectionSize, &tableList, &decodeReadSize) == TRUE ){
  2671. -                       for( size_t j=0; j<tableList.size(); j++ ){
  2672. -                           if( tableList[j]->PATTable != NULL ){
  2673. -                               if( CheckPAT(tsPacket.PID, tableList[j]->PATTable) == TRUE ){
  2674. -                                   tableList[j]->PATTable = NULL;
  2675. -                               }
  2676. -                           }else if( tableList[j]->PMTTable != NULL ){
  2677. -                               if( CheckPMT(tsPacket.PID, tableList[j]->PMTTable) == TRUE ){
  2678. -                                   tableList[j]->PMTTable = NULL;
  2679. -                               }
  2680. -                           }else if( tableList[j]->NITTable != NULL ){
  2681. -                               if( CheckNIT(tsPacket.PID, tableList[j]->NITTable) == TRUE ){
  2682. -                                   tableList[j]->NITTable = NULL;
  2683. -                               }
  2684. -                           }else if( tableList[j]->SDTTable != NULL ){
  2685. -                               if( CheckSDT(tsPacket.PID, tableList[j]->SDTTable) == TRUE ){
  2686. -                                   tableList[j]->SDTTable = NULL;
  2687. -                               }
  2688. -                           }else if( tableList[j]->TOTTable != NULL ){
  2689. -                               if( CheckTOT(tsPacket.PID, tableList[j]->TOTTable) == TRUE ){
  2690. -                                   tableList[j]->TOTTable = NULL;
  2691. -                               }
  2692. -                           }else if( tableList[j]->TDTTable != NULL ){
  2693. -                               if( CheckTDT(tsPacket.PID, tableList[j]->TDTTable) == TRUE ){
  2694. -                                   tableList[j]->TDTTable = NULL;
  2695. -                               }
  2696. -                           }else if( tableList[j]->EITTable != NULL ){
  2697. -                               if( CheckEIT(tsPacket.PID, tableList[j]->EITTable) == TRUE ){
  2698. -                                   tableList[j]->EITTable = NULL;
  2699. -                               }
  2700. -                           }else if( tableList[j]->BITTable != NULL ){
  2701. -                               if( CheckBIT(tsPacket.PID, tableList[j]->BITTable) == TRUE ){
  2702. -                                   tableList[j]->BITTable = NULL;
  2703. -                               }
  2704. -                           }else if( tableList[j]->SITTable != NULL ){
  2705. -                               if( CheckSIT(tsPacket.PID, tableList[j]->SITTable) == TRUE ){
  2706. -                                   tableList[j]->SITTable = NULL;
  2707. -                               }
  2708. -                           }else if( tableList[j]->EITTable_SD != NULL ){
  2709. -                               if( CheckEIT_SD(tsPacket.PID, tableList[j]->EITTable_SD) == TRUE ){
  2710. -                                   tableList[j]->EITTable_SD = NULL;
  2711. -                               }
  2712. -                           }else if( tableList[j]->EITTable_SD2 != NULL ){
  2713. -                               if( CheckEIT_SD2(tsPacket.PID, tableList[j]->EITTable_SD2) == TRUE ){
  2714. -                                   tableList[j]->EITTable_SD2 = NULL;
  2715. -                               }
  2716. -                           }
  2717. -                           SAFE_DELETE(tableList[j]);
  2718. +   CTSPacketUtil tsPacket;
  2719. +   if( tsPacket.Set188TS(data, 188) == TRUE ){
  2720. +       if( tsPacket.PID == 0x1FFF ){
  2721. +           return;
  2722. +       }
  2723. +       CTSBuffUtil* buffUtil;
  2724. +
  2725. +       map<WORD, CTSBuffUtil*>::iterator itr;
  2726. +       itr = this->buffUtilMap.find( tsPacket.PID );
  2727. +       if( itr == this->buffUtilMap.end() ){
  2728. +           //まだPIDがないので新規
  2729. +           buffUtil = new CTSBuffUtil;
  2730. +           this->buffUtilMap.insert(pair<WORD, CTSBuffUtil*>(tsPacket.PID, buffUtil));
  2731. +       }else{
  2732. +           buffUtil = itr->second;
  2733. +       }
  2734. +       if( buffUtil->Add188TS(&tsPacket) == TRUE ){
  2735. +           BYTE* section;
  2736. +           DWORD sectionSize;
  2737. +           while( buffUtil->GetSectionBuff( &section, &sectionSize ) == TRUE ){
  2738. +               if( buffUtil->IsPES() == TRUE ){
  2739. +                   continue;
  2740. +               }
  2741. +               CTableUtil tableUtil;
  2742. +
  2743. +               vector<TABLE_DATA*> tableList;
  2744. +               if( tableUtil.Decode(section, sectionSize, &tableList, NULL) == TRUE ){
  2745. +                   for( size_t j=0; j<tableList.size(); j++ ){
  2746. +                       BOOL ret;
  2747. +                       switch( tableList[j]->type ){
  2748. +                       case TABLE_DATA::TYPE_PAT:
  2749. +                           ret = CheckPAT(tsPacket.PID, static_cast<CPATTable*>(tableList[j]->table));
  2750. +                           break;
  2751. +                       case TABLE_DATA::TYPE_PMT:
  2752. +                           ret = CheckPMT(tsPacket.PID, static_cast<CPMTTable*>(tableList[j]->table));
  2753. +                           break;
  2754. +                       case TABLE_DATA::TYPE_NIT:
  2755. +                           ret = CheckNIT(tsPacket.PID, static_cast<CNITTable*>(tableList[j]->table));
  2756. +                           break;
  2757. +                       case TABLE_DATA::TYPE_SDT:
  2758. +                           ret = CheckSDT(tsPacket.PID, static_cast<CSDTTable*>(tableList[j]->table));
  2759. +                           break;
  2760. +                       case TABLE_DATA::TYPE_EIT:
  2761. +                           ret = CheckEIT(tsPacket.PID, static_cast<CEITTable*>(tableList[j]->table));
  2762. +                           break;
  2763. +                       case TABLE_DATA::TYPE_TDT:
  2764. +                           ret = CheckTDT(tsPacket.PID, static_cast<CTDTTable*>(tableList[j]->table));
  2765. +                           break;
  2766. +                       case TABLE_DATA::TYPE_TOT:
  2767. +                           ret = CheckTOT(tsPacket.PID, static_cast<CTOTTable*>(tableList[j]->table));
  2768. +                           break;
  2769. +                       case TABLE_DATA::TYPE_SIT:
  2770. +                           ret = CheckSIT(tsPacket.PID, static_cast<CSITTable*>(tableList[j]->table));
  2771. +                           break;
  2772. +                       case TABLE_DATA::TYPE_BIT:
  2773. +                           ret = CheckBIT(tsPacket.PID, static_cast<CBITTable*>(tableList[j]->table));
  2774. +                           break;
  2775. +                       case TABLE_DATA::TYPE_EIT_SD:
  2776. +                           ret = CheckEIT_SD(tsPacket.PID, static_cast<CEITTable_SD*>(tableList[j]->table));
  2777. +                           break;
  2778. +                       case TABLE_DATA::TYPE_EIT_SD2:
  2779. +                           ret = CheckEIT_SD2(tsPacket.PID, static_cast<CEITTable_SD2*>(tableList[j]->table));
  2780. +                           break;
  2781. +                       case TABLE_DATA::TYPE_CAT:
  2782. +                       case TABLE_DATA::TYPE_BAT:
  2783. +                       case TABLE_DATA::TYPE_SDTT:
  2784. +                       case TABLE_DATA::TYPE_CDT:
  2785. +                       default:
  2786. +                           ret = FALSE;
  2787.                         }
  2788. -                   }else{
  2789. -                       if( section[0] == 0 ){
  2790. -                           _OutputDebugString(L"★pid 0x%04X\r\n", tsPacket.PID);
  2791. +                       if (ret == TRUE){
  2792. +                           tableList[j]->table = NULL;
  2793.                         }
  2794. +                       delete tableList[j];
  2795. +                   }
  2796. +               }else{
  2797. +                   if( section[0] == 0 ){
  2798. +                       _OutputDebugString(L"★pid 0x%04X\r\n", tsPacket.PID);
  2799.                     }
  2800.                 }
  2801.             }
  2802. @@ -213,7 +210,7 @@
  2803.             this->patInfo = pat;
  2804.         }else if(this->patInfo->version_number != pat->version_number){
  2805.             //バージョン変わった
  2806. -           SAFE_DELETE(this->patInfo);
  2807. +           delete this->patInfo;
  2808.             this->patInfo = pat;
  2809.         }else{
  2810.             //変更なし
  2811. @@ -237,7 +234,7 @@
  2812.     }else{
  2813.         if( itrPmt->second->version_number != pmt->version_number ){
  2814.             //バージョン変わった
  2815. -           SAFE_DELETE(itrPmt->second);
  2816. +           delete itrPmt->second;
  2817.             this->pmtMap.erase(itrPmt);
  2818.            
  2819.             this->pmtMap.insert(pair<WORD, CPMTTable*>(PID, pmt));
  2820. @@ -273,7 +270,7 @@
  2821.             if( this->nitActualInfo->network_id != nit->network_id ){
  2822.                 //NID変わったのでネットワーク変わった
  2823.                 ChangeTSIDClear(PID);
  2824. -               SAFE_DELETE(this->nitActualInfo);
  2825. +               delete this->nitActualInfo;
  2826.                 this->nitActualInfo = new NIT_SECTION_INFO;
  2827.                 this->nitActualInfo->network_id = nit->network_id;
  2828.                 this->nitActualInfo->version_number = nit->version_number;
  2829. @@ -281,7 +278,7 @@
  2830.                 this->nitActualInfo->nitSection.insert(pair<BYTE, CNITTable*>(nit->section_number, nit));
  2831.             }else if(this->nitActualInfo->version_number != nit->version_number){
  2832.                 //バージョン変わった
  2833. -               SAFE_DELETE(this->nitActualInfo);
  2834. +               delete this->nitActualInfo;
  2835.                 this->nitActualInfo = new NIT_SECTION_INFO;
  2836.                 this->nitActualInfo->network_id = nit->network_id;
  2837.                 this->nitActualInfo->version_number = nit->version_number;
  2838. @@ -297,7 +294,7 @@
  2839.                         if( itr->second->TSInfoList[0]->original_network_id != nit->TSInfoList[0]->original_network_id ){
  2840.                             //ONID変わったのでネットワーク変わった
  2841.                             ChangeTSIDClear(PID);
  2842. -                           SAFE_DELETE(this->nitActualInfo);
  2843. +                           delete this->nitActualInfo;
  2844.                             this->nitActualInfo = new NIT_SECTION_INFO;
  2845.                             this->nitActualInfo->network_id = nit->network_id;
  2846.                             this->nitActualInfo->version_number = nit->version_number;
  2847. @@ -307,7 +304,7 @@
  2848.                             if( itr->second->TSInfoList[0]->transport_stream_id != nit->TSInfoList[0]->transport_stream_id ){
  2849.                                 //TSID変わったのでネットワーク変わった
  2850.                                 ChangeTSIDClear(PID);
  2851. -                               SAFE_DELETE(this->nitActualInfo);
  2852. +                               delete this->nitActualInfo;
  2853.                                 this->nitActualInfo = new NIT_SECTION_INFO;
  2854.                                 this->nitActualInfo->network_id = nit->network_id;
  2855.                                 this->nitActualInfo->version_number = nit->version_number;
  2856. @@ -411,7 +408,7 @@
  2857.             if( this->sdtActualInfo->original_network_id != sdt->original_network_id ){
  2858.                 //ONID変わったのでネットワーク変わった
  2859.                 ChangeTSIDClear(PID);
  2860. -               SAFE_DELETE(this->sdtActualInfo);
  2861. +               delete this->sdtActualInfo;
  2862.                 this->sdtActualInfo = new SDT_SECTION_INFO;
  2863.                 this->sdtActualInfo->original_network_id = sdt->original_network_id;
  2864.                 this->sdtActualInfo->transport_stream_id = sdt->transport_stream_id;
  2865. @@ -421,7 +418,7 @@
  2866.             }else if( this->sdtActualInfo->transport_stream_id != sdt->transport_stream_id ){
  2867.                 //TSID変わったのでチャンネル変わった
  2868.                 ChangeTSIDClear(PID);
  2869. -               SAFE_DELETE(this->sdtActualInfo);
  2870. +               delete this->sdtActualInfo;
  2871.                 this->sdtActualInfo = new SDT_SECTION_INFO;
  2872.                 this->sdtActualInfo->original_network_id = sdt->original_network_id;
  2873.                 this->sdtActualInfo->transport_stream_id = sdt->transport_stream_id;
  2874. @@ -430,7 +427,7 @@
  2875.                 this->sdtActualInfo->sdtSection.insert(pair<BYTE, CSDTTable*>(sdt->section_number, sdt));
  2876.             }else if( this->sdtActualInfo->version_number != sdt->version_number ){
  2877.                 //バージョン変わった
  2878. -               SAFE_DELETE(this->sdtActualInfo);
  2879. +               delete this->sdtActualInfo;
  2880.                 this->sdtActualInfo = new SDT_SECTION_INFO;
  2881.                 this->sdtActualInfo->original_network_id = sdt->original_network_id;
  2882.                 this->sdtActualInfo->transport_stream_id = sdt->transport_stream_id;
  2883. @@ -584,7 +581,7 @@
  2884.             this->bitInfo = bit;
  2885.         }else if( this->bitInfo->version_number != bit->version_number ){
  2886.             //バージョン変わった
  2887. -           SAFE_DELETE(this->bitInfo);
  2888. +           delete this->bitInfo;
  2889.             this->bitInfo = bit;
  2890.         }else{
  2891.             //変化なし
  2892. @@ -641,7 +638,7 @@
  2893.     }else{
  2894.         if( this->sitInfo->version_number != sit->version_number ){
  2895.             //バージョン変わった
  2896. -           SAFE_DELETE(this->sitInfo);
  2897. +           delete this->sitInfo;
  2898.             this->sitInfo = sit;
  2899.         }else{
  2900.             //変化なし
  2901. diff -u -r -N a/EDCB-work-plus-s/EpgDataCap3/EpgDataCap3/Table/TableUtil.cpp b/EDCB-work-plus-s/EpgDataCap3/EpgDataCap3/Table/TableUtil.cpp
  2902. --- a/EDCB-work-plus-s/EpgDataCap3/EpgDataCap3/Table/TableUtil.cpp  2015-05-06 02:05:26.000000000 +0900
  2903. +++ b/EDCB-work-plus-s/EpgDataCap3/EpgDataCap3/Table/TableUtil.cpp  2015-05-01 09:48:07.000000000 +0900
  2904. @@ -13,8 +13,8 @@
  2905.  {
  2906.     if( tableList != NULL ){
  2907.         vector<TABLE_DATA*>::iterator itr;
  2908. -       for( itr = tableList->begin(); itr != tableList->end(); itr++ ){
  2909. -           SAFE_DELETE(*itr);
  2910. +       for( itr = tableList->begin(); itr != tableList->end(); ++itr ){
  2911. +           delete *itr;
  2912.         }
  2913.         tableList->clear();
  2914.     }
  2915. @@ -27,156 +27,95 @@
  2916.     }
  2917.     DWORD decodeSize = 0;
  2918.     while( decodeSize < dataSize ){
  2919. -       DWORD readSize = 0;
  2920.         TABLE_DATA* item = new TABLE_DATA;
  2921. -       if( data[decodeSize] == 0x00 ){
  2922. -           item->PATTable = new CPATTable;
  2923. -           if( item->PATTable->Decode(data + decodeSize, dataSize-decodeSize, &readSize) == FALSE ){
  2924. -               SAFE_DELETE(item);
  2925. -               Clear(tableList);
  2926. -               return FALSE;
  2927. -           }else{
  2928. -               tableList->push_back(item);
  2929. -           }
  2930. -       }else if( data[decodeSize] == 0x01 ){
  2931. -           item->CATTable = new CCATTable;
  2932. -           if( item->CATTable->Decode(data + decodeSize, dataSize-decodeSize, &readSize) == FALSE ){
  2933. -               SAFE_DELETE(item);
  2934. -               Clear(tableList);
  2935. -               return FALSE;
  2936. +       switch (data[decodeSize]){
  2937. +       case 0x00:
  2938. +           item->type = TABLE_DATA::TYPE_PAT;
  2939. +           item->table = new CPATTable;
  2940. +           break;
  2941. +       case 0x01:
  2942. +           item->type = TABLE_DATA::TYPE_CAT;
  2943. +           item->table = new CCATTable;
  2944. +           break;
  2945. +       case 0x02:
  2946. +           item->type = TABLE_DATA::TYPE_PMT;
  2947. +           item->table = new CPMTTable;
  2948. +           break;
  2949. +       case 0x40:
  2950. +       case 0x41:
  2951. +           item->type = TABLE_DATA::TYPE_NIT;
  2952. +           item->table = new CNITTable;
  2953. +           break;
  2954. +       case 0x42:
  2955. +       case 0x46:
  2956. +           item->type = TABLE_DATA::TYPE_SDT;
  2957. +           item->table = new CSDTTable;
  2958. +           break;
  2959. +       case 0x4A:
  2960. +           item->type = TABLE_DATA::TYPE_BAT;
  2961. +           item->table = new CBATTable;
  2962. +           break;
  2963. +       case 0x70:
  2964. +           item->type = TABLE_DATA::TYPE_TDT;
  2965. +           item->table = new CTDTTable;
  2966. +           break;
  2967. +       case 0x73:
  2968. +           item->type = TABLE_DATA::TYPE_TOT;
  2969. +           item->table = new CTOTTable;
  2970. +           break;
  2971. +       case 0xC8:
  2972. +           item->type = TABLE_DATA::TYPE_CDT;
  2973. +           item->table = new CCDTTable;
  2974. +           break;
  2975. +       case 0xC3:
  2976. +           item->type = TABLE_DATA::TYPE_SDTT;
  2977. +           item->table = new CSDTTTable;
  2978. +           break;
  2979. +       case 0xC4:
  2980. +           item->type = TABLE_DATA::TYPE_BIT;
  2981. +           item->table = new CBITTable;
  2982. +           break;
  2983. +       case 0x7F:
  2984. +           item->type = TABLE_DATA::TYPE_SIT;
  2985. +           item->table = new CSITTable;
  2986. +           break;
  2987. +       case 0xA4:
  2988. +       case 0xA7:
  2989. +           item->type = TABLE_DATA::TYPE_EIT_SD;
  2990. +           item->table = new CEITTable_SD;
  2991. +           break;
  2992. +       case 0xA2:
  2993. +       case 0xA3:
  2994. +           item->type = TABLE_DATA::TYPE_EIT_SD2;
  2995. +           item->table = new CEITTable_SD2;
  2996. +           break;
  2997. +       default:
  2998. +           if( 0x4E <= data[decodeSize] && data[decodeSize] <= 0x6F ){
  2999. +               item->type = TABLE_DATA::TYPE_EIT;
  3000. +               item->table = new CEITTable;
  3001. +           }else if( data[decodeSize] == 0xFF ){
  3002. +               //stuffing
  3003. +               delete item;
  3004. +               decodeSize = dataSize;
  3005. +               continue;
  3006.             }else{
  3007. -               tableList->push_back(item);
  3008. -           }
  3009. -       }else if( data[decodeSize] == 0x02 ){
  3010. -           item->PMTTable = new CPMTTable;
  3011. -           if( item->PMTTable->Decode(data + decodeSize, dataSize-decodeSize, &readSize) == FALSE ){
  3012. -               SAFE_DELETE(item);
  3013. +               //_OutputDebugString(L"++CTableUtil:: err UnknownTable 0x%02X\r\n", data[decodeSize]);
  3014. +               delete item;
  3015.                 Clear(tableList);
  3016.                 return FALSE;
  3017. -           }else{
  3018. -               tableList->push_back(item);
  3019.             }
  3020. -       }else if( data[decodeSize] == 0x40 || data[decodeSize] == 0x41 ){
  3021. -           item->NITTable = new CNITTable;
  3022. -           if( item->NITTable->Decode(data + decodeSize, dataSize-decodeSize, &readSize) == FALSE ){
  3023. -               SAFE_DELETE(item);
  3024. -               Clear(tableList);
  3025. -               return FALSE;
  3026. -           }else{
  3027. -               tableList->push_back(item);
  3028. -           }
  3029. -       }else if( data[decodeSize] == 0x42 || data[decodeSize] == 0x46 ){
  3030. -           item->SDTTable = new CSDTTable;
  3031. -           if( item->SDTTable->Decode(data + decodeSize, dataSize-decodeSize, &readSize) == FALSE ){
  3032. -               SAFE_DELETE(item);
  3033. -               Clear(tableList);
  3034. -               return FALSE;
  3035. -           }else{
  3036. -               tableList->push_back(item);
  3037. -           }
  3038. -       }else if( data[decodeSize] == 0x4A ){
  3039. -           item->BATTable = new CBATTable;
  3040. -           if( item->BATTable->Decode(data + decodeSize, dataSize-decodeSize, &readSize) == FALSE ){
  3041. -               SAFE_DELETE(item);
  3042. -               Clear(tableList);
  3043. -               return FALSE;
  3044. -           }else{
  3045. -               tableList->push_back(item);
  3046. -           }
  3047. -       }else if( 0x4E <= data[decodeSize] && data[decodeSize] <= 0x6F ){
  3048. -           item->EITTable = new CEITTable;
  3049. -           if( item->EITTable->Decode(data + decodeSize, dataSize-decodeSize, &readSize) == FALSE ){
  3050. -               SAFE_DELETE(item);
  3051. -               Clear(tableList);
  3052. -               return FALSE;
  3053. -           }else{
  3054. -               tableList->push_back(item);
  3055. -           }
  3056. -       }else if( data[decodeSize] == 0x70 ){
  3057. -           item->TDTTable = new CTDTTable;
  3058. -           if( item->TDTTable->Decode(data + decodeSize, dataSize-decodeSize, &readSize) == FALSE ){
  3059. -               SAFE_DELETE(item);
  3060. -               Clear(tableList);
  3061. -               return FALSE;
  3062. -           }else{
  3063. -               tableList->push_back(item);
  3064. -           }
  3065. -       }else if( data[decodeSize] == 0x73 ){
  3066. -           item->TOTTable = new CTOTTable;
  3067. -           if( item->TOTTable->Decode(data + decodeSize, dataSize-decodeSize, &readSize) == FALSE ){
  3068. -               SAFE_DELETE(item);
  3069. -               Clear(tableList);
  3070. -               return FALSE;
  3071. -           }else{
  3072. -               tableList->push_back(item);
  3073. -           }
  3074. -       }else if( data[decodeSize] == 0xC8 ){
  3075. -           item->CDTTable = new CCDTTable;
  3076. -           if( item->CDTTable->Decode(data + decodeSize, dataSize-decodeSize, &readSize) == FALSE ){
  3077. -               SAFE_DELETE(item);
  3078. -               Clear(tableList);
  3079. -               return FALSE;
  3080. -           }else{
  3081. -               tableList->push_back(item);
  3082. -           }
  3083. -       }else if( data[decodeSize] == 0xC3 ){
  3084. -           item->SDTTTable = new CSDTTTable;
  3085. -           if( item->SDTTTable->Decode(data + decodeSize, dataSize-decodeSize, &readSize) == FALSE ){
  3086. -               SAFE_DELETE(item);
  3087. -               Clear(tableList);
  3088. -               return FALSE;
  3089. -           }else{
  3090. -               tableList->push_back(item);
  3091. -           }
  3092. -       }else if( data[decodeSize] == 0xC4 ){
  3093. -           item->BITTable = new CBITTable;
  3094. -           if( item->BITTable->Decode(data + decodeSize, dataSize-decodeSize, &readSize) == FALSE ){
  3095. -               SAFE_DELETE(item);
  3096. -               Clear(tableList);
  3097. -               return FALSE;
  3098. -           }else{
  3099. -               tableList->push_back(item);
  3100. -           }
  3101. -       }else if( data[decodeSize] == 0x7F ){
  3102. -           item->SITTable = new CSITTable;
  3103. -           if( item->SITTable->Decode(data + decodeSize, dataSize-decodeSize, &readSize) == FALSE ){
  3104. -               SAFE_DELETE(item);
  3105. -               Clear(tableList);
  3106. -               return FALSE;
  3107. -           }else{
  3108. -               tableList->push_back(item);
  3109. -           }
  3110. -       }else if( 0xA4 == data[decodeSize] || 0xA7 == data[decodeSize]){
  3111. -           item->EITTable_SD = new CEITTable_SD;
  3112. -           if( item->EITTable_SD->Decode(data + decodeSize, dataSize-decodeSize, &readSize) == FALSE ){
  3113. -               SAFE_DELETE(item);
  3114. -               Clear(tableList);
  3115. -               return FALSE;
  3116. -           }else{
  3117. -               tableList->push_back(item);
  3118. -           }
  3119. -       }else if( 0xA2 == data[decodeSize] || 0xA3 == data[decodeSize]){
  3120. -           item->EITTable_SD2 = new CEITTable_SD2;
  3121. -           if( item->EITTable_SD2->Decode(data + decodeSize, dataSize-decodeSize, &readSize) == FALSE ){
  3122. -               SAFE_DELETE(item);
  3123. -               Clear(tableList);
  3124. -               return FALSE;
  3125. -           }else{
  3126. -               tableList->push_back(item);
  3127. -           }
  3128. -       }else if( data[decodeSize] == 0xFF ){
  3129. -           //stuffing
  3130. -           decodeSize = dataSize;
  3131. -       }else{
  3132. -           //_OutputDebugString(L"++CTableUtil:: err UnknownTable 0x%02X\r\n", data[decodeSize]);
  3133. -           SAFE_DELETE(item);
  3134. +       }
  3135. +       DWORD readSize;
  3136. +       if( item->table->Decode(data+decodeSize, dataSize-decodeSize, &readSize) == FALSE ){
  3137. +           delete item;
  3138.             Clear(tableList);
  3139.             return FALSE;
  3140.         }
  3141. +       tableList->push_back(item);
  3142.         decodeSize += readSize;
  3143.     }
  3144.     if( decodeReadSize != NULL ){
  3145. -       *decodeReadSize = dataSize;
  3146. +       *decodeReadSize = decodeSize;
  3147.     }
  3148.     return TRUE;
  3149.  }
  3150. diff -u -r -N a/EDCB-work-plus-s/EpgDataCap3/EpgDataCap3/Table/TableUtilDef.h b/EDCB-work-plus-s/EpgDataCap3/EpgDataCap3/Table/TableUtilDef.h
  3151. --- a/EDCB-work-plus-s/EpgDataCap3/EpgDataCap3/Table/TableUtilDef.h 2015-05-06 02:05:26.000000000 +0900
  3152. +++ b/EDCB-work-plus-s/EpgDataCap3/EpgDataCap3/Table/TableUtilDef.h 2015-05-01 03:30:34.000000000 +0900
  3153. @@ -1,6 +1,7 @@
  3154.  #ifndef __TABLE_UTIL_DEF_H__
  3155.  #define __TABLE_UTIL_DEF_H__
  3156.  
  3157. +#include "PSITable.h"
  3158.  #include "BATTable.h"
  3159.  #include "CATTable.h"
  3160.  #include "EITTable.h"
  3161. @@ -18,55 +19,33 @@
  3162.  #include "EITTable_SD2.h"
  3163.  
  3164.  typedef struct _TABLE_DATA{
  3165. -   CBATTable* BATTable;
  3166. -   CCATTable* CATTable;
  3167. -   CEITTable* EITTable;
  3168. -   CNITTable* NITTable;
  3169. -   CPATTable* PATTable;
  3170. -   CPMTTable* PMTTable;
  3171. -   CSDTTable* SDTTable;
  3172. -   CTDTTable* TDTTable;
  3173. -   CTOTTable* TOTTable;
  3174. -   CCDTTable* CDTTable;
  3175. -   CSDTTTable* SDTTTable;
  3176. -   CBITTable* BITTable;
  3177. -   CSITTable* SITTable;
  3178. -   CEITTable_SD* EITTable_SD;
  3179. -   CEITTable_SD2* EITTable_SD2;
  3180. +   enum t_type{
  3181. +       TYPE_PAT = 0,
  3182. +       TYPE_PMT,
  3183. +       TYPE_CAT,
  3184. +       TYPE_NIT,
  3185. +       TYPE_SDT,
  3186. +       TYPE_BAT,
  3187. +       TYPE_EIT,
  3188. +       TYPE_TDT,
  3189. +       TYPE_TOT,
  3190. +       TYPE_SIT,
  3191. +       TYPE_SDTT,
  3192. +       TYPE_BIT,
  3193. +       TYPE_EIT_SD,
  3194. +       TYPE_EIT_SD2,
  3195. +       TYPE_CDT,
  3196. +       TYPE_OTHER,
  3197. +   };
  3198. +   t_type type;
  3199. +   CPSITable* table;
  3200.  
  3201.     _TABLE_DATA(void){
  3202. -       BATTable = NULL;
  3203. -       CATTable = NULL;
  3204. -       EITTable = NULL;
  3205. -       NITTable = NULL;
  3206. -       PATTable = NULL;
  3207. -       PMTTable = NULL;
  3208. -       SDTTable = NULL;
  3209. -       TDTTable = NULL;
  3210. -       TOTTable = NULL;
  3211. -       CDTTable = NULL;
  3212. -       SDTTTable = NULL;
  3213. -       BITTable = NULL;
  3214. -       SITTable = NULL;
  3215. -       EITTable_SD = NULL;
  3216. -       EITTable_SD2 = NULL;
  3217. +       type = TYPE_OTHER;
  3218. +       table = NULL;
  3219.     };
  3220.     ~_TABLE_DATA(void){
  3221. -       SAFE_DELETE(BATTable);
  3222. -       SAFE_DELETE(CATTable);
  3223. -       SAFE_DELETE(EITTable);
  3224. -       SAFE_DELETE(NITTable);
  3225. -       SAFE_DELETE(PATTable);
  3226. -       SAFE_DELETE(PMTTable);
  3227. -       SAFE_DELETE(SDTTable);
  3228. -       SAFE_DELETE(TDTTable);
  3229. -       SAFE_DELETE(TOTTable);
  3230. -       SAFE_DELETE(CDTTable);
  3231. -       SAFE_DELETE(SDTTTable);
  3232. -       SAFE_DELETE(BITTable);
  3233. -       SAFE_DELETE(SITTable);
  3234. -       SAFE_DELETE(EITTable_SD);
  3235. -       SAFE_DELETE(EITTable_SD2);
  3236. +       delete table;
  3237.     };
  3238.  }TABLE_DATA;
  3239.  
  3240. diff -u -r -N a/EDCB-work-plus-s/EpgDataCap_Bon/EpgDataCap_Bon/EpgDataCap_Bon.vcxproj b/EDCB-work-plus-s/EpgDataCap_Bon/EpgDataCap_Bon/EpgDataCap_Bon.vcxproj
  3241. --- a/EDCB-work-plus-s/EpgDataCap_Bon/EpgDataCap_Bon/EpgDataCap_Bon.vcxproj 2015-05-06 02:05:26.000000000 +0900
  3242. +++ b/EDCB-work-plus-s/EpgDataCap_Bon/EpgDataCap_Bon/EpgDataCap_Bon.vcxproj 2015-05-01 10:57:30.000000000 +0900
  3243. @@ -193,20 +193,23 @@
  3244.      <None Include="res\EpgDataCap_Bon_Vista_vio_rev2.ico" />
  3245.    </ItemGroup>
  3246.    <ItemGroup>
  3247. +    <ClInclude Include="..\..\BonCtrl\arib_std_b25.h" />
  3248.      <ClInclude Include="..\..\BonCtrl\BonCtrl.h" />
  3249.      <ClInclude Include="..\..\BonCtrl\BonCtrlDef.h" />
  3250.      <ClInclude Include="..\..\BonCtrl\BonDriverUtil.h" />
  3251. +    <ClInclude Include="..\..\BonCtrl\b_cas_card.h" />
  3252.      <ClInclude Include="..\..\BonCtrl\CATUtil.h" />
  3253.      <ClInclude Include="..\..\BonCtrl\ChSetUtil.h" />
  3254.      <ClInclude Include="..\..\BonCtrl\CreatePATPacket.h" />
  3255.      <ClInclude Include="..\..\BonCtrl\CreatePMTPacket.h" />
  3256. +    <ClInclude Include="..\..\BonCtrl\decoder.h" />
  3257.      <ClInclude Include="..\..\BonCtrl\DropCount.h" />
  3258. -    <ClInclude Include="..\..\BonCtrl\IB25Decoder.h" />
  3259.      <ClInclude Include="..\..\BonCtrl\IBonDriver.h" />
  3260.      <ClInclude Include="..\..\BonCtrl\IBonDriver2.h" />
  3261.      <ClInclude Include="..\..\BonCtrl\OneServiceUtil.h" />
  3262.      <ClInclude Include="..\..\BonCtrl\PacketInit.h" />
  3263.      <ClInclude Include="..\..\BonCtrl\PMTUtil.h" />
  3264. +    <ClInclude Include="..\..\BonCtrl\portable.h" />
  3265.      <ClInclude Include="..\..\BonCtrl\ScrambleDecoderUtil.h" />
  3266.      <ClInclude Include="..\..\BonCtrl\SendTCP.h" />
  3267.      <ClInclude Include="..\..\BonCtrl\SendUDP.h" />
  3268. @@ -257,6 +260,7 @@
  3269.      <ClCompile Include="..\..\BonCtrl\ChSetUtil.cpp" />
  3270.      <ClCompile Include="..\..\BonCtrl\CreatePATPacket.cpp" />
  3271.      <ClCompile Include="..\..\BonCtrl\CreatePMTPacket.cpp" />
  3272. +    <ClCompile Include="..\..\BonCtrl\decoder.cpp" />
  3273.      <ClCompile Include="..\..\BonCtrl\DropCount.cpp" />
  3274.      <ClCompile Include="..\..\BonCtrl\OneServiceUtil.cpp" />
  3275.      <ClCompile Include="..\..\BonCtrl\PacketInit.cpp" />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement