69 squash_plugin_add_codec (SquashPlugin* plugin, SquashCodec* codec) {
70 SquashContext* context;
72 assert (plugin != NULL);
73 assert (codec != NULL);
75 context = plugin->context;
78 SQUASH_TREE_INSERT(&(plugin->codecs),
_SquashCodec, tree, codec);
80 squash_context_add_codec (context, codec);
83 SQUASH_MTX_DEFINE(plugin_init)
102 if (plugin->plugin == NULL) {
108 char* plugin_file_name;
109 size_t plugin_dir_length;
110 size_t plugin_name_length;
111 size_t plugin_file_name_max_length;
114 plugin_dir_length = strlen (plugin->directory);
115 plugin_name_length = strlen (plugin->name);
116 plugin_file_name_max_length = plugin_dir_length + squash_version_api_length + plugin_name_length + 19 + strlen (SQUASH_SHARED_LIBRARY_SUFFIX);
117 plugin_file_name = (
char*) malloc (plugin_file_name_max_length + 1);
119 snprintf (plugin_file_name, plugin_file_name_max_length + 1,
120 "%s/libsquash%s-plugin-%s%s", plugin->directory,
SQUASH_VERSION_API, plugin->name, SQUASH_SHARED_LIBRARY_SUFFIX);
123 handle = dlopen (plugin_file_name, RTLD_LAZY);
125 handle = LoadLibrary (TEXT(plugin_file_name));
128 free (plugin_file_name);
130 if (handle != NULL) {
131 SQUASH_MTX_LOCK(plugin_init);
132 if (plugin->plugin == NULL) {
133 plugin->plugin = handle;
136 SQUASH_MTX_UNLOCK(plugin_init);
141 if (handle != NULL) {
145 FreeLibrary (handle);
150 *(
void **) (&init_func) = dlsym (plugin->plugin,
"squash_plugin_init_plugin");
152 *(
void **) (&init_func) = GetProcAddress (handle,
"squash_plugin_init_plugin");
154 if (init_func != NULL) {
171 assert (plugin != NULL);
185 assert (plugin != NULL);
187 return plugin->license;
199 SquashCodec key = { 0, };
200 SquashCodec* codec_real;
202 assert (plugin != NULL);
203 assert (codec != NULL);
205 key.name = (
char*) codec;
207 codec_real = SQUASH_TREE_FIND (&(plugin->codecs),
_SquashCodec, tree, &key);
222 squash_plugin_compare (SquashPlugin* a, SquashPlugin* b) {
226 return strcmp (a->name, b->name);
229 SQUASH_MTX_DEFINE(codec_init)
241 squash_plugin_init_codec (SquashPlugin* plugin, SquashCodec* codec, SquashCodecImpl* impl) {
244 assert (plugin != NULL);
246 if (plugin->plugin == NULL) {
253 if (codec->initialized == 0) {
254 SquashStatus (*init_codec_func) (SquashCodec*, SquashCodecImpl*);
257 *(
void **) (&init_codec_func) = dlsym (plugin->plugin,
"squash_plugin_init_codec");
259 *(
void **) (&init_codec_func) = GetProcAddress (plugin->plugin,
"squash_plugin_init_codec");
262 if (init_codec_func == NULL) {
266 SQUASH_MTX_LOCK(codec_init);
267 res = init_codec_func (codec, impl);
271 if (codec->impl.process_stream != NULL)
273 if (codec->impl.get_uncompressed_size != NULL)
275 SQUASH_MTX_UNLOCK(codec_init);
299 SQUASH_TREE_FORWARD_APPLY(&(plugin->codecs),
_SquashCodec, tree, func, data);
311 squash_plugin_new (
char* name,
char* directory, SquashContext* context) {
312 SquashPlugin* plugin = (SquashPlugin*) malloc (
sizeof (SquashPlugin));
315 plugin->license = NULL;
316 plugin->context = context;
317 plugin->directory = directory;
318 plugin->plugin = NULL;
319 SQUASH_TREE_ENTRY_INIT(plugin->tree);
320 SQUASH_TREE_INIT(&(plugin->codecs), squash_codec_compare);
Mask of flags which are automatically set based on which callbacks are provided.
#define SQUASH_VERSION_API
SquashStatus squash_codec_init(SquashCodec *codec)
Initialize a codec.
void squash_plugin_foreach_codec(SquashPlugin *plugin, SquashCodecForeachFunc func, void *data)
Execute a callback for every codec in the plugin.
SquashLicense * squash_plugin_get_licenses(SquashPlugin *plugin)
Get the licenses of the plugin.
A compression/decompression codec.
SquashStatus
Status codes.
SquashStatus squash_error(SquashStatus status)
Emit an error.
void(* SquashCodecForeachFunc)(SquashCodec *codec, void *data)
Squashlback to be invoked on each SquashCodec in a set.
SquashStatus squash_plugin_init(SquashPlugin *plugin)
load a SquashPlugin
SquashCodec * squash_plugin_get_codec(SquashPlugin *plugin, const char *codec)
Get a codec from a plugin by name.
Unable to load the requested resource.
Operation completed successfully.
const char * squash_plugin_get_name(SquashPlugin *plugin)
Get the name of a plugin.
The compressed data encodes the length of the uncompressed data without having to decompress it...
The codec natively supports a streaming interface.