summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibVideo
diff options
context:
space:
mode:
authorZaggy1024 <zaggy1024@gmail.com>2022-11-13 19:13:50 -0600
committerAndreas Kling <kling@serenityos.org>2022-11-25 23:28:39 +0100
commit2a9fb8b439f4180ca6b3c790b712ba8cf666b68c (patch)
tree715664ab29f4cfbd8853279f75aa641fdfe26f5d /Userland/Libraries/LibVideo
parenta58bf7c3d1b532a6c5b9c679eacece058e392eca (diff)
downloadserenity-2a9fb8b439f4180ca6b3c790b712ba8cf666b68c.zip
LibVideo: Give Matroska duration an absolute value getter
Previously, the duration had to be multiplied by timestamp_scale and converted to a Time object, now SegmentInformation::duration() does it itself.
Diffstat (limited to 'Userland/Libraries/LibVideo')
-rw-r--r--Userland/Libraries/LibVideo/Containers/Matroska/Document.h12
-rw-r--r--Userland/Libraries/LibVideo/Containers/Matroska/MatroskaDemuxer.cpp6
-rw-r--r--Userland/Libraries/LibVideo/Containers/Matroska/Reader.cpp4
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());