diff mbox

[FFmpeg-devel] avcodec/ffv1dec_template: Optimize common case in run mode

Message ID 20190522234628.17299-1-michael@niedermayer.cc
State Accepted
Commit e6f4d5dc384af334a5c7b61969db9d7d9c1b7e0a
Headers show

Commit Message

Michael Niedermayer May 22, 2019, 11:46 p.m. UTC
Fixes: Timeout (14sec -> 9sec)
Fixes: 13398/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_FFV1_fuzzer-5664106709778432

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

Comments

Carl Eugen Hoyos May 23, 2019, 8:57 a.m. UTC | #1
Am Do., 23. Mai 2019 um 01:47 Uhr schrieb Michael Niedermayer
<michael@niedermayer.cc>:
>
> Fixes: Timeout (14sec -> 9sec)
> Fixes: 13398/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_FFV1_fuzzer-5664106709778432
>
> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/ffv1dec_template.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/libavcodec/ffv1dec_template.c b/libavcodec/ffv1dec_template.c
> index 1b7f6c4bf5..0b1d176ba1 100644
> --- a/libavcodec/ffv1dec_template.c
> +++ b/libavcodec/ffv1dec_template.c
> @@ -86,11 +86,19 @@ static av_always_inline int RENAME(decode_line)(FFV1Context *s, int w,
>                          run_mode = 2;
>                      }
>                  }
> +                if (sample[1][x - 1] == sample[0][x - 1]) {
> +                    while (run_count > 1 && w-x > 1) {
> +                        sample[1][x] = sample[0][x];
> +                        x++;
> +                        run_count--;
> +                    }
> +                } else {

Does this change have a measurable effect on your usual sample files?

Carl Eugen
Michael Niedermayer May 23, 2019, 8:36 p.m. UTC | #2
On Thu, May 23, 2019 at 10:57:14AM +0200, Carl Eugen Hoyos wrote:
> Am Do., 23. Mai 2019 um 01:47 Uhr schrieb Michael Niedermayer
> <michael@niedermayer.cc>:
> >
> > Fixes: Timeout (14sec -> 9sec)
> > Fixes: 13398/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_FFV1_fuzzer-5664106709778432
> >
> > Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >  libavcodec/ffv1dec_template.c | 8 ++++++++
> >  1 file changed, 8 insertions(+)
> >
> > diff --git a/libavcodec/ffv1dec_template.c b/libavcodec/ffv1dec_template.c
> > index 1b7f6c4bf5..0b1d176ba1 100644
> > --- a/libavcodec/ffv1dec_template.c
> > +++ b/libavcodec/ffv1dec_template.c
> > @@ -86,11 +86,19 @@ static av_always_inline int RENAME(decode_line)(FFV1Context *s, int w,
> >                          run_mode = 2;
> >                      }
> >                  }
> > +                if (sample[1][x - 1] == sample[0][x - 1]) {
> > +                    while (run_count > 1 && w-x > 1) {
> > +                        sample[1][x] = sample[0][x];
> > +                        x++;
> > +                        run_count--;
> > +                    }
> > +                } else {
> 
> Does this change have a measurable effect on your usual sample files?

decode_line() becomes 1% faster for fate/vsynth2-ffv1.avi
for another fate sample there is a 0.5% speedup
the effect should be bigger for files with "flat" colored areas
the new faster branch is used in 97-100% of the cases in fate samples
compared to the older more complex (which i tested)

vsynth3-ffv1-v3-bgr0.avi had the lowest percentual useage of about 97%


[...]
Michael Niedermayer May 27, 2019, 4:04 p.m. UTC | #3
On Thu, May 23, 2019 at 10:36:10PM +0200, Michael Niedermayer wrote:
> On Thu, May 23, 2019 at 10:57:14AM +0200, Carl Eugen Hoyos wrote:
> > Am Do., 23. Mai 2019 um 01:47 Uhr schrieb Michael Niedermayer
> > <michael@niedermayer.cc>:
> > >
> > > Fixes: Timeout (14sec -> 9sec)
> > > Fixes: 13398/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_FFV1_fuzzer-5664106709778432
> > >
> > > Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > > ---
> > >  libavcodec/ffv1dec_template.c | 8 ++++++++
> > >  1 file changed, 8 insertions(+)
> > >
> > > diff --git a/libavcodec/ffv1dec_template.c b/libavcodec/ffv1dec_template.c
> > > index 1b7f6c4bf5..0b1d176ba1 100644
> > > --- a/libavcodec/ffv1dec_template.c
> > > +++ b/libavcodec/ffv1dec_template.c
> > > @@ -86,11 +86,19 @@ static av_always_inline int RENAME(decode_line)(FFV1Context *s, int w,
> > >                          run_mode = 2;
> > >                      }
> > >                  }
> > > +                if (sample[1][x - 1] == sample[0][x - 1]) {
> > > +                    while (run_count > 1 && w-x > 1) {
> > > +                        sample[1][x] = sample[0][x];
> > > +                        x++;
> > > +                        run_count--;
> > > +                    }
> > > +                } else {
> > 
> > Does this change have a measurable effect on your usual sample files?
> 
> decode_line() becomes 1% faster for fate/vsynth2-ffv1.avi
> for another fate sample there is a 0.5% speedup
> the effect should be bigger for files with "flat" colored areas
> the new faster branch is used in 97-100% of the cases in fate samples
> compared to the older more complex (which i tested)
> 
> vsynth3-ffv1-v3-bgr0.avi had the lowest percentual useage of about 97%


will add this to the commit message and apply

thx

[...]
diff mbox

Patch

diff --git a/libavcodec/ffv1dec_template.c b/libavcodec/ffv1dec_template.c
index 1b7f6c4bf5..0b1d176ba1 100644
--- a/libavcodec/ffv1dec_template.c
+++ b/libavcodec/ffv1dec_template.c
@@ -86,11 +86,19 @@  static av_always_inline int RENAME(decode_line)(FFV1Context *s, int w,
                         run_mode = 2;
                     }
                 }
+                if (sample[1][x - 1] == sample[0][x - 1]) {
+                    while (run_count > 1 && w-x > 1) {
+                        sample[1][x] = sample[0][x];
+                        x++;
+                        run_count--;
+                    }
+                } else {
                 while (run_count > 1 && w-x > 1) {
                     sample[1][x] = RENAME(predict)(sample[1] + x, sample[0] + x);
                     x++;
                     run_count--;
                 }
+                }
                 run_count--;
                 if (run_count < 0) {
                     run_mode  = 0;