diff options
-rw-r--r-- | CMakeLists.txt | 15 | ||||
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | include/kitchensink/internal/kitlibstate.h | 3 | ||||
-rw-r--r-- | include/kitchensink/internal/libass.h | 57 | ||||
-rw-r--r-- | src/internal/libass.c | 24 | ||||
-rw-r--r-- | src/internal/subtitle/kitsubtitle.c | 9 | ||||
-rw-r--r-- | src/internal/subtitle/renderers/kitsubass.c | 3 | ||||
-rw-r--r-- | src/kitlib.c | 40 |
8 files changed, 133 insertions, 22 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index d70cfd1..a72d9f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,14 +14,14 @@ add_definitions( ) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") -set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb -pedantic -Werror -fno-omit-frame-pointer -Wno-deprecated-declarations") +set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb -Werror -fno-omit-frame-pointer -Wno-deprecated-declarations") set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -ggdb -O2 -fno-omit-frame-pointer -DNDEBUG") set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2 -DNDEBUG") set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -Os -DNDEBUG") option(BUILD_EXAMPLES "Build examples" OFF) option(BUILD_TESTS "Build unittests" OFF) -option(USE_ASS "Use libass" ON) +option(USE_DYNAMIC_LIBASS "Use dynamically loaded libass" ON) find_package(SDL2) find_package(ffmpeg COMPONENTS avcodec avformat avutil swscale swresample) @@ -40,9 +40,16 @@ if(BUILD_TESTS) add_subdirectory(tests) endif() -if(USE_ASS) +if(USE_DYNAMIC_LIBASS) + if(WIN32 OR MINGW OR MSYS) + set(DYNAMIC_LIBASS_NAME "\"libass-9.dll\"") + else() + set(DYNAMIC_LIBASS_NAME "\"libass.so\"") + endif() + add_definitions(-DUSE_DYNAMIC_LIBASS) + add_definitions(-DDYNAMIC_LIBASS_NAME=${DYNAMIC_LIBASS_NAME}) +else() find_package(ass) - add_definitions(-DUSE_ASS) set(LIBRARIES ${LIBRARIES} ${ASS_LIBRARIES}) set(INCLUDES ${INCLUDES} ${ASS_INCLUDE_DIRS}) endif() @@ -16,6 +16,10 @@ Features: * Seeking forwards and backwards * Bitmap & libass subtitle support. No text (srt, sub) support yet. +Note! Master branch is for the development of v1.0.0 series. v0 can be found in the +rel-kitchensink-0 branch. v0 is no longer in active development and only bug- and security-fixes +are accepted. + ## 1. Library requirements Build requirements: diff --git a/include/kitchensink/internal/kitlibstate.h b/include/kitchensink/internal/kitlibstate.h index e16a5c9..ad515b9 100644 --- a/include/kitchensink/internal/kitlibstate.h +++ b/include/kitchensink/internal/kitlibstate.h @@ -1,12 +1,13 @@ #ifndef KITLIBSTATE_H #define KITLIBSTATE_H -#include <ass/ass.h> +#include "kitchensink/internal/libass.h" #include "kitchensink/kitconfig.h" typedef struct Kit_LibraryState { unsigned int init_flags; ASS_Library *libass_handle; + void *ass_so_handle; } Kit_LibraryState; KIT_LOCAL Kit_LibraryState* Kit_GetLibraryState(); diff --git a/include/kitchensink/internal/libass.h b/include/kitchensink/internal/libass.h new file mode 100644 index 0000000..0c9730a --- /dev/null +++ b/include/kitchensink/internal/libass.h @@ -0,0 +1,57 @@ +#ifndef KITLIBASS_H
+#define KITLIBASS_H
+
+#ifndef USE_DYNAMIC_LIBASS
+
+#include <ass/ass.h>
+
+#else // USE_DYNAMIC_LIBASS
+
+#include <stdint.h>
+#include <stdarg.h>
+
+typedef struct ass_library ASS_Library;
+typedef struct ass_renderer ASS_Renderer;
+typedef struct ass_track ASS_Track;
+
+typedef struct ass_image {
+ int w, h;
+ int stride;
+ unsigned char *bitmap;
+ uint32_t color;
+ int dst_x, dst_y;
+ struct ass_image *next;
+ enum {
+ IMAGE_TYPE_CHARACTER,
+ IMAGE_TYPE_OUTLINE,
+ IMAGE_TYPE_SHADOW
+ } type;
+} ASS_Image;
+
+typedef enum {
+ ASS_HINTING_NONE = 0,
+ ASS_HINTING_LIGHT,
+ ASS_HINTING_NORMAL,
+ ASS_HINTING_NATIVE
+} ASS_Hinting;
+
+ASS_Library* (*ass_library_init)(void);
+void (*ass_library_done)(ASS_Library *priv);
+void (*ass_process_codec_private)(ASS_Track *track, char *data, int size);
+void (*ass_set_message_cb)(ASS_Library *priv, void (*msg_cb)(int level, const char *fmt, va_list args, void *data), void *data);
+ASS_Renderer* (*ass_renderer_init)(ASS_Library *);
+void (*ass_renderer_done)(ASS_Renderer *priv);
+void (*ass_set_frame_size)(ASS_Renderer *priv, int w, int h);
+void (*ass_set_hinting)(ASS_Renderer *priv, ASS_Hinting ht);
+void (*ass_set_fonts)(ASS_Renderer *priv, const char *default_font, const char *default_family, int dfp, const char *config, int update);
+ASS_Image* (*ass_render_frame)(ASS_Renderer *priv, ASS_Track *track, long long now, int *detect_change);
+ASS_Track* (*ass_new_track)(ASS_Library *);
+void (*ass_free_track)(ASS_Track *track);
+void (*ass_process_data)(ASS_Track *track, char *data, int size);
+void (*ass_add_font)(ASS_Library *library, char *name, char *data, int data_size);
+
+int load_libass(void *handle);
+
+#endif // USE_DYNAMIC_LIBASS
+
+#endif // KITLIBASS_H
diff --git a/src/internal/libass.c b/src/internal/libass.c new file mode 100644 index 0000000..a13e32d --- /dev/null +++ b/src/internal/libass.c @@ -0,0 +1,24 @@ +#ifdef USE_DYNAMIC_LIBASS
+
+#include <SDL2/SDL_loadso.h>
+#include "kitchensink/internal/libass.h"
+
+int load_libass(void *handle) {
+ ass_library_init = SDL_LoadFunction(handle, "ass_library_init");
+ ass_library_done = SDL_LoadFunction(handle, "ass_library_done");
+ ass_set_message_cb = SDL_LoadFunction(handle, "ass_set_message_cb");
+ ass_renderer_init = SDL_LoadFunction(handle, "ass_renderer_init");
+ ass_renderer_done = SDL_LoadFunction(handle, "ass_renderer_done");
+ ass_set_frame_size = SDL_LoadFunction(handle, "ass_set_frame_size");
+ ass_set_hinting = SDL_LoadFunction(handle, "ass_set_hinting");
+ ass_set_fonts = SDL_LoadFunction(handle, "ass_set_fonts");
+ ass_render_frame = SDL_LoadFunction(handle, "ass_render_frame");
+ ass_new_track = SDL_LoadFunction(handle, "ass_new_track");
+ ass_free_track = SDL_LoadFunction(handle, "ass_free_track");
+ ass_process_data = SDL_LoadFunction(handle, "ass_process_data");
+ ass_add_font = SDL_LoadFunction(handle, "ass_add_font");
+ ass_process_codec_private = SDL_LoadFunction(handle, "ass_process_codec_private");
+ return 0;
+}
+
+#endif // USE_DYNAMIC_LIBASS
diff --git a/src/internal/subtitle/kitsubtitle.c b/src/internal/subtitle/kitsubtitle.c index 1f5fb72..c9691c7 100644 --- a/src/internal/subtitle/kitsubtitle.c +++ b/src/internal/subtitle/kitsubtitle.c @@ -6,6 +6,7 @@ #include "kitchensink/internal/utils/kitlog.h"
#include "kitchensink/kiterror.h"
+#include "kitchensink/kitlib.h"
#include "kitchensink/internal/utils/kitlog.h"
#include "kitchensink/internal/kitlibstate.h"
#include "kitchensink/internal/subtitle/kitsubtitlepacket.h"
@@ -93,6 +94,8 @@ Kit_Decoder* Kit_CreateSubtitleDecoder(const Kit_Source *src, Kit_SubtitleFormat return NULL;
}
+ Kit_LibraryState *library_state = Kit_GetLibraryState();
+
// First the generic decoder component
Kit_Decoder *dec = Kit_CreateDecoder(
src, src->subtitle_stream_index,
@@ -122,7 +125,11 @@ Kit_Decoder* Kit_CreateSubtitleDecoder(const Kit_Source *src, Kit_SubtitleFormat case AV_CODEC_ID_SUBRIP:
case AV_CODEC_ID_SSA:
case AV_CODEC_ID_ASS:
- ren = Kit_CreateASSSubtitleRenderer(dec, w, h);
+ if(library_state->init_flags & KIT_INIT_ASS) {
+ ren = Kit_CreateASSSubtitleRenderer(dec, w, h);
+ } else {
+ format->is_enabled = false;
+ }
break;
case AV_CODEC_ID_DVD_SUBTITLE:
case AV_CODEC_ID_DVB_SUBTITLE:
diff --git a/src/internal/subtitle/renderers/kitsubass.c b/src/internal/subtitle/renderers/kitsubass.c index 18bf967..2a9eedf 100644 --- a/src/internal/subtitle/renderers/kitsubass.c +++ b/src/internal/subtitle/renderers/kitsubass.c @@ -1,7 +1,6 @@ #include <assert.h>
#include <stdlib.h>
-#include <ass/ass.h>
#include <SDL2/SDL_surface.h>
#include "kitchensink/kiterror.h"
@@ -197,6 +196,8 @@ Kit_SubtitleRenderer* Kit_CreateASSSubtitleRenderer(const Kit_Decoder *dec, int dec->codec_ctx->subtitle_header_size);
}
+ LOG("kekekekee\n");
+
// Set callbacks and userdata, and we're go
ass_ren->renderer = ass_renderer;
ass_ren->track = ass_track;
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() { |