1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 01:17:46 +00:00

AK: Rename Time to Duration

That's what this class really is; in fact that's what the first line of
the comment says it is.

This commit does not rename the main files, since those will contain
other time-related classes in a little bit.
This commit is contained in:
kleines Filmröllchen 2023-03-13 16:30:34 +01:00 committed by Jelle Raaijmakers
parent 82ddc813d5
commit 213025f210
140 changed files with 634 additions and 628 deletions

View file

@ -88,7 +88,7 @@ void ConnectionToServer::update_good_sleep_time()
auto sample_rate = static_cast<double>(get_sample_rate());
auto buffer_play_time_ns = 1'000'000'000.0 / (sample_rate / static_cast<double>(AUDIO_BUFFER_SIZE));
// A factor of 1 should be good for now.
m_good_sleep_time = Time::from_nanoseconds(static_cast<unsigned>(buffer_play_time_ns)).to_timespec();
m_good_sleep_time = Duration::from_nanoseconds(static_cast<unsigned>(buffer_play_time_ns)).to_timespec();
}
// Non-realtime audio writing loop

View file

@ -117,7 +117,7 @@ static struct tm* time_to_tm(struct tm* tm, time_t t, StringView time_zone)
return nullptr;
}
if (auto offset = TimeZone::get_time_zone_offset(time_zone, AK::Time::from_seconds(t)); offset.has_value()) {
if (auto offset = TimeZone::get_time_zone_offset(time_zone, AK::Duration::from_seconds(t)); offset.has_value()) {
tm->tm_isdst = offset->in_dst == TimeZone::InDST::Yes;
t += offset->seconds;
}
@ -171,12 +171,12 @@ static time_t tm_to_time(struct tm* tm, StringView time_zone)
auto timestamp = ((days_since_epoch * 24 + tm->tm_hour) * 60 + tm->tm_min) * 60 + tm->tm_sec;
if (tm->tm_isdst < 0) {
if (auto offset = TimeZone::get_time_zone_offset(time_zone, AK::Time::from_seconds(timestamp)); offset.has_value())
if (auto offset = TimeZone::get_time_zone_offset(time_zone, AK::Duration::from_seconds(timestamp)); offset.has_value())
timestamp -= offset->seconds;
} else {
auto index = tm->tm_isdst == 0 ? 0 : 1;
if (auto offsets = TimeZone::get_named_time_zone_offsets(time_zone, AK::Time::from_seconds(timestamp)); offsets.has_value())
if (auto offsets = TimeZone::get_named_time_zone_offsets(time_zone, AK::Duration::from_seconds(timestamp)); offsets.has_value())
timestamp -= offsets->at(index).seconds;
}
@ -407,7 +407,7 @@ void tzset()
tzname[1] = const_cast<char*>(__utc);
};
if (auto offsets = TimeZone::get_named_time_zone_offsets(__tzname, AK::Time::now_realtime()); offsets.has_value()) {
if (auto offsets = TimeZone::get_named_time_zone_offsets(__tzname, AK::Duration::now_realtime()); offsets.has_value()) {
if (!offsets->at(0).name.copy_characters_to_buffer(__tzname_standard, TZNAME_MAX))
return set_default_values();
if (!offsets->at(1).name.copy_characters_to_buffer(__tzname_daylight, TZNAME_MAX))

View file

@ -20,7 +20,7 @@ ElapsedTimer ElapsedTimer::start_new()
void ElapsedTimer::start()
{
m_valid = true;
m_origin_time = m_precise ? Time::now_monotonic() : Time::now_monotonic_coarse();
m_origin_time = m_precise ? Duration::now_monotonic() : Duration::now_monotonic_coarse();
}
void ElapsedTimer::reset()
@ -34,10 +34,10 @@ i64 ElapsedTimer::elapsed_milliseconds() const
return elapsed_time().to_milliseconds();
}
Time ElapsedTimer::elapsed_time() const
Duration ElapsedTimer::elapsed_time() const
{
VERIFY(is_valid());
auto now = m_precise ? Time::now_monotonic() : Time::now_monotonic_coarse();
auto now = m_precise ? Duration::now_monotonic() : Duration::now_monotonic_coarse();
return now - m_origin_time;
}

View file

@ -24,7 +24,7 @@ public:
void reset();
i64 elapsed_milliseconds() const;
Time elapsed_time() const;
Duration elapsed_time() const;
// FIXME: Move callers to elapsed_milliseconds(), remove this.
i64 elapsed() const // milliseconds
@ -32,10 +32,10 @@ public:
return elapsed_milliseconds();
}
Time const& origin_time() const { return m_origin_time; }
Duration const& origin_time() const { return m_origin_time; }
private:
Time m_origin_time {};
Duration m_origin_time {};
bool m_precise { false };
bool m_valid { false };
};

View file

@ -29,14 +29,14 @@ thread_local ThreadData* s_thread_data;
struct EventLoopTimer {
int timer_id { 0 };
Time interval;
Time fire_time;
Duration interval;
Duration fire_time;
bool should_reload { false };
TimerShouldFireWhenNotVisible fire_when_not_visible { TimerShouldFireWhenNotVisible::No };
WeakPtr<Object> owner;
void reload(Time const& now) { fire_time = now + interval; }
bool has_expired(Time const& now) const { return now > fire_time; }
void reload(Duration const& now) { fire_time = now + interval; }
bool has_expired(Duration const& now) const { return now > fire_time; }
};
struct ThreadData {
@ -171,16 +171,16 @@ retry:
// Figure out how long to wait at maximum.
// This mainly depends on the PumpMode and whether we have pending events, but also the next expiring timer.
Time now;
Duration now;
struct timeval timeout = { 0, 0 };
bool should_wait_forever = false;
if (mode == EventLoopImplementation::PumpMode::WaitForEvents && !has_pending_events) {
auto next_timer_expiration = get_next_timer_expiration();
if (next_timer_expiration.has_value()) {
now = Time::now_monotonic_coarse();
now = Duration::now_monotonic_coarse();
auto computed_timeout = next_timer_expiration.value() - now;
if (computed_timeout.is_negative())
computed_timeout = Time::zero();
computed_timeout = Duration::zero();
timeout = computed_timeout.to_timeval();
} else {
should_wait_forever = true;
@ -231,7 +231,7 @@ try_select_again:
}
if (!thread_data.timers.is_empty()) {
now = Time::now_monotonic_coarse();
now = Duration::now_monotonic_coarse();
}
// Handle expired timers.
@ -349,10 +349,10 @@ void EventLoopImplementationUnix::notify_forked_and_in_child()
thread_data.pid = getpid();
}
Optional<Time> EventLoopManagerUnix::get_next_timer_expiration()
Optional<Duration> EventLoopManagerUnix::get_next_timer_expiration()
{
auto now = Time::now_monotonic_coarse();
Optional<Time> soonest {};
auto now = Duration::now_monotonic_coarse();
Optional<Duration> soonest {};
for (auto& it : ThreadData::the().timers) {
auto& fire_time = it.value->fire_time;
auto owner = it.value->owner.strong_ref();
@ -489,8 +489,8 @@ int EventLoopManagerUnix::register_timer(Object& object, int milliseconds, bool
auto& thread_data = ThreadData::the();
auto timer = make<EventLoopTimer>();
timer->owner = object;
timer->interval = Time::from_milliseconds(milliseconds);
timer->reload(Time::now_monotonic_coarse());
timer->interval = Duration::from_milliseconds(milliseconds);
timer->reload(Duration::now_monotonic_coarse());
timer->should_reload = should_reload;
timer->fire_when_not_visible = fire_when_not_visible;
int timer_id = thread_data.id_allocator.allocate();

View file

@ -28,7 +28,7 @@ public:
virtual void unregister_signal(int handler_id) override;
void wait_for_events(EventLoopImplementation::PumpMode);
static Optional<Time> get_next_timer_expiration();
static Optional<Duration> get_next_timer_expiration();
private:
void dispatch_signal(int signal_number);

View file

@ -18,10 +18,13 @@
static_assert(false, "This file must only be used for macOS");
#endif
#define FixedPoint FixedPointMacOS // AK::FixedPoint conflicts with FixedPoint from MacTypes.h.
// Several AK types conflict with MacOS types.
#define FixedPoint FixedPointMacOS
#define Duration DurationMacOS
#include <CoreServices/CoreServices.h>
#include <dispatch/dispatch.h>
#undef FixedPoint
#undef Duration
namespace Core {

View file

@ -177,7 +177,7 @@ ErrorOr<void> PosixSocketHelper::set_close_on_exec(bool enabled)
return {};
}
ErrorOr<void> PosixSocketHelper::set_receive_timeout(Time timeout)
ErrorOr<void> PosixSocketHelper::set_receive_timeout(Duration timeout)
{
auto timeout_spec = timeout.to_timespec();
return System::setsockopt(m_fd, SOL_SOCKET, SO_RCVTIMEO, &timeout_spec, sizeof(timeout_spec));
@ -231,13 +231,13 @@ ErrorOr<size_t> PosixSocketHelper::pending_bytes() const
return static_cast<size_t>(value);
}
ErrorOr<NonnullOwnPtr<UDPSocket>> UDPSocket::connect(DeprecatedString const& host, u16 port, Optional<Time> timeout)
ErrorOr<NonnullOwnPtr<UDPSocket>> UDPSocket::connect(DeprecatedString const& host, u16 port, Optional<Duration> timeout)
{
auto ip_address = TRY(resolve_host(host, SocketType::Datagram));
return connect(SocketAddress { ip_address, port }, timeout);
}
ErrorOr<NonnullOwnPtr<UDPSocket>> UDPSocket::connect(SocketAddress const& address, Optional<Time> timeout)
ErrorOr<NonnullOwnPtr<UDPSocket>> UDPSocket::connect(SocketAddress const& address, Optional<Duration> timeout)
{
auto socket = TRY(adopt_nonnull_own_or_enomem(new (nothrow) UDPSocket()));

View file

@ -141,7 +141,7 @@ public:
ErrorOr<void> set_blocking(bool enabled);
ErrorOr<void> set_close_on_exec(bool enabled);
ErrorOr<void> set_receive_timeout(Time timeout);
ErrorOr<void> set_receive_timeout(Duration timeout);
void setup_notifier();
RefPtr<Core::Notifier> notifier() { return m_notifier; }
@ -215,8 +215,8 @@ private:
class UDPSocket final : public Socket {
public:
static ErrorOr<NonnullOwnPtr<UDPSocket>> connect(DeprecatedString const& host, u16 port, Optional<Time> timeout = {});
static ErrorOr<NonnullOwnPtr<UDPSocket>> connect(SocketAddress const& address, Optional<Time> timeout = {});
static ErrorOr<NonnullOwnPtr<UDPSocket>> connect(DeprecatedString const& host, u16 port, Optional<Duration> timeout = {});
static ErrorOr<NonnullOwnPtr<UDPSocket>> connect(SocketAddress const& address, Optional<Duration> timeout = {});
UDPSocket(UDPSocket&& other)
: Socket(static_cast<Socket&&>(other))

View file

@ -40,7 +40,7 @@ void Screensaver::mousedown_event(GUI::MouseEvent&)
void Screensaver::mousemove_event(GUI::MouseEvent& event)
{
auto now = AK::Time::now_monotonic();
auto now = AK::Duration::now_monotonic();
if ((now - m_start_time).to_milliseconds() < mouse_tracking_delay_milliseconds)
return;

View file

@ -30,7 +30,7 @@ public:
protected:
Screensaver()
: m_start_time(AK::Time::now_monotonic())
: m_start_time(AK::Duration::now_monotonic())
{
}
@ -38,7 +38,7 @@ private:
void trigger_exit();
Optional<Gfx::IntPoint> m_mouse_origin;
AK::Time m_start_time;
AK::Duration m_start_time;
};
}

View file

@ -63,12 +63,12 @@ ErrorOr<Dialog::ExecResult> MessageBox::try_show_error(Window* parent_window, St
return TRY(try_show(parent_window, text, "Error"sv, GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK));
}
Dialog::ExecResult MessageBox::ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<Time> last_unmodified_timestamp)
Dialog::ExecResult MessageBox::ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<Duration> last_unmodified_timestamp)
{
return MUST(try_ask_about_unsaved_changes(parent_window, path, last_unmodified_timestamp));
}
ErrorOr<Dialog::ExecResult> MessageBox::try_ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<Time> last_unmodified_timestamp)
ErrorOr<Dialog::ExecResult> MessageBox::try_ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<Duration> last_unmodified_timestamp)
{
StringBuilder builder;
TRY(builder.try_append("Save changes to "sv));
@ -79,7 +79,7 @@ ErrorOr<Dialog::ExecResult> MessageBox::try_ask_about_unsaved_changes(Window* pa
TRY(builder.try_append(" before closing?"sv));
if (!path.is_empty() && last_unmodified_timestamp.has_value()) {
auto age = (Time::now_monotonic() - *last_unmodified_timestamp).to_seconds();
auto age = (Duration::now_monotonic() - *last_unmodified_timestamp).to_seconds();
auto readable_time = human_readable_time(age);
TRY(builder.try_appendff("\nLast saved {} ago.", readable_time));
}

View file

@ -40,12 +40,12 @@ public:
static ExecResult show(Window* parent_window, StringView text, StringView title, Type type = Type::None, InputType input_type = InputType::OK);
static ExecResult show_error(Window* parent_window, StringView text);
static ExecResult ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<Time> last_unmodified_timestamp = {});
static ExecResult ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<Duration> last_unmodified_timestamp = {});
static ErrorOr<ExecResult> try_show(Badge<FileSystemAccessServer::ConnectionFromClient>, i32 window_server_client_id, i32 parent_window_id, StringView text, StringView title);
static ErrorOr<ExecResult> try_show(Window* parent_window, StringView text, StringView title, Type type = Type::None, InputType input_type = InputType::OK);
static ErrorOr<ExecResult> try_show_error(Window* parent_window, StringView text);
static ErrorOr<ExecResult> try_ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<Time> last_unmodified_timestamp = {});
static ErrorOr<ExecResult> try_ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<Duration> last_unmodified_timestamp = {});
static ErrorOr<NonnullRefPtr<MessageBox>> create(Window* parent_window, StringView text, StringView title, Type type = Type::None, InputType input_type = InputType::OK);

View file

@ -894,7 +894,7 @@ bool InsertTextCommand::merge_with(GUI::Command const& other)
m_text = builder.to_deprecated_string();
m_range.set_end(typed_other.m_range.end());
m_timestamp = Time::now_monotonic();
m_timestamp = Duration::now_monotonic();
return true;
}
@ -994,7 +994,7 @@ bool RemoveTextCommand::merge_with(GUI::Command const& other)
m_text = builder.to_deprecated_string();
m_range.set_start(typed_other.m_range.start());
m_timestamp = Time::now_monotonic();
m_timestamp = Duration::now_monotonic();
return true;
}

View file

@ -26,7 +26,7 @@
namespace GUI {
constexpr Time COMMAND_COMMIT_TIME = Time::from_milliseconds(400);
constexpr Duration COMMAND_COMMIT_TIME = Duration::from_milliseconds(400);
struct TextDocumentSpan {
TextRange range;
@ -228,9 +228,9 @@ public:
}
protected:
bool commit_time_expired() const { return Time::now_monotonic() - m_timestamp >= COMMAND_COMMIT_TIME; }
bool commit_time_expired() const { return Duration::now_monotonic() - m_timestamp >= COMMAND_COMMIT_TIME; }
Time m_timestamp = Time::now_monotonic();
Duration m_timestamp = Duration::now_monotonic();
TextDocument& m_document;
TextDocument::Client const* m_client { nullptr };
};

View file

@ -81,7 +81,7 @@ void UndoStack::set_current_unmodified()
return;
m_clean_index = m_stack_index;
m_last_unmodified_timestamp = Time::now_monotonic();
m_last_unmodified_timestamp = Duration::now_monotonic();
if (on_state_change)
on_state_change();

View file

@ -31,7 +31,7 @@ public:
void set_current_unmodified();
bool is_current_modified() const;
Optional<Time> last_unmodified_timestamp() const { return m_last_unmodified_timestamp; }
Optional<Duration> last_unmodified_timestamp() const { return m_last_unmodified_timestamp; }
void clear();
@ -44,7 +44,7 @@ private:
Vector<NonnullOwnPtr<Command>> m_stack;
size_t m_stack_index { 0 };
Optional<size_t> m_clean_index;
Optional<Time> m_last_unmodified_timestamp;
Optional<Duration> m_last_unmodified_timestamp;
};
}

View file

@ -70,10 +70,10 @@ ErrorOr<JsonValue> decode(Decoder& decoder)
}
template<>
ErrorOr<Time> decode(Decoder& decoder)
ErrorOr<Duration> decode(Decoder& decoder)
{
auto nanoseconds = TRY(decoder.decode<i64>());
return AK::Time::from_nanoseconds(nanoseconds);
return AK::Duration::from_nanoseconds(nanoseconds);
}
template<>

View file

@ -94,7 +94,7 @@ template<>
ErrorOr<JsonValue> decode(Decoder&);
template<>
ErrorOr<Time> decode(Decoder&);
ErrorOr<Duration> decode(Decoder&);
template<>
ErrorOr<URL> decode(Decoder&);

View file

@ -85,7 +85,7 @@ ErrorOr<void> encode(Encoder& encoder, JsonValue const& value)
}
template<>
ErrorOr<void> encode(Encoder& encoder, Time const& value)
ErrorOr<void> encode(Encoder& encoder, Duration const& value)
{
return encoder.encode(value.to_nanoseconds());
}

View file

@ -123,7 +123,7 @@ template<>
ErrorOr<void> encode(Encoder&, JsonValue const&);
template<>
ErrorOr<void> encode(Encoder&, Time const&);
ErrorOr<void> encode(Encoder&, Duration const&);
template<>
ErrorOr<void> encode(Encoder&, URL const&);

View file

@ -38,7 +38,7 @@ public:
protected:
Core::ElapsedTimer m_timer;
Time m_time_difference {};
Duration m_time_difference {};
};
class PassManager : public Pass {

View file

@ -33,7 +33,7 @@ JS::ThrowCompletionOr<void> AgentObject::initialize(JS::Realm& realm)
JS_DEFINE_NATIVE_FUNCTION(AgentObject::monotonic_now)
{
auto time = Time::now_monotonic();
auto time = Duration::now_monotonic();
auto milliseconds = time.to_milliseconds();
return Value(static_cast<double>(milliseconds));
}

View file

@ -323,7 +323,7 @@ void Heap::sweep_dead_cells(bool print_report, Core::ElapsedTimer const& measure
}
if (print_report) {
Time const time_spent = measurement_timer.elapsed_time();
Duration const time_spent = measurement_timer.elapsed_time();
size_t live_block_count = 0;
for_each_block([&](auto&) {
++live_block_count;

View file

@ -298,7 +298,7 @@ static i64 clip_bigint_to_sane_time(Crypto::SignedBigInteger const& value)
static Crypto::SignedBigInteger const min_bigint { NumericLimits<i64>::min() };
static Crypto::SignedBigInteger const max_bigint { NumericLimits<i64>::max() };
// The provided epoch (nano)seconds value is potentially out of range for AK::Time and subsequently
// The provided epoch (nano)seconds value is potentially out of range for AK::Duration and subsequently
// get_time_zone_offset(). We can safely assume that the TZDB has no useful information that far
// into the past and future anyway, so clamp it to the i64 range.
if (value < min_bigint)
@ -314,7 +314,7 @@ static i64 clip_bigint_to_sane_time(Crypto::SignedBigInteger const& value)
Vector<Crypto::SignedBigInteger> get_named_time_zone_epoch_nanoseconds(StringView time_zone_identifier, i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond)
{
auto local_nanoseconds = get_utc_epoch_nanoseconds(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond);
auto local_time = Time::from_nanoseconds(clip_bigint_to_sane_time(local_nanoseconds));
auto local_time = Duration::from_nanoseconds(clip_bigint_to_sane_time(local_nanoseconds));
// FIXME: LibTimeZone does not behave exactly as the spec expects. It does not consider repeated or skipped time points.
auto offset = TimeZone::get_time_zone_offset(time_zone_identifier, local_time);
@ -332,10 +332,10 @@ i64 get_named_time_zone_offset_nanoseconds(StringView time_zone_identifier, Cryp
auto time_zone = TimeZone::time_zone_from_string(time_zone_identifier);
VERIFY(time_zone.has_value());
// Since Time::from_seconds() and Time::from_nanoseconds() both take an i64, converting to
// Since Duration::from_seconds() and Duration::from_nanoseconds() both take an i64, converting to
// seconds first gives us a greater range. The TZDB doesn't have sub-second offsets.
auto seconds = epoch_nanoseconds.divided_by(s_one_billion_bigint).quotient;
auto time = Time::from_seconds(clip_bigint_to_sane_time(seconds));
auto time = Duration::from_seconds(clip_bigint_to_sane_time(seconds));
auto offset = TimeZone::get_time_zone_offset(*time_zone, time);
VERIFY(offset.has_value());

View file

@ -131,7 +131,7 @@ static double parse_simplified_iso8601(DeprecatedString const& iso_8601)
// We parsed a valid date simplified ISO 8601 string.
VERIFY(year.has_value()); // A valid date string always has at least a year.
auto time = AK::Time::from_timestamp(*year, month.value_or(1), day.value_or(1), hours.value_or(0), minutes.value_or(0), seconds.value_or(0), milliseconds.value_or(0));
auto time = AK::Duration::from_timestamp(*year, month.value_or(1), day.value_or(1), hours.value_or(0), minutes.value_or(0), seconds.value_or(0), milliseconds.value_or(0));
auto time_ms = static_cast<double>(time.to_milliseconds());
// https://tc39.es/ecma262/#sec-date.parse:
@ -208,7 +208,7 @@ ThrowCompletionOr<Value> DateConstructor::call()
{
// 1. If NewTarget is undefined, then
// a. Let now be the time value (UTC) identifying the current time.
auto now = AK::Time::now_realtime().to_milliseconds();
auto now = AK::Duration::now_realtime().to_milliseconds();
// b. Return ToDateString(now).
return PrimitiveString::create(vm(), to_date_string(now));
@ -225,7 +225,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> DateConstructor::construct(FunctionObjec
// 3. If numberOfArgs = 0, then
if (vm.argument_count() == 0) {
// a. Let dv be the time value (UTC) identifying the current time.
auto now = AK::Time::now_realtime().to_milliseconds();
auto now = AK::Duration::now_realtime().to_milliseconds();
date_value = static_cast<double>(now);
}
// 4. Else if numberOfArgs = 1, then

View file

@ -1164,7 +1164,7 @@ DeprecatedString time_zone_string(double time)
auto tz_name = TimeZone::current_time_zone();
// Most implementations seem to prefer the long-form display name of the time zone. Not super important, but we may as well match that behavior.
if (auto maybe_offset = TimeZone::get_time_zone_offset(tz_name, AK::Time::from_milliseconds(time)); maybe_offset.has_value()) {
if (auto maybe_offset = TimeZone::get_time_zone_offset(tz_name, AK::Duration::from_milliseconds(time)); maybe_offset.has_value()) {
if (auto long_name = Locale::get_time_zone_name(Locale::default_locale(), tz_name, Locale::CalendarPatternStyle::Long, maybe_offset->in_dst); long_name.has_value())
tz_name = long_name.release_value();
}

View file

@ -162,9 +162,9 @@ enum class OptionDefaults {
// Table 8: Record returned by ToLocalTime, https://tc39.es/ecma402/#table-datetimeformat-tolocaltime-record
// Note: [[InDST]] is not included here - it is handled by LibUnicode / LibTimeZone.
struct LocalTime {
AK::Time time_since_epoch() const
AK::Duration time_since_epoch() const
{
return AK::Time::from_timestamp(year, month + 1, day + 1, hour, minute, second, millisecond);
return AK::Duration::from_timestamp(year, month + 1, day + 1, hour, minute, second, millisecond);
}
int weekday { 0 }; // [[Weekday]]

View file

@ -165,11 +165,11 @@ TimeZone* system_time_zone(VM& vm)
BigInt* system_utc_epoch_nanoseconds(VM& vm)
{
// 1. Let ns be the approximate current UTC date and time, in nanoseconds since the epoch.
auto now = Time::now_realtime().to_nanoseconds();
auto now = AK::Duration::now_realtime().to_nanoseconds();
auto ns = Crypto::SignedBigInteger { now };
// 2. Set ns to the result of clamping ns between nsMinInstant and nsMaxInstant.
// NOTE: Time::to_nanoseconds() already clamps between -(2^63) and 2^63 - 1, the range of an i64,
// NOTE: Duration::to_nanoseconds() already clamps between -(2^63) and 2^63 - 1, the range of an i64,
// if an overflow occurs during seconds -> nanoseconds conversion.
// 3. Return (ns).

View file

@ -301,7 +301,7 @@ static ErrorOr<Optional<String>> format_time_zone_offset(StringView locale, Cale
}
// https://unicode.org/reports/tr35/tr35-dates.html#Time_Zone_Format_Terminology
ErrorOr<String> format_time_zone(StringView locale, StringView time_zone, CalendarPatternStyle style, AK::Time time)
ErrorOr<String> format_time_zone(StringView locale, StringView time_zone, CalendarPatternStyle style, AK::Duration time)
{
auto offset = TimeZone::get_time_zone_offset(time_zone, time);
if (!offset.has_value())

View file

@ -226,7 +226,7 @@ ErrorOr<Optional<StringView>> get_calendar_weekday_symbol(StringView locale, Str
ErrorOr<Optional<StringView>> get_calendar_day_period_symbol(StringView locale, StringView calendar, CalendarPatternStyle style, DayPeriod value);
ErrorOr<Optional<StringView>> get_calendar_day_period_symbol_for_hour(StringView locale, StringView calendar, CalendarPatternStyle style, u8 hour);
ErrorOr<String> format_time_zone(StringView locale, StringView time_zone, CalendarPatternStyle style, AK::Time time);
ErrorOr<String> format_time_zone(StringView locale, StringView time_zone, CalendarPatternStyle style, AK::Duration time);
Optional<StringView> get_time_zone_name(StringView locale, StringView time_zone, CalendarPatternStyle style, TimeZone::InDST in_dst);
Optional<TimeZoneFormat> get_time_zone_format(StringView locale);

View file

@ -186,7 +186,7 @@ Optional<StringView> canonicalize_time_zone(StringView time_zone)
Optional<DaylightSavingsRule> __attribute__((weak)) daylight_savings_rule_from_string(StringView) { return {}; }
StringView __attribute__((weak)) daylight_savings_rule_to_string(DaylightSavingsRule) { return {}; }
Optional<Offset> __attribute__((weak)) get_time_zone_offset([[maybe_unused]] TimeZone time_zone, AK::Time)
Optional<Offset> __attribute__((weak)) get_time_zone_offset([[maybe_unused]] TimeZone time_zone, AK::Duration)
{
#if !ENABLE_TIME_ZONE_DATA
VERIFY(time_zone == TimeZone::UTC);
@ -196,14 +196,14 @@ Optional<Offset> __attribute__((weak)) get_time_zone_offset([[maybe_unused]] Tim
#endif
}
Optional<Offset> get_time_zone_offset(StringView time_zone, AK::Time time)
Optional<Offset> get_time_zone_offset(StringView time_zone, AK::Duration time)
{
if (auto maybe_time_zone = time_zone_from_string(time_zone); maybe_time_zone.has_value())
return get_time_zone_offset(*maybe_time_zone, time);
return {};
}
Optional<Array<NamedOffset, 2>> __attribute__((weak)) get_named_time_zone_offsets([[maybe_unused]] TimeZone time_zone, AK::Time)
Optional<Array<NamedOffset, 2>> __attribute__((weak)) get_named_time_zone_offsets([[maybe_unused]] TimeZone time_zone, AK::Duration)
{
#if !ENABLE_TIME_ZONE_DATA
VERIFY(time_zone == TimeZone::UTC);
@ -217,7 +217,7 @@ Optional<Array<NamedOffset, 2>> __attribute__((weak)) get_named_time_zone_offset
#endif
}
Optional<Array<NamedOffset, 2>> get_named_time_zone_offsets(StringView time_zone, AK::Time time)
Optional<Array<NamedOffset, 2>> get_named_time_zone_offsets(StringView time_zone, AK::Duration time)
{
if (auto maybe_time_zone = time_zone_from_string(time_zone); maybe_time_zone.has_value())
return get_named_time_zone_offsets(*maybe_time_zone, time);

View file

@ -61,11 +61,11 @@ Optional<StringView> canonicalize_time_zone(StringView time_zone);
Optional<DaylightSavingsRule> daylight_savings_rule_from_string(StringView daylight_savings_rule);
StringView daylight_savings_rule_to_string(DaylightSavingsRule daylight_savings_rule);
Optional<Offset> get_time_zone_offset(TimeZone time_zone, AK::Time time);
Optional<Offset> get_time_zone_offset(StringView time_zone, AK::Time time);
Optional<Offset> get_time_zone_offset(TimeZone time_zone, AK::Duration time);
Optional<Offset> get_time_zone_offset(StringView time_zone, AK::Duration time);
Optional<Array<NamedOffset, 2>> get_named_time_zone_offsets(TimeZone time_zone, AK::Time time);
Optional<Array<NamedOffset, 2>> get_named_time_zone_offsets(StringView time_zone, AK::Time time);
Optional<Array<NamedOffset, 2>> get_named_time_zone_offsets(TimeZone time_zone, AK::Duration time);
Optional<Array<NamedOffset, 2>> get_named_time_zone_offsets(StringView time_zone, AK::Duration time);
Optional<Location> get_time_zone_location(TimeZone time_zone);
Optional<Location> get_time_zone_location(StringView time_zone);

View file

@ -31,9 +31,9 @@ public:
// Returns the timestamp of the keyframe that was seeked to.
// The value is `Optional` to allow the demuxer to decide not to seek so that it can keep its position
// in the case that the timestamp is closer to the current time than the nearest keyframe.
virtual DecoderErrorOr<Optional<Time>> seek_to_most_recent_keyframe(Track track, Time timestamp, Optional<Time> earliest_available_sample = OptionalNone()) = 0;
virtual DecoderErrorOr<Optional<Duration>> seek_to_most_recent_keyframe(Track track, Duration timestamp, Optional<Duration> earliest_available_sample = OptionalNone()) = 0;
virtual DecoderErrorOr<Time> duration() = 0;
virtual DecoderErrorOr<Duration> duration() = 0;
protected:
virtual DecoderErrorOr<NonnullOwnPtr<Sample>> get_next_sample_for_track(Track track) = 0;

View file

@ -32,11 +32,11 @@ public:
void set_writing_app(DeprecatedString writing_app) { m_writing_app = move(writing_app); }
Optional<double> duration_unscaled() const { return m_duration_unscaled; }
void set_duration_unscaled(double duration) { m_duration_unscaled.emplace(duration); }
Optional<Time> duration() const
Optional<Duration> duration() const
{
if (!duration_unscaled().has_value())
return {};
return Time::from_nanoseconds(static_cast<i64>(static_cast<double>(timestamp_scale()) * duration_unscaled().value()));
return Duration::from_nanoseconds(static_cast<i64>(static_cast<double>(timestamp_scale()) * duration_unscaled().value()));
}
private:
@ -167,8 +167,8 @@ public:
u64 track_number() const { return m_track_number; }
void set_track_number(u64 track_number) { m_track_number = track_number; }
Time timestamp() const { return m_timestamp; }
void set_timestamp(Time timestamp) { m_timestamp = timestamp; }
Duration timestamp() const { return m_timestamp; }
void set_timestamp(Duration timestamp) { m_timestamp = timestamp; }
bool only_keyframes() const { return m_only_keyframes; }
void set_only_keyframes(bool only_keyframes) { m_only_keyframes = only_keyframes; }
bool invisible() const { return m_invisible; }
@ -185,7 +185,7 @@ public:
private:
u64 m_track_number { 0 };
Time m_timestamp { Time::zero() };
Duration m_timestamp { Duration::zero() };
bool m_only_keyframes { false };
bool m_invisible { false };
Lacing m_lacing { None };
@ -195,11 +195,11 @@ private:
class Cluster {
public:
Time timestamp() const { return m_timestamp; }
void set_timestamp(Time timestamp) { m_timestamp = timestamp; }
Duration timestamp() const { return m_timestamp; }
void set_timestamp(Duration timestamp) { m_timestamp = timestamp; }
private:
Time m_timestamp { Time::zero() };
Duration m_timestamp { Duration::zero() };
};
class CueTrackPosition {
@ -219,14 +219,14 @@ private:
class CuePoint {
public:
Time timestamp() const { return m_timestamp; }
void set_timestamp(Time timestamp) { m_timestamp = timestamp; }
Duration timestamp() const { return m_timestamp; }
void set_timestamp(Duration timestamp) { m_timestamp = timestamp; }
OrderedHashMap<u64, CueTrackPosition>& track_positions() { return m_track_positions; }
OrderedHashMap<u64, CueTrackPosition> const& track_positions() const { return m_track_positions; }
Optional<CueTrackPosition const&> position_for_track(u64 track_number) const { return m_track_positions.get(track_number); }
private:
Time m_timestamp = Time::min();
Duration m_timestamp = Duration::min();
OrderedHashMap<u64, CueTrackPosition> m_track_positions;
};

View file

@ -71,7 +71,7 @@ DecoderErrorOr<MatroskaDemuxer::TrackStatus*> MatroskaDemuxer::get_track_status(
return &m_track_statuses.get(track).release_value();
}
DecoderErrorOr<Optional<Time>> MatroskaDemuxer::seek_to_most_recent_keyframe(Track track, Time timestamp, Optional<Time> earliest_available_sample)
DecoderErrorOr<Optional<Duration>> MatroskaDemuxer::seek_to_most_recent_keyframe(Track track, Duration timestamp, Optional<Duration> earliest_available_sample)
{
// Removing the track status will cause us to start from the beginning.
if (timestamp.is_zero()) {
@ -113,10 +113,10 @@ DecoderErrorOr<NonnullOwnPtr<Sample>> MatroskaDemuxer::get_next_sample_for_track
return make<VideoSample>(status.block->frame(status.frame_index++), cicp, status.block->timestamp());
}
DecoderErrorOr<Time> MatroskaDemuxer::duration()
DecoderErrorOr<Duration> MatroskaDemuxer::duration()
{
auto duration = TRY(m_reader.segment_information()).duration();
return duration.value_or(Time::zero());
return duration.value_or(Duration::zero());
}
}

View file

@ -29,9 +29,9 @@ public:
DecoderErrorOr<Vector<Track>> get_tracks_for_type(TrackType type) override;
DecoderErrorOr<Optional<Time>> seek_to_most_recent_keyframe(Track track, Time timestamp, Optional<Time> earliest_available_sample = OptionalNone()) override;
DecoderErrorOr<Optional<Duration>> seek_to_most_recent_keyframe(Track track, Duration timestamp, Optional<Duration> earliest_available_sample = OptionalNone()) override;
DecoderErrorOr<Time> duration() override;
DecoderErrorOr<Duration> duration() override;
protected:
DecoderErrorOr<NonnullOwnPtr<Sample>> get_next_sample_for_track(Track track) override;

View file

@ -543,11 +543,11 @@ static DecoderErrorOr<Cluster> parse_cluster(Streamer& streamer, u64 timestamp_s
TRY_READ(streamer.seek_to_position(first_element_position));
Cluster cluster;
cluster.set_timestamp(Time::from_nanoseconds(timestamp.release_value() * timestamp_scale));
cluster.set_timestamp(Duration::from_nanoseconds(timestamp.release_value() * timestamp_scale));
return cluster;
}
static DecoderErrorOr<Block> parse_simple_block(Streamer& streamer, Time cluster_timestamp, u64 segment_timestamp_scale, TrackEntry track)
static DecoderErrorOr<Block> parse_simple_block(Streamer& streamer, Duration cluster_timestamp, u64 segment_timestamp_scale, TrackEntry track)
{
Block block;
@ -567,11 +567,11 @@ static DecoderErrorOr<Block> parse_simple_block(Streamer& streamer, Time cluster
// of that track. To get the timestamp in nanoseconds of the first frame in a Block or
// SimpleBlock, the formula becomes:
// `( ( Cluster\Timestamp + ( block timestamp * TrackTimestampScale ) ) * TimestampScale ) - CodecDelay`
Time timestamp_offset = Time::from_nanoseconds(static_cast<i64>(static_cast<double>(TRY_READ(streamer.read_i16()) * segment_timestamp_scale) * track.timestamp_scale()));
timestamp_offset -= Time::from_nanoseconds(static_cast<i64>(track.codec_delay()));
Duration timestamp_offset = Duration::from_nanoseconds(static_cast<i64>(static_cast<double>(TRY_READ(streamer.read_i16()) * segment_timestamp_scale) * track.timestamp_scale()));
timestamp_offset -= Duration::from_nanoseconds(static_cast<i64>(track.codec_delay()));
// This is only mentioned in the elements specification under TrackOffset.
// https://www.matroska.org/technical/elements.html
timestamp_offset += Time::from_nanoseconds(static_cast<i64>(track.timestamp_offset()));
timestamp_offset += Duration::from_nanoseconds(static_cast<i64>(track.timestamp_offset()));
block.set_timestamp(cluster_timestamp + timestamp_offset);
auto flags = TRY_READ(streamer.read_octet());
@ -704,7 +704,7 @@ static DecoderErrorOr<CuePoint> parse_cue_point(Streamer& streamer, u64 timestam
// https://github.com/mozilla/nestegg/tree/ec6adfbbf979678e3058cc4695257366f39e290b/src/nestegg.c#L2411-L2416
// https://github.com/mozilla/nestegg/tree/ec6adfbbf979678e3058cc4695257366f39e290b/src/nestegg.c#L1383-L1392
// Other fields that specify Matroska Ticks may also use Segment Ticks instead, who knows :^(
auto timestamp = Time::from_nanoseconds(static_cast<i64>(TRY_READ(streamer.read_u64()) * timestamp_scale));
auto timestamp = Duration::from_nanoseconds(static_cast<i64>(TRY_READ(streamer.read_u64()) * timestamp_scale));
cue_point.set_timestamp(timestamp);
dbgln_if(MATROSKA_DEBUG, "Read CuePoint timestamp {}ms", cue_point.timestamp().to_milliseconds());
break;
@ -775,7 +775,7 @@ DecoderErrorOr<void> Reader::ensure_cues_are_parsed()
return {};
}
DecoderErrorOr<void> Reader::seek_to_cue_for_timestamp(SampleIterator& iterator, Time const& timestamp)
DecoderErrorOr<void> Reader::seek_to_cue_for_timestamp(SampleIterator& iterator, Duration const& timestamp)
{
auto const& cue_points = MUST(cue_points_for_track(iterator.m_track.track_number())).release_value();
@ -814,7 +814,7 @@ DecoderErrorOr<void> Reader::seek_to_cue_for_timestamp(SampleIterator& iterator,
return {};
}
static DecoderErrorOr<void> search_clusters_for_keyframe_before_timestamp(SampleIterator& iterator, Time const& timestamp)
static DecoderErrorOr<void> search_clusters_for_keyframe_before_timestamp(SampleIterator& iterator, Duration const& timestamp)
{
#if MATROSKA_DEBUG
size_t inter_frames_count;
@ -856,7 +856,7 @@ DecoderErrorOr<bool> Reader::has_cues_for_track(u64 track_number)
return m_cues.contains(track_number);
}
DecoderErrorOr<SampleIterator> Reader::seek_to_random_access_point(SampleIterator iterator, Time timestamp)
DecoderErrorOr<SampleIterator> Reader::seek_to_random_access_point(SampleIterator iterator, Duration timestamp)
{
if (TRY(has_cues_for_track(iterator.m_track.track_number()))) {
TRY(seek_to_cue_for_timestamp(iterator, timestamp));

View file

@ -39,7 +39,7 @@ public:
DecoderErrorOr<size_t> track_count();
DecoderErrorOr<SampleIterator> create_sample_iterator(u64 track_number);
DecoderErrorOr<SampleIterator> seek_to_random_access_point(SampleIterator, Time);
DecoderErrorOr<SampleIterator> seek_to_random_access_point(SampleIterator, Duration);
DecoderErrorOr<Optional<Vector<CuePoint> const&>> cue_points_for_track(u64 track_number);
DecoderErrorOr<bool> has_cues_for_track(u64 track_number);
@ -58,7 +58,7 @@ private:
DecoderErrorOr<void> parse_cues(Streamer&);
DecoderErrorOr<void> ensure_cues_are_parsed();
DecoderErrorOr<void> seek_to_cue_for_timestamp(SampleIterator&, Time const&);
DecoderErrorOr<void> seek_to_cue_for_timestamp(SampleIterator&, Duration const&);
RefPtr<Core::MappedFile> m_mapped_file;
ReadonlyBytes m_data;
@ -84,7 +84,7 @@ class SampleIterator {
public:
DecoderErrorOr<Block> next_block();
Cluster const& current_cluster() { return *m_current_cluster; }
Optional<Time> const& last_timestamp() { return m_last_timestamp; }
Optional<Duration> const& last_timestamp() { return m_last_timestamp; }
private:
friend class Reader;
@ -108,7 +108,7 @@ private:
// Must always point to an element ID or the end of the stream.
size_t m_position { 0 };
Optional<Time> m_last_timestamp;
Optional<Duration> m_last_timestamp;
Optional<Cluster> m_current_cluster;
};

View file

@ -107,12 +107,12 @@ void PlaybackManager::pause_playback()
TRY_OR_FATAL_ERROR(m_playback_handler->pause());
}
Time PlaybackManager::current_playback_time()
Duration PlaybackManager::current_playback_time()
{
return m_playback_handler->current_time();
}
Time PlaybackManager::duration()
Duration PlaybackManager::duration()
{
auto duration_result = ({
auto demuxer_locker = Threading::MutexLocker(m_demuxer_mutex);
@ -179,12 +179,12 @@ void PlaybackManager::timer_callback()
TRY_OR_FATAL_ERROR(m_playback_handler->do_timed_state_update());
}
void PlaybackManager::seek_to_timestamp(Time target_timestamp, SeekMode seek_mode)
void PlaybackManager::seek_to_timestamp(Duration target_timestamp, SeekMode seek_mode)
{
TRY_OR_FATAL_ERROR(m_playback_handler->seek(target_timestamp, seek_mode));
}
Optional<Time> PlaybackManager::seek_demuxer_to_most_recent_keyframe(Time timestamp, Optional<Time> earliest_available_sample)
Optional<Duration> PlaybackManager::seek_demuxer_to_most_recent_keyframe(Duration timestamp, Optional<Duration> earliest_available_sample)
{
auto result = m_demuxer->seek_to_most_recent_keyframe(m_selected_video_track, timestamp, move(earliest_available_sample));
if (result.is_error())
@ -211,13 +211,13 @@ void PlaybackManager::set_state_update_timer(int delay_ms)
void PlaybackManager::restart_playback()
{
seek_to_timestamp(Time::zero());
seek_to_timestamp(Duration::zero());
}
void PlaybackManager::decode_and_queue_one_sample()
{
#if PLAYBACK_MANAGER_DEBUG
auto start_time = Time::now_monotonic();
auto start_time = Duration::now_monotonic();
#endif
FrameQueueItem item_to_enqueue;
@ -326,12 +326,12 @@ void PlaybackManager::decode_and_queue_one_sample()
m_buffer_is_full.exchange(false);
}
Time PlaybackManager::PlaybackStateHandler::current_time() const
Duration PlaybackManager::PlaybackStateHandler::current_time() const
{
return m_manager.m_last_present_in_media_time;
}
ErrorOr<void> PlaybackManager::PlaybackStateHandler::seek(Time target_timestamp, SeekMode seek_mode)
ErrorOr<void> PlaybackManager::PlaybackStateHandler::seek(Duration target_timestamp, SeekMode seek_mode)
{
return replace_handler_and_delete_this<SeekingStateHandler>(is_playing(), target_timestamp, seek_mode);
}
@ -408,7 +408,7 @@ public:
private:
ErrorOr<void> on_enter() override
{
m_last_present_in_real_time = Time::now_monotonic();
m_last_present_in_real_time = Duration::now_monotonic();
return do_timed_state_update();
}
@ -427,9 +427,9 @@ private:
return replace_handler_and_delete_this<BufferingStateHandler>(true);
}
Time current_time() const override
Duration current_time() const override
{
return manager().m_last_present_in_media_time + (Time::now_monotonic() - m_last_present_in_real_time);
return manager().m_last_present_in_media_time + (Duration::now_monotonic() - m_last_present_in_real_time);
}
ErrorOr<void> do_timed_state_update() override
@ -498,7 +498,7 @@ private:
// If we have a frame, send it for presentation.
if (should_present_frame) {
auto now = Time::now_monotonic();
auto now = Duration::now_monotonic();
manager().m_last_present_in_media_time += now - m_last_present_in_real_time;
m_last_present_in_real_time = now;
@ -520,7 +520,7 @@ private:
return {};
}
Time m_last_present_in_real_time = Time::zero();
Duration m_last_present_in_real_time = Duration::zero();
};
class PlaybackManager::PausedStateHandler : public PlaybackManager::PlaybackStateHandler {
@ -574,7 +574,7 @@ class PlaybackManager::BufferingStateHandler : public PlaybackManager::ResumingS
class PlaybackManager::SeekingStateHandler : public PlaybackManager::ResumingStateHandler {
public:
SeekingStateHandler(PlaybackManager& manager, bool playing, Time target_timestamp, SeekMode seek_mode)
SeekingStateHandler(PlaybackManager& manager, bool playing, Duration target_timestamp, SeekMode seek_mode)
: ResumingStateHandler(manager, playing)
, m_target_timestamp(target_timestamp)
, m_seek_mode(seek_mode)
@ -655,14 +655,14 @@ private:
StringView name() override { return "Seeking"sv; }
ErrorOr<void> seek(Time target_timestamp, SeekMode seek_mode) override
ErrorOr<void> seek(Duration target_timestamp, SeekMode seek_mode) override
{
m_target_timestamp = target_timestamp;
m_seek_mode = seek_mode;
return on_enter();
}
Time current_time() const override
Duration current_time() const override
{
return m_target_timestamp;
}
@ -676,7 +676,7 @@ private:
PlaybackState get_state() const override { return PlaybackState::Seeking; }
Time m_target_timestamp { Time::zero() };
Duration m_target_timestamp { Duration::zero() };
SeekMode m_seek_mode { SeekMode::Accurate };
};
@ -700,7 +700,7 @@ private:
{
// When Stopped, the decoder thread will be waiting for a signal to start its loop going again.
manager().m_decode_wait_condition.broadcast();
return replace_handler_and_delete_this<SeekingStateHandler>(true, Time::zero(), SeekMode::Fast);
return replace_handler_and_delete_this<SeekingStateHandler>(true, Duration::zero(), SeekMode::Fast);
}
bool is_playing() const override { return false; };
PlaybackState get_state() const override { return PlaybackState::Stopped; }

View file

@ -27,30 +27,30 @@ class FrameQueueItem {
public:
FrameQueueItem()
: m_data(Empty())
, m_timestamp(Time::zero())
, m_timestamp(Duration::zero())
{
}
static constexpr Time no_timestamp = Time::min();
static constexpr Duration no_timestamp = Duration::min();
enum class Type {
Frame,
Error,
};
static FrameQueueItem frame(RefPtr<Gfx::Bitmap> bitmap, Time timestamp)
static FrameQueueItem frame(RefPtr<Gfx::Bitmap> bitmap, Duration timestamp)
{
return FrameQueueItem(move(bitmap), timestamp);
}
static FrameQueueItem error_marker(DecoderError&& error, Time timestamp)
static FrameQueueItem error_marker(DecoderError&& error, Duration timestamp)
{
return FrameQueueItem(move(error), timestamp);
}
bool is_frame() const { return m_data.has<RefPtr<Gfx::Bitmap>>(); }
RefPtr<Gfx::Bitmap> bitmap() const { return m_data.get<RefPtr<Gfx::Bitmap>>(); }
Time timestamp() const { return m_timestamp; }
Duration timestamp() const { return m_timestamp; }
bool is_error() const { return m_data.has<DecoderError>(); }
DecoderError const& error() const { return m_data.get<DecoderError>(); }
@ -71,21 +71,21 @@ public:
}
private:
FrameQueueItem(RefPtr<Gfx::Bitmap> bitmap, Time timestamp)
FrameQueueItem(RefPtr<Gfx::Bitmap> bitmap, Duration timestamp)
: m_data(move(bitmap))
, m_timestamp(timestamp)
{
VERIFY(m_timestamp != no_timestamp);
}
FrameQueueItem(DecoderError&& error, Time timestamp)
FrameQueueItem(DecoderError&& error, Duration timestamp)
: m_data(move(error))
, m_timestamp(timestamp)
{
}
Variant<Empty, RefPtr<Gfx::Bitmap>, DecoderError> m_data { Empty() };
Time m_timestamp { no_timestamp };
Duration m_timestamp { no_timestamp };
};
static constexpr size_t frame_buffer_count = 4;
@ -122,7 +122,7 @@ public:
void resume_playback();
void pause_playback();
void restart_playback();
void seek_to_timestamp(Time, SeekMode = DEFAULT_SEEK_MODE);
void seek_to_timestamp(Duration, SeekMode = DEFAULT_SEEK_MODE);
bool is_playing() const
{
return m_playback_handler->is_playing();
@ -134,8 +134,8 @@ public:
u64 number_of_skipped_frames() const { return m_skipped_frames; }
Time current_playback_time();
Time duration();
Duration current_playback_time();
Duration duration();
Function<void(RefPtr<Gfx::Bitmap>)> on_video_frame;
Function<void()> on_playback_state_change;
@ -158,7 +158,7 @@ private:
void timer_callback();
// This must be called with m_demuxer_mutex locked!
Optional<Time> seek_demuxer_to_most_recent_keyframe(Time timestamp, Optional<Time> earliest_available_sample = OptionalNone());
Optional<Duration> seek_demuxer_to_most_recent_keyframe(Duration timestamp, Optional<Duration> earliest_available_sample = OptionalNone());
Optional<FrameQueueItem> dequeue_one_frame();
void set_state_update_timer(int delay_ms);
@ -172,7 +172,7 @@ private:
void dispatch_state_change();
void dispatch_fatal_error(Error);
Time m_last_present_in_media_time = Time::zero();
Duration m_last_present_in_media_time = Duration::zero();
NonnullOwnPtr<Demuxer> m_demuxer;
Threading::Mutex m_demuxer_mutex;
@ -212,10 +212,10 @@ private:
virtual PlaybackState get_state() const = 0;
virtual ErrorOr<void> pause() { return {}; };
virtual ErrorOr<void> buffer() { return {}; };
virtual ErrorOr<void> seek(Time target_timestamp, SeekMode);
virtual ErrorOr<void> seek(Duration target_timestamp, SeekMode);
virtual ErrorOr<void> stop();
virtual Time current_time() const;
virtual Duration current_time() const;
virtual ErrorOr<void> do_timed_state_update() { return {}; };

View file

@ -21,7 +21,7 @@ public:
class VideoSample : public Sample {
public:
VideoSample(ReadonlyBytes data, CodingIndependentCodePoints container_cicp, Time timestamp)
VideoSample(ReadonlyBytes data, CodingIndependentCodePoints container_cicp, Duration timestamp)
: m_data(data)
, m_container_cicp(container_cicp)
, m_timestamp(timestamp)
@ -31,12 +31,12 @@ public:
bool is_video_sample() const override { return true; }
ReadonlyBytes const& data() const { return m_data; }
CodingIndependentCodePoints container_cicp() const { return m_container_cicp; }
Time timestamp() const { return m_timestamp; }
Duration timestamp() const { return m_timestamp; }
private:
ReadonlyBytes m_data;
CodingIndependentCodePoints m_container_cicp;
Time m_timestamp;
Duration m_timestamp;
};
// FIXME: Add samples for audio, subtitles, etc.

View file

@ -22,7 +22,7 @@ enum class TrackType : u32 {
class Track {
struct VideoData {
Time duration {};
Duration duration {};
u64 pixel_width { 0 };
u64 pixel_height { 0 };
};

View file

@ -12,7 +12,7 @@
namespace Web::Cookie {
static DeprecatedString time_to_string(Time const& time)
static DeprecatedString time_to_string(Duration const& time)
{
auto local_time = Core::DateTime::from_timestamp(time.to_seconds());
return local_time.to_deprecated_string("%Y-%m-%d %H:%M:%S %Z"sv);
@ -87,11 +87,11 @@ ErrorOr<Web::Cookie::Cookie> IPC::decode(Decoder& decoder)
auto value = TRY(decoder.decode<DeprecatedString>());
auto domain = TRY(decoder.decode<DeprecatedString>());
auto path = TRY(decoder.decode<DeprecatedString>());
auto creation_time = TRY(decoder.decode<Time>());
auto expiry_time = TRY(decoder.decode<Time>());
auto creation_time = TRY(decoder.decode<Duration>());
auto expiry_time = TRY(decoder.decode<Duration>());
auto host_only = TRY(decoder.decode<bool>());
auto http_only = TRY(decoder.decode<bool>());
auto last_access_time = TRY(decoder.decode<Time>());
auto last_access_time = TRY(decoder.decode<Duration>());
auto persistent = TRY(decoder.decode<bool>());
auto secure = TRY(decoder.decode<bool>());
auto same_site = TRY(decoder.decode<Web::Cookie::SameSite>());

View file

@ -32,9 +32,9 @@ struct Cookie {
DeprecatedString name;
DeprecatedString value;
SameSite same_site;
Time creation_time {};
Time last_access_time {};
Time expiry_time {};
Duration creation_time {};
Duration last_access_time {};
Duration expiry_time {};
DeprecatedString domain {};
DeprecatedString path {};
bool secure { false };

View file

@ -27,7 +27,7 @@ static void on_path_attribute(ParsedCookie& parsed_cookie, StringView attribute_
static void on_secure_attribute(ParsedCookie& parsed_cookie);
static void on_http_only_attribute(ParsedCookie& parsed_cookie);
static void on_same_site_attribute(ParsedCookie& parsed_cookie, StringView attribute_value);
static Optional<Time> parse_date_time(StringView date_string);
static Optional<Duration> parse_date_time(StringView date_string);
Optional<ParsedCookie> parse_cookie(DeprecatedString const& cookie_string)
{
@ -169,10 +169,10 @@ void on_max_age_attribute(ParsedCookie& parsed_cookie, StringView attribute_valu
if (auto delta_seconds = attribute_value.to_int(); delta_seconds.has_value()) {
if (*delta_seconds <= 0) {
// If delta-seconds is less than or equal to zero (0), let expiry-time be the earliest representable date and time.
parsed_cookie.expiry_time_from_max_age_attribute = Time::min();
parsed_cookie.expiry_time_from_max_age_attribute = Duration::min();
} else {
// Otherwise, let the expiry-time be the current date and time plus delta-seconds seconds.
parsed_cookie.expiry_time_from_max_age_attribute = Time::now_realtime() + Time::from_seconds(*delta_seconds);
parsed_cookie.expiry_time_from_max_age_attribute = Duration::now_realtime() + Duration::from_seconds(*delta_seconds);
}
}
}
@ -236,7 +236,7 @@ void on_same_site_attribute(ParsedCookie& parsed_cookie, StringView attribute_va
parsed_cookie.same_site_attribute = same_site_from_string(attribute_value);
}
Optional<Time> parse_date_time(StringView date_string)
Optional<Duration> parse_date_time(StringView date_string)
{
// https://tools.ietf.org/html/rfc6265#section-5.1.1
unsigned hour = 0;
@ -345,7 +345,7 @@ Optional<Time> parse_date_time(StringView date_string)
// day-of-month-value, the month-value, the year-value, the hour-value, the minute-value, and the second-value, respectively.
// If no such date exists, abort these steps and fail to parse the cookie-date.
// FIXME: Fail on dates that do not exist.
auto parsed_cookie_date = Time::from_timestamp(year, month, day_of_month, hour, minute, second, 0);
auto parsed_cookie_date = Duration::from_timestamp(year, month, day_of_month, hour, minute, second, 0);
// 7. Return the parsed-cookie-date as the result of this algorithm.
return parsed_cookie_date;
@ -374,8 +374,8 @@ ErrorOr<Web::Cookie::ParsedCookie> IPC::decode(Decoder& decoder)
{
auto name = TRY(decoder.decode<DeprecatedString>());
auto value = TRY(decoder.decode<DeprecatedString>());
auto expiry_time_from_expires_attribute = TRY(decoder.decode<Optional<Time>>());
auto expiry_time_from_max_age_attribute = TRY(decoder.decode<Optional<Time>>());
auto expiry_time_from_expires_attribute = TRY(decoder.decode<Optional<Duration>>());
auto expiry_time_from_max_age_attribute = TRY(decoder.decode<Optional<Duration>>());
auto domain = TRY(decoder.decode<Optional<DeprecatedString>>());
auto path = TRY(decoder.decode<Optional<DeprecatedString>>());
auto secure_attribute_present = TRY(decoder.decode<bool>());

View file

@ -18,8 +18,8 @@ struct ParsedCookie {
DeprecatedString name;
DeprecatedString value;
SameSite same_site_attribute { SameSite::Default };
Optional<Time> expiry_time_from_expires_attribute {};
Optional<Time> expiry_time_from_max_age_attribute {};
Optional<Duration> expiry_time_from_expires_attribute {};
Optional<Duration> expiry_time_from_max_age_attribute {};
Optional<DeprecatedString> domain {};
Optional<DeprecatedString> path {};
bool secure_attribute_present { false };

View file

@ -1651,7 +1651,7 @@ void Document::completely_finish_loading()
VERIFY(browsing_context());
// 2. Set document's completely loaded time to the current time.
m_completely_loaded_time = AK::Time::now_realtime();
m_completely_loaded_time = AK::Duration::now_realtime();
// 3. Let container be document's browsing context's container.
auto container = JS::make_handle(browsing_context()->container());

View file

@ -612,7 +612,7 @@ private:
JS::GCPtr<HTMLCollection> m_all;
// https://html.spec.whatwg.org/#completely-loaded-time
Optional<AK::Time> m_completely_loaded_time;
Optional<AK::Duration> m_completely_loaded_time;
// https://html.spec.whatwg.org/multipage/dom.html#concept-document-navigation-id
Optional<String> m_navigation_id;

View file

@ -59,7 +59,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<File>> File::create(JS::Realm& realm, Vecto
// 3. If the lastModified member is provided, let d be set to the lastModified dictionary member. If it is not provided, set d to the current date and time represented as the number of milliseconds since the Unix Epoch (which is the equivalent of Date.now() [ECMA-262]).
// Note: Since ECMA-262 Date objects convert to long long values representing the number of milliseconds since the Unix Epoch, the lastModified member could be a Date object [ECMA-262].
last_modified = options->last_modified.has_value() ? options->last_modified.value() : Time::now_realtime().to_milliseconds();
last_modified = options->last_modified.has_value() ? options->last_modified.value() : Duration::now_realtime().to_milliseconds();
}
// 4. Return a new File object F such that:

View file

@ -1585,7 +1585,7 @@ WebIDL::ExceptionOr<void> HTMLMediaElement::dispatch_time_update_event()
ScopeGuard guard { [this] { m_running_time_update_event_handler = false; } };
m_running_time_update_event_handler = true;
m_last_time_update_event_time = Time::now_monotonic();
m_last_time_update_event_time = Duration::now_monotonic();
dispatch_event(TRY(DOM::Event::create(realm(), HTML::EventNames::timeupdate)));
return {};
@ -1617,7 +1617,7 @@ void HTMLMediaElement::time_marches_on(TimeMarchesOnReason reason)
auto dispatch_event = true;
if (m_last_time_update_event_time.has_value()) {
auto time_since_last_event = Time::now_monotonic() - *m_last_time_update_event_time;
auto time_since_last_event = Duration::now_monotonic() - *m_last_time_update_event_time;
dispatch_event = time_since_last_event.to_milliseconds() > 250;
}

View file

@ -211,7 +211,7 @@ private:
Optional<DOM::DocumentLoadEventDelayer> m_delaying_the_load_event;
bool m_running_time_update_event_handler { false };
Optional<Time> m_last_time_update_event_time;
Optional<Duration> m_last_time_update_event_time;
JS::GCPtr<DOM::DocumentObserver> m_document_observer;

View file

@ -128,7 +128,7 @@ void HTMLVideoElement::on_paused()
void HTMLVideoElement::on_seek(double position, MediaSeekMode seek_mode)
{
if (m_video_track)
m_video_track->seek(Time::from_milliseconds(position * 1000.0), seek_mode);
m_video_track->seek(Duration::from_milliseconds(position * 1000.0), seek_mode);
}
// https://html.spec.whatwg.org/multipage/media.html#attr-video-poster

View file

@ -98,17 +98,17 @@ void VideoTrack::pause_video(Badge<HTMLVideoElement>)
m_playback_manager->pause_playback();
}
Time VideoTrack::position() const
Duration VideoTrack::position() const
{
return m_playback_manager->current_playback_time();
}
Time VideoTrack::duration() const
Duration VideoTrack::duration() const
{
return m_playback_manager->selected_video_track().video_data().duration;
}
void VideoTrack::seek(Time position, MediaSeekMode seek_mode)
void VideoTrack::seek(Duration position, MediaSeekMode seek_mode)
{
switch (seek_mode) {
case MediaSeekMode::Accurate:

View file

@ -25,9 +25,9 @@ public:
void play_video(Badge<HTMLVideoElement>);
void pause_video(Badge<HTMLVideoElement>);
Time position() const;
Time duration() const;
void seek(Time, MediaSeekMode);
Duration position() const;
Duration duration() const;
void seek(Duration, MediaSeekMode);
u64 pixel_width() const;
u64 pixel_height() const;

View file

@ -55,7 +55,7 @@ DOMHighResTimeStamp coarsened_shared_current_time(bool cross_origin_isolated_cap
DOMHighResTimeStamp unsafe_shared_current_time()
{
// The unsafe shared current time must return the current value of the shared monotonic clock.
return Time::now_monotonic().to_nanoseconds() / 1e6;
return Duration::now_monotonic().to_nanoseconds() / 1e6;
}
}

View file

@ -41,7 +41,7 @@ public:
void set_body(ByteBuffer body) { m_body = move(body); }
void start_timer() { m_load_timer.start(); };
Time load_time() const { return m_load_timer.elapsed_time(); }
Duration load_time() const { return m_load_timer.elapsed_time(); }
Optional<Page&>& page() { return m_page; };
void set_page(Page& page) { m_page = page; }

View file

@ -329,7 +329,7 @@ ExecuteScriptResultSerialized execute_async_script(Web::Page& page, DeprecatedSt
auto* window = page.top_level_browsing_context().active_window();
auto& realm = window->realm();
auto& vm = window->vm();
auto start = Time::now_monotonic();
auto start = Duration::now_monotonic();
// 4. Let promise be a new Promise.
auto promise = JS::Promise::create(realm);
@ -383,7 +383,7 @@ ExecuteScriptResultSerialized execute_async_script(Web::Page& page, DeprecatedSt
vm.custom_data()->spin_event_loop_until([&] {
if (script_promise.state() != JS::Promise::State::Pending)
return true;
if (timeout.has_value() && (Time::now_monotonic() - start) > Time::from_seconds(static_cast<i64>(*timeout)))
if (timeout.has_value() && (Duration::now_monotonic() - start) > Duration::from_seconds(static_cast<i64>(*timeout)))
return true;
return false;
});