diff mbox

[FFmpeg-devel,3/5] avcodec/hevc_refs: Optimize 16bit generate_missing_ref()

Message ID 20190806213006.25210-3-michael@niedermayer.cc
State Accepted
Commit da8936969fe695a042282d5686e12227745d299a
Headers show

Commit Message

Michael Niedermayer Aug. 6, 2019, 9:30 p.m. UTC
Fixes: Timeout (86sec -> 8sec)
Fixes: 15702/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_HEVC_fuzzer-5657764929470464

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/hevc_refs.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Comments

Paul B Mahol Aug. 11, 2019, 10:51 a.m. UTC | #1
LGTM

On Tue, Aug 6, 2019 at 11:32 PM Michael Niedermayer <michael@niedermayer.cc>
wrote:

> Fixes: Timeout (86sec -> 8sec)
> Fixes:
> 15702/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_HEVC_fuzzer-5657764929470464
>
> Found-by: continuous fuzzing process
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by
> <https://github.com/google/oss-fuzz/tree/master/projects/ffmpegSigned-off-by>:
> Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/hevc_refs.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c
> index 7cf3a55725..7870a72fd6 100644
> --- a/libavcodec/hevc_refs.c
> +++ b/libavcodec/hevc_refs.c
> @@ -394,7 +394,7 @@ static void mark_ref(HEVCFrame *frame, int flag)
>  static HEVCFrame *generate_missing_ref(HEVCContext *s, int poc)
>  {
>      HEVCFrame *frame;
> -    int i, x, y;
> +    int i, y;
>
>      frame = alloc_frame(s);
>      if (!frame)
> @@ -407,11 +407,11 @@ static HEVCFrame *generate_missing_ref(HEVCContext
> *s, int poc)
>                         frame->frame->buf[i]->size);
>          } else {
>              for (i = 0; frame->frame->data[i]; i++)
> -                for (y = 0; y < (s->ps.sps->height >>
> s->ps.sps->vshift[i]); y++)
> -                    for (x = 0; x < (s->ps.sps->width >>
> s->ps.sps->hshift[i]); x++) {
> -                        AV_WN16(frame->frame->data[i] + y *
> frame->frame->linesize[i] + 2 * x,
> -                                1 << (s->ps.sps->bit_depth - 1));
> -                    }
> +                for (y = 0; y < (s->ps.sps->height >>
> s->ps.sps->vshift[i]); y++) {
> +                    uint8_t *dst = frame->frame->data[i] + y *
> frame->frame->linesize[i];
> +                    AV_WN16(dst, 1 << (s->ps.sps->bit_depth - 1));
> +                    av_memcpy_backptr(dst + 2, 2, 2*(s->ps.sps->width >>
> s->ps.sps->hshift[i]) - 2);
> +                }
>          }
>      }
>
> --
> 2.22.0
>
> _______________________________________________
> 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".
Michael Niedermayer Aug. 11, 2019, 3:27 p.m. UTC | #2
On Sun, Aug 11, 2019 at 12:51:59PM +0200, Paul B Mahol wrote:
> LGTM

will apply

thx

[...]
diff mbox

Patch

diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c
index 7cf3a55725..7870a72fd6 100644
--- a/libavcodec/hevc_refs.c
+++ b/libavcodec/hevc_refs.c
@@ -394,7 +394,7 @@  static void mark_ref(HEVCFrame *frame, int flag)
 static HEVCFrame *generate_missing_ref(HEVCContext *s, int poc)
 {
     HEVCFrame *frame;
-    int i, x, y;
+    int i, y;
 
     frame = alloc_frame(s);
     if (!frame)
@@ -407,11 +407,11 @@  static HEVCFrame *generate_missing_ref(HEVCContext *s, int poc)
                        frame->frame->buf[i]->size);
         } else {
             for (i = 0; frame->frame->data[i]; i++)
-                for (y = 0; y < (s->ps.sps->height >> s->ps.sps->vshift[i]); y++)
-                    for (x = 0; x < (s->ps.sps->width >> s->ps.sps->hshift[i]); x++) {
-                        AV_WN16(frame->frame->data[i] + y * frame->frame->linesize[i] + 2 * x,
-                                1 << (s->ps.sps->bit_depth - 1));
-                    }
+                for (y = 0; y < (s->ps.sps->height >> s->ps.sps->vshift[i]); y++) {
+                    uint8_t *dst = frame->frame->data[i] + y * frame->frame->linesize[i];
+                    AV_WN16(dst, 1 << (s->ps.sps->bit_depth - 1));
+                    av_memcpy_backptr(dst + 2, 2, 2*(s->ps.sps->width >> s->ps.sps->hshift[i]) - 2);
+                }
         }
     }