From b6ad0113cbd5d8d6511db7948b7de912cbc8e549 Mon Sep 17 00:00:00 2001 From: longinus Date: Fri, 18 Feb 2011 12:20:35 +0000 Subject: [PATCH] add bit parser git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/rec10@840 4e526526-5e11-4fc0-8910-f8fd03428081 --- epgdump/Makefile | 4 +- epgdump/bit.c | 133 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ epgdump/bit.h | 57 +++++++++++++++++++++++ epgdump/dsmcc.c | 1 - epgdump/epgdump.c | 18 ++++++-- epgdump/sdt.c | 6 ++- epgdump/sdt.h | 1 + epgdump/util.c | 3 -- epgdump/util.h | 2 + 9 files changed, 212 insertions(+), 13 deletions(-) create mode 100644 epgdump/bit.c create mode 100644 epgdump/bit.h diff --git a/epgdump/Makefile b/epgdump/Makefile index 79264f4..8fab02d 100644 --- a/epgdump/Makefile +++ b/epgdump/Makefile @@ -1,7 +1,7 @@ PREFIX = /usr/local TARGETS = epgdump -OBJ_TARGETS = epgdump.o aribstr.o eit.o ts.o util.o psi.o sdt.o cdt.o sdtt.o dsmcc.o tot.o clt2png.o -HEDDERDEPEND = eit.h psi.h sdt.h cdt.h sdtt.h dsmcc.h tot.h clt2png.h aribstr.h ts.h util.h +OBJ_TARGETS = epgdump.o aribstr.o eit.o ts.o util.o psi.o sdt.o cdt.o sdtt.o dsmcc.o tot.o bit.o clt2png.o +HEDDERDEPEND = aribstr.h eit.h ts.h util.h psi.h sdt.h cdt.h sdtt.h dsmcc.h tot.h bit.h clt2png.h LANG = C CC = gcc diff --git a/epgdump/bit.c b/epgdump/bit.c new file mode 100644 index 0000000..0646624 --- /dev/null +++ b/epgdump/bit.c @@ -0,0 +1,133 @@ +// -*- tab-width:4 -*- + +#include +#include +#include + +#include "bit.h" + +// 2-STD-B10v4_6.pdf p89 (101/399) +int parseBIThead(unsigned char *data, BIThead *head) { + int boff = 0; + + memset(head, 0, sizeof(BIThead)); + + head->table_id = getBit(data, &boff, 8); + head->section_syntax_indicator = getBit(data, &boff, 1); + head->reserved_future_use1 = getBit(data, &boff, 1); + head->reserved1 = getBit(data, &boff, 2); + head->section_length = getBit(data, &boff, 12); + head->original_network_id = getBit(data, &boff, 16); + head->reserved2 = getBit(data, &boff, 2); + head->version_number = getBit(data, &boff, 5); + head->current_next_indicator = getBit(data, &boff, 1); + head->section_number = getBit(data, &boff, 8); + head->last_section_number = getBit(data, &boff, 8); + head->reserved_future_use2 = getBit(data, &boff, 3); + head->broadcast_view_propriety = getBit(data, &boff, 1); + head->first_descriptors_length = getBit(data, &boff, 12); + return 10 + head->first_descriptors_length; +} + +// 4-TR-B14v4_3-2p3.pdf p4-254 (276/543) +int parseBITloop(unsigned char *data, BITloop *loop) { + int boff = 0; + + memset(loop, 0, sizeof(BITloop)); + + loop->broadcaster_id = getBit(data, &boff, 8); + loop->reserved_future_use = getBit(data, &boff, 4); + loop->broadcaster_descriptors_length = getBit(data, &boff, 12); + + return 3; +} + +// SI伝送パラメータ記述子 +int parseBITdesc(unsigned char *data, BITdesc *desc) { + int boff = 0; + + memset(desc, 0, sizeof(BITdesc)); + + desc->descriptor_tag = getBit(data, &boff, 8); + desc->descriptor_length = getBit(data, &boff, 8); + desc->parameter_version = getBit(data, &boff, 8); + desc->update_time = getBit(data, &boff,16); + + return 5; +} + +int parseBITtable(unsigned char *data, BITtable *table) { + int boff = 0; + + memset(table, 0, sizeof(BITtable)); + + table->table_id = getBit(data, &boff, 8); + table->table_description_length = getBit(data, &boff, 8); + table->table_cycle = getBit(data, &boff, 16); + + return table->table_description_length + 2; +} + +void dumpBIT(unsigned char *ptr) +{ + BIThead bith; + BITloop bitl; + BITdesc bitd; + BITtable bitt; + + int len = 0; + int loop_len = 0; + int desc_len = 0; + int table_len = 0; + + /* BIT */ + len = parseBIThead(ptr, &bith); + ptr += len; + loop_len = bith.section_length - (len - 3 + 4); // 3は共通ヘッダ長 4はCRC + + while(loop_len > 0) { + len = parseBITloop(ptr, &bitl); + ptr += len; + loop_len -= len; + + desc_len = bitl.broadcaster_descriptors_length; + loop_len -= desc_len; + + while(desc_len > 0) { + len = parseBITdesc(ptr, &bitd); + ptr += len; + desc_len -= len; + + table_len = bitd.descriptor_length - 3; + desc_len -= table_len; + + if ( bitd.descriptor_tag != 0xD7 ) { + ptr += table_len; + continue; + } + + while(table_len > 0) { + len = parseBITtable(ptr, &bitt); + ptr += len; + table_len -= len; + + /* + 0x4E (M-EIT,L-EIT) + 0x50(各局伝送パラメータ運用部分の H-EIT[schedule basic]) + 0x58 (各局伝送パラメータ運用部分の H-EIT[schedule extended]) + 0xC3(SDTT) + 0xC8(CDT) + */ + + if (0) printf("BIT=(%d)%d:%d:%d:%d|0x%x:%d:%d=BCD(%d)\n", + bitl.broadcaster_id, bitd.descriptor_tag, bitd.descriptor_length, + bitd.parameter_version, bitd.update_time, + bitt.table_id, bitt.table_description_length, + bitt.table_cycle, BCD(bitt.table_cycle)); + } + } + } + + return; +} + diff --git a/epgdump/bit.h b/epgdump/bit.h new file mode 100644 index 0000000..fd964ce --- /dev/null +++ b/epgdump/bit.h @@ -0,0 +1,57 @@ +#ifndef BIT_H +#define BIT_H 1 + +#include "util.h" +#include "ts_ctl.h" + +typedef struct _BIThead { + unsigned char table_id; + int section_syntax_indicator; + int reserved_future_use1; + int reserved1; + int section_length; + int original_network_id; + int reserved2; + int version_number; + int current_next_indicator; + int section_number; + int last_section_number; + int reserved_future_use2; + int broadcast_view_propriety; + int first_descriptors_length; + // first_descriptors skipped +} BIThead; + +typedef struct _BITloop { + int broadcaster_id; + int reserved_future_use; + int broadcaster_descriptors_length; +} BITloop; + +typedef struct _BITdesc { + int descriptor_tag; + int descriptor_length; + int parameter_version; + int update_time; +} BITdesc; + +typedef struct _BITtable { + int table_id; + int table_description_length; + int table_cycle; +} BITtable; + +#ifdef __cplusplus +extern "C"{ +#endif /* __cplusplus */ + + int parseBIThead(unsigned char *data, BIThead *head); + int parseBITdesc(unsigned char *data, BITdesc *desc); + void dumpBIT(unsigned char *ptr); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif + diff --git a/epgdump/dsmcc.c b/epgdump/dsmcc.c index 0a21085..7924935 100644 --- a/epgdump/dsmcc.c +++ b/epgdump/dsmcc.c @@ -164,7 +164,6 @@ void dumpDSMCC(unsigned char *ptr, int * downloadDataId, DSM_CONTROL *dsmctl) DSMCCbodyDIIModule *module; int len = 0; - int loop_len = 0; int i = 0; /* DSMCC */ diff --git a/epgdump/epgdump.c b/epgdump/epgdump.c index bb33d3c..0c0141b 100755 --- a/epgdump/epgdump.c +++ b/epgdump/epgdump.c @@ -34,11 +34,11 @@ static CONTENT_TYPE ContentCatList[CAT_COUNT] = { { "ドキュメンタリー・教養", "documentary" }, { "演劇", "stage" }, { "趣味・実用", "hobby" }, - { "福祉", "etc" }, //福祉 - { "予備", "etc" }, //予備 - { "予備", "etc" }, //予備 - { "予備", "etc" }, //予備 - { "その他", "etc" } //その他 + { "福祉", "welfare" }, + { "予備", "etc" }, + { "予備", "etc" }, + { "予備", "etc" }, + { "その他", "etc" } }; @@ -130,6 +130,10 @@ void GetSDT(FILE *infile, SVT_CONTROL *svttop, SECcache *secs, //else if((bsecs->pid & 0xFF) == 0x23) { // dumpSDTT(bsecs->buf, *station, *station_count); //} + /* BIT */ + else if((bsecs->pid & 0xFF) == 0x24) { + dumpBIT(bsecs->buf); + } /* CDT */ else if((bsecs->pid & 0xFF) == 0x29) { dumpCDT(bsecs->buf, *station, *station_count); @@ -383,6 +387,7 @@ int main(int argc, char *argv[]) fprintf(stdout, "Usage : %s (/LOGO) {/BS|/CS|} \n", argv[0]); fprintf(stdout, "\n"); fprintf(stdout, "/LOGO ロゴ取得モード。独立して指定し、番組表の出力を行ないません。\n"); + fprintf(stdout, " 必要なTSの長さ 地上波は10分 BS/CSは20分です。\n"); fprintf(stdout, "id チャンネル識別子。地上波の物理チャンネルを与えます。\n"); fprintf(stdout, "/BS BSモード。一つのTSからBS全局のデータを読み込みます。\n"); fprintf(stdout, "/CS CSモード。一つのTSから複数局のデータを読み込みます。\n"); @@ -439,6 +444,9 @@ int main(int argc, char *argv[]) char *head = "CS"; GetSDT(infile, svttop, secs, SECCOUNT, &pStas, &staCount, head, is_logo); }else if(strcmp(arg_onTV, "/TEST") == 0){ + memset(secs, 0, sizeof(SECcache) * SECCOUNT); + secs[0].pid = 0x24; /* BIT */ + char *head = "TEST"; GetSDT(infile, svttop, secs, SECCOUNT, &pStas, &staCount, head, 0); //if (sta_count) diff --git a/epgdump/sdt.c b/epgdump/sdt.c index 0f8d12a..3cc2f23 100755 --- a/epgdump/sdt.c +++ b/epgdump/sdt.c @@ -178,8 +178,9 @@ void dumpSDT(unsigned char *ptr, SVT_CONTROL *top,STATION **station, int * stati if ( logd.logo_transmission_type != 0x01 ) continue; for (i=0; i>4)*10+(n&0xf)) - time_t parseMJD( unsigned char *data ) { int tnum, year, mon, mday; struct tm MJD; diff --git a/epgdump/util.h b/epgdump/util.h index a2cff51..1b782f8 100755 --- a/epgdump/util.h +++ b/epgdump/util.h @@ -4,6 +4,8 @@ #define MAXSECLEN 4096 #include +//#define BCD(n) ((n/100)<<8)|(((n%100)/10)<<4)|(n%10) +#define BCD(n) ((n>>4)*10+(n&0xf)) #ifdef __cplusplus extern "C"{ -- 2.11.0