version 1.20, 2010/09/29 21:36:23
|
version 1.21, 2010/09/29 21:37:12
|
Line 57 static int ipfd;
|
Line 57 static int ipfd;
|
#define TABBUF_SIZE (1<<15) |
#define TABBUF_SIZE (1<<15) |
#define MAX_PSI_SIZE (4096+1) |
#define MAX_PSI_SIZE (4096+1) |
|
|
static unsigned int tabin[TABLE_PID_LAST-TABLE_PID_FIRST+1]; |
static struct { |
static unsigned int tabinold[TABLE_PID_LAST-TABLE_PID_FIRST+1]; |
unsigned char *tabbuf; |
static unsigned int tabout[TABLE_PID_LAST-TABLE_PID_FIRST+1]; |
unsigned int tabin; |
static unsigned char conticnt[TABLE_PID_LAST-TABLE_PID_FIRST+1]; |
unsigned int tabout; |
static unsigned char *tabbuf[TABLE_PID_LAST-TABLE_PID_FIRST+1]; |
unsigned char tabinold; |
|
unsigned char conticnt; |
|
} perpid[TABLE_PID_LAST-TABLE_PID_FIRST+1]; |
|
|
#define TABLEID_FIRST 0x40 |
#define TABLEID_FIRST 0x40 |
#define TABLEID_LAST 0x7F |
#define TABLEID_LAST 0x7F |
Line 1469 static void gentab(struct sitab *st, str
|
Line 1471 static void gentab(struct sitab *st, str
|
unsigned char *b; |
unsigned char *b; |
memset(&descrcnt[0], 0, sizeof(descrcnt)); |
memset(&descrcnt[0], 0, sizeof(descrcnt)); |
i = st->pid - TABLE_PID_FIRST; |
i = st->pid - TABLE_PID_FIRST; |
b = &tabbuf[i][tabin[i]]; |
b = &perpid[i].tabbuf[perpid[i].tabin]; |
*b++ = st->pid >> 8; |
*b++ = st->pid >> 8; |
*b++ = st->pid; |
*b++ = st->pid; |
switch (st->esi) { |
switch (st->esi) { |
Line 1486 static void gentab(struct sitab *st, str
|
Line 1488 static void gentab(struct sitab *st, str
|
fprintf(stderr, "internal error (gentab, %d)\n", st->esi); |
fprintf(stderr, "internal error (gentab, %d)\n", st->esi); |
exit(1); |
exit(1); |
} |
} |
tabin[i] += l+2; |
perpid[i].tabin += l+2; |
} |
} |
|
|
static enum enumsi alloctab(long pid, long tid) |
static enum enumsi alloctab(long pid, long tid) |
Line 2027 static void argloop(int f0)
|
Line 2029 static void argloop(int f0)
|
} |
} |
i = 0; |
i = 0; |
while (tmo != 0 && i <= TABLE_PID_LAST-TABLE_PID_FIRST) { |
while (tmo != 0 && i <= TABLE_PID_LAST-TABLE_PID_FIRST) { |
if ((tabin[i] > tabout[i]) |
if ((perpid[i].tabin > perpid[i].tabout) |
&& (r >= (((((tabbuf[i][tabout[i]+3] & 0x0F) << 8) |
&& (r >= (((((perpid[i].tabbuf[perpid[i].tabout+3] & 0x0F) << 8) |
+ tabbuf[i][tabout[i]+4] + TS_HEADSLEN + TS_PFIELDLEN |
+ perpid[i].tabbuf[perpid[i].tabout+4] + TS_HEADSLEN |
+ TS_PACKET_SIZE - TS_PACKET_HEADSIZE) |
+ TS_PFIELDLEN + TS_PACKET_SIZE - TS_PACKET_HEADSIZE) |
* 131) / 128))) { |
* 131) / 128))) { |
tmo = 0; |
tmo = 0; |
#ifdef DEBUG |
#ifdef DEBUG |
{ |
{ |
int x; |
int x; |
fprintf(stderr, "tabbuf[%d..%d-1]:\n", tabout[i], tabin[i]); |
fprintf(stderr, "tabbuf[%d..%d-1]:\n", |
for (x = tabout[i]; x < tabin[i]; x++) { |
perpid[i].tabout, perpid[i].tabin); |
fprintf(stderr, "%02x ", tabbuf[i][x]); |
for (x = perpid[i].tabout; x < perpid[i].tabin; x++) { |
|
fprintf(stderr, "%02x ", perpid[i].tabbuf[x]); |
} |
} |
fprintf(stderr, "\n"); |
fprintf(stderr, "\n"); |
} |
} |
Line 2054 static void argloop(int f0)
|
Line 2057 static void argloop(int f0)
|
fprintf(stderr, "internal error (pid)\n"); |
fprintf(stderr, "internal error (pid)\n"); |
exit(1); |
exit(1); |
} |
} |
tabinold[i] = tabin[i]; |
perpid[i].tabinold = perpid[i].tabin ? 1 : 0; |
if (tmo != 0) { |
if (tmo != 0) { |
if (tabin[i] == 0) { |
if (perpid[i].tabin == 0) { |
i = (st->soon.tv_sec - tv.tv_sec) * 1000 |
i = (st->soon.tv_sec - tv.tv_sec) * 1000 |
+ (st->soon.tv_usec - tv.tv_usec) / 1000; |
+ (st->soon.tv_usec - tv.tv_usec) / 1000; |
if (i <= 0) { |
if (i <= 0) { |
Line 2071 static void argloop(int f0)
|
Line 2074 static void argloop(int f0)
|
n = pollfd_poll(tmo); |
n = pollfd_poll(tmo); |
gettimeofday(&tv, NULL); |
gettimeofday(&tv, NULL); |
for (i = 0; i <= TABLE_PID_LAST-TABLE_PID_FIRST; i++) { |
for (i = 0; i <= TABLE_PID_LAST-TABLE_PID_FIRST; i++) { |
while ((tabin[i] > tabout[i]) |
while ((perpid[i].tabin > perpid[i].tabout) |
&& (r >= (((((tabbuf[i][tabout[i]+3] & 0x0F) << 8) |
&& (r >= (((((perpid[i].tabbuf[perpid[i].tabout+3] & 0x0F) << 8) |
+ tabbuf[i][tabout[i]+4] + TS_HEADSLEN + TS_PFIELDLEN |
+ perpid[i].tabbuf[perpid[i].tabout+4] + TS_HEADSLEN |
+ TS_PACKET_SIZE - TS_PACKET_HEADSIZE) |
+ TS_PFIELDLEN + TS_PACKET_SIZE - TS_PACKET_HEADSIZE) |
* 131) / 128))) { |
* 131) / 128))) { |
tabout[i] += tab2ts(&tabbuf[i][tabout[i]], &conticnt[i]); |
perpid[i].tabout += |
|
tab2ts(&perpid[i].tabbuf[perpid[i].tabout], &perpid[i].conticnt); |
r = outout - outin; |
r = outout - outin; |
if (r < 0) { |
if (r < 0) { |
r += OUTBUF_SIZE; |
r += OUTBUF_SIZE; |
} |
} |
} |
} |
if (tabin[i] <= tabout[i]) { |
if (perpid[i].tabin <= perpid[i].tabout) { |
tabin[i] = tabout[i] = 0; |
perpid[i].tabin = perpid[i].tabout = 0; |
} |
} |
} |
} |
if ((n > 0) && (n1 >= 0) && (r = pollfd_rev(n1))) { |
if ((n > 0) && (n1 >= 0) && (r = pollfd_rev(n1))) { |
Line 2111 static void argloop(int f0)
|
Line 2115 static void argloop(int f0)
|
pst = &runtab; |
pst = &runtab; |
while ((st = *pst) != NULL) { |
while ((st = *pst) != NULL) { |
i = st->pid - TABLE_PID_FIRST; |
i = st->pid - TABLE_PID_FIRST; |
if ((tabinold[i] == 0) |
if ((perpid[i].tabinold == 0) |
&& (tabin[i] < (TABBUF_SIZE-MAX_PSI_SIZE+1-2)) |
&& (perpid[i].tabin < (TABBUF_SIZE-MAX_PSI_SIZE+1-2)) |
&& ((st->soon.tv_sec < tv.tv_sec) |
&& ((st->soon.tv_sec < tv.tv_sec) |
|| ((st->soon.tv_sec == tv.tv_sec) |
|| ((st->soon.tv_sec == tv.tv_sec) |
&& (st->soon.tv_usec <= tv.tv_usec)))) { |
&& (st->soon.tv_usec <= tv.tv_usec)))) { |
Line 2181 static void argloop(int f0)
|
Line 2185 static void argloop(int f0)
|
fprintf(stderr, "\n"); |
fprintf(stderr, "\n"); |
#endif |
#endif |
i = newtab->pid - TABLE_PID_FIRST; |
i = newtab->pid - TABLE_PID_FIRST; |
if ((tabbuf[i] == NULL) |
if ((perpid[i].tabbuf == NULL) |
&& ((tabbuf[i] = malloc(TABBUF_SIZE)) == NULL)) { |
&& ((perpid[i].tabbuf = malloc(TABBUF_SIZE)) == NULL)) { |
fprintf(stderr, "malloc failed for table buffer pid=%02lx\n", |
fprintf(stderr, "malloc failed for table buffer pid=%02lx\n", |
newtab->pid); |
newtab->pid); |
free(newtab->tab); |
free(newtab->tab); |
Line 2245 int main(int argc, char *argv[])
|
Line 2249 int main(int argc, char *argv[])
|
system_init(); |
system_init(); |
unblockf(STDIN_FILENO); |
unblockf(STDIN_FILENO); |
unblockf(STDOUT_FILENO); |
unblockf(STDOUT_FILENO); |
memset(&tabin[0], 0, sizeof(tabin)); |
|
memset(&tabout[0], 0, sizeof(tabout)); |
|
memset(&conticnt[0], 0, sizeof(conticnt)); |
|
memset(&nextversion[0], 0, sizeof(nextversion)); |
memset(&nextversion[0], 0, sizeof(nextversion)); |
for (a = TABLE_PID_LAST-TABLE_PID_FIRST; a >= 0; a--) { |
memset(&perpid[0], 0, sizeof(perpid)); |
tabbuf[a] = NULL; |
|
} |
|
a = 1; |
a = 1; |
do { |
do { |
if ((a < argc) && (strcmp(argv[a], "-"))) { |
if ((a < argc) && (strcmp(argv[a], "-"))) { |