Advertisement
Guest User

sample+b25

a guest
Aug 31st, 2014
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 4.78 KB | None | 0 0
  1. diff -r 9e44cc43345d sample
  2. Binary file sample has changed
  3. diff -r 9e44cc43345d sample.cpp
  4. --- a/sample.cpp    Sun Aug 31 20:06:03 2014 +0900
  5. +++ b/sample.cpp    Sun Aug 31 23:47:57 2014 +0900
  6. @@ -1,5 +1,5 @@
  7.  /*
  8. -$ g++ -O2 -Wall -rdynamic -o sample sample.cpp -ldl
  9. +$ g++ -O2 -Wall -rdynamic -o sample sample.cpp -ldl -larib25
  10.  */
  11.  #define FILE_OFFSET_BITS   64
  12.  #include <unistd.h>
  13. @@ -15,6 +15,70 @@
  14.  #include "typedef.h"
  15.  #include "IBonDriver2.h"
  16.  
  17. +#include <getopt.h>
  18. +#include "arib25/arib_std_b25.h"
  19. +
  20. +class B25Decorder {
  21. +   ARIB_STD_B25 *b25;
  22. +   B_CAS_CARD *bcas;
  23. +   bool valid;
  24. +   ARIB_STD_B25_BUFFER sbuf;
  25. +   ARIB_STD_B25_BUFFER dbuf;
  26. +
  27. +public:
  28. +   B25Decorder(bool strip = false, bool emm = false, int round = 4)
  29. +       : b25(0),
  30. +         bcas(0),
  31. +         valid(true)
  32. +   {
  33. +       bcas = create_b_cas_card();
  34. +       if (!bcas) goto err;
  35. +       if (bcas->init(bcas) < 0) goto err;
  36. +       b25 = create_arib_std_b25();
  37. +       if (!b25) goto err;
  38. +       if (b25->set_strip(b25, strip) < 0) goto err;
  39. +       if (b25->set_emm_proc(b25, emm) < 0) goto err;
  40. +       if (b25->set_multi2_round(b25, round) < 0) goto err;
  41. +       if (b25->set_b_cas_card(b25, bcas) < 0) goto err;
  42. +       return;
  43. +   err:
  44. +       fprintf(stderr, "B25Decorder initialize failed.\n");
  45. +       valid = false;
  46. +   }
  47. +
  48. +   ~B25Decorder()
  49. +   {
  50. +       if (b25) b25->release(b25);
  51. +       if (bcas) bcas->release(bcas);
  52. +   }
  53. +
  54. +   ssize_t write(int fd, void *buf, size_t count)
  55. +   {
  56. +       if (!valid) return ::write(fd, buf, count);
  57. +       sbuf.data = static_cast<uint8_t *>(buf);
  58. +       sbuf.size = count;
  59. +       int code;
  60. +       if ((code = b25->put(b25, &sbuf)) < 0) return code;
  61. +       if ((code = b25->get(b25, &dbuf)) < 0) return code;
  62. +       if (dbuf.size > 0)
  63. +       {
  64. +           ssize_t len = ::write(fd, dbuf.data, dbuf.size);
  65. +           if (len < 0) return len;
  66. +       }
  67. +       return count;
  68. +   }
  69. +
  70. +   int flush(int fd)
  71. +   {
  72. +       if (!valid) return 0;
  73. +       int code;
  74. +       if ((code = b25->flush(b25)) < 0) return code;
  75. +       if ((code = b25->get(b25, &dbuf)) < 0) return code;
  76. +       if (dbuf.size > 0) return ::write(fd, dbuf.data, dbuf.size);
  77. +       return 0;
  78. +   }
  79. +};
  80. +
  81.  static volatile BOOL bStop = FALSE;
  82.  static void handler(int sig)
  83.  {
  84. @@ -23,13 +87,17 @@
  85.  
  86.  void usage(char *p)
  87.  {
  88. -   fprintf(stderr, "usage: %s [-b bondriver] [-s space_no] [-c channel_no] ( [-t sec] [-o filename] )\n", p);
  89. +   fprintf(stderr, "usage: %s [--b25 [--round N] [--strip] [--EMM]] [-b bondriver] [-s space_no] [-c channel_no] ( [-t sec] [-o filename] )\n", p);
  90.     exit(0);
  91.  }
  92.  
  93.  int main(int argc, char *argv[])
  94.  {
  95.     int opt, bfind, sfind, cfind, ofind, wfd;
  96. +   bool b25 = false;
  97. +   bool strip = false;
  98. +   bool emm = false;
  99. +   int round = 4;
  100.     char *bon, *output;
  101.     DWORD sec, dwSpace, dwChannel;
  102.  
  103. @@ -38,7 +106,21 @@
  104.     bon = output = NULL;
  105.     bfind = sfind = cfind = ofind = 0;
  106.     dwSpace = dwChannel = 0;
  107. -   while ((opt = getopt(argc, argv, "b:s:c:t:o:")) != -1)
  108. +
  109. +   static struct option options[] = {
  110. +       {"bondriver", required_argument, NULL, 'b'},
  111. +       {"space",     required_argument, NULL, 's'},
  112. +       {"channel",   required_argument, NULL, 'c'},
  113. +       {"time",      required_argument, NULL, 't'},
  114. +       {"output",    required_argument, NULL, 'o'},
  115. +       {"b25",             no_argument, NULL, 'B'},
  116. +       {"round",     required_argument, NULL, 'R'},
  117. +       {"strip",           no_argument, NULL, 'S'},
  118. +       {"EMM",             no_argument, NULL, 'E'},
  119. +       {0}
  120. +   };
  121. +
  122. +   while ((opt = getopt_long(argc, argv, "b:s:c:t:o:BR:SE", options, NULL)) != -1)
  123.     {
  124.         switch (opt)
  125.         {
  126. @@ -61,6 +143,18 @@
  127.             output = optarg;
  128.             ofind = 1;
  129.             break;
  130. +       case 'B':
  131. +           b25 = true;
  132. +           break;
  133. +       case 'R':
  134. +           round = strtoul(optarg, NULL, 10);
  135. +           break;
  136. +       case 'S':
  137. +           strip = true;
  138. +           break;
  139. +       case 'E':
  140. +           emm = true;
  141. +           break;
  142.         default:
  143.             usage(argv[0]);
  144.         }
  145. @@ -150,6 +244,11 @@
  146.     timespec ts;
  147.     ts.tv_sec = 0;
  148.     ts.tv_nsec = 10 * 1000 * 1000;  // 10ms
  149. +   B25Decorder *b25dec(0);
  150. +   if (b25) {
  151. +       b25dec = new B25Decorder(strip, emm, round);
  152. +       //fprintf(stderr, "%d, %d, %d\n", strip, emm, round);
  153. +   }
  154.     while (!bStop)
  155.     {
  156.         // TSストリーム取得
  157. @@ -161,7 +260,15 @@
  158.             int len, left = (int)dwSize;
  159.             do
  160.             {
  161. -               len = write(wfd, pBuf, left);
  162. +               if (b25dec)
  163. +               {
  164. +                   len = b25dec->write(wfd, pBuf, left);
  165. +                   len = left;
  166. +               }
  167. +               else
  168. +               {
  169. +                   len = write(wfd, pBuf, left);
  170. +               }
  171.                 if (len < 0)
  172.                 {
  173.                     perror("write");
  174. @@ -188,7 +295,14 @@
  175.             int len, left = (int)dwSize;
  176.             do
  177.             {
  178. -               len = write(wfd, pBuf, left);
  179. +               if (b25dec)
  180. +               {
  181. +                   len = b25dec->write(wfd, pBuf, left);
  182. +               }
  183. +               else
  184. +               {
  185. +                   len = write(wfd, pBuf, left);
  186. +               }
  187.                 if (len < 0)
  188.                 {
  189.                     perror("write");
  190. @@ -203,6 +317,8 @@
  191.     }
  192.  
  193.  err:
  194. +   if (b25dec) b25dec->flush(wfd);
  195. +   delete b25dec;
  196.     close(wfd);
  197.     // インスタンス解放 & モジュールリリース
  198.     pIBon->Release();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement