1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 19:07:34 +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

@ -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;
};