LibWeb: Port HTMLVideoElement to play videos with Video::PlaybackManager

This has several advantages over the current manual demuxing currently
being performed. PlaybackManager hides the specific demuxer being used,
which will allow more codecs to be added transparently to LibWeb. It
also provides buffering and controls playback rate for us.

Further, it will allow us to much more easily implement the "media
timeline" to render a timestamp and implement seeking.
This commit is contained in:
Timothy Flynn 2023-04-09 12:08:49 -04:00 committed by Linus Groh
parent 7132047c92
commit edf85d39c6
Notes: sideshowbarker 2024-07-17 07:20:57 +09:00
5 changed files with 87 additions and 93 deletions

View file

@ -11,13 +11,9 @@
#include <LibWeb/HTML/HTMLVideoElement.h>
#include <LibWeb/HTML/VideoTrack.h>
#include <LibWeb/Layout/VideoBox.h>
#include <LibWeb/Platform/Timer.h>
namespace Web::HTML {
// FIXME: Determine a reasonable framerate somehow. For now, this is roughly 24fps.
static constexpr int s_frame_delay_ms = 42;
HTMLVideoElement::HTMLVideoElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLMediaElement(document, move(qualified_name))
{
@ -81,32 +77,28 @@ void HTMLVideoElement::set_video_track(JS::GCPtr<HTML::VideoTrack> video_track)
set_needs_style_update(true);
document().set_needs_layout();
if (m_video_timer)
m_video_timer->stop();
if (m_video_track)
m_video_track->pause_video({});
m_video_track = video_track;
}
void HTMLVideoElement::set_current_frame(Badge<VideoTrack>, RefPtr<Gfx::Bitmap> frame)
{
m_current_frame = move(frame);
layout_node()->set_needs_display();
}
void HTMLVideoElement::on_playing()
{
if (!m_video_timer) {
m_video_timer = Platform::Timer::create_repeating(s_frame_delay_ms, [this]() {
if (auto frame = m_video_track->next_frame())
m_current_frame = move(frame);
else
m_video_timer->stop();
layout_node()->set_needs_display();
});
}
m_video_timer->start();
if (m_video_track)
m_video_track->play_video({});
}
void HTMLVideoElement::on_paused()
{
if (m_video_timer)
m_video_timer->stop();
if (m_video_track)
m_video_track->pause_video({});
}
}