Skip to content

Commit

Permalink
update capi module to support 3 styles of dynamic load c library
Browse files Browse the repository at this point in the history
currently used in SubtitleProcessorLibASS.cpp.
add "#define ASS_CAPI_NS" to use namespace style and do not unload the
library manually in your code
  • Loading branch information
wang-bin committed Jun 4, 2015
1 parent ba857cc commit e20f808
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 57 deletions.
2 changes: 1 addition & 1 deletion contrib/capi
3 changes: 3 additions & 0 deletions src/subtitle/SubtitleProcessorLibASS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 21,9 @@

#include <stdarg.h>
#include <string>
//#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"
Expand Down
102 changes: 51 additions & 51 deletions src/subtitle/ass_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,80 20,82 @@
******************************************************************************/
//#define DEBUG_RESOLVE
//#define DEBUG_LOAD

#include "ass_api.h"
//#define CAPI_IS_LAZY_RESOLVE 0
#ifndef CAPI_LINK_ASS
#include "capi.h"
#include <QtCore/QLibrary>
#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",
NULL
};
# 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
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);
Expand Down Expand Up @@ -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"
25 changes: 20 additions & 5 deletions src/subtitle/ass_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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"

0 comments on commit e20f808

Please sign in to comment.