MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / mpegts_push_data

Function mpegts_push_data

libavformat/mpegts.c:1177–1466  ·  view source on GitHub ↗

return non zero if a packet could be constructed */

Source from the content-addressed store, hash-verified

1175
1176/* return non zero if a packet could be constructed */
1177static int mpegts_push_data(MpegTSFilter *filter,
1178 const uint8_t *buf, int buf_size, int is_start,
1179 int64_t pos)
1180{
1181 PESContext *pes = filter->u.pes_filter.opaque;
1182 MpegTSContext *ts = pes->ts;
1183 const uint8_t *p;
1184 int ret, len;
1185
1186 if (!ts->pkt)
1187 return 0;
1188
1189 if (is_start) {
1190 if (pes->state == MPEGTS_PAYLOAD && pes->data_index > 0) {
1191 ret = new_pes_packet(pes, ts->pkt);
1192 if (ret < 0)
1193 return ret;
1194 ts->stop_parse = 1;
1195 } else {
1196 reset_pes_packet_state(pes);
1197 }
1198 pes->state = MPEGTS_HEADER;
1199 pes->ts_packet_pos = pos;
1200 }
1201 p = buf;
1202 while (buf_size > 0) {
1203 switch (pes->state) {
1204 case MPEGTS_HEADER:
1205 len = PES_START_SIZE - pes->data_index;
1206 if (len > buf_size)
1207 len = buf_size;
1208 memcpy(pes->header + pes->data_index, p, len);
1209 pes->data_index += len;
1210 p += len;
1211 buf_size -= len;
1212 if (pes->data_index == PES_START_SIZE) {
1213 /* we got all the PES or section header. We can now
1214 * decide */
1215 if (pes->header[0] == 0x00 && pes->header[1] == 0x00 &&
1216 pes->header[2] == 0x01) {
1217 /* it must be an MPEG-2 PES stream */
1218 pes->stream_id = pes->header[3];
1219 av_log(pes->stream, AV_LOG_TRACE, "pid=%x stream_id=%#x\n", pes->pid, pes->stream_id);
1220
1221 if ((pes->st && pes->st->discard == AVDISCARD_ALL &&
1222 (!pes->sub_st ||
1223 pes->sub_st->discard == AVDISCARD_ALL)) ||
1224 pes->stream_id == STREAM_ID_PADDING_STREAM)
1225 goto skip;
1226
1227 /* stream not present in PMT */
1228 if (!pes->st) {
1229 if (ts->skip_changes)
1230 goto skip;
1231 if (ts->merge_pmt_versions)
1232 goto skip; /* wait for PMT to merge new stream */
1233
1234 pes->st = avformat_new_stream(ts->stream, NULL);

Callers

nothing calls this directly

Calls 10

new_pes_packetFunction · 0.85
reset_pes_packet_stateFunction · 0.85
av_logFunction · 0.85
avformat_new_streamFunction · 0.85
mpegts_set_stream_infoFunction · 0.85
ffstreamFunction · 0.85
ff_parse_pes_ptsFunction · 0.85
read_sl_headerFunction · 0.85
buffer_pool_getFunction · 0.85

Tested by

no test coverage detected