Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff -r 9e44cc43345d sample
- Binary file sample has changed
- diff -r 9e44cc43345d sample.cpp
- --- a/sample.cpp Sun Aug 31 20:06:03 2014 +0900
- +++ b/sample.cpp Sun Aug 31 23:47:57 2014 +0900
- @@ -1,5 +1,5 @@
- /*
- -$ g++ -O2 -Wall -rdynamic -o sample sample.cpp -ldl
- +$ g++ -O2 -Wall -rdynamic -o sample sample.cpp -ldl -larib25
- */
- #define FILE_OFFSET_BITS 64
- #include <unistd.h>
- @@ -15,6 +15,70 @@
- #include "typedef.h"
- #include "IBonDriver2.h"
- +#include <getopt.h>
- +#include "arib25/arib_std_b25.h"
- +
- +class B25Decorder {
- + ARIB_STD_B25 *b25;
- + B_CAS_CARD *bcas;
- + bool valid;
- + ARIB_STD_B25_BUFFER sbuf;
- + ARIB_STD_B25_BUFFER dbuf;
- +
- +public:
- + B25Decorder(bool strip = false, bool emm = false, int round = 4)
- + : b25(0),
- + bcas(0),
- + valid(true)
- + {
- + bcas = create_b_cas_card();
- + if (!bcas) goto err;
- + if (bcas->init(bcas) < 0) goto err;
- + b25 = create_arib_std_b25();
- + if (!b25) goto err;
- + if (b25->set_strip(b25, strip) < 0) goto err;
- + if (b25->set_emm_proc(b25, emm) < 0) goto err;
- + if (b25->set_multi2_round(b25, round) < 0) goto err;
- + if (b25->set_b_cas_card(b25, bcas) < 0) goto err;
- + return;
- + err:
- + fprintf(stderr, "B25Decorder initialize failed.\n");
- + valid = false;
- + }
- +
- + ~B25Decorder()
- + {
- + if (b25) b25->release(b25);
- + if (bcas) bcas->release(bcas);
- + }
- +
- + ssize_t write(int fd, void *buf, size_t count)
- + {
- + if (!valid) return ::write(fd, buf, count);
- + sbuf.data = static_cast<uint8_t *>(buf);
- + sbuf.size = count;
- + int code;
- + if ((code = b25->put(b25, &sbuf)) < 0) return code;
- + if ((code = b25->get(b25, &dbuf)) < 0) return code;
- + if (dbuf.size > 0)
- + {
- + ssize_t len = ::write(fd, dbuf.data, dbuf.size);
- + if (len < 0) return len;
- + }
- + return count;
- + }
- +
- + int flush(int fd)
- + {
- + if (!valid) return 0;
- + int code;
- + if ((code = b25->flush(b25)) < 0) return code;
- + if ((code = b25->get(b25, &dbuf)) < 0) return code;
- + if (dbuf.size > 0) return ::write(fd, dbuf.data, dbuf.size);
- + return 0;
- + }
- +};
- +
- static volatile BOOL bStop = FALSE;
- static void handler(int sig)
- {
- @@ -23,13 +87,17 @@
- void usage(char *p)
- {
- - fprintf(stderr, "usage: %s [-b bondriver] [-s space_no] [-c channel_no] ( [-t sec] [-o filename] )\n", p);
- + fprintf(stderr, "usage: %s [--b25 [--round N] [--strip] [--EMM]] [-b bondriver] [-s space_no] [-c channel_no] ( [-t sec] [-o filename] )\n", p);
- exit(0);
- }
- int main(int argc, char *argv[])
- {
- int opt, bfind, sfind, cfind, ofind, wfd;
- + bool b25 = false;
- + bool strip = false;
- + bool emm = false;
- + int round = 4;
- char *bon, *output;
- DWORD sec, dwSpace, dwChannel;
- @@ -38,7 +106,21 @@
- bon = output = NULL;
- bfind = sfind = cfind = ofind = 0;
- dwSpace = dwChannel = 0;
- - while ((opt = getopt(argc, argv, "b:s:c:t:o:")) != -1)
- +
- + static struct option options[] = {
- + {"bondriver", required_argument, NULL, 'b'},
- + {"space", required_argument, NULL, 's'},
- + {"channel", required_argument, NULL, 'c'},
- + {"time", required_argument, NULL, 't'},
- + {"output", required_argument, NULL, 'o'},
- + {"b25", no_argument, NULL, 'B'},
- + {"round", required_argument, NULL, 'R'},
- + {"strip", no_argument, NULL, 'S'},
- + {"EMM", no_argument, NULL, 'E'},
- + {0}
- + };
- +
- + while ((opt = getopt_long(argc, argv, "b:s:c:t:o:BR:SE", options, NULL)) != -1)
- {
- switch (opt)
- {
- @@ -61,6 +143,18 @@
- output = optarg;
- ofind = 1;
- break;
- + case 'B':
- + b25 = true;
- + break;
- + case 'R':
- + round = strtoul(optarg, NULL, 10);
- + break;
- + case 'S':
- + strip = true;
- + break;
- + case 'E':
- + emm = true;
- + break;
- default:
- usage(argv[0]);
- }
- @@ -150,6 +244,11 @@
- timespec ts;
- ts.tv_sec = 0;
- ts.tv_nsec = 10 * 1000 * 1000; // 10ms
- + B25Decorder *b25dec(0);
- + if (b25) {
- + b25dec = new B25Decorder(strip, emm, round);
- + //fprintf(stderr, "%d, %d, %d\n", strip, emm, round);
- + }
- while (!bStop)
- {
- // TSストリーム取得
- @@ -161,7 +260,15 @@
- int len, left = (int)dwSize;
- do
- {
- - len = write(wfd, pBuf, left);
- + if (b25dec)
- + {
- + len = b25dec->write(wfd, pBuf, left);
- + len = left;
- + }
- + else
- + {
- + len = write(wfd, pBuf, left);
- + }
- if (len < 0)
- {
- perror("write");
- @@ -188,7 +295,14 @@
- int len, left = (int)dwSize;
- do
- {
- - len = write(wfd, pBuf, left);
- + if (b25dec)
- + {
- + len = b25dec->write(wfd, pBuf, left);
- + }
- + else
- + {
- + len = write(wfd, pBuf, left);
- + }
- if (len < 0)
- {
- perror("write");
- @@ -203,6 +317,8 @@
- }
- err:
- + if (b25dec) b25dec->flush(wfd);
- + delete b25dec;
- close(wfd);
- // インスタンス解放 & モジュールリリース
- pIBon->Release();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement