diff mbox series

[FFmpeg-devel,1/2] avcodec/jpeg2000dec: Set sample aspect ratio before getting buffer

Message ID AS8P250MB0744DC3730843D0BD93B8D9A8F519@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM
State Accepted
Commit d5a0dc037df48f53cb4dbe37cfae1724f11c8a58
Headers show
Series [FFmpeg-devel,1/2] avcodec/jpeg2000dec: Set sample aspect ratio before getting buffer | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt Sept. 23, 2022, 3:40 p.m. UTC
That way the SAR will be automatically set on the AVFrame.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
If I am not mistaken, then the earlier code would set the sar
with a delay of one frame on the returned frames in case
there is a sar change mid-stream. But I don't have a sample
for this.

 libavcodec/jpeg2000dec.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Tomas Härdin Sept. 23, 2022, 6:23 p.m. UTC | #1
fre 2022-09-23 klockan 17:40 +0200 skrev Andreas Rheinhardt:
> That way the SAR will be automatically set on the AVFrame.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
> If I am not mistaken, then the earlier code would set the sar
> with a delay of one frame on the returned frames in case
> there is a sar change mid-stream. But I don't have a sample
> for this.
> 
>  libavcodec/jpeg2000dec.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
> index 7d9661f29f..c3f2a7aa03 100644
> --- a/libavcodec/jpeg2000dec.c
> +++ b/libavcodec/jpeg2000dec.c
> @@ -2519,6 +2519,10 @@ static int
> jpeg2000_decode_frame(AVCodecContext *avctx, AVFrame *picture,
>      if (ret = jpeg2000_read_main_headers(s))
>          goto end;
>  
> +    if (s->sar.num && s->sar.den)
> +        avctx->sample_aspect_ratio = s->sar;
> +    s->sar.num = s->sar.den = 0;
> +
>      /* get picture buffer */
>      if ((ret = ff_thread_get_buffer(avctx, picture, 0)) < 0)
>          goto end;
> @@ -2547,9 +2551,6 @@ static int jpeg2000_decode_frame(AVCodecContext
> *avctx, AVFrame *picture,
>  
>      if (s->avctx->pix_fmt == AV_PIX_FMT_PAL8)
>          memcpy(picture->data[1], s->palette, 256 *
> sizeof(uint32_t));
> -    if (s->sar.num && s->sar.den)
> -        avctx->sample_aspect_ratio = s->sar;
> -    s->sar.num = s->sar.den = 0;

I suspect not doing this is what caused my simple hack to not work when
ff_thread_get_buffer() was skipped. Looks OK, passes FATE.

/Tomas
Andreas Rheinhardt Sept. 23, 2022, 6:48 p.m. UTC | #2
Tomas Härdin:
> fre 2022-09-23 klockan 17:40 +0200 skrev Andreas Rheinhardt:
>> That way the SAR will be automatically set on the AVFrame.
>>
>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
>> ---
>> If I am not mistaken, then the earlier code would set the sar
>> with a delay of one frame on the returned frames in case
>> there is a sar change mid-stream. But I don't have a sample
>> for this.
>>
>>  libavcodec/jpeg2000dec.c | 7 ++++---
>>  1 file changed, 4 insertions(+), 3 deletions(-)
>>
>> diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
>> index 7d9661f29f..c3f2a7aa03 100644
>> --- a/libavcodec/jpeg2000dec.c
>> +++ b/libavcodec/jpeg2000dec.c
>> @@ -2519,6 +2519,10 @@ static int
>> jpeg2000_decode_frame(AVCodecContext *avctx, AVFrame *picture,
>>      if (ret = jpeg2000_read_main_headers(s))
>>          goto end;
>>  
>> +    if (s->sar.num && s->sar.den)
>> +        avctx->sample_aspect_ratio = s->sar;
>> +    s->sar.num = s->sar.den = 0;
>> +
>>      /* get picture buffer */
>>      if ((ret = ff_thread_get_buffer(avctx, picture, 0)) < 0)
>>          goto end;
>> @@ -2547,9 +2551,6 @@ static int jpeg2000_decode_frame(AVCodecContext
>> *avctx, AVFrame *picture,
>>  
>>      if (s->avctx->pix_fmt == AV_PIX_FMT_PAL8)
>>          memcpy(picture->data[1], s->palette, 256 *
>> sizeof(uint32_t));
>> -    if (s->sar.num && s->sar.den)
>> -        avctx->sample_aspect_ratio = s->sar;
>> -    s->sar.num = s->sar.den = 0;
> 
> I suspect not doing this is what caused my simple hack to not work when
> ff_thread_get_buffer() was skipped. Looks OK, passes FATE.
> 

FYI: Patch two passes FATE even without patch one. In what way did your
simple hack not work when ff_thread_get_buffer() is skipped?

- Andreas
Tomas Härdin Sept. 23, 2022, 7:36 p.m. UTC | #3
fre 2022-09-23 klockan 20:48 +0200 skrev Andreas Rheinhardt:
> Tomas Härdin:
> > fre 2022-09-23 klockan 17:40 +0200 skrev Andreas Rheinhardt:
> > > That way the SAR will be automatically set on the AVFrame.
> > > 
> > > Signed-off-by: Andreas Rheinhardt
> > > <andreas.rheinhardt@outlook.com>
> > > ---
> > > If I am not mistaken, then the earlier code would set the sar
> > > with a delay of one frame on the returned frames in case
> > > there is a sar change mid-stream. But I don't have a sample
> > > for this.
> > > 
> > >  libavcodec/jpeg2000dec.c | 7 ++++---
> > >  1 file changed, 4 insertions(+), 3 deletions(-)
> > > 
> > > diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
> > > index 7d9661f29f..c3f2a7aa03 100644
> > > --- a/libavcodec/jpeg2000dec.c
> > > +++ b/libavcodec/jpeg2000dec.c
> > > @@ -2519,6 +2519,10 @@ static int
> > > jpeg2000_decode_frame(AVCodecContext *avctx, AVFrame *picture,
> > >      if (ret = jpeg2000_read_main_headers(s))
> > >          goto end;
> > >  
> > > +    if (s->sar.num && s->sar.den)
> > > +        avctx->sample_aspect_ratio = s->sar;
> > > +    s->sar.num = s->sar.den = 0;
> > > +
> > >      /* get picture buffer */
> > >      if ((ret = ff_thread_get_buffer(avctx, picture, 0)) < 0)
> > >          goto end;
> > > @@ -2547,9 +2551,6 @@ static int
> > > jpeg2000_decode_frame(AVCodecContext
> > > *avctx, AVFrame *picture,
> > >  
> > >      if (s->avctx->pix_fmt == AV_PIX_FMT_PAL8)
> > >          memcpy(picture->data[1], s->palette, 256 *
> > > sizeof(uint32_t));
> > > -    if (s->sar.num && s->sar.den)
> > > -        avctx->sample_aspect_ratio = s->sar;
> > > -    s->sar.num = s->sar.den = 0;
> > 
> > I suspect not doing this is what caused my simple hack to not work
> > when
> > ff_thread_get_buffer() was skipped. Looks OK, passes FATE.
> > 
> 
> FYI: Patch two passes FATE even without patch one. In what way did
> your
> simple hack not work when ff_thread_get_buffer() is skipped?

I had it like patch attached. I suspect the reason it didn't work is
because it sets *got_frame. If I run it then I get

  Assertion frame->buf[0] failed at libavcodec/decode.c:502
  Avbruten (SIGABRT)

/Tomas
Andreas Rheinhardt Sept. 23, 2022, 7:56 p.m. UTC | #4
Tomas Härdin:
> fre 2022-09-23 klockan 20:48 +0200 skrev Andreas Rheinhardt:
>> Tomas Härdin:
>>> fre 2022-09-23 klockan 17:40 +0200 skrev Andreas Rheinhardt:
>>>> That way the SAR will be automatically set on the AVFrame.
>>>>
>>>> Signed-off-by: Andreas Rheinhardt
>>>> <andreas.rheinhardt@outlook.com>
>>>> ---
>>>> If I am not mistaken, then the earlier code would set the sar
>>>> with a delay of one frame on the returned frames in case
>>>> there is a sar change mid-stream. But I don't have a sample
>>>> for this.
>>>>
>>>>  libavcodec/jpeg2000dec.c | 7 ++++---
>>>>  1 file changed, 4 insertions(+), 3 deletions(-)
>>>>
>>>> diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
>>>> index 7d9661f29f..c3f2a7aa03 100644
>>>> --- a/libavcodec/jpeg2000dec.c
>>>> +++ b/libavcodec/jpeg2000dec.c
>>>> @@ -2519,6 +2519,10 @@ static int
>>>> jpeg2000_decode_frame(AVCodecContext *avctx, AVFrame *picture,
>>>>      if (ret = jpeg2000_read_main_headers(s))
>>>>          goto end;
>>>>  
>>>> +    if (s->sar.num && s->sar.den)
>>>> +        avctx->sample_aspect_ratio = s->sar;
>>>> +    s->sar.num = s->sar.den = 0;
>>>> +
>>>>      /* get picture buffer */
>>>>      if ((ret = ff_thread_get_buffer(avctx, picture, 0)) < 0)
>>>>          goto end;
>>>> @@ -2547,9 +2551,6 @@ static int
>>>> jpeg2000_decode_frame(AVCodecContext
>>>> *avctx, AVFrame *picture,
>>>>  
>>>>      if (s->avctx->pix_fmt == AV_PIX_FMT_PAL8)
>>>>          memcpy(picture->data[1], s->palette, 256 *
>>>> sizeof(uint32_t));
>>>> -    if (s->sar.num && s->sar.den)
>>>> -        avctx->sample_aspect_ratio = s->sar;
>>>> -    s->sar.num = s->sar.den = 0;
>>>
>>> I suspect not doing this is what caused my simple hack to not work
>>> when
>>> ff_thread_get_buffer() was skipped. Looks OK, passes FATE.
>>>
>>
>> FYI: Patch two passes FATE even without patch one. In what way did
>> your
>> simple hack not work when ff_thread_get_buffer() is skipped?
> 
> I had it like patch attached. I suspect the reason it didn't work is
> because it sets *got_frame. If I run it then I get
> 
>   Assertion frame->buf[0] failed at libavcodec/decode.c:502
>   Avbruten (SIGABRT)
> 
> /Tomas
> 

Yeah, that's not how it's supposed to work. Will apply my patches.
Thanks for the review.

- Andreas
diff mbox series

Patch

diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
index 7d9661f29f..c3f2a7aa03 100644
--- a/libavcodec/jpeg2000dec.c
+++ b/libavcodec/jpeg2000dec.c
@@ -2519,6 +2519,10 @@  static int jpeg2000_decode_frame(AVCodecContext *avctx, AVFrame *picture,
     if (ret = jpeg2000_read_main_headers(s))
         goto end;
 
+    if (s->sar.num && s->sar.den)
+        avctx->sample_aspect_ratio = s->sar;
+    s->sar.num = s->sar.den = 0;
+
     /* get picture buffer */
     if ((ret = ff_thread_get_buffer(avctx, picture, 0)) < 0)
         goto end;
@@ -2547,9 +2551,6 @@  static int jpeg2000_decode_frame(AVCodecContext *avctx, AVFrame *picture,
 
     if (s->avctx->pix_fmt == AV_PIX_FMT_PAL8)
         memcpy(picture->data[1], s->palette, 256 * sizeof(uint32_t));
-    if (s->sar.num && s->sar.den)
-        avctx->sample_aspect_ratio = s->sar;
-    s->sar.num = s->sar.den = 0;
 
     return bytestream2_tell(&s->g);