return non zero if a packet could be constructed */
| 1175 | |
| 1176 | /* return non zero if a packet could be constructed */ |
| 1177 | static 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); |
nothing calls this directly
no test coverage detected