📄 systems.cpp
字号:
#include "main.h"/************************************************************************* Create_Sector creates a complete sector. Also copies Pack and Sys_Header informations into the sector buffer, then reads a packet full of data from the input stream into the sector buffer.*************************************************************************/static unsigned char data_buffer[MAX_SECTOR_SIZE];void create_sector ( Sector_struc *sector, Pack_struc *pack, Sys_header_struc *sys_header, unsigned int packet_size, unsigned int partial_packet_size, FILE *inputstream, unsigned char type, unsigned char subtype, unsigned char buffer_scale, unsigned int buffer_size, unsigned char buffers, Timecode_struc *PTS, Timecode_struc *DTS, unsigned char timestamps, unsigned int which_streams, unsigned int sector_pad, unsigned int svcd_offset, unsigned int write_broken_link, unsigned int write_seq_end, unsigned int write_seq_hdr, unsigned int sh_length, unsigned char *seq_hdr){ int i, j, data_bytes, numFound, syncFound, firstOffset, pad_size; unsigned char *index, *tmpPtr=NULL; unsigned int data_size, stuff_size, k; index = sector->buf; sector->length_of_sector=0; /* Should we copy Pack Header information ? */ if (pack != NULL) { if (mplex_type > MPEG_VCD) i = MPEG2_PACK_HEADER_SIZE; else i = MPEG1_PACK_HEADER_SIZE; memcpy (index, pack->buf, i); index += i; sector->length_of_sector += i; } /* Should we copy System Header information ? */ if (sys_header != NULL) { i = sizeof(sys_header->buf); /* only one stream? 3 to 6 bytes less in sys header */ if (!(which_streams & STREAMS_VIDEO)) i -= 3; if (!(which_streams & STREAMS_AUDIO)) i -= 3; if (!(which_streams & STREAMS_AUDIO1)) i -= 3; memcpy (index, sys_header->buf, i); index += i; sector->length_of_sector += i; } /* write constant packet header data */ *(index++) = (unsigned char)(PACKET_START)>>16; *(index++) = (unsigned char)(PACKET_START & 0x00ffff)>>8; *(index++) = (unsigned char)(PACKET_START & 0x0000ff); *(index++) = type; /* if it's a padding packet handle it here */ if (type == PADDING_STR) { i = 0; if (which_streams == STREAMS_AUDIO) i = 5; if (mplex_type > MPEG_VCD) data_bytes = packet_size + MPEG2_AFTER_PACKET_LENGTH - i; else data_bytes = packet_size + MPEG1_AFTER_PACKET_LENGTH - i; *(index++) = (unsigned char)(data_bytes >> 8); *(index++) = (unsigned char)(data_bytes & 0xff); if (mplex_type < MPEG_MPEG2) { *(index++) = 0x0F; for (j = 0; j < data_bytes - 1; j++) *(index++) = (unsigned char) STUFFING_BYTE; } else for (j = 0; j < data_bytes; j++) *(index++)=(unsigned char) STUFFING_BYTE; } else { /* if partial_packet_size != packet_data_size then write a padding packet after */ /* the data packet to keep the sector length constant. This is done as long as */ /* there is enough room for a padding packet (at least 7 bytes), if not, put in */ /* stuff_size stuffing bytes */ if (packet_size != partial_packet_size) { data_size = partial_packet_size; pad_size = packet_size - partial_packet_size; } else { data_size = packet_size; pad_size = 0; } /* check if we have enough data, if not increase stuffing/padding */ i = data_size; if (type == PRIVATE_STREAM1) i -= 4; /* four bytes less for AC3 data */ if (write_seq_hdr && sh_length) { data_bytes = sh_length; for (j = 0; j < data_bytes; j++) data_buffer[j] = seq_hdr[j]; } else data_bytes = 0; if (svcd_offset) { j = fread(&data_buffer[data_bytes], sizeof (unsigned char), svcd_offset, inputstream); data_bytes += j; if (j != (int)svcd_offset) pad_size += i - j; else { j = data_bytes; data_buffer[j++] = 0; data_buffer[j++] = 0; data_buffer[j++] = 1; data_buffer[j++] = 0xB2; /* user_data_start_code */ data_buffer[j++] = 0x10; /* tag_name = scan information */ data_buffer[j++] = 0x0E; /* U_length */ data_buffer[j++] = 0x00; data_buffer[j++] = 0x80; data_buffer[j++] = 0x80; /* Previous_I_offset */ data_buffer[j++] = 0x00; data_buffer[j++] = 0x80; data_buffer[j++] = 0x80; /* Next_I_offset */ data_buffer[j++] = 0x00; data_buffer[j++] = 0x80; data_buffer[j++] = 0x80; /* Backward_offset */ data_buffer[j++] = 0x00; data_buffer[j++] = 0x80; data_buffer[j++] = 0x80; /* Forward_offset */ data_bytes += 18; } } data_bytes += fread(&data_buffer[data_bytes], sizeof (unsigned char), i - data_bytes, inputstream); if (data_bytes != i) pad_size += i - data_bytes; if (write_seq_end && pad_size > 4) { data_buffer[data_bytes++] = 0; data_buffer[data_bytes++] = 0; data_buffer[data_bytes++] = 1; data_buffer[data_bytes++] = 0xB7; /* write in a sequence end code */ pad_size -= 4; } if (write_broken_link) { i = 0; k = 0xFFFFFFFF; while ((k != GROUP_START) && (i < data_bytes)) k = (k << 8) | data_buffer[i++]; if (k == GROUP_START) data_buffer[i + 3] = data_buffer[i + 3] | 0x20; } if (type == PRIVATE_STREAM1) data_bytes += 4; if (pad_size < 7) { stuff_size = pad_size; pad_size = 0; } else stuff_size = 0; if (mplex_type > MPEG_VCD) { i = 0; if (type != 0xE0) i = 5; *(index++) = (unsigned char)((data_bytes + stuff_size + MPEG2_AFTER_PACKET_LENGTH - i) >> 8); *(index++) = (unsigned char)((data_bytes + stuff_size + MPEG2_AFTER_PACKET_LENGTH - i) & 0xff); if (mplex_type == MPEG_SVCD) *(index++) = 0x81; /* set the original bit */ else *(index++) = 0x80; if (timestamps == TIMESTAMPS_NO) *(index++) = TIMESTAMPS_NO | buffers; else *(index++) = (timestamps << 6) | buffers; if (type == 0xE0) *(index++) = 13 + stuff_size; /* PES_header_data_length */ else *(index++) = 8 + stuff_size; /* PES_header_data_length without DTS's */ /* should we write PTS, PTS & DTS or nothing at all ? */ switch (timestamps) { case MPEG2_TIMESTAMPS_PTS: buffer_timecode(PTS, MARKER_JUST_PTS, &index); copy_timecode(PTS, §or->TS); break; case MPEG2_TIMESTAMPS_PTS_DTS: buffer_timecode(PTS, MARKER_PTS, &index); buffer_timecode(DTS, MPEG2_MARKER_DTS, &index); copy_timecode(DTS, §or->TS); break; } /* should we write buffer info ? */ if (buffers) { *(index++) = 0x1E; *(index++) = (unsigned char) (0x40 | (buffer_scale << 5) | (buffer_size >> 8)); *(index++) = (unsigned char) (buffer_size & 0xff); } i = stuff_size; if (timestamps == TIMESTAMPS_NO) { if (type == 0xE0) i += 10; else i += 5; } else if ((timestamps == MPEG2_TIMESTAMPS_PTS) && (type == 0xE0)) i += 5; if (!buffers) i += 3; for (j = 0; j < i; j++) *(index++)=(unsigned char) STUFFING_BYTE; } else { i = 0; if (type != 0xE0) i = 5; *(index++) = (unsigned char)((data_bytes + stuff_size + MPEG1_AFTER_PACKET_LENGTH - i) >> 8); *(index++) = (unsigned char)((data_bytes + stuff_size + MPEG1_AFTER_PACKET_LENGTH - i) & 0xff); i = stuff_size; if (!buffers)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -