Annotation of multiplexer/global.h, revision 1.2
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 */
1.2 ! oskar 230: int repeatitions;
1.1 oskar 231: int auto_programnb;
232: content_type content;
233: union {
234: struct {
235: struct streamdescr *stream;
236: } pes;
237: struct {
238: time_stamp time;
239: struct {
240: clockref scr;
241: long muxrate;
242: } ph;
243: struct {
244: long ratebound;
245: int audiobound;
246: int videobound;
247: boolean csps_flag;
248: boolean fixed_flag;
249: boolean system_video_lock_flag;
250: boolean system_audio_lock_flag;
251: boolean packet_rate_restriction_flag;
252: short buffer_bound[MAX_STRPERPS-PES_LOWEST_SID];
253: } sh;
254: /*
255: struct {
256: } dir;
257: */
258: struct streamdescr *stream[MAX_STRPERPS];
259: } ps;
260: struct {
261: int transportstreamid;
262: byte pat_version;
263: byte newpat_version;
264: pmt_descr *pat;
265: pmt_descr *newpat;
266: int tsautos;
267: tsauto_descr *tsauto;
268: struct streamdescr *stream[MAX_STRPERTS];
269: } ts;
270: } u;
271: } file_descr;
272:
273: typedef struct {
274: int program_number;
275: int pcr_pid;
276: int pmt_pid;
277: int map_sequence; /* don't need ? */
278: byte pmt_conticnt;
279: byte pmt_version;
280: boolean changed;
281: int pat_section;
282: int streams;
283: struct streamdescr *stream[MAX_STRPERPRG];
284: } prog_descr;
285:
286: typedef struct streamdescr {
287: refr_ctrl ctrl;
288: refr_data data;
289: int sourceid; /* index into fdescr->u.xx.stream[] */
290: byte stream_id; /* elementary stream id, table 2-35, etc */
291: byte stream_type;
292: byte version;
293: byte *elemdvld[NUMBER_ELEMD]; /* as valid for out */
294: byte elemdescr[MAX_PSI_SIZE];
295: /*what if a stream is leftupper corner in one prog, but elsewhere in another?*/
296: file_descr *fdescr;
297: byte conticnt;
298: byte endaction;
299: boolean isamap;
300: union {
301: struct {
302: int pid; /* splicets: 0010..1FFE, spliceps: ...FF */
303: struct streamdescr *mapstream;
304: boolean discontinuity;
305: boolean trigger;
306: boolean mention;
307: boolean has_clockref; /* in output */
308: int next_clockref;
309: int delta;
310: int lasttime;
311: int progs;
312: prog_descr *pdescr[MAX_PRGFORSTR];
313: } d;
314: struct {
315: int readtime;
316: int psi_length;
317: byte psi_data[MAX_PSI_SIZE+TS_PACKET_SIZE];
318: } m;
319: } u;
320: } stream_descr;
321:
322:
323: extern boolean timed_io;
324: extern boolean accept_weird_scr;
325: extern int global_delta;
326: extern int psi_frequency_msec;
327: extern boolean psi_frequency_changed;
328:
329: int msec_now (void);
330:
331: void global_init (void);
332:
333:
334: #ifdef DEBUG_TIMEPOLL
335:
336: #define max_timepoll (1024*1024)
337:
338: typedef struct {
339: struct timeval tv;
340: int msec_now;
341: int usec;
342: int tmo;
343: int sr, si, so;
344: unsigned char cnt_msecnow;
345: unsigned char nfdso, nfdsi;
346: unsigned char nfdsrevent;
347: unsigned char flags;
348: } timepoll;
349: #define LTP_FLAG_DELTASHIFT 0x80
350: #define LTP_FLAG_OUTPUT 0x40
351: #define LTP_FLAG_INPUT 0x20
352: #define LTP_FLAG_SPLIT 0x10
353: #define LTP_FLAG_PROCESS 0x08
354:
355: extern timepoll logtp [max_timepoll];
356: extern long logtpc;
357: extern timepoll *ltp;
358:
359: #endif
360:
LinuxTV legacy CVS <linuxtv.org/cvs>