Skip to content
Permalink
Browse files
Use dav1d decoder instead of libaom decoder
https://bugs.webkit.org/show_bug.cgi?id=248523
rdar://problem/102804765

Reviewed by Jean-Yves Avenard.

dav1d decoder is more efficient than libaom decoder so it is best to use dav1d.
dav1d is a librarly linked in WebCore so we create a dav1d webrtc decoder in WebCore and not libwebrtc.
We integrate this decoder at WebKit level.

We have to export more headers, including libyuv from libwebrtc to be used in WebCore.
We update xcconfig for that purpose.

We link dav1d conditionnaly on ENABLE_WEB_RTC if it is not already linked through libavif.

* Source/ThirdParty/libwebrtc/Configurations/libwebrtc.iOS.exp:
* Source/ThirdParty/libwebrtc/Configurations/libwebrtc.iOSsim.exp:
* Source/ThirdParty/libwebrtc/Configurations/libwebrtc.mac.exp:
* Source/ThirdParty/libwebrtc/Source/webrtc/sdk/WebKit/WebKitDecoder.h:
* Source/ThirdParty/libwebrtc/Source/webrtc/sdk/WebKit/WebKitDecoder.mm:
(webrtc::RemoteVideoDecoder::RemoteVideoDecoder):
(webrtc::RemoteVideoDecoderFactory::CreateVideoDecoder):
* Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/components/video_codec/RTCDefaultVideoDecoderFactory.m:
(-[RTCDefaultVideoDecoderFactory supportedCodecs]):
(-[RTCDefaultVideoDecoderFactory createDecoder:]):
* Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/components/video_codec/RTCDefaultVideoEncoderFactory.m:
(+[RTCDefaultVideoEncoderFactory supportedCodecsWithH265:vp9Profile0:vp9Profile2:av1:]):
(-[RTCDefaultVideoEncoderFactory createEncoder:]):
* Source/ThirdParty/libwebrtc/libwebrtc.xcodeproj/project.pbxproj:
* Source/WebCore/PAL/libavif/dav1d/dav1d.xcodeproj/project.pbxproj:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCDav1dDecoder.cpp: Added.
(WebCore::ScopedDav1dData::~ScopedDav1dData):
(WebCore::ScopedDav1dData::Data):
(WebCore::ScopedDav1dPicture::~ScopedDav1dPicture):
(WebCore::ScopedDav1dPicture::Picture):
(WebCore::NullFreeCallback):
(WebCore::Dav1dDecoder::Dav1dDecoder):
(WebCore::Dav1dDecoder::~Dav1dDecoder):
(WebCore::Dav1dDecoder::Configure):
(WebCore::Dav1dDecoder::RegisterDecodeCompleteCallback):
(WebCore::Dav1dDecoder::Release):
(WebCore::Dav1dDecoder::GetDecoderInfo const):
(WebCore::Dav1dDecoder::ImplementationName const):
(WebCore::Dav1dDecoder::Decode):
(WebCore::createLibWebRTCDav1dDecoder):
* Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCDav1dDecoder.h: Added.
* Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp:
(WebKit::createVideoDecoder):
(WebKit::releaseVideoDecoder):
(WebKit::decodeVideoFrame):
(WebKit::registerDecodeCompleteCallback):

Canonical link: https://commits.webkit.org/257357@main
  • Loading branch information
youennf committed Dec 4, 2022
1 parent bd076ef commit 61a22089e97ad4735d146b243494f19ec670ee4f
Show file tree
Hide file tree
Showing 16 changed files with 544 additions and 33 deletions.
@@ -204,7 +204,7 @@ __ZN6webrtc17setDecodingFormatEPvPKhmtt
__ZN6webrtc11decodeFrameEPvxPKhm
__ZN6webrtc24videoDecoderTaskCompleteEPvjjP10__CVBuffer
__ZN6webrtc24videoDecoderTaskCompleteEPvjjS0_PFP10__CVBufferS0_EPFvS0_Eii
__ZN6webrtc24setVideoDecoderCallbacksEPFPvRKNS_14SdpVideoFormatEEPFiS0_EPFiS0_jPKhmttEPFiS0_S0_E
__ZN6webrtc24setVideoDecoderCallbacksEPFNS_18WebKitVideoDecoderERKNS_14SdpVideoFormatEEPFiPvEPFiS6_jPKhmttEPFiS6_S6_E
__ZN6webrtc24toWebRTCVideoFrameBufferEPvPFP10__CVBufferS0_EPFvS0_Eii
__ZN6webrtc24videoFrameBufferProviderERKNS_10VideoFrameE
__ZN6webrtc19setDecoderFrameSizeEPvtt
@@ -362,3 +362,16 @@ __ZNK6webrtc10ColorSpace5rangeEv
__ZNK6webrtc10ColorSpace6matrixEv
__ZNK6webrtc10ColorSpace8transferEv
__ZNK6webrtc10ColorSpace9primariesEv
_I420Copy
__ZN6webrtc10VideoFrame7Builder15set_color_spaceEPKNS_10ColorSpaceE
__ZN6webrtc10VideoFrame7Builder15set_ntp_time_msEx
__ZN6webrtc10VideoFrame7Builder17set_timestamp_rtpEj
__ZN6webrtc10VideoFrame7Builder22set_video_frame_bufferERKN3rtc13scoped_refptrINS_16VideoFrameBufferEEE
__ZN6webrtc10VideoFrame7Builder5buildEv
__ZN6webrtc10VideoFrame7BuilderC1Ev
__ZN6webrtc10VideoFrame7BuilderD1Ev
__ZN6webrtc20VideoFrameBufferPool16CreateI420BufferEii
__ZN6webrtc20VideoFrameBufferPool7ReleaseEv
__ZN6webrtc20VideoFrameBufferPoolC1Ebm
__ZN6webrtc20VideoFrameBufferPoolD1Ev
__ZTVN6webrtc12VideoDecoderE
@@ -204,7 +204,7 @@ __ZN6webrtc17setDecodingFormatEPvPKhmtt
__ZN6webrtc11decodeFrameEPvxPKhm
__ZN6webrtc24videoDecoderTaskCompleteEPvjjP10__CVBuffer
__ZN6webrtc24videoDecoderTaskCompleteEPvjjS0_PFP10__CVBufferS0_EPFvS0_Eii
__ZN6webrtc24setVideoDecoderCallbacksEPFPvRKNS_14SdpVideoFormatEEPFiS0_EPFiS0_jPKhmttEPFiS0_S0_E
__ZN6webrtc24setVideoDecoderCallbacksEPFNS_18WebKitVideoDecoderERKNS_14SdpVideoFormatEEPFiPvEPFiS6_jPKhmttEPFiS6_S6_E
__ZN6webrtc24toWebRTCVideoFrameBufferEPvPFP10__CVBufferS0_EPFvS0_Eii
__ZN6webrtc24videoFrameBufferProviderERKNS_10VideoFrameE
__ZN6webrtc19setDecoderFrameSizeEPvtt
@@ -362,3 +362,16 @@ __ZNK6webrtc10ColorSpace5rangeEv
__ZNK6webrtc10ColorSpace6matrixEv
__ZNK6webrtc10ColorSpace8transferEv
__ZNK6webrtc10ColorSpace9primariesEv
_I420Copy
__ZN6webrtc10VideoFrame7Builder15set_color_spaceEPKNS_10ColorSpaceE
__ZN6webrtc10VideoFrame7Builder15set_ntp_time_msEx
__ZN6webrtc10VideoFrame7Builder17set_timestamp_rtpEj
__ZN6webrtc10VideoFrame7Builder22set_video_frame_bufferERKN3rtc13scoped_refptrINS_16VideoFrameBufferEEE
__ZN6webrtc10VideoFrame7Builder5buildEv
__ZN6webrtc10VideoFrame7BuilderC1Ev
__ZN6webrtc10VideoFrame7BuilderD1Ev
__ZN6webrtc20VideoFrameBufferPool16CreateI420BufferEii
__ZN6webrtc20VideoFrameBufferPool7ReleaseEv
__ZN6webrtc20VideoFrameBufferPoolC1Ebm
__ZN6webrtc20VideoFrameBufferPoolD1Ev
__ZTVN6webrtc12VideoDecoderE
@@ -206,7 +206,7 @@ __ZN6webrtc24videoDecoderTaskCompleteEPvjjP10__CVBuffer
__ZN6webrtc24videoDecoderTaskCompleteEPvjjS0_PFP10__CVBufferS0_EPFvS0_Eii
__ZN6webrtc24toWebRTCVideoFrameBufferEPvPFP10__CVBufferS0_EPFvS0_Eii
__ZN6webrtc24videoFrameBufferProviderERKNS_10VideoFrameE
__ZN6webrtc24setVideoDecoderCallbacksEPFPvRKNS_14SdpVideoFormatEEPFiS0_EPFiS0_jPKhmttEPFiS0_S0_E
__ZN6webrtc24setVideoDecoderCallbacksEPFNS_18WebKitVideoDecoderERKNS_14SdpVideoFormatEEPFiPvEPFiS6_jPKhmttEPFiS6_S6_E
__ZN6webrtc19setDecoderFrameSizeEPvtt
__ZN6webrtc18RtpCodecCapabilityC1Ev
__ZN6webrtc24encoderVideoTaskCompleteEPvNS_14VideoCodecTypeEPKhmRKNS_22WebKitEncodedFrameInfoE
@@ -362,3 +362,16 @@ __ZNK6webrtc10ColorSpace5rangeEv
__ZNK6webrtc10ColorSpace6matrixEv
__ZNK6webrtc10ColorSpace8transferEv
__ZNK6webrtc10ColorSpace9primariesEv
_I420Copy
__ZN6webrtc10VideoFrame7Builder15set_color_spaceEPKNS_10ColorSpaceE
__ZN6webrtc10VideoFrame7Builder15set_ntp_time_msEx
__ZN6webrtc10VideoFrame7Builder17set_timestamp_rtpEj
__ZN6webrtc10VideoFrame7Builder22set_video_frame_bufferERKN3rtc13scoped_refptrINS_16VideoFrameBufferEEE
__ZN6webrtc10VideoFrame7Builder5buildEv
__ZN6webrtc10VideoFrame7BuilderC1Ev
__ZN6webrtc10VideoFrame7BuilderD1Ev
__ZN6webrtc20VideoFrameBufferPool16CreateI420BufferEii
__ZN6webrtc20VideoFrameBufferPool7ReleaseEv
__ZN6webrtc20VideoFrameBufferPoolC1Ebm
__ZN6webrtc20VideoFrameBufferPoolD1Ev
__ZTVN6webrtc12VideoDecoderE
@@ -45,11 +45,15 @@ namespace webrtc {
struct SdpVideoFormat;
class VideoDecoderFactory;

using WebKitVideoDecoder = void*;
struct WebKitVideoDecoder {
using Value = void*;
Value value { nullptr };
bool isWebRTCVideoDecoder { false };
};
using VideoDecoderCreateCallback = WebKitVideoDecoder(*)(const SdpVideoFormat& format);
using VideoDecoderReleaseCallback = int32_t(*)(WebKitVideoDecoder);
using VideoDecoderDecodeCallback = int32_t(*)(WebKitVideoDecoder, uint32_t timeStamp, const uint8_t*, size_t length, uint16_t width, uint16_t height);
using VideoDecoderRegisterDecodeCompleteCallback = int32_t(*)(WebKitVideoDecoder, void* decodedImageCallback);
using VideoDecoderReleaseCallback = int32_t(*)(WebKitVideoDecoder::Value);
using VideoDecoderDecodeCallback = int32_t(*)(WebKitVideoDecoder::Value, uint32_t timeStamp, const uint8_t*, size_t length, uint16_t width, uint16_t height);
using VideoDecoderRegisterDecodeCompleteCallback = int32_t(*)(WebKitVideoDecoder::Value, void* decodedImageCallback);

void setVideoDecoderCallbacks(VideoDecoderCreateCallback, VideoDecoderReleaseCallback, VideoDecoderDecodeCallback, VideoDecoderRegisterDecodeCompleteCallback);

@@ -161,7 +161,7 @@ - (void)flush {

class RemoteVideoDecoder final : public webrtc::VideoDecoder {
public:
RemoteVideoDecoder(WebKitVideoDecoder, bool isVP9);
RemoteVideoDecoder(WebKitVideoDecoder::Value, bool isVP9);
~RemoteVideoDecoder();

bool isVP9() const { return m_isVP9; }
@@ -173,7 +173,7 @@ - (void)flush {
int32_t Release() final;
const char* ImplementationName() const final { return "RemoteVideoToolBox"; }

WebKitVideoDecoder m_internalDecoder;
WebKitVideoDecoder::Value m_internalDecoder;
bool m_isVP9 { false };
};

@@ -198,7 +198,7 @@ void setVideoDecoderCallbacks(VideoDecoderCreateCallback createCallback, VideoDe
callbacks.registerDecodeCompleteCallback = registerDecodeCompleteCallback;
}

RemoteVideoDecoder::RemoteVideoDecoder(WebKitVideoDecoder internalDecoder, bool isVP9)
RemoteVideoDecoder::RemoteVideoDecoder(WebKitVideoDecoder::Value internalDecoder, bool isVP9)
: m_internalDecoder(internalDecoder)
, m_isVP9(isVP9)
{
@@ -280,11 +280,14 @@ void videoDecoderTaskComplete(void* callback, uint32_t timeStamp, uint32_t timeS
if (!videoDecoderCallbacks().createCallback)
return m_internalFactory->CreateVideoDecoder(format);

auto identifier = videoDecoderCallbacks().createCallback(format);
if (!identifier)
auto createdDecoder = videoDecoderCallbacks().createCallback(format);
if (!createdDecoder.value)
return m_internalFactory->CreateVideoDecoder(format);

auto decoder = std::make_unique<RemoteVideoDecoder>(identifier, format.name == "VP9");
if (createdDecoder.isWebRTCVideoDecoder)
return std::unique_ptr<VideoDecoder> { static_cast<VideoDecoder*>(createdDecoder.value) };

auto decoder = std::make_unique<RemoteVideoDecoder>(createdDecoder.value, format.name == "VP9");
if (!decoder->isVP9())
return decoder;
return webrtc::CreateVideoDecoderSoftwareFallbackWrapper(m_internalFactory->CreateVideoDecoder(format), std::move(decoder));
@@ -23,7 +23,7 @@
#import "RTCH265ProfileLevelId.h"
#import "RTCVideoDecoderH265.h"
#endif
#if !defined(DISABLE_LIBAOM_AV1)
#if !defined(DISABLE_RTC_AV1)
#import "sdk/objc/api/video_codec/RTCVideoDecoderAV1.h"
#endif

@@ -97,7 +97,7 @@ - (id)initWithH265:(bool)supportsH265 vp9Profile0:(bool)supportsVP9Profile0 vp9P
}]];
}
#endif
#if !defined(DISABLE_LIBAOM_AV1)
#if !defined(DISABLE_RTC_AV1)
if (_supportsAv1) {
[codecs addObject:[[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecAv1Name]];
}
@@ -122,7 +122,7 @@ - (id)initWithH265:(bool)supportsH265 vp9Profile0:(bool)supportsVP9Profile0 vp9P
return [RTCVideoDecoderVP9 vp9Decoder];
}
#endif
#if !defined(DISABLE_LIBAOM_AV1)
#if !defined(DISABLE_RTC_AV1)
} else if ([info.name isEqualToString:kRTCVideoCodecAv1Name]) {
return [RTCVideoDecoderAV1 av1Decoder];
}
@@ -22,7 +22,7 @@
#import "RTCH265ProfileLevelId.h"
#import "RTCVideoEncoderH265.h"
#endif
#if !defined(DISABLE_LIBAOM_AV1_ENCODER)
#if !defined(DISABLE_RTC_AV1)
#import "sdk/objc/api/video_codec/RTCVideoEncoderAV1.h"
#endif

@@ -98,7 +98,7 @@ - (id)initWithH265:(bool)supportsH265 vp9Profile0:(bool)supportsVP9Profile0 vp9P
}]];
}
#endif
#if !defined(DISABLE_LIBAOM_AV1)
#if !defined(DISABLE_RTC_AV1)
if (supportsAv1) {
[codecs addObject:[[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecAv1Name]];
}
@@ -125,7 +125,7 @@ - (id)initWithH265:(bool)supportsH265 vp9Profile0:(bool)supportsVP9Profile0 vp9P
}
#endif
}
#if !defined(DISABLE_LIBAOM_AV1)
#if !defined(DISABLE_RTC_AV1)
if ([info.name isEqualToString:kRTCVideoCodecAv1Name]) {
return [RTCVideoEncoderAV1 av1Encoder];
}

0 comments on commit 61a2208

Please sign in to comment.