diff mbox

[FFmpeg-devel] avfilter/vf_tonemap: don't use NAN constant as an initializer

Message ID 20170907015913.6600-1-jamrial@gmail.com
State New
Headers show

Commit Message

James Almer Sept. 7, 2017, 1:59 a.m. UTC
Netbsd:
src/libavfilter/vf_tonemap.c:314: error: initializer element is not constant
src/libavfilter/vf_tonemap.c:314: error: (near initialization for 'tonemap_options[8].default_val.dbl')

DJGPP
src/libavfilter/vf_tonemap.c:314:87: error: initializer element is not constant
     { "param",        "tonemap parameter", OFFSET(param), AV_OPT_TYPE_DOUBLE, {.dbl = NAN}, DBL_MIN, DBL_MAX, FLAGS },
                                                                                       ^
src/libavfilter/vf_tonemap.c:314:87: note: (near initialization for 'tonemap_options[8].default_val.dbl')

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavfilter/vf_tonemap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Michael Niedermayer Sept. 7, 2017, 9:16 p.m. UTC | #1
On Wed, Sep 06, 2017 at 10:59:13PM -0300, James Almer wrote:
> Netbsd:
> src/libavfilter/vf_tonemap.c:314: error: initializer element is not constant
> src/libavfilter/vf_tonemap.c:314: error: (near initialization for 'tonemap_options[8].default_val.dbl')
> 
> DJGPP
> src/libavfilter/vf_tonemap.c:314:87: error: initializer element is not constant
>      { "param",        "tonemap parameter", OFFSET(param), AV_OPT_TYPE_DOUBLE, {.dbl = NAN}, DBL_MIN, DBL_MAX, FLAGS },
>                                                                                        ^
> src/libavfilter/vf_tonemap.c:314:87: note: (near initialization for 'tonemap_options[8].default_val.dbl')
> 
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavfilter/vf_tonemap.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavfilter/vf_tonemap.c b/libavfilter/vf_tonemap.c
> index 10308bdb16..d2c7ffa831 100644
> --- a/libavfilter/vf_tonemap.c
> +++ b/libavfilter/vf_tonemap.c
> @@ -311,7 +311,7 @@ static const AVOption tonemap_options[] = {
>      {     "reinhard", 0, 0, AV_OPT_TYPE_CONST, {.i64 = TONEMAP_REINHARD},          0, 0, FLAGS, "tonemap" },
>      {     "hable",    0, 0, AV_OPT_TYPE_CONST, {.i64 = TONEMAP_HABLE},             0, 0, FLAGS, "tonemap" },
>      {     "mobius",   0, 0, AV_OPT_TYPE_CONST, {.i64 = TONEMAP_MOBIUS},            0, 0, FLAGS, "tonemap" },
> -    { "param",        "tonemap parameter", OFFSET(param), AV_OPT_TYPE_DOUBLE, {.dbl = NAN}, DBL_MIN, DBL_MAX, FLAGS },
> +    { "param",        "tonemap parameter", OFFSET(param), AV_OPT_TYPE_DOUBLE, {.dbl = nan("")}, DBL_MIN, DBL_MAX, FLAGS },

building shared libs: (seems ok with static)
on linux x86-64

src/libavfilter/vf_tonemap.c:314:108: error: initializer element is not a compile-time constant
    { "param", "tonemap parameter", __builtin_offsetof(TonemapContext, param), AV_OPT_TYPE_DOUBLE, {.dbl = nan("")}, 2.2250738585072014e-308, 1.7976931348623157e+308, 16 | (1<<16) },
                                                                                                           ^~~~~~~
1 error generated.
make: *** [libavfilter/vf_tonemap.o] Error 1
make: *** Waiting for unfinished jobs....
src/libavfilter/vf_uspp.c:253:15: warning: 'avcodec_encode_video2' is deprecated [-Wdeprecated-declarations]
        ret = avcodec_encode_video2(p->avctx_enc[i], &pkt, p->frame, &got_pkt_ptr);
              ^
src/libavcodec/avcodec.h:5486:5: note: 'avcodec_encode_video2' has been explicitly marked deprecated here
int avcodec_encode_video2(AVCodecContext *avctx, AVPacket *avpkt,
    ^
src/libavfilter/vf_uspp.c:259:41: warning: 'coded_frame' is deprecated [-Wdeprecated-declarations]
        p->frame_dec = p->avctx_enc[i]->coded_frame;
                                        ^
src/libavcodec/avcodec.h:3167:42: note: 'coded_frame' has been explicitly marked deprecated here
    __attribute__((deprecated)) AVFrame *coded_frame;
                                         ^
2 warnings generated.

[...]
James Almer Sept. 7, 2017, 9:26 p.m. UTC | #2
On 9/7/2017 6:16 PM, Michael Niedermayer wrote:
> On Wed, Sep 06, 2017 at 10:59:13PM -0300, James Almer wrote:
>> Netbsd:
>> src/libavfilter/vf_tonemap.c:314: error: initializer element is not constant
>> src/libavfilter/vf_tonemap.c:314: error: (near initialization for 'tonemap_options[8].default_val.dbl')
>>
>> DJGPP
>> src/libavfilter/vf_tonemap.c:314:87: error: initializer element is not constant
>>      { "param",        "tonemap parameter", OFFSET(param), AV_OPT_TYPE_DOUBLE, {.dbl = NAN}, DBL_MIN, DBL_MAX, FLAGS },
>>                                                                                        ^
>> src/libavfilter/vf_tonemap.c:314:87: note: (near initialization for 'tonemap_options[8].default_val.dbl')
>>
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>  libavfilter/vf_tonemap.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/libavfilter/vf_tonemap.c b/libavfilter/vf_tonemap.c
>> index 10308bdb16..d2c7ffa831 100644
>> --- a/libavfilter/vf_tonemap.c
>> +++ b/libavfilter/vf_tonemap.c
>> @@ -311,7 +311,7 @@ static const AVOption tonemap_options[] = {
>>      {     "reinhard", 0, 0, AV_OPT_TYPE_CONST, {.i64 = TONEMAP_REINHARD},          0, 0, FLAGS, "tonemap" },
>>      {     "hable",    0, 0, AV_OPT_TYPE_CONST, {.i64 = TONEMAP_HABLE},             0, 0, FLAGS, "tonemap" },
>>      {     "mobius",   0, 0, AV_OPT_TYPE_CONST, {.i64 = TONEMAP_MOBIUS},            0, 0, FLAGS, "tonemap" },
>> -    { "param",        "tonemap parameter", OFFSET(param), AV_OPT_TYPE_DOUBLE, {.dbl = NAN}, DBL_MIN, DBL_MAX, FLAGS },
>> +    { "param",        "tonemap parameter", OFFSET(param), AV_OPT_TYPE_DOUBLE, {.dbl = nan("")}, DBL_MIN, DBL_MAX, FLAGS },
> 
> building shared libs: (seems ok with static)
> on linux x86-64
> 
> src/libavfilter/vf_tonemap.c:314:108: error: initializer element is not a compile-time constant
>     { "param", "tonemap parameter", __builtin_offsetof(TonemapContext, param), AV_OPT_TYPE_DOUBLE, {.dbl = nan("")}, 2.2250738585072014e-308, 1.7976931348623157e+308, 16 | (1<<16) },

What can we do, then? NAN and nan("") are sometimes compile-time
constants and sometimes not, apparently depending on build type and
target system.

CCing Vittorio as he's the author of the filter.
Michael Niedermayer Sept. 7, 2017, 10:17 p.m. UTC | #3
On Thu, Sep 07, 2017 at 06:26:50PM -0300, James Almer wrote:
> On 9/7/2017 6:16 PM, Michael Niedermayer wrote:
> > On Wed, Sep 06, 2017 at 10:59:13PM -0300, James Almer wrote:
> >> Netbsd:
> >> src/libavfilter/vf_tonemap.c:314: error: initializer element is not constant
> >> src/libavfilter/vf_tonemap.c:314: error: (near initialization for 'tonemap_options[8].default_val.dbl')
> >>
> >> DJGPP
> >> src/libavfilter/vf_tonemap.c:314:87: error: initializer element is not constant
> >>      { "param",        "tonemap parameter", OFFSET(param), AV_OPT_TYPE_DOUBLE, {.dbl = NAN}, DBL_MIN, DBL_MAX, FLAGS },
> >>                                                                                        ^
> >> src/libavfilter/vf_tonemap.c:314:87: note: (near initialization for 'tonemap_options[8].default_val.dbl')
> >>
> >> Signed-off-by: James Almer <jamrial@gmail.com>
> >> ---
> >>  libavfilter/vf_tonemap.c | 2 +-
> >>  1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/libavfilter/vf_tonemap.c b/libavfilter/vf_tonemap.c
> >> index 10308bdb16..d2c7ffa831 100644
> >> --- a/libavfilter/vf_tonemap.c
> >> +++ b/libavfilter/vf_tonemap.c
> >> @@ -311,7 +311,7 @@ static const AVOption tonemap_options[] = {
> >>      {     "reinhard", 0, 0, AV_OPT_TYPE_CONST, {.i64 = TONEMAP_REINHARD},          0, 0, FLAGS, "tonemap" },
> >>      {     "hable",    0, 0, AV_OPT_TYPE_CONST, {.i64 = TONEMAP_HABLE},             0, 0, FLAGS, "tonemap" },
> >>      {     "mobius",   0, 0, AV_OPT_TYPE_CONST, {.i64 = TONEMAP_MOBIUS},            0, 0, FLAGS, "tonemap" },
> >> -    { "param",        "tonemap parameter", OFFSET(param), AV_OPT_TYPE_DOUBLE, {.dbl = NAN}, DBL_MIN, DBL_MAX, FLAGS },
> >> +    { "param",        "tonemap parameter", OFFSET(param), AV_OPT_TYPE_DOUBLE, {.dbl = nan("")}, DBL_MIN, DBL_MAX, FLAGS },
> > 
> > building shared libs: (seems ok with static)
> > on linux x86-64
> > 
> > src/libavfilter/vf_tonemap.c:314:108: error: initializer element is not a compile-time constant
> >     { "param", "tonemap parameter", __builtin_offsetof(TonemapContext, param), AV_OPT_TYPE_DOUBLE, {.dbl = nan("")}, 2.2250738585072014e-308, 1.7976931348623157e+308, 16 | (1<<16) },
> 
> What can we do, then? NAN and nan("") are sometimes compile-time
> constants and sometimes not, apparently depending on build type and
> target system.

using a finite value instead of NAN would avoid this problem
DBL_MIN or DBL_MAX may be options

[...]
Nicolas George Sept. 8, 2017, 8:25 a.m. UTC | #4
Le primidi 21 fructidor, an CCXXV, James Almer a écrit :
> What can we do, then? NAN and nan("") are sometimes compile-time
> constants and sometimes not, apparently depending on build type and
> target system.
> 
> CCing Vittorio as he's the author of the filter.

"The macro NAN is defined if and only if the implementation supports
quiet NaNs for the float type. It expands to a constant expression of
type float representing a quiet NaN."

-> If the macro is defined, it must be a compile-time constant.
Therefore, DJGPP is wrong.

I say let the people who care about DJGPP fix it, and in the meantime
use "--disable-filter=tonemap".

Regards,
Hendrik Leppkes Sept. 8, 2017, 9:53 a.m. UTC | #5
On Fri, Sep 8, 2017 at 10:25 AM, Nicolas George <george@nsup.org> wrote:
> Le primidi 21 fructidor, an CCXXV, James Almer a écrit :
>> What can we do, then? NAN and nan("") are sometimes compile-time
>> constants and sometimes not, apparently depending on build type and
>> target system.
>>
>> CCing Vittorio as he's the author of the filter.
>
> "The macro NAN is defined if and only if the implementation supports
> quiet NaNs for the float type. It expands to a constant expression of
> type float representing a quiet NaN."
>
> -> If the macro is defined, it must be a compile-time constant.
> Therefore, DJGPP is wrong.
>

So if it would not be defined at all, the filter would still not
build. So what exactly does that change?

- Hendrik
Derek Buitenhuis Sept. 8, 2017, 12:34 p.m. UTC | #6
On 9/8/2017 10:53 AM, Hendrik Leppkes wrote:
> So if it would not be defined at all, the filter would still not
> build. So what exactly does that change?

Yes it would:

    libavutil/mathematics.h:#define NAN            av_int2float(0x7fc00000)

- Derek
Vittorio Giovara Sept. 8, 2017, 12:39 p.m. UTC | #7
On Thu, Sep 7, 2017 at 11:26 PM, James Almer <jamrial@gmail.com> wrote:

> On 9/7/2017 6:16 PM, Michael Niedermayer wrote:
> > On Wed, Sep 06, 2017 at 10:59:13PM -0300, James Almer wrote:
> >> Netbsd:
> >> src/libavfilter/vf_tonemap.c:314: error: initializer element is not
> constant
> >> src/libavfilter/vf_tonemap.c:314: error: (near initialization for
> 'tonemap_options[8].default_val.dbl')
> >>
> >> DJGPP
> >> src/libavfilter/vf_tonemap.c:314:87: error: initializer element is not
> constant
> >>      { "param",        "tonemap parameter", OFFSET(param),
> AV_OPT_TYPE_DOUBLE, {.dbl = NAN}, DBL_MIN, DBL_MAX, FLAGS },
> >>
>                 ^
> >> src/libavfilter/vf_tonemap.c:314:87: note: (near initialization for
> 'tonemap_options[8].default_val.dbl')
> >>
> >> Signed-off-by: James Almer <jamrial@gmail.com>
> >> ---
> >>  libavfilter/vf_tonemap.c | 2 +-
> >>  1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/libavfilter/vf_tonemap.c b/libavfilter/vf_tonemap.c
> >> index 10308bdb16..d2c7ffa831 100644
> >> --- a/libavfilter/vf_tonemap.c
> >> +++ b/libavfilter/vf_tonemap.c
> >> @@ -311,7 +311,7 @@ static const AVOption tonemap_options[] = {
> >>      {     "reinhard", 0, 0, AV_OPT_TYPE_CONST, {.i64 =
> TONEMAP_REINHARD},          0, 0, FLAGS, "tonemap" },
> >>      {     "hable",    0, 0, AV_OPT_TYPE_CONST, {.i64 =
> TONEMAP_HABLE},             0, 0, FLAGS, "tonemap" },
> >>      {     "mobius",   0, 0, AV_OPT_TYPE_CONST, {.i64 =
> TONEMAP_MOBIUS},            0, 0, FLAGS, "tonemap" },
> >> -    { "param",        "tonemap parameter", OFFSET(param),
> AV_OPT_TYPE_DOUBLE, {.dbl = NAN}, DBL_MIN, DBL_MAX, FLAGS },
> >> +    { "param",        "tonemap parameter", OFFSET(param),
> AV_OPT_TYPE_DOUBLE, {.dbl = nan("")}, DBL_MIN, DBL_MAX, FLAGS },
> >
> > building shared libs: (seems ok with static)
> > on linux x86-64
> >
> > src/libavfilter/vf_tonemap.c:314:108: error: initializer element is not
> a compile-time constant
> >     { "param", "tonemap parameter", __builtin_offsetof(TonemapContext,
> param), AV_OPT_TYPE_DOUBLE, {.dbl = nan("")}, 2.2250738585072014e-308,
> 1.7976931348623157e+308, 16 | (1<<16) },
>
> What can we do, then? NAN and nan("") are sometimes compile-time
> constants and sometimes not, apparently depending on build type and
> target system.
>

Another option, although not ideal, could be to make this filter dependent
on vf_zscale, which suffers from the same bug but is disabled on those
architecture because zimg is not installed.
James Almer Sept. 8, 2017, 2:38 p.m. UTC | #8
On 9/8/2017 5:25 AM, Nicolas George wrote:
> Le primidi 21 fructidor, an CCXXV, James Almer a écrit :
>> What can we do, then? NAN and nan("") are sometimes compile-time
>> constants and sometimes not, apparently depending on build type and
>> target system.
>>
>> CCing Vittorio as he's the author of the filter.
> 
> "The macro NAN is defined if and only if the implementation supports
> quiet NaNs for the float type. It expands to a constant expression of
> type float representing a quiet NaN."
> 
> -> If the macro is defined, it must be a compile-time constant.
> Therefore, DJGPP is wrong.

Yes, both DJGPP and Netbsd are wrong. There's a ticket in the latter's
bug tracker since like 2010.

> 
> I say let the people who care about DJGPP fix it, and in the meantime
> use "--disable-filter=tonemap".

A configure check for NAN being a compile-time constant as a dependency
for this filter is IMO a cleaner solution.

> 
> Regards,
> 
> 
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
diff mbox

Patch

diff --git a/libavfilter/vf_tonemap.c b/libavfilter/vf_tonemap.c
index 10308bdb16..d2c7ffa831 100644
--- a/libavfilter/vf_tonemap.c
+++ b/libavfilter/vf_tonemap.c
@@ -311,7 +311,7 @@  static const AVOption tonemap_options[] = {
     {     "reinhard", 0, 0, AV_OPT_TYPE_CONST, {.i64 = TONEMAP_REINHARD},          0, 0, FLAGS, "tonemap" },
     {     "hable",    0, 0, AV_OPT_TYPE_CONST, {.i64 = TONEMAP_HABLE},             0, 0, FLAGS, "tonemap" },
     {     "mobius",   0, 0, AV_OPT_TYPE_CONST, {.i64 = TONEMAP_MOBIUS},            0, 0, FLAGS, "tonemap" },
-    { "param",        "tonemap parameter", OFFSET(param), AV_OPT_TYPE_DOUBLE, {.dbl = NAN}, DBL_MIN, DBL_MAX, FLAGS },
+    { "param",        "tonemap parameter", OFFSET(param), AV_OPT_TYPE_DOUBLE, {.dbl = nan("")}, DBL_MIN, DBL_MAX, FLAGS },
     { "desat",        "desaturation strength", OFFSET(desat), AV_OPT_TYPE_DOUBLE, {.dbl = 2}, 0, DBL_MAX, FLAGS },
     { "peak",         "signal peak override", OFFSET(peak), AV_OPT_TYPE_DOUBLE, {.dbl = 0}, 0, DBL_MAX, FLAGS },
     { NULL }