Files
ladybird/Libraries/LibMedia/PlaybackStates/ResumingStateHandler.cpp
Zaggy1024 f9081fbde6 LibMedia: Dispose future media data and flush decoders when idle
In order to free up memory when a video is paused for an extended
period, we add a new Suspended state to PlaybackManager which tells the
data providers to suspend. The data providers will handle this signal
by disposing of their entire decoded data queue and flushing their
decoder.

When initially creating a PlaybackManager, and when resuming to a
paused state, the delay before suspension will be much lower than when
pausing from any other state. This is intended to prevent media
elements from consuming memory for long when decoding the first frame
for display, as well as to allow the data providers to suspend much
more quickly after a seek while paused.

Currently, resuming playback doesn't display much of a delay on my
MacBook, though that may change once we completely tear down the
decoder in the suspended state. It may also be exacerbated by using
hardware decoders due more complex decoder initialization.
2026-01-26 15:49:07 -06:00

24 lines
569 B
C++

/*
* Copyright (c) 2025-2026, Gregory Bertilson <gregory@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "ResumingStateHandler.h"
#include <LibMedia/PlaybackManager.h>
#include <LibMedia/PlaybackStates/PausedStateHandler.h>
#include <LibMedia/PlaybackStates/PlayingStateHandler.h>
namespace Media {
void ResumingStateHandler::resume()
{
if (m_playing)
manager().replace_state_handler<PlayingStateHandler>();
else
manager().replace_state_handler<PausedStateHandler>(PlaybackManager::RESUMING_SUSPEND_TIMEOUT_MS);
}
}