X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gst%2Fgstprotection.c;h=af0434a2b7ac26f13d7c6fbcec4338dc5959ce34;hb=dac5966da6a0f53d0443dfa1ac239289028c415d;hp=36f36adf6d454d92fdfd47d8fac2767b6f57dc00;hpb=abdafb0d641448e4693bd98740f7c26f1860fa15;p=platform%2Fupstream%2Fgstreamer.git diff --git a/gst/gstprotection.c b/gst/gstprotection.c index 36f36ad..af0434a 100644 --- a/gst/gstprotection.c +++ b/gst/gstprotection.c @@ -19,6 +19,7 @@ /** * SECTION:gstprotection + * @title: GstProtection * @short_description: Functions and classes to support encrypted streams. * * The GstProtectionMeta class enables the information needed to decrypt a @@ -84,19 +85,41 @@ gst_protection_meta_free (GstMeta * meta, GstBuffer * buffer) gst_structure_free (protection_meta->info); } +static gboolean +gst_protection_meta_transform (GstBuffer * transbuf, GstMeta * meta, + GstBuffer * buffer, GQuark type, gpointer data) +{ + GstProtectionMeta *protection_meta = (GstProtectionMeta *) meta; + + if (GST_META_TRANSFORM_IS_COPY (type)) { + GstMetaTransformCopy *copy = data; + if (!copy->region) { + /* only copy if the complete data is copied as well */ + gst_buffer_add_protection_meta (transbuf, + gst_structure_copy (protection_meta->info)); + } else { + return FALSE; + } + } else { + /* transform type not supported */ + return FALSE; + } + return TRUE; +} + const GstMetaInfo * gst_protection_meta_get_info (void) { static const GstMetaInfo *protection_meta_info = NULL; - if (g_once_init_enter (&protection_meta_info)) { + if (g_once_init_enter ((GstMetaInfo **) & protection_meta_info)) { const GstMetaInfo *meta = gst_meta_register (GST_PROTECTION_META_API_TYPE, "GstProtectionMeta", sizeof (GstProtectionMeta), gst_protection_meta_init, - gst_protection_meta_free, - (GstMetaTransformFunction) NULL); + gst_protection_meta_free, gst_protection_meta_transform); - g_once_init_leave (&protection_meta_info, meta); + g_once_init_leave ((GstMetaInfo **) & protection_meta_info, + (GstMetaInfo *) meta); } return protection_meta_info; } @@ -111,7 +134,7 @@ gst_protection_meta_get_info (void) * * Attaches protection metadata to a #GstBuffer. * - * Returns: a pointer to the added #GstProtectionMeta if successful; %NULL if + * Returns: (transfer none): a pointer to the added #GstProtectionMeta if successful; %NULL if * unsuccessful. * * Since: 1.6 @@ -135,7 +158,7 @@ gst_buffer_add_protection_meta (GstBuffer * buffer, GstStructure * info) /** * gst_protection_select_system: - * @system_identifiers: (transfer none): A null terminated array of strings + * @system_identifiers: (transfer none) (array zero-terminated=1): A null terminated array of strings * that contains the UUID values of each protection system that is to be * checked. * @@ -143,9 +166,10 @@ gst_buffer_add_protection_meta (GstBuffer * buffer, GstStructure * info) * an element that supports one of the supplied UUIDs. If more than one * element matches, the system ID of the highest ranked element is selected. * - * Returns: (transfer none): One of the strings from @system_identifiers that - * indicates the highest ranked element that implements the protection system - * indicated by that system ID, or %NULL if no element has been found. + * Returns: (transfer none) (nullable): One of the strings from + * @system_identifiers that indicates the highest ranked element that + * implements the protection system indicated by that system ID, or %NULL if no + * element has been found. * * Since: 1.6 */ @@ -170,6 +194,68 @@ gst_protection_select_system (const gchar ** system_identifiers) return retval; } +/** + * gst_protection_filter_systems_by_available_decryptors: + * @system_identifiers: (transfer none) (array zero-terminated=1): + * A null terminated array of strings that contains the UUID values of each + * protection system that is to be checked. + * + * Iterates the supplied list of UUIDs and checks the GstRegistry for + * all the decryptors supporting one of the supplied UUIDs. + * + * Returns: (transfer full) (array zero-terminated=1) (nullable): + * A null terminated array containing all + * the @system_identifiers supported by the set of available decryptors, or + * %NULL if no matches were found. + * + * Since: 1.14 + */ +gchar ** +gst_protection_filter_systems_by_available_decryptors (const gchar ** + system_identifiers) +{ + GList *decryptors, *walk; + gchar **retval = NULL; + guint i = 0, decryptors_number; + + decryptors = + gst_element_factory_list_get_elements (GST_ELEMENT_FACTORY_TYPE_DECRYPTOR, + GST_RANK_MARGINAL); + + decryptors_number = g_list_length (decryptors); + + GST_TRACE ("found %u decrytors", decryptors_number); + + if (decryptors_number == 0) + goto beach; + + retval = g_new (gchar *, decryptors_number + 1); + + for (walk = decryptors; walk; walk = g_list_next (walk)) { + GstElementFactory *fact = (GstElementFactory *) walk->data; + const char *found_sys_id = + gst_protection_factory_check (fact, system_identifiers); + + GST_DEBUG ("factory %s is valid for %s", GST_OBJECT_NAME (fact), + found_sys_id); + + if (found_sys_id) { + retval[i++] = g_strdup (found_sys_id); + } + } + retval[i] = NULL; + + if (retval[0] == NULL) { + g_free (retval); + retval = NULL; + } + +beach: + gst_plugin_feature_list_free (decryptors); + + return retval; +} + static const gchar * gst_protection_factory_check (GstElementFactory * fact, const gchar ** system_identifiers) @@ -182,18 +268,19 @@ gst_protection_factory_check (GstElementFactory * fact, GstStaticPadTemplate *templ = walk->data; GstCaps *caps = gst_static_pad_template_get_caps (templ); guint leng = gst_caps_get_size (caps); + guint i, j; - for (guint i = 0; !retval && i < leng; ++i) { + for (i = 0; !retval && i < leng; ++i) { GstStructure *st; st = gst_caps_get_structure (caps, i); - if (gst_structure_has_field_typed (st, PROTECTION_SYSTEM_ID_CAPS_FIELD, - G_TYPE_STRING)) { + if (gst_structure_has_field_typed (st, + GST_PROTECTION_SYSTEM_ID_CAPS_FIELD, G_TYPE_STRING)) { const gchar *sys_id = - gst_structure_get_string (st, PROTECTION_SYSTEM_ID_CAPS_FIELD); + gst_structure_get_string (st, GST_PROTECTION_SYSTEM_ID_CAPS_FIELD); GST_DEBUG ("Found decryptor that supports protection system %s", sys_id); - for (guint j = 0; !retval && system_identifiers[j]; ++j) { + for (j = 0; !retval && system_identifiers[j]; ++j) { GST_TRACE (" compare with %s", system_identifiers[j]); if (g_ascii_strcasecmp (system_identifiers[j], sys_id) == 0) { GST_DEBUG (" Selecting %s", system_identifiers[j]);