Skip to content

Commit bd9b474

Browse files
committed
ipc: add 'msg' JSON IPC command
1 parent 3fb164c commit bd9b474

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

DOCS/man/ipc.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,20 @@ extra commands can also be used as part of the protocol:
316316
lead to breakages with future mpv releases. Instead, make a feature request,
317317
and ask for a proper event that returns the information you need.
318318

319+
``msg``
320+
Write a log message using the client's log instance. The first parameter to
321+
this command is the log-level and must be one of the log levels accepted by
322+
the ``mp.msg.log`` Lua function. The parameters after must all be strings.
323+
Spaces are inserted to separate multiple parameters. A newline is added to
324+
the end.
325+
326+
Example:
327+
328+
::
329+
330+
{ "command": ["msg", "error", "hello", "from", "IPC", "client!"] }
331+
{ "error": "success" }
332+
319333
``enable_event``, ``disable_event``
320334
Enables or disables the named event. Mirrors the ``mpv_request_event`` C
321335
API function. If the string ``all`` is used instead of an event name, all

input/ipc.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <mpv/client.h>
1919

2020
#include "common/msg.h"
21+
#include "common/msg_control.h"
2122
#include "input/input.h"
2223
#include "misc/json.h"
2324
#include "misc/node.h"
@@ -343,6 +344,30 @@ static char *json_execute_command(struct mpv_handle *client, void *ta_parent,
343344
}
344345
rc = mpv_request_event(client, event, enable);
345346
}
347+
} else if (cmd && !strcmp("msg", cmd)) {
348+
if (cmd_node->u.list->num < 3) {
349+
rc = MPV_ERROR_INVALID_PARAMETER;
350+
goto error;
351+
}
352+
353+
for (int i = 1; i < cmd_node->u.list->num; i++) {
354+
if (cmd_node->u.list->values[i].format != MPV_FORMAT_STRING) {
355+
rc = MPV_ERROR_INVALID_PARAMETER;
356+
goto error;
357+
}
358+
}
359+
360+
int level = mp_msg_find_level(cmd_node->u.list->values[1].u.string);
361+
if (level < 0) {
362+
rc = MPV_ERROR_INVALID_PARAMETER;
363+
goto error;
364+
}
365+
366+
for (int i = 2; i < cmd_node->u.list->num; i++) {
367+
mp_msg(log, level, (i == 2 ? "%s" : " %s"),
368+
cmd_node->u.list->values[i].u.string);
369+
}
370+
mp_msg(log, level, "\n");
346371
} else {
347372
mpv_node result_node = {0};
348373

0 commit comments

Comments
 (0)