From fa8f5d1bf73eaaedd0be6be84a55ccb98779ad0f Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Sun, 3 Jul 2022 20:44:13 +0200 Subject: [PATCH] Update MPV headers --- Vendor/mpv/include/client.h | 118 +++++++++++++++++++++++++++++++++--- Vendor/mpv/include/render.h | 112 ++++++++++++++++++++++++++++++++++ 2 files changed, 220 insertions(+), 10 deletions(-) diff --git a/Vendor/mpv/include/client.h b/Vendor/mpv/include/client.h index 2e8dcdc9..da4be581 100644 --- a/Vendor/mpv/include/client.h +++ b/Vendor/mpv/include/client.h @@ -141,7 +141,15 @@ extern "C" { * - In certain cases, mpv may start sub processes (such as with the ytdl * wrapper script). * - Using UNIX IPC (off by default) will override the SIGPIPE signal handler, - * and set it to SIG_IGN. + * and set it to SIG_IGN. Some invocations of the "subprocess" command will + * also do that. + * - mpv will reseed the legacy C random number generator by calling srand() at + * some random point once. + * - mpv may start sub processes, so overriding SIGCHLD, or waiting on all PIDs + * (such as calling wait()) by the parent process or any other library within + * the process must be avoided. libmpv itself only waits for its own PIDs. + * - If anything in the process registers signal handlers, they must set the + * SA_RESTART flag. Otherwise you WILL get random failures on signals. * * Encoding of filenames * --------------------- @@ -227,7 +235,7 @@ extern "C" { * relational operators (<, >, <=, >=). */ #define MPV_MAKE_VERSION(major, minor) (((major) << 16) | (minor) | 0UL) -#define MPV_CLIENT_API_VERSION MPV_MAKE_VERSION(1, 107) +#define MPV_CLIENT_API_VERSION MPV_MAKE_VERSION(1, 109) /** * The API user is allowed to "#define MPV_ENABLE_DEPRECATED 0" before @@ -386,6 +394,23 @@ void mpv_free(void *data); */ const char *mpv_client_name(mpv_handle *ctx); +/** + * Return the ID of this client handle. Every client has its own unique ID. This + * ID is never reused by the core, even if the mpv_handle at hand gets destroyed + * and new handles get allocated. + * + * IDs are never 0 or negative. + * + * Some mpv APIs (not necessarily all) accept a name in the form "@" in + * addition of the proper mpv_client_name(), where "" is the ID in decimal + * form (e.g. "@123"). For example, the "script-message-to" command takes the + * client name as first argument, but also accepts the client ID formatted in + * this manner. + * + * @return The client ID. + */ +int64_t mpv_client_id(mpv_handle *ctx); + /** * Create a new mpv instance and an associated client API handle to control * the mpv instance. This instance is in a pre-initialized state, @@ -643,7 +668,9 @@ int64_t mpv_get_time_us(mpv_handle *ctx); */ typedef enum mpv_format { /** - * Invalid. Sometimes used for empty values. + * Invalid. Sometimes used for empty values. This is always defined to 0, + * so a normal 0-init of mpv_format (or e.g. mpv_node) is guaranteed to set + * this it to MPV_FORMAT_NONE (which makes some things saner as consequence). */ MPV_FORMAT_NONE = 0, /** @@ -760,8 +787,7 @@ typedef enum mpv_format { MPV_FORMAT_NODE_MAP = 8, /** * A raw, untyped byte array. Only used only with mpv_node, and only in - * some very special situations. (Currently, only for the screenshot-raw - * command.) + * some very specific situations. (Some commands use it.) */ MPV_FORMAT_BYTE_ARRAY = 9 } mpv_format; @@ -1006,6 +1032,11 @@ int mpv_command_string(mpv_handle *ctx, const char *args); * error code set if running the command failed. For commands that * return data, the data is put into mpv_event_command.result. * + * The only case when you do not receive an event is when the function call + * itself fails. This happens only if parsing the command itself (or otherwise + * validating it) fails, i.e. the return code of the API call is not 0 or + * positive. + * * Safe to be called from mpv render API threads. * * @param reply_userdata the value mpv_event.reply_userdata of the reply will @@ -1287,6 +1318,7 @@ typedef enum mpv_event_id { MPV_EVENT_COMMAND_REPLY = 5, /** * Notification before playback start of a file (before the file is loaded). + * See also mpv_event and mpv_event_start_file. */ MPV_EVENT_START_FILE = 6, /** @@ -1318,15 +1350,19 @@ typedef enum mpv_event_id { * and might be removed in the far future. */ MPV_EVENT_TRACK_SWITCHED = 10, -#endif /** * Idle mode was entered. In this mode, no file is played, and the playback * core waits for new commands. (The command line player normally quits * instead of entering idle mode, unless --idle was specified. If mpv * was started with mpv_create(), idle mode is enabled by default.) + * + * @deprecated This is equivalent to using mpv_observe_property() on the + * "idle-active" property. The event is redundant, and might be + * removed in the far future. As a further warning, this event + * is not necessarily sent at the right point anymore (at the + * start of the program), while the property behaves correctly. */ MPV_EVENT_IDLE = 11, -#if MPV_ENABLE_DEPRECATED /** * Playback was paused. This indicates the user pause state. * @@ -1419,9 +1455,9 @@ typedef enum mpv_event_id { MPV_EVENT_SEEK = 20, /** * There was a discontinuity of some sort (like a seek), and playback - * was reinitialized. Usually happens after seeking, or ordered chapter - * segment switches. The main purpose is allowing the client to detect - * when a seek request is finished. + * was reinitialized. Usually happens on start of playback and after + * seeking. The main purpose is allowing the client to detect when a seek + * request is finished. */ MPV_EVENT_PLAYBACK_RESTART = 21, /** @@ -1581,6 +1617,14 @@ typedef enum mpv_end_file_reason { MPV_END_FILE_REASON_REDIRECT = 5, } mpv_end_file_reason; +/// Since API version 1.108. +typedef struct mpv_event_start_file { + /** + * Playlist entry ID of the file being loaded now. + */ + int64_t playlist_entry_id; +} mpv_event_start_file; + typedef struct mpv_event_end_file { /** * Corresponds to the values in enum mpv_end_file_reason (the "int" type @@ -1596,6 +1640,34 @@ typedef struct mpv_event_end_file { * Since API version 1.9. */ int error; + /** + * Playlist entry ID of the file that was being played or attempted to be + * played. This has the same value as the playlist_entry_id field in the + * corresponding mpv_event_start_file event. + * Since API version 1.108. + */ + int64_t playlist_entry_id; + /** + * If loading ended, because the playlist entry to be played was for example + * a playlist, and the current playlist entry is replaced with a number of + * other entries. This may happen at least with MPV_END_FILE_REASON_REDIRECT + * (other event types may use this for similar but different purposes in the + * future). In this case, playlist_insert_id will be set to the playlist + * entry ID of the first inserted entry, and playlist_insert_num_entries to + * the total number of inserted playlist entries. Note this in this specific + * case, the ID of the last inserted entry is playlist_insert_id+num-1. + * Beware that depending on circumstances, you may observe the new playlist + * entries before seeing the event (e.g. reading the "playlist" property or + * getting a property change notification before receiving the event). + * Since API version 1.108. + */ + int64_t playlist_insert_id; + /** + * See playlist_insert_id. Only non-0 if playlist_insert_id is valid. Never + * negative. + * Since API version 1.108. + */ + int playlist_insert_num_entries; } mpv_event_end_file; #if MPV_ENABLE_DEPRECATED @@ -1675,6 +1747,7 @@ typedef struct mpv_event { * MPV_EVENT_PROPERTY_CHANGE: mpv_event_property* * MPV_EVENT_LOG_MESSAGE: mpv_event_log_message* * MPV_EVENT_CLIENT_MESSAGE: mpv_event_client_message* + * MPV_EVENT_START_FILE: mpv_event_start_file* (since v1.108) * MPV_EVENT_END_FILE: mpv_event_end_file* * MPV_EVENT_HOOK: mpv_event_hook* * MPV_EVENT_COMMAND_REPLY* mpv_event_command* @@ -1686,6 +1759,31 @@ typedef struct mpv_event { void *data; } mpv_event; +/** + * Convert the given src event to a mpv_node, and set *dst to the result. *dst + * is set to a MPV_FORMAT_NODE_MAP, with fields for corresponding mpv_event and + * mpv_event.data/mpv_event_* fields. + * + * The exact details are not completely documented out of laziness. A start + * is located in the "Events" section of the manpage. + * + * *dst may point to newly allocated memory, or pointers in mpv_event. You must + * copy the entire mpv_node if you want to reference it after mpv_event becomes + * invalid (such as making a new mpv_wait_event() call, or destroying the + * mpv_handle from which it was returned). Call mpv_free_node_contents() to free + * any memory allocations made by this API function. + * + * Safe to be called from mpv render API threads. + * + * @param dst Target. This is not read and fully overwritten. Must be released + * with mpv_free_node_contents(). Do not write to pointers returned + * by it. (On error, this may be left as an empty node.) + * @param src The source event. Not modified (it's not const due to the author's + * prejudice of the C version of const). + * @return error code (MPV_ERROR_NOMEM only, if at all) + */ +int mpv_event_to_node(mpv_node *dst, mpv_event *src); + /** * Enable or disable the given event. * diff --git a/Vendor/mpv/include/render.h b/Vendor/mpv/include/render.h index 293de3c9..06811d54 100644 --- a/Vendor/mpv/include/render.h +++ b/Vendor/mpv/include/render.h @@ -50,6 +50,7 @@ extern "C" { * ------------------ * * OpenGL: via MPV_RENDER_API_TYPE_OPENGL, see render_gl.h header. + * Software: via MPV_RENDER_API_TYPE_SW, see section "Software renderer" * * Threading * --------- @@ -120,6 +121,40 @@ extern "C" { * * You must free the context with mpv_render_context_free() before the mpv core * is destroyed. If this doesn't happen, undefined behavior will result. + * + * Software renderer + * ----------------- + * + * MPV_RENDER_API_TYPE_SW provides an extremely simple (but slow) renderer to + * memory surfaces. You probably don't want to use this. Use other render API + * types, or other methods of video embedding. + * + * Use mpv_render_context_create() with MPV_RENDER_PARAM_API_TYPE set to + * MPV_RENDER_API_TYPE_SW. + * + * Call mpv_render_context_render() with various MPV_RENDER_PARAM_SW_* fields + * to render the video frame to an in-memory surface. The following fields are + * required: MPV_RENDER_PARAM_SW_SIZE, MPV_RENDER_PARAM_SW_FORMAT, + * MPV_RENDER_PARAM_SW_STRIDE, MPV_RENDER_PARAM_SW_POINTER. + * + * This method of rendering is very slow, because everything, including color + * conversion, scaling, and OSD rendering, is done on the CPU, single-threaded. + * In particular, large video or display sizes, as well as presence of OSD or + * subtitles can make it too slow for realtime. As with other software rendering + * VOs, setting "sw-fast" may help. Enabling or disabling zimg may help, + * depending on the platform. + * + * In addition, certain multimedia job creation measures like HDR may not work + * properly, and will have to be manually handled by for example inserting + * filters. + * + * This API is not really suitable to extract individual frames from video etc. + * (basically non-playback uses) - there are better libraries for this. It can + * be used this way, but it may be clunky and tricky. + * + * Further notes: + * - MPV_RENDER_PARAM_FLIP_Y is currently ignored (unsupported) + * - MPV_RENDER_PARAM_DEPTH is ignored (meaningless) */ /** @@ -312,6 +347,80 @@ typedef enum mpv_render_param_type { * Type : struct mpv_opengl_drm_params_v2* */ MPV_RENDER_PARAM_DRM_DISPLAY_V2 = 16, + /** + * MPV_RENDER_API_TYPE_SW only: rendering target surface size, mandatory. + * Valid for MPV_RENDER_API_TYPE_SW & mpv_render_context_render(). + * Type: int[2] (e.g.: int s[2] = {w, h}; param.data = &s[0];) + * + * The video frame is transformed as with other VOs. Typically, this means + * the video gets scaled and black bars are added if the video size or + * aspect ratio mismatches with the target size. + */ + MPV_RENDER_PARAM_SW_SIZE = 17, + /** + * MPV_RENDER_API_TYPE_SW only: rendering target surface pixel format, + * mandatory. + * Valid for MPV_RENDER_API_TYPE_SW & mpv_render_context_render(). + * Type: char* (e.g.: char *f = "rgb0"; param.data = f;) + * + * Valid values are: + * "rgb0", "bgr0", "0bgr", "0rgb" + * 4 bytes per pixel RGB, 1 byte (8 bit) per component, component bytes + * with increasing address from left to right (e.g. "rgb0" has r at + * address 0), the "0" component contains uninitialized garbage (often + * the value 0, but not necessarily; the bad naming is inherited from + * FFmpeg) + * Pixel alignment size: 4 bytes + * "rgb24" + * 3 bytes per pixel RGB. This is strongly discouraged because it is + * very slow. + * Pixel alignment size: 1 bytes + * other + * The API may accept other pixel formats, using mpv internal format + * names, as long as it's internally marked as RGB, has exactly 1 + * plane, and is supported as conversion output. It is not a good idea + * to rely on any of these. Their semantics and handling could change. + */ + MPV_RENDER_PARAM_SW_FORMAT = 18, + /** + * MPV_RENDER_API_TYPE_SW only: rendering target surface bytes per line, + * mandatory. + * Valid for MPV_RENDER_API_TYPE_SW & mpv_render_context_render(). + * Type: size_t* + * + * This is the number of bytes between a pixel (x, y) and (x, y + 1) on the + * target surface. It must be a multiple of the pixel size, and have space + * for the surface width as specified by MPV_RENDER_PARAM_SW_SIZE. + * + * Both stride and pointer value should be a multiple of 64 to facilitate + * fast SIMD operation. Lower alignment might trigger slower code paths, + * and in the worst case, will copy the entire target frame. If mpv is built + * with zimg (and zimg is not disabled), the performance impact might be + * less. + * In either cases, the pointer and stride must be aligned at least to the + * pixel alignment size. Otherwise, crashes and undefined behavior is + * possible on platforms which do not support unaligned accesses (either + * through normal memory access or aligned SIMD memory access instructions). + */ + MPV_RENDER_PARAM_SW_STRIDE = 19, + /* + * MPV_RENDER_API_TYPE_SW only: rendering target surface pixel data pointer, + * mandatory. + * Valid for MPV_RENDER_API_TYPE_SW & mpv_render_context_render(). + * Type: void* + * + * This points to the first pixel at the left/top corner (0, 0). In + * particular, each line y starts at (pointer + stride * y). Upon rendering, + * all data between pointer and (pointer + stride * h) is overwritten. + * Whether the padding between (w, y) and (0, y + 1) is overwritten is left + * unspecified (it should not be, but unfortunately some scaler backends + * will do it anyway). It is assumed that even the padding after the last + * line (starting at bytepos(w, h) until (pointer + stride * h)) is + * writable. + * + * See MPV_RENDER_PARAM_SW_STRIDE for alignment requirements. + */ + MPV_RENDER_PARAM_SW_POINTER = 20, } mpv_render_param_type; /** @@ -354,7 +463,10 @@ typedef struct mpv_render_param { /** * Predefined values for MPV_RENDER_PARAM_API_TYPE. */ +// See render_gl.h #define MPV_RENDER_API_TYPE_OPENGL "opengl" +// See section "Software renderer" +#define MPV_RENDER_API_TYPE_SW "sw" /** * Flags used in mpv_render_frame_info.flags. Each value represents a bit in it.