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
386386 av_frame_unref(avci->recon_frame);
387387 } else {
388388 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−
392389 av_packet_unref(avci->in_pkt);
393390
394391 avctx->pts_correction_last_pts =
@@ -453,13 +450,6 @@ av_cold int avcodec_close(AVCodecContext *avctx) · 58 unmodified lines
453450 av_freep(&avci->byte_buffer);
454451 av_frame_free(&avci->buffer_frame);
455452 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− }
463453 av_packet_free(&avci->last_pkt_props);
464454
465455 av_packet_free(&avci->in_pkt);
libavcodec/decode.c+7−40
@@ -132,38 +132,16 @@ fail2: · 131 unmodified lines
132132 return 0;
133133 }
134134
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−
149135 static int extract_packet_props(AVCodecInternal *avci, const AVPacket *pkt)
150136 {
151− AVPacket tmp = { 0 };
152137 int ret = 0;
153138
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().
157144 }
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−
167145 return ret;
168146 }
169147
@@ -483,7 +461,6 @@ FF_ENABLE_DEPRECATION_WARNINGS · 313 unmodified lines
483461
484462 if (ret >= pkt->size || ret < 0) {
485463 av_packet_unref(pkt);
486− av_packet_unref(avci->last_pkt_props);
487464 } else {
488465 int consumed = ret;
489466
@@ -578,8 +555,6 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) · 88 unmodified lines
578555
579556 if (codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_FRAME) {
580557 ret = codec->cb.receive_frame(avctx, frame);
581− if (ret != AVERROR(EAGAIN))
582− av_packet_unref(avci->last_pkt_props);
583558 } else
584559 ret = decode_simple_receive_frame(avctx, frame);
585560
@@ -593,12 +568,6 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) · 7 unmodified lines
593568 return ok;
594569 }
595570
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−
602571 if (!ret) {
603572 frame->best_effort_timestamp = guess_correct_pts(avctx,
604573 frame->pts,
@@ -1293,7 +1262,7 @@ static int add_metadata_from_side_data(const AVPacket *avpkt, AVFrame *frame) · 688 unmodified lines
12931262
12941263 int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
12951264 {
1296− AVPacket *pkt = avctx->internal->last_pkt_props;
1265+ const AVPacket *pkt = avctx->internal->last_pkt_props;
12971266 static const struct {
12981267 enum AVPacketSideDataType packet;
12991268 enum AVFrameSideDataType frame;
@@ -1651,9 +1620,7 @@ FF_ENABLE_DEPRECATION_WARNINGS · 351 unmodified lines
16511620
16521621 avci->in_pkt = av_packet_alloc();
16531622 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)
16571624 return AVERROR(ENOMEM);
16581625
16591626 ret = decode_bsfs_init(avctx);
libavcodec/internal.h+0−1
@@ -88,7 +88,6 @@ typedef struct AVCodecInternal { · 87 unmodified lines
8888 * for decoding.
8989 */
9090 AVPacket *last_pkt_props;
91− struct AVFifo *pkt_props;
9291
9392 /**
9493 * 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
189189 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
190190 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
191191 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

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