Diff for /multiplexer/repeatts.c between versions 1.4 and 1.5

version 1.4, 2003/02/21 11:35:11 version 1.5, 2003/02/21 18:20:26
Line 20 Line 20
 #include <stdio.h>  #include <stdio.h>
 #include "global.h"  #include "global.h"
   
 #define D(x)                    /* x */  
   #define D(x)                   /* x */
   
 #define MAX_ANOTATE (16 * 256)  #define MAX_ANOTATE (16 * 256)
   
Line 33  static byte combuf[MAX_DATA_COMB]; Line 34  static byte combuf[MAX_DATA_COMB];
 static int dati, dato;  static int dati, dato;
 static byte data[MAX_ANOTATE];  static byte data[MAX_ANOTATE];
   
 static t_msec nextrdelay, nextfdelay;  static t_msec nextfdelay;
   
   static int    num_packets;
   static t_msec transmission_time;
   
 t_msec  t_msec
 msec_now (void)  msec_now (void)
 {  {
     static int       first_call = 1;  
     static long long first_time;
     static long long now;
   
     struct timeval tv;
     
     gettimeofday (&tv, NULL);
   #if 0
 #define MSEC_EXPONENT 21  #define MSEC_EXPONENT 21
   static long last;    static long last;
   static int local_delta;    static int local_delta;
   struct timeval tv;  
   gettimeofday (&tv, NULL);  
   if ((tv.tv_sec & (~((1L << MSEC_EXPONENT) - 1))) != last)    if ((tv.tv_sec & (~((1L << MSEC_EXPONENT) - 1))) != last)
     {      {
       last = tv.tv_sec & (~((1L << MSEC_EXPONENT) - 1));        last = tv.tv_sec & (~((1L << MSEC_EXPONENT) - 1));
Line 50  msec_now (void) Line 60  msec_now (void)
     }      }
   return ((tv.tv_sec & ((1L << MSEC_EXPONENT) - 1)) * 1000    return ((tv.tv_sec & ((1L << MSEC_EXPONENT) - 1)) * 1000
           + tv.tv_usec / 1000 + local_delta);            + tv.tv_usec / 1000 + local_delta);
   #endif
     now = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
     if (first_call)
       {
         first_call = 0;
         first_time = now;
       }
   
     return (t_msec)(now - first_time);
 }  }
   
 static void  static void
Line 162  D (fprintf (stderr, "file %d, mode %07o, Line 181  D (fprintf (stderr, "file %d, mode %07o,
                                           if ((stat.st_size %                                            if ((stat.st_size %
                                                TS_PACKET_SIZE) == 0)                                                 TS_PACKET_SIZE) == 0)
                                             {                                              {
                                               if (stat.st_size > 0)                                                num_packets = stat.st_size /
                                                 {                                                  TS_PACKET_SIZE;
                                                   nextrdelay =                                                transmission_time = l2;
                                                     l2 / (stat.st_size /  
                                                           TS_PACKET_SIZE);  
                                                 }  
                                               else  
                                                 {  
                                                   nextrdelay = 0;  
                                                 }  
                                               nextfdelay = l1;                                                nextfdelay = l1;
 D (fprintf (stderr, "next opened(%d,%d)\n", nextfdelay, nextrdelay));  D (fprintf (stderr, "next opened(%d, %d, %d)\n", 
               nextfdelay, num_packets, transmission_time));
                                               return (TRUE);                                                return (TRUE);
                                             }                                              }
                                           else                                            else
Line 271  main (int argc, char *argv[]) Line 284  main (int argc, char *argv[])
   int polli, pollo, polls;    int polli, pollo, polls;
   int toberead = 0;   /* to make gcc happy */    int toberead = 0;   /* to make gcc happy */
   int currentf;    int currentf;
     int packet_count = 0;
   
   boolean dotime;    boolean dotime;
   t_msec rtime;    t_msec rtime;
     t_msec rtime_base = 0;
   t_msec ftime;    t_msec ftime;
   t_msec rdelay = 0;  /* to make gcc happy */  
   t_msec fdelay = 0;  /* to make gcc happy */    t_msec fdelay = 0;  /* to make gcc happy */
   t_msec now;    t_msec now;
   struct pollfd ufds[3];    struct pollfd ufds[3];
Line 285  main (int argc, char *argv[]) Line 300  main (int argc, char *argv[])
       while (!quit)        while (!quit)
         {          {
           now = msec_now ();            now = msec_now ();
           D (fprintf (stderr, "now(%d)\n", now));            D (fprintf (stderr, "now(%x)\n", now));
           if (currentf < 0)            if (currentf < 0)
             {              {
               toberead = 0;                toberead = 0;
               rdelay = nextrdelay;  
               fdelay = nextfdelay;                fdelay = nextfdelay;
               if ((ftime - now) < 0)                if ((ftime - now) < 0)
                 {                  {
                   ftime = now;                    ftime = now;
                 }                  }
               rtime = ftime;                rtime_base = rtime = ftime;
                 packet_count = 0;
               currentf = nextf;                currentf = nextf;
               nextf = -1;                nextf = -1;
               D (fprintf (stderr, "next current(%d,%d,%d)\n", currentf, fdelay, rdelay));                D (fprintf (stderr, "next current(%d,%d)\n", currentf, fdelay));
             }              }
           if (currentf >= 0)            if (currentf >= 0)
             {              {
Line 308  main (int argc, char *argv[]) Line 323  main (int argc, char *argv[])
                       TS_PACKET_SIZE)                        TS_PACKET_SIZE)
                     {                      {
                       toberead += TS_PACKET_SIZE;                        toberead += TS_PACKET_SIZE;
                       rtime += rdelay;  
                         packet_count++;
                         if (num_packets > 0)
                           {
                             rtime = rtime_base + 
                               (t_msec)(((long long)packet_count * transmission_time) /
                                        num_packets);
                             D (fprintf (stderr, "%d %d %d %d %d\n", 
                                         rtime, rtime_base, packet_count, 
                                         transmission_time, num_packets));
                           }
                           
                       dotime = TRUE;                        dotime = TRUE;
                       D (fprintf (stderr, "timer a(%d,%d)\n", toberead, rtime));                        D (fprintf (stderr, "timer a(%d,%d)\n", toberead, rtime));
                     }                      }
                   else                    else
                     {                      {
                       rtime = now;                        rtime_base = rtime = now;
                         packet_count = 0;
                       dotime = FALSE;                        dotime = FALSE;
                       D (fprintf (stderr, "timer b(%d,%d)\n", toberead, rtime));                        D (fprintf (stderr, "timer b(%d,%d)\n", toberead, rtime));
                     }                      }
Line 409  main (int argc, char *argv[]) Line 436  main (int argc, char *argv[])
                     {                      {
                       ftime = now;                        ftime = now;
                     }                      }
                   rtime = ftime;                    rtime_base = rtime = ftime;
                     packet_count = 0;
                 }                  }
             }              }
           if ((pollo != 0)            if ((pollo != 0)

Removed from v.1.4  
changed lines
  Added in v.1.5


LinuxTV legacy CVS <linuxtv.org/cvs>