1 2 /* 3 * interact.h: Program/System stream packet generator 4 * 5 * Copyright (C) 2003 Andrew Stevens <andrew.stevens@philips.com> 6 * 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of version 2 of the GNU General Public License 10 * as published by the Free Software Foundation. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 */ 21 22 #ifndef __SYSTEMS_HH__ 23 #define __SYSTEMS_HH__ 24 25 #include "inputstrm.hpp" 26 #include "outputstrm.hpp" 27 #include <vector> 28 29 using std::vector; 30 31 /* Buffer size parameters */ 32 33 #define MAX_SECTOR_SIZE 16384 34 #define MAX_PACK_HEADER_SIZE 255 35 #define MAX_SYS_HEADER_SIZE 255 36 37 38 typedef struct sector_struc /* Ein Sektor, kann Pack, Sys Header */ 39 /* und Packet enthalten. */ 40 { unsigned char buf [MAX_SECTOR_SIZE] ; 41 unsigned int length_of_packet_data ; 42 //clockticks TS ; 43 } Sector_struc; 44 45 struct Pack_struc /* Pack Info */ 46 { 47 uint8_t buf[MAX_PACK_HEADER_SIZE]; 48 int length; 49 clockticks SCR; 50 }; 51 52 struct Sys_header_struc /* System Header Info */ 53 { 54 uint8_t buf[MAX_SYS_HEADER_SIZE]; 55 int length; 56 }; 57 58 59 class PS_Stream 60 { 61 public: 62 PS_Stream( unsigned _mpeg, 63 unsigned int _sector_size, 64 OutputStream &_output_strm, 65 off_t max_segment_size // 0 = No Limit 66 ); 67 virtual ~PS_Stream(); 68 69 unsigned int PacketPayload( MuxStream &strm, 70 Sys_header_struc *sys_header, 71 Pack_struc *pack_header, 72 int buffers, int PTSstamp, int DTSstamp ); 73 74 unsigned int CreateSector (Pack_struc *pack, 75 Sys_header_struc *sys_header, 76 unsigned int max_packet_data_size, 77 MuxStream &strm, 78 bool buffers, 79 bool end_marker, 80 clockticks PTS, 81 clockticks DTS, 82 uint8_t timestamps 83 ); 84 static void BufferSectorHeader( uint8_t *buf, 85 Pack_struc *pack, 86 Sys_header_struc *sys_header, 87 uint8_t *&header_end ); 88 static void BufferPacketHeader( uint8_t *buf, 89 uint8_t type, 90 unsigned int mpeg_version, 91 bool buffers, 92 unsigned int buffer_size, 93 uint8_t buffer_scale, 94 clockticks PTS, 95 clockticks DTS, 96 uint8_t timestamps, 97 unsigned int min_pes_hdr_len, 98 uint8_t *&size_field, 99 uint8_t *&header_end ); 100 101 static inline void BufferPacketSize(uint8_t * size_field,uint8_t * packet_end)102 BufferPacketSize( uint8_t *size_field, uint8_t *packet_end ) 103 { 104 unsigned int packet_size = packet_end-size_field-2; 105 size_field[0] = static_cast<uint8_t>(packet_size>>8); 106 size_field[1] = static_cast<uint8_t>(packet_size&0xff); 107 108 } 109 110 virtual void CreatePack ( Pack_struc *pack, 111 clockticks SCR, 112 unsigned int mux_rate 113 ); 114 virtual void CreateSysHeader ( Sys_header_struc *sys_header, 115 unsigned int rate_bound, 116 bool fixed, 117 int CSPS, 118 bool audio_lock, 119 bool video_lock, 120 vector<MuxStream *> &streams 121 ); 122 Open()123 inline int Open() { return output_strm.Open(); } Close()124 inline void Close() { output_strm.Close(); } RawWrite(uint8_t * data,unsigned int len)125 inline void RawWrite(uint8_t *data, unsigned int len) 126 { 127 return output_strm.Write( data, len ); 128 } NextSegment()129 inline void NextSegment() { output_strm.NextSegment(); } 130 bool SegmentLimReached(); 131 132 133 private: 134 static void 135 BufferDtsPtsMpeg1ScrTimecode (clockticks timecode, 136 uint8_t marker, 137 uint8_t *&buffer); 138 static void BufferMpeg2ScrTimecode( clockticks timecode, 139 uint8_t *&buffer); 140 void BufferPaddingPacket( int padding, 141 uint8_t *&buffer ); 142 private: 143 OutputStream &output_strm; 144 unsigned int mpeg_version; 145 unsigned int sector_size; 146 off_t max_segment_size; 147 uint8_t *sector_buf; 148 }; 149 #endif // __SYSTEMS_HH__ 150 151 152 /* 153 * Local variables: 154 * c-file-style: "stroustrup" 155 * tab-width: 4 156 * indent-tabs-mode: nil 157 * End: 158 */ 159