Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Thilo Borgmann <thilo.borgmann@mail.de>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH v3 5/6] avcodec/webp: make init_canvas_frame static
Date: Fri, 21 Jul 2023 01:07:51 +0200
Message-ID: <20230720230752.68246-6-thilo.borgmann@mail.de> (raw)
In-Reply-To: <20230720230752.68246-1-thilo.borgmann@mail.de>

---
 libavcodec/webp.c | 143 +++++++++++++++++++++++-----------------------
 1 file changed, 71 insertions(+), 72 deletions(-)

diff --git a/libavcodec/webp.c b/libavcodec/webp.c
index 8cc417af36..277f2c58bb 100644
--- a/libavcodec/webp.c
+++ b/libavcodec/webp.c
@@ -1351,7 +1351,77 @@ static int vp8_lossy_decode_frame(AVCodecContext *avctx, AVFrame *p,
     }
     return ret;
 }
-int init_canvas_frame(WebPContext *s, int format, int key_frame);
+
+static int init_canvas_frame(WebPContext *s, int format, int key_frame)
+{
+    AVFrame *canvas = s->canvas_frame.f;
+    int height;
+    int ret;
+
+    // canvas is needed only for animation
+    if (!(s->vp8x_flags & VP8X_FLAG_ANIMATION))
+        return 0;
+
+    // avoid init for non-key frames whose format and size did not change
+    if (!key_frame &&
+        canvas->data[0] &&
+        canvas->format == format &&
+        canvas->width  == s->canvas_width &&
+        canvas->height == s->canvas_height)
+        return 0;
+
+    // canvas changes within IPPP sequences will lose thread sync
+    // because of the ThreadFrame reallocation and will wait forever
+    // so if frame-threading is used, forbid canvas changes and unlock
+    // previous frames
+    if (!key_frame && canvas->data[0]) {
+        if (s->avctx->thread_count > 1) {
+            av_log(s->avctx, AV_LOG_WARNING, "Canvas change detected. The output will be damaged. Use -threads 1 to try decoding with best effort.\n");
+            // unlock previous frames that have sent an _await() call
+            ff_thread_report_progress(&s->canvas_frame, INT_MAX, 0);
+            return AVERROR_PATCHWELCOME;
+        } else {
+            // warn for damaged frames
+            av_log(s->avctx, AV_LOG_WARNING, "Canvas change detected. The output will be damaged.\n");
+        }
+    }
+
+    s->avctx->pix_fmt = format;
+    canvas->format    = format;
+    canvas->width     = s->canvas_width;
+    canvas->height    = s->canvas_height;
+
+    // VP8 decoder changed the width and height in AVCodecContext.
+    // Change it back to the canvas size.
+    ret = ff_set_dimensions(s->avctx, s->canvas_width, s->canvas_height);
+    if (ret < 0)
+        return ret;
+
+    ff_thread_release_ext_buffer(s->avctx, &s->canvas_frame);
+    ret = ff_thread_get_ext_buffer(s->avctx, &s->canvas_frame, AV_GET_BUFFER_FLAG_REF);
+    if (ret < 0)
+        return ret;
+
+    if (canvas->format == AV_PIX_FMT_ARGB) {
+        height = canvas->height;
+        memset(canvas->data[0], 0, height * canvas->linesize[0]);
+    } else /* if (canvas->format == AV_PIX_FMT_YUVA420P) */ {
+        const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(canvas->format);
+        for (int comp = 0; comp < desc->nb_components; comp++) {
+            int plane = desc->comp[comp].plane;
+
+            if (comp == 1 || comp == 2)
+                height = AV_CEIL_RSHIFT(canvas->height, desc->log2_chroma_h);
+            else
+                height = FFALIGN(canvas->height, 1 << desc->log2_chroma_h);
+
+            memset(canvas->data[plane], s->transparent_yuva[plane],
+                   height * canvas->linesize[plane]);
+        }
+    }
+
+    return 0;
+}
 
 static int webp_decode_frame_common(AVCodecContext *avctx, uint8_t *data, int size,
                                     int *got_frame, int key_frame)
@@ -1590,77 +1660,6 @@ exif_end:
     return size;
 }
 
-int init_canvas_frame(WebPContext *s, int format, int key_frame)
-{
-    AVFrame *canvas = s->canvas_frame.f;
-    int height;
-    int ret;
-
-    // canvas is needed only for animation
-    if (!(s->vp8x_flags & VP8X_FLAG_ANIMATION))
-        return 0;
-
-    // avoid init for non-key frames whose format and size did not change
-    if (!key_frame &&
-        canvas->data[0] &&
-        canvas->format == format &&
-        canvas->width  == s->canvas_width &&
-        canvas->height == s->canvas_height)
-        return 0;
-
-    // canvas changes within IPPP sequences will loose thread sync
-    // because of the ThreadFrame reallocation and will wait forever
-    // so if frame-threading is used, forbid canvas changes and unlock
-    // previous frames
-    if (!key_frame && canvas->data[0]) {
-        if (s->avctx->thread_count > 1) {
-            av_log(s->avctx, AV_LOG_WARNING, "Canvas change detected. The output will be damaged. Use -threads 1 to try decoding with best effort.\n");
-            // unlock previous frames that have sent an _await() call
-            ff_thread_report_progress(&s->canvas_frame, INT_MAX, 0);
-            return AVERROR_PATCHWELCOME;
-        } else {
-            // warn for damaged frames
-            av_log(s->avctx, AV_LOG_WARNING, "Canvas change detected. The output will be damaged.\n");
-        }
-    }
-
-    s->avctx->pix_fmt = format;
-    canvas->format    = format;
-    canvas->width     = s->canvas_width;
-    canvas->height    = s->canvas_height;
-
-    // VP8 decoder changed the width and height in AVCodecContext.
-    // Change it back to the canvas size.
-    ret = ff_set_dimensions(s->avctx, s->canvas_width, s->canvas_height);
-    if (ret < 0)
-        return ret;
-
-    ff_thread_release_ext_buffer(s->avctx, &s->canvas_frame);
-    ret = ff_thread_get_ext_buffer(s->avctx, &s->canvas_frame, AV_GET_BUFFER_FLAG_REF);
-    if (ret < 0)
-        return ret;
-
-    if (canvas->format == AV_PIX_FMT_ARGB) {
-        height = canvas->height;
-        memset(canvas->data[0], 0, height * canvas->linesize[0]);
-    } else /* if (canvas->format == AV_PIX_FMT_YUVA420P) */ {
-        const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(canvas->format);
-        for (int comp = 0; comp < desc->nb_components; comp++) {
-            int plane = desc->comp[comp].plane;
-
-            if (comp == 1 || comp == 2)
-                height = AV_CEIL_RSHIFT(canvas->height, desc->log2_chroma_h);
-            else
-                height = FFALIGN(canvas->height, 1 << desc->log2_chroma_h);
-
-            memset(canvas->data[plane], s->transparent_yuva[plane],
-                   height * canvas->linesize[plane]);
-        }
-    }
-
-    return 0;
-}
-
 /*
  * Blend src1 (foreground) and src2 (background) into dest, in ARGB format.
  * width, height are the dimensions of src1
-- 
2.37.1 (Apple Git-137.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".

  parent reply	other threads:[~2023-07-20 23:08 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-20 23:07 [FFmpeg-devel] [PATCH v3 0/6] webp: add support for animated WebP decoding Thilo Borgmann
2023-07-20 23:07 ` [FFmpeg-devel] [PATCH v3 1/6] avcodec/webp: move definitions into header Thilo Borgmann
2023-07-20 23:07 ` [FFmpeg-devel] [PATCH v3 2/6] avcodec/webp: remove unused definitions Thilo Borgmann
2023-07-20 23:07 ` [FFmpeg-devel] [PATCH v3 3/6] avcodec/webp_parser: parse each frame into one packet Thilo Borgmann
2023-07-20 23:07 ` [FFmpeg-devel] [PATCH v3 4/6] libavcodec/webp: add support for animated WebP decoding Thilo Borgmann
2023-07-20 23:07 ` Thilo Borgmann [this message]
2023-07-20 23:07 ` [FFmpeg-devel] [PATCH v3 6/6] libavformat/webp: add WebP demuxer Thilo Borgmann
2023-07-24 20:44 ` [FFmpeg-devel] [PATCH v3 0/6] webp: add support for animated WebP decoding James Zern
2023-07-25  8:59   ` Thilo Borgmann

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=20230720230752.68246-6-thilo.borgmann@mail.de \
    --to=thilo.borgmann@mail.de \
    --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