+ kid_buf = gst_buffer_new_allocate (NULL, 16, NULL);
+ gst_buffer_fill (kid_buf, 0, kid, 16);
+ if (ss_info->default_properties)
+ gst_structure_free (ss_info->default_properties);
+ ss_info->default_properties =
+ gst_structure_new ("application/x-cenc",
+ "iv_size", G_TYPE_UINT, iv_size,
+ "encrypted", G_TYPE_BOOLEAN, is_encrypted,
+ "kid", GST_TYPE_BUFFER, kid_buf, NULL);
+ GST_DEBUG_OBJECT (qtdemux, "default sample properties: "
+ "is_encrypted=%u, iv_size=%u", is_encrypted, iv_size);
+ gst_buffer_unref (kid_buf);
+ } else if ((flags & 0x000002)) {
+ uses_sub_sample_encryption = TRUE;
+ }
+
+ if (!gst_byte_reader_get_uint32_be (&br, &qtdemux->cenc_aux_sample_count)) {
+ GST_ERROR_OBJECT (qtdemux, "Error getting box's sample count field");
+ return;
+ }
+
+ ss_info->crypto_info =
+ g_ptr_array_new_full (qtdemux->cenc_aux_sample_count,
+ (GDestroyNotify) qtdemux_gst_structure_free);
+
+ for (i = 0; i < qtdemux->cenc_aux_sample_count; ++i) {
+ GstStructure *properties;
+ guint8 *data;
+ GstBuffer *buf;
+
+ properties = qtdemux_get_cenc_sample_properties (qtdemux, stream, i);
+ if (properties == NULL) {
+ GST_ERROR_OBJECT (qtdemux, "failed to get properties for sample %u", i);
+ return;
+ }
+
+ if (!gst_byte_reader_dup_data (&br, iv_size, &data)) {
+ GST_ERROR_OBJECT (qtdemux, "IV data not present for sample %u", i);
+ gst_structure_free (properties);
+ return;
+ }
+ buf = gst_buffer_new_wrapped (data, iv_size);
+ gst_structure_set (properties, "iv", GST_TYPE_BUFFER, buf, NULL);
+ gst_buffer_unref (buf);
+
+ if (uses_sub_sample_encryption) {
+ guint16 n_subsamples;
+
+ if (!gst_byte_reader_get_uint16_be (&br, &n_subsamples)
+ || n_subsamples == 0) {
+ GST_ERROR_OBJECT (qtdemux,
+ "failed to get subsample count for sample %u", i);
+ gst_structure_free (properties);
+ return;
+ }
+ GST_LOG_OBJECT (qtdemux, "subsample count: %u", n_subsamples);
+ if (!gst_byte_reader_dup_data (&br, n_subsamples * 6, &data)) {
+ GST_ERROR_OBJECT (qtdemux, "failed to get subsample data for sample %u",
+ i);
+ gst_structure_free (properties);
+ return;
+ }
+ buf = gst_buffer_new_wrapped (data, n_subsamples * 6);
+ gst_structure_set (properties,
+ "subsample_count", G_TYPE_UINT, n_subsamples,
+ "subsamples", GST_TYPE_BUFFER, buf, NULL);
+ gst_buffer_unref (buf);
+ } else {
+ gst_structure_set (properties, "subsample_count", G_TYPE_UINT, 0, NULL);
+ }
+
+ g_ptr_array_add (ss_info->crypto_info, properties);
+ }
+}
+
+static void
+qtdemux_parse_uuid (GstQTDemux * qtdemux, const guint8 * buffer, gint length)
+{
+ static const guint8 xmp_uuid[] = { 0xBE, 0x7A, 0xCF, 0xCB,
+ 0x97, 0xA9, 0x42, 0xE8,
+ 0x9C, 0x71, 0x99, 0x94,
+ 0x91, 0xE3, 0xAF, 0xAC
+ };
+ static const guint8 playready_uuid[] = {
+ 0xd0, 0x8a, 0x4f, 0x18, 0x10, 0xf3, 0x4a, 0x82,
+ 0xb6, 0xc8, 0x32, 0xd8, 0xab, 0xa1, 0x83, 0xd3
+ };
+
+ static const guint8 piff_sample_encryption_uuid[] = {
+ 0xa2, 0x39, 0x4f, 0x52, 0x5a, 0x9b, 0x4f, 0x14,
+ 0xa2, 0x44, 0x6c, 0x42, 0x7c, 0x64, 0x8d, 0xf4
+ };
+
+ guint offset;
+
+ /* counts as header data */
+ qtdemux->header_size += length;
+
+ offset = (QT_UINT32 (buffer) == 0) ? 16 : 8;
+
+ if (length <= offset + 16) {
+ GST_DEBUG_OBJECT (qtdemux, "uuid atom is too short, skipping");
+ return;
+ }
+
+ if (memcmp (buffer + offset, xmp_uuid, 16) == 0) {
+ GstBuffer *buf;
+ GstTagList *taglist;
+
+ buf = _gst_buffer_new_wrapped ((guint8 *) buffer + offset + 16,
+ length - offset - 16, NULL);
+ taglist = gst_tag_list_from_xmp_buffer (buf);
+ gst_buffer_unref (buf);
+
+ /* make sure we have a usable taglist */
+ qtdemux->tag_list = gst_tag_list_make_writable (qtdemux->tag_list);
+
+ qtdemux_handle_xmp_taglist (qtdemux, qtdemux->tag_list, taglist);
+
+ } else if (memcmp (buffer + offset, playready_uuid, 16) == 0) {
+ int len;
+ const gunichar2 *s_utf16;
+ char *contents;
+
+ len = GST_READ_UINT16_LE (buffer + offset + 0x30);
+ s_utf16 = (const gunichar2 *) (buffer + offset + 0x32);
+ contents = g_utf16_to_utf8 (s_utf16, len / 2, NULL, NULL, NULL);
+ GST_ERROR_OBJECT (qtdemux, "contents: %s", contents);
+
+ g_free (contents);
+
+ GST_ELEMENT_ERROR (qtdemux, STREAM, DECRYPT,
+ (_("Cannot play stream because it is encrypted with PlayReady DRM.")),