2 * Copyright (C) 2006 Josep Torra <josep@fluendo.com>
3 * 2006 Mathieu Garcia <matthieu@fluendo.com>
4 * 2006,2007 Stefan Kost <ensonic@users.sf.net>
5 * 2008 Sebastian Dröge <slomo@circular-chaos.org>
6 * 2008 Jan Schmidt <jan.schmidt@sun.com>
8 * gstregistrychunks.c: GstRegistryChunk helper for serialising/deserialising
9 * plugin entries and features.
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details.
21 * You should have received a copy of the GNU Library General Public
22 * License along with this library; if not, write to the
23 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
24 * Boston, MA 02110-1301, USA.
31 #include <gst/gst_private.h>
32 #include <gst/gstconfig.h>
33 #include <gst/gstelement.h>
34 #include <gst/gsttypefind.h>
35 #include <gst/gsttypefindfactory.h>
36 #include <gst/gstdevicemonitorfactory.h>
37 #include <gst/gsturi.h>
38 #include <gst/gstinfo.h>
39 #include <gst/gstenumtypes.h>
40 #include <gst/gstpadtemplate.h>
42 #include <gst/gstregistrychunks.h>
44 #define GST_CAT_DEFAULT GST_CAT_REGISTRY
46 /* count string length, but return -1 if we hit the eof */
48 _strnlen (const gchar * str, gint maxlen)
52 while (G_LIKELY (len < maxlen)) {
53 if (G_UNLIKELY (str[len] == '\0'))
61 #define unpack_element(inptr, outptr, element, endptr, error_label) G_STMT_START{ \
62 if (inptr + sizeof(element) > endptr) { \
63 GST_ERROR ("Failed reading element " G_STRINGIFY (element) \
64 ". Have %d bytes need %" G_GSIZE_FORMAT, \
65 (int) (endptr - inptr), sizeof(element)); \
68 outptr = (element *) inptr; \
69 inptr += sizeof (element); \
72 #define unpack_const_string(inptr, outptr, endptr, error_label) G_STMT_START{\
73 gint _len = _strnlen (inptr, (endptr-inptr)); \
76 outptr = g_intern_string ((const gchar *)inptr); \
80 #define unpack_string(inptr, outptr, endptr, error_label) G_STMT_START{\
81 gint _len = _strnlen (inptr, (endptr-inptr)); \
84 outptr = g_memdup ((gconstpointer)inptr, _len + 1); \
88 #define unpack_string_nocopy(inptr, outptr, endptr, error_label) G_STMT_START{\
89 gint _len = _strnlen (inptr, (endptr-inptr)); \
92 outptr = (const gchar *)inptr; \
96 #define ALIGNMENT (sizeof (void *))
97 #define alignment(_address) (gsize)_address%ALIGNMENT
98 #define align(_ptr) _ptr += (( alignment(_ptr) == 0) ? 0 : ALIGNMENT-alignment(_ptr))
101 _priv_gst_registry_chunk_free (GstRegistryChunk * chunk)
103 if (!(chunk->flags & GST_REGISTRY_CHUNK_FLAG_CONST)) {
104 if ((chunk->flags & GST_REGISTRY_CHUNK_FLAG_MALLOC))
105 g_free (chunk->data);
107 g_slice_free1 (chunk->size, chunk->data);
109 g_slice_free (GstRegistryChunk, chunk);
113 * gst_registry_chunks_save_const_string:
115 * Store a const string in a binary chunk.
117 * Returns: %TRUE for success
119 inline static gboolean
120 gst_registry_chunks_save_const_string (GList ** list, const gchar * str)
122 GstRegistryChunk *chunk;
124 if (G_UNLIKELY (str == NULL)) {
125 GST_ERROR ("unexpected NULL string in plugin or plugin feature data");
129 chunk = g_slice_new (GstRegistryChunk);
130 chunk->data = (gpointer) str;
131 chunk->size = strlen ((gchar *) chunk->data) + 1;
132 chunk->flags = GST_REGISTRY_CHUNK_FLAG_CONST;
133 chunk->align = FALSE;
134 *list = g_list_prepend (*list, chunk);
139 * gst_registry_chunks_save_string:
141 * Store a string in a binary chunk.
143 * Returns: %TRUE for success
145 inline static gboolean
146 gst_registry_chunks_save_string (GList ** list, gchar * str)
148 GstRegistryChunk *chunk;
150 chunk = g_slice_new (GstRegistryChunk);
152 chunk->size = strlen ((gchar *) chunk->data) + 1;
153 chunk->flags = GST_REGISTRY_CHUNK_FLAG_MALLOC;
154 chunk->align = FALSE;
155 *list = g_list_prepend (*list, chunk);
160 * gst_registry_chunks_save_data:
162 * Store some data in a binary chunk.
164 * Returns: the initialized chunk
166 inline static GstRegistryChunk *
167 gst_registry_chunks_make_data (gpointer data, gulong size)
169 GstRegistryChunk *chunk;
171 chunk = g_slice_new (GstRegistryChunk);
174 chunk->flags = GST_REGISTRY_CHUNK_FLAG_NONE;
181 * gst_registry_chunks_save_pad_template:
183 * Store pad_templates in binary chunks.
185 * Returns: %TRUE for success
188 gst_registry_chunks_save_pad_template (GList ** list,
189 GstStaticPadTemplate * template)
191 GstRegistryChunkPadTemplate *pt;
192 GstRegistryChunk *chk;
194 pt = g_slice_new (GstRegistryChunkPadTemplate);
196 gst_registry_chunks_make_data (pt, sizeof (GstRegistryChunkPadTemplate));
198 pt->presence = template->presence;
199 pt->direction = template->direction;
201 /* pack pad template strings */
202 gst_registry_chunks_save_const_string (list,
203 (gchar *) (template->static_caps.string));
204 gst_registry_chunks_save_const_string (list, template->name_template);
206 *list = g_list_prepend (*list, chk);
211 #define VALIDATE_UTF8(__details, __entry) \
213 if (!g_utf8_validate (__details->__entry, -1, NULL)) { \
214 g_warning ("Invalid UTF-8 in " G_STRINGIFY (__entry) ": %s", \
215 __details->__entry); \
216 g_free (__details->__entry); \
217 __details->__entry = g_strdup ("[ERROR: invalid UTF-8]"); \
222 * gst_registry_chunks_save_feature:
224 * Store features in binary chunks.
226 * Returns: %TRUE for success
229 gst_registry_chunks_save_feature (GList ** list, GstPluginFeature * feature)
231 const gchar *type_name = G_OBJECT_TYPE_NAME (feature);
232 GstRegistryChunkPluginFeature *pf = NULL;
233 GstRegistryChunk *chk = NULL;
238 GST_ERROR ("NULL feature type_name, aborting.");
242 if (GST_IS_ELEMENT_FACTORY (feature)) {
243 GstRegistryChunkElementFactory *ef;
244 GstElementFactory *factory = GST_ELEMENT_FACTORY (feature);
246 /* Initialize with zeroes because of struct padding and
247 * valgrind complaining about copying unitialized memory
249 ef = g_slice_new0 (GstRegistryChunkElementFactory);
250 pf_size = sizeof (GstRegistryChunkElementFactory);
251 chk = gst_registry_chunks_make_data (ef, pf_size);
252 ef->npadtemplates = ef->ninterfaces = ef->nuriprotocols = 0;
253 pf = (GstRegistryChunkPluginFeature *) ef;
255 /* save interfaces */
256 for (walk = factory->interfaces; walk;
257 walk = g_list_next (walk), ef->ninterfaces++) {
258 gst_registry_chunks_save_const_string (list, (gchar *) walk->data);
260 GST_DEBUG_OBJECT (feature, "saved %d interfaces %d pad templates",
261 ef->ninterfaces, ef->npadtemplates);
264 if (GST_URI_TYPE_IS_VALID (factory->uri_type)) {
265 if (factory->uri_protocols && *factory->uri_protocols) {
266 GstRegistryChunk *subchk;
270 gst_registry_chunks_make_data (&factory->uri_type,
271 sizeof (factory->uri_type));
272 subchk->flags = GST_REGISTRY_CHUNK_FLAG_CONST;
274 protocol = factory->uri_protocols;
276 gst_registry_chunks_save_const_string (list, *protocol++);
279 *list = g_list_prepend (*list, subchk);
280 GST_DEBUG_OBJECT (feature, "Saved %d UriTypes", ef->nuriprotocols);
282 g_warning ("GStreamer feature '%s' is URI handler but does not provide"
283 " any protocols it can handle", GST_OBJECT_NAME (feature));
287 /* save pad-templates */
288 for (walk = factory->staticpadtemplates; walk;
289 walk = g_list_next (walk), ef->npadtemplates++) {
290 GstStaticPadTemplate *template = walk->data;
292 if (!gst_registry_chunks_save_pad_template (list, template)) {
293 GST_ERROR_OBJECT (feature, "Can't fill pad template, aborting.");
298 /* pack element metadata strings */
299 gst_registry_chunks_save_string (list,
300 gst_structure_to_string (factory->metadata));
301 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
302 GstRegistryChunkTypeFindFactory *tff;
303 GstTypeFindFactory *factory = GST_TYPE_FIND_FACTORY (feature);
306 /* Initialize with zeroes because of struct padding and
307 * valgrind complaining about copying unitialized memory
309 tff = g_slice_new0 (GstRegistryChunkTypeFindFactory);
310 pf_size = sizeof (GstRegistryChunkTypeFindFactory);
311 chk = gst_registry_chunks_make_data (tff, pf_size);
312 tff->nextensions = 0;
313 pf = (GstRegistryChunkPluginFeature *) tff;
315 /* save extensions */
316 if (factory->extensions) {
317 while (factory->extensions[tff->nextensions]) {
318 gst_registry_chunks_save_const_string (list,
319 factory->extensions[tff->nextensions++]);
322 GST_DEBUG_OBJECT (feature, "saved %d extensions", tff->nextensions);
325 GstCaps *fcaps = gst_caps_ref (factory->caps);
326 /* we simplify the caps before saving. This is a lot faster
327 * when loading them later on */
328 fcaps = gst_caps_simplify (fcaps);
329 str = gst_caps_to_string (fcaps);
330 gst_caps_unref (fcaps);
332 gst_registry_chunks_save_string (list, str);
334 gst_registry_chunks_save_const_string (list, "");
336 } else if (GST_IS_DEVICE_MONITOR_FACTORY (feature)) {
337 GstRegistryChunkDeviceMonitorFactory *tff;
338 GstDeviceMonitorFactory *factory = GST_DEVICE_MONITOR_FACTORY (feature);
340 /* Initialize with zeroes because of struct padding and
341 * valgrind complaining about copying unitialized memory
343 tff = g_slice_new0 (GstRegistryChunkDeviceMonitorFactory);
345 gst_registry_chunks_make_data (tff,
346 sizeof (GstRegistryChunkDeviceMonitorFactory));
347 pf = (GstRegistryChunkPluginFeature *) tff;
350 /* pack element metadata strings */
351 gst_registry_chunks_save_string (list,
352 gst_structure_to_string (factory->metadata));
354 GST_WARNING_OBJECT (feature, "unhandled feature type '%s'", type_name);
358 pf->rank = feature->rank;
359 *list = g_list_prepend (*list, chk);
361 /* pack plugin feature strings */
362 gst_registry_chunks_save_const_string (list, GST_OBJECT_NAME (feature));
363 gst_registry_chunks_save_const_string (list, (gchar *) type_name);
370 g_slice_free (GstRegistryChunk, chk);
371 g_slice_free1 (pf_size, pf);
376 gst_registry_chunks_save_plugin_dep (GList ** list, GstPluginDep * dep)
378 GstRegistryChunkDep *ed;
379 GstRegistryChunk *chk;
382 ed = g_slice_new (GstRegistryChunkDep);
383 chk = gst_registry_chunks_make_data (ed, sizeof (GstRegistryChunkDep));
385 ed->flags = dep->flags;
390 ed->env_hash = dep->env_hash;
391 ed->stat_hash = dep->stat_hash;
393 for (s = dep->env_vars; s != NULL && *s != NULL; ++s, ++ed->n_env_vars)
394 gst_registry_chunks_save_string (list, g_strdup (*s));
396 for (s = dep->paths; s != NULL && *s != NULL; ++s, ++ed->n_paths)
397 gst_registry_chunks_save_string (list, g_strdup (*s));
399 for (s = dep->names; s != NULL && *s != NULL; ++s, ++ed->n_names)
400 gst_registry_chunks_save_string (list, g_strdup (*s));
402 *list = g_list_prepend (*list, chk);
404 GST_LOG ("Saved external plugin dependency");
409 * _priv_gst_registry_chunks_save_plugin:
411 * Adapt a GstPlugin to our GstRegistryChunkPluginElement structure, and
412 * prepend it as a GstRegistryChunk in the provided list.
416 _priv_gst_registry_chunks_save_plugin (GList ** list, GstRegistry * registry,
419 GstRegistryChunkPluginElement *pe;
420 GstRegistryChunk *chk;
421 GList *plugin_features = NULL;
424 pe = g_slice_new (GstRegistryChunkPluginElement);
426 gst_registry_chunks_make_data (pe,
427 sizeof (GstRegistryChunkPluginElement));
429 pe->file_size = plugin->file_size;
430 pe->file_mtime = plugin->file_mtime;
434 /* pack external deps */
435 for (walk = plugin->priv->deps; walk != NULL; walk = walk->next) {
436 if (!gst_registry_chunks_save_plugin_dep (list, walk->data)) {
437 GST_ERROR ("Could not save external plugin dependency, aborting.");
443 /* pack plugin features */
445 gst_registry_get_feature_list_by_plugin (registry, plugin->desc.name);
446 for (walk = plugin_features; walk; walk = g_list_next (walk), pe->nfeatures++) {
447 GstPluginFeature *feature = GST_PLUGIN_FEATURE (walk->data);
449 if (!gst_registry_chunks_save_feature (list, feature)) {
450 GST_ERROR ("Can't fill plugin feature, aborting.");
455 gst_plugin_feature_list_free (plugin_features);
457 /* pack cache data */
458 if (plugin->priv->cache_data) {
459 gchar *cache_str = gst_structure_to_string (plugin->priv->cache_data);
460 gst_registry_chunks_save_string (list, cache_str);
462 gst_registry_chunks_save_const_string (list, "");
465 /* pack plugin element strings */
466 gst_registry_chunks_save_const_string (list,
467 (plugin->desc.release_datetime) ? plugin->desc.release_datetime : "");
468 gst_registry_chunks_save_const_string (list, plugin->desc.origin);
469 gst_registry_chunks_save_const_string (list, plugin->desc.package);
470 gst_registry_chunks_save_const_string (list, plugin->desc.source);
471 gst_registry_chunks_save_const_string (list, plugin->desc.license);
472 gst_registry_chunks_save_const_string (list, plugin->desc.version);
473 gst_registry_chunks_save_const_string (list, plugin->filename);
474 gst_registry_chunks_save_const_string (list, plugin->desc.description);
475 gst_registry_chunks_save_const_string (list, plugin->desc.name);
477 *list = g_list_prepend (*list, chk);
479 GST_DEBUG ("Found %d features in plugin \"%s\"", pe->nfeatures,
485 gst_plugin_feature_list_free (plugin_features);
486 g_slice_free (GstRegistryChunk, chk);
487 g_slice_free (GstRegistryChunkPluginElement, pe);
492 * gst_registry_chunks_load_pad_template:
494 * Make a new GstStaticPadTemplate from current GstRegistryChunkPadTemplate
497 * Returns: new GstStaticPadTemplate
500 gst_registry_chunks_load_pad_template (GstElementFactory * factory, gchar ** in,
503 GstRegistryChunkPadTemplate *pt;
504 GstStaticPadTemplate *template = NULL;
507 GST_DEBUG ("Reading/casting for GstRegistryChunkPadTemplate at address %p",
509 unpack_element (*in, pt, GstRegistryChunkPadTemplate, end, fail);
511 template = g_slice_new (GstStaticPadTemplate);
512 template->presence = pt->presence;
513 template->direction = (GstPadDirection) pt->direction;
514 template->static_caps.caps = NULL;
516 /* unpack pad template strings */
517 unpack_const_string (*in, template->name_template, end, fail);
518 unpack_const_string (*in, template->static_caps.string, end, fail);
520 __gst_element_factory_add_static_pad_template (factory, template);
521 GST_DEBUG ("Added pad_template %s", template->name_template);
525 GST_INFO ("Reading pad template failed");
527 g_slice_free (GstStaticPadTemplate, template);
532 * gst_registry_chunks_load_feature:
534 * Make a new GstPluginFeature from current binary plugin feature structure
536 * Returns: new GstPluginFeature
539 gst_registry_chunks_load_feature (GstRegistry * registry, gchar ** in,
540 gchar * end, GstPlugin * plugin)
542 GstRegistryChunkPluginFeature *pf = NULL;
543 GstPluginFeature *feature = NULL;
544 const gchar *const_str, *type_name;
545 const gchar *feature_name;
546 const gchar *plugin_name;
551 plugin_name = plugin->desc.name;
553 /* unpack plugin feature strings */
554 unpack_string_nocopy (*in, type_name, end, fail);
556 if (G_UNLIKELY (!type_name)) {
557 GST_ERROR ("No feature type name");
561 /* unpack more plugin feature strings */
562 unpack_string_nocopy (*in, feature_name, end, fail);
564 GST_DEBUG ("Plugin '%s' feature '%s' typename : '%s'", plugin_name,
565 feature_name, type_name);
567 if (G_UNLIKELY (!(type = g_type_from_name (type_name)))) {
568 GST_ERROR ("Unknown type from typename '%s' for plugin '%s'", type_name,
572 if (G_UNLIKELY ((feature = g_object_newv (type, 0, NULL)) == NULL)) {
573 GST_ERROR ("Can't create feature from type");
576 gst_plugin_feature_set_name (feature, feature_name);
578 if (G_UNLIKELY (!GST_IS_PLUGIN_FEATURE (feature))) {
579 GST_ERROR ("typename : '%s' is not a plugin feature", type_name);
583 if (GST_IS_ELEMENT_FACTORY (feature)) {
584 GstRegistryChunkElementFactory *ef;
586 GstElementFactory *factory = GST_ELEMENT_FACTORY_CAST (feature);
588 const gchar *meta_data_str;
591 GST_LOG ("Reading/casting for GstRegistryChunkElementFactory at address %p",
593 unpack_element (*in, ef, GstRegistryChunkElementFactory, end, fail);
594 pf = (GstRegistryChunkPluginFeature *) ef;
596 /* unpack element factory strings */
597 unpack_string_nocopy (*in, meta_data_str, end, fail);
598 if (meta_data_str && *meta_data_str) {
599 factory->metadata = gst_structure_from_string (meta_data_str, NULL);
600 if (!factory->metadata) {
602 ("Error when trying to deserialize structure for metadata '%s'",
607 n = ef->npadtemplates;
608 GST_DEBUG ("Element factory : npadtemplates=%d", n);
610 /* load pad templates */
611 for (i = 0; i < n; i++) {
612 if (G_UNLIKELY (!gst_registry_chunks_load_pad_template (factory, in,
614 GST_ERROR ("Error while loading binary pad template");
620 if (G_UNLIKELY ((n = ef->nuriprotocols))) {
621 GST_DEBUG ("Reading %d UriTypes at address %p", n, *in);
624 factory->uri_type = *((guint *) * in);
625 *in += sizeof (factory->uri_type);
626 /*unpack_element(*in, &factory->uri_type, factory->uri_type, end, fail); */
628 factory->uri_protocols = g_new0 (gchar *, n + 1);
629 for (i = 0; i < n; i++) {
630 unpack_string (*in, str, end, fail);
631 factory->uri_protocols[i] = str;
634 /* load interfaces */
635 if (G_UNLIKELY ((n = ef->ninterfaces))) {
636 GST_DEBUG ("Reading %d Interfaces at address %p", n, *in);
637 for (i = 0; i < n; i++) {
638 unpack_string_nocopy (*in, const_str, end, fail);
639 __gst_element_factory_add_interface (factory, const_str);
642 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
643 GstRegistryChunkTypeFindFactory *tff;
644 GstTypeFindFactory *factory = GST_TYPE_FIND_FACTORY (feature);
648 ("Reading/casting for GstRegistryChunkPluginFeature at address %p",
650 unpack_element (*in, tff, GstRegistryChunkTypeFindFactory, end, fail);
651 pf = (GstRegistryChunkPluginFeature *) tff;
653 /* load typefinder caps */
654 unpack_string_nocopy (*in, const_str, end, fail);
655 if (const_str != NULL && *const_str != '\0')
656 factory->caps = gst_caps_from_string (const_str);
658 factory->caps = NULL;
660 /* load extensions */
661 if (tff->nextensions) {
662 GST_DEBUG ("Reading %d Typefind extensions at address %p",
663 tff->nextensions, *in);
664 factory->extensions = g_new0 (gchar *, tff->nextensions + 1);
665 /* unpack in reverse order to maintain the correct order */
666 for (i = tff->nextensions; i > 0; i--) {
667 unpack_string (*in, str, end, fail);
668 factory->extensions[i - 1] = str;
671 } else if (GST_IS_DEVICE_MONITOR_FACTORY (feature)) {
672 GstRegistryChunkDeviceMonitorFactory *dmf;
673 GstDeviceMonitorFactory *factory = GST_DEVICE_MONITOR_FACTORY (feature);
674 const gchar *meta_data_str;
678 ("Reading/casting for GstRegistryChunkPluginFeature at address %p",
680 unpack_element (*in, dmf, GstRegistryChunkDeviceMonitorFactory, end, fail);
682 pf = (GstRegistryChunkPluginFeature *) dmf;
684 /* unpack element factory strings */
685 unpack_string_nocopy (*in, meta_data_str, end, fail);
686 if (meta_data_str && *meta_data_str) {
687 factory->metadata = gst_structure_from_string (meta_data_str, NULL);
688 if (!factory->metadata) {
690 ("Error when trying to deserialize structure for metadata '%s'",
696 GST_WARNING ("unhandled factory type : %s", G_OBJECT_TYPE_NAME (feature));
700 feature->rank = pf->rank;
702 feature->plugin_name = plugin_name;
703 feature->plugin = plugin;
704 g_object_add_weak_pointer ((GObject *) plugin,
705 (gpointer *) & feature->plugin);
707 gst_registry_add_feature (registry, feature);
708 GST_DEBUG ("Added feature %s, plugin %p %s", GST_OBJECT_NAME (feature),
709 plugin, plugin_name);
715 GST_INFO ("Reading plugin feature failed");
717 if (GST_IS_OBJECT (feature))
718 gst_object_unref (feature);
720 g_object_unref (feature);
726 gst_registry_chunks_load_plugin_dep_strv (gchar ** in, gchar * end, guint n)
733 arr = g_new0 (gchar *, n + 1);
735 unpack_string (*in, arr[n - 1], end, fail);
740 GST_INFO ("Reading plugin dependency strings failed");
745 gst_registry_chunks_load_plugin_dep (GstPlugin * plugin, gchar ** in,
749 GstRegistryChunkDep *d;
753 GST_LOG_OBJECT (plugin, "Unpacking GstRegistryChunkDep from %p", *in);
754 unpack_element (*in, d, GstRegistryChunkDep, end, fail);
756 dep = g_slice_new (GstPluginDep);
758 dep->env_hash = d->env_hash;
759 dep->stat_hash = d->stat_hash;
761 dep->flags = (GstPluginDependencyFlags) d->flags;
763 dep->names = gst_registry_chunks_load_plugin_dep_strv (in, end, d->n_names);
764 dep->paths = gst_registry_chunks_load_plugin_dep_strv (in, end, d->n_paths);
766 gst_registry_chunks_load_plugin_dep_strv (in, end, d->n_env_vars);
768 plugin->priv->deps = g_list_append (plugin->priv->deps, dep);
770 GST_DEBUG_OBJECT (plugin, "Loaded external plugin dependency from registry: "
771 "env_hash: %08x, stat_hash: %08x", dep->env_hash, dep->stat_hash);
772 for (s = dep->env_vars; s != NULL && *s != NULL; ++s)
773 GST_LOG_OBJECT (plugin, " evar: %s", *s);
774 for (s = dep->paths; s != NULL && *s != NULL; ++s)
775 GST_LOG_OBJECT (plugin, " path: %s", *s);
776 for (s = dep->names; s != NULL && *s != NULL; ++s)
777 GST_LOG_OBJECT (plugin, " name: %s", *s);
781 GST_INFO ("Reading plugin dependency failed");
787 * _priv_gst_registry_chunks_load_plugin:
789 * Make a new GstPlugin from current GstRegistryChunkPluginElement structure
790 * and add it to the GstRegistry. Return an offset to the next
791 * GstRegistryChunkPluginElement structure.
794 _priv_gst_registry_chunks_load_plugin (GstRegistry * registry, gchar ** in,
795 gchar * end, GstPlugin ** out_plugin)
797 #ifndef GST_DISABLE_GST_DEBUG
800 GstRegistryChunkPluginElement *pe;
801 const gchar *cache_str = NULL;
802 GstPlugin *plugin = NULL;
806 GST_LOG ("Reading/casting for GstRegistryChunkPluginElement at address %p",
808 unpack_element (*in, pe, GstRegistryChunkPluginElement, end, fail);
810 plugin = g_object_newv (GST_TYPE_PLUGIN, 0, NULL);
812 /* TODO: also set GST_PLUGIN_FLAG_CONST */
813 GST_OBJECT_FLAG_SET (plugin, GST_PLUGIN_FLAG_CACHED);
814 plugin->file_mtime = pe->file_mtime;
815 plugin->file_size = pe->file_size;
817 /* unpack plugin element strings */
818 unpack_const_string (*in, plugin->desc.name, end, fail);
819 unpack_const_string (*in, plugin->desc.description, end, fail);
820 unpack_string (*in, plugin->filename, end, fail);
821 unpack_const_string (*in, plugin->desc.version, end, fail);
822 unpack_const_string (*in, plugin->desc.license, end, fail);
823 unpack_const_string (*in, plugin->desc.source, end, fail);
824 unpack_const_string (*in, plugin->desc.package, end, fail);
825 unpack_const_string (*in, plugin->desc.origin, end, fail);
826 unpack_const_string (*in, plugin->desc.release_datetime, end, fail);
828 GST_LOG ("read strings for name='%s'", plugin->desc.name);
829 GST_LOG (" desc.description='%s'", plugin->desc.description);
830 GST_LOG (" filename='%s'", plugin->filename);
831 GST_LOG (" desc.version='%s'", plugin->desc.version);
832 GST_LOG (" desc.license='%s'", plugin->desc.license);
833 GST_LOG (" desc.source='%s'", plugin->desc.source);
834 GST_LOG (" desc.package='%s'", plugin->desc.package);
835 GST_LOG (" desc.origin='%s'", plugin->desc.origin);
836 GST_LOG (" desc.datetime=%s", plugin->desc.release_datetime);
838 if (plugin->desc.release_datetime[0] == '\0')
839 plugin->desc.release_datetime = NULL;
841 /* unpack cache data */
842 unpack_string_nocopy (*in, cache_str, end, fail);
843 if (cache_str != NULL && *cache_str != '\0')
844 plugin->priv->cache_data = gst_structure_from_string (cache_str, NULL);
846 /* If the license string is 'BLACKLIST', mark this as a blacklisted
848 if (strcmp (plugin->desc.license, "BLACKLIST") == 0)
849 GST_OBJECT_FLAG_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED);
851 plugin->basename = g_path_get_basename (plugin->filename);
853 /* Takes ownership of plugin */
854 gst_registry_add_plugin (registry, plugin);
856 GST_DEBUG ("Added plugin '%s' plugin with %d features from binary registry",
857 plugin->desc.name, n);
859 /* Load plugin features */
860 for (i = 0; i < n; i++) {
861 if (G_UNLIKELY (!gst_registry_chunks_load_feature (registry, in, end,
863 GST_ERROR ("Error while loading binary feature for plugin '%s'",
864 GST_STR_NULL (plugin->desc.name));
865 gst_registry_remove_plugin (registry, plugin);
870 /* Load external plugin dependencies */
871 for (i = 0; i < pe->n_deps; ++i) {
872 if (G_UNLIKELY (!gst_registry_chunks_load_plugin_dep (plugin, in, end))) {
873 GST_ERROR_OBJECT (plugin, "Could not read external plugin dependency "
874 "for plugin '%s'", GST_STR_NULL (plugin->desc.name));
875 gst_registry_remove_plugin (registry, plugin);
881 *out_plugin = plugin;
887 GST_INFO ("Reading plugin failed after %u bytes", (guint) (end - start));
892 _priv_gst_registry_chunks_save_global_header (GList ** list,
893 GstRegistry * registry, guint32 filter_env_hash)
895 GstRegistryChunkGlobalHeader *hdr;
896 GstRegistryChunk *chk;
898 hdr = g_slice_new (GstRegistryChunkGlobalHeader);
899 chk = gst_registry_chunks_make_data (hdr,
900 sizeof (GstRegistryChunkGlobalHeader));
902 hdr->filter_env_hash = filter_env_hash;
904 *list = g_list_prepend (*list, chk);
906 GST_LOG ("Saved global header (filter_env_hash=0x%08x)", filter_env_hash);
910 _priv_gst_registry_chunks_load_global_header (GstRegistry * registry,
911 gchar ** in, gchar * end, guint32 * filter_env_hash)
913 GstRegistryChunkGlobalHeader *hdr;
916 GST_LOG ("Reading/casting for GstRegistryChunkGlobalHeader at %p", *in);
917 unpack_element (*in, hdr, GstRegistryChunkGlobalHeader, end, fail);
918 *filter_env_hash = hdr->filter_env_hash;
923 GST_WARNING ("Reading global header failed");