diff options
Diffstat (limited to 'Userland/Libraries/LibVideo')
3 files changed, 13 insertions, 9 deletions
diff --git a/Userland/Libraries/LibVideo/Containers/Matroska/Document.h b/Userland/Libraries/LibVideo/Containers/Matroska/Document.h index b60051d0ad..195647fc1a 100644 --- a/Userland/Libraries/LibVideo/Containers/Matroska/Document.h +++ b/Userland/Libraries/LibVideo/Containers/Matroska/Document.h @@ -31,14 +31,20 @@ public: void set_muxing_app(String muxing_app) { m_muxing_app = move(muxing_app); } Utf8View writing_app() const { return Utf8View(m_writing_app); } void set_writing_app(String writing_app) { m_writing_app = move(writing_app); } - Optional<double> duration() const { return m_duration; } - void set_duration(double duration) { m_duration.emplace(duration); } + Optional<double> duration_unscaled() const { return m_duration_unscaled; } + void set_duration_unscaled(double duration) { m_duration_unscaled.emplace(duration); } + Optional<Time> duration() const + { + if (!duration_unscaled().has_value()) + return {}; + return Time::from_nanoseconds(static_cast<i64>(static_cast<double>(timestamp_scale()) * duration_unscaled().value())); + } private: u64 m_timestamp_scale { 1'000'000 }; String m_muxing_app; String m_writing_app; - Optional<double> m_duration; + Optional<double> m_duration_unscaled; }; class TrackEntry { diff --git a/Userland/Libraries/LibVideo/Containers/Matroska/MatroskaDemuxer.cpp b/Userland/Libraries/LibVideo/Containers/Matroska/MatroskaDemuxer.cpp index dcdaf858f6..62dbb1625b 100644 --- a/Userland/Libraries/LibVideo/Containers/Matroska/MatroskaDemuxer.cpp +++ b/Userland/Libraries/LibVideo/Containers/Matroska/MatroskaDemuxer.cpp @@ -82,10 +82,8 @@ DecoderErrorOr<NonnullOwnPtr<Sample>> MatroskaDemuxer::get_next_sample_for_track DecoderErrorOr<Time> MatroskaDemuxer::duration() { - auto segment_information = TRY(m_reader.segment_information()); - if (!segment_information.duration().has_value()) - return Time::zero(); - return Time::from_nanoseconds(static_cast<i64>(segment_information.duration().value() * segment_information.timestamp_scale())); + auto duration = TRY(m_reader.segment_information()).duration(); + return duration.value_or(Time::zero()); } } diff --git a/Userland/Libraries/LibVideo/Containers/Matroska/Reader.cpp b/Userland/Libraries/LibVideo/Containers/Matroska/Reader.cpp index 57cf222869..abc4f0f958 100644 --- a/Userland/Libraries/LibVideo/Containers/Matroska/Reader.cpp +++ b/Userland/Libraries/LibVideo/Containers/Matroska/Reader.cpp @@ -270,8 +270,8 @@ static DecoderErrorOr<SegmentInformation> parse_information(Streamer& streamer) dbgln_if(MATROSKA_DEBUG, "Read WritingApp attribute: {}", segment_information.writing_app().as_string()); break; case DURATION_ID: - segment_information.set_duration(TRY_READ(streamer.read_float())); - dbgln_if(MATROSKA_DEBUG, "Read Duration attribute: {}", segment_information.duration().value()); + segment_information.set_duration_unscaled(TRY_READ(streamer.read_float())); + dbgln_if(MATROSKA_DEBUG, "Read Duration attribute: {}", segment_information.duration_unscaled().value()); break; default: TRY_READ(streamer.read_unknown_element()); |