Annotation of multiplexer/global.h, revision 1.1

1.1     ! oskar       1: /*
        !             2:  * ISO 13818 stream multiplexer
        !             3:  * Copyright (C) 2001 Convergence Integrated Media GmbH Berlin
        !             4:  * Author: Oskar Schirmer (oskar@convergence.de)
        !             5:  */
        !             6: 
        !             7: #include <asm/types.h>
        !             8: #include <sys/types.h>
        !             9: #include <sys/poll.h>
        !            10: #include <sys/time.h>
        !            11: #include <sys/unistd.h>
        !            12: #include <sys/stat.h>
        !            13: #include <unistd.h>
        !            14: #include <fcntl.h>
        !            15: #include <stdlib.h>
        !            16: #include <string.h>
        !            17: #include <errno.h>
        !            18: 
        !            19: /* for a timing and poll profile: */
        !            20: #if 0
        !            21: #define DEBUG_TIMEPOLL
        !            22: #endif
        !            23: 
        !            24: #define MAX_MSEC_OUTDELAY  500
        !            25: #define MAX_MSEC_PUSHJTTR  (2 * 250)
        !            26: #define MAX_MSEC_PCRDIST   100
        !            27: #define PCR_INTERPOLSIZE   8
        !            28: 
        !            29: #define MAX_POLLFD    (MAX_INFILE+3)
        !            30: 
        !            31: #define MAX_DATA_COMB 512
        !            32: #define HIGHWATER_COM 8
        !            33: 
        !            34: #define BUFSIZ_FACTOR 32 * 2
        !            35: 
        !            36: #define MAX_CTRL_OUTB 32 * BUFSIZ_FACTOR
        !            37: #define MAX_DATA_OUTB 4096 * BUFSIZ_FACTOR
        !            38: #define HIGHWATER_OUT 512
        !            39: #define MAX_WRITE_OUT (128 * 188)
        !            40: #define OUT_TRIGCOND  (MAX_DATA_OUTB / 2)
        !            41: 
        !            42: #define MAX_CTRL_INB  32 * BUFSIZ_FACTOR
        !            43: #define MAX_DATA_INB  4096 * BUFSIZ_FACTOR
        !            44: #define MAX_DATA_RAWB 4096 * BUFSIZ_FACTOR
        !            45: #define HIGHWATER_IN  (512 * 4 * 8)
        !            46: #define MAX_READ_IN   (1024 * 8)
        !            47: #define IN_TRIGCOND   (MAX_DATA_INB / 2)
        !            48: 
        !            49: #define MAX_INSTREAM  64 /* ? */
        !            50: #define MAX_INFILE    8  /* ? */
        !            51: 
        !            52: #define MAX_STRPERPS  (1<<8)
        !            53: #define MAX_STRPERTS  (1<<13)
        !            54: 
        !            55: #define MAX_STRPERPRG 42 /* ? */
        !            56: #define MAX_PRGFORSTR 12 /* ? */
        !            57: #define MAX_OUTPROG   16  /* ? */
        !            58: 
        !            59: /*
        !            60: #define MAX_CTRL_MAPSTR  4
        !            61: #define MAX_DATA_MAPSTR  4096
        !            62: */
        !            63: 
        !            64: #define MAX_PSI_SIZE  1025
        !            65: #define MAX_PMTSTREAMS (MAX_PSI_SIZE / 4)
        !            66: 
        !            67: #define ENDFILE_CLOSE 0
        !            68: #define ENDFILE_RESET 1
        !            69: #define ENDFILE_CHAIN 2
        !            70: 
        !            71: #define ENDSTR_KILL      0
        !            72: #define ENDSTR_CLOSE     1
        !            73: #define ENDSTR_WAIT      2
        !            74: 
        !            75: #define PES_LOWEST_SID    (0xBC)
        !            76: #define NUMBER_ELEMD  19
        !            77: #define TS_PACKET_SIZE 188
        !            78: 
        !            79: #define CRC_SIZE 4
        !            80: 
        !            81: #define boolean __u8
        !            82: #define FALSE   0
        !            83: #define TRUE    1
        !            84: 
        !            85: #define byte __u8
        !            86: 
        !            87: typedef struct {
        !            88:   unsigned long base;
        !            89:   unsigned short ext;
        !            90:   unsigned char ba33;
        !            91:   boolean valid;
        !            92: } clockref;
        !            93: 
        !            94: /*
        !            95: #define MIXTIME_MSEC 0x01
        !            96: #define MIXTIME_TVAL 0x02
        !            97: #define MIXTIME_CREF 0x04
        !            98: #define mixflag cr.flags
        !            99: typedef struct {
        !           100:   int msec;
        !           101:   struct timeval tv;
        !           102:   clockref cr;
        !           103:   clockref *localrelativeclockref;
        !           104: } mixtime;
        !           105: */
        !           106: 
        !           107: typedef struct {
        !           108:   int read;
        !           109:   int push;
        !           110: } time_stamp;
        !           111: 
        !           112: typedef struct {
        !           113:   int index;
        !           114:   int length;
        !           115:   int sequence;
        !           116:   int scramble;
        !           117:   time_stamp time;
        !           118:   clockref pcr; /* FIXME: this goes parallel to time.push */
        !           119:   clockref opcr;
        !           120: } ctrl_buffer;
        !           121: 
        !           122: typedef struct {
        !           123:   ctrl_buffer *ptr;
        !           124:   int in;
        !           125:   int out;
        !           126:   int mask;
        !           127: } refr_ctrl;
        !           128: 
        !           129: typedef struct {
        !           130:   byte *ptr;
        !           131:   int in;
        !           132:   int out;
        !           133:   int mask;
        !           134: } refr_data;
        !           135: 
        !           136: #define list_empty(refr) ((refr).out == (refr).in)
        !           137: 
        !           138: #define list_create(refr,size) \
        !           139:   ((((size) & ((size)-1)) || (size < 2)) ? \
        !           140:      warn (LERR,"List Create",EGLO,1,1,size), FALSE : \
        !           141:    ((refr).ptr = malloc((size) * sizeof(*(refr).ptr))) == NULL ? \
        !           142:      warn (LERR,"List Create",EGLO,1,2,size), FALSE : \
        !           143:    ((refr).mask = (size)-1, (refr).in = (refr).out = 0, TRUE))
        !           144: 
        !           145: #define list_release(refr) \
        !           146:   ((refr).mask = 0, free((refr).ptr), (refr).ptr = NULL)
        !           147: 
        !           148: #define list_free(refr) \
        !           149:   (((refr).out - (refr).in - 1) & (refr).mask)
        !           150: 
        !           151: #define list_freeinend(refr) \
        !           152:   ((refr).mask + 1 - (refr).in)
        !           153: 
        !           154: #define list_size(refr) \
        !           155:   (((refr).in - (refr).out) & (refr).mask)
        !           156: 
        !           157: #define list_full(refr) \
        !           158:   (list_free(refr) == 0)
        !           159: 
        !           160: #define list_incr(var,refr,incr) \
        !           161:   ((var) = (((var) + (incr)) & (refr).mask))
        !           162: 
        !           163: #define clockref2msec(cref) \
        !           164:   ((cref).base / 90)
        !           165: 
        !           166: #define msec2clockref(msec,cref) \
        !           167:   (((cref).base = (msec) * 90), ((cref).ext = 0), ((cref).ba33 = 0))
        !           168: 
        !           169: #define marker_check(data,val,mask) \
        !           170:   (((data & mask) != val) ? \
        !           171:     warn(LWAR,"Marker bit",EGLO,2,data,mask), TRUE : FALSE)
        !           172: 
        !           173: #define marker_bit(data,bit) \
        !           174:   marker_check(data,1<<bit,1<<bit)
        !           175: 
        !           176: #define mmin(a,b) ((a)<(b)?(a):(b))
        !           177: #define mmax(a,b) ((a)<(b)?(b):(a))
        !           178: 
        !           179: #define unionalloc(typ,fld) \
        !           180:   (malloc (sizeof(typ)-sizeof(((typ*)0)->u)+sizeof(((typ*)0)->u.fld)))
        !           181: 
        !           182: typedef struct {
        !           183:   int sourceid;
        !           184:   int programnumber;
        !           185:   byte version;
        !           186:   byte *elemdnew[NUMBER_ELEMD];
        !           187: } mapreference;
        !           188: 
        !           189: typedef struct pmtdescr {
        !           190:   struct pmtdescr *next;
        !           191:   short pat_section;
        !           192:   byte pmt_version;
        !           193:   int programnumber;
        !           194:   int pcr_pid;
        !           195:   int pmt_pid;
        !           196:   int streams;
        !           197:   short stream[MAX_PMTSTREAMS];
        !           198:   byte streamtype[MAX_PMTSTREAMS];
        !           199:   int descrlen;
        !           200:   byte elemdescr[MAX_PSI_SIZE];
        !           201: } pmt_descr;
        !           202: 
        !           203: typedef struct {
        !           204:   int sprg, tprg, ssid, tsid;
        !           205: } tsauto_descr;
        !           206: 
        !           207: typedef enum {
        !           208:   ct_none,
        !           209: /*  ct_elementary, */
        !           210:   ct_packetized,
        !           211:   ct_program,
        !           212:   ct_transport,
        !           213:   ct_unknown
        !           214: } content_type;
        !           215: 
        !           216: typedef struct {
        !           217:   refr_data data;
        !           218:   char *name;
        !           219:   int handle;
        !           220:   struct stat stat;
        !           221:   struct pollfd *ufds;
        !           222:   int skipped; /* undesired bytes skipped, total */
        !           223:   int payload; /* split payload used total */
        !           224:   int total; /* split total (skipped, used, wasted) */
        !           225:   int sequence; /* source counter for PES sequence */
        !           226:   int opendatastreams;
        !           227:   int openmapstreams;
        !           228:   byte endaction;
        !           229:   boolean automatic; /* extract'o'use */
        !           230:   int auto_programnb;
        !           231:   content_type content;
        !           232:   union {
        !           233:     struct {
        !           234:       struct streamdescr *stream;
        !           235:     } pes;
        !           236:     struct {
        !           237:       time_stamp time;
        !           238:       struct {
        !           239:         clockref scr;
        !           240:         long muxrate;
        !           241:       } ph;
        !           242:       struct {
        !           243:         long ratebound;
        !           244:         int audiobound;
        !           245:         int videobound;
        !           246:         boolean csps_flag;
        !           247:         boolean fixed_flag;
        !           248:         boolean system_video_lock_flag;
        !           249:         boolean system_audio_lock_flag;
        !           250:         boolean packet_rate_restriction_flag;
        !           251:         short buffer_bound[MAX_STRPERPS-PES_LOWEST_SID];
        !           252:       } sh;
        !           253: /*
        !           254:       struct {
        !           255:       } dir;
        !           256: */
        !           257:       struct streamdescr *stream[MAX_STRPERPS];
        !           258:     } ps;
        !           259:     struct {
        !           260:       int transportstreamid;
        !           261:       byte pat_version;
        !           262:       byte newpat_version;
        !           263:       pmt_descr *pat;
        !           264:       pmt_descr *newpat;
        !           265:       int tsautos;
        !           266:       tsauto_descr *tsauto;
        !           267:       struct streamdescr *stream[MAX_STRPERTS];
        !           268:     } ts;
        !           269:   } u;
        !           270: } file_descr;
        !           271: 
        !           272: typedef struct {
        !           273:   int program_number;
        !           274:   int pcr_pid;
        !           275:   int pmt_pid;
        !           276:   int map_sequence; /* don't need ? */
        !           277:   byte pmt_conticnt;
        !           278:   byte pmt_version;
        !           279:   boolean changed;
        !           280:   int pat_section;
        !           281:   int streams;
        !           282:   struct streamdescr *stream[MAX_STRPERPRG];
        !           283: } prog_descr;
        !           284: 
        !           285: typedef struct streamdescr {
        !           286:   refr_ctrl ctrl;
        !           287:   refr_data data;
        !           288:   int sourceid; /* index into fdescr->u.xx.stream[] */
        !           289:   byte stream_id; /* elementary stream id, table 2-35, etc */
        !           290:   byte stream_type;
        !           291:   byte version;
        !           292:   byte *elemdvld[NUMBER_ELEMD]; /* as valid for out */
        !           293:   byte elemdescr[MAX_PSI_SIZE];
        !           294: /*what if a stream is leftupper corner in one prog, but elsewhere in another?*/
        !           295:   file_descr *fdescr;
        !           296:   byte conticnt;
        !           297:   byte endaction;
        !           298:   boolean isamap;
        !           299:   union {
        !           300:     struct {
        !           301:       int pid; /* splicets: 0010..1FFE, spliceps: ...FF */
        !           302:       struct streamdescr *mapstream;
        !           303:       boolean discontinuity;
        !           304:       boolean trigger;
        !           305:       boolean mention;
        !           306:       boolean has_clockref; /* in output */
        !           307:       int next_clockref;
        !           308:       int delta;
        !           309:       int lasttime;
        !           310:       int progs;
        !           311:       prog_descr *pdescr[MAX_PRGFORSTR];
        !           312:     } d;
        !           313:     struct {
        !           314:       int readtime;
        !           315:       int psi_length;
        !           316:       byte psi_data[MAX_PSI_SIZE+TS_PACKET_SIZE];
        !           317:     } m;
        !           318:   } u;
        !           319: } stream_descr;
        !           320: 
        !           321: 
        !           322: extern boolean timed_io;
        !           323: extern boolean accept_weird_scr;
        !           324: extern int global_delta;
        !           325: extern int psi_frequency_msec;
        !           326: extern boolean psi_frequency_changed;
        !           327: 
        !           328: int msec_now (void);
        !           329: 
        !           330: void global_init (void);
        !           331: 
        !           332: 
        !           333: #ifdef DEBUG_TIMEPOLL
        !           334: 
        !           335: #define max_timepoll (1024*1024)
        !           336: 
        !           337: typedef struct {
        !           338:   struct timeval tv;
        !           339:   int msec_now;
        !           340:   int usec;
        !           341:   int tmo;
        !           342:   int sr, si, so;
        !           343:   unsigned char cnt_msecnow;
        !           344:   unsigned char nfdso, nfdsi;
        !           345:   unsigned char nfdsrevent;
        !           346:   unsigned char flags;
        !           347: } timepoll;
        !           348: #define LTP_FLAG_DELTASHIFT 0x80
        !           349: #define LTP_FLAG_OUTPUT     0x40
        !           350: #define LTP_FLAG_INPUT      0x20
        !           351: #define LTP_FLAG_SPLIT      0x10
        !           352: #define LTP_FLAG_PROCESS    0x08
        !           353: 
        !           354: extern timepoll logtp [max_timepoll];
        !           355: extern long logtpc;
        !           356: extern timepoll *ltp;
        !           357: 
        !           358: #endif
        !           359: 

LinuxTV legacy CVS <linuxtv.org/cvs>