mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:28:12 +00:00
LibWeb: Create a basic layout node for HTMLVideoElement
This commit is contained in:
parent
725d7c3699
commit
f156d3d5e5
10 changed files with 338 additions and 0 deletions
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <AK/IDAllocator.h>
|
||||
#include <LibGfx/Bitmap.h>
|
||||
#include <LibJS/Runtime/Realm.h>
|
||||
#include <LibJS/Runtime/VM.h>
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
|
@ -12,6 +13,7 @@
|
|||
#include <LibWeb/DOM/Event.h>
|
||||
#include <LibWeb/HTML/EventNames.h>
|
||||
#include <LibWeb/HTML/HTMLMediaElement.h>
|
||||
#include <LibWeb/HTML/HTMLVideoElement.h>
|
||||
#include <LibWeb/HTML/VideoTrack.h>
|
||||
#include <LibWeb/HTML/VideoTrackList.h>
|
||||
|
||||
|
@ -52,6 +54,65 @@ void VideoTrack::visit_edges(Cell::Visitor& visitor)
|
|||
visitor.visit(m_video_track_list);
|
||||
}
|
||||
|
||||
RefPtr<Gfx::Bitmap> VideoTrack::next_frame()
|
||||
{
|
||||
auto frame_sample = m_demuxer->get_next_video_sample_for_track(m_track);
|
||||
if (frame_sample.is_error()) {
|
||||
if (frame_sample.error().category() != Video::DecoderErrorCategory::EndOfStream)
|
||||
dbgln("VideoTrack: Error getting next video sample: {}", frame_sample.error().description());
|
||||
return {};
|
||||
}
|
||||
|
||||
OwnPtr<Video::VideoFrame> decoded_frame;
|
||||
|
||||
while (!decoded_frame) {
|
||||
auto result = m_decoder.receive_sample(frame_sample.value()->data());
|
||||
if (result.is_error()) {
|
||||
dbgln("VideoTrack: Error receiving video sample data: {}", frame_sample.error().description());
|
||||
return {};
|
||||
}
|
||||
|
||||
while (true) {
|
||||
auto frame_result = m_decoder.get_decoded_frame();
|
||||
if (frame_result.is_error()) {
|
||||
if (frame_result.error().category() == Video::DecoderErrorCategory::NeedsMoreInput)
|
||||
break;
|
||||
|
||||
dbgln("VideoTrack: Error decoding video frame: {}", frame_result.error().description());
|
||||
return {};
|
||||
}
|
||||
|
||||
decoded_frame = frame_result.release_value();
|
||||
VERIFY(decoded_frame);
|
||||
}
|
||||
}
|
||||
|
||||
auto& cicp = decoded_frame->cicp();
|
||||
cicp.adopt_specified_values(frame_sample.value()->container_cicp());
|
||||
cicp.default_code_points_if_unspecified({ Video::ColorPrimaries::BT709, Video::TransferCharacteristics::BT709, Video::MatrixCoefficients::BT709, Video::VideoFullRangeFlag::Studio });
|
||||
|
||||
// BT.601, BT.709 and BT.2020 have a similar transfer function to sRGB, so other applications
|
||||
// (Chromium, VLC) forgo transfer characteristics conversion. We will emulate that behavior by
|
||||
// handling those as sRGB instead, which causes no transfer function change in the output,
|
||||
// unless display color management is later implemented.
|
||||
switch (cicp.transfer_characteristics()) {
|
||||
case Video::TransferCharacteristics::BT601:
|
||||
case Video::TransferCharacteristics::BT709:
|
||||
case Video::TransferCharacteristics::BT2020BitDepth10:
|
||||
case Video::TransferCharacteristics::BT2020BitDepth12:
|
||||
cicp.set_transfer_characteristics(Video::TransferCharacteristics::SRGB);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
auto bitmap = decoded_frame->to_bitmap();
|
||||
if (bitmap.is_error())
|
||||
return {};
|
||||
|
||||
return bitmap.release_value();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/media.html#dom-videotrack-selected
|
||||
void VideoTrack::set_selected(bool selected)
|
||||
{
|
||||
|
@ -83,6 +144,12 @@ void VideoTrack::set_selected(bool selected)
|
|||
}
|
||||
|
||||
m_selected = selected;
|
||||
|
||||
// AD-HOC: Inform the video element node that we have (un)selected a video track for layout.
|
||||
if (is<HTMLVideoElement>(*m_media_element)) {
|
||||
auto& video_element = verify_cast<HTMLVideoElement>(*m_media_element);
|
||||
video_element.set_video_track(m_selected ? this : nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue