Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WebCodecs] Limit the number of codec operations we can enqueue
https://bugs.webkit.org/show_bug.cgi?id=284448 rdar://141272065 Reviewed by NOBODY (OOPS!). While the WebCodecs specs clearly allows for boundless queue for calculating "Codec Saturdation", a side effect is that both decodeQueueSize and encodeQueueSize can only ever be observed with a size of 0. The value of decodeQueueSize and encodeQueueSize is used by some site (including W3C's WebCodecs's own example) as a way to limit how much in advance it will attempt to encode or decode. Both Chrome and Firefox have a limit on how many codecs operations (1 for Firefox, between 1 and 8 for Chrome) they will enqueue concurrently. To minimise web compatibility issue, in addition to lodging a spec bug (w3c/webcodecs#864) we also introduce a limit on how many frames with submit to the internal decoder/encoder before submitting more: - 1 for Audio - 4 for Video. In order of not having to replicate 4 times the code in {Audio|Video}{Encoder|Decoder} we create a new WebCodecsBase that handles all the control message queue operations as well as handle how many codec operations have been submitted, and of which all WebCodecs inherit from. Doing so allows to remove a lot of similar code across all webcodecs and get us closer to the verbiage of the specs. Another benefit is that WebCodecsControlMessage no longer needs to be a templated class, and we make it return a "Processed" or "Not Processed" value as the specs does. No change in observable behaviours with existing WPT. Tested that it allows the WebCodecs reference player to work. No new tests as none of the work above is per spec. * Source/WebCore/Headers.cmake: * Source/WebCore/Modules/webcodecs/WebCodecsAudioDecoder.cpp: (WebCore::WebCodecsAudioDecoder::WebCodecsAudioDecoder): (WebCore::WebCodecsAudioDecoder::configure): (WebCore::WebCodecsAudioDecoder::decode): (WebCore::WebCodecsAudioDecoder::flush): (WebCore::WebCodecsAudioDecoder::closeDecoder): (WebCore::WebCodecsAudioDecoder::resetDecoder): (WebCore::WebCodecsAudioDecoder::stop): (WebCore::WebCodecsAudioDecoder::scheduleDequeueEvent): Deleted. (WebCore::WebCodecsAudioDecoder::queueControlMessageAndProcess): Deleted. (WebCore::WebCodecsAudioDecoder::processControlMessageQueue): Deleted. (WebCore::WebCodecsAudioDecoder::virtualHasPendingActivity const): Deleted. * Source/WebCore/Modules/webcodecs/WebCodecsAudioDecoder.h: (WebCore::WebCodecsAudioDecoder::decodeQueueSize const): (WebCore::WebCodecsAudioDecoder::state const): Deleted. * Source/WebCore/Modules/webcodecs/WebCodecsAudioEncoder.cpp: (WebCore::WebCodecsAudioEncoder::WebCodecsAudioEncoder): (WebCore::WebCodecsAudioEncoder::configure): (WebCore::WebCodecsAudioEncoder::encode): (WebCore::WebCodecsAudioEncoder::flush): (WebCore::WebCodecsAudioEncoder::closeEncoder): (WebCore::WebCodecsAudioEncoder::resetEncoder): (WebCore::WebCodecsAudioEncoder::stop): (WebCore::WebCodecsAudioEncoder::scheduleDequeueEvent): Deleted. (WebCore::WebCodecsAudioEncoder::queueControlMessageAndProcess): Deleted. (WebCore::WebCodecsAudioEncoder::processControlMessageQueue): Deleted. (WebCore::WebCodecsAudioEncoder::virtualHasPendingActivity const): Deleted. * Source/WebCore/Modules/webcodecs/WebCodecsAudioEncoder.h: (WebCore::WebCodecsAudioEncoder::encodeQueueSize const): (WebCore::WebCodecsAudioEncoder::state const): Deleted. * Source/WebCore/Modules/webcodecs/WebCodecsBase.cpp: Added. (WebCore::WebCodecsBase::WebCodecsBase): (WebCore::WebCodecsBase::queueControlMessageAndProcess): (WebCore::WebCodecsBase::queueControlMessageForCodecOperationAndProcess): (WebCore::WebCodecsBase::scheduleDequeueEvent): (WebCore::WebCodecsBase::processControlMessageQueue): (WebCore::WebCodecsBase::incrementOperationQueueSize): (WebCore::WebCodecsBase::decrementOperationQueueSizeAndScheduleDequeueEvent): (WebCore::WebCodecsBase::decreaseCodecOperationCountAndMaybeProcessControlMessageQueue): (WebCore::WebCodecsBase::clearControlMessageQueue): (WebCore::WebCodecsBase::clearControlMessageQueueAndMaybeScheduleDequeueEvent): (WebCore::WebCodecsBase::blockControlMessageQueue): (WebCore::WebCodecsBase::unblockControlMessageQueue): (WebCore::WebCodecsBase::virtualHasPendingActivity const): * Source/WebCore/Modules/webcodecs/WebCodecsBase.h: Copied from Source/WebCore/Modules/webcodecs/WebCodecsVideoDecoder.h. (WebCore::WebCodecsBase::state const): (WebCore::WebCodecsBase::setState): (WebCore::WebCodecsBase::operationQueueSize const): (WebCore::WebCodecsBase::maximumCodecOperationsEnqueued const): (WebCore::WebCodecsBase::increaseCodecOperationCount): (WebCore::WebCodecsBase::isCodecSaturated const): * Source/WebCore/Modules/webcodecs/WebCodecsControlMessage.h: * Source/WebCore/Modules/webcodecs/WebCodecsVideoDecoder.cpp: (WebCore::WebCodecsVideoDecoder::WebCodecsVideoDecoder): (WebCore::WebCodecsVideoDecoder::configure): (WebCore::WebCodecsVideoDecoder::decode): (WebCore::WebCodecsVideoDecoder::flush): (WebCore::WebCodecsVideoDecoder::closeDecoder): (WebCore::WebCodecsVideoDecoder::resetDecoder): (WebCore::WebCodecsVideoDecoder::stop): (WebCore::WebCodecsVideoDecoder::scheduleDequeueEvent): Deleted. (WebCore::WebCodecsVideoDecoder::queueControlMessageAndProcess): Deleted. (WebCore::WebCodecsVideoDecoder::processControlMessageQueue): Deleted. (WebCore::WebCodecsVideoDecoder::virtualHasPendingActivity const): Deleted. * Source/WebCore/Modules/webcodecs/WebCodecsVideoDecoder.h: (WebCore::WebCodecsVideoDecoder::decodeQueueSize const): (WebCore::WebCodecsVideoDecoder::state const): Deleted. * Source/WebCore/Modules/webcodecs/WebCodecsVideoEncoder.cpp: (WebCore::WebCodecsVideoEncoder::WebCodecsVideoEncoder): (WebCore::WebCodecsVideoEncoder::updateRates): (WebCore::WebCodecsVideoEncoder::configure): (WebCore::WebCodecsVideoEncoder::encode): (WebCore::WebCodecsVideoEncoder::flush): (WebCore::WebCodecsVideoEncoder::closeEncoder): (WebCore::WebCodecsVideoEncoder::resetEncoder): (WebCore::WebCodecsVideoEncoder::stop): (WebCore::WebCodecsVideoEncoder::scheduleDequeueEvent): Deleted. (WebCore::WebCodecsVideoEncoder::queueControlMessageAndProcess): Deleted. (WebCore::WebCodecsVideoEncoder::processControlMessageQueue): Deleted. (WebCore::WebCodecsVideoEncoder::virtualHasPendingActivity const): Deleted. * Source/WebCore/Modules/webcodecs/WebCodecsVideoEncoder.h: (WebCore::WebCodecsVideoEncoder::encodeQueueSize const): (WebCore::WebCodecsVideoEncoder::state const): Deleted. * Source/WebCore/Sources.txt: * Source/WebCore/WebCore.xcodeproj/project.pbxproj:
- Loading branch information