diff mbox series

[FFmpeg-devel,10/12] avcodec/rv10: Replace switch by LUT

Message ID AS8P250MB0744676950E61AB83D8CC0028FC4A@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM
State Accepted
Commit 951bcc3c0335cfdac130a359a93c1b3e3c2a0550
Headers show
Series [FFmpeg-devel,1/4] avcodec/mpegvideo_dec: Check for existence of planes before accesses | expand

Commit Message

Andreas Rheinhardt Oct. 3, 2023, 4:04 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/rv10.c | 21 +++++----------------
 1 file changed, 5 insertions(+), 16 deletions(-)

Comments

Michael Niedermayer Oct. 4, 2023, 5:27 p.m. UTC | #1
On Tue, Oct 03, 2023 at 06:04:02PM +0200, Andreas Rheinhardt wrote:
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavcodec/rv10.c | 21 +++++----------------
>  1 file changed, 5 insertions(+), 16 deletions(-)

ok

[...]
Vittorio Giovara Oct. 6, 2023, 1:42 a.m. UTC | #2
On Tue, Oct 3, 2023 at 12:03 PM Andreas Rheinhardt <
andreas.rheinhardt@outlook.com> wrote:

> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavcodec/rv10.c | 21 +++++----------------
>  1 file changed, 5 insertions(+), 16 deletions(-)
>
> diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c
> index 3f9d5ff242..216328ffe7 100644
> --- a/libavcodec/rv10.c
> +++ b/libavcodec/rv10.c
> @@ -158,25 +158,14 @@ static int rv10_decode_picture_header(MpegEncContext
> *s)
>
>  static int rv20_decode_picture_header(RVDecContext *rv, int whole_size)
>  {
> +    static const enum AVPictureType pict_types[] =
> +        { AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_I /* hmm ... */,
>

Any chance we could replace this comment with something more detailed (or
remove it if not needed)?
Andreas Rheinhardt Oct. 6, 2023, 2:03 a.m. UTC | #3
Vittorio Giovara:
> On Tue, Oct 3, 2023 at 12:03 PM Andreas Rheinhardt <
> andreas.rheinhardt@outlook.com> wrote:
> 
>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
>> ---
>>  libavcodec/rv10.c | 21 +++++----------------
>>  1 file changed, 5 insertions(+), 16 deletions(-)
>>
>> diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c
>> index 3f9d5ff242..216328ffe7 100644
>> --- a/libavcodec/rv10.c
>> +++ b/libavcodec/rv10.c
>> @@ -158,25 +158,14 @@ static int rv10_decode_picture_header(MpegEncContext
>> *s)
>>
>>  static int rv20_decode_picture_header(RVDecContext *rv, int whole_size)
>>  {
>> +    static const enum AVPictureType pict_types[] =
>> +        { AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_I /* hmm ... */,
>>
> 
> Any chance we could replace this comment with something more detailed (or
> remove it if not needed)?

The comment has been added when the mapping for 1 was added in
248a1aa54c0 (which made the default case dead code). I simply preserved
it, Michael probably added it to show that he was not completely sure. I
don't know whether there are different semantics for the two values.
I do not object to the removal of this comment.

- Andreas
Michael Niedermayer Oct. 7, 2023, 4:44 p.m. UTC | #4
On Fri, Oct 06, 2023 at 04:03:40AM +0200, Andreas Rheinhardt wrote:
> Vittorio Giovara:
> > On Tue, Oct 3, 2023 at 12:03 PM Andreas Rheinhardt <
> > andreas.rheinhardt@outlook.com> wrote:
> > 
> >> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> >> ---
> >>  libavcodec/rv10.c | 21 +++++----------------
> >>  1 file changed, 5 insertions(+), 16 deletions(-)
> >>
> >> diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c
> >> index 3f9d5ff242..216328ffe7 100644
> >> --- a/libavcodec/rv10.c
> >> +++ b/libavcodec/rv10.c
> >> @@ -158,25 +158,14 @@ static int rv10_decode_picture_header(MpegEncContext
> >> *s)
> >>
> >>  static int rv20_decode_picture_header(RVDecContext *rv, int whole_size)
> >>  {
> >> +    static const enum AVPictureType pict_types[] =
> >> +        { AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_I /* hmm ... */,
> >>
> > 
> > Any chance we could replace this comment with something more detailed (or
> > remove it if not needed)?
> 
> The comment has been added when the mapping for 1 was added in
> 248a1aa54c0 (which made the default case dead code). I simply preserved
> it, Michael probably added it to show that he was not completely sure. I
> don't know whether there are different semantics for the two values.
> I do not object to the removal of this comment.

Its a bit odd when 2 values mean the same thing in a reverse engeneered
format. One kind of thinks, that there is likely some difference that we
just dont know about. maybe teh comment could elaborate in this direction
and or someone could recheck if this is still the current best knowledge ...

thx

[...]
diff mbox series

Patch

diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c
index 3f9d5ff242..216328ffe7 100644
--- a/libavcodec/rv10.c
+++ b/libavcodec/rv10.c
@@ -158,25 +158,14 @@  static int rv10_decode_picture_header(MpegEncContext *s)
 
 static int rv20_decode_picture_header(RVDecContext *rv, int whole_size)
 {
+    static const enum AVPictureType pict_types[] =
+        { AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_I /* hmm ... */,
+          AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B };
     MpegEncContext *s = &rv->m;
-    int seq, mb_pos, i, ret;
+    int seq, mb_pos, ret;
     int rpr_max;
 
-    i = get_bits(&s->gb, 2);
-    switch (i) {
-    case 0:
-        s->pict_type = AV_PICTURE_TYPE_I;
-        break;
-    case 1:
-        s->pict_type = AV_PICTURE_TYPE_I;
-        break;                                  // hmm ...
-    case 2:
-        s->pict_type = AV_PICTURE_TYPE_P;
-        break;
-    case 3:
-        s->pict_type = AV_PICTURE_TYPE_B;
-        break;
-    }
+    s->pict_type = pict_types[get_bits(&s->gb, 2)];
 
     if (s->low_delay && s->pict_type == AV_PICTURE_TYPE_B) {
         av_log(s->avctx, AV_LOG_ERROR, "low delay B\n");