Skip to content
Permalink
Browse files
Make sure to create VPx WebCodecs encoders and decoders asynchronously
https://bugs.webkit.org/show_bug.cgi?id=246396
rdar://problem/101070923

Reviewed by Eric Carlson.

Make sure to hop to vpx queue before notifying web codecs that they are configured.

* LayoutTests/imported/w3c/web-platform-tests/webcodecs/videoDecoder-codec-specific.https.any.worker_vp8-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/webcodecs/videoDecoder-codec-specific.https.any.worker_vp9-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/webcodecs/videoDecoder-codec-specific.https.any_vp8-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/webcodecs/videoDecoder-codec-specific.https.any_vp9-expected.txt:
* Source/WebCore/platform/LibWebRTCVPXVideoDecoder.cpp:
(WebCore::LibWebRTCVPXVideoDecoder::create):
* Source/WebCore/platform/LibWebRTCVPXVideoDecoder.h:
* Source/WebCore/platform/LibWebRTCVPXVideoEncoder.cpp:
(WebCore::LibWebRTCVPXVideoEncoder::create):
* Source/WebCore/platform/LibWebRTCVPXVideoEncoder.h:
* Source/WebCore/platform/VideoDecoder.cpp:
(WebCore::VideoDecoder::createLocalDecoder):
* Source/WebCore/platform/VideoEncoder.cpp:
(WebCore::VideoEncoder::createLocalEncoder):

Canonical link: https://commits.webkit.org/255478@main
  • Loading branch information
youennf committed Oct 13, 2022
1 parent e96f63e commit c73a0fb7ac161fed7c0ec5d18efa14fa73bec957
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 12 deletions.
@@ -6,7 +6,7 @@ PASS Test invalid configs
PASS Test configure()
PASS Decode a key frame
PASS Decode a non key frame first fails
FAIL Verify reset() suppresses outputs assert_greater_than: expected a number greater than 0 but got 0
PASS Verify reset() suppresses outputs
PASS Test unconfigured VideoDecoder operations
PASS Test closed VideoDecoder operations
FAIL Decode empty frame promise_rejects_dom: function "function () { throw e }" threw object "EncodingError: VPx decoding failed with error 1" that is not a DOMException AbortError: property "code" is equal to 0, expected 20
@@ -6,7 +6,7 @@ PASS Test invalid configs
PASS Test configure()
PASS Decode a key frame
PASS Decode a non key frame first fails
FAIL Verify reset() suppresses outputs assert_greater_than: expected a number greater than 0 but got 0
PASS Verify reset() suppresses outputs
PASS Test unconfigured VideoDecoder operations
PASS Test closed VideoDecoder operations
FAIL Decode empty frame promise_rejects_dom: function "function () { throw e }" threw object "EncodingError: VPx decoding failed with error 1" that is not a DOMException AbortError: property "code" is equal to 0, expected 20
@@ -6,7 +6,7 @@ PASS Test invalid configs
PASS Test configure()
PASS Decode a key frame
PASS Decode a non key frame first fails
FAIL Verify reset() suppresses outputs assert_greater_than: expected a number greater than 0 but got 0
PASS Verify reset() suppresses outputs
PASS Test unconfigured VideoDecoder operations
PASS Test closed VideoDecoder operations
FAIL Decode empty frame promise_rejects_dom: function "function () { throw e }" threw object "EncodingError: VPx decoding failed with error 1" that is not a DOMException AbortError: property "code" is equal to 0, expected 20
@@ -6,7 +6,7 @@ PASS Test invalid configs
PASS Test configure()
PASS Decode a key frame
PASS Decode a non key frame first fails
FAIL Verify reset() suppresses outputs assert_greater_than: expected a number greater than 0 but got 0
PASS Verify reset() suppresses outputs
PASS Test unconfigured VideoDecoder operations
PASS Test closed VideoDecoder operations
FAIL Decode empty frame promise_rejects_dom: function "function () { throw e }" threw object "EncodingError: VPx decoding failed with error 1" that is not a DOMException AbortError: property "code" is equal to 0, expected 20
@@ -73,6 +73,17 @@ class LibWebRTCVPXInternalVideoDecoder : public ThreadSafeRefCounted<LibWebRTCVP
bool m_isClosed { false };
};

void LibWebRTCVPXVideoDecoder::create(Type type, CreateCallback&& callback, OutputCallback&& outputCallback, PostTaskCallback&& postTaskCallback)
{
auto decoder = makeUniqueRef<LibWebRTCVPXVideoDecoder>(type, WTFMove(outputCallback), WTFMove(postTaskCallback));
vpxQueue().dispatch([callback = WTFMove(callback), decoder = WTFMove(decoder)]() mutable {
auto internalDecoder = decoder->m_internalDecoder;
internalDecoder->postTask([callback = WTFMove(callback), decoder = WTFMove(decoder)]() mutable {
callback(UniqueRef<VideoDecoder> { WTFMove(decoder) });
});
});
}

LibWebRTCVPXVideoDecoder::LibWebRTCVPXVideoDecoder(Type type, OutputCallback&& outputCallback, PostTaskCallback&& postTaskCallback)
: m_internalDecoder(LibWebRTCVPXInternalVideoDecoder::create(type, WTFMove(outputCallback), WTFMove(postTaskCallback)))
{
@@ -39,6 +39,8 @@ class LibWebRTCVPXVideoDecoder : public VideoDecoder {
WTF_MAKE_FAST_ALLOCATED;
public:
enum class Type { VP8, VP9 };
static void create(Type, CreateCallback&&, OutputCallback&&, PostTaskCallback&&);

LibWebRTCVPXVideoDecoder(Type, OutputCallback&&, PostTaskCallback&&);
~LibWebRTCVPXVideoDecoder();

@@ -74,6 +74,17 @@ class LibWebRTCVPXInternalVideoEncoder : public ThreadSafeRefCounted<LibWebRTCVP
bool m_isClosed { false };
};

void LibWebRTCVPXVideoEncoder::create(Type type, const VideoEncoder::Config& config, CreateCallback&& callback, DescriptionCallback&& descriptionCallback, OutputCallback&& outputCallback, PostTaskCallback&& postTaskCallback)
{
auto encoder = makeUniqueRef<LibWebRTCVPXVideoEncoder>(type, config, WTFMove(descriptionCallback), WTFMove(outputCallback), WTFMove(postTaskCallback));
vpxQueue().dispatch([callback = WTFMove(callback), encoder = WTFMove(encoder)]() mutable {
auto internalEncoder = encoder->m_internalEncoder;
internalEncoder->postTask([callback = WTFMove(callback), encoder = WTFMove(encoder)]() mutable {
callback(UniqueRef<VideoEncoder> { WTFMove(encoder) });
});
});
}

LibWebRTCVPXVideoEncoder::LibWebRTCVPXVideoEncoder(Type type, const VideoEncoder::Config& config, DescriptionCallback&& descriptionCallback, OutputCallback&& outputCallback, PostTaskCallback&& postTaskCallback)
: m_internalEncoder(LibWebRTCVPXInternalVideoEncoder::create(type, config, WTFMove(outputCallback), WTFMove(postTaskCallback)))
{
@@ -39,6 +39,8 @@ class LibWebRTCVPXVideoEncoder : public VideoEncoder {
WTF_MAKE_FAST_ALLOCATED;
public:
enum class Type { VP8, VP9 };
static void create(Type, const Config&, CreateCallback&&, DescriptionCallback&&, OutputCallback&&, PostTaskCallback&&);

LibWebRTCVPXVideoEncoder(Type, const Config&, DescriptionCallback&&, OutputCallback&&, PostTaskCallback&&);
~LibWebRTCVPXVideoEncoder();

@@ -53,13 +53,11 @@ void VideoDecoder::createLocalDecoder(const String& codecName, const Config&, Cr
{
#if USE(LIBWEBRTC)
if (codecName == "vp8"_s) {
UniqueRef<VideoDecoder> decoder = makeUniqueRef<LibWebRTCVPXVideoDecoder>(LibWebRTCVPXVideoDecoder::Type::VP8, WTFMove(outputCallback), WTFMove(postCallback));
callback(WTFMove(decoder));
LibWebRTCVPXVideoDecoder::create(LibWebRTCVPXVideoDecoder::Type::VP8, WTFMove(callback), WTFMove(outputCallback), WTFMove(postCallback));
return;
}
if (codecName.startsWith("vp09.00"_s)) {
UniqueRef<VideoDecoder> decoder = makeUniqueRef<LibWebRTCVPXVideoDecoder>(LibWebRTCVPXVideoDecoder::Type::VP9, WTFMove(outputCallback), WTFMove(postCallback));
callback(WTFMove(decoder));
LibWebRTCVPXVideoDecoder::create(LibWebRTCVPXVideoDecoder::Type::VP9, WTFMove(callback), WTFMove(outputCallback), WTFMove(postCallback));
return;
}
#else
@@ -52,13 +52,11 @@ void VideoEncoder::createLocalEncoder(const String& codecName, const Config& con
{
#if USE(LIBWEBRTC)
if (codecName == "vp8"_s) {
UniqueRef<VideoEncoder> encoder = makeUniqueRef<LibWebRTCVPXVideoEncoder>(LibWebRTCVPXVideoEncoder::Type::VP8, config, WTFMove(descriptionCallback), WTFMove(outputCallback), WTFMove(postCallback));
callback(WTFMove(encoder));
LibWebRTCVPXVideoEncoder::create(LibWebRTCVPXVideoEncoder::Type::VP8, config, WTFMove(callback), WTFMove(descriptionCallback), WTFMove(outputCallback), WTFMove(postCallback));
return;
}
if (codecName.startsWith("vp09.00"_s)) {
UniqueRef<VideoEncoder> encoder = makeUniqueRef<LibWebRTCVPXVideoEncoder>(LibWebRTCVPXVideoEncoder::Type::VP9, config, WTFMove(descriptionCallback), WTFMove(outputCallback), WTFMove(postCallback));
callback(WTFMove(encoder));
LibWebRTCVPXVideoEncoder::create(LibWebRTCVPXVideoEncoder::Type::VP9, config, WTFMove(callback), WTFMove(descriptionCallback), WTFMove(outputCallback), WTFMove(postCallback));
return;
}
#else

0 comments on commit c73a0fb

Please sign in to comment.