Changeset 270290 in webkit
- Timestamp:
- Dec 1, 2020 1:43:00 AM (20 months ago)
- Location:
- trunk
- Files:
-
- 34 edited
- 1 copied
-
LayoutTests/ChangeLog (modified) (1 diff)
-
LayoutTests/http/wpt/webrtc/sframe-transform-expected.txt (modified) (1 diff)
-
LayoutTests/http/wpt/webrtc/sframe-transform.html (modified) (1 diff)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/Modules/mediastream/RTCEncodedAudioFrame.cpp (modified) (1 diff)
-
Source/WebCore/Modules/mediastream/RTCEncodedAudioFrame.h (modified) (1 diff)
-
Source/WebCore/Modules/mediastream/RTCEncodedFrame.cpp (modified) (1 diff)
-
Source/WebCore/Modules/mediastream/RTCEncodedFrame.h (modified) (1 diff)
-
Source/WebCore/Modules/mediastream/RTCEncodedVideoFrame.cpp (modified) (1 diff)
-
Source/WebCore/Modules/mediastream/RTCEncodedVideoFrame.h (modified) (1 diff)
-
Source/WebCore/Modules/mediastream/RTCRtpSFrameTransform.cpp (modified) (4 diffs)
-
Source/WebCore/Modules/mediastream/RTCRtpSFrameTransform.h (modified) (3 diffs)
-
Source/WebCore/Modules/mediastream/RTCRtpSFrameTransform.idl (modified) (3 diffs)
-
Source/WebCore/Modules/mediastream/RTCRtpSFrameTransformer.cpp (modified) (6 diffs)
-
Source/WebCore/Modules/mediastream/RTCRtpSFrameTransformer.h (modified) (4 diffs)
-
Source/WebCore/Modules/mediastream/RTCRtpSFrameTransformerCocoa.cpp (modified) (1 diff)
-
Source/WebCore/Modules/mediastream/RTCRtpScriptTransformer.cpp (modified) (3 diffs)
-
Source/WebCore/Modules/mediastream/RTCRtpScriptTransformer.h (modified) (2 diffs)
-
Source/WebCore/Modules/mediastream/RTCRtpTransformBackend.h (modified) (1 diff)
-
Source/WebCore/Modules/mediastream/RTCRtpTransformableFrame.h (modified) (1 diff)
-
Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCRtpSenderTransformBackend.cpp (modified) (1 diff)
-
Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCRtpTransformBackend.cpp (modified) (3 diffs)
-
Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCRtpTransformBackend.h (modified) (1 diff)
-
Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCRtpTransformableFrame.cpp (copied) (copied from trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCRtpSenderTransformBackend.cpp) (1 diff)
-
Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCRtpTransformableFrame.h (modified) (2 diffs)
-
Source/WebCore/Modules/streams/ReadableStreamSource.cpp (modified) (1 diff)
-
Source/WebCore/Modules/streams/ReadableStreamSource.h (modified) (2 diffs)
-
Source/WebCore/Modules/streams/WritableStreamSink.h (modified) (1 diff)
-
Source/WebCore/Sources.txt (modified) (1 diff)
-
Source/WebCore/WebCore.xcodeproj/project.pbxproj (modified) (2 diffs)
-
Source/WebCore/bindings/js/WritableStream.cpp (modified) (2 diffs)
-
Source/WebCore/bindings/js/WritableStream.h (modified) (1 diff)
-
Source/WebCore/bindings/scripts/CodeGeneratorJS.pm (modified) (1 diff)
-
Tools/ChangeLog (modified) (1 diff)
-
Tools/TestWebKitAPI/Tests/WebCore/RTCRtpSFrameTransformerTests.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r270289 r270290 1 2020-12-01 Youenn Fablet <youenn@apple.com> 2 3 Add support for readable/writable to RTCRtpSFrameTransform 4 https://bugs.webkit.org/show_bug.cgi?id=219298 5 6 Reviewed by Eric Carlson. 7 8 * http/wpt/webrtc/sframe-transform-expected.txt: 9 * http/wpt/webrtc/sframe-transform.html: 10 1 11 2020-12-01 Diego Pino Garcia <dpino@igalia.com> 2 12 -
trunk/LayoutTests/http/wpt/webrtc/sframe-transform-expected.txt
r270107 r270290 1 1 2 2 PASS Cannot reuse attached transforms 3 PASS RTCRtpSFrameTransform exposes readable and writable 4 PASS readable/writable are locked when attached and after being attached 5 PASS SFrame with array buffer - authentication size 10 6 PASS SFrame decryption with array buffer that is too small 7 PASS SFrame transform gets errored if trying to process unexpected value types 3 8 -
trunk/LayoutTests/http/wpt/webrtc/sframe-transform.html
r270107 r270290 29 29 receiver1.transform = null; 30 30 }, "Cannot reuse attached transforms"); 31 32 test(() => { 33 const senderTransform = new RTCRtpSFrameTransform(); 34 35 assert_true(senderTransform.readable instanceof ReadableStream); 36 assert_true(senderTransform.writable instanceof WritableStream); 37 }, "RTCRtpSFrameTransform exposes readable and writable"); 38 39 promise_test(async (test) => { 40 const pc = new RTCPeerConnection(); 41 const senderTransform = new RTCRtpSFrameTransform(); 42 const receiverTransform = new RTCRtpSFrameTransform(); 43 const sender1 = pc.addTransceiver('audio').sender; 44 const sender2 = pc.addTransceiver('video').sender; 45 const receiver1 = pc.getReceivers()[0]; 46 const receiver2 = pc.getReceivers()[1]; 47 48 assert_false(senderTransform.readable.locked, "sender readable before"); 49 assert_false(senderTransform.writable.locked, "sender writable before"); 50 assert_false(receiverTransform.readable.locked, "receiver readable before"); 51 assert_false(receiverTransform.writable.locked, "receiver writable before"); 52 53 sender1.transform = senderTransform; 54 receiver1.transform = receiverTransform; 55 56 assert_true(senderTransform.readable.locked, "sender readable during"); 57 assert_true(senderTransform.writable.locked, "sender writable during"); 58 assert_true(receiverTransform.readable.locked, "receiver readable during"); 59 assert_true(receiverTransform.writable.locked, "receiver writable during"); 60 61 sender1.transform = null; 62 receiver1.transform = null; 63 64 assert_true(senderTransform.readable.locked, "sender readable after"); 65 assert_true(senderTransform.writable.locked, "sender writable after"); 66 assert_true(receiverTransform.readable.locked, "receiver readable after"); 67 assert_true(receiverTransform.writable.locked, "receiver writable after"); 68 }, "readable/writable are locked when attached and after being attached"); 69 70 promise_test(async (test) => { 71 const key = await crypto.subtle.importKey("raw", new Uint8Array([143, 77, 43, 10, 72, 19, 37, 67, 236, 219, 24, 93, 26, 165, 91, 178]), "HKDF", false, ["deriveBits", "deriveKey"]); 72 73 const senderTransform = new RTCRtpSFrameTransform({ role : 'encrypt', authenticationSize: 10 }); 74 senderTransform.setEncryptionKey(key); 75 76 const receiverTransform = new RTCRtpSFrameTransform({ role : 'decrypt', authenticationSize: 10 }); 77 receiverTransform.setEncryptionKey(key); 78 79 const writer = senderTransform.writable.getWriter(); 80 const reader = receiverTransform.readable.getReader(); 81 82 senderTransform.readable.pipeTo(receiverTransform.writable); 83 84 const sent = new ArrayBuffer(8); 85 const view = new Int8Array(sent); 86 for (let cptr = 0; cptr < sent.byteLength; ++cptr) 87 view[cptr] = cptr; 88 89 writer.write(sent); 90 const received = await reader.read(); 91 92 assert_equals(received.value.byteLength, 8); 93 const view2 = new Int8Array(received.value); 94 for (let cptr = 0; cptr < sent.byteLength; ++cptr) 95 assert_equals(view2[cptr], view[cptr]); 96 }, "SFrame with array buffer - authentication size 10"); 97 98 promise_test(async (test) => { 99 const key = await crypto.subtle.importKey("raw", new Uint8Array([143, 77, 43, 10, 72, 19, 37, 67, 236, 219, 24, 93, 26, 165, 91, 178]), "HKDF", false, ["deriveBits", "deriveKey"]); 100 101 const senderTransform = new RTCRtpSFrameTransform({ role : 'encrypt', authenticationSize: 10 }); 102 const senderWriter = senderTransform.writable.getWriter(); 103 const senderReader = senderTransform.readable.getReader(); 104 105 const receiverTransform = new RTCRtpSFrameTransform({ role : 'decrypt', authenticationSize: 10 }); 106 const receiverWriter = receiverTransform.writable.getWriter(); 107 const receiverReader = receiverTransform.readable.getReader(); 108 109 senderTransform.setEncryptionKey(key); 110 receiverTransform.setEncryptionKey(key); 111 112 const chunk = new ArrayBuffer(8); 113 114 // decryption should fail, leading to an empty array buffer. 115 await receiverWriter.write(chunk); 116 let received = await receiverReader.read(); 117 assert_equals(received.value.byteLength, 0); 118 119 // We write again but this time with a chunk we can decrypt. 120 await senderWriter.write(chunk); 121 const encrypted = await senderReader.read(); 122 await receiverWriter.write(encrypted.value); 123 received = await receiverReader.read(); 124 assert_equals(received.value.byteLength, 8); 125 }, "SFrame decryption with array buffer that is too small"); 126 127 promise_test(async (test) => { 128 const key = await crypto.subtle.importKey("raw", new Uint8Array([143, 77, 43, 10, 72, 19, 37, 67, 236, 219, 24, 93, 26, 165, 91, 178]), "HKDF", false, ["deriveBits", "deriveKey"]); 129 130 const receiverTransform = new RTCRtpSFrameTransform({ role : 'decrypt', authenticationSize: 10 }); 131 const receiverWriter = receiverTransform.writable.getWriter(); 132 receiverTransform.setEncryptionKey(key); 133 134 // decryption should fail, leading to erroring the transform. 135 await promise_rejects_js(test, TypeError, receiverWriter.write({ })); 136 await promise_rejects_js(test, TypeError, receiverWriter.closed); 137 }, "SFrame transform gets errored if trying to process unexpected value types"); 138 31 139 </script> 32 140 </body> -
trunk/Source/WebCore/ChangeLog
r270288 r270290 1 2020-12-01 Youenn Fablet <youenn@apple.com> 2 3 Add support for readable/writable to RTCRtpSFrameTransform 4 https://bugs.webkit.org/show_bug.cgi?id=219298 5 6 Reviewed by Eric Carlson. 7 8 Add support for locking WritableStream and checking locked state. 9 Add readable/writable getters so that RTCRtpSFrameTransform can be used as a TransformStream. 10 Make a refactoring to allow reuse of SimpleReadableStreamSource and SimpleWritableStreamSink. 11 12 In case of encryption/decryption error, we do not error the transform as this is final. 13 Instead, we output empty buffers. 14 In case of trying to encrypt unexpected objects, we error the transform. 15 16 Move RTCRtpTransformableFrame to be ref counted. 17 This allows to keep a RTCRtpTransformableFrame for each RTCEncodedFrame even though the underlying 18 webrtc frame (which is a unique ptr) is given back to the webrtc backend after processing. 19 20 Covered by updated test. 21 22 * Modules/mediastream/RTCEncodedAudioFrame.cpp: 23 (WebCore::RTCEncodedAudioFrame::RTCEncodedAudioFrame): 24 * Modules/mediastream/RTCEncodedAudioFrame.h: 25 (WebCore::RTCEncodedAudioFrame::create): 26 * Modules/mediastream/RTCEncodedFrame.cpp: 27 (WebCore::RTCEncodedFrame::RTCEncodedFrame): 28 * Modules/mediastream/RTCEncodedFrame.h: 29 (WebCore::RTCEncodedFrame::rtcFrame): 30 * Modules/mediastream/RTCEncodedVideoFrame.cpp: 31 (WebCore::RTCEncodedVideoFrame::RTCEncodedVideoFrame): 32 * Modules/mediastream/RTCEncodedVideoFrame.h: 33 (WebCore::RTCEncodedVideoFrame::create): 34 * Modules/mediastream/RTCRtpSFrameTransform.cpp: 35 (WebCore::RTCRtpSFrameTransform::RTCRtpSFrameTransform): 36 (WebCore::RTCRtpSFrameTransform::isAttached const): 37 (WebCore::RTCRtpSFrameTransform::initializeTransformer): 38 (WebCore::RTCRtpSFrameTransform::willClearBackend): 39 (WebCore::transformFrame): 40 (WebCore::RTCRtpSFrameTransform::createStreams): 41 (WebCore::RTCRtpSFrameTransform::readable): 42 (WebCore::RTCRtpSFrameTransform::writable): 43 * Modules/mediastream/RTCRtpSFrameTransform.h: 44 (WebCore::RTCRtpSFrameTransform::create): 45 * Modules/mediastream/RTCRtpSFrameTransform.idl: 46 * Modules/mediastream/RTCRtpSFrameTransformer.cpp: 47 (WebCore::RTCRtpSFrameTransformer::setEncryptionKey): 48 (WebCore::RTCRtpSFrameTransformer::decryptFrame): 49 (WebCore::RTCRtpSFrameTransformer::encryptFrame): 50 (WebCore::RTCRtpSFrameTransformer::transform): 51 (WebCore::RTCRtpSFrameTransformer::updateAuthenticationSize): 52 * Modules/mediastream/RTCRtpSFrameTransformer.h: 53 (WebCore::RTCRtpSFrameTransformer::setIsEncrypting): 54 (WebCore::RTCRtpSFrameTransformer::setAuthenticationSize): 55 * Modules/mediastream/RTCRtpSFrameTransformerCocoa.cpp: 56 (WebCore::RTCRtpSFrameTransformer::updateAuthenticationSize): 57 * Modules/mediastream/RTCRtpScriptTransformer.cpp: 58 (WebCore::RTCRtpScriptTransformer::startStreams): 59 * Modules/mediastream/RTCRtpScriptTransformer.h: 60 * Modules/mediastream/RTCRtpTransformBackend.h: 61 * Modules/mediastream/RTCRtpTransformableFrame.h: 62 * Modules/mediastream/libwebrtc/LibWebRTCRtpSenderTransformBackend.cpp: 63 * Modules/mediastream/libwebrtc/LibWebRTCRtpTransformBackend.cpp: 64 (WebCore::LibWebRTCRtpTransformBackend::processTransformedFrame): 65 (WebCore::LibWebRTCRtpTransformBackend::Transform): 66 * Modules/mediastream/libwebrtc/LibWebRTCRtpTransformBackend.h: 67 * Modules/mediastream/libwebrtc/LibWebRTCRtpTransformableFrame.cpp: Added. 68 * Modules/mediastream/libwebrtc/LibWebRTCRtpTransformableFrame.h: 69 * Modules/streams/ReadableStreamSource.h: 70 (WebCore::SimpleReadableStreamSource::create): 71 (WebCore::SimpleReadableStreamSource::close): 72 (WebCore::SimpleReadableStreamSource::enqueue): 73 * Modules/streams/WritableStreamSink.h: 74 (WebCore::SimpleWritableStreamSink::create): 75 (WebCore::SimpleWritableStreamSink::SimpleWritableStreamSink): 76 (WebCore::SimpleWritableStreamSink::write): 77 * bindings/js/WritableStream.cpp: 78 (WebCore::WritableStreamInternal::callFunction): 79 (WebCore::checkWritableStream): 80 (WebCore::WritableStream::lock): 81 (WebCore::WritableStream::isLocked const): 82 * bindings/js/WritableStream.h: 83 * bindings/scripts/CodeGeneratorJS.pm: 84 (AddToIncludesForIDLType): 85 1 86 2020-12-01 Sergio Villar Senin <svillar@igalia.com> 2 87 -
trunk/Source/WebCore/Modules/mediastream/RTCEncodedAudioFrame.cpp
r270107 r270290 31 31 namespace WebCore { 32 32 33 RTCEncodedAudioFrame::RTCEncodedAudioFrame( UniqueRef<RTCRtpTransformableFrame>&& frame)33 RTCEncodedAudioFrame::RTCEncodedAudioFrame(Ref<RTCRtpTransformableFrame>&& frame) 34 34 : RTCEncodedFrame(WTFMove(frame)) 35 35 { -
trunk/Source/WebCore/Modules/mediastream/RTCEncodedAudioFrame.h
r270107 r270290 34 34 class RTCEncodedAudioFrame : public RTCEncodedFrame { 35 35 public: 36 static Ref<RTCEncodedAudioFrame> create( UniqueRef<RTCRtpTransformableFrame>&& frame) { return adoptRef(*new RTCEncodedAudioFrame(WTFMove(frame))); }36 static Ref<RTCEncodedAudioFrame> create(Ref<RTCRtpTransformableFrame>&& frame) { return adoptRef(*new RTCEncodedAudioFrame(WTFMove(frame))); } 37 37 ~RTCEncodedAudioFrame(); 38 38 39 39 private: 40 explicit RTCEncodedAudioFrame( UniqueRef<RTCRtpTransformableFrame>&&);40 explicit RTCEncodedAudioFrame(Ref<RTCRtpTransformableFrame>&&); 41 41 }; 42 42 -
trunk/Source/WebCore/Modules/mediastream/RTCEncodedFrame.cpp
r270107 r270290 34 34 namespace WebCore { 35 35 36 RTCEncodedFrame::RTCEncodedFrame( UniqueRef<RTCRtpTransformableFrame>&& frame)36 RTCEncodedFrame::RTCEncodedFrame(Ref<RTCRtpTransformableFrame>&& frame) 37 37 : m_frame(WTFMove(frame)) 38 38 { -
trunk/Source/WebCore/Modules/mediastream/RTCEncodedFrame.h
r270107 r270290 44 44 void setData(JSC::ArrayBuffer&); 45 45 46 UniqueRef<RTCRtpTransformableFrame> takeRTCFrame() { return WTFMove(m_frame); }46 RTCRtpTransformableFrame& rtcFrame() { return m_frame.get(); } 47 47 48 48 protected: 49 explicit RTCEncodedFrame( UniqueRef<RTCRtpTransformableFrame>&&);49 explicit RTCEncodedFrame(Ref<RTCRtpTransformableFrame>&&); 50 50 51 UniqueRef<RTCRtpTransformableFrame> m_frame;51 Ref<RTCRtpTransformableFrame> m_frame; 52 52 }; 53 53 -
trunk/Source/WebCore/Modules/mediastream/RTCEncodedVideoFrame.cpp
r270107 r270290 31 31 namespace WebCore { 32 32 33 RTCEncodedVideoFrame::RTCEncodedVideoFrame( UniqueRef<RTCRtpTransformableFrame>&& frame)33 RTCEncodedVideoFrame::RTCEncodedVideoFrame(Ref<RTCRtpTransformableFrame>&& frame) 34 34 : RTCEncodedFrame(WTFMove(frame)) 35 35 { -
trunk/Source/WebCore/Modules/mediastream/RTCEncodedVideoFrame.h
r270107 r270290 34 34 class RTCEncodedVideoFrame : public RTCEncodedFrame { 35 35 public: 36 static Ref<RTCEncodedVideoFrame> create( UniqueRef<RTCRtpTransformableFrame>&& frame) { return adoptRef(*new RTCEncodedVideoFrame(WTFMove(frame))); }36 static Ref<RTCEncodedVideoFrame> create(Ref<RTCRtpTransformableFrame>&& frame) { return adoptRef(*new RTCEncodedVideoFrame(WTFMove(frame))); } 37 37 ~RTCEncodedVideoFrame(); 38 38 39 39 private: 40 explicit RTCEncodedVideoFrame( UniqueRef<RTCRtpTransformableFrame>&&);40 explicit RTCEncodedVideoFrame(Ref<RTCRtpTransformableFrame>&&); 41 41 }; 42 42 -
trunk/Source/WebCore/Modules/mediastream/RTCRtpSFrameTransform.cpp
r270107 r270290 30 30 31 31 #include "CryptoKeyRaw.h" 32 #include "JSDOMConvertBufferSource.h" 32 33 #include "Logging.h" 34 #include "RTCEncodedAudioFrame.h" 35 #include "RTCEncodedVideoFrame.h" 33 36 #include "RTCRtpSFrameTransformer.h" 34 37 #include "RTCRtpTransformBackend.h" 35 38 #include "RTCRtpTransformableFrame.h" 39 #include "ReadableStream.h" 40 #include "ReadableStreamSource.h" 41 #include "SharedBuffer.h" 42 #include "WritableStream.h" 43 #include "WritableStreamSink.h" 36 44 37 45 namespace WebCore { 38 46 39 RTCRtpSFrameTransform::RTCRtpSFrameTransform() 40 : m_transformer(RTCRtpSFrameTransformer::create()) 41 { 47 RTCRtpSFrameTransform::RTCRtpSFrameTransform(ScriptExecutionContext& context, Options options) 48 : ContextDestructionObserver(&context) 49 , m_transformer(RTCRtpSFrameTransformer::create()) 50 { 51 m_transformer->setIsEncrypting(options.role == Role::Encrypt); 52 m_transformer->setAuthenticationSize(options.authenticationSize); 42 53 } 43 54 … … 68 79 } 69 80 81 bool RTCRtpSFrameTransform::isAttached() const 82 { 83 return m_isAttached || (m_readable && m_readable->isLocked()) || (m_writable && m_writable->isLocked()); 84 } 85 70 86 void RTCRtpSFrameTransform::initializeTransformer(RTCRtpTransformBackend& backend, Side side) 71 87 { 88 ASSERT(!isAttached()); 89 72 90 m_isAttached = true; 73 m_transformer->setIsSending(side == Side::Sender); 74 m_transformer->setIsProcessingAudio(backend.mediaType() == RTCRtpTransformBackend::MediaType::Audio); 91 if (m_readable) 92 m_readable->lock(); 93 if (m_writable) 94 m_writable->lock(); 95 96 m_transformer->setIsEncrypting(side == Side::Sender); 97 m_transformer->setAuthenticationSize(backend.mediaType() == RTCRtpTransformBackend::MediaType::Audio ? 4 : 10); 75 98 76 99 backend.setTransformableFrameCallback([transformer = m_transformer, backend = makeRef(backend)](auto&& frame) { … … 85 108 frame->setData({ result.returnValue().data(), result.returnValue().size() }); 86 109 87 backend->processTransformedFrame( WTFMove(frame.get()));110 backend->processTransformedFrame(frame.get()); 88 111 }); 89 112 } 90 113 91 92 114 void RTCRtpSFrameTransform::initializeBackendForReceiver(RTCRtpTransformBackend& backend) 93 115 { … … 103 125 { 104 126 backend.clearTransformableFrameCallback(); 105 m_isAttached = false; 127 } 128 129 template<typename Frame> 130 void transformFrame(Frame& frame, JSDOMGlobalObject& globalObject, RTCRtpSFrameTransformer& transformer, SimpleReadableStreamSource& source) 131 { 132 auto chunk = frame.rtcFrame().data(); 133 auto result = transformer.transform(chunk.data, chunk.size); 134 RELEASE_LOG_ERROR_IF(result.hasException(), WebRTC, "RTCRtpSFrameTransform failed transforming a frame"); 135 136 RTCRtpTransformableFrame::Data transformedChunk; 137 // In case of error, we just pass along the frame with empty data. 138 if (!result.hasException()) 139 transformedChunk = { result.returnValue().data(), result.returnValue().size() }; 140 141 frame.rtcFrame().setData(transformedChunk); 142 source.enqueue(toJS(&globalObject, &globalObject, frame)); 143 } 144 145 template<> 146 void transformFrame(JSC::ArrayBuffer& value, JSDOMGlobalObject& globalObject, RTCRtpSFrameTransformer& transformer, SimpleReadableStreamSource& source) 147 { 148 auto result = transformer.transform(static_cast<const uint8_t*>(value.data()), value.byteLength()); 149 RELEASE_LOG_ERROR_IF(result.hasException(), WebRTC, "RTCRtpSFrameTransform failed transforming a frame"); 150 151 auto buffer = result.hasException() ? SharedBuffer::create() : SharedBuffer::create(result.returnValue().data(), result.returnValue().size()); 152 source.enqueue(toJS(&globalObject, &globalObject, buffer->tryCreateArrayBuffer().get())); 153 } 154 155 void RTCRtpSFrameTransform::createStreams() 156 { 157 auto& globalObject = *scriptExecutionContext()->globalObject(); 158 159 m_readableStreamSource = SimpleReadableStreamSource::create(); 160 auto readable = ReadableStream::create(globalObject, m_readableStreamSource.copyRef()); 161 if (readable.hasException()) 162 return; 163 164 auto writable = WritableStream::create(globalObject, SimpleWritableStreamSink::create([transformer = m_transformer, readableStreamSource = m_readableStreamSource](auto& context, auto value) -> ExceptionOr<void> { 165 auto& globalObject = *JSC::jsCast<JSDOMGlobalObject*>(context.globalObject()); 166 auto scope = DECLARE_THROW_SCOPE(globalObject.vm()); 167 168 auto frame = convert<IDLUnion<IDLArrayBuffer, IDLInterface<RTCEncodedAudioFrame>, IDLInterface<RTCEncodedVideoFrame>>>(globalObject, value); 169 if (scope.exception()) 170 return Exception { ExistingExceptionError }; 171 172 // We do not want to throw any exception in the transform to make sure we do not error the transform. 173 WTF::switchOn(frame, [&](RefPtr<RTCEncodedAudioFrame>& value) { 174 transformFrame(*value, globalObject, transformer.get(), *readableStreamSource); 175 }, [&](RefPtr<RTCEncodedVideoFrame>& value) { 176 transformFrame(*value, globalObject, transformer.get(), *readableStreamSource); 177 }, [&](RefPtr<ArrayBuffer>& value) { 178 transformFrame(*value, globalObject, transformer.get(), *readableStreamSource); 179 }); 180 return { }; 181 })); 182 if (writable.hasException()) 183 return; 184 185 m_readable = readable.releaseReturnValue(); 186 m_writable = writable.releaseReturnValue(); 187 if (m_isAttached) { 188 m_readable->lock(); 189 m_writable->lock(); 190 } 191 } 192 193 ExceptionOr<RefPtr<ReadableStream>> RTCRtpSFrameTransform::readable() 194 { 195 auto* context = scriptExecutionContext(); 196 if (!context) 197 return Exception { InvalidStateError }; 198 199 if (!m_readable) 200 createStreams(); 201 202 return m_readable.copyRef(); 203 } 204 205 ExceptionOr<RefPtr<WritableStream>> RTCRtpSFrameTransform::writable() 206 { 207 auto* context = scriptExecutionContext(); 208 if (!context) 209 return Exception { InvalidStateError }; 210 211 if (!m_writable) 212 createStreams(); 213 214 return m_writable.copyRef(); 106 215 } 107 216 -
trunk/Source/WebCore/Modules/mediastream/RTCRtpSFrameTransform.h
r270107 r270290 28 28 #if ENABLE(WEB_RTC) 29 29 30 #include "ContextDestructionObserver.h" 30 31 #include "JSDOMPromiseDeferred.h" 31 32 … … 35 36 class RTCRtpSFrameTransformer; 36 37 class RTCRtpTransformBackend; 38 class ReadableStream; 39 class SimpleReadableStreamSource; 40 class WritableStream; 37 41 38 class RTCRtpSFrameTransform : public RefCounted<RTCRtpSFrameTransform> {42 class RTCRtpSFrameTransform : public RefCounted<RTCRtpSFrameTransform>, private ContextDestructionObserver { 39 43 public: 40 static Ref<RTCRtpSFrameTransform> create() { return adoptRef(*new RTCRtpSFrameTransform); } 44 enum class Role { Encrypt, Decrypt }; 45 struct Options { 46 Role role { Role::Encrypt }; 47 uint64_t authenticationSize { 10 }; 48 }; 49 50 static Ref<RTCRtpSFrameTransform> create(ScriptExecutionContext& context, Options options) { return adoptRef(*new RTCRtpSFrameTransform(context, options)); } 41 51 ~RTCRtpSFrameTransform(); 42 52 43 53 void setEncryptionKey(CryptoKey&, Optional<uint64_t>, DOMPromiseDeferred<void>&&); 44 54 45 bool isAttached() const { return m_isAttached; }55 bool isAttached() const; 46 56 void initializeBackendForReceiver(RTCRtpTransformBackend&); 47 57 void initializeBackendForSender(RTCRtpTransformBackend&); … … 50 60 WEBCORE_EXPORT uint64_t counterForTesting() const; 51 61 62 ExceptionOr<RefPtr<ReadableStream>> readable(); 63 ExceptionOr<RefPtr<WritableStream>> writable(); 64 52 65 private: 53 RTCRtpSFrameTransform( );66 RTCRtpSFrameTransform(ScriptExecutionContext&, Options); 54 67 55 68 enum class Side { Sender, Receiver }; 56 69 void initializeTransformer(RTCRtpTransformBackend&, Side); 70 void createStreams(); 57 71 58 72 bool m_isAttached { false }; 59 73 Ref<RTCRtpSFrameTransformer> m_transformer; 74 RefPtr<ReadableStream> m_readable; 75 RefPtr<WritableStream> m_writable; 76 RefPtr<SimpleReadableStreamSource> m_readableStreamSource; 60 77 }; 61 78 -
trunk/Source/WebCore/Modules/mediastream/RTCRtpSFrameTransform.idl
r270107 r270290 24 24 */ 25 25 26 enum RTCRtpSFrameTransformRole { 27 "encrypt", 28 "decrypt" 29 }; 30 31 dictionary RTCRtpSFrameTransformOptions { 32 RTCRtpSFrameTransformRole role = "encrypt"; 33 unsigned long authenticationSize = 10; 34 }; 35 26 36 [ 27 37 Conditional=WEB_RTC, … … 29 39 ExportMacro=WEBCORE_EXPORT, 30 40 Exposed=Window, 31 ImplementationLacksVTable,32 41 JSGenerateToNativeObject, 33 42 ] interface RTCRtpSFrameTransform { 34 constructor();43 [CallWith=ScriptExecutionContext] constructor(optional RTCRtpSFrameTransformOptions options); 35 44 36 45 Promise<undefined> setEncryptionKey(CryptoKey key, optional unsigned long long keyID); … … 38 47 // Promise<undefined> ratchetEncryptionKey(); 39 48 // Promise<undefined> setSigningKey(CryptoKey key); 49 50 [MayThrowException] readonly attribute ReadableStream readable; 51 [MayThrowException] readonly attribute WritableStream writable; 40 52 }; -
trunk/Source/WebCore/Modules/mediastream/RTCRtpSFrameTransformer.cpp
r269830 r270290 168 168 m_keyId = *keyId; 169 169 170 updateAuthenticationSize(); 170 171 m_hasKey = true; 172 171 173 return { }; 172 174 } … … 174 176 ExceptionOr<Vector<uint8_t>> RTCRtpSFrameTransformer::decryptFrame(const uint8_t* frameData, size_t frameSize) 175 177 { 176 // FIXME: Support signature.177 178 178 auto locker = holdLock(m_keyLock); 179 179 … … 191 191 return Exception { NotSupportedError }; 192 192 } 193 194 if (frameSize < (header->size + m_authenticationSize)) 195 return Exception { DataError, "Chunk is too small for authentication size" }; 193 196 194 197 // Compute signature … … 215 218 ExceptionOr<Vector<uint8_t>> RTCRtpSFrameTransformer::encryptFrame(const uint8_t* frameData, size_t frameSize) 216 219 { 217 // FIXME: Support signature.218 219 220 static const unsigned MaxHeaderSize = 17; 220 221 … … 260 261 { 261 262 if (!m_hasKey) 262 return Exception { InvalidStateError };263 264 return m_is Sending ? encryptFrame(data, size) : decryptFrame(data, size);263 return Exception { InvalidStateError, "Key is not initialized"_s }; 264 265 return m_isEncrypting ? encryptFrame(data, size) : decryptFrame(data, size); 265 266 } 266 267 … … 295 296 return { }; 296 297 } 298 299 void RTCRtpSFrameTransformer::updateAuthenticationSize() 300 { 301 } 297 302 #endif // !PLATFORM(COCOA) 298 303 -
trunk/Source/WebCore/Modules/mediastream/RTCRtpSFrameTransformer.h
r269830 r270290 41 41 WEBCORE_EXPORT ~RTCRtpSFrameTransformer(); 42 42 43 void setIs Sending(bool);44 void set IsProcessingAudio(bool);43 void setIsEncrypting(bool); 44 void setAuthenticationSize(uint64_t); 45 45 46 46 WEBCORE_EXPORT ExceptionOr<void> setEncryptionKey(const Vector<uint8_t>& rawKey, Optional<uint64_t>); … … 67 67 ExceptionOr<Vector<uint8_t>> decryptData(const uint8_t*, size_t, const Vector<uint8_t>& iv, const Vector<uint8_t>& key); 68 68 Vector<uint8_t> computeEncryptedDataSignature(const uint8_t*, size_t, const Vector<uint8_t>& key); 69 void updateAuthenticationSize(); 69 70 70 71 Lock m_keyLock; … … 74 75 Vector<uint8_t> m_saltKey; 75 76 76 bool m_is Sending { false };77 bool m_isEncrypting { false }; 77 78 uint64_t m_authenticationSize { 10 }; 78 79 uint64_t m_keyId { 0 }; … … 80 81 }; 81 82 82 inline void RTCRtpSFrameTransformer::setIs Sending(bool isSending)83 inline void RTCRtpSFrameTransformer::setIsEncrypting(bool isEncrypting) 83 84 { 84 m_is Sending = isSending;85 m_isEncrypting = isEncrypting; 85 86 } 86 87 87 inline void RTCRtpSFrameTransformer::set IsProcessingAudio(bool isProcessingAudio)88 inline void RTCRtpSFrameTransformer::setAuthenticationSize(uint64_t size) 88 89 { 89 m_authenticationSize = isProcessingAudio ? 4 : 10;90 m_authenticationSize = size; 90 91 } 91 92 -
trunk/Source/WebCore/Modules/mediastream/RTCRtpSFrameTransformerCocoa.cpp
r269830 r270290 69 69 } 70 70 71 void RTCRtpSFrameTransformer::updateAuthenticationSize() 72 { 73 if (m_authenticationSize > CC_SHA256_DIGEST_LENGTH) 74 m_authenticationSize = CC_SHA256_DIGEST_LENGTH; 75 } 76 71 77 } // namespace WebCore 72 78 -
trunk/Source/WebCore/Modules/mediastream/RTCRtpScriptTransformer.cpp
r270107 r270290 41 41 namespace WebCore { 42 42 43 class RTCRtpReadableStreamSource44 : public ReadableStreamSource45 , public CanMakeWeakPtr<RTCRtpReadableStreamSource> {46 public:47 static Ref<RTCRtpReadableStreamSource> create() { return adoptRef(*new RTCRtpReadableStreamSource); }48 49 void close() { controller().close(); }50 void enqueue(JSC::JSValue value) { controller().enqueue(value); }51 52 private:53 RTCRtpReadableStreamSource() = default;54 55 // ReadableStreamSource56 void setActive() final { }57 void setInactive() final { }58 void doStart() final { }59 void doPull() final { }60 void doCancel() final { }61 };62 63 class RTCRtpWritableStreamSink : public WritableStreamSink {64 public:65 static Ref<RTCRtpWritableStreamSink> create(Function<void(UniqueRef<RTCRtpTransformableFrame>&&)>&& enqueueFunction) { return adoptRef(*new RTCRtpWritableStreamSink(WTFMove(enqueueFunction))); }66 67 private:68 explicit RTCRtpWritableStreamSink(Function<void(UniqueRef<RTCRtpTransformableFrame>&&)>&& enqueueFunction)69 : m_enqueueFunction(WTFMove(enqueueFunction))70 {71 }72 73 void write(ScriptExecutionContext& context, JSC::JSValue value, DOMPromiseDeferred<void>&& promise)74 {75 auto& globalObject = *context.globalObject();76 77 auto scope = DECLARE_THROW_SCOPE(globalObject.vm());78 auto frame = convert<IDLUnion<IDLInterface<RTCEncodedAudioFrame>, IDLInterface<RTCEncodedVideoFrame>>>(globalObject, value);79 80 if (scope.exception()) {81 promise.reject(Exception { ExistingExceptionError }, RejectAsHandled::Yes);82 return;83 }84 85 WTF::switchOn(frame, [&](RefPtr<RTCEncodedAudioFrame>& value) {86 m_enqueueFunction(value->takeRTCFrame());87 }, [&](RefPtr<RTCEncodedVideoFrame>& value) {88 m_enqueueFunction(value->takeRTCFrame());89 });90 promise.resolve();91 }92 93 // FIXME: Decide whether clearing all pending frames.94 void close() final { }95 void error(String&&) final { }96 97 Function<void(UniqueRef<RTCRtpTransformableFrame>&&)> m_enqueueFunction;98 };99 100 43 ExceptionOr<Ref<RTCRtpScriptTransformer>> RTCRtpScriptTransformer::create(ScriptExecutionContext& context) 101 44 { … … 119 62 } 120 63 121 RefPtr< RTCRtpReadableStreamSource> RTCRtpScriptTransformer::startStreams(RTCRtpTransformBackend& backend)64 RefPtr<SimpleReadableStreamSource> RTCRtpScriptTransformer::startStreams(RTCRtpTransformBackend& backend) 122 65 { 123 66 auto callback = WTFMove(m_callback); … … 131 74 JSC::JSLockHolder lock(vm); 132 75 133 auto readableStreamSource = RTCRtpReadableStreamSource::create();76 auto readableStreamSource = SimpleReadableStreamSource::create(); 134 77 auto readableStream = ReadableStream::create(globalObject, readableStreamSource.copyRef()); 135 78 if (readableStream.hasException()) 136 79 return nullptr; 137 80 138 auto writableStream = WritableStream::create(globalObject, RTCRtpWritableStreamSink::create([backend = makeRef(backend)](auto&& frame) { 139 backend->processTransformedFrame(WTFMove(frame.get())); 81 auto writableStream = WritableStream::create(globalObject, SimpleWritableStreamSink::create([backend = makeRef(backend)](auto& context, auto value) -> ExceptionOr<void> { 82 auto& globalObject = *context.globalObject(); 83 84 auto scope = DECLARE_THROW_SCOPE(globalObject.vm()); 85 auto frame = convert<IDLUnion<IDLInterface<RTCEncodedAudioFrame>, IDLInterface<RTCEncodedVideoFrame>>>(globalObject, value); 86 87 if (scope.exception()) 88 return Exception { ExistingExceptionError }; 89 90 auto rtcFrame = WTF::switchOn(frame, [&](RefPtr<RTCEncodedAudioFrame>& value) { 91 return makeRef(value->rtcFrame()); 92 }, [&](RefPtr<RTCEncodedVideoFrame>& value) { 93 return makeRef(value->rtcFrame()); 94 }); 95 backend->processTransformedFrame(rtcFrame.get()); 96 return { }; 140 97 })); 141 98 if (writableStream.hasException()) -
trunk/Source/WebCore/Modules/mediastream/RTCRtpScriptTransformer.h
r270107 r270290 39 39 class ScriptExecutionContext; 40 40 class RTCRtpTransformBackend; 41 class RTCRtpReadableStreamSource;41 class SimpleReadableStreamSource; 42 42 43 43 class RTCRtpScriptTransformer … … 60 60 RTCRtpScriptTransformer(ScriptExecutionContext&, Ref<MessagePort>&&); 61 61 62 RefPtr< RTCRtpReadableStreamSource> startStreams(RTCRtpTransformBackend&);62 RefPtr<SimpleReadableStreamSource> startStreams(RTCRtpTransformBackend&); 63 63 64 64 // ActiveDOMObject -
trunk/Source/WebCore/Modules/mediastream/RTCRtpTransformBackend.h
r270107 r270290 37 37 virtual ~RTCRtpTransformBackend() = default; 38 38 39 using Callback = Function<void( UniqueRef<RTCRtpTransformableFrame>&&)>;39 using Callback = Function<void(Ref<RTCRtpTransformableFrame>&&)>; 40 40 virtual void setTransformableFrameCallback(Callback&&) = 0; 41 41 virtual void clearTransformableFrameCallback() = 0; 42 virtual void processTransformedFrame(RTCRtpTransformableFrame& &) = 0;42 virtual void processTransformedFrame(RTCRtpTransformableFrame&) = 0; 43 43 44 44 enum class MediaType { Audio, Video }; 45 45 virtual MediaType mediaType() const = 0; 46 46 47 enum class Side { Sender, Receiver };47 enum class Side { Receiver, Sender }; 48 48 virtual Side side() const = 0; 49 49 }; -
trunk/Source/WebCore/Modules/mediastream/RTCRtpTransformableFrame.h
r270107 r270290 27 27 #if ENABLE(WEB_RTC) 28 28 29 #include <wtf/RefCounted.h> 30 29 31 namespace WebCore { 30 32 31 class RTCRtpTransformableFrame { 32 WTF_MAKE_FAST_ALLOCATED; 33 class RTCRtpTransformableFrame : public RefCounted<RTCRtpTransformableFrame> { 33 34 public: 34 35 virtual ~RTCRtpTransformableFrame() = default; 35 36 36 37 struct Data { 37 const uint8_t* data ;38 size_t size ;38 const uint8_t* data { nullptr }; 39 size_t size { 0 }; 39 40 }; 40 41 virtual Data data() const = 0; -
trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCRtpSenderTransformBackend.cpp
r269764 r270290 53 53 } 54 54 55 56 55 } // namespace WebCore 57 56 -
trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCRtpTransformBackend.cpp
r270107 r270290 29 29 30 30 #include "LibWebRTCRtpTransformableFrame.h" 31 #include <wtf/UniqueRef.h>32 31 33 32 namespace WebCore { … … 50 49 } 51 50 52 void LibWebRTCRtpTransformBackend::processTransformedFrame(RTCRtpTransformableFrame& &frame)51 void LibWebRTCRtpTransformBackend::processTransformedFrame(RTCRtpTransformableFrame& frame) 53 52 { 54 53 auto locker = holdLock(m_outputCallbackLock); 55 54 if (m_outputCallback) 56 m_outputCallback->OnTransformedFrame( LibWebRTCRtpTransformableFrame::toRTCFrame(WTFMove(static_cast<LibWebRTCRtpTransformableFrame&>(frame))));55 m_outputCallback->OnTransformedFrame(static_cast<LibWebRTCRtpTransformableFrame&>(frame).takeRTCFrame()); 57 56 } 58 57 … … 62 61 auto locker = holdLock(m_inputCallbackLock); 63 62 if (m_inputCallback) { 64 m_inputCallback( makeUniqueRef<LibWebRTCRtpTransformableFrame>(WTFMove(rtcFrame)));63 m_inputCallback(LibWebRTCRtpTransformableFrame::create(WTFMove(rtcFrame))); 65 64 return; 66 65 } -
trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCRtpTransformBackend.h
r269764 r270290 47 47 void setInputCallback(Callback&&); 48 48 49 protected: 50 MediaType mediaType() const final { return m_mediaType; } 51 49 52 private: 50 53 void setOutputCallback(rtc::scoped_refptr<webrtc::TransformedFrameCallback>&&); 51 54 52 55 // RTCRtpTransformBackend 53 void processTransformedFrame(RTCRtpTransformableFrame& &) final;56 void processTransformedFrame(RTCRtpTransformableFrame&) final; 54 57 void clearTransformableFrameCallback() final; 55 MediaType mediaType() const final { return m_mediaType; }56 58 Side side() const final { return m_side; } 57 59 -
trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCRtpTransformableFrame.cpp
r270289 r270290 24 24 25 25 #include "config.h" 26 #include "LibWebRTCRtp SenderTransformBackend.h"26 #include "LibWebRTCRtpTransformableFrame.h" 27 27 28 28 #if ENABLE(WEB_RTC) && USE(LIBWEBRTC) 29 29 30 #include "LibWebRTCRtpTransformableFrame.h" 30 ALLOW_UNUSED_PARAMETERS_BEGIN 31 ALLOW_DEPRECATED_DECLARATIONS_BEGIN 32 33 #include <webrtc/api/frame_transformer_interface.h> 34 35 ALLOW_DEPRECATED_DECLARATIONS_END 36 ALLOW_UNUSED_PARAMETERS_END 31 37 32 38 namespace WebCore { 33 39 34 static inline LibWebRTCRtpSenderTransformBackend::MediaType mediaTypeFromSender(const webrtc::RtpSenderInterface& sender) 35 { 36 return sender.media_type() == cricket::MEDIA_TYPE_AUDIO ? RTCRtpTransformBackend::MediaType::Audio : RTCRtpTransformBackend::MediaType::Video; 37 } 38 39 LibWebRTCRtpSenderTransformBackend::LibWebRTCRtpSenderTransformBackend(rtc::scoped_refptr<webrtc::RtpSenderInterface> rtcSender) 40 : LibWebRTCRtpTransformBackend(mediaTypeFromSender(*rtcSender), Side::Sender) 41 , m_rtcSender(WTFMove(rtcSender)) 40 LibWebRTCRtpTransformableFrame::LibWebRTCRtpTransformableFrame(std::unique_ptr<webrtc::TransformableFrameInterface>&& frame) 41 : m_rtcFrame(WTFMove(frame)) 42 42 { 43 43 } 44 44 45 LibWebRTCRtp SenderTransformBackend::~LibWebRTCRtpSenderTransformBackend()45 LibWebRTCRtpTransformableFrame::~LibWebRTCRtpTransformableFrame() 46 46 { 47 47 } 48 48 49 void LibWebRTCRtpSenderTransformBackend::setTransformableFrameCallback(Callback&& callback)49 std::unique_ptr<webrtc::TransformableFrameInterface> LibWebRTCRtpTransformableFrame::takeRTCFrame() 50 50 { 51 setInputCallback(WTFMove(callback)); 52 m_rtcSender->SetEncoderToPacketizerFrameTransformer(this); 51 return WTFMove(m_rtcFrame); 53 52 } 54 53 54 RTCRtpTransformableFrame::Data LibWebRTCRtpTransformableFrame::data() const 55 { 56 if (!m_rtcFrame) 57 return { nullptr, 0 }; 58 auto data = m_rtcFrame->GetData(); 59 return { data.begin(), data.size() }; 60 } 61 62 void LibWebRTCRtpTransformableFrame::setData(Data data) 63 { 64 if (m_rtcFrame) 65 m_rtcFrame->SetData({ data.data, data.size }); 66 } 55 67 56 68 } // namespace WebCore -
trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCRtpTransformableFrame.h
r269764 r270290 28 28 29 29 #include "RTCRtpTransformableFrame.h" 30 #include <wtf/Ref.h> 31 32 namespace webrtc { 33 class TransformableFrameInterface; 34 } 30 35 31 36 namespace WebCore { … … 34 39 WTF_MAKE_FAST_ALLOCATED; 35 40 public: 36 explicit LibWebRTCRtpTransformableFrame(std::unique_ptr<webrtc::TransformableFrameInterface>&&);37 virtual ~LibWebRTCRtpTransformableFrame() = default;41 static Ref<LibWebRTCRtpTransformableFrame> create(std::unique_ptr<webrtc::TransformableFrameInterface>&& frame) { return adoptRef(*new LibWebRTCRtpTransformableFrame(WTFMove(frame))); } 42 ~LibWebRTCRtpTransformableFrame(); 38 43 39 st atic std::unique_ptr<webrtc::TransformableFrameInterface> toRTCFrame(LibWebRTCRtpTransformableFrame&&);44 std::unique_ptr<webrtc::TransformableFrameInterface> takeRTCFrame(); 40 45 41 46 private: 47 explicit LibWebRTCRtpTransformableFrame(std::unique_ptr<webrtc::TransformableFrameInterface>&&); 48 42 49 Data data() const final; 43 void setData(Data data) final { m_rtcFrame->SetData({ data.data, data.size }); }50 void setData(Data) final; 44 51 45 52 std::unique_ptr<webrtc::TransformableFrameInterface> m_rtcFrame; 46 53 }; 47 54 48 inline LibWebRTCRtpTransformableFrame::LibWebRTCRtpTransformableFrame(std::unique_ptr<webrtc::TransformableFrameInterface>&& frame)49 : m_rtcFrame(WTFMove(frame))50 {51 }52 53 inline std::unique_ptr<webrtc::TransformableFrameInterface> LibWebRTCRtpTransformableFrame::toRTCFrame(LibWebRTCRtpTransformableFrame&& frame)54 {55 return WTFMove(frame.m_rtcFrame);56 }57 58 inline RTCRtpTransformableFrame::Data LibWebRTCRtpTransformableFrame::data() const59 {60 auto data = m_rtcFrame->GetData();61 return { data.begin(), data.size() };62 }63 64 55 } // namespace WebCore 65 56 -
trunk/Source/WebCore/Modules/streams/ReadableStreamSource.cpp
r263700 r270290 27 27 #include "config.h" 28 28 #include "ReadableStreamSource.h" 29 30 #include "JSDOMPromiseDeferred.h"31 29 32 30 namespace WebCore { -
trunk/Source/WebCore/Modules/streams/ReadableStreamSource.h
r263700 r270290 29 29 #pragma once 30 30 31 #include "JSDOMPromiseDeferred.h" 31 32 #include "ReadableStreamDefaultController.h" 32 33 #include <wtf/Optional.h> 34 #include <wtf/WeakPtr.h> 33 35 34 36 namespace WebCore { 35 36 template<typename IDLType> class DOMPromiseDeferred;37 37 38 38 class ReadableStreamSource : public RefCounted<ReadableStreamSource> { … … 67 67 }; 68 68 69 class SimpleReadableStreamSource 70 : public ReadableStreamSource 71 , public CanMakeWeakPtr<SimpleReadableStreamSource> { 72 public: 73 static Ref<SimpleReadableStreamSource> create() { return adoptRef(*new SimpleReadableStreamSource); } 74 75 void close() { controller().close(); } 76 void enqueue(JSC::JSValue value) { controller().enqueue(value); } 77 78 private: 79 SimpleReadableStreamSource() = default; 80 81 // ReadableStreamSource 82 void setActive() final { } 83 void setInactive() final { } 84 void doStart() final { } 85 void doPull() final { } 86 void doCancel() final { } 87 }; 88 69 89 } // namespace WebCore -
trunk/Source/WebCore/Modules/streams/WritableStreamSink.h
r270107 r270290 46 46 }; 47 47 48 class SimpleWritableStreamSink : public WritableStreamSink { 49 public: 50 using WriteCallback = Function<ExceptionOr<void>(ScriptExecutionContext&, JSC::JSValue)>; 51 static Ref<SimpleWritableStreamSink> create(WriteCallback&& writeCallback) { return adoptRef(*new SimpleWritableStreamSink(WTFMove(writeCallback))); } 52 53 private: 54 explicit SimpleWritableStreamSink(WriteCallback&&); 55 56 void write(ScriptExecutionContext&, JSC::JSValue, DOMPromiseDeferred<void>&&) final; 57 void close() final { } 58 void error(String&&) final { } 59 60 WriteCallback m_writeCallback; 61 }; 62 63 inline SimpleWritableStreamSink::SimpleWritableStreamSink(WriteCallback&& writeCallback) 64 : m_writeCallback(WTFMove(writeCallback)) 65 { 66 } 67 68 inline void SimpleWritableStreamSink::write(ScriptExecutionContext& context, JSC::JSValue value, DOMPromiseDeferred<void>&& promise) 69 { 70 promise.settle(m_writeCallback(context, value)); 71 } 72 48 73 } // namespace WebCore -
trunk/Source/WebCore/Sources.txt
r270257 r270290 183 183 Modules/mediastream/libwebrtc/LibWebRTCRtpSenderTransformBackend.cpp 184 184 Modules/mediastream/libwebrtc/LibWebRTCRtpTransformBackend.cpp 185 Modules/mediastream/libwebrtc/LibWebRTCRtpTransformableFrame.cpp 185 186 Modules/model-element/HTMLModelElement.cpp 186 187 Modules/notifications/Notification.cpp -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r270257 r270290 7538 7538 410A8EF924F8F47B004F9070 /* TextEncoderStreamEncoder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TextEncoderStreamEncoder.h; sourceTree = "<group>"; }; 7539 7539 410B7E711045FAB000D8224F /* JSMessageEventCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSMessageEventCustom.cpp; sourceTree = "<group>"; }; 7540 410BA1312570FE57002E2F8A /* LibWebRTCRtpTransformableFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LibWebRTCRtpTransformableFrame.cpp; path = libwebrtc/LibWebRTCRtpTransformableFrame.cpp; sourceTree = "<group>"; }; 7540 7541 410E445F234373AD000173D4 /* LibWebRTCSocketIdentifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LibWebRTCSocketIdentifier.h; path = libwebrtc/LibWebRTCSocketIdentifier.h; sourceTree = "<group>"; }; 7541 7542 410F565524FCF70500A2E50C /* RTCSessionDescriptionInit.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = RTCSessionDescriptionInit.idl; sourceTree = "<group>"; }; … … 19286 19287 4186BD4D2140B9E80001826F /* LibWebRTCRtpTransceiverBackend.cpp */, 19287 19288 4186BD4B2140A8050001826F /* LibWebRTCRtpTransceiverBackend.h */, 19289 410BA1312570FE57002E2F8A /* LibWebRTCRtpTransformableFrame.cpp */, 19288 19290 4181C5CC2555836800AEB0FF /* LibWebRTCRtpTransformableFrame.h */, 19289 19291 4181C5CE2555895500AEB0FF /* LibWebRTCRtpTransformBackend.cpp */, -
trunk/Source/WebCore/bindings/js/WritableStream.cpp
r270107 r270290 37 37 using namespace JSC; 38 38 39 namespace WritableStreamInternal { 40 static inline JSC::JSValue callFunction(JSC::JSGlobalObject& lexicalGlobalObject, JSC::JSValue jsFunction, JSC::JSValue thisValue, const JSC::ArgList& arguments) 41 { 42 VM& vm = lexicalGlobalObject.vm(); 43 auto scope = DECLARE_CATCH_SCOPE(vm); 44 auto callData = JSC::getCallData(vm, jsFunction); 45 ASSERT(callData.type != JSC::CallData::Type::None); 46 auto result = call(&lexicalGlobalObject, jsFunction, callData, thisValue, arguments); 47 scope.assertNoException(); 48 return result; 49 } 50 } 51 52 static inline bool checkWritableStream(JSDOMGlobalObject& globalObject, JSWritableStream* writableStream, JSC::JSValue function) 53 { 54 auto& lexicalGlobalObject = globalObject; 55 56 ASSERT(function); 57 JSC::MarkedArgumentBuffer arguments; 58 arguments.append(writableStream); 59 ASSERT(!arguments.hasOverflowed()); 60 return WritableStreamInternal::callFunction(lexicalGlobalObject, function, JSC::jsUndefined(), arguments).isTrue(); 61 } 62 39 63 ExceptionOr<Ref<WritableStream>> WritableStream::create(JSC::JSGlobalObject& lexicalGlobalObject, RefPtr<WritableStreamSink>&& sink) 40 64 { … … 61 85 } 62 86 87 void WritableStream::lock() 88 { 89 auto& lexicalGlobalObject = *m_globalObject; 90 VM& vm = lexicalGlobalObject.vm(); 91 auto scope = DECLARE_CATCH_SCOPE(vm); 92 93 auto& clientData = *static_cast<JSVMClientData*>(vm.clientData); 94 95 auto* constructor = JSC::asObject(m_globalObject->get(&lexicalGlobalObject, clientData.builtinNames().WritableStreamDefaultWriterPrivateName())); 96 97 auto constructData = getConstructData(vm, constructor); 98 ASSERT(constructData.type != CallData::Type::None); 99 100 MarkedArgumentBuffer args; 101 args.append(writableStream()); 102 ASSERT(!args.hasOverflowed()); 103 104 JSC::construct(&lexicalGlobalObject, constructor, constructData, args); 105 scope.assertNoException(); 63 106 } 107 108 bool WritableStream::isLocked() const 109 { 110 return checkWritableStream(*globalObject(), writableStream(), globalObject()->builtinInternalFunctions().writableStreamInternals().m_isWritableStreamLockedFunction.get()); 111 } 112 113 } -
trunk/Source/WebCore/bindings/js/WritableStream.h
r270107 r270290 43 43 JSWritableStream* writableStream() const { return guarded(); } 44 44 45 void lock(); 46 bool isLocked() const; 47 45 48 private: 46 49 WritableStream(JSDOMGlobalObject&, JSWritableStream&); -
trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
r270115 r270290 636 636 if ($type->name eq "ReadableStream") { 637 637 AddToIncludes("ReadableStream.h", $includesRef, $conditional); 638 return; 639 } 640 641 if ($type->name eq "WritableStream") { 642 AddToIncludes("WritableStream.h", $includesRef, $conditional); 638 643 return; 639 644 } -
trunk/Tools/ChangeLog
r270282 r270290 1 2020-12-01 Youenn Fablet <youenn@apple.com> 2 3 Add support for readable/writable to RTCRtpSFrameTransform 4 https://bugs.webkit.org/show_bug.cgi?id=219298 5 6 Reviewed by Eric Carlson. 7 8 * TestWebKitAPI/Tests/WebCore/RTCRtpSFrameTransformerTests.cpp: 9 (TestWebKitAPI::createVideoTransformer): 10 1 11 2020-11-30 Wenson Hsieh <wenson_hsieh@apple.com> 2 12 -
trunk/Tools/TestWebKitAPI/Tests/WebCore/RTCRtpSFrameTransformerTests.cpp
r269830 r270290 71 71 } 72 72 73 static Ref<WebCore::RTCRtpSFrameTransformer> createVideoTransformer(bool is Sending = true)73 static Ref<WebCore::RTCRtpSFrameTransformer> createVideoTransformer(bool isEncrypting = true) 74 74 { 75 75 auto transformer = WebCore::RTCRtpSFrameTransformer::create(); 76 transformer->setIs Sending(isSending);77 transformer->set IsProcessingAudio(false);76 transformer->setIsEncrypting(isEncrypting); 77 transformer->setAuthenticationSize(10); 78 78 79 79 auto keyId = Vector<uint8_t>::from(198, 31, 251, 197, 48, 139, 91, 51);
Note: See TracChangeset
for help on using the changeset viewer.