command: allow using ASS tags on OSD messages

We don't allow this by default, because it would be silly if random
external data (like filenames or file tags) could accidentally trigger
them.

Add a property that magically disables this ASS tag escaping.

Note that malicious input could still disable ASS tag escaping by
itself. This would be annoying but harmless.
This commit is contained in:
wm4
2014-09-18 00:49:55 +02:00
parent a522441bbe
commit 6c3d25e6f5
5 changed files with 48 additions and 4 deletions

View File

@@ -1298,8 +1298,25 @@ Property list
``osd-sym-cc`` ``osd-sym-cc``
Inserts the current OSD symbol as opaque OSD control code (cc). This makes Inserts the current OSD symbol as opaque OSD control code (cc). This makes
sense with the ``show_text`` command only. The control code is sense only with the ``show_text`` command or options which set OSD messages.
implementation specific and is useless for any other use. The control code is implementation specific and is useless for anything else.
``osd-ass-cc``
``${osd-ass-cc/0}`` disables escaping ASS sequences of text in OSD,
``${osd-ass-cc/1}`` enables it again. By default, ASS sequences are
escaped to avoid accidental formatting, and this property can disable
this behavior. Note that the properties return an opaque OSD control
code, which only makes sense for the ``show_text`` command or options
which set OSD messages.
.. admonition:: Example
--osd-status-msg='This is ${osd-ass-cc/0}{\\b1}bold text'
Any ASS override tags as understood by libass can be used.
Note that you need to escape the ``\`` character, because the string is
processed for C escape sequences before passing it to the OSD code.
``options/<name>`` (RW) ``options/<name>`` (RW)
Read-only access to value of option ``--<name>``. Most options can be Read-only access to value of option ``--<name>``. Most options can be

View File

@@ -2229,6 +2229,17 @@ static int mp_property_osd_sym(void *ctx, struct m_property *prop,
return m_property_strdup_ro(action, arg, temp); return m_property_strdup_ro(action, arg, temp);
} }
static int mp_property_osd_ass(void *ctx, struct m_property *prop,
int action, void *arg)
{
struct m_sub_property props[] = {
{"0", SUB_PROP_STR(osd_ass_0)},
{"1", SUB_PROP_STR(osd_ass_1)},
{0}
};
return m_property_read_sub(props, action, arg);
}
/// Video fps (RO) /// Video fps (RO)
static int mp_property_fps(void *ctx, struct m_property *prop, static int mp_property_fps(void *ctx, struct m_property *prop,
int action, void *arg) int action, void *arg)
@@ -2816,6 +2827,7 @@ static const struct m_property mp_properties[] = {
{"osd-par", mp_property_osd_par}, {"osd-par", mp_property_osd_par},
{"osd-sym-cc", mp_property_osd_sym}, {"osd-sym-cc", mp_property_osd_sym},
{"osd-ass-cc", mp_property_osd_ass},
// Subs // Subs
{"sid", mp_property_sub}, {"sid", mp_property_sub},

View File

@@ -219,6 +219,8 @@ void osd_destroy_backend(struct osd_state *osd);
// doesn't need locking // doesn't need locking
void osd_get_function_sym(char *buffer, size_t buffer_size, int osd_function); void osd_get_function_sym(char *buffer, size_t buffer_size, int osd_function);
extern const char *osd_ass_0;
extern const char *osd_ass_1;
// defined in backend, but locks if required // defined in backend, but locks if required
void osd_object_get_resolution(struct osd_state *osd, int obj, void osd_object_get_resolution(struct osd_state *osd, int obj,

View File

@@ -6,6 +6,9 @@
#include "talloc.h" #include "talloc.h"
#include "osd.h" #include "osd.h"
const char *osd_ass_0 = "";
const char *osd_ass_1 = "";
void osd_init_backend(struct osd_state *osd) void osd_init_backend(struct osd_state *osd)
{ {
} }

View File

@@ -159,8 +159,13 @@ void osd_get_function_sym(char *buffer, size_t buffer_size, int osd_function)
snprintf(buffer, buffer_size, "\xFF%c", osd_function); snprintf(buffer, buffer_size, "\xFF%c", osd_function);
} }
// Same trick as above: never valid UTF-8, so we expect it's free for use.
const char *osd_ass_0 = "\xFD";
const char *osd_ass_1 = "\xFE";
static void mangle_ass(bstr *dst, const char *in) static void mangle_ass(bstr *dst, const char *in)
{ {
bool escape_ass = true;
while (*in) { while (*in) {
// As used by osd_get_function_sym(). // As used by osd_get_function_sym().
if (in[0] == '\xFF' && in[1]) { if (in[0] == '\xFF' && in[1]) {
@@ -170,11 +175,16 @@ static void mangle_ass(bstr *dst, const char *in)
in += 2; in += 2;
continue; continue;
} }
if (*in == '{') if (*in == '\xFD' || *in == '\xFE') {
escape_ass = *in == '\xFE';
in += 1;
continue;
}
if (escape_ass && *in == '{')
bstr_xappend(NULL, dst, bstr0("\\")); bstr_xappend(NULL, dst, bstr0("\\"));
bstr_xappend(NULL, dst, (bstr){(char *)in, 1}); bstr_xappend(NULL, dst, (bstr){(char *)in, 1});
// Break ASS escapes with U+2060 WORD JOINER // Break ASS escapes with U+2060 WORD JOINER
if (*in == '\\') if (escape_ass && *in == '\\')
mp_append_utf8_bstr(NULL, dst, 0x2060); mp_append_utf8_bstr(NULL, dst, 0x2060);
in++; in++;
} }