--- multiplexer/splice.c 2001/08/01 08:23:18 1.6 +++ multiplexer/splice.c 2001/08/02 14:51:22 1.7 @@ -23,15 +23,19 @@ t_msec next_psi_periodic; t_msec psi_frequency_msec; boolean psi_frequency_changed; -boolean configuration_on; +int configuration_on; boolean configuration_changed; +boolean configuration_descr_changed; const char *configuration_total = "Conf: progs: %d\n"; +static modifydescr_descr *globalmodifydescr; + boolean splice_init (void) { psi_frequency_msec = 0; psi_frequency_changed = FALSE; - configuration_on = FALSE; + configuration_on = 0; + globalmodifydescr = NULL; return (splice_specific_init ()); } @@ -213,6 +217,35 @@ stream_descr *splice_findpcrstream (prog return (NULL); } +/* Print configuration of descriptors + * Precondition: manud!=NULL + */ +static void splice_descr_configuration (descr_descr *manud, + descr_descr *autod) +{ + int i, l; + byte *y; + i = NUMBER_DESCR; + while (--i >= 0) { + y = manud->refx[i]; + if (y == NULL) { + if (autod != NULL) { + y = autod->refx[i]; + } + } else if (y[1] == 0) { + y = NULL; + } + if (y != NULL) { + l = y[1]; + fprintf (stderr, "Conf: descr:%02X len:%d data:", *y++, l); + while (--l >= 0) { + fprintf (stderr, "%02X", *++y); + } + fprintf (stderr, "\n"); + } + } +} + /* Print configuration for one program * Precondition: p!=NULL */ @@ -233,6 +266,9 @@ void splice_one_configuration (prog_desc fprintf (stderr, " (%d)", s); } fprintf (stderr, "\n"); + if (configuration_on > 1) { + splice_descr_configuration (&p->manudescr, NULL); /* Missing auto descr! */ + } while (--i >= 0) { stream_descr *s; s = p->stream[i]; @@ -240,18 +276,256 @@ void splice_one_configuration (prog_desc "file:%d source:%04hX num:%2d name:%s\n", s->u.d.pid, s->stream_type, s->stream_id, s->fdescr->content, s->sourceid, s->fdescr->filerefnum, s->fdescr->name); + if (configuration_on > 1) { + splice_descr_configuration (s->manudescr, s->autodescr); + } } st = p->stump; while (st != NULL) { fprintf (stderr, "Conf: stream:%04hX type:%02X\n", st->pid, st->stream_type); + if (configuration_on > 1) { + splice_descr_configuration (&st->manudescr, NULL); + } st = st->next; } } -void splice_set_configuration (boolean on) +void splice_set_configuration (int on) { configuration_on = on; configuration_changed = TRUE; } +static void splice_modifydescriptor (descr_descr *md, + int dtag, + int dlength, + byte *data, + stream_descr *s) +{ + int i, j; + byte *t, *u; + if (dtag < 0) { + clear_descrdescr (md); + } else { + t = md->refx[dtag]; + if ((dlength < 0) + || ((t != NULL) + && (t != &md->null[0]))) { + j = t[1]+2; + i = NUMBER_DESCR; + while (--i >= 0) { + if ((md->refx[i]-t) > 0) { + md->refx[i] -= j; + } + } + memmove (t,&t[j],sizeof(md->data)-(j+(t-&md->data[0]))); + } + if (dlength == 0) { + t = &md->null[0]; + } else if (dlength < 0) { + t = NULL; + } else { + i = NUMBER_DESCR; + t = &md->data[0]; + while (--i >= 0) { + u = md->refx[i]; + if (u != NULL) { + u = &u[u[1]+2]; + if ((u-t) > 0) { + t = u; + } + } + } + if (t-&md->data[0] < 0) { + warn (LERR,"No space left",ESPC,5,2,t-&md->data[0]); + return; + } + if ((t-&md->data[0]+dlength+2-MAX_PSI_SIZE) > 0) { + warn (LWAR,"No space left",ESPC,5,1,t-&md->data[0]); + return; + } + t[0] = dtag; + t[1] = dlength; + memcpy (&t[2],data,dlength); + } + md->refx[dtag] = t; + } + if (s != NULL) { + i = s->u.d.progs; + while (--i >= 0) { + s->u.d.pdescr[i]->changed = TRUE; + } + } +} + +static void splice_modifydescrlater (int programnb, + short sid, + short pid, + int dtag, + int dlength, + byte *data) +{ + modifydescr_descr *l; + modifydescr_descr **pl; + pl = &globalmodifydescr; + l = *pl; + while (l != NULL) { + if ((programnb < 0) /* delete older matching entries */ + || ((programnb == l->programnb) + && ((pid == 0) + || ((pid == l->pid) + && (sid == l->sid) + && ((dtag < 0) + || (dtag == l->dtag)))))) { + *pl = l->next; + free (l); + } else { + pl = &l->next; + } + l = *pl; + } + if ((dtag >= 0) + && (dlength >= 0)) { /* don't save modifiers, that delete */ + if ((l = malloc (sizeof(modifydescr_descr))) != NULL) { + l->next = NULL; + l->programnb = programnb; + l->sid = sid; + l->pid = pid; + l->dtag = dtag; + l->dlength = dlength; + if (dlength > 0) { + memcpy (&l->data[0],data,dlength); + } + *pl = l; /* append at end of list */ + } else { + warn (LERR,"Malloc fail",ETSC,12,1,programnb); + } + } +} + +/* For a new program and maybe stream or stump, + * check presence of applicable descriptors, that have been stored. + * All non-NULL parameters must be completely linked into p upon call! + * Precondition: p != NULL + */ +void splice_modifycheckmatch (int programnb, + prog_descr *p, + stream_descr *s, + stump_descr *st) +{ + modifydescr_descr *l; + modifydescr_descr **pl; + pl = &globalmodifydescr; + l = *pl; + while (l != NULL) { + if ((programnb == l->programnb) + && (((l->sid < 0) + && (l->pid < 0)) + || ((l->pid > 0) + && (((s != NULL) + && (l->pid == s->u.d.pid)) + || ((st != NULL) + && (l->pid = st->pid)))) + || ((l->sid >= 0) + && (s != NULL) + && (l->sid == s->stream_id)))) { + splice_modifytargetdescrprog (p,programnb, + l->sid,l->pid,l->dtag,l->dlength,&l->data[0],st); + *pl = l->next; + free (l); + } else { + pl = &l->next; + } + l = *pl; + } +} + +/* Modify an entry in a manudescr struct. + */ +void splice_modifytargetdescrprog (prog_descr *p, + int programnb, + short sid, + short pid, + int dtag, + int dlength, + byte *data, + stump_descr *globstump) +{ + int i; + stream_descr *s; + stump_descr *st; + if (sid >= 0) { + if (p != NULL) { + i = p->streams; + while (--i >= 0) { + s = p->stream[i]; + if (s->stream_id == sid) { + splice_modifydescriptor (s->manudescr,dtag,dlength,data,s); + configuration_descr_changed = TRUE; + return; + } + } + } + splice_modifydescrlater (programnb,sid,pid,dtag,dlength,data); + } else { + if (pid > 0) { + if (p != NULL) { + i = p->streams; + while (--i >= 0) { + s = p->stream[i]; + if (s->u.d.pid == pid) { + splice_modifydescriptor (s->manudescr,dtag,dlength,data,s); + configuration_descr_changed = TRUE; + return; + } + } + st = p->stump; + } else { + st = globstump; + } + while (st != NULL) { + if ((st->pid == pid) + && (st->program_number == programnb)) { + splice_modifydescriptor (&st->manudescr,dtag,dlength,data,NULL); + if (p != NULL) { + p->changed = TRUE; + } + configuration_descr_changed = TRUE; + return; + } + st = st->next; + } + splice_modifydescrlater (programnb,sid,pid,dtag,dlength,data); + } else if (pid < 0) { + if (p != NULL) { + splice_modifydescriptor (&p->manudescr,dtag,dlength,data,NULL); + p->changed = TRUE; + configuration_descr_changed = TRUE; + } else { + splice_modifydescrlater (programnb,sid,pid,dtag,dlength,data); + } + } else { + if (p != NULL) { + i = p->streams; + while (--i >= 0) { + s = p->stream[i]; + splice_modifydescriptor (s->manudescr,dtag,dlength,data,s); + } + splice_modifydescriptor (&p->manudescr,dtag,dlength,data,NULL); + configuration_descr_changed = TRUE; + st = p->stump; + } else { + st = globstump; + } + while (st != NULL) { + if (st->program_number == programnb) { + splice_modifydescriptor (&st->manudescr,dtag,dlength,data,NULL); + } + st = st->next; + } + splice_modifydescrlater (programnb,sid,pid,dtag,dlength,data); + } + } +} +