History

Revert "avcodec/decode: use a packet list to store packet properties"

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.

James Almer committed 3 years ago

Commit b1fdb0b1 parent c06e88e4 files · +8 −52Browse files

Unified · Split

4 files
  1. libavcodec/avcodec.c +0 −10
  2. libavcodec/decode.c +7 −40
  3. libavcodec/internal.h +0 −1
  4. tests/ref/fate/flcl1905 +1 −1
libavcodec/avcodec.c+0−10
@@ -386,9 +386,6 @@ void avcodec_flush_buffers(AVCodecContext *avctx) · 385 unmodified lines
386 av_frame_unref(avci->recon_frame);386 av_frame_unref(avci->recon_frame);
387 } else {387 } else {
388 av_packet_unref(avci->last_pkt_props);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 av_packet_unref(avci->in_pkt);389 av_packet_unref(avci->in_pkt);
393 390
394 avctx->pts_correction_last_pts =391 avctx->pts_correction_last_pts =
@@ -453,13 +450,6 @@ av_cold int avcodec_close(AVCodecContext *avctx) · 58 unmodified lines
453 av_freep(&avci->byte_buffer);450 av_freep(&avci->byte_buffer);
454 av_frame_free(&avci->buffer_frame);451 av_frame_free(&avci->buffer_frame);
455 av_packet_free(&avci->buffer_pkt);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 av_packet_free(&avci->last_pkt_props);453 av_packet_free(&avci->last_pkt_props);
464 454
465 av_packet_free(&avci->in_pkt);455 av_packet_free(&avci->in_pkt);
libavcodec/decode.c+7−40
@@ -132,38 +132,16 @@ fail2: · 131 unmodified lines
132 return 0;132 return 0;
133}133}
134 134
135#define IS_EMPTY(pkt) (!(pkt)->data)
136
137static 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
149static int extract_packet_props(AVCodecInternal *avci, const AVPacket *pkt)135static int extract_packet_props(AVCodecInternal *avci, const AVPacket *pkt)
150{136{
151 AVPacket tmp = { 0 };
152 int ret = 0;137 int ret = 0;
153 138
154 if (IS_EMPTY(avci->last_pkt_props)) {139 av_packet_unref(avci->last_pkt_props);
155 if (av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1) < 0)140 if (pkt) {
156 return copy_packet_props(avci->last_pkt_props, 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 return ret;145 return ret;
168}146}
169 147
@@ -483,7 +461,6 @@ FF_ENABLE_DEPRECATION_WARNINGS · 313 unmodified lines
483 461
484 if (ret >= pkt->size || ret < 0) {462 if (ret >= pkt->size || ret < 0) {
485 av_packet_unref(pkt);463 av_packet_unref(pkt);
486 av_packet_unref(avci->last_pkt_props);
487 } else {464 } else {
488 int consumed = ret;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 if (codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_FRAME) {556 if (codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_FRAME) {
580 ret = codec->cb.receive_frame(avctx, frame);557 ret = codec->cb.receive_frame(avctx, frame);
581 if (ret != AVERROR(EAGAIN))
582 av_packet_unref(avci->last_pkt_props);
583 } else558 } else
584 ret = decode_simple_receive_frame(avctx, frame);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 return ok;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 if (!ret) {571 if (!ret) {
603 frame->best_effort_timestamp = guess_correct_pts(avctx,572 frame->best_effort_timestamp = guess_correct_pts(avctx,
604 frame->pts,573 frame->pts,
@@ -1293,7 +1262,7 @@ static int add_metadata_from_side_data(const AVPacket *avpkt, AVFrame *frame) · 688 unmodified lines
1293 1262
1294int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)1263int 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 static const struct {1266 static const struct {
1298 enum AVPacketSideDataType packet;1267 enum AVPacketSideDataType packet;
1299 enum AVFrameSideDataType frame;1268 enum AVFrameSideDataType frame;
@@ -1651,9 +1620,7 @@ FF_ENABLE_DEPRECATION_WARNINGS · 351 unmodified lines
1651 1620
1652 avci->in_pkt = av_packet_alloc();1621 avci->in_pkt = av_packet_alloc();
1653 avci->last_pkt_props = av_packet_alloc();1622 avci->last_pkt_props = av_packet_alloc();
1654 avci->pkt_props = av_fifo_alloc2(1, sizeof(*avci->last_pkt_props),1623 if (!avci->in_pkt || !avci->last_pkt_props)
1655 AV_FIFO_FLAG_AUTO_GROW);
1656 if (!avci->in_pkt || !avci->last_pkt_props || !avci->pkt_props)
1657 return AVERROR(ENOMEM);1624 return AVERROR(ENOMEM);
1658 1625
1659 ret = decode_bsfs_init(avctx);1626 ret = decode_bsfs_init(avctx);
libavcodec/internal.h+0−1
@@ -88,7 +88,6 @@ typedef struct AVCodecInternal { · 87 unmodified lines
88 * for decoding.88 * for decoding.
89 */89 */
90 AVPacket *last_pkt_props;90 AVPacket *last_pkt_props;
91 struct AVFifo *pkt_props;
92 91
93 /**92 /**
94 * temporary buffer used for encoders to store their bitstream93 * temporary buffer used for encoders to store their bitstream
tests/ref/fate/flcl1905+1−1
@@ -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
189frame|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=unknown189frame|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
190frame|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=unknown190frame|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
191packet|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_191packet|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_
192frame|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=unknown192frame|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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t