diff mbox series

[FFmpeg-devel,2/2] swscale/utils: Improve return codes of sws_setColorspaceDetails()

Message ID 20211022214538.13139-2-michael@niedermayer.cc
State New
Headers show
Series [FFmpeg-devel,1/2] swscale/utils: Set all threads to the same colorspace even on failure | expand

Commit Message

Michael Niedermayer Oct. 22, 2021, 9:45 p.m. UTC
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libswscale/utils.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

James Almer Oct. 23, 2021, 1:55 a.m. UTC | #1
On 10/22/2021 6:45 PM, Michael Niedermayer wrote:
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>   libswscale/utils.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/libswscale/utils.c b/libswscale/utils.c
> index 3752c3ec38c..632f6fd4648 100644
> --- a/libswscale/utils.c
> +++ b/libswscale/utils.c
> @@ -995,7 +995,10 @@ int sws_setColorspaceDetails(struct SwsContext *c, const int inv_table[4],
>                                        0, 1 << 16, 1 << 16);
>               return 0;
>           }
> -        return -1;
> +        //We do not support this combination currently, we need to cascade more contexts to compensate
> +        if (memcmp(c->dstColorspaceTable, c->srcColorspaceTable, sizeof(int) * 4))
> +            return AVERROR_PATCHWELCOME;

The doxy does not allow return values other than -1.

> +        return 0;
>       }
>   
>       if (!isYUV(c->dstFormat) && !isGray(c->dstFormat)) {
>
Michael Niedermayer Oct. 23, 2021, 7:56 a.m. UTC | #2
On Fri, Oct 22, 2021 at 10:55:25PM -0300, James Almer wrote:
> On 10/22/2021 6:45 PM, Michael Niedermayer wrote:
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >   libswscale/utils.c | 5 ++++-
> >   1 file changed, 4 insertions(+), 1 deletion(-)
> > 
> > diff --git a/libswscale/utils.c b/libswscale/utils.c
> > index 3752c3ec38c..632f6fd4648 100644
> > --- a/libswscale/utils.c
> > +++ b/libswscale/utils.c
> > @@ -995,7 +995,10 @@ int sws_setColorspaceDetails(struct SwsContext *c, const int inv_table[4],
> >                                        0, 1 << 16, 1 << 16);
> >               return 0;
> >           }
> > -        return -1;
> > +        //We do not support this combination currently, we need to cascade more contexts to compensate
> > +        if (memcmp(c->dstColorspaceTable, c->srcColorspaceTable, sizeof(int) * 4))
> > +            return AVERROR_PATCHWELCOME;
> 
> The doxy does not allow return values other than -1.

That is strictly not true
the doxy only says what will happen if "not supported" (that is return -1)
it doesnt say what other error conditions will do nor what non error 
conditions will

but for sake of not breaking anyones code its indeed better to leave this
at -1

thx

[...]
diff mbox series

Patch

diff --git a/libswscale/utils.c b/libswscale/utils.c
index 3752c3ec38c..632f6fd4648 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -995,7 +995,10 @@  int sws_setColorspaceDetails(struct SwsContext *c, const int inv_table[4],
                                      0, 1 << 16, 1 << 16);
             return 0;
         }
-        return -1;
+        //We do not support this combination currently, we need to cascade more contexts to compensate
+        if (memcmp(c->dstColorspaceTable, c->srcColorspaceTable, sizeof(int) * 4))
+            return AVERROR_PATCHWELCOME;
+        return 0;
     }
 
     if (!isYUV(c->dstFormat) && !isGray(c->dstFormat)) {