tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 690667d26164261df846b84bb2f9ec0be40074be
parent 2dfe18ccee54772d732e6a8eb5d9328ca7af827c
Author: Chun-Min Chang <chun.m.chang@gmail.com>
Date:   Sat, 25 Oct 2025 01:01:05 +0000

Bug 1995664 - Add a pref to wait for encoded results in WMF encoder r=media-playback-reviewers,azebrowski

This patch introduces a preference that forces the WMF encoder in realtime mode
to waitfor the encoded results before resolving the encode promise, instead of
resolving it upon receiving any system-encoder's response.

Note that there is a timer to ensure the encode promise is resolved within a
reasonable time. Hence, if no output is produced in time, the promise will be
resolved by the timer instead.

Differential Revision: https://phabricator.services.mozilla.com/D269528

Diffstat:
Mdom/media/platforms/wmf/MFTEncoder.cpp | 17++++++++++++-----
Mmodules/libpref/init/StaticPrefList.yaml | 5+++++
2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/dom/media/platforms/wmf/MFTEncoder.cpp b/dom/media/platforms/wmf/MFTEncoder.cpp @@ -1243,12 +1243,16 @@ void MFTEncoder::EventHandler(MediaEventType aEventType, HRESULT aStatus) { return; } + const bool waitForOutput = + StaticPrefs::media_wmf_encoder_realtime_wait_for_output(); + ProcessedResult result = processed.unwrap(); MFT_ENC_LOGV( "%s processed: %s\n\tpending inputs: %zu\n\tinput needed: %zu\n\tpending " - "outputs: %zu", + "outputs: %zu (waitForOutput=%s)", MediaEventTypeStr(aEventType), MFTEncoder::EnumValueToString(result), - mPendingInputs.size(), mNumNeedInput, mOutputs.Length()); + mPendingInputs.size(), mNumNeedInput, mOutputs.Length(), + waitForOutput ? "yes" : "no"); switch (result) { case ProcessedResult::AllAvailableInputsProcessed: // Since mNumNeedInput was incremented in ProcessEvent(), before calling @@ -1266,9 +1270,12 @@ void MFTEncoder::EventHandler(MediaEventType aEventType, HRESULT aStatus) { if (mState == State::Encoding) { // In realtime mode, we could resolve the encode promise only upon // receiving an output. However, since the performance gain is minor, - // it's not worth risking a scenario where the encode promise is - // resolved by the timer callback if no output is produced in time. - MaybeResolveOrRejectEncodePromise(); + // unless the wait-for-output setting is enabled, it's better to prevent + // the encode promise from being resolved by the timer callback if no + // output is produced in time. + if (!waitForOutput) { + MaybeResolveOrRejectEncodePromise(); + } } else if (mState == State::PreDraining) { if (mPendingInputs.empty()) { MaybeResolveOrRejectPreDrainPromise(); diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml @@ -11906,6 +11906,11 @@ value: true mirror: always +- name: media.wmf.encoder.realtime.wait-for-output + type: RelaxedAtomicBool + value: @IS_NIGHTLY_BUILD@ + mirror: always + # Using Windows Media Foundation Media Engine for encrypted playback # 0 : disable, 1 : enable for encrypted and clear, # 2 : enable for encrypted only, 3 : enable for clear only