* Parse a packet, add all split parts to parse_queue. * * @param pkt Packet to parse; must not be NULL. * @param flush Indicates whether to flush. If set, pkt must be blank. */
| 1176 | * @param flush Indicates whether to flush. If set, pkt must be blank. |
| 1177 | */ |
| 1178 | static int parse_packet(AVFormatContext *s, AVPacket *pkt, |
| 1179 | int stream_index, int flush) |
| 1180 | { |
| 1181 | FormatContextInternal *const fci = ff_fc_internal(s); |
| 1182 | AVStream *st = s->streams[stream_index]; |
| 1183 | FFStream *const sti = ffstream(st); |
| 1184 | AVPacket *out_pkt = sti->parse_pkt; |
| 1185 | const AVPacketSideData *sd = NULL; |
| 1186 | const uint8_t *data = pkt->data; |
| 1187 | uint8_t *extradata = sti->avctx->extradata; |
| 1188 | int extradata_size = sti->avctx->extradata_size; |
| 1189 | int size = pkt->size; |
| 1190 | int ret = 0, got_output = flush, pkt_side_data_consumed = 0; |
| 1191 | |
| 1192 | if (!size && !flush && sti->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) { |
| 1193 | // preserve 0-size sync packets |
| 1194 | compute_pkt_fields(s, st, sti->parser, pkt, pkt->dts, pkt->pts); |
| 1195 | |
| 1196 | // Theora has valid 0-sized packets that need to be output |
| 1197 | if (st->codecpar->codec_id == AV_CODEC_ID_THEORA) { |
| 1198 | ret = avpriv_packet_list_put(&fci->parse_queue, |
| 1199 | pkt, NULL, 0); |
| 1200 | if (ret < 0) |
| 1201 | goto fail; |
| 1202 | } |
| 1203 | } |
| 1204 | |
| 1205 | if (pkt->side_data_elems) |
| 1206 | sd = av_packet_side_data_get(pkt->side_data, pkt->side_data_elems, |
| 1207 | AV_PKT_DATA_NEW_EXTRADATA); |
| 1208 | if (sd) { |
| 1209 | av_assert1(size && !flush); |
| 1210 | |
| 1211 | sti->avctx->extradata = sd->data; |
| 1212 | sti->avctx->extradata_size = sd->size; |
| 1213 | } |
| 1214 | |
| 1215 | while (size > 0 || (flush && got_output)) { |
| 1216 | int64_t next_pts = pkt->pts; |
| 1217 | int64_t next_dts = pkt->dts; |
| 1218 | int len; |
| 1219 | |
| 1220 | len = av_parser_parse2(sti->parser, sti->avctx, |
| 1221 | &out_pkt->data, &out_pkt->size, data, size, |
| 1222 | pkt->pts, pkt->dts, pkt->pos); |
| 1223 | |
| 1224 | pkt->pts = pkt->dts = AV_NOPTS_VALUE; |
| 1225 | pkt->pos = -1; |
| 1226 | /* increment read pointer */ |
| 1227 | av_assert1(data || !len); |
| 1228 | data = len ? data + len : data; |
| 1229 | size -= len; |
| 1230 | |
| 1231 | got_output = !!out_pkt->size; |
| 1232 | |
| 1233 | if (pkt->side_data && !out_pkt->side_data) { |
| 1234 | /* for the first iteration, side_data are simply moved to output. |
| 1235 | * in case of additional iterations, they are duplicated each time. */ |
no test coverage detected