Reader.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Copyright (c) 2023, Gregory Bertilson <Zaggy1024@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "Reader.h"
  7. namespace Gfx::ISOBMFF {
  8. ErrorOr<Reader> Reader::create(MaybeOwned<SeekableStream> stream)
  9. {
  10. return Reader(move(stream));
  11. }
  12. ErrorOr<BoxList> Reader::read_entire_file()
  13. {
  14. BoxList top_level_boxes;
  15. while (!m_stream->is_eof()) {
  16. auto box_header = TRY(read_box_header(*m_stream));
  17. BoxStream box_stream { *m_stream, static_cast<size_t>(box_header.contents_size) };
  18. switch (box_header.type) {
  19. case BoxType::FileTypeBox:
  20. TRY(top_level_boxes.try_append(TRY(FileTypeBox::create_from_stream(box_stream))));
  21. break;
  22. default:
  23. TRY(top_level_boxes.try_append(TRY(UnknownBox::create_from_stream(box_header.type, box_stream))));
  24. break;
  25. }
  26. if (!box_stream.is_eof())
  27. return Error::from_string_literal("Reader did not consume all data");
  28. }
  29. return top_level_boxes;
  30. }
  31. }