summaryrefslogtreecommitdiff
path: root/src/kitlib.c
diff options
context:
space:
mode:
authorTuomas Virtanen <katajakasa@gmail.com>2018-03-26 15:15:19 +0300
committerTuomas Virtanen <katajakasa@gmail.com>2018-03-26 15:15:19 +0300
commit2843974d284cb2046318d2da5fcedc95104e88d9 (patch)
tree6f0ed517d59917f848da74e4a7e66893b8b5d807 /src/kitlib.c
parent56ae05977b1a6f720ab85dc733a9ceec6c7be7e3 (diff)
Allow runtime loading of libass library.
Previously libass could only be statically linked. Now we allow runtime loading of the library on request (just like other SDL libraries do).
Diffstat (limited to 'src/kitlib.c')
-rw-r--r--src/kitlib.c40
1 files changed, 25 insertions, 15 deletions
diff --git a/src/kitlib.c b/src/kitlib.c
index 2a2307b..2daf44d 100644
--- a/src/kitlib.c
+++ b/src/kitlib.c
@@ -1,16 +1,23 @@
#include <assert.h>
+#include <SDL2/SDL_loadso.h>
#include <libavformat/avformat.h>
+#include "kitchensink/internal/utils/kitlog.h"
#include "kitchensink/kitchensink.h"
#include "kitchensink/internal/kitlibstate.h"
-#ifdef USE_ASS
-#include <ass/ass.h>
-
static void _libass_msg_callback(int level, const char *fmt, va_list va, void *data) {}
int Kit_InitASS(Kit_LibraryState *state) {
+#ifdef USE_DYNAMIC_LIBASS
+ state->ass_so_handle = SDL_LoadObject(DYNAMIC_LIBASS_NAME);
+ if(state->ass_so_handle == NULL) {
+ Kit_SetError("Unable to load ASS library");
+ return 1;
+ }
+ load_libass(state->ass_so_handle);
+#endif
state->libass_handle = ass_library_init();
ass_set_message_cb(state->libass_handle, _libass_msg_callback, NULL);
return 0;
@@ -19,35 +26,38 @@ int Kit_InitASS(Kit_LibraryState *state) {
void Kit_CloseASS(Kit_LibraryState *state) {
ass_library_done(state->libass_handle);
state->libass_handle = NULL;
-}
-
-#else
-
-int Kit_InitASS(Kit_LibraryState *state) { return 1; }
-void Kit_CloseASS(Kit_LibraryState *state) {}
-
+#ifdef USE_DYNAMIC_LIBASS
+ SDL_UnloadObject(state->ass_so_handle);
+ state->ass_so_handle = NULL;
#endif
-
+}
int Kit_Init(unsigned int flags) {
Kit_LibraryState *state = Kit_GetLibraryState();
if(state->init_flags != 0) {
Kit_SetError("Kitchensink is already initialized.");
- return 1;
+ goto exit_0;
}
av_register_all();
if(flags & KIT_INIT_NETWORK) {
avformat_network_init();
- state->init_flags |= KIT_INIT_NETWORK;
}
if(flags & KIT_INIT_ASS) {
- if(Kit_InitASS(state) == 0) {
- state->init_flags |= KIT_INIT_ASS;
+ if(Kit_InitASS(state) != 0) {
+ goto exit_1;
}
}
+
+ state->init_flags = flags;
return 0;
+
+exit_1:
+ avformat_network_deinit();
+
+exit_0:
+ return 1;
}
void Kit_Quit() {