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/gstdynamictypefactory.h>
39 #include <gst/gsturi.h>
40 #include <gst/gstinfo.h>
41 #include <gst/gstenumtypes.h>
42 #include <gst/gstpadtemplate.h>
44 #include <gst/gstregistrychunks.h>
46 #define GST_CAT_DEFAULT GST_CAT_REGISTRY
48 /* count string length, but return -1 if we hit the eof */
50 _strnlen (const gchar * str, gint maxlen)
54 while (G_LIKELY (len < maxlen)) {
55 if (G_UNLIKELY (str[len] == '\0'))
63 #define unpack_element(inptr, outptr, element, endptr, error_label) G_STMT_START{ \
64 if (inptr + sizeof(element) > endptr) { \
65 GST_ERROR ("Failed reading element " G_STRINGIFY (element) \
66 ". Have %d bytes need %" G_GSIZE_FORMAT, \
67 (int) (endptr - inptr), sizeof(element)); \
70 outptr = (element *) inptr; \
71 inptr += sizeof (element); \
74 #define unpack_const_string(inptr, outptr, endptr, error_label) G_STMT_START{\
75 gint _len = _strnlen (inptr, (endptr-inptr)); \
78 outptr = g_intern_string ((const gchar *)inptr); \
82 #define unpack_string(inptr, outptr, endptr, error_label) G_STMT_START{\
83 gint _len = _strnlen (inptr, (endptr-inptr)); \
86 outptr = g_memdup ((gconstpointer)inptr, _len + 1); \
90 #define unpack_string_nocopy(inptr, outptr, endptr, error_label) G_STMT_START{\
91 gint _len = _strnlen (inptr, (endptr-inptr)); \
94 outptr = (const gchar *)inptr; \
98 #define ALIGNMENT (sizeof (void *))
99 #define alignment(_address) (gsize)_address%ALIGNMENT
100 #define align(_ptr) _ptr += (( alignment(_ptr) == 0) ? 0 : ALIGNMENT-alignment(_ptr))
103 _priv_gst_registry_chunk_free (GstRegistryChunk * chunk)
105 if (!(chunk->flags & GST_REGISTRY_CHUNK_FLAG_CONST)) {
106 if ((chunk->flags & GST_REGISTRY_CHUNK_FLAG_MALLOC))
107 g_free (chunk->data);
109 g_slice_free1 (chunk->size, chunk->data);
111 g_slice_free (GstRegistryChunk, chunk);
115 * gst_registry_chunks_save_const_string:
117 * Store a const string in a binary chunk.
119 * Returns: %TRUE for success
121 inline static gboolean
122 gst_registry_chunks_save_const_string (GList ** list, const gchar * str)
124 GstRegistryChunk *chunk;
126 if (G_UNLIKELY (str == NULL)) {
127 GST_ERROR ("unexpected NULL string in plugin or plugin feature data");
131 chunk = g_slice_new (GstRegistryChunk);
132 chunk->data = (gpointer) str;
133 chunk->size = strlen ((gchar *) chunk->data) + 1;
134 chunk->flags = GST_REGISTRY_CHUNK_FLAG_CONST;
135 chunk->align = FALSE;
136 *list = g_list_prepend (*list, chunk);
141 * gst_registry_chunks_save_string:
143 * Store a string in a binary chunk.
145 * Returns: %TRUE for success
147 inline static gboolean
148 gst_registry_chunks_save_string (GList ** list, gchar * str)
150 GstRegistryChunk *chunk;
152 chunk = g_slice_new (GstRegistryChunk);
154 chunk->size = strlen ((gchar *) chunk->data) + 1;
155 chunk->flags = GST_REGISTRY_CHUNK_FLAG_MALLOC;
156 chunk->align = FALSE;
157 *list = g_list_prepend (*list, chunk);
162 * gst_registry_chunks_save_data:
164 * Store some data in a binary chunk.
166 * Returns: the initialized chunk
168 inline static GstRegistryChunk *
169 gst_registry_chunks_make_data (gpointer data, gulong size)
171 GstRegistryChunk *chunk;
173 chunk = g_slice_new (GstRegistryChunk);
176 chunk->flags = GST_REGISTRY_CHUNK_FLAG_NONE;
183 * gst_registry_chunks_save_pad_template:
185 * Store pad_templates in binary chunks.
187 * Returns: %TRUE for success
190 gst_registry_chunks_save_pad_template (GList ** list,
191 GstStaticPadTemplate * template)
193 GstRegistryChunkPadTemplate *pt;
194 GstRegistryChunk *chk;
196 pt = g_slice_new (GstRegistryChunkPadTemplate);
198 gst_registry_chunks_make_data (pt, sizeof (GstRegistryChunkPadTemplate));
200 pt->presence = template->presence;
201 pt->direction = template->direction;
203 /* pack pad template strings */
204 gst_registry_chunks_save_const_string (list,
205 (gchar *) (template->static_caps.string));
206 gst_registry_chunks_save_const_string (list, template->name_template);
208 *list = g_list_prepend (*list, chk);
214 * gst_registry_chunks_save_feature:
216 * Store features in binary chunks.
218 * Returns: %TRUE for success
221 gst_registry_chunks_save_feature (GList ** list, GstPluginFeature * feature)
223 const gchar *type_name = G_OBJECT_TYPE_NAME (feature);
224 GstRegistryChunkPluginFeature *pf = NULL;
225 GstRegistryChunk *chk = NULL;
230 GST_ERROR ("NULL feature type_name, aborting.");
234 if (GST_IS_ELEMENT_FACTORY (feature)) {
235 GstRegistryChunkElementFactory *ef;
236 GstElementFactory *factory = GST_ELEMENT_FACTORY (feature);
238 /* Initialize with zeroes because of struct padding and
239 * valgrind complaining about copying unitialized memory
241 ef = g_slice_new0 (GstRegistryChunkElementFactory);
242 pf_size = sizeof (GstRegistryChunkElementFactory);
243 chk = gst_registry_chunks_make_data (ef, pf_size);
244 ef->npadtemplates = ef->ninterfaces = ef->nuriprotocols = 0;
245 pf = (GstRegistryChunkPluginFeature *) ef;
247 /* save interfaces */
248 for (walk = factory->interfaces; walk;
249 walk = g_list_next (walk), ef->ninterfaces++) {
250 gst_registry_chunks_save_const_string (list, (gchar *) walk->data);
252 GST_DEBUG_OBJECT (feature, "saved %d interfaces %d pad templates",
253 ef->ninterfaces, ef->npadtemplates);
256 if (GST_URI_TYPE_IS_VALID (factory->uri_type)) {
257 if (factory->uri_protocols && *factory->uri_protocols) {
258 GstRegistryChunk *subchk;
262 gst_registry_chunks_make_data (&factory->uri_type,
263 sizeof (factory->uri_type));
264 subchk->flags = GST_REGISTRY_CHUNK_FLAG_CONST;
266 protocol = factory->uri_protocols;
268 gst_registry_chunks_save_const_string (list, *protocol++);
271 *list = g_list_prepend (*list, subchk);
272 GST_DEBUG_OBJECT (feature, "Saved %d UriTypes", ef->nuriprotocols);
274 g_warning ("GStreamer feature '%s' is URI handler but does not provide"
275 " any protocols it can handle", GST_OBJECT_NAME (feature));
279 /* save pad-templates */
280 for (walk = factory->staticpadtemplates; walk;
281 walk = g_list_next (walk), ef->npadtemplates++) {
282 GstStaticPadTemplate *template = walk->data;
284 if (!gst_registry_chunks_save_pad_template (list, template)) {
285 GST_ERROR_OBJECT (feature, "Can't fill pad template, aborting.");
290 /* pack element metadata strings */
291 gst_registry_chunks_save_string (list,
292 gst_structure_to_string (factory->metadata));
293 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
294 GstRegistryChunkTypeFindFactory *tff;
295 GstTypeFindFactory *factory = GST_TYPE_FIND_FACTORY (feature);
298 /* Initialize with zeroes because of struct padding and
299 * valgrind complaining about copying unitialized memory
301 tff = g_slice_new0 (GstRegistryChunkTypeFindFactory);
302 pf_size = sizeof (GstRegistryChunkTypeFindFactory);
303 chk = gst_registry_chunks_make_data (tff, pf_size);
304 tff->nextensions = 0;
305 pf = (GstRegistryChunkPluginFeature *) tff;
307 /* save extensions */
308 if (factory->extensions) {
309 while (factory->extensions[tff->nextensions]) {
310 gst_registry_chunks_save_const_string (list,
311 factory->extensions[tff->nextensions++]);
314 GST_DEBUG_OBJECT (feature, "saved %d extensions", tff->nextensions);
317 GstCaps *fcaps = gst_caps_ref (factory->caps);
318 /* we simplify the caps before saving. This is a lot faster
319 * when loading them later on */
320 fcaps = gst_caps_simplify (fcaps);
321 str = gst_caps_to_string (fcaps);
322 gst_caps_unref (fcaps);
324 gst_registry_chunks_save_string (list, str);
326 gst_registry_chunks_save_const_string (list, "");
328 } else if (GST_IS_DEVICE_PROVIDER_FACTORY (feature)) {
329 GstRegistryChunkDeviceProviderFactory *tff;
330 GstDeviceProviderFactory *factory = GST_DEVICE_PROVIDER_FACTORY (feature);
332 /* Initialize with zeroes because of struct padding and
333 * valgrind complaining about copying unitialized memory
335 tff = g_slice_new0 (GstRegistryChunkDeviceProviderFactory);
337 gst_registry_chunks_make_data (tff,
338 sizeof (GstRegistryChunkDeviceProviderFactory));
339 pf = (GstRegistryChunkPluginFeature *) tff;
342 /* pack element metadata strings */
343 gst_registry_chunks_save_string (list,
344 gst_structure_to_string (factory->metadata));
345 } else if (GST_IS_TRACER_FACTORY (feature)) {
346 /* Initialize with zeroes because of struct padding and
347 * valgrind complaining about copying unitialized memory
349 pf = g_slice_new0 (GstRegistryChunkPluginFeature);
350 pf_size = sizeof (GstRegistryChunkPluginFeature);
351 chk = gst_registry_chunks_make_data (pf, pf_size);
352 } else if (GST_IS_DYNAMIC_TYPE_FACTORY (feature)) {
353 GstRegistryChunkDynamicTypeFactory *tmp;
355 tmp = g_slice_new0 (GstRegistryChunkDynamicTypeFactory);
357 gst_registry_chunks_make_data (tmp,
358 sizeof (GstRegistryChunkDynamicTypeFactory));
359 pf = (GstRegistryChunkPluginFeature *) tmp;
361 GST_WARNING_OBJECT (feature, "unhandled feature type '%s'", type_name);
365 pf->rank = feature->rank;
366 *list = g_list_prepend (*list, chk);
368 /* pack plugin feature strings */
369 gst_registry_chunks_save_const_string (list, GST_OBJECT_NAME (feature));
370 gst_registry_chunks_save_const_string (list, (gchar *) type_name);
377 g_slice_free (GstRegistryChunk, chk);
378 g_slice_free1 (pf_size, pf);
383 gst_registry_chunks_save_plugin_dep (GList ** list, GstPluginDep * dep)
385 GstRegistryChunkDep *ed;
386 GstRegistryChunk *chk;
389 ed = g_slice_new (GstRegistryChunkDep);
390 chk = gst_registry_chunks_make_data (ed, sizeof (GstRegistryChunkDep));
392 ed->flags = dep->flags;
397 ed->env_hash = dep->env_hash;
398 ed->stat_hash = dep->stat_hash;
400 for (s = dep->env_vars; s != NULL && *s != NULL; ++s, ++ed->n_env_vars)
401 gst_registry_chunks_save_string (list, g_strdup (*s));
403 for (s = dep->paths; s != NULL && *s != NULL; ++s, ++ed->n_paths)
404 gst_registry_chunks_save_string (list, g_strdup (*s));
406 for (s = dep->names; s != NULL && *s != NULL; ++s, ++ed->n_names)
407 gst_registry_chunks_save_string (list, g_strdup (*s));
409 *list = g_list_prepend (*list, chk);
411 GST_LOG ("Saved external plugin dependency");
416 * _priv_gst_registry_chunks_save_plugin:
418 * Adapt a GstPlugin to our GstRegistryChunkPluginElement structure, and
419 * prepend it as a GstRegistryChunk in the provided list.
423 _priv_gst_registry_chunks_save_plugin (GList ** list, GstRegistry * registry,
426 GstRegistryChunkPluginElement *pe;
427 GstRegistryChunk *chk;
428 GList *plugin_features = NULL;
431 pe = g_slice_new (GstRegistryChunkPluginElement);
433 gst_registry_chunks_make_data (pe,
434 sizeof (GstRegistryChunkPluginElement));
436 pe->file_size = plugin->file_size;
437 pe->file_mtime = plugin->file_mtime;
441 /* pack external deps */
442 for (walk = plugin->priv->deps; walk != NULL; walk = walk->next) {
443 if (!gst_registry_chunks_save_plugin_dep (list, walk->data)) {
444 GST_ERROR ("Could not save external plugin dependency, aborting.");
450 /* pack plugin features */
452 gst_registry_get_feature_list_by_plugin (registry, plugin->desc.name);
453 for (walk = plugin_features; walk; walk = g_list_next (walk), pe->nfeatures++) {
454 GstPluginFeature *feature = GST_PLUGIN_FEATURE (walk->data);
456 if (!gst_registry_chunks_save_feature (list, feature)) {
457 GST_ERROR ("Can't fill plugin feature, aborting.");
462 gst_plugin_feature_list_free (plugin_features);
464 /* pack cache data */
465 if (plugin->priv->cache_data) {
466 gchar *cache_str = gst_structure_to_string (plugin->priv->cache_data);
467 gst_registry_chunks_save_string (list, cache_str);
469 gst_registry_chunks_save_const_string (list, "");
472 /* pack plugin element strings */
473 gst_registry_chunks_save_const_string (list,
474 (plugin->desc.release_datetime) ? plugin->desc.release_datetime : "");
475 gst_registry_chunks_save_const_string (list, plugin->desc.origin);
476 gst_registry_chunks_save_const_string (list, plugin->desc.package);
477 gst_registry_chunks_save_const_string (list, plugin->desc.source);
478 gst_registry_chunks_save_const_string (list, plugin->desc.license);
479 gst_registry_chunks_save_const_string (list, plugin->desc.version);
480 gst_registry_chunks_save_const_string (list, plugin->filename);
481 gst_registry_chunks_save_const_string (list, plugin->desc.description);
482 gst_registry_chunks_save_const_string (list, plugin->desc.name);
484 *list = g_list_prepend (*list, chk);
486 GST_DEBUG ("Found %d features in plugin \"%s\"", pe->nfeatures,
492 gst_plugin_feature_list_free (plugin_features);
493 g_slice_free (GstRegistryChunk, chk);
494 g_slice_free (GstRegistryChunkPluginElement, pe);
499 * gst_registry_chunks_load_pad_template:
501 * Make a new GstStaticPadTemplate from current GstRegistryChunkPadTemplate
504 * Returns: new GstStaticPadTemplate
507 gst_registry_chunks_load_pad_template (GstElementFactory * factory, gchar ** in,
510 GstRegistryChunkPadTemplate *pt;
511 GstStaticPadTemplate *template = NULL;
514 GST_DEBUG ("Reading/casting for GstRegistryChunkPadTemplate at address %p",
516 unpack_element (*in, pt, GstRegistryChunkPadTemplate, end, fail);
518 template = g_slice_new (GstStaticPadTemplate);
519 template->presence = pt->presence;
520 template->direction = (GstPadDirection) pt->direction;
521 template->static_caps.caps = NULL;
523 /* unpack pad template strings */
524 unpack_const_string (*in, template->name_template, end, fail);
525 unpack_const_string (*in, template->static_caps.string, end, fail);
527 __gst_element_factory_add_static_pad_template (factory, template);
528 GST_DEBUG ("Added pad_template %s", template->name_template);
532 GST_INFO ("Reading pad template failed");
534 g_slice_free (GstStaticPadTemplate, template);
539 * gst_registry_chunks_load_feature:
541 * Make a new GstPluginFeature from current binary plugin feature structure
543 * Returns: new GstPluginFeature
546 gst_registry_chunks_load_feature (GstRegistry * registry, gchar ** in,
547 gchar * end, GstPlugin * plugin)
549 GstRegistryChunkPluginFeature *pf = NULL;
550 GstPluginFeature *feature = NULL;
551 const gchar *const_str, *type_name;
552 const gchar *feature_name;
553 const gchar *plugin_name;
558 plugin_name = plugin->desc.name;
560 /* unpack plugin feature strings */
561 unpack_string_nocopy (*in, type_name, end, fail);
563 if (G_UNLIKELY (!type_name)) {
564 GST_ERROR ("No feature type name");
568 /* unpack more plugin feature strings */
569 unpack_string_nocopy (*in, feature_name, end, fail);
571 GST_DEBUG ("Plugin '%s' feature '%s' typename : '%s'", plugin_name,
572 feature_name, type_name);
574 if (G_UNLIKELY (!(type = g_type_from_name (type_name)))) {
575 GST_ERROR ("Unknown type from typename '%s' for plugin '%s'", type_name,
579 if (G_UNLIKELY ((feature = g_object_new (type, NULL)) == NULL)) {
580 GST_ERROR ("Can't create feature from type");
583 gst_plugin_feature_set_name (feature, feature_name);
585 if (G_UNLIKELY (!GST_IS_PLUGIN_FEATURE (feature))) {
586 GST_ERROR ("typename : '%s' is not a plugin feature", type_name);
590 if (GST_IS_ELEMENT_FACTORY (feature)) {
591 GstRegistryChunkElementFactory *ef;
593 GstElementFactory *factory = GST_ELEMENT_FACTORY_CAST (feature);
595 const gchar *meta_data_str;
598 GST_LOG ("Reading/casting for GstRegistryChunkElementFactory at address %p",
600 unpack_element (*in, ef, GstRegistryChunkElementFactory, end, fail);
601 pf = (GstRegistryChunkPluginFeature *) ef;
603 /* unpack element factory strings */
604 unpack_string_nocopy (*in, meta_data_str, end, fail);
605 if (meta_data_str && *meta_data_str) {
606 factory->metadata = gst_structure_from_string (meta_data_str, NULL);
607 if (!factory->metadata) {
609 ("Error when trying to deserialize structure for metadata '%s'",
614 n = ef->npadtemplates;
615 GST_DEBUG ("Element factory : npadtemplates=%d", n);
617 /* load pad templates */
618 for (i = 0; i < n; i++) {
619 if (G_UNLIKELY (!gst_registry_chunks_load_pad_template (factory, in,
621 GST_ERROR ("Error while loading binary pad template");
627 if (G_UNLIKELY ((n = ef->nuriprotocols))) {
628 GST_DEBUG ("Reading %d UriTypes at address %p", n, *in);
631 factory->uri_type = *((guint *) * in);
632 *in += sizeof (factory->uri_type);
633 /*unpack_element(*in, &factory->uri_type, factory->uri_type, end, fail); */
635 factory->uri_protocols = g_new0 (gchar *, n + 1);
636 for (i = 0; i < n; i++) {
637 unpack_string (*in, str, end, fail);
638 factory->uri_protocols[i] = str;
641 /* load interfaces */
642 if (G_UNLIKELY ((n = ef->ninterfaces))) {
643 GST_DEBUG ("Reading %d Interfaces at address %p", n, *in);
644 for (i = 0; i < n; i++) {
645 unpack_string_nocopy (*in, const_str, end, fail);
646 __gst_element_factory_add_interface (factory, const_str);
649 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
650 GstRegistryChunkTypeFindFactory *tff;
651 GstTypeFindFactory *factory = GST_TYPE_FIND_FACTORY (feature);
655 ("Reading/casting for GstRegistryChunkPluginFeature at address %p",
657 unpack_element (*in, tff, GstRegistryChunkTypeFindFactory, end, fail);
658 pf = (GstRegistryChunkPluginFeature *) tff;
660 /* load typefinder caps */
661 unpack_string_nocopy (*in, const_str, end, fail);
662 if (const_str != NULL && *const_str != '\0')
663 factory->caps = gst_caps_from_string (const_str);
665 factory->caps = NULL;
667 /* load extensions */
668 if (tff->nextensions) {
669 GST_DEBUG ("Reading %d Typefind extensions at address %p",
670 tff->nextensions, *in);
671 factory->extensions = g_new0 (gchar *, tff->nextensions + 1);
672 /* unpack in reverse order to maintain the correct order */
673 for (i = tff->nextensions; i > 0; i--) {
674 unpack_string (*in, str, end, fail);
675 factory->extensions[i - 1] = str;
678 } else if (GST_IS_DEVICE_PROVIDER_FACTORY (feature)) {
679 GstRegistryChunkDeviceProviderFactory *dmf;
680 GstDeviceProviderFactory *factory = GST_DEVICE_PROVIDER_FACTORY (feature);
681 const gchar *meta_data_str;
685 ("Reading/casting for GstRegistryChunkPluginFeature at address %p",
688 unpack_element (*in, dmf, GstRegistryChunkDeviceProviderFactory, end, fail);
690 pf = (GstRegistryChunkPluginFeature *) dmf;
692 /* unpack element factory strings */
693 unpack_string_nocopy (*in, meta_data_str, end, fail);
694 if (meta_data_str && *meta_data_str) {
695 factory->metadata = gst_structure_from_string (meta_data_str, NULL);
696 if (!factory->metadata) {
698 ("Error when trying to deserialize structure for metadata '%s'",
703 } else if (GST_IS_TRACER_FACTORY (feature)) {
706 ("Reading/casting for GstRegistryChunkPluginFeature at address %p",
708 unpack_element (*in, pf, GstRegistryChunkPluginFeature, end, fail);
709 } else if (GST_IS_DYNAMIC_TYPE_FACTORY (feature)) {
710 GstRegistryChunkDynamicTypeFactory *tmp;
712 unpack_element (*in, tmp, GstRegistryChunkDynamicTypeFactory, end, fail);
714 pf = (GstRegistryChunkPluginFeature *) tmp;
716 GST_WARNING ("unhandled factory type : %s", G_OBJECT_TYPE_NAME (feature));
720 feature->rank = pf->rank;
722 feature->plugin_name = plugin_name;
723 feature->plugin = plugin;
724 g_object_add_weak_pointer ((GObject *) plugin,
725 (gpointer *) & feature->plugin);
727 gst_registry_add_feature (registry, feature);
728 GST_DEBUG ("Added feature %s, plugin %p %s", GST_OBJECT_NAME (feature),
729 plugin, plugin_name);
735 GST_INFO ("Reading plugin feature failed");
737 if (GST_IS_OBJECT (feature))
738 gst_object_unref (feature);
740 g_object_unref (feature);
746 gst_registry_chunks_load_plugin_dep_strv (gchar ** in, gchar * end, guint n)
753 arr = g_new0 (gchar *, n + 1);
755 unpack_string (*in, arr[n - 1], end, fail);
760 GST_INFO ("Reading plugin dependency strings failed");
766 gst_registry_chunks_load_plugin_dep (GstPlugin * plugin, gchar ** in,
770 GstRegistryChunkDep *d;
774 GST_LOG_OBJECT (plugin, "Unpacking GstRegistryChunkDep from %p", *in);
775 unpack_element (*in, d, GstRegistryChunkDep, end, fail);
777 dep = g_slice_new (GstPluginDep);
779 dep->env_hash = d->env_hash;
780 dep->stat_hash = d->stat_hash;
782 dep->flags = (GstPluginDependencyFlags) d->flags;
784 dep->names = gst_registry_chunks_load_plugin_dep_strv (in, end, d->n_names);
785 dep->paths = gst_registry_chunks_load_plugin_dep_strv (in, end, d->n_paths);
787 gst_registry_chunks_load_plugin_dep_strv (in, end, d->n_env_vars);
789 plugin->priv->deps = g_list_append (plugin->priv->deps, dep);
791 GST_DEBUG_OBJECT (plugin, "Loaded external plugin dependency from registry: "
792 "env_hash: %08x, stat_hash: %08x", dep->env_hash, dep->stat_hash);
793 for (s = dep->env_vars; s != NULL && *s != NULL; ++s)
794 GST_LOG_OBJECT (plugin, " evar: %s", *s);
795 for (s = dep->paths; s != NULL && *s != NULL; ++s)
796 GST_LOG_OBJECT (plugin, " path: %s", *s);
797 for (s = dep->names; s != NULL && *s != NULL; ++s)
798 GST_LOG_OBJECT (plugin, " name: %s", *s);
802 GST_INFO ("Reading plugin dependency failed");
808 * _priv_gst_registry_chunks_load_plugin:
810 * Make a new GstPlugin from current GstRegistryChunkPluginElement structure
811 * and add it to the GstRegistry. Return an offset to the next
812 * GstRegistryChunkPluginElement structure.
815 _priv_gst_registry_chunks_load_plugin (GstRegistry * registry, gchar ** in,
816 gchar * end, GstPlugin ** out_plugin)
818 #ifndef GST_DISABLE_GST_DEBUG
821 GstRegistryChunkPluginElement *pe;
822 const gchar *cache_str = NULL;
823 GstPlugin *plugin = NULL;
827 GST_LOG ("Reading/casting for GstRegistryChunkPluginElement at address %p",
829 unpack_element (*in, pe, GstRegistryChunkPluginElement, end, fail);
831 plugin = g_object_new (GST_TYPE_PLUGIN, NULL);
833 /* TODO: also set GST_PLUGIN_FLAG_CONST */
834 GST_OBJECT_FLAG_SET (plugin, GST_PLUGIN_FLAG_CACHED);
835 plugin->file_mtime = pe->file_mtime;
836 plugin->file_size = pe->file_size;
838 /* unpack plugin element strings */
839 unpack_const_string (*in, plugin->desc.name, end, fail);
840 unpack_const_string (*in, plugin->desc.description, end, fail);
841 unpack_string (*in, plugin->filename, end, fail);
842 unpack_const_string (*in, plugin->desc.version, end, fail);
843 unpack_const_string (*in, plugin->desc.license, end, fail);
844 unpack_const_string (*in, plugin->desc.source, end, fail);
845 unpack_const_string (*in, plugin->desc.package, end, fail);
846 unpack_const_string (*in, plugin->desc.origin, end, fail);
847 unpack_const_string (*in, plugin->desc.release_datetime, end, fail);
849 GST_LOG ("read strings for name='%s'", plugin->desc.name);
850 GST_LOG (" desc.description='%s'", plugin->desc.description);
851 GST_LOG (" filename='%s'", plugin->filename);
852 GST_LOG (" desc.version='%s'", plugin->desc.version);
853 GST_LOG (" desc.license='%s'", plugin->desc.license);
854 GST_LOG (" desc.source='%s'", plugin->desc.source);
855 GST_LOG (" desc.package='%s'", plugin->desc.package);
856 GST_LOG (" desc.origin='%s'", plugin->desc.origin);
857 GST_LOG (" desc.datetime=%s", plugin->desc.release_datetime);
859 if (plugin->desc.release_datetime[0] == '\0')
860 plugin->desc.release_datetime = NULL;
862 /* unpack cache data */
863 unpack_string_nocopy (*in, cache_str, end, fail);
864 if (cache_str != NULL && *cache_str != '\0')
865 plugin->priv->cache_data = gst_structure_from_string (cache_str, NULL);
867 /* If the license string is 'BLACKLIST', mark this as a blacklisted
869 if (strcmp (plugin->desc.license, "BLACKLIST") == 0)
870 GST_OBJECT_FLAG_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED);
872 plugin->basename = g_path_get_basename (plugin->filename);
874 /* Takes ownership of plugin */
875 gst_registry_add_plugin (registry, plugin);
877 GST_DEBUG ("Added plugin '%s' plugin with %d features from binary registry",
878 plugin->desc.name, n);
880 /* Load plugin features */
881 for (i = 0; i < n; i++) {
882 if (G_UNLIKELY (!gst_registry_chunks_load_feature (registry, in, end,
884 GST_ERROR ("Error while loading binary feature for plugin '%s'",
885 GST_STR_NULL (plugin->desc.name));
886 gst_registry_remove_plugin (registry, plugin);
891 /* Load external plugin dependencies */
892 for (i = 0; i < pe->n_deps; ++i) {
893 if (G_UNLIKELY (!gst_registry_chunks_load_plugin_dep (plugin, in, end))) {
894 GST_ERROR_OBJECT (plugin, "Could not read external plugin dependency "
895 "for plugin '%s'", GST_STR_NULL (plugin->desc.name));
896 gst_registry_remove_plugin (registry, plugin);
902 *out_plugin = plugin;
908 GST_INFO ("Reading plugin failed after %u bytes", (guint) (end - start));
913 _priv_gst_registry_chunks_save_global_header (GList ** list,
914 GstRegistry * registry, guint32 filter_env_hash)
916 GstRegistryChunkGlobalHeader *hdr;
917 GstRegistryChunk *chk;
919 hdr = g_slice_new (GstRegistryChunkGlobalHeader);
920 chk = gst_registry_chunks_make_data (hdr,
921 sizeof (GstRegistryChunkGlobalHeader));
923 hdr->filter_env_hash = filter_env_hash;
925 *list = g_list_prepend (*list, chk);
927 GST_LOG ("Saved global header (filter_env_hash=0x%08x)", filter_env_hash);
931 _priv_gst_registry_chunks_load_global_header (GstRegistry * registry,
932 gchar ** in, gchar * end, guint32 * filter_env_hash)
934 GstRegistryChunkGlobalHeader *hdr;
937 GST_LOG ("Reading/casting for GstRegistryChunkGlobalHeader at %p", *in);
938 unpack_element (*in, hdr, GstRegistryChunkGlobalHeader, end, fail);
939 *filter_env_hash = hdr->filter_env_hash;
944 GST_WARNING ("Reading global header failed");