mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-02 17:28:48 +00:00
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:
parent
7132047c92
commit
edf85d39c6
Notes:
sideshowbarker
2024-07-17 07:20:57 +09:00
Author: https://github.com/trflynn89
Commit: edf85d39c6
Pull-request: https://github.com/SerenityOS/serenity/pull/18264
5 changed files with 87 additions and 93 deletions
|
@ -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({});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue