Skip to content

Commit 879e104

Browse files
committed
osdep/compiler.h: introduce mp_isnan
Some platforms like MinGW have suboptimal isnan, so use __builtin_isnan instead if possible.
1 parent d3ec15b commit 879e104

File tree

8 files changed

+27
-21
lines changed

8 files changed

+27
-21
lines changed

demux/demux_lavf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ static void handle_new_stream(demuxer_t *demuxer, int i)
760760
const uint8_t *sd = mp_av_stream_get_side_data(st, AV_PKT_DATA_DISPLAYMATRIX);
761761
if (sd) {
762762
double r = av_display_rotation_get((int32_t *)sd);
763-
if (!isnan(r))
763+
if (!mp_isnan(r))
764764
sh->codec->rotate = (((int)(-r) % 360) + 360) % 360;
765765
}
766766

options/m_option.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,15 +1021,15 @@ static int parse_double(struct mp_log *log, const m_option_t *opt,
10211021
static char *print_double(const m_option_t *opt, const void *val)
10221022
{
10231023
double f = VAL(val);
1024-
if (isnan(f) && (opt->flags & M_OPT_DEFAULT_NAN))
1024+
if (mp_isnan(f) && (opt->flags & M_OPT_DEFAULT_NAN))
10251025
return talloc_strdup(NULL, "default");
10261026
return talloc_asprintf(NULL, "%f", f);
10271027
}
10281028

10291029
static char *pretty_print_double(const m_option_t *opt, const void *val)
10301030
{
10311031
double f = VAL(val);
1032-
if (isnan(f))
1032+
if (mp_isnan(f))
10331033
return print_double(opt, val);
10341034
return mp_format_double(NULL, f, 4, false, false, !(opt->flags & M_OPT_FIXED_LEN_PRINT));
10351035
}
@@ -1078,7 +1078,7 @@ static int double_get(const m_option_t *opt, void *ta_parent,
10781078
struct mpv_node *dst, void *src)
10791079
{
10801080
double f = VAL(src);
1081-
if (isnan(f) && (opt->flags & M_OPT_DEFAULT_NAN)) {
1081+
if (mp_isnan(f) && (opt->flags & M_OPT_DEFAULT_NAN)) {
10821082
dst->format = MPV_FORMAT_STRING;
10831083
dst->u.string = talloc_strdup(ta_parent, "default");
10841084
} else {
@@ -1091,8 +1091,8 @@ static int double_get(const m_option_t *opt, void *ta_parent,
10911091
static bool double_equal(const m_option_t *opt, void *a, void *b)
10921092
{
10931093
double fa = VAL(a), fb = VAL(b);
1094-
if (isnan(fa) || isnan(fb))
1095-
return isnan(fa) == isnan(fb);
1094+
if (mp_isnan(fa) || mp_isnan(fb))
1095+
return mp_isnan(fa) == mp_isnan(fb);
10961096
return fa == fb;
10971097
}
10981098

osdep/compiler.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@
5454
#define MP_ASSERT_UNREACHABLE() ((void)0)
5555
#endif
5656

57+
#if __has_builtin(__builtin_isnan)
58+
#define mp_isnan __builtin_isnan
59+
#else
60+
#define mp_isnan isnan
61+
#endif
62+
5763
#ifdef __MINGW_PRINTF_FORMAT
5864
#define MP_PRINTF_FORMAT __MINGW_PRINTF_FORMAT
5965
#elif __has_attribute(format)

video/mp_image.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ struct mp_image *mp_image_from_av_frame(struct AVFrame *src)
11241124
int vflip = ((int64_t)matrix[0] * (int64_t)matrix[4]
11251125
- (int64_t)matrix[1] * (int64_t)matrix[3]) < 0;
11261126
double r = av_display_rotation_get(matrix);
1127-
if (!isnan(r)) {
1127+
if (!mp_isnan(r)) {
11281128
dst->params.rotate = (((int)(-r) % 360) + 360) % 360;
11291129
dst->params.vflip = vflip;
11301130
}

video/out/drm_common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ static bool mode_match(const drmModeModeInfo *mode,
797797
unsigned int height,
798798
double refresh)
799799
{
800-
if (isnan(refresh)) {
800+
if (mp_isnan(refresh)) {
801801
return
802802
(mode->hdisplay == width) &&
803803
(mode->vdisplay == height);

video/out/gpu/video.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,7 +1750,7 @@ static void load_shader(struct gl_video *p, struct bstr body)
17501750
// Semantic equality
17511751
static bool double_seq(double a, double b)
17521752
{
1753-
return (isnan(a) && isnan(b)) || a == b;
1753+
return (mp_isnan(a) && mp_isnan(b)) || a == b;
17541754
}
17551755

17561756
static bool scaler_fun_eq(struct scaler_fun a, struct scaler_fun b)
@@ -1817,9 +1817,9 @@ static void reinit_scaler(struct gl_video *p, struct scaler *scaler,
18171817
scaler->kernel->w = *t_window;
18181818

18191819
for (int n = 0; n < 2; n++) {
1820-
if (!isnan(conf->kernel.params[n]))
1820+
if (!mp_isnan(conf->kernel.params[n]))
18211821
scaler->kernel->f.params[n] = conf->kernel.params[n];
1822-
if (!isnan(conf->window.params[n]))
1822+
if (!mp_isnan(conf->window.params[n]))
18231823
scaler->kernel->w.params[n] = conf->window.params[n];
18241824
}
18251825

@@ -3368,7 +3368,7 @@ static void gl_video_interpolate_frame(struct gl_video *p, struct vo_frame *t,
33683368
// position itself
33693369
double vsync_dist = t->vsync_interval / t->ideal_frame_duration,
33703370
threshold = tscale->conf.kernel.params[0];
3371-
threshold = isnan(threshold) ? 0.0 : threshold;
3371+
threshold = mp_isnan(threshold) ? 0.0 : threshold;
33723372
mix = (1 - mix) / vsync_dist;
33733373
mix = mix <= 0 + threshold ? 0 : mix;
33743374
mix = mix >= 1 - threshold ? 1 : mix;

video/out/gpu/video_shaders.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ void pass_sample_oversample(struct gl_shader_cache *sc, struct scaler *scaler,
300300
gl_sc_uniform_vec2(sc, "output_size", (float[2]){w, h});
301301
GLSL(vec2 coeff = fcoord * output_size/size;)
302302
float threshold = scaler->conf.kernel.params[0];
303-
threshold = isnan(threshold) ? 0.0 : threshold;
303+
threshold = mp_isnan(threshold) ? 0.0 : threshold;
304304
GLSLF("coeff = (coeff - %f) * 1.0/%f;\n", threshold, 1.0 - 2 * threshold);
305305
GLSL(coeff = clamp(coeff, 0.0, 1.0);)
306306
// Compute the right blend of colors
@@ -723,12 +723,12 @@ static void pass_tone_map(struct gl_shader_cache *sc,
723723
float param = opts->curve_param;
724724
switch (curve) {
725725
case TONE_MAPPING_CLIP:
726-
GLSLF("sig = min(%f * sig, 1.0);\n", isnan(param) ? 1.0 : param);
726+
GLSLF("sig = min(%f * sig, 1.0);\n", mp_isnan(param) ? 1.0 : param);
727727
break;
728728

729729
case TONE_MAPPING_MOBIUS:
730730
GLSLF("if (sig_peak > (1.0 + 1e-6)) {\n");
731-
GLSLF("const float j = %f;\n", isnan(param) ? 0.3 : param);
731+
GLSLF("const float j = %f;\n", mp_isnan(param) ? 0.3 : param);
732732
// solve for M(j) = j; M(sig_peak) = 1.0; M'(j) = 1.0
733733
// where M(x) = scale * (x+a)/(x+b)
734734
GLSLF("float a = -j*j * (sig_peak - 1.0) / (j*j - 2.0*j + sig_peak);\n");
@@ -742,7 +742,7 @@ static void pass_tone_map(struct gl_shader_cache *sc,
742742
break;
743743

744744
case TONE_MAPPING_REINHARD: {
745-
float contrast = isnan(param) ? 0.5 : param,
745+
float contrast = mp_isnan(param) ? 0.5 : param,
746746
offset = (1.0 - contrast) / contrast;
747747
GLSLF("sig = sig / (sig + vec3(%f));\n", offset);
748748
GLSLF("float scale = (sig_peak + %f) / sig_peak;\n", offset);
@@ -765,7 +765,7 @@ static void pass_tone_map(struct gl_shader_cache *sc,
765765
}
766766

767767
case TONE_MAPPING_GAMMA: {
768-
float gamma = isnan(param) ? 1.8 : param;
768+
float gamma = mp_isnan(param) ? 1.8 : param;
769769
GLSLF("const float cutoff = 0.05, gamma = 1.0/%f;\n", gamma);
770770
GLSL(float scale = pow(cutoff / sig_peak, gamma.x) / cutoff;)
771771
GLSLF("sig = mix(scale * sig,"
@@ -776,7 +776,7 @@ static void pass_tone_map(struct gl_shader_cache *sc,
776776
}
777777

778778
case TONE_MAPPING_LINEAR: {
779-
float coeff = isnan(param) ? 1.0 : param;
779+
float coeff = mp_isnan(param) ? 1.0 : param;
780780
GLSLF("sig = min(%f / sig_peak, 1.0) * sig;\n", coeff);
781781
break;
782782
}

video/out/vo_gpu_next.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,9 +2237,9 @@ static const struct pl_filter_config *map_scaler(struct priv *p,
22372237
}
22382238

22392239
for (int i = 0; i < 2; i++) {
2240-
if (!isnan(cfg->kernel.params[i]))
2240+
if (!mp_isnan(cfg->kernel.params[i]))
22412241
par->config.params[i] = cfg->kernel.params[i];
2242-
if (!isnan(cfg->window.params[i]))
2242+
if (!mp_isnan(cfg->window.params[i]))
22432243
par->config.wparams[i] = cfg->window.params[i];
22442244
}
22452245

@@ -2574,7 +2574,7 @@ static void update_render_options(struct vo *vo)
25742574
pars->color_map_params.tone_mapping_function = tone_map_funs[opts->tone_map.curve];
25752575
AV_NOWARN_DEPRECATED(
25762576
pars->color_map_params.tone_mapping_param = opts->tone_map.curve_param;
2577-
if (isnan(pars->color_map_params.tone_mapping_param)) // vo_gpu compatibility
2577+
if (mp_isnan(pars->color_map_params.tone_mapping_param)) // vo_gpu compatibility
25782578
pars->color_map_params.tone_mapping_param = 0.0;
25792579
)
25802580
pars->color_map_params.inverse_tone_mapping = opts->tone_map.inverse;

0 commit comments

Comments
 (0)