lavc/avcodec: switch to new FIFO API

release/5.1
Anton Khirnov 3 years ago committed by Andreas Rheinhardt
parent 93ed375574
commit 37e70d4802
  1. 17
      libavcodec/avcodec.c
  2. 24
      libavcodec/decode.c
  3. 2
      libavcodec/internal.h

@ -183,7 +183,8 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
avci->es.in_frame = av_frame_alloc(); avci->es.in_frame = av_frame_alloc();
avci->in_pkt = av_packet_alloc(); avci->in_pkt = av_packet_alloc();
avci->last_pkt_props = av_packet_alloc(); avci->last_pkt_props = av_packet_alloc();
avci->pkt_props = av_fifo_alloc(sizeof(*avci->last_pkt_props)); avci->pkt_props = av_fifo_alloc2(1, sizeof(*avci->last_pkt_props),
AV_FIFO_FLAG_AUTO_GROW);
if (!avci->buffer_frame || !avci->buffer_pkt || if (!avci->buffer_frame || !avci->buffer_pkt ||
!avci->es.in_frame || !avci->in_pkt || !avci->es.in_frame || !avci->in_pkt ||
!avci->last_pkt_props || !avci->pkt_props) { !avci->last_pkt_props || !avci->pkt_props) {
@ -399,13 +400,8 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
av_packet_unref(avci->buffer_pkt); av_packet_unref(avci->buffer_pkt);
av_packet_unref(avci->last_pkt_props); av_packet_unref(avci->last_pkt_props);
while (av_fifo_size(avci->pkt_props) >= sizeof(*avci->last_pkt_props)) { while (av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1) >= 0)
av_fifo_generic_read(avci->pkt_props,
avci->last_pkt_props, sizeof(*avci->last_pkt_props),
NULL);
av_packet_unref(avci->last_pkt_props); av_packet_unref(avci->last_pkt_props);
}
av_fifo_reset(avci->pkt_props);
av_frame_unref(avci->es.in_frame); av_frame_unref(avci->es.in_frame);
av_packet_unref(avci->in_pkt); av_packet_unref(avci->in_pkt);
@ -464,12 +460,11 @@ av_cold int avcodec_close(AVCodecContext *avctx)
av_frame_free(&avci->buffer_frame); av_frame_free(&avci->buffer_frame);
av_packet_free(&avci->buffer_pkt); av_packet_free(&avci->buffer_pkt);
if (avci->pkt_props) { if (avci->pkt_props) {
while (av_fifo_size(avci->pkt_props) >= sizeof(*avci->last_pkt_props)) { while (av_fifo_can_read(avci->pkt_props)) {
av_packet_unref(avci->last_pkt_props); av_packet_unref(avci->last_pkt_props);
av_fifo_generic_read(avci->pkt_props, avci->last_pkt_props, av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1);
sizeof(*avci->last_pkt_props), NULL);
} }
av_fifo_freep(&avci->pkt_props); av_fifo_freep2(&avci->pkt_props);
} }
av_packet_free(&avci->last_pkt_props); av_packet_free(&avci->last_pkt_props);

@ -165,26 +165,19 @@ static int extract_packet_props(AVCodecInternal *avci, const AVPacket *pkt)
int ret = 0; int ret = 0;
if (IS_EMPTY(avci->last_pkt_props)) { if (IS_EMPTY(avci->last_pkt_props)) {
if (av_fifo_size(avci->pkt_props) >= sizeof(*pkt)) { if (av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1) < 0)
av_fifo_generic_read(avci->pkt_props, avci->last_pkt_props,
sizeof(*avci->last_pkt_props), NULL);
} else
return copy_packet_props(avci->last_pkt_props, pkt); return copy_packet_props(avci->last_pkt_props, pkt);
} }
if (av_fifo_space(avci->pkt_props) < sizeof(*pkt)) {
ret = av_fifo_grow(avci->pkt_props, sizeof(*pkt));
if (ret < 0)
return ret;
}
ret = copy_packet_props(&tmp, pkt); ret = copy_packet_props(&tmp, pkt);
if (ret < 0) if (ret < 0)
return ret; return ret;
av_fifo_generic_write(avci->pkt_props, &tmp, sizeof(tmp), NULL); ret = av_fifo_write(avci->pkt_props, &tmp, 1);
if (ret < 0)
av_packet_unref(&tmp);
return 0; return ret;
} }
static int decode_bsfs_init(AVCodecContext *avctx) static int decode_bsfs_init(AVCodecContext *avctx)
@ -544,9 +537,10 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
avci->draining_done = 1; avci->draining_done = 1;
if (!(avctx->codec->caps_internal & FF_CODEC_CAP_SETS_FRAME_PROPS) && if (!(avctx->codec->caps_internal & FF_CODEC_CAP_SETS_FRAME_PROPS) &&
IS_EMPTY(avci->last_pkt_props) && av_fifo_size(avci->pkt_props) >= sizeof(*avci->last_pkt_props)) IS_EMPTY(avci->last_pkt_props)) {
av_fifo_generic_read(avci->pkt_props, // May fail if the FIFO is empty.
avci->last_pkt_props, sizeof(*avci->last_pkt_props), NULL); av_fifo_read(avci->pkt_props, avci->last_pkt_props, 1);
}
if (!ret) { if (!ret) {
frame->best_effort_timestamp = guess_correct_pts(avctx, frame->best_effort_timestamp = guess_correct_pts(avctx,

@ -149,7 +149,7 @@ typedef struct AVCodecInternal {
* for decoding. * for decoding.
*/ */
AVPacket *last_pkt_props; AVPacket *last_pkt_props;
AVFifoBuffer *pkt_props; AVFifo *pkt_props;
/** /**
* temporary buffer used for encoders to store their bitstream * temporary buffer used for encoders to store their bitstream

Loading…
Cancel
Save