Set a custom function that should be called when there are new events. Use
this if blocking in mpv_wait_event() to wait for new events is not feasible.
Keep in mind that the callback will be called from foreign threads. You
must not make any assumptions of the environment, and you must return as
soon as possible (i.e. no long blocking waits). Exiting the callback through
any other means than a normal return is forbidden (no throwing exceptions,
no longjmp() calls). You must not change any local thread state (such as
the C floating point environment).
You are not allowed to call any client API functions inside of the callback.
In particular, you should not do any processing in the callback, but wake up
another thread that does all the work. The callback is meant strictly for
notification only, and is called from arbitrary core parts of the player,
that make no considerations for reentrant API use or allowing the callee to
spend a lot of time doing other things. Keep in mind that it's also possible
that the callback is called from a thread while a mpv API function is called
(i.e. it can be reentrant).
In general, the client API expects you to call mpv_wait_event() to receive
notifications, and the wakeup callback is merely a helper utility to make
this easier in certain situations. Note that it's possible that there's
only one wakeup callback invocation for multiple events. You should call
mpv_wait_event() with no timeout until MPV_EVENT_NONE is reached, at which
point the event queue is empty.
If you actually want to do processing in a callback, spawn a thread that
does nothing but call mpv_wait_event() in a loop and dispatches the result
to a callback.
Only one wakeup callback can be set.
@param cb function that should be called if a wakeup is required
@param d arbitrary userdata passed to cb
Set a custom function that should be called when there are new events. Use this if blocking in mpv_wait_event() to wait for new events is not feasible.
Keep in mind that the callback will be called from foreign threads. You must not make any assumptions of the environment, and you must return as soon as possible (i.e. no long blocking waits). Exiting the callback through any other means than a normal return is forbidden (no throwing exceptions, no longjmp() calls). You must not change any local thread state (such as the C floating point environment).
You are not allowed to call any client API functions inside of the callback. In particular, you should not do any processing in the callback, but wake up another thread that does all the work. The callback is meant strictly for notification only, and is called from arbitrary core parts of the player, that make no considerations for reentrant API use or allowing the callee to spend a lot of time doing other things. Keep in mind that it's also possible that the callback is called from a thread while a mpv API function is called (i.e. it can be reentrant).
In general, the client API expects you to call mpv_wait_event() to receive notifications, and the wakeup callback is merely a helper utility to make this easier in certain situations. Note that it's possible that there's only one wakeup callback invocation for multiple events. You should call mpv_wait_event() with no timeout until MPV_EVENT_NONE is reached, at which point the event queue is empty.
If you actually want to do processing in a callback, spawn a thread that does nothing but call mpv_wait_event() in a loop and dispatches the result to a callback.
Only one wakeup callback can be set.
@param cb function that should be called if a wakeup is required @param d arbitrary userdata passed to cb