Advertisement
Guest User

Untitled

a guest
Jan 29th, 2015
544
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.99 KB | None | 0 0
  1. #b25 patch for version 1.1.4.11
  2.  
  3. --- BonDriverProxyEx/BonDriverProxyEx.cpp Wed Jan 28 12:51:38 2015
  4. +++ BonDriverProxyEx/BonDriverProxyEx.cpp Thu Jan 29 09:04:18 2015
  5. @@ -6,6 +6,8 @@
  6. #define DETAILLOG2 1
  7. #endif
  8.  
  9. +static int g_b25_enable = false;
  10. +
  11. static int Init(HMODULE hModule)
  12. {
  13. char szIniPath[MAX_PATH + 16] = { '\0' };
  14. @@ -25,6 +27,7 @@
  15. GetPrivateProfileStringA("OPTION", "PORT", "1192", g_Port, sizeof(g_Port), szIniPath);
  16. g_OpenTunerRetDelay = GetPrivateProfileIntA("OPTION", "OPENTUNER_RETURN_DELAY", 0, szIniPath);
  17. g_SandBoxedRelease = GetPrivateProfileIntA("OPTION", "SANDBOXED_RELEASE", 0, szIniPath);
  18. + g_b25_enable = GetPrivateProfileIntA("OPTION", "B25_DECODE", 0, szIniPath);
  19.  
  20. g_PacketFifoSize = GetPrivateProfileIntA("SYSTEM", "PACKET_FIFO_SIZE", 64, szIniPath);
  21. g_TsPacketBufSize = GetPrivateProfileIntA("SYSTEM", "TSPACKET_BUFSIZE", (188 * 1024), szIniPath);
  22. @@ -124,6 +127,7 @@
  23. m_pStopTsRead = NULL;
  24. m_pTsLock = NULL;
  25. m_ppos = NULL;
  26. + m_b25 = NULL;
  27. m_dwSpace = m_dwChannel = 0x7fffffff; // INT_MAX
  28. m_pDriversMapKey = NULL;
  29. m_iDriverNo = -1;
  30. @@ -157,6 +161,7 @@
  31. delete m_pStopTsRead;
  32. delete m_pTsLock;
  33. delete m_ppos;
  34. + delete m_b25;
  35. }
  36.  
  37. Release();
  38. @@ -376,6 +381,7 @@
  39. delete m_pStopTsRead;
  40. delete m_pTsLock;
  41. delete m_ppos;
  42. + delete m_b25;
  43. }
  44. CloseTuner();
  45. }
  46. @@ -389,6 +395,7 @@
  47. m_pStopTsRead = NULL;
  48. m_pTsLock = NULL;
  49. m_ppos = NULL;
  50. + m_b25 = NULL;
  51. m_bTunerOpen = FALSE;
  52. break;
  53. }
  54. @@ -521,6 +528,8 @@
  55. //m_pTsLock = NULL;
  56. delete m_ppos;
  57. //m_ppos = NULL;
  58. + delete m_b25;
  59. + //m_b25 = NULL;
  60. }
  61. CloseTuner();
  62. //m_bTunerOpen = FALSE;
  63. @@ -560,6 +569,7 @@
  64. m_pStopTsRead = (*it)->m_pStopTsRead;
  65. m_pTsLock = (*it)->m_pTsLock;
  66. m_ppos = (*it)->m_ppos;
  67. + m_b25 = (*it)->m_b25;
  68. if (m_hTsRead)
  69. {
  70. m_pTsLock->Enter();
  71. @@ -666,12 +676,18 @@
  72. m_pStopTsRead = new BOOL(FALSE);
  73. m_pTsLock = new cCriticalSection();
  74. m_ppos = new DWORD(0);
  75. - LPVOID *ppv = new LPVOID[5];
  76. + if (g_b25_enable)
  77. + {
  78. + m_b25 = new B25Decoder();
  79. + m_b25->init();
  80. + }
  81. + LPVOID *ppv = new LPVOID[6];
  82. ppv[0] = m_pIBon;
  83. ppv[1] = m_pTsReceiversList;
  84. ppv[2] = m_pStopTsRead;
  85. ppv[3] = m_pTsLock;
  86. ppv[4] = m_ppos;
  87. + ppv[5] = m_b25;
  88. m_hTsRead = ::CreateThread(NULL, 0, cProxyServerEx::TsReader, ppv, 0, NULL);
  89. if (m_hTsRead == NULL)
  90. {
  91. @@ -684,6 +700,8 @@
  92. m_pTsLock = NULL;
  93. delete m_ppos;
  94. m_ppos = NULL;
  95. + delete m_b25;
  96. + m_b25 = NULL;
  97. m_Error.Set();
  98. }
  99. }
  100. @@ -717,6 +735,7 @@
  101. (*it)->m_pStopTsRead = m_pStopTsRead;
  102. (*it)->m_pTsLock = m_pTsLock;
  103. (*it)->m_ppos = m_ppos;
  104. + (*it)->m_b25 = m_b25;
  105. if (m_hTsRead)
  106. {
  107. m_pTsLock->Enter();
  108. @@ -966,6 +985,7 @@
  109. volatile BOOL &StopTsRead = *(static_cast<BOOL *>(ppv[2]));
  110. cCriticalSection &TsLock = *(static_cast<cCriticalSection *>(ppv[3]));
  111. DWORD &pos = *(static_cast<DWORD *>(ppv[4]));
  112. + B25Decoder *b25 = static_cast<B25Decoder *>(ppv[5]);
  113. delete[] ppv;
  114. DWORD dwSize, dwRemain, now, before = 0;
  115. float fSignalLevel = 0;
  116. @@ -991,6 +1011,17 @@
  117. LOCK(TsLock);
  118. if (pIBon->GetTsStream(&pBuf, &dwSize, &dwRemain) && (dwSize != 0))
  119. {
  120. + if (b25)
  121. + {
  122. + ARIB_STD_B25_BUFFER buf;
  123. + buf.data = pBuf;
  124. + buf.size = dwSize;
  125. + b25->decode(&buf);
  126. + if (buf.size == 0)
  127. + goto next;
  128. + pBuf = buf.data;
  129. + dwSize = buf.size;
  130. + }
  131. if ((pos + dwSize) < TsPacketBufSize)
  132. {
  133. ::memcpy(&pTsBuf[pos], pBuf, dwSize);
  134. @@ -1044,6 +1075,7 @@
  135. }
  136. }
  137. }
  138. + next:
  139. if (dwRemain == 0)
  140. ::Sleep(WAIT_TIME);
  141. }
  142. @@ -1084,6 +1116,8 @@
  143. m_pTsLock = NULL;
  144. delete m_ppos;
  145. m_ppos = NULL;
  146. + delete m_b25;
  147. + m_b25 = NULL;
  148. }
  149. }
  150.  
  151. @@ -1144,6 +1178,7 @@
  152. m_pStopTsRead = NULL;
  153. m_pTsLock = NULL;
  154. m_ppos = NULL;
  155. + m_b25 = NULL;
  156. return TRUE;
  157. }
  158. next:
  159. @@ -1265,6 +1300,7 @@
  160. m_pStopTsRead = pCandidate->m_pStopTsRead;
  161. m_pTsLock = pCandidate->m_pTsLock;
  162. m_ppos = pCandidate->m_ppos;
  163. + m_b25 = pCandidate->m_b25;
  164. }
  165.  
  166. // 選択したインスタンスが既にTSストリーム配信中なら、その配信対象リストに自身を追加
  167. diff -u -d -r -N BonDriverProxyEx/BonDriverProxyEx.h BonDriverProxyEx/BonDriverProxyEx.h
  168. --- BonDriverProxyEx/BonDriverProxyEx.h Wed Jan 28 12:51:38 2015
  169. +++ BonDriverProxyEx/BonDriverProxyEx.h Thu Jan 29 09:04:32 2015
  170. @@ -9,6 +9,7 @@
  171. #include <map>
  172. #include "Common.h"
  173. #include "IBonDriver3.h"
  174. +#include "decoder.h"
  175.  
  176. #if _DEBUG
  177. #define _CRTDBG_MAP_ALLOC
  178. @@ -53,6 +54,7 @@
  179. BOOL * volatile m_pStopTsRead;
  180. cCriticalSection *m_pTsLock;
  181. DWORD *m_ppos;
  182. + class B25Decoder *m_b25;
  183. BOOL m_bChannelLock;
  184. #if _DEBUG
  185. public:
  186.  
  187. --- BonDriverProxyEx/BonDriverProxyEx.vcxproj Wed Jan 28 12:51:38 2015
  188. +++ BonDriverProxyEx/BonDriverProxyEx.vcxproj Thu Jan 29 09:06:30 2015
  189. @@ -91,7 +91,7 @@
  190. <Link>
  191. <SubSystem>Windows</SubSystem>
  192. <GenerateDebugInformation>true</GenerateDebugInformation>
  193. - <AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
  194. + <AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ws2_32.lib;winscard.lib;%(AdditionalDependencies)</AdditionalDependencies>
  195. </Link>
  196. </ItemDefinitionGroup>
  197. <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
  198. @@ -107,7 +107,7 @@
  199. <Link>
  200. <SubSystem>Windows</SubSystem>
  201. <GenerateDebugInformation>true</GenerateDebugInformation>
  202. - <AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
  203. + <AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ws2_32.lib;winscard.lib;%(AdditionalDependencies)</AdditionalDependencies>
  204. </Link>
  205. </ItemDefinitionGroup>
  206. <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
  207. @@ -128,7 +128,7 @@
  208. <GenerateDebugInformation>false</GenerateDebugInformation>
  209. <EnableCOMDATFolding>true</EnableCOMDATFolding>
  210. <OptimizeReferences>true</OptimizeReferences>
  211. - <AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
  212. + <AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ws2_32.lib;winscard.lib;%(AdditionalDependencies)</AdditionalDependencies>
  213. </Link>
  214. </ItemDefinitionGroup>
  215. <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
  216. @@ -149,11 +149,16 @@
  217. <GenerateDebugInformation>false</GenerateDebugInformation>
  218. <EnableCOMDATFolding>true</EnableCOMDATFolding>
  219. <OptimizeReferences>true</OptimizeReferences>
  220. - <AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
  221. + <AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ws2_32.lib;winscard.lib;%(AdditionalDependencies)</AdditionalDependencies>
  222. </Link>
  223. </ItemDefinitionGroup>
  224. <ItemGroup>
  225. + <ClCompile Include="arib25\arib_std_b25.c" />
  226. + <ClCompile Include="arib25\b_cas_card.c" />
  227. + <ClCompile Include="arib25\multi2.c" />
  228. + <ClCompile Include="arib25\ts_section_parser.c" />
  229. <ClCompile Include="BonDriverProxyEx.cpp" />
  230. + <ClCompile Include="decoder.cpp" />
  231. </ItemGroup>
  232. <ItemGroup>
  233. <ResourceCompile Include="BonDriverProxyEx.rc" />
  234. @@ -164,7 +169,18 @@
  235. <ClInclude Include="..\inc\IBonDriver.h" />
  236. <ClInclude Include="..\inc\IBonDriver2.h" />
  237. <ClInclude Include="..\inc\IBonDriver3.h" />
  238. + <ClInclude Include="arib25\arib_std_b25.h" />
  239. + <ClInclude Include="arib25\arib_std_b25_error_code.h" />
  240. + <ClInclude Include="arib25\b_cas_card.h" />
  241. + <ClInclude Include="arib25\b_cas_card_error_code.h" />
  242. + <ClInclude Include="arib25\multi2.h" />
  243. + <ClInclude Include="arib25\multi2_error_code.h" />
  244. + <ClInclude Include="arib25\portable.h" />
  245. + <ClInclude Include="arib25\ts_common_types.h" />
  246. + <ClInclude Include="arib25\ts_section_parser.h" />
  247. + <ClInclude Include="arib25\ts_section_parser_error_code.h" />
  248. <ClInclude Include="BonDriverProxyEx.h" />
  249. + <ClInclude Include="decoder.h" />
  250. </ItemGroup>
  251. <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  252. <ImportGroup Label="ExtensionTargets">
  253.  
  254. --- BonDriverProxyEx/decoder.cpp Thu Jan 1 00:00:00 1970
  255. +++ BonDriverProxyEx/decoder.cpp Thu Jan 29 23:14:12 2015
  256. @@ -0,0 +1,127 @@
  257. +// -*- coding: utf-8 -*-
  258. +#include <cstddef>
  259. +#include <cassert>
  260. +#include "decoder.h"
  261. +
  262. +int B25Decoder::multi2_round = 4;
  263. +int B25Decoder::strip = 0;
  264. +int B25Decoder::emm_proc = 0;
  265. +
  266. +B25Decoder::B25Decoder()
  267. + : _bcas(NULL)
  268. + , _b25(NULL)
  269. + , _init_called(false)
  270. + , _pass_through_bytes(0)
  271. +{
  272. +}
  273. +
  274. +B25Decoder::~B25Decoder()
  275. +{
  276. + release();
  277. +}
  278. +
  279. +int B25Decoder::init()
  280. +{
  281. + _init_called = true;
  282. +
  283. + int rc;
  284. +
  285. + assert(_bcas == NULL);
  286. + assert(_b25 == NULL);
  287. +
  288. + _bcas = create_b_cas_card(), rc = 0;
  289. + if (!_bcas) goto err;
  290. +
  291. + rc = _bcas->init(_bcas);
  292. + if (rc < 0) goto err;
  293. +
  294. + _b25 = create_arib_std_b25(), rc = 0;
  295. + if (!_b25) goto err;
  296. +
  297. + rc = _b25->set_b_cas_card(_b25, _bcas);
  298. + if (rc < 0) goto err;
  299. +
  300. + rc = _b25->set_strip(_b25, strip);
  301. + if (rc < 0) goto err;
  302. +
  303. + rc = _b25->set_emm_proc(_b25, emm_proc);
  304. + if (rc < 0) goto err;
  305. +
  306. + rc = _b25->set_multi2_round(_b25, multi2_round);
  307. + if (rc < 0) goto err;
  308. +
  309. + return rc;
  310. +
  311. +err:
  312. +
  313. + release();
  314. +
  315. + return rc;
  316. +}
  317. +
  318. +void B25Decoder::release()
  319. +{
  320. + if (_b25)
  321. + {
  322. + _b25->release(_b25);
  323. + _b25 = NULL;
  324. + }
  325. +
  326. + if (_bcas)
  327. + {
  328. + _bcas->release(_bcas);
  329. + _bcas = NULL;
  330. + }
  331. +}
  332. +
  333. +int B25Decoder::put(ARIB_STD_B25_BUFFER *buf)
  334. +{
  335. + if (isPassThrough())
  336. + {
  337. + _pass_through_buf = *buf;
  338. +
  339. + if (!_init_called)
  340. + return 0;
  341. +
  342. + // 一定間隔でinitを試みる
  343. +
  344. + _pass_through_bytes += buf->size;
  345. + if (_pass_through_bytes > 1024*1024*8)
  346. + {
  347. + if (init() >= 0)
  348. + goto ready;
  349. + _pass_through_bytes = 0;
  350. + }
  351. +
  352. + return 0;
  353. + }
  354. +
  355. +ready:
  356. +
  357. + const int rc = _b25->put(_b25, buf);
  358. + if (rc < 0)
  359. + {
  360. + // 乱暴だけどエラーコードに関係なくB-CASカードが抜かれたと判断。
  361. + // 以降、パススルー動作。
  362. + // ※カードを抜くとARIB_STD_B25_ERROR_ECM_PROC_FAILURE(-9)
  363. +
  364. + release();
  365. + _pass_through_buf = *buf;
  366. + _pass_through_bytes = buf->size;
  367. + }
  368. +
  369. + return rc;
  370. +}
  371. +
  372. +int B25Decoder::get(ARIB_STD_B25_BUFFER *buf)
  373. +{
  374. + if (isPassThrough())
  375. + {
  376. + *buf = _pass_through_buf;
  377. + return 0;
  378. + }
  379. +
  380. + const int rc = _b25->get(_b25, buf);
  381. +
  382. + return rc;
  383. +}
  384. diff -u -d -r -N BonDriverProxyEx/decoder.h BonDriverProxyEx/decoder.h
  385. --- BonDriverProxyEx/decoder.h Thu Jan 1 00:00:00 1970
  386. +++ BonDriverProxyEx/decoder.h Thu Jan 29 23:14:28 2015
  387. @@ -0,0 +1,48 @@
  388. +// -*- coding: utf-8 -*-
  389. +#pragma once
  390. +
  391. +#include "arib25/arib_std_b25.h"
  392. +
  393. +class B25Decoder
  394. +{
  395. + B_CAS_CARD *_bcas;
  396. + ARIB_STD_B25 *_b25;
  397. +
  398. + bool _init_called;
  399. + ARIB_STD_B25_BUFFER _pass_through_buf;
  400. + uint32_t _pass_through_bytes;
  401. +
  402. +public:
  403. + B25Decoder();
  404. +
  405. + ~B25Decoder();
  406. +
  407. + int init();
  408. +
  409. + void release();
  410. +
  411. + int put(ARIB_STD_B25_BUFFER *buf);
  412. +
  413. + int get(ARIB_STD_B25_BUFFER *buf);
  414. +
  415. + void decode(ARIB_STD_B25_BUFFER *buf)
  416. + {
  417. + (void) put(buf); // putは常に成功する
  418. + (void) get(buf); // getもlibarib25を読む限り常に成功する
  419. + }
  420. +
  421. + bool isValid() const { return _b25 != 0; }
  422. +
  423. + bool isPassThrough() const { return _b25 == 0; }
  424. +
  425. + // initialize parameter
  426. +
  427. + static int multi2_round;
  428. + static int strip;
  429. + static int emm_proc;
  430. +
  431. +private:
  432. +
  433. + B25Decoder(const B25Decoder &); // undef
  434. + B25Decoder &operator=(const B25Decoder &); // undef
  435. +};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement