Skip to content

Truly independent web browser

LibMedia: Check video producer queue contents for seek fast paths

Zaggy1024e98bc2c422f2
diff --git a/Libraries/LibMedia/Producers/DecodedAudioProducer.cpp b/Libraries/LibMedia/Producers/DecodedAudioProducer.cpp
index ecb95d81b8c..51683219b7b 100644
--- a/Libraries/LibMedia/Producers/DecodedAudioProducer.cpp
+++ b/Libraries/LibMedia/Producers/DecodedAudioProducer.cpp
@@ -327,7 +327,7 @@ void DecodedAudioProducer::ThreadData::consume()
note_consumer_activity_while_locked();
if (m_queue.is_empty())
return;
- m_earliest_available_timestamp = max(m_earliest_available_timestamp, m_queue.head().block.media_time_end());
+ m_consumed_media_time_end = max(m_consumed_media_time_end, m_queue.head().block.media_time_end());
m_queue.dequeue();
wake();
}
@@ -549,12 +549,12 @@ void DecodedAudioProducer::ThreadData::handle_seek()
m_demuxer->reset_blocking_reads_aborted_for_track(m_track);
if (seek_reason == SeekReason::DecoderResetNeeded && !seek_was_externally_requested) {
- timestamp = m_earliest_available_timestamp;
+ timestamp = m_consumed_media_time_end;
if (!m_queue.is_empty())
timestamp = m_queue.tail().block.media_time_end();
} else {
m_queue.clear();
- m_earliest_available_timestamp = timestamp;
+ m_consumed_media_time_end = timestamp;
}
m_current_halting_status = PipelineStatus::Pending;
diff --git a/Libraries/LibMedia/Producers/DecodedAudioProducer.h b/Libraries/LibMedia/Producers/DecodedAudioProducer.h
index 7c3bb8a3bdf..395609c54d6 100644
--- a/Libraries/LibMedia/Producers/DecodedAudioProducer.h
+++ b/Libraries/LibMedia/Producers/DecodedAudioProducer.h
@@ -154,7 +154,7 @@ private:
size_t m_queue_max_size { 8 };
AudioQueue m_queue;
- AK::Duration m_earliest_available_timestamp;
+ AK::Duration m_consumed_media_time_end;
ErrorHandler m_error_handler;
ReadBlockedChangeHandler m_read_blocked_change_handler;
PipelineStatus m_current_halting_status { PipelineStatus::Pending };
diff --git a/Libraries/LibMedia/Producers/DecodedVideoProducer.cpp b/Libraries/LibMedia/Producers/DecodedVideoProducer.cpp
index f2e76e653e0..42d51c5c1aa 100644
--- a/Libraries/LibMedia/Producers/DecodedVideoProducer.cpp
+++ b/Libraries/LibMedia/Producers/DecodedVideoProducer.cpp
@@ -111,7 +111,6 @@ void DecodedVideoProducer::ThreadData::consume()
if (m_queue.is_empty())
return;
frame = m_queue.dequeue().frame;
- m_earliest_available_timestamp = max(m_earliest_available_timestamp, frame->timestamp() + frame->duration());
wake();
}
@@ -438,7 +437,6 @@ bool DecodedVideoProducer::ThreadData::handle_auto_suspension()
m_queue.clear();
m_last_queued_frame = nullptr;
- m_latest_available_timestamp = m_earliest_available_timestamp;
m_decoder.clear();
m_auto_suspend_requested = false;
m_current_halting_status = PipelineStatus::Suspended;
@@ -462,7 +460,6 @@ void DecodedVideoProducer::ThreadData::queue_frame(NonnullRefPtr<VideoFrame> con
{
m_queue.enqueue({ frame });
m_last_queued_frame = frame;
- m_latest_available_timestamp = max(m_latest_available_timestamp, frame->end());
dispatch_wake_if_needed_while_locked();
}
@@ -474,8 +471,12 @@ void DecodedVideoProducer::ThreadData::dispatch_error(DecoderError&& error)
bool DecodedVideoProducer::ThreadData::is_within_available_range_while_locked(AK::Duration timestamp) const
{
- return timestamp >= m_earliest_available_timestamp
- && (timestamp < m_latest_available_timestamp || m_current_halting_status == PipelineStatus::EndOfStream);
+ auto is_at_end_of_stream = m_current_halting_status == PipelineStatus::EndOfStream;
+ if (m_queue.is_empty())
+ return is_at_end_of_stream && m_last_queued_frame != nullptr && timestamp >= m_last_queued_frame->timestamp();
+ if (timestamp < m_queue.head().frame->timestamp())
+ return false;
+ return is_at_end_of_stream || timestamp < m_queue.tail().frame->end();
}
void DecodedVideoProducer::ThreadData::re_emit_last_frame_if_at_end_of_stream_while_locked()
@@ -576,7 +577,6 @@ void DecodedVideoProducer::ThreadData::handle_seek()
}
if (seek_reason == SeekReason::DecoderResetNeeded && !seek_was_externally_requested && !has_clamped_target) {
- timestamp = m_latest_available_timestamp;
if (m_last_queued_frame != nullptr)
timestamp = m_last_queued_frame->end();
} else {
@@ -586,8 +586,6 @@ void DecodedVideoProducer::ThreadData::handle_seek()
m_queue.clear();
m_last_queued_frame = nullptr;
- m_earliest_available_timestamp = timestamp;
- m_latest_available_timestamp = timestamp;
}
m_current_halting_status = PipelineStatus::Pending;
diff --git a/Libraries/LibMedia/Producers/DecodedVideoProducer.h b/Libraries/LibMedia/Producers/DecodedVideoProducer.h
index df16f755be1..f0360ae5f27 100644
--- a/Libraries/LibMedia/Producers/DecodedVideoProducer.h
+++ b/Libraries/LibMedia/Producers/DecodedVideoProducer.h
@@ -164,8 +164,6 @@ private:
FrameQueue m_queue;
RefPtr<VideoFrame> m_last_queued_frame;
- AK::Duration m_earliest_available_timestamp;
- AK::Duration m_latest_available_timestamp;
ErrorHandler m_error_handler;
ReadBlockedChangeHandler m_read_blocked_change_handler;
PipelineStatus m_current_halting_status { PipelineStatus::Pending };