From e20f80815cb89d1a6c28bbc6a22c9a2d9a28a463 Mon Sep 17 00:00:00 2001 From: wang-bin Date: Thu, 4 Jun 2015 11:56:20 +0800 Subject: [PATCH] update capi module to support 3 styles of dynamic load c library currently used in SubtitleProcessorLibASS.cpp. add "#define ASS_CAPI_NS" to use namespace style and do not unload the library manually in your code --- contrib/capi | 2 +- src/subtitle/SubtitleProcessorLibASS.cpp | 3 + src/subtitle/ass_api.cpp | 102 +++++++++++------------ src/subtitle/ass_api.h | 25 ++++-- 4 files changed, 75 insertions(+), 57 deletions(-) diff --git a/contrib/capi b/contrib/capi index 36e821328..ac05d09d5 160000 --- a/contrib/capi +++ b/contrib/capi @@ -1 +1 @@ -Subproject commit 36e8213286e20335a575b242462018a4412b62f8 +Subproject commit ac05d09d5c66b531b0211397b47bed3c659267ca diff --git a/src/subtitle/SubtitleProcessorLibASS.cpp b/src/subtitle/SubtitleProcessorLibASS.cpp index dffb5a359..f7d7c668d 100644 --- a/src/subtitle/SubtitleProcessorLibASS.cpp +++ b/src/subtitle/SubtitleProcessorLibASS.cpp @@ -21,6 +21,9 @@ #include #include +//#define ASS_CAPI_NS // do not unload() manually! +//#define CAPI_LINK_ASS + #include "ass_api.h" #include "QtAV/private/SubtitleProcessor.h" #include "QtAV/private/prepost.h" diff --git a/src/subtitle/ass_api.cpp b/src/subtitle/ass_api.cpp index e6b679e39..8541c4e90 100644 --- a/src/subtitle/ass_api.cpp +++ b/src/subtitle/ass_api.cpp @@ -20,16 +20,17 @@ ******************************************************************************/ //#define DEBUG_RESOLVE //#define DEBUG_LOAD - -#include "ass_api.h" +//#define CAPI_IS_LAZY_RESOLVE 0 #ifndef CAPI_LINK_ASS -#include "capi.h" #include +#include "capi.h" #endif +#include "ass_api.h" //include last to avoid covering types later namespace ass { #ifdef CAPI_LINK_ASS class api_dll {public: bool isLoaded() const {return true;}}; +CAPI_DEFINE_DLL #else static const char* names[] = { "ass", @@ -37,10 +38,10 @@ static const char* names[] = { }; # if 1 static const int versions[] = { - capi::NoVersion, + ::capi::NoVersion, // the following line will be replaced by the content of config/ass/version if exists 5, 4 - , capi::EndVersion + , ::capi::EndVersion }; CAPI_BEGIN_DLL_VER(names, versions, QLibrary) # else @@ -48,52 +49,53 @@ CAPI_BEGIN_DLL(names, QLibrary) # endif //1 // CAPI_DEFINE_RESOLVER(argc, return_type, name, argv_no_name) // mkapi code generation BEGIN -//CAPI_DEFINE_RESOLVER(int, ass_library_version, CAPI_ARG0()) -CAPI_DEFINE_RESOLVER(ASS_Library *, ass_library_init, CAPI_ARG0()) -CAPI_DEFINE_RESOLVER(void, ass_library_done, CAPI_ARG1(ASS_Library *)) -//CAPI_DEFINE_RESOLVER(void, ass_set_fonts_dir, CAPI_ARG2(ASS_Library *, const char *)) -//CAPI_DEFINE_RESOLVER(void, ass_set_extract_fonts, CAPI_ARG2(ASS_Library *, int)) -//CAPI_DEFINE_RESOLVER(void, ass_set_style_overrides, CAPI_ARG2(ASS_Library *, char **)) -//CAPI_DEFINE_RESOLVER(void, ass_process_force_style, CAPI_ARG1(ASS_Track *)) -CAPI_DEFINE_RESOLVER(void, ass_set_message_cb, CAPI_ARG3(ASS_Library *, void (*msg_cb) +//CAPI_DEFINE_ENTRY(int, ass_library_version, CAPI_ARG0()) +CAPI_DEFINE_ENTRY(ASS_Library *, ass_library_init, CAPI_ARG0()) +CAPI_DEFINE_ENTRY(void, ass_library_done, CAPI_ARG1(ASS_Library *)) +//CAPI_DEFINE_ENTRY(void, ass_set_fonts_dir, CAPI_ARG2(ASS_Library *, const char *)) +//CAPI_DEFINE_ENTRY(void, ass_set_extract_fonts, CAPI_ARG2(ASS_Library *, int)) +//CAPI_DEFINE_ENTRY(void, ass_set_style_overrides, CAPI_ARG2(ASS_Library *, char **)) +//CAPI_DEFINE_ENTRY(void, ass_process_force_style, CAPI_ARG1(ASS_Track *)) +CAPI_DEFINE_ENTRY(void, ass_set_message_cb, CAPI_ARG3(ASS_Library *, void (*msg_cb) (int level, const char *fmt, va_list args, void *data), void *)) -CAPI_DEFINE_RESOLVER(ASS_Renderer *, ass_renderer_init, CAPI_ARG1(ASS_Library *)) -CAPI_DEFINE_RESOLVER(void, ass_renderer_done, CAPI_ARG1(ASS_Renderer *)) -CAPI_DEFINE_RESOLVER(void, ass_set_frame_size, CAPI_ARG3(ASS_Renderer *, int, int)) -//CAPI_DEFINE_RESOLVER(void, ass_set_storage_size, CAPI_ARG3(ASS_Renderer *, int, int)) -CAPI_DEFINE_RESOLVER(void, ass_set_shaper, CAPI_ARG2(ASS_Renderer *, ASS_ShapingLevel)) -//CAPI_DEFINE_RESOLVER(void, ass_set_margins, CAPI_ARG5(ASS_Renderer *, int, int, int, int)) -//CAPI_DEFINE_RESOLVER(void, ass_set_use_margins, CAPI_ARG2(ASS_Renderer *, int)) -//CAPI_DEFINE_RESOLVER(void, ass_set_pixel_aspect, CAPI_ARG2(ASS_Renderer *, double)) -//CAPI_DEFINE_RESOLVER(void, ass_set_aspect_ratio, CAPI_ARG3(ASS_Renderer *, double, double)) -//CAPI_DEFINE_RESOLVER(void, ass_set_font_scale, CAPI_ARG2(ASS_Renderer *, double)) -//CAPI_DEFINE_RESOLVER(void, ass_set_hinting, CAPI_ARG2(ASS_Renderer *, ASS_Hinting)) -//CAPI_DEFINE_RESOLVER(void, ass_set_line_spacing, CAPI_ARG2(ASS_Renderer *, double)) -//CAPI_DEFINE_RESOLVER(void, ass_set_line_position, CAPI_ARG2(ASS_Renderer *, double)) -CAPI_DEFINE_RESOLVER(void, ass_set_fonts, CAPI_ARG6(ASS_Renderer *, const char *, const char *, int, const char *, int)) -//CAPI_DEFINE_RESOLVER(void, ass_set_selective_style_override_enabled, CAPI_ARG2(ASS_Renderer *, int)) -//CAPI_DEFINE_RESOLVER(void, ass_set_selective_style_override, CAPI_ARG2(ASS_Renderer *, ASS_Style *)) -//CAPI_DEFINE_RESOLVER(int, ass_fonts_update, CAPI_ARG1(ASS_Renderer *)) -//CAPI_DEFINE_RESOLVER(void, ass_set_cache_limits, CAPI_ARG3(ASS_Renderer *, int, int)) -CAPI_DEFINE_RESOLVER(ASS_Image *, ass_render_frame, CAPI_ARG4(ASS_Renderer *, ASS_Track *, long long, int *)) -CAPI_DEFINE_RESOLVER(ASS_Track *, ass_new_track, CAPI_ARG1(ASS_Library *)) -CAPI_DEFINE_RESOLVER(void, ass_free_track, CAPI_ARG1(ASS_Track *)) -//CAPI_DEFINE_RESOLVER(int, ass_alloc_style, CAPI_ARG1(ASS_Track *)) -//CAPI_DEFINE_RESOLVER(int, ass_alloc_event, CAPI_ARG1(ASS_Track *)) -//CAPI_DEFINE_RESOLVER(void, ass_free_style, CAPI_ARG2(ASS_Track *, int)) -//CAPI_DEFINE_RESOLVER(void, ass_free_event, CAPI_ARG2(ASS_Track *, int)) -CAPI_DEFINE_RESOLVER(void, ass_process_data, CAPI_ARG3(ASS_Track *, char *, int)) -CAPI_DEFINE_RESOLVER(void, ass_process_codec_private, CAPI_ARG3(ASS_Track *, char *, int)) -CAPI_DEFINE_RESOLVER(void, ass_process_chunk, CAPI_ARG5(ASS_Track *, char *, int, long long, long long)) -CAPI_DEFINE_RESOLVER(void, ass_flush_events, CAPI_ARG1(ASS_Track *)) -CAPI_DEFINE_RESOLVER(ASS_Track *, ass_read_file, CAPI_ARG3(ASS_Library *, char *, char *)) -CAPI_DEFINE_RESOLVER(ASS_Track *, ass_read_memory, CAPI_ARG4(ASS_Library *, char *, size_t, char *)) -//CAPI_DEFINE_RESOLVER(int, ass_read_styles, CAPI_ARG3(ASS_Track *, char *, char *)) -//CAPI_DEFINE_RESOLVER(void, ass_add_font, CAPI_ARG4(ASS_Library *, char *, char *, int)) -//CAPI_DEFINE_RESOLVER(void, ass_clear_fonts, CAPI_ARG1(ASS_Library *)) -//CAPI_DEFINE_RESOLVER(long long, ass_step_sub, CAPI_ARG3(ASS_Track *, long long, int)) +CAPI_DEFINE_ENTRY(ASS_Renderer *, ass_renderer_init, CAPI_ARG1(ASS_Library *)) +CAPI_DEFINE_ENTRY(void, ass_renderer_done, CAPI_ARG1(ASS_Renderer *)) +CAPI_DEFINE_ENTRY(void, ass_set_frame_size, CAPI_ARG3(ASS_Renderer *, int, int)) +//CAPI_DEFINE_ENTRY(void, ass_set_storage_size, CAPI_ARG3(ASS_Renderer *, int, int)) +CAPI_DEFINE_ENTRY(void, ass_set_shaper, CAPI_ARG2(ASS_Renderer *, ASS_ShapingLevel)) +//CAPI_DEFINE_ENTRY(void, ass_set_margins, CAPI_ARG5(ASS_Renderer *, int, int, int, int)) +//CAPI_DEFINE_ENTRY(void, ass_set_use_margins, CAPI_ARG2(ASS_Renderer *, int)) +//CAPI_DEFINE_ENTRY(void, ass_set_pixel_aspect, CAPI_ARG2(ASS_Renderer *, double)) +//CAPI_DEFINE_ENTRY(void, ass_set_aspect_ratio, CAPI_ARG3(ASS_Renderer *, double, double)) +//CAPI_DEFINE_ENTRY(void, ass_set_font_scale, CAPI_ARG2(ASS_Renderer *, double)) +//CAPI_DEFINE_ENTRY(void, ass_set_hinting, CAPI_ARG2(ASS_Renderer *, ASS_Hinting)) +//CAPI_DEFINE_ENTRY(void, ass_set_line_spacing, CAPI_ARG2(ASS_Renderer *, double)) +//CAPI_DEFINE_ENTRY(void, ass_set_line_position, CAPI_ARG2(ASS_Renderer *, double)) +CAPI_DEFINE_ENTRY(void, ass_set_fonts, CAPI_ARG6(ASS_Renderer *, const char *, const char *, int, const char *, int)) +//CAPI_DEFINE_ENTRY(void, ass_set_selective_style_override_enabled, CAPI_ARG2(ASS_Renderer *, int)) +//CAPI_DEFINE_ENTRY(void, ass_set_selective_style_override, CAPI_ARG2(ASS_Renderer *, ASS_Style *)) +//CAPI_DEFINE_ENTRY(int, ass_fonts_update, CAPI_ARG1(ASS_Renderer *)) +//CAPI_DEFINE_ENTRY(void, ass_set_cache_limits, CAPI_ARG3(ASS_Renderer *, int, int)) +CAPI_DEFINE_ENTRY(ASS_Image *, ass_render_frame, CAPI_ARG4(ASS_Renderer *, ASS_Track *, long long, int *)) +CAPI_DEFINE_ENTRY(ASS_Track *, ass_new_track, CAPI_ARG1(ASS_Library *)) +CAPI_DEFINE_ENTRY(void, ass_free_track, CAPI_ARG1(ASS_Track *)) +//CAPI_DEFINE_ENTRY(int, ass_alloc_style, CAPI_ARG1(ASS_Track *)) +//CAPI_DEFINE_ENTRY(int, ass_alloc_event, CAPI_ARG1(ASS_Track *)) +//CAPI_DEFINE_ENTRY(void, ass_free_style, CAPI_ARG2(ASS_Track *, int)) +//CAPI_DEFINE_ENTRY(void, ass_free_event, CAPI_ARG2(ASS_Track *, int)) +CAPI_DEFINE_ENTRY(void, ass_process_data, CAPI_ARG3(ASS_Track *, char *, int)) +CAPI_DEFINE_ENTRY(void, ass_process_codec_private, CAPI_ARG3(ASS_Track *, char *, int)) +CAPI_DEFINE_ENTRY(void, ass_process_chunk, CAPI_ARG5(ASS_Track *, char *, int, long long, long long)) +CAPI_DEFINE_ENTRY(void, ass_flush_events, CAPI_ARG1(ASS_Track *)) +CAPI_DEFINE_ENTRY(ASS_Track *, ass_read_file, CAPI_ARG3(ASS_Library *, char *, char *)) +CAPI_DEFINE_ENTRY(ASS_Track *, ass_read_memory, CAPI_ARG4(ASS_Library *, char *, size_t, char *)) +//CAPI_DEFINE_ENTRY(int, ass_read_styles, CAPI_ARG3(ASS_Track *, char *, char *)) +//CAPI_DEFINE_ENTRY(void, ass_add_font, CAPI_ARG4(ASS_Library *, char *, char *, int)) +//CAPI_DEFINE_ENTRY(void, ass_clear_fonts, CAPI_ARG1(ASS_Library *)) +//CAPI_DEFINE_ENTRY(long long, ass_step_sub, CAPI_ARG3(ASS_Track *, long long, int)) // mkapi code generation END CAPI_END_DLL() +CAPI_DEFINE_DLL // CAPI_DEFINE(argc, return_type, name, argv_no_name) typedef void (*ass_set_message_cb_msg_cb1) (int level, const char *fmt, va_list args, void *data); @@ -143,7 +145,5 @@ CAPI_DEFINE(ASS_Track *, ass_read_memory, CAPI_ARG4(ASS_Library *, char *, size_ //CAPI_DEFINE(long long, ass_step_sub, CAPI_ARG3(ASS_Track *, long long, int)) // mkapi code generation END #endif //CAPI_LINK_ASS -api::api() : dll(new api_dll()) {} -api::~api() { delete dll;} -bool api::loaded() const { return dll->isLoaded(); } } //namespace ass +//this file is generated by "mkapi.sh -name ass /usr/local/include/ass/ass.h" diff --git a/src/subtitle/ass_api.h b/src/subtitle/ass_api.h index 1f78a9d88..da336b046 100644 --- a/src/subtitle/ass_api.h +++ b/src/subtitle/ass_api.h @@ -23,20 +23,32 @@ #define ASS_API_H // no need to include the C header if only functions declared there +#ifndef CAPI_LINK_ASS +namespace ass { +namespace capi { +#else extern "C" { +#endif // the following line will be replaced by the content of config/ASS/include if exists #include "ass/ass.h" +#ifndef CAPI_LINK_ASS +} +#endif } namespace ass { +#ifndef CAPI_LINK_ASS +using namespace capi; // original header is in namespace capi, types are changed +#endif // CAPI_LINK_ASS class api_dll; class api { + api_dll *dll; public: api(); virtual ~api(); virtual bool loaded() const; // user may inherits multiple api classes: final::loaded() { return base1::loaded() && base2::loaded();} -#ifndef CAPI_LINK_ASS +#if !defined(CAPI_LINK_ASS) && !defined(ASS_CAPI_NS) // mkapi code generation BEGIN int ass_library_version(); ASS_Library * ass_library_init(); @@ -83,11 +95,14 @@ class api void ass_clear_fonts(ASS_Library * library); long long ass_step_sub(ASS_Track * track, long long now, int movement); // mkapi code generation END -#endif //CAPI_LINK_ASS -private: - api_dll *dll; +#endif // !defined(CAPI_LINK_ASS) && !defined(ASS_CAPI_NS) }; } //namespace ass - +#ifdef ASS_CAPI_NS +using namespace ass::capi; +#else +using namespace ass; +#endif #endif // ASS_API_H +//this file is generated by "mkapi.sh -name ass /usr/local/include/ass/ass.h"