OSDN Git Service

add bit parser
[rec10/rec10-git.git] / epgdump / epgdump.c
index e4dd11e..0c0141b 100755 (executable)
@@ -34,23 +34,17 @@ static  CONTENT_TYPE        ContentCatList[CAT_COUNT] = {
        { "ドキュメンタリー・教養", "documentary" },
        { "演劇", "stage" },
        { "趣味・実用", "hobby" },
-       { "福祉", "etc" },                    //福祉
-       { "予備", "etc" }, //予備
-       { "予備", "etc" }, //予備
-       { "予備", "etc" }, //予備
-       { "その他", "etc" } //その他
+       { "福祉", "welfare" },
+       { "予備", "etc" },
+       { "予備", "etc" },
+       { "予備", "etc" },
+       { "その他", "etc" }
 };
 
 
 SVT_CONTROL    *svttop = NULL;
 DSM_CONTROL    dsmctl[1024];
 #define                SECCOUNT        64
-char   title[1024];
-char   subtitle[1024];
-char   desc[102400] = {0};
-char   Category[1024];
-char   ServiceName[1024];
-char   Logo[8192];
 static unsigned char *base64 = (unsigned char *)"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 
 static void base64_char(unsigned long bb, int srclen, unsigned char *dest, int j)
@@ -114,7 +108,7 @@ void        xmlspecialchars(char *str)
 
 
 void   GetSDT(FILE *infile, SVT_CONTROL *svttop, SECcache *secs, 
-       int count, STATION **station, int * station_count, char *header, int is_bs_cs_logo)
+       int count, STATION **station, int * station_count, char *header, int is_logo)
 {
        SECcache  *bsecs;
        int pmtpids[SECCOUNT];
@@ -136,11 +130,15 @@ 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);
                }
-               else if ( is_bs_cs_logo ) {
+               else if ( is_logo ) {
                        /* PAT */
                        if((bsecs->pid & 0xFF) == 0x00) {
                                dumpPAT(bsecs->buf, secs, count, pmtpids);
@@ -182,6 +180,13 @@ void       GetEIT(FILE *infile, FILE *outfile, STATION *psta, SECcache *secs)
        char    cendtime[32];
        char    cstarttime[32];
 
+       char    title[1024];
+       char    subtitle[1024];
+       char    desc[102400] = {0};
+       char    Category[1024];
+       char    VideoType[1024];
+       char    AudioType[1024];
+
        memset(secs, 0,  sizeof(SECcache) * SECCOUNT);
        secs[0].pid = 0x12; /* EIT  */
        secs[1].pid = 0x26; /* EIT  */
@@ -227,6 +232,14 @@ void       GetEIT(FILE *infile, FILE *outfile, STATION *psta, SECcache *secs)
                strcpy(Category, ContentCatList[eitcur->content_type].japanese);
                xmlspecialchars(Category);
 
+               memset(VideoType, '\0', sizeof(VideoType));
+               strcpy(VideoType, parseComponentDescType(eitcur->video_type));
+               xmlspecialchars(VideoType);
+
+               memset(AudioType, '\0', sizeof(AudioType));
+               strcpy(AudioType, parseAudioComponentDescType(eitcur->audio_type));
+               xmlspecialchars(AudioType);
+
                tl.tm_sec = eitcur->ss ;
                tl.tm_min = eitcur->hm ;
                tl.tm_hour = eitcur->hh ;
@@ -249,12 +262,15 @@ void      GetEIT(FILE *infile, FILE *outfile, STATION *psta, SECcache *secs)
                memset(cstarttime, '\0', sizeof(cstarttime));
                strftime(cendtime, (sizeof(cendtime) - 1), "%Y%m%d%H%M%S", endtl);
                strftime(cstarttime, (sizeof(cstarttime) - 1), "%Y%m%d%H%M%S", &tl);
+
                fprintf(outfile, "  <programme start=\"%s +0900\" stop=\"%s +0900\" channel=\"%s\" event=\"%d\">\n",    
                                cstarttime, cendtime, psta->ontv, eitcur->event_id);
                fprintf(outfile, "    <title lang=\"ja_JP\">%s</title>\n", title);
                fprintf(outfile, "    <desc lang=\"ja_JP\">%s</desc>\n", subtitle);
                fprintf(outfile, "    <longdesc lang=\"ja_JP\">%s</longdesc>\n", desc);
                fprintf(outfile, "    <category lang=\"ja_JP\">%s</category>\n", Category);
+               fprintf(outfile, "    <video type=\"%d\">%s</video>\n", eitcur->video_type, VideoType);
+               fprintf(outfile, "    <audio type=\"%d\" multi=\"%d\">%s</audio>\n", eitcur->audio_type, eitcur->multi_type, AudioType);
                //fprintf(outfile, "    <category lang=\"en\">%s</category>\n", ContentCatList[eitcur->content_type].english);
                fprintf(outfile, "  </programme>\n");
 #if 0
@@ -329,20 +345,20 @@ int main(int argc, char *argv[])
        STATION *pStas ;
        int             act = 0;
        int             i , j, k ;
-       int             is_bs_cs_logo = 0;
+       int             is_logo = 0;
        SDTTdata  sdtd;
        SDTTdataLoop *loop;
        SDTTdataService *service;
 
-       /* 興味のあるpidを指定 */
-       memset(secs, 0,  sizeof(SECcache) * SECCOUNT);
-       secs[0].pid = 0x00; /* PAT  */
-       secs[1].pid = 0x11; /* SDT  */
-       secs[2].pid = 0x23; /* SDTT */
-       secs[3].pid = 0x29; /* CDT  */
-
        memset(dsmctl, 0,  sizeof(dsmctl));
 
+       if(argc == 5 && strcmp(argv[1], "/LOGO") == 0){
+               argc--;
+               argv[1] = argv[2];
+               argv[2] = argv[3];
+               argv[3] = argv[4];
+               is_logo = 1;
+       }
        if(argc == 4){
                arg_onTV = argv[1];
                if(strcmp(argv[2], "-")) {
@@ -368,9 +384,10 @@ int main(int argc, char *argv[])
                        outfile = stdout;
                }
        }else{
-               fprintf(stdout, "Usage : %s {/BS|/CS} <tsFile> <xmlFile>\n", argv[0]);
-               fprintf(stdout, "Usage : %s <id> <tsFile> <xmlFile>\n", argv[0]);
+               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");
@@ -394,6 +411,24 @@ int main(int argc, char *argv[])
        svttop = calloc(1, sizeof(SVT_CONTROL));
        act = 0 ;
 
+       /* 興味のあるpidを指定 */
+       if ( is_logo ) {
+               memset(secs, 0,  sizeof(SECcache) * SECCOUNT);
+               secs[0].pid = 0x00; /* PAT  */
+               secs[1].pid = 0x11; /* SDT  */
+               secs[2].pid = 0x29; /* CDT  */
+       }
+       else {
+               memset(secs, 0,  sizeof(SECcache) * SECCOUNT);
+               secs[0].pid = 0x00; /* PAT  */
+               secs[1].pid = 0x11; /* SDT  */
+               secs[2].pid = 0x12; /* EIT  */
+               secs[3].pid = 0x23; /* SDTT */
+               secs[4].pid = 0x26; /* EIT  */
+               secs[5].pid = 0x27; /* EIT  */
+               secs[6].pid = 0x29; /* CDT  */
+       }
+
        if(strcmp(arg_onTV, "/TIME") == 0){
                printf("TSに載っている時刻データは2秒ほど早めてあるのかもしれません。\n");
                memset(secs, 0,  sizeof(SECcache) * SECCOUNT);
@@ -404,14 +439,14 @@ int main(int argc, char *argv[])
                goto cleanup;
        }else if(strcmp(arg_onTV, "/BS") == 0){
                char *head = "BS";
-               GetSDT(infile, svttop, secs, SECCOUNT, &pStas, &staCount, head, 0);
+               GetSDT(infile, svttop, secs, SECCOUNT, &pStas, &staCount, head, is_logo);
        }else if(strcmp(arg_onTV, "/CS") == 0){
                char *head = "CS";
-               GetSDT(infile, svttop, secs, SECCOUNT, &pStas, &staCount, head, 0);
-       }else if(strcmp(arg_onTV, "/BSCSLOGO") == 0){
-               is_bs_cs_logo = 1;
-               GetSDT(infile, svttop, secs, SECCOUNT, &pStas, &staCount, "", 1);
+               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) 
@@ -445,63 +480,80 @@ int main(int argc, char *argv[])
        fprintf(outfile, "<!DOCTYPE tv SYSTEM \"xmltv.dtd\">\n\n");
        fprintf(outfile, "<tv generator-info-name=\"tsEPG2xml\" generator-info-url=\"http://localhost/\">\n");
 
-       for ( i = 0; i < 1024; i++) {
-               if ( dsmctl[i].isUsed == 0 ) break;
-               parseSDTTdata(dsmctl[i].blockData, &sdtd);
-
-               for (j = 0; j < sdtd.number_of_loop; j++) {
-                       loop = sdtd.loop + sizeof(SDTTdataLoop) * j;
-
-                       for ( k = 0; k < loop->number_of_services; k++) {
-                               service = loop->services + sizeof(SDTTdataService) * k;
-
-                               /*
-                               for(lp = 0 ; lp < staCount ; lp++){
-                                       if ( 
-                                               pStas[lp].tsId == service->transport_stream_id && 
-                                               pStas[lp].onId == service->original_network_id && 
-                                               pStas[lp].svId == service->service_id
-                                       ) {
-                                               clt2png(loop->data, 
-                                                       &pStas[lp].logo_array[sdtd.logo_type].logo, 
-                                                       &pStas[lp].logo_array[sdtd.logo_type].logo_size);
-                                       }
+       char    ServiceName[1024];
+       char    Logo[8192];
+
+       if ( is_logo ) {
+               memset(Logo, '\0', sizeof(Logo));
+               for(lp = 0 ; lp < staCount ; lp++){
+                       for ( i = 0 ; i < 6 ; i++) {
+                               if (pStas[lp].logo_array[i].logo) {
+                                       base64_encode(Logo, pStas[lp].logo_array[i].logo, pStas[lp].logo_array[i].logo_size);
+                                       xmlspecialchars(Logo);
+                                       fprintf(outfile, "    <logo ts=\"%d\" on=\"%d\" sv=\"%d\" type=\"%d\">%s</logo>\n", 
+                                               pStas[lp].tsId, 
+                                               pStas[lp].onId, 
+                                               pStas[lp].svId, 
+                                               i, 
+                                               Logo);
                                }
-                               */
-
-                               #if 0
-                               printf( "SDTTdataLoop (%d:%d) %d:%d[%d:%d:%d]%d\n", 
-                                       i, j, 
-                                       sdtd.logo_type, 
-                                       loop->logo_id, 
-                                       service->transport_stream_id, 
-                                       service->original_network_id, 
-                                       service->service_id, 
-                                       loop->data_size
-                               );
-                               #endif
-
-                               if ( is_bs_cs_logo ) {
-                                       fprintf(outfile, "  <logo ts=\"%d\" on=\"%d\" sv=\"%d\" type=\"%d\">%d</logo>\n", 
+                       }
+               }
+
+               for ( i = 0; i < 1024; i++) {
+                       if ( dsmctl[i].isUsed == 0 ) break;
+                       parseSDTTdata(dsmctl[i].blockData, &sdtd);
+
+                       for (j = 0; j < sdtd.number_of_loop; j++) {
+                               loop = sdtd.loop + sizeof(SDTTdataLoop) * j;
+
+                               for ( k = 0; k < loop->number_of_services; k++) {
+                                       service = loop->services + sizeof(SDTTdataService) * k;
+
+                                       /*
+                                       for(lp = 0 ; lp < staCount ; lp++){
+                                               if ( 
+                                                       pStas[lp].tsId == service->transport_stream_id && 
+                                                       pStas[lp].onId == service->original_network_id && 
+                                                       pStas[lp].svId == service->service_id
+                                               ) {
+                                                       clt2png(loop->data, 
+                                                               &pStas[lp].logo_array[sdtd.logo_type].logo, 
+                                                               &pStas[lp].logo_array[sdtd.logo_type].logo_size);
+                                               }
+                                       }
+                                       */
+
+                                       #if 0
+                                       printf( "SDTTdataLoop (%d:%d) %d:%d[%d:%d:%d]%d\n", 
+                                               i, j, 
+                                               sdtd.logo_type, 
+                                               loop->logo_id, 
+                                               service->transport_stream_id, 
+                                               service->original_network_id, 
+                                               service->service_id, 
+                                               loop->data_size
+                                       );
+                                       #endif
+
+                               
+                                       void* logo = NULL;
+                                       int logo_size = 0;
+
+                                       clt2png(loop->data, &logo, &logo_size);
+                                       memset(Logo, '\0', sizeof(Logo));
+                                       base64_encode(Logo, logo, logo_size);
+                                       xmlspecialchars(Logo);
+
+                                       fprintf(outfile, "  <logo ts=\"%d\" on=\"%d\" sv=\"%d\" type=\"%d\" dlid=\"%d\">%s</logo>\n", 
                                                service->transport_stream_id, 
                                                service->original_network_id, 
                                                service->service_id, 
                                                sdtd.logo_type, 
-                                               loop->logo_id);
+                                               loop->logo_id, 
+                                               Logo);
                                }
-                       }
 
-                       if ( is_bs_cs_logo ) {
-                               void* logo = NULL;
-                               int logo_size = 0;
-
-                               clt2png(loop->data, &logo, &logo_size);
-                               memset(Logo, '\0', sizeof(Logo));
-                               base64_encode(Logo, logo, logo_size);
-                               xmlspecialchars(Logo);
-                               fprintf(outfile, "  <logodata id=\"%d\">%s</logodata>\n", 
-                                       loop->logo_id, 
-                                       Logo);
                        }
                }
        }
@@ -514,18 +566,9 @@ int main(int argc, char *argv[])
                fprintf(outfile, "    <display-name lang=\"ja_JP\">%s</display-name>\n", ServiceName);
                fprintf(outfile, "    <id ts=\"%d\" on=\"%d\" sv=\"%d\"/>\n", pStas[lp].tsId, pStas[lp].onId, pStas[lp].svId);
 
-               memset(Logo, '\0', sizeof(Logo));
-               for ( i = 0 ; i < 6 ; i++) {
-                       if (pStas[lp].logo_array[i].logo) {
-                               base64_encode(Logo, pStas[lp].logo_array[i].logo, pStas[lp].logo_array[i].logo_size);
-                               xmlspecialchars(Logo);
-                               fprintf(outfile, "    <logo type=\"%02d\">%s</logo>\n", i, Logo);
-                       }
-               }
-
                fprintf(outfile, "  </channel>\n");
        }
-       if ( is_bs_cs_logo ) {
+       if ( is_logo ) {
                fprintf(outfile, "</tv>\n");
                goto cleanup;
        }