diff options
author | Tuomas Virtanen <katajakasa@gmail.com> | 2016-01-17 22:46:18 +0200 |
---|---|---|
committer | Tuomas Virtanen <katajakasa@gmail.com> | 2016-01-17 22:46:18 +0200 |
commit | 766a346e516a58fd110caca311ecaec68b47bc12 (patch) | |
tree | 189acf02cec11701e48d7a94e9748c83deb46baa /src/kitlib.c | |
parent | defe24601e2338a6a6d3145220e25c56bf1c3147 (diff) |
Add support for libass subtitles
Diffstat (limited to 'src/kitlib.c')
-rw-r--r-- | src/kitlib.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/kitlib.c b/src/kitlib.c new file mode 100644 index 0000000..3c3eee3 --- /dev/null +++ b/src/kitlib.c @@ -0,0 +1,59 @@ +#include "kitchensink/kitchensink.h" +#include "kitchensink/internal/kitlibstate.h" +#include <libavformat/avformat.h> +#include <ass/ass.h> +#include <assert.h> + +// No-op +void _libass_msg_callback(int level, const char *fmt, va_list va, void *data) {} + +int Kit_Init(unsigned int flags) { + Kit_LibraryState *state = Kit_GetLibraryState(); + + if(state->init_flags != 0) { + Kit_SetError("Kitchensink is already initialized."); + return 1; + } + if(flags & KIT_INIT_NETWORK) { + avformat_network_init(); + } + if(flags & KIT_INIT_FORMATS) { + av_register_all(); + } + + state->init_flags = flags; + + // Init libass + state->libass_handle = ass_library_init(); + + // Set up libass font directories + if(strcmp(SDL_GetPlatform(), "Windows") == 0) { + ass_set_fonts_dir(state->libass_handle, "C:/Windows/Fonts"); + } + else if(strcmp(SDL_GetPlatform(), "Linux") == 0) { + ass_set_fonts_dir(state->libass_handle, "/usr/share/fonts"); + } + + // Make libass message spam go away + ass_set_message_cb(state->libass_handle, _libass_msg_callback, NULL); + + return 0; +} + +void Kit_Quit() { + Kit_LibraryState *state = Kit_GetLibraryState(); + + if(state->init_flags & KIT_INIT_NETWORK) { + avformat_network_deinit(); + } + state->init_flags = 0; + + ass_library_done(state->libass_handle); +} + +void Kit_GetVersion(Kit_Version *version) { + assert(version != NULL); + version->major = KIT_VERSION_MAJOR; + version->minor = KIT_VERSION_MINOR; + version->patch = KIT_VERSION_PATCH; +} |