History

client API, lua, ipc: unify event struct return

Both Lua and the JSON IPC code need to convert the mpv_event struct (and everything it points to) to Lua tables or JSON. I was getting sick of having to make the same changes to Lua and IPC. Do what has been done everywhere else, and let the core handle this by going through mpv_node (which is supposed to serve both Lua tables and JSON, and potentially other scripting language backends). Expose it as new libmpv API function. The new API is still a bit "rough" and support for other event types might be added in the future. This silently adds support for the playlist_entry_id fields to both Lua and JSON IPC. There is a small API change for Lua; I don't think this matters, so I didn't care about compatibility. The new code in client.c is mashed up from the Lua and the IPC code. The manpage additions are moved from the Lua docs, and made slightly more "general". Some danger for unintended regressions both in Lua and IPC. Also damn these node functions suck, expect crashes due to UB. Not sure why this became more code instead of less compared to before (according to the diff stat), even though some code duplication across Lua and IPC was removed. Software development sucks.

wm4 committed 6 years ago

Commit 218d6641 parent 7e885a39 files · +294 −259Browse files

Unified · Split

9 files
  1. DOCS/client-api-changes.rst +1 −0
  2. DOCS/interface-changes.rst +2 −0
  3. DOCS/man/input.rst +144 −0
  4. DOCS/man/lua.rst +1 −110
  5. input/ipc.c +9 −99
  6. libmpv/client.h +25 −0
  7. libmpv/mpv.def +1 −0
  8. player/client.c +100 −0
  9. player/lua.c +11 −50
DOCS/client-api-changes.rst+1−0
@@ -35,6 +35,7 @@ API changes · 34 unmodified lines
3535 --- mpv 0.33.0 ---
3636 1.108 - Deprecate MPV_EVENT_IDLE
3737 - add mpv_event_start_file, mpv_event_end_file.playlist_entry_id
38+ - add mpv_event_to_node()
3839 1.107 - Remove the deprecated qthelper.hpp. This was obviously not part of the
3940 libmpv API, only an "additionally" provided helper, thus this is not
4041 considered an API change. If you are maintaining a project that relies
DOCS/interface-changes.rst+2−0
@@ -54,6 +54,8 @@ Interface changes · 53 unmodified lines
5454 Using the "playlist-play-index" command is recommended instead.
5555 - add "playlist-play-index" command
5656 - add playlist-current-pos, playlist-playing-pos properties
57+ - Lua end-file events do not set the "error" field anymore, use "file_error"
58+ instead.
5759 --- mpv 0.32.0 ---
5860 - change behavior when using legacy option syntax with options that start
5961 with two dashes (``--`` instead of a ``-``). Now, using the recommended
DOCS/man/input.rst+144−0
@@ -1275,6 +1275,150 @@ Input Commands that are Possibly Subject to Change · 1274 unmodified lines
12751275
12761276 Undocumented commands: ``ao-reload`` (experimental/internal).
12771277
1278+List of events
1279+~~~~~~~~~~~~~~
1280+
1281+This is a partial list of events. This section describes what
1282+``mpv_event_to_node()`` returns, and which is what scripting APIs and the JSON
1283+IPC sees. Note that the C API has separate C-level declarations with
1284+``mpv_event``, which may be slightly different.
1285+
1286+All events can have the following fields:
1287+
1288+``event``
1289+ Name as the event (as returned by ``mpv_event_name()``).
1290+
1291+``error``
1292+ Set to an error string (as returned by ``mpv_error_string()``). This field
1293+ is missing if no error happened, or the event type does not report error.
1294+ Most events leave this unset.
1295+
1296+This list uses the event name field value, and the C API symbol in brackets:
1297+
1298+``start-file`` (``MPV_EVENT_START_FILE``)
1299+ Happens right before a new file is loaded. When you receive this, the
1300+ player is loading the file (or possibly already done with it).
1301+
1302+ This has the following fields:
1303+
1304+ ``playlist_entry_id``
1305+ Playlist entry ID of the file being loaded now.
1306+
1307+``end-file`` (``MPV_EVENT_END_FILE``)
1308+ Happens after a file was unloaded. Typically, the player will load the
1309+ next file right away, or quit if this was the last file.
1310+
1311+ The event has the following fields:
1312+
1313+ ``reason``
1314+ Has one of these values:
1315+
1316+ ``eof``
1317+ The file has ended. This can (but doesn't have to) include
1318+ incomplete files or broken network connections under
1319+ circumstances.
1320+
1321+ ``stop``
1322+ Playback was ended by a command.
1323+
1324+ ``quit``
1325+ Playback was ended by sending the quit command.
1326+
1327+ ``error``
1328+ An error happened. In this case, an ``error`` field is present with
1329+ the error string.
1330+
1331+ ``redirect``
1332+ Happens with playlists and similar. Details see
1333+ ``MPV_END_FILE_REASON_REDIRECT`` in the C API.
1334+
1335+ ``unknown``
1336+ Unknown. Normally doesn't happen, unless the Lua API is out of sync
1337+ with the C API. (Likewise, it could happen that your script gets
1338+ reason strings that did not exist yet at the time your script was
1339+ written.)
1340+
1341+ ``playlist_entry_id``
1342+ Playlist entry ID of the file that was being played or attempted to be
1343+ played. This has the same value as the ``playlist_entry_id`` field in the
1344+ corresponding ``start-file`` event.
1345+
1346+ ``file_error``
1347+ Set to mpv error string describing the approximate reason why playback
1348+ failed. Unset if no error known. (In Lua scripting, this value was set
1349+ on the ``error`` field directly before mpv 0.33.0. Now the ``error``
1350+ field always indicates success, i.e. is not set.)
1351+
1352+``file-loaded`` (``MPV_EVENT_FILE_LOADED``)
1353+ Happens after a file was loaded and begins playback.
1354+
1355+``seek`` (``MPV_EVENT_SEEK``)
1356+ Happens on seeking. (This might include cases when the player seeks
1357+ internally, even without user interaction. This includes e.g. segment
1358+ changes when playing ordered chapters Matroska files.)
1359+
1360+``playback-restart`` (``MPV_EVENT_PLAYBACK_RESTART``)
1361+ Start of playback after seek or after file was loaded.
1362+
1363+``shutdown`` (``MPV_EVENT_SHUTDOWN``)
1364+ Sent when the player quits, and the script should terminate. Normally
1365+ handled automatically. See `Details on the script initialization and lifecycle`_.
1366+
1367+``log-message`` (``MPV_EVENT_LOG_MESSAGE``)
1368+ Receives messages enabled with ``mpv_request_log_messages()`` (Lua:
1369+ ``mp.enable_messages``).
1370+
1371+ This contains, in addition to the default event fields, the following
1372+ fields:
1373+
1374+ ``prefix``
1375+ The module prefix, identifies the sender of the message. This is what
1376+ the terminal player puts in front of the message text when using the
1377+ ``--v`` option, and is also what is used for ``--msg-level``.
1378+
1379+ ``level``
1380+ The log level as string. See ``msg.log`` for possible log level names.
1381+ Note that later versions of mpv might add new levels or remove
1382+ (undocumented) existing ones.
1383+
1384+ ``text``
1385+ The log message. The text will end with a newline character. Sometimes
1386+ it can contain multiple lines.
1387+
1388+ Keep in mind that these messages are meant to be hints for humans. You
1389+ should not parse them, and prefix/level/text of messages might change
1390+ any time.
1391+
1392+``hook``
1393+ The event has the following fields:
1394+
1395+ ``hook_id``
1396+ ID to pass to ``mpv_hook_continue()``. The Lua scripting wrapper
1397+ provides a better API around this with ``mp.add_hook()``.
1398+
1399+``get-property-reply`` (``MPV_EVENT_GET_PROPERTY_REPLY``)
1400+ Undocumented.
1401+
1402+``set-property-reply`` (``MPV_EVENT_SET_PROPERTY_REPLY``)
1403+ Undocumented.
1404+
1405+``command-reply`` (``MPV_EVENT_COMMAND_REPLY``)
1406+ Undocumented.
1407+
1408+``client-message`` (``MPV_EVENT_CLIENT_MESSAGE``)
1409+ Undocumented.
1410+
1411+``video-reconfig`` (``MPV_EVENT_VIDEO_RECONFIG``)
1412+ Happens on video output or filter reconfig.
1413+
1414+``audio-reconfig`` (``MPV_EVENT_AUDIO_RECONFIG``)
1415+ Happens on audio output or filter reconfig.
1416+
1417+The following events also happen, but are deprecated: ``tracks-changed``,
1418+``track-switched``, ``pause``, ``unpause``, ``metadata-update``, ``idle``,
1419+``tick``, ``chapter-change``. Use ``mpv_observe_property()``
1420+(Lua: ``mp.observe_property()``) instead.
1421+
12781422 Hooks
12791423 ~~~~~
12801424
DOCS/man/lua.rst+1−110
@@ -871,116 +871,7 @@ Example: · 870 unmodified lines
871871
872872 mp.register_event("file-loaded", my_fn)
873873
874−
875−
876−List of events
877−--------------
878−
879−``start-file``
880− Happens right before a new file is loaded. When you receive this, the
881− player is loading the file (or possibly already done with it).
882−
883−``end-file``
884− Happens after a file was unloaded. Typically, the player will load the
885− next file right away, or quit if this was the last file.
886−
887− The event has the ``reason`` field, which takes one of these values:
888−
889− ``eof``
890− The file has ended. This can (but doesn't have to) include
891− incomplete files or broken network connections under
892− circumstances.
893−
894− ``stop``
895− Playback was ended by a command.
896−
897− ``quit``
898− Playback was ended by sending the quit command.
899−
900− ``error``
901− An error happened. In this case, an ``error`` field is present with
902− the error string.
903−
904− ``redirect``
905− Happens with playlists and similar. Details see
906− ``MPV_END_FILE_REASON_REDIRECT`` in the C API.
907−
908− ``unknown``
909− Unknown. Normally doesn't happen, unless the Lua API is out of sync
910− with the C API. (Likewise, it could happen that your script gets
911− reason strings that did not exist yet at the time your script was
912− written.)
913−
914−``file-loaded``
915− Happens after a file was loaded and begins playback.
916−
917−``seek``
918− Happens on seeking. (This might include cases when the player seeks
919− internally, even without user interaction. This includes e.g. segment
920− changes when playing ordered chapters Matroska files.)
921−
922−``playback-restart``
923− Start of playback after seek or after file was loaded.
924−
925−``idle``
926− Idle mode is entered. This happens when playback ended, and the player was
927− started with ``--idle`` or ``--force-window``. This mode is implicitly ended
928− when the ``start-file`` or ``shutdown`` events happen.
929−
930−``tick``
931− Called after a video frame was displayed. This is a hack, and you should
932− avoid using it. Use timers instead and maybe watch pausing/unpausing events
933− to avoid wasting CPU when the player is paused. This is deprecated.
934−
935−``shutdown``
936− Sent when the player quits, and the script should terminate. Normally
937− handled automatically. See `Details on the script initialization and lifecycle`_.
938−
939−``log-message``
940− Receives messages enabled with ``mp.enable_messages``. The message data
941− is contained in the table passed as first parameter to the event handler.
942− The table contains, in addition to the default event fields, the following
943− fields:
944−
945− ``prefix``
946− The module prefix, identifies the sender of the message. This is what
947− the terminal player puts in front of the message text when using the
948− ``--v`` option, and is also what is used for ``--msg-level``.
949−
950− ``level``
951− The log level as string. See ``msg.log`` for possible log level names.
952− Note that later versions of mpv might add new levels or remove
953− (undocumented) existing ones.
954−
955− ``text``
956− The log message. The text will end with a newline character. Sometimes
957− it can contain multiple lines.
958−
959− Keep in mind that these messages are meant to be hints for humans. You
960− should not parse them, and prefix/level/text of messages might change
961− any time.
962−
963−``get-property-reply``
964− Undocumented (not useful for Lua scripts).
965−
966−``set-property-reply``
967− Undocumented (not useful for Lua scripts).
968−
969−``command-reply``
970− Undocumented (not useful for Lua scripts).
971−
972−``client-message``
973− Undocumented (used internally).
974−
975−``video-reconfig``
976− Happens on video output or filter reconfig.
977−
978−``audio-reconfig``
979− Happens on audio output or filter reconfig.
980−
981−The following events also happen, but are deprecated: ``tracks-changed``,
982−``track-switched``, ``pause``, ``unpause``, ``metadata-update``,
983−``chapter-change``. Use ``mp.observe_property()`` instead.
874+For the existing event types, see `List of events`_.
984875
985876 Extras
986877 ------
input/ipc.c+9−99
@@ -37,28 +37,6 @@ static mpv_node *mpv_node_array_get(mpv_node *src, int index) · 36 unmodified lines
3737 return &src->u.list->values[index];
3838 }
3939
40−static void mpv_node_array_add(void *ta_parent, mpv_node *src, mpv_node *val)
41−{
42− if (src->format != MPV_FORMAT_NODE_ARRAY)
43− return;
44−
45− if (!src->u.list)
46− src->u.list = talloc_zero(ta_parent, mpv_node_list);
47−
48− MP_TARRAY_GROW(src->u.list, src->u.list->values, src->u.list->num);
49−
50− static const struct m_option type = { .type = CONF_TYPE_NODE };
51− m_option_get_node(&type, ta_parent, &src->u.list->values[src->u.list->num], val);
52−
53− src->u.list->num++;
54−}
55−
56−static void mpv_node_array_add_string(void *ta_parent, mpv_node *src, const char *val)
57−{
58− mpv_node val_node = {.format = MPV_FORMAT_STRING, .u.string = (char *)val};
59− mpv_node_array_add(ta_parent, src, &val_node);
60−}
61−
6240 static void mpv_node_map_add(void *ta_parent, mpv_node *src, const char *key, mpv_node *val)
6341 {
6442 if (src->format != MPV_FORMAT_NODE_MAP)
@@ -84,25 +62,12 @@ static void mpv_node_map_add_null(void *ta_parent, mpv_node *src, const char *ke · 19 unmodified lines
8462 mpv_node_map_add(ta_parent, src, key, &val_node);
8563 }
8664
87−static void mpv_node_map_add_flag(void *ta_parent, mpv_node *src, const char *key, bool val)
88−{
89− mpv_node val_node = {.format = MPV_FORMAT_FLAG, .u.flag = val};
90−
91− mpv_node_map_add(ta_parent, src, key, &val_node);
92−}
93−
9465 static void mpv_node_map_add_int64(void *ta_parent, mpv_node *src, const char *key, int64_t val)
9566 {
9667 mpv_node val_node = {.format = MPV_FORMAT_INT64, .u.int64 = val};
9768 mpv_node_map_add(ta_parent, src, key, &val_node);
9869 }
9970
100−static void mpv_node_map_add_double(void *ta_parent, mpv_node *src, const char *key, double val)
101−{
102− mpv_node val_node = {.format = MPV_FORMAT_DOUBLE, .u.double_ = val};
103− mpv_node_map_add(ta_parent, src, key, &val_node);
104−}
105−
10671 static void mpv_node_map_add_string(void *ta_parent, mpv_node *src, const char *key, const char *val)
10772 {
10873 mpv_node val_node = {.format = MPV_FORMAT_STRING, .u.string = (char*)val};
@@ -124,74 +89,19 @@ static void mpv_format_command_reply(void *ta_parent, mpv_event *event, · 15 unmodified lines
12489 mpv_node_map_add(ta_parent, dst, "data", &cmd->result);
12590 }
12691
127−static void mpv_event_to_node(void *ta_parent, mpv_event *event, mpv_node *dst)
128−{
129− if (event->event_id == MPV_EVENT_COMMAND_REPLY) {
130− mpv_format_command_reply(ta_parent, event, dst);
131− return;
132− }
133−
134− mpv_node_map_add_string(ta_parent, dst, "event", mpv_event_name(event->event_id));
135−
136− if (event->reply_userdata)
137− mpv_node_map_add_int64(ta_parent, dst, "id", event->reply_userdata);
138−
139− if (event->error < 0)
140− mpv_node_map_add_string(ta_parent, dst, "error", mpv_error_string(event->error));
141−
142− switch (event->event_id) {
143− case MPV_EVENT_LOG_MESSAGE: {
144− mpv_event_log_message *msg = event->data;
145−
146− mpv_node_map_add_string(ta_parent, dst, "prefix", msg->prefix);
147− mpv_node_map_add_string(ta_parent, dst, "level", msg->level);
148− mpv_node_map_add_string(ta_parent, dst, "text", msg->text);
149−
150− break;
151− }
152−
153− case MPV_EVENT_CLIENT_MESSAGE: {
154− mpv_event_client_message *msg = event->data;
155−
156− mpv_node args_node = {.format = MPV_FORMAT_NODE_ARRAY, .u.list = NULL};
157− for (int n = 0; n < msg->num_args; n++)
158− mpv_node_array_add_string(ta_parent, &args_node, msg->args[n]);
159− mpv_node_map_add(ta_parent, dst, "args", &args_node);
160− break;
161− }
162−
163− case MPV_EVENT_PROPERTY_CHANGE: {
164− mpv_event_property *prop = event->data;
165−
166− mpv_node_map_add_string(ta_parent, dst, "name", prop->name);
167−
168− switch (prop->format) {
169− case MPV_FORMAT_NODE:
170− mpv_node_map_add(ta_parent, dst, "data", prop->data);
171− break;
172− case MPV_FORMAT_DOUBLE:
173− mpv_node_map_add_double(ta_parent, dst, "data", *(double *)prop->data);
174− break;
175− case MPV_FORMAT_FLAG:
176− mpv_node_map_add_flag(ta_parent, dst, "data", *(int *)prop->data);
177− break;
178− case MPV_FORMAT_STRING:
179− mpv_node_map_add_string(ta_parent, dst, "data", *(char **)prop->data);
180− break;
181− default:
182− mpv_node_map_add_null(ta_parent, dst, "data");
183− }
184− break;
185− }
186− }
187−}
188−
18992 char *mp_json_encode_event(mpv_event *event)
19093 {
19194 void *ta_parent = talloc_new(NULL);
192− mpv_node event_node = {.format = MPV_FORMAT_NODE_MAP, .u.list = NULL};
19395
194− mpv_event_to_node(ta_parent, event, &event_node);
96+ struct mpv_node event_node;
97+ if (event->event_id == MPV_EVENT_COMMAND_REPLY) {
98+ event_node = (mpv_node){.format = MPV_FORMAT_NODE_MAP, .u.list = NULL};
99+ mpv_format_command_reply(ta_parent, event, &event_node);
100+ } else {
101+ mpv_event_to_node(&event_node, event);
102+ // Abuse mpv_event_to_node() internals.
103+ talloc_steal(ta_parent, node_get_alloc(&event_node));
104+ }
195105
196106 char *output = talloc_strdup(NULL, "");
197107 json_write(&output, &event_node);
libmpv/client.h+25−0
@@ -1717,6 +1717,31 @@ typedef struct mpv_event { · 1716 unmodified lines
17171717 void *data;
17181718 } mpv_event;
17191719
1720+/**
1721+ * Convert the given src event to a mpv_node, and set *dst to the result. *dst
1722+ * is set to a MPV_FORMAT_NODE_MAP, with fields for corresponding mpv_event and
1723+ * mpv_event.data/mpv_event_* fields.
1724+ *
1725+ * The exact details are not completely documented out of laziness. A start
1726+ * is located in the "Events" section of the manpage.
1727+ *
1728+ * *dst may point to newly allocated memory, or pointers in mpv_event. You must
1729+ * copy the entire mpv_node if you want to reference it after mpv_event becomes
1730+ * invalid (such as making a new mpv_wait_event() call, or destroying the
1731+ * mpv_handle from which it was returned). Call mpv_free_node_contents() to free
1732+ * any memory allocations made by this API function.
1733+ *
1734+ * Safe to be called from mpv render API threads.
1735+ *
1736+ * @param dst Target. This is not read and fully overwritten. Must be released
1737+ * with mpv_free_node_contents(). Do not write to pointers returned
1738+ * by it. (On error, this may be left as an empty node.)
1739+ * @param src The source event. Not modified (it's not const due to the author's
1740+ * prejudice of the C version of const).
1741+ * @return error code (MPV_ERROR_NOMEM only, if at all)
1742+ */
1743+int mpv_event_to_node(mpv_node *dst, mpv_event *src);
1744+
17201745 /**
17211746 * Enable or disable the given event.
17221747 *
libmpv/mpv.def+1−0
@@ -13,6 +13,7 @@ mpv_create_weak_client · 12 unmodified lines
1313 mpv_destroy
1414 mpv_detach_destroy
1515 mpv_error_string
16+mpv_event_to_node
1617 mpv_event_name
1718 mpv_free
1819 mpv_free_node_contents
player/client.c+100−0
@@ -676,6 +676,9 @@ static void dup_event_data(struct mpv_event *ev) · 675 unmodified lines
676676 ev->data = msg;
677677 break;
678678 }
679+ case MPV_EVENT_START_FILE:
680+ ev->data = talloc_memdup(NULL, ev->data, sizeof(mpv_event_start_file));
681+ break;
679682 case MPV_EVENT_END_FILE:
680683 ev->data = talloc_memdup(NULL, ev->data, sizeof(mpv_event_end_file));
681684 break;
@@ -1910,6 +1913,103 @@ unsigned long mpv_client_api_version(void) · 1228 unmodified lines
19101913 return MPV_CLIENT_API_VERSION;
19111914 }
19121915
1916+int mpv_event_to_node(mpv_node *dst, mpv_event *event)
1917+{
1918+ *dst = (mpv_node){0};
1919+
1920+ node_init(dst, MPV_FORMAT_NODE_MAP, NULL);
1921+ node_map_add_string(dst, "event", mpv_event_name(event->event_id));
1922+
1923+ if (event->error < 0)
1924+ node_map_add_string(dst, "error", mpv_error_string(event->error));
1925+
1926+ switch (event->event_id) {
1927+
1928+ case MPV_EVENT_START_FILE: {
1929+ mpv_event_start_file *esf = event->data;
1930+
1931+ node_map_add_int64(dst, "playlist_entry_id", esf->playlist_entry_id);
1932+ break;
1933+ }
1934+
1935+ case MPV_EVENT_END_FILE: {
1936+ mpv_event_end_file *eef = event->data;
1937+
1938+ const char *reason;
1939+ switch (eef->reason) {
1940+ case MPV_END_FILE_REASON_EOF: reason = "eof"; break;
1941+ case MPV_END_FILE_REASON_STOP: reason = "stop"; break;
1942+ case MPV_END_FILE_REASON_QUIT: reason = "quit"; break;
1943+ case MPV_END_FILE_REASON_ERROR: reason = "error"; break;
1944+ case MPV_END_FILE_REASON_REDIRECT: reason = "redirect"; break;
1945+ default:
1946+ reason = "unknown";
1947+ }
1948+ node_map_add_string(dst, "reason", reason);
1949+
1950+ node_map_add_int64(dst, "playlist_entry_id", eef->playlist_entry_id);
1951+
1952+ if (eef->reason == MPV_END_FILE_REASON_ERROR)
1953+ node_map_add_string(dst, "file_error", mpv_error_string(eef->error));
1954+ break;
1955+ }
1956+
1957+ case MPV_EVENT_LOG_MESSAGE: {
1958+ mpv_event_log_message *msg = event->data;
1959+
1960+ node_map_add_string(dst, "prefix", msg->prefix);
1961+ node_map_add_string(dst, "level", msg->level);
1962+ node_map_add_string(dst, "text", msg->text);
1963+ break;
1964+ }
1965+
1966+ case MPV_EVENT_CLIENT_MESSAGE: {
1967+ mpv_event_client_message *msg = event->data;
1968+
1969+ struct mpv_node *args = node_map_add(dst, "args", MPV_FORMAT_NODE_ARRAY);
1970+ for (int n = 0; n < msg->num_args; n++) {
1971+ struct mpv_node *sn = node_array_add(args, MPV_FORMAT_NONE);
1972+ sn->format = MPV_FORMAT_STRING;
1973+ sn->u.string = (char *)msg->args[n];
1974+ }
1975+ break;
1976+ }
1977+
1978+ case MPV_EVENT_PROPERTY_CHANGE: {
1979+ mpv_event_property *prop = event->data;
1980+
1981+ node_map_add_string(dst, "name", prop->name);
1982+
1983+ switch (prop->format) {
1984+ case MPV_FORMAT_NODE:
1985+ *node_map_add(dst, "data", MPV_FORMAT_NONE) =
1986+ *(struct mpv_node *)prop->data;
1987+ break;
1988+ case MPV_FORMAT_DOUBLE:
1989+ node_map_add_double(dst, "data", *(double *)prop->data);
1990+ break;
1991+ case MPV_FORMAT_FLAG:
1992+ node_map_add_flag(dst, "data", *(int *)prop->data);
1993+ break;
1994+ case MPV_FORMAT_STRING:
1995+ node_map_add_string(dst, "data", *(char **)prop->data);
1996+ break;
1997+ default: ;
1998+ }
1999+ break;
2000+ }
2001+
2002+ case MPV_EVENT_HOOK: {
2003+ mpv_event_hook *hook = event->data;
2004+
2005+ node_map_add_int64(dst, "hook_id", hook->id);
2006+ break;
2007+ }
2008+
2009+ }
2010+ return 0;
2011+}
2012+
19132013 static const char *const err_table[] = {
19142014 [-MPV_ERROR_SUCCESS] = "success",
19152015 [-MPV_ERROR_EVENT_QUEUE_FULL] = "event queue full",
player/lua.c+11−50
@@ -519,50 +519,6 @@ static int script_wait_event(lua_State *L) · 518 unmodified lines
519519 }
520520
521521 switch (event->event_id) {
522− case MPV_EVENT_LOG_MESSAGE: {
523− mpv_event_log_message *msg = event->data;
524−
525− lua_pushstring(L, msg->prefix); // event s
526− lua_setfield(L, -2, "prefix"); // event
527− lua_pushstring(L, msg->level); // event s
528− lua_setfield(L, -2, "level"); // event
529− lua_pushstring(L, msg->text); // event s
530− lua_setfield(L, -2, "text"); // event
531− break;
532− }
533− case MPV_EVENT_CLIENT_MESSAGE: {
534− mpv_event_client_message *msg = event->data;
535−
536− lua_newtable(L); // event args
537− for (int n = 0; n < msg->num_args; n++) {
538− lua_pushinteger(L, n + 1); // event args N
539− lua_pushstring(L, msg->args[n]); // event args N val
540− lua_settable(L, -3); // event args
541− }
542− lua_setfield(L, -2, "args"); // event
543− break;
544− }
545− case MPV_EVENT_END_FILE: {
546− mpv_event_end_file *eef = event->data;
547− const char *reason;
548− switch (eef->reason) {
549− case MPV_END_FILE_REASON_EOF: reason = "eof"; break;
550− case MPV_END_FILE_REASON_STOP: reason = "stop"; break;
551− case MPV_END_FILE_REASON_QUIT: reason = "quit"; break;
552− case MPV_END_FILE_REASON_ERROR: reason = "error"; break;
553− case MPV_END_FILE_REASON_REDIRECT: reason = "redirect"; break;
554− default:
555− reason = "unknown";
556− }
557− lua_pushstring(L, reason); // event reason
558− lua_setfield(L, -2, "reason"); // event
559−
560− if (eef->reason == MPV_END_FILE_REASON_ERROR) {
561− lua_pushstring(L, mpv_error_string(eef->error)); // event error
562− lua_setfield(L, -2, "error"); // event
563− }
564− break;
565− }
566522 case MPV_EVENT_PROPERTY_CHANGE: {
567523 mpv_event_property *prop = event->data;
568524 lua_pushstring(L, prop->name);
@@ -586,12 +542,6 @@ static int script_wait_event(lua_State *L) · 17 unmodified lines
586542 lua_setfield(L, -2, "data");
587543 break;
588544 }
589− case MPV_EVENT_HOOK: {
590− mpv_event_hook *hook = event->data;
591− lua_pushinteger(L, hook->id);
592− lua_setfield(L, -2, "hook_id");
593− break;
594− }
595545 case MPV_EVENT_COMMAND_REPLY: {
596546 mpv_event_command *cmd = event->data;
597547 pushnode(L, &cmd->result);
@@ -599,6 +549,17 @@ static int script_wait_event(lua_State *L) · 1 unmodified line
599549 break;
600550 }
601551 default: ;
552+ struct mpv_node rn;
553+ mpv_event_to_node(&rn, event);
554+
555+ assert(rn.format == MPV_FORMAT_NODE_MAP);
556+ mpv_node_list *list = rn.u.list;
557+ for (int n = 0; n < list->num; n++) {
558+ pushnode(L, &list->values[n]);
559+ lua_setfield(L, -2, list->keys[n]);
560+ }
561+
562+ mpv_free_node_contents(&rn);
602563 }
603564
604565 // return event

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t