OSDN Git Service

add bit parser
authorlonginus <longinus@4e526526-5e11-4fc0-8910-f8fd03428081>
Fri, 18 Feb 2011 12:20:35 +0000 (12:20 +0000)
committerlonginus <longinus@4e526526-5e11-4fc0-8910-f8fd03428081>
Fri, 18 Feb 2011 12:20:35 +0000 (12:20 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/rec10@840 4e526526-5e11-4fc0-8910-f8fd03428081

epgdump/Makefile
epgdump/bit.c [new file with mode: 0644]
epgdump/bit.h [new file with mode: 0644]
epgdump/dsmcc.c
epgdump/epgdump.c
epgdump/sdt.c
epgdump/sdt.h
epgdump/util.c
epgdump/util.h

index 79264f4..8fab02d 100644 (file)
@@ -1,7 +1,7 @@
 PREFIX         = /usr/local
 TARGETS        = epgdump
 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
 
 LANG           = C
 CC             = gcc
diff --git a/epgdump/bit.c b/epgdump/bit.c
new file mode 100644 (file)
index 0000000..0646624
--- /dev/null
@@ -0,0 +1,133 @@
+// -*- tab-width:4 -*-
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#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 (file)
index 0000000..fd964ce
--- /dev/null
@@ -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
+
index 0a21085..7924935 100644 (file)
@@ -164,7 +164,6 @@ void dumpDSMCC(unsigned char *ptr, int * downloadDataId, DSM_CONTROL *dsmctl)
        DSMCCbodyDIIModule *module;
 
        int len = 0;
        DSMCCbodyDIIModule *module;
 
        int len = 0;
-       int loop_len = 0;
        int i = 0;
 
        /* DSMCC */
        int i = 0;
 
        /* DSMCC */
index bb33d3c..0c0141b 100755 (executable)
@@ -34,11 +34,11 @@ static  CONTENT_TYPE        ContentCatList[CAT_COUNT] = {
        { "ドキュメンタリー・教養", "documentary" },
        { "演劇", "stage" },
        { "趣味・実用", "hobby" },
        { "ドキュメンタリー・教養", "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);
                //}
                //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);
                /* 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|<id>} <tsFile> <outfile>\n", argv[0]);
                fprintf(stdout, "\n");
                fprintf(stdout, "/LOGO    ロゴ取得モード。独立して指定し、番組表の出力を行ないません。\n");
                fprintf(stdout, "Usage : %s (/LOGO) {/BS|/CS|<id>} <tsFile> <outfile>\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");
                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){
                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) 
                char *head = "TEST";
                GetSDT(infile, svttop, secs, SECCOUNT, &pStas, &staCount, head, 0);
                //if (sta_count) 
index 0f8d12a..3cc2f23 100755 (executable)
@@ -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<stationi; i++) {
 
                                if ( logd.logo_transmission_type != 0x01 ) continue;
                                for (i=0; i<stationi; i++) {
-                                       if ( pStation[i].svId == sdtb.service_id ) {
+                                       if ( pStation[i].svId == sdtb.service_id && pStation[i].logo_version < logd.logo_version ) {
                                                pStation[i].logo_download_data_id = logd.download_data_id;
                                                pStation[i].logo_download_data_id = logd.download_data_id;
+                                               pStation[i].logo_version = logd.logo_version;
                                        }
                                }
 
                                        }
                                }
 
@@ -215,12 +216,13 @@ void dumpSDT(unsigned char *ptr, SVT_CONTROL *top,STATION **station, int * stati
                                        }
 
                                        pStation = realloc(pStation, (stationi + 1) * sizeof(STATION));
                                        }
 
                                        pStation = realloc(pStation, (stationi + 1) * sizeof(STATION));
+                                       memset(&pStation[stationi], 0, sizeof(STATION));
+
                                        pStation[stationi].name = malloc( strlen(desc.service_name) + 1 );
                                        pStation[stationi].ontv = malloc( strlen(sid) + 1 );
                                        pStation[stationi].tsId = sdth.transport_stream_id;
                                        pStation[stationi].onId = sdth.original_network_id;
                                        pStation[stationi].svId = sdtb.service_id;
                                        pStation[stationi].name = malloc( strlen(desc.service_name) + 1 );
                                        pStation[stationi].ontv = malloc( strlen(sid) + 1 );
                                        pStation[stationi].tsId = sdth.transport_stream_id;
                                        pStation[stationi].onId = sdth.original_network_id;
                                        pStation[stationi].svId = sdtb.service_id;
-                                       memset(pStation[stationi].logo_array, 0, sizeof(pStation[stationi].logo_array));
 
                                        strcpy(pStation[stationi].name, desc.service_name);
                                        strcpy(pStation[stationi].ontv, sid);
 
                                        strcpy(pStation[stationi].name, desc.service_name);
                                        strcpy(pStation[stationi].ontv, sid);
index f6b877a..786dc37 100755 (executable)
@@ -71,6 +71,7 @@ typedef struct _TAG_STATION
        int             onId;           // TransportStreamID
        int             svId;           // ServiceID
        unsigned int    logo_download_data_id;
        int             onId;           // TransportStreamID
        int             svId;           // ServiceID
        unsigned int    logo_download_data_id;
+       unsigned int    logo_version;
        LOGO    logo_array[6];
 } STATION;
 
        LOGO    logo_array[6];
 } STATION;
 
index f85021f..a091c23 100755 (executable)
@@ -96,9 +96,6 @@ void* allocCopy(void* src, int *boff, size_t size) {
        return mem;
 }
 
        return mem;
 }
 
-//#define BCD(n) ((n/100)<<8)|(((n%100)/10)<<4)|(n%10)
-#define BCD(n) ((n>>4)*10+(n&0xf))
-
 time_t parseMJD( unsigned char *data ) {
        int tnum, year, mon, mday;
        struct tm MJD;
 time_t parseMJD( unsigned char *data ) {
        int tnum, year, mon, mday;
        struct tm MJD;
index a2cff51..1b782f8 100755 (executable)
@@ -4,6 +4,8 @@
 #define MAXSECLEN 4096
 
 #include <time.h>
 #define MAXSECLEN 4096
 
 #include <time.h>
+//#define BCD(n) ((n/100)<<8)|(((n%100)/10)<<4)|(n%10)
+#define BCD(n) ((n>>4)*10+(n&0xf))
 
 #ifdef __cplusplus
 extern "C"{
 
 #ifdef __cplusplus
 extern "C"{