diff --git a/.gitignore b/.gitignore index 29e15d9fd1..fdc85ccd6f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ *.exe *.pyc .depend +*~ /config.h /config.mak @@ -14,6 +15,7 @@ /input/input_conf.h /tags /TAGS +/ID /video/out/x11_icon.inc /demux/ebml_defs.c /demux/ebml_types.h diff --git a/common/av_log.c b/common/av_log.c index e07721852c..460309b537 100644 --- a/common/av_log.c +++ b/common/av_log.c @@ -36,14 +36,14 @@ #include #include +#include +#include #include #include #include #include #include #include -#include -#include #if HAVE_LIBAVDEVICE #include diff --git a/common/playlist.c b/common/playlist.c index 21e5f63097..2eca8b7a79 100644 --- a/common/playlist.c +++ b/common/playlist.c @@ -16,12 +16,12 @@ */ #include +#include #include "config.h" #include "playlist.h" #include "common/common.h" #include "common/global.h" #include "common/msg.h" -#include "misc/random.h" #include "mpv_talloc.h" #include "options/path.h" @@ -148,7 +148,7 @@ void playlist_shuffle(struct playlist *pl) for (int n = 0; n < pl->num_entries; n++) pl->entries[n]->original_index = n; for (int n = 0; n < pl->num_entries - 1; n++) { - size_t j = (size_t)((pl->num_entries - n) * mp_rand_next_double()); + size_t j = g_random_int_range(0, pl->num_entries - n); MPSWAP(struct playlist_entry *, pl->entries[n], pl->entries[n + j]); } playlist_update_indexes(pl, 0, -1); diff --git a/meson.build b/meson.build index c0c769736b..6dbbacd931 100644 --- a/meson.build +++ b/meson.build @@ -134,7 +134,6 @@ sources = files( 'misc/json.c', 'misc/natural_sort.c', 'misc/node.c', - 'misc/random.c', 'misc/rendezvous.c', 'misc/thread_pool.c', 'misc/thread_tools.c', diff --git a/misc/random.c b/misc/random.c deleted file mode 100644 index 780c67ec10..0000000000 --- a/misc/random.c +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Implementation of non-cryptographic pseudo-random number - * generator algorithm known as xoshiro. - * - * This file is part of mpv. - * - * mpv is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * mpv is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with mpv. If not, see . - */ - -#include -#include - -#include "random.h" - -static uint64_t state[4]; -static pthread_mutex_t state_mutex = PTHREAD_MUTEX_INITIALIZER; - -static inline uint64_t rotl_u64(const uint64_t x, const int k) -{ - return (x << k) | (x >> (64 - k)); -} - -static inline uint64_t splitmix64(uint64_t *const x) -{ - uint64_t z = (*x += UINT64_C(0x9e3779b97f4a7c15)); - z = (z ^ (z >> 30)) * UINT64_C(0xbf58476d1ce4e5b9); - z = (z ^ (z >> 27)) * UINT64_C(0x94d049bb133111eb); - return z ^ (z >> 31); -} - -void mp_rand_seed(uint64_t seed) -{ - pthread_mutex_lock(&state_mutex); - state[0] = seed; - for (int i = 1; i < 4; i++) - state[i] = splitmix64(&seed); - pthread_mutex_unlock(&state_mutex); -} - -uint64_t mp_rand_next(void) -{ - uint64_t result, t; - - pthread_mutex_lock(&state_mutex); - - result = rotl_u64(state[1] * 5, 7) * 9; - t = state[1] << 17; - - state[2] ^= state[0]; - state[3] ^= state[1]; - state[1] ^= state[2]; - state[0] ^= state[3]; - state[2] ^= t; - state[3] = rotl_u64(state[3], 45); - - pthread_mutex_unlock(&state_mutex); - - return result; -} - -double mp_rand_next_double(void) -{ - return (mp_rand_next() >> 11) * 0x1.0p-53; -} diff --git a/misc/random.h b/misc/random.h deleted file mode 100644 index 9a3bef2fbc..0000000000 --- a/misc/random.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Implementation of non-cryptographic pseudo-random number - * generator algorithm known as xoshiro. - * - * This file is part of mpv. - * - * mpv is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * mpv is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with mpv. If not, see . - */ - -#pragma once - -#include - -/* - * Initialize the pseudo-random number generator's state with - * the given 64-bit seed. - */ -void mp_rand_seed(uint64_t seed); - -/* - * Return the next 64-bit psuedo-random integer, and update the state - * accordingly. - */ -uint64_t mp_rand_next(void); - -/* - * Return a double value in the range of [0.0, 1.0) with uniform - * distribution, and update the state accordingly. - */ -double mp_rand_next_double(void); diff --git a/options/options.c b/options/options.c index 0b1c58d9a6..d944273b4e 100644 --- a/options/options.c +++ b/options/options.c @@ -716,8 +716,8 @@ static const m_option_t mp_opts[] = { OPT_FLAG(ignore_path_in_watch_later_config)}, {"watch-later-directory", OPT_STRING(watch_later_directory), .flags = M_OPT_FILE}, + {"watch-later-hmackey", OPT_STRING(watch_later_hmackey)}, {"watch-later-options", OPT_STRINGLIST(watch_later_options)}, - {"ordered-chapters", OPT_FLAG(ordered_chapters)}, {"ordered-chapters-files", OPT_STRING(ordered_chapters_files), .flags = M_OPT_FILE}, diff --git a/options/options.h b/options/options.h index f38f3b6bfb..d1ab97a079 100644 --- a/options/options.h +++ b/options/options.h @@ -256,6 +256,7 @@ typedef struct MPOpts { int write_filename_in_watch_later_config; int ignore_path_in_watch_later_config; char *watch_later_directory; + char *watch_later_hmackey; char **watch_later_options; int pause; int keep_open; diff --git a/osdep/io.c b/osdep/io.c index ec55aa2647..48553f4e45 100644 --- a/osdep/io.c +++ b/osdep/io.c @@ -28,11 +28,10 @@ #include #include #include - +#include #include "mpv_talloc.h" #include "config.h" -#include "misc/random.h" #include "osdep/io.h" #include "osdep/terminal.h" @@ -803,9 +802,7 @@ int mp_mkostemps(char *template, int suffixlen, int flags) } for (size_t fuckshit = 0; fuckshit < UINT32_MAX; fuckshit++) { - // Using a random value may make it require fewer iterations (even if - // not truly random; just a counter would be sufficient). - size_t fuckmess = mp_rand_next(); + size_t fuckmess = g_random_int(); char crap[7] = ""; snprintf(crap, sizeof(crap), "%06zx", fuckmess); memcpy(t, crap, 6); diff --git a/osdep/timer.c b/osdep/timer.c index 8a52823b0f..761a9f4a39 100644 --- a/osdep/timer.c +++ b/osdep/timer.c @@ -25,7 +25,6 @@ #include "common/common.h" #include "common/msg.h" -#include "misc/random.h" #include "timer.h" static uint64_t raw_time_offset; @@ -34,7 +33,6 @@ static pthread_once_t timer_init_once = PTHREAD_ONCE_INIT; static void do_timer_init(void) { mp_raw_time_init(); - mp_rand_seed(mp_raw_time_us()); raw_time_offset = mp_raw_time_us(); // Arbitrary additional offset to avoid confusing relative/absolute times. // Also,we rule that the timer never returns 0 (so default-initialized diff --git a/player/configfiles.c b/player/configfiles.c index 65dd9df425..5bcbbe5931 100644 --- a/player/configfiles.c +++ b/player/configfiles.c @@ -22,9 +22,10 @@ #include #include #include +#include +#include #include - -#include +#include #include "config.h" #include "mpv_talloc.h" @@ -199,23 +200,44 @@ static char *mp_get_playback_resume_config_filename(struct MPContext *mpctx, struct MPOpts *opts = mpctx->opts; char *res = NULL; void *tmp = talloc_new(NULL); - const char *realpath = fname; + const char *somepath = fname; bstr bfname = bstr0(fname); + AVHMAC *hmac; + char *mykey; + if (!mp_is_url(bfname)) { if (opts->ignore_path_in_watch_later_config) { - realpath = mp_basename(fname); + somepath = mp_basename(fname); } else { char *cwd = mp_getcwd(tmp); if (!cwd) goto exit; - realpath = mp_path_join(tmp, cwd, fname); + somepath = realpath(mp_path_join(tmp, cwd, fname), NULL); + if (somepath == NULL) { + goto exit; + } } + } else { + if (bstr_startswith0(bfname, "dvd://") && opts->dvd_opts && opts->dvd_opts->device) + somepath = talloc_asprintf(tmp, "%s - %s", somepath, opts->dvd_opts->device); + if ((bstr_startswith0(bfname, "br://") || bstr_startswith0(bfname, "bd://") || + bstr_startswith0(bfname, "bluray://")) && opts->bluray_device) + somepath = talloc_asprintf(tmp, "%s - %s", somepath, opts->bluray_device); } - uint8_t md5[16]; - av_md5_sum(md5, realpath, strlen(realpath)); + + uint8_t hmac_out[32]; + //MP_INFO(mpctx, "mp_get_playback_resume_config_filename hmac(\"%s\")\n", somepath); + hmac = av_hmac_alloc(AV_HMAC_SHA256); + if (hmac == NULL) goto exit; + if (mpctx->opts->watch_later_hmackey) + mykey = mpctx->opts->watch_later_hmackey; + else + mykey = ""; + av_hmac_calc(hmac, somepath, strlen(somepath), mykey, strlen(mykey), hmac_out, sizeof(hmac_out)); + char *conf = talloc_strdup(tmp, ""); - for (int i = 0; i < 16; i++) - conf = talloc_asprintf_append(conf, "%02X", md5[i]); + for (int i = 0; i < 32; i++) + conf = talloc_asprintf_append(conf, "%02X", hmac_out[i]); if (!mpctx->cached_watch_later_configdir) { char *wl_dir = mpctx->opts->watch_later_directory; diff --git a/player/lua/stats.lua b/player/lua/stats.lua index c9e3afc5c0..56d337aa38 100644 --- a/player/lua/stats.lua +++ b/player/lua/stats.lua @@ -762,6 +762,7 @@ local function add_audio(s) append(s, r["format"], {prefix="Format:", nl=cc and "" or o.nl}) append(s, r["samplerate"], {prefix="Sample Rate:", suffix=" Hz"}) append_property(s, "packet-audio-bitrate", {prefix="Bitrate:", suffix=" kbps"}) + append_property(s, "speed", {prefix="Speed:"}) append_filters(s, "af", "Filters:") end diff --git a/sub/lavc_conv.c b/sub/lavc_conv.c index d9f628492c..b02becdbc5 100644 --- a/sub/lavc_conv.c +++ b/sub/lavc_conv.c @@ -83,10 +83,6 @@ struct lavc_conv *lavc_conv_create(struct mp_log *log, const char *codec_name, goto error; if (mp_lavc_set_extradata(avctx, extradata, extradata_len) < 0) goto error; - -#if LIBAVCODEC_VERSION_MAJOR < 59 - av_dict_set(&opts, "sub_text_format", "ass", 0); -#endif av_dict_set(&opts, "flags2", "+ass_ro_flush_noop", 0); if (strcmp(codec_name, "eia_608") == 0) av_dict_set(&opts, "real_time", "1", 0); diff --git a/video/image_writer.c b/video/image_writer.c index a818bae9de..d1d80af7cf 100644 --- a/video/image_writer.c +++ b/video/image_writer.c @@ -77,7 +77,7 @@ const struct m_option image_writer_opts[] = { {"png-filter", OPT_INT(png_filter), M_RANGE(0, 5)}, {"webp-lossless", OPT_FLAG(webp_lossless)}, {"webp-quality", OPT_INT(webp_quality), M_RANGE(0, 100)}, - {"webp-compression", OPT_INT(webp_compression), M_RANGE(0, 6)}, + {"webp-compression", OPT_INT(webp_compression), M_RANGE(0, 9)}, #if HAVE_JPEGXL {"jxl-distance", OPT_DOUBLE(jxl_distance), M_RANGE(0.0, 15.0)}, {"jxl-effort", OPT_INT(jxl_effort), M_RANGE(1, 9)}, diff --git a/waftools/detections/compiler.py b/waftools/detections/compiler.py index 06baa98ac0..ef54fc568d 100644 --- a/waftools/detections/compiler.py +++ b/waftools/detections/compiler.py @@ -18,7 +18,10 @@ def __test_and_add_flags__(ctx, flags): def __add_generic_flags__(ctx): ctx.env.CFLAGS += ["-D_ISOC99_SOURCE", "-D_GNU_SOURCE", - "-D_FILE_OFFSET_BITS=64", "-Wall"] + "-D_FILE_OFFSET_BITS=64", "-Wall", + "-fPIC", "-fstack-protector-strong", + "-U_FORTIFY_SOURCE", "-D_FORTIFY_SOURCE=3", "-flto", + "-fstack-clash-protection", "-fcf-protection=full", "--param=ssp-buffer-size=4"] if ctx.check_cc(cflags="-std=c11", mandatory=False): ctx.env.CFLAGS += ["-std=c11"] @@ -26,10 +29,10 @@ def __add_generic_flags__(ctx): ctx.env.CFLAGS += ["-std=c99"] if ctx.is_optimization(): - ctx.env.CFLAGS += ['-O2'] + ctx.env.CFLAGS += ['-O3', "-march=native", "-gdwarf-4"] if ctx.is_debug_build(): - ctx.env.CFLAGS += ['-g'] + ctx.env.CFLAGS += ['-gdwarf-4'] __test_and_add_flags__(ctx, ["-Werror=implicit-function-declaration", "-Wno-error=deprecated-declarations", @@ -52,11 +55,13 @@ def __add_gcc_flags__(ctx): "-Wno-pointer-sign", # GCC bug 66425 "-Wno-unused-result"] + ctx.env.LAST_LINKFLAGS += ["-flto", "-pie", "-Wl,-z,relro", "-Wl,-z,now", "-lglib-2.0"] def __add_clang_flags__(ctx): ctx.env.CFLAGS += ["-Wno-logical-op-parentheses", "-fcolor-diagnostics", "-Wno-tautological-compare", "-Wno-tautological-constant-out-of-range-compare"] + ctx.env.LAST_LINKFLAGS += ["-pie", "-Wl,-z,relro", "-Wl,-z,now", "-lglib-2.0"] def __add_mswin_flags__(ctx): ctx.env.CFLAGS += ['-D_WIN32_WINNT=0x0602', '-DUNICODE', '-DCOBJMACROS', diff --git a/wscript_build.py b/wscript_build.py index 980eca19ad..a589c20e8e 100644 --- a/wscript_build.py +++ b/wscript_build.py @@ -335,7 +335,6 @@ def build(ctx): ( "misc/natural_sort.c" ), ( "misc/node.c" ), ( "misc/rendezvous.c" ), - ( "misc/random.c" ), ( "misc/thread_pool.c" ), ( "misc/thread_tools.c" ),