diff options
author | Grigori Goronzy <greg@blackbox> | 2009-07-11 02:18:51 +0200 |
---|---|---|
committer | Grigori Goronzy <greg@blackbox> | 2009-07-11 02:22:18 +0200 |
commit | 2c412cdab94a7bb27c5a1e04ab902295215de888 (patch) | |
tree | c1372ebf5e6473b287e152a40c88587f3470d237 /libass/ass_library.c | |
parent | 613a22ab9b96453c10de6d75b43067652ad6d7db (diff) | |
download | libass-2c412cdab94a7bb27c5a1e04ab902295215de888.tar.bz2 libass-2c412cdab94a7bb27c5a1e04ab902295215de888.tar.xz |
Message callback funtionality
Introduce functionality for providing a message callback that is used
for passing messages to the controlling application instead of simply
printing them to standard output. The function pointer to the callback
is stored in the ass_library_t instance. ass_msg needs access to it, so
in many places the library instance needs to be passed around now.
The default behavior is the old one: messages of MSGL_INFO or lower
are printed to the standard output, prefixed with "[ass]".
Diffstat (limited to 'libass/ass_library.c')
-rw-r--r-- | libass/ass_library.c | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/libass/ass_library.c b/libass/ass_library.c index ce877da..2a8f5b2 100644 --- a/libass/ass_library.c +++ b/libass/ass_library.c @@ -22,14 +22,27 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <stdarg.h> #include "ass.h" #include "ass_library.h" +#include "ass_utils.h" +static void ass_msg_handler(int level, char *fmt, va_list *va) +{ + if (level > MSGL_INFO) + return; + printf("[ass] "); + vprintf(fmt, *va); + printf("\n"); +} ass_library_t *ass_library_init(void) { - return calloc(1, sizeof(ass_library_t)); + ass_library_t* lib = calloc(1, sizeof(ass_library_t)); + lib->msg_callback = ass_msg_handler; + + return lib; } void ass_library_done(ass_library_t *priv) @@ -114,3 +127,16 @@ void ass_clear_fonts(ass_library_t *priv) priv->fontdata = NULL; priv->num_fontdata = 0; } + +/* + * Register a message callback function with libass. Without setting one, + * a default handler is used which prints everything with MSGL_INFO or + * higher to the standard output. + */ +void ass_set_message_cb(ass_library_t *priv, + void (*msg_cb)(int, char *, va_list *)) +{ + if (msg_cb) + priv->msg_callback = msg_cb; +} + |