@@ -58,6 +58,154 @@ class SrsMpegtsFrame
58
58
SrsMpegtsFrame ();
59
59
};
60
60
61
+ /* *
62
+ * the pid of ts packet,
63
+ * Table 2-3 ¨C PID table, hls-mpeg-ts-iso13818-1.pdf, page 37
64
+ */
65
+ enum SrsTsPid
66
+ {
67
+ // Program Association Table(see Table 2-25).
68
+ SrsTsPidPAT = 0x00 ,
69
+ // Conditional Access Table (see Table 2-27).
70
+ SrsTsPidCAT = 0x01 ,
71
+ // Transport Stream Description Table
72
+ SrsTsPidTSDT = 0x02 ,
73
+ // null packets (see Table 2-3)
74
+ SrsTsPidNULL = 0x01FFF ,
75
+ };
76
+
77
+ /* *
78
+ * the transport_scrambling_control of ts packet,
79
+ * Table 2-4 ¨C Scrambling control values, hls-mpeg-ts-iso13818-1.pdf, page 38
80
+ */
81
+ enum SrsTsScrambled
82
+ {
83
+ // Not scrambled
84
+ SrsTsScrambledDisabled = 0x00 ,
85
+ // User-defined
86
+ SrsTsScrambledUserDefined1 = 0x01 ,
87
+ // User-defined
88
+ SrsTsScrambledUserDefined2 = 0x02 ,
89
+ // User-defined
90
+ SrsTsScrambledUserDefined3 = 0x03 ,
91
+ };
92
+
93
+ /* *
94
+ * the adaption_field_control of ts packet,
95
+ * Table 2-5 ¨C Adaptation field control values, hls-mpeg-ts-iso13818-1.pdf, page 38
96
+ */
97
+ enum SrsTsAdaptationFieldType
98
+ {
99
+ // Reserved for future use by ISO/IEC
100
+ SrsTsAdaptationFieldTypeReserved = 0x00 ,
101
+ // No adaptation_field, payload only
102
+ SrsTsAdaptationFieldTypePayloadOnly = 0x01 ,
103
+ // Adaptation_field only, no payload
104
+ SrsTsAdaptationFieldTypeAdaptionOnly = 0x02 ,
105
+ // Adaptation_field followed by payload
106
+ SrsTsAdaptationFieldTypeBoth = 0x03 ,
107
+ };
108
+
109
+ class SrsTsAdaptationField
110
+ {
111
+ };
112
+
113
+ /* *
114
+ * the packet in ts stream,
115
+ * 2.4.3.2 Transport Stream packet layer, hls-mpeg-ts-iso13818-1.pdf, page 36
116
+ * Transport Stream packets shall be 188 bytes long.
117
+ */
118
+ class SrsTsPacket
119
+ {
120
+ private:
121
+ /* *
122
+ * The sync_byte is a fixed 8-bit field whose value is '0100 0111' (0x47). Sync_byte emulation in the choice of
123
+ * values for other regularly occurring fields, such as PID, should be avoided.
124
+ */
125
+ int8_t sync_byte; // 8bits
126
+ /* *
127
+ * The transport_error_indicator is a 1-bit flag. When set to '1' it indicates that at least
128
+ * 1 uncorrectable bit error exists in the associated Transport Stream packet. This bit may be set to '1' by entities external to
129
+ * the transport layer. When set to '1' this bit shall not be reset to '0' unless the bit value(s) in error have been corrected.
130
+ */
131
+ int8_t transport_error_indicator; // 1bit
132
+ /* *
133
+ * The payload_unit_start_indicator is a 1-bit flag which has normative meaning for
134
+ * Transport Stream packets that carry PES packets (refer to 2.4.3.6) or PSI data (refer to 2.4.4).
135
+ *
136
+ * When the payload of the Transport Stream packet contains PES packet data, the payload_unit_start_indicator has the
137
+ * following significance: a '1' indicates that the payload of this Transport Stream packet will commence with the first byte
138
+ * of a PES packet and a '0' indicates no PES packet shall start in this Transport Stream packet. If the
139
+ * payload_unit_start_indicator is set to '1', then one and only one PES packet starts in this Transport Stream packet. This
140
+ * also applies to private streams of stream_type 6 (refer to Table 2-29).
141
+ *
142
+ * When the payload of the Transport Stream packet contains PSI data, the payload_unit_start_indicator has the following
143
+ * significance: if the Transport Stream packet carries the first byte of a PSI section, the payload_unit_start_indicator value
144
+ * shall be '1', indicating that the first byte of the payload of this Transport Stream packet carries the pointer_field. If the
145
+ * Transport Stream packet does not carry the first byte of a PSI section, the payload_unit_start_indicator value shall be '0',
146
+ * indicating that there is no pointer_field in the payload. Refer to 2.4.4.1 and 2.4.4.2. This also applies to private streams of
147
+ * stream_type 5 (refer to Table 2-29).
148
+ *
149
+ * For null packets the payload_unit_start_indicator shall be set to '0'.
150
+ *
151
+ * The meaning of this bit for Transport Stream packets carrying only private data is not defined in this Specification.
152
+ */
153
+ int8_t payload_unit_start_indicator; // 1bit
154
+ /* *
155
+ * The transport_priority is a 1-bit indicator. When set to '1' it indicates that the associated packet is
156
+ * of greater priority than other packets having the same PID which do not have the bit set to '1'. The transport mechanism
157
+ * can use this to prioritize its data within an elementary stream. Depending on the application the transport_priority field
158
+ * may be coded regardless of the PID or within one PID only. This field may be changed by channel specific encoders or
159
+ * decoders.
160
+ */
161
+ int8_t transport_priority; // 1bit
162
+ /* *
163
+ * The PID is a 13-bit field, indicating the type of the data stored in the packet payload. PID value 0x0000 is
164
+ * reserved for the Program Association Table (see Table 2-25). PID value 0x0001 is reserved for the Conditional Access
165
+ * Table (see Table 2-27). PID values 0x0002 ¨C 0x000F are reserved. PID value 0x1FFF is reserved for null packets (see
166
+ * Table 2-3).
167
+ */
168
+ SrsTsPid pid; // 13bits
169
+ /* *
170
+ * This 2-bit field indicates the scrambling mode of the Transport Stream packet payload.
171
+ * The Transport Stream packet header, and the adaptation field when present, shall not be scrambled. In the case of a null
172
+ * packet the value of the transport_scrambling_control field shall be set to '00' (see Table 2-4).
173
+ */
174
+ SrsTsScrambled transport_scrambling_control; // 2bits
175
+ /* *
176
+ * This 2-bit field indicates whether this Transport Stream packet header is followed by an
177
+ * adaptation field and/or payload (see Table 2-5).
178
+ *
179
+ * ITU-T Rec. H.222.0 | ISO/IEC 13818-1 decoders shall discard Transport Stream packets with the
180
+ * adaptation_field_control field set to a value of '00'. In the case of a null packet the value of the adaptation_field_control
181
+ * shall be set to '01'.
182
+ */
183
+ SrsTsAdaptationFieldType adaption_field_control; // 2bits
184
+ /* *
185
+ * The continuity_counter is a 4-bit field incrementing with each Transport Stream packet with the
186
+ * same PID. The continuity_counter wraps around to 0 after its maximum value. The continuity_counter shall not be
187
+ *incremented when the adaptation_field_control of the packet equals '00' or '10'.
188
+ *
189
+ * In Transport Streams, duplicate packets may be sent as two, and only two, consecutive Transport Stream packets of the
190
+ * same PID. The duplicate packets shall have the same continuity_counter value as the original packet and the
191
+ * adaptation_field_control field shall be equal to '01' or '11'. In duplicate packets each byte of the original packet shall be
192
+ * duplicated, with the exception that in the program clock reference fields, if present, a valid value shall be encoded.
193
+ *
194
+ * The continuity_counter in a particular Transport Stream packet is continuous when it differs by a positive value of one
195
+ * from the continuity_counter value in the previous Transport Stream packet of the same PID, or when either of the nonincrementing
196
+ * conditions (adaptation_field_control set to '00' or '10', or duplicate packets as described above) are met.
197
+ * The continuity counter may be discontinuous when the discontinuity_indicator is set to '1' (refer to 2.4.3.4). In the case of
198
+ * a null packet the value of the continuity_counter is undefined.
199
+ */
200
+ u_int8_t continuity_counter; // 4bits
201
+ private:
202
+ SrsTsAdaptationField* adaptation_field;
203
+ public:
204
+ SrsTsPacket ();
205
+ virtual ~SrsTsPacket ();
206
+ public:
207
+ };
208
+
61
209
/* *
62
210
* write data from frame(header info) and buffer(data) to ts file.
63
211
* it's a simple object wrapper for utility from nginx-rtmp: SrsMpegtsWriter
0 commit comments