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

Disabling hardware acceleration #98

Closed
aboba opened this issue Feb 16, 2022 · 17 comments
Closed

Disabling hardware acceleration #98

aboba opened this issue Feb 16, 2022 · 17 comments
Assignees
Labels
PR exists TPAC 2023 For discussion at TPAC

Comments

@aboba
Copy link
Contributor

aboba commented Feb 16, 2022

WebCodecs has a hardwareAcceleration member in the VideoConfig dictionary.

Is there a way to express a similar preference in WebRTC?

@Orphis
Copy link
Contributor

Orphis commented Feb 17, 2022

We don't have anything related to it and it's been up to the user agent for now. We could reuse the same member in the sender's parameters to achieve a similar result.

I'm wondering if there's any signal happening when you use "prefer-hardware" and the user agent needs to fallback to a software implementation.

@alvestrand
Copy link
Collaborator

hardwareAcceleration is an input parameter to Media Capabilities.
I wonder if the right pattern is to allow the user to take the output of mediaCapabilities and use that in setCodecPreferences, and have this guarantee that the right codec implemetnation is chosen.

@aboba
Copy link
Contributor Author

aboba commented Feb 17, 2022

In Chromium, WebCodecs "prefer-hardware" and "prefer-software" are interpreted as requirements (though the spec indicates that they should be thought of as a hint). "no-preference" is closer to "use hardware if you can, otherwise fallback to software".

Looking at MediaCapabilties, VideoConfiguration does not currently include a hardwareAcceleration member. However, MediaCapabilitiesInfo (the output) does indicate whether the configuration is supported, smooth or power efficient.

@HuaChunbo
Copy link
Member

I think that Media Capabilities will not be able to reflect all the runtime failures during encoding/decoding for hardware. The fallback mechanism will take care encoding/decoding job if hardware fails during runtime.

@fippo
Copy link
Contributor

fippo commented Feb 28, 2022

I went through my list-of-interesting bugs and found quite a few which were related to hardware encoding or decoding.
The last one was the worst but the size of the list emphasizes the need for an API that at least offers an escape hatch.

Hardware H264 Encoder is being used instead of OpenH264 on MacOS resulting in poor frame rate / pixelated video
https://bugs.chromium.org/p/chromium/issues/detail?id=1142273&

Consider adding support for hardware vp8 decoding on Windows.
https://bugs.chromium.org/p/chromium/issues/detail?id=1062849

Disabling hardware acceleration silently fails to encode camera frames in WebRTC on macOS
https://bugs.chromium.org/p/chromium/issues/detail?id=1168948&

If the stream obtained via HTMLVideoElement.captureStream() is sent on peer connection, it does not send any actual data
https://bugs.chromium.org/p/chromium/issues/detail?id=1156408

Green Screen on WebRTC (w/ H264 Codec) Recorded Videos when Hardware Acceleration is disabled
https://bugs.chromium.org/p/chromium/issues/detail?id=1176817

VP9 decoder shows a green strip at the bottom (Windows only)
https://bugs.chromium.org/p/chromium/issues/detail?id=1201801#c11

Encode fps drops sharply after pc.replaceTrack, due to FrameDropper kicking in from too many hugesFrames encoded, when encoding H.264 on MacOS
https://bugs.chromium.org/p/webrtc/issues/detail?id=12704

WebRTC video stream shows green and garbled in chrome 91 Beta
https://bugs.chromium.org/p/chromium/issues/detail?id=1213063

Resolution cannot ramp-up to 720P on Windows Chrome 91 with HW acceleration enabled
https://bugs.chromium.org/p/webrtc/issues/detail?id=12942

VP8 encoder issue when hardware acceleration enabled on mobile device
https://bugs.chromium.org/p/chromium/issues/detail?id=1237677

Windows H264 encoder may freeze
https://bugs.chromium.org/p/chromium/issues/detail?id=1252710

Android MediaCodec Encoder requires 16-pixel alignment
https://bugs.chromium.org/p/webrtc/issues/detail?id=13089

VP8 encoder issue when hardware acceleration enabled on mobile device
https://bugs.chromium.org/p/chromium/issues/detail?id=1237677

iPadOS 15 / iOS 15 unable to decode VP9 stream
https://bugs.webkit.org/show_bug.cgi?id=230604#c11

WebRTC Output FPS Drops to 0 and Does Not Recover
https://bugs.chromium.org/p/chromium/issues/detail?id=1261560

Android HW Encoder produces corrupted images (also in Google Duo)
https://bugs.chromium.org/p/webrtc/issues/detail?id=11337

Chrome Canary - WebRTC RTCPeerConnection.close() not returning
https://bugs.chromium.org/p/chromium/issues/detail?id=1264465
root cause was hw decoder deinit

WebRTC framesSent plummets for no obvious reason
https://bugs.chromium.org/p/chromium/issues/detail?id=1088650

Corrupt WebRTC video from VP9 hardware decoder on Intel/Windows
https://bugs.chromium.org/p/chromium/issues/detail?id=1279214

Safari: VP9-SVS no video stream from remote peer on some devices
https://bugs.webkit.org/show_bug.cgi?id=231074

Apple Silicon: Black screen share on remote side of peerconnection
https://bugs.webkit.org/show_bug.cgi?id=236870

H264 HW encoding/decoding cause breaks the picture
https://bugs.chromium.org/p/webrtc/issues/detail?id=13693

H264 HW encoder produces 1 key frame per second on webrtc
https://bugs.chromium.org/p/chromium/issues/detail?id=1296524

Chrome version 98(which introduces HW encoding) degrades sent resolution and increases keyframe generation https://bugs.chromium.org/p/chromium/issues/detail?id=1295815

@aboba
Copy link
Contributor Author

aboba commented Feb 28, 2022

@fippo That is a very impressive list of bugs!

@Orphis @alvestrand Are we looking to modify the negotiation process (e.g. filter codecs emitted by createOffer())? Or we talking about a parameter setting?

Parameter setting could work in a scenario where both hardware and software support is available and the goal is to prefer one over the other. But if the preferred codec is only supported in hardware, setParameters("prefer-software") would imply attempting to modify the envelope of what is negotiated in Offer/Answer, which is not permitted in WebRTC 1.0.

An extension to setCodecPreferences() could affect how createOffer() and createAnswer() behave. For example, a "prefer-software" would filter out codecs only supported in hardware. But that wouldn't take effect until the negotiation completes.

@fippo
Copy link
Contributor

fippo commented Mar 20, 2022

Sadly I missed the meeting. Here is what I would do (I actually have a chrome CL for it even), extending RTCRtpSender and Receiver with

    [CallWith=ScriptState] static void disableGPU();

When called before creating any peerconnection this disables hardware encoding and decoding respectively.

This is a sledgehammer and a terrible API but making it

  • inconvenient to use for the developer (by not integrating nicely)
  • inconvenient to use for the user (by requiring a page reload to change the decision)
  • clear that it is just an emergency measure

is intentional. This should be covered by appropriate usage metrics, ideally ones allowing to identify large users and then asking them why they feel a need to use it. This API should not be an excuse not to fix bugs ;-)

@aboba
Copy link
Contributor Author

aboba commented Mar 20, 2022

Meeting minutes and video are available here.

As noted in the minutes, the high level question was whether this is something the browser should handle "under the covers" (e.g. via a whitelist) or something that the application should have control over. If the application has the ability to disable hardware acceleration, how does it know when to do so? Disabling all hw acceleration, or hw acceleration for a particular codec, may be a blunt instrument. If there is a bug in a particular codec and set of hardware, how does the application know whether it is running on that hardware? It would need to access information about the device which would also be useful for fingerprinting. That concern is not present with a whitelist.

@danjenkins
Copy link

I don't believe a whitelist makes sense across multiple browser vendors, developers are already having to write "if safari and 15.1... disable h264" kinds of conditions.... I like @fippo 's idea of "an emergency scenario API" that doesn't give fine grained control but does give the control to the end developer allowing them to do "if chrome 100 disable hardware acceleration" - at the end of the day developers are currently stopped from being able to fix a failing web app and sometimes spend weeks waiting for a browser release - why would a whitelist get changed any quicker - we're still reliant on someone from a browser agreeing the issue exists and removing something from a whitelist. Let the developer take control but do it in a way that doesn't allow fingerprinting.

@threema-danilo
Copy link

developers are already having to write "if safari and 15.1... disable h264" kinds of conditions....

In case this information is useful, at Threema we already have a exclusion list of devices with broken hardware codecs. (Not surprisingly, all of them are made by Samsung.) https://github.com/threema-ch/threema-android/blob/557b69f33dd1db96f58e41f6602e32522470f53e/app/src/main/java/ch/threema/app/voip/Config.java#L59-L64

Additionally we also have an exclusion list for hardware AEC: https://github.com/threema-ch/threema-android/blob/557b69f33dd1db96f58e41f6602e32522470f53e/app/src/main/java/ch/threema/app/voip/Config.java#L35-L41 Maybe an API for disabling hardware acceleration for video codecs could be extended to also support disabling hardware AEC?

moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Apr 27, 2022
Chrome has had a variety of issues with hardware encoders:
w3c/webrtc-extensions#98 (comment)

We'll disable hardware encoders for now so that we can get consistent
behaviour everywhere. Once we've updated to a modern libwebrtc we
can reenable them.

This also makes it so that we can get resolution scaling on H264 without having
to cherrypick patches from upstream libwebrtc.

Differential Revision: https://phabricator.services.mozilla.com/D144773
jamienicol pushed a commit to jamienicol/gecko that referenced this issue Apr 28, 2022
Chrome has had a variety of issues with hardware encoders:
w3c/webrtc-extensions#98 (comment)

We'll disable hardware encoders for now so that we can get consistent
behaviour everywhere. Once we've updated to a modern libwebrtc we
can reenable them.

This also makes it so that we can get resolution scaling on H264 without having
to cherrypick patches from upstream libwebrtc.

Differential Revision: https://phabricator.services.mozilla.com/D144773
@aboba aboba added the TPAC 2023 For discussion at TPAC label Aug 25, 2022
@fippo
Copy link
Contributor

fippo commented Dec 1, 2022

https://www.w3.org/2022/09/12-webrtc-minutes.html#t18 -- TPAC minutes (so I can find them). PR should be incoming soon.

@bdrtc
Copy link

bdrtc commented Dec 1, 2022

great! !Looking forward to this feature coming soon, We have encountered several video blurring problems caused by hardware decoding, and finally can only be solved by manually turning off hardware acceleration through chrome://flags,
especially on mobile platforms。

@fippo
Copy link
Contributor

fippo commented Dec 2, 2022

We have encountered several video blurring problems caused by hardware decoding

Please file a chrome bug. In particular for Intel they are very interested in fixing issues that pop up.

@bdrtc
Copy link

bdrtc commented Jan 10, 2023

the issue fixed via #128 ?

@HuaChunbo
Copy link
Member

@bdrtc, have you filed a related Chromium bug regarding the hw encoding problems you found?

@bdrtc
Copy link

bdrtc commented Jan 12, 2023

@bdrtc, have you filed a related Chromium bug regarding the hw encoding problems you found?
hi, not yet, it happened in android device of xiaomi when decoding h264, not intel. thanks.

@aboba
Copy link
Contributor Author

aboba commented Jan 17, 2023

Addressed by PR #128

@aboba aboba closed this as completed Jan 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR exists TPAC 2023 For discussion at TPAC
Projects
None yet
Development

No branches or pull requests

8 participants