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;
713 unpack_element (*in, tmp, GstRegistryChunkDynamicTypeFactory, end, fail);
715 pf = (GstRegistryChunkPluginFeature *) tmp;
717 GST_WARNING ("unhandled factory type : %s", G_OBJECT_TYPE_NAME (feature));
721 feature->rank = pf->rank;
723 feature->plugin_name = plugin_name;
724 feature->plugin = plugin;
725 g_object_add_weak_pointer ((GObject *) plugin,
726 (gpointer *) & feature->plugin);
728 gst_registry_add_feature (registry, feature);
729 GST_DEBUG ("Added feature %s, plugin %p %s", GST_OBJECT_NAME (feature),
730 plugin, plugin_name);
736 GST_INFO ("Reading plugin feature failed");
738 if (GST_IS_OBJECT (feature))
739 gst_object_unref (feature);
741 g_object_unref (feature);
747 gst_registry_chunks_load_plugin_dep_strv (gchar ** in, gchar * end, guint n)
754 arr = g_new0 (gchar *, n + 1);
756 unpack_string (*in, arr[n - 1], end, fail);
761 GST_INFO ("Reading plugin dependency strings failed");
767 gst_registry_chunks_load_plugin_dep (GstPlugin * plugin, gchar ** in,
771 GstRegistryChunkDep *d;
775 GST_LOG_OBJECT (plugin, "Unpacking GstRegistryChunkDep from %p", *in);
776 unpack_element (*in, d, GstRegistryChunkDep, end, fail);
778 dep = g_slice_new (GstPluginDep);
780 dep->env_hash = d->env_hash;
781 dep->stat_hash = d->stat_hash;
783 dep->flags = (GstPluginDependencyFlags) d->flags;
785 dep->names = gst_registry_chunks_load_plugin_dep_strv (in, end, d->n_names);
786 dep->paths = gst_registry_chunks_load_plugin_dep_strv (in, end, d->n_paths);
788 gst_registry_chunks_load_plugin_dep_strv (in, end, d->n_env_vars);
790 plugin->priv->deps = g_list_append (plugin->priv->deps, dep);
792 GST_DEBUG_OBJECT (plugin, "Loaded external plugin dependency from registry: "
793 "env_hash: %08x, stat_hash: %08x", dep->env_hash, dep->stat_hash);
794 for (s = dep->env_vars; s != NULL && *s != NULL; ++s)
795 GST_LOG_OBJECT (plugin, " evar: %s", *s);
796 for (s = dep->paths; s != NULL && *s != NULL; ++s)
797 GST_LOG_OBJECT (plugin, " path: %s", *s);
798 for (s = dep->names; s != NULL && *s != NULL; ++s)
799 GST_LOG_OBJECT (plugin, " name: %s", *s);
803 GST_INFO ("Reading plugin dependency failed");
809 * _priv_gst_registry_chunks_load_plugin:
811 * Make a new GstPlugin from current GstRegistryChunkPluginElement structure
812 * and add it to the GstRegistry. Return an offset to the next
813 * GstRegistryChunkPluginElement structure.
816 _priv_gst_registry_chunks_load_plugin (GstRegistry * registry, gchar ** in,
817 gchar * end, GstPlugin ** out_plugin)
819 #ifndef GST_DISABLE_GST_DEBUG
822 GstRegistryChunkPluginElement *pe;
823 const gchar *cache_str = NULL;
824 GstPlugin *plugin = NULL;
828 GST_LOG ("Reading/casting for GstRegistryChunkPluginElement at address %p",
830 unpack_element (*in, pe, GstRegistryChunkPluginElement, end, fail);
832 plugin = g_object_new (GST_TYPE_PLUGIN, NULL);
834 /* TODO: also set GST_PLUGIN_FLAG_CONST */
835 GST_OBJECT_FLAG_SET (plugin, GST_PLUGIN_FLAG_CACHED);
836 plugin->file_mtime = pe->file_mtime;
837 plugin->file_size = pe->file_size;
839 /* unpack plugin element strings */
840 unpack_const_string (*in, plugin->desc.name, end, fail);
841 unpack_const_string (*in, plugin->desc.description, end, fail);
842 unpack_string (*in, plugin->filename, end, fail);
843 unpack_const_string (*in, plugin->desc.version, end, fail);
844 unpack_const_string (*in, plugin->desc.license, end, fail);
845 unpack_const_string (*in, plugin->desc.source, end, fail);
846 unpack_const_string (*in, plugin->desc.package, end, fail);
847 unpack_const_string (*in, plugin->desc.origin, end, fail);
848 unpack_const_string (*in, plugin->desc.release_datetime, end, fail);
850 GST_LOG ("read strings for name='%s'", plugin->desc.name);
851 GST_LOG (" desc.description='%s'", plugin->desc.description);
852 GST_LOG (" filename='%s'", plugin->filename);
853 GST_LOG (" desc.version='%s'", plugin->desc.version);
854 GST_LOG (" desc.license='%s'", plugin->desc.license);
855 GST_LOG (" desc.source='%s'", plugin->desc.source);
856 GST_LOG (" desc.package='%s'", plugin->desc.package);
857 GST_LOG (" desc.origin='%s'", plugin->desc.origin);
858 GST_LOG (" desc.datetime=%s", plugin->desc.release_datetime);
860 if (plugin->desc.release_datetime[0] == '\0')
861 plugin->desc.release_datetime = NULL;
863 /* unpack cache data */
864 unpack_string_nocopy (*in, cache_str, end, fail);
865 if (cache_str != NULL && *cache_str != '\0')
866 plugin->priv->cache_data = gst_structure_from_string (cache_str, NULL);
868 /* If the license string is 'BLACKLIST', mark this as a blacklisted
870 if (strcmp (plugin->desc.license, "BLACKLIST") == 0)
871 GST_OBJECT_FLAG_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED);
873 plugin->basename = g_path_get_basename (plugin->filename);
875 /* Takes ownership of plugin */
876 gst_registry_add_plugin (registry, plugin);
878 GST_DEBUG ("Added plugin '%s' plugin with %d features from binary registry",
879 plugin->desc.name, n);
881 /* Load plugin features */
882 for (i = 0; i < n; i++) {
883 if (G_UNLIKELY (!gst_registry_chunks_load_feature (registry, in, end,
885 GST_ERROR ("Error while loading binary feature for plugin '%s'",
886 GST_STR_NULL (plugin->desc.name));
887 gst_registry_remove_plugin (registry, plugin);
892 /* Load external plugin dependencies */
893 for (i = 0; i < pe->n_deps; ++i) {
894 if (G_UNLIKELY (!gst_registry_chunks_load_plugin_dep (plugin, in, end))) {
895 GST_ERROR_OBJECT (plugin, "Could not read external plugin dependency "
896 "for plugin '%s'", GST_STR_NULL (plugin->desc.name));
897 gst_registry_remove_plugin (registry, plugin);
903 *out_plugin = plugin;
909 GST_INFO ("Reading plugin failed after %u bytes", (guint) (end - start));
914 _priv_gst_registry_chunks_save_global_header (GList ** list,
915 GstRegistry * registry, guint32 filter_env_hash)
917 GstRegistryChunkGlobalHeader *hdr;
918 GstRegistryChunk *chk;
920 hdr = g_slice_new (GstRegistryChunkGlobalHeader);
921 chk = gst_registry_chunks_make_data (hdr,
922 sizeof (GstRegistryChunkGlobalHeader));
924 hdr->filter_env_hash = filter_env_hash;
926 *list = g_list_prepend (*list, chk);
928 GST_LOG ("Saved global header (filter_env_hash=0x%08x)", filter_env_hash);
932 _priv_gst_registry_chunks_load_global_header (GstRegistry * registry,
933 gchar ** in, gchar * end, guint32 * filter_env_hash)
935 GstRegistryChunkGlobalHeader *hdr;
938 GST_LOG ("Reading/casting for GstRegistryChunkGlobalHeader at %p", *in);
939 unpack_element (*in, hdr, GstRegistryChunkGlobalHeader, end, fail);
940 *filter_env_hash = hdr->filter_env_hash;
945 GST_WARNING ("Reading global header failed");