mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 03:47:34 +00:00
LibVideo: Delay playback errors by their sample timestamps when we can
If we encounter an error in the video decoder, we can set a timestamp for the error item in the queue so that it will display the error only when the frame that caused the error would have been displayed.
This commit is contained in:
parent
2a228e8a6e
commit
5da0c6f916
2 changed files with 49 additions and 53 deletions
|
@ -25,6 +25,8 @@
|
|||
namespace Video {
|
||||
|
||||
struct FrameQueueItem {
|
||||
static constexpr Time no_timestamp = Time::min();
|
||||
|
||||
enum class Type {
|
||||
Frame,
|
||||
Error,
|
||||
|
@ -35,14 +37,14 @@ struct FrameQueueItem {
|
|||
return FrameQueueItem(move(bitmap), timestamp);
|
||||
}
|
||||
|
||||
static FrameQueueItem error_marker(DecoderError&& error)
|
||||
static FrameQueueItem error_marker(DecoderError&& error, Time timestamp)
|
||||
{
|
||||
return FrameQueueItem(move(error));
|
||||
return FrameQueueItem(move(error), timestamp);
|
||||
}
|
||||
|
||||
bool is_frame() const { return m_data.has<FrameData>(); }
|
||||
RefPtr<Gfx::Bitmap> bitmap() const { return m_data.get<FrameData>().bitmap; }
|
||||
Time timestamp() const { return m_data.get<FrameData>().timestamp; }
|
||||
bool is_frame() const { return m_data.has<RefPtr<Gfx::Bitmap>>(); }
|
||||
RefPtr<Gfx::Bitmap> bitmap() const { return m_data.get<RefPtr<Gfx::Bitmap>>(); }
|
||||
Time timestamp() const { return m_timestamp; }
|
||||
|
||||
bool is_error() const { return m_data.has<DecoderError>(); }
|
||||
DecoderError const& error() const { return m_data.get<DecoderError>(); }
|
||||
|
@ -56,27 +58,26 @@ struct FrameQueueItem {
|
|||
DeprecatedString debug_string() const
|
||||
{
|
||||
if (is_error())
|
||||
return error().string_literal();
|
||||
return DeprecatedString::formatted("{} at {}ms", error().string_literal(), timestamp().to_milliseconds());
|
||||
return DeprecatedString::formatted("frame at {}ms", timestamp().to_milliseconds());
|
||||
}
|
||||
|
||||
private:
|
||||
struct FrameData {
|
||||
RefPtr<Gfx::Bitmap> bitmap;
|
||||
Time timestamp;
|
||||
};
|
||||
|
||||
FrameQueueItem(RefPtr<Gfx::Bitmap> bitmap, Time timestamp)
|
||||
: m_data(FrameData { move(bitmap), timestamp })
|
||||
: m_data(move(bitmap))
|
||||
, m_timestamp(timestamp)
|
||||
{
|
||||
VERIFY(m_timestamp != no_timestamp);
|
||||
}
|
||||
|
||||
FrameQueueItem(DecoderError&& error)
|
||||
FrameQueueItem(DecoderError&& error, Time timestamp)
|
||||
: m_data(move(error))
|
||||
, m_timestamp(timestamp)
|
||||
{
|
||||
}
|
||||
|
||||
Variant<Empty, FrameData, DecoderError> m_data;
|
||||
Variant<Empty, RefPtr<Gfx::Bitmap>, DecoderError> m_data;
|
||||
Time m_timestamp;
|
||||
};
|
||||
|
||||
static constexpr size_t FRAME_BUFFER_COUNT = 4;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue