mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-02 04:27:12 +02:00
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.
47 lines
1007 B
C++
47 lines
1007 B
C++
/*
|
|
* Copyright (c) 2025, Gregory Bertilson <zaggy1024@gmail.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Time.h>
|
|
#include <LibMedia/Forward.h>
|
|
#include <LibMedia/PlaybackStates/PlaybackState.h>
|
|
#include <LibMedia/SeekMode.h>
|
|
|
|
namespace Media {
|
|
|
|
class PlaybackStateHandler {
|
|
public:
|
|
PlaybackStateHandler(PlaybackManager& manager)
|
|
: m_manager(manager)
|
|
{
|
|
}
|
|
virtual ~PlaybackStateHandler() = default;
|
|
|
|
virtual void on_enter() = 0;
|
|
virtual void on_exit() = 0;
|
|
|
|
virtual void play() = 0;
|
|
virtual void pause() = 0;
|
|
virtual void seek(AK::Duration timestamp, SeekMode);
|
|
|
|
virtual bool is_playing() = 0;
|
|
virtual PlaybackState state() = 0;
|
|
|
|
virtual void enter_buffering() { VERIFY_NOT_REACHED(); }
|
|
virtual void exit_buffering() { VERIFY_NOT_REACHED(); }
|
|
|
|
virtual void on_track_enabled(Track const&);
|
|
|
|
protected:
|
|
PlaybackManager& manager() const { return m_manager; }
|
|
|
|
private:
|
|
PlaybackManager& m_manager;
|
|
};
|
|
|
|
}
|