Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: James Almer <jamrial@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 2/4] avcodec/decode: allow the decoder to signal an unrecoverable error was found
Date: Tue, 22 Nov 2022 10:07:30 -0300
Message-ID: <20221122130732.403-2-jamrial@gmail.com> (raw)
In-Reply-To: <20221122130732.403-1-jamrial@gmail.com>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/avcodec.c  |  1 +
 libavcodec/decode.c   | 17 ++++++++++++++++-
 libavcodec/internal.h |  5 +++++
 3 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index a85d3c2309..7818b6e33b 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -397,6 +397,7 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
         av_bsf_flush(avci->bsf);
     }
 
+    avci->fatal         = 0;
     avci->draining      = 0;
     avci->draining_done = 0;
     avci->nb_draining_errors = 0;
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 6be2d3d6ed..04c9d374ce 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -576,7 +576,9 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
 
     av_assert0(!frame->buf[0]);
 
-    if (codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_FRAME) {
+    if (avci->fatal) {
+        ret = avci->draining ? AVERROR_EOF : AVERROR_UNRECOVERABLE;
+    } else if (codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_FRAME) {
         ret = codec->cb.receive_frame(avctx, frame);
         if (ret != AVERROR(EAGAIN))
             av_packet_unref(avci->last_pkt_props);
@@ -586,6 +588,9 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
     if (ret == AVERROR_EOF)
         avci->draining_done = 1;
 
+    if (ret == AVERROR_UNRECOVERABLE)
+        avci->fatal = 1;
+
     /* preserve ret */
     ok = detect_colorspace(avctx, frame);
     if (ok < 0) {
@@ -648,6 +653,16 @@ int attribute_align_arg avcodec_send_packet(AVCodecContext *avctx, const AVPacke
     if (avpkt && !avpkt->size && avpkt->data)
         return AVERROR(EINVAL);
 
+    if (avctx->internal->fatal) {
+        /* The API expects EOF signaling to always be handled even with
+         * decoding errors */
+        if (!avpkt || (!avpkt->data && !avpkt->side_data_elems)) {
+            avctx->internal->draining = 1;
+            return 0;
+        }
+        return AVERROR_UNRECOVERABLE;
+    }
+
     av_packet_unref(avci->buffer_pkt);
     if (avpkt && (avpkt->data || avpkt->side_data_elems)) {
         ret = av_packet_ref(avci->buffer_pkt, avpkt);
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index 76a6ea6bc6..622f5728e2 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -142,6 +142,11 @@ typedef struct AVCodecInternal {
      */
     int draining;
 
+    /**
+     * An unrecoverable error was found, decoding can't proceed normally
+     */
+    int fatal;
+
     /**
      * Temporary buffers for newly received or not yet output packets/frames.
      */
-- 
2.38.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  reply	other threads:[~2022-11-22 13:09 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-22 13:07 [FFmpeg-devel] [PATCH 1/4] avutil/error: add a new error to signal processing got into an unrecoverable state James Almer
2022-11-22 13:07 ` James Almer [this message]
2022-11-22 13:07 ` [FFmpeg-devel] [PATCH 3/4] avutil/cuda_check: propagate AVERROR_UNRECOVERABLE when needed James Almer
2022-11-22 13:21   ` Timo Rothenpieler
2022-11-22 13:31     ` James Almer
2022-11-22 14:33       ` Soft Works
2022-11-22 14:41         ` James Almer
2022-11-22 14:55           ` Soft Works
2022-11-22 18:08           ` Soft Works
2022-11-22 14:48         ` Andreas Rheinhardt
2022-11-22 14:59           ` Soft Works
2022-11-22 15:15       ` Timo Rothenpieler
2022-11-22 16:02         ` Soft Works
2022-11-22 22:59           ` Timo Rothenpieler
2022-11-22 23:49             ` Soft Works
2022-11-22 13:07 ` [FFmpeg-devel] [PATCH 4/4] fftools/ffmpeg: handle decoders returning AVERROR_UNRECOVERABLE James Almer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221122130732.403-2-jamrial@gmail.com \
    --to=jamrial@gmail.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git