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/gsttracerfactory.h>
35 #include <gst/gsttypefind.h>
36 #include <gst/gsttypefindfactory.h>
37 #include <gst/gstdeviceproviderfactory.h>
38 #include <gst/gsturi.h>
39 #include <gst/gstinfo.h>
40 #include <gst/gstenumtypes.h>
41 #include <gst/gstpadtemplate.h>
43 #include <gst/gstregistrychunks.h>
45 #define GST_CAT_DEFAULT GST_CAT_REGISTRY
47 /* count string length, but return -1 if we hit the eof */
49 _strnlen (const gchar * str, gint maxlen)
53 while (G_LIKELY (len < maxlen)) {
54 if (G_UNLIKELY (str[len] == '\0'))
62 #define unpack_element(inptr, outptr, element, endptr, error_label) G_STMT_START{ \
63 if (inptr + sizeof(element) > endptr) { \
64 GST_ERROR ("Failed reading element " G_STRINGIFY (element) \
65 ". Have %d bytes need %" G_GSIZE_FORMAT, \
66 (int) (endptr - inptr), sizeof(element)); \
69 outptr = (element *) inptr; \
70 inptr += sizeof (element); \
73 #define unpack_const_string(inptr, outptr, endptr, error_label) G_STMT_START{\
74 gint _len = _strnlen (inptr, (endptr-inptr)); \
77 outptr = g_intern_string ((const gchar *)inptr); \
81 #define unpack_string(inptr, outptr, endptr, error_label) G_STMT_START{\
82 gint _len = _strnlen (inptr, (endptr-inptr)); \
85 outptr = g_memdup ((gconstpointer)inptr, _len + 1); \
89 #define unpack_string_nocopy(inptr, outptr, endptr, error_label) G_STMT_START{\
90 gint _len = _strnlen (inptr, (endptr-inptr)); \
93 outptr = (const gchar *)inptr; \
97 #define ALIGNMENT (sizeof (void *))
98 #define alignment(_address) (gsize)_address%ALIGNMENT
99 #define align(_ptr) _ptr += (( alignment(_ptr) == 0) ? 0 : ALIGNMENT-alignment(_ptr))
102 _priv_gst_registry_chunk_free (GstRegistryChunk * chunk)
104 if (!(chunk->flags & GST_REGISTRY_CHUNK_FLAG_CONST)) {
105 if ((chunk->flags & GST_REGISTRY_CHUNK_FLAG_MALLOC))
106 g_free (chunk->data);
108 g_slice_free1 (chunk->size, chunk->data);
110 g_slice_free (GstRegistryChunk, chunk);
114 * gst_registry_chunks_save_const_string:
116 * Store a const string in a binary chunk.
118 * Returns: %TRUE for success
120 inline static gboolean
121 gst_registry_chunks_save_const_string (GList ** list, const gchar * str)
123 GstRegistryChunk *chunk;
125 if (G_UNLIKELY (str == NULL)) {
126 GST_ERROR ("unexpected NULL string in plugin or plugin feature data");
130 chunk = g_slice_new (GstRegistryChunk);
131 chunk->data = (gpointer) str;
132 chunk->size = strlen ((gchar *) chunk->data) + 1;
133 chunk->flags = GST_REGISTRY_CHUNK_FLAG_CONST;
134 chunk->align = FALSE;
135 *list = g_list_prepend (*list, chunk);
140 * gst_registry_chunks_save_string:
142 * Store a string in a binary chunk.
144 * Returns: %TRUE for success
146 inline static gboolean
147 gst_registry_chunks_save_string (GList ** list, gchar * str)
149 GstRegistryChunk *chunk;
151 chunk = g_slice_new (GstRegistryChunk);
153 chunk->size = strlen ((gchar *) chunk->data) + 1;
154 chunk->flags = GST_REGISTRY_CHUNK_FLAG_MALLOC;
155 chunk->align = FALSE;
156 *list = g_list_prepend (*list, chunk);
161 * gst_registry_chunks_save_data:
163 * Store some data in a binary chunk.
165 * Returns: the initialized chunk
167 inline static GstRegistryChunk *
168 gst_registry_chunks_make_data (gpointer data, gulong size)
170 GstRegistryChunk *chunk;
172 chunk = g_slice_new (GstRegistryChunk);
175 chunk->flags = GST_REGISTRY_CHUNK_FLAG_NONE;
182 * gst_registry_chunks_save_pad_template:
184 * Store pad_templates in binary chunks.
186 * Returns: %TRUE for success
189 gst_registry_chunks_save_pad_template (GList ** list,
190 GstStaticPadTemplate * template)
192 GstRegistryChunkPadTemplate *pt;
193 GstRegistryChunk *chk;
195 pt = g_slice_new (GstRegistryChunkPadTemplate);
197 gst_registry_chunks_make_data (pt, sizeof (GstRegistryChunkPadTemplate));
199 pt->presence = template->presence;
200 pt->direction = template->direction;
202 /* pack pad template strings */
203 gst_registry_chunks_save_const_string (list,
204 (gchar *) (template->static_caps.string));
205 gst_registry_chunks_save_const_string (list, template->name_template);
207 *list = g_list_prepend (*list, chk);
213 * gst_registry_chunks_save_feature:
215 * Store features in binary chunks.
217 * Returns: %TRUE for success
220 gst_registry_chunks_save_feature (GList ** list, GstPluginFeature * feature)
222 const gchar *type_name = G_OBJECT_TYPE_NAME (feature);
223 GstRegistryChunkPluginFeature *pf = NULL;
224 GstRegistryChunk *chk = NULL;
229 GST_ERROR ("NULL feature type_name, aborting.");
233 if (GST_IS_ELEMENT_FACTORY (feature)) {
234 GstRegistryChunkElementFactory *ef;
235 GstElementFactory *factory = GST_ELEMENT_FACTORY (feature);
237 /* Initialize with zeroes because of struct padding and
238 * valgrind complaining about copying unitialized memory
240 ef = g_slice_new0 (GstRegistryChunkElementFactory);
241 pf_size = sizeof (GstRegistryChunkElementFactory);
242 chk = gst_registry_chunks_make_data (ef, pf_size);
243 ef->npadtemplates = ef->ninterfaces = ef->nuriprotocols = 0;
244 pf = (GstRegistryChunkPluginFeature *) ef;
246 /* save interfaces */
247 for (walk = factory->interfaces; walk;
248 walk = g_list_next (walk), ef->ninterfaces++) {
249 gst_registry_chunks_save_const_string (list, (gchar *) walk->data);
251 GST_DEBUG_OBJECT (feature, "saved %d interfaces %d pad templates",
252 ef->ninterfaces, ef->npadtemplates);
255 if (GST_URI_TYPE_IS_VALID (factory->uri_type)) {
256 if (factory->uri_protocols && *factory->uri_protocols) {
257 GstRegistryChunk *subchk;
261 gst_registry_chunks_make_data (&factory->uri_type,
262 sizeof (factory->uri_type));
263 subchk->flags = GST_REGISTRY_CHUNK_FLAG_CONST;
265 protocol = factory->uri_protocols;
267 gst_registry_chunks_save_const_string (list, *protocol++);
270 *list = g_list_prepend (*list, subchk);
271 GST_DEBUG_OBJECT (feature, "Saved %d UriTypes", ef->nuriprotocols);
273 g_warning ("GStreamer feature '%s' is URI handler but does not provide"
274 " any protocols it can handle", GST_OBJECT_NAME (feature));
278 /* save pad-templates */
279 for (walk = factory->staticpadtemplates; walk;
280 walk = g_list_next (walk), ef->npadtemplates++) {
281 GstStaticPadTemplate *template = walk->data;
283 if (!gst_registry_chunks_save_pad_template (list, template)) {
284 GST_ERROR_OBJECT (feature, "Can't fill pad template, aborting.");
289 /* pack element metadata strings */
290 gst_registry_chunks_save_string (list,
291 gst_structure_to_string (factory->metadata));
292 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
293 GstRegistryChunkTypeFindFactory *tff;
294 GstTypeFindFactory *factory = GST_TYPE_FIND_FACTORY (feature);
297 /* Initialize with zeroes because of struct padding and
298 * valgrind complaining about copying unitialized memory
300 tff = g_slice_new0 (GstRegistryChunkTypeFindFactory);
301 pf_size = sizeof (GstRegistryChunkTypeFindFactory);
302 chk = gst_registry_chunks_make_data (tff, pf_size);
303 tff->nextensions = 0;
304 pf = (GstRegistryChunkPluginFeature *) tff;
306 /* save extensions */
307 if (factory->extensions) {
308 while (factory->extensions[tff->nextensions]) {
309 gst_registry_chunks_save_const_string (list,
310 factory->extensions[tff->nextensions++]);
313 GST_DEBUG_OBJECT (feature, "saved %d extensions", tff->nextensions);
316 GstCaps *fcaps = gst_caps_ref (factory->caps);
317 /* we simplify the caps before saving. This is a lot faster
318 * when loading them later on */
319 fcaps = gst_caps_simplify (fcaps);
320 str = gst_caps_to_string (fcaps);
321 gst_caps_unref (fcaps);
323 gst_registry_chunks_save_string (list, str);
325 gst_registry_chunks_save_const_string (list, "");
327 } else if (GST_IS_DEVICE_PROVIDER_FACTORY (feature)) {
328 GstRegistryChunkDeviceProviderFactory *tff;
329 GstDeviceProviderFactory *factory = GST_DEVICE_PROVIDER_FACTORY (feature);
331 /* Initialize with zeroes because of struct padding and
332 * valgrind complaining about copying unitialized memory
334 tff = g_slice_new0 (GstRegistryChunkDeviceProviderFactory);
336 gst_registry_chunks_make_data (tff,
337 sizeof (GstRegistryChunkDeviceProviderFactory));
338 pf = (GstRegistryChunkPluginFeature *) tff;
341 /* pack element metadata strings */
342 gst_registry_chunks_save_string (list,
343 gst_structure_to_string (factory->metadata));
344 } else if (GST_IS_TRACER_FACTORY (feature)) {
345 /* Initialize with zeroes because of struct padding and
346 * valgrind complaining about copying unitialized memory
348 pf = g_slice_new0 (GstRegistryChunkPluginFeature);
349 pf_size = sizeof (GstRegistryChunkPluginFeature);
350 chk = gst_registry_chunks_make_data (pf, pf_size);
352 GST_WARNING_OBJECT (feature, "unhandled feature type '%s'", type_name);
356 pf->rank = feature->rank;
357 *list = g_list_prepend (*list, chk);
359 /* pack plugin feature strings */
360 gst_registry_chunks_save_const_string (list, GST_OBJECT_NAME (feature));
361 gst_registry_chunks_save_const_string (list, (gchar *) type_name);
368 g_slice_free (GstRegistryChunk, chk);
369 g_slice_free1 (pf_size, pf);
374 gst_registry_chunks_save_plugin_dep (GList ** list, GstPluginDep * dep)
376 GstRegistryChunkDep *ed;
377 GstRegistryChunk *chk;
380 ed = g_slice_new (GstRegistryChunkDep);
381 chk = gst_registry_chunks_make_data (ed, sizeof (GstRegistryChunkDep));
383 ed->flags = dep->flags;
388 ed->env_hash = dep->env_hash;
389 ed->stat_hash = dep->stat_hash;
391 for (s = dep->env_vars; s != NULL && *s != NULL; ++s, ++ed->n_env_vars)
392 gst_registry_chunks_save_string (list, g_strdup (*s));
394 for (s = dep->paths; s != NULL && *s != NULL; ++s, ++ed->n_paths)
395 gst_registry_chunks_save_string (list, g_strdup (*s));
397 for (s = dep->names; s != NULL && *s != NULL; ++s, ++ed->n_names)
398 gst_registry_chunks_save_string (list, g_strdup (*s));
400 *list = g_list_prepend (*list, chk);
402 GST_LOG ("Saved external plugin dependency");
407 * _priv_gst_registry_chunks_save_plugin:
409 * Adapt a GstPlugin to our GstRegistryChunkPluginElement structure, and
410 * prepend it as a GstRegistryChunk in the provided list.
414 _priv_gst_registry_chunks_save_plugin (GList ** list, GstRegistry * registry,
417 GstRegistryChunkPluginElement *pe;
418 GstRegistryChunk *chk;
419 GList *plugin_features = NULL;
422 pe = g_slice_new (GstRegistryChunkPluginElement);
424 gst_registry_chunks_make_data (pe,
425 sizeof (GstRegistryChunkPluginElement));
427 pe->file_size = plugin->file_size;
428 pe->file_mtime = plugin->file_mtime;
432 /* pack external deps */
433 for (walk = plugin->priv->deps; walk != NULL; walk = walk->next) {
434 if (!gst_registry_chunks_save_plugin_dep (list, walk->data)) {
435 GST_ERROR ("Could not save external plugin dependency, aborting.");
441 /* pack plugin features */
443 gst_registry_get_feature_list_by_plugin (registry, plugin->desc.name);
444 for (walk = plugin_features; walk; walk = g_list_next (walk), pe->nfeatures++) {
445 GstPluginFeature *feature = GST_PLUGIN_FEATURE (walk->data);
447 if (!gst_registry_chunks_save_feature (list, feature)) {
448 GST_ERROR ("Can't fill plugin feature, aborting.");
453 gst_plugin_feature_list_free (plugin_features);
455 /* pack cache data */
456 if (plugin->priv->cache_data) {
457 gchar *cache_str = gst_structure_to_string (plugin->priv->cache_data);
458 gst_registry_chunks_save_string (list, cache_str);
460 gst_registry_chunks_save_const_string (list, "");
463 /* pack plugin element strings */
464 gst_registry_chunks_save_const_string (list,
465 (plugin->desc.release_datetime) ? plugin->desc.release_datetime : "");
466 gst_registry_chunks_save_const_string (list, plugin->desc.origin);
467 gst_registry_chunks_save_const_string (list, plugin->desc.package);
468 gst_registry_chunks_save_const_string (list, plugin->desc.source);
469 gst_registry_chunks_save_const_string (list, plugin->desc.license);
470 gst_registry_chunks_save_const_string (list, plugin->desc.version);
471 gst_registry_chunks_save_const_string (list, plugin->filename);
472 gst_registry_chunks_save_const_string (list, plugin->desc.description);
473 gst_registry_chunks_save_const_string (list, plugin->desc.name);
475 *list = g_list_prepend (*list, chk);
477 GST_DEBUG ("Found %d features in plugin \"%s\"", pe->nfeatures,
483 gst_plugin_feature_list_free (plugin_features);
484 g_slice_free (GstRegistryChunk, chk);
485 g_slice_free (GstRegistryChunkPluginElement, pe);
490 * gst_registry_chunks_load_pad_template:
492 * Make a new GstStaticPadTemplate from current GstRegistryChunkPadTemplate
495 * Returns: new GstStaticPadTemplate
498 gst_registry_chunks_load_pad_template (GstElementFactory * factory, gchar ** in,
501 GstRegistryChunkPadTemplate *pt;
502 GstStaticPadTemplate *template = NULL;
505 GST_DEBUG ("Reading/casting for GstRegistryChunkPadTemplate at address %p",
507 unpack_element (*in, pt, GstRegistryChunkPadTemplate, end, fail);
509 template = g_slice_new (GstStaticPadTemplate);
510 template->presence = pt->presence;
511 template->direction = (GstPadDirection) pt->direction;
512 template->static_caps.caps = NULL;
514 /* unpack pad template strings */
515 unpack_const_string (*in, template->name_template, end, fail);
516 unpack_const_string (*in, template->static_caps.string, end, fail);
518 __gst_element_factory_add_static_pad_template (factory, template);
519 GST_DEBUG ("Added pad_template %s", template->name_template);
523 GST_INFO ("Reading pad template failed");
525 g_slice_free (GstStaticPadTemplate, template);
530 * gst_registry_chunks_load_feature:
532 * Make a new GstPluginFeature from current binary plugin feature structure
534 * Returns: new GstPluginFeature
537 gst_registry_chunks_load_feature (GstRegistry * registry, gchar ** in,
538 gchar * end, GstPlugin * plugin)
540 GstRegistryChunkPluginFeature *pf = NULL;
541 GstPluginFeature *feature = NULL;
542 const gchar *const_str, *type_name;
543 const gchar *feature_name;
544 const gchar *plugin_name;
549 plugin_name = plugin->desc.name;
551 /* unpack plugin feature strings */
552 unpack_string_nocopy (*in, type_name, end, fail);
554 if (G_UNLIKELY (!type_name)) {
555 GST_ERROR ("No feature type name");
559 /* unpack more plugin feature strings */
560 unpack_string_nocopy (*in, feature_name, end, fail);
562 GST_DEBUG ("Plugin '%s' feature '%s' typename : '%s'", plugin_name,
563 feature_name, type_name);
565 if (G_UNLIKELY (!(type = g_type_from_name (type_name)))) {
566 GST_ERROR ("Unknown type from typename '%s' for plugin '%s'", type_name,
570 if (G_UNLIKELY ((feature = g_object_newv (type, 0, NULL)) == NULL)) {
571 GST_ERROR ("Can't create feature from type");
574 gst_plugin_feature_set_name (feature, feature_name);
576 if (G_UNLIKELY (!GST_IS_PLUGIN_FEATURE (feature))) {
577 GST_ERROR ("typename : '%s' is not a plugin feature", type_name);
581 if (GST_IS_ELEMENT_FACTORY (feature)) {
582 GstRegistryChunkElementFactory *ef;
584 GstElementFactory *factory = GST_ELEMENT_FACTORY_CAST (feature);
586 const gchar *meta_data_str;
589 GST_LOG ("Reading/casting for GstRegistryChunkElementFactory at address %p",
591 unpack_element (*in, ef, GstRegistryChunkElementFactory, end, fail);
592 pf = (GstRegistryChunkPluginFeature *) ef;
594 /* unpack element factory strings */
595 unpack_string_nocopy (*in, meta_data_str, end, fail);
596 if (meta_data_str && *meta_data_str) {
597 factory->metadata = gst_structure_from_string (meta_data_str, NULL);
598 if (!factory->metadata) {
600 ("Error when trying to deserialize structure for metadata '%s'",
605 n = ef->npadtemplates;
606 GST_DEBUG ("Element factory : npadtemplates=%d", n);
608 /* load pad templates */
609 for (i = 0; i < n; i++) {
610 if (G_UNLIKELY (!gst_registry_chunks_load_pad_template (factory, in,
612 GST_ERROR ("Error while loading binary pad template");
618 if (G_UNLIKELY ((n = ef->nuriprotocols))) {
619 GST_DEBUG ("Reading %d UriTypes at address %p", n, *in);
622 factory->uri_type = *((guint *) * in);
623 *in += sizeof (factory->uri_type);
624 /*unpack_element(*in, &factory->uri_type, factory->uri_type, end, fail); */
626 factory->uri_protocols = g_new0 (gchar *, n + 1);
627 for (i = 0; i < n; i++) {
628 unpack_string (*in, str, end, fail);
629 factory->uri_protocols[i] = str;
632 /* load interfaces */
633 if (G_UNLIKELY ((n = ef->ninterfaces))) {
634 GST_DEBUG ("Reading %d Interfaces at address %p", n, *in);
635 for (i = 0; i < n; i++) {
636 unpack_string_nocopy (*in, const_str, end, fail);
637 __gst_element_factory_add_interface (factory, const_str);
640 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
641 GstRegistryChunkTypeFindFactory *tff;
642 GstTypeFindFactory *factory = GST_TYPE_FIND_FACTORY (feature);
646 ("Reading/casting for GstRegistryChunkPluginFeature at address %p",
648 unpack_element (*in, tff, GstRegistryChunkTypeFindFactory, end, fail);
649 pf = (GstRegistryChunkPluginFeature *) tff;
651 /* load typefinder caps */
652 unpack_string_nocopy (*in, const_str, end, fail);
653 if (const_str != NULL && *const_str != '\0')
654 factory->caps = gst_caps_from_string (const_str);
656 factory->caps = NULL;
658 /* load extensions */
659 if (tff->nextensions) {
660 GST_DEBUG ("Reading %d Typefind extensions at address %p",
661 tff->nextensions, *in);
662 factory->extensions = g_new0 (gchar *, tff->nextensions + 1);
663 /* unpack in reverse order to maintain the correct order */
664 for (i = tff->nextensions; i > 0; i--) {
665 unpack_string (*in, str, end, fail);
666 factory->extensions[i - 1] = str;
669 } else if (GST_IS_DEVICE_PROVIDER_FACTORY (feature)) {
670 GstRegistryChunkDeviceProviderFactory *dmf;
671 GstDeviceProviderFactory *factory = GST_DEVICE_PROVIDER_FACTORY (feature);
672 const gchar *meta_data_str;
676 ("Reading/casting for GstRegistryChunkPluginFeature at address %p",
679 unpack_element (*in, dmf, GstRegistryChunkDeviceProviderFactory, end, fail);
681 pf = (GstRegistryChunkPluginFeature *) dmf;
683 /* unpack element factory strings */
684 unpack_string_nocopy (*in, meta_data_str, end, fail);
685 if (meta_data_str && *meta_data_str) {
686 factory->metadata = gst_structure_from_string (meta_data_str, NULL);
687 if (!factory->metadata) {
689 ("Error when trying to deserialize structure for metadata '%s'",
694 } else if (GST_IS_TRACER_FACTORY (feature)) {
697 ("Reading/casting for GstRegistryChunkPluginFeature at address %p",
699 unpack_element (*in, pf, GstRegistryChunkPluginFeature, end, fail);
701 GST_WARNING ("unhandled factory type : %s", G_OBJECT_TYPE_NAME (feature));
705 feature->rank = pf->rank;
707 feature->plugin_name = plugin_name;
708 feature->plugin = plugin;
709 g_object_add_weak_pointer ((GObject *) plugin,
710 (gpointer *) & feature->plugin);
712 gst_registry_add_feature (registry, feature);
713 GST_DEBUG ("Added feature %s, plugin %p %s", GST_OBJECT_NAME (feature),
714 plugin, plugin_name);
720 GST_INFO ("Reading plugin feature failed");
722 if (GST_IS_OBJECT (feature))
723 gst_object_unref (feature);
725 g_object_unref (feature);
731 gst_registry_chunks_load_plugin_dep_strv (gchar ** in, gchar * end, guint n)
738 arr = g_new0 (gchar *, n + 1);
740 unpack_string (*in, arr[n - 1], end, fail);
745 GST_INFO ("Reading plugin dependency strings failed");
750 gst_registry_chunks_load_plugin_dep (GstPlugin * plugin, gchar ** in,
754 GstRegistryChunkDep *d;
758 GST_LOG_OBJECT (plugin, "Unpacking GstRegistryChunkDep from %p", *in);
759 unpack_element (*in, d, GstRegistryChunkDep, end, fail);
761 dep = g_slice_new (GstPluginDep);
763 dep->env_hash = d->env_hash;
764 dep->stat_hash = d->stat_hash;
766 dep->flags = (GstPluginDependencyFlags) d->flags;
768 dep->names = gst_registry_chunks_load_plugin_dep_strv (in, end, d->n_names);
769 dep->paths = gst_registry_chunks_load_plugin_dep_strv (in, end, d->n_paths);
771 gst_registry_chunks_load_plugin_dep_strv (in, end, d->n_env_vars);
773 plugin->priv->deps = g_list_append (plugin->priv->deps, dep);
775 GST_DEBUG_OBJECT (plugin, "Loaded external plugin dependency from registry: "
776 "env_hash: %08x, stat_hash: %08x", dep->env_hash, dep->stat_hash);
777 for (s = dep->env_vars; s != NULL && *s != NULL; ++s)
778 GST_LOG_OBJECT (plugin, " evar: %s", *s);
779 for (s = dep->paths; s != NULL && *s != NULL; ++s)
780 GST_LOG_OBJECT (plugin, " path: %s", *s);
781 for (s = dep->names; s != NULL && *s != NULL; ++s)
782 GST_LOG_OBJECT (plugin, " name: %s", *s);
786 GST_INFO ("Reading plugin dependency failed");
792 * _priv_gst_registry_chunks_load_plugin:
794 * Make a new GstPlugin from current GstRegistryChunkPluginElement structure
795 * and add it to the GstRegistry. Return an offset to the next
796 * GstRegistryChunkPluginElement structure.
799 _priv_gst_registry_chunks_load_plugin (GstRegistry * registry, gchar ** in,
800 gchar * end, GstPlugin ** out_plugin)
802 #ifndef GST_DISABLE_GST_DEBUG
805 GstRegistryChunkPluginElement *pe;
806 const gchar *cache_str = NULL;
807 GstPlugin *plugin = NULL;
811 GST_LOG ("Reading/casting for GstRegistryChunkPluginElement at address %p",
813 unpack_element (*in, pe, GstRegistryChunkPluginElement, end, fail);
815 plugin = g_object_newv (GST_TYPE_PLUGIN, 0, NULL);
817 /* TODO: also set GST_PLUGIN_FLAG_CONST */
818 GST_OBJECT_FLAG_SET (plugin, GST_PLUGIN_FLAG_CACHED);
819 plugin->file_mtime = pe->file_mtime;
820 plugin->file_size = pe->file_size;
822 /* unpack plugin element strings */
823 unpack_const_string (*in, plugin->desc.name, end, fail);
824 unpack_const_string (*in, plugin->desc.description, end, fail);
825 unpack_string (*in, plugin->filename, end, fail);
826 unpack_const_string (*in, plugin->desc.version, end, fail);
827 unpack_const_string (*in, plugin->desc.license, end, fail);
828 unpack_const_string (*in, plugin->desc.source, end, fail);
829 unpack_const_string (*in, plugin->desc.package, end, fail);
830 unpack_const_string (*in, plugin->desc.origin, end, fail);
831 unpack_const_string (*in, plugin->desc.release_datetime, end, fail);
833 GST_LOG ("read strings for name='%s'", plugin->desc.name);
834 GST_LOG (" desc.description='%s'", plugin->desc.description);
835 GST_LOG (" filename='%s'", plugin->filename);
836 GST_LOG (" desc.version='%s'", plugin->desc.version);
837 GST_LOG (" desc.license='%s'", plugin->desc.license);
838 GST_LOG (" desc.source='%s'", plugin->desc.source);
839 GST_LOG (" desc.package='%s'", plugin->desc.package);
840 GST_LOG (" desc.origin='%s'", plugin->desc.origin);
841 GST_LOG (" desc.datetime=%s", plugin->desc.release_datetime);
843 if (plugin->desc.release_datetime[0] == '\0')
844 plugin->desc.release_datetime = NULL;
846 /* unpack cache data */
847 unpack_string_nocopy (*in, cache_str, end, fail);
848 if (cache_str != NULL && *cache_str != '\0')
849 plugin->priv->cache_data = gst_structure_from_string (cache_str, NULL);
851 /* If the license string is 'BLACKLIST', mark this as a blacklisted
853 if (strcmp (plugin->desc.license, "BLACKLIST") == 0)
854 GST_OBJECT_FLAG_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED);
856 plugin->basename = g_path_get_basename (plugin->filename);
858 /* Takes ownership of plugin */
859 gst_registry_add_plugin (registry, plugin);
861 GST_DEBUG ("Added plugin '%s' plugin with %d features from binary registry",
862 plugin->desc.name, n);
864 /* Load plugin features */
865 for (i = 0; i < n; i++) {
866 if (G_UNLIKELY (!gst_registry_chunks_load_feature (registry, in, end,
868 GST_ERROR ("Error while loading binary feature for plugin '%s'",
869 GST_STR_NULL (plugin->desc.name));
870 gst_registry_remove_plugin (registry, plugin);
875 /* Load external plugin dependencies */
876 for (i = 0; i < pe->n_deps; ++i) {
877 if (G_UNLIKELY (!gst_registry_chunks_load_plugin_dep (plugin, in, end))) {
878 GST_ERROR_OBJECT (plugin, "Could not read external plugin dependency "
879 "for plugin '%s'", GST_STR_NULL (plugin->desc.name));
880 gst_registry_remove_plugin (registry, plugin);
886 *out_plugin = plugin;
892 GST_INFO ("Reading plugin failed after %u bytes", (guint) (end - start));
897 _priv_gst_registry_chunks_save_global_header (GList ** list,
898 GstRegistry * registry, guint32 filter_env_hash)
900 GstRegistryChunkGlobalHeader *hdr;
901 GstRegistryChunk *chk;
903 hdr = g_slice_new (GstRegistryChunkGlobalHeader);
904 chk = gst_registry_chunks_make_data (hdr,
905 sizeof (GstRegistryChunkGlobalHeader));
907 hdr->filter_env_hash = filter_env_hash;
909 *list = g_list_prepend (*list, chk);
911 GST_LOG ("Saved global header (filter_env_hash=0x%08x)", filter_env_hash);
915 _priv_gst_registry_chunks_load_global_header (GstRegistry * registry,
916 gchar ** in, gchar * end, guint32 * filter_env_hash)
918 GstRegistryChunkGlobalHeader *hdr;
921 GST_LOG ("Reading/casting for GstRegistryChunkGlobalHeader at %p", *in);
922 unpack_element (*in, hdr, GstRegistryChunkGlobalHeader, end, fail);
923 *filter_env_hash = hdr->filter_env_hash;
928 GST_WARNING ("Reading global header failed");