diff options
author | kleines Filmröllchen <filmroellchen@serenityos.org> | 2023-03-13 16:30:34 +0100 |
---|---|---|
committer | Jelle Raaijmakers <jelle@gmta.nl> | 2023-05-24 23:18:07 +0200 |
commit | 213025f210a785ca71b7659d7dc4f5dc3c030622 (patch) | |
tree | c255161bbb780822d4d5a21c3157303f905b781b /Userland/Libraries/LibVideo/Containers | |
parent | 82ddc813d52b8314f63c583a90953ae5ac607ffd (diff) | |
download | serenity-213025f210a785ca71b7659d7dc4f5dc3c030622.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibVideo/Containers')
6 files changed, 31 insertions, 31 deletions
diff --git a/Userland/Libraries/LibVideo/Containers/Demuxer.h b/Userland/Libraries/LibVideo/Containers/Demuxer.h index 0915b8685e..967326f9ec 100644 --- a/Userland/Libraries/LibVideo/Containers/Demuxer.h +++ b/Userland/Libraries/LibVideo/Containers/Demuxer.h @@ -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; diff --git a/Userland/Libraries/LibVideo/Containers/Matroska/Document.h b/Userland/Libraries/LibVideo/Containers/Matroska/Document.h index 9c9e5abcac..39cce17ae5 100644 --- a/Userland/Libraries/LibVideo/Containers/Matroska/Document.h +++ b/Userland/Libraries/LibVideo/Containers/Matroska/Document.h @@ -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; }; diff --git a/Userland/Libraries/LibVideo/Containers/Matroska/MatroskaDemuxer.cpp b/Userland/Libraries/LibVideo/Containers/Matroska/MatroskaDemuxer.cpp index e01da0cc6f..744356cd19 100644 --- a/Userland/Libraries/LibVideo/Containers/Matroska/MatroskaDemuxer.cpp +++ b/Userland/Libraries/LibVideo/Containers/Matroska/MatroskaDemuxer.cpp @@ -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()); } } diff --git a/Userland/Libraries/LibVideo/Containers/Matroska/MatroskaDemuxer.h b/Userland/Libraries/LibVideo/Containers/Matroska/MatroskaDemuxer.h index eeddd16630..225ebed06f 100644 --- a/Userland/Libraries/LibVideo/Containers/Matroska/MatroskaDemuxer.h +++ b/Userland/Libraries/LibVideo/Containers/Matroska/MatroskaDemuxer.h @@ -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; diff --git a/Userland/Libraries/LibVideo/Containers/Matroska/Reader.cpp b/Userland/Libraries/LibVideo/Containers/Matroska/Reader.cpp index b6a87b194d..43a1ee64a8 100644 --- a/Userland/Libraries/LibVideo/Containers/Matroska/Reader.cpp +++ b/Userland/Libraries/LibVideo/Containers/Matroska/Reader.cpp @@ -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)); diff --git a/Userland/Libraries/LibVideo/Containers/Matroska/Reader.h b/Userland/Libraries/LibVideo/Containers/Matroska/Reader.h index ccfd54ca75..80cf336e43 100644 --- a/Userland/Libraries/LibVideo/Containers/Matroska/Reader.h +++ b/Userland/Libraries/LibVideo/Containers/Matroska/Reader.h @@ -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; }; |