--- multiplexer/en300468ts.c 2010/09/29 21:39:52 1.24 +++ multiplexer/en300468ts.c 2010/09/29 21:41:40 1.25 @@ -68,8 +68,6 @@ static struct { #define TABLEID_FIRST 0x40 #define TABLEID_LAST 0x7F -static unsigned char nextversion[TABLEID_LAST-TABLEID_FIRST+1]; - #define TS_PACKET_SIZE 188 #define TS_HEADSLEN 3 #define TS_PACKET_HEADSIZE 4 @@ -242,6 +240,7 @@ struct sitab { static struct sitab *newtab = NULL; static struct sitab *runtab = NULL; +static struct sitab *oldtab = NULL; #define SYNTAX_END 0 #define SYNTAX_LOOPEND 1 @@ -1564,6 +1563,26 @@ static enum enumsi alloctab(long pid, lo return e; } +static unsigned char nextversion(struct sitab *nt) +{ + struct sitab **pst; + struct sitab *st; + pst = &oldtab; + while ((st = *pst)) { + if ((st->pid == nt->pid) && (st->tableid == nt->tableid) + && (st->tableid_ext == nt->tableid_ext)) { + unsigned char v = st->version + 1; + *pst = st->next; + free(st->tab); + free(st); + return v; + } else { + pst = &st->next; + } + } + return 0; +} + static void droptab(long pid, long tableid, long tableid_ext) { struct sitab **pst; @@ -1573,9 +1592,8 @@ static void droptab(long pid, long table if ((st->pid == pid) && (st->tableid == tableid) && ((tableid_ext < 0) || (st->tableid_ext == tableid_ext))) { *pst = st->next; - nextversion[st->tableid - TABLEID_FIRST] = (st->version + 1) & 0x1F; - free(st->tab); - free(st); + st->next = oldtab; + oldtab = st; } else { pst = &st->next; } @@ -2153,9 +2171,8 @@ static void argloop(int f0) gentab(st, &tv); if (st->freqmsec <= 0) { *pst = st->next; - nextversion[st->tableid - TABLEID_FIRST] = (st->version + 1) & 0x1F; - free(st->tab); - free(st); + st->next = oldtab; + oldtab = st; } else { pst = &st->next; } @@ -2208,7 +2225,7 @@ static void argloop(int f0) newtab->tableid_ext = newtab->tab[0]; } droptab(newtab->pid, newtab->tableid, newtab->tableid_ext); - newtab->version = nextversion[newtab->tableid - TABLEID_FIRST]; + newtab->version = nextversion(newtab); newtab->soon = tv; newtab->next = runtab; runtab = newtab; @@ -2264,7 +2281,6 @@ int main(int argc, char *argv[]) system_init(); unblockf(STDIN_FILENO); unblockf(STDOUT_FILENO); - memset(&nextversion[0], 0, sizeof(nextversion)); memset(&perpid[0], 0, sizeof(perpid)); a = 1; do {