1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 23:27:43 +00:00

LibCore: Make MappedFile OwnPtr-based

Since it will become a stream in a little bit, it should behave like all
non-trivial stream classes, who are not primarily intended to have
shared ownership to make closing behavior more predictable. Across all
uses of MappedFile, there is only one use case of shared mapped files in
LibVideo, which now uses the thin SharedMappedFile wrapper.
This commit is contained in:
kleines Filmröllchen 2023-09-26 00:54:34 +02:00 committed by Tim Schumacher
parent 5b2496e522
commit 062e0db46c
32 changed files with 80 additions and 64 deletions

View file

@ -14,7 +14,7 @@ DecoderErrorOr<NonnullOwnPtr<MatroskaDemuxer>> MatroskaDemuxer::from_file(String
return make<MatroskaDemuxer>(TRY(Reader::from_file(filename)));
}
DecoderErrorOr<NonnullOwnPtr<MatroskaDemuxer>> MatroskaDemuxer::from_mapped_file(NonnullRefPtr<Core::MappedFile> mapped_file)
DecoderErrorOr<NonnullOwnPtr<MatroskaDemuxer>> MatroskaDemuxer::from_mapped_file(NonnullOwnPtr<Core::MappedFile> mapped_file)
{
return make<MatroskaDemuxer>(TRY(Reader::from_mapped_file(move(mapped_file))));
}

View file

@ -18,7 +18,7 @@ public:
// FIXME: We should instead accept some abstract data streaming type so that the demuxer
// can work with non-contiguous data.
static DecoderErrorOr<NonnullOwnPtr<MatroskaDemuxer>> from_file(StringView filename);
static DecoderErrorOr<NonnullOwnPtr<MatroskaDemuxer>> from_mapped_file(NonnullRefPtr<Core::MappedFile> mapped_file);
static DecoderErrorOr<NonnullOwnPtr<MatroskaDemuxer>> from_mapped_file(NonnullOwnPtr<Core::MappedFile> mapped_file);
static DecoderErrorOr<NonnullOwnPtr<MatroskaDemuxer>> from_data(ReadonlyBytes data);

View file

@ -86,13 +86,13 @@ constexpr u32 CUE_REFERENCE_ID = 0xDB;
DecoderErrorOr<Reader> Reader::from_file(StringView path)
{
auto mapped_file = DECODER_TRY(DecoderErrorCategory::IO, Core::MappedFile::map(path));
return from_mapped_file(mapped_file);
return from_mapped_file(move(mapped_file));
}
DecoderErrorOr<Reader> Reader::from_mapped_file(NonnullRefPtr<Core::MappedFile> mapped_file)
DecoderErrorOr<Reader> Reader::from_mapped_file(NonnullOwnPtr<Core::MappedFile> mapped_file)
{
auto reader = TRY(from_data(mapped_file->bytes()));
reader.m_mapped_file = move(mapped_file);
reader.m_mapped_file = make_ref_counted<Core::SharedMappedFile>(move(mapped_file));
return reader;
}

View file

@ -25,7 +25,7 @@ public:
typedef Function<DecoderErrorOr<IterationDecision>(TrackEntry const&)> TrackEntryCallback;
static DecoderErrorOr<Reader> from_file(StringView path);
static DecoderErrorOr<Reader> from_mapped_file(NonnullRefPtr<Core::MappedFile> mapped_file);
static DecoderErrorOr<Reader> from_mapped_file(NonnullOwnPtr<Core::MappedFile> mapped_file);
static DecoderErrorOr<Reader> from_data(ReadonlyBytes data);
@ -60,7 +60,7 @@ private:
DecoderErrorOr<void> ensure_cues_are_parsed();
DecoderErrorOr<void> seek_to_cue_for_timestamp(SampleIterator&, Duration const&);
RefPtr<Core::MappedFile> m_mapped_file;
RefPtr<Core::SharedMappedFile> m_mapped_file;
ReadonlyBytes m_data;
Optional<EBMLHeader> m_header;
@ -89,7 +89,7 @@ public:
private:
friend class Reader;
SampleIterator(RefPtr<Core::MappedFile> file, ReadonlyBytes data, TrackEntry track, u64 timestamp_scale, size_t position)
SampleIterator(RefPtr<Core::SharedMappedFile> file, ReadonlyBytes data, TrackEntry track, u64 timestamp_scale, size_t position)
: m_file(move(file))
, m_data(data)
, m_track(move(track))
@ -100,7 +100,7 @@ private:
DecoderErrorOr<void> seek_to_cue_point(CuePoint const& cue_point);
RefPtr<Core::MappedFile> m_file;
RefPtr<Core::SharedMappedFile> m_file;
ReadonlyBytes m_data;
TrackEntry m_track;
u64 m_segment_timestamp_scale { 0 };