The idea behind last_pkt_props was to store the properties of the last packet fed to the decoder. Any sort of queueing required by CODEC_CAP_DELAY decoders that consume several packets before they start outputting frames should be done by the decoders in question. An example of this is libdav1d. This is required for the following commits that will fix last_pkt_props in frame threading scenarios, as well as maintain its contents during flush. This revers commit 022a12b306ab2096e6ac9fc9b149828a849d65b2.
Unified · Split
| @@ -386,9 +386,6 @@ void avcodec_flush_buffers(AVCodecContext *avctx) · 385 unmodified lines | ||
| 386 | 386 | av_frame_unref(avci->recon_frame); |
| 387 | 387 | } else { |
| 388 | 388 | av_packet_unref(avci->last_pkt_props); |
| 389 | − while (av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1) >= 0) | |
| 390 | − av_packet_unref(avci->last_pkt_props); | |
| 391 | − | |
| 392 | 389 | av_packet_unref(avci->in_pkt); |
| 393 | 390 | |
| 394 | 391 | avctx->pts_correction_last_pts = |
| @@ -453,13 +450,6 @@ av_cold int avcodec_close(AVCodecContext *avctx) · 58 unmodified lines | ||
| 453 | 450 | av_freep(&avci->byte_buffer); |
| 454 | 451 | av_frame_free(&avci->buffer_frame); |
| 455 | 452 | av_packet_free(&avci->buffer_pkt); |
| 456 | − if (avci->pkt_props) { | |
| 457 | − while (av_fifo_can_read(avci->pkt_props)) { | |
| 458 | − av_packet_unref(avci->last_pkt_props); | |
| 459 | − av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1); | |
| 460 | − } | |
| 461 | − av_fifo_freep2(&avci->pkt_props); | |
| 462 | − } | |
| 463 | 453 | av_packet_free(&avci->last_pkt_props); |
| 464 | 454 | |
| 465 | 455 | av_packet_free(&avci->in_pkt); |
| @@ -132,38 +132,16 @@ fail2: · 131 unmodified lines | ||
| 132 | 132 | return 0; |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | −#define IS_EMPTY(pkt) (!(pkt)->data) | |
| 136 | − | |
| 137 | −static int copy_packet_props(AVPacket *dst, const AVPacket *src) | |
| 138 | −{ | |
| 139 | − int ret = av_packet_copy_props(dst, src); | |
| 140 | − if (ret < 0) | |
| 141 | − return ret; | |
| 142 | − | |
| 143 | − dst->size = src->size; // HACK: Needed for ff_decode_frame_props(). | |
| 144 | − dst->data = (void*)1; // HACK: Needed for IS_EMPTY(). | |
| 145 | − | |
| 146 | − return 0; | |
| 147 | −} | |
| 148 | − | |
| 149 | 135 | static int extract_packet_props(AVCodecInternal *avci, const AVPacket *pkt) |
| 150 | 136 | { |
| 151 | − AVPacket tmp = { 0 }; | |
| 152 | 137 | int ret = 0; |
| 153 | 138 | |
| 154 | − if (IS_EMPTY(avci->last_pkt_props)) { | |
| 155 | − if (av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1) < 0) | |
| 156 | − return copy_packet_props(avci->last_pkt_props, pkt); | |
| 139 | + av_packet_unref(avci->last_pkt_props); | |
| 140 | + if (pkt) { | |
| 141 | + ret = av_packet_copy_props(avci->last_pkt_props, pkt); | |
| 142 | + if (!ret) | |
| 143 | + avci->last_pkt_props->size = pkt->size; // HACK: Needed for ff_decode_frame_props(). | |
| 157 | 144 | } |
| 158 | − | |
| 159 | − ret = copy_packet_props(&tmp, pkt); | |
| 160 | − if (ret < 0) | |
| 161 | − return ret; | |
| 162 | − | |
| 163 | − ret = av_fifo_write(avci->pkt_props, &tmp, 1); | |
| 164 | − if (ret < 0) | |
| 165 | − av_packet_unref(&tmp); | |
| 166 | − | |
| 167 | 145 | return ret; |
| 168 | 146 | } |
| 169 | 147 | |
| @@ -483,7 +461,6 @@ FF_ENABLE_DEPRECATION_WARNINGS · 313 unmodified lines | ||
| 483 | 461 | |
| 484 | 462 | if (ret >= pkt->size || ret < 0) { |
| 485 | 463 | av_packet_unref(pkt); |
| 486 | − av_packet_unref(avci->last_pkt_props); | |
| 487 | 464 | } else { |
| 488 | 465 | int consumed = ret; |
| 489 | 466 | |
| @@ -578,8 +555,6 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) · 88 unmodified lines | ||
| 578 | 555 | |
| 579 | 556 | if (codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_FRAME) { |
| 580 | 557 | ret = codec->cb.receive_frame(avctx, frame); |
| 581 | − if (ret != AVERROR(EAGAIN)) | |
| 582 | − av_packet_unref(avci->last_pkt_props); | |
| 583 | 558 | } else |
| 584 | 559 | ret = decode_simple_receive_frame(avctx, frame); |
| 585 | 560 | |
| @@ -593,12 +568,6 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) · 7 unmodified lines | ||
| 593 | 568 | return ok; |
| 594 | 569 | } |
| 595 | 570 | |
| 596 | − if (!(codec->caps_internal & FF_CODEC_CAP_SETS_FRAME_PROPS) && | |
| 597 | − IS_EMPTY(avci->last_pkt_props)) { | |
| 598 | − // May fail if the FIFO is empty. | |
| 599 | − av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1); | |
| 600 | − } | |
| 601 | − | |
| 602 | 571 | if (!ret) { |
| 603 | 572 | frame->best_effort_timestamp = guess_correct_pts(avctx, |
| 604 | 573 | frame->pts, |
| @@ -1293,7 +1262,7 @@ static int add_metadata_from_side_data(const AVPacket *avpkt, AVFrame *frame) · 688 unmodified lines | ||
| 1293 | 1262 | |
| 1294 | 1263 | int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame) |
| 1295 | 1264 | { |
| 1296 | − AVPacket *pkt = avctx->internal->last_pkt_props; | |
| 1265 | + const AVPacket *pkt = avctx->internal->last_pkt_props; | |
| 1297 | 1266 | static const struct { |
| 1298 | 1267 | enum AVPacketSideDataType packet; |
| 1299 | 1268 | enum AVFrameSideDataType frame; |
| @@ -1651,9 +1620,7 @@ FF_ENABLE_DEPRECATION_WARNINGS · 351 unmodified lines | ||
| 1651 | 1620 | |
| 1652 | 1621 | avci->in_pkt = av_packet_alloc(); |
| 1653 | 1622 | avci->last_pkt_props = av_packet_alloc(); |
| 1654 | − avci->pkt_props = av_fifo_alloc2(1, sizeof(*avci->last_pkt_props), | |
| 1655 | − AV_FIFO_FLAG_AUTO_GROW); | |
| 1656 | − if (!avci->in_pkt || !avci->last_pkt_props || !avci->pkt_props) | |
| 1623 | + if (!avci->in_pkt || !avci->last_pkt_props) | |
| 1657 | 1624 | return AVERROR(ENOMEM); |
| 1658 | 1625 | |
| 1659 | 1626 | ret = decode_bsfs_init(avctx); |
| @@ -88,7 +88,6 @@ typedef struct AVCodecInternal { · 87 unmodified lines | ||
| 88 | 88 | * for decoding. |
| 89 | 89 | */ |
| 90 | 90 | AVPacket *last_pkt_props; |
| 91 | − struct AVFifo *pkt_props; | |
| 92 | 91 | |
| 93 | 92 | /** |
| 94 | 93 | * temporary buffer used for encoders to store their bitstream |
| @@ -189,4 +189,4 @@ frame|media_type=audio|stream_index=0|key_frame=1|pts=N/A|pts_time=N/A|pkt_dts=N · 188 unmodified lines | ||
| 189 | 189 | frame|media_type=audio|stream_index=0|key_frame=1|pts=N/A|pts_time=N/A|pkt_dts=N/A|pkt_dts_time=N/A|best_effort_timestamp=N/A|best_effort_timestamp_time=N/A|pkt_duration=22528|pkt_duration_time=0.510839|duration=22528|duration_time=0.510839|pkt_pos=61436|pkt_size=744|sample_fmt=fltp|nb_samples=2048|channels=2|channel_layout=unknown |
| 190 | 190 | frame|media_type=audio|stream_index=0|key_frame=1|pts=N/A|pts_time=N/A|pkt_dts=N/A|pkt_dts_time=N/A|best_effort_timestamp=N/A|best_effort_timestamp_time=N/A|pkt_duration=22528|pkt_duration_time=0.510839|duration=22528|duration_time=0.510839|pkt_pos=61436|pkt_size=372|sample_fmt=fltp|nb_samples=2048|channels=2|channel_layout=unknown |
| 191 | 191 | packet|codec_type=audio|stream_index=0|pts=360448|pts_time=8.173424|dts=360448|dts_time=8.173424|duration=44|duration_time=0.000998|size=8|pos=65528|flags=K_ |
| 192 | −frame|media_type=audio|stream_index=0|key_frame=1|pts=N/A|pts_time=N/A|pkt_dts=N/A|pkt_dts_time=N/A|best_effort_timestamp=N/A|best_effort_timestamp_time=N/A|pkt_duration=N/A|pkt_duration_time=N/A|duration=N/A|duration_time=N/A|pkt_pos=N/A|pkt_size=0|sample_fmt=fltp|nb_samples=2048|channels=2|channel_layout=unknown | |
| 192 | +frame|media_type=audio|stream_index=0|key_frame=1|pts=N/A|pts_time=N/A|pkt_dts=N/A|pkt_dts_time=N/A|best_effort_timestamp=N/A|best_effort_timestamp_time=N/A|pkt_duration=44|pkt_duration_time=0.000998|duration=44|duration_time=0.000998|pkt_pos=65528|pkt_size=8|sample_fmt=fltp|nb_samples=2048|channels=2|channel_layout=unknown | |