Title: [280972] trunk
Revision
280972
Author
[email protected]
Date
2021-08-12 10:13:11 -0700 (Thu, 12 Aug 2021)

Log Message

Adopt span in RTCRtpSFrameTransform
https://bugs.webkit.org/show_bug.cgi?id=229029

Reviewed by Eric Carlson.

Source/WebCore:

Transition to Span for improved readability, no change of behavior.

* Modules/mediastream/RTCEncodedFrame.cpp:
(WebCore::RTCEncodedFrame::data const):
* Modules/mediastream/RTCRtpSFrameTransform.cpp:
(WebCore::processFrame):
(WebCore::RTCRtpSFrameTransform::initializeTransformer):
(WebCore::transformFrame):
(WebCore::RTCRtpSFrameTransform::createStreams):
* Modules/mediastream/RTCRtpSFrameTransformer.cpp:
(WebCore::RTCRtpSFrameTransformer::decryptFrame):
(WebCore::RTCRtpSFrameTransformer::encryptFrame):
(WebCore::RTCRtpSFrameTransformer::transform):
* Modules/mediastream/RTCRtpSFrameTransformer.h:
* Modules/mediastream/RTCRtpScriptTransformer.cpp:
(WebCore::RTCRtpScriptTransformer::writable):
* Modules/mediastream/RTCRtpTransformableFrame.h:
(): Deleted.
* Modules/mediastream/libwebrtc/LibWebRTCRtpTransformableFrame.cpp:
(WebCore::LibWebRTCRtpTransformableFrame::data const):
(WebCore::LibWebRTCRtpTransformableFrame::setData):
* Modules/mediastream/libwebrtc/LibWebRTCRtpTransformableFrame.h:

Tools:

* TestWebKitAPI/Tests/WebCore/RTCRtpSFrameTransformerTests.cpp:
(TestWebKitAPI::TEST):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (280971 => 280972)


--- trunk/Source/WebCore/ChangeLog	2021-08-12 16:26:56 UTC (rev 280971)
+++ trunk/Source/WebCore/ChangeLog	2021-08-12 17:13:11 UTC (rev 280972)
@@ -1,3 +1,33 @@
+2021-08-12  Youenn Fablet  <[email protected]>
+
+        Adopt span in RTCRtpSFrameTransform
+        https://bugs.webkit.org/show_bug.cgi?id=229029
+
+        Reviewed by Eric Carlson.
+
+        Transition to Span for improved readability, no change of behavior.
+
+        * Modules/mediastream/RTCEncodedFrame.cpp:
+        (WebCore::RTCEncodedFrame::data const):
+        * Modules/mediastream/RTCRtpSFrameTransform.cpp:
+        (WebCore::processFrame):
+        (WebCore::RTCRtpSFrameTransform::initializeTransformer):
+        (WebCore::transformFrame):
+        (WebCore::RTCRtpSFrameTransform::createStreams):
+        * Modules/mediastream/RTCRtpSFrameTransformer.cpp:
+        (WebCore::RTCRtpSFrameTransformer::decryptFrame):
+        (WebCore::RTCRtpSFrameTransformer::encryptFrame):
+        (WebCore::RTCRtpSFrameTransformer::transform):
+        * Modules/mediastream/RTCRtpSFrameTransformer.h:
+        * Modules/mediastream/RTCRtpScriptTransformer.cpp:
+        (WebCore::RTCRtpScriptTransformer::writable):
+        * Modules/mediastream/RTCRtpTransformableFrame.h:
+        (): Deleted.
+        * Modules/mediastream/libwebrtc/LibWebRTCRtpTransformableFrame.cpp:
+        (WebCore::LibWebRTCRtpTransformableFrame::data const):
+        (WebCore::LibWebRTCRtpTransformableFrame::setData):
+        * Modules/mediastream/libwebrtc/LibWebRTCRtpTransformableFrame.h:
+
 2021-08-12  Johnson Zhou  <[email protected]>
 
         Removal of "TypedOM" prefix for CSSOM Object names

Modified: trunk/Source/WebCore/Modules/mediastream/RTCEncodedFrame.cpp (280971 => 280972)


--- trunk/Source/WebCore/Modules/mediastream/RTCEncodedFrame.cpp	2021-08-12 16:26:56 UTC (rev 280971)
+++ trunk/Source/WebCore/Modules/mediastream/RTCEncodedFrame.cpp	2021-08-12 17:13:11 UTC (rev 280972)
@@ -41,7 +41,7 @@
 RefPtr<JSC::ArrayBuffer> RTCEncodedFrame::data() const
 {
     auto data = ""
-    return JSC::ArrayBuffer::create(data.data, data.size);
+    return JSC::ArrayBuffer::create(data.data(), data.size());
 }
 
 void RTCEncodedFrame::setData(JSC::ArrayBuffer& buffer)

Modified: trunk/Source/WebCore/Modules/mediastream/RTCRtpSFrameTransform.cpp (280971 => 280972)


--- trunk/Source/WebCore/Modules/mediastream/RTCRtpSFrameTransform.cpp	2021-08-12 16:26:56 UTC (rev 280971)
+++ trunk/Source/WebCore/Modules/mediastream/RTCRtpSFrameTransform.cpp	2021-08-12 17:13:11 UTC (rev 280972)
@@ -115,9 +115,9 @@
     }
 }
 
-static std::optional<Vector<uint8_t>> processFrame(const uint8_t* data, size_t size, RTCRtpSFrameTransformer& transformer, ScriptExecutionContextIdentifier identifier, const WeakPtr<RTCRtpSFrameTransform>& weakTransform)
+static std::optional<Vector<uint8_t>> processFrame(Span<const uint8_t> data, RTCRtpSFrameTransformer& transformer, ScriptExecutionContextIdentifier identifier, const WeakPtr<RTCRtpSFrameTransform>& weakTransform)
 {
-    auto result = transformer.transform(data, size);
+    auto result = transformer.transform(data);
     if (!result.has_value()) {
         auto errorInformation = WTFMove(result.error());
         errorInformation.message = { };
@@ -159,9 +159,9 @@
 
     backend.setTransformableFrameCallback([transformer = m_transformer, identifier = context->contextIdentifier(), backend = makeRef(backend), weakThis = makeWeakPtr(this)](auto&& frame) {
         auto chunk = frame->data();
-        if (!chunk.data || !chunk.size)
+        if (!chunk.data() || !chunk.size())
             return;
-        auto result = processFrame(chunk.data, chunk.size, transformer.get(), identifier, weakThis);
+        auto result = processFrame(chunk, transformer.get(), identifier, weakThis);
 
         if (!result)
             return;
@@ -187,9 +187,9 @@
     backend.clearTransformableFrameCallback();
 }
 
-static void transformFrame(const uint8_t* data, size_t size, JSDOMGlobalObject& globalObject, RTCRtpSFrameTransformer& transformer, SimpleReadableStreamSource& source, ScriptExecutionContextIdentifier identifier, const WeakPtr<RTCRtpSFrameTransform>& weakTransform)
+static void transformFrame(Span<const uint8_t> data, JSDOMGlobalObject& globalObject, RTCRtpSFrameTransformer& transformer, SimpleReadableStreamSource& source, ScriptExecutionContextIdentifier identifier, const WeakPtr<RTCRtpSFrameTransform>& weakTransform)
 {
-    auto result = processFrame(data, size, transformer, identifier, weakTransform);
+    auto result = processFrame(data, transformer, identifier, weakTransform);
     auto buffer = result ? SharedBuffer::create(WTFMove(*result)) : SharedBuffer::create();
     source.enqueue(toJS(&globalObject, &globalObject, buffer->tryCreateArrayBuffer().get()));
 }
@@ -198,8 +198,8 @@
 void transformFrame(Frame& frame, JSDOMGlobalObject& globalObject, RTCRtpSFrameTransformer& transformer, SimpleReadableStreamSource& source, ScriptExecutionContextIdentifier identifier, const WeakPtr<RTCRtpSFrameTransform>& weakTransform)
 {
     auto chunk = frame.rtcFrame().data();
-    auto result = processFrame(chunk.data, chunk.size, transformer, identifier, weakTransform);
-    RTCRtpTransformableFrame::Data transformedChunk;
+    auto result = processFrame(chunk, transformer, identifier, weakTransform);
+    Span<const uint8_t> transformedChunk;
     if (result)
         transformedChunk = { result->data(), result->size() };
     frame.rtcFrame().setData(transformedChunk);
@@ -229,9 +229,9 @@
         }, [&](RefPtr<RTCEncodedVideoFrame>& value) {
             transformFrame(*value, globalObject, transformer.get(), *readableStreamSource, context.contextIdentifier(), weakThis);
         }, [&](RefPtr<ArrayBuffer>& value) {
-            transformFrame(static_cast<const uint8_t*>(value->data()), value->byteLength(), globalObject, transformer.get(), *readableStreamSource, context.contextIdentifier(), weakThis);
+            transformFrame({ static_cast<const uint8_t*>(value->data()), value->byteLength() }, globalObject, transformer.get(), *readableStreamSource, context.contextIdentifier(), weakThis);
         }, [&](RefPtr<ArrayBufferView>& value) {
-            transformFrame(static_cast<const uint8_t*>(value->data()), value->byteLength(), globalObject, transformer.get(), *readableStreamSource, context.contextIdentifier(), weakThis);
+            transformFrame({ static_cast<const uint8_t*>(value->data()), value->byteLength() }, globalObject, transformer.get(), *readableStreamSource, context.contextIdentifier(), weakThis);
         });
         return { };
     }));

Modified: trunk/Source/WebCore/Modules/mediastream/RTCRtpSFrameTransformer.cpp (280971 => 280972)


--- trunk/Source/WebCore/Modules/mediastream/RTCRtpSFrameTransformer.cpp	2021-08-12 16:26:56 UTC (rev 280971)
+++ trunk/Source/WebCore/Modules/mediastream/RTCRtpSFrameTransformer.cpp	2021-08-12 17:13:11 UTC (rev 280972)
@@ -206,8 +206,11 @@
     return { };
 }
 
-RTCRtpSFrameTransformer::TransformResult RTCRtpSFrameTransformer::decryptFrame(const uint8_t* frameData, size_t frameSize)
+RTCRtpSFrameTransformer::TransformResult RTCRtpSFrameTransformer::decryptFrame(Span<const uint8_t> data)
 {
+    auto* frameData = data.data();
+    auto frameSize = data.size();
+
     Vector<uint8_t> buffer;
     switch (m_compatibilityMode) {
     case CompatibilityMode::H264: {
@@ -276,8 +279,11 @@
     return result.releaseReturnValue();
 }
 
-RTCRtpSFrameTransformer::TransformResult RTCRtpSFrameTransformer::encryptFrame(const uint8_t* frameData, size_t frameSize)
+RTCRtpSFrameTransformer::TransformResult RTCRtpSFrameTransformer::encryptFrame(Span<const uint8_t> data)
 {
+    auto* frameData = data.data();
+    auto frameSize = data.size();
+
     static const unsigned MaxHeaderSize = 17;
 
     Vector<uint8_t> transformedData;
@@ -337,12 +343,12 @@
     return transformedData;
 }
 
-RTCRtpSFrameTransformer::TransformResult RTCRtpSFrameTransformer::transform(const uint8_t* data, size_t size)
+RTCRtpSFrameTransformer::TransformResult RTCRtpSFrameTransformer::transform(Span<const uint8_t> data)
 {
     if (!m_hasKey)
         return makeUnexpected(ErrorInformation { Error::KeyID,  "Key is not initialized", 0 });
 
-    return m_isEncrypting ? encryptFrame(data, size) : decryptFrame(data, size);
+    return m_isEncrypting ? encryptFrame(data) : decryptFrame(data);
 }
 
 #if !PLATFORM(COCOA)

Modified: trunk/Source/WebCore/Modules/mediastream/RTCRtpSFrameTransformer.h (280971 => 280972)


--- trunk/Source/WebCore/Modules/mediastream/RTCRtpSFrameTransformer.h	2021-08-12 16:26:56 UTC (rev 280971)
+++ trunk/Source/WebCore/Modules/mediastream/RTCRtpSFrameTransformer.h	2021-08-12 17:13:11 UTC (rev 280972)
@@ -56,7 +56,7 @@
         uint64_t keyId { 0 };
     };
     using TransformResult = Expected<Vector<uint8_t>, ErrorInformation>;
-    WEBCORE_EXPORT TransformResult transform(const uint8_t*, size_t);
+    WEBCORE_EXPORT TransformResult transform(Span<const uint8_t>);
 
     const Vector<uint8_t>& authenticationKey() const { return m_authenticationKey; }
     const Vector<uint8_t>& encryptionKey() const { return m_encryptionKey; }
@@ -71,8 +71,8 @@
 private:
     WEBCORE_EXPORT explicit RTCRtpSFrameTransformer(CompatibilityMode);
 
-    TransformResult decryptFrame(const uint8_t*, size_t);
-    TransformResult encryptFrame(const uint8_t*, size_t);
+    TransformResult decryptFrame(Span<const uint8_t>);
+    TransformResult encryptFrame(Span<const uint8_t>);
 
     enum class ShouldUpdateKeys { No, Yes };
     ExceptionOr<void> updateEncryptionKey(const Vector<uint8_t>& rawKey, std::optional<uint64_t>, ShouldUpdateKeys = ShouldUpdateKeys::Yes) WTF_REQUIRES_LOCK(m_keyLock);

Modified: trunk/Source/WebCore/Modules/mediastream/RTCRtpScriptTransformer.cpp (280971 => 280972)


--- trunk/Source/WebCore/Modules/mediastream/RTCRtpScriptTransformer.cpp	2021-08-12 16:26:56 UTC (rev 280971)
+++ trunk/Source/WebCore/Modules/mediastream/RTCRtpScriptTransformer.cpp	2021-08-12 17:13:11 UTC (rev 280972)
@@ -106,7 +106,7 @@
             });
 
             // If no data, skip the frame since there is nothing to packetize or decode.
-            if (rtcFrame->data().data)
+            if (rtcFrame->data().data())
                 transformer->m_backend->processTransformedFrame(rtcFrame.get());
             return { };
         }));

Modified: trunk/Source/WebCore/Modules/mediastream/RTCRtpTransformableFrame.h (280971 => 280972)


--- trunk/Source/WebCore/Modules/mediastream/RTCRtpTransformableFrame.h	2021-08-12 16:26:56 UTC (rev 280971)
+++ trunk/Source/WebCore/Modules/mediastream/RTCRtpTransformableFrame.h	2021-08-12 17:13:11 UTC (rev 280972)
@@ -27,6 +27,7 @@
 #if ENABLE(WEB_RTC)
 
 #include <wtf/RefCounted.h>
+#include <wtf/Span.h>
 #include <wtf/Vector.h>
 
 namespace WebCore {
@@ -50,12 +51,8 @@
 public:
     virtual ~RTCRtpTransformableFrame() = default;
 
-    struct Data {
-        const uint8_t* data { nullptr };
-        size_t size { 0 };
-    };
-    virtual Data data() const = 0;
-    virtual void setData(Data) = 0;
+    virtual Span<const uint8_t> data() const = 0;
+    virtual void setData(Span<const uint8_t>) = 0;
 
     virtual uint64_t timestamp() const = 0;
     virtual RTCEncodedAudioFrameMetadata audioMetadata() const = 0;

Modified: trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCRtpTransformableFrame.cpp (280971 => 280972)


--- trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCRtpTransformableFrame.cpp	2021-08-12 16:26:56 UTC (rev 280971)
+++ trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCRtpTransformableFrame.cpp	2021-08-12 17:13:11 UTC (rev 280972)
@@ -52,18 +52,18 @@
     return WTFMove(m_rtcFrame);
 }
 
-RTCRtpTransformableFrame::Data LibWebRTCRtpTransformableFrame::data() const
+Span<const uint8_t> LibWebRTCRtpTransformableFrame::data() const
 {
     if (!m_rtcFrame)
-        return { nullptr, 0 };
+        return { };
     auto data = ""
     return { data.begin(), data.size() };
 }
 
-void LibWebRTCRtpTransformableFrame::setData(Data data)
+void LibWebRTCRtpTransformableFrame::setData(Span<const uint8_t> data)
 {
     if (m_rtcFrame)
-        m_rtcFrame->SetData({ data.data, data.size });
+        m_rtcFrame->SetData({ data.data(), data.size() });
 }
 
 bool LibWebRTCRtpTransformableFrame::isKeyFrame() const

Modified: trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCRtpTransformableFrame.h (280971 => 280972)


--- trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCRtpTransformableFrame.h	2021-08-12 16:26:56 UTC (rev 280971)
+++ trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCRtpTransformableFrame.h	2021-08-12 17:13:11 UTC (rev 280972)
@@ -47,8 +47,8 @@
     LibWebRTCRtpTransformableFrame(std::unique_ptr<webrtc::TransformableFrameInterface>&&, bool isAudioSenderFrame);
 
     // RTCRtpTransformableFrame
-    Data data() const final;
-    void setData(Data) final;
+    Span<const uint8_t> data() const final;
+    void setData(Span<const uint8_t>) final;
     bool isKeyFrame() const final;
     uint64_t timestamp() const final;
     RTCEncodedAudioFrameMetadata audioMetadata() const final;

Modified: trunk/Tools/ChangeLog (280971 => 280972)


--- trunk/Tools/ChangeLog	2021-08-12 16:26:56 UTC (rev 280971)
+++ trunk/Tools/ChangeLog	2021-08-12 17:13:11 UTC (rev 280972)
@@ -1,3 +1,13 @@
+2021-08-12  Youenn Fablet  <[email protected]>
+
+        Adopt span in RTCRtpSFrameTransform
+        https://bugs.webkit.org/show_bug.cgi?id=229029
+
+        Reviewed by Eric Carlson.
+
+        * TestWebKitAPI/Tests/WebCore/RTCRtpSFrameTransformerTests.cpp:
+        (TestWebKitAPI::TEST):
+
 2021-08-12  Chris Dumez  <[email protected]>
 
         Unreviewed API test build fix with recent MacOS SDK.

Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/RTCRtpSFrameTransformerTests.cpp (280971 => 280972)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/RTCRtpSFrameTransformerTests.cpp	2021-08-12 16:26:56 UTC (rev 280971)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/RTCRtpSFrameTransformerTests.cpp	2021-08-12 17:13:11 UTC (rev 280972)
@@ -199,11 +199,11 @@
     auto decryptor = createVideoTransformer(false);
     auto frame = Vector<uint8_t>::from(135, 89, 51, 166, 248, 129, 157, 111, 190, 134, 220);
 
-    auto encryptedResult = encryptor->transform(frame.data(), frame.size());
+    auto encryptedResult = encryptor->transform({ frame.data(), frame.size() });
     EXPECT_TRUE(encryptedResult.has_value());
 
     auto encrypted = WTFMove(encryptedResult.value());
-    auto decryptedResult = decryptor->transform(encrypted.data(), encrypted.size());
+    auto decryptedResult = decryptor->transform({ encrypted.data(), encrypted.size() });
     EXPECT_TRUE(decryptedResult.has_value());
 
     checkVectorsAreEqual(decryptedResult.value(), frame);
@@ -219,11 +219,11 @@
 
     auto frame = Vector<uint8_t>::from(135, 89, 51, 166, 248, 129, 157, 111, 190, 134, 220);
 
-    auto encryptedResult = encryptor->transform(frame.data(), frame.size());
+    auto encryptedResult = encryptor->transform({ frame.data(), frame.size() });
     EXPECT_TRUE(encryptedResult.has_value());
 
     auto encrypted = WTFMove(encryptedResult.value());
-    auto decryptedResult = decryptor->transform(encrypted.data(), encrypted.size());
+    auto decryptedResult = decryptor->transform({ encrypted.data(), encrypted.size() });
     EXPECT_TRUE(decryptedResult.has_value());
 
     checkVectorsAreEqual(decryptedResult.value(), frame);
@@ -241,11 +241,11 @@
 
     auto frame = Vector<uint8_t>::from(135, 89, 51, 166, 248, 129, 157, 111, 190, 134, 220, 56);
 
-    auto encryptedResult = encryptor->transform(frame.data(), frame.size());
+    auto encryptedResult = encryptor->transform({ frame.data(), frame.size() });
     EXPECT_TRUE(encryptedResult.has_value());
 
     auto encrypted = WTFMove(encryptedResult.value());
-    auto decryptedResult = decryptor->transform(encrypted.data(), encrypted.size());
+    auto decryptedResult = decryptor->transform({ encrypted.data(), encrypted.size() });
     EXPECT_TRUE(decryptedResult.has_value());
 
     checkVectorsAreEqual(decryptedResult.value(), frame);
@@ -256,7 +256,7 @@
     auto transformer = createVideoTransformer();
 
     uint8_t frame1[] = { 135, 89, 51, 166, 248, 129, 157, 111, 190, 134, 220 };
-    auto result = transformer->transform(frame1, sizeof(frame1));
+    auto result = transformer->transform({ frame1, sizeof(frame1) });
     EXPECT_TRUE(result.has_value());
 
     checkVectorsAreEqual(result.value(), Vector<uint8_t>::from(
@@ -299,10 +299,10 @@
     auto transformer = createVideoTransformer();
 
     uint8_t frame1[] = { 8, 164, 189, 18, 61, 117, 132, 43, 117, 169, 42 };
-    auto result = transformer->transform(frame1, sizeof(frame1));
+    auto result = transformer->transform({ frame1, sizeof(frame1) });
     EXPECT_TRUE(result.has_value());
     for (size_t cptr = 0; cptr < 256; ++cptr) {
-        result = transformer->transform(frame1, sizeof(frame1));
+        result = transformer->transform({ frame1, sizeof(frame1) });
         EXPECT_TRUE(result.has_value());
     }
 
@@ -348,7 +348,7 @@
     transformer->setCounter(65536);
 
     uint8_t frame1[] = { 0, 33, 244, 24, 236, 156, 127, 8, 48, 88, 220 };
-    auto result = transformer->transform(frame1, sizeof(frame1));
+    auto result = transformer->transform({ frame1, sizeof(frame1) });
     EXPECT_TRUE(result.has_value());
 
     checkVectorsAreEqual(result.value(), Vector<uint8_t>::from(
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to