├── .gitignore
├── README.md
├── build.sh
├── clean.sh
├── compile.sh
├── download.sh
├── framework-meta
├── Info.plist
└── libmpv
│ ├── Headers
│ ├── client.h
│ ├── libmpv.h
│ ├── render.h
│ ├── render_gl.h
│ └── stream_cb.h
│ └── Modules
│ └── module.modulemap
├── patch.diff
├── scripts
├── ffmpeg-build
├── freetype-build
├── fribidi-build
├── harfbuzz-build
├── libass-build
├── mpv-build
└── uchardet-build
└── xcframework.sh
/.gitignore:
--------------------------------------------------------------------------------
1 | lib/
2 | downloads/
3 | src/
4 | scratch-ios/
5 | scratch-tv/
6 | openssl/
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # mpv iOS build scripts
2 |
3 | These are build scripts for building [libmpv](https://github.com/mpv-player/mpv), and its dependencies:
4 |
5 | * FFmpeg
6 | * libass
7 | * freetype
8 | * harfbuzz
9 | * fribidi
10 | * uchardet
11 |
12 | Currently used to help build [Outplayer](http://get.outplayer.app) on iOS.
13 |
14 | ## Configuration
15 |
16 | Tested with:
17 |
18 | * macOS 12.5
19 | * Xcode 14.1
20 |
21 | ## Usage
22 |
23 | 1. [Build OpenSSL](https://github.com/x2on/OpenSSL-for-iPhone/tree/dc64c470b5e1aeec5d66d861e6dc164478c9289b) for iOS and tvOS
24 | 2. Copy built OpenSSL libraries to `./openssl`
25 | 3. Run `./download.sh` to download and unarchive the projects' source
26 | 4. Run `./compile.sh -p PLATFORM -e ENVIRONMENT`, where platform is one of `ios`, `tv` and environment is one of:
27 |
28 | `development`: builds x86_64 and arm64 static libaries, and builds mpv with debug symbols and no optimization.
29 |
30 | `distribution`: builds arm64 static libraries, adds bitcode, and adds `-Os` to optimize for size and speed.
31 |
32 | 5. Run `./xcframework.sh` to create a framework from the development and distribution architectures.
33 |
34 | Alternatively, run `./build.sh` to build and create a framework for iOS and tvOS from the development and distribution architectures.
35 |
36 | ## References
37 |
38 | These scripts build upon [ybma-xbzheng/mpv-build-mac-iOS](https://github.com/ybma-xbzheng/mpv-build-mac-iOS) and [mpv-player/mpv-build](https://github.com/mpv-player/mpv-build)
--------------------------------------------------------------------------------
/build.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh -e
2 |
3 | ./compile.sh -p ios -e development && ./compile.sh -p ios -e distribution && ./compile.sh -p tv -e development && ./compile.sh -p tv -e distribution && ./xcframework.sh
4 |
--------------------------------------------------------------------------------
/clean.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh -e
2 |
3 | rm -rf downloads src scratch-ios scratch-tv lib-ios lib-tv
--------------------------------------------------------------------------------
/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh -e
2 |
3 | LIBRARIES="libuchardet libfribidi libfreetype libharfbuzz libass ffmpeg libmpv libssl"
4 | IOS_SDK_VERSION="15.5"
5 | TVOS_SDK_VERSION="15.4"
6 | DEPLOYMENT_TARGET="11.0"
7 |
8 | export PKG_CONFIG_PATH
9 | export LDFLAGS
10 | export CFLAGS
11 | export CXXFLAGS
12 | export COMMON_OPTIONS
13 | export ENVIRONMENT
14 | export ARCH
15 | export PLATFORM
16 | export CMAKE_OSX_ARCHITECTURES
17 |
18 | while getopts "p:e:" OPTION; do
19 | case $OPTION in
20 | e )
21 | ENVIRONMENT=$(echo "$OPTARG" | awk '{print tolower($0)}')
22 | ;;
23 | p )
24 | PLATFORM=$(echo "$OPTARG" | awk '{print tolower($0)}')
25 | ;;
26 | ? )
27 | echo "Invalid option"
28 | exit 1
29 | ;;
30 | esac
31 | done
32 |
33 | export PATH="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/:$PATH"
34 |
35 | if [[ "$ENVIRONMENT" = "distribution" ]]; then
36 | ARCHS="arm64"
37 | elif [[ "$ENVIRONMENT" = "development" ]]; then
38 | ARCHS="x86_64 arm64"
39 | elif [[ "$ENVIRONMENT" = "" ]]; then
40 | echo "An environment option is required (-e development or -e distribution)"
41 | exit 1
42 | else
43 | echo "Unhandled environment option"
44 | exit 1
45 | fi
46 |
47 | if [[ "$PLATFORM" = "ios" ]]; then
48 | SDK_VERSION=$IOS_SDK_VERSION
49 | PLATFORM_SIMULATOR="iPhoneSimulator"
50 | PLATFORM_DEVICE="iPhoneOS"
51 | SDKPATH_SIMULATOR="$(xcodebuild -sdk iphonesimulator -version Path)"
52 | SDKPATH_DEVICE="$(xcodebuild -sdk iphoneos -version Path)"
53 | MIN_VERSION_SIMULATOR_CFLAG="-mios-simulator-version-min"
54 | MIN_VERSION_SIMULATOR_LDFLAG="-Wl,-ios_simulator_version_min"
55 | MIN_VERSION_DEVICE_CFLAG="-mios-version-min"
56 | MIN_VERSION_DEVICE_LDFLAG="-Wl,-ios_version_min"
57 | elif [[ "$PLATFORM" = "tv" ]]; then
58 | SDK_VERSION=$TVOS_SDK_VERSION
59 | PLATFORM_SIMULATOR="AppleTVSimulator"
60 | PLATFORM_DEVICE="AppleTVOS"
61 | SDKPATH_SIMULATOR="$(xcodebuild -sdk appletvsimulator -version Path)"
62 | SDKPATH_DEVICE="$(xcodebuild -sdk appletvos -version Path)"
63 | MIN_VERSION_SIMULATOR_CFLAG="-mtvos-simulator-version-min"
64 | MIN_VERSION_SIMULATOR_LDFLAG="-Wl,-tvos_simulator_version_min"
65 | MIN_VERSION_DEVICE_CFLAG="-mtvos-version-min"
66 | MIN_VERSION_DEVICE_LDFLAG="-Wl,-tvos_version_min"
67 | elif [[ "$PLATFORM" = "" ]]; then
68 | echo "A platform option is required (-p ios or -p tv)"
69 | exit 1
70 | else
71 | echo "Unhandled platform option"
72 | exit 1
73 | fi
74 |
75 | ROOT="$(pwd)"
76 | SCRIPTS="$ROOT/scripts"
77 | SCRATCH="$ROOT/scratch-$PLATFORM"
78 | export SRC="$ROOT/src"
79 |
80 | for ARCH in $ARCHS; do
81 | if [[ $ARCH = "arm64" ]]; then
82 | HOSTFLAG="aarch64"
83 | CMAKE_OSX_ARCHITECTURES=$ARCH
84 | if [[ "$ENVIRONMENT" = "development" ]]; then
85 | PLATFORM=$PLATFORM_SIMULATOR
86 | export SDKPATH=$SDKPATH_SIMULATOR
87 | ACFLAGS="-arch $ARCH -isysroot $SDKPATH $MIN_VERSION_SIMULATOR_CFLAG=$DEPLOYMENT_TARGET"
88 | ALDFLAGS="-arch $ARCH -isysroot $SDKPATH $MIN_VERSION_SIMULATOR_LDFLAG,$DEPLOYMENT_TARGET -lbz2"
89 | OPENSSL="$ROOT/openssl/$PLATFORM$SDK_VERSION-arm64.sdk"
90 | else
91 | PLATFORM=$PLATFORM_DEVICE
92 | export SDKPATH=$SDKPATH_DEVICE
93 | ACFLAGS="-arch $ARCH -isysroot $SDKPATH $MIN_VERSION_DEVICE_CFLAG=$DEPLOYMENT_TARGET"
94 | ALDFLAGS="-arch $ARCH -isysroot $SDKPATH $MIN_VERSION_DEVICE_LDFLAG,$DEPLOYMENT_TARGET -lbz2"
95 | OPENSSL="$ROOT/openssl/$PLATFORM$SDK_VERSION-arm64.sdk"
96 | fi
97 | elif [[ $ARCH = "x86_64" ]]; then
98 | HOSTFLAG="x86_64"
99 | CMAKE_OSX_ARCHITECTURES=$ARCH
100 | PLATFORM=$PLATFORM_SIMULATOR
101 | export SDKPATH=$SDKPATH_SIMULATOR
102 | ACFLAGS="-arch $ARCH -isysroot $SDKPATH $MIN_VERSION_SIMULATOR_CFLAG=$DEPLOYMENT_TARGET"
103 | ALDFLAGS="-arch $ARCH -isysroot $SDKPATH $MIN_VERSION_SIMULATOR_LDFLAG,$DEPLOYMENT_TARGET -lbz2"
104 | OPENSSL="$ROOT/openssl/$PLATFORM$SDK_VERSION-x86_64.sdk"
105 | else
106 | echo "Unhandled architecture option"
107 | exit 1
108 | fi
109 |
110 | if [[ "$ENVIRONMENT" = "development" ]]; then
111 | CFLAGS="$ACFLAGS"
112 | LDFLAGS="$ALDFLAGS"
113 | else
114 | CFLAGS="$ACFLAGS -fembed-bitcode -Os"
115 | LDFLAGS="$ALDFLAGS -fembed-bitcode -Os"
116 | fi
117 | CXXFLAGS="$CFLAGS"
118 |
119 | CFLAGS="$CFLAGS -I$OPENSSL/include"
120 | LDFLAGS="$LDFLAGS -L$OPENSSL/lib"
121 |
122 | mkdir -p $SCRATCH
123 |
124 | PKG_CONFIG_PATH="$SCRATCH/$ARCH-$ENVIRONMENT/lib/pkgconfig"
125 | COMMON_OPTIONS="--prefix=$SCRATCH/$ARCH-$ENVIRONMENT --exec-prefix=$SCRATCH/$ARCH-$ENVIRONMENT --build=x86_64-apple-darwin14 --enable-static \
126 | --disable-shared --disable-dependency-tracking --with-pic --host=$HOSTFLAG"
127 |
128 | for LIBRARY in $LIBRARIES; do
129 | case $LIBRARY in
130 | "libfribidi" )
131 | mkdir -p $SCRATCH/$ARCH-$ENVIRONMENT/fribidi && cd $_ && $SCRIPTS/fribidi-build
132 | ;;
133 | "libfreetype" )
134 | mkdir -p $SCRATCH/$ARCH-$ENVIRONMENT/freetype && cd $_ && $SCRIPTS/freetype-build
135 | ;;
136 | "libharfbuzz" )
137 | mkdir -p $SCRATCH/$ARCH-$ENVIRONMENT/harfbuzz && cd $_ && $SCRIPTS/harfbuzz-build
138 | ;;
139 | "libass" )
140 | mkdir -p $SCRATCH/$ARCH-$ENVIRONMENT/libass && cd $_ && $SCRIPTS/libass-build
141 | ;;
142 | "libuchardet" )
143 | mkdir -p $SCRATCH/$ARCH-$ENVIRONMENT/uchardet && cd $_ && $SCRIPTS/uchardet-build
144 | ;;
145 | "ffmpeg" )
146 | mkdir -p $SCRATCH/$ARCH-$ENVIRONMENT/ffmpeg && cd $_ && $SCRIPTS/ffmpeg-build
147 | ;;
148 | "libmpv" )
149 | if [[ "$ENVIRONMENT" = "development" ]]; then
150 | CFLAGS="$ACFLAGS -fembed-bitcode -g2 -Og"
151 | LDFLAGS="$ALDFLAGS -fembed-bitcode -g2 -Og"
152 | fi
153 | $SCRIPTS/mpv-build && cp $SRC/mpv*/build/libmpv.a "$SCRATCH/$ARCH-$ENVIRONMENT/lib"
154 | ;;
155 | "libssl" )
156 | cp -a $OPENSSL/include/. $SCRATCH/$ARCH-$ENVIRONMENT/include/
157 | cp -a $OPENSSL/lib/. $SCRATCH/$ARCH-$ENVIRONMENT/lib/
158 | ;;
159 | esac
160 | done
161 | done
162 |
--------------------------------------------------------------------------------
/download.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh -e
2 |
3 | # Change to preferred versions
4 | MPV_VERSION="0.35.1"
5 | FFMPEG_VERSION="6.0"
6 | LIBASS_VERSION="0.14.0"
7 | FREETYPE_VERSION="2.10.0"
8 | HARFBUZZ_VERSION="2.9.0"
9 | FRIBIDI_VERSION="1.0.8"
10 | UCHARDET_VERSION="0.0.8"
11 |
12 | MPV_URL="https://github.com/mpv-player/mpv/archive/v$MPV_VERSION.tar.gz"
13 | FFMPEG_URL="http://www.ffmpeg.org/releases/ffmpeg-$FFMPEG_VERSION.tar.bz2"
14 | LIBASS_URL="https://github.com/libass/libass/releases/download/$LIBASS_VERSION/libass-$LIBASS_VERSION.tar.gz"
15 | FREETYPE_URL="https://sourceforge.net/projects/freetype/files/freetype2/$FREETYPE_VERSION/freetype-$FREETYPE_VERSION.tar.bz2"
16 | HARFBUZZ_URL="https://github.com/harfbuzz/harfbuzz/releases/download/$HARFBUZZ_VERSION/harfbuzz-$HARFBUZZ_VERSION.tar.xz"
17 | FRIBIDI_URL="https://github.com/fribidi/fribidi/releases/download/v$FRIBIDI_VERSION/fribidi-$FRIBIDI_VERSION.tar.bz2"
18 | UCHARDET_URL="https://www.freedesktop.org/software/uchardet/releases/uchardet-$UCHARDET_VERSION.tar.xz"
19 |
20 | rm -rf src
21 | mkdir -p src downloads
22 | for URL in $UCHARDET_URL $FREETYPE_URL $HARFBUZZ_URL $FRIBIDI_URL $LIBASS_URL $FFMPEG_URL $MPV_URL; do
23 | TARNAME=${URL##*/}
24 | if [ ! -f "downloads/$TARNAME" ]; then
25 | curl -f -L -- $URL > downloads/$TARNAME
26 | fi
27 | echo "$TARNAME"
28 | tar xvf downloads/$TARNAME -C src
29 | done
30 |
31 | sed -i "" "s/typedef ptrdiff_t GLsizeiptr;/typedef intptr_t GLsizeiptr;/" ./src/mpv-$MPV_VERSION/video/out/opengl/gl_headers.h;
32 |
33 | patch -p0 < patch.diff
34 |
35 | echo "\033[1;32mDownloaded: \033[0m\n mpv: $MPV_VERSION \
36 | \n FFmpeg: $FFMPEG_VERSION \
37 | \n libass: $LIBASS_VERSION \
38 | \n freetype: $FREETYPE_VERSION \
39 | \n harfbuzz: $HARFBUZZ_VERSION \
40 | \n fribidi: $FRIBIDI_VERSION \
41 | \n uchardet: $UCHARDET_VERSION "
--------------------------------------------------------------------------------
/framework-meta/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | {NAME}
9 | CFBundleIdentifier
10 | com.na.{NAME}
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | {NAME}
15 | CFBundlePackageType
16 | FMWK
17 |
18 |
--------------------------------------------------------------------------------
/framework-meta/libmpv/Headers/client.h:
--------------------------------------------------------------------------------
1 | /* Copyright (C) 2017 the mpv developers
2 | *
3 | * Permission to use, copy, modify, and/or distribute this software for any
4 | * purpose with or without fee is hereby granted, provided that the above
5 | * copyright notice and this permission notice appear in all copies.
6 | *
7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14 | */
15 |
16 | /*
17 | * Note: the client API is licensed under ISC (see above) to enable
18 | * other wrappers outside of mpv. But keep in mind that the
19 | * mpv core is by default still GPLv2+ - unless built with
20 | * --enable-lgpl, which makes it LGPLv2+.
21 | */
22 |
23 | #ifndef MPV_CLIENT_API_H_
24 | #define MPV_CLIENT_API_H_
25 |
26 | #include
27 | #include
28 |
29 | #ifdef __cplusplus
30 | extern "C" {
31 | #endif
32 |
33 | /**
34 | * Mechanisms provided by this API
35 | * -------------------------------
36 | *
37 | * This API provides general control over mpv playback. It does not give you
38 | * direct access to individual components of the player, only the whole thing.
39 | * It's somewhat equivalent to MPlayer's slave mode. You can send commands,
40 | * retrieve or set playback status or settings with properties, and receive
41 | * events.
42 | *
43 | * The API can be used in two ways:
44 | * 1) Internally in mpv, to provide additional features to the command line
45 | * player. Lua scripting uses this. (Currently there is no plugin API to
46 | * get a client API handle in external user code. It has to be a fixed
47 | * part of the player at compilation time.)
48 | * 2) Using mpv as a library with mpv_create(). This basically allows embedding
49 | * mpv in other applications.
50 | *
51 | * Documentation
52 | * -------------
53 | *
54 | * The libmpv C API is documented directly in this header. Note that most
55 | * actual interaction with this player is done through
56 | * options/commands/properties, which can be accessed through this API.
57 | * Essentially everything is done with them, including loading a file,
58 | * retrieving playback progress, and so on.
59 | *
60 | * These are documented elsewhere:
61 | * * http://mpv.io/manual/master/#options
62 | * * http://mpv.io/manual/master/#list-of-input-commands
63 | * * http://mpv.io/manual/master/#properties
64 | *
65 | * You can also look at the examples here:
66 | * * https://github.com/mpv-player/mpv-examples/tree/master/libmpv
67 | *
68 | * Event loop
69 | * ----------
70 | *
71 | * In general, the API user should run an event loop in order to receive events.
72 | * This event loop should call mpv_wait_event(), which will return once a new
73 | * mpv client API is available. It is also possible to integrate client API
74 | * usage in other event loops (e.g. GUI toolkits) with the
75 | * mpv_set_wakeup_callback() function, and then polling for events by calling
76 | * mpv_wait_event() with a 0 timeout.
77 | *
78 | * Note that the event loop is detached from the actual player. Not calling
79 | * mpv_wait_event() will not stop playback. It will eventually congest the
80 | * event queue of your API handle, though.
81 | *
82 | * Synchronous vs. asynchronous calls
83 | * ----------------------------------
84 | *
85 | * The API allows both synchronous and asynchronous calls. Synchronous calls
86 | * have to wait until the playback core is ready, which currently can take
87 | * an unbounded time (e.g. if network is slow or unresponsive). Asynchronous
88 | * calls just queue operations as requests, and return the result of the
89 | * operation as events.
90 | *
91 | * Asynchronous calls
92 | * ------------------
93 | *
94 | * The client API includes asynchronous functions. These allow you to send
95 | * requests instantly, and get replies as events at a later point. The
96 | * requests are made with functions carrying the _async suffix, and replies
97 | * are returned by mpv_wait_event() (interleaved with the normal event stream).
98 | *
99 | * A 64 bit userdata value is used to allow the user to associate requests
100 | * with replies. The value is passed as reply_userdata parameter to the request
101 | * function. The reply to the request will have the reply
102 | * mpv_event->reply_userdata field set to the same value as the
103 | * reply_userdata parameter of the corresponding request.
104 | *
105 | * This userdata value is arbitrary and is never interpreted by the API. Note
106 | * that the userdata value 0 is also allowed, but then the client must be
107 | * careful not accidentally interpret the mpv_event->reply_userdata if an
108 | * event is not a reply. (For non-replies, this field is set to 0.)
109 | *
110 | * Asynchronous calls may be reordered in arbitrarily with other synchronous
111 | * and asynchronous calls. If you want a guaranteed order, you need to wait
112 | * until asynchronous calls report completion before doing the next call.
113 | *
114 | * See also the section "Asynchronous command details" in the manpage.
115 | *
116 | * Multithreading
117 | * --------------
118 | *
119 | * The client API is generally fully thread-safe, unless otherwise noted.
120 | * Currently, there is no real advantage in using more than 1 thread to access
121 | * the client API, since everything is serialized through a single lock in the
122 | * playback core.
123 | *
124 | * Basic environment requirements
125 | * ------------------------------
126 | *
127 | * This documents basic requirements on the C environment. This is especially
128 | * important if mpv is used as library with mpv_create().
129 | *
130 | * - The LC_NUMERIC locale category must be set to "C". If your program calls
131 | * setlocale(), be sure not to use LC_ALL, or if you do, reset LC_NUMERIC
132 | * to its sane default: setlocale(LC_NUMERIC, "C").
133 | * - If a X11 based VO is used, mpv will set the xlib error handler. This error
134 | * handler is process-wide, and there's no proper way to share it with other
135 | * xlib users within the same process. This might confuse GUI toolkits.
136 | * - mpv uses some other libraries that are not library-safe, such as Fribidi
137 | * (used through libass), ALSA, FFmpeg, and possibly more.
138 | * - The FPU precision must be set at least to double precision.
139 | * - On Windows, mpv will call timeBeginPeriod(1).
140 | * - On memory exhaustion, mpv will kill the process.
141 | * - In certain cases, mpv may start sub processes (such as with the ytdl
142 | * wrapper script).
143 | * - Using UNIX IPC (off by default) will override the SIGPIPE signal handler,
144 | * and set it to SIG_IGN.
145 | * - mpv will reseed the legacy C random number generator by calling srand() at
146 | * some random point once.
147 | *
148 | * Encoding of filenames
149 | * ---------------------
150 | *
151 | * mpv uses UTF-8 everywhere.
152 | *
153 | * On some platforms (like Linux), filenames actually do not have to be UTF-8;
154 | * for this reason libmpv supports non-UTF-8 strings. libmpv uses what the
155 | * kernel uses and does not recode filenames. At least on Linux, passing a
156 | * string to libmpv is like passing a string to the fopen() function.
157 | *
158 | * On Windows, filenames are always UTF-8, libmpv converts between UTF-8 and
159 | * UTF-16 when using win32 API functions. libmpv never uses or accepts
160 | * filenames in the local 8 bit encoding. It does not use fopen() either;
161 | * it uses _wfopen().
162 | *
163 | * On OS X, filenames and other strings taken/returned by libmpv can have
164 | * inconsistent unicode normalization. This can sometimes lead to problems.
165 | * You have to hope for the best.
166 | *
167 | * Also see the remarks for MPV_FORMAT_STRING.
168 | *
169 | * Embedding the video window
170 | * --------------------------
171 | *
172 | * Using the render API (in render_cb.h) is recommended. This API requires
173 | * you to create and maintain an OpenGL context, to which you can render
174 | * video using a specific API call. This API does not include keyboard or mouse
175 | * input directly.
176 | *
177 | * There is an older way to embed the native mpv window into your own. You have
178 | * to get the raw window handle, and set it as "wid" option. This works on X11,
179 | * win32, and OSX only. It's much easier to use than the render API, but
180 | * also has various problems.
181 | *
182 | * Also see client API examples and the mpv manpage. There is an extensive
183 | * discussion here:
184 | * https://github.com/mpv-player/mpv-examples/tree/master/libmpv#methods-of-embedding-the-video-window
185 | *
186 | * Compatibility
187 | * -------------
188 | *
189 | * mpv development doesn't stand still, and changes to mpv internals as well as
190 | * to its interface can cause compatibility issues to client API users.
191 | *
192 | * The API is versioned (see MPV_CLIENT_API_VERSION), and changes to it are
193 | * documented in DOCS/client-api-changes.rst. The C API itself will probably
194 | * remain compatible for a long time, but the functionality exposed by it
195 | * could change more rapidly. For example, it's possible that options are
196 | * renamed, or change the set of allowed values.
197 | *
198 | * Defensive programming should be used to potentially deal with the fact that
199 | * options, commands, and properties could disappear, change their value range,
200 | * or change the underlying datatypes. It might be a good idea to prefer
201 | * MPV_FORMAT_STRING over other types to decouple your code from potential
202 | * mpv changes.
203 | *
204 | * Also see: DOCS/compatibility.rst
205 | *
206 | * Future changes
207 | * --------------
208 | *
209 | * This are the planned changes that will most likely be done on the next major
210 | * bump of the library:
211 | *
212 | * - remove all symbols and include files that are marked as deprecated
213 | * - reassign enum numerical values to remove gaps
214 | * - remove the mpv_opengl_init_params.extra_exts field
215 | * - change the type of mpv_event_end_file.reason
216 | * - disabling all events by default
217 | */
218 |
219 | /**
220 | * The version is incremented on each API change. The 16 lower bits form the
221 | * minor version number, and the 16 higher bits the major version number. If
222 | * the API becomes incompatible to previous versions, the major version
223 | * number is incremented. This affects only C part, and not properties and
224 | * options.
225 | *
226 | * Every API bump is described in DOCS/client-api-changes.rst
227 | *
228 | * You can use MPV_MAKE_VERSION() and compare the result with integer
229 | * relational operators (<, >, <=, >=).
230 | */
231 | #define MPV_MAKE_VERSION(major, minor) (((major) << 16) | (minor) | 0UL)
232 | #define MPV_CLIENT_API_VERSION MPV_MAKE_VERSION(1, 107)
233 |
234 | /**
235 | * The API user is allowed to "#define MPV_ENABLE_DEPRECATED 0" before
236 | * including any libmpv headers. Then deprecated symbols will be excluded
237 | * from the headers. (Of course, deprecated properties and commands and
238 | * other functionality will still work.)
239 | */
240 | #ifndef MPV_ENABLE_DEPRECATED
241 | #define MPV_ENABLE_DEPRECATED 1
242 | #endif
243 |
244 | /**
245 | * Return the MPV_CLIENT_API_VERSION the mpv source has been compiled with.
246 | */
247 | unsigned long mpv_client_api_version(void);
248 |
249 | /**
250 | * Client context used by the client API. Every client has its own private
251 | * handle.
252 | */
253 | typedef struct mpv_handle mpv_handle;
254 |
255 | /**
256 | * List of error codes than can be returned by API functions. 0 and positive
257 | * return values always mean success, negative values are always errors.
258 | */
259 | typedef enum mpv_error {
260 | /**
261 | * No error happened (used to signal successful operation).
262 | * Keep in mind that many API functions returning error codes can also
263 | * return positive values, which also indicate success. API users can
264 | * hardcode the fact that ">= 0" means success.
265 | */
266 | MPV_ERROR_SUCCESS = 0,
267 | /**
268 | * The event ringbuffer is full. This means the client is choked, and can't
269 | * receive any events. This can happen when too many asynchronous requests
270 | * have been made, but not answered. Probably never happens in practice,
271 | * unless the mpv core is frozen for some reason, and the client keeps
272 | * making asynchronous requests. (Bugs in the client API implementation
273 | * could also trigger this, e.g. if events become "lost".)
274 | */
275 | MPV_ERROR_EVENT_QUEUE_FULL = -1,
276 | /**
277 | * Memory allocation failed.
278 | */
279 | MPV_ERROR_NOMEM = -2,
280 | /**
281 | * The mpv core wasn't configured and initialized yet. See the notes in
282 | * mpv_create().
283 | */
284 | MPV_ERROR_UNINITIALIZED = -3,
285 | /**
286 | * Generic catch-all error if a parameter is set to an invalid or
287 | * unsupported value. This is used if there is no better error code.
288 | */
289 | MPV_ERROR_INVALID_PARAMETER = -4,
290 | /**
291 | * Trying to set an option that doesn't exist.
292 | */
293 | MPV_ERROR_OPTION_NOT_FOUND = -5,
294 | /**
295 | * Trying to set an option using an unsupported MPV_FORMAT.
296 | */
297 | MPV_ERROR_OPTION_FORMAT = -6,
298 | /**
299 | * Setting the option failed. Typically this happens if the provided option
300 | * value could not be parsed.
301 | */
302 | MPV_ERROR_OPTION_ERROR = -7,
303 | /**
304 | * The accessed property doesn't exist.
305 | */
306 | MPV_ERROR_PROPERTY_NOT_FOUND = -8,
307 | /**
308 | * Trying to set or get a property using an unsupported MPV_FORMAT.
309 | */
310 | MPV_ERROR_PROPERTY_FORMAT = -9,
311 | /**
312 | * The property exists, but is not available. This usually happens when the
313 | * associated subsystem is not active, e.g. querying audio parameters while
314 | * audio is disabled.
315 | */
316 | MPV_ERROR_PROPERTY_UNAVAILABLE = -10,
317 | /**
318 | * Error setting or getting a property.
319 | */
320 | MPV_ERROR_PROPERTY_ERROR = -11,
321 | /**
322 | * General error when running a command with mpv_command and similar.
323 | */
324 | MPV_ERROR_COMMAND = -12,
325 | /**
326 | * Generic error on loading (usually used with mpv_event_end_file.error).
327 | */
328 | MPV_ERROR_LOADING_FAILED = -13,
329 | /**
330 | * Initializing the audio output failed.
331 | */
332 | MPV_ERROR_AO_INIT_FAILED = -14,
333 | /**
334 | * Initializing the video output failed.
335 | */
336 | MPV_ERROR_VO_INIT_FAILED = -15,
337 | /**
338 | * There was no audio or video data to play. This also happens if the
339 | * file was recognized, but did not contain any audio or video streams,
340 | * or no streams were selected.
341 | */
342 | MPV_ERROR_NOTHING_TO_PLAY = -16,
343 | /**
344 | * When trying to load the file, the file format could not be determined,
345 | * or the file was too broken to open it.
346 | */
347 | MPV_ERROR_UNKNOWN_FORMAT = -17,
348 | /**
349 | * Generic error for signaling that certain system requirements are not
350 | * fulfilled.
351 | */
352 | MPV_ERROR_UNSUPPORTED = -18,
353 | /**
354 | * The API function which was called is a stub only.
355 | */
356 | MPV_ERROR_NOT_IMPLEMENTED = -19,
357 | /**
358 | * Unspecified error.
359 | */
360 | MPV_ERROR_GENERIC = -20
361 | } mpv_error;
362 |
363 | /**
364 | * Return a string describing the error. For unknown errors, the string
365 | * "unknown error" is returned.
366 | *
367 | * @param error error number, see enum mpv_error
368 | * @return A static string describing the error. The string is completely
369 | * static, i.e. doesn't need to be deallocated, and is valid forever.
370 | */
371 | const char *mpv_error_string(int error);
372 |
373 | /**
374 | * General function to deallocate memory returned by some of the API functions.
375 | * Call this only if it's explicitly documented as allowed. Calling this on
376 | * mpv memory not owned by the caller will lead to undefined behavior.
377 | *
378 | * @param data A valid pointer returned by the API, or NULL.
379 | */
380 | void mpv_free(void *data);
381 |
382 | /**
383 | * Return the name of this client handle. Every client has its own unique
384 | * name, which is mostly used for user interface purposes.
385 | *
386 | * @return The client name. The string is read-only and is valid until the
387 | * mpv_handle is destroyed.
388 | */
389 | const char *mpv_client_name(mpv_handle *ctx);
390 |
391 | /**
392 | * Create a new mpv instance and an associated client API handle to control
393 | * the mpv instance. This instance is in a pre-initialized state,
394 | * and needs to be initialized to be actually used with most other API
395 | * functions.
396 | *
397 | * Some API functions will return MPV_ERROR_UNINITIALIZED in the uninitialized
398 | * state. You can call mpv_set_property() (or mpv_set_property_string() and
399 | * other variants, and before mpv 0.21.0 mpv_set_option() etc.) to set initial
400 | * options. After this, call mpv_initialize() to start the player, and then use
401 | * e.g. mpv_command() to start playback of a file.
402 | *
403 | * The point of separating handle creation and actual initialization is that
404 | * you can configure things which can't be changed during runtime.
405 | *
406 | * Unlike the command line player, this will have initial settings suitable
407 | * for embedding in applications. The following settings are different:
408 | * - stdin/stdout/stderr and the terminal will never be accessed. This is
409 | * equivalent to setting the --no-terminal option.
410 | * (Technically, this also suppresses C signal handling.)
411 | * - No config files will be loaded. This is roughly equivalent to using
412 | * --config=no. Since libmpv 1.15, you can actually re-enable this option,
413 | * which will make libmpv load config files during mpv_initialize(). If you
414 | * do this, you are strongly encouraged to set the "config-dir" option too.
415 | * (Otherwise it will load the mpv command line player's config.)
416 | * For example:
417 | * mpv_set_option_string(mpv, "config-dir", "/my/path"); // set config root
418 | * mpv_set_option_string(mpv, "config", "yes"); // enable config loading
419 | * (call mpv_initialize() _after_ this)
420 | * - Idle mode is enabled, which means the playback core will enter idle mode
421 | * if there are no more files to play on the internal playlist, instead of
422 | * exiting. This is equivalent to the --idle option.
423 | * - Disable parts of input handling.
424 | * - Most of the different settings can be viewed with the command line player
425 | * by running "mpv --show-profile=libmpv".
426 | *
427 | * All this assumes that API users want a mpv instance that is strictly
428 | * isolated from the command line player's configuration, user settings, and
429 | * so on. You can re-enable disabled features by setting the appropriate
430 | * options.
431 | *
432 | * The mpv command line parser is not available through this API, but you can
433 | * set individual options with mpv_set_property(). Files for playback must be
434 | * loaded with mpv_command() or others.
435 | *
436 | * Note that you should avoid doing concurrent accesses on the uninitialized
437 | * client handle. (Whether concurrent access is definitely allowed or not has
438 | * yet to be decided.)
439 | *
440 | * @return a new mpv client API handle. Returns NULL on error. Currently, this
441 | * can happen in the following situations:
442 | * - out of memory
443 | * - LC_NUMERIC is not set to "C" (see general remarks)
444 | */
445 | mpv_handle *mpv_create(void);
446 |
447 | /**
448 | * Initialize an uninitialized mpv instance. If the mpv instance is already
449 | * running, an error is returned.
450 | *
451 | * This function needs to be called to make full use of the client API if the
452 | * client API handle was created with mpv_create().
453 | *
454 | * Only the following options are required to be set _before_ mpv_initialize():
455 | * - options which are only read at initialization time:
456 | * - config
457 | * - config-dir
458 | * - input-conf
459 | * - load-scripts
460 | * - script
461 | * - player-operation-mode
462 | * - input-app-events (OSX)
463 | * - all encoding mode options
464 | *
465 | * @return error code
466 | */
467 | int mpv_initialize(mpv_handle *ctx);
468 |
469 | /**
470 | * Disconnect and destroy the mpv_handle. ctx will be deallocated with this
471 | * API call.
472 | *
473 | * If the last mpv_handle is detached, the core player is destroyed. In
474 | * addition, if there are only weak mpv_handles (such as created by
475 | * mpv_create_weak_client() or internal scripts), these mpv_handles will
476 | * be sent MPV_EVENT_SHUTDOWN. This function may block until these clients
477 | * have responded to the shutdown event, and the core is finally destroyed.
478 | */
479 | void mpv_destroy(mpv_handle *ctx);
480 |
481 | #if MPV_ENABLE_DEPRECATED
482 | /**
483 | * @deprecated use mpv_destroy(), which has exactly the same semantics (the
484 | * deprecation is a mere rename)
485 | *
486 | * Since mpv client API version 1.29:
487 | * If the last mpv_handle is detached, the core player is destroyed. In
488 | * addition, if there are only weak mpv_handles (such as created by
489 | * mpv_create_weak_client() or internal scripts), these mpv_handles will
490 | * be sent MPV_EVENT_SHUTDOWN. This function may block until these clients
491 | * have responded to the shutdown event, and the core is finally destroyed.
492 | *
493 | * Before mpv client API version 1.29:
494 | * This left the player running. If you want to be sure that the
495 | * player is terminated, send a "quit" command, and wait until the
496 | * MPV_EVENT_SHUTDOWN event is received, or use mpv_terminate_destroy().
497 | */
498 | void mpv_detach_destroy(mpv_handle *ctx);
499 | #endif
500 |
501 | /**
502 | * Similar to mpv_destroy(), but brings the player and all clients down
503 | * as well, and waits until all of them are destroyed. This function blocks. The
504 | * advantage over mpv_destroy() is that while mpv_destroy() merely
505 | * detaches the client handle from the player, this function quits the player,
506 | * waits until all other clients are destroyed (i.e. all mpv_handles are
507 | * detached), and also waits for the final termination of the player.
508 | *
509 | * Since mpv_destroy() is called somewhere on the way, it's not safe to
510 | * call other functions concurrently on the same context.
511 | *
512 | * Since mpv client API version 1.29:
513 | * The first call on any mpv_handle will block until the core is destroyed.
514 | * This means it will wait until other mpv_handle have been destroyed. If you
515 | * want asynchronous destruction, just run the "quit" command, and then react
516 | * to the MPV_EVENT_SHUTDOWN event.
517 | * If another mpv_handle already called mpv_terminate_destroy(), this call will
518 | * not actually block. It will destroy the mpv_handle, and exit immediately,
519 | * while other mpv_handles might still be uninitializing.
520 | *
521 | * Before mpv client API version 1.29:
522 | * If this is called on a mpv_handle that was not created with mpv_create(),
523 | * this function will merely send a quit command and then call
524 | * mpv_destroy(), without waiting for the actual shutdown.
525 | */
526 | void mpv_terminate_destroy(mpv_handle *ctx);
527 |
528 | /**
529 | * Create a new client handle connected to the same player core as ctx. This
530 | * context has its own event queue, its own mpv_request_event() state, its own
531 | * mpv_request_log_messages() state, its own set of observed properties, and
532 | * its own state for asynchronous operations. Otherwise, everything is shared.
533 | *
534 | * This handle should be destroyed with mpv_destroy() if no longer
535 | * needed. The core will live as long as there is at least 1 handle referencing
536 | * it. Any handle can make the core quit, which will result in every handle
537 | * receiving MPV_EVENT_SHUTDOWN.
538 | *
539 | * This function can not be called before the main handle was initialized with
540 | * mpv_initialize(). The new handle is always initialized, unless ctx=NULL was
541 | * passed.
542 | *
543 | * @param ctx Used to get the reference to the mpv core; handle-specific
544 | * settings and parameters are not used.
545 | * If NULL, this function behaves like mpv_create() (ignores name).
546 | * @param name The client name. This will be returned by mpv_client_name(). If
547 | * the name is already in use, or contains non-alphanumeric
548 | * characters (other than '_'), the name is modified to fit.
549 | * If NULL, an arbitrary name is automatically chosen.
550 | * @return a new handle, or NULL on error
551 | */
552 | mpv_handle *mpv_create_client(mpv_handle *ctx, const char *name);
553 |
554 | /**
555 | * This is the same as mpv_create_client(), but the created mpv_handle is
556 | * treated as a weak reference. If all mpv_handles referencing a core are
557 | * weak references, the core is automatically destroyed. (This still goes
558 | * through normal uninit of course. Effectively, if the last non-weak mpv_handle
559 | * is destroyed, then the weak mpv_handles receive MPV_EVENT_SHUTDOWN and are
560 | * asked to terminate as well.)
561 | *
562 | * Note if you want to use this like refcounting: you have to be aware that
563 | * mpv_terminate_destroy() _and_ mpv_destroy() for the last non-weak
564 | * mpv_handle will block until all weak mpv_handles are destroyed.
565 | */
566 | mpv_handle *mpv_create_weak_client(mpv_handle *ctx, const char *name);
567 |
568 | /**
569 | * Load a config file. This loads and parses the file, and sets every entry in
570 | * the config file's default section as if mpv_set_option_string() is called.
571 | *
572 | * The filename should be an absolute path. If it isn't, the actual path used
573 | * is unspecified. (Note: an absolute path starts with '/' on UNIX.) If the
574 | * file wasn't found, MPV_ERROR_INVALID_PARAMETER is returned.
575 | *
576 | * If a fatal error happens when parsing a config file, MPV_ERROR_OPTION_ERROR
577 | * is returned. Errors when setting options as well as other types or errors
578 | * are ignored (even if options do not exist). You can still try to capture
579 | * the resulting error messages with mpv_request_log_messages(). Note that it's
580 | * possible that some options were successfully set even if any of these errors
581 | * happen.
582 | *
583 | * @param filename absolute path to the config file on the local filesystem
584 | * @return error code
585 | */
586 | int mpv_load_config_file(mpv_handle *ctx, const char *filename);
587 |
588 | #if MPV_ENABLE_DEPRECATED
589 |
590 | /**
591 | * This does nothing since mpv 0.23.0 (API version 1.24). Below is the
592 | * description of the old behavior.
593 | *
594 | * Stop the playback thread. This means the core will stop doing anything, and
595 | * only run and answer to client API requests. This is sometimes useful; for
596 | * example, no new frame will be queued to the video output, so doing requests
597 | * which have to wait on the video output can run instantly.
598 | *
599 | * Suspension is reentrant and recursive for convenience. Any thread can call
600 | * the suspend function multiple times, and the playback thread will remain
601 | * suspended until the last thread resumes it. Note that during suspension, all
602 | * clients still have concurrent access to the core, which is serialized through
603 | * a single mutex.
604 | *
605 | * Call mpv_resume() to resume the playback thread. You must call mpv_resume()
606 | * for each mpv_suspend() call. Calling mpv_resume() more often than
607 | * mpv_suspend() is not allowed.
608 | *
609 | * Calling this on an uninitialized player (see mpv_create()) will deadlock.
610 | *
611 | * @deprecated This function, as well as mpv_resume(), are deprecated, and
612 | * will stop doing anything soon. Their semantics were never
613 | * well-defined, and their usefulness is extremely limited. The
614 | * calls will remain stubs in order to keep ABI compatibility.
615 | */
616 | void mpv_suspend(mpv_handle *ctx);
617 |
618 | /**
619 | * See mpv_suspend().
620 | */
621 | void mpv_resume(mpv_handle *ctx);
622 |
623 | #endif
624 |
625 | /**
626 | * Return the internal time in microseconds. This has an arbitrary start offset,
627 | * but will never wrap or go backwards.
628 | *
629 | * Note that this is always the real time, and doesn't necessarily have to do
630 | * with playback time. For example, playback could go faster or slower due to
631 | * playback speed, or due to playback being paused. Use the "time-pos" property
632 | * instead to get the playback status.
633 | *
634 | * Unlike other libmpv APIs, this can be called at absolutely any time (even
635 | * within wakeup callbacks), as long as the context is valid.
636 | *
637 | * Safe to be called from mpv render API threads.
638 | */
639 | int64_t mpv_get_time_us(mpv_handle *ctx);
640 |
641 | /**
642 | * Data format for options and properties. The API functions to get/set
643 | * properties and options support multiple formats, and this enum describes
644 | * them.
645 | */
646 | typedef enum mpv_format {
647 | /**
648 | * Invalid. Sometimes used for empty values.
649 | */
650 | MPV_FORMAT_NONE = 0,
651 | /**
652 | * The basic type is char*. It returns the raw property string, like
653 | * using ${=property} in input.conf (see input.rst).
654 | *
655 | * NULL isn't an allowed value.
656 | *
657 | * Warning: although the encoding is usually UTF-8, this is not always the
658 | * case. File tags often store strings in some legacy codepage,
659 | * and even filenames don't necessarily have to be in UTF-8 (at
660 | * least on Linux). If you pass the strings to code that requires
661 | * valid UTF-8, you have to sanitize it in some way.
662 | * On Windows, filenames are always UTF-8, and libmpv converts
663 | * between UTF-8 and UTF-16 when using win32 API functions. See
664 | * the "Encoding of filenames" section for details.
665 | *
666 | * Example for reading:
667 | *
668 | * char *result = NULL;
669 | * if (mpv_get_property(ctx, "property", MPV_FORMAT_STRING, &result) < 0)
670 | * goto error;
671 | * printf("%s\n", result);
672 | * mpv_free(result);
673 | *
674 | * Or just use mpv_get_property_string().
675 | *
676 | * Example for writing:
677 | *
678 | * char *value = "the new value";
679 | * // yep, you pass the address to the variable
680 | * // (needed for symmetry with other types and mpv_get_property)
681 | * mpv_set_property(ctx, "property", MPV_FORMAT_STRING, &value);
682 | *
683 | * Or just use mpv_set_property_string().
684 | *
685 | */
686 | MPV_FORMAT_STRING = 1,
687 | /**
688 | * The basic type is char*. It returns the OSD property string, like
689 | * using ${property} in input.conf (see input.rst). In many cases, this
690 | * is the same as the raw string, but in other cases it's formatted for
691 | * display on OSD. It's intended to be human readable. Do not attempt to
692 | * parse these strings.
693 | *
694 | * Only valid when doing read access. The rest works like MPV_FORMAT_STRING.
695 | */
696 | MPV_FORMAT_OSD_STRING = 2,
697 | /**
698 | * The basic type is int. The only allowed values are 0 ("no")
699 | * and 1 ("yes").
700 | *
701 | * Example for reading:
702 | *
703 | * int result;
704 | * if (mpv_get_property(ctx, "property", MPV_FORMAT_FLAG, &result) < 0)
705 | * goto error;
706 | * printf("%s\n", result ? "true" : "false");
707 | *
708 | * Example for writing:
709 | *
710 | * int flag = 1;
711 | * mpv_set_property(ctx, "property", MPV_FORMAT_FLAG, &flag);
712 | */
713 | MPV_FORMAT_FLAG = 3,
714 | /**
715 | * The basic type is int64_t.
716 | */
717 | MPV_FORMAT_INT64 = 4,
718 | /**
719 | * The basic type is double.
720 | */
721 | MPV_FORMAT_DOUBLE = 5,
722 | /**
723 | * The type is mpv_node.
724 | *
725 | * For reading, you usually would pass a pointer to a stack-allocated
726 | * mpv_node value to mpv, and when you're done you call
727 | * mpv_free_node_contents(&node).
728 | * You're expected not to write to the data - if you have to, copy it
729 | * first (which you have to do manually).
730 | *
731 | * For writing, you construct your own mpv_node, and pass a pointer to the
732 | * API. The API will never write to your data (and copy it if needed), so
733 | * you're free to use any form of allocation or memory management you like.
734 | *
735 | * Warning: when reading, always check the mpv_node.format member. For
736 | * example, properties might change their type in future versions
737 | * of mpv, or sometimes even during runtime.
738 | *
739 | * Example for reading:
740 | *
741 | * mpv_node result;
742 | * if (mpv_get_property(ctx, "property", MPV_FORMAT_NODE, &result) < 0)
743 | * goto error;
744 | * printf("format=%d\n", (int)result.format);
745 | * mpv_free_node_contents(&result).
746 | *
747 | * Example for writing:
748 | *
749 | * mpv_node value;
750 | * value.format = MPV_FORMAT_STRING;
751 | * value.u.string = "hello";
752 | * mpv_set_property(ctx, "property", MPV_FORMAT_NODE, &value);
753 | */
754 | MPV_FORMAT_NODE = 6,
755 | /**
756 | * Used with mpv_node only. Can usually not be used directly.
757 | */
758 | MPV_FORMAT_NODE_ARRAY = 7,
759 | /**
760 | * See MPV_FORMAT_NODE_ARRAY.
761 | */
762 | MPV_FORMAT_NODE_MAP = 8,
763 | /**
764 | * A raw, untyped byte array. Only used only with mpv_node, and only in
765 | * some very special situations. (Currently, only for the screenshot-raw
766 | * command.)
767 | */
768 | MPV_FORMAT_BYTE_ARRAY = 9
769 | } mpv_format;
770 |
771 | /**
772 | * Generic data storage.
773 | *
774 | * If mpv writes this struct (e.g. via mpv_get_property()), you must not change
775 | * the data. In some cases (mpv_get_property()), you have to free it with
776 | * mpv_free_node_contents(). If you fill this struct yourself, you're also
777 | * responsible for freeing it, and you must not call mpv_free_node_contents().
778 | */
779 | typedef struct mpv_node {
780 | union {
781 | char *string; /** valid if format==MPV_FORMAT_STRING */
782 | int flag; /** valid if format==MPV_FORMAT_FLAG */
783 | int64_t int64; /** valid if format==MPV_FORMAT_INT64 */
784 | double double_; /** valid if format==MPV_FORMAT_DOUBLE */
785 | /**
786 | * valid if format==MPV_FORMAT_NODE_ARRAY
787 | * or if format==MPV_FORMAT_NODE_MAP
788 | */
789 | struct mpv_node_list *list;
790 | /**
791 | * valid if format==MPV_FORMAT_BYTE_ARRAY
792 | */
793 | struct mpv_byte_array *ba;
794 | } u;
795 | /**
796 | * Type of the data stored in this struct. This value rules what members in
797 | * the given union can be accessed. The following formats are currently
798 | * defined to be allowed in mpv_node:
799 | *
800 | * MPV_FORMAT_STRING (u.string)
801 | * MPV_FORMAT_FLAG (u.flag)
802 | * MPV_FORMAT_INT64 (u.int64)
803 | * MPV_FORMAT_DOUBLE (u.double_)
804 | * MPV_FORMAT_NODE_ARRAY (u.list)
805 | * MPV_FORMAT_NODE_MAP (u.list)
806 | * MPV_FORMAT_BYTE_ARRAY (u.ba)
807 | * MPV_FORMAT_NONE (no member)
808 | *
809 | * If you encounter a value you don't know, you must not make any
810 | * assumptions about the contents of union u.
811 | */
812 | mpv_format format;
813 | } mpv_node;
814 |
815 | /**
816 | * (see mpv_node)
817 | */
818 | typedef struct mpv_node_list {
819 | /**
820 | * Number of entries. Negative values are not allowed.
821 | */
822 | int num;
823 | /**
824 | * MPV_FORMAT_NODE_ARRAY:
825 | * values[N] refers to value of the Nth item
826 | *
827 | * MPV_FORMAT_NODE_MAP:
828 | * values[N] refers to value of the Nth key/value pair
829 | *
830 | * If num > 0, values[0] to values[num-1] (inclusive) are valid.
831 | * Otherwise, this can be NULL.
832 | */
833 | mpv_node *values;
834 | /**
835 | * MPV_FORMAT_NODE_ARRAY:
836 | * unused (typically NULL), access is not allowed
837 | *
838 | * MPV_FORMAT_NODE_MAP:
839 | * keys[N] refers to key of the Nth key/value pair. If num > 0, keys[0] to
840 | * keys[num-1] (inclusive) are valid. Otherwise, this can be NULL.
841 | * The keys are in random order. The only guarantee is that keys[N] belongs
842 | * to the value values[N]. NULL keys are not allowed.
843 | */
844 | char **keys;
845 | } mpv_node_list;
846 |
847 | /**
848 | * (see mpv_node)
849 | */
850 | typedef struct mpv_byte_array {
851 | /**
852 | * Pointer to the data. In what format the data is stored is up to whatever
853 | * uses MPV_FORMAT_BYTE_ARRAY.
854 | */
855 | void *data;
856 | /**
857 | * Size of the data pointed to by ptr.
858 | */
859 | size_t size;
860 | } mpv_byte_array;
861 |
862 | /**
863 | * Frees any data referenced by the node. It doesn't free the node itself.
864 | * Call this only if the mpv client API set the node. If you constructed the
865 | * node yourself (manually), you have to free it yourself.
866 | *
867 | * If node->format is MPV_FORMAT_NONE, this call does nothing. Likewise, if
868 | * the client API sets a node with this format, this function doesn't need to
869 | * be called. (This is just a clarification that there's no danger of anything
870 | * strange happening in these cases.)
871 | */
872 | void mpv_free_node_contents(mpv_node *node);
873 |
874 | /**
875 | * Set an option. Note that you can't normally set options during runtime. It
876 | * works in uninitialized state (see mpv_create()), and in some cases in at
877 | * runtime.
878 | *
879 | * Using a format other than MPV_FORMAT_NODE is equivalent to constructing a
880 | * mpv_node with the given format and data, and passing the mpv_node to this
881 | * function.
882 | *
883 | * Note: this is semi-deprecated. For most purposes, this is not needed anymore.
884 | * Starting with mpv version 0.21.0 (version 1.23) most options can be set
885 | * with mpv_set_property() (and related functions), and even before
886 | * mpv_initialize(). In some obscure corner cases, using this function
887 | * to set options might still be required (see below, and also section
888 | * "Inconsistencies between options and properties" on the manpage). Once
889 | * these are resolved, the option setting functions might be fully
890 | * deprecated.
891 | *
892 | * The following options still need to be set either _before_
893 | * mpv_initialize() with mpv_set_property() (or related functions), or
894 | * with mpv_set_option() (or related functions) at any time:
895 | * - options shadowed by deprecated properties:
896 | * - demuxer (property deprecated in 0.21.0)
897 | * - idle (property deprecated in 0.21.0)
898 | * - fps (property deprecated in 0.21.0)
899 | * - cache (property deprecated in 0.21.0)
900 | * - length (property deprecated in 0.10.0)
901 | * - audio-samplerate (property deprecated in 0.10.0)
902 | * - audio-channels (property deprecated in 0.10.0)
903 | * - audio-format (property deprecated in 0.10.0)
904 | * - deprecated options shadowed by properties:
905 | * - chapter (option deprecated in 0.21.0)
906 | * - playlist-pos (option deprecated in 0.21.0)
907 | * The deprecated properties were removed in mpv 0.23.0.
908 | *
909 | * @param name Option name. This is the same as on the mpv command line, but
910 | * without the leading "--".
911 | * @param format see enum mpv_format.
912 | * @param[in] data Option value (according to the format).
913 | * @return error code
914 | */
915 | int mpv_set_option(mpv_handle *ctx, const char *name, mpv_format format,
916 | void *data);
917 |
918 | /**
919 | * Convenience function to set an option to a string value. This is like
920 | * calling mpv_set_option() with MPV_FORMAT_STRING.
921 | *
922 | * @return error code
923 | */
924 | int mpv_set_option_string(mpv_handle *ctx, const char *name, const char *data);
925 |
926 | /**
927 | * Send a command to the player. Commands are the same as those used in
928 | * input.conf, except that this function takes parameters in a pre-split
929 | * form.
930 | *
931 | * The commands and their parameters are documented in input.rst.
932 | *
933 | * Does not use OSD and string expansion by default (unlike mpv_command_string()
934 | * and input.conf).
935 | *
936 | * @param[in] args NULL-terminated list of strings. Usually, the first item
937 | * is the command, and the following items are arguments.
938 | * @return error code
939 | */
940 | int mpv_command(mpv_handle *ctx, const char **args);
941 |
942 | /**
943 | * Same as mpv_command(), but allows passing structured data in any format.
944 | * In particular, calling mpv_command() is exactly like calling
945 | * mpv_command_node() with the format set to MPV_FORMAT_NODE_ARRAY, and
946 | * every arg passed in order as MPV_FORMAT_STRING.
947 | *
948 | * Does not use OSD and string expansion by default.
949 | *
950 | * The args argument can have one of the following formats:
951 | *
952 | * MPV_FORMAT_NODE_ARRAY:
953 | * Positional arguments. Each entry is an argument using an arbitrary
954 | * format (the format must be compatible to the used command). Usually,
955 | * the first item is the command name (as MPV_FORMAT_STRING). The order
956 | * of arguments is as documented in each command description.
957 | *
958 | * MPV_FORMAT_NODE_MAP:
959 | * Named arguments. This requires at least an entry with the key "name"
960 | * to be present, which must be a string, and contains the command name.
961 | * The special entry "_flags" is optional, and if present, must be an
962 | * array of strings, each being a command prefix to apply. All other
963 | * entries are interpreted as arguments. They must use the argument names
964 | * as documented in each command description. Some commands do not
965 | * support named arguments at all, and must use MPV_FORMAT_NODE_ARRAY.
966 | *
967 | * @param[in] args mpv_node with format set to one of the values documented
968 | * above (see there for details)
969 | * @param[out] result Optional, pass NULL if unused. If not NULL, and if the
970 | * function succeeds, this is set to command-specific return
971 | * data. You must call mpv_free_node_contents() to free it
972 | * (again, only if the command actually succeeds).
973 | * Not many commands actually use this at all.
974 | * @return error code (the result parameter is not set on error)
975 | */
976 | int mpv_command_node(mpv_handle *ctx, mpv_node *args, mpv_node *result);
977 |
978 | /**
979 | * This is essentially identical to mpv_command() but it also returns a result.
980 | *
981 | * Does not use OSD and string expansion by default.
982 | *
983 | * @param[in] args NULL-terminated list of strings. Usually, the first item
984 | * is the command, and the following items are arguments.
985 | * @param[out] result Optional, pass NULL if unused. If not NULL, and if the
986 | * function succeeds, this is set to command-specific return
987 | * data. You must call mpv_free_node_contents() to free it
988 | * (again, only if the command actually succeeds).
989 | * Not many commands actually use this at all.
990 | * @return error code (the result parameter is not set on error)
991 | */
992 | int mpv_command_ret(mpv_handle *ctx, const char **args, mpv_node *result);
993 |
994 | /**
995 | * Same as mpv_command, but use input.conf parsing for splitting arguments.
996 | * This is slightly simpler, but also more error prone, since arguments may
997 | * need quoting/escaping.
998 | *
999 | * This also has OSD and string expansion enabled by default.
1000 | */
1001 | int mpv_command_string(mpv_handle *ctx, const char *args);
1002 |
1003 | /**
1004 | * Same as mpv_command, but run the command asynchronously.
1005 | *
1006 | * Commands are executed asynchronously. You will receive a
1007 | * MPV_EVENT_COMMAND_REPLY event. This event will also have an
1008 | * error code set if running the command failed. For commands that
1009 | * return data, the data is put into mpv_event_command.result.
1010 | *
1011 | * Safe to be called from mpv render API threads.
1012 | *
1013 | * @param reply_userdata the value mpv_event.reply_userdata of the reply will
1014 | * be set to (see section about asynchronous calls)
1015 | * @param args NULL-terminated list of strings (see mpv_command())
1016 | * @return error code (if parsing or queuing the command fails)
1017 | */
1018 | int mpv_command_async(mpv_handle *ctx, uint64_t reply_userdata,
1019 | const char **args);
1020 |
1021 | /**
1022 | * Same as mpv_command_node(), but run it asynchronously. Basically, this
1023 | * function is to mpv_command_node() what mpv_command_async() is to
1024 | * mpv_command().
1025 | *
1026 | * See mpv_command_async() for details.
1027 | *
1028 | * Safe to be called from mpv render API threads.
1029 | *
1030 | * @param reply_userdata the value mpv_event.reply_userdata of the reply will
1031 | * be set to (see section about asynchronous calls)
1032 | * @param args as in mpv_command_node()
1033 | * @return error code (if parsing or queuing the command fails)
1034 | */
1035 | int mpv_command_node_async(mpv_handle *ctx, uint64_t reply_userdata,
1036 | mpv_node *args);
1037 |
1038 | /**
1039 | * Signal to all async requests with the matching ID to abort. This affects
1040 | * the following API calls:
1041 | *
1042 | * mpv_command_async
1043 | * mpv_command_node_async
1044 | *
1045 | * All of these functions take a reply_userdata parameter. This API function
1046 | * tells all requests with the matching reply_userdata value to try to return
1047 | * as soon as possible. If there are multiple requests with matching ID, it
1048 | * aborts all of them.
1049 | *
1050 | * This API function is mostly asynchronous itself. It will not wait until the
1051 | * command is aborted. Instead, the command will terminate as usual, but with
1052 | * some work not done. How this is signaled depends on the specific command (for
1053 | * example, the "subprocess" command will indicate it by "killed_by_us" set to
1054 | * true in the result). How long it takes also depends on the situation. The
1055 | * aborting process is completely asynchronous.
1056 | *
1057 | * Not all commands may support this functionality. In this case, this function
1058 | * will have no effect. The same is true if the request using the passed
1059 | * reply_userdata has already terminated, has not been started yet, or was
1060 | * never in use at all.
1061 | *
1062 | * You have to be careful of race conditions: the time during which the abort
1063 | * request will be effective is _after_ e.g. mpv_command_async() has returned,
1064 | * and before the command has signaled completion with MPV_EVENT_COMMAND_REPLY.
1065 | *
1066 | * @param reply_userdata ID of the request to be aborted (see above)
1067 | */
1068 | void mpv_abort_async_command(mpv_handle *ctx, uint64_t reply_userdata);
1069 |
1070 | /**
1071 | * Set a property to a given value. Properties are essentially variables which
1072 | * can be queried or set at runtime. For example, writing to the pause property
1073 | * will actually pause or unpause playback.
1074 | *
1075 | * If the format doesn't match with the internal format of the property, access
1076 | * usually will fail with MPV_ERROR_PROPERTY_FORMAT. In some cases, the data
1077 | * is automatically converted and access succeeds. For example, MPV_FORMAT_INT64
1078 | * is always converted to MPV_FORMAT_DOUBLE, and access using MPV_FORMAT_STRING
1079 | * usually invokes a string parser. The same happens when calling this function
1080 | * with MPV_FORMAT_NODE: the underlying format may be converted to another
1081 | * type if possible.
1082 | *
1083 | * Using a format other than MPV_FORMAT_NODE is equivalent to constructing a
1084 | * mpv_node with the given format and data, and passing the mpv_node to this
1085 | * function. (Before API version 1.21, this was different.)
1086 | *
1087 | * Note: starting with mpv 0.21.0 (client API version 1.23), this can be used to
1088 | * set options in general. It even can be used before mpv_initialize()
1089 | * has been called. If called before mpv_initialize(), setting properties
1090 | * not backed by options will result in MPV_ERROR_PROPERTY_UNAVAILABLE.
1091 | * In some cases, properties and options still conflict. In these cases,
1092 | * mpv_set_property() accesses the options before mpv_initialize(), and
1093 | * the properties after mpv_initialize(). These conflicts will be removed
1094 | * in mpv 0.23.0. See mpv_set_option() for further remarks.
1095 | *
1096 | * @param name The property name. See input.rst for a list of properties.
1097 | * @param format see enum mpv_format.
1098 | * @param[in] data Option value.
1099 | * @return error code
1100 | */
1101 | int mpv_set_property(mpv_handle *ctx, const char *name, mpv_format format,
1102 | void *data);
1103 |
1104 | /**
1105 | * Convenience function to set a property to a string value.
1106 | *
1107 | * This is like calling mpv_set_property() with MPV_FORMAT_STRING.
1108 | */
1109 | int mpv_set_property_string(mpv_handle *ctx, const char *name, const char *data);
1110 |
1111 | /**
1112 | * Set a property asynchronously. You will receive the result of the operation
1113 | * as MPV_EVENT_SET_PROPERTY_REPLY event. The mpv_event.error field will contain
1114 | * the result status of the operation. Otherwise, this function is similar to
1115 | * mpv_set_property().
1116 | *
1117 | * Safe to be called from mpv render API threads.
1118 | *
1119 | * @param reply_userdata see section about asynchronous calls
1120 | * @param name The property name.
1121 | * @param format see enum mpv_format.
1122 | * @param[in] data Option value. The value will be copied by the function. It
1123 | * will never be modified by the client API.
1124 | * @return error code if sending the request failed
1125 | */
1126 | int mpv_set_property_async(mpv_handle *ctx, uint64_t reply_userdata,
1127 | const char *name, mpv_format format, void *data);
1128 |
1129 | /**
1130 | * Read the value of the given property.
1131 | *
1132 | * If the format doesn't match with the internal format of the property, access
1133 | * usually will fail with MPV_ERROR_PROPERTY_FORMAT. In some cases, the data
1134 | * is automatically converted and access succeeds. For example, MPV_FORMAT_INT64
1135 | * is always converted to MPV_FORMAT_DOUBLE, and access using MPV_FORMAT_STRING
1136 | * usually invokes a string formatter.
1137 | *
1138 | * @param name The property name.
1139 | * @param format see enum mpv_format.
1140 | * @param[out] data Pointer to the variable holding the option value. On
1141 | * success, the variable will be set to a copy of the option
1142 | * value. For formats that require dynamic memory allocation,
1143 | * you can free the value with mpv_free() (strings) or
1144 | * mpv_free_node_contents() (MPV_FORMAT_NODE).
1145 | * @return error code
1146 | */
1147 | int mpv_get_property(mpv_handle *ctx, const char *name, mpv_format format,
1148 | void *data);
1149 |
1150 | /**
1151 | * Return the value of the property with the given name as string. This is
1152 | * equivalent to mpv_get_property() with MPV_FORMAT_STRING.
1153 | *
1154 | * See MPV_FORMAT_STRING for character encoding issues.
1155 | *
1156 | * On error, NULL is returned. Use mpv_get_property() if you want fine-grained
1157 | * error reporting.
1158 | *
1159 | * @param name The property name.
1160 | * @return Property value, or NULL if the property can't be retrieved. Free
1161 | * the string with mpv_free().
1162 | */
1163 | char *mpv_get_property_string(mpv_handle *ctx, const char *name);
1164 |
1165 | /**
1166 | * Return the property as "OSD" formatted string. This is the same as
1167 | * mpv_get_property_string, but using MPV_FORMAT_OSD_STRING.
1168 | *
1169 | * @return Property value, or NULL if the property can't be retrieved. Free
1170 | * the string with mpv_free().
1171 | */
1172 | char *mpv_get_property_osd_string(mpv_handle *ctx, const char *name);
1173 |
1174 | /**
1175 | * Get a property asynchronously. You will receive the result of the operation
1176 | * as well as the property data with the MPV_EVENT_GET_PROPERTY_REPLY event.
1177 | * You should check the mpv_event.error field on the reply event.
1178 | *
1179 | * Safe to be called from mpv render API threads.
1180 | *
1181 | * @param reply_userdata see section about asynchronous calls
1182 | * @param name The property name.
1183 | * @param format see enum mpv_format.
1184 | * @return error code if sending the request failed
1185 | */
1186 | int mpv_get_property_async(mpv_handle *ctx, uint64_t reply_userdata,
1187 | const char *name, mpv_format format);
1188 |
1189 | /**
1190 | * Get a notification whenever the given property changes. You will receive
1191 | * updates as MPV_EVENT_PROPERTY_CHANGE. Note that this is not very precise:
1192 | * for some properties, it may not send updates even if the property changed.
1193 | * This depends on the property, and it's a valid feature request to ask for
1194 | * better update handling of a specific property. (For some properties, like
1195 | * ``clock``, which shows the wall clock, this mechanism doesn't make too
1196 | * much sense anyway.)
1197 | *
1198 | * Property changes are coalesced: the change events are returned only once the
1199 | * event queue becomes empty (e.g. mpv_wait_event() would block or return
1200 | * MPV_EVENT_NONE), and then only one event per changed property is returned.
1201 | *
1202 | * You always get an initial change notification. This is meant to initialize
1203 | * the user's state to the current value of the property.
1204 | *
1205 | * Normally, change events are sent only if the property value changes according
1206 | * to the requested format. mpv_event_property will contain the property value
1207 | * as data member.
1208 | *
1209 | * Warning: if a property is unavailable or retrieving it caused an error,
1210 | * MPV_FORMAT_NONE will be set in mpv_event_property, even if the
1211 | * format parameter was set to a different value. In this case, the
1212 | * mpv_event_property.data field is invalid.
1213 | *
1214 | * If the property is observed with the format parameter set to MPV_FORMAT_NONE,
1215 | * you get low-level notifications whether the property _may_ have changed, and
1216 | * the data member in mpv_event_property will be unset. With this mode, you
1217 | * will have to determine yourself whether the property really changed. On the
1218 | * other hand, this mechanism can be faster and uses less resources.
1219 | *
1220 | * Observing a property that doesn't exist is allowed. (Although it may still
1221 | * cause some sporadic change events.)
1222 | *
1223 | * Keep in mind that you will get change notifications even if you change a
1224 | * property yourself. Try to avoid endless feedback loops, which could happen
1225 | * if you react to the change notifications triggered by your own change.
1226 | *
1227 | * Only the mpv_handle on which this was called will receive the property
1228 | * change events, or can unobserve them.
1229 | *
1230 | * Safe to be called from mpv render API threads.
1231 | *
1232 | * @param reply_userdata This will be used for the mpv_event.reply_userdata
1233 | * field for the received MPV_EVENT_PROPERTY_CHANGE
1234 | * events. (Also see section about asynchronous calls,
1235 | * although this function is somewhat different from
1236 | * actual asynchronous calls.)
1237 | * If you have no use for this, pass 0.
1238 | * Also see mpv_unobserve_property().
1239 | * @param name The property name.
1240 | * @param format see enum mpv_format. Can be MPV_FORMAT_NONE to omit values
1241 | * from the change events.
1242 | * @return error code (usually fails only on OOM or unsupported format)
1243 | */
1244 | int mpv_observe_property(mpv_handle *mpv, uint64_t reply_userdata,
1245 | const char *name, mpv_format format);
1246 |
1247 | /**
1248 | * Undo mpv_observe_property(). This will remove all observed properties for
1249 | * which the given number was passed as reply_userdata to mpv_observe_property.
1250 | *
1251 | * Safe to be called from mpv render API threads.
1252 | *
1253 | * @param registered_reply_userdata ID that was passed to mpv_observe_property
1254 | * @return negative value is an error code, >=0 is number of removed properties
1255 | * on success (includes the case when 0 were removed)
1256 | */
1257 | int mpv_unobserve_property(mpv_handle *mpv, uint64_t registered_reply_userdata);
1258 |
1259 | typedef enum mpv_event_id {
1260 | /**
1261 | * Nothing happened. Happens on timeouts or sporadic wakeups.
1262 | */
1263 | MPV_EVENT_NONE = 0,
1264 | /**
1265 | * Happens when the player quits. The player enters a state where it tries
1266 | * to disconnect all clients. Most requests to the player will fail, and
1267 | * the client should react to this and quit with mpv_destroy() as soon as
1268 | * possible.
1269 | */
1270 | MPV_EVENT_SHUTDOWN = 1,
1271 | /**
1272 | * See mpv_request_log_messages().
1273 | */
1274 | MPV_EVENT_LOG_MESSAGE = 2,
1275 | /**
1276 | * Reply to a mpv_get_property_async() request.
1277 | * See also mpv_event and mpv_event_property.
1278 | */
1279 | MPV_EVENT_GET_PROPERTY_REPLY = 3,
1280 | /**
1281 | * Reply to a mpv_set_property_async() request.
1282 | * (Unlike MPV_EVENT_GET_PROPERTY, mpv_event_property is not used.)
1283 | */
1284 | MPV_EVENT_SET_PROPERTY_REPLY = 4,
1285 | /**
1286 | * Reply to a mpv_command_async() or mpv_command_node_async() request.
1287 | * See also mpv_event and mpv_event_command.
1288 | */
1289 | MPV_EVENT_COMMAND_REPLY = 5,
1290 | /**
1291 | * Notification before playback start of a file (before the file is loaded).
1292 | */
1293 | MPV_EVENT_START_FILE = 6,
1294 | /**
1295 | * Notification after playback end (after the file was unloaded).
1296 | * See also mpv_event and mpv_event_end_file.
1297 | */
1298 | MPV_EVENT_END_FILE = 7,
1299 | /**
1300 | * Notification when the file has been loaded (headers were read etc.), and
1301 | * decoding starts.
1302 | */
1303 | MPV_EVENT_FILE_LOADED = 8,
1304 | #if MPV_ENABLE_DEPRECATED
1305 | /**
1306 | * The list of video/audio/subtitle tracks was changed. (E.g. a new track
1307 | * was found. This doesn't necessarily indicate a track switch; for this,
1308 | * MPV_EVENT_TRACK_SWITCHED is used.)
1309 | *
1310 | * @deprecated This is equivalent to using mpv_observe_property() on the
1311 | * "track-list" property. The event is redundant, and might
1312 | * be removed in the far future.
1313 | */
1314 | MPV_EVENT_TRACKS_CHANGED = 9,
1315 | /**
1316 | * A video/audio/subtitle track was switched on or off.
1317 | *
1318 | * @deprecated This is equivalent to using mpv_observe_property() on the
1319 | * "vid", "aid", and "sid" properties. The event is redundant,
1320 | * and might be removed in the far future.
1321 | */
1322 | MPV_EVENT_TRACK_SWITCHED = 10,
1323 | #endif
1324 | /**
1325 | * Idle mode was entered. In this mode, no file is played, and the playback
1326 | * core waits for new commands. (The command line player normally quits
1327 | * instead of entering idle mode, unless --idle was specified. If mpv
1328 | * was started with mpv_create(), idle mode is enabled by default.)
1329 | */
1330 | MPV_EVENT_IDLE = 11,
1331 | #if MPV_ENABLE_DEPRECATED
1332 | /**
1333 | * Playback was paused. This indicates the user pause state.
1334 | *
1335 | * The user pause state is the state the user requested (changed with the
1336 | * "pause" property). There is an internal pause state too, which is entered
1337 | * if e.g. the network is too slow (the "core-idle" property generally
1338 | * indicates whether the core is playing or waiting).
1339 | *
1340 | * This event is sent whenever any pause states change, not only the user
1341 | * state. You might get multiple events in a row while these states change
1342 | * independently. But the event ID sent always indicates the user pause
1343 | * state.
1344 | *
1345 | * If you don't want to deal with this, use mpv_observe_property() on the
1346 | * "pause" property and ignore MPV_EVENT_PAUSE/UNPAUSE. Likewise, the
1347 | * "core-idle" property tells you whether video is actually playing or not.
1348 | *
1349 | * @deprecated The event is redundant with mpv_observe_property() as
1350 | * mentioned above, and might be removed in the far future.
1351 | */
1352 | MPV_EVENT_PAUSE = 12,
1353 | /**
1354 | * Playback was unpaused. See MPV_EVENT_PAUSE for not so obvious details.
1355 | *
1356 | * @deprecated The event is redundant with mpv_observe_property() as
1357 | * explained in the MPV_EVENT_PAUSE comments, and might be
1358 | * removed in the far future.
1359 | */
1360 | MPV_EVENT_UNPAUSE = 13,
1361 | /**
1362 | * Sent every time after a video frame is displayed. Note that currently,
1363 | * this will be sent in lower frequency if there is no video, or playback
1364 | * is paused - but that will be removed in the future, and it will be
1365 | * restricted to video frames only.
1366 | *
1367 | * @deprecated Use mpv_observe_property() with relevant properties instead
1368 | * (such as "playback-time").
1369 | */
1370 | MPV_EVENT_TICK = 14,
1371 | /**
1372 | * @deprecated This was used internally with the internal "script_dispatch"
1373 | * command to dispatch keyboard and mouse input for the OSC.
1374 | * It was never useful in general and has been completely
1375 | * replaced with "script-binding".
1376 | * This event never happens anymore, and is included in this
1377 | * header only for compatibility.
1378 | */
1379 | MPV_EVENT_SCRIPT_INPUT_DISPATCH = 15,
1380 | #endif
1381 | /**
1382 | * Triggered by the script-message input command. The command uses the
1383 | * first argument of the command as client name (see mpv_client_name()) to
1384 | * dispatch the message, and passes along all arguments starting from the
1385 | * second argument as strings.
1386 | * See also mpv_event and mpv_event_client_message.
1387 | */
1388 | MPV_EVENT_CLIENT_MESSAGE = 16,
1389 | /**
1390 | * Happens after video changed in some way. This can happen on resolution
1391 | * changes, pixel format changes, or video filter changes. The event is
1392 | * sent after the video filters and the VO are reconfigured. Applications
1393 | * embedding a mpv window should listen to this event in order to resize
1394 | * the window if needed.
1395 | * Note that this event can happen sporadically, and you should check
1396 | * yourself whether the video parameters really changed before doing
1397 | * something expensive.
1398 | */
1399 | MPV_EVENT_VIDEO_RECONFIG = 17,
1400 | /**
1401 | * Similar to MPV_EVENT_VIDEO_RECONFIG. This is relatively uninteresting,
1402 | * because there is no such thing as audio output embedding.
1403 | */
1404 | MPV_EVENT_AUDIO_RECONFIG = 18,
1405 | #if MPV_ENABLE_DEPRECATED
1406 | /**
1407 | * Happens when metadata (like file tags) is possibly updated. (It's left
1408 | * unspecified whether this happens on file start or only when it changes
1409 | * within a file.)
1410 | *
1411 | * @deprecated This is equivalent to using mpv_observe_property() on the
1412 | * "metadata" property. The event is redundant, and might
1413 | * be removed in the far future.
1414 | */
1415 | MPV_EVENT_METADATA_UPDATE = 19,
1416 | #endif
1417 | /**
1418 | * Happens when a seek was initiated. Playback stops. Usually it will
1419 | * resume with MPV_EVENT_PLAYBACK_RESTART as soon as the seek is finished.
1420 | */
1421 | MPV_EVENT_SEEK = 20,
1422 | /**
1423 | * There was a discontinuity of some sort (like a seek), and playback
1424 | * was reinitialized. Usually happens after seeking, or ordered chapter
1425 | * segment switches. The main purpose is allowing the client to detect
1426 | * when a seek request is finished.
1427 | */
1428 | MPV_EVENT_PLAYBACK_RESTART = 21,
1429 | /**
1430 | * Event sent due to mpv_observe_property().
1431 | * See also mpv_event and mpv_event_property.
1432 | */
1433 | MPV_EVENT_PROPERTY_CHANGE = 22,
1434 | #if MPV_ENABLE_DEPRECATED
1435 | /**
1436 | * Happens when the current chapter changes.
1437 | *
1438 | * @deprecated This is equivalent to using mpv_observe_property() on the
1439 | * "chapter" property. The event is redundant, and might
1440 | * be removed in the far future.
1441 | */
1442 | MPV_EVENT_CHAPTER_CHANGE = 23,
1443 | #endif
1444 | /**
1445 | * Happens if the internal per-mpv_handle ringbuffer overflows, and at
1446 | * least 1 event had to be dropped. This can happen if the client doesn't
1447 | * read the event queue quickly enough with mpv_wait_event(), or if the
1448 | * client makes a very large number of asynchronous calls at once.
1449 | *
1450 | * Event delivery will continue normally once this event was returned
1451 | * (this forces the client to empty the queue completely).
1452 | */
1453 | MPV_EVENT_QUEUE_OVERFLOW = 24,
1454 | /**
1455 | * Triggered if a hook handler was registered with mpv_hook_add(), and the
1456 | * hook is invoked. If you receive this, you must handle it, and continue
1457 | * the hook with mpv_hook_continue().
1458 | * See also mpv_event and mpv_event_hook.
1459 | */
1460 | MPV_EVENT_HOOK = 25,
1461 | // Internal note: adjust INTERNAL_EVENT_BASE when adding new events.
1462 | } mpv_event_id;
1463 |
1464 | /**
1465 | * Return a string describing the event. For unknown events, NULL is returned.
1466 | *
1467 | * Note that all events actually returned by the API will also yield a non-NULL
1468 | * string with this function.
1469 | *
1470 | * @param event event ID, see see enum mpv_event_id
1471 | * @return A static string giving a short symbolic name of the event. It
1472 | * consists of lower-case alphanumeric characters and can include "-"
1473 | * characters. This string is suitable for use in e.g. scripting
1474 | * interfaces.
1475 | * The string is completely static, i.e. doesn't need to be deallocated,
1476 | * and is valid forever.
1477 | */
1478 | const char *mpv_event_name(mpv_event_id event);
1479 |
1480 | typedef struct mpv_event_property {
1481 | /**
1482 | * Name of the property.
1483 | */
1484 | const char *name;
1485 | /**
1486 | * Format of the data field in the same struct. See enum mpv_format.
1487 | * This is always the same format as the requested format, except when
1488 | * the property could not be retrieved (unavailable, or an error happened),
1489 | * in which case the format is MPV_FORMAT_NONE.
1490 | */
1491 | mpv_format format;
1492 | /**
1493 | * Received property value. Depends on the format. This is like the
1494 | * pointer argument passed to mpv_get_property().
1495 | *
1496 | * For example, for MPV_FORMAT_STRING you get the string with:
1497 | *
1498 | * char *value = *(char **)(event_property->data);
1499 | *
1500 | * Note that this is set to NULL if retrieving the property failed (the
1501 | * format will be MPV_FORMAT_NONE).
1502 | */
1503 | void *data;
1504 | } mpv_event_property;
1505 |
1506 | /**
1507 | * Numeric log levels. The lower the number, the more important the message is.
1508 | * MPV_LOG_LEVEL_NONE is never used when receiving messages. The string in
1509 | * the comment after the value is the name of the log level as used for the
1510 | * mpv_request_log_messages() function.
1511 | * Unused numeric values are unused, but reserved for future use.
1512 | */
1513 | typedef enum mpv_log_level {
1514 | MPV_LOG_LEVEL_NONE = 0, /// "no" - disable absolutely all messages
1515 | MPV_LOG_LEVEL_FATAL = 10, /// "fatal" - critical/aborting errors
1516 | MPV_LOG_LEVEL_ERROR = 20, /// "error" - simple errors
1517 | MPV_LOG_LEVEL_WARN = 30, /// "warn" - possible problems
1518 | MPV_LOG_LEVEL_INFO = 40, /// "info" - informational message
1519 | MPV_LOG_LEVEL_V = 50, /// "v" - noisy informational message
1520 | MPV_LOG_LEVEL_DEBUG = 60, /// "debug" - very noisy technical information
1521 | MPV_LOG_LEVEL_TRACE = 70, /// "trace" - extremely noisy
1522 | } mpv_log_level;
1523 |
1524 | typedef struct mpv_event_log_message {
1525 | /**
1526 | * The module prefix, identifies the sender of the message. As a special
1527 | * case, if the message buffer overflows, this will be set to the string
1528 | * "overflow" (which doesn't appear as prefix otherwise), and the text
1529 | * field will contain an informative message.
1530 | */
1531 | const char *prefix;
1532 | /**
1533 | * The log level as string. See mpv_request_log_messages() for possible
1534 | * values. The level "no" is never used here.
1535 | */
1536 | const char *level;
1537 | /**
1538 | * The log message. It consists of 1 line of text, and is terminated with
1539 | * a newline character. (Before API version 1.6, it could contain multiple
1540 | * or partial lines.)
1541 | */
1542 | const char *text;
1543 | /**
1544 | * The same contents as the level field, but as a numeric ID.
1545 | * Since API version 1.6.
1546 | */
1547 | mpv_log_level log_level;
1548 | } mpv_event_log_message;
1549 |
1550 | /// Since API version 1.9.
1551 | typedef enum mpv_end_file_reason {
1552 | /**
1553 | * The end of file was reached. Sometimes this may also happen on
1554 | * incomplete or corrupted files, or if the network connection was
1555 | * interrupted when playing a remote file. It also happens if the
1556 | * playback range was restricted with --end or --frames or similar.
1557 | */
1558 | MPV_END_FILE_REASON_EOF = 0,
1559 | /**
1560 | * Playback was stopped by an external action (e.g. playlist controls).
1561 | */
1562 | MPV_END_FILE_REASON_STOP = 2,
1563 | /**
1564 | * Playback was stopped by the quit command or player shutdown.
1565 | */
1566 | MPV_END_FILE_REASON_QUIT = 3,
1567 | /**
1568 | * Some kind of error happened that lead to playback abort. Does not
1569 | * necessarily happen on incomplete or broken files (in these cases, both
1570 | * MPV_END_FILE_REASON_ERROR or MPV_END_FILE_REASON_EOF are possible).
1571 | *
1572 | * mpv_event_end_file.error will be set.
1573 | */
1574 | MPV_END_FILE_REASON_ERROR = 4,
1575 | /**
1576 | * The file was a playlist or similar. When the playlist is read, its
1577 | * entries will be appended to the playlist after the entry of the current
1578 | * file, the entry of the current file is removed, and a MPV_EVENT_END_FILE
1579 | * event is sent with reason set to MPV_END_FILE_REASON_REDIRECT. Then
1580 | * playback continues with the playlist contents.
1581 | * Since API version 1.18.
1582 | */
1583 | MPV_END_FILE_REASON_REDIRECT = 5,
1584 | } mpv_end_file_reason;
1585 |
1586 | typedef struct mpv_event_end_file {
1587 | /**
1588 | * Corresponds to the values in enum mpv_end_file_reason (the "int" type
1589 | * will be replaced with mpv_end_file_reason on the next ABI bump).
1590 | *
1591 | * Unknown values should be treated as unknown.
1592 | */
1593 | int reason;
1594 | /**
1595 | * If reason==MPV_END_FILE_REASON_ERROR, this contains a mpv error code
1596 | * (one of MPV_ERROR_...) giving an approximate reason why playback
1597 | * failed. In other cases, this field is 0 (no error).
1598 | * Since API version 1.9.
1599 | */
1600 | int error;
1601 | } mpv_event_end_file;
1602 |
1603 | #if MPV_ENABLE_DEPRECATED
1604 | /** @deprecated see MPV_EVENT_SCRIPT_INPUT_DISPATCH for remarks
1605 | */
1606 | typedef struct mpv_event_script_input_dispatch {
1607 | int arg0;
1608 | const char *type;
1609 | } mpv_event_script_input_dispatch;
1610 | #endif
1611 |
1612 | typedef struct mpv_event_client_message {
1613 | /**
1614 | * Arbitrary arguments chosen by the sender of the message. If num_args > 0,
1615 | * you can access args[0] through args[num_args - 1] (inclusive). What
1616 | * these arguments mean is up to the sender and receiver.
1617 | * None of the valid items are NULL.
1618 | */
1619 | int num_args;
1620 | const char **args;
1621 | } mpv_event_client_message;
1622 |
1623 | typedef struct mpv_event_hook {
1624 | /**
1625 | * The hook name as passed to mpv_hook_add().
1626 | */
1627 | const char *name;
1628 | /**
1629 | * Internal ID that must be passed to mpv_hook_continue().
1630 | */
1631 | uint64_t id;
1632 | } mpv_event_hook;
1633 |
1634 | // Since API version 1.102.
1635 | typedef struct mpv_event_command {
1636 | /**
1637 | * Result data of the command. Note that success/failure is signaled
1638 | * separately via mpv_event.error. This field is only for result data
1639 | * in case of success. Most commands leave it at MPV_FORMAT_NONE. Set
1640 | * to MPV_FORMAT_NONE on failure.
1641 | */
1642 | mpv_node result;
1643 | } mpv_event_command;
1644 |
1645 | typedef struct mpv_event {
1646 | /**
1647 | * One of mpv_event. Keep in mind that later ABI compatible releases might
1648 | * add new event types. These should be ignored by the API user.
1649 | */
1650 | mpv_event_id event_id;
1651 | /**
1652 | * This is mainly used for events that are replies to (asynchronous)
1653 | * requests. It contains a status code, which is >= 0 on success, or < 0
1654 | * on error (a mpv_error value). Usually, this will be set if an
1655 | * asynchronous request fails.
1656 | * Used for:
1657 | * MPV_EVENT_GET_PROPERTY_REPLY
1658 | * MPV_EVENT_SET_PROPERTY_REPLY
1659 | * MPV_EVENT_COMMAND_REPLY
1660 | */
1661 | int error;
1662 | /**
1663 | * If the event is in reply to a request (made with this API and this
1664 | * API handle), this is set to the reply_userdata parameter of the request
1665 | * call. Otherwise, this field is 0.
1666 | * Used for:
1667 | * MPV_EVENT_GET_PROPERTY_REPLY
1668 | * MPV_EVENT_SET_PROPERTY_REPLY
1669 | * MPV_EVENT_COMMAND_REPLY
1670 | * MPV_EVENT_PROPERTY_CHANGE
1671 | * MPV_EVENT_HOOK
1672 | */
1673 | uint64_t reply_userdata;
1674 | /**
1675 | * The meaning and contents of the data member depend on the event_id:
1676 | * MPV_EVENT_GET_PROPERTY_REPLY: mpv_event_property*
1677 | * MPV_EVENT_PROPERTY_CHANGE: mpv_event_property*
1678 | * MPV_EVENT_LOG_MESSAGE: mpv_event_log_message*
1679 | * MPV_EVENT_CLIENT_MESSAGE: mpv_event_client_message*
1680 | * MPV_EVENT_END_FILE: mpv_event_end_file*
1681 | * MPV_EVENT_HOOK: mpv_event_hook*
1682 | * MPV_EVENT_COMMAND_REPLY* mpv_event_command*
1683 | * other: NULL
1684 | *
1685 | * Note: future enhancements might add new event structs for existing or new
1686 | * event types.
1687 | */
1688 | void *data;
1689 | } mpv_event;
1690 |
1691 | /**
1692 | * Enable or disable the given event.
1693 | *
1694 | * Some events are enabled by default. Some events can't be disabled.
1695 | *
1696 | * (Informational note: currently, all events are enabled by default, except
1697 | * MPV_EVENT_TICK.)
1698 | *
1699 | * Safe to be called from mpv render API threads.
1700 | *
1701 | * @param event See enum mpv_event_id.
1702 | * @param enable 1 to enable receiving this event, 0 to disable it.
1703 | * @return error code
1704 | */
1705 | int mpv_request_event(mpv_handle *ctx, mpv_event_id event, int enable);
1706 |
1707 | /**
1708 | * Enable or disable receiving of log messages. These are the messages the
1709 | * command line player prints to the terminal. This call sets the minimum
1710 | * required log level for a message to be received with MPV_EVENT_LOG_MESSAGE.
1711 | *
1712 | * @param min_level Minimal log level as string. Valid log levels:
1713 | * no fatal error warn info v debug trace
1714 | * The value "no" disables all messages. This is the default.
1715 | * An exception is the value "terminal-default", which uses the
1716 | * log level as set by the "--msg-level" option. This works
1717 | * even if the terminal is disabled. (Since API version 1.19.)
1718 | * Also see mpv_log_level.
1719 | * @return error code
1720 | */
1721 | int mpv_request_log_messages(mpv_handle *ctx, const char *min_level);
1722 |
1723 | /**
1724 | * Wait for the next event, or until the timeout expires, or if another thread
1725 | * makes a call to mpv_wakeup(). Passing 0 as timeout will never wait, and
1726 | * is suitable for polling.
1727 | *
1728 | * The internal event queue has a limited size (per client handle). If you
1729 | * don't empty the event queue quickly enough with mpv_wait_event(), it will
1730 | * overflow and silently discard further events. If this happens, making
1731 | * asynchronous requests will fail as well (with MPV_ERROR_EVENT_QUEUE_FULL).
1732 | *
1733 | * Only one thread is allowed to call this on the same mpv_handle at a time.
1734 | * The API won't complain if more than one thread calls this, but it will cause
1735 | * race conditions in the client when accessing the shared mpv_event struct.
1736 | * Note that most other API functions are not restricted by this, and no API
1737 | * function internally calls mpv_wait_event(). Additionally, concurrent calls
1738 | * to different mpv_handles are always safe.
1739 | *
1740 | * As long as the timeout is 0, this is safe to be called from mpv render API
1741 | * threads.
1742 | *
1743 | * @param timeout Timeout in seconds, after which the function returns even if
1744 | * no event was received. A MPV_EVENT_NONE is returned on
1745 | * timeout. A value of 0 will disable waiting. Negative values
1746 | * will wait with an infinite timeout.
1747 | * @return A struct containing the event ID and other data. The pointer (and
1748 | * fields in the struct) stay valid until the next mpv_wait_event()
1749 | * call, or until the mpv_handle is destroyed. You must not write to
1750 | * the struct, and all memory referenced by it will be automatically
1751 | * released by the API on the next mpv_wait_event() call, or when the
1752 | * context is destroyed. The return value is never NULL.
1753 | */
1754 | mpv_event *mpv_wait_event(mpv_handle *ctx, double timeout);
1755 |
1756 | /**
1757 | * Interrupt the current mpv_wait_event() call. This will wake up the thread
1758 | * currently waiting in mpv_wait_event(). If no thread is waiting, the next
1759 | * mpv_wait_event() call will return immediately (this is to avoid lost
1760 | * wakeups).
1761 | *
1762 | * mpv_wait_event() will receive a MPV_EVENT_NONE if it's woken up due to
1763 | * this call. But note that this dummy event might be skipped if there are
1764 | * already other events queued. All what counts is that the waiting thread
1765 | * is woken up at all.
1766 | *
1767 | * Safe to be called from mpv render API threads.
1768 | */
1769 | void mpv_wakeup(mpv_handle *ctx);
1770 |
1771 | /**
1772 | * Set a custom function that should be called when there are new events. Use
1773 | * this if blocking in mpv_wait_event() to wait for new events is not feasible.
1774 | *
1775 | * Keep in mind that the callback will be called from foreign threads. You
1776 | * must not make any assumptions of the environment, and you must return as
1777 | * soon as possible (i.e. no long blocking waits). Exiting the callback through
1778 | * any other means than a normal return is forbidden (no throwing exceptions,
1779 | * no longjmp() calls). You must not change any local thread state (such as
1780 | * the C floating point environment).
1781 | *
1782 | * You are not allowed to call any client API functions inside of the callback.
1783 | * In particular, you should not do any processing in the callback, but wake up
1784 | * another thread that does all the work. The callback is meant strictly for
1785 | * notification only, and is called from arbitrary core parts of the player,
1786 | * that make no considerations for reentrant API use or allowing the callee to
1787 | * spend a lot of time doing other things. Keep in mind that it's also possible
1788 | * that the callback is called from a thread while a mpv API function is called
1789 | * (i.e. it can be reentrant).
1790 | *
1791 | * In general, the client API expects you to call mpv_wait_event() to receive
1792 | * notifications, and the wakeup callback is merely a helper utility to make
1793 | * this easier in certain situations. Note that it's possible that there's
1794 | * only one wakeup callback invocation for multiple events. You should call
1795 | * mpv_wait_event() with no timeout until MPV_EVENT_NONE is reached, at which
1796 | * point the event queue is empty.
1797 | *
1798 | * If you actually want to do processing in a callback, spawn a thread that
1799 | * does nothing but call mpv_wait_event() in a loop and dispatches the result
1800 | * to a callback.
1801 | *
1802 | * Only one wakeup callback can be set.
1803 | *
1804 | * @param cb function that should be called if a wakeup is required
1805 | * @param d arbitrary userdata passed to cb
1806 | */
1807 | void mpv_set_wakeup_callback(mpv_handle *ctx, void (*cb)(void *d), void *d);
1808 |
1809 | /**
1810 | * Block until all asynchronous requests are done. This affects functions like
1811 | * mpv_command_async(), which return immediately and return their result as
1812 | * events.
1813 | *
1814 | * This is a helper, and somewhat equivalent to calling mpv_wait_event() in a
1815 | * loop until all known asynchronous requests have sent their reply as event,
1816 | * except that the event queue is not emptied.
1817 | *
1818 | * In case you called mpv_suspend() before, this will also forcibly reset the
1819 | * suspend counter of the given handle.
1820 | */
1821 | void mpv_wait_async_requests(mpv_handle *ctx);
1822 |
1823 | /**
1824 | * A hook is like a synchronous event that blocks the player. You register
1825 | * a hook handler with this function. You will get an event, which you need
1826 | * to handle, and once things are ready, you can let the player continue with
1827 | * mpv_hook_continue().
1828 | *
1829 | * Currently, hooks can't be removed explicitly. But they will be implicitly
1830 | * removed if the mpv_handle it was registered with is destroyed. This also
1831 | * continues the hook if it was being handled by the destroyed mpv_handle (but
1832 | * this should be avoided, as it might mess up order of hook execution).
1833 | *
1834 | * Hook handlers are ordered globally by priority and order of registration.
1835 | * Handlers for the same hook with same priority are invoked in order of
1836 | * registration (the handler registered first is run first). Handlers with
1837 | * lower priority are run first (which seems backward).
1838 | *
1839 | * See the "Hooks" section in the manpage to see which hooks are currently
1840 | * defined.
1841 | *
1842 | * Some hooks might be reentrant (so you get multiple MPV_EVENT_HOOK for the
1843 | * same hook). If this can happen for a specific hook type, it will be
1844 | * explicitly documented in the manpage.
1845 | *
1846 | * Only the mpv_handle on which this was called will receive the hook events,
1847 | * or can "continue" them.
1848 | *
1849 | * @param reply_userdata This will be used for the mpv_event.reply_userdata
1850 | * field for the received MPV_EVENT_HOOK events.
1851 | * If you have no use for this, pass 0.
1852 | * @param name The hook name. This should be one of the documented names. But
1853 | * if the name is unknown, the hook event will simply be never
1854 | * raised.
1855 | * @param priority See remarks above. Use 0 as a neutral default.
1856 | * @return error code (usually fails only on OOM)
1857 | */
1858 | int mpv_hook_add(mpv_handle *ctx, uint64_t reply_userdata,
1859 | const char *name, int priority);
1860 |
1861 | /**
1862 | * Respond to a MPV_EVENT_HOOK event. You must call this after you have handled
1863 | * the event. There is no way to "cancel" or "stop" the hook.
1864 | *
1865 | * Calling this will will typically unblock the player for whatever the hook
1866 | * is responsible for (e.g. for the "on_load" hook it lets it continue
1867 | * playback).
1868 | *
1869 | * It is explicitly undefined behavior to call this more than once for each
1870 | * MPV_EVENT_HOOK, to pass an incorrect ID, or to call this on a mpv_handle
1871 | * different from the one that registered the handler and received the event.
1872 | *
1873 | * @param id This must be the value of the mpv_event_hook.id field for the
1874 | * corresponding MPV_EVENT_HOOK.
1875 | * @return error code
1876 | */
1877 | int mpv_hook_continue(mpv_handle *ctx, uint64_t id);
1878 |
1879 | #if MPV_ENABLE_DEPRECATED
1880 |
1881 | /**
1882 | * Return a UNIX file descriptor referring to the read end of a pipe. This
1883 | * pipe can be used to wake up a poll() based processing loop. The purpose of
1884 | * this function is very similar to mpv_set_wakeup_callback(), and provides
1885 | * a primitive mechanism to handle coordinating a foreign event loop and the
1886 | * libmpv event loop. The pipe is non-blocking. It's closed when the mpv_handle
1887 | * is destroyed. This function always returns the same value (on success).
1888 | *
1889 | * This is in fact implemented using the same underlying code as for
1890 | * mpv_set_wakeup_callback() (though they don't conflict), and it is as if each
1891 | * callback invocation writes a single 0 byte to the pipe. When the pipe
1892 | * becomes readable, the code calling poll() (or select()) on the pipe should
1893 | * read all contents of the pipe and then call mpv_wait_event(c, 0) until
1894 | * no new events are returned. The pipe contents do not matter and can just
1895 | * be discarded. There is not necessarily one byte per readable event in the
1896 | * pipe. For example, the pipes are non-blocking, and mpv won't block if the
1897 | * pipe is full. Pipes are normally limited to 4096 bytes, so if there are
1898 | * more than 4096 events, the number of readable bytes can not equal the number
1899 | * of events queued. Also, it's possible that mpv does not write to the pipe
1900 | * once it's guaranteed that the client was already signaled. See the example
1901 | * below how to do it correctly.
1902 | *
1903 | * Example:
1904 | *
1905 | * int pipefd = mpv_get_wakeup_pipe(mpv);
1906 | * if (pipefd < 0)
1907 | * error();
1908 | * while (1) {
1909 | * struct pollfd pfds[1] = {
1910 | * { .fd = pipefd, .events = POLLIN },
1911 | * };
1912 | * // Wait until there are possibly new mpv events.
1913 | * poll(pfds, 1, -1);
1914 | * if (pfds[0].revents & POLLIN) {
1915 | * // Empty the pipe. Doing this before calling mpv_wait_event()
1916 | * // ensures that no wakeups are missed. It's not so important to
1917 | * // make sure the pipe is really empty (it will just cause some
1918 | * // additional wakeups in unlikely corner cases).
1919 | * char unused[256];
1920 | * read(pipefd, unused, sizeof(unused));
1921 | * while (1) {
1922 | * mpv_event *ev = mpv_wait_event(mpv, 0);
1923 | * // If MPV_EVENT_NONE is received, the event queue is empty.
1924 | * if (ev->event_id == MPV_EVENT_NONE)
1925 | * break;
1926 | * // Process the event.
1927 | * ...
1928 | * }
1929 | * }
1930 | * }
1931 | *
1932 | * @deprecated this function will be removed in the future. If you need this
1933 | * functionality, use mpv_set_wakeup_callback(), create a pipe
1934 | * manually, and call write() on your pipe in the callback.
1935 | *
1936 | * @return A UNIX FD of the read end of the wakeup pipe, or -1 on error.
1937 | * On MS Windows/MinGW, this will always return -1.
1938 | */
1939 | int mpv_get_wakeup_pipe(mpv_handle *ctx);
1940 |
1941 | /**
1942 | * @deprecated use render.h
1943 | */
1944 | typedef enum mpv_sub_api {
1945 | /**
1946 | * For using mpv's OpenGL renderer on an external OpenGL context.
1947 | * mpv_get_sub_api(MPV_SUB_API_OPENGL_CB) returns mpv_opengl_cb_context*.
1948 | * This context can be used with mpv_opengl_cb_* functions.
1949 | * Will return NULL if unavailable (if OpenGL support was not compiled in).
1950 | * See opengl_cb.h for details.
1951 | *
1952 | * @deprecated use render.h
1953 | */
1954 | MPV_SUB_API_OPENGL_CB = 1
1955 | } mpv_sub_api;
1956 |
1957 | /**
1958 | * This is used for additional APIs that are not strictly part of the core API.
1959 | * See the individual mpv_sub_api member values.
1960 | *
1961 | * @deprecated use render.h
1962 | */
1963 | void *mpv_get_sub_api(mpv_handle *ctx, mpv_sub_api sub_api);
1964 |
1965 | #endif
1966 |
1967 | #ifdef __cplusplus
1968 | }
1969 | #endif
1970 |
1971 | #endif
1972 |
--------------------------------------------------------------------------------
/framework-meta/libmpv/Headers/libmpv.h:
--------------------------------------------------------------------------------
1 | #import
2 | #import
3 | #import
4 | #import
5 |
--------------------------------------------------------------------------------
/framework-meta/libmpv/Headers/render.h:
--------------------------------------------------------------------------------
1 | /* Copyright (C) 2018 the mpv developers
2 | *
3 | * Permission to use, copy, modify, and/or distribute this software for any
4 | * purpose with or without fee is hereby granted, provided that the above
5 | * copyright notice and this permission notice appear in all copies.
6 | *
7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14 | */
15 |
16 | #ifndef MPV_CLIENT_API_RENDER_H_
17 | #define MPV_CLIENT_API_RENDER_H_
18 |
19 | #include "client.h"
20 |
21 | #ifdef __cplusplus
22 | extern "C" {
23 | #endif
24 |
25 | /**
26 | * Overview
27 | * --------
28 | *
29 | * This API can be used to make mpv render using supported graphic APIs (such
30 | * as OpenGL). It can be used to handle video display.
31 | *
32 | * The renderer needs to be created with mpv_render_context_create() before
33 | * you start playback (or otherwise cause a VO to be created). Then (with most
34 | * backends) mpv_render_context_render() can be used to explicitly render the
35 | * current video frame. Use mpv_render_context_set_update_callback() to get
36 | * notified when there is a new frame to draw.
37 | *
38 | * Preferably rendering should be done in a separate thread. If you call
39 | * normal libmpv API functions on the renderer thread, deadlocks can result
40 | * (these are made non-fatal with timeouts, but user experience will obviously
41 | * suffer). See "Threading" section below.
42 | *
43 | * You can output and embed video without this API by setting the mpv "wid"
44 | * option to a native window handle (see "Embedding the video window" section
45 | * in the client.h header). In general, using the render API is recommended,
46 | * because window embedding can cause various issues, especially with GUI
47 | * toolkits and certain platforms.
48 | *
49 | * Supported backends
50 | * ------------------
51 | *
52 | * OpenGL: via MPV_RENDER_API_TYPE_OPENGL, see render_gl.h header.
53 | *
54 | * Threading
55 | * ---------
56 | *
57 | * You are recommended to do rendering on a separate thread than normal libmpv
58 | * use.
59 | *
60 | * The mpv_render_* functions can be called from any thread, under the
61 | * following conditions:
62 | * - only one of the mpv_render_* functions can be called at the same time
63 | * (unless they belong to different mpv cores created by mpv_create())
64 | * - never can be called from within the callbacks set with
65 | * mpv_set_wakeup_callback() or mpv_render_context_set_update_callback()
66 | * - if the OpenGL backend is used, for all functions the OpenGL context
67 | * must be "current" in the calling thread, and it must be the same OpenGL
68 | * context as the mpv_render_context was created with. Otherwise, undefined
69 | * behavior will occur.
70 | * - the thread does not call libmpv API functions other than the mpv_render_*
71 | * functions, except APIs which are declared as safe (see below). Likewise,
72 | * there must be no lock or wait dependency from the render thread to a
73 | * thread using other libmpv functions. Basically, the situation that your
74 | * render thread waits for a "not safe" libmpv API function to return must
75 | * not happen. If you ignore this requirement, deadlocks can happen, which
76 | * are made non-fatal with timeouts; then playback quality will be degraded,
77 | * and the message
78 | * mpv_render_context_render() not being called or stuck.
79 | * is logged. If you set MPV_RENDER_PARAM_ADVANCED_CONTROL, you promise that
80 | * this won't happen, and must absolutely guarantee it, or a real deadlock
81 | * will freeze the mpv core thread forever.
82 | *
83 | * libmpv functions which are safe to call from a render thread are:
84 | * - functions marked with "Safe to be called from mpv render API threads."
85 | * - client.h functions which don't have an explicit or implicit mpv_handle
86 | * parameter
87 | * - mpv_render_* functions; but only for the same mpv_render_context pointer.
88 | * If the pointer is different, mpv_render_context_free() is not safe. (The
89 | * reason is that if MPV_RENDER_PARAM_ADVANCED_CONTROL is set, it may have
90 | * to process still queued requests from the core, which it can do only for
91 | * the current context, while requests for other contexts would deadlock.
92 | * Also, it may have to wait and block for the core to terminate the video
93 | * chain to make sure no resources are used after context destruction.)
94 | * - if the mpv_handle parameter refers to a different mpv core than the one
95 | * you're rendering for (very obscure, but allowed)
96 | *
97 | * Note about old libmpv version:
98 | *
99 | * Before API version 1.105 (basically in mpv 0.29.x), simply enabling
100 | * MPV_RENDER_PARAM_ADVANCED_CONTROL could cause deadlock issues. This can
101 | * be worked around by setting the "vd-lavc-dr" option to "no".
102 | * In addition, you were required to call all mpv_render*() API functions
103 | * from the same thread on which mpv_render_context_create() was originally
104 | * run (for the same the mpv_render_context). Not honoring it led to UB
105 | * (deadlocks, use of invalid pthread_t handles), even if you moved your GL
106 | * context to a different thread correctly.
107 | * These problems were addressed in API version 1.105 (mpv 0.30.0).
108 | *
109 | * Context and handle lifecycle
110 | * ----------------------------
111 | *
112 | * Video initialization will fail if the render context was not initialized yet
113 | * (with mpv_render_context_create()), or it will revert to a VO that creates
114 | * its own window.
115 | *
116 | * Currently, there can be only 1 mpv_render_context at a time per mpv core.
117 | *
118 | * Calling mpv_render_context_free() while a VO is using the render context is
119 | * active will disable video.
120 | *
121 | * You must free the context with mpv_render_context_free() before the mpv core
122 | * is destroyed. If this doesn't happen, undefined behavior will result.
123 | */
124 |
125 | /**
126 | * Opaque context, returned by mpv_render_context_create().
127 | */
128 | typedef struct mpv_render_context mpv_render_context;
129 |
130 | /**
131 | * Parameters for mpv_render_param (which is used in a few places such as
132 | * mpv_render_context_create().
133 | *
134 | * Also see mpv_render_param for conventions and how to use it.
135 | */
136 | typedef enum mpv_render_param_type {
137 | /**
138 | * Not a valid value, but also used to terminate a params array. Its value
139 | * is always guaranteed to be 0 (even if the ABI changes in the future).
140 | */
141 | MPV_RENDER_PARAM_INVALID = 0,
142 | /**
143 | * The render API to use. Valid for mpv_render_context_create().
144 | *
145 | * Type: char*
146 | *
147 | * Defined APIs:
148 | *
149 | * MPV_RENDER_API_TYPE_OPENGL:
150 | * OpenGL desktop 2.1 or later (preferably core profile compatible to
151 | * OpenGL 3.2), or OpenGLES 2.0 or later.
152 | * Providing MPV_RENDER_PARAM_OPENGL_INIT_PARAMS is required.
153 | * It is expected that an OpenGL context is valid and "current" when
154 | * calling mpv_render_* functions (unless specified otherwise). It
155 | * must be the same context for the same mpv_render_context.
156 | */
157 | MPV_RENDER_PARAM_API_TYPE = 1,
158 | /**
159 | * Required parameters for initializing the OpenGL renderer. Valid for
160 | * mpv_render_context_create().
161 | * Type: mpv_opengl_init_params*
162 | */
163 | MPV_RENDER_PARAM_OPENGL_INIT_PARAMS = 2,
164 | /**
165 | * Describes a GL render target. Valid for mpv_render_context_render().
166 | * Type: mpv_opengl_fbo*
167 | */
168 | MPV_RENDER_PARAM_OPENGL_FBO = 3,
169 | /**
170 | * Control flipped rendering. Valid for mpv_render_context_render().
171 | * Type: int*
172 | * If the value is set to 0, render normally. Otherwise, render it flipped,
173 | * which is needed e.g. when rendering to an OpenGL default framebuffer
174 | * (which has a flipped coordinate system).
175 | */
176 | MPV_RENDER_PARAM_FLIP_Y = 4,
177 | /**
178 | * Control surface depth. Valid for mpv_render_context_render().
179 | * Type: int*
180 | * This implies the depth of the surface passed to the render function in
181 | * bits per channel. If omitted or set to 0, the renderer will assume 8.
182 | * Typically used to control dithering.
183 | */
184 | MPV_RENDER_PARAM_DEPTH = 5,
185 | /**
186 | * ICC profile blob. Valid for mpv_render_context_set_parameter().
187 | * Type: mpv_byte_array*
188 | * Set an ICC profile for use with the "icc-profile-auto" option. (If the
189 | * option is not enabled, the ICC data will not be used.)
190 | */
191 | MPV_RENDER_PARAM_ICC_PROFILE = 6,
192 | /**
193 | * Ambient light in lux. Valid for mpv_render_context_set_parameter().
194 | * Type: int*
195 | * This can be used for automatic gamma correction.
196 | */
197 | MPV_RENDER_PARAM_AMBIENT_LIGHT = 7,
198 | /**
199 | * X11 Display, sometimes used for hwdec. Valid for
200 | * mpv_render_context_create(). The Display must stay valid for the lifetime
201 | * of the mpv_render_context.
202 | * Type: Display*
203 | */
204 | MPV_RENDER_PARAM_X11_DISPLAY = 8,
205 | /**
206 | * Wayland display, sometimes used for hwdec. Valid for
207 | * mpv_render_context_create(). The wl_display must stay valid for the
208 | * lifetime of the mpv_render_context.
209 | * Type: struct wl_display*
210 | */
211 | MPV_RENDER_PARAM_WL_DISPLAY = 9,
212 | /**
213 | * Better control about rendering and enabling some advanced features. Valid
214 | * for mpv_render_context_create().
215 | *
216 | * This conflates multiple requirements the API user promises to abide if
217 | * this option is enabled:
218 | *
219 | * - The API user's render thread, which is calling the mpv_render_*()
220 | * functions, never waits for the core. Otherwise deadlocks can happen.
221 | * See "Threading" section.
222 | * - The callback set with mpv_render_context_set_update_callback() can now
223 | * be called even if there is no new frame. The API user should call the
224 | * mpv_render_context_update() function, and interpret the return value
225 | * for whether a new frame should be rendered.
226 | * - Correct functionality is impossible if the update callback is not set,
227 | * or not set soon enough after mpv_render_context_create() (the core can
228 | * block while waiting for you to call mpv_render_context_update(), and
229 | * if the update callback is not correctly set, it will deadlock, or
230 | * block for too long).
231 | *
232 | * In general, setting this option will enable the following features (and
233 | * possibly more):
234 | *
235 | * - "Direct rendering", which means the player decodes directly to a
236 | * texture, which saves a copy per video frame ("vd-lavc-dr" option
237 | * needs to be enabled, and the rendering backend as well as the
238 | * underlying GPU API/driver needs to have support for it).
239 | * - Rendering screenshots with the GPU API if supported by the backend
240 | * (instead of using a suboptimal software fallback via libswscale).
241 | *
242 | * Warning: do not just add this without reading the "Threading" section
243 | * above, and then wondering that deadlocks happen. The
244 | * requirements are tricky. But also note that even if advanced
245 | * control is disabled, not adhering to the rules will lead to
246 | * playback problems. Enabling advanced controls simply makes
247 | * violating these rules fatal.
248 | *
249 | * Type: int*: 0 for disable (default), 1 for enable
250 | */
251 | MPV_RENDER_PARAM_ADVANCED_CONTROL = 10,
252 | /**
253 | * Return information about the next frame to render. Valid for
254 | * mpv_render_context_get_info().
255 | *
256 | * Type: mpv_render_frame_info*
257 | *
258 | * It strictly returns information about the _next_ frame. The implication
259 | * is that e.g. mpv_render_context_update()'s return value will have
260 | * MPV_RENDER_UPDATE_FRAME set, and the user is supposed to call
261 | * mpv_render_context_render(). If there is no next frame, then the
262 | * return value will have is_valid set to 0.
263 | */
264 | MPV_RENDER_PARAM_NEXT_FRAME_INFO = 11,
265 | /**
266 | * Enable or disable video timing. Valid for mpv_render_context_render().
267 | *
268 | * Type: int*: 0 for disable, 1 for enable (default)
269 | *
270 | * When video is timed to audio, the player attempts to render video a bit
271 | * ahead, and then do a blocking wait until the target display time is
272 | * reached. This blocks mpv_render_context_render() for up to the amount
273 | * specified with the "video-timing-offset" global option. You can set
274 | * this parameter to 0 to disable this kind of waiting. If you do, it's
275 | * recommended to use the target time value in mpv_render_frame_info to
276 | * wait yourself, or to set the "video-timing-offset" to 0 instead.
277 | *
278 | * Disabling this without doing anything in addition will result in A/V sync
279 | * being slightly off.
280 | */
281 | MPV_RENDER_PARAM_BLOCK_FOR_TARGET_TIME = 12,
282 | /**
283 | * Use to skip rendering in mpv_render_context_render().
284 | *
285 | * Type: int*: 0 for rendering (default), 1 for skipping
286 | *
287 | * If this is set, you don't need to pass a target surface to the render
288 | * function (and if you do, it's completely ignored). This can still call
289 | * into the lower level APIs (i.e. if you use OpenGL, the OpenGL context
290 | * must be set).
291 | *
292 | * Be aware that the render API will consider this frame as having been
293 | * rendered. All other normal rules also apply, for example about whether
294 | * you have to call mpv_render_context_report_swap(). It also does timing
295 | * in the same way.
296 | */
297 | MPV_RENDER_PARAM_SKIP_RENDERING = 13,
298 | /**
299 | * Deprecated. Not supported. Use MPV_RENDER_PARAM_DRM_DISPLAY_V2 instead.
300 | * Type : struct mpv_opengl_drm_params*
301 | */
302 | MPV_RENDER_PARAM_DRM_DISPLAY = 14,
303 | /**
304 | * DRM draw surface size, contains draw surface dimensions.
305 | * Valid for mpv_render_context_create().
306 | * Type : struct mpv_opengl_drm_draw_surface_size*
307 | */
308 | MPV_RENDER_PARAM_DRM_DRAW_SURFACE_SIZE = 15,
309 | /**
310 | * DRM display, contains drm display handles.
311 | * Valid for mpv_render_context_create().
312 | * Type : struct mpv_opengl_drm_params_v2*
313 | */
314 | MPV_RENDER_PARAM_DRM_DISPLAY_V2 = 16,
315 | } mpv_render_param_type;
316 |
317 | /**
318 | * For backwards compatibility with the old naming of
319 | * MPV_RENDER_PARAM_DRM_DRAW_SURFACE_SIZE
320 | */
321 | #define MPV_RENDER_PARAM_DRM_OSD_SIZE MPV_RENDER_PARAM_DRM_DRAW_SURFACE_SIZE
322 |
323 | /**
324 | * Used to pass arbitrary parameters to some mpv_render_* functions. The
325 | * meaning of the data parameter is determined by the type, and each
326 | * MPV_RENDER_PARAM_* documents what type the value must point to.
327 | *
328 | * Each value documents the required data type as the pointer you cast to
329 | * void* and set on mpv_render_param.data. For example, if MPV_RENDER_PARAM_FOO
330 | * documents the type as Something* , then the code should look like this:
331 | *
332 | * Something foo = {...};
333 | * mpv_render_param param;
334 | * param.type = MPV_RENDER_PARAM_FOO;
335 | * param.data = & foo;
336 | *
337 | * Normally, the data field points to exactly 1 object. If the type is char*,
338 | * it points to a 0-terminated string.
339 | *
340 | * In all cases (unless documented otherwise) the pointers need to remain
341 | * valid during the call only. Unless otherwise documented, the API functions
342 | * will not write to the params array or any data pointed to it.
343 | *
344 | * As a convention, parameter arrays are always terminated by type==0. There
345 | * is no specific order of the parameters required. The order of the 2 fields in
346 | * this struct is guaranteed (even after ABI changes).
347 | */
348 | typedef struct mpv_render_param {
349 | enum mpv_render_param_type type;
350 | void *data;
351 | } mpv_render_param;
352 |
353 |
354 | /**
355 | * Predefined values for MPV_RENDER_PARAM_API_TYPE.
356 | */
357 | #define MPV_RENDER_API_TYPE_OPENGL "opengl"
358 |
359 | /**
360 | * Flags used in mpv_render_frame_info.flags. Each value represents a bit in it.
361 | */
362 | typedef enum mpv_render_frame_info_flag {
363 | /**
364 | * Set if there is actually a next frame. If unset, there is no next frame
365 | * yet, and other flags and fields that require a frame to be queued will
366 | * be unset.
367 | *
368 | * This is set for _any_ kind of frame, even for redraw requests.
369 | *
370 | * Note that when this is unset, it simply means no new frame was
371 | * decoded/queued yet, not necessarily that the end of the video was
372 | * reached. A new frame can be queued after some time.
373 | *
374 | * If the return value of mpv_render_context_render() had the
375 | * MPV_RENDER_UPDATE_FRAME flag set, this flag will usually be set as well,
376 | * unless the frame is rendered, or discarded by other asynchronous events.
377 | */
378 | MPV_RENDER_FRAME_INFO_PRESENT = 1 << 0,
379 | /**
380 | * If set, the frame is not an actual new video frame, but a redraw request.
381 | * For example if the video is paused, and an option that affects video
382 | * rendering was changed (or any other reason), an update request can be
383 | * issued and this flag will be set.
384 | *
385 | * Typically, redraw frames will not be subject to video timing.
386 | *
387 | * Implies MPV_RENDER_FRAME_INFO_PRESENT.
388 | */
389 | MPV_RENDER_FRAME_INFO_REDRAW = 1 << 1,
390 | /**
391 | * If set, this is supposed to reproduce the previous frame perfectly. This
392 | * is usually used for certain "video-sync" options ("display-..." modes).
393 | * Typically the renderer will blit the video from a FBO. Unset otherwise.
394 | *
395 | * Implies MPV_RENDER_FRAME_INFO_PRESENT.
396 | */
397 | MPV_RENDER_FRAME_INFO_REPEAT = 1 << 2,
398 | /**
399 | * If set, the player timing code expects that the user thread blocks on
400 | * vsync (by either delaying the render call, or by making a call to
401 | * mpv_render_context_report_swap() at vsync time).
402 | *
403 | * Implies MPV_RENDER_FRAME_INFO_PRESENT.
404 | */
405 | MPV_RENDER_FRAME_INFO_BLOCK_VSYNC = 1 << 3,
406 | } mpv_render_frame_info_flag;
407 |
408 | /**
409 | * Information about the next video frame that will be rendered. Can be
410 | * retrieved with MPV_RENDER_PARAM_NEXT_FRAME_INFO.
411 | */
412 | typedef struct mpv_render_frame_info {
413 | /**
414 | * A bitset of mpv_render_frame_info_flag values (i.e. multiple flags are
415 | * combined with bitwise or).
416 | */
417 | uint64_t flags;
418 | /**
419 | * Absolute time at which the frame is supposed to be displayed. This is in
420 | * the same unit and base as the time returned by mpv_get_time_us(). For
421 | * frames that are redrawn, or if vsync locked video timing is used (see
422 | * "video-sync" option), then this can be 0. The "video-timing-offset"
423 | * option determines how much "headroom" the render thread gets (but a high
424 | * enough frame rate can reduce it anyway). mpv_render_context_render() will
425 | * normally block until the time is elapsed, unless you pass it
426 | * MPV_RENDER_PARAM_BLOCK_FOR_TARGET_TIME = 0.
427 | */
428 | int64_t target_time;
429 | } mpv_render_frame_info;
430 |
431 | /**
432 | * Initialize the renderer state. Depending on the backend used, this will
433 | * access the underlying GPU API and initialize its own objects.
434 | *
435 | * You must free the context with mpv_render_context_free(). Not doing so before
436 | * the mpv core is destroyed may result in memory leaks or crashes.
437 | *
438 | * Currently, only at most 1 context can exists per mpv core (it represents the
439 | * main video output).
440 | *
441 | * You should pass the following parameters:
442 | * - MPV_RENDER_PARAM_API_TYPE to select the underlying backend/GPU API.
443 | * - Backend-specific init parameter, like MPV_RENDER_PARAM_OPENGL_INIT_PARAMS.
444 | * - Setting MPV_RENDER_PARAM_ADVANCED_CONTROL and following its rules is
445 | * strongly recommended.
446 | * - If you want to use hwdec, possibly hwdec interop resources.
447 | *
448 | * @param res set to the context (on success) or NULL (on failure). The value
449 | * is never read and always overwritten.
450 | * @param mpv handle used to get the core (the mpv_render_context won't depend
451 | * on this specific handle, only the core referenced by it)
452 | * @param params an array of parameters, terminated by type==0. It's left
453 | * unspecified what happens with unknown parameters. At least
454 | * MPV_RENDER_PARAM_API_TYPE is required, and most backends will
455 | * require another backend-specific parameter.
456 | * @return error code, including but not limited to:
457 | * MPV_ERROR_UNSUPPORTED: the OpenGL version is not supported
458 | * (or required extensions are missing)
459 | * MPV_ERROR_NOT_IMPLEMENTED: an unknown API type was provided, or
460 | * support for the requested API was not
461 | * built in the used libmpv binary.
462 | * MPV_ERROR_INVALID_PARAMETER: at least one of the provided parameters was
463 | * not valid.
464 | */
465 | int mpv_render_context_create(mpv_render_context **res, mpv_handle *mpv,
466 | mpv_render_param *params);
467 |
468 | /**
469 | * Attempt to change a single parameter. Not all backends and parameter types
470 | * support all kinds of changes.
471 | *
472 | * @param ctx a valid render context
473 | * @param param the parameter type and data that should be set
474 | * @return error code. If a parameter could actually be changed, this returns
475 | * success, otherwise an error code depending on the parameter type
476 | * and situation.
477 | */
478 | int mpv_render_context_set_parameter(mpv_render_context *ctx,
479 | mpv_render_param param);
480 |
481 | /**
482 | * Retrieve information from the render context. This is NOT a counterpart to
483 | * mpv_render_context_set_parameter(), because you generally can't read
484 | * parameters set with it, and this function is not meant for this purpose.
485 | * Instead, this is for communicating information from the renderer back to the
486 | * user. See mpv_render_param_type; entries which support this function
487 | * explicitly mention it, and for other entries you can assume it will fail.
488 | *
489 | * You pass param with param.type set and param.data pointing to a variable
490 | * of the required data type. The function will then overwrite that variable
491 | * with the returned value (at least on success).
492 | *
493 | * @param ctx a valid render context
494 | * @param param the parameter type and data that should be retrieved
495 | * @return error code. If a parameter could actually be retrieved, this returns
496 | * success, otherwise an error code depending on the parameter type
497 | * and situation. MPV_ERROR_NOT_IMPLEMENTED is used for unknown
498 | * param.type, or if retrieving it is not supported.
499 | */
500 | int mpv_render_context_get_info(mpv_render_context *ctx,
501 | mpv_render_param param);
502 |
503 | typedef void (*mpv_render_update_fn)(void *cb_ctx);
504 |
505 | /**
506 | * Set the callback that notifies you when a new video frame is available, or
507 | * if the video display configuration somehow changed and requires a redraw.
508 | * Similar to mpv_set_wakeup_callback(), you must not call any mpv API from
509 | * the callback, and all the other listed restrictions apply (such as not
510 | * exiting the callback by throwing exceptions).
511 | *
512 | * This can be called from any thread, except from an update callback. In case
513 | * of the OpenGL backend, no OpenGL state or API is accessed.
514 | *
515 | * Calling this will raise an update callback immediately.
516 | *
517 | * @param callback callback(callback_ctx) is called if the frame should be
518 | * redrawn
519 | * @param callback_ctx opaque argument to the callback
520 | */
521 | void mpv_render_context_set_update_callback(mpv_render_context *ctx,
522 | mpv_render_update_fn callback,
523 | void *callback_ctx);
524 |
525 | /**
526 | * The API user is supposed to call this when the update callback was invoked
527 | * (like all mpv_render_* functions, this has to happen on the render thread,
528 | * and _not_ from the update callback itself).
529 | *
530 | * This is optional if MPV_RENDER_PARAM_ADVANCED_CONTROL was not set (default).
531 | * Otherwise, it's a hard requirement that this is called after each update
532 | * callback. If multiple update callback happened, and the function could not
533 | * be called sooner, it's OK to call it once after the last callback.
534 | *
535 | * If an update callback happens during or after this function, the function
536 | * must be called again at the soonest possible time.
537 | *
538 | * If MPV_RENDER_PARAM_ADVANCED_CONTROL was set, this will do additional work
539 | * such as allocating textures for the video decoder.
540 | *
541 | * @return a bitset of mpv_render_update_flag values (i.e. multiple flags are
542 | * combined with bitwise or). Typically, this will tell the API user
543 | * what should happen next. E.g. if the MPV_RENDER_UPDATE_FRAME flag is
544 | * set, mpv_render_context_render() should be called. If flags unknown
545 | * to the API user are set, or if the return value is 0, nothing needs
546 | * to be done.
547 | */
548 | uint64_t mpv_render_context_update(mpv_render_context *ctx);
549 |
550 | /**
551 | * Flags returned by mpv_render_context_update(). Each value represents a bit
552 | * in the function's return value.
553 | */
554 | typedef enum mpv_render_update_flag {
555 | /**
556 | * A new video frame must be rendered. mpv_render_context_render() must be
557 | * called.
558 | */
559 | MPV_RENDER_UPDATE_FRAME = 1 << 0,
560 | } mpv_render_context_flag;
561 |
562 | /**
563 | * Render video.
564 | *
565 | * Typically renders the video to a target surface provided via mpv_render_param
566 | * (the details depend on the backend in use). Options like "panscan" are
567 | * applied to determine which part of the video should be visible and how the
568 | * video should be scaled. You can change these options at runtime by using the
569 | * mpv property API.
570 | *
571 | * The renderer will reconfigure itself every time the target surface
572 | * configuration (such as size) is changed.
573 | *
574 | * This function implicitly pulls a video frame from the internal queue and
575 | * renders it. If no new frame is available, the previous frame is redrawn.
576 | * The update callback set with mpv_render_context_set_update_callback()
577 | * notifies you when a new frame was added. The details potentially depend on
578 | * the backends and the provided parameters.
579 | *
580 | * Generally, libmpv will invoke your update callback some time before the video
581 | * frame should be shown, and then lets this function block until the supposed
582 | * display time. This will limit your rendering to video FPS. You can prevent
583 | * this by setting the "video-timing-offset" global option to 0. (This applies
584 | * only to "audio" video sync mode.)
585 | *
586 | * You should pass the following parameters:
587 | * - Backend-specific target object, such as MPV_RENDER_PARAM_OPENGL_FBO.
588 | * - Possibly transformations, such as MPV_RENDER_PARAM_FLIP_Y.
589 | *
590 | * @param ctx a valid render context
591 | * @param params an array of parameters, terminated by type==0. Which parameters
592 | * are required depends on the backend. It's left unspecified what
593 | * happens with unknown parameters.
594 | * @return error code
595 | */
596 | int mpv_render_context_render(mpv_render_context *ctx, mpv_render_param *params);
597 |
598 | /**
599 | * Tell the renderer that a frame was flipped at the given time. This is
600 | * optional, but can help the player to achieve better timing.
601 | *
602 | * Note that calling this at least once informs libmpv that you will use this
603 | * function. If you use it inconsistently, expect bad video playback.
604 | *
605 | * If this is called while no video is initialized, it is ignored.
606 | *
607 | * @param ctx a valid render context
608 | */
609 | void mpv_render_context_report_swap(mpv_render_context *ctx);
610 |
611 | /**
612 | * Destroy the mpv renderer state.
613 | *
614 | * If video is still active (e.g. a file playing), video will be disabled
615 | * forcefully.
616 | *
617 | * @param ctx a valid render context. After this function returns, this is not
618 | * a valid pointer anymore. NULL is also allowed and does nothing.
619 | */
620 | void mpv_render_context_free(mpv_render_context *ctx);
621 |
622 | #ifdef __cplusplus
623 | }
624 | #endif
625 |
626 | #endif
627 |
--------------------------------------------------------------------------------
/framework-meta/libmpv/Headers/render_gl.h:
--------------------------------------------------------------------------------
1 | /* Copyright (C) 2018 the mpv developers
2 | *
3 | * Permission to use, copy, modify, and/or distribute this software for any
4 | * purpose with or without fee is hereby granted, provided that the above
5 | * copyright notice and this permission notice appear in all copies.
6 | *
7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14 | */
15 |
16 | #ifndef MPV_CLIENT_API_RENDER_GL_H_
17 | #define MPV_CLIENT_API_RENDER_GL_H_
18 |
19 | #include "render.h"
20 |
21 | #ifdef __cplusplus
22 | extern "C" {
23 | #endif
24 |
25 | /**
26 | * OpenGL backend
27 | * --------------
28 | *
29 | * This header contains definitions for using OpenGL with the render.h API.
30 | *
31 | * OpenGL interop
32 | * --------------
33 | *
34 | * The OpenGL backend has some special rules, because OpenGL itself uses
35 | * implicit per-thread contexts, which causes additional API problems.
36 | *
37 | * This assumes the OpenGL context lives on a certain thread controlled by the
38 | * API user. All mpv_render_* APIs have to be assumed to implicitly use the
39 | * OpenGL context if you pass a mpv_render_context using the OpenGL backend,
40 | * unless specified otherwise.
41 | *
42 | * The OpenGL context is indirectly accessed through the OpenGL function
43 | * pointers returned by the get_proc_address callback in mpv_opengl_init_params.
44 | * Generally, mpv will not load the system OpenGL library when using this API.
45 | *
46 | * OpenGL state
47 | * ------------
48 | *
49 | * OpenGL has a large amount of implicit state. All the mpv functions mentioned
50 | * above expect that the OpenGL state is reasonably set to OpenGL standard
51 | * defaults. Likewise, mpv will attempt to leave the OpenGL context with
52 | * standard defaults. The following state is excluded from this:
53 | *
54 | * - the glViewport state
55 | * - the glScissor state (but GL_SCISSOR_TEST is in its default value)
56 | * - glBlendFuncSeparate() state (but GL_BLEND is in its default value)
57 | * - glClearColor() state
58 | * - mpv may overwrite the callback set with glDebugMessageCallback()
59 | * - mpv always disables GL_DITHER at init
60 | *
61 | * Messing with the state could be avoided by creating shared OpenGL contexts,
62 | * but this is avoided for the sake of compatibility and interoperability.
63 | *
64 | * On OpenGL 2.1, mpv will strictly call functions like glGenTextures() to
65 | * create OpenGL objects. You will have to do the same. This ensures that
66 | * objects created by mpv and the API users don't clash. Also, legacy state
67 | * must be either in its defaults, or not interfere with core state.
68 | *
69 | * API use
70 | * -------
71 | *
72 | * The mpv_render_* API is used. That API supports multiple backends, and this
73 | * section documents specifics for the OpenGL backend.
74 | *
75 | * Use mpv_render_context_create() with MPV_RENDER_PARAM_API_TYPE set to
76 | * MPV_RENDER_API_TYPE_OPENGL, and MPV_RENDER_PARAM_OPENGL_INIT_PARAMS provided.
77 | *
78 | * Call mpv_render_context_render() with MPV_RENDER_PARAM_OPENGL_FBO to render
79 | * the video frame to an FBO.
80 | *
81 | * Hardware decoding
82 | * -----------------
83 | *
84 | * Hardware decoding via this API is fully supported, but requires some
85 | * additional setup. (At least if direct hardware decoding modes are wanted,
86 | * instead of copying back surface data from GPU to CPU RAM.)
87 | *
88 | * There may be certain requirements on the OpenGL implementation:
89 | *
90 | * - Windows: ANGLE is required (although in theory GL/DX interop could be used)
91 | * - Intel/Linux: EGL is required, and also the native display resource needs
92 | * to be provided (e.g. MPV_RENDER_PARAM_X11_DISPLAY for X11 and
93 | * MPV_RENDER_PARAM_WL_DISPLAY for Wayland)
94 | * - nVidia/Linux: Both GLX and EGL should work (GLX is required if vdpau is
95 | * used, e.g. due to old drivers.)
96 | * - OSX: CGL is required (CGLGetCurrentContext() returning non-NULL)
97 | * - iOS: EAGL is required (EAGLContext.currentContext returning non-nil)
98 | *
99 | * Once these things are setup, hardware decoding can be enabled/disabled at
100 | * any time by setting the "hwdec" property.
101 | */
102 |
103 | /**
104 | * For initializing the mpv OpenGL state via MPV_RENDER_PARAM_OPENGL_INIT_PARAMS.
105 | */
106 | typedef struct mpv_opengl_init_params {
107 | /**
108 | * This retrieves OpenGL function pointers, and will use them in subsequent
109 | * operation.
110 | * Usually, you can simply call the GL context APIs from this callback (e.g.
111 | * glXGetProcAddressARB or wglGetProcAddress), but some APIs do not always
112 | * return pointers for all standard functions (even if present); in this
113 | * case you have to compensate by looking up these functions yourself when
114 | * libmpv wants to resolve them through this callback.
115 | * libmpv will not normally attempt to resolve GL functions on its own, nor
116 | * does it link to GL libraries directly.
117 | */
118 | void *(*get_proc_address)(void *ctx, const char *name);
119 | /**
120 | * Value passed as ctx parameter to get_proc_address().
121 | */
122 | void *get_proc_address_ctx;
123 | /**
124 | * This should not be used. It is deprecated and will be removed or ignored
125 | * when the opengl_cb API is removed.
126 | */
127 | const char *extra_exts;
128 | } mpv_opengl_init_params;
129 |
130 | /**
131 | * For MPV_RENDER_PARAM_OPENGL_FBO.
132 | */
133 | typedef struct mpv_opengl_fbo {
134 | /**
135 | * Framebuffer object name. This must be either a valid FBO generated by
136 | * glGenFramebuffers() that is complete and color-renderable, or 0. If the
137 | * value is 0, this refers to the OpenGL default framebuffer.
138 | */
139 | int fbo;
140 | /**
141 | * Valid dimensions. This must refer to the size of the framebuffer. This
142 | * must always be set.
143 | */
144 | int w, h;
145 | /**
146 | * Underlying texture internal format (e.g. GL_RGBA8), or 0 if unknown. If
147 | * this is the default framebuffer, this can be an equivalent.
148 | */
149 | int internal_format;
150 | } mpv_opengl_fbo;
151 |
152 | /**
153 | * Deprecated. For MPV_RENDER_PARAM_DRM_DISPLAY.
154 | */
155 | typedef struct mpv_opengl_drm_params {
156 | int fd;
157 | int crtc_id;
158 | int connector_id;
159 | struct _drmModeAtomicReq **atomic_request_ptr;
160 | int render_fd;
161 | } mpv_opengl_drm_params;
162 |
163 | /**
164 | * For MPV_RENDER_PARAM_DRM_DRAW_SURFACE_SIZE.
165 | */
166 | typedef struct mpv_opengl_drm_draw_surface_size {
167 | /**
168 | * size of the draw plane surface in pixels.
169 | */
170 | int width, height;
171 | } mpv_opengl_drm_draw_surface_size;
172 |
173 | /**
174 | * For MPV_RENDER_PARAM_DRM_DISPLAY_V2.
175 | */
176 | typedef struct mpv_opengl_drm_params_v2 {
177 | /**
178 | * DRM fd (int). Set to -1 if invalid.
179 | */
180 | int fd;
181 |
182 | /**
183 | * Currently used crtc id
184 | */
185 | int crtc_id;
186 |
187 | /**
188 | * Currently used connector id
189 | */
190 | int connector_id;
191 |
192 | /**
193 | * Pointer to a drmModeAtomicReq pointer that is being used for the renderloop.
194 | * This pointer should hold a pointer to the atomic request pointer
195 | * The atomic request pointer is usually changed at every renderloop.
196 | */
197 | struct _drmModeAtomicReq **atomic_request_ptr;
198 |
199 | /**
200 | * DRM render node. Used for VAAPI interop.
201 | * Set to -1 if invalid.
202 | */
203 | int render_fd;
204 | } mpv_opengl_drm_params_v2;
205 |
206 |
207 | /**
208 | * For backwards compatibility with the old naming of mpv_opengl_drm_draw_surface_size
209 | */
210 | #define mpv_opengl_drm_osd_size mpv_opengl_drm_draw_surface_size
211 |
212 | #ifdef __cplusplus
213 | }
214 | #endif
215 |
216 | #endif
217 |
--------------------------------------------------------------------------------
/framework-meta/libmpv/Headers/stream_cb.h:
--------------------------------------------------------------------------------
1 | /* Copyright (C) 2017 the mpv developers
2 | *
3 | * Permission to use, copy, modify, and/or distribute this software for any
4 | * purpose with or without fee is hereby granted, provided that the above
5 | * copyright notice and this permission notice appear in all copies.
6 | *
7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14 | */
15 |
16 | #ifndef MPV_CLIENT_API_STREAM_CB_H_
17 | #define MPV_CLIENT_API_STREAM_CB_H_
18 |
19 | #include "client.h"
20 |
21 | #ifdef __cplusplus
22 | extern "C" {
23 | #endif
24 |
25 | /**
26 | * Warning: this API is not stable yet.
27 | *
28 | * Overview
29 | * --------
30 | *
31 | * This API can be used to make mpv read from a stream with a custom
32 | * implementation. This interface is inspired by funopen on BSD and
33 | * fopencookie on linux. The stream is backed by user-defined callbacks
34 | * which can implement customized open, read, seek, size and close behaviors.
35 | *
36 | * Usage
37 | * -----
38 | *
39 | * Register your stream callbacks with the mpv_stream_cb_add_ro() function. You
40 | * have to provide a mpv_stream_cb_open_ro_fn callback to it (open_fn argument).
41 | *
42 | * Once registered, you can `loadfile myprotocol://myfile`. Your open_fn will be
43 | * invoked with the URI and you must fill out the provided mpv_stream_cb_info
44 | * struct. This includes your stream callbacks (like read_fn), and an opaque
45 | * cookie, which will be passed as the first argument to all the remaining
46 | * stream callbacks.
47 | *
48 | * Note that your custom callbacks must not invoke libmpv APIs as that would
49 | * cause a deadlock. (Unless you call a different mpv_handle than the one the
50 | * callback was registered for, and the mpv_handles refer to different mpv
51 | * instances.)
52 | *
53 | * Stream lifetime
54 | * ---------------
55 | *
56 | * A stream remains valid until its close callback has been called. It's up to
57 | * libmpv to call the close callback, and the libmpv user cannot close it
58 | * directly with the stream_cb API.
59 | *
60 | * For example, if you consider your custom stream to become suddenly invalid
61 | * (maybe because the underlying stream died), libmpv will continue using your
62 | * stream. All you can do is returning errors from each callback, until libmpv
63 | * gives up and closes it.
64 | *
65 | * Protocol registration and lifetime
66 | * ----------------------------------
67 | *
68 | * Protocols remain registered until the mpv instance is terminated. This means
69 | * in particular that it can outlive the mpv_handle that was used to register
70 | * it, but once mpv_terminate_destroy() is called, your registered callbacks
71 | * will not be called again.
72 | *
73 | * Protocol unregistration is finished after the mpv core has been destroyed
74 | * (e.g. after mpv_terminate_destroy() has returned).
75 | *
76 | * If you do not call mpv_terminate_destroy() yourself (e.g. plugin-style code),
77 | * you will have to deal with the registration or even streams outliving your
78 | * code. Here are some possible ways to do this:
79 | * - call mpv_terminate_destroy(), which destroys the core, and will make sure
80 | * all streams are closed once this function returns
81 | * - you refcount all resources your stream "cookies" reference, so that it
82 | * doesn't matter if streams live longer than expected
83 | * - create "cancellation" semantics: after your protocol has been unregistered,
84 | * notify all your streams that are still opened, and make them drop all
85 | * referenced resources - then return errors from the stream callbacks as
86 | * long as the stream is still opened
87 | *
88 | */
89 |
90 | /**
91 | * Read callback used to implement a custom stream. The semantics of the
92 | * callback match read(2) in blocking mode. Short reads are allowed (you can
93 | * return less bytes than requested, and libmpv will retry reading the rest
94 | * with another call). If no data can be immediately read, the callback must
95 | * block until there is new data. A return of 0 will be interpreted as final
96 | * EOF, although libmpv might retry the read, or seek to a different position.
97 | *
98 | * @param cookie opaque cookie identifying the stream,
99 | * returned from mpv_stream_cb_open_fn
100 | * @param buf buffer to read data into
101 | * @param size of the buffer
102 | * @return number of bytes read into the buffer
103 | * @return 0 on EOF
104 | * @return -1 on error
105 | */
106 | typedef int64_t (*mpv_stream_cb_read_fn)(void *cookie, char *buf, uint64_t nbytes);
107 |
108 | /**
109 | * Seek callback used to implement a custom stream.
110 | *
111 | * Note that mpv will issue a seek to position 0 immediately after opening. This
112 | * is used to test whether the stream is seekable (since seekability might
113 | * depend on the URI contents, not just the protocol). Return
114 | * MPV_ERROR_UNSUPPORTED if seeking is not implemented for this stream. This
115 | * seek also serves to establish the fact that streams start at position 0.
116 | *
117 | * This callback can be NULL, in which it behaves as if always returning
118 | * MPV_ERROR_UNSUPPORTED.
119 | *
120 | * @param cookie opaque cookie identifying the stream,
121 | * returned from mpv_stream_cb_open_fn
122 | * @param offset target absolut stream position
123 | * @return the resulting offset of the stream
124 | * MPV_ERROR_UNSUPPORTED or MPV_ERROR_GENERIC if the seek failed
125 | */
126 | typedef int64_t (*mpv_stream_cb_seek_fn)(void *cookie, int64_t offset);
127 |
128 | /**
129 | * Size callback used to implement a custom stream.
130 | *
131 | * Return MPV_ERROR_UNSUPPORTED if no size is known.
132 | *
133 | * This callback can be NULL, in which it behaves as if always returning
134 | * MPV_ERROR_UNSUPPORTED.
135 | *
136 | * @param cookie opaque cookie identifying the stream,
137 | * returned from mpv_stream_cb_open_fn
138 | * @return the total size in bytes of the stream
139 | */
140 | typedef int64_t (*mpv_stream_cb_size_fn)(void *cookie);
141 |
142 | /**
143 | * Close callback used to implement a custom stream.
144 | *
145 | * @param cookie opaque cookie identifying the stream,
146 | * returned from mpv_stream_cb_open_fn
147 | */
148 | typedef void (*mpv_stream_cb_close_fn)(void *cookie);
149 |
150 | /**
151 | * Cancel callback used to implement a custom stream.
152 | *
153 | * This callback is used to interrupt any current or future read and seek
154 | * operations. It will be called from a separate thread than the demux
155 | * thread, and should not block.
156 | *
157 | * This callback can be NULL.
158 | *
159 | * Available since API 1.106.
160 | *
161 | * @param cookie opaque cookie identifying the stream,
162 | * returned from mpv_stream_cb_open_fn
163 | */
164 | typedef void (*mpv_stream_cb_cancel_fn)(void *cookie);
165 |
166 | /**
167 | * See mpv_stream_cb_open_ro_fn callback.
168 | */
169 | typedef struct mpv_stream_cb_info {
170 | /**
171 | * Opaque user-provided value, which will be passed to the other callbacks.
172 | * The close callback will be called to release the cookie. It is not
173 | * interpreted by mpv. It doesn't even need to be a valid pointer.
174 | *
175 | * The user sets this in the mpv_stream_cb_open_ro_fn callback.
176 | */
177 | void *cookie;
178 |
179 | /**
180 | * Callbacks set by the user in the mpv_stream_cb_open_ro_fn callback. Some
181 | * of them are optional, and can be left unset.
182 | *
183 | * The following callbacks are mandatory: read_fn, close_fn
184 | */
185 | mpv_stream_cb_read_fn read_fn;
186 | mpv_stream_cb_seek_fn seek_fn;
187 | mpv_stream_cb_size_fn size_fn;
188 | mpv_stream_cb_close_fn close_fn;
189 | mpv_stream_cb_cancel_fn cancel_fn; /* since API 1.106 */
190 | } mpv_stream_cb_info;
191 |
192 | /**
193 | * Open callback used to implement a custom read-only (ro) stream. The user
194 | * must set the callback fields in the passed info struct. The cookie field
195 | * also can be set to store state associated to the stream instance.
196 | *
197 | * Note that the info struct is valid only for the duration of this callback.
198 | * You can't change the callbacks or the pointer to the cookie at a later point.
199 | *
200 | * Each stream instance created by the open callback can have different
201 | * callbacks.
202 | *
203 | * The close_fn callback will terminate the stream instance. The pointers to
204 | * your callbacks and cookie will be discarded, and the callbacks will not be
205 | * called again.
206 | *
207 | * @param user_data opaque user data provided via mpv_stream_cb_add()
208 | * @param uri name of the stream to be opened (with protocol prefix)
209 | * @param info fields which the user should fill
210 | * @return 0 on success, MPV_ERROR_LOADING_FAILED if the URI cannot be opened.
211 | */
212 | typedef int (*mpv_stream_cb_open_ro_fn)(void *user_data, char *uri,
213 | mpv_stream_cb_info *info);
214 |
215 | /**
216 | * Add a custom stream protocol. This will register a protocol handler under
217 | * the given protocol prefix, and invoke the given callbacks if an URI with the
218 | * matching protocol prefix is opened.
219 | *
220 | * The "ro" is for read-only - only read-only streams can be registered with
221 | * this function.
222 | *
223 | * The callback remains registered until the mpv core is registered.
224 | *
225 | * If a custom stream with the same name is already registered, then the
226 | * MPV_ERROR_INVALID_PARAMETER error is returned.
227 | *
228 | * @param protocol protocol prefix, for example "foo" for "foo://" URIs
229 | * @param user_data opaque pointer passed into the mpv_stream_cb_open_fn
230 | * callback.
231 | * @return error code
232 | */
233 | int mpv_stream_cb_add_ro(mpv_handle *ctx, const char *protocol, void *user_data,
234 | mpv_stream_cb_open_ro_fn open_fn);
235 |
236 | #ifdef __cplusplus
237 | }
238 | #endif
239 |
240 | #endif
241 |
--------------------------------------------------------------------------------
/framework-meta/libmpv/Modules/module.modulemap:
--------------------------------------------------------------------------------
1 | framework module libmpv {
2 | umbrella "."
3 | export *
4 | }
5 |
--------------------------------------------------------------------------------
/patch.diff:
--------------------------------------------------------------------------------
1 | --- src/mpv-0.35.1/bootstrap.py
2 | +++ src/mpv-0.35.1/bootstrap.py
3 | @@ -5,10 +5,10 @@
4 | import os, sys, stat, hashlib, subprocess
5 | from urllib.request import urlopen, URLError
6 |
7 | -WAFRELEASE = "waf-2.0.24"
8 | +WAFRELEASE = "waf-2.0.15"
9 | WAFURLS = ["https://waf.io/" + WAFRELEASE,
10 | "https://www.freehackers.org/~tnagy/release/" + WAFRELEASE]
11 | -SHA256HASH = "93909bca823a675f9f40af7c65b24887c3a3c0efdf411ff1978ba827194bdeb0"
12 | +SHA256HASH = "34b8156ea375089e1bed5a31acfaff4024f6f3e96f3bee98f801f0c281ad3d2c"
13 |
14 | if os.path.exists("waf"):
15 | wafver = subprocess.check_output([sys.executable, './waf', '--version']).decode()
16 | --- src/mpv-0.35.1/wscript
17 | +++ src/mpv-0.35.1/wscript
18 | @@ -245,6 +245,12 @@ iconv support use --disable-iconv.",
19 | 'desc': 'w32/dos paths',
20 | 'deps': 'os-win32 || os-cygwin',
21 | 'func': check_true
22 | + }, {
23 | + 'name': 'posix-spawn',
24 | + 'desc': 'spawnp()/kill() POSIX support',
25 | + 'func': check_statement(['spawn.h', 'signal.h'],
26 | + 'posix_spawnp(0,0,0,0,0,0); kill(0,0)'),
27 | + 'deps': '!mingw && !tvos',
28 | }, {
29 | 'name': 'glob-posix',
30 | 'desc': 'glob() POSIX support',
31 | --- src/mpv-0.35.1/wscript_build.py
32 | +++ src/mpv-0.35.1/wscript_build.py
33 | @@ -209,7 +209,7 @@ def build(ctx):
34 | ])
35 |
36 | subprocess_c = ctx.pick_first_matching_dep([
37 | - ( "osdep/subprocess-posix.c", "posix" ),
38 | + ( "osdep/subprocess-posix.c", "posix-spawn" ),
39 | ( "osdep/subprocess-win.c", "win32-desktop" ),
40 | ( "osdep/subprocess-dummy.c" ),
41 | ])
42 | --- src/ffmpeg-6.0/libavfilter/metal/utils.m
43 | +++ src/ffmpeg-6.0/libavfilter/metal/utils.m
44 | @@ -31,7 +31,7 @@ void ff_metal_compute_encoder_dispatch(id device,
45 | BOOL fallback = YES;
46 | // MAC_OS_X_VERSION_10_15 is only defined on SDKs new enough to include its functionality (including iOS, tvOS, etc)
47 | #ifdef MAC_OS_X_VERSION_10_15
48 | - if (@available(macOS 10.15, iOS 11, tvOS 14.5, *)) {
49 | + if (@available(macOS 10.15, iOS 13, tvOS 14.5, *)) {
50 | if ([device supportsFamily:MTLGPUFamilyCommon3]) {
51 | MTLSize threadsPerGrid = MTLSizeMake(width, height, 1);
52 | [encoder dispatchThreads:threadsPerGrid threadsPerThreadgroup:threadsPerThreadgroup];
53 |
--------------------------------------------------------------------------------
/scripts/ffmpeg-build:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | set -e
3 |
4 | FFMPEG_OPTIONS="${COMMON_OPTIONS%% *} \
5 | --enable-cross-compile \
6 | --disable-lzma \
7 | --disable-sdl2 \
8 | --disable-debug \
9 | --disable-programs \
10 | --disable-doc \
11 | --disable-audiotoolbox \
12 | --enable-pic \
13 | --enable-shared \
14 | --enable-openssl \
15 | --disable-indev=avfoundation"
16 |
17 | if [[ "$ARCH" = "x86_64" ]]; then
18 | FFMPEG_OPTIONS="${FFMPEG_OPTIONS} \
19 | --disable-asm"
20 | fi
21 |
22 | if [[ ! `which gas-preprocessor.pl` ]]; then
23 | curl -L https://github.com/libav/gas-preprocessor/raw/master/gas-preprocessor.pl -o /usr/local/bin/gas-preprocessor.pl \
24 | && chmod +x /usr/local/bin/gas-preprocessor.pl
25 | fi
26 |
27 | if [[ "$ARCH" = "arm64" ]]; then
28 | EXPORT="GASPP_FIX_XCODE5=1"
29 | fi
30 |
31 | XCRUN_SDK=`echo $PLATFORM | tr '[:upper:]' '[:lower:]'`
32 | CC="xcrun -sdk $XCRUN_SDK clang"
33 |
34 | if [[ "$ARCH" = "arm64" ]]; then
35 | AS="gas-preprocessor.pl -arch aarch64 -- $CC"
36 | else
37 | AS="gas-preprocessor.pl -- $CC"
38 | fi
39 |
40 |
41 | $SRC/ffmpeg*/configure $FFMPEG_OPTIONS \
42 | --target-os=darwin \
43 | --arch=$ARCH \
44 | --cc="$CC" \
45 | --as="$AS" \
46 | --extra-cflags="$CFLAGS"
47 |
48 | make -j4 install $EXPORT
49 |
--------------------------------------------------------------------------------
/scripts/freetype-build:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | set -e
3 |
4 | $SRC/freetype*/configure $COMMON_OPTIONS \
5 | --with-zlib=yes \
6 | --without-png \
7 | --with-bzip2=no \
8 | --with-harfbuzz=no
9 | make install
--------------------------------------------------------------------------------
/scripts/fribidi-build:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | set -e
3 |
4 | $SRC/fribidi*/configure $COMMON_OPTIONS
5 | make install
--------------------------------------------------------------------------------
/scripts/harfbuzz-build:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | set -e
3 |
4 | $SRC/harfbuzz*/configure $COMMON_OPTIONS \
5 | --with-icu=no \
6 | --with-glib=no \
7 | --with-fontconfig=no \
8 | --with-coretext=no \
9 | --with-freetype=yes \
10 | --with-cairo=no
11 | make install
--------------------------------------------------------------------------------
/scripts/libass-build:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | set -e
3 |
4 | OPT="--disable-fontconfig \
5 | --disable-require-system-font-provider \
6 | --enable-directwrite"
7 |
8 | $SRC/libass*/configure $COMMON_OPTIONS $OPT
9 |
10 | make install
--------------------------------------------------------------------------------
/scripts/mpv-build:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | set -e
3 |
4 | OPTS="--prefix=$SCRATCH/$ARCH \
5 | --exec-prefix=$SCRATCH/$ARCH \
6 | --disable-cplayer \
7 | --disable-lcms2 \
8 | --disable-lua \
9 | --disable-rubberband \
10 | --disable-zimg \
11 | --enable-libmpv-static \
12 | --enable-ios-gl \
13 | --enable-gl \
14 | --disable-javascript \
15 | --disable-libbluray \
16 | --disable-vapoursynth \
17 | --enable-uchardet \
18 | --enable-lgpl"
19 |
20 | if [[ "$ENVIRONMENT" = "development" ]]; then
21 | OPTS="$OPTS --disable-optimize"
22 | fi
23 |
24 | cd $SRC/mpv*
25 | ./bootstrap.py
26 | ./waf configure $OPTS
27 | ./waf build -j4
--------------------------------------------------------------------------------
/scripts/uchardet-build:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | set -e
3 |
4 | PREFIX="${COMMON_OPTIONS%% *}"
5 | PREFIX="${PREFIX##*=}"
6 |
7 | UCHARDET_OPTIONS="-DCMAKE_INSTALL_PREFIX=$PREFIX -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=false -DCMAKE_OSX_SYSROOT=$SDKPATH"
8 |
9 | cmake $SRC/uchardet* $UCHARDET_OPTIONS && make
10 | make install
--------------------------------------------------------------------------------
/xcframework.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh -e
2 |
3 | LIBRARIES="libuchardet libfribidi libfreetype libharfbuzz libass libmpv libavcodec libavdevice libavfilter libavformat libavutil libswresample libswscale libcrypto libssl"
4 | PLATFORMS="ios tv"
5 | ROOT="$(pwd)"
6 | LIB="$ROOT/lib"
7 | mkdir -p $LIB
8 |
9 | for LIBRARY in $LIBRARIES; do
10 | FRAMEWORKS=""
11 | ENVIRONMENTS=""
12 | for PLATFORM in $PLATFORMS; do
13 | SCRATCH="$ROOT/scratch-$PLATFORM"
14 |
15 | if [ -d "$SCRATCH/x86_64-development" ] && [ -d "$SCRATCH/arm64-development" ]; then
16 | ENVIRONMENTS="$ENVIRONMENTS development"
17 | mkdir -p $SCRATCH/development/$LIBRARY.framework
18 | lipo -create $SCRATCH/x86_64-development/lib/$LIBRARY.a $SCRATCH/arm64-development/lib/$LIBRARY.a -o $SCRATCH/development/$LIBRARY.framework/$LIBRARY
19 | fi
20 |
21 | if [[ -d "$SCRATCH/arm64-distribution" ]]; then
22 | ENVIRONMENTS="$ENVIRONMENTS distribution"
23 | mkdir -p $SCRATCH/distribution/$LIBRARY.framework
24 | cp $SCRATCH/arm64-distribution/lib/$LIBRARY.a $SCRATCH/distribution/$LIBRARY.framework/$LIBRARY
25 | fi
26 |
27 | for ENVIRONMENT in $ENVIRONMENTS; do
28 | cp -a $ROOT/framework-meta/Info.plist $SCRATCH/$ENVIRONMENT/$LIBRARY.framework/Info.plist
29 | sed -i "" "s/{NAME}/$LIBRARY/g" $SCRATCH/$ENVIRONMENT/$LIBRARY.framework/Info.plist
30 | if [[ "$LIBRARY" = "libmpv" ]]; then
31 | cp -a $ROOT/framework-meta/libmpv/. $SCRATCH/$ENVIRONMENT/$LIBRARY.framework/
32 | fi
33 | FRAMEWORKS="$FRAMEWORKS -framework $SCRATCH/$ENVIRONMENT/$LIBRARY.framework"
34 | done
35 | done
36 | xcodebuild -create-xcframework $FRAMEWORKS -output $LIB/$LIBRARY.xcframework
37 | done
38 |
--------------------------------------------------------------------------------