Title: [227067] trunk
Revision
227067
Author
[email protected]
Date
2018-01-17 09:00:07 -0800 (Wed, 17 Jan 2018)

Log Message

[EME][GStreamer] Add the full-sample encryption support in the GStreamer ClearKey decryptor
https://bugs.webkit.org/show_bug.cgi?id=180080

Patch by Yacine Bandou <[email protected]> on 2018-01-17
Reviewed by Xabier Rodriguez-Calvar.

Source/WebCore:

Currently the GStreamer clearKey decryptor doesn't support the full-sample encryption,
where the buffer is entirely encrypted, it supports only the sub-sample encryption.

Test: media/encrypted-media/clearKey/clearKey-cenc-audio-playback-mse.html

* platform/graphics/gstreamer/eme/WebKitClearKeyDecryptorGStreamer.cpp:
(webKitMediaClearKeyDecryptorDecrypt):

LayoutTests:

* platform/wpe/TestExpectations:
This patch fixes the crash of the test clearKey-cenc-audio-playback-mse.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (227066 => 227067)


--- trunk/LayoutTests/ChangeLog	2018-01-17 14:30:58 UTC (rev 227066)
+++ trunk/LayoutTests/ChangeLog	2018-01-17 17:00:07 UTC (rev 227067)
@@ -1,3 +1,13 @@
+2018-01-17  Yacine Bandou  <[email protected]>
+
+        [EME][GStreamer] Add the full-sample encryption support in the GStreamer ClearKey decryptor
+        https://bugs.webkit.org/show_bug.cgi?id=180080
+
+        Reviewed by Xabier Rodriguez-Calvar.
+
+        * platform/wpe/TestExpectations:
+        This patch fixes the crash of the test clearKey-cenc-audio-playback-mse.
+
 2018-01-17  Ali Juma  <[email protected]>
 
         Update web platform tests for Visual Viewport API

Modified: trunk/LayoutTests/platform/wpe/TestExpectations (227066 => 227067)


--- trunk/LayoutTests/platform/wpe/TestExpectations	2018-01-17 14:30:58 UTC (rev 227066)
+++ trunk/LayoutTests/platform/wpe/TestExpectations	2018-01-17 17:00:07 UTC (rev 227067)
@@ -1129,8 +1129,6 @@
 
 webkit.org/b/178703 imported/w3c/web-platform-tests/encrypted-media/clearkey-mp4-playback-temporary-clear-encrypted.html [ Crash ]
 
-webkit.org/b/180080 media/encrypted-media/clearKey/clearKey-cenc-audio-playback-mse.html [ Crash ]
-
 webkit.org/b/178705 webgl/1.0.2/conformance/rendering/multisample-corruption.html [ Failure ]
 
 webkit.org/b/179957 crypto/workers/subtle/aes-cbc-import-key-decrypt.html [ Pass Crash ]

Modified: trunk/Source/WebCore/ChangeLog (227066 => 227067)


--- trunk/Source/WebCore/ChangeLog	2018-01-17 14:30:58 UTC (rev 227066)
+++ trunk/Source/WebCore/ChangeLog	2018-01-17 17:00:07 UTC (rev 227067)
@@ -1,3 +1,17 @@
+2018-01-17  Yacine Bandou  <[email protected]>
+        [EME][GStreamer] Add the full-sample encryption support in the GStreamer ClearKey decryptor
+        https://bugs.webkit.org/show_bug.cgi?id=180080
+
+        Reviewed by Xabier Rodriguez-Calvar.
+
+        Currently the GStreamer clearKey decryptor doesn't support the full-sample encryption,
+        where the buffer is entirely encrypted, it supports only the sub-sample encryption.
+
+        Test: media/encrypted-media/clearKey/clearKey-cenc-audio-playback-mse.html
+
+        * platform/graphics/gstreamer/eme/WebKitClearKeyDecryptorGStreamer.cpp:
+        (webKitMediaClearKeyDecryptorDecrypt):
+
 2018-01-17  Zan Dobersek  <[email protected]>
 
         Unreviewed follow-up to r227051.

Modified: trunk/Source/WebCore/platform/graphics/gstreamer/eme/WebKitClearKeyDecryptorGStreamer.cpp (227066 => 227067)


--- trunk/Source/WebCore/platform/graphics/gstreamer/eme/WebKitClearKeyDecryptorGStreamer.cpp	2018-01-17 14:30:58 UTC (rev 227066)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/eme/WebKitClearKeyDecryptorGStreamer.cpp	2018-01-17 17:00:07 UTC (rev 227067)
@@ -207,6 +207,12 @@
 static gboolean webKitMediaClearKeyDecryptorDecrypt(WebKitMediaCommonEncryptionDecrypt* self, GstBuffer* ivBuffer, GstBuffer* buffer, unsigned subSampleCount, GstBuffer* subSamplesBuffer)
 {
     GstMapInfo ivMap;
+    // Check ivBuffer isn't null.
+    if (!ivBuffer) {
+        GST_ERROR_OBJECT(self, "Error, the ivBuffer is null");
+        return false;
+    }
+
     if (!gst_buffer_map(ivBuffer, &ivMap, GST_MAP_READ)) {
         GST_ERROR_OBJECT(self, "Failed to map IV");
         return false;
@@ -223,12 +229,18 @@
     gst_buffer_unmap(ivBuffer, &ivMap);
 
     WebKitMediaClearKeyDecryptPrivate* priv = WEBKIT_MEDIA_CK_DECRYPT_GET_PRIVATE(WEBKIT_MEDIA_CK_DECRYPT(self));
-    gcry_error_t error = gcry_cipher_setctr(priv->handle, ctr, CLEARKEY_SIZE);
-    if (error) {
-        GST_ERROR_OBJECT(self, "gcry_cipher_setctr failed: %s", gpg_strerror(error));
+    gcry_error_t cipherError = gcry_cipher_setctr(priv->handle, ctr, CLEARKEY_SIZE);
+    if (cipherError) {
+        GST_ERROR_OBJECT(self, "gcry_cipher_setctr failed: %s", gpg_strerror(cipherError));
         return false;
     }
 
+    // Check buffer isn't null.
+    if (!buffer) {
+        GST_ERROR_OBJECT(self, "Error, the buffer is null");
+        return false;
+    }
+
     GstMapInfo map;
     gboolean bufferMapped = gst_buffer_map(buffer, &map, static_cast<GstMapFlags>(GST_MAP_READWRITE));
     if (!bufferMapped) {
@@ -236,34 +248,55 @@
         return false;
     }
 
+    bool returnValue = true;
+    GstByteReader* reader;
+    unsigned position = 0;
     GstMapInfo subSamplesMap;
-    gboolean subsamplesBufferMapped = gst_buffer_map(subSamplesBuffer, &subSamplesMap, GST_MAP_READ);
-    if (!subsamplesBufferMapped) {
+
+    if (!subSampleCount) {
+        // Full sample encryption.
+        GST_TRACE_OBJECT(self, "full sample encryption: %d encrypted bytes", map.size);
+
+        // Check if the buffer is empty.
+        if (map.size) {
+            cipherError = gcry_cipher_decrypt(priv->handle, map.data, map.size, 0, 0);
+            if (cipherError) {
+                GST_ERROR_OBJECT(self, "full sample decryption failed: %s", gpg_strerror(cipherError));
+                returnValue = false;
+            }
+        }
+        goto releaseBuffer;
+    }
+
+    // Check subSamplesBuffer isn't null.
+    if (!subSamplesBuffer) {
+        GST_ERROR_OBJECT(self, "Error, the subSampleBuffer is null");
+        returnValue = false;
+        goto releaseBuffer;
+    }
+
+    // Subsample encryption.
+    if (!gst_buffer_map(subSamplesBuffer, &subSamplesMap, GST_MAP_READ)) {
         GST_ERROR_OBJECT(self, "Failed to map subsample buffer");
-        gst_buffer_unmap(buffer, &map);
-        return false;
+        returnValue = false;
+        goto releaseBuffer;
     }
 
-    GstByteReader* reader = gst_byte_reader_new(subSamplesMap.data, subSamplesMap.size);
-    unsigned position = 0;
-    unsigned sampleIndex = 0;
-
+    reader = gst_byte_reader_new(subSamplesMap.data, subSamplesMap.size);
     GST_DEBUG_OBJECT(self, "position: %d, size: %zu", position, map.size);
 
     while (position < map.size) {
         guint16 nBytesClear = 0;
         guint32 nBytesEncrypted = 0;
+        unsigned sampleIndex = 0;
 
         if (sampleIndex < subSampleCount) {
             if (!gst_byte_reader_get_uint16_be(reader, &nBytesClear)
                 || !gst_byte_reader_get_uint32_be(reader, &nBytesEncrypted)) {
                 GST_DEBUG_OBJECT(self, "unsupported");
-                gst_byte_reader_free(reader);
-                gst_buffer_unmap(buffer, &map);
-                gst_buffer_unmap(subSamplesBuffer, &subSamplesMap);
-                return false;
+                returnValue = false;
+                goto releaseSubsamples;
             }
-
             sampleIndex++;
         } else {
             nBytesClear = 0;
@@ -270,26 +303,26 @@
             nBytesEncrypted = map.size - position;
         }
 
-        GST_TRACE_OBJECT(self, "%d bytes clear (todo=%zu)", nBytesClear, map.size - position);
+        GST_TRACE_OBJECT(self, "subsample index %u - %hu bytes clear (todo=%zu)", sampleIndex, nBytesClear, map.size - position);
         position += nBytesClear;
         if (nBytesEncrypted) {
-            GST_TRACE_OBJECT(self, "%d bytes encrypted (todo=%zu)", nBytesEncrypted, map.size - position);
-            error = gcry_cipher_decrypt(priv->handle, map.data + position, nBytesEncrypted, 0, 0);
-            if (error) {
-                GST_ERROR_OBJECT(self, "decryption failed: %s", gpg_strerror(error));
-                gst_byte_reader_free(reader);
-                gst_buffer_unmap(buffer, &map);
-                gst_buffer_unmap(subSamplesBuffer, &subSamplesMap);
-                return false;
+            GST_TRACE_OBJECT(self, "subsample index %u - %hu bytes encrypted (todo=%zu)", sampleIndex, nBytesEncrypted, map.size - position);
+            cipherError = gcry_cipher_decrypt(priv->handle, map.data + position, nBytesEncrypted, 0, 0);
+            if (cipherError) {
+                GST_ERROR_OBJECT(self, "sub sample index %u decryption failed: %s", sampleIndex, gpg_strerror(cipherError));
+                returnValue = false;
+                goto releaseSubsamples;
             }
             position += nBytesEncrypted;
         }
     }
+releaseSubsamples:
+    gst_byte_reader_free(reader);
+    gst_buffer_unmap(subSamplesBuffer, &subSamplesMap);
 
-    gst_byte_reader_free(reader);
+releaseBuffer:
     gst_buffer_unmap(buffer, &map);
-    gst_buffer_unmap(subSamplesBuffer, &subSamplesMap);
-    return true;
+    return returnValue;
 }
 
 static void webKitMediaClearKeyDecryptorReleaseCipher(WebKitMediaCommonEncryptionDecrypt* self)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to