mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
avcodec/decode: use a packet list to store packet properties
Keeping only the latest packet fed to the decoder works only for decoders that return a frame immediately after every consumed packet. Decoders that consume several packets before they return a frame will fill said frame with properties taken from the last consumed packet instead of the earliest. Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
parent
8a81820624
commit
022a12b306
@ -43,6 +43,7 @@
|
|||||||
#include "decode.h"
|
#include "decode.h"
|
||||||
#include "hwconfig.h"
|
#include "hwconfig.h"
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
#include "packet_internal.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
|
|
||||||
typedef struct FramePool {
|
typedef struct FramePool {
|
||||||
@ -142,15 +143,24 @@ fail2:
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int extract_packet_props(AVCodecInternal *avci, const AVPacket *pkt)
|
#define IS_EMPTY(pkt) (!(pkt)->data)
|
||||||
|
|
||||||
|
static int extract_packet_props(AVCodecInternal *avci, AVPacket *pkt)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
av_packet_unref(avci->last_pkt_props);
|
ret = avpriv_packet_list_put(&avci->pkt_props, &avci->pkt_props_tail, pkt,
|
||||||
if (pkt) {
|
av_packet_copy_props, 0);
|
||||||
ret = av_packet_copy_props(avci->last_pkt_props, pkt);
|
if (ret < 0)
|
||||||
if (!ret)
|
return ret;
|
||||||
avci->last_pkt_props->size = pkt->size; // HACK: Needed for ff_decode_frame_props().
|
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().
|
||||||
|
|
||||||
|
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));
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -512,6 +522,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
|
|||||||
|
|
||||||
if (ret >= pkt->size || ret < 0) {
|
if (ret >= pkt->size || ret < 0) {
|
||||||
av_packet_unref(pkt);
|
av_packet_unref(pkt);
|
||||||
|
av_packet_unref(avci->last_pkt_props);
|
||||||
} else {
|
} else {
|
||||||
int consumed = ret;
|
int consumed = ret;
|
||||||
|
|
||||||
@ -550,9 +561,11 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
|
|||||||
|
|
||||||
av_assert0(!frame->buf[0]);
|
av_assert0(!frame->buf[0]);
|
||||||
|
|
||||||
if (avctx->codec->receive_frame)
|
if (avctx->codec->receive_frame) {
|
||||||
ret = avctx->codec->receive_frame(avctx, frame);
|
ret = avctx->codec->receive_frame(avctx, frame);
|
||||||
else
|
if (ret != AVERROR(EAGAIN))
|
||||||
|
av_packet_unref(avci->last_pkt_props);
|
||||||
|
} else
|
||||||
ret = decode_simple_receive_frame(avctx, frame);
|
ret = decode_simple_receive_frame(avctx, frame);
|
||||||
|
|
||||||
if (ret == AVERROR_EOF)
|
if (ret == AVERROR_EOF)
|
||||||
@ -1683,7 +1696,7 @@ static int add_metadata_from_side_data(const AVPacket *avpkt, AVFrame *frame)
|
|||||||
|
|
||||||
int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
|
int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
|
||||||
{
|
{
|
||||||
const AVPacket *pkt = avctx->internal->last_pkt_props;
|
AVPacket *pkt = avctx->internal->last_pkt_props;
|
||||||
int i;
|
int i;
|
||||||
static const struct {
|
static const struct {
|
||||||
enum AVPacketSideDataType packet;
|
enum AVPacketSideDataType packet;
|
||||||
@ -1701,6 +1714,11 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
|
|||||||
{ AV_PKT_DATA_S12M_TIMECODE, AV_FRAME_DATA_S12M_TIMECODE },
|
{ 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 (pkt) {
|
if (pkt) {
|
||||||
frame->pts = pkt->pts;
|
frame->pts = pkt->pts;
|
||||||
#if FF_API_PKT_PTS
|
#if FF_API_PKT_PTS
|
||||||
|
@ -145,6 +145,8 @@ typedef struct AVCodecInternal {
|
|||||||
* for decoding.
|
* for decoding.
|
||||||
*/
|
*/
|
||||||
AVPacket *last_pkt_props;
|
AVPacket *last_pkt_props;
|
||||||
|
AVPacketList *pkt_props;
|
||||||
|
AVPacketList *pkt_props_tail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* temporary buffer used for encoders to store their bitstream
|
* temporary buffer used for encoders to store their bitstream
|
||||||
|
@ -50,6 +50,7 @@
|
|||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "frame_thread_encoder.h"
|
#include "frame_thread_encoder.h"
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
#include "packet_internal.h"
|
||||||
#include "put_bits.h"
|
#include "put_bits.h"
|
||||||
#include "raw.h"
|
#include "raw.h"
|
||||||
#include "bytestream.h"
|
#include "bytestream.h"
|
||||||
@ -1149,6 +1150,8 @@ av_cold int avcodec_close(AVCodecContext *avctx)
|
|||||||
av_packet_free(&avctx->internal->compat_encode_packet);
|
av_packet_free(&avctx->internal->compat_encode_packet);
|
||||||
av_packet_free(&avctx->internal->buffer_pkt);
|
av_packet_free(&avctx->internal->buffer_pkt);
|
||||||
av_packet_free(&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_packet_free(&avctx->internal->ds.in_pkt);
|
av_packet_free(&avctx->internal->ds.in_pkt);
|
||||||
av_frame_free(&avctx->internal->es.in_frame);
|
av_frame_free(&avctx->internal->es.in_frame);
|
||||||
|
Loading…
Reference in New Issue
Block a user