Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cocoa] Remote video codecs should surface any error happening during encoding to web pages #20876

Conversation

youennf
Copy link
Contributor

@youennf youennf commented Nov 24, 2023

279e75f

[Cocoa] Remote video codecs should surface any error happening during encoding to web pages
https://bugs.webkit.org/show_bug.cgi?id=265307
rdar://118770776

Reviewed by Eric Carlson.

We were not exposing the encoder errors to JavaScript, while the spec asks us to do so.
We add to H264 and HEVC encoders a way to be notified of any error, and update the code so that,
either the success or error callback is called for every encoding task.

We update LibWebRTCCodecs to make encoding and flush IPC messages with a response handler.
This allows to call the WebCodecs encoding task completion handler with the result of the encoding task.
We use NativePromise for both as a convenience and we make sure that the order of messages is guaranteed.

Covered by a new test which triggers an encoding error by using a low H264 encoding level with large video frames.
This should in theory be handled at configure step but we are not yet checking precisely enough this.
When we do this, we will need to change the test and it will probably be pass for all platforms as the checking code might be in WebKit and not below.
This test is only passing in Sonoma since below, the underlying encoder is not triggering an encoding error.

* LayoutTests/TestExpectations:
* LayoutTests/http/wpt/webcodecs/encoder-task-failing-expected.txt: Added.
* LayoutTests/http/wpt/webcodecs/encoder-task-failing.html: Added.
* LayoutTests/platform/mac-wk2/TestExpectations:
* Source/ThirdParty/libwebrtc/Configurations/libwebrtc.exp:
* Source/ThirdParty/libwebrtc/Source/webrtc/sdk/WebKit/WebKitEncoder.h:
* Source/ThirdParty/libwebrtc/Source/webrtc/sdk/WebKit/WebKitEncoder.mm:
(-[WK_RTCLocalVideoH264H265Encoder setErrorCallback:]):
(webrtc::createLocalEncoder):
* Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/base/RTCVideoEncoder.h:
* Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/components/video_codec/RTCVideoEncoderH264.h:
* Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/components/video_codec/RTCVideoEncoderH264.mm:
(-[RTCVideoEncoderH264 setErrorCallback:]):
(-[RTCVideoEncoderH264 encode:codecSpecificInfo:frameTypes:]):
(-[RTCVideoEncoderH264 frameWasEncoded:flags:sampleBuffer:codecSpecificInfo:width:height:renderTimeMs:timestamp:duration:rotation:isKeyFrameRequired:]):
* Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/components/video_codec/RTCVideoEncoderH265.h:
* Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/components/video_codec/RTCVideoEncoderH265.mm:
(-[RTCVideoEncoderH265 setErrorCallback:]):
(-[RTCVideoEncoderH265 encode:codecSpecificInfo:frameTypes:]):
(-[RTCVideoEncoderH265 frameWasEncoded:flags:sampleBuffer:width:height:renderTimeMs:timestamp:rotation:]):
* Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.h:
* Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.messages.in:
* Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.mm:
(WebKit::LibWebRTCCodecsProxy::createEncoder):
(WebKit::LibWebRTCCodecsProxy::encodeFrame):
(WebKit::LibWebRTCCodecsProxy::notifyEncoderResult):
(WebKit::LibWebRTCCodecsProxy::flushEncoder):
* Source/WebKit/WebProcess/GPU/media/RemoteVideoCodecFactory.cpp:
(WebKit::RemoteVideoEncoderCallbacks::close):
(WebKit::RemoteVideoEncoder::encode):
(WebKit::RemoteVideoEncoderCallbacks::notifyEncodedChunk):
(WebKit::RemoteVideoEncoderCallbacks::addDuration): Deleted.
* Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp:
(WebKit::LibWebRTCCodecs::encodeFrameInternal):
(WebKit::LibWebRTCCodecs::encodeFrame):
(WebKit::LibWebRTCCodecs::flushEncoder):
(WebKit::LibWebRTCCodecs::flushEncoderCompleted): Deleted.
* Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.h:
* Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.messages.in:

Canonical link: https://commits.webkit.org/271377@main

eb64486

Misc iOS, tvOS & watchOS macOS Linux Windows
βœ… πŸ§ͺ style βœ… πŸ›  ios βœ… πŸ›  mac βœ… πŸ›  wpe βœ… πŸ›  wincairo
βœ… πŸ›  ios-sim βœ… πŸ›  mac-AS-debug   πŸ§ͺ wpe-wk2
βœ… πŸ§ͺ webkitperl βœ… πŸ§ͺ ios-wk2 βœ… πŸ§ͺ api-mac βœ… πŸ§ͺ api-wpe
  πŸ§ͺ ios-wk2-wpt βœ… πŸ§ͺ mac-wk1 βœ… πŸ›  gtk
βœ… πŸ§ͺ api-ios βœ… πŸ§ͺ mac-wk2 βœ… πŸ§ͺ gtk-wk2
βœ… πŸ›  tv βœ… πŸ§ͺ mac-AS-debug-wk2 βœ… πŸ§ͺ api-gtk
βœ… πŸ›  tv-sim βœ… πŸ§ͺ mac-wk2-stress
βœ… πŸ›  πŸ§ͺ merge βœ… πŸ›  watch
βœ… πŸ›  watch-sim

@youennf youennf requested a review from cdumez as a code owner November 24, 2023 17:13
@youennf youennf self-assigned this Nov 24, 2023
@youennf youennf added the Media Bugs related to the HTML 5 Media elements. label Nov 24, 2023
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Nov 24, 2023
Copy link
Contributor

@eric-carlson eric-carlson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me once the bots are hapoy

@youennf youennf force-pushed the eng/Cocoa-Remote-video-codecs-should-surface-any-error-happening-during-encoding-to-web-pages branch from 88a81df to 9759b7c Compare November 27, 2023 08:47
@youennf youennf force-pushed the eng/Cocoa-Remote-video-codecs-should-surface-any-error-happening-during-encoding-to-web-pages branch from 9759b7c to bb427b8 Compare November 28, 2023 07:26
@youennf youennf force-pushed the eng/Cocoa-Remote-video-codecs-should-surface-any-error-happening-during-encoding-to-web-pages branch from bb427b8 to c21b3f1 Compare November 29, 2023 11:38
@youennf youennf force-pushed the eng/Cocoa-Remote-video-codecs-should-surface-any-error-happening-during-encoding-to-web-pages branch from c21b3f1 to eb64486 Compare December 1, 2023 07:09
@youennf youennf removed the merging-blocked Applied to prevent a change from being merged label Dec 1, 2023
@youennf youennf added the merge-queue Applied to send a pull request to merge-queue label Dec 1, 2023
… encoding to web pages

https://bugs.webkit.org/show_bug.cgi?id=265307
rdar://118770776

Reviewed by Eric Carlson.

We were not exposing the encoder errors to JavaScript, while the spec asks us to do so.
We add to H264 and HEVC encoders a way to be notified of any error, and update the code so that,
either the success or error callback is called for every encoding task.

We update LibWebRTCCodecs to make encoding and flush IPC messages with a response handler.
This allows to call the WebCodecs encoding task completion handler with the result of the encoding task.
We use NativePromise for both as a convenience and we make sure that the order of messages is guaranteed.

Covered by a new test which triggers an encoding error by using a low H264 encoding level with large video frames.
This should in theory be handled at configure step but we are not yet checking precisely enough this.
When we do this, we will need to change the test and it will probably be pass for all platforms as the checking code might be in WebKit and not below.
This test is only passing in Sonoma since below, the underlying encoder is not triggering an encoding error.

* LayoutTests/TestExpectations:
* LayoutTests/http/wpt/webcodecs/encoder-task-failing-expected.txt: Added.
* LayoutTests/http/wpt/webcodecs/encoder-task-failing.html: Added.
* LayoutTests/platform/mac-wk2/TestExpectations:
* Source/ThirdParty/libwebrtc/Configurations/libwebrtc.exp:
* Source/ThirdParty/libwebrtc/Source/webrtc/sdk/WebKit/WebKitEncoder.h:
* Source/ThirdParty/libwebrtc/Source/webrtc/sdk/WebKit/WebKitEncoder.mm:
(-[WK_RTCLocalVideoH264H265Encoder setErrorCallback:]):
(webrtc::createLocalEncoder):
* Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/base/RTCVideoEncoder.h:
* Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/components/video_codec/RTCVideoEncoderH264.h:
* Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/components/video_codec/RTCVideoEncoderH264.mm:
(-[RTCVideoEncoderH264 setErrorCallback:]):
(-[RTCVideoEncoderH264 encode:codecSpecificInfo:frameTypes:]):
(-[RTCVideoEncoderH264 frameWasEncoded:flags:sampleBuffer:codecSpecificInfo:width:height:renderTimeMs:timestamp:duration:rotation:isKeyFrameRequired:]):
* Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/components/video_codec/RTCVideoEncoderH265.h:
* Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/components/video_codec/RTCVideoEncoderH265.mm:
(-[RTCVideoEncoderH265 setErrorCallback:]):
(-[RTCVideoEncoderH265 encode:codecSpecificInfo:frameTypes:]):
(-[RTCVideoEncoderH265 frameWasEncoded:flags:sampleBuffer:width:height:renderTimeMs:timestamp:rotation:]):
* Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.h:
* Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.messages.in:
* Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.mm:
(WebKit::LibWebRTCCodecsProxy::createEncoder):
(WebKit::LibWebRTCCodecsProxy::encodeFrame):
(WebKit::LibWebRTCCodecsProxy::notifyEncoderResult):
(WebKit::LibWebRTCCodecsProxy::flushEncoder):
* Source/WebKit/WebProcess/GPU/media/RemoteVideoCodecFactory.cpp:
(WebKit::RemoteVideoEncoderCallbacks::close):
(WebKit::RemoteVideoEncoder::encode):
(WebKit::RemoteVideoEncoderCallbacks::notifyEncodedChunk):
(WebKit::RemoteVideoEncoderCallbacks::addDuration): Deleted.
* Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp:
(WebKit::LibWebRTCCodecs::encodeFrameInternal):
(WebKit::LibWebRTCCodecs::encodeFrame):
(WebKit::LibWebRTCCodecs::flushEncoder):
(WebKit::LibWebRTCCodecs::flushEncoderCompleted): Deleted.
* Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.h:
* Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.messages.in:

Canonical link: https://commits.webkit.org/271377@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/Cocoa-Remote-video-codecs-should-surface-any-error-happening-during-encoding-to-web-pages branch from eb64486 to 279e75f Compare December 1, 2023 12:05
@webkit-commit-queue
Copy link
Collaborator

Committed 271377@main (279e75f): https://commits.webkit.org/271377@main

Reviewed commits have been landed. Closing PR #20876 and removing active labels.

@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Dec 1, 2023
@webkit-commit-queue webkit-commit-queue merged commit 279e75f into WebKit:main Dec 1, 2023
webkit-commit-queue pushed a commit to youennf/WebKit that referenced this pull request Dec 4, 2023
…odecs are a constant failure

https://bugs.webkit.org/show_bug.cgi?id=265483
rdar://118901410

Reviewed by Jean-Yves Avenard.

x86_64 VTB encoder does not like some low resolutions, increase to 200x200 to handle this correctly..
In the future, WebKit#20876 will surface such errors instead of silently failing.

* LayoutTests/http/wpt/webcodecs/h264-encoder-default-config.https.any.js:
(async encoderTest):

Canonical link: https://commits.webkit.org/271464@main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Media Bugs related to the HTML 5 Media elements.
Projects
None yet
5 participants