Diff for /multiplexer/splicets.c between versions 1.12 and 1.13

version 1.12, 2001/07/19 09:52:34 version 1.13, 2001/08/01 08:23:18
Line 52  static prog_descr *prog [MAX_OUTPROG]; Line 52  static prog_descr *prog [MAX_OUTPROG];
 static int nextpid;  static int nextpid;
 static stream_descr *outs [MAX_STRPERTS];  static stream_descr *outs [MAX_STRPERTS];
   
   static stump_descr *globalstumps;
   
 boolean splice_specific_init (void)  boolean splice_specific_init (void)
 {  {
   progs = 0;    progs = 0;
Line 64  boolean splice_specific_init (void) Line 66  boolean splice_specific_init (void)
   psi_size = psi_done = 0;    psi_size = psi_done = 0;
   unit_start = TS_UNIT_START;    unit_start = TS_UNIT_START;
   transportstreamid = 0x4227;    transportstreamid = 0x4227;
     globalstumps = NULL;
   return (TRUE);    return (TRUE);
 }  }
   
Line 80  void splice_setpsifrequency (t_msec freq Line 83  void splice_setpsifrequency (t_msec freq
   
 static int findapid (stream_descr *s)  static int findapid (stream_descr *s)
 {  {
   boolean ok = TRUE;    byte okness = 2;
     int h;
   do {    do {
     if ((nextpid < TS_PID_SPLICELO) || (nextpid >= TS_PID_SPLICEHI)) {      if ((nextpid < TS_PID_SPLICELO) || (nextpid >= TS_PID_SPLICEHI)) {
       if (!ok) {        warn (LDEB,"Next PID",ETSC,1,okness,nextpid);
         if (okness == 0) {
         warn (LERR,"No PID found",ETSC,2,1,0);          warn (LERR,"No PID found",ETSC,2,1,0);
         return (0);          return (0);
       }        }
       ok = FALSE;        okness -= 1;
       nextpid = TS_PID_SPLICELO;        nextpid = TS_PID_SPLICELO;
     } else {      } else {
         warn (LDEB,"Next PID",ETSC,2,okness,nextpid);
       nextpid += 1;        nextpid += 1;
     }      }
   } while (outs[nextpid] != NULL);      if (okness != 0) {
         h = input_tssiinafilerange (nextpid);
         warn (LDEB,"Next PID",ETSC,3,h,nextpid);
         if (h >= 0) {
           nextpid = h;
         }
       } else {
         h = -1;
       }
     } while ((h >= 0)
           || (outs[nextpid] != NULL));
   outs[nextpid] = s;    outs[nextpid] = s;
   warn (LDEB,"Next PID",ETSC,2,2,nextpid);    warn (LDEB,"Next PID",ETSC,2,2,nextpid);
   return (nextpid);    return (nextpid);
Line 111  void splice_all_configuration (void) Line 127  void splice_all_configuration (void)
   }    }
 }  }
   
   void splice_addsirange (file_descr *f,
       int lower,
       int upper)
   {
     int i, r;
     tssi_descr *tssi;
     prog_descr *p;
     tssi = malloc (sizeof (tssi_descr));
     if (tssi != NULL) {
       if (ts_file_stream (f,TS_UNPARSED_SI) == NULL) {
         ts_file_stream (f,TS_UNPARSED_SI) = input_openstream (f,
                 TS_UNPARSED_SI,0,0,sd_unparsedsi,NULL);
       }
       if (ts_file_stream (f,TS_UNPARSED_SI) != NULL) {
         tssi->next = f->u.ts.tssi;
         tssi->pid_low = lower;
         tssi->pid_high = upper;
         f->u.ts.tssi = tssi;
         r = upper; /* check for collision against existing PIDs, first sd_data */
         while (r >= lower) {
           stream_descr *s;
           s = outs[r];
           if ((s != NULL)
            && (s != PMT_STREAM)) {
             if (s->streamdata == sd_data) {
               i = findapid (s);
               if (input_tssiinafilerange (i) >= 0) { /* none free! */
                 outs[i] = NULL;
               } else {
                 int j;
                 s->u.d.pid = i;
                 j = s->u.d.progs;
                 while (--j >= 0) {
                   p = s->u.d.pdescr[j];
                   p->changed = TRUE;
                   if (p->pcr_pid == r) {
                     p->pcr_pid = i;
                   }
                 }
                 configuration_changed = TRUE;
                 outs[r] = NULL;
               }
             } else {
               warn (LERR,"Bad PID",ETSC,11,s->streamdata,r);
             }
           }
           r -= 1;
         }
         i = progs; /* ...then sd_map */
         while (--i >= 0) {
           p = prog[i];
           r = p->pmt_pid;
           if ((r >= lower)
            && (r <= upper)) {
             int q;
             q = findapid (PMT_STREAM);
             if (input_tssiinafilerange (q) >= 0) { /* none free! */
               outs[q] = NULL;
             } else {
               int j;
               outs[r] = NULL;
               j = i;
               while (--j >= 0) {
                 if (prog[j]->pmt_pid == r) {
                   prog[j]->pmt_pid = q;
                 }
               }
               p->pmt_pid = q;
               changed_pat = TRUE;
               configuration_changed = TRUE;
             }
           }
         }
       } else {
         free (tssi);
       }
     }
   }
   
   void splice_createstump (int programnb,
       short pid,
       byte styp)
   {
     prog_descr *p;
     stump_descr **pst;
     stump_descr *st;
     p = splice_getprog (programnb);
     if (p != NULL) {
       configuration_changed = TRUE;
       p->changed = TRUE;
       pst = &(p->stump);
     } else {
       pst = &globalstumps;
     }
     st = *pst;
     while ((st != NULL)
         && ((st->pid != pid)
          || (st->program_number != programnb))) {
       st = st->next;
     }
     if (st == NULL) {
       st = malloc (sizeof(stump_descr));
       st->next = *pst;
       st->program_number = programnb;
       st->pid = pid;
       *pst = st;
     }
     st->stream_type = styp;
     clear_descrdescr (&(st->manudescr));
   }
   
   stump_descr *splice_getstumps (int programnb,
       short pid)
   {
     prog_descr *p;
     stump_descr **pst;
     stump_descr *rl;
     rl = NULL;
     p = splice_getprog (programnb);
     if (p != NULL) {
       pst = &(p->stump);
     } else {
       pst = &globalstumps;
     }
     while (*pst != NULL) {
       stump_descr *st;
       st = *pst;
       if ((st->program_number == programnb)
        && ((pid < 0)
         || (pid == st->pid))) {
         st = *pst;
         *pst = st->next;
         st->next = rl;
         rl = st;
         if (p != NULL) {
           configuration_changed = TRUE;
           p->changed = TRUE;
         }
       } else {
         pst = &((*pst)->next);
       }
     }
     return (rl);
   }
   
 prog_descr *splice_getprog (int programnb)  prog_descr *splice_getprog (int programnb)
 {  {
   int i;    int i;
Line 141  prog_descr *splice_openprog (int program Line 302  prog_descr *splice_openprog (int program
           p->changed = TRUE;            p->changed = TRUE;
           p->pat_section = 0; /* more ? */            p->pat_section = 0; /* more ? */
           p->streams = 0;            p->streams = 0;
             p->stump = splice_getstumps (programnb,-1);
           prog[progs++] = p;            prog[progs++] = p;
           changed_pat = TRUE;            changed_pat = TRUE;
           configuration_changed = TRUE;            configuration_changed = TRUE;
Line 164  void splice_closeprog (prog_descr *p) Line 326  void splice_closeprog (prog_descr *p)
   while (p->streams > 0) {    while (p->streams > 0) {
     unlink_streamprog (p->stream[0],p);      unlink_streamprog (p->stream[0],p);
   }    }
     releasechain (stump_descr,p->stump);
   n = -1;    n = -1;
   if (p->pmt_pid >= 0) {    if (p->pmt_pid >= 0) {
     i = progs;      i = progs;
Line 274  static int make_pmtsection (stream_descr Line 437  static int make_pmtsection (stream_descr
 {  {
   int i;    int i;
   byte *d;    byte *d;
     stump_descr *st;
   p->changed = FALSE;    p->changed = FALSE;
   d = dest;    d = dest;
   *d++ = TS_TABLEID_PMT;    *d++ = TS_TABLEID_PMT;
Line 300  static int make_pmtsection (stream_descr Line 464  static int make_pmtsection (stream_descr
   *d++ = 0xE0 | (i >> 8);    *d++ = 0xE0 | (i >> 8);
   *d++ = i;    *d++ = i;
   d += 2;    d += 2;
   i = NUMBER_ELEMD;    if (s->fdescr->content == ct_program) {
   while (--i > 0) {      i = NUMBER_ELEMD;
     if (s->fdescr->content == ct_program) {      while (--i > 0) {
       byte *y;        byte *y;
       y = s->fdescr->u.ps.stream[0]->elemdvld[i]; /* this one ? why ? */        y = s->fdescr->u.ps.stream[0]->manudescr->refx[i];
         if (y == NULL) {
           y = s->fdescr->u.ps.stream[0]->autodescr->refx[i]; /* this one? why? */
         }
       if (y != NULL) {        if (y != NULL) {
         memcpy (d,y,y[1]+2);          memcpy (d,y,y[1]+2);
         d += y[1]+2;          d += y[1]+2;
Line 328  static int make_pmtsection (stream_descr Line 495  static int make_pmtsection (stream_descr
       x = NUMBER_ELEMD;        x = NUMBER_ELEMD;
       while (--x > 0) {        while (--x > 0) {
         byte *y;          byte *y;
         y = p->stream[i]->elemdvld[x];          y = p->stream[i]->manudescr->refx[x];
           if (y == NULL) {
             y = p->stream[i]->autodescr->refx[x];
           }
         if (y != NULL) {          if (y != NULL) {
           memcpy (d,y,y[1]+2);            memcpy (d,y,y[1]+2);
           d += y[1]+2;            d += y[1]+2;
Line 339  static int make_pmtsection (stream_descr Line 509  static int make_pmtsection (stream_descr
       *--e = 0xF0 | (x >> 8);        *--e = 0xF0 | (x >> 8);
     }      }
   }    }
     st = p->stump;
     while (st != NULL) {
       int x;
       byte *e;
       *d++ = st->stream_type;
       x = st->pid;
       *d++ = 0xE0 | (x >> 8);
       *d++ = x;
       d += 2;
       e = d;
       x = NUMBER_ELEMD;
       while (--x > 0) {
         byte *y;
         y = st->manudescr.refx[x];
         if (y != NULL) {
           memcpy (d,y,y[1]+2);
           d += y[1]+2;
         }
       }
       x = d - e;
       *--e = x;
       *--e = 0xF0 | (x >> 8);
       st = st->next;
     }
   i = d + CRC_SIZE - dest - TS_TRANSPORTID;    i = d + CRC_SIZE - dest - TS_TRANSPORTID;
   dest[TS_SECTIONLEN] = 0xB0 | (i >> 8);    dest[TS_SECTIONLEN] = 0xB0 | (i >> 8);
   dest[TS_SECTIONLEN+1] = i;    dest[TS_SECTIONLEN+1] = i;

Removed from v.1.12  
changed lines
  Added in v.1.13


LinuxTV legacy CVS <linuxtv.org/cvs>