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);
212 #define VALIDATE_UTF8(__details, __entry) \
214 if (!g_utf8_validate (__details->__entry, -1, NULL)) { \
215 g_warning ("Invalid UTF-8 in " G_STRINGIFY (__entry) ": %s", \
216 __details->__entry); \
217 g_free (__details->__entry); \
218 __details->__entry = g_strdup ("[ERROR: invalid UTF-8]"); \
223 * gst_registry_chunks_save_feature:
225 * Store features in binary chunks.
227 * Returns: %TRUE for success
230 gst_registry_chunks_save_feature (GList ** list, GstPluginFeature * feature)
232 const gchar *type_name = G_OBJECT_TYPE_NAME (feature);
233 GstRegistryChunkPluginFeature *pf = NULL;
234 GstRegistryChunk *chk = NULL;
239 GST_ERROR ("NULL feature type_name, aborting.");
243 if (GST_IS_ELEMENT_FACTORY (feature)) {
244 GstRegistryChunkElementFactory *ef;
245 GstElementFactory *factory = GST_ELEMENT_FACTORY (feature);
247 /* Initialize with zeroes because of struct padding and
248 * valgrind complaining about copying unitialized memory
250 ef = g_slice_new0 (GstRegistryChunkElementFactory);
251 pf_size = sizeof (GstRegistryChunkElementFactory);
252 chk = gst_registry_chunks_make_data (ef, pf_size);
253 ef->npadtemplates = ef->ninterfaces = ef->nuriprotocols = 0;
254 pf = (GstRegistryChunkPluginFeature *) ef;
256 /* save interfaces */
257 for (walk = factory->interfaces; walk;
258 walk = g_list_next (walk), ef->ninterfaces++) {
259 gst_registry_chunks_save_const_string (list, (gchar *) walk->data);
261 GST_DEBUG_OBJECT (feature, "saved %d interfaces %d pad templates",
262 ef->ninterfaces, ef->npadtemplates);
265 if (GST_URI_TYPE_IS_VALID (factory->uri_type)) {
266 if (factory->uri_protocols && *factory->uri_protocols) {
267 GstRegistryChunk *subchk;
271 gst_registry_chunks_make_data (&factory->uri_type,
272 sizeof (factory->uri_type));
273 subchk->flags = GST_REGISTRY_CHUNK_FLAG_CONST;
275 protocol = factory->uri_protocols;
277 gst_registry_chunks_save_const_string (list, *protocol++);
280 *list = g_list_prepend (*list, subchk);
281 GST_DEBUG_OBJECT (feature, "Saved %d UriTypes", ef->nuriprotocols);
283 g_warning ("GStreamer feature '%s' is URI handler but does not provide"
284 " any protocols it can handle", GST_OBJECT_NAME (feature));
288 /* save pad-templates */
289 for (walk = factory->staticpadtemplates; walk;
290 walk = g_list_next (walk), ef->npadtemplates++) {
291 GstStaticPadTemplate *template = walk->data;
293 if (!gst_registry_chunks_save_pad_template (list, template)) {
294 GST_ERROR_OBJECT (feature, "Can't fill pad template, aborting.");
299 /* pack element metadata strings */
300 gst_registry_chunks_save_string (list,
301 gst_structure_to_string (factory->metadata));
302 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
303 GstRegistryChunkTypeFindFactory *tff;
304 GstTypeFindFactory *factory = GST_TYPE_FIND_FACTORY (feature);
307 /* Initialize with zeroes because of struct padding and
308 * valgrind complaining about copying unitialized memory
310 tff = g_slice_new0 (GstRegistryChunkTypeFindFactory);
311 pf_size = sizeof (GstRegistryChunkTypeFindFactory);
312 chk = gst_registry_chunks_make_data (tff, pf_size);
313 tff->nextensions = 0;
314 pf = (GstRegistryChunkPluginFeature *) tff;
316 /* save extensions */
317 if (factory->extensions) {
318 while (factory->extensions[tff->nextensions]) {
319 gst_registry_chunks_save_const_string (list,
320 factory->extensions[tff->nextensions++]);
323 GST_DEBUG_OBJECT (feature, "saved %d extensions", tff->nextensions);
326 GstCaps *fcaps = gst_caps_ref (factory->caps);
327 /* we simplify the caps before saving. This is a lot faster
328 * when loading them later on */
329 fcaps = gst_caps_simplify (fcaps);
330 str = gst_caps_to_string (fcaps);
331 gst_caps_unref (fcaps);
333 gst_registry_chunks_save_string (list, str);
335 gst_registry_chunks_save_const_string (list, "");
337 } else if (GST_IS_DEVICE_PROVIDER_FACTORY (feature)) {
338 GstRegistryChunkDeviceProviderFactory *tff;
339 GstDeviceProviderFactory *factory = GST_DEVICE_PROVIDER_FACTORY (feature);
341 /* Initialize with zeroes because of struct padding and
342 * valgrind complaining about copying unitialized memory
344 tff = g_slice_new0 (GstRegistryChunkDeviceProviderFactory);
346 gst_registry_chunks_make_data (tff,
347 sizeof (GstRegistryChunkDeviceProviderFactory));
348 pf = (GstRegistryChunkPluginFeature *) tff;
351 /* pack element metadata strings */
352 gst_registry_chunks_save_string (list,
353 gst_structure_to_string (factory->metadata));
354 } else if (GST_IS_TRACER_FACTORY (feature)) {
355 /* Initialize with zeroes because of struct padding and
356 * valgrind complaining about copying unitialized memory
358 pf = g_slice_new0 (GstRegistryChunkPluginFeature);
359 pf_size = sizeof (GstRegistryChunkPluginFeature);
360 chk = gst_registry_chunks_make_data (pf, pf_size);
362 GST_WARNING_OBJECT (feature, "unhandled feature type '%s'", type_name);
366 pf->rank = feature->rank;
367 *list = g_list_prepend (*list, chk);
369 /* pack plugin feature strings */
370 gst_registry_chunks_save_const_string (list, GST_OBJECT_NAME (feature));
371 gst_registry_chunks_save_const_string (list, (gchar *) type_name);
378 g_slice_free (GstRegistryChunk, chk);
379 g_slice_free1 (pf_size, pf);
384 gst_registry_chunks_save_plugin_dep (GList ** list, GstPluginDep * dep)
386 GstRegistryChunkDep *ed;
387 GstRegistryChunk *chk;
390 ed = g_slice_new (GstRegistryChunkDep);
391 chk = gst_registry_chunks_make_data (ed, sizeof (GstRegistryChunkDep));
393 ed->flags = dep->flags;
398 ed->env_hash = dep->env_hash;
399 ed->stat_hash = dep->stat_hash;
401 for (s = dep->env_vars; s != NULL && *s != NULL; ++s, ++ed->n_env_vars)
402 gst_registry_chunks_save_string (list, g_strdup (*s));
404 for (s = dep->paths; s != NULL && *s != NULL; ++s, ++ed->n_paths)
405 gst_registry_chunks_save_string (list, g_strdup (*s));
407 for (s = dep->names; s != NULL && *s != NULL; ++s, ++ed->n_names)
408 gst_registry_chunks_save_string (list, g_strdup (*s));
410 *list = g_list_prepend (*list, chk);
412 GST_LOG ("Saved external plugin dependency");
417 * _priv_gst_registry_chunks_save_plugin:
419 * Adapt a GstPlugin to our GstRegistryChunkPluginElement structure, and
420 * prepend it as a GstRegistryChunk in the provided list.
424 _priv_gst_registry_chunks_save_plugin (GList ** list, GstRegistry * registry,
427 GstRegistryChunkPluginElement *pe;
428 GstRegistryChunk *chk;
429 GList *plugin_features = NULL;
432 pe = g_slice_new (GstRegistryChunkPluginElement);
434 gst_registry_chunks_make_data (pe,
435 sizeof (GstRegistryChunkPluginElement));
437 pe->file_size = plugin->file_size;
438 pe->file_mtime = plugin->file_mtime;
442 /* pack external deps */
443 for (walk = plugin->priv->deps; walk != NULL; walk = walk->next) {
444 if (!gst_registry_chunks_save_plugin_dep (list, walk->data)) {
445 GST_ERROR ("Could not save external plugin dependency, aborting.");
451 /* pack plugin features */
453 gst_registry_get_feature_list_by_plugin (registry, plugin->desc.name);
454 for (walk = plugin_features; walk; walk = g_list_next (walk), pe->nfeatures++) {
455 GstPluginFeature *feature = GST_PLUGIN_FEATURE (walk->data);
457 if (!gst_registry_chunks_save_feature (list, feature)) {
458 GST_ERROR ("Can't fill plugin feature, aborting.");
463 gst_plugin_feature_list_free (plugin_features);
465 /* pack cache data */
466 if (plugin->priv->cache_data) {
467 gchar *cache_str = gst_structure_to_string (plugin->priv->cache_data);
468 gst_registry_chunks_save_string (list, cache_str);
470 gst_registry_chunks_save_const_string (list, "");
473 /* pack plugin element strings */
474 gst_registry_chunks_save_const_string (list,
475 (plugin->desc.release_datetime) ? plugin->desc.release_datetime : "");
476 gst_registry_chunks_save_const_string (list, plugin->desc.origin);
477 gst_registry_chunks_save_const_string (list, plugin->desc.package);
478 gst_registry_chunks_save_const_string (list, plugin->desc.source);
479 gst_registry_chunks_save_const_string (list, plugin->desc.license);
480 gst_registry_chunks_save_const_string (list, plugin->desc.version);
481 gst_registry_chunks_save_const_string (list, plugin->filename);
482 gst_registry_chunks_save_const_string (list, plugin->desc.description);
483 gst_registry_chunks_save_const_string (list, plugin->desc.name);
485 *list = g_list_prepend (*list, chk);
487 GST_DEBUG ("Found %d features in plugin \"%s\"", pe->nfeatures,
493 gst_plugin_feature_list_free (plugin_features);
494 g_slice_free (GstRegistryChunk, chk);
495 g_slice_free (GstRegistryChunkPluginElement, pe);
500 * gst_registry_chunks_load_pad_template:
502 * Make a new GstStaticPadTemplate from current GstRegistryChunkPadTemplate
505 * Returns: new GstStaticPadTemplate
508 gst_registry_chunks_load_pad_template (GstElementFactory * factory, gchar ** in,
511 GstRegistryChunkPadTemplate *pt;
512 GstStaticPadTemplate *template = NULL;
515 GST_DEBUG ("Reading/casting for GstRegistryChunkPadTemplate at address %p",
517 unpack_element (*in, pt, GstRegistryChunkPadTemplate, end, fail);
519 template = g_slice_new (GstStaticPadTemplate);
520 template->presence = pt->presence;
521 template->direction = (GstPadDirection) pt->direction;
522 template->static_caps.caps = NULL;
524 /* unpack pad template strings */
525 unpack_const_string (*in, template->name_template, end, fail);
526 unpack_const_string (*in, template->static_caps.string, end, fail);
528 __gst_element_factory_add_static_pad_template (factory, template);
529 GST_DEBUG ("Added pad_template %s", template->name_template);
533 GST_INFO ("Reading pad template failed");
535 g_slice_free (GstStaticPadTemplate, template);
540 * gst_registry_chunks_load_feature:
542 * Make a new GstPluginFeature from current binary plugin feature structure
544 * Returns: new GstPluginFeature
547 gst_registry_chunks_load_feature (GstRegistry * registry, gchar ** in,
548 gchar * end, GstPlugin * plugin)
550 GstRegistryChunkPluginFeature *pf = NULL;
551 GstPluginFeature *feature = NULL;
552 const gchar *const_str, *type_name;
553 const gchar *feature_name;
554 const gchar *plugin_name;
559 plugin_name = plugin->desc.name;
561 /* unpack plugin feature strings */
562 unpack_string_nocopy (*in, type_name, end, fail);
564 if (G_UNLIKELY (!type_name)) {
565 GST_ERROR ("No feature type name");
569 /* unpack more plugin feature strings */
570 unpack_string_nocopy (*in, feature_name, end, fail);
572 GST_DEBUG ("Plugin '%s' feature '%s' typename : '%s'", plugin_name,
573 feature_name, type_name);
575 if (G_UNLIKELY (!(type = g_type_from_name (type_name)))) {
576 GST_ERROR ("Unknown type from typename '%s' for plugin '%s'", type_name,
580 if (G_UNLIKELY ((feature = g_object_newv (type, 0, NULL)) == NULL)) {
581 GST_ERROR ("Can't create feature from type");
584 gst_plugin_feature_set_name (feature, feature_name);
586 if (G_UNLIKELY (!GST_IS_PLUGIN_FEATURE (feature))) {
587 GST_ERROR ("typename : '%s' is not a plugin feature", type_name);
591 if (GST_IS_ELEMENT_FACTORY (feature)) {
592 GstRegistryChunkElementFactory *ef;
594 GstElementFactory *factory = GST_ELEMENT_FACTORY_CAST (feature);
596 const gchar *meta_data_str;
599 GST_LOG ("Reading/casting for GstRegistryChunkElementFactory at address %p",
601 unpack_element (*in, ef, GstRegistryChunkElementFactory, end, fail);
602 pf = (GstRegistryChunkPluginFeature *) ef;
604 /* unpack element factory strings */
605 unpack_string_nocopy (*in, meta_data_str, end, fail);
606 if (meta_data_str && *meta_data_str) {
607 factory->metadata = gst_structure_from_string (meta_data_str, NULL);
608 if (!factory->metadata) {
610 ("Error when trying to deserialize structure for metadata '%s'",
615 n = ef->npadtemplates;
616 GST_DEBUG ("Element factory : npadtemplates=%d", n);
618 /* load pad templates */
619 for (i = 0; i < n; i++) {
620 if (G_UNLIKELY (!gst_registry_chunks_load_pad_template (factory, in,
622 GST_ERROR ("Error while loading binary pad template");
628 if (G_UNLIKELY ((n = ef->nuriprotocols))) {
629 GST_DEBUG ("Reading %d UriTypes at address %p", n, *in);
632 factory->uri_type = *((guint *) * in);
633 *in += sizeof (factory->uri_type);
634 /*unpack_element(*in, &factory->uri_type, factory->uri_type, end, fail); */
636 factory->uri_protocols = g_new0 (gchar *, n + 1);
637 for (i = 0; i < n; i++) {
638 unpack_string (*in, str, end, fail);
639 factory->uri_protocols[i] = str;
642 /* load interfaces */
643 if (G_UNLIKELY ((n = ef->ninterfaces))) {
644 GST_DEBUG ("Reading %d Interfaces at address %p", n, *in);
645 for (i = 0; i < n; i++) {
646 unpack_string_nocopy (*in, const_str, end, fail);
647 __gst_element_factory_add_interface (factory, const_str);
650 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
651 GstRegistryChunkTypeFindFactory *tff;
652 GstTypeFindFactory *factory = GST_TYPE_FIND_FACTORY (feature);
656 ("Reading/casting for GstRegistryChunkPluginFeature at address %p",
658 unpack_element (*in, tff, GstRegistryChunkTypeFindFactory, end, fail);
659 pf = (GstRegistryChunkPluginFeature *) tff;
661 /* load typefinder caps */
662 unpack_string_nocopy (*in, const_str, end, fail);
663 if (const_str != NULL && *const_str != '\0')
664 factory->caps = gst_caps_from_string (const_str);
666 factory->caps = NULL;
668 /* load extensions */
669 if (tff->nextensions) {
670 GST_DEBUG ("Reading %d Typefind extensions at address %p",
671 tff->nextensions, *in);
672 factory->extensions = g_new0 (gchar *, tff->nextensions + 1);
673 /* unpack in reverse order to maintain the correct order */
674 for (i = tff->nextensions; i > 0; i--) {
675 unpack_string (*in, str, end, fail);
676 factory->extensions[i - 1] = str;
679 } else if (GST_IS_DEVICE_PROVIDER_FACTORY (feature)) {
680 GstRegistryChunkDeviceProviderFactory *dmf;
681 GstDeviceProviderFactory *factory = GST_DEVICE_PROVIDER_FACTORY (feature);
682 const gchar *meta_data_str;
686 ("Reading/casting for GstRegistryChunkPluginFeature at address %p",
689 unpack_element (*in, dmf, GstRegistryChunkDeviceProviderFactory, end, fail);
691 pf = (GstRegistryChunkPluginFeature *) dmf;
693 /* unpack element factory strings */
694 unpack_string_nocopy (*in, meta_data_str, end, fail);
695 if (meta_data_str && *meta_data_str) {
696 factory->metadata = gst_structure_from_string (meta_data_str, NULL);
697 if (!factory->metadata) {
699 ("Error when trying to deserialize structure for metadata '%s'",
704 } else if (GST_IS_TRACER_FACTORY (feature)) {
707 ("Reading/casting for GstRegistryChunkPluginFeature at address %p",
709 unpack_element (*in, pf, GstRegistryChunkPluginFeature, end, fail);
711 GST_WARNING ("unhandled factory type : %s", G_OBJECT_TYPE_NAME (feature));
715 feature->rank = pf->rank;
717 feature->plugin_name = plugin_name;
718 feature->plugin = plugin;
719 g_object_add_weak_pointer ((GObject *) plugin,
720 (gpointer *) & feature->plugin);
722 gst_registry_add_feature (registry, feature);
723 GST_DEBUG ("Added feature %s, plugin %p %s", GST_OBJECT_NAME (feature),
724 plugin, plugin_name);
730 GST_INFO ("Reading plugin feature failed");
732 if (GST_IS_OBJECT (feature))
733 gst_object_unref (feature);
735 g_object_unref (feature);
741 gst_registry_chunks_load_plugin_dep_strv (gchar ** in, gchar * end, guint n)
748 arr = g_new0 (gchar *, n + 1);
750 unpack_string (*in, arr[n - 1], end, fail);
755 GST_INFO ("Reading plugin dependency strings failed");
760 gst_registry_chunks_load_plugin_dep (GstPlugin * plugin, gchar ** in,
764 GstRegistryChunkDep *d;
768 GST_LOG_OBJECT (plugin, "Unpacking GstRegistryChunkDep from %p", *in);
769 unpack_element (*in, d, GstRegistryChunkDep, end, fail);
771 dep = g_slice_new (GstPluginDep);
773 dep->env_hash = d->env_hash;
774 dep->stat_hash = d->stat_hash;
776 dep->flags = (GstPluginDependencyFlags) d->flags;
778 dep->names = gst_registry_chunks_load_plugin_dep_strv (in, end, d->n_names);
779 dep->paths = gst_registry_chunks_load_plugin_dep_strv (in, end, d->n_paths);
781 gst_registry_chunks_load_plugin_dep_strv (in, end, d->n_env_vars);
783 plugin->priv->deps = g_list_append (plugin->priv->deps, dep);
785 GST_DEBUG_OBJECT (plugin, "Loaded external plugin dependency from registry: "
786 "env_hash: %08x, stat_hash: %08x", dep->env_hash, dep->stat_hash);
787 for (s = dep->env_vars; s != NULL && *s != NULL; ++s)
788 GST_LOG_OBJECT (plugin, " evar: %s", *s);
789 for (s = dep->paths; s != NULL && *s != NULL; ++s)
790 GST_LOG_OBJECT (plugin, " path: %s", *s);
791 for (s = dep->names; s != NULL && *s != NULL; ++s)
792 GST_LOG_OBJECT (plugin, " name: %s", *s);
796 GST_INFO ("Reading plugin dependency failed");
802 * _priv_gst_registry_chunks_load_plugin:
804 * Make a new GstPlugin from current GstRegistryChunkPluginElement structure
805 * and add it to the GstRegistry. Return an offset to the next
806 * GstRegistryChunkPluginElement structure.
809 _priv_gst_registry_chunks_load_plugin (GstRegistry * registry, gchar ** in,
810 gchar * end, GstPlugin ** out_plugin)
812 #ifndef GST_DISABLE_GST_DEBUG
815 GstRegistryChunkPluginElement *pe;
816 const gchar *cache_str = NULL;
817 GstPlugin *plugin = NULL;
821 GST_LOG ("Reading/casting for GstRegistryChunkPluginElement at address %p",
823 unpack_element (*in, pe, GstRegistryChunkPluginElement, end, fail);
825 plugin = g_object_newv (GST_TYPE_PLUGIN, 0, NULL);
827 /* TODO: also set GST_PLUGIN_FLAG_CONST */
828 GST_OBJECT_FLAG_SET (plugin, GST_PLUGIN_FLAG_CACHED);
829 plugin->file_mtime = pe->file_mtime;
830 plugin->file_size = pe->file_size;
832 /* unpack plugin element strings */
833 unpack_const_string (*in, plugin->desc.name, end, fail);
834 unpack_const_string (*in, plugin->desc.description, end, fail);
835 unpack_string (*in, plugin->filename, end, fail);
836 unpack_const_string (*in, plugin->desc.version, end, fail);
837 unpack_const_string (*in, plugin->desc.license, end, fail);
838 unpack_const_string (*in, plugin->desc.source, end, fail);
839 unpack_const_string (*in, plugin->desc.package, end, fail);
840 unpack_const_string (*in, plugin->desc.origin, end, fail);
841 unpack_const_string (*in, plugin->desc.release_datetime, end, fail);
843 GST_LOG ("read strings for name='%s'", plugin->desc.name);
844 GST_LOG (" desc.description='%s'", plugin->desc.description);
845 GST_LOG (" filename='%s'", plugin->filename);
846 GST_LOG (" desc.version='%s'", plugin->desc.version);
847 GST_LOG (" desc.license='%s'", plugin->desc.license);
848 GST_LOG (" desc.source='%s'", plugin->desc.source);
849 GST_LOG (" desc.package='%s'", plugin->desc.package);
850 GST_LOG (" desc.origin='%s'", plugin->desc.origin);
851 GST_LOG (" desc.datetime=%s", plugin->desc.release_datetime);
853 if (plugin->desc.release_datetime[0] == '\0')
854 plugin->desc.release_datetime = NULL;
856 /* unpack cache data */
857 unpack_string_nocopy (*in, cache_str, end, fail);
858 if (cache_str != NULL && *cache_str != '\0')
859 plugin->priv->cache_data = gst_structure_from_string (cache_str, NULL);
861 /* If the license string is 'BLACKLIST', mark this as a blacklisted
863 if (strcmp (plugin->desc.license, "BLACKLIST") == 0)
864 GST_OBJECT_FLAG_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED);
866 plugin->basename = g_path_get_basename (plugin->filename);
868 /* Takes ownership of plugin */
869 gst_registry_add_plugin (registry, plugin);
871 GST_DEBUG ("Added plugin '%s' plugin with %d features from binary registry",
872 plugin->desc.name, n);
874 /* Load plugin features */
875 for (i = 0; i < n; i++) {
876 if (G_UNLIKELY (!gst_registry_chunks_load_feature (registry, in, end,
878 GST_ERROR ("Error while loading binary feature for plugin '%s'",
879 GST_STR_NULL (plugin->desc.name));
880 gst_registry_remove_plugin (registry, plugin);
885 /* Load external plugin dependencies */
886 for (i = 0; i < pe->n_deps; ++i) {
887 if (G_UNLIKELY (!gst_registry_chunks_load_plugin_dep (plugin, in, end))) {
888 GST_ERROR_OBJECT (plugin, "Could not read external plugin dependency "
889 "for plugin '%s'", GST_STR_NULL (plugin->desc.name));
890 gst_registry_remove_plugin (registry, plugin);
896 *out_plugin = plugin;
902 GST_INFO ("Reading plugin failed after %u bytes", (guint) (end - start));
907 _priv_gst_registry_chunks_save_global_header (GList ** list,
908 GstRegistry * registry, guint32 filter_env_hash)
910 GstRegistryChunkGlobalHeader *hdr;
911 GstRegistryChunk *chk;
913 hdr = g_slice_new (GstRegistryChunkGlobalHeader);
914 chk = gst_registry_chunks_make_data (hdr,
915 sizeof (GstRegistryChunkGlobalHeader));
917 hdr->filter_env_hash = filter_env_hash;
919 *list = g_list_prepend (*list, chk);
921 GST_LOG ("Saved global header (filter_env_hash=0x%08x)", filter_env_hash);
925 _priv_gst_registry_chunks_load_global_header (GstRegistry * registry,
926 gchar ** in, gchar * end, guint32 * filter_env_hash)
928 GstRegistryChunkGlobalHeader *hdr;
931 GST_LOG ("Reading/casting for GstRegistryChunkGlobalHeader at %p", *in);
932 unpack_element (*in, hdr, GstRegistryChunkGlobalHeader, end, fail);
933 *filter_env_hash = hdr->filter_env_hash;
938 GST_WARNING ("Reading global header failed");