Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] avcodec/ffv1: Only allocate ThreadFrames for the decoder
@ 2022-09-04 23:28 Andreas Rheinhardt
  2022-09-06  1:34 ` Andreas Rheinhardt
  0 siblings, 1 reply; 2+ messages in thread
From: Andreas Rheinhardt @ 2022-09-04 23:28 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

The FFV1 decoder only uses the last frame's data to conceal
errors. The encoder does not have this problem and therefore
only uses the current frame and none of the ThreadFrames.
So only allocate them for the decoder.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/ffv1.c    | 13 -------------
 libavcodec/ffv1dec.c | 23 ++++++++++++++++++++++-
 2 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
index c8781cdaaa..b6204740ed 100644
--- a/libavcodec/ffv1.c
+++ b/libavcodec/ffv1.c
@@ -43,11 +43,6 @@ av_cold int ff_ffv1_common_init(AVCodecContext *avctx)
     s->avctx = avctx;
     s->flags = avctx->flags;
 
-    s->picture.f = av_frame_alloc();
-    s->last_picture.f = av_frame_alloc();
-    if (!s->picture.f || !s->last_picture.f)
-        return AVERROR(ENOMEM);
-
     s->width  = avctx->width;
     s->height = avctx->height;
 
@@ -198,14 +193,6 @@ av_cold int ff_ffv1_close(AVCodecContext *avctx)
     FFV1Context *s = avctx->priv_data;
     int i, j;
 
-    if (s->picture.f)
-        ff_thread_release_ext_buffer(avctx, &s->picture);
-    av_frame_free(&s->picture.f);
-
-    if (s->last_picture.f)
-        ff_thread_release_ext_buffer(avctx, &s->last_picture);
-    av_frame_free(&s->last_picture.f);
-
     for (j = 0; j < s->max_slice_count; j++) {
         FFV1Context *fs = s->slice_context[j];
         for (i = 0; i < s->plane_count; i++) {
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 794c58cc40..d4bc60a7da 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -823,6 +823,11 @@ static av_cold int decode_init(AVCodecContext *avctx)
     if ((ret = ff_ffv1_common_init(avctx)) < 0)
         return ret;
 
+    f->picture.f      = av_frame_alloc();
+    f->last_picture.f = av_frame_alloc();
+    if (!f->picture.f || !f->last_picture.f)
+        return AVERROR(ENOMEM);
+
     if (avctx->extradata_size > 0 && (ret = read_extra_header(f)) < 0)
         return ret;
 
@@ -1068,6 +1073,22 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
 }
 #endif
 
+static av_cold int ffv1_decode_close(AVCodecContext *avctx)
+{
+    FFV1Context *const s = avctx->priv_data;
+
+    if (s->picture.f) {
+        ff_thread_release_ext_buffer(avctx, &s->picture);
+        av_frame_free(&s->picture.f);
+    }
+
+    if (s->last_picture.f) {
+        ff_thread_release_ext_buffer(avctx, &s->last_picture);
+        av_frame_free(&s->last_picture.f);
+    }
+    return ff_ffv1_close(avctx);
+}
+
 const FFCodec ff_ffv1_decoder = {
     .p.name         = "ffv1",
     CODEC_LONG_NAME("FFmpeg video codec #1"),
@@ -1075,7 +1096,7 @@ const FFCodec ff_ffv1_decoder = {
     .p.id           = AV_CODEC_ID_FFV1,
     .priv_data_size = sizeof(FFV1Context),
     .init           = decode_init,
-    .close          = ff_ffv1_close,
+    .close          = ffv1_decode_close,
     FF_CODEC_DECODE_CB(decode_frame),
     UPDATE_THREAD_CONTEXT(update_thread_context),
     .p.capabilities = AV_CODEC_CAP_DR1 /*| AV_CODEC_CAP_DRAW_HORIZ_BAND*/ |
-- 
2.34.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".

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avcodec/ffv1: Only allocate ThreadFrames for the decoder
  2022-09-04 23:28 [FFmpeg-devel] [PATCH] avcodec/ffv1: Only allocate ThreadFrames for the decoder Andreas Rheinhardt
@ 2022-09-06  1:34 ` Andreas Rheinhardt
  0 siblings, 0 replies; 2+ messages in thread
From: Andreas Rheinhardt @ 2022-09-06  1:34 UTC (permalink / raw)
  To: ffmpeg-devel

Andreas Rheinhardt:
> The FFV1 decoder only uses the last frame's data to conceal
> errors. The encoder does not have this problem and therefore
> only uses the current frame and none of the ThreadFrames.
> So only allocate them for the decoder.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavcodec/ffv1.c    | 13 -------------
>  libavcodec/ffv1dec.c | 23 ++++++++++++++++++++++-
>  2 files changed, 22 insertions(+), 14 deletions(-)
> 
> diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
> index c8781cdaaa..b6204740ed 100644
> --- a/libavcodec/ffv1.c
> +++ b/libavcodec/ffv1.c
> @@ -43,11 +43,6 @@ av_cold int ff_ffv1_common_init(AVCodecContext *avctx)
>      s->avctx = avctx;
>      s->flags = avctx->flags;
>  
> -    s->picture.f = av_frame_alloc();
> -    s->last_picture.f = av_frame_alloc();
> -    if (!s->picture.f || !s->last_picture.f)
> -        return AVERROR(ENOMEM);
> -
>      s->width  = avctx->width;
>      s->height = avctx->height;
>  
> @@ -198,14 +193,6 @@ av_cold int ff_ffv1_close(AVCodecContext *avctx)
>      FFV1Context *s = avctx->priv_data;
>      int i, j;
>  
> -    if (s->picture.f)
> -        ff_thread_release_ext_buffer(avctx, &s->picture);
> -    av_frame_free(&s->picture.f);
> -
> -    if (s->last_picture.f)
> -        ff_thread_release_ext_buffer(avctx, &s->last_picture);
> -    av_frame_free(&s->last_picture.f);
> -
>      for (j = 0; j < s->max_slice_count; j++) {
>          FFV1Context *fs = s->slice_context[j];
>          for (i = 0; i < s->plane_count; i++) {
> diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
> index 794c58cc40..d4bc60a7da 100644
> --- a/libavcodec/ffv1dec.c
> +++ b/libavcodec/ffv1dec.c
> @@ -823,6 +823,11 @@ static av_cold int decode_init(AVCodecContext *avctx)
>      if ((ret = ff_ffv1_common_init(avctx)) < 0)
>          return ret;
>  
> +    f->picture.f      = av_frame_alloc();
> +    f->last_picture.f = av_frame_alloc();
> +    if (!f->picture.f || !f->last_picture.f)
> +        return AVERROR(ENOMEM);
> +
>      if (avctx->extradata_size > 0 && (ret = read_extra_header(f)) < 0)
>          return ret;
>  
> @@ -1068,6 +1073,22 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
>  }
>  #endif
>  
> +static av_cold int ffv1_decode_close(AVCodecContext *avctx)
> +{
> +    FFV1Context *const s = avctx->priv_data;
> +
> +    if (s->picture.f) {
> +        ff_thread_release_ext_buffer(avctx, &s->picture);
> +        av_frame_free(&s->picture.f);
> +    }
> +
> +    if (s->last_picture.f) {
> +        ff_thread_release_ext_buffer(avctx, &s->last_picture);
> +        av_frame_free(&s->last_picture.f);
> +    }
> +    return ff_ffv1_close(avctx);
> +}
> +
>  const FFCodec ff_ffv1_decoder = {
>      .p.name         = "ffv1",
>      CODEC_LONG_NAME("FFmpeg video codec #1"),
> @@ -1075,7 +1096,7 @@ const FFCodec ff_ffv1_decoder = {
>      .p.id           = AV_CODEC_ID_FFV1,
>      .priv_data_size = sizeof(FFV1Context),
>      .init           = decode_init,
> -    .close          = ff_ffv1_close,
> +    .close          = ffv1_decode_close,
>      FF_CODEC_DECODE_CB(decode_frame),
>      UPDATE_THREAD_CONTEXT(update_thread_context),
>      .p.capabilities = AV_CODEC_CAP_DR1 /*| AV_CODEC_CAP_DRAW_HORIZ_BAND*/ |

Will apply this tomorrow unless there are objections.

- Andreas
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-06  1:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-04 23:28 [FFmpeg-devel] [PATCH] avcodec/ffv1: Only allocate ThreadFrames for the decoder Andreas Rheinhardt
2022-09-06  1:34 ` Andreas Rheinhardt

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