You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-15 14:13:16 +02:00
avcodec/v4l2_m2m_dec: fix dropped packets while decoding
* FFmpeg retrieves a packet from the bitstream * It attempts to get an input buffer (from its own list or by dequeuing one from the driver) * If no input buffer is found, the bitstream packet is dropped instead of scheduled for trying again later It's an issue that showed especially at high speeds (like using `-f null -` as output parameters). Signed-off-by: Aman Gupta <aman@tmm1.net>
This commit is contained in:
committed by
Aman Gupta
parent
fac834b2ae
commit
584ac1ad0b
@@ -56,6 +56,7 @@ typedef struct V4L2m2mContext {
|
|||||||
|
|
||||||
/* null frame/packet received */
|
/* null frame/packet received */
|
||||||
int draining;
|
int draining;
|
||||||
|
AVPacket buf_pkt;
|
||||||
|
|
||||||
/* Reference to self; only valid while codec is active. */
|
/* Reference to self; only valid while codec is active. */
|
||||||
AVBufferRef *self_ref;
|
AVBufferRef *self_ref;
|
||||||
|
@@ -133,9 +133,14 @@ static int v4l2_receive_frame(AVCodecContext *avctx, AVFrame *frame)
|
|||||||
AVPacket avpkt = {0};
|
AVPacket avpkt = {0};
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = ff_decode_get_packet(avctx, &avpkt);
|
if (s->buf_pkt.size) {
|
||||||
if (ret < 0 && ret != AVERROR_EOF)
|
avpkt = s->buf_pkt;
|
||||||
return ret;
|
memset(&s->buf_pkt, 0, sizeof(AVPacket));
|
||||||
|
} else {
|
||||||
|
ret = ff_decode_get_packet(avctx, &avpkt);
|
||||||
|
if (ret < 0 && ret != AVERROR_EOF)
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
if (s->draining)
|
if (s->draining)
|
||||||
goto dequeue;
|
goto dequeue;
|
||||||
@@ -144,6 +149,8 @@ static int v4l2_receive_frame(AVCodecContext *avctx, AVFrame *frame)
|
|||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (ret != AVERROR(EAGAIN))
|
if (ret != AVERROR(EAGAIN))
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
s->buf_pkt = avpkt;
|
||||||
/* no input buffers available, continue dequeing */
|
/* no input buffers available, continue dequeing */
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,7 +168,8 @@ static int v4l2_receive_frame(AVCodecContext *avctx, AVFrame *frame)
|
|||||||
}
|
}
|
||||||
|
|
||||||
dequeue:
|
dequeue:
|
||||||
av_packet_unref(&avpkt);
|
if (!s->buf_pkt.size)
|
||||||
|
av_packet_unref(&avpkt);
|
||||||
return ff_v4l2_context_dequeue_frame(capture, frame, -1);
|
return ff_v4l2_context_dequeue_frame(capture, frame, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,7 +215,10 @@ static av_cold int v4l2_decode_init(AVCodecContext *avctx)
|
|||||||
|
|
||||||
static av_cold int v4l2_decode_close(AVCodecContext *avctx)
|
static av_cold int v4l2_decode_close(AVCodecContext *avctx)
|
||||||
{
|
{
|
||||||
return ff_v4l2_m2m_codec_end(avctx->priv_data);
|
V4L2m2mPriv *priv = avctx->priv_data;
|
||||||
|
V4L2m2mContext* s = priv->context;
|
||||||
|
av_packet_unref(&s->buf_pkt);
|
||||||
|
return ff_v4l2_m2m_codec_end(priv);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define OFFSET(x) offsetof(V4L2m2mPriv, x)
|
#define OFFSET(x) offsetof(V4L2m2mPriv, x)
|
||||||
|
Reference in New Issue
Block a user