mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
avcodec/decode: port last_pkt_props to AVFifoBuffer
Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
parent
7819412f44
commit
b34d1de8dc
@ -43,7 +43,6 @@
|
||||
#include "decode.h"
|
||||
#include "hwconfig.h"
|
||||
#include "internal.h"
|
||||
#include "packet_internal.h"
|
||||
#include "thread.h"
|
||||
|
||||
typedef struct FramePool {
|
||||
@ -145,24 +144,44 @@ fail2:
|
||||
|
||||
#define IS_EMPTY(pkt) (!(pkt)->data)
|
||||
|
||||
static int extract_packet_props(AVCodecInternal *avci, AVPacket *pkt)
|
||||
static int copy_packet_props(AVPacket *dst, AVPacket *src)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
ret = avpriv_packet_list_put(&avci->pkt_props, &avci->pkt_props_tail, pkt,
|
||||
av_packet_copy_props, 0);
|
||||
int ret = av_packet_copy_props(dst, src);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
avci->pkt_props_tail->pkt.size = pkt->size; // HACK: Needed for ff_decode_frame_props().
|
||||
avci->pkt_props_tail->pkt.data = (void*)1; // HACK: Needed for IS_EMPTY().
|
||||
|
||||
dst->size = src->size; // HACK: Needed for ff_decode_frame_props().
|
||||
dst->data = (void*)1; // HACK: Needed for IS_EMPTY().
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int extract_packet_props(AVCodecInternal *avci, AVPacket *pkt)
|
||||
{
|
||||
AVPacket tmp = { 0 };
|
||||
int ret = 0;
|
||||
|
||||
if (IS_EMPTY(avci->last_pkt_props)) {
|
||||
ret = avpriv_packet_list_get(&avci->pkt_props,
|
||||
&avci->pkt_props_tail,
|
||||
avci->last_pkt_props);
|
||||
av_assert0(ret != AVERROR(EAGAIN));
|
||||
if (av_fifo_size(avci->pkt_props) >= sizeof(*pkt)) {
|
||||
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 ret;
|
||||
|
||||
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);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
av_fifo_generic_write(avci->pkt_props, &tmp, sizeof(tmp), NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ff_decode_bsfs_init(AVCodecContext *avctx)
|
||||
@ -1726,10 +1745,9 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
|
||||
{ AV_PKT_DATA_S12M_TIMECODE, AV_FRAME_DATA_S12M_TIMECODE },
|
||||
};
|
||||
|
||||
if (IS_EMPTY(pkt))
|
||||
avpriv_packet_list_get(&avctx->internal->pkt_props,
|
||||
&avctx->internal->pkt_props_tail,
|
||||
pkt);
|
||||
if (IS_EMPTY(pkt) && av_fifo_size(avctx->internal->pkt_props) >= sizeof(*pkt))
|
||||
av_fifo_generic_read(avctx->internal->pkt_props,
|
||||
pkt, sizeof(*pkt), NULL);
|
||||
|
||||
if (pkt) {
|
||||
frame->pts = pkt->pts;
|
||||
|
@ -28,6 +28,7 @@
|
||||
|
||||
#include "libavutil/buffer.h"
|
||||
#include "libavutil/channel_layout.h"
|
||||
#include "libavutil/fifo.h"
|
||||
#include "libavutil/mathematics.h"
|
||||
#include "libavutil/pixfmt.h"
|
||||
#include "avcodec.h"
|
||||
@ -147,8 +148,7 @@ typedef struct AVCodecInternal {
|
||||
* for decoding.
|
||||
*/
|
||||
AVPacket *last_pkt_props;
|
||||
AVPacketList *pkt_props;
|
||||
AVPacketList *pkt_props_tail;
|
||||
AVFifoBuffer *pkt_props;
|
||||
|
||||
/**
|
||||
* temporary buffer used for encoders to store their bitstream
|
||||
|
@ -50,7 +50,6 @@
|
||||
#include "thread.h"
|
||||
#include "frame_thread_encoder.h"
|
||||
#include "internal.h"
|
||||
#include "packet_internal.h"
|
||||
#include "put_bits.h"
|
||||
#include "raw.h"
|
||||
#include "bytestream.h"
|
||||
@ -594,9 +593,10 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
|
||||
avci->es.in_frame = av_frame_alloc();
|
||||
avci->ds.in_pkt = av_packet_alloc();
|
||||
avci->last_pkt_props = av_packet_alloc();
|
||||
avci->pkt_props = av_fifo_alloc(sizeof(*avci->last_pkt_props));
|
||||
if (!avci->buffer_frame || !avci->buffer_pkt ||
|
||||
!avci->es.in_frame || !avci->ds.in_pkt ||
|
||||
!avci->last_pkt_props) {
|
||||
!avci->last_pkt_props || !avci->pkt_props) {
|
||||
ret = AVERROR(ENOMEM);
|
||||
goto free_and_end;
|
||||
}
|
||||
@ -1077,7 +1077,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
|
||||
#endif
|
||||
av_frame_free(&avci->buffer_frame);
|
||||
av_packet_free(&avci->buffer_pkt);
|
||||
av_packet_free(&avci->last_pkt_props);
|
||||
av_fifo_freep(&avci->pkt_props);
|
||||
|
||||
av_packet_free(&avci->ds.in_pkt);
|
||||
av_frame_free(&avci->es.in_frame);
|
||||
@ -1120,8 +1120,13 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
|
||||
av_packet_unref(avci->buffer_pkt);
|
||||
|
||||
av_packet_unref(avci->last_pkt_props);
|
||||
avpriv_packet_list_free(&avci->pkt_props,
|
||||
&avci->pkt_props_tail);
|
||||
while (av_fifo_size(avci->pkt_props) >= sizeof(*avci->last_pkt_props)) {
|
||||
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_fifo_reset(avci->pkt_props);
|
||||
|
||||
av_frame_unref(avci->es.in_frame);
|
||||
av_packet_unref(avci->ds.in_pkt);
|
||||
@ -1189,9 +1194,17 @@ av_cold int avcodec_close(AVCodecContext *avctx)
|
||||
#endif
|
||||
av_frame_free(&avctx->internal->buffer_frame);
|
||||
av_packet_free(&avctx->internal->buffer_pkt);
|
||||
av_packet_unref(avctx->internal->last_pkt_props);
|
||||
while (av_fifo_size(avctx->internal->pkt_props) >=
|
||||
sizeof(*avctx->internal->last_pkt_props)) {
|
||||
av_fifo_generic_read(avctx->internal->pkt_props,
|
||||
avctx->internal->last_pkt_props,
|
||||
sizeof(*avctx->internal->last_pkt_props),
|
||||
NULL);
|
||||
av_packet_unref(avctx->internal->last_pkt_props);
|
||||
}
|
||||
av_packet_free(&avctx->internal->last_pkt_props);
|
||||
avpriv_packet_list_free(&avctx->internal->pkt_props,
|
||||
&avctx->internal->pkt_props_tail);
|
||||
av_fifo_freep(&avctx->internal->pkt_props);
|
||||
|
||||
av_packet_free(&avctx->internal->ds.in_pkt);
|
||||
av_frame_free(&avctx->internal->es.in_frame);
|
||||
|
Loading…
Reference in New Issue
Block a user