Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[WebCodecs] Implement pixel buffer conversion for video frames produc…
…ed by libwebrtc VPX decoders

https://bugs.webkit.org/show_bug.cgi?id=246998
rdar://problem/101534191

Reviewed by Eric Carlson.

Our drawing path requires conversion to CVPixelBuffer right now.
Implement the conversion for now.

* LayoutTests/imported/w3c/web-platform-tests/webcodecs/videoFrame-createImageBitmap.https.any-expected.txt:
* Source/WebCore/platform/LibWebRTCVPXVideoDecoder.cpp:
(WebCore::LibWebRTCVPXInternalVideoDecoder::Decoded):

Canonical link: https://commits.webkit.org/255958@main
  • Loading branch information
youennf committed Oct 25, 2022
1 parent cac80a1 commit 21c5196
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
@@ -1,3 +1,3 @@

FAIL Create ImageBitmap for a VideoFrame from VP9 decoder. assert_approx_equals: expected 50 +/- 10 but got 0
PASS Create ImageBitmap for a VideoFrame from VP9 decoder.

28 changes: 25 additions & 3 deletions Source/WebCore/platform/LibWebRTCVPXVideoDecoder.cpp
Expand Up @@ -28,6 +28,7 @@

#if ENABLE(WEB_CODECS) && USE(LIBWEBRTC)

#include "Logging.h"
#include "VideoFrameLibWebRTC.h"
#include <wtf/FastMalloc.h>
#include <wtf/NeverDestroyed.h>
Expand All @@ -45,6 +46,8 @@ ALLOW_COMMA_BEGIN
ALLOW_COMMA_END
ALLOW_UNUSED_PARAMETERS_END

#include "CoreVideoSoftLink.h"

namespace WebCore {

static WorkQueue& vpxQueue()
Expand Down Expand Up @@ -164,9 +167,28 @@ int32_t LibWebRTCVPXInternalVideoDecoder::Decoded(webrtc::VideoFrame& frame)
if (protectedThis->m_isClosed)
return;

auto videoFrame = VideoFrameLibWebRTC::create({ }, false, VideoFrame::Rotation::None, WTFMove(buffer), [](auto&) {
// FIXME: To implement.
return nullptr;
auto videoFrame = VideoFrameLibWebRTC::create({ }, false, VideoFrame::Rotation::None, WTFMove(buffer), [](auto& buffer) {
return adoptCF(webrtc::createPixelBufferFromFrameBuffer(buffer, [](size_t width, size_t height, webrtc::BufferType bufferType) -> CVPixelBufferRef {
OSType pixelBufferType;
switch (bufferType) {
case webrtc::BufferType::I420:
pixelBufferType = kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange;
break;
case webrtc::BufferType::I010:
pixelBufferType = kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange;
break;
default:
return nullptr;
}

CVPixelBufferRef pixelBuffer = nullptr;
auto status = CVPixelBufferCreate(kCFAllocatorDefault, width, height, pixelBufferType, nullptr, &pixelBuffer);
if (status != kCVReturnSuccess) {
RELEASE_LOG_ERROR(Media, "Failed creating a pixel buffer for converting a VPX frame with error %d", status);
return nullptr;
}
return pixelBuffer;
}));
});

protectedThis->m_outputCallback(VideoDecoder::DecodedFrame { WTFMove(videoFrame), timestamp, duration });
Expand Down

0 comments on commit 21c5196

Please sign in to comment.