mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibGfx/ISOBMFF: Support box header size 0 to mean "until end of data"
JPEG2000 uses this, and as far as I can tell it's also part of ISO/IEC 14496-12.
This commit is contained in:
parent
0d098211b7
commit
9bf29356a2
Notes:
sideshowbarker
2024-07-16 23:03:06 +09:00
Author: https://github.com/nico Commit: https://github.com/SerenityOS/serenity/commit/9bf29356a2 Pull-request: https://github.com/SerenityOS/serenity/pull/23676
4 changed files with 18 additions and 11 deletions
|
@ -8,7 +8,7 @@
|
|||
|
||||
namespace Gfx::ISOBMFF {
|
||||
|
||||
ErrorOr<BoxHeader> read_box_header(Stream& stream)
|
||||
ErrorOr<BoxHeader> read_box_header(BoxStream& stream)
|
||||
{
|
||||
BoxHeader header;
|
||||
u64 total_size = TRY(stream.read_value<BigEndian<u32>>());
|
||||
|
@ -16,12 +16,16 @@ ErrorOr<BoxHeader> read_box_header(Stream& stream)
|
|||
|
||||
u64 data_size_read = sizeof(u32) + sizeof(BoxType);
|
||||
|
||||
if (total_size == 1) {
|
||||
total_size = TRY(stream.read_value<BigEndian<u64>>());
|
||||
data_size_read += sizeof(u64);
|
||||
}
|
||||
if (total_size == 0) {
|
||||
header.contents_size = stream.remaining();
|
||||
} else {
|
||||
if (total_size == 1) {
|
||||
total_size = TRY(stream.read_value<BigEndian<u64>>());
|
||||
data_size_read += sizeof(u64);
|
||||
}
|
||||
|
||||
header.contents_size = total_size - data_size_read;
|
||||
header.contents_size = total_size - data_size_read;
|
||||
}
|
||||
return header;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ struct BoxHeader {
|
|||
u64 contents_size { 0 };
|
||||
};
|
||||
|
||||
ErrorOr<BoxHeader> read_box_header(Stream& stream);
|
||||
ErrorOr<BoxHeader> read_box_header(BoxStream& stream);
|
||||
|
||||
struct Box {
|
||||
Box() = default;
|
||||
|
|
|
@ -10,7 +10,8 @@ namespace Gfx::ISOBMFF {
|
|||
|
||||
ErrorOr<Reader> Reader::create(MaybeOwned<SeekableStream> stream)
|
||||
{
|
||||
return Reader(move(stream));
|
||||
size_t size = TRY(stream->size());
|
||||
return Reader(move(stream), size);
|
||||
}
|
||||
|
||||
ErrorOr<BoxList> Reader::read_entire_file()
|
||||
|
@ -18,8 +19,8 @@ ErrorOr<BoxList> Reader::read_entire_file()
|
|||
BoxList top_level_boxes;
|
||||
|
||||
while (!m_stream->is_eof()) {
|
||||
auto box_header = TRY(read_box_header(*m_stream));
|
||||
BoxStream box_stream { *m_stream, static_cast<size_t>(box_header.contents_size) };
|
||||
auto box_header = TRY(read_box_header(m_box_stream));
|
||||
BoxStream box_stream { m_box_stream, static_cast<size_t>(box_header.contents_size) };
|
||||
|
||||
switch (box_header.type) {
|
||||
case BoxType::FileTypeBox:
|
||||
|
|
|
@ -23,14 +23,16 @@ public:
|
|||
ErrorOr<Vector<BrandIdentifier>> get_minor_brands();
|
||||
|
||||
private:
|
||||
Reader(MaybeOwned<SeekableStream> stream)
|
||||
Reader(MaybeOwned<SeekableStream> stream, size_t size)
|
||||
: m_stream(move(stream))
|
||||
, m_box_stream(*m_stream, size)
|
||||
{
|
||||
}
|
||||
|
||||
ErrorOr<void> parse_initial_data();
|
||||
|
||||
MaybeOwned<SeekableStream> m_stream;
|
||||
BoxStream m_box_stream;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue