10
buffer_timecode (timecode, marker, buffer)
13
unsigned char **buffer;
18
temp = (marker << 4) | ((timecode >> 29) & 0x38) |
19
((timecode >> 29) & 0x6) | 1;
20
*((*buffer)++) = temp;
21
temp = (timecode & 0x3fc00000) >> 22;
22
*((*buffer)++) = temp;
23
temp = ((timecode & 0x003f8000) >> 14) | 1;
24
*((*buffer)++) = temp;
25
temp = (timecode & 0x7f80) >> 7;
26
*((*buffer)++) = temp;
27
temp = ((timecode & 0x007f) << 1) | 1;
28
*((*buffer)++) = temp;
31
/*************************************************************************
32
creates a complete sector.
33
Also copies Pack and Sys_Header informations into the
34
sector buffer, then reads a packet full of data from
35
the input stream into the sector buffer.
36
*************************************************************************/
40
create_sector (sector, pack, sys_header,
41
packet_size, inputbuffer, type,
42
buffer_scale, buffer_size, buffers, PTS, DTS, timestamps, which_streams)
46
Sys_header_struc *sys_header;
47
unsigned int packet_size;
48
unsigned char *inputbuffer;
51
unsigned char buffer_scale;
52
unsigned int buffer_size;
53
unsigned char buffers;
56
unsigned char timestamps;
57
unsigned int which_streams;
62
unsigned char *size_offset;
64
/* printf("creating sector\n"); */
67
sector->length_of_sector = 0;
69
/* Should we copy Pack Header information ? */
72
i = sizeof (pack->buf);
73
memcpy (index, pack->buf, i);
75
sector->length_of_sector += i;
78
/* Should we copy System Header information ? */
80
if (sys_header != NULL) {
81
i = sizeof (sys_header->buf);
83
/* only one stream? 3 bytes less in sys header */
84
if (which_streams != STREAMS_BOTH)
87
memcpy (index, sys_header->buf, i);
89
sector->length_of_sector += i;
92
/* write constant packet header data */
94
*(index++) = (unsigned char) (PACKET_START) >> 16;
95
*(index++) = (unsigned char) (PACKET_START & 0x00ffff) >> 8;
96
*(index++) = (unsigned char) (PACKET_START & 0x0000ff);
99
/* we remember this offset in case we will have to shrink this packet */
102
*(index++) = (unsigned char) ((packet_size - PACKET_HEADER_SIZE) >> 8);
103
*(index++) = (unsigned char) ((packet_size - PACKET_HEADER_SIZE) & 0xff);
105
*(index++) = STUFFING_BYTE;
106
*(index++) = STUFFING_BYTE;
107
*(index++) = STUFFING_BYTE;
113
if (timestamps == TIMESTAMPS_NO)
115
else if (timestamps == TIMESTAMPS_PTS)
118
/* printf("%i stuffing %d\n", i, timestamps); */
120
for (j = 0; j < i; j++)
121
*(index++) = STUFFING_BYTE;
123
/* should we write buffer info ? */
126
*(index++) = (unsigned char) (0x40 |
127
(buffer_scale << 5) | (buffer_size >> 8));
128
*(index++) = (unsigned char) (buffer_size & 0xff);
131
/* should we write PTS, PTS & DTS or nothing at all ? */
133
switch (timestamps) {
135
*(index++) = MARKER_NO_TIMESTAMPS;
138
buffer_timecode (PTS, MARKER_JUST_PTS, &index);
141
case TIMESTAMPS_PTS_DTS:
142
buffer_timecode (PTS, MARKER_PTS, &index);
143
buffer_timecode (DTS, MARKER_DTS, &index);
148
/* read in packet data */
150
i = (packet_size - PACKET_HEADER_SIZE - AFTER_PACKET_LENGTH);
152
if (type == PADDING_STR) {
153
for (j = 0; j < i; j++)
154
*(index++) = (unsigned char) STUFFING_BYTE;
157
/*tmp = fread (index, sizeof (unsigned char), i, inputstream); */
158
memcpy (index, inputbuffer, i);
162
/* if we did not get enough data bytes, shorten the Packet length */
165
packet_size -= (i - tmp);
167
(unsigned char) ((packet_size - PACKET_HEADER_SIZE) >> 8);
169
(unsigned char) ((packet_size - PACKET_HEADER_SIZE) & 0xff);
171
/* zero byte stuffing in the last Packet of a stream */
172
/* we don't need this any more, since we shortenend the packet */
173
/* for (j=tmp; j<i; j++) */
174
/* *(index++)=(unsigned char) ZERO_STUFFING_BYTE; */
179
/* write other struct data */
181
sector->length_of_sector += packet_size;
182
sector->length_of_packet_data = tmp;
186
/*************************************************************************
187
writes specifical pack header information into a buffer
188
later this will be copied from the sector routine into
190
*************************************************************************/
193
create_pack (pack, SCR, mux_rate)
196
unsigned int mux_rate;
200
unsigned char *index;
204
*(index++) = (unsigned char) ((PACK_START) >> 24);
205
*(index++) = (unsigned char) ((PACK_START & 0x00ff0000) >> 16);
206
*(index++) = (unsigned char) ((PACK_START & 0x0000ff00) >> 8);
207
*(index++) = (unsigned char) (PACK_START & 0x000000ff);
208
buffer_timecode (SCR, MARKER_SCR, &index);
209
*(index++) = (unsigned char) (0x80 | (mux_rate >> 15));
210
*(index++) = (unsigned char) (0xff & (mux_rate >> 7));
211
*(index++) = (unsigned char) (0x01 | ((mux_rate & 0x7f) << 1));
216
/*************************************************************************
217
writes specifical system header information into a buffer
218
later this will be copied from the sector routine into
220
*************************************************************************/
223
create_sys_header (sys_header, rate_bound, audio_bound,
224
fixed, CSPS, audio_lock, video_lock,
226
stream1, buffer1_scale, buffer1_size,
227
stream2, buffer2_scale, buffer2_size, which_streams)
229
Sys_header_struc *sys_header;
230
unsigned int rate_bound;
231
unsigned char audio_bound;
234
unsigned char audio_lock;
235
unsigned char video_lock;
236
unsigned char video_bound;
238
unsigned char stream1;
239
unsigned char buffer1_scale;
240
unsigned int buffer1_size;
241
unsigned char stream2;
242
unsigned char buffer2_scale;
243
unsigned int buffer2_size;
244
unsigned int which_streams;
247
unsigned char *index;
249
index = sys_header->buf;
251
/* if we are not using both streams, we should clear some
254
if (!(which_streams & STREAMS_AUDIO))
256
if (!(which_streams & STREAMS_VIDEO))
259
*(index++) = (unsigned char) ((SYS_HEADER_START) >> 24);
260
*(index++) = (unsigned char) ((SYS_HEADER_START & 0x00ff0000) >> 16);
261
*(index++) = (unsigned char) ((SYS_HEADER_START & 0x0000ff00) >> 8);
262
*(index++) = (unsigned char) (SYS_HEADER_START & 0x000000ff);
264
if (which_streams == STREAMS_BOTH) {
265
*(index++) = (unsigned char) (SYS_HEADER_LENGTH >> 8);
266
*(index++) = (unsigned char) (SYS_HEADER_LENGTH & 0xff);
268
*(index++) = (unsigned char) ((SYS_HEADER_LENGTH - 3) >> 8);
269
*(index++) = (unsigned char) ((SYS_HEADER_LENGTH - 3) & 0xff);
272
*(index++) = (unsigned char) (0x80 | (rate_bound >> 15));
273
*(index++) = (unsigned char) (0xff & (rate_bound >> 7));
274
*(index++) = (unsigned char) (0x01 | ((rate_bound & 0x7f) << 1));
275
*(index++) = (unsigned char) ((audio_bound << 2) | (fixed << 1) | CSPS);
276
*(index++) = (unsigned char) ((audio_lock << 7) |
277
(video_lock << 6) | 0x20 | video_bound);
279
*(index++) = (unsigned char) RESERVED_BYTE;
281
if (which_streams & STREAMS_AUDIO) {
282
*(index++) = stream1;
283
*(index++) = (unsigned char) (0xc0 |
284
(buffer1_scale << 5) | (buffer1_size >> 8));
285
*(index++) = (unsigned char) (buffer1_size & 0xff);
288
if (which_streams & STREAMS_VIDEO) {
289
*(index++) = stream2;
290
*(index++) = (unsigned char) (0xc0 |
291
(buffer2_scale << 5) | (buffer2_size >> 8));
292
*(index++) = (unsigned char) (buffer2_size & 0xff);