ladybird/Libraries/LibMedia/GenericTimeProvider.cpp
Zaggy1024 a06f87d728 LibMedia: Transmit seeks and resolve them through the pipeline
Seeking is now unified under one single method signature implemented by
all producers and transmitted through the pipeline by all sinks. By
doing it this way, we can simply instantaneously notify each node of
the pipeline that it needs to stop what it's doing and seek. For nodes
that are threaded (particularly the source providers), this causes them
to stop pushing data to their queue immediately, so that no stale data
makes it through to the output. Then, when new data does come through,
that is a clear indication that the seek has completed.

Note that track enablement is now through the pipeline as well, which
means that SuspendedStateHandler no longer has a way to suspend newly-
enabled tracks. Decoder suspension will need to be reworked to fit into
this new pipeline, sleeping/disposing and restarting entirely based on
the pull() timing in the producers.
2026-05-13 02:05:35 -05:00

44 lines
985 B
C++

/*
* Copyright (c) 2025, Gregory Bertilson <gregory@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "GenericTimeProvider.h"
namespace Media {
GenericTimeProvider::GenericTimeProvider() = default;
GenericTimeProvider::~GenericTimeProvider() = default;
AK::Duration GenericTimeProvider::current_time() const
{
auto time = m_media_time;
if (m_monotonic_time_on_resume.has_value())
time += MonotonicTime::now() - m_monotonic_time_on_resume.value();
return time;
}
void GenericTimeProvider::resume()
{
m_monotonic_time_on_resume.emplace(MonotonicTime::now());
}
void GenericTimeProvider::pause()
{
if (!m_monotonic_time_on_resume.has_value())
return;
m_media_time = current_time();
m_monotonic_time_on_resume = {};
}
void GenericTimeProvider::seek(AK::Duration time)
{
if (m_monotonic_time_on_resume.has_value())
m_monotonic_time_on_resume.emplace(MonotonicTime::now());
m_media_time = time;
}
}